|
@@ -6,21 +6,17 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
|
+import com.qmth.sop.business.bean.dto.UserArchivesDto;
|
|
|
import com.qmth.sop.business.bean.params.ServiceScopeParam;
|
|
|
-import com.qmth.sop.business.bean.result.CrmServiceResult;
|
|
|
-import com.qmth.sop.business.bean.result.CrmSubTotalResult;
|
|
|
-import com.qmth.sop.business.bean.result.TBCrmResult;
|
|
|
+import com.qmth.sop.business.bean.result.*;
|
|
|
import com.qmth.sop.business.entity.SysUser;
|
|
|
import com.qmth.sop.business.entity.TBCrm;
|
|
|
import com.qmth.sop.business.entity.TBService;
|
|
|
+import com.qmth.sop.business.entity.TBUserArchivesAllocation;
|
|
|
import com.qmth.sop.business.mapper.TBCrmMapper;
|
|
|
-import com.qmth.sop.business.service.TBCrmService;
|
|
|
-import com.qmth.sop.business.service.TBServiceService;
|
|
|
+import com.qmth.sop.business.service.*;
|
|
|
import com.qmth.sop.common.contant.SystemConstant;
|
|
|
-import com.qmth.sop.common.enums.ExceptionResultEnum;
|
|
|
-import com.qmth.sop.common.enums.FieldUniqueEnum;
|
|
|
-import com.qmth.sop.common.enums.ProductTypeEnum;
|
|
|
-import com.qmth.sop.common.enums.ServiceStatusEnum;
|
|
|
+import com.qmth.sop.common.enums.*;
|
|
|
import com.qmth.sop.common.util.ResultUtil;
|
|
|
import com.qmth.sop.common.util.ServletUtil;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
@@ -31,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -44,6 +41,12 @@ import java.util.stream.Collectors;
|
|
|
public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements TBCrmService {
|
|
|
@Resource
|
|
|
private TBServiceService tbServiceService;
|
|
|
+ @Resource
|
|
|
+ private TBUserArchivesAllocationService tbUserArchivesAllocationService;
|
|
|
+ @Resource
|
|
|
+ private SysRoleService sysRoleService;
|
|
|
+ @Resource
|
|
|
+ private TBUserArchivesService tbUserArchivesService;
|
|
|
|
|
|
@Override
|
|
|
public IPage<CrmServiceResult> findServiceScopePage(Long serviceUnitId, String city, ProductTypeEnum productType, String customName, Boolean bindStatus, Integer pageNumber, Integer pageSize) {
|
|
@@ -111,7 +114,7 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
|
|
|
}
|
|
|
}
|
|
|
UpdateWrapper<TBCrm> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper.lambda().set(TBCrm::getServiceId,null).eq(TBCrm::getId,tbCrm.getId());
|
|
|
+ updateWrapper.lambda().set(TBCrm::getServiceId, null).eq(TBCrm::getId, tbCrm.getId());
|
|
|
this.update(updateWrapper);
|
|
|
}
|
|
|
|
|
@@ -146,53 +149,53 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
|
|
|
|
|
|
@Override
|
|
|
public IPage<TBCrmResult> query(IPage<Map> iPage, Long serviceId, Long leadId, Long crmUserId, ProductTypeEnum type, String custom, String crmNo, Long startTime, Long endTime) {
|
|
|
- return this.baseMapper.query(iPage ,serviceId,leadId,crmUserId,Objects.nonNull(type)?type.name():null,custom,crmNo,startTime,endTime);
|
|
|
+ return this.baseMapper.query(iPage, serviceId, leadId, crmUserId, Objects.nonNull(type) ? type.name() : null, custom, crmNo, startTime, endTime);
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 新增修改派单信息表
|
|
|
- *
|
|
|
- * @param tBCrm
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Transactional
|
|
|
- public Boolean saveTBCrm(TBCrm tBCrm) {
|
|
|
- try {
|
|
|
+ /**
|
|
|
+ * 新增修改派单信息表
|
|
|
+ *
|
|
|
+ * @param tBCrm
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Boolean saveTBCrm(TBCrm tBCrm) {
|
|
|
+ try {
|
|
|
tBCrm.setSync(false);
|
|
|
tBCrm.setEnable(true);
|
|
|
- SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
- if (Objects.isNull(tBCrm.getId())) {// 新增
|
|
|
- tBCrm.insertInfo(sysUser.getId());
|
|
|
- } else { // 修改
|
|
|
- tBCrm.updateInfo(sysUser.getId());
|
|
|
- }
|
|
|
- return saveOrUpdate(tBCrm);
|
|
|
- } catch (Exception e) {
|
|
|
- if (e instanceof DuplicateKeyException) {
|
|
|
- String errorColumn = e.getCause().toString();
|
|
|
- String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
|
|
|
- throw ExceptionResultEnum.SQL_ERROR.exception("[" + FieldUniqueEnum.convertToTitle(columnStr) + "]数据不允许重复插入");
|
|
|
- } else if (e instanceof ApiException) {
|
|
|
- ResultUtil.error((ApiException) e, e.getMessage());
|
|
|
- } else {
|
|
|
- ResultUtil.error(e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除派单信息表
|
|
|
- *
|
|
|
- * @param id
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Transactional
|
|
|
- public Boolean delete(Long id) {
|
|
|
- return this.removeById(id);
|
|
|
- }
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
+ if (Objects.isNull(tBCrm.getId())) {// 新增
|
|
|
+ tBCrm.insertInfo(sysUser.getId());
|
|
|
+ } else { // 修改
|
|
|
+ tBCrm.updateInfo(sysUser.getId());
|
|
|
+ }
|
|
|
+ return saveOrUpdate(tBCrm);
|
|
|
+ } catch (Exception e) {
|
|
|
+ if (e instanceof DuplicateKeyException) {
|
|
|
+ String errorColumn = e.getCause().toString();
|
|
|
+ String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
|
|
|
+ throw ExceptionResultEnum.SQL_ERROR.exception("[" + FieldUniqueEnum.convertToTitle(columnStr) + "]数据不允许重复插入");
|
|
|
+ } else if (e instanceof ApiException) {
|
|
|
+ ResultUtil.error((ApiException) e, e.getMessage());
|
|
|
+ } else {
|
|
|
+ ResultUtil.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除派单信息表
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Boolean delete(Long id) {
|
|
|
+ return this.removeById(id);
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
@@ -213,4 +216,50 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
|
|
|
return this.updateBatchById(tbCrmList);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public CrmProjectResult findCrmProjectBySopNo(String sopNo) {
|
|
|
+ CrmProjectResult result = new CrmProjectResult();
|
|
|
+ List<CrmProjectResult> crmProjectResults = this.baseMapper.findCrmProjectBySopNo(sopNo);
|
|
|
+ if (CollectionUtils.isNotEmpty(crmProjectResults)) {
|
|
|
+ if (crmProjectResults.size() > 1) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("根据sop号找到多个与之对应的派单异常");
|
|
|
+ }
|
|
|
+ CrmProjectResult crmProjectResult = crmProjectResults.get(0);
|
|
|
+ String crmNo = crmProjectResult.getCrmNo();
|
|
|
+
|
|
|
+ List<TBUserArchivesAllocation> archivesAllocationList = tbUserArchivesAllocationService.list(new QueryWrapper<TBUserArchivesAllocation>()
|
|
|
+ .lambda().eq(TBUserArchivesAllocation::getCrmNo, crmNo));
|
|
|
+
|
|
|
+ RoleResult effectRole = sysRoleService.findRoleInfoByArchivesType(RoleTypeEnum.EFFECT_ENGINEER);
|
|
|
+ Long effectRoleId = effectRole.getRoleId();
|
|
|
+
|
|
|
+ List<UserArchivesDto> effectEngineerList = archivesAllocationList.stream()
|
|
|
+ .filter(e -> effectRoleId.equals(e.getRoleId()))
|
|
|
+ .flatMap(e -> {
|
|
|
+ UserArchivesDto dto = new UserArchivesDto();
|
|
|
+ Long userArchivesId = e.getArchivesId();
|
|
|
+ dto.setUserArchivesId(userArchivesId);
|
|
|
+ dto.setUserId(e.getUserId());
|
|
|
+ dto.setName(tbUserArchivesService.getById(userArchivesId).getName());
|
|
|
+ return Stream.of(dto);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ RoleResult assistant = sysRoleService.findRoleInfoByArchivesType(RoleTypeEnum.ASSISTANT_ENGINEER);
|
|
|
+ Long assistantRoleId = assistant.getRoleId();
|
|
|
+ List<UserArchivesDto> assistantEngineerList = archivesAllocationList.stream()
|
|
|
+ .filter(e -> assistantRoleId.equals(e.getRoleId()))
|
|
|
+ .flatMap(e -> {
|
|
|
+ UserArchivesDto dto = new UserArchivesDto();
|
|
|
+ Long userArchivesId = e.getArchivesId();
|
|
|
+ dto.setUserArchivesId(userArchivesId);
|
|
|
+ dto.setUserId(e.getUserId());
|
|
|
+ dto.setName(tbUserArchivesService.getById(userArchivesId).getName());
|
|
|
+ return Stream.of(dto);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ crmProjectResult.setEffectEngineerList(effectEngineerList);
|
|
|
+ crmProjectResult.setAssistantEngineerList(assistantEngineerList);
|
|
|
+ result = crmProjectResult;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|