d06d7d4d51305f2b1c28f53eb1c7556a555d1eb1.svn-base 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. package cn.com.goldenwater.dcproj.service.impl.plansd;
  2. import cn.com.goldenwater.dcproj.constValue.AdCodeLabel;
  3. import cn.com.goldenwater.dcproj.constValue.BisInspEnum;
  4. import cn.com.goldenwater.dcproj.dao.*;
  5. import cn.com.goldenwater.dcproj.dto.*;
  6. import cn.com.goldenwater.dcproj.model.*;
  7. import cn.com.goldenwater.dcproj.param.*;
  8. import cn.com.goldenwater.dcproj.service.*;
  9. import cn.com.goldenwater.dcproj.service.impl.system.BisInspObjFactory;
  10. import cn.com.goldenwater.dcproj.utils.Constant;
  11. import cn.com.goldenwater.dcproj.utils.DateUtils;
  12. import cn.com.goldenwater.dcproj.utils.StringUtils;
  13. import cn.com.goldenwater.id.util.UuidUtil;
  14. import org.apache.commons.collections.CollectionUtils;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Service;
  17. import org.springframework.transaction.annotation.Transactional;
  18. import java.util.*;
  19. import java.util.stream.Collectors;
  20. @Service
  21. @Transactional(rollbackFor = Exception.class)
  22. public class BisInspGroupArrangementServiceImpl implements BisInspGroupArrangementService {
  23. @Autowired
  24. private BisInspGroupArrangementDao bisInspGroupArrangementDao;
  25. @Autowired
  26. private AttInspTypeDao attInspTypeDao;
  27. @Autowired
  28. private SupervisionPlanDao supervisionPlanDao;
  29. @Autowired
  30. private BisInspAllDao bisInspAllDao;
  31. @Autowired
  32. private BisInspPlanYearDao bisInspPlanYearDao;
  33. @Autowired
  34. private BisInspPlanDtlDao bisInspPlanDtlDao;
  35. @Autowired
  36. private OlBisInspOrgService olBisInspOrgService;
  37. @Autowired
  38. private BisInspPlanService bisInspPlanService;
  39. @Autowired
  40. private BisInspAllObjDao bisInspAllObjDao;
  41. @Autowired
  42. private OlBisInspOrgService inspOrgService;
  43. @Autowired
  44. private BisInspObjFactory factory;
  45. @Autowired
  46. private BisInspPlanDpDao bisInspPlanDpDao;
  47. @Autowired
  48. private BisInspPlanDtlAddvcdDao bisInspPlanDtlAddvcdDao;
  49. @Autowired
  50. private SupervisionPlanService supervisionPlanService;
  51. @Autowired
  52. private BisInspAllRlationDao bisInspAllRlationDao;
  53. @Autowired
  54. private BisInspSelAreaDao bisInspSelAreaDao;
  55. @Autowired
  56. private BisInspPlanLogService bisInspPlanLogService;
  57. @Autowired
  58. private BisInspPlanDtlPtypDao bisInspPlanDtlPtypDao;
  59. @Override
  60. public List<PlanAllInfoDto> getAllInfoByPnmAndTypeAndOrgId(BisInspGroupArrangementParam param) {
  61. List<PlanAllInfoDto> list = bisInspGroupArrangementDao.getAllInfoByPnmAndTypeAndOrgId(param);
  62. if (CollectionUtils.isNotEmpty(list)) {
  63. for (PlanAllInfoDto p : list) {
  64. Optional.ofNullable(bisInspPlanDtlDao.get(p.getDtlId())).ifPresent(dtl -> {
  65. BisInspPlanYear year = bisInspPlanYearDao.get(dtl.getPlanId());
  66. p.setChkName(year.getChkName());
  67. p.setPlanYearId(year.getId());
  68. p.setState(year.getState());
  69. p.setDtlName(dtl.getNm());
  70. p.setChkYear(year.getChkYear());
  71. });
  72. String planDpId = p.getPlanDpId();
  73. if (StringUtils.isNotBlank(planDpId)) {
  74. Optional.ofNullable(bisInspPlanDpDao.get(planDpId)).ifPresent(dp -> p.setPlanDpNm(dp.getDpName()));
  75. }
  76. List<String> idsList = Arrays.stream(StringUtils.split(p.getIds(), ",")).collect(Collectors.toList());
  77. String idsStr = idsList.stream().collect(Collectors.joining("','", "'", "'"));
  78. //获取人员
  79. p.setPersonnelList(this.supervisionPlanDao.getPersAllDtoByIdsList(idsStr));
  80. //获取分工区域
  81. p.setAreaList(this.supervisionPlanDao.getPersAllAreaDtoByIdsList(idsStr));
  82. //组
  83. List<PlanAllGroupDto> groupList = new ArrayList<>();
  84. for (String id : idsList) {
  85. PlanAllGroupDto dto = new PlanAllGroupDto();
  86. //督查类别信息
  87. AttInspType attInspType = attInspTypeDao.get(StringUtils.substring(id, Constant.INT_ZERO, Constant.INT_THREE));
  88. dto.setNm(attInspType.getName());
  89. dto.setpType(attInspType.getPtype());
  90. BisInspAll bisInspAll = bisInspAllDao.get(id);
  91. dto.setId(bisInspAll.getId());
  92. dto.setQuantity(bisInspAll.getQuantity());
  93. dto.setObjectList(this.supervisionPlanDao.getPersAllObjDtoByIdList(bisInspAll.getId()));
  94. groupList.add(dto);
  95. }
  96. int numberOfUnits = bisInspPlanDtlPtypDao.selectCount(new BisInspPlanDtlPtypParam(p.getDtlId()));
  97. //判断是否可添加
  98. if (groupList.size() >= numberOfUnits) {
  99. p.setItPossibleToAdd(Boolean.FALSE);
  100. }
  101. p.setGroupList(groupList);
  102. }
  103. }
  104. return list;
  105. }
  106. @Override
  107. public void add(PlanAllAddDto addDto) {
  108. BisInspPlanDtl dtl = bisInspPlanDtlDao.get(addDto.getDtlId());
  109. if (Objects.isNull(dtl)) {
  110. return;
  111. }
  112. BisInspPlanYear planYear = bisInspPlanYearDao.get(dtl.getPlanId());
  113. if (Objects.isNull(planYear)) {
  114. return;
  115. }
  116. OlBisInspOrg olBisInspOrg = olBisInspOrgService.get(addDto.getOrgId());
  117. String province = inspOrgService.getProvince(addDto.getOrgId());
  118. List<String> typeList = addDto.getTypeList();
  119. for (String type : typeList) {
  120. String guId = lengthType(type) + addDto.getOrgId();
  121. String batchName = Calendar.getInstance().get(Calendar.YEAR) + "年" + (StringUtils.isBlank(planYear.getChkName()) ? "" : planYear.getChkName()) + "督查";
  122. //查询类别中是否有创建的批次
  123. BisInspAllParam bisInspAllParam = new BisInspAllParam();
  124. bisInspAllParam.setId(guId);
  125. bisInspAllParam.setPnm(batchName);
  126. bisInspAllParam.setIsPlan(Constant.STRING_ONE);
  127. List<BisInspAll> eList = bisInspAllDao.findList(bisInspAllParam);
  128. BisInspPlan bisInspPlan = new BisInspPlan();
  129. bisInspPlan.setChkType(null);
  130. bisInspPlan.setChkForm(null);
  131. bisInspPlan.setIsPlan(Constant.STRING_ONE);
  132. bisInspPlan.setLeadDep(null);
  133. bisInspPlan.setPalnSttm(DateUtils.Str2Date(addDto.getStTm()));
  134. bisInspPlan.setPalnEntm(DateUtils.Str2Date(addDto.getEnTm()));
  135. bisInspPlan.setYearTaskId(dtl.getId());
  136. bisInspPlan.setOrgId(dtl.getOrgId());
  137. bisInspPlan.setPlanDpId(addDto.getPlanDpId());
  138. bisInspPlan.setProvince(province);
  139. bisInspPlan.setNote(addDto.getNote());
  140. Optional.ofNullable(olBisInspOrg).ifPresent(o -> bisInspPlan.setOrgName(o.getOrgNm()));
  141. String batchId = null;
  142. if (CollectionUtils.isEmpty(eList)) {
  143. //创建批次
  144. bisInspPlan.setGuid(guId);
  145. bisInspPlan.setPrsnTitle(batchName);
  146. bisInspPlan.setQuantity(addDto.getQuantity());
  147. OrganizationAndBatchAndGroup r = bisInspPlanService.addBisInspPlan(bisInspPlan);
  148. if (Objects.nonNull(r)) {
  149. batchId = r.getCode();
  150. }
  151. } else {
  152. batchId = eList.get(Constant.INT_ZERO).getId();
  153. }
  154. //创建组
  155. bisInspPlan.setGuid(batchId);
  156. bisInspPlan.setPrsnTitle(addDto.getPnm());
  157. bisInspPlan.setQuantity(addDto.getQuantity());
  158. OrganizationAndBatchAndGroup r = bisInspPlanService.addBisInspPlan(bisInspPlan);
  159. String code = r.getCode();
  160. List<BisInspPlanDtlAddvcd> addvcdList = bisInspPlanDtlAddvcdDao.findList(new BisInspPlanDtlAddvcdParam(dtl.getId()));
  161. if (CollectionUtils.isNotEmpty(addvcdList)) {
  162. //督查区域
  163. List<PersAllAreaDto> areaList = new ArrayList<>();
  164. addvcdList.forEach(addvcd -> areaList.add(new PersAllAreaDto(addvcd.getAdCode(), addvcd.getAdName())));
  165. if (CollectionUtils.isNotEmpty(areaList)) {
  166. for (PersAllAreaDto pad : areaList) {
  167. String uuid = UuidUtil.uuid();
  168. this.supervisionPlanDao.insertSupArea(uuid, code, pad.getAdCode(), pad.getAdName(), addDto.getOrgId(), province);
  169. }
  170. }
  171. }
  172. }
  173. }
  174. private String lengthType(String type) {
  175. if (type.length() == Constant.INT_ONE) {
  176. return "00" + type;
  177. } else if (type.length() == Constant.INT_TWO) {
  178. return "0" + type;
  179. } else {
  180. return type;
  181. }
  182. }
  183. @Override
  184. public void update(PlanAllUpDto dto) {
  185. String code = dto.getId();
  186. String province = inspOrgService.getProvince(dto.getOrgId());
  187. //添加督查人员
  188. List<PersAllDto> personnelList = dto.getPersonnelList();
  189. if (CollectionUtils.isNotEmpty(personnelList)) {
  190. for (PersAllDto pers : personnelList) {
  191. BisInspAllRlationParam rlationParam = new BisInspAllRlationParam();
  192. rlationParam.setProvince(province);
  193. rlationParam.setId(code);
  194. rlationParam.setPersid(pers.getGuid());
  195. List<BisInspAllRlation> list = bisInspAllRlationDao.findList(rlationParam);
  196. if (CollectionUtils.isEmpty(list)){
  197. this.supervisionPlanDao.insertPers(code, pers.getGuid(), pers.getPersType(), dto.getOrgId(), province, String.valueOf(Integer.parseInt(code.substring(0, 3))));
  198. }
  199. }
  200. }
  201. List<PersAllObjDto> objectList = dto.getObjectList();
  202. //添加督查对象
  203. if (CollectionUtils.isNotEmpty(objectList)) {
  204. for (PersAllObjDto objDto : objectList) {
  205. String type = lengthType(objDto.getPtype());
  206. // 去重判断 跟据 基础表ID、组ID、PTYPE 判NullPointerException断是否重复
  207. BisInspAllObjParam inspAllObjParam = new BisInspAllObjParam();
  208. inspAllObjParam.setId(code);
  209. inspAllObjParam.setCode(objDto.getCode());
  210. inspAllObjParam.setPtype(objDto.getPtype());
  211. List<BisInspAllObj> inspAllObjDaoList = bisInspAllObjDao.findList(inspAllObjParam);
  212. if (CollectionUtils.isNotEmpty(inspAllObjDaoList)) {
  213. continue;
  214. }
  215. // 添加督查对象
  216. BisInspAllObj bisInspAllObj = this.addObj(code, dto.getPersId(), dto.getOrgId(), objDto, type);
  217. // 添加登记表
  218. BisInspObjStrategy strategy = factory.createStrategy(objDto.getPtype());
  219. strategy.insertObj(bisInspAllObj, dto.getPersId());
  220. }
  221. }
  222. }
  223. @Override
  224. public void cleanGroupInfo(String groupId, String orgId ,String persId) {
  225. BisInspAllObjParam bisInspObjParam = new BisInspAllObjParam();
  226. bisInspObjParam.setId(groupId);
  227. //根据组id获取objid
  228. bisInspObjParam.setOrgId(orgId);
  229. List<BisInspAllObj> bisInspAllObjList = this.bisInspAllObjDao.findList(bisInspObjParam);
  230. if (bisInspAllObjList.size() > 0) {
  231. for (BisInspAllObj bisInspAllObj : bisInspAllObjList) {
  232. //根据objid删除登记表等数据
  233. supervisionPlanService.cleanObjDataByObjId(String.valueOf(Integer.parseInt(groupId.substring(0, 3))), bisInspAllObj.getObjId());
  234. }
  235. }
  236. BisInspSelAreaParam bisInspSelAreaParam = new BisInspSelAreaParam();
  237. bisInspSelAreaParam.setId(groupId);
  238. //删除督查区域
  239. this.bisInspSelAreaDao.deleteBy(bisInspSelAreaParam);
  240. BisInspAllRlationParam bisInspAllRlationParam = new BisInspAllRlationParam();
  241. bisInspAllRlationParam.setId(groupId);
  242. //删除督查人员
  243. this.bisInspAllRlationDao.deleteBy(bisInspAllRlationParam);
  244. //删除组
  245. this.bisInspAllDao.delete(groupId);
  246. //删除组记录
  247. this.bisInspPlanLogService.insert(new BisInspPlanLog(groupId,persId));
  248. }
  249. /**
  250. * @param ids 组id ,分割
  251. * @param orgId 机构id
  252. */
  253. @Override
  254. public void delAll(String ids, String orgId, String persId) {
  255. List<String> idList = Arrays.stream(StringUtils.split(ids, ",")).collect(Collectors.toList());
  256. for (String id : idList) {
  257. this.cleanGroupInfo(id, orgId, persId);
  258. }
  259. }
  260. @Override
  261. public void updateInfo(PlanAllUpDto dto) {
  262. List<String> idList = Arrays.stream(StringUtils.split(dto.getIds(), ",")).collect(Collectors.toList());
  263. //修改督查组名称
  264. if (StringUtils.isNotBlank(dto.getPnm()) || StringUtils.isNotBlank(dto.getStTm()) || StringUtils.isNotBlank(dto.getEnTm()) || Objects.nonNull(dto.getQuantity())) {
  265. BisInspAllDto bisInspAllDto = new BisInspAllDto();
  266. bisInspAllDto.setPnm(dto.getPnm());
  267. bisInspAllDto.setSttm(dto.getStTm());
  268. bisInspAllDto.setEntm(dto.getEnTm());
  269. bisInspAllDto.setQuantity(dto.getQuantity());
  270. for (String id : idList) {
  271. bisInspAllDto.setId(id);
  272. this.supervisionPlanDao.updateNode(bisInspAllDto);
  273. }
  274. }
  275. }
  276. @Override
  277. public void delSinglePersonnel(PlanAllDelDto dto) {
  278. BisInspAllRlationParam param = new BisInspAllRlationParam();
  279. param.setId(dto.getGroupId());
  280. param.setPersid(dto.getDelId());
  281. //删除督查人员
  282. this.bisInspAllRlationDao.deleteBy(param);
  283. }
  284. @Override
  285. public void delSingleObject(PlanAllDelDto dto) {
  286. String groupId = dto.getGroupId();
  287. if (groupId.length() > Constant.INT_THREE) {
  288. BisInspAllObjParam objParam = new BisInspAllObjParam();
  289. objParam.setId(groupId);
  290. objParam.setCode(dto.getDelId());
  291. Optional.ofNullable(bisInspAllObjDao.findList(objParam)).ifPresent(objList -> {
  292. for (BisInspAllObj bisInspAllObj : objList) {
  293. //根据objid删除登记表等数据
  294. this.supervisionPlanService.cleanObjDataByObjId(String.valueOf(Integer.parseInt(StringUtils.substring(groupId, 0, 3))), bisInspAllObj.getObjId());
  295. }
  296. });
  297. }
  298. }
  299. /**
  300. * 添加对象表 BIS_INSP_ALL_OBJ
  301. *
  302. * @param code 组id
  303. * @param persId 创建人
  304. * @param orgId 机构id
  305. * @param persObj obj
  306. * @param type 督查类别
  307. * @return BisInspAllObj
  308. */
  309. private BisInspAllObj addObj(String code, String persId, String orgId, PersAllObjDto persObj, String type) {
  310. OlBisInspOrg olBisInspOrg = olBisInspOrgService.get(orgId);
  311. //行政区划
  312. String adCode = null;
  313. if (Objects.nonNull(olBisInspOrg)) {
  314. adCode = olBisInspOrg.getRlcode();
  315. }
  316. //省级行政区划
  317. String province = inspOrgService.getProvince(orgId);
  318. BisInspAllObj bisInspAllObj = new BisInspAllObj();
  319. bisInspAllObj.setObjId(UuidUtil.uuid());
  320. bisInspAllObj.setPtype(persObj.getPtype());
  321. bisInspAllObj.setCode(persObj.getCode());
  322. bisInspAllObj.setId(code);
  323. bisInspAllObj.setNm(persObj.getName());
  324. bisInspAllObj.setProvince(province);
  325. bisInspAllObj.setPersId(persId);
  326. // 查询经纬度
  327. // 30 超标洪水防御 没有省级划分,所以无法获取经纬度
  328. if (!BisInspEnum.EFP.getRlation().equals(type)) {
  329. LgtdAndLttd lgtdAndLttd = this.supervisionPlanDao.getLgtdAndLttd(persObj.getCode(), type);
  330. Optional.ofNullable(lgtdAndLttd).ifPresent(ld -> {
  331. bisInspAllObj.setLgtd(ld.getLgtd());
  332. bisInspAllObj.setLttd(ld.getLttd());
  333. bisInspAllObj.setLgtdpc(ld.getLgtdPc());
  334. bisInspAllObj.setLttdpc(ld.getLttdPc());
  335. });
  336. }
  337. // 判断是否是全国数据
  338. if (!adCode.startsWith(AdCodeLabel.START_PARENT_ADCODE)) {
  339. bisInspAllObj.setAdCode(adCode);
  340. bisInspAllObj.setOrgId(orgId);
  341. }
  342. // 添加督查对象
  343. this.bisInspAllObjDao.insert(bisInspAllObj);
  344. return bisInspAllObj;
  345. }
  346. }