package cn.com.goldenwater.dcproj.controller.safeprod; import cn.com.goldenwater.core.web.BaseController; import cn.com.goldenwater.core.web.BaseResponse; import cn.com.goldenwater.dcproj.model.AttAdBase; import cn.com.goldenwater.dcproj.model.ChkSafeStatList; import cn.com.goldenwater.dcproj.model.ChkSafeStatListIndustry; import cn.com.goldenwater.dcproj.param.ChkSafeStatListIndustryParam; import cn.com.goldenwater.dcproj.param.ChkSafeStatListParam; import cn.com.goldenwater.dcproj.service.AttAdBaseService; import cn.com.goldenwater.dcproj.service.ChkSafeStatListIndustryService; import cn.com.goldenwater.dcproj.service.ChkSafeStatListService; import cn.com.goldenwater.dcproj.service.OlBisInspOrgService; import cn.com.goldenwater.dcproj.util.ReadExcelUtil; import cn.com.goldenwater.dcproj.utils.AdLevelUtil; import cn.com.goldenwater.dcproj.utils.StringUtils; import cn.com.goldenwater.dcproj.utils.impexcel.ExpAndImpUtil; import cn.com.goldenwater.id.util.UuidUtil; import com.github.pagehelper.PageInfo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; 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.util.Assert; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.stream.Collectors; /** * 成都市水务行业安全大检查情况统计Controller * * @author ruoyi * @date 2023-02-22 */ @Api(value = "成都市水务行业安全大检查情况统计表", tags = "成都市水务行业安全大检查情况统计表") @RestController @RequestMapping("/chk/safe/stat/record") public class ChkSafeStatListController extends BaseController { private Logger logger = LoggerFactory.getLogger(getClass()); /** * 成都市水务行业安全大检查情况统计 服务 */ @Autowired private ChkSafeStatListService chkSafeStatListService; /** * 成都市水务行业安全大检查行业(领域) 服务 */ @Autowired private ChkSafeStatListIndustryService chkSafeStatListIndustryService; @Value("${export.templatePath}") private String templatePath; /** * 上传模板名称 * 水务行业安全大检查情况表 */ private String templateName = "chkSafeStatList.xls"; /** * 机构 区域 服务 */ @Autowired private OlBisInspOrgService olBisInspOrgService; @Autowired private AttAdBaseService attAdBaseService; /** * 新增/编辑成都市水务行业安全大检查情况统计单表 */ @ApiOperation(value = "修改") @RequestMapping(value = "/", method = RequestMethod.POST) public BaseResponse insert(@ApiParam(name = "chkSafeStatList", value = "ChkSafeStatList", required = true) @RequestBody ChkSafeStatList chkSafeStatList) { int ret = 0; if (StringUtils.isBlank(chkSafeStatList.getId())) { chkSafeStatList.setOrgId(getCurrentOrgId()); chkSafeStatList.setPersId(getCurrentPersId()); chkSafeStatList.setAdCode(olBisInspOrgService.getRlProvince(getCurrentOrgId())); //填报状态 1新增 2上报 chkSafeStatList.setFillRepoStat("1"); ret = chkSafeStatListService.insert(chkSafeStatList); } else { ret = chkSafeStatListService.update(chkSafeStatList); } return buildSuccessResponse(chkSafeStatList); } /** * 删除成都市水务行业安全大检查情况统计 单表 */ @ApiOperation(value = "根据ID删除") @RequestMapping(value = "delete/{id}", method = RequestMethod.POST) public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { int ret = chkSafeStatListService.delete(id); return buildSuccessResponse(); } @ApiOperation(value = "更新成都市水务行业安全大检查情况统计表") @RequestMapping(value = "/update", method = RequestMethod.POST) public BaseResponse update(@ApiParam(name = "chkSafeProdLedger", value = "chkSafeProdLedger", required = true) @RequestBody ChkSafeStatList chkSafeStatList) { Assert.notNull(chkSafeStatList.getId(), "主键id为必填参数"); int ret = chkSafeStatListService.update(chkSafeStatList); return buildSuccessResponse(chkSafeStatList); } @ApiOperation(value = "批量上报 成都市水务行业安全大检查情况统计") @RequestMapping(value = "/report/batch", method = RequestMethod.POST) public BaseResponse batchReport(@ApiParam(name = "ids", value = "ids", required = true) @RequestParam String[] ids) { Assert.notNull(ids, "主键id为必填参数"); int ret = chkSafeStatListService.batchReportByIds(ids); return buildSuccessResponse(ret); } /** * 查询成都市水务行业安全大检查情况统计单表 */ @ApiOperation(value = "根据ID获取单表") @RequestMapping(value = "/{id}", method = RequestMethod.GET) public BaseResponse get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { ChkSafeStatList chkSafeStatList = chkSafeStatListService.get(id); return buildSuccessResponse(chkSafeStatList); } /** * 查询成都市水务行业安全大检查情况统计列表 */ @ApiOperation(value = "列表--分页") @RequestMapping(value = "/page", method = RequestMethod.POST) public BaseResponse page(@ApiParam(name = "chkSafeStatListParam", value = "chkSafeStatListParam", required = true) @RequestBody ChkSafeStatListParam chkSafeStatListParam) { if (StringUtils.isBlank(chkSafeStatListParam.getAdCode())) { chkSafeStatListParam.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getRlProvince(getCurrentOrgId()))); } AttAdBase attAdBase = attAdBaseService.getByAdcode(olBisInspOrgService.getRlProvince(getCurrentOrgId())); // 2 省 3 市 4 县 5 乡镇 6 村 if ("3".equals(attAdBase.getAdGrad())) { // 如果是市级的 只查询 上报的 1-新增; 2-上报 chkSafeStatListParam.setFillRepoStat("2"); } return buildSuccessResponse(chkSafeStatListService.findPageInfo(chkSafeStatListParam)); } /** * 导出成都市水务行业安全大检查情况统计列表 */ @ApiOperation(value = "根据条件导出成都市水务行业安全大检查情况统计") @RequestMapping(value = "/export", method = RequestMethod.POST) public void export(@ApiParam(name = "chkSafeStatListParam", value = "chkSafeStatListParam") @RequestBody(required = false) ChkSafeStatListParam chkSafeStatListParam, HttpServletResponse response) { if (StringUtils.isBlank(chkSafeStatListParam.getAdCode())) { chkSafeStatListParam.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getRlProvince(getCurrentOrgId()))); } AttAdBase attAdBase = attAdBaseService.getByAdcode(olBisInspOrgService.getRlProvince(getCurrentOrgId())); // 2 省 3 市 4 县 5 乡镇 6 村 if ("3".equals(attAdBase.getAdGrad())) { // 如果是市级的 只查询 上报的 1-新增; 2-上报 chkSafeStatListParam.setFillRepoStat("2"); } chkSafeStatListService.export(chkSafeStatListParam, response); } @ApiOperation(value = "下载模板") @RequestMapping(value = "/dowmTemplate", method = RequestMethod.GET) public BaseResponse dowmTemplate(HttpServletResponse response) { try { ExpAndImpUtil.downloadFile(response, templatePath + File.separator + templateName, "成都市安全生产大检查行动检查情况统计表"); } catch (Exception e) { return buildFailResponse(e); } return buildSuccessResponse(); } @ApiOperation("批量上报 上传xls导入数据") @RequestMapping(value = "/impExl", method = RequestMethod.POST) public BaseResponse> impExl(@RequestParam("file") MultipartFile multfile) throws IOException, InvalidFormatException { // 获取文件名 String fileName = multfile.getOriginalFilename(); // 获取文件后缀 String prefix = fileName.substring(fileName.lastIndexOf(".")); // 用uuid作为文件名,防止生成的临时文件重复 String uuid = UuidUtil.uuid(); File file = File.createTempFile(uuid, prefix); // MultipartFile to File multfile.transferTo(Paths.get(file.getPath())); // 获取当前当前用户机构和行政区划 String curOrgId = getCurrentOrgId(); String curPersId = getCurrentPersId(); List resultList = new ArrayList<>(); // 获取excle表格内容 忽略第1行 String[][] data = ReadExcelUtil.getDataAll(file, 1, 0); try { if (data != null && data.length > 0) { Date curDate = new Date(); List industryList = chkSafeStatListIndustryService.findList(new ChkSafeStatListIndustryParam()); List safeStatLists = new ArrayList<>(data.length); for (int i = 0; i < data.length; i++) { ChkSafeStatList safeStat = new ChkSafeStatList(curDate, curPersId); if (org.apache.commons.lang3.StringUtils.isBlank(data[i][0])) { // 此行首列的 单元格为空 就认为 此行结束 resultList.add("第" + (i + 2) + "行结束"); break; } // 行政区域代码 String adCode = data[i][0].substring(0, 12); safeStat.setOrgId(curOrgId); safeStat.setAdCode(adCode); // 报送单位 safeStat.setChkSubmitDept(data[i][4]); // 行业(领域) safeStat.setChkIndustry(formatIndustryType(data[i][5], industryList)); safeStat.setChkGroupNum(formatNum(data[i][6])); safeStat.setChkGroupNumUndercover(formatNum(data[i][7])); safeStat.setChkPointNum(formatNum(data[i][8])); safeStat.setInspGeneralChk(formatNum(data[i][9])); safeStat.setInspGeneralRepair(formatNum(data[i][10])); safeStat.setInspMajorChk(formatNum(data[i][11])); safeStat.setInspMajorRepair(formatNum(data[i][12])); safeStat.setDangerRectFund(data[i][13]); safeStat.setCrackDownIllegalAction(formatNum(data[i][14])); safeStat.setRepairViolateRuleAction(formatNum(data[i][15])); safeStat.setStopProdRect(formatNum(data[i][16])); safeStat.setSuspendLicense(formatNum(data[i][17])); safeStat.setShutClampDown(formatNum(data[i][18])); safeStat.setPenaltyFine(data[i][19]); safeStat.setActbExpsUnit(formatNum(data[i][20])); safeStat.setJoinPunishTrustBreakEntp(formatNum(data[i][21])); // 报送月份 safeStatLists.add(safeStat); } // 批量导入 this.chkSafeStatListService.insertBatchFile(safeStatLists); } } catch (Exception e) { logger.error(e.getMessage()); return buildFailResponse(); } return buildSuccessResponse(resultList); } private String formatIndustryType(String industryType, List industryList) { try { if (StringUtils.isBlank(industryType)) { return null; } String formatStr = industryList.stream().filter(f -> industryType.equals(f.getIndustryType())).map(m -> m.getId()).collect(Collectors.joining()); return formatStr; } catch (Exception e) { return null; } } private Long formatNum(String cellVal) { if (StringUtils.isBlank(cellVal)) { return 0L; } try { return Long.parseLong(cellVal); } catch (NumberFormatException e) { return 0L; } } }