Commit a2fbc69b authored by wei's avatar wei 🎱

供方名录编码规则

parent 0dc92b03
package com.yonde.dcs.plan.core.encode;
import com.yonde.dcs.plan.common.vo.ExtSupplierManageVO;
import com.yonde.dcs.plan.core.service.ExtSupplierManageService;
import com.yonde.dex.initialization.encoder.CustomizeEncode;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.Year;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
/**
* 工艺规程自定义编码规则
*/
@Slf4j
@Component
public class ProcessPlanEncode implements CustomizeEncode<ExtSupplierManageVO> {
@Autowired
ExtSupplierManageService extSupplierManageService;
@Override
public synchronized String generateEncode(ExtSupplierManageVO extSupplierManageVO) {
String code = "";
String currentYear = Year.now().getValue() + "";
// 查询出最大编号+1
List<ExtSupplierManageVO> allList = extSupplierManageService.findAll();
allList = allList.stream().sorted(Comparator.comparing(ExtSupplierManageVO::getCreateTime)
.reversed()).collect(Collectors.toList());
// 初始规则 G-1-2024
if (CollectionUtils.isEmpty(allList)) {
code = "G-1-" + currentYear;
} else {
String number = allList.get(0).getNumber();
String[] split = number.split("-");
if (split.length > 2) {
int seq = Integer.parseInt(split[1]) + 1;//每次加1
code = "G-" + seq + "-" + currentYear;
}
}
log.info("generateEncode.code={}", code);
return code;
}
}
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