| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package cn.com.goldenwater.dcproj.controller.general;
- import cn.com.goldenwater.core.web.BaseController;
- import cn.com.goldenwater.core.web.BaseResponse;
- import cn.com.goldenwater.dcproj.service.ExcelImportService;
- import cn.com.goldenwater.dcproj.utils.impexcel.ExpAndImpUtil;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.RestController;
- import org.springframework.web.multipart.MultipartFile;
- import javax.servlet.http.HttpServletResponse;
- import java.io.File;
- /**
- * @author lql
- * @date 2021-3-7
- */
- @Api(value = "Excel导入数据", tags = "Excel导入数据")
- @RestController
- @RequestMapping("/excel/import")
- public class ExcelImportController extends BaseController {
- private Logger logger = LoggerFactory.getLogger(getClass());
- @Value("${export.templatePath}")
- private String templatePath;
- @Autowired
- private ExcelImportService excelImportService;
- @ApiOperation(value = "导入河湖四乱基础表数据")
- @RequestMapping(value = "/attBase/hhsl", method = RequestMethod.POST)
- public BaseResponse insert(@RequestParam(value = "file") MultipartFile file) {
- try {
- // 读取excel文件
- String result = excelImportService.excelImport(file);
- return buildSuccessResponse(result);
- } catch (Exception e) {
- e.printStackTrace();
- logger.error("文件读取失败", e);
- }
- return buildFailResponse("文件读取失败");
- }
- @ApiOperation("下载人员基本信息模板")
- @RequestMapping(value = "/template/hhsl", method = RequestMethod.GET)
- public BaseResponse downTemplateExcel(HttpServletResponse response) {
- try {
- ExpAndImpUtil.downloadFile(response, templatePath + File.separator + "attHhslBaseList.xls", "河湖四乱导入模板");
- } catch (Exception e) {
- buildFailResponse(e.getMessage());
- }
- return buildSuccessResponse();
- }
- }
|