| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399 |
- package cn.com.goldenwater.dcproj.service.impl.plansd;
- import cn.com.goldenwater.dcproj.constValue.AdCodeLabel;
- import cn.com.goldenwater.dcproj.constValue.BisInspEnum;
- import cn.com.goldenwater.dcproj.dao.*;
- import cn.com.goldenwater.dcproj.dto.*;
- 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.system.BisInspObjFactory;
- import cn.com.goldenwater.dcproj.utils.Constant;
- import cn.com.goldenwater.dcproj.utils.DateUtils;
- import cn.com.goldenwater.dcproj.utils.StringUtils;
- import cn.com.goldenwater.id.util.UuidUtil;
- import org.apache.commons.collections.CollectionUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.util.*;
- import java.util.stream.Collectors;
- @Service
- @Transactional(rollbackFor = Exception.class)
- public class BisInspGroupArrangementServiceImpl implements BisInspGroupArrangementService {
- @Autowired
- private BisInspGroupArrangementDao bisInspGroupArrangementDao;
- @Autowired
- private AttInspTypeDao attInspTypeDao;
- @Autowired
- private SupervisionPlanDao supervisionPlanDao;
- @Autowired
- private BisInspAllDao bisInspAllDao;
- @Autowired
- private BisInspPlanYearDao bisInspPlanYearDao;
- @Autowired
- private BisInspPlanDtlDao bisInspPlanDtlDao;
- @Autowired
- private OlBisInspOrgService olBisInspOrgService;
- @Autowired
- private BisInspPlanService bisInspPlanService;
- @Autowired
- private BisInspAllObjDao bisInspAllObjDao;
- @Autowired
- private OlBisInspOrgService inspOrgService;
- @Autowired
- private BisInspObjFactory factory;
- @Autowired
- private BisInspPlanDpDao bisInspPlanDpDao;
- @Autowired
- private BisInspPlanDtlAddvcdDao bisInspPlanDtlAddvcdDao;
- @Autowired
- private SupervisionPlanService supervisionPlanService;
- @Autowired
- private BisInspAllRlationDao bisInspAllRlationDao;
- @Autowired
- private BisInspSelAreaDao bisInspSelAreaDao;
- @Autowired
- private BisInspPlanLogService bisInspPlanLogService;
- @Autowired
- private BisInspPlanDtlPtypDao bisInspPlanDtlPtypDao;
- @Override
- public List<PlanAllInfoDto> getAllInfoByPnmAndTypeAndOrgId(BisInspGroupArrangementParam param) {
- List<PlanAllInfoDto> list = bisInspGroupArrangementDao.getAllInfoByPnmAndTypeAndOrgId(param);
- if (CollectionUtils.isNotEmpty(list)) {
- for (PlanAllInfoDto p : list) {
- Optional.ofNullable(bisInspPlanDtlDao.get(p.getDtlId())).ifPresent(dtl -> {
- BisInspPlanYear year = bisInspPlanYearDao.get(dtl.getPlanId());
- p.setChkName(year.getChkName());
- p.setPlanYearId(year.getId());
- p.setState(year.getState());
- p.setDtlName(dtl.getNm());
- p.setChkYear(year.getChkYear());
- });
- String planDpId = p.getPlanDpId();
- if (StringUtils.isNotBlank(planDpId)) {
- Optional.ofNullable(bisInspPlanDpDao.get(planDpId)).ifPresent(dp -> p.setPlanDpNm(dp.getDpName()));
- }
- List<String> idsList = Arrays.stream(StringUtils.split(p.getIds(), ",")).collect(Collectors.toList());
- String idsStr = idsList.stream().collect(Collectors.joining("','", "'", "'"));
- //获取人员
- p.setPersonnelList(this.supervisionPlanDao.getPersAllDtoByIdsList(idsStr));
- //获取分工区域
- p.setAreaList(this.supervisionPlanDao.getPersAllAreaDtoByIdsList(idsStr));
- //组
- List<PlanAllGroupDto> groupList = new ArrayList<>();
- for (String id : idsList) {
- PlanAllGroupDto dto = new PlanAllGroupDto();
- //督查类别信息
- AttInspType attInspType = attInspTypeDao.get(StringUtils.substring(id, Constant.INT_ZERO, Constant.INT_THREE));
- dto.setNm(attInspType.getName());
- dto.setpType(attInspType.getPtype());
- BisInspAll bisInspAll = bisInspAllDao.get(id);
- dto.setId(bisInspAll.getId());
- dto.setQuantity(bisInspAll.getQuantity());
- dto.setObjectList(this.supervisionPlanDao.getPersAllObjDtoByIdList(bisInspAll.getId()));
- groupList.add(dto);
- }
- int numberOfUnits = bisInspPlanDtlPtypDao.selectCount(new BisInspPlanDtlPtypParam(p.getDtlId()));
- //判断是否可添加
- if (groupList.size() >= numberOfUnits) {
- p.setItPossibleToAdd(Boolean.FALSE);
- }
- p.setGroupList(groupList);
- }
- }
- return list;
- }
- @Override
- public void add(PlanAllAddDto addDto) {
- BisInspPlanDtl dtl = bisInspPlanDtlDao.get(addDto.getDtlId());
- if (Objects.isNull(dtl)) {
- return;
- }
- BisInspPlanYear planYear = bisInspPlanYearDao.get(dtl.getPlanId());
- if (Objects.isNull(planYear)) {
- return;
- }
- OlBisInspOrg olBisInspOrg = olBisInspOrgService.get(addDto.getOrgId());
- String province = inspOrgService.getProvince(addDto.getOrgId());
- List<String> typeList = addDto.getTypeList();
- for (String type : typeList) {
- String guId = lengthType(type) + addDto.getOrgId();
- String batchName = Calendar.getInstance().get(Calendar.YEAR) + "年" + (StringUtils.isBlank(planYear.getChkName()) ? "" : planYear.getChkName()) + "督查";
- //查询类别中是否有创建的批次
- BisInspAllParam bisInspAllParam = new BisInspAllParam();
- bisInspAllParam.setId(guId);
- bisInspAllParam.setPnm(batchName);
- bisInspAllParam.setIsPlan(Constant.STRING_ONE);
- List<BisInspAll> eList = bisInspAllDao.findList(bisInspAllParam);
- BisInspPlan bisInspPlan = new BisInspPlan();
- bisInspPlan.setChkType(null);
- bisInspPlan.setChkForm(null);
- bisInspPlan.setIsPlan(Constant.STRING_ONE);
- bisInspPlan.setLeadDep(null);
- bisInspPlan.setPalnSttm(DateUtils.Str2Date(addDto.getStTm()));
- bisInspPlan.setPalnEntm(DateUtils.Str2Date(addDto.getEnTm()));
- bisInspPlan.setYearTaskId(dtl.getId());
- bisInspPlan.setOrgId(dtl.getOrgId());
- bisInspPlan.setPlanDpId(addDto.getPlanDpId());
- bisInspPlan.setProvince(province);
- bisInspPlan.setNote(addDto.getNote());
- Optional.ofNullable(olBisInspOrg).ifPresent(o -> bisInspPlan.setOrgName(o.getOrgNm()));
- String batchId = null;
- if (CollectionUtils.isEmpty(eList)) {
- //创建批次
- bisInspPlan.setGuid(guId);
- bisInspPlan.setPrsnTitle(batchName);
- bisInspPlan.setQuantity(addDto.getQuantity());
- OrganizationAndBatchAndGroup r = bisInspPlanService.addBisInspPlan(bisInspPlan);
- if (Objects.nonNull(r)) {
- batchId = r.getCode();
- }
- } else {
- batchId = eList.get(Constant.INT_ZERO).getId();
- }
- //创建组
- bisInspPlan.setGuid(batchId);
- bisInspPlan.setPrsnTitle(addDto.getPnm());
- bisInspPlan.setQuantity(addDto.getQuantity());
- OrganizationAndBatchAndGroup r = bisInspPlanService.addBisInspPlan(bisInspPlan);
- String code = r.getCode();
- List<BisInspPlanDtlAddvcd> addvcdList = bisInspPlanDtlAddvcdDao.findList(new BisInspPlanDtlAddvcdParam(dtl.getId()));
- if (CollectionUtils.isNotEmpty(addvcdList)) {
- //督查区域
- List<PersAllAreaDto> areaList = new ArrayList<>();
- addvcdList.forEach(addvcd -> areaList.add(new PersAllAreaDto(addvcd.getAdCode(), addvcd.getAdName())));
- if (CollectionUtils.isNotEmpty(areaList)) {
- for (PersAllAreaDto pad : areaList) {
- String uuid = UuidUtil.uuid();
- this.supervisionPlanDao.insertSupArea(uuid, code, pad.getAdCode(), pad.getAdName(), addDto.getOrgId(), province);
- }
- }
- }
- }
- }
- private String lengthType(String type) {
- if (type.length() == Constant.INT_ONE) {
- return "00" + type;
- } else if (type.length() == Constant.INT_TWO) {
- return "0" + type;
- } else {
- return type;
- }
- }
- @Override
- public void update(PlanAllUpDto dto) {
- String code = dto.getId();
- String province = inspOrgService.getProvince(dto.getOrgId());
- //添加督查人员
- List<PersAllDto> personnelList = dto.getPersonnelList();
- if (CollectionUtils.isNotEmpty(personnelList)) {
- for (PersAllDto pers : personnelList) {
- BisInspAllRlationParam rlationParam = new BisInspAllRlationParam();
- rlationParam.setProvince(province);
- rlationParam.setId(code);
- rlationParam.setPersid(pers.getGuid());
- List<BisInspAllRlation> list = bisInspAllRlationDao.findList(rlationParam);
- if (CollectionUtils.isEmpty(list)){
- this.supervisionPlanDao.insertPers(code, pers.getGuid(), pers.getPersType(), dto.getOrgId(), province, String.valueOf(Integer.parseInt(code.substring(0, 3))));
- }
- }
- }
- List<PersAllObjDto> objectList = dto.getObjectList();
- //添加督查对象
- if (CollectionUtils.isNotEmpty(objectList)) {
- for (PersAllObjDto objDto : objectList) {
- String type = lengthType(objDto.getPtype());
- // 去重判断 跟据 基础表ID、组ID、PTYPE 判NullPointerException断是否重复
- BisInspAllObjParam inspAllObjParam = new BisInspAllObjParam();
- inspAllObjParam.setId(code);
- inspAllObjParam.setCode(objDto.getCode());
- inspAllObjParam.setPtype(objDto.getPtype());
- List<BisInspAllObj> inspAllObjDaoList = bisInspAllObjDao.findList(inspAllObjParam);
- if (CollectionUtils.isNotEmpty(inspAllObjDaoList)) {
- continue;
- }
- // 添加督查对象
- BisInspAllObj bisInspAllObj = this.addObj(code, dto.getPersId(), dto.getOrgId(), objDto, type);
- // 添加登记表
- BisInspObjStrategy strategy = factory.createStrategy(objDto.getPtype());
- strategy.insertObj(bisInspAllObj, dto.getPersId());
- }
- }
- }
- @Override
- public void cleanGroupInfo(String groupId, String orgId ,String persId) {
- BisInspAllObjParam bisInspObjParam = new BisInspAllObjParam();
- bisInspObjParam.setId(groupId);
- //根据组id获取objid
- bisInspObjParam.setOrgId(orgId);
- List<BisInspAllObj> bisInspAllObjList = this.bisInspAllObjDao.findList(bisInspObjParam);
- if (bisInspAllObjList.size() > 0) {
- for (BisInspAllObj bisInspAllObj : bisInspAllObjList) {
- //根据objid删除登记表等数据
- supervisionPlanService.cleanObjDataByObjId(String.valueOf(Integer.parseInt(groupId.substring(0, 3))), bisInspAllObj.getObjId());
- }
- }
- BisInspSelAreaParam bisInspSelAreaParam = new BisInspSelAreaParam();
- bisInspSelAreaParam.setId(groupId);
- //删除督查区域
- this.bisInspSelAreaDao.deleteBy(bisInspSelAreaParam);
- BisInspAllRlationParam bisInspAllRlationParam = new BisInspAllRlationParam();
- bisInspAllRlationParam.setId(groupId);
- //删除督查人员
- this.bisInspAllRlationDao.deleteBy(bisInspAllRlationParam);
- //删除组
- this.bisInspAllDao.delete(groupId);
- //删除组记录
- this.bisInspPlanLogService.insert(new BisInspPlanLog(groupId,persId));
- }
- /**
- * @param ids 组id ,分割
- * @param orgId 机构id
- */
- @Override
- public void delAll(String ids, String orgId, String persId) {
- List<String> idList = Arrays.stream(StringUtils.split(ids, ",")).collect(Collectors.toList());
- for (String id : idList) {
- this.cleanGroupInfo(id, orgId, persId);
- }
- }
- @Override
- public void updateInfo(PlanAllUpDto dto) {
- List<String> idList = Arrays.stream(StringUtils.split(dto.getIds(), ",")).collect(Collectors.toList());
- //修改督查组名称
- if (StringUtils.isNotBlank(dto.getPnm()) || StringUtils.isNotBlank(dto.getStTm()) || StringUtils.isNotBlank(dto.getEnTm()) || Objects.nonNull(dto.getQuantity())) {
- BisInspAllDto bisInspAllDto = new BisInspAllDto();
- bisInspAllDto.setPnm(dto.getPnm());
- bisInspAllDto.setSttm(dto.getStTm());
- bisInspAllDto.setEntm(dto.getEnTm());
- bisInspAllDto.setQuantity(dto.getQuantity());
- for (String id : idList) {
- bisInspAllDto.setId(id);
- this.supervisionPlanDao.updateNode(bisInspAllDto);
- }
- }
- }
- @Override
- public void delSinglePersonnel(PlanAllDelDto dto) {
- BisInspAllRlationParam param = new BisInspAllRlationParam();
- param.setId(dto.getGroupId());
- param.setPersid(dto.getDelId());
- //删除督查人员
- this.bisInspAllRlationDao.deleteBy(param);
- }
- @Override
- public void delSingleObject(PlanAllDelDto dto) {
- String groupId = dto.getGroupId();
- if (groupId.length() > Constant.INT_THREE) {
- BisInspAllObjParam objParam = new BisInspAllObjParam();
- objParam.setId(groupId);
- objParam.setCode(dto.getDelId());
- Optional.ofNullable(bisInspAllObjDao.findList(objParam)).ifPresent(objList -> {
- for (BisInspAllObj bisInspAllObj : objList) {
- //根据objid删除登记表等数据
- this.supervisionPlanService.cleanObjDataByObjId(String.valueOf(Integer.parseInt(StringUtils.substring(groupId, 0, 3))), bisInspAllObj.getObjId());
- }
- });
- }
- }
- /**
- * 添加对象表 BIS_INSP_ALL_OBJ
- *
- * @param code 组id
- * @param persId 创建人
- * @param orgId 机构id
- * @param persObj obj
- * @param type 督查类别
- * @return BisInspAllObj
- */
- private BisInspAllObj addObj(String code, String persId, String orgId, PersAllObjDto persObj, String type) {
- OlBisInspOrg olBisInspOrg = olBisInspOrgService.get(orgId);
- //行政区划
- String adCode = null;
- if (Objects.nonNull(olBisInspOrg)) {
- adCode = olBisInspOrg.getRlcode();
- }
- //省级行政区划
- String province = inspOrgService.getProvince(orgId);
- BisInspAllObj bisInspAllObj = new BisInspAllObj();
- bisInspAllObj.setObjId(UuidUtil.uuid());
- bisInspAllObj.setPtype(persObj.getPtype());
- bisInspAllObj.setCode(persObj.getCode());
- bisInspAllObj.setId(code);
- bisInspAllObj.setNm(persObj.getName());
- bisInspAllObj.setProvince(province);
- bisInspAllObj.setPersId(persId);
- // 查询经纬度
- // 30 超标洪水防御 没有省级划分,所以无法获取经纬度
- if (!BisInspEnum.EFP.getRlation().equals(type)) {
- LgtdAndLttd lgtdAndLttd = this.supervisionPlanDao.getLgtdAndLttd(persObj.getCode(), type);
- Optional.ofNullable(lgtdAndLttd).ifPresent(ld -> {
- bisInspAllObj.setLgtd(ld.getLgtd());
- bisInspAllObj.setLttd(ld.getLttd());
- bisInspAllObj.setLgtdpc(ld.getLgtdPc());
- bisInspAllObj.setLttdpc(ld.getLttdPc());
- });
- }
- // 判断是否是全国数据
- if (!adCode.startsWith(AdCodeLabel.START_PARENT_ADCODE)) {
- bisInspAllObj.setAdCode(adCode);
- bisInspAllObj.setOrgId(orgId);
- }
- // 添加督查对象
- this.bisInspAllObjDao.insert(bisInspAllObj);
- return bisInspAllObj;
- }
- }
|