郑永安
2023-09-19 69185134fcfaf913ea45f1255677225a2cc311a4
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
package com.gk.hotwork.Controller;
 
import com.alibaba.fastjson.JSONObject;
import com.gk.hotwork.Controller.Base.BaseController;
import com.gk.hotwork.Domain.*;
import com.gk.hotwork.Domain.Utils.*;
import com.gk.hotwork.Domain.Vo.*;
import com.gk.hotwork.Service.AppFileService;
import com.gk.hotwork.Service.HelpDocService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
 
import java.util.Date;
import java.util.HashMap;
 
 
@Api(tags = "APP版本信息接口")
@RestController
public class AppFileController extends BaseController {
    @Value("${appPath}")
    private String appPath;
    @Value("${app}")
    private String app;
    @Value("${appUrl}")
    private String appUrl;
    @Autowired
    AppFileService appFileService;
    @Autowired
    HelpDocService helpDocService;
 
    @GetMapping("/appFile")
    @ApiOperation(value = "获取App文件数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex",value = "当前页码"),
            @ApiImplicitParam(name = "pageSize",value = "每页行数"),
            @ApiImplicitParam(name = "sort",value = "排序规则"),
            @ApiImplicitParam(name = "order",value = "排序字段"),
            @ApiImplicitParam(name = "filetype",value = "文件类型"),
    })
    public Msg getAppFileInfo(@RequestParam(defaultValue = "0") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize, String sort, String order,
                            @RequestParam(required = false) String filetype){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
 
        PageInfo pageInfo = new PageInfo(pageIndex, pageSize,sort,order);
        HashMap<String, Object> condition = new HashMap<String, Object>();
 
        if (StringUtils.isNotBlank(filetype)){
            condition.put("filetype",filetype.trim());
        }
 
        pageInfo.setCondition(condition);
        appFileService.selectDataGrid(pageInfo);
        msg.setResult(pageInfo);
        return msg;
    }
 
    @GetMapping("/newAppFile")
    @ApiOperation(value = "获取最新App文件数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "filetype",value = "文件类型"),
    })
    public Msg getNewAppFile(String filetype){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        AppFileInfo appFileInfo = appFileService.selectNew(filetype);
        if (appFileInfo != null){
            msg.setResult(appFileInfo);
            return msg;
        }else {
            msg.setCode("999");
            msg.setMessage("未找到文件");
            return msg;
        }
    }
 
    @ApiOperation(value = "添加文件",response = Msg.class)
    @PostMapping("/addAppFile")
    public Msg addAppFile(AppFileVo appFileVo) throws Exception {
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        AppFileInfo appFileInfo = BeanUtils.copy(appFileVo, AppFileInfo.class);
 
        if (appFileVo.getFile() != null){
            String filePath = UploadUtil.uploadFile(appFileVo.getFile(),appPath);
            appFileInfo.setFileurl(app + filePath);
        }
        appFileInfo.setCreated(new Date());
        appFileInfo.setUpdated(new Date());
        appFileService.save(appFileInfo);
        return msg;
    }
 
    @ApiOperation(value = "修改文件",response = Msg.class)
    @PostMapping("/editAppFile")
    public Msg editAppFile(AppFileVo appFileVo) throws Exception {
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        AppFileInfo appFileInfo = BeanUtils.copy(appFileVo, AppFileInfo.class);
 
        if (appFileVo.getFile() != null){
            String filePath = UploadUtil.uploadFile(appFileVo.getFile(),appPath);
            appFileInfo.setFileurl(app+filePath);
        }
        appFileInfo.setUpdated(new Date());
        appFileService.updateById(appFileInfo);
        return msg;
    }
 
    @ApiOperation(value = "删除文件",response = Msg.class)
    @PostMapping("/delAppFile")
    public Msg delAppFile(@RequestBody JSONObject jsonObject){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        Long id = jsonObject.getLong("id");
 
        AppFileInfo appFileInfo = appFileService.getById(id);
        if (appFileInfo != null){
            appFileService.removeById(appFileInfo);
        }else {
            msg.setCode("999");
            msg.setMessage("未找到记录");
        }
        return msg;
    }
 
    @GetMapping("/helpDoc")
    @ApiOperation(value = "获取帮助文档数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex",value = "当前页码"),
            @ApiImplicitParam(name = "pageSize",value = "每页行数"),
            @ApiImplicitParam(name = "sort",value = "排序规则"),
            @ApiImplicitParam(name = "order",value = "排序字段"),
            @ApiImplicitParam(name = "name",value = "文件名称"),
    })
    public Msg getHelpDocInfo(@RequestParam(defaultValue = "0") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize, String sort, String order,
                              String name){
        Msg msg = new Msg(true);
 
        PageInfo pageInfo = new PageInfo(pageIndex, pageSize,sort,order);
        HashMap<String, Object> condition = new HashMap<>(4);
 
        if (StringUtils.isNotBlank(name)){
            condition.put("name",name.trim());
        }
 
        pageInfo.setCondition(condition);
        helpDocService.selectDataGrid(pageInfo);
        msg.setResult(pageInfo);
        return msg;
    }
 
    @ApiOperation(value = "添加帮助文档",response = Msg.class)
    @PostMapping("/addHelpDoc")
    public Msg addHelpDoc(HelpDocVo helpDocVo) throws Exception {
        Msg msg = new Msg(true);
        HelpDocInfo helpDocInfo = BeanUtils.copy(helpDocVo, HelpDocInfo.class);
 
        if (helpDocVo.getFile() != null){
            String filePath = UploadUtil.uploadFile(helpDocVo.getFile(),appPath);
            helpDocInfo.setFileurl(appUrl+filePath);
        }
        helpDocInfo.setCreated(new Date());
        helpDocInfo.setUpdated(new Date());
        helpDocService.save(helpDocInfo);
        return msg;
    }
 
    @ApiOperation(value = "修改帮助文档",response = Msg.class)
    @PostMapping("/editHelpDoc")
    public Msg editHelpDoc(HelpDocVo helpDocVo) throws Exception {
        Msg msg = new Msg(true);
 
        HelpDocInfo helpDocInfo = BeanUtils.copy(helpDocVo, HelpDocInfo.class);
        if (helpDocVo.getFile() != null){
            String filePath = UploadUtil.uploadFile(helpDocVo.getFile(),appPath);
            helpDocInfo.setFileurl(appUrl+filePath);
        }
        helpDocInfo.setUpdated(new Date());
 
        helpDocService.updateById(helpDocInfo);
        return msg;
    }
 
    @ApiOperation(value = "删除帮助文档(假删)",response = Msg.class)
    @PostMapping("/delHelpDoc")
    public Msg delHelpDoc(@RequestBody JSONObject jsonObject) {
        Msg msg = new Msg(true);
        Long id = jsonObject.getLong("id");
        HelpDocInfo helpDocInfo = helpDocService.getById(id);
        if (helpDocInfo != null) {
            helpDocInfo.setIsdel((byte) 1);
            helpDocService.updateById(helpDocInfo);
        } else {
            msg.setCode("999");
            msg.setMessage("未找到记录");
        }
        return msg;
    }
}