package cn.com.goldenwater.dcproj.utils; import cn.com.goldenwater.dcproj.constValue.JinChaEnum; import cn.com.goldenwater.dcproj.constValue.TacEnum; import cn.com.goldenwater.dcproj.dao.BisInspPreListDao; import cn.com.goldenwater.dcproj.dto.CateTotal; import cn.com.goldenwater.dcproj.dto.PblmRetCount; import cn.com.goldenwater.dcproj.model.*; import cn.com.goldenwater.id.util.UuidUtil; import com.github.pagehelper.PageInfo; import org.apache.commons.lang3.StringUtils; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; public class InspUtils { public static String convertThirdLengthStr(String value) { if (value == null) { return value; } switch (value.length()) { case 1: value = "00" + value; break; case 2: value = "0" + value; break; default: } return value; } public static void addPreList(BisInspBaseView bisInspBaseView, BisInspPreListDao bisInspPreListDao) { List inspPreLists = bisInspBaseView.getInspPreLists(); StringBuffer buffer = new StringBuffer(); if (inspPreLists == null) { return; } for (BisInspPreList inspPreList : inspPreLists) { String viewPreId = UuidUtil.uuid(); inspPreList.setViewPreId(viewPreId); inspPreList.setViewId(bisInspBaseView.getViewId()); buffer.append(inspPreList.getViewPreName() + ","); bisInspPreListDao.insert(inspPreList); } if (StringUtils.isNotBlank(buffer.toString())) { String viewPreNames = buffer.substring(0, buffer.length() - 1); bisInspBaseView.setViewPreNames(viewPreNames); } if (bisInspBaseView.getInspPreLists() != null) { bisInspBaseView.setViewPres(bisInspBaseView.getInspPreLists().size()); } } public static String getTypeState(String type, TacPawpRgstr tacPawpRgstr) { if (JinChaEnum.TACPAWPPDBST.getKey().equals(type)) { return tacPawpRgstr.getPdbstStat(); } if (JinChaEnum.TacPawpBstocmTsopbfp.getKey().equals(type)) { return tacPawpRgstr.getBstocmTsopbfpStat(); } if (JinChaEnum.TacPawpRaiobis.getKey().equals(type)) { return tacPawpRgstr.getRaiobisStat(); } if (JinChaEnum.TacPawpBstocmCms.getKey().equals(type)) { return tacPawpRgstr.getBstocmCmsStat(); } if (JinChaEnum.TacPawpBitopqPeqaa.getKey().equals(type)) { return tacPawpRgstr.getBitopqPeqaaStat(); } if (JinChaEnum.TacPawpBioesRwunit.getKey().equals(type)) { return tacPawpRgstr.getBioesRwunitStat(); } return "0"; } public static String getBySn(String sn) { if (StringUtils.isBlank(sn)) { return ""; } String[] arrays = sn.split("\\."); if (arrays.length == 3) { if (arrays[1].length() == 1) { arrays[1] = "0" + arrays[1]; } if (arrays[2].length() == 1) { arrays[2] = "0" + arrays[2]; } return arrays[0] + arrays[1] + arrays[2]; } if (arrays.length == 2) { if (arrays[1].length() == 1) { arrays[1] = "0" + arrays[1] + "00"; } return arrays[0] + arrays[1]; } return ""; } public static String getPblmType(String pblmChType) { if ("5".equals(pblmChType) || "6".equals(pblmChType)) { return "5"; } if ("7".equals(pblmChType)) { return "6"; } return pblmChType; } public static PblmRetCount setPblmCount(List cateTotals) { PblmRetCount pblmRetCount = new PblmRetCount(); pblmRetCount.setRsName("总计"); int total = 0; for (CateTotal cateTotal : cateTotals) { total += cateTotal.getTotal(); if ("一般".equals(cateTotal.getCate())) { pblmRetCount.setCate0(cateTotal.getTotal()); } if ("较重".equals(cateTotal.getCate())) { pblmRetCount.setCate1(cateTotal.getTotal()); } if ("严重".equals(cateTotal.getCate())) { pblmRetCount.setCate2(cateTotal.getTotal()); } if ("特别严重".equals(cateTotal.getCate())) { pblmRetCount.setCate3(cateTotal.getTotal()); } } pblmRetCount.setSub(total); return pblmRetCount; } public static String setOrgIds(String orgIds) { if (StringUtils.isNotBlank(orgIds)) { if (!orgIds.contains("'")) { orgIds = orgIds.replace(",", "','"); orgIds = "'" + orgIds + "'"; } } return orgIds; } public static String setPlbmName(String problemType) { if ("0".equals(problemType)) { return "违规行为"; } if ("1".equals(problemType)) { return "质量缺陷"; } if ("2".equals(problemType)) { return "合同问题"; } if ("3".equals(problemType)) { return "工程缺陷"; } return null; } public static String setProblemType(String inspName) { if ("违规行为".equals(inspName)) { return "0"; } if ("质量缺陷".equals(inspName)) { return "1"; } if ("合同问题".equals(inspName)) { return "2"; } if ("工程缺陷".equals(inspName)) { return "3"; } return null; } private static Map sort1 = new HashMap<>(); private static Map sort2 = new HashMap<>(); static { sort1.put("0", "质量管理违法行为"); sort1.put("1", "安全生产违法行为"); sort1.put("2", "质量缺陷"); sort1.put("3", "合同问题"); sort1.put("4", "运行管理违规行为"); } static { sort2.put("0", "质量体系"); sort2.put("1", "过程控制"); sort2.put("2", "施工准备"); sort2.put("3", "设计变更"); sort2.put("4", "原材料及中间产品"); sort2.put("5", "过程控制"); sort2.put("6", "事故处理"); } /** * 获取类型1 */ public static String getSort1(String key) { return sort1.get(key); } /** * 获取类型2 */ public static String getSort2(String key) { return sort2.get(key); } public static void initTempDocFile(File directory) { if (directory.isDirectory()) { /**只保留3小时内的临时文件*/ long nowTime = System.currentTimeMillis() - 3 * 3600 * 1000L; File[] fileList = directory.listFiles(pathname -> { long lastModifyTime = pathname.lastModified(); return lastModifyTime < nowTime; }); if (fileList != null && fileList.length != 0) { for (File file1 : fileList) { try { file1.delete(); } catch (Exception e) { } } } } } public static void addLocs(PageInfo inspPblmList) { for (BisInspPblm bisInspPblm : inspPblmList.getList()) { if (StringUtils.isNotBlank(bisInspPblm.getAdFullName())) { String[] adFullNames = bisInspPblm.getAdFullName().split("-"); bisInspPblm.setProvince(adFullNames[0]); if (adFullNames.length > 1) { bisInspPblm.setCity(adFullNames[1]); } if (adFullNames.length > 2) { bisInspPblm.setCountry(adFullNames[2]); } } } } public static void addLocsNew(PageInfo inspPblmList) { for (KeyRegPblm bisInspPblm : inspPblmList.getList()) { if (StringUtils.isNotBlank(bisInspPblm.getAdFullName())) { String[] adFullNames = bisInspPblm.getAdFullName().split("-"); bisInspPblm.setProvince(adFullNames[0]); if (adFullNames.length > 1) { bisInspPblm.setCity(adFullNames[1]); } if (adFullNames.length > 2) { bisInspPblm.setCountry(adFullNames[2]); } } } } public static boolean isImage(File file) throws IOException { BufferedImage bi = ImageIO.read(file); if (bi == null) { return false; } return true; } public static String getSpfsnlType(String pblmChType) { if (TacEnum.QIANQI.getKey().equals(pblmChType)) { return TacEnum.QIANQI.getValue(); } if (TacEnum.JIANSHE.getKey().equals(pblmChType)) { return TacEnum.JIANSHE.getValue(); } if (TacEnum.JIHUA.getKey().equals(pblmChType)) { return TacEnum.JIHUA.getValue(); } if (TacEnum.CAIWU.getKey().equals(pblmChType)) { return TacEnum.CAIWU.getValue(); } if (TacEnum.ZILIANGSHITI.getKey().equals(pblmChType)) { return TacEnum.ZILIANGSHITI.getValue(); } if (TacEnum.ZILIANGGUANLI.getKey().equals(pblmChType)) { return TacEnum.ZILIANGGUANLI.getValue(); } return TacEnum.ANQUAN.getValue(); } }