Commit 185307ab authored by 刘林's avatar 刘林

fix(jg):96333重复问题修复

parent 741e839b
......@@ -86,7 +86,7 @@
idx_biz_jg_register_info jri
LEFT JOIN idx_biz_jg_other_info other on jri.RECORD = other.RECORD where jri.RECORD in (select re.equ_id from tzs_jg_use_registration_eq re where ur.sequence_nbr = re.equip_transfer_id)) as supervisoryCode ,
(SELECT
group_concat(other.CODE96333)
group_concat(IFNULL(other.CODE96333, '') SEPARATOR ',')
from
idx_biz_jg_register_info jri
LEFT JOIN idx_biz_jg_other_info other on jri.RECORD = other.RECORD where jri.RECORD in (select re.equ_id from tzs_jg_use_registration_eq re where ur.sequence_nbr = re.equip_transfer_id)) as code96333 ,
......
......@@ -1613,9 +1613,27 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
this.rollBackRegisterInfo(jgRelationEquip, idxBizJgRegisterInfo);
// 5.es 回退
this.rollBackEsInfo(jgRelationEquip, idxBizJgRegisterInfo);
//6.释放96333码为 未使用状态
this.release96333Code(jgRelationEquip);
});
}
/**
* 释放96333码为未使用状态
* @param jgRelationEquip jgRelationEquip
*/
private void release96333Code(JgInstallationNoticeEq jgRelationEquip) {
Optional.ofNullable(jgRelationEquip)
.map(JgInstallationNoticeEq::getEquId)
.map(equId -> tzsJgOtherInfoMapper.selectOne(
new LambdaQueryWrapper<OtherInfo>()
.eq(OtherInfo::getRecord, equId)
.select(OtherInfo::getSupervisoryCode)
))
.map(OtherInfo::getSupervisoryCode)
.ifPresent(code -> supervisoryCodeInfoMapper.updateStatus(Collections.singletonList(code)));
}
private void rollBackEsInfo(JgInstallationNoticeEq jgRelationEquip, IdxBizJgRegisterInfo idxBizJgRegisterInfo) {
Optional<ESEquipmentCategoryDto> optional = esEquipmentCategory.findById(jgRelationEquip.getEquId());
if (optional.isPresent()) {
......
......@@ -205,6 +205,8 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
private IdxBizJgConstructionInfoMapper constructionInfoMapper;
@Autowired
private SuperviseInfoMapper superviseInfoMapper;
@Autowired
SupervisoryCodeInfoMapper supervisoryCodeInfoMapper;
/**
* @param auditPassDate 通过时间
......@@ -2384,6 +2386,10 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
map.put("countyCode", useInfo.getCounty());
map.put("equCategory", registerInfo.getEquCategory());
map.put("isXiXian", dataMap.get("isXixian"));
//有96333码,不生成96333码,只生成监管码
if ("1".equals(otherInfo.getCode96333Type())) {
map.put("code96333", otherInfo.getCode96333());
}
ResponseModel<Map<String, Object>> code = tzsServiceFeignClient.createCode(map);
Map<String, Object> result = code.getResult();
if (!ObjectUtils.isEmpty(result)) {
......@@ -2524,9 +2530,33 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
this.clearMainInfo(record);
// 删除检验检测信息
this.clearInspectionInfo(record);
// 释放96333码为 未使用状态
this.release96333Code(record);
}
}
/**
* 释放96333码为未使用状态
* @param record 记录值
*/
private void release96333Code(String record) {
Optional.ofNullable(
otherInfoMapper.selectOne(
new LambdaQueryWrapper<IdxBizJgOtherInfo>()
.eq(IdxBizJgOtherInfo::getRecord, record)
.select(IdxBizJgOtherInfo::getSupervisoryCode, IdxBizJgOtherInfo::getCode96333Type)
)
).ifPresent(otherInfo -> {
String supervisoryCode = otherInfo.getSupervisoryCode();
//手动输入直接删除
if ("0".equals(otherInfo.getCode96333Type())) {
supervisoryCodeInfoMapper.delete(new QueryWrapper<SupervisoryCodeInfo>().eq("SUPERVISORY_CODE", supervisoryCode));
} else {
supervisoryCodeInfoMapper.updateStatus(Collections.singletonList(supervisoryCode));
}
});
}
private void clearInspectionInfo(String record) {
inspectionDetectionInfoMapper.delete(new LambdaQueryWrapper<InspectionDetectionInfo>().eq(AbstractEquipBaseEntity::getRecord, record));
InspectionDetectionInfo inspectionDetectionInfo = new InspectionDetectionInfo();
......
......@@ -58,4 +58,12 @@ public interface CategoryOtherInfoMapper extends BaseMapper<CategoryOtherInfo> {
*/
List<KV> selectSupervisorCodeMaxValue();
/**
* 查询电梯码是否重复
* @param elevatorCode 96333
* @param status 0 手动输入
* @return 0
*/
Integer checkElevatorCodeRepeat(@Param("elevatorCode") String elevatorCode, String status);
}
......@@ -45,4 +45,6 @@ public interface IEquipmentCategoryService {
void creatXiXian(String type);
Map<String, Object> commonUpdateEsDataByIds(Map<String, Map<String, Object>> paramMap);
String selectExceedElevatorCode(String prefix);
}
......@@ -38,7 +38,9 @@
SELECT ROW_NUMBER() OVER (PARTITION BY SUBSTRING (CODE96333 FROM 1 FOR 2) ORDER BY CODE96333 DESC) AS row_num,
CODE96333
FROM biz_jg_supervisory_code
WHERE CODE96333 IS NOT NULL AND CODE96333 <![CDATA[<> '']]>)
WHERE CREATE_STATUS = 1
AND CODE96333 IS NOT NULL
AND CODE96333 <![CDATA[<> '']]>)
SELECT '96333_' || SUBSTRING(CODE96333 FROM 1 FOR 2) AS name,
CODE96333 AS value
FROM ElevatorResults WHERE row_num = 1
......@@ -192,4 +194,11 @@
LIMIT 1
</select>
<select id="checkElevatorCodeRepeat" resultType="java.lang.Integer">
SELECT CODE96333 code
FROM biz_jg_supervisory_code
WHERE CODE96333 = #{elevatorCode} and create_status = #{status}
ORDER BY code
</select>
</mapper>
......@@ -632,4 +632,16 @@ public class EquipmentCategoryController extends BaseController {
public ResponseModel<Map<String, Object>> commonUpdateEsDataByIds(@RequestBody Map<String, Map<String, Object>> paramMap) {
return ResponseHelper.buildResponse(equipmentCategoryService.commonUpdateEsDataByIds(paramMap));
}
/**
* 根据前缀查询96333空余序列码
*
* @return s
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@RequestMapping(value = "/selectExceedElevatorCode", method = RequestMethod.POST)
@ApiOperation(httpMethod = "POST", value = "根据前缀查询96333空余序列码", notes = "根据前缀查询96333空余序列码")
public ResponseModel<String> selectExceedElevatorCode(@RequestParam("prefix") String prefix) {
return ResponseHelper.buildResponse(equipmentCategoryService.selectExceedElevatorCode(prefix));
}
}
......@@ -692,7 +692,7 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
// 查询未使用的电梯码
categoryOtherInfo = categoryOtherInfoMapper.selectElevatorCode(prefix, EquipmentCategoryEnum.WSY.getCode());
// 如果存在未使用的电梯码则启用未使用的否则创建
String elevator = ObjectUtils.isEmpty(categoryOtherInfo) ? generateCodeService.createElevatorCode("96333_" + prefix) : categoryOtherInfo.getCode();
String elevator = ObjectUtils.isEmpty(categoryOtherInfo) ? this.createElevatorCode(prefix) : categoryOtherInfo.getCode();
if (!ObjectUtils.isEmpty(categoryOtherInfo)) {
supervisoryCodeInfoMapper.delete(new QueryWrapper<SupervisoryCodeInfo>().eq("code96333", categoryOtherInfo.getCode()));
}
......@@ -747,6 +747,44 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
return equipmentCategoryMapper.getAdministrativeDivision(type, county).get("code").toString();
}
/**
* 生成96333电梯识别码
*
* @param prefix 电梯码前缀
* @return 96333电梯识别码
*/
public String selectExceedElevatorCode(String prefix) {
StringBuilder elevatorCode = new StringBuilder();
// 生成生成96333电梯码前缀
elevatorCode.append(prefix);
String initCode = elevatorCode + EquipmentCategoryEnum.getValue.get(elevatorCode.toString());
CategoryOtherInfo initSupervisoryCode = categoryOtherInfoMapper.queryInitCode(initCode); // 查询是否已经生成过初始值
if (ValidationUtil.isEmpty(initSupervisoryCode)) {
elevatorCode.append(EquipmentCategoryEnum.getValue.get(prefix));
} else {
// 获取行政区划区县、市是否存在历史96333电梯码
CategoryOtherInfo elevatorOtherInfo = categoryOtherInfoMapper.selectElevatorCode(elevatorCode.toString(), null);
if (!ObjectUtils.isEmpty(elevatorOtherInfo) && elevatorOtherInfo.getCode() != null) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
Integer start = Integer.valueOf(prefix + EquipmentCategoryEnum.getCode.get(prefix));
Integer end = Integer.valueOf(elevatorOtherInfo.getCode());
List<Integer> allCodeList = IntStream.rangeClosed(start, end)
.boxed()
.collect(Collectors.toList());
List<Integer> codeList = categoryOtherInfoMapper.selectExceedElevatorCodeList(start, prefix);
List<Integer> resultList = getDiffrent(allCodeList, codeList);
if (!ObjectUtils.isEmpty(resultList)) {
elevatorCode.setLength(0);
elevatorCode.append(resultList.get(0));
}
stopWatch.stop();
}
}
return elevatorCode.toString();
}
/**
* 生成监管码
*
......@@ -795,7 +833,6 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
* @param prefix 电梯码前缀
* @return 96333电梯识别码
*/
@Deprecated
public String createElevatorCode(String prefix) {
StringBuilder elevatorCode = new StringBuilder();
// 生成生成96333电梯码前缀
......@@ -821,20 +858,22 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
elevatorCode.setLength(0);
elevatorCode.append(resultList.get(0));
} else {
// 获取补零位长度
String elevatorCode1 = elevatorOtherInfo.getCode().substring(2);
long num = Long.parseLong(elevatorCode1) + 1;
int numLength = String.valueOf(num).length();
int a = 5 - numLength;
StringBuilder zero = new StringBuilder();
for (int i = 0; i < a; i++) {
zero.append(EquipmentCategoryEnum.BLW.getCode());
}
zero.append(num);
elevatorCode.append(zero);
//// 获取补零位长度
//String elevatorCode1 = elevatorOtherInfo.getCode().substring(2);
//long num = Long.parseLong(elevatorCode1) + 1;
//int numLength = String.valueOf(num).length();
//int a = 5 - numLength;
//StringBuilder zero = new StringBuilder();
//for (int i = 0; i < a; i++) {
// zero.append(EquipmentCategoryEnum.BLW.getCode());
//}
//zero.append(num);
//elevatorCode.append(zero);
do {
elevatorCode = new StringBuilder(generateCodeService.createElevatorCode("96333_" + prefix));
} while (categoryOtherInfoMapper.checkElevatorCodeRepeat(elevatorCode.toString(), "0") > 0);
}
stopWatch.stop();
}
}
return elevatorCode.toString();
......@@ -847,8 +886,6 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
*/
public List<JSONObject> getCompanyType() {
ReginParams reginParams = JSON.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId(), RequestContext.getToken())).toString(), ReginParams.class);
List<CompanyModel> companys = reginParams.getUserModel().getCompanys();
......
......@@ -413,4 +413,15 @@ public class GenerateCodeServiceImpl implements IGenerateCodeService {
long expirationTimeInSeconds = expirationDate.getTime() - System.currentTimeMillis();
redisTemplate.expire(key, expirationTimeInSeconds, TimeUnit.MILLISECONDS);
}
/**
* redis 设置不过期的 key
*
* @param key key
* @param value value
*/
public void setValueWithoutExpiration(String key, String value) {
ValueOperations<String, String> valueOps = redisTemplate.opsForValue();
valueOps.set(key, value);
}
}
\ No newline at end of file
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