|
@@ -16,10 +16,7 @@ import com.qmth.sop.business.mapper.TBServiceRegionMapper;
|
|
|
import com.qmth.sop.business.service.*;
|
|
|
import com.qmth.sop.common.base.BaseEntity;
|
|
|
import com.qmth.sop.common.contant.SystemConstant;
|
|
|
-import com.qmth.sop.common.enums.ExceptionResultEnum;
|
|
|
-import com.qmth.sop.common.enums.RoleTypeEnum;
|
|
|
-import com.qmth.sop.common.enums.ServiceStatusEnum;
|
|
|
-import com.qmth.sop.common.enums.UserArchivesStatusEnum;
|
|
|
+import com.qmth.sop.common.enums.*;
|
|
|
import com.qmth.sop.common.util.ServletUtil;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -202,6 +199,9 @@ public class TBServiceRegionServiceImpl extends ServiceImpl<TBServiceRegionMappe
|
|
|
List<TBCrm> willDisposeCrmList = tbCrmService.list(new QueryWrapper<TBCrm>().lambda().in(TBCrm::getRegionDetailId, willDeleteRegionDetailIdList));
|
|
|
|
|
|
for (TBCrm tbCrm : willDisposeCrmList) {
|
|
|
+ if (!CrmStatusEnum.UN_PUBLISH.equals(tbCrm.getStatus())){
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("该大区规划中存在已经发布的派单[" + tbCrm.getCrmNo() + "(" + tbCrm.getName() + ")" + "]不能修改区域");
|
|
|
+ }
|
|
|
// 之前派单有划定在服务单元 -> 解绑派单所有资源信息
|
|
|
List<TBUserArchivesAllocation> dbAllocationList = tbUserArchivesAllocationService.list(new QueryWrapper<TBUserArchivesAllocation>().lambda()
|
|
|
.eq(TBUserArchivesAllocation::getCrmNo, tbCrm.getCrmNo())
|
|
@@ -269,26 +269,56 @@ public class TBServiceRegionServiceImpl extends ServiceImpl<TBServiceRegionMappe
|
|
|
if (Objects.isNull(tbServiceRegion)) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("服务区域规划不存在");
|
|
|
}
|
|
|
- // 同时清除派单和大区经理的关系
|
|
|
- Long serviceId = tbServiceRegion.getServiceId();
|
|
|
- TBService tbService = tbServiceService.getById(serviceId);
|
|
|
- if (ServiceStatusEnum.FINISH.equals(tbService.getStatus())) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception(ServiceStatusEnum.FINISH.getTitle() + "的服务单元不能作废");
|
|
|
- }
|
|
|
-
|
|
|
- Long leadId = tbServiceRegion.getLeadId();
|
|
|
- UpdateWrapper<TBCrm> crmUpdateWrapper = new UpdateWrapper<>();
|
|
|
- crmUpdateWrapper.lambda()
|
|
|
- .eq(TBCrm::getServiceId, serviceId)
|
|
|
- .eq(TBCrm::getLeadId, leadId)
|
|
|
- .set(TBCrm::getLeadId, null);
|
|
|
- tbCrmService.update(crmUpdateWrapper);
|
|
|
|
|
|
// 删除派单规划详情
|
|
|
- tbServiceRegionDetailService.remove(new QueryWrapper<TBServiceRegionDetail>().lambda().eq(TBServiceRegionDetail::getServiceRegionId, tbServiceRegion.getId()));
|
|
|
+ List<Long> willDeleteRegionDetailIdList = tbServiceRegionDetailService.list(new QueryWrapper<TBServiceRegionDetail>()
|
|
|
+ .lambda()
|
|
|
+ .eq(TBServiceRegionDetail::getServiceRegionId, tbServiceRegion.getId()))
|
|
|
+ .stream()
|
|
|
+ .map(TBServiceRegionDetail::getId)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 清空之前派单绑定的资源信息
|
|
|
+ if (CollectionUtils.isNotEmpty(willDeleteRegionDetailIdList)) {
|
|
|
+ List<TBCrm> willDisposeCrmList = tbCrmService.list(new QueryWrapper<TBCrm>().lambda().in(TBCrm::getRegionDetailId, willDeleteRegionDetailIdList));
|
|
|
+
|
|
|
+ for (TBCrm tbCrm : willDisposeCrmList) {
|
|
|
+ if (!CrmStatusEnum.UN_PUBLISH.equals(tbCrm.getStatus())){
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("该大区规划中存在已经发布的派单[" + tbCrm.getCrmNo() + "(" + tbCrm.getName() + ")" + "]不能修改区域");
|
|
|
+ }
|
|
|
+ // 之前派单有划定在服务单元 -> 解绑派单所有资源信息
|
|
|
+ List<TBUserArchivesAllocation> dbAllocationList = tbUserArchivesAllocationService.list(new QueryWrapper<TBUserArchivesAllocation>().lambda()
|
|
|
+ .eq(TBUserArchivesAllocation::getCrmNo, tbCrm.getCrmNo())
|
|
|
+ .eq(TBUserArchivesAllocation::getServiceId, tbCrm.getServiceId()));
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(dbAllocationList)) {
|
|
|
+ // 释放工程师资源
|
|
|
+ List<Long> archivesIdList = dbAllocationList.stream().map(TBUserArchivesAllocation::getArchivesId).distinct().collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isNotEmpty(archivesIdList)) {
|
|
|
+ UpdateWrapper<TBUserArchives> archivesUpdateWrapper = new UpdateWrapper<>();
|
|
|
+ archivesUpdateWrapper.lambda()
|
|
|
+ .in(TBUserArchives::getId, archivesIdList)
|
|
|
+ .set(TBUserArchives::getStatus, UserArchivesStatusEnum.FREE);
|
|
|
+ tbUserArchivesService.update(archivesUpdateWrapper);
|
|
|
+ }
|
|
|
+ // 删除之前的派单分配详情
|
|
|
+ tbUserArchivesAllocationService.removeByIds(dbAllocationList.stream().map(TBUserArchivesAllocation::getId).distinct().collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ UpdateWrapper<TBCrm> crmUpdateWrapper = new UpdateWrapper<>();
|
|
|
+ crmUpdateWrapper.lambda()
|
|
|
+ .in(TBCrm::getRegionDetailId, willDeleteRegionDetailIdList)
|
|
|
+ .set(TBCrm::getRegionCoordinatorId, null)
|
|
|
+ .set(TBCrm::getRegionId, null)
|
|
|
+ .set(TBCrm::getRegionDetailId, null)
|
|
|
+ .set(TBCrm::getLeadId, null);
|
|
|
+ tbCrmService.update(crmUpdateWrapper);
|
|
|
+ }
|
|
|
|
|
|
// 删除派单规划
|
|
|
- tbServiceRegion.setEnable(false);
|
|
|
+ tbServiceRegionDetailService.removeByIds(willDeleteRegionDetailIdList);
|
|
|
this.removeById(tbServiceRegion);
|
|
|
}
|
|
|
}
|