chen_xi
2022-09-30 4753c019b4cb00c127ac83148dd820d271bea048
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
package com.moral.api.controller;
 
 
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
 
import java.io.IOException;
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
import com.moral.api.pojo.bo.ExcelBO;
import com.moral.api.pojo.vo.excel.ExcelVo;
import com.moral.api.service.ExcelService;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import com.moral.util.WebUtils;
 
@Slf4j
@RestController
@RequestMapping("/excel")
public class ExcelController {
 
    @Autowired
    private ExcelService excelService;
 
    /**
     * 导入
     * @param request
     * @return
     * @throws IOException
     */
    @PostMapping("excelImport")
    public ResultMessage excelImport(HttpServletRequest request) throws IOException {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if (!params.containsKey("time") || !params.containsKey("code") || params.containsKey("data")){
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("files");
        ExcelBO excelBO = excelService.importTemplate(files, params);
        return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),excelBO);
    }
 
 
    /**
     * 导出
     * @param id
     * @return
     */
    @GetMapping("/excelExport")
    public ResultMessage excelExport(Integer id){
        if (id==null){
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        ExcelVo export = excelService.export(id);
        if (export==null){
            return ResultMessage.fail(ResponseCodeEnum.TARGET_IS_NULL.getCode(), ResponseCodeEnum.TARGET_IS_NULL.getMsg());
        }
 
        return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),export);
    }
 
    /**
     * 查询
     * @param startTime
     * @param code
     * @param endTime
     * @return
     */
    @GetMapping("/selectExcel")
    public  ResultMessage selectExcel(String startTime,String code, String endTime){
        if (startTime == null || code==null || endTime==null){
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        List<ExcelBO> excelBOS = excelService.excelSelect(startTime, code, endTime);
        if (excelBOS==null){
            return ResultMessage.fail(ResponseCodeEnum.TARGET_IS_NULL.getCode(), ResponseCodeEnum.TARGET_IS_NULL.getMsg());
        }
        return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),excelBOS);
    }
 
}