package cn.com.goldenwater.dcproj.service.impl.ducha; import cn.com.goldenwater.core.service.AbstractCrudService; import cn.com.goldenwater.dcproj.dao.*; import cn.com.goldenwater.dcproj.dto.AllNodeDto; import cn.com.goldenwater.dcproj.dto.BisInspGroupDto; import cn.com.goldenwater.dcproj.dto.ObjIdDto; import cn.com.goldenwater.dcproj.model.*; import cn.com.goldenwater.dcproj.param.BisInspPlanParam; import cn.com.goldenwater.dcproj.service.BisInspPlanService; import cn.com.goldenwater.dcproj.service.OlBisInspOrgService; import org.apache.commons.collections.map.HashedMap; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.util.*; /** * @author lune * @date 2019-2-18 */ @Service @Transactional(rollbackFor = Exception.class) public class BisInspPlanServiceImpl extends AbstractCrudService implements BisInspPlanService { @Autowired private BisInspPlanDao bisInspPlanDao; @Autowired private BisInspAllDao bisInspAllDao; @Autowired private BisInspGroupDao bisInspGroupDao; @Autowired private AttPersBaseDao attPersBaseDao; @Autowired private BisInspObjDao bisInspObjDao; @Autowired private SupervisionPlanDao supervisionPlanDao; @Autowired private OlBisInspOrgDao bisInspOrgDao; @Autowired private OlBisInspOrgService olBisInspOrgService; public BisInspPlanServiceImpl(BisInspPlanDao bisInspPlanDao) { super(bisInspPlanDao); this.bisInspPlanDao = bisInspPlanDao; } @Override public OrganizationAndBatchAndGroup addBisInspPlan(BisInspPlan bisInspPlan) { if (null == bisInspPlan) { return null; } BisInspAll bisInspAll = new BisInspAll(); //根据父id查询最大的子id BisInspAll max = bisInspAllDao.getMaxOne(bisInspPlan.getGuid(), bisInspPlan.getOrgId()); if (null != max) { Long upOne = NumberUtils.toLong(max.getId()); String newId = String.format("%0" + max.getId().length() + "d", (upOne + 1)); bisInspAll.setId(newId); } else { bisInspAll.setId(bisInspPlan.getGuid() + "001"); } if (bisInspPlan.getPalnSttm() != null) { String year = new SimpleDateFormat("yyyy").format(bisInspPlan.getPalnSttm()); String mnth = new SimpleDateFormat("MM").format(bisInspPlan.getPalnSttm()); bisInspAll.setInspYear(year); bisInspAll.setInspMnth(mnth); } else { String year = new SimpleDateFormat("yyyy").format(LocalDateTime.now()); String mnth = new SimpleDateFormat("MM").format(LocalDateTime.now()); bisInspAll.setInspYear(year); bisInspAll.setInspMnth(mnth); } bisInspAll.setEntm(bisInspPlan.getPalnEntm()); bisInspAll.setSttm(bisInspPlan.getPalnSttm()); bisInspAll.setProvince(bisInspPlan.getProvince()); bisInspAll.setOrgName(bisInspPlan.getOrgName()); bisInspAll.setPid(bisInspPlan.getGuid()); bisInspAll.setPnm(bisInspPlan.getPrsnTitle()); bisInspAll.setChkType(bisInspPlan.getChkType()); bisInspAll.setChkForm(bisInspPlan.getChkForm()); bisInspAll.setYearTaskId(bisInspPlan.getYearTaskId()); bisInspAll.setLeadDep(bisInspPlan.getLeadDep()); bisInspAll.setIsPlan(bisInspPlan.getIsPlan()); bisInspAll.setOrgId(bisInspPlan.getOrgId()); bisInspAll.setQuantity(bisInspPlan.getQuantity()); bisInspAll.setPlanDpId(bisInspPlan.getPlanDpId()); bisInspAll.setNote(bisInspPlan.getNote()); bisInspAllDao.insert(bisInspAll); OrganizationAndBatchAndGroup result = new OrganizationAndBatchAndGroup(); result.setName(bisInspPlan.getPrsnTitle()); result.setCode(bisInspAll.getId()); result.setType("3"); return result; } @Override public List findListByPersId(String persId) { return bisInspPlanDao.findListByPersId(persId); } @Override public Map getDetail(String inspGroupId, String plnaId) { HashMap result = new HashMap<>(); BisInspPlan bisInspPlan = bisInspPlanDao.get(plnaId); result.put("plan", bisInspPlan == null ? new BisInspPlan() : bisInspPlan); BisInspGroup bisInspGroup = bisInspGroupDao.get(inspGroupId); result.put("group", bisInspGroup == null ? new BisInspGroup() : bisInspGroup); List listByInspGroupId = attPersBaseDao.getListByInspGroupId(inspGroupId); result.put("persList", listByInspGroupId == null ? new ArrayList<>() : listByInspGroupId); List listByGroupIdAndPlanId = bisInspObjDao.findListByGroupIdAndPlanId(inspGroupId, plnaId); result.put("objList", listByGroupIdAndPlanId == null ? new ArrayList<>() : listByGroupIdAndPlanId); return result; } @Override public Map deletePlan(String id, String orgId) { String province = olBisInspOrgService.getProvince(orgId); List bisInspAllRlationList = this.bisInspPlanDao.getAllRlation(id, province);//人员和组 List bisInspAllObjList = this.bisInspPlanDao.getAllObj(id, province);//对象和组 List bisInspSelAreaList = this.bisInspPlanDao.getAllArea(id, orgId, province); Map map = new HashedMap(); if (bisInspAllRlationList.size() > 0) { map.put("code", 1001); map.put("message", "请先删除人员或对象"); } else if (bisInspAllObjList.size() > 0) { map.put("code", 1001); map.put("message", "请先删除人员或对象"); } else if (bisInspSelAreaList.size() > 0) { map.put("code", 1001); map.put("message", "请先删除人员或对象"); } else { bisInspAllDao.delete(id); map.put("code", 1002); map.put("message", "删除成功"); } return map; } @Override public List addInspPlanBatch(BisInspPlan bisInspPlan) { List list = new ArrayList<>(); if (bisInspPlan != null) { String objType = bisInspPlan.getObjType(); String orgId = bisInspPlan.getOrgId(); String orgName = bisInspPlan.getOrgName(); if (StringUtils.isEmpty(orgName)) { OlBisInspOrg bisInspOrg = bisInspOrgDao.get(orgId); orgName = bisInspOrg.getOrgNm(); } String persId = bisInspPlan.getPersId(); String name = bisInspPlan.getPrsnTitle(); Date sttm = bisInspPlan.getPalnSttm(); Date entm = bisInspPlan.getPalnEntm(); String province = olBisInspOrgService.getProvince(bisInspPlan.getOrgId()); if (StringUtils.isNotEmpty(objType) && StringUtils.isNotEmpty(orgId)) { int type = Integer.parseInt(objType); String typeOrg = "00" + type + orgId; BisInspAll bisInspAll = bisInspAllDao.get(typeOrg); if (bisInspAll == null) { BisInspAll batch = new BisInspAll(); batch.setId(typeOrg); batch.setPnm(orgName); batch.setPid("00" + type); batch.setSttm(sttm); batch.setEntm(entm); batch.setProvince(province); bisInspAllDao.insert(batch); } String newGroupId = ""; ObjIdDto objIdDto = supervisionPlanDao.getMaxGroupId(typeOrg, orgId, province); if (objIdDto.getId() != null) {//如果该批次下有组,则组id加1 String rtId = objIdDto.getId().substring(objIdDto.getId().length() - 1, objIdDto.getId().length()); int i = Integer.parseInt(rtId) + 1; newGroupId = String.valueOf(i); if ("10".equals(newGroupId)) { String sid = objIdDto.getId().substring(objIdDto.getId().length() - 2, objIdDto.getId().length() - 1); int j = Integer.parseInt(sid) + 1; String ss = String.valueOf(j); newGroupId = objIdDto.getId().substring(0, objIdDto.getId().length() - 2) + ss + "0"; } else { newGroupId = objIdDto.getId().substring(0, objIdDto.getId().length() - 1) + newGroupId; } } else {//如果该批次下没有组,则组id后三位为001 newGroupId = typeOrg + "001"; } BisInspAll batch = new BisInspAll(); batch.setId(newGroupId); batch.setPnm(name); batch.setPid(typeOrg); batch.setSttm(sttm); batch.setProvince(province); batch.setEntm(entm); bisInspAllDao.insert(batch); list = supervisionPlanDao.getNodeByPersid(persId, type + "", orgId, province); } } return list; } }