郑永安
2023-06-19 f65443d8abeaedc9d102324565e8368e7c9d90c8
src/main/java/com/gk/firework/Controller/AppFileController.java
对比新文件
@@ -0,0 +1,211 @@
package com.gk.firework.Controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gk.firework.Controller.Base.BaseController;
import com.gk.firework.Domain.*;
import com.gk.firework.Domain.Utils.*;
import com.gk.firework.Domain.Vo.*;
import com.gk.firework.Service.AppFileService;
import com.gk.firework.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.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@Api(tags = "APP版本信息接口")
@RestController
public class AppFileController extends BaseController {
    @Value("${appPath}")
    private String appPath;
    @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,
                            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(appUrl+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(appUrl+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;
    }
}