Commit 3a398dda authored by 刘林's avatar 刘林

fix(jg):压力容器批量导入优化批量生产监管码

parent 940bb024
...@@ -26,6 +26,15 @@ public interface TzsServiceFeignClient { ...@@ -26,6 +26,15 @@ public interface TzsServiceFeignClient {
ResponseModel<Map<String, Object>> createCode(@RequestBody Map<String, Object> map); ResponseModel<Map<String, Object>> createCode(@RequestBody Map<String, Object> map);
/** /**
* 批量创建监管码-设备导入用
*
* @param map 请求体
* @return
*/
@RequestMapping(value = "/equipment-category/createSupervisoryCodeBatch", method = RequestMethod.POST)
ResponseModel<List<Map<String, String>>> createCodeBatch(@RequestBody Map<String, Object> map);
/**
* 创建监管码及96333 * 创建监管码及96333
* *
* @param paramMap 请求体 * @param paramMap 请求体
......
...@@ -4341,6 +4341,14 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste ...@@ -4341,6 +4341,14 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
List<DictionarieValueModel> fillingMedium = Systemctl.dictionarieClient.dictValues("FILLING_MEDIUM").getResult(); List<DictionarieValueModel> fillingMedium = Systemctl.dictionarieClient.dictValues("FILLING_MEDIUM").getResult();
Map<String, Object> fillingMediumMap = fillingMedium.stream().collect(Collectors.toMap(DictionarieValueModel::getDictDataValue, Map<String, Object> fillingMediumMap = fillingMedium.stream().collect(Collectors.toMap(DictionarieValueModel::getDictDataValue,
DictionarieValueModel::getDictDataKey)); DictionarieValueModel::getDictDataKey));
Iterator<String> supervisoryCodeIterator;
if ("his".equals(equipInfoDto.getDataSource())) {
supervisoryCodeIterator = this
.getSupervisoryCodeBatch(equipInfoDto.getPossession(), equipInfoDto.getEquCategoryCode(), equipInfoCylinderExcelDtoList.size())
.iterator();
} else {
supervisoryCodeIterator = Collections.emptyIterator();
}
equipInfoCylinderExcelDtoList.forEach(data -> { equipInfoCylinderExcelDtoList.forEach(data -> {
JgUseRegistrationEq jgRelationEquip = new JgUseRegistrationEq(); JgUseRegistrationEq jgRelationEquip = new JgUseRegistrationEq();
if ("his".equals(equipInfoDto.getDataSource()) && "1".equals(data.getWhetherVehicleCylinder())) { if ("his".equals(equipInfoDto.getDataSource()) && "1".equals(data.getWhetherVehicleCylinder())) {
...@@ -4489,7 +4497,7 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste ...@@ -4489,7 +4497,7 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
otherInfo.setRecDate(new Date()); otherInfo.setRecDate(new Date());
otherInfo.setCylinderStampAttachment(cylinderStampAttachment); otherInfo.setCylinderStampAttachment(cylinderStampAttachment);
if ("his".equals(equipInfoDto.getDataSource())) { if ("his".equals(equipInfoDto.getDataSource())) {
otherInfo.setSupervisoryCode(this.getSupervisoryCode(equipInfoDto.getPossession(), registerInfo.getEquCategory())); otherInfo.setSupervisoryCode(supervisoryCodeIterator.next());
} }
otherInfo.setClaimStatus("已认领"); otherInfo.setClaimStatus("已认领");
otherInfoList.add(otherInfo); otherInfoList.add(otherInfo);
...@@ -5128,6 +5136,26 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste ...@@ -5128,6 +5136,26 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
.orElse(""); .orElse("");
} }
/**
* 批量生成监管码
*/
public List<String> getSupervisoryCodeBatch(String possession, String equCategory, int batchSize) {
boolean isXiXian = XI_XIAN.getCode().equals(possession);
String cityOrCountyCode = isXiXian ? XIAN_YANG.getCode() : possession;
Map<String, Object> params = new HashMap<>();
params.put("cityCode", cityOrCountyCode);
params.put("isXiXian", isXiXian ? 1 : 0);
params.put("equCategory", equCategory);
params.put("countyCode", cityOrCountyCode);
params.put("batchSize", batchSize);
return Optional.ofNullable(tzsServiceFeignClient.createCodeBatch(params).getResult())
.map(list -> list.stream()
.map(res -> String.valueOf(res.get("superviseCode")))
.collect(Collectors.toList()))
.orElse(Collections.emptyList());
}
// 注入依赖 // 注入依赖
private void injectDependencies(PressureVesselListener listener, Map<String, Object> paramMap) { private void injectDependencies(PressureVesselListener listener, Map<String, Object> paramMap) {
listener.setIdxBizJgRegisterInfoService(idxBizJgRegisterInfoService); listener.setIdxBizJgRegisterInfoService(idxBizJgRegisterInfoService);
......
package com.yeejoin.amos.boot.module.ymt.api.mapper; package com.yeejoin.amos.boot.module.ymt.api.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.yeejoin.amos.boot.module.common.api.mapper.CustomBaseMapper;
import com.yeejoin.amos.boot.module.ymt.api.entity.SupervisoryCodeInfo; import com.yeejoin.amos.boot.module.ymt.api.entity.SupervisoryCodeInfo;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
/** /**
...@@ -12,9 +11,10 @@ import java.util.List; ...@@ -12,9 +11,10 @@ import java.util.List;
* @author system_generator * @author system_generator
* @date 2021-10-20 * @date 2021-10-20
*/ */
public interface SupervisoryCodeInfoMapper extends BaseMapper<SupervisoryCodeInfo> { public interface SupervisoryCodeInfoMapper extends CustomBaseMapper<SupervisoryCodeInfo> {
void updateStatus(@Param("superviseCodeList") List<String> superviseCodeList); void updateStatus(@Param("superviseCodeList") List<String> superviseCodeList);
void updateStatusBySuperviseCode(String superviseCode); void updateStatusBySuperviseCode(String superviseCode);
} }
...@@ -23,6 +23,8 @@ public interface IEquipmentCategoryService { ...@@ -23,6 +23,8 @@ public interface IEquipmentCategoryService {
Map<String, String> createSupervisorCode(Map<String, Object> map); Map<String, String> createSupervisorCode(Map<String, Object> map);
List<Map<String, String>> createSupervisoryCodeBatch(Map<String, Object> map);
List<LinkedHashMap> getTree(); List<LinkedHashMap> getTree();
List<LinkedHashMap> creatTree(); List<LinkedHashMap> creatTree();
......
...@@ -51,6 +51,12 @@ public interface IGenerateCodeService { ...@@ -51,6 +51,12 @@ public interface IGenerateCodeService {
* @return 7位监管编码生成 * @return 7位监管编码生成
*/ */
String createSupervisoryCode(String key); String createSupervisoryCode(String key);
/**
* 监管编码生成(7位)-导入批量生成
* @param key key
* @return 7位监管编码生成
*/
List<String> createSupervisoryCodeBatch(String key, int batchSize);
String initCode(); String initCode();
} }
...@@ -735,7 +735,7 @@ ...@@ -735,7 +735,7 @@
v2.REC_DATE v2.REC_DATE
FROM "idx_biz_jg_other_info" v1 FROM "idx_biz_jg_other_info" v1
LEFT JOIN "biz_jg_supervisory_code" v2 on v1.SUPERVISORY_CODE = v2.SUPERVISORY_CODE LEFT JOIN "biz_jg_supervisory_code" v2 on v1.SUPERVISORY_CODE = v2.SUPERVISORY_CODE
WHERE v1."SUPERVISORY_CODE" ~ 'X31' AND v1."CODE96333" ~ '^32' WHERE v1."SUPERVISORY_CODE" ~ 'X3' AND v1."CODE96333" ~ '^32'
AND v2.create_status = '1' AND v2.create_status = '1'
ORDER BY v2."REC_DATE" DESC ORDER BY v2."REC_DATE" DESC
</select> </select>
......
...@@ -12,4 +12,14 @@ ...@@ -12,4 +12,14 @@
<update id="updateStatusBySuperviseCode"> <update id="updateStatusBySuperviseCode">
update biz_jg_supervisory_code set status = '1' where supervisory_code = #{superviseCode} update biz_jg_supervisory_code set status = '1' where supervisory_code = #{superviseCode}
</update> </update>
<insert id="insertBatchSomeColumn" parameterType="java.util.List">
INSERT INTO biz_jg_supervisory_code
(sequence_nbr, supervisory_code, code96333, status, create_status)
VALUES
<foreach collection="list" item="item" separator=",">
(#{item.sequenceNbr}, #{item.supervisoryCode}, #{item.code96333}, #{item.status}, #{item.createStatus})
</foreach>
</insert>
</mapper> </mapper>
\ No newline at end of file
...@@ -276,6 +276,19 @@ public class EquipmentCategoryController extends BaseController { ...@@ -276,6 +276,19 @@ public class EquipmentCategoryController extends BaseController {
} }
/** /**
* 批量生成监管码-设备批量导入用
*
* @return
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@RequestMapping(value = "/createSupervisoryCodeBatch", method = RequestMethod.POST)
@ApiOperation(httpMethod = "POST", value = "批量生成监管码", notes = "生成监管码和96333码")
public ResponseModel<Object> createSupervisoryCodeBatch(@RequestBody Map<String, Object> map) {
return ResponseHelper.buildResponse(equipmentCategoryService.createSupervisoryCodeBatch(map));
}
/**
* 修改数据状态是否显示编辑按钮 * 修改数据状态是否显示编辑按钮
* *
* @return * @return
......
...@@ -10,6 +10,7 @@ import com.google.common.collect.Lists; ...@@ -10,6 +10,7 @@ import com.google.common.collect.Lists;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams; import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey; import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils; import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.biz.common.utils.SnowflakeIdUtil;
import com.yeejoin.amos.boot.module.common.api.dao.ESEquipmentCategory; import com.yeejoin.amos.boot.module.common.api.dao.ESEquipmentCategory;
import com.yeejoin.amos.boot.module.common.api.dao.EsEquipmentDao; import com.yeejoin.amos.boot.module.common.api.dao.EsEquipmentDao;
import com.yeejoin.amos.boot.module.common.api.dto.ESEquipmentCategoryDto; import com.yeejoin.amos.boot.module.common.api.dto.ESEquipmentCategoryDto;
...@@ -35,6 +36,7 @@ import com.yeejoin.amos.component.feign.utils.FeignUtil; ...@@ -35,6 +36,7 @@ import com.yeejoin.amos.component.feign.utils.FeignUtil;
import com.yeejoin.amos.feign.privilege.Privilege; import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.CompanyModel; import com.yeejoin.amos.feign.privilege.model.CompanyModel;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.lucene.queryparser.classic.QueryParser; import org.apache.lucene.queryparser.classic.QueryParser;
import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchRequest;
...@@ -289,6 +291,9 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -289,6 +291,9 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
private String startCode; private String startCode;
@Autowired @Autowired
private SnowflakeIdUtil sequence;
@Autowired
private RedisUtils redisUtils; private RedisUtils redisUtils;
// 一码通checkCode中redis key过期时间 // 一码通checkCode中redis key过期时间
private long time = 300l; private long time = 300l;
...@@ -467,6 +472,84 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -467,6 +472,84 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
return codeMap; return codeMap;
} }
/**
* 批量生成监管码
*/
@Override
public List<Map<String, String>> createSupervisoryCodeBatch(Map<String, Object> map) {
String city, county, equipCategory, isNotXiXian, code96333, superviseCode;
int batchSize = 1;
// 获取对应行政区划
city = String.valueOf(map.get("cityCode"));
county = String.valueOf(map.get("countyCode"));
code96333 = String.valueOf(map.get("code96333"));
superviseCode = String.valueOf(map.get("superviseCode"));
// 获取对应设备分类
equipCategory = String.valueOf(map.get("equCategory"));
if ("null".equals(equipCategory) || "null".equals(city) || "null".equals(county)) {
throw new BadRequest("请求参数不全,请查看参数中是否携带 cityCode、countyCode、equCategory 三个参数及对应值");
}
isNotXiXian = Optional.ofNullable(map.get("isXiXian")).orElse("0").toString();
batchSize = (int) Optional.ofNullable(map.get("batchSize")).orElse(1);
// 生成码
List<Map<String, String>> codeMapList = creatBatchCode(isNotXiXian, city, county, equipCategory, code96333, superviseCode, batchSize);
if (ObjectUtils.isEmpty(codeMapList)) {
throw new BadRequest("该请求参数未生成监管码或96333码,请核对参数");
}
return codeMapList;
}
/**
* 批量生成监管码
*/
public List<Map<String, String>> creatBatchCode(String isNotXiXian,
String city,
String county,
String equipCategory,
String code96333,
String supervisionCode,
int batchSize) {
RLock lock = redissonClient.getLock(LOCK_KEY);
List<Map<String, String>> resultList = new ArrayList<>();
try {
lock.lock();
log.info("加锁成功,开始生成 {} 条监管码", batchSize);
List<String> supervisorList = createSupervisoryCodeBatch(isNotXiXian, city, county, equipCategory, batchSize);
if (CollectionUtils.isEmpty(supervisorList)) {
throw new BadRequest("未生成任何监管码,请检查参数");
}
String equState = EquipmentCategoryEnum.CSZT.getCode();
List<SupervisoryCodeInfo> supervisoryCodeInfoList = new ArrayList<>();
for (String supervisorCode : supervisorList) {
SupervisoryCodeInfo newInfo = new SupervisoryCodeInfo();
newInfo.setSupervisoryCode(supervisorCode);
newInfo.setCode96333(code96333);
newInfo.setCreateStatus("INIT");
newInfo.setStatus(equState);
newInfo.setSequenceNbr(sequence.nextId());
supervisoryCodeInfoList.add(newInfo);
Map<String, String> resultMap = new HashMap<>();
resultMap.put("superviseCode", supervisorCode);
resultMap.put("code96333", "");
resultList.add(resultMap);
}
supervisoryCodeInfoMapper.insertBatchSomeColumn(supervisoryCodeInfoList, 500);
log.info("成功生成 {} 条监管码", resultList.size());
} catch (Exception e) {
log.error("批量生成监管码失败", e);
throw new RuntimeException("批量生成监管码失败: " + e.getMessage(), e);
} finally {
if (lock.isHeldByCurrentThread()) {
lock.unlock();
log.info("释放锁");
}
}
return resultList;
}
@Override @Override
public List<LinkedHashMap> getTree() { public List<LinkedHashMap> getTree() {
List<LinkedHashMap> result = (List<LinkedHashMap>) redisUtils.get(REGULATOR_UNIT_TREE); List<LinkedHashMap> result = (List<LinkedHashMap>) redisUtils.get(REGULATOR_UNIT_TREE);
...@@ -888,6 +971,26 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -888,6 +971,26 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
} }
/** /**
* 批量生成监管码-设备批量导入使用
*
* @param city 行政区划市
* @param county 行政区划区
* @return 监管码
*/
public List<String> createSupervisoryCodeBatch(String isNotXiXian, String city, String county, String equipCategory, int batchSize) {
StringBuilder supervisorCode = new StringBuilder();
String division = null;
if (((XIAN.equals(city) || XIAN_YANG.equals(city)) && "1".equals(isNotXiXian))) {
division = "X";
} else {
Map<String, Object> divisionMap = equipmentCategoryMapper.getAdministrativeDivision(EquipmentCategoryEnum.XZQH.getCode(), county);
division = ObjectUtils.isEmpty(divisionMap) ? equipmentCategoryMapper.getAdministrativeDivision(EquipmentCategoryEnum.XZQH.getCode(), city).get("code").toString() : divisionMap.get("code").toString();
}
supervisorCode.append(division).append(equipCategory);
return generateCodeService.createSupervisoryCodeBatch(String.valueOf(supervisorCode), batchSize);
}
/**
* 生成96333电梯识别码 * 生成96333电梯识别码
* *
* @param prefix 电梯码前缀 * @param prefix 电梯码前缀
......
...@@ -105,6 +105,13 @@ public class GenerateCodeServiceImpl implements IGenerateCodeService { ...@@ -105,6 +105,13 @@ public class GenerateCodeServiceImpl implements IGenerateCodeService {
return (key.length() == 5) ? generateSupervisorySequence(key) : "生成码规则不对!"; return (key.length() == 5) ? generateSupervisorySequence(key) : "生成码规则不对!";
} }
public List<String> createSupervisoryCodeBatch(String key, int batchSize) {
if (key == null || key.length() != 5) {
return Collections.singletonList("生成码规则不对!");
}
return generateSupervisorySequenceBatch(key, batchSize);
}
@Override @Override
public String initCode() { public String initCode() {
categoryOtherInfoMapper.selectSupervisorCodeMaxValue().forEach(vo -> categoryOtherInfoMapper.selectSupervisorCodeMaxValue().forEach(vo ->
...@@ -148,6 +155,59 @@ public class GenerateCodeServiceImpl implements IGenerateCodeService { ...@@ -148,6 +155,59 @@ public class GenerateCodeServiceImpl implements IGenerateCodeService {
} }
/** /**
* 批量生成监管码
*
* @param sequenceKey Redis 中存储的序列 key
* @param batchSize 需要生成的数量
* @return 批量生成的顺序码列表
*/
public List<String> generateSupervisorySequenceBatch(String sequenceKey, int batchSize) {
RLock lock = redissonClient.getLock(LOCK_KEY_SUPERVISORY);
try {
boolean locked = lock.tryLock(10, TimeUnit.SECONDS);
log.info("尝试获取锁: {}", locked);
if (locked) {
ValueOperations<String, String> valueOps = redisTemplate.opsForValue();
String currentSequenceStr = valueOps.get(sequenceKey);
// 如果为空,则初始化为0
long currentSequence = (currentSequenceStr != null)
? Long.parseLong(currentSequenceStr)
: this.initRedis(sequenceKey);
log.info("获取《{}》当前顺序码:{}", sequenceKey, currentSequence);
List<String> results = new ArrayList<>(batchSize);
for (int i = 1; i <= batchSize; i++) {
long nextSeq = currentSequence + i;
String formattedSequence = String.format(
GenerateCodeServiceImpl.SUPERVISOR_SEQUENCE_TYPE, nextSeq);
results.add(sequenceKey + "-" + formattedSequence);
}
// 更新 Redis 里的最新顺序号
long newSequence = currentSequence + batchSize;
valueOps.set(sequenceKey, String.valueOf(newSequence));
log.info("更新《{}》顺序码到:{}", sequenceKey, newSequence);
return results;
} else {
throw new RuntimeException("Failed to acquire lock for sequence generation");
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException("Thread interrupted while acquiring lock", e);
} finally {
if (lock.isHeldByCurrentThread()) {
lock.unlock();
log.info("释放锁");
}
}
}
/**
* 监管码为空的话,初始化Redis * 监管码为空的话,初始化Redis
* *
* @param sequenceKey key * @param sequenceKey key
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment