Commit 19ae83b9 by wangnb

orderCenter订单号生成规则修改--think.wang

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@30446 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent 21908a8d
......@@ -32,7 +32,6 @@ import com.glsx.ordercenter.utils.SnowflakeWorker;
import com.glsx.ordercenter.utils.SpringContextUtils;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.text.StrBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -2179,23 +2178,24 @@ public class OrderServiceImpl implements IOrderService {
@Override
public String getOrderSn(int orderType) {
StrBuilder builder = new StrBuilder(OrderTypeEnum.getOrderNoPrefix(orderType));
StringBuffer buffer = new StringBuffer();
buffer.append(OrderTypeEnum.getOrderNoPrefix(orderType));
SnowflakeWorker worker2 = new SnowflakeWorker(2);
String snowId = String.valueOf(worker2.nextId());
int len = snowId.length();
if (len == 16) { //长度16直接返回
return builder.append(snowId).toString();
return buffer.append(snowId).toString();
}
if (len > 16) { //长度大于16,截取
builder.append(snowId.substring(len - 16, len));
return builder.toString();
buffer.append(snowId.substring(len - 16, len));
return buffer.toString();
}
//长度不足的,前面补0
int count = 16 - len;
for (int i = 0; i < count; i++) {
builder.append("0");
buffer.append("0");
}
return builder.append(snowId).toString();
return buffer.append(snowId).toString();
}
@Override
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!