浏览代码

add:派单新增编辑

caozixuan 1 年之前
父节点
当前提交
4e57c86bb6

+ 3 - 2
sop-api/src/main/java/com/qmth/sop/server/api/TBCrmController.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.constant.ApiConstant;
+import com.qmth.sop.business.bean.params.TBCrmParam;
 import com.qmth.sop.business.bean.result.DingElementResult;
 import com.qmth.sop.business.bean.result.ServiceRegionDetailResult;
 import com.qmth.sop.business.bean.result.TBCrmResult;
@@ -73,11 +74,11 @@ public class TBCrmController {
     @RequestMapping(value = "/save", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})
     @OperationLog(logType = LogTypeEnum.EDIT)
-    public Result save(@Valid @ApiParam(value = "派单信息表信息", required = true) @RequestBody(required = true) TBCrm tBCrm, BindingResult bindingResult) throws InterruptedException {
+    public Result save(@Valid @ApiParam(value = "派单信息表信息", required = true) @RequestBody TBCrmParam tbCrmParam, BindingResult bindingResult) throws InterruptedException {
         if (bindingResult.hasErrors()) {
             return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
         }
-        return ResultUtil.ok(tBCrmService.saveTBCrm(tBCrm));
+        return ResultUtil.ok(tBCrmService.saveTBCrm(tbCrmParam));
     }
 
 

+ 134 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/params/TBCrmParam.java

@@ -0,0 +1,134 @@
+package com.qmth.sop.business.bean.params;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.sop.common.annotation.EditKey;
+import io.swagger.annotations.ApiModelProperty;
+import org.hibernate.validator.constraints.Range;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @Description: 派单参数
+ * @Author: CaoZixuan
+ * @Date: 2024-05-16
+ */
+public class TBCrmParam {
+
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "派单id")
+    @EditKey
+    private Long id;
+
+    @ApiModelProperty(value = "项目名称")
+    @NotNull(message = "缺少项目名称")
+    @NotBlank(message = "缺少项目名称")
+    private String crmName;
+
+    @ApiModelProperty(value = "项目单号")
+    @NotNull(message = "缺少项目单号")
+    @NotBlank(message = "缺少项目单号")
+    private String crmNo;
+
+    @ApiModelProperty(value = "派单时间")
+    @NotNull(message = "派单时间不能为空")
+    @Range(min = 1L, message = "请提供派单时间")
+    private Long beginTime;
+
+    @ApiModelProperty(value = "客户经理id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    @NotNull(message = "客户经理不能为空")
+    @Range(min = 1L, message = "请提供客户经理")
+    private Long crmUserId;
+
+    @ApiModelProperty(value = "客户id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    @NotNull(message = "客户不能为空")
+    @Range(min = 1L, message = "请提供客户")
+    private Long customId;
+
+    @ApiModelProperty(value = "考试开始时间")
+    private Long examStartTime;
+
+    @ApiModelProperty(value = "考试结束时间")
+    private Long examEndTime;
+
+    @ApiModelProperty(value = "产品id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    @NotNull(message = "产品不能为空")
+    @Range(min = 1L, message = "请提供产品")
+    private Long productId;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getCrmName() {
+        return crmName;
+    }
+
+    public void setCrmName(String crmName) {
+        this.crmName = crmName;
+    }
+
+    public String getCrmNo() {
+        return crmNo;
+    }
+
+    public void setCrmNo(String crmNo) {
+        this.crmNo = crmNo;
+    }
+
+    public Long getBeginTime() {
+        return beginTime;
+    }
+
+    public void setBeginTime(Long beginTime) {
+        this.beginTime = beginTime;
+    }
+
+    public Long getCrmUserId() {
+        return crmUserId;
+    }
+
+    public void setCrmUserId(Long crmUserId) {
+        this.crmUserId = crmUserId;
+    }
+
+    public Long getCustomId() {
+        return customId;
+    }
+
+    public void setCustomId(Long customId) {
+        this.customId = customId;
+    }
+
+    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 Long getProductId() {
+        return productId;
+    }
+
+    public void setProductId(Long productId) {
+        this.productId = productId;
+    }
+}

+ 1 - 1
sop-business/src/main/java/com/qmth/sop/business/entity/TBCrm.java

@@ -54,7 +54,7 @@ public class TBCrm extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "考试开始时间")
     private Long examStartTime;
 
-    @ApiModelProperty(value = "考试结束时间")
+    @ApiModelProperty(value = "考试开始时间")
     private Long examEndTime;
 
     @ApiModelProperty(value = "产品id")

+ 3 - 0
sop-business/src/main/java/com/qmth/sop/business/service/TBCrmService.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.sop.business.bean.dto.SopCrmInfo;
 import com.qmth.sop.business.bean.params.ServiceScopeParam;
+import com.qmth.sop.business.bean.params.TBCrmParam;
 import com.qmth.sop.business.bean.result.CrmProjectResult;
 import com.qmth.sop.business.bean.result.CrmServiceResult;
 import com.qmth.sop.business.bean.result.CrmSubTotalResult;
@@ -114,6 +115,8 @@ public interface TBCrmService extends IService<TBCrm> {
      */
     Boolean saveTBCrm(TBCrm tBCrm);
 
+    Long saveTBCrm(TBCrmParam tbCrmParam);
+
     /**
      * 删除派单信息表
      *

+ 95 - 0
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBCrmServiceImpl.java

@@ -11,6 +11,7 @@ import com.qmth.sop.business.bean.dto.RoleDto;
 import com.qmth.sop.business.bean.dto.SopCrmInfo;
 import com.qmth.sop.business.bean.dto.UserArchivesDto;
 import com.qmth.sop.business.bean.params.ServiceScopeParam;
+import com.qmth.sop.business.bean.params.TBCrmParam;
 import com.qmth.sop.business.bean.result.*;
 import com.qmth.sop.business.entity.*;
 import com.qmth.sop.business.mapper.TBCrmMapper;
@@ -84,6 +85,9 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
     @Resource
     private SysMessageService sysMessageService;
 
+    @Resource
+    private SysUserRoleService sysUserRoleService;
+
     @Override
     public IPage<CrmServiceResult> findServiceScopePage(Long serviceUnitId, String city, ProductTypeEnum productType,
             String customName, Boolean bindStatus, Integer pageNumber, Integer pageSize) {
@@ -264,6 +268,97 @@ public class TBCrmServiceImpl extends ServiceImpl<TBCrmMapper, TBCrm> implements
         return null;
     }
 
+    @Transactional
+    @Override
+    public Long saveTBCrm(TBCrmParam tbCrmParam) {
+        SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
+        try {
+            Long id = tbCrmParam.getId();
+            String crmName = tbCrmParam.getCrmName();
+            String crmNo = tbCrmParam.getCrmNo();
+            Long beginTime = tbCrmParam.getBeginTime();
+            Long crmUserId = tbCrmParam.getCrmUserId();
+            Long customId = tbCrmParam.getCustomId();
+            Long examStartTime = tbCrmParam.getExamStartTime();
+            Long examEndTime = tbCrmParam.getExamEndTime();
+            Long productId = tbCrmParam.getProductId();
+
+            if (examStartTime > 0 && examEndTime > 0 && examEndTime < examStartTime) {
+                throw ExceptionResultEnum.ERROR.exception("考试结束时间不能小于考试开始时间");
+            }
+            TBCrm checkCrmNo = this.getOne(
+                    new QueryWrapper<TBCrm>().lambda().eq(TBCrm::getCrmNo, crmNo).last(SystemConstant.LIMIT1));
+            if (Objects.nonNull(checkCrmNo) && !Objects.equals(checkCrmNo.getId(), id)) {
+                throw ExceptionResultEnum.ERROR.exception("派单号不能重复");
+            }
+            if (!sysUserRoleService.userContainsRoles(crmUserId, RoleTypeEnum.ACCOUNT_MANAGER)) {
+                throw ExceptionResultEnum.ERROR.exception("未找到客户经理信息");
+            }
+            if (Objects.isNull(sysCustomService.getById(customId))) {
+                throw ExceptionResultEnum.ERROR.exception("未找到客户信息");
+            }
+            if (Objects.isNull(tbProductService.getById(productId))) {
+                throw ExceptionResultEnum.ERROR.exception("未找到产品信息");
+            }
+
+            if (Objects.isNull(id)) {
+                // id不存在新增
+                TBCrm tbCrm = new TBCrm();
+                tbCrm.setName(crmName);
+                tbCrm.setCrmNo(crmNo);
+                tbCrm.setBeginTime(beginTime);
+                tbCrm.setCrmUserId(crmUserId);
+                tbCrm.setCustomId(customId);
+                if (examStartTime > 0) {
+                    tbCrm.setExamStartTime(examStartTime);
+                }
+                if (examEndTime > 0) {
+                    tbCrm.setExamEndTime(examEndTime);
+                }
+                tbCrm.setProductId(productId);
+
+                tbCrm.setSync(false);
+                tbCrm.setEnable(true);
+                tbCrm.setStatus(CrmStatusEnum.UN_PUBLISH);
+                tbCrm.insertInfo(sysUser.getId());
+                this.save(tbCrm);
+                id = tbCrm.getId();
+            } else {
+                // id存在更新
+                TBCrm dbTBCrm = this.getById(id);
+                if (Objects.isNull(dbTBCrm)) {
+                    throw ExceptionResultEnum.ERROR.exception("未找到派单信息");
+                }
+                dbTBCrm.setName(crmName);
+                dbTBCrm.setCrmNo(crmNo);
+                dbTBCrm.setBeginTime(beginTime);
+                dbTBCrm.setCrmUserId(crmUserId);
+                dbTBCrm.setCustomId(customId);
+                if (examStartTime > 0) {
+                    dbTBCrm.setExamStartTime(examStartTime);
+                }
+                if (examEndTime > 0) {
+                    dbTBCrm.setExamEndTime(examEndTime);
+                }
+                dbTBCrm.setProductId(productId);
+                dbTBCrm.updateInfo(sysUser.getId());
+                this.updateById(dbTBCrm);
+            }
+            return id;
+        } catch (Exception e) {
+            if (e instanceof DuplicateKeyException) {
+                String errorColumn = e.getCause().toString();
+                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());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
+            return null;
+        }
+    }
+
     /**
      * 删除派单信息表
      *