|
|
package com.yohoufo.order.service.support.codegenerator.impl;
|
|
|
|
|
|
import com.yohobuy.ufo.model.order.common.OrderCodeType;
|
|
|
import com.yohobuy.ufo.model.order.constants.OpsEnv;
|
|
|
import com.yohoufo.order.model.dto.OrderCodeRule;
|
|
|
import com.yohoufo.order.service.impl.MetaConfigService;
|
|
|
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
|
|
|
import com.yohoufo.order.service.support.codegenerator.bean.CodeBitMeta;
|
|
|
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
|
...
|
...
|
@@ -31,6 +34,9 @@ public class OrderCodeGeneratorImpl implements OrderCodeGenerator { |
|
|
@Autowired
|
|
|
MachineIdProvider machineIdProvider;
|
|
|
|
|
|
@Autowired
|
|
|
MetaConfigService metaConfigService;
|
|
|
|
|
|
long machineId = 0l;
|
|
|
|
|
|
@PostConstruct
|
...
|
...
|
@@ -41,7 +47,13 @@ public class OrderCodeGeneratorImpl implements OrderCodeGenerator { |
|
|
}
|
|
|
|
|
|
if (idPopulator == null){
|
|
|
idPopulator = new AtomicIdPopulator();
|
|
|
|
|
|
SequenceStrategy.SingleData sssd = createSequence();
|
|
|
long seq = sssd.start;
|
|
|
|
|
|
AtomicIdPopulator.Variant variant = new AtomicIdPopulator().new Variant(seq);
|
|
|
|
|
|
idPopulator = new AtomicIdPopulator(variant);
|
|
|
}
|
|
|
|
|
|
machineId = machineIdProvider.getMachineId();
|
...
|
...
|
@@ -50,6 +62,31 @@ public class OrderCodeGeneratorImpl implements OrderCodeGenerator { |
|
|
validateMachineId(this.machineId);
|
|
|
}
|
|
|
|
|
|
private SequenceStrategy.SingleData createSequence(){
|
|
|
OrderCodeRule ocr = metaConfigService.getOrderCodeRule();
|
|
|
Long seq = 0L;
|
|
|
String env = null;
|
|
|
boolean envIsNull = false;
|
|
|
if (ocr==null || (envIsNull = ((env=ocr.getEnv()) == null))){
|
|
|
log.warn("in order code generator env use prd, OrderCodeRule {}", ocr);
|
|
|
}
|
|
|
//明确指定了配置使用非生产环境时,序列号从1000开始
|
|
|
if (!envIsNull && !OpsEnv.PRD.getName().equalsIgnoreCase(env)){
|
|
|
seq = 1000L;
|
|
|
log.info("in order code generator env use not prd config, OrderCodeRule {} seq {}", ocr, seq);
|
|
|
}
|
|
|
log.info("in order code generator init config, OrderCodeRule {} seq {}", ocr, seq);
|
|
|
/*
|
|
|
*这是常驻内存的方式,其实很不妥,运维不方便;
|
|
|
* 数据库修改后需要重新发布工程才能获取新值
|
|
|
*/
|
|
|
SequenceStrategy.SingleData sssd = SequenceStrategy.SingleData.create(env, seq);
|
|
|
|
|
|
return sssd;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public long generate(OrderCodeType type) {
|
|
|
CodeMeta id = new CodeMeta();
|
|
|
|
...
|
...
|
|