|
@@ -17,7 +17,6 @@ import com.qmth.sop.business.mapper.TBCrmMapper;
|
|
|
import com.qmth.sop.business.service.*;
|
|
|
import com.qmth.sop.business.sync.FxxkApiUtils;
|
|
|
import com.qmth.sop.business.sync.been.fxxk.FxxkCrm;
|
|
|
-import com.qmth.sop.common.base.BaseEntity;
|
|
|
import com.qmth.sop.common.contant.SystemConstant;
|
|
|
import com.qmth.sop.common.enums.*;
|
|
|
import com.qmth.sop.common.util.ResultUtil;
|
|
@@ -51,7 +50,7 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
|
|
|
@Resource
|
|
|
private TBUserArchivesService tbUserArchivesService;
|
|
|
@Resource
|
|
|
- private TBServiceRegionService tbServiceRegionService;
|
|
|
+ private TBServiceRegionDetailService tbServiceRegionDetailService;
|
|
|
@Resource
|
|
|
private SysUserService sysUserService;
|
|
|
@Resource
|
|
@@ -111,29 +110,7 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
|
|
|
List<TBCrm> tbCrmList = this.listByIds(crmIdList);
|
|
|
// 派单调配资源变换
|
|
|
for (TBCrm dbCrm : tbCrmList) {
|
|
|
- tbUserArchivesAllocationService.crmReBindServiceUnit(dbCrm.getCrmNo(), dbCrm.getServiceId(), serviceUnitId);
|
|
|
- }
|
|
|
-
|
|
|
- // 绑定服务单元
|
|
|
- tbCrmList = tbCrmList.stream().peek(e -> e.setServiceId(serviceUnitId)).collect(Collectors.toList());
|
|
|
- this.updateBatchById(tbCrmList);
|
|
|
-
|
|
|
- // 自动匹配派单对应的大区经理
|
|
|
- tbCrmList = tbCrmList.stream().peek(e -> {
|
|
|
- Long regionLeaderId = tbServiceRegionService.findRegionLeader(serviceUnitId, e.getCrmNo());
|
|
|
- if (Objects.nonNull(regionLeaderId)) {
|
|
|
- e.setLeadId(regionLeaderId);
|
|
|
- }
|
|
|
- }).collect(Collectors.toList());
|
|
|
- this.updateBatchById(tbCrmList);
|
|
|
-
|
|
|
- // 解绑区域协调人
|
|
|
- for (TBCrm tbCrm : tbCrmList) {
|
|
|
- UpdateWrapper<TBCrm> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper.lambda()
|
|
|
- .in(TBCrm::getId, tbCrm.getId())
|
|
|
- .set(TBCrm::getRegionCoordinatorId, null);
|
|
|
- this.update(updateWrapper);
|
|
|
+ this.crmReBindServiceUnit(dbCrm.getCrmNo(), dbCrm.getServiceId(), serviceUnitId);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -152,13 +129,7 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
|
|
|
throw ExceptionResultEnum.ERROR.exception("服务单元的当前状态更新为" + ServiceStatusEnum.FINISH.name() + "不允许移除");
|
|
|
}
|
|
|
}
|
|
|
- UpdateWrapper<TBCrm> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper.lambda()
|
|
|
- .set(TBCrm::getServiceId, null)
|
|
|
- .set(TBCrm::getLeadId, null)
|
|
|
- .eq(TBCrm::getId, tbCrm.getId());
|
|
|
- this.update(updateWrapper);
|
|
|
- tbUserArchivesAllocationService.crmReBindServiceUnit(tbCrm.getCrmNo(), serviceUnitId, null);
|
|
|
+ this.crmReBindServiceUnit(tbCrm.getCrmNo(), serviceUnitId, null);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -201,7 +172,7 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
|
|
|
/**
|
|
|
* 新增修改派单信息表
|
|
|
*
|
|
|
- * @param tBCrm
|
|
|
+ * @param tBCrm tBCrm
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional
|
|
@@ -225,28 +196,14 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
|
|
|
boolean result = saveOrUpdate(tBCrm);
|
|
|
Long serviceId = tBCrm.getServiceId();
|
|
|
if (result) {
|
|
|
- if (serviceId != null && serviceId > 0) {
|
|
|
- // 有服务单元 -> 绑定服务单元和大区经理
|
|
|
- Long regionLeaderId = tbServiceRegionService.findRegionLeader(serviceId, tBCrm.getCrmNo());
|
|
|
- UpdateWrapper<TBCrm> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper.lambda().eq(TBCrm::getId, tBCrm.getId()).set(TBCrm::getLeadId, regionLeaderId);
|
|
|
- this.update(updateWrapper);
|
|
|
- } else {
|
|
|
- // 有服务单元 -> 解绑服务单元和大区经理
|
|
|
- UpdateWrapper<TBCrm> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper.lambda()
|
|
|
- .eq(TBCrm::getId, tBCrm.getId())
|
|
|
- .set(TBCrm::getLeadId, null)
|
|
|
- .set(TBCrm::getServiceId, null);
|
|
|
- this.update(updateWrapper);
|
|
|
- }
|
|
|
+ this.crmReBindServiceUnit(tBCrm.getCrmNo(), oldServiceUnitId, serviceId);
|
|
|
}
|
|
|
- tbUserArchivesAllocationService.crmReBindServiceUnit(tBCrm.getCrmNo(), oldServiceUnitId, serviceId);
|
|
|
+
|
|
|
return result;
|
|
|
} catch (Exception e) {
|
|
|
if (e instanceof DuplicateKeyException) {
|
|
|
String errorColumn = e.getCause().toString();
|
|
|
- String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
|
|
|
+ String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3).replaceAll("'", "");
|
|
|
throw ExceptionResultEnum.SQL_ERROR.exception("[" + FieldUniqueEnum.convertToTitle(columnStr) + "]数据不允许重复插入");
|
|
|
} else if (e instanceof ApiException) {
|
|
|
ResultUtil.error((ApiException) e, ((ApiException) e).getCode(), e.getMessage());
|
|
@@ -255,13 +212,12 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除派单信息表
|
|
|
*
|
|
|
- * @param id
|
|
|
+ * @param id id
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional
|
|
@@ -269,23 +225,6 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
|
|
|
return this.removeById(id);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- @Transactional
|
|
|
- public boolean batchZone(long serviceId, long[] crmIds) {
|
|
|
- List<Long> crmIdList = Arrays.stream(crmIds).boxed().collect(Collectors.toList());
|
|
|
- List<TBCrm> tbCrmList = this.listByIds(crmIdList);
|
|
|
- tbCrmList.forEach(e -> e.setServiceId(serviceId));
|
|
|
- this.updateBatchById(tbCrmList);
|
|
|
-
|
|
|
- tbCrmList.forEach(e -> {
|
|
|
- Long regionLeaderId = tbServiceRegionService.findRegionLeader(serviceId, e.getCrmNo());
|
|
|
- if (Objects.nonNull(regionLeaderId)) {
|
|
|
- e.setLeadId(regionLeaderId);
|
|
|
- }
|
|
|
- });
|
|
|
- return this.updateBatchById(tbCrmList);
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public boolean batchDisable(long[] crmIds) {
|
|
@@ -417,6 +356,64 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
|
|
|
return this.baseMapper.findByTBCrmListByServiceUnitIdAndAddress(serviceUnitId, province, city);
|
|
|
}
|
|
|
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void crmReBindServiceUnit(String crmNo, Long oldServiceUnitId, Long newServiceUnitId) {
|
|
|
+ TBCrm tbCrm = this.findByCrmNo(crmNo);
|
|
|
+ if (CrmStatusEnum.PUBLISH.equals(tbCrm.getStatus())) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(String.format("已发布的派单[%s]不能重新划分,请先撤销发布", tbCrm.getCrmNo()));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (oldServiceUnitId != null && oldServiceUnitId > 0) {
|
|
|
+ // 之前派单有划定在服务单元 -> 解绑派单所有资源信息
|
|
|
+ List<TBUserArchivesAllocation> dbAllocationList = tbUserArchivesAllocationService.list(new QueryWrapper<TBUserArchivesAllocation>().lambda()
|
|
|
+ .eq(TBUserArchivesAllocation::getCrmNo, crmNo)
|
|
|
+ .eq(TBUserArchivesAllocation::getServiceId, oldServiceUnitId));
|
|
|
+
|
|
|
+ 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> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.lambda()
|
|
|
+ .eq(TBCrm::getId, tbCrm.getId())
|
|
|
+ .set(TBCrm::getServiceId, null)
|
|
|
+ .set(TBCrm::getLeadId, null)
|
|
|
+ .set(TBCrm::getRegionId, null)
|
|
|
+ .set(TBCrm::getRegionDetailId, null)
|
|
|
+ .set(TBCrm::getRegionCoordinatorId, null);
|
|
|
+ this.update(updateWrapper);
|
|
|
+ }
|
|
|
+ if (newServiceUnitId != null && newServiceUnitId > 0) {
|
|
|
+ // 为派单划定的新服务单元绑定大区信息
|
|
|
+ UpdateWrapper<TBCrm> bindServiceWrapper = new UpdateWrapper<>();
|
|
|
+ bindServiceWrapper.lambda()
|
|
|
+ .eq(TBCrm::getId, tbCrm.getId())
|
|
|
+ .set(TBCrm::getServiceId, newServiceUnitId);
|
|
|
+ this.update(bindServiceWrapper);
|
|
|
+
|
|
|
+ ServiceRegionDetailResult regionDetail = tbServiceRegionDetailService.findRegionDetail(newServiceUnitId, crmNo);
|
|
|
+ if (Objects.nonNull(regionDetail)) {
|
|
|
+ UpdateWrapper<TBCrm> matchWrapper = new UpdateWrapper<>();
|
|
|
+ matchWrapper.lambda()
|
|
|
+ .eq(TBCrm::getId, tbCrm.getId())
|
|
|
+ .set(TBCrm::getLeadId, regionDetail.getLeadId())
|
|
|
+ .set(TBCrm::getRegionId, regionDetail.getServiceRegionId())
|
|
|
+ .set(TBCrm::getRegionDetailId, regionDetail.getServiceRegionDetailId());
|
|
|
+ this.update(matchWrapper);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public Map<String, Object> syncCrmFromFxxk(Map<String, Object> map) {
|