| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402 |
- 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.ChkSafeProdLedger;
- import cn.com.goldenwater.dcproj.model.ChkSafeSelsProj;
- import cn.com.goldenwater.dcproj.param.ChkSafeSelsProjParam;
- import cn.com.goldenwater.dcproj.service.AttAdBaseService;
- import cn.com.goldenwater.dcproj.service.ChkSafeProdLedgerService;
- import cn.com.goldenwater.dcproj.service.ChkSafeSelsProjService;
- 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.text.ParseException;
- import java.time.LocalDateTime;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * @author zyd
- * @date 2022-6-2
- */
- @Api(value = "成都市水务局安全生产监督检查台账", tags = "成都市水务局安全生产监督检查台账")
- @RestController
- @RequestMapping("/chk/safe/prod/ledger")
- public class ChkSafeProdLedgerController extends BaseController {
- private Logger logger = LoggerFactory.getLogger(getClass());
- @Autowired
- private ChkSafeProdLedgerService chkSafeProdLedgerService;
- @Autowired
- private OlBisInspOrgService olBisInspOrgService;
- @Autowired
- private AttAdBaseService attAdBaseService;
- /**
- * 项目类型
- */
- @Autowired
- private ChkSafeSelsProjService chkSafeSelsProjService;
- @Value("${export.templatePath}")
- private String templatePath;
- private String[] parsePatterns = {
- "yyyy-M", "yyyy-M-d", "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM-dd HH", "yyyy-MM", "yyyy",
- "yyyy/M", "yyyy/M/d", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy-MM-dd HH", "yyyy/MM", "HH:mm:ss",
- "yyyy.M", "yyyy.M.d", "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy-MM-dd HH", "yyyy.MM", "HH:mm",
- "yyyy年MM月dd日", "yyyy年MM月dd日HH时mm分ss秒", "yyyy年MM月dd日HH时mm分", "yyyy年MM月dd日HH时", "yyyy年MM月", "HH时mm分",
- "yyyy年M月d日", "yyyy年M月d日H时m分s秒", "yyyy年M月d日H时m分", "yyyy年M月d日H时", "yyyy年M月", "H时m分"};
- /**
- * 上传模板名称
- * 安全生产监督检查台账
- */
- private String templateName = "chkSafeProdLedger.xls";
- @ApiOperation(value = "添加安全生产监督检查台账-基础表")
- @RequestMapping(value = "/", method = RequestMethod.POST)
- public BaseResponse<ChkSafeProdLedger> insert(@ApiParam(name = "chkSafeProdLedger", value = "chkSafeProdLedger", required = true) @RequestBody ChkSafeProdLedger chkSafeProdLedger) {
- if (StringUtils.isBlank(chkSafeProdLedger.getId())) {
- chkSafeProdLedger.setOrgId(getCurrentOrgId());
- chkSafeProdLedger.setPersId(getCurrentPersId());
- chkSafeProdLedger.setAdCode(olBisInspOrgService.getRlProvince(getCurrentOrgId()));
- //填报状态 1新增 2上报
- chkSafeProdLedger.setFillRepoStat("1");
- int ret = chkSafeProdLedgerService.insert(chkSafeProdLedger);
- } else {
- int ret = chkSafeProdLedgerService.update(chkSafeProdLedger);
- }
- return buildSuccessResponse(chkSafeProdLedger);
- }
- @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 = chkSafeProdLedgerService.delete(id);
- return buildSuccessResponse();
- }
- @ApiOperation(value = "更新安全生产监督检查台账-基础表信息")
- @RequestMapping(value = "/update", method = RequestMethod.POST)
- public BaseResponse<ChkSafeProdLedger> update(@ApiParam(name = "chkSafeProdLedger", value = "chkSafeProdLedger", required = true) @RequestBody ChkSafeProdLedger chkSafeProdLedger) {
- Assert.notNull(chkSafeProdLedger.getId(), "主键id为必填参数");
- int ret = chkSafeProdLedgerService.update(chkSafeProdLedger);
- return buildSuccessResponse(chkSafeProdLedger);
- }
- @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 = chkSafeProdLedgerService.batchReportByIds(ids);
- return buildSuccessResponse(ret);
- }
- @ApiOperation(value = "根据ID获取安全生产监督检查台账-基础表(单表)")
- @RequestMapping(value = "/{id}", method = RequestMethod.GET)
- public BaseResponse<ChkSafeProdLedger> get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
- ChkSafeProdLedger attRdwpgdBase = chkSafeProdLedgerService.get(id);
- return buildSuccessResponse(attRdwpgdBase);
- }
- @ApiOperation(value = "获取列表数据")
- @RequestMapping(value = "/page", method = RequestMethod.POST)
- public BaseResponse<PageInfo> findPcPage(@RequestBody ChkSafeProdLedger chkSafeProdLedger) {
- if (StringUtils.isBlank(chkSafeProdLedger.getAdCode())) {
- chkSafeProdLedger.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-上报
- chkSafeProdLedger.setFillRepoStat("2");
- }
- PageInfo<ChkSafeProdLedger> pageInfo = chkSafeProdLedgerService.findPageInfo(chkSafeProdLedger);
- return buildSuccessResponse(pageInfo);
- }
- @ApiOperation(value = "市级获取区/县列表数据")
- @RequestMapping(value = "/page/sub", method = RequestMethod.POST)
- public BaseResponse<PageInfo> findSubPcPage(@RequestBody ChkSafeProdLedger chkSafeProdLedger) {
- if (StringUtils.isBlank(chkSafeProdLedger.getAdCode())) {
- chkSafeProdLedger.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getRlProvince(getCurrentOrgId())));
- }
- // 市级的 只查询 上报的 1-新增; 2-上报
- chkSafeProdLedger.setFillRepoStat("2");
- PageInfo<ChkSafeProdLedger> pageInfo = chkSafeProdLedgerService.findPageInfo(chkSafeProdLedger);
- return buildSuccessResponse(pageInfo);
- }
- @ApiOperation(value = "获取市级汇总列表数据")
- @RequestMapping(value = "/page/summary", method = RequestMethod.POST)
- public BaseResponse<PageInfo> findPcCityPage(@RequestBody ChkSafeProdLedger chkSafeProdLedger) {
- chkSafeProdLedger.setOrgId(getCurrentOrgId());
- PageInfo<Map<String, Object>> pageInfo = chkSafeProdLedgerService.findSummaryPage(chkSafeProdLedger);
- return buildSuccessResponse(pageInfo);
- }
- @ApiOperation(value = "获取当前账户是否是县")
- @RequestMapping(value = "/getIsCounty", method = RequestMethod.GET)
- public BaseResponse<Boolean> getIsCounty() {
- AttAdBase attAdBase = attAdBaseService.getByAdcode(olBisInspOrgService.getRlProvince(getCurrentOrgId()));
- // 2 省 3 市 4 县 5 乡镇 6 村
- if ("4".equals(attAdBase.getAdGrad())) {
- return buildSuccessResponse(true);
- }
- return buildSuccessResponse(false);
- }
- @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();
- // 台账导入 默认当前用户的行政区域代码
- String adCode = olBisInspOrgService.getRlProvince(getCurrentOrgId());
- List<String> resultList = new ArrayList<>();
- // 获取excle表格内容 忽略第1行
- String[][] data = ReadExcelUtil.getDataAll(file, 1, 0);
- try {
- if (data != null && data.length > 0) {
- // 填报单位
- String submitDept = data[0][4];
- if (StringUtils.isBlank(submitDept)) {
- logger.error("填报单位为空");
- resultList.add("第" + (2) + "行填报单位不能为空");
- return buildSuccessResponse(resultList);
- }
- submitDept = submitDept.trim();
- // 报送月份 填报日期 不需要了
- Calendar newTime = Calendar.getInstance();
- // 项目类型
- List<ChkSafeSelsProj> projList = this.chkSafeSelsProjService.queryLedgerSelectOptions(null);
- List<ChkSafeProdLedger> prodLedgerList = new ArrayList<>(data.length);
- for (int i = 2; i < data.length; i++) {
- newTime.add(Calendar.SECOND, 10);
- ChkSafeProdLedger chkSafeProdLedger = new ChkSafeProdLedger(curOrgId, adCode, submitDept, newTime.getTime(), curPersId);
- if (org.apache.commons.lang3.StringUtils.isBlank(data[i][0])) {
- // 此行首列的 单元格为空 就认为 此行结束
- resultList.add("第" + (i + 2) + "行结束");
- break;
- }
- // 检查日期 必填
- chkSafeProdLedger.setChkDttm(parseDate(data[i][1], null));
- // 检查单位 必填
- chkSafeProdLedger.setLeadDep(data[i][2]);
- // 检查单位负责人 必填
- chkSafeProdLedger.setLeadDepRespPers(data[i][3]);
- // 项目类型 必填
- chkSafeProdLedger.setChkProjType(formatProjType(data[i][4], projList));
- // 被检查单位(项目)必填
- chkSafeProdLedger.setChkOrg(data[i][5]);
- // 被检查单位负责人 非必填
- chkSafeProdLedger.setChkOrgRespPers(data[i][6]);
- // 被检查单位负责人电话 非必填
- chkSafeProdLedger.setChkOrgRespPersMobi(data[i][7]);
- // 检查结果 必填
- chkSafeProdLedger.setChkResult(formatChkResult(data[i][8]));
- // 隐患问题 检查结果--未发现隐患 无需填报 非必填
- chkSafeProdLedger.setChkDgerPblm(data[i][9]);
- // 处理意见 检查结果--未发现隐患 无需填报 非必填
- chkSafeProdLedger.setChkHandSugg(data[i][10]);
- // 整改时限 检查结果--未发现隐患 无需填报 非必填
- chkSafeProdLedger.setChkHandEdtm(parseDate(data[i][11], null));
- // 整改落实情况 检查结果--未发现隐患 无需填报 非必填
- chkSafeProdLedger.setChkRectImplInfo(formatChkRectImplInfo(data[i][12]));
- // 整改落实情况说明 检查结果--未发现隐患 无需填报 非必填
- chkSafeProdLedger.setChkRectImplInfoDesc(data[i][13]);
- // 整改验收时间 检查结果--未发现隐患 无需填报 非必填
- chkSafeProdLedger.setChkAcceTm(parseDate(data[i][14], null));
- // 整改验收人 检查结果--未发现隐患 无需填报 非必填
- chkSafeProdLedger.setChkAccePers(data[i][15]);
- // 报送单位
- chkSafeProdLedger.setChkFillUnit(data[i][16]);
- prodLedgerList.add(chkSafeProdLedger);
- }
- // 批量导入
- this.chkSafeProdLedgerService.insertBatchFile(prodLedgerList);
- }
- } catch (Exception e) {
- logger.error(e.getMessage());
- return buildFailResponse();
- }
- return buildSuccessResponse(resultList);
- }
- private String formatProjType(String projType, List<ChkSafeSelsProj> 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 String formatChkRectImplInfo(String chkRectImplInfo) {
- switch (chkRectImplInfo) {
- case "未整改":
- chkRectImplInfo = "0";
- break;
- case "正在整改":
- chkRectImplInfo = "1";
- break;
- case "完成整改":
- chkRectImplInfo = "2";
- break;
- default:
- break;
- }
- return chkRectImplInfo;
- }
- private String formatChkResult(String chkResult) {
- switch (chkResult) {
- case "无隐患":
- chkResult = "0";
- break;
- case "有隐患":
- chkResult = "1";
- break;
- default:
- break;
- }
- return chkResult;
- }
- /**
- * 导出成都市水务局安全生产监督检查台账
- */
- @ApiOperation(value = "根据条件导出成都市水务局安全生产监督检查台账")
- @RequestMapping(value = "/export", method = RequestMethod.POST)
- public void export(@ApiParam(name = "chkSafeProdLedger", value = "chkSafeProdLedger")
- @RequestBody(required = false) ChkSafeProdLedger chkSafeProdLedger,
- HttpServletResponse response) {
- if (StringUtils.isBlank(chkSafeProdLedger.getAdCode())) {
- chkSafeProdLedger.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-上报
- chkSafeProdLedger.setFillRepoStat("2");
- }
- chkSafeProdLedgerService.export(chkSafeProdLedger, response);
- }
- /**
- * 导出成都市水务局安全生产监督检查台账
- * 市级账号 导出 区县数据
- */
- @ApiOperation(value = "根据条件导出成都市水务局安全生产监督检查台账")
- @RequestMapping(value = "/export/sub", method = RequestMethod.POST)
- public void exportSub(@ApiParam(name = "chkSafeProdLedger", value = "chkSafeProdLedger")
- @RequestBody(required = false) ChkSafeProdLedger chkSafeProdLedger,
- HttpServletResponse response) {
- if (StringUtils.isBlank(chkSafeProdLedger.getAdCode())) {
- chkSafeProdLedger.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getRlProvince(getCurrentOrgId())));
- }
- chkSafeProdLedger.setFillRepoStat("2");
- chkSafeProdLedgerService.export(chkSafeProdLedger, response);
- }
- /**
- * 导出成都市水务局安全生产监督检查台账
- */
- @ApiOperation(value = "根据条件导出成都市水务局安全生产监督检查台账")
- @RequestMapping(value = "/export/summary", method = RequestMethod.POST)
- public void exportSummary(@ApiParam(name = "chkSafeProdLedger", value = "chkSafeProdLedger")
- @RequestBody(required = false) ChkSafeProdLedger chkSafeProdLedger,
- HttpServletResponse response) {
- String curOrgId = getCurrentOrgId();
- chkSafeProdLedger.setOrgId(curOrgId);
- chkSafeProdLedgerService.exportSummary(chkSafeProdLedger, response);
- }
- /**
- * 日期型字符串转化为日期 格式
- */
- private Date parseDate(Object str, String... curParsePatterns) {
- if (str == null || StringUtils.isBlank(str.toString())) {
- return null;
- }
- try {
- if (null == curParsePatterns) {
- return org.apache.commons.lang3.time.DateUtils.parseDate(str.toString(), parsePatterns);
- } else {
- return org.apache.commons.lang3.time.DateUtils.parseDate(str.toString(), curParsePatterns);
- }
- } catch (ParseException e) {
- return null;
- }
- }
- private LocalDateTime convertDateToLocalDateTime(Date date) {
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(date);
- LocalDateTime localDateTime = LocalDateTime.of(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
- return localDateTime;
- }
- /**
- * 查询 安全生产监督检查台账的 项目类型
- */
- @ApiOperation(value = "下来框列表")
- @RequestMapping(value = "/proj/type/selectOptions", method = RequestMethod.POST)
- public BaseResponse<List<ChkSafeSelsProj>> querySelectOptions(@ApiParam(name = "chkSafeSelsProjParam", value = "chkSafeSelsProjParam", required = false)
- @RequestBody(required = false) ChkSafeSelsProjParam chkSafeSelsProjParam) {
- return buildSuccessResponse(chkSafeSelsProjService.queryLedgerSelectOptions(chkSafeSelsProjParam));
- }
- }
|