02bf31a19d26329b926e2aeb5d57121e2c2d6337.svn-base 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. package cn.com.goldenwater.dcproj.service.impl.ducha;
  2. import cn.com.goldenwater.core.service.AbstractCrudService;
  3. import cn.com.goldenwater.dcproj.dao.*;
  4. import cn.com.goldenwater.dcproj.dto.AllNodeDto;
  5. import cn.com.goldenwater.dcproj.dto.BisInspGroupDto;
  6. import cn.com.goldenwater.dcproj.dto.ObjIdDto;
  7. import cn.com.goldenwater.dcproj.model.*;
  8. import cn.com.goldenwater.dcproj.param.BisInspPlanParam;
  9. import cn.com.goldenwater.dcproj.service.BisInspPlanService;
  10. import cn.com.goldenwater.dcproj.service.OlBisInspOrgService;
  11. import org.apache.commons.collections.map.HashedMap;
  12. import org.apache.commons.lang3.StringUtils;
  13. import org.apache.commons.lang3.math.NumberUtils;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16. import org.springframework.transaction.annotation.Transactional;
  17. import java.text.SimpleDateFormat;
  18. import java.time.LocalDateTime;
  19. import java.util.*;
  20. /**
  21. * @author lune
  22. * @date 2019-2-18
  23. */
  24. @Service
  25. @Transactional(rollbackFor = Exception.class)
  26. public class BisInspPlanServiceImpl extends AbstractCrudService<BisInspPlan, BisInspPlanParam> implements BisInspPlanService {
  27. @Autowired
  28. private BisInspPlanDao bisInspPlanDao;
  29. @Autowired
  30. private BisInspAllDao bisInspAllDao;
  31. @Autowired
  32. private BisInspGroupDao bisInspGroupDao;
  33. @Autowired
  34. private AttPersBaseDao attPersBaseDao;
  35. @Autowired
  36. private BisInspObjDao bisInspObjDao;
  37. @Autowired
  38. private SupervisionPlanDao supervisionPlanDao;
  39. @Autowired
  40. private OlBisInspOrgDao bisInspOrgDao;
  41. @Autowired
  42. private OlBisInspOrgService olBisInspOrgService;
  43. public BisInspPlanServiceImpl(BisInspPlanDao bisInspPlanDao) {
  44. super(bisInspPlanDao);
  45. this.bisInspPlanDao = bisInspPlanDao;
  46. }
  47. @Override
  48. public OrganizationAndBatchAndGroup addBisInspPlan(BisInspPlan bisInspPlan) {
  49. if (null == bisInspPlan) {
  50. return null;
  51. }
  52. BisInspAll bisInspAll = new BisInspAll();
  53. //根据父id查询最大的子id
  54. BisInspAll max = bisInspAllDao.getMaxOne(bisInspPlan.getGuid(), bisInspPlan.getOrgId());
  55. if (null != max) {
  56. Long upOne = NumberUtils.toLong(max.getId());
  57. String newId = String.format("%0" + max.getId().length() + "d", (upOne + 1));
  58. bisInspAll.setId(newId);
  59. } else {
  60. bisInspAll.setId(bisInspPlan.getGuid() + "001");
  61. }
  62. if (bisInspPlan.getPalnSttm() != null) {
  63. String year = new SimpleDateFormat("yyyy").format(bisInspPlan.getPalnSttm());
  64. String mnth = new SimpleDateFormat("MM").format(bisInspPlan.getPalnSttm());
  65. bisInspAll.setInspYear(year);
  66. bisInspAll.setInspMnth(mnth);
  67. } else {
  68. String year = new SimpleDateFormat("yyyy").format(LocalDateTime.now());
  69. String mnth = new SimpleDateFormat("MM").format(LocalDateTime.now());
  70. bisInspAll.setInspYear(year);
  71. bisInspAll.setInspMnth(mnth);
  72. }
  73. bisInspAll.setEntm(bisInspPlan.getPalnEntm());
  74. bisInspAll.setSttm(bisInspPlan.getPalnSttm());
  75. bisInspAll.setProvince(bisInspPlan.getProvince());
  76. bisInspAll.setOrgName(bisInspPlan.getOrgName());
  77. bisInspAll.setPid(bisInspPlan.getGuid());
  78. bisInspAll.setPnm(bisInspPlan.getPrsnTitle());
  79. bisInspAll.setChkType(bisInspPlan.getChkType());
  80. bisInspAll.setChkForm(bisInspPlan.getChkForm());
  81. bisInspAll.setYearTaskId(bisInspPlan.getYearTaskId());
  82. bisInspAll.setLeadDep(bisInspPlan.getLeadDep());
  83. bisInspAll.setIsPlan(bisInspPlan.getIsPlan());
  84. bisInspAll.setOrgId(bisInspPlan.getOrgId());
  85. bisInspAll.setQuantity(bisInspPlan.getQuantity());
  86. bisInspAll.setPlanDpId(bisInspPlan.getPlanDpId());
  87. bisInspAll.setNote(bisInspPlan.getNote());
  88. bisInspAllDao.insert(bisInspAll);
  89. OrganizationAndBatchAndGroup result = new OrganizationAndBatchAndGroup();
  90. result.setName(bisInspPlan.getPrsnTitle());
  91. result.setCode(bisInspAll.getId());
  92. result.setType("3");
  93. return result;
  94. }
  95. @Override
  96. public List<BisInspGroupDto> findListByPersId(String persId) {
  97. return bisInspPlanDao.findListByPersId(persId);
  98. }
  99. @Override
  100. public Map<String, Object> getDetail(String inspGroupId, String plnaId) {
  101. HashMap<String, Object> result = new HashMap<>();
  102. BisInspPlan bisInspPlan = bisInspPlanDao.get(plnaId);
  103. result.put("plan", bisInspPlan == null ? new BisInspPlan() : bisInspPlan);
  104. BisInspGroup bisInspGroup = bisInspGroupDao.get(inspGroupId);
  105. result.put("group", bisInspGroup == null ? new BisInspGroup() : bisInspGroup);
  106. List<AttPersBase> listByInspGroupId = attPersBaseDao.getListByInspGroupId(inspGroupId);
  107. result.put("persList", listByInspGroupId == null ? new ArrayList<>() : listByInspGroupId);
  108. List<BisInspObj> listByGroupIdAndPlanId = bisInspObjDao.findListByGroupIdAndPlanId(inspGroupId, plnaId);
  109. result.put("objList", listByGroupIdAndPlanId == null ? new ArrayList<>() : listByGroupIdAndPlanId);
  110. return result;
  111. }
  112. @Override
  113. public Map<String, Object> deletePlan(String id, String orgId) {
  114. String province = olBisInspOrgService.getProvince(orgId);
  115. List<BisInspAllRlation> bisInspAllRlationList = this.bisInspPlanDao.getAllRlation(id, province);//人员和组
  116. List<BisInspAllObj> bisInspAllObjList = this.bisInspPlanDao.getAllObj(id, province);//对象和组
  117. List<BisInspSelArea> bisInspSelAreaList = this.bisInspPlanDao.getAllArea(id, orgId, province);
  118. Map<String, Object> map = new HashedMap();
  119. if (bisInspAllRlationList.size() > 0) {
  120. map.put("code", 1001);
  121. map.put("message", "请先删除人员或对象");
  122. } else if (bisInspAllObjList.size() > 0) {
  123. map.put("code", 1001);
  124. map.put("message", "请先删除人员或对象");
  125. } else if (bisInspSelAreaList.size() > 0) {
  126. map.put("code", 1001);
  127. map.put("message", "请先删除人员或对象");
  128. } else {
  129. bisInspAllDao.delete(id);
  130. map.put("code", 1002);
  131. map.put("message", "删除成功");
  132. }
  133. return map;
  134. }
  135. @Override
  136. public List<AllNodeDto> addInspPlanBatch(BisInspPlan bisInspPlan) {
  137. List<AllNodeDto> list = new ArrayList<>();
  138. if (bisInspPlan != null) {
  139. String objType = bisInspPlan.getObjType();
  140. String orgId = bisInspPlan.getOrgId();
  141. String orgName = bisInspPlan.getOrgName();
  142. if (StringUtils.isEmpty(orgName)) {
  143. OlBisInspOrg bisInspOrg = bisInspOrgDao.get(orgId);
  144. orgName = bisInspOrg.getOrgNm();
  145. }
  146. String persId = bisInspPlan.getPersId();
  147. String name = bisInspPlan.getPrsnTitle();
  148. Date sttm = bisInspPlan.getPalnSttm();
  149. Date entm = bisInspPlan.getPalnEntm();
  150. String province = olBisInspOrgService.getProvince(bisInspPlan.getOrgId());
  151. if (StringUtils.isNotEmpty(objType) && StringUtils.isNotEmpty(orgId)) {
  152. int type = Integer.parseInt(objType);
  153. String typeOrg = "00" + type + orgId;
  154. BisInspAll bisInspAll = bisInspAllDao.get(typeOrg);
  155. if (bisInspAll == null) {
  156. BisInspAll batch = new BisInspAll();
  157. batch.setId(typeOrg);
  158. batch.setPnm(orgName);
  159. batch.setPid("00" + type);
  160. batch.setSttm(sttm);
  161. batch.setEntm(entm);
  162. batch.setProvince(province);
  163. bisInspAllDao.insert(batch);
  164. }
  165. String newGroupId = "";
  166. ObjIdDto objIdDto = supervisionPlanDao.getMaxGroupId(typeOrg, orgId, province);
  167. if (objIdDto.getId() != null) {//如果该批次下有组,则组id加1
  168. String rtId = objIdDto.getId().substring(objIdDto.getId().length() - 1, objIdDto.getId().length());
  169. int i = Integer.parseInt(rtId) + 1;
  170. newGroupId = String.valueOf(i);
  171. if ("10".equals(newGroupId)) {
  172. String sid = objIdDto.getId().substring(objIdDto.getId().length() - 2, objIdDto.getId().length() - 1);
  173. int j = Integer.parseInt(sid) + 1;
  174. String ss = String.valueOf(j);
  175. newGroupId = objIdDto.getId().substring(0, objIdDto.getId().length() - 2) + ss + "0";
  176. } else {
  177. newGroupId = objIdDto.getId().substring(0, objIdDto.getId().length() - 1) + newGroupId;
  178. }
  179. } else {//如果该批次下没有组,则组id后三位为001
  180. newGroupId = typeOrg + "001";
  181. }
  182. BisInspAll batch = new BisInspAll();
  183. batch.setId(newGroupId);
  184. batch.setPnm(name);
  185. batch.setPid(typeOrg);
  186. batch.setSttm(sttm);
  187. batch.setProvince(province);
  188. batch.setEntm(entm);
  189. bisInspAllDao.insert(batch);
  190. list = supervisionPlanDao.getNodeByPersid(persId, type + "", orgId, province);
  191. }
  192. }
  193. return list;
  194. }
  195. }