Browse Source

add:查询项目派单信息

caozixuan 1 year ago
parent
commit
9275d7c696

+ 47 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/dto/UserArchivesDto.java

@@ -0,0 +1,47 @@
+package com.qmth.sop.business.bean.dto;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * @Description: 用户档案dto
+ * @Author: CaoZixuan
+ * @Date: 2023-08-31
+ */
+public class UserArchivesDto {
+    @ApiModelProperty("用户id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long userId;
+
+    @ApiModelProperty("档案id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long userArchivesId;
+
+    @ApiModelProperty("名称")
+    private String name;
+
+    public Long getUserId() {
+        return userId;
+    }
+
+    public void setUserId(Long userId) {
+        this.userId = userId;
+    }
+
+    public Long getUserArchivesId() {
+        return userArchivesId;
+    }
+
+    public void setUserArchivesId(Long userArchivesId) {
+        this.userArchivesId = userArchivesId;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+}

+ 157 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/result/CrmProjectResult.java

@@ -0,0 +1,157 @@
+package com.qmth.sop.business.bean.result;
+
+import com.qmth.sop.business.bean.dto.UserArchivesDto;
+import com.qmth.sop.common.enums.ProductTypeEnum;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.util.List;
+
+/**
+ * @Description: 项目派单信息
+ * @Author: CaoZixuan
+ * @Date: 2023-08-31
+ */
+public class CrmProjectResult {
+    @ApiModelProperty("项目单号")
+    private String crmNo;
+
+    @ApiModelProperty("项目名称")
+    private String crmName;
+
+    @ApiModelProperty("派单时间")
+    private Long crmBeginTime;
+
+    @ApiModelProperty("客户经理")
+    private String crmUserName;
+
+    @ApiModelProperty("客户类型")
+    private ProductTypeEnum customType;
+
+    @ApiModelProperty("客户名称")
+    private String customName;
+
+    @ApiModelProperty("考试开始时间")
+    private Long examStartTime;
+
+    @ApiModelProperty("考试开始时间")
+    private Long examEndTime;
+
+    @ApiModelProperty("实施产品")
+    private String productName;
+
+    @ApiModelProperty("服务单元")
+    private String serviceUnitName;
+
+    @ApiModelProperty("区域负责人名称")
+    private String regionCoordinatorName;
+
+    @ApiModelProperty("实施工程师集合")
+    private List<UserArchivesDto> effectEngineerList;
+
+    @ApiModelProperty("助理工程师集合")
+    private List<UserArchivesDto> assistantEngineerList;
+
+    public String getCrmNo() {
+        return crmNo;
+    }
+
+    public void setCrmNo(String crmNo) {
+        this.crmNo = crmNo;
+    }
+
+    public String getCrmName() {
+        return crmName;
+    }
+
+    public void setCrmName(String crmName) {
+        this.crmName = crmName;
+    }
+
+    public Long getCrmBeginTime() {
+        return crmBeginTime;
+    }
+
+    public void setCrmBeginTime(Long crmBeginTime) {
+        this.crmBeginTime = crmBeginTime;
+    }
+
+    public String getCrmUserName() {
+        return crmUserName;
+    }
+
+    public void setCrmUserName(String crmUserName) {
+        this.crmUserName = crmUserName;
+    }
+
+    public ProductTypeEnum getCustomType() {
+        return customType;
+    }
+
+    public void setCustomType(ProductTypeEnum customType) {
+        this.customType = customType;
+    }
+
+    public String getCustomName() {
+        return customName;
+    }
+
+    public void setCustomName(String customName) {
+        this.customName = customName;
+    }
+
+    public Long getExamStartTime() {
+        return examStartTime;
+    }
+
+    public void setExamStartTime(Long examStartTime) {
+        this.examStartTime = examStartTime;
+    }
+
+    public Long getExamEndTime() {
+        return examEndTime;
+    }
+
+    public void setExamEndTime(Long examEndTime) {
+        this.examEndTime = examEndTime;
+    }
+
+    public String getProductName() {
+        return productName;
+    }
+
+    public void setProductName(String productName) {
+        this.productName = productName;
+    }
+
+    public String getServiceUnitName() {
+        return serviceUnitName;
+    }
+
+    public void setServiceUnitName(String serviceUnitName) {
+        this.serviceUnitName = serviceUnitName;
+    }
+
+    public String getRegionCoordinatorName() {
+        return regionCoordinatorName;
+    }
+
+    public void setRegionCoordinatorName(String regionCoordinatorName) {
+        this.regionCoordinatorName = regionCoordinatorName;
+    }
+
+    public List<UserArchivesDto> getEffectEngineerList() {
+        return effectEngineerList;
+    }
+
+    public void setEffectEngineerList(List<UserArchivesDto> effectEngineerList) {
+        this.effectEngineerList = effectEngineerList;
+    }
+
+    public List<UserArchivesDto> getAssistantEngineerList() {
+        return assistantEngineerList;
+    }
+
+    public void setAssistantEngineerList(List<UserArchivesDto> assistantEngineerList) {
+        this.assistantEngineerList = assistantEngineerList;
+    }
+}

+ 15 - 5
sop-business/src/main/java/com/qmth/sop/business/mapper/TBCrmMapper.java

@@ -3,6 +3,7 @@ package com.qmth.sop.business.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.qmth.sop.business.bean.result.CrmProjectResult;
 import com.qmth.sop.business.bean.result.CrmServiceResult;
 import com.qmth.sop.business.bean.result.SysLogResult;
 import com.qmth.sop.business.bean.result.TBCrmResult;
@@ -69,11 +70,20 @@ public interface TBCrmMapper extends BaseMapper<TBCrm> {
      */
     List<CrmServiceResult> findOrderListByServiceIds(@Param("serviceIdList") List<Long> serviceIdList);
 
-	/**
-	 * 查询列表
-	 * @param iPage
-	 * @return
-	 */
+    /**
+     * 查询列表
+     *
+     * @param iPage
+     * @return
+     */
 
     IPage<TBCrmResult> query(IPage<Map> iPage, @Param("serviceId") Long serviceId, @Param("leadId") Long leadId, @Param("crmUserId") Long crmUserId, @Param("type") String type, @Param("custom") String custom, @Param("crmNo") String crmNo, @Param("startTime") Long startTime, @Param("endTime") Long endTime);
+
+    /**
+     * 根据sopNo查询派单项目信息
+     *
+     * @param sopNo sop号
+     * @return 派单项目结果
+     */
+    List<CrmProjectResult> findCrmProjectBySopNo(@Param("sopNo") String sopNo);
 }

+ 10 - 2
sop-business/src/main/java/com/qmth/sop/business/service/TBCrmService.java

@@ -1,9 +1,9 @@
 package com.qmth.sop.business.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.sop.business.bean.params.ServiceScopeParam;
+import com.qmth.sop.business.bean.result.CrmProjectResult;
 import com.qmth.sop.business.bean.result.CrmServiceResult;
 import com.qmth.sop.business.bean.result.CrmSubTotalResult;
 import com.qmth.sop.business.bean.result.TBCrmResult;
@@ -83,13 +83,13 @@ public interface TBCrmService extends IService<TBCrm> {
 
     /**
      * 根据编号查询crm
+     *
      * @param crmNo crm单号
      * @return crm
      */
     TBCrm findByCrmNo(String crmNo);
 
 
-
     /**
      * 查询列表
      *
@@ -97,6 +97,7 @@ public interface TBCrmService extends IService<TBCrm> {
      * @return
      */
     IPage<TBCrmResult> query(IPage<Map> iPage, Long serviceId, Long leadId, Long crmUserId, ProductTypeEnum type, String custom, String crmNo, Long startTime, Long endTime);
+
     /**
      * 新增修改派单信息表
      *
@@ -116,4 +117,11 @@ public interface TBCrmService extends IService<TBCrm> {
 
     boolean batchDisable(long[] crmIds);
 
+    /**
+     * 根据sopNo查询项目派单信息
+     *
+     * @param sopNo sopNo
+     * @return 项目派单信息
+     */
+    CrmProjectResult findCrmProjectBySopNo(String sopNo);
 }

+ 101 - 52
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBCrmServiceImpl.java

@@ -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;
+    }
 }

+ 33 - 0
sop-business/src/main/resources/mapper/TBCrmMapper.xml

@@ -185,4 +185,37 @@
         ORDER BY
         a.create_time DESC
     </select>
+    <select id="findCrmProjectBySopNo" resultType="com.qmth.sop.business.bean.result.CrmProjectResult">
+        SELECT
+            tbc.crm_no AS crmNo,
+            tbc.name AS crmName,
+            tbc.begin_time AS crmBeginTime,
+            manager.real_name AS crmUserName,
+            sc.type AS customType,
+            sc.name AS customName,
+            tbc.exam_start_time AS examStartTime,
+            tbc.exam_end_time AS examEndTime,
+            tbp.name AS productName,
+            tbs.name AS serviceUnitName,
+            region.real_name AS regionCoordinatorName
+        FROM
+            t_f_custom_flow_entity tfcfe
+                LEFT JOIN
+            t_b_crm tbc ON tfcfe.crm_no = tbc.crm_no
+                LEFT JOIN
+            sys_user manager ON tbc.crm_user_id = manager.id
+                LEFT JOIN
+            sys_custom sc ON tbc.custom_id = sc.id
+                LEFT JOIN
+            t_b_product tbp ON tbc.product_id = tbp.id
+                LEFT JOIN
+            t_b_service tbs ON tbc.service_id = tbs.id
+                LEFT JOIN
+            sys_user region ON tbc.region_coordinator_id = region.id
+        <where>
+            <if test="sopNo != null and sopNo != ''">
+                AND tfcfe.code = #{sopNo}
+            </if>
+        </where>
+    </select>
 </mapper>