yantian yue
2023-10-18 69fbaaa1a5fd16b05953e750ea7fcc3e18e3a27c
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
package cn.stylefeng.guns.excel.controller;
 
import cn.stylefeng.guns.base.consts.ConstantsContext;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.core.util.FileDownload;
import cn.stylefeng.guns.excel.entity.ExcelExportDeploy;
import cn.stylefeng.guns.excel.model.params.ExcelExportDeployParam;
import cn.stylefeng.guns.excel.service.ExcelExportDeployService;
import cn.stylefeng.guns.sys.modular.system.entity.FileInfo;
import cn.stylefeng.guns.sys.modular.system.model.UploadResult;
import cn.stylefeng.guns.sys.modular.system.service.FileInfoService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletResponse;
 
import static cn.stylefeng.guns.excel.consts.ExcelConstants.EXCEL_FILE_TEMPLATE_PATH;
 
/**
 * excel导出配置控制器
 *
 * @author York
 * @Date 2019-11-26 16:52:02
 */
@Controller
@RequestMapping("/excelExportDeploy")
public class ExcelExportDeployController extends BaseController {
 
    private String PREFIX = "/modular/excel";
 
    @Autowired
    private FileInfoService fileInfoService;
 
    @Autowired
    private ExcelExportDeployService excelExportDeployService;
 
    /**
     * 跳转到主页面
     *
     * @author York
     * @Date 2019-11-26
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/excelExportDeploy.html";
    }
 
    /**
     * 新增页面
     *
     * @author York
     * @Date 2019-11-26
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/excelExportDeploy_add.html";
    }
 
    /**
     * 编辑页面
     *
     * @author York
     * @Date 2019-11-26
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/excelExportDeploy_edit.html";
    }
 
    /**
     * 新增接口
     *
     * @author York
     * @Date 2019-11-26
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ExcelExportDeployParam excelExportDeployParam) {
        this.excelExportDeployService.add(excelExportDeployParam);
        return ResponseData.success();
    }
 
    /**
     * 编辑接口
     *
     * @author York
     * @Date 2019-11-26
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(ExcelExportDeployParam excelExportDeployParam) {
        this.excelExportDeployService.update(excelExportDeployParam);
        return ResponseData.success();
    }
 
    /**
     * 删除接口
     *
     * @author York
     * @Date 2019-11-26
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ExcelExportDeployParam excelExportDeployParam) {
        this.excelExportDeployService.delete(excelExportDeployParam);
        return ResponseData.success();
    }
 
    /**
     * 上传模版文件
     *
     * @return
     */
    @RequestMapping("/uploadTemplate")
    @ResponseBody
    public ResponseData uploadTemplate(@RequestPart("file") MultipartFile file) {
        try {
            if (file == null) {
                return ResponseData.error("请选择要上传的模版文件");
            }
 
            //上传路径设置
            String fileSavePath = ConstantsContext.getFileUploadPath();
            fileSavePath = fileSavePath + EXCEL_FILE_TEMPLATE_PATH;
 
            UploadResult uploadResult = fileInfoService.uploadFile(file, fileSavePath);
            if (!uploadResult.getOriginalFilename().contains(".xls")) {
                return ResponseData.error("上传的模版文件必须为2003版的excel文件");
            }
 
            return ResponseData.success(EXCEL_FILE_TEMPLATE_PATH + uploadResult.getFinalName());
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseData.error(e.getMessage());
        }
 
    }
 
    /**
     * 下载模板文件
     *
     * @author fengshuonan
     * @Date 2019-2-23 10:48:29
     */
    @RequestMapping(path = "/download/{fileFinalName}")
    public void download(@PathVariable String fileFinalName, HttpServletResponse httpServletResponse) {
 
        //上传路径设置
        String fileSavePath = ConstantsContext.getFileUploadPath();
        fileSavePath = fileSavePath + EXCEL_FILE_TEMPLATE_PATH;
 
        //查找文件信息
        FileInfo fileInfo = fileInfoService.getByFinalName(fileFinalName);
 
        try {
            FileDownload.fileDownload(httpServletResponse, fileSavePath + fileFinalName, fileInfo.getFileName());
        } catch (Exception e) {
            e.printStackTrace();
        }
 
    }
 
    /**
     * 查看详情接口
     *
     * @author York
     * @Date 2019-11-26
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ExcelExportDeployParam excelExportDeployParam) {
        ExcelExportDeploy detail = this.excelExportDeployService.getById(excelExportDeployParam.getId());
        return ResponseData.success(detail);
    }
 
    /**
     * 查询列表
     *
     * @author York
     * @Date 2019-11-26
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(ExcelExportDeployParam excelExportDeployParam) {
        return this.excelExportDeployService.findPageBySpec(excelExportDeployParam);
    }
 
}