Commit 705da10d authored by zhengyi's avatar zhengyi

补充跟进必填字段逻辑校验

parent ef71df7c
......@@ -37,4 +37,17 @@ public interface ErrorCodeConstants {
ErrorCode FOLLOWUP_NUMBER_NOT_NULL = new ErrorCode(1005001015, "客户跟进编号不能为空");
ErrorCode FOLLOWUP_TYPE_NOT_NULL = new ErrorCode(1005001016, "请选择跟进类型");
ErrorCode BUSINESS_OPPORTUNITY_FOLLOWUP_OFFER_NOT_NULL = new ErrorCode(1005001017, "商机跟进时,请选择报价单");
ErrorCode CUSTOMER_NOT_NULL = new ErrorCode(1005001018, "请选择客户");
ErrorCode CUSTOMER_CONTACT_NOT_NULL = new ErrorCode(1005001019, "请选择客户联系人");
ErrorCode FOLLOWUP_TIME_NOT_NULL = new ErrorCode(1005001020, "请选择跟进时间");
ErrorCode FOLLOWUP_METHOD_NOT_NULL = new ErrorCode(1005001021, "请选择跟进方式");
ErrorCode CUSTOMER_SERVICE_NOT_NULL = new ErrorCode(1005001022, "请选择客户经理");
ErrorCode FOLLOWUP_RESULT_NOT_NULL = new ErrorCode(1005001023, "请选择跟进结果");
ErrorCode FOLLOWUP_PURPOSE_NOT_NULL = new ErrorCode(1005001024, "请填写跟进目的");
ErrorCode FOLLOWUP_FEEFBACK_NOT_NULL = new ErrorCode(1005001025, "请填写跟进情况");
ErrorCode NEXT_FOLLOWUP_TIME_NOT_NULL = new ErrorCode(1005001026, "请选择下次跟进时间");
ErrorCode NEXT_FOLLOWUP_PLAN_NOT_NULL = new ErrorCode(1005001027, "请填写下一步计划");
}
......@@ -24,7 +24,10 @@ import cn.iocoder.yudao.module.ecw.enums.CustomerFollowupStatusEnum;
import cn.iocoder.yudao.module.ecw.enums.CustomerOperateTypeEnum;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
......@@ -36,8 +39,8 @@ import java.util.List;
import java.util.Objects;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.customer.enums.ErrorCodeConstants.FOLLOWUP_ALREADY_SUBMITTED;
import static cn.iocoder.yudao.module.customer.enums.ErrorCodeConstants.FOLLOWUP_NOT_EXISTS;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
import static cn.iocoder.yudao.module.customer.enums.ErrorCodeConstants.*;
/**
* 客户跟进 Service 实现类
......@@ -93,6 +96,7 @@ public class CustomerFollowupServiceImpl extends AbstractService<CustomerFollowu
@Override
@Transactional(rollbackFor = Exception.class)
public Long createFollowup(CustomerFollowupCreateReqVO createReqVO) {
// 更新编号,内部会判断冲突
//OrderNumberLogListener
OrderNumberLogEvent event = new OrderNumberLogEvent();
......@@ -106,6 +110,12 @@ public class CustomerFollowupServiceImpl extends AbstractService<CustomerFollowu
applicationContext.publishEvent(event);
// 插入
CustomerFollowupDO followup = CustomerFollowupConvert.INSTANCE.convert(createReqVO);
if (Objects.isNull(followup.getFollowType())){
throw exception(FOLLOWUP_TYPE_NOT_NULL);
}
if (followup.getFollowType() == 2 && Objects.isNull(followup.getOfferId())){
throw exception(BUSINESS_OPPORTUNITY_FOLLOWUP_OFFER_NOT_NULL);
}
// 设置联系人名称
setContactName(followup);
followup.setNumber(newNumber);
......@@ -113,6 +123,10 @@ public class CustomerFollowupServiceImpl extends AbstractService<CustomerFollowu
// 获取客户经理的部门id
followup.setDeptId(adminUserApi.getUserDeptId(followup.getFollowUserId()));
}
// 当跟进为提交结果时,除附件和上级跟进单非必填,其他参数都时必填
if (followup.getStatus() == 1){
validateFollowupMustParams(followup);
}
followupMapper.insert(followup);
Long customerId = createReqVO.getCustomerId();
......@@ -143,6 +157,40 @@ public class CustomerFollowupServiceImpl extends AbstractService<CustomerFollowu
return followup.getId();
}
private void validateFollowupMustParams(CustomerFollowupDO followup) {
if (Objects.isNull(followup.getCustomerId())){
throw exception(CUSTOMER_NOT_NULL);
}
if (Objects.isNull(followup.getContactId())){
throw exception(CUSTOMER_CONTACT_NOT_NULL);
}
if (Objects.isNull(followup.getFollowTime())){
throw exception(FOLLOWUP_TIME_NOT_NULL);
}
if (Objects.isNull(followup.getFollowMethod())){
throw exception(FOLLOWUP_METHOD_NOT_NULL);
}
if (Objects.isNull(followup.getFollowUserId())){
throw exception(CUSTOMER_SERVICE_NOT_NULL);
}
if (Objects.isNull(followup.getResultType())){
throw exception(FOLLOWUP_RESULT_NOT_NULL);
}
if (StringUtils.isBlank(followup.getPurpose())){
throw exception(FOLLOWUP_PURPOSE_NOT_NULL);
}
if (StringUtils.isBlank(followup.getFeedback())){
throw exception(FOLLOWUP_FEEFBACK_NOT_NULL);
}
if (Objects.isNull(followup.getNextTime())){
throw exception(NEXT_FOLLOWUP_TIME_NOT_NULL);
}
if (StringUtils.isBlank(followup.getNextPlan())){
throw exception(NEXT_FOLLOWUP_PLAN_NOT_NULL);
}
}
private void setContactName(CustomerFollowupDO followup) {
// 设置联系人名称
Long contactId = followup.getContactId();
......@@ -156,6 +204,7 @@ public class CustomerFollowupServiceImpl extends AbstractService<CustomerFollowu
@Override
public void updateFollowup(CustomerFollowupUpdateReqVO updateReqVO) {
// 校验存在
Long id = updateReqVO.getId();
CustomerFollowupDO customerFollowupDO = followupMapper.selectById(id);
......@@ -167,13 +216,22 @@ public class CustomerFollowupServiceImpl extends AbstractService<CustomerFollowu
}
// 更新
CustomerFollowupDO updateObj = CustomerFollowupConvert.INSTANCE.convert(updateReqVO);
if (Objects.isNull(updateObj.getFollowType())){
throw exception(FOLLOWUP_TYPE_NOT_NULL);
}
if (updateObj.getFollowType() == 2 && Objects.isNull(updateObj.getOfferId())){
throw exception(BUSINESS_OPPORTUNITY_FOLLOWUP_OFFER_NOT_NULL);
}
// 设置联系人名称
setContactName(updateObj);
if (Objects.nonNull(updateObj.getFollowUserId())){
// 获取客户经理的部门id
updateObj.setDeptId(adminUserApi.getUserDeptId(updateObj.getFollowUserId()));
}
// 当跟进为提交结果时,除附件和上级跟进单非必填,其他参数都时必填
if (updateObj.getStatus() == 1){
validateFollowupMustParams(updateObj);
}
followupMapper.updateById(updateObj);
Long customerId = updateReqVO.getCustomerId();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment