|
@@ -18,7 +18,6 @@ import com.fjhx.purchase.service.IPurchaseContractService;
|
|
import com.fjhx.reportPrice.service.IReportPriceBillService;
|
|
import com.fjhx.reportPrice.service.IReportPriceBillService;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
-import org.springblade.core.redis.lock.RedisLockClient;
|
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
import org.springblade.core.tool.utils.Func;
|
|
import org.springblade.core.tool.utils.Func;
|
|
import org.springblade.core.tool.utils.SpringUtil;
|
|
import org.springblade.core.tool.utils.SpringUtil;
|
|
@@ -74,7 +73,7 @@ public class CodeRuleUtil {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public static String getCode(int codeRuleType, String customerId, String productId, String countryId) {
|
|
public static String getCode(int codeRuleType, String customerId, String productId, String countryId) {
|
|
- String code = "";
|
|
|
|
|
|
+ StringBuilder code = new StringBuilder();
|
|
|
|
|
|
//获取编码配置规则信息
|
|
//获取编码配置规则信息
|
|
CodeRule rule = iCodeRuleApi.getCodeRule(codeRuleType);
|
|
CodeRule rule = iCodeRuleApi.getCodeRule(codeRuleType);
|
|
@@ -95,19 +94,19 @@ public class CodeRuleUtil {
|
|
Integer key = cr.getInteger("key");
|
|
Integer key = cr.getInteger("key");
|
|
//年份编号
|
|
//年份编号
|
|
if (key == CodeRuleEnum.CODE_RULE_1.getKey()) {
|
|
if (key == CodeRuleEnum.CODE_RULE_1.getKey()) {
|
|
- code += new SimpleDateFormat("yy").format(new Date());
|
|
|
|
|
|
+ code.append(new SimpleDateFormat("yy").format(new Date()));
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
//业务代码
|
|
//业务代码
|
|
if (key == CodeRuleEnum.CODE_RULE_2.getKey()) {
|
|
if (key == CodeRuleEnum.CODE_RULE_2.getKey()) {
|
|
- code += Optional.ofNullable(cr.getString("value")).orElse("");
|
|
|
|
|
|
+ code.append(Optional.ofNullable(cr.getString("value")).orElse(""));
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
//国家代码
|
|
//国家代码
|
|
if (key == CodeRuleEnum.CODE_RULE_3.getKey()) {
|
|
if (key == CodeRuleEnum.CODE_RULE_3.getKey()) {
|
|
City city = iCityApi.getOneById(countryId);
|
|
City city = iCityApi.getOneById(countryId);
|
|
if (Func.isNotEmpty(city)) {
|
|
if (Func.isNotEmpty(city)) {
|
|
- code += Optional.ofNullable(city.getEnglishShort()).orElse("");
|
|
|
|
|
|
+ code.append(Optional.ofNullable(city.getEnglishShort()).orElse(""));
|
|
}
|
|
}
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
@@ -115,7 +114,7 @@ public class CodeRuleUtil {
|
|
if (key == CodeRuleEnum.CODE_RULE_4.getKey()) {
|
|
if (key == CodeRuleEnum.CODE_RULE_4.getKey()) {
|
|
User user = iUserClient.getDetails(AuthUtil.getUserId());
|
|
User user = iUserClient.getDetails(AuthUtil.getUserId());
|
|
if (Func.isNotEmpty(user)) {
|
|
if (Func.isNotEmpty(user)) {
|
|
- code += Optional.ofNullable(user.getDmCode()).orElse("");
|
|
|
|
|
|
+ code.append(Optional.ofNullable(user.getDmCode()).orElse(""));
|
|
}
|
|
}
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
@@ -123,7 +122,7 @@ public class CodeRuleUtil {
|
|
if (key == CodeRuleEnum.CODE_RULE_5.getKey()) {
|
|
if (key == CodeRuleEnum.CODE_RULE_5.getKey()) {
|
|
Customer customer = iCustomerApi.getCustomerById(customerId);
|
|
Customer customer = iCustomerApi.getCustomerById(customerId);
|
|
if (Func.isNotEmpty(customer)) {
|
|
if (Func.isNotEmpty(customer)) {
|
|
- code += Optional.ofNullable(customer.getDmCode()).orElse("");
|
|
|
|
|
|
+ code.append(Optional.ofNullable(customer.getDmCode()).orElse(""));
|
|
}
|
|
}
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
@@ -131,26 +130,24 @@ public class CodeRuleUtil {
|
|
if (key == CodeRuleEnum.CODE_RULE_6.getKey()) {
|
|
if (key == CodeRuleEnum.CODE_RULE_6.getKey()) {
|
|
Product product = iProductService.getById(productId);
|
|
Product product = iProductService.getById(productId);
|
|
if (Func.isNotEmpty(product)) {
|
|
if (Func.isNotEmpty(product)) {
|
|
- code += Optional.ofNullable(product.getDmCode()).orElse("");
|
|
|
|
|
|
+ code.append(Optional.ofNullable(product.getDmCode()).orElse(""));
|
|
}
|
|
}
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
//自增总编号
|
|
//自增总编号
|
|
if (key == CodeRuleEnum.CODE_RULE_7.getKey()) {
|
|
if (key == CodeRuleEnum.CODE_RULE_7.getKey()) {
|
|
- //总编号当前值
|
|
|
|
- String codeCurrentValue = Optional.ofNullable(String.valueOf(rule.getCodeCurrentValue())).orElse("1");
|
|
|
|
- //总编号长度
|
|
|
|
|
|
+ // 总编号当前值
|
|
|
|
+ StringBuilder codeCurrentValue = new StringBuilder(Optional.ofNullable(String.valueOf(rule.getCodeCurrentValue())).orElse("1"));
|
|
|
|
+ // 总编号长度
|
|
int value = Optional.ofNullable(cr.getInteger("value")).orElse(0);
|
|
int value = Optional.ofNullable(cr.getInteger("value")).orElse(0);
|
|
if (codeCurrentValue.length() < value) {
|
|
if (codeCurrentValue.length() < value) {
|
|
- //进行补位
|
|
|
|
|
|
+ // 进行补位
|
|
int complementLength = value - codeCurrentValue.length();
|
|
int complementLength = value - codeCurrentValue.length();
|
|
- if (complementLength > 0) {
|
|
|
|
- for (int i = 0; i < complementLength; i++) {
|
|
|
|
- codeCurrentValue = "0" + codeCurrentValue;
|
|
|
|
- }
|
|
|
|
|
|
+ for (int i = 0; i < complementLength; i++) {
|
|
|
|
+ codeCurrentValue.insert(0, "0");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- code += codeCurrentValue;
|
|
|
|
|
|
+ code.append(codeCurrentValue);
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
//自增自编号
|
|
//自增自编号
|
|
@@ -174,36 +171,33 @@ public class CodeRuleUtil {
|
|
if (codeRuleType == CodeRuleTypeEnum.CODE_RULE_TYPE_4.getKey()) {
|
|
if (codeRuleType == CodeRuleTypeEnum.CODE_RULE_TYPE_4.getKey()) {
|
|
count = iPurchaseContractService.getCount(prefixCode, countryId, customerId, productId);
|
|
count = iPurchaseContractService.getCount(prefixCode, countryId, customerId, productId);
|
|
}
|
|
}
|
|
- //步长1
|
|
|
|
|
|
+ // 步长1
|
|
count++;
|
|
count++;
|
|
- String countStr = String.valueOf(count);
|
|
|
|
- //子编号长度
|
|
|
|
|
|
+ StringBuilder countStr = new StringBuilder(String.valueOf(count));
|
|
|
|
+ // 子编号长度
|
|
int value = Optional.ofNullable(cr.getInteger("value")).orElse(0);
|
|
int value = Optional.ofNullable(cr.getInteger("value")).orElse(0);
|
|
if (countStr.length() < value) {
|
|
if (countStr.length() < value) {
|
|
- //进行补位
|
|
|
|
|
|
+ // 进行补位
|
|
int complementLength = value - countStr.length();
|
|
int complementLength = value - countStr.length();
|
|
- if (complementLength > 0) {
|
|
|
|
- for (int i = 0; i < complementLength; i++) {
|
|
|
|
- countStr = "0" + countStr;
|
|
|
|
- }
|
|
|
|
|
|
+ for (int i = 0; i < complementLength; i++) {
|
|
|
|
+ countStr.insert(0, "0");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- code += countStr;
|
|
|
|
|
|
+ code.append(countStr);
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
//间隔符
|
|
//间隔符
|
|
if (key == CodeRuleEnum.CODE_RULE_9.getKey()) {
|
|
if (key == CodeRuleEnum.CODE_RULE_9.getKey()) {
|
|
- code += Optional.ofNullable(cr.getString("value")).orElse("");
|
|
|
|
- continue;
|
|
|
|
|
|
+ code.append(Optional.ofNullable(cr.getString("value")).orElse(""));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//自增总编号+1
|
|
//自增总编号+1
|
|
- if (StringUtils.isNotBlank(code)) {
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(code.toString())) {
|
|
iCodeRuleApi.updateCodeCurrentValueById(rule.getId());
|
|
iCodeRuleApi.updateCodeCurrentValueById(rule.getId());
|
|
}
|
|
}
|
|
|
|
|
|
- return code;
|
|
|
|
|
|
+ return code.toString();
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
* 获取分布式锁key
|
|
* 获取分布式锁key
|