package cn.com.goldenwater.dcproj.service.impl.importex; import cn.com.goldenwater.core.service.AbstractCrudService; import cn.com.goldenwater.dcproj.constValue.SplitValue; import cn.com.goldenwater.dcproj.controller.rsvr.AttRsBaseController; import cn.com.goldenwater.dcproj.dao.AttRsBaseCrrctDao; import cn.com.goldenwater.dcproj.dao.BisInspRsvrRgstrDao; import cn.com.goldenwater.dcproj.dao.ImpExcelDao; import cn.com.goldenwater.dcproj.dto.BisInspRsvrRgstrPcDto; import cn.com.goldenwater.dcproj.model.*; import cn.com.goldenwater.dcproj.param.*; import cn.com.goldenwater.dcproj.service.*; import cn.com.goldenwater.dcproj.service.impl.rsvr.BisInspRsvrRgstrServiceImpl; import cn.com.goldenwater.dcproj.socket.WebSocketServer; import cn.com.goldenwater.dcproj.utils.export.TableEnum; import cn.com.goldenwater.dcproj.utils.export.template.CreateSkExcelTemplate; import cn.com.goldenwater.dcproj.utils.impexcel.ImportExcel; import cn.com.goldenwater.id.util.UuidUtil; import com.github.pagehelper.PageInfo; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import static cn.com.goldenwater.dcproj.controller.rsvr.AttRsBaseController.isNumeric; import static cn.com.goldenwater.dcproj.utils.export.FieldFormatDispatch.getFormatValue; import static cn.com.goldenwater.dcproj.utils.impexcel.ExportExcel.downloadExcelFile; import static cn.com.goldenwater.dcproj.utils.impexcel.ImpUtil.checkIsDate; import static cn.com.goldenwater.dcproj.utils.impexcel.ImportExcel.convertMapToBean; /** *

* 导入业务 *

* * @author liyz * @date 2019/4/9 19:22 **/ @Service @Transactional(rollbackFor = Exception.class) public class ImpExcelServiceImpl extends AbstractCrudService implements ImpExcelService { private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS"); private static ConcurrentHashMap> concurrentHashMap = new ConcurrentHashMap<>(); @Autowired private ImpExcelDao impExcelDao; @Autowired private CreateSkExcelTemplate createSkExcelTemplate; @Autowired private BisInspBaseExtService bisInspBaseExtService; @Autowired private BisInspBasePresExtService bisInspBasePresExtService; @Autowired private BisInspRsvrRgstrService bisInspRsvrRgstrService; @Autowired private BisInspSafeExtManageService bisInspSafeExtManageService; @Autowired private BisInspBaseViewService bisInspBaseViewService; @Autowired private BisInspPreListService bisInspPreListService; @Autowired private BisInspRsvrRgstrDao bisInspRsvrRgstrDao; @Autowired private BisInspRsvrProjectService bisInspRsvrProjectService; @Autowired private BisInspRsvrBenefitsService bisInspRsvrBenefitsService; @Autowired private AttRsBaseCrrctDao attRsBaseCrrctDao; @Value("${impExcel.basePath}") private String path; @Autowired private GwComFileService gwComFileService; private static final String FILE_EXTS = "xls"; public ImpExcelServiceImpl(ImpExcelDao impExcelDao) { super(impExcelDao); this.impExcelDao = impExcelDao; } @Override public boolean parseAndInsert(String tid, String filePath, String sid, String userId) { // 确定是哪一张表的Excel TableEnum tableEnum = TableEnum.getTypeByValue(tid); if (tableEnum != null) { switch (tableEnum) { case T8: List listSkTable = parseSkTables(filePath, sid); return this.insertSkTables(listSkTable, sid, userId); default: break; } } return false; } @Override public int downloadSkExcelTemplate(HttpServletResponse response, TypeExportParam tep) { //不需要的逻辑 ByteArrayOutputStream os = new ByteArrayOutputStream(); int i = createSkExcelTemplate.createBisInspRsvrRgstrPcDtoExcel(tep, os); if (i != 0) { String fileName = TableEnum.getNameByValue(tep.getTableIds()) + ".xls"; downloadExcelFile(response, os, fileName); } return i; } @Override public String uploadExcel(String userId, String sid, MultipartFile file, String tid) { // 上传文件 String id = tid + "-" + UUID.randomUUID().toString(); if (file != null) { String fileName = file.getOriginalFilename(); // 获取扩展名称 String ext = fileName.substring(1 + fileName.lastIndexOf(".")); if (!ext.endsWith(FILE_EXTS)) { WebSocketServer.sendInfo(sdf.format(new Date()) + "-文件类型不对", sid); return ""; } } //按时间日期存文件 Calendar dat = Calendar.getInstance(); String filePath = this.path + File.separator + dat.get(Calendar.YEAR) + File.separator + (dat.get(Calendar.MONTH) + 1) + File.separator + dat.get(Calendar.DAY_OF_MONTH); boolean boo = gwComFileService.writeFile(id, FILE_EXTS, file, filePath); WebSocketServer.sendInfo(sdf.format(new Date()) + "-①开始上传", sid); if (boo) { WebSocketServer.sendInfo(sdf.format(new Date()) + "-上传成功√", sid); return filePath + File.separator + id + "." + FILE_EXTS; } else { WebSocketServer.sendInfo(sdf.format(new Date()) + "-上传失败×", sid); return ""; } } @Override public List parseExcel(String userId, String sid, String filePath, String tid, String pid) { TableEnum tableEnum = TableEnum.getTypeByValue(tid); if (tableEnum != null) { switch (tableEnum) { case T8: // 得到解析出来的原始数据 List listSkTable = parseSkTables(filePath, sid); // 得到过滤后的数据 listSkTable = this.filterNotTreeIdData(listSkTable, pid, userId); // websocket 发送信息到前台 WebSocketServer.sendInfo(sdf.format(new Date()) + "-读取完成,自动过滤无督查表id的行数据,过滤后共" + listSkTable.size() + "行√", sid); // listResult的作用是把字典数据转为汉字后展示到前台 List listResult = new ArrayList<>(); for (LinkedHashMap lhm : listSkTable) { LinkedHashMap map = new LinkedHashMap<>(); for (Object o : lhm.keySet()) { String key = o.toString(); String value = lhm.get(key).toString(); // 转化为汉字,并检查是否有错误,有的话加上错误标识 Object formatValue = getFormatValue("sk", key, value, false); map.put(key, formatValue.toString()); } listResult.add(map); } // websocket 发送信息到前台 WebSocketServer.sendInfo(sdf.format(new Date()) + "-完成数据校验√", sid); // 如果有数据,就放入缓存中 if (listSkTable.size() > 0) { concurrentHashMap.put(sid, listSkTable); } // 返回前端的数据 return listResult; default: return null; } } return null; } public List showErrData(List listResult){ // 给前端返回数据,如果没有数据 if(listResult.size() == 0){ return new ArrayList(){{ add(new LinkedHashMap(){{ put("Message","empty"); }}); }} ; }else{// 如果有数据 // 得到错误的数据 listResult = this.getErrData(listResult); if(listResult.size() == 0){ return new ArrayList(){{ add(new LinkedHashMap(){{ put("Message","success"); }}); }} ; }else { return listResult; } } } public List getErrData(List listResult){ List list = new ArrayList<>(); for(LinkedHashMap map : listResult){ Iterator it = map.keySet().iterator(); while (it.hasNext()){ String key = it.next().toString(); String value = map.get(key).toString(); if(value.contains("$E$")){ list.add(map); } } } return list; } @Override public Boolean insertExcel(String userId, String sid, String tid) { TableEnum tableEnum = TableEnum.getTypeByValue(tid); if (tableEnum != null) { switch (tableEnum) { case T8: // 从缓存里取出数据 List listSkTable = concurrentHashMap.get(sid); boolean aBoolean = false; if (listSkTable != null) { // 执行入库操作 aBoolean = insertSkTables(listSkTable, sid, userId); // 执行完成,删除缓存里的数据 concurrentHashMap.remove(sid); } return aBoolean; default: return false; } } return false; } /** * 从水库Excel里把数据解析出来 */ public List parseSkTables(String filePath, String sid) { List listSkTable = null; int startRow = 4; int endRow = 0; try { // 获取到从Excel里提取到的数据,并已格式化 listSkTable = (List) ImportExcel.importExcel(filePath, startRow, endRow, LinkedHashMap.class, sid, "sk"); } catch (IOException e) { e.printStackTrace(); } return listSkTable; } /** * 过滤掉findList不是此用户下的此节点的数据 * * @see BisInspRsvrRgstrServiceImpl#findPcPage(TypeParam) */ private List filterNotTreeIdData(List listSkTable, String pid, String userId) { TypeExportParam tep = new TypeExportParam(); tep.setType("rsvr"); tep.setPresId(userId); // 水库 tep.setpType("1"); tep.setTableIds("08"); // 0未督查 1督查中 2已督查 tep.setState("1,0"); tep.setId(pid); List list = bisInspRsvrRgstrDao.findPcPage(tep); List rgstrIds = list.stream().map(BisInspRsvrRgstrPcDto::getRgstrId).collect(Collectors.toList()); if (listSkTable == null) { return new ArrayList<>(); } else { listSkTable = listSkTable.stream().filter(x -> x.get("rgstrId") != null && !"".equals(x.get("rgstrId")) && rgstrIds.toString().contains(x.get("rgstrId").toString())).collect(Collectors.toList()); } return listSkTable; } /** * 真正的添加数据入库 */ private boolean insertSkTables(List listSkTable, String sid, String userId) { // websocket 向前台发送信息,开始进行批量填报 WebSocketServer.sendInfo(sdf.format(new Date()) + "-③开始批量填报", sid); int i = 0; for (LinkedHashMap lhp : listSkTable) { i++; try { String rgstrId = lhp.get("rgstrId").toString(); if (rgstrId == null || StringUtils.isBlank(rgstrId) || rgstrId.length() != 32) { WebSocketServer.sendInfo(sdf.format(new Date()) + "-数据校验失败:表格第" + i + 5 + "行的<督查填报代码>列填写有误,请从导出模板里编辑填项后上传填报!", sid); return false; } // 1.修改基础信息表和基础信息纠错表 insertOrUpdateBaseCrrct(lhp, userId); // 2.重点环节落实情况 insertOrUpdateBaseExt(lhp, userId); // 3.责任人落实情况 insertOrUpdateBasePresExt(lhp, userId); // 4.水库工程实体和运行管理情况 insertOrUpdateSafeExtManage(lhp, userId); // 5 走访情况 insertOrUpdatePreList(lhp, userId); // 6.水库工程实体(新表) insertOrUpdateRsvrProject(lhp, userId); // 7.效益发挥情况 insertOrUpdateRsvrBenefits(lhp, userId); WebSocketServer.sendInfo(sdf.format(new Date()) + "-第" + i + "条:" + lhp.get("rsName") + "填报完成√", sid); } catch (Exception e) { e.printStackTrace(); } } WebSocketServer.sendInfo(sdf.format(new Date()) + "-批量填报完成,共" + i + "条。√", sid); return true; } /** * 添加或修改重点落实环节 * * 说明:填报的字段 * emerPlanSameAppr: "2" * emerPlanSameEme: "1" * emerPlanSameExta: "1" * emerPlanSameSpeed: "2" * rainForc: "1" * recPersId: "89E69B31FE1344A98316A0153BA7386C" * rgstrId: "0bdb496bc27c4fd48bb17708a2dd895d" * schPlanSameAppr: "1" * schPlanSameExta: "1" * schPlanSameSpeed: "1" * */ public void insertOrUpdateBaseExt(LinkedHashMap lhp, String userId) { try { String rgstrId = lhp.get("rgstrId").toString(); // 先判断一下是否已经填报 BisInspBaseExtParam bisInspBaseExtParam = new BisInspBaseExtParam(); bisInspBaseExtParam.setRgstrId(rgstrId); List inspBaseExtList = bisInspBaseExtService.findList(bisInspBaseExtParam); BisInspBaseExt inspBaseExt = null; if(inspBaseExtList.size() > 0){ inspBaseExt = inspBaseExtList.get(0); } BisInspBaseExt bisInspBaseExt = new BisInspBaseExt(); // 从导入的Excel里的字段赋值 bisInspBaseExt = (BisInspBaseExt) convertMapToBean(bisInspBaseExt.getClass(), lhp); // 添加时必填项 用户id bisInspBaseExt.setRecPersId(userId); // 添加时必填项 督查登记表id bisInspBaseExt.setRgstrId(rgstrId); // 如果没有填报 if (inspBaseExt == null || StringUtils.isBlank(inspBaseExt.getThrqId())) { // 入库 this.insertBaseExt(bisInspBaseExt); } else { // 修改 Date date = new Date(); bisInspBaseExt.setUpdateTime(date); bisInspBaseExt.setUpdateTime(date); // 这个是重点情况表的id,必填项 bisInspBaseExt.setThrqId(inspBaseExt.getThrqId()); int i = bisInspBaseExtService.update(bisInspBaseExt); } if(!"0".equals(bisInspBaseExt.getRainForc()) && !"0".equals(bisInspBaseExt.getRainForcNote()) && !"0".equals(bisInspBaseExt.getSchPlanSameExta()) && !"0".equals(bisInspBaseExt.getEmerPlanSameExta())){ bisInspRsvrRgstrService.updateRsvr(bisInspBaseExt.getRgstrId(), "2", "ext"); }else { // 未完成 bisInspRsvrRgstrService.updateRsvr(bisInspBaseExt.getRgstrId(), "1", "ext"); } } catch (Exception e) { e.printStackTrace(); } } private void insertBaseExt(BisInspBaseExt bisInspBaseExt) { Date date = new Date(); String uuid = UuidUtil.uuid(); bisInspBaseExt.setThrqId(uuid); bisInspBaseExt.setStatus("1"); bisInspBaseExt.setCreateTime(date); bisInspBaseExt.setUpdateTime(date); int ret = bisInspBaseExtService.insert(bisInspBaseExt); BisInspRsvrRgstr inspRsvrRgstr = new BisInspRsvrRgstr(); inspRsvrRgstr.setRgstrId(bisInspBaseExt.getRgstrId()); inspRsvrRgstr.setBaseStat("1"); inspRsvrRgstr.setState("1"); bisInspRsvrRgstrService.update(inspRsvrRgstr); } /** * 添加或修改责任人落实情况 * */ public void insertOrUpdateBasePresExt(LinkedHashMap lhp, String userId) { try { String rgstrId = lhp.get("rgstrId").toString(); // 先判断一下是否已经填报 BisInspBasePresExtParam bisInspBasePresExtParam = new BisInspBasePresExtParam(); bisInspBasePresExtParam.setRgstrId(rgstrId); BisInspBasePresExt inspBasePresExt = bisInspBasePresExtService.getBy(bisInspBasePresExtParam); BisInspBasePresExt bisInspBasePresExt = new BisInspBasePresExt(); // 从Excel里获取的数据设置 bisInspBasePresExt = (BisInspBasePresExt) convertMapToBean(bisInspBasePresExt.getClass(), lhp); // 必填项数据设置 bisInspBasePresExt.setRecPersId(userId); bisInspBasePresExt.setRgstrId(rgstrId); if (inspBasePresExt == null || StringUtils.isBlank(inspBasePresExt.getDutyId())) { this.insertBasePresExt(bisInspBasePresExt); } else { // 修改 bisInspBasePresExt.setUpdateTime(new Date()); bisInspBasePresExt.setDutyId(inspBasePresExt.getDutyId()); int ret = bisInspBasePresExtService.update(bisInspBasePresExt); } if(!"0".equals(bisInspBasePresExt.getHasWiunWaoLegPers()) && !"0".equals(bisInspBasePresExt.getHasPatrolPers()) && !"0".equals(bisInspBasePresExt.getHasTechPers()) ){ bisInspRsvrRgstrService.updateRsvr(bisInspBasePresExt.getRgstrId(), "2", "pres"); }else { // 未完成 bisInspRsvrRgstrService.updateRsvr(bisInspBasePresExt.getRgstrId(), "1", "pres"); } } catch (Exception e) { e.printStackTrace(); } } /** * * 添加的字段 * hasAttendTrain: "1" * hasPatrolPers: "1" * hasTechPers: "1" * hasWiunWaoLegPers: "1" * patrolPersDuty: "1" * patrolPersResu: "1" * recPersId: "89E69B31FE1344A98316A0153BA7386C" 用户id 必填项 * rgstrId: "138122c2a35c4e90bfddf7a57481d5b3" 督查表id 必填项 * techPersResu: "1" * wiunWaoLegPersResu: "1" * * 修改的字段 * createTime: 1555468322000 * dangReportObj: null * dtyprsnId: "0" * dutyId: "5cc1a3ad0d1747ffad9f990907c7a496" * fundSour: null * fundSourCount: 0 * hasAttendTrain: "1" * hasAttendTrainNote: null * hasExtPatrol: "0" * hasFlLowLimLev: null * hasKnowEmerPlanSame: null * hasPatrolPers: "1" * hasRepDangReal: null * hasReport: null * hasTechPers: "1" * hasWiunWaoLegPers: "1" * isPatrolMsgComp: null * manaOrg: null * noManHasPres: "0" * orgProp: null * otherReasonNote: null * patrolFundSour: null * patrolPers: null * patrolPersDuty: "2" * patrolPersId: null * patrolPersNote: null * patrolPersResu: "3" * patrolPersResuNote: null * patrolPersTel: null * patrolReward: 0 * protalRate: 0 * recPers2: "许伟" * recPersId: "89E69B31FE1344A98316A0153BA7386C" * recPersTel: null * rgstrId: "cab2ec01a2864169bc95e789b38d630c" * specialManage: "0" * status: "0" * techPers: null * techPersDuty: null * techPersId: null * techPersResu: "1" * techPersResuNote: null * techPersTel: null * techPresNote: null * updateTime: 1555468366000 * wiunWaoLegPers: null * wiunWaoLegPersDuty: null * wiunWaoLegPersId: null * wiunWaoLegPersResu: "1" * wiunWaoLegPersTel: null */ public void insertBasePresExt(BisInspBasePresExt bisInspBasePresExt) throws InstantiationException, IllegalAccessException { String uuid = UuidUtil.uuid(); bisInspBasePresExt.setDutyId(uuid); bisInspBasePresExt.setStatus("0"); bisInspBasePresExt.setCreateTime(new Date()); bisInspBasePresExt.setUpdateTime(new Date()); int ret = bisInspBasePresExtService.insert(bisInspBasePresExt); BisInspRsvrRgstr inspRsvrRgstr = new BisInspRsvrRgstr(); inspRsvrRgstr.setRgstrId(bisInspBasePresExt.getRgstrId()); inspRsvrRgstr.setPresStat("1"); inspRsvrRgstr.setState("1"); bisInspRsvrRgstrService.update(inspRsvrRgstr); } /** * 添加或修改水库工程实体和运行管理情况 * */ public void insertOrUpdateSafeExtManage(LinkedHashMap lhp, String userId) { try { String rgstrId = lhp.get("rgstrId").toString(); // 先判断一下是否已经填报 BisInspSafeExtManageParam bisInspSafeExtManageParam = new BisInspSafeExtManageParam(); bisInspSafeExtManageParam.setRgstrId(rgstrId); BisInspSafeExtManage inspSafeExtManage = bisInspSafeExtManageService.getBy(bisInspSafeExtManageParam); BisInspSafeExtManage bisInspSafeExtManage = new BisInspSafeExtManage(); bisInspSafeExtManage = (BisInspSafeExtManage) convertMapToBean(bisInspSafeExtManage.getClass(), lhp); // 必填项数据设置 bisInspSafeExtManage.setRecPersId(userId); bisInspSafeExtManage.setRgstrId(rgstrId); if (inspSafeExtManage == null || StringUtils.isBlank(inspSafeExtManage.getMngrnId())) { this.insertSafeExtManage(bisInspSafeExtManage); } else { bisInspSafeExtManage.setUpdateTime(new Date()); bisInspSafeExtManage.setMngrnId(inspSafeExtManage.getMngrnId()); int ret = bisInspSafeExtManageService.update(bisInspSafeExtManage); } if(!"0".equals(bisInspSafeExtManage.getHasSpeManage()) && !"0".equals(bisInspSafeExtManage.getHasWdEmnic()) && !"0".equals(bisInspSafeExtManage.getIfDamWarnLogo()) && !"0".equals(bisInspSafeExtManage.getSafeComment())){ bisInspRsvrRgstrService.updateRsvr(bisInspSafeExtManage.getRgstrId(), "2", "safe"); }else { // 未完成 bisInspRsvrRgstrService.updateRsvr(bisInspSafeExtManage.getRgstrId(), "1", "safe"); } if (StringUtils.isNotBlank(bisInspSafeExtManage.getSafeComment())) { bisInspRsvrRgstrService.updateRsvr(bisInspSafeExtManage.getRgstrId(), "2", "dam"); } } catch (Exception e) { e.printStackTrace(); } } public void insertSafeExtManage(BisInspSafeExtManage bisInspSafeExtManage) { String uuid = UuidUtil.uuid(); bisInspSafeExtManage.setMngrnId(uuid); bisInspSafeExtManage.setStatus("0"); bisInspSafeExtManage.setCreateTime(new Date()); bisInspSafeExtManage.setUpdateTime(new Date()); int ret = bisInspSafeExtManageService.insert(bisInspSafeExtManage); BisInspRsvrRgstr inspRsvrRgstr = new BisInspRsvrRgstr(); inspRsvrRgstr.setRgstrId(bisInspSafeExtManage.getRgstrId()); inspRsvrRgstr.setResRunStat("1"); inspRsvrRgstr.setState("1"); bisInspRsvrRgstrService.update(inspRsvrRgstr); } /** * 添加或修改走访情况 * */ public void insertOrUpdatePreList(LinkedHashMap lhp, String userId) { try { String rgstrId = lhp.get("rgstrId").toString(); // 先获取viewId 判断是否先添加,其实在前端已经判断过了,直接会走update BisInspBaseViewParam bisInspBaseViewParam = new BisInspBaseViewParam(); bisInspBaseViewParam.setRgstrId(rgstrId); BisInspBaseView inspBaseView = bisInspBaseViewService.getBy(bisInspBaseViewParam); BisInspBaseView bisInspBaseView = new BisInspBaseView(); bisInspBaseView.setRecPersId(userId); bisInspBaseView.setRgstrId(rgstrId); if (inspBaseView == null || StringUtils.isBlank(inspBaseView.getViewId())) { this.insertPreList(bisInspBaseView); } else { // 所有的添加其实都是修改 String viewId = inspBaseView.getViewId(); this.updatePreList(bisInspBaseView, viewId, lhp); } } catch (Exception e) { e.printStackTrace(); } } public void insertPreList(BisInspBaseView bisInspBaseView) { try { // 添加 String uuid = UuidUtil.uuid(); bisInspBaseView.setViewId(uuid); bisInspBaseView.setCreateTime(new Date()); bisInspBaseView.setStatus("0"); bisInspBaseView.setUpdateTime(new Date()); bisInspBaseViewService.insertBaseView(bisInspBaseView); } catch (Exception e) { e.printStackTrace(); } } public void updatePreList(BisInspBaseView bisInspBaseView, String viewId, LinkedHashMap lhp) throws InstantiationException, IllegalAccessException { bisInspBaseView.setUpdateTime(new Date()); // 必填项 bisInspBaseView.setViewId(viewId); BisInspPreList bisInspPreList = new BisInspPreList(); // 获取Excel里填报的人员信息 bisInspPreList = (BisInspPreList) convertMapToBean(bisInspPreList.getClass(), lhp); // 获取原来的人员列表 List inspPreLists = this.getInspPreLists(viewId); if (inspPreLists == null) { inspPreLists = new ArrayList<>(); } // 把新增的人员加进去 String preNameNew = bisInspPreList.getViewPreName(); // 名字为空字符串,不添加 if(StringUtils.isNotBlank(preNameNew)){ if(inspPreLists.size() == 0){ // 如果原来没有人员,直接添加 inspPreLists.add(bisInspPreList); }else { int count = 0; for(BisInspPreList pre : inspPreLists){ if(preNameNew.equals(pre.getViewPreName())){ // 如果有相同的名字,count + 1 count ++ ; } } if(count == 0){ inspPreLists.add(bisInspPreList); } } } bisInspBaseView.setInspPreLists(inspPreLists); int ret = bisInspBaseViewService.updateBaseView(bisInspBaseView); BisInspRsvrRgstr inspRsvrRgstr = new BisInspRsvrRgstr(); if (org.apache.commons.lang3.StringUtils.isBlank(bisInspBaseView.getRgstrId())) { bisInspBaseView = bisInspBaseViewService.get(bisInspBaseView.getViewId()); } inspRsvrRgstr.setRgstrId(bisInspBaseView.getRgstrId()); inspRsvrRgstr.setViewStat("1"); inspRsvrRgstr.setState("1"); bisInspRsvrRgstrService.update(inspRsvrRgstr); } /** * 获取人员列表 * */ private List getInspPreLists(String viewId) { List inspPreLists; BisInspPreListParam inspPreListParam = new BisInspPreListParam(); inspPreListParam.setViewId(viewId); // 按照原来前端的逻辑来写 inspPreListParam.setPageSize(50); PageInfo bisInspPreList = bisInspPreListService.findPageInfo(inspPreListParam); inspPreLists = bisInspPreList.getList(); return inspPreLists; } /** * 添加或修改工程实体 * */ public void insertOrUpdateRsvrProject(LinkedHashMap lhp, String userId){ try{ String rgstrId = lhp.get("rgstrId").toString(); // 先判断一下是否已经填报 BisInspRsvrProjectParam bisInspRsvrProjectParam = new BisInspRsvrProjectParam(); bisInspRsvrProjectParam.setRgstrId(rgstrId); BisInspRsvrProject inspRsvrProject = bisInspRsvrProjectService.getBy(bisInspRsvrProjectParam); BisInspRsvrProject bisInspRsvrProject = new BisInspRsvrProject(); bisInspRsvrProject = (BisInspRsvrProject) convertMapToBean(bisInspRsvrProject.getClass(), lhp); // 必填项数据设置 bisInspRsvrProject.setRecPersId(userId); bisInspRsvrProject.setRgstrId(rgstrId); if(inspRsvrProject != null && org.apache.commons.lang3.StringUtils.isNotBlank(inspRsvrProject.getId())){ bisInspRsvrProject.setId(inspRsvrProject.getId()); bisInspRsvrProjectService.update(bisInspRsvrProject); }else{ String uuid = UuidUtil.uuid(); bisInspRsvrProject.setId(uuid); bisInspRsvrProjectService.insert(bisInspRsvrProject); } if(!"0".equals(bisInspRsvrProject.getPoorCountry()) && !"0".equals(bisInspRsvrProject.getWaterRunInfo()) && !"0".equals(bisInspRsvrProject.getFsltdzInfo()) && !"0".equals(bisInspRsvrProject.getDiskRunInfo()) && !"0".equals(bisInspRsvrProject.getHasSetMainFl()) && !"0".equals(bisInspRsvrProject.getHasSetPourFl()) && !"0".equals(bisInspRsvrProject.getHasExtDamSafeAppr()) && !"0".equals(bisInspRsvrProject.getIfReinForce()) ){ bisInspRsvrRgstrService.updateRsvr(bisInspRsvrProject.getRgstrId(), "2", "project"); }else { // 未完成 bisInspRsvrRgstrService.updateRsvr(bisInspRsvrProject.getRgstrId(), "1", "project"); } if (StringUtils.isNotBlank(bisInspRsvrProject.getIfDamSafe()) && StringUtils.isNotBlank(bisInspRsvrProject.getIfReinForce())) { bisInspRsvrRgstrService.updateRsvr(bisInspRsvrProject.getRgstrId(), "2", "rein"); }else { // 未完成 bisInspRsvrRgstrService.updateRsvr(bisInspRsvrProject.getRgstrId(), "1", "rein"); } }catch (Exception e){ e.printStackTrace(); } } /** * 添加或修改效益发挥情况 * */ public void insertOrUpdateRsvrBenefits(LinkedHashMap lhp, String userId){ try{ String rgstrId = lhp.get("rgstrId").toString(); // 先判断一下是否已经填报 BisInspRsvrBenefitsParam bisInspRsvrBenefitsParam = new BisInspRsvrBenefitsParam(); bisInspRsvrBenefitsParam.setRgstrId(rgstrId); BisInspRsvrBenefits inspRsvrBenefits = bisInspRsvrBenefitsService.getBy(bisInspRsvrBenefitsParam); BisInspRsvrBenefits bisInspRsvrBenefits = new BisInspRsvrBenefits(); bisInspRsvrBenefits = (BisInspRsvrBenefits) convertMapToBean(bisInspRsvrBenefits.getClass(), lhp); // diskRunInfo 和 hasSetMainFl 字段 与工程实体里的重复,单独处理 String diskRunInfo = "diskRunInfo2"; String hasSetMainFl = "hasSetMainFl2"; if(lhp.get(diskRunInfo) != null){ bisInspRsvrBenefits.setDiskRunInfo(lhp.get(diskRunInfo).toString()); }else { bisInspRsvrBenefits.setDiskRunInfo(""); } if(lhp.get(hasSetMainFl) != null){ bisInspRsvrBenefits.setHasSetMainFl(lhp.get(hasSetMainFl).toString()); }else { bisInspRsvrBenefits.setHasSetMainFl(""); } // 必填项数据设置 bisInspRsvrBenefits.setRecPersId(userId); bisInspRsvrBenefits.setRgstrId(rgstrId); if(inspRsvrBenefits != null && org.apache.commons.lang3.StringUtils.isNotBlank(inspRsvrBenefits.getId())){ bisInspRsvrBenefits.setId(inspRsvrBenefits.getId()); bisInspRsvrBenefitsService.update(bisInspRsvrBenefits); }else{ String uuid = UuidUtil.uuid(); bisInspRsvrBenefits.setId(uuid); bisInspRsvrBenefits.setCreateTime(new Date()); bisInspRsvrBenefitsService.insert(bisInspRsvrBenefits); } if(!"0".equals(bisInspRsvrBenefits.getIfEffective()) && !"0".equals(bisInspRsvrBenefits.getIfWaterS()) && !"0".equals(bisInspRsvrBenefits.getDiskRunInfo()) ){ bisInspRsvrRgstrService.updateRsvr(bisInspRsvrBenefits.getRgstrId(), "2", "fits"); }else { // 未完成 bisInspRsvrRgstrService.updateRsvr(bisInspRsvrBenefits.getRgstrId(), "1", "fits"); } }catch (Exception e){ e.printStackTrace(); } } /** * 添加或修改水库基础信息(主要是修改) * * @see AttRsBaseController#update(AttRsBaseCrrct) */ public void insertOrUpdateBaseCrrct(LinkedHashMap lhp, String userId){ try { String rgstrId = lhp.get("rgstrId").toString(); // 1.修改纠错表 AttRsBaseCrrct attRsBase = new AttRsBaseCrrct(); // 这里把Excel里的字段转成实体类字段 attRsBase = (AttRsBaseCrrct) convertMapToBean(attRsBase.getClass(), lhp); // userId放在下面,不然会被上一步冲掉 attRsBase.setPersId(userId); // 设置建成时间 if(org.apache.commons.lang3.StringUtils.isNotBlank(attRsBase.getCompDateStr())) { try { // 不是时间格式会报错,判断一下,不是时间格式就不赋给它了 if(checkIsDate(attRsBase.getCompDateStr())){ attRsBase.setCompDate(new SimpleDateFormat(SplitValue.TIME_SPLIT).parse(attRsBase.getCompDateStr())); } } catch (ParseException e) { e.printStackTrace(); } } // 设置经纬度 attRsBase.setCenterX(attRsBase.getCenterXGd()); attRsBase.setCenterY(attRsBase.getCenterYGd()); AttRsBaseCrrct baseCrrct=attRsBaseCrrctDao.get(attRsBase.getRsCode(),attRsBase.getPersId()); // 需要新增吗?只是修改就够了吧。 不不,需要新增,否则原来为空的进不去。 if(baseCrrct==null){ attRsBaseCrrctDao.insert(attRsBase); }else { attRsBaseCrrctDao.update(attRsBase); } // 2.修改登记表 BisInspRsvrRgstrParam bisInspRsvrRgstrParam=new BisInspRsvrRgstrParam(); // 不能用objId 和 rsCode 因为objId我这里获取不到,所以我直接用rgstrId获取 bisInspRsvrRgstrParam.setRgstrId(rgstrId); // 防止有冗余数据,用rgstrId查出来的数据不是唯一的,其实是数据的问题,这里只是保证不出错 List bisInspRsvrRgstrList=bisInspRsvrRgstrService.findList(bisInspRsvrRgstrParam); BisInspRsvrRgstr bisInspRsvrRgstr = null; if(bisInspRsvrRgstrList.size() > 0){ bisInspRsvrRgstr = bisInspRsvrRgstrList.get(0); } if(bisInspRsvrRgstr!=null){ bisInspRsvrRgstr.setDamType(attRsBase.getDamType()); bisInspRsvrRgstr.setDamRegCode(attRsBase.getRegCode()); bisInspRsvrRgstr.setEngScal(attRsBase.getEngScal()); bisInspRsvrRgstr.setAdCode(attRsBase.getAdmDiv()); bisInspRsvrRgstr.setObjId(attRsBase.getObjId()); //详细地址 bisInspRsvrRgstr.setHystSite(attRsBase.getRsLoc()); if(org.apache.commons.lang3.StringUtils.isNotBlank(attRsBase.getLocation()) && !isNumeric(attRsBase.getLocation())){ bisInspRsvrRgstr.setLocation(attRsBase.getLocation()); } bisInspRsvrRgstr.setRsvrAdmName(attRsBase.getRsAdmName()); if(attRsBase.getDamSizeHig()==null){ bisInspRsvrRgstr.setDamMaxHigh(null); }else { bisInspRsvrRgstr.setDamMaxHigh(Double.toString(attRsBase.getDamSizeHig())); } bisInspRsvrRgstr.setRsCode(attRsBase.getRsCode()); bisInspRsvrRgstr.setTotCap(attRsBase.getTotCap()); if(attRsBase.getCenterYGd()!=null && !"".equals(attRsBase.getCenterYGd())){ bisInspRsvrRgstr.setRsvrLat(Double.parseDouble(attRsBase.getCenterYGd())); } if(attRsBase.getCenterXGd()!=null && !"".equals(attRsBase.getCenterXGd())){ bisInspRsvrRgstr.setRsvrLong(Double.parseDouble(attRsBase.getCenterXGd())); } bisInspRsvrRgstr.setResCreateTime(attRsBase.getCompDate()); bisInspRsvrRgstr.setCompDateStr(attRsBase.getCompDateStr()); Date date=new Date(); bisInspRsvrRgstr.setUptm(date); bisInspRsvrRgstr.setHasDamRegCode("1"); bisInspRsvrRgstr.setRsvrNm(attRsBase.getRsName()); bisInspRsvrRgstrService.update(bisInspRsvrRgstr); } } catch (Exception e) { e.printStackTrace(); } } }