|
@@ -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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 删除派单信息表
|
|
|
*
|