xiaoyong931011
2020-10-15 9088bdd31984501044a6e2a663cb858637f7ae5c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package com.xcong.excoin.modules.helpCenter.controller;
 
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
 
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
 
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
 
import com.xcong.excoin.common.annotation.ControllerEndpoint;
import com.xcong.excoin.common.controller.BaseController;
import com.xcong.excoin.common.entity.FebsResponse;
import com.xcong.excoin.common.entity.QueryRequest;
import com.xcong.excoin.common.utils.OssUtils;
import com.xcong.excoin.modules.helpCenter.entity.HelpCenterArticleEntity;
import com.xcong.excoin.modules.helpCenter.entity.HelpCenterNoticeEntity;
import com.xcong.excoin.modules.helpCenter.entity.HelpCenterTypeEntity;
import com.xcong.excoin.modules.helpCenter.service.HelpCenterService;
import sun.misc.BASE64Encoder;
 
import cn.hutool.core.util.IdUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
 
@Slf4j
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/helpCenter")
public class HelpCenterController extends BaseController {
    
    private final HelpCenterService helpCenterService;
    
    /**
     * 帮助中心---类型---删除
     * @param id
     * @return
     */
    @GetMapping("helpCenterTypeDelete/{id}")
    @ControllerEndpoint(operation = "删除", exceptionMessage = "删除失败")
    public FebsResponse helpCenterTypeDelete(@NotNull(message = "{required}") @PathVariable Long id) {
        return helpCenterService.helpCenterTypeDelete(id);
    }
    
    /**
     * 帮助中心---类型---新增
     */
    @PostMapping("helpCenterTypeAdds")
    @ControllerEndpoint(operation = " 帮助中心---类型---新增", exceptionMessage = "新增失败")
    public FebsResponse helpCenterTypeAdds(@Valid HelpCenterTypeEntity helpCenterTypeEntity) {
        helpCenterService.helpCenterTypeAdds(helpCenterTypeEntity);
        return new FebsResponse().success();
    }
    
    /**
     *  帮助中心---类型---列表
     * @return
     */
    @GetMapping("getHelpCenterTypeList")
    public FebsResponse getHelpCenterTypeList(HelpCenterTypeEntity helpCenterTypeEntity, QueryRequest request) {
        Map<String, Object> data = getDataTable(helpCenterService.findHelpCenterTypeListInPage(helpCenterTypeEntity, request));
        return new FebsResponse().success().data(data);
    }
    
    /**
     *  帮助中心---列表
     * @return
     */
    @GetMapping("getHelpCenterList")
    public FebsResponse getHelpCenterList(HelpCenterNoticeEntity helpCenterNoticeEntity, QueryRequest request) {
        Map<String, Object> data = getDataTable(helpCenterService.findHelpCenterListInPage(helpCenterNoticeEntity, request));
        return new FebsResponse().success().data(data);
    }
    
    /**
     * 帮助中心---删除公告
     * @param id
     * @return
     */
    @GetMapping("helpCenterDelete/{id}")
    @ControllerEndpoint(operation = "删除公告", exceptionMessage = "删除失败")
    public FebsResponse helpCenterDelete(@NotNull(message = "{required}") @PathVariable Long id) {
        return helpCenterService.helpCenterDelete(id);
    }
    
    /**
     * 帮助中心---新增
     */
    @PostMapping("helpCenterAdds")
    @ControllerEndpoint(operation = " 帮助中心---新增", exceptionMessage = "新增失败")
    public FebsResponse helpCenterAdds(@Valid HelpCenterNoticeEntity helpCenterNoticeEntity) {
        helpCenterService.helpCenterAdds(helpCenterNoticeEntity);
        return new FebsResponse().success();
    }
    
    /**
     * 帮助中心---中文确认
     * @return
     */
    @PostMapping("helpCenterConfirm")
    @ControllerEndpoint(operation = "帮助中心---确认", exceptionMessage = "设置失败")
    public FebsResponse helpCenterConfirm(@Valid HelpCenterArticleEntity helpCenterArticleEntity) {
        return helpCenterService.helpCenterConfirm(helpCenterArticleEntity);
    }
    
    /**
     * 帮助中心---英文确认
     * @return
     */
    @PostMapping("helpCenterUsConfirm")
    @ControllerEndpoint(operation = "帮助中心---确认", exceptionMessage = "设置失败")
    public FebsResponse helpCenterUsConfirm(@Valid HelpCenterArticleEntity helpCenterArticleEntity) {
        return helpCenterService.helpCenterUsConfirm(helpCenterArticleEntity);
    }
    
    /**
     *  帮助中心---图片上传
     * @param uploadDto
     * @return
     */
    @PostMapping(value = "/uploadFileBase64")
    @ControllerEndpoint(operation = "帮助中心---图片上传", exceptionMessage = "上传失败")
    public Map<String,Object> uploadFileBase64(@RequestBody @Validated MultipartFile file) {
        if (file.isEmpty()) {
            new FebsResponse().message("上传文件为空");
        }
        
        //文件加密
        BASE64Encoder base64Encoder =new BASE64Encoder();
        String base64EncoderImg = null;
        try {
            base64EncoderImg = base64Encoder.encode(file.getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
 
        String imageFuffix = ".jpg";
        String imageNames = System.currentTimeMillis() + IdUtil.simpleUUID() + imageFuffix;
        String imageName = "uploadeFile/image/" + imageNames;
        OssUtils.uploadFileWithBase64(base64EncoderImg, imageName);
            String bucket_name ="https://excoin.oss-cn-hangzhou.aliyuncs.com";
            String url = bucket_name + "/" + imageName;
            
            Map<String,Object> map = new HashMap<String,Object>();
            Map<String,Object> map2 = new HashMap<String,Object>();
            map.put("code",0);//0表示成功,1失败
            map.put("msg","上传成功");//提示消息
            map.put("data",map2);
            map2.put("src",url);//图片url
            map2.put("title",imageNames);//图片名称,这个会显示在输入框里
            return map;
    }
    
    
 
}