Commit 3c3a14ea LN

1.根据配置的过期时间设置条码过期时间

1 个父辈 25d7b121
...@@ -169,6 +169,7 @@ public class Constants { ...@@ -169,6 +169,7 @@ public class Constants {
public static final String CACHE_SAME_BARCODE_SETTINGS ="CACHE_sameBarcode_settings"; public static final String CACHE_SAME_BARCODE_SETTINGS ="CACHE_sameBarcode_settings";
public static final String CHCHE_ExpirationDateConfig = "micron_expiration_config";
/** /**
* 当前入库信息: * 当前入库信息:
*/ */
......
...@@ -16,9 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -16,9 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.yaml.snakeyaml.comments.CommentType; import org.yaml.snakeyaml.comments.CommentType;
import java.util.Collection; import java.util.*;
import java.util.Date;
import java.util.List;
/** /**
* Created by sunke on 2021/7/13. * Created by sunke on 2021/7/13.
...@@ -36,7 +34,7 @@ public class CodeResolve { ...@@ -36,7 +34,7 @@ public class CodeResolve {
private List<BarcodeRule> barcodeRuleList; private List<BarcodeRule> barcodeRuleList;
private Integer defaultExpiresDay=0; private Integer defaultExpiresDay=0;
Map<String, Integer> configMap =new HashMap<>();
public void updateBarcodeRuleList(List<String> ruleList){ public void updateBarcodeRuleList(List<String> ruleList){
barcodeRuleList = Lists.newArrayList(); barcodeRuleList = Lists.newArrayList();
...@@ -50,10 +48,43 @@ public class CodeResolve { ...@@ -50,10 +48,43 @@ public class CodeResolve {
defaultExpiresDay=expiresDay; defaultExpiresDay=expiresDay;
} }
public void updateConfigMap(Map<String,Integer> map){
this.configMap=map;
}
public CodeBean resolveSingleCode(String barcodeItemStr ){ public CodeBean resolveSingleCode(String barcodeItemStr ){
return resolveSingleCode(barcodeItemStr, COMPONENT_TYPE.COMPONENT); return resolveSingleCode(barcodeItemStr, COMPONENT_TYPE.COMPONENT);
} }
public int getTargetValid(String pn,int validDay) {
try {
if (validDay > 0) {
return validDay;
}
int year = 0;
if (configMap != null)
for (String key :
configMap.keySet()) {
if (pn.startsWith(key)) {
year = configMap.get(key);
break;
}
}
if (year > 0) {
return year * 365;
}
if (defaultExpiresDay != null && defaultExpiresDay > 0) {
return defaultExpiresDay;
}
} catch (Exception ex) {
log.error(" getTargetValid [" + validDay + "] 出错:" + ex.toString());
}
return 0;
}
/** /**
* 解析条码为单个 Barcode,自动保存到数据库 * 解析条码为单个 Barcode,自动保存到数据库
*/ */
...@@ -160,9 +191,10 @@ public class CodeResolve { ...@@ -160,9 +191,10 @@ public class CodeResolve {
setSize = true; setSize = true;
} }
} }
if(validDay<=0&& defaultExpiresDay!=null&&defaultExpiresDay>0){ // if(validDay<=0&& defaultExpiresDay!=null&&defaultExpiresDay>0){
validDay=defaultExpiresDay; // validDay=defaultExpiresDay;
} // }
validDay=getTargetValid(barcode.getPartNumber(),validDay);
if((!setSize)&& codeBeanFromRule.hasReelSizeInfo()){ if((!setSize)&& codeBeanFromRule.hasReelSizeInfo()){
//如果客户端传入的有尺寸,但尺寸不一致,使用上传上来的尺寸 //如果客户端传入的有尺寸,但尺寸不一致,使用上传上来的尺寸
if(barcode.getHeight() != codeBeanFromRule.getReelHeight() || barcode.getPlateSize() != codeBeanFromRule.getReelWidth()){ if(barcode.getHeight() != codeBeanFromRule.getReelHeight() || barcode.getPlateSize() != codeBeanFromRule.getReelWidth()){
...@@ -295,9 +327,10 @@ public class CodeResolve { ...@@ -295,9 +327,10 @@ public class CodeResolve {
Date produceDate = barcodeFromRule.getProduceDate(); Date produceDate = barcodeFromRule.getProduceDate();
if(produceDate != null && barcodeFromRule.getExpireDate() == null){ if(produceDate != null && barcodeFromRule.getExpireDate() == null){
int validDay = component.getValidDay(); int validDay = component.getValidDay();
if(validDay<=0&& defaultExpiresDay!=null&&defaultExpiresDay>0){ // if(validDay<=0&& defaultExpiresDay!=null&&defaultExpiresDay>0){
validDay=defaultExpiresDay; // validDay=defaultExpiresDay;
} // }
validDay=getTargetValid(component.getPartNumber(),validDay);
if( validDay > 0){ if( validDay > 0){
log.info("设置"+barcodeFromRule.getBarcode()+"的过期时间"); log.info("设置"+barcodeFromRule.getBarcode()+"的过期时间");
Date expireDate = DateUtil.addDays(produceDate, validDay); Date expireDate = DateUtil.addDays(produceDate, validDay);
......
...@@ -114,6 +114,9 @@ public class DataCache { ...@@ -114,6 +114,9 @@ public class DataCache {
initCacheItem(); initCacheItem();
Integer expireDay = getCache(Constants.CACHE_ExpiresDay); Integer expireDay = getCache(Constants.CACHE_ExpiresDay);
codeResolve.updateExpiresDay(expireDay); codeResolve.updateExpiresDay(expireDay);
Map<String, Integer> conMap=getCache(Constants.CHCHE_ExpirationDateConfig);
codeResolve.updateConfigMap(conMap);
} }
private void initCacheItem() { private void initCacheItem() {
...@@ -175,6 +178,9 @@ public class DataCache { ...@@ -175,6 +178,9 @@ public class DataCache {
if (cacheKey.equals(Constants.CACHE_ExpiresDay)) { if (cacheKey.equals(Constants.CACHE_ExpiresDay)) {
codeResolve.updateExpiresDay((Integer) value); codeResolve.updateExpiresDay((Integer) value);
} }
if(cacheKey.equals(Constants.CHCHE_ExpirationDateConfig)){
codeResolve.updateConfigMap((Map<String, Integer>)value);
}
log.info("updateCache [" + cacheKey + "]=[" + value + "]"); log.info("updateCache [" + cacheKey + "]=[" + value + "]");
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!