| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- 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 com.workflow.common.util.convert.Assert;
- 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.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RequestBody;
- 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;
- import java.io.IOException;
- import java.nio.file.Paths;
- import java.text.SimpleDateFormat;
- 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<ChkSafeStatList> 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<Integer> 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<ChkSafeStatList> 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<PageInfo> 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<List<String>> 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<String> resultList = new ArrayList<>();
- // 获取excle表格内容 忽略第1行
- String[][] data = ReadExcelUtil.getDataAll(file, 1, 0);
- try {
- if (data != null && data.length > 0){
- Date curDate = new Date();
- List<ChkSafeStatListIndustry> industryList = chkSafeStatListIndustryService.findList(new ChkSafeStatListIndustryParam());
- List<ChkSafeStatList> 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<ChkSafeStatListIndustry> 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;
- }
- }
- }
|