Commit b1082215 authored by yanghao's avatar yanghao

fix: #803 【客户】6. 创建跟进记录,没有带入编号

parent ec6a10ee
......@@ -221,6 +221,40 @@ public class CodeUtils {
}
}
/**
* 功能描述: 自动生成跟进单单号. 格式: GJ+年份YYYY+六位数
*
* @param maxOddNumbers 数据库中的最新单号
* @return java.lang.String
*/
public static String getOddFollowupNumbers(String maxOddNumbers) {
// 格式: GJ+年份YYYY+六位数
int numberLength = 14;
//获取当前日期并将其进行格式化
String formatYear = getDateTime("yyyy");
int newEndIntNum;
//判断数据中的最大单号是否存在,是否包含当前日期
if (StringUtils.isNotEmpty(maxOddNumbers) && maxOddNumbers.length() == numberLength &&
maxOddNumbers.substring(2, 8).equals(formatYear)) {
//截取后四位数
String endNum = maxOddNumbers.substring(maxOddNumbers.length() - 6);
//把截取的最后六位数解析为int
int endIntNum = Integer.parseInt(endNum);
//在将其加1(自增1)
newEndIntNum = endIntNum + 1;
} else {
// 如果为空(第一次生成)或者当前最大订单号的日期与当前日期不一致说明需要重新计数生成单号
newEndIntNum = 1;
}
//生成单号
String newOddNumber = String.format("%s%s%06d", "GJ", formatYear, newEndIntNum);
//将单号返回
return newOddNumber;
}
/**
* 功能描述: 自动生成收款单单单号
......
......@@ -35,4 +35,6 @@ public interface ErrorCodeConstants {
ErrorCode FOLLOWUP_NOT_EXISTS = new ErrorCode(1005001013, "客户跟进不存在");
ErrorCode FOLLOWUP_ALREADY_SUBMITTED = new ErrorCode(1005001014, "客户跟进已提交不可再修改");
ErrorCode FOLLOWUP_NUMBER_NOT_NULL = new ErrorCode(1005001015, "客户跟进编号不能为空");
}
package cn.iocoder.yudao.module.customer.service.customerFollowup;
import java.text.MessageFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import javax.annotation.Resource;
import cn.iocoder.yudao.framework.apollo.core.event.OrderNumberLogEvent;
import cn.iocoder.yudao.framework.common.util.code.CodeUtils;
import cn.iocoder.yudao.framework.i18n.core.I18nMessage;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils;
......@@ -15,12 +18,16 @@ import cn.iocoder.yudao.module.customer.dal.dataobject.customer.CustomerDO;
import cn.iocoder.yudao.module.customer.dal.dataobject.customerContacts.CustomerContactsDO;
import cn.iocoder.yudao.module.customer.dal.mysql.customer.CustomerMapper;
import cn.iocoder.yudao.module.customer.dal.mysql.customerContacts.CustomerContactsMapper;
import cn.iocoder.yudao.module.customer.enums.ErrorCodeConstants;
import cn.iocoder.yudao.module.customer.service.customerOperateLog.CustomerOperateLogService;
import cn.iocoder.yudao.module.customer.vo.customerOperateLog.CustomerOperateLogCreateReqVO;
import cn.iocoder.yudao.module.ecw.enums.CustomerFollowupStatusEnum;
import cn.iocoder.yudao.module.ecw.enums.CustomerOperateTypeEnum;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO;
import cn.iocoder.yudao.framework.mybatis.core.service.AbstractService;
......@@ -54,36 +61,48 @@ public class CustomerFollowupServiceImpl extends AbstractService<CustomerFollowu
@Resource
private CustomerContactsMapper customerContactsMapper;
// 注入applicationContext
@Resource
private ApplicationContext applicationContext;
private static final String FOLLOWUP_NEW_NUMBER = "followup:new:number";
/**
* 跟进单编号生成方式:GJ+年份+六位数字,按年份累计
* @return
*/
@Override
public String generateFollowupNumber() {
// 获取当前时间的年份
LocalDate now = LocalDate.now();
int year = now.getYear();
// 获取当前年份的初始化时间
LocalDateTime startOfYear = LocalDateTime.of(year, 1, 1, 0, 0, 0, 0);
Date from = Date.from(startOfYear.atZone(ZoneId.systemDefault()).toInstant());
Long count = followupMapper.selectCount(new LambdaQueryWrapperX<CustomerFollowupDO>()
.ge(CustomerFollowupDO::getCreateTime, from));
return String.format("GJ%d%06d", year, count + 1);
// 跟进单号生成
OrderNumberLogEvent event = new OrderNumberLogEvent();
event.setType(6);
event.setNumberKey(FOLLOWUP_NEW_NUMBER);
applicationContext.publishEvent(event);
String newFollowupNumber = CodeUtils.getOddFollowupNumbers(event.getNumber());
return newFollowupNumber;
}
@Override
@Transactional(rollbackFor = Exception.class)
public Long createFollowup(CustomerFollowupCreateReqVO createReqVO) {
// 获取新编号
String newNumber = createReqVO.getNumber();
String number = generateFollowupNumber();
createReqVO.setNumber(number);
// 编号不存在,报异常
if (StringUtils.isBlank(newNumber)) {
throw exception(ErrorCodeConstants.FOLLOWUP_NUMBER_NOT_NULL);
}
// 更新编号,内部会判断冲突
OrderNumberLogEvent event = new OrderNumberLogEvent();
event.setType(6);
event.setNumberKey(FOLLOWUP_NEW_NUMBER);
event.setNewNumber(newNumber);
applicationContext.publishEvent(event);
// 插入
CustomerFollowupDO followup = CustomerFollowupConvert.INSTANCE.convert(createReqVO);
// 设置联系人名称
setContactName(followup);
......
......@@ -42,6 +42,16 @@ public class CustomerFollowupController {
@Resource
private FileMakeApi fileMakeApi;
@GetMapping("/getFollowupNewNumber")
@ApiOperation("获得最新的跟进编号")
public CommonResult<String> getFollowupNewNumber() {
String number = followupService.generateFollowupNumber();
return success(number);
}
@PostMapping("/create")
@ApiOperation("创建客户跟进")
// @PreAuthorize("@ss.hasPermission('customer:followup:create')")
......
......@@ -15,6 +15,7 @@ public enum OrderNumberEnum {
RECEIPT_NO(3, "收款单号"),
PAYMENT_NO(3, "付款单号"),
COMMISSION_PAYMENT_NO(5, "佣金付款单号"),
FOLLOWUP_NO(6, "跟进单号"),
;
/**
* 类型
......
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