package cn.com.goldenwater.dcproj.service.impl.tac; import cn.com.goldenwater.core.service.AbstractCrudService; import cn.com.goldenwater.dcproj.dao.*; import cn.com.goldenwater.dcproj.model.*; import cn.com.goldenwater.dcproj.param.TacPblmRectOrgParam; import cn.com.goldenwater.dcproj.param.TacPblmRectParam; import cn.com.goldenwater.dcproj.param.TacPblmRectPblmParam; import cn.com.goldenwater.dcproj.param.TacPblmRectPrctParam; import cn.com.goldenwater.dcproj.service.TacPblmRectOrgService; import cn.com.goldenwater.dcproj.service.TacPblmRectPblmService; import cn.com.goldenwater.dcproj.service.TacPblmRectPrctService; import cn.com.goldenwater.dcproj.service.TacPblmRectService; import cn.com.goldenwater.id.util.UuidUtil; import org.apache.commons.lang3.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 java.util.Date; import java.util.List; /** * @author lhc * @date 2019-12-20 */ @Service @Transactional public class TacPblmRectServiceImpl extends AbstractCrudService implements TacPblmRectService { @Autowired private TacPblmRectDao tacPblmRectDao; @Autowired private BisInspOrgDao bisInspOrgDao; @Autowired private TacPblmRectOrgService tacPblmRectOrgService; @Autowired private TacPblmRectPrctService tacPblmRectPrctService; @Autowired private TacPblmRectPblmService tacPblmRectPblmService; @Autowired private BisInspAllRlationPersDao bisInspAllRlationPersDao; @Autowired private TacPawpRgstrDao tacPawpRgstrDao; @Autowired private TacPblmInfoDao tacPblmInfoDao; @Autowired private BisInspAllRlationPersDao rlationPersDao; @Autowired private TacPblmRectOrgDao tacPblmRectOrgDao; @Value("${adLength}") private String adLength; public TacPblmRectServiceImpl(TacPblmRectDao tacPblmRectDao) { super(tacPblmRectDao); this.tacPblmRectDao = tacPblmRectDao; } @Override public Boolean isExist(TacPblmRect tacPblmRect) { TacPblmRectParam tacPblmRectParam = new TacPblmRectParam(); tacPblmRectParam.setYear(tacPblmRect.getYear()); tacPblmRectParam.setBatch(tacPblmRect.getBatch()); tacPblmRectParam.setDataStat("0"); List tacPblmRects = tacPblmRectDao.findList(tacPblmRectParam); if (tacPblmRects.size() > 0) { return true; } else { return false; } } @Override public int insert(TacPblmRect tacPblmRect) { String uuid = UuidUtil.uuid(); // 生成uuid tacPblmRect.setId(uuid); tacPblmRect.setIntm(new Date()); tacPblmRect.setUptm(new Date()); tacPblmRect.setDataStat("0"); String state = "7"; //根据年度 批次 插入每个省的通知信息 List bisInspOrgs = bisInspOrgDao.getOrgByTac(tacPblmRect.getYear(), tacPblmRect.getBatch(), state,adLength); //设置人员姓名 BisInspAllRlationPers bisInspAllRlationPers = bisInspAllRlationPersDao.get(tacPblmRect.getPersId()); tacPblmRect.setPersName(bisInspAllRlationPers.getPersName()); Long rectPrjctSize = 0L; Long rectPblmSize = 0L; for (BisInspOrg bisInspOrg : bisInspOrgs ) { //插入整改单位 TacPblmRectOrg tacPblmRectOrg = new TacPblmRectOrg(); tacPblmRectOrg.setId(UuidUtil.uuid()); tacPblmRectOrg.setRectId(uuid); tacPblmRectOrg.setYear(tacPblmRect.getYear()); tacPblmRectOrg.setBatch(tacPblmRect.getBatch()); tacPblmRectOrg.setRectOrgId(bisInspOrg.getOrgId()); tacPblmRectOrg.setRectOrgNm(bisInspOrg.getOrgNm()); tacPblmRectOrg.setPersId(tacPblmRect.getPersId()); tacPblmRectOrg.setPersName(tacPblmRect.getPersName()); tacPblmRectOrg.setState("0"); //插入通知信息到省通知 tacPblmRectOrg.setTitle(tacPblmRect.getTitle()); tacPblmRectOrg.setNub(tacPblmRect.getNub()); tacPblmRectOrg.setPrintTm(tacPblmRect.getPrintTm()); tacPblmRectOrg.setCloseTm(tacPblmRect.getCloseTm()); String orgId = bisInspOrg.getOrgId(); String orgNm = bisInspOrg.getOrgNm(); //插入工程总数 Long prjctSize = insertProject(tacPblmRectOrg.getPersId(), tacPblmRectOrg.getPersName(), uuid, tacPblmRectOrg.getId(), tacPblmRect.getYear(), tacPblmRect.getBatch(), orgId, orgNm, state); rectPrjctSize = rectPrjctSize + prjctSize; tacPblmRectOrg.setPrjctSize(prjctSize); //插入问题总数 Long pblmSize = insertPblm(tacPblmRectOrg.getPersId(), tacPblmRectOrg.getPersName(), uuid, tacPblmRectOrg.getId(), tacPblmRect.getYear(), tacPblmRect.getBatch(), orgId, orgNm, state); rectPblmSize = pblmSize + rectPblmSize; tacPblmRectOrg.setPblmSize(pblmSize); tacPblmRectOrgService.insert(tacPblmRectOrg); //插入工程 //插入问题 } tacPblmRect.setPrjctSize(rectPrjctSize); tacPblmRect.setPblmSize(rectPblmSize); return this.tacPblmRectDao.insert(tacPblmRect); } /** * 根据年度批次找出所有的工程 返回工程总数 * * @param rectId 通知ID * @param orgId 通知单位ID * @param year 年 * @param batch 批次 * @param state 状态 * @return */ private Long insertProject(String persId, String perName, String rectId, String rectOrgId, Long year, Long batch, String orgId, String orgNm, String state) { //按年度和批次 提取状态为7的工程 String adCode = orgId.substring(3); List tacPawpRgstrs = tacPawpRgstrDao.getRgstrListByBatch(year, batch, adCode, state); for (TacPawpRgstr tacPawpRgstr : tacPawpRgstrs ) { TacPblmRectPrct tacPblmRectPrct = new TacPblmRectPrct(); tacPblmRectPrct.setName(tacPawpRgstr.getName()); tacPblmRectPrct.setRgstrId(tacPawpRgstr.getId()); tacPblmRectPrct.setRectOrgId(rectOrgId); tacPblmRectPrct.setPersId(persId); tacPblmRectPrct.setPersName(perName); tacPblmRectPrct.setYear(year); tacPblmRectPrct.setBatch(batch); tacPblmRectPrct.setOrgId(orgId); tacPblmRectPrct.setOrgNm(orgNm); tacPblmRectPrct.setRectId(rectId); tacPblmRectPrctService.insert(tacPblmRectPrct); } return Long.parseLong(String.valueOf(tacPawpRgstrs.size())); } private Long insertPblm(String persId, String perName, String rectId, String rectOrgId, Long year, Long batch, String orgId, String orgNm, String state) { //按年度和批次 提取状态为7的问题 String adCode = orgId.substring(3); List tacPblmInfos = tacPblmInfoDao.findListByYearBatch(state, year, batch, adCode); for (TacPblmInfo tacPblmInfo : tacPblmInfos ) { TacPblmRectPblm tacPblmRectPblm = new TacPblmRectPblm(); tacPblmRectPblm.setRectId(rectId); tacPblmRectPblm.setRectOrgId(rectOrgId); tacPblmRectPblm.setObjId(tacPblmInfo.getObjId()); tacPblmRectPblm.setRgstrId(tacPblmInfo.getRgstrId()); tacPblmRectPblm.setName(tacPblmInfo.getName()); tacPblmRectPblm.setPblmId(tacPblmInfo.getId()); tacPblmRectPblm.setPblmNm(tacPblmInfo.getPblmNm()); tacPblmRectPblm.setPblmPasi(tacPblmInfo.getPblmPasi()); tacPblmRectPblm.setIfCasePblm(tacPblmRectPblm.getIfCasePblm()); tacPblmRectPblm.setPblmDesc(tacPblmInfo.getPblmDesc()); tacPblmRectPblm.setPblmReason(tacPblmInfo.getPblmReason()); tacPblmRectPblm.setPblmstdId(tacPblmInfo.getPblmstdId()); tacPblmRectPblm.setRectState("1"); tacPblmRectPblm.setPersId(persId); tacPblmRectPblm.setPersName(perName); tacPblmRectPblm.setYear(year); tacPblmRectPblm.setBatch(batch); tacPblmRectPblm.setOrgId(orgId); tacPblmRectPblm.setOrgNm(orgNm); tacPblmRectPblm.setListType(tacPblmInfo.getListType()); tacPblmRectPblmService.insert(tacPblmRectPblm); } return Long.parseLong(String.valueOf(tacPblmInfos.size())); } @Override public int update(TacPblmRect tacPblmRect) { tacPblmRect.setUptm(new Date()); //更新冗余的省级相关信息 if (StringUtils.isNotBlank(tacPblmRect.getTitle()) || StringUtils.isNotBlank(tacPblmRect.getNub()) || tacPblmRect.getCloseTm() != null || tacPblmRect.getCloseTm() != null) { TacPblmRectOrg tacPblmRectOrg = new TacPblmRectOrg(); tacPblmRectOrg.setRectId(tacPblmRect.getId()); tacPblmRectOrg.setNub(tacPblmRect.getNub()); tacPblmRectOrg.setTitle(tacPblmRect.getTitle()); tacPblmRectOrg.setCloseTm(tacPblmRect.getCloseTm()); tacPblmRectOrg.setPrintTm(tacPblmRect.getPrintTm()); tacPblmRectOrgDao.updateBy(tacPblmRectOrg); } return this.tacPblmRectDao.update(tacPblmRect); } @Override public int delete(String id) { //删除问题 TacPblmRectPblmParam tacPblmRectPblmParam = new TacPblmRectPblmParam(); tacPblmRectPblmParam.setRectId(id); tacPblmRectPblmService.deleteBy(tacPblmRectPblmParam); //删除工程信息 TacPblmRectPrctParam tacPblmRectPrctParam = new TacPblmRectPrctParam(); tacPblmRectPrctParam.setRectId(id); tacPblmRectPrctService.deleteBy(tacPblmRectPrctParam); //删除通知单位 TacPblmRectOrgParam tacPblmRectOrgParam = new TacPblmRectOrgParam(); tacPblmRectOrgParam.setRectId(id); tacPblmRectOrgService.deleteBy(tacPblmRectOrgParam); return this.tacPblmRectDao.delete(id); } @Override public List getYear(String persId) { /* if (StringUtils.isNotBlank(persId)) { if ("1".equals(rlationPersDao.get(persId).getPersType())) { persId = ""; } }*/ persId = ""; return tacPblmRectDao.getYear(persId); } @Override public List getBatchByYearPersId(String persId, String year) { /* if (StringUtils.isNotBlank(persId)) { if ("1".equals(rlationPersDao.get(persId).getPersType())) { persId = ""; } }*/ persId = ""; return tacPblmRectDao.getBatchByYearPersId(persId, year); } }