mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 19:15:35 +08:00
update 电单车
This commit is contained in:
@@ -2,9 +2,14 @@ package com.jsowell.pile.service;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.jsowell.common.constant.CacheConstants;
|
||||
import com.jsowell.common.constant.Constants;
|
||||
import com.jsowell.common.core.domain.entity.SysDictData;
|
||||
import com.jsowell.common.core.redis.RedisCache;
|
||||
import com.jsowell.common.util.DictUtils;
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
import com.jsowell.pile.domain.PileBasicInfo;
|
||||
import com.jsowell.system.service.SysDictDataService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -27,8 +32,18 @@ public class PileSnGenerateService {
|
||||
@Autowired
|
||||
private PileBasicInfoService pileBasicInfoService;
|
||||
|
||||
@Autowired
|
||||
private SysDictDataService dictDataService;
|
||||
|
||||
private final String prefix = "88";
|
||||
|
||||
// 桩号生成字典类型
|
||||
private String pile_sn_generate_type = "pile_sn_generate";
|
||||
|
||||
private String EV_PILE_SN_LABEL = "云快充桩号";
|
||||
|
||||
private String EBIKE_PILE_SN_LABEL = "友电桩号";
|
||||
|
||||
/**
|
||||
* 获取递增的序列号 汽车桩
|
||||
* 充电桩编号定义为14位: 固定位88 + 年份23 + 10位自增数字不足补0
|
||||
@@ -50,7 +65,6 @@ public class PileSnGenerateService {
|
||||
// String pileSnNum = StringUtils.substring(pileSn, 4, pileSn.length());
|
||||
// 再将该值存入数据库
|
||||
redisCache.setCacheObject(key, pileSnNum.intValue());
|
||||
|
||||
}
|
||||
Long increNum = redisCache.increment(key, 1);
|
||||
// 年份
|
||||
@@ -63,13 +77,14 @@ public class PileSnGenerateService {
|
||||
return increResult;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量生成sn号
|
||||
*
|
||||
* @param size
|
||||
* @return
|
||||
*/
|
||||
public List<String> generateSN(int size) {
|
||||
public List<String> generateEVPileSN(int size) {
|
||||
List<String> resultList = Lists.newArrayList();
|
||||
if (size <= 0) {
|
||||
return resultList;
|
||||
@@ -80,6 +95,11 @@ public class PileSnGenerateService {
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成电单车桩号
|
||||
* @param size 生成数量
|
||||
* @return
|
||||
*/
|
||||
public List<String> generateEBikeSN(int size) {
|
||||
List<String> resultList = Lists.newArrayList();
|
||||
if (size <= 0) {
|
||||
@@ -98,31 +118,48 @@ public class PileSnGenerateService {
|
||||
* @return
|
||||
*/
|
||||
public synchronized String getEBikePileSn(String prefix) {
|
||||
String key = CacheConstants.PILE_SN_GENERATE_KEY + prefix;
|
||||
String increResult = null;
|
||||
try {
|
||||
// 取缓存
|
||||
Integer pileNum = redisCache.getCacheObject(key);
|
||||
if (pileNum == null) {
|
||||
// 缓存中没有,从数据库中取
|
||||
PileBasicInfo pileInfo = pileBasicInfoService.getMaxNumPileInfo();
|
||||
String pileSn = pileInfo.getSn();
|
||||
// 将前四位截取,并将后面转为long
|
||||
Long pileSnNum = Long.parseLong(StringUtils.substring(pileSn, 4, pileSn.length()));
|
||||
// String pileSnNum = StringUtils.substring(pileSn, 4, pileSn.length());
|
||||
// 再将该值存入数据库
|
||||
redisCache.setCacheObject(key, pileSnNum.intValue());
|
||||
|
||||
}
|
||||
Long increNum = redisCache.increment(key, 1);
|
||||
// 年份
|
||||
int year = LocalDate.now().getYear() - 2000;
|
||||
//不足补位
|
||||
increResult = prefix + year + String.format("%1$010d", increNum);
|
||||
} catch (Exception e) {
|
||||
logger.error("获取序列号失败", e);
|
||||
// 年份
|
||||
int year = LocalDate.now().getYear() - 2000;
|
||||
|
||||
// 取字典中保存的值
|
||||
String dictValue = DictUtils.getDictValue(pile_sn_generate_type, EBIKE_PILE_SN_LABEL + year);
|
||||
if (StringUtils.isNotBlank(dictValue)) {
|
||||
// 将前四位截取,并将后面转为long
|
||||
Long pileSnNum = Long.parseLong(dictValue);
|
||||
pileSnNum += 1;
|
||||
// 再将该值存入数据库
|
||||
increResult = prefix + year + String.format("%1$04d", pileSnNum);
|
||||
save2Dict(year, pileSnNum);
|
||||
} else {
|
||||
// 没有值, 从1开始, 并保存到字典中
|
||||
Long pileSnNum = 1L;
|
||||
increResult = prefix + year + String.format("%1$04d", pileSnNum);
|
||||
save2Dict(year, pileSnNum);
|
||||
}
|
||||
return increResult;
|
||||
}
|
||||
|
||||
|
||||
private void save2Dict(int year, long pileSnNum) {
|
||||
SysDictData queryData = new SysDictData();
|
||||
queryData.setDictType(pile_sn_generate_type);
|
||||
queryData.setDictLabel(EBIKE_PILE_SN_LABEL + year);
|
||||
List<SysDictData> sysDictData = dictDataService.selectDictDataList(queryData);
|
||||
if (CollectionUtils.isNotEmpty(sysDictData)) {
|
||||
SysDictData dictData = sysDictData.get(0);
|
||||
dictData.setDictValue(pileSnNum + "");
|
||||
dictDataService.updateDictData(dictData);
|
||||
} else {
|
||||
SysDictData dictData = new SysDictData();
|
||||
dictData.setDictType(pile_sn_generate_type);
|
||||
dictData.setDictLabel(EBIKE_PILE_SN_LABEL + year);
|
||||
dictData.setDictValue(pileSnNum + "");
|
||||
dictData.setListClass(Constants.DEFAULT);
|
||||
dictData.setCreateBy(Constants.SYSTEM);
|
||||
dictDataService.insertDictData(dictData);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user