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.ChkSafeSelsProj; import cn.com.goldenwater.dcproj.model.ChkSafeSpvsEnforceLawStat; import cn.com.goldenwater.dcproj.param.ChkSafeSelsProjParam; import cn.com.goldenwater.dcproj.param.ChkSafeSpvsEnforceLawStatParam; import cn.com.goldenwater.dcproj.service.AttAdBaseService; import cn.com.goldenwater.dcproj.service.ChkSafeSelsProjService; import cn.com.goldenwater.dcproj.service.ChkSafeSpvsEnforceLawStatService; 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/spvs/enforce/law/stat") public class ChkSafeSpvsEnforceLawStatController extends BaseController { private Logger logger = LoggerFactory.getLogger(getClass()); /** * 成都市水务安全生产'护安'监管执法专项行动统计汇总 服务 */ @Autowired private ChkSafeSpvsEnforceLawStatService chkSafeSpvsEnforceLawStatService; /** * 项目类型 */ @Autowired private ChkSafeSelsProjService chkSafeSelsProjService; /** * 机构 区域 服务 */ @Autowired private OlBisInspOrgService olBisInspOrgService; @Autowired private AttAdBaseService attAdBaseService; @Value("${export.templatePath}") private String templatePath; /** * 上传模板名称 * 监管执法专项行动 统计汇总表 */ private String templateName = "chkSafeSpvsEnforceLawStat.xls"; /** * 新增/编辑成都市水务安全生产'护安'监管执法专项行动统计汇总单表 */ @ApiOperation(value = "修改") @RequestMapping(value = "/", method = RequestMethod.POST) public BaseResponse insert(@ApiParam(name = "chkSafeSpvsEnforceLawStat", value = "ChkSafeSpvsEnforceLawStat", required = true) @RequestBody ChkSafeSpvsEnforceLawStat chkSafeSpvsEnforceLawStat) { int ret = 0; if (StringUtils.isBlank(chkSafeSpvsEnforceLawStat.getId())) { chkSafeSpvsEnforceLawStat.setOrgId(getCurrentOrgId()); chkSafeSpvsEnforceLawStat.setPersId(getCurrentPersId()); chkSafeSpvsEnforceLawStat.setAdCode(olBisInspOrgService.getRlProvince(getCurrentOrgId())); ret = chkSafeSpvsEnforceLawStatService.insert(chkSafeSpvsEnforceLawStat); } else { ret = chkSafeSpvsEnforceLawStatService.update(chkSafeSpvsEnforceLawStat); } return buildSuccessResponse(chkSafeSpvsEnforceLawStat); } /** * 删除成都市水务安全生产'护安'监管执法专项行动统计汇总 单表 */ @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 = chkSafeSpvsEnforceLawStatService.delete(id); return buildSuccessResponse(); } @ApiOperation(value = "更新成都市水务安全生产'护安'监管执法专项行动统计汇总表") @RequestMapping(value = "/update", method = RequestMethod.POST) public BaseResponse update(@ApiParam(name = "chkSafeProdLedger", value = "chkSafeProdLedger", required = true) @RequestBody ChkSafeSpvsEnforceLawStat chkSafeSpvsEnforceLawStat) { Assert.notNull(chkSafeSpvsEnforceLawStat.getId(), "主键id为必填参数"); int ret = chkSafeSpvsEnforceLawStatService.update(chkSafeSpvsEnforceLawStat); return buildSuccessResponse(chkSafeSpvsEnforceLawStat); } @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 = chkSafeSpvsEnforceLawStatService.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) { ChkSafeSpvsEnforceLawStat chkSafeSpvsEnforceLawStat = chkSafeSpvsEnforceLawStatService.get(id); return buildSuccessResponse(chkSafeSpvsEnforceLawStat); } /** * 查询成都市水务安全生产'护安'监管执法专项行动统计汇总列表 */ @ApiOperation(value = "列表--分页") @RequestMapping(value = "/page", method = RequestMethod.POST) public BaseResponse page(@ApiParam(name = "chkSafeSpvsEnforceLawStatParam", value = "chkSafeSpvsEnforceLawStatParam", required = true) @RequestBody ChkSafeSpvsEnforceLawStatParam chkSafeSpvsEnforceLawStatParam) { if (StringUtils.isBlank(chkSafeSpvsEnforceLawStatParam.getAdCode())) { chkSafeSpvsEnforceLawStatParam.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-上报 chkSafeSpvsEnforceLawStatParam.setFillRepoStat("2"); } return buildSuccessResponse(chkSafeSpvsEnforceLawStatService.findPageInfo(chkSafeSpvsEnforceLawStatParam)); } /** * 导出成都市水务安全生产'护安'监管执法专项行动统计汇总列表 */ @ApiOperation(value = "根据条件导出成都市水务安全生产'护安'监管执法专项行动统计汇总") @RequestMapping(value = "/export", method = RequestMethod.POST) public void export(@ApiParam(name = "chkSafeSpvsEnforceLawStatParam", value = "chkSafeSpvsEnforceLawStatParam") @RequestBody(required = false) ChkSafeSpvsEnforceLawStatParam chkSafeSpvsEnforceLawStatParam, HttpServletResponse response) { if (StringUtils.isBlank(chkSafeSpvsEnforceLawStatParam.getAdCode())) { chkSafeSpvsEnforceLawStatParam.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-上报 chkSafeSpvsEnforceLawStatParam.setFillRepoStat("2"); } chkSafeSpvsEnforceLawStatService.export(chkSafeSpvsEnforceLawStatParam, response); } @ApiOperation(value = "下载模板") @RequestMapping(value = "/dowmTemplate", method = RequestMethod.GET) public BaseResponse dowmTemplate(HttpServletResponse response) { try { ExpAndImpUtil.downloadFile(response, templatePath + File.separator + templateName, "成都市水务安全生产”护安2023“监管执法专项行动统计汇总表"); } 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 projList = chkSafeSelsProjService.findList(new ChkSafeSelsProjParam()); List safeSpvsEnforceLawStatList = new ArrayList<>(data.length); for (int i = 0; i < data.length; i++) { ChkSafeSpvsEnforceLawStat cssels = new ChkSafeSpvsEnforceLawStat(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); cssels.setOrgId(curOrgId); cssels.setAdCode(adCode); // 报送单位 cssels.setChkSubmitDept(data[i][4]); // 项目类型 cssels.setChkProjType(formatProjType(data[i][5], projList)); cssels.setChkProjSubType(formatProjType(data[i][6], projList)); cssels.setChkGroupNum(formatNum(data[i][7])); cssels.setChkPersTime(formatNum(data[i][8])); cssels.setChkSafeExpertTime(formatNum(data[i][9])); cssels.setChkUnitNum(formatNum(data[i][10])); cssels.setChkFindDangerTotalNum(formatNum(data[i][11])); cssels.setChkFindDangerGeneralNum(formatNum(data[i][12])); cssels.setChkFindDangerMajorNum(formatNum(data[i][13])); cssels.setChkRectDangerTotalNum(formatNum(data[i][14])); cssels.setChkRectDangerGeneralNum(formatNum(data[i][15])); cssels.setChkRectDangerMajorNum(formatNum(data[i][16])); cssels.setSceneEmergencyDisposal(formatNum(data[i][17])); cssels.setPenaltyRecord(formatNum(data[i][18])); cssels.setPenaltyImposeFine(data[i][19]); cssels.setPenaltyShutProd(formatNum(data[i][20])); cssels.setPenaltySuspendLicense(formatNum(data[i][21])); cssels.setIssueEnforceLawWrit(formatNum(data[i][22])); cssels.setInformExposeFreq(formatNum(data[i][23])); cssels.setHandOverCaseGeneral(formatNum(data[i][24])); cssels.setHandOverCaseMajor(formatNum(data[i][25])); safeSpvsEnforceLawStatList.add(cssels); } // 批量导入 this.chkSafeSpvsEnforceLawStatService.insertBatchFile(safeSpvsEnforceLawStatList); } } catch (Exception e) { logger.error(e.getMessage()); return buildFailResponse(); } return buildSuccessResponse(resultList); } private String formatProjType(String projType, List projList) { try { if (StringUtils.isBlank(projType)) { return null; } String formatStr = projList.stream().filter(f -> projType.equals(f.getProjType())).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; } } }