懒羊羊
2023-08-30 1ac2bc1590406d9babec036e154d8d08f34a6aa1
提交 | 用户 | 时间
1ac2bc 1 package cn.stylefeng.guns.excel.controller;
2
3 import cn.stylefeng.guns.base.consts.ConstantsContext;
4 import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
5 import cn.stylefeng.guns.sys.core.util.FileDownload;
6 import cn.stylefeng.guns.excel.entity.ExcelExportDeploy;
7 import cn.stylefeng.guns.excel.model.params.ExcelExportDeployParam;
8 import cn.stylefeng.guns.excel.service.ExcelExportDeployService;
9 import cn.stylefeng.guns.sys.modular.system.entity.FileInfo;
10 import cn.stylefeng.guns.sys.modular.system.model.UploadResult;
11 import cn.stylefeng.guns.sys.modular.system.service.FileInfoService;
12 import cn.stylefeng.roses.core.base.controller.BaseController;
13 import cn.stylefeng.roses.kernel.model.response.ResponseData;
14 import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.stereotype.Controller;
16 import org.springframework.web.bind.annotation.PathVariable;
17 import org.springframework.web.bind.annotation.RequestMapping;
18 import org.springframework.web.bind.annotation.RequestPart;
19 import org.springframework.web.bind.annotation.ResponseBody;
20 import org.springframework.web.multipart.MultipartFile;
21
22 import javax.servlet.http.HttpServletResponse;
23
24 import static cn.stylefeng.guns.excel.consts.ExcelConstants.EXCEL_FILE_TEMPLATE_PATH;
25
26 /**
27  * excel导出配置控制器
28  *
29  * @author York
30  * @Date 2019-11-26 16:52:02
31  */
32 @Controller
33 @RequestMapping("/excelExportDeploy")
34 public class ExcelExportDeployController extends BaseController {
35
36     private String PREFIX = "/modular/excel";
37
38     @Autowired
39     private FileInfoService fileInfoService;
40
41     @Autowired
42     private ExcelExportDeployService excelExportDeployService;
43
44     /**
45      * 跳转到主页面
46      *
47      * @author York
48      * @Date 2019-11-26
49      */
50     @RequestMapping("")
51     public String index() {
52         return PREFIX + "/excelExportDeploy.html";
53     }
54
55     /**
56      * 新增页面
57      *
58      * @author York
59      * @Date 2019-11-26
60      */
61     @RequestMapping("/add")
62     public String add() {
63         return PREFIX + "/excelExportDeploy_add.html";
64     }
65
66     /**
67      * 编辑页面
68      *
69      * @author York
70      * @Date 2019-11-26
71      */
72     @RequestMapping("/edit")
73     public String edit() {
74         return PREFIX + "/excelExportDeploy_edit.html";
75     }
76
77     /**
78      * 新增接口
79      *
80      * @author York
81      * @Date 2019-11-26
82      */
83     @RequestMapping("/addItem")
84     @ResponseBody
85     public ResponseData addItem(ExcelExportDeployParam excelExportDeployParam) {
86         this.excelExportDeployService.add(excelExportDeployParam);
87         return ResponseData.success();
88     }
89
90     /**
91      * 编辑接口
92      *
93      * @author York
94      * @Date 2019-11-26
95      */
96     @RequestMapping("/editItem")
97     @ResponseBody
98     public ResponseData editItem(ExcelExportDeployParam excelExportDeployParam) {
99         this.excelExportDeployService.update(excelExportDeployParam);
100         return ResponseData.success();
101     }
102
103     /**
104      * 删除接口
105      *
106      * @author York
107      * @Date 2019-11-26
108      */
109     @RequestMapping("/delete")
110     @ResponseBody
111     public ResponseData delete(ExcelExportDeployParam excelExportDeployParam) {
112         this.excelExportDeployService.delete(excelExportDeployParam);
113         return ResponseData.success();
114     }
115
116     /**
117      * 上传模版文件
118      *
119      * @return
120      */
121     @RequestMapping("/uploadTemplate")
122     @ResponseBody
123     public ResponseData uploadTemplate(@RequestPart("file") MultipartFile file) {
124         try {
125             if (file == null) {
126                 return ResponseData.error("请选择要上传的模版文件");
127             }
128
129             //上传路径设置
130             String fileSavePath = ConstantsContext.getFileUploadPath();
131             fileSavePath = fileSavePath + EXCEL_FILE_TEMPLATE_PATH;
132
133             UploadResult uploadResult = fileInfoService.uploadFile(file, fileSavePath);
134             if (!uploadResult.getOriginalFilename().contains(".xls")) {
135                 return ResponseData.error("上传的模版文件必须为2003版的excel文件");
136             }
137
138             return ResponseData.success(EXCEL_FILE_TEMPLATE_PATH + uploadResult.getFinalName());
139         } catch (Exception e) {
140             e.printStackTrace();
141             return ResponseData.error(e.getMessage());
142         }
143
144     }
145
146     /**
147      * 下载模板文件
148      *
149      * @author fengshuonan
150      * @Date 2019-2-23 10:48:29
151      */
152     @RequestMapping(path = "/download/{fileFinalName}")
153     public void download(@PathVariable String fileFinalName, HttpServletResponse httpServletResponse) {
154
155         //上传路径设置
156         String fileSavePath = ConstantsContext.getFileUploadPath();
157         fileSavePath = fileSavePath + EXCEL_FILE_TEMPLATE_PATH;
158
159         //查找文件信息
160         FileInfo fileInfo = fileInfoService.getByFinalName(fileFinalName);
161
162         try {
163             FileDownload.fileDownload(httpServletResponse, fileSavePath + fileFinalName, fileInfo.getFileName());
164         } catch (Exception e) {
165             e.printStackTrace();
166         }
167
168     }
169
170     /**
171      * 查看详情接口
172      *
173      * @author York
174      * @Date 2019-11-26
175      */
176     @RequestMapping("/detail")
177     @ResponseBody
178     public ResponseData detail(ExcelExportDeployParam excelExportDeployParam) {
179         ExcelExportDeploy detail = this.excelExportDeployService.getById(excelExportDeployParam.getId());
180         return ResponseData.success(detail);
181     }
182
183     /**
184      * 查询列表
185      *
186      * @author York
187      * @Date 2019-11-26
188      */
189     @ResponseBody
190     @RequestMapping("/list")
191     public LayuiPageInfo list(ExcelExportDeployParam excelExportDeployParam) {
192         return this.excelExportDeployService.findPageBySpec(excelExportDeployParam);
193     }
194
195 }