Commit 5c02680a authored by LiuLin's avatar LiuLin

fix(ymt):生成顺序码调整代码结构,需要feign接口调用,参考TzsServiceFeignClient,接口在GenerateCodeController中

parent fed7ba69
...@@ -6,8 +6,8 @@ import org.springframework.cloud.openfeign.FeignClient; ...@@ -6,8 +6,8 @@ import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.Map; import java.util.Map;
@FeignClient(name = "TZS-YMT", path = "/ymt", configuration = @FeignClient(name = "TZS-YMT", path = "/ymt", configuration =
...@@ -33,4 +33,16 @@ public interface TzsServiceFeignClient { ...@@ -33,4 +33,16 @@ public interface TzsServiceFeignClient {
@RequestMapping(value = "/equipment-category/commonUpdateEsData", method = RequestMethod.POST) @RequestMapping(value = "/equipment-category/commonUpdateEsData", method = RequestMethod.POST)
ResponseModel<Map<String, Object>> commonUpdateEsDataByIds(@RequestBody Map<String, Map<String, Object>> paramMap); ResponseModel<Map<String, Object>> commonUpdateEsDataByIds(@RequestBody Map<String, Map<String, Object>> paramMap);
/**
* 申请单编号生成
* @param type type
* @param batchSize batchSize
* @return List
*/
@RequestMapping(value = "/generate-code/applicationFormCode", method = RequestMethod.POST)
ResponseModel<Map<String, Object>> applicationFormCode(@RequestParam("type") String type,
@RequestParam("batchSize") int batchSize);
} }
//package com.yeejoin.amos.boot.module.ymt.api.controller;
//
//import com.yeejoin.amos.boot.biz.common.controller.BaseController;
//import com.yeejoin.amos.boot.module.ymt.api.service.ICreateCodeService;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.*;
//import org.typroject.tyboot.core.foundation.enumeration.UserType;
//import org.typroject.tyboot.core.restful.doc.TycloudOperation;
//import org.typroject.tyboot.core.restful.utils.ResponseHelper;
//import org.typroject.tyboot.core.restful.utils.ResponseModel;
//import java.util.List;
//
///**
// *
// * 生成顺序码
// * @author LiuLin
// * @date 2023-12-14
// */
//@RestController
//@Api(tags = "生成顺序码")
//@RequestMapping(value = "/code")
//public class CreateCodeController extends BaseController {
//
// @Autowired
// private ICreateCodeService createCodeService;
//
// /**
// * 申请单编号生成
// * @param type type
// * @param batchSize batchSize
// * @return List
// */
// @TycloudOperation(ApiLevel = UserType.AGENCY)
// @PostMapping(value = "/ANCode")
// @ApiOperation(httpMethod = "POST", value = "申请单编号生成", notes = "申请单编号生成")
// public ResponseModel<List<String>> createANCode(@RequestParam("type") String type,
// @RequestParam("batchSize") int batchSize) {
// return ResponseHelper.buildResponse(createCodeService.createApplicationFormCode(type,batchSize));
// }
//
// /**
// * 生成设备注册编码
// * @param key key
// * @return String
// */
// @TycloudOperation(ApiLevel = UserType.AGENCY)
// @PostMapping(value = "/DRCode")
// @ApiOperation(httpMethod = "POST", value = "生成设备注册编码", notes = "生成设备注册编码")
// public ResponseModel<String> createDRCode(@RequestParam("key") String key) {
// return ResponseHelper.buildResponse(createCodeService.createDeviceRegistrationCode(key));
// }
//
// /**
// * 使用登记证生成
// * @param key key
// * @return String
// */
// @TycloudOperation(ApiLevel = UserType.AGENCY)
// @PostMapping(value = "/URCode")
// @ApiOperation(httpMethod = "POST", value = "使用登记证生成", notes = "使用登记证生成")
// public ResponseModel<String> createURCode(@RequestParam("key") String key) {
// return ResponseHelper.buildResponse(createCodeService.createUseRegistrationCode(key));
// }
//
// /**
// * 96333顺序码生成
// * @param key key
// * @return String
// */
// @TycloudOperation(ApiLevel = UserType.AGENCY)
// @PostMapping(value = "/elevatorCode")
// @ApiOperation(httpMethod = "POST", value = "96333顺序码生成", notes = "96333顺序码生成")
// public ResponseModel<String> elevatorCode(@RequestParam("key") String key) {
// return ResponseHelper.buildResponse(createCodeService.createElevatorCode(key));
// }
//
// /**
// * 监管顺序码生成
// * @param key key
// * @return String
// */
// @TycloudOperation(ApiLevel = UserType.AGENCY)
// @PostMapping(value = "/sequenceKeyCode")
// @ApiOperation(httpMethod = "POST", value = "监管顺序码生成", notes = "监管顺序码生成")
// public ResponseModel<String> sequenceKeyCode(@RequestParam("key") String key) {
// return ResponseHelper.buildResponse(createCodeService.createSupervisoryCode(key));
// }
//}
package com.yeejoin.amos.boot.module.ymt.api.service;
import java.util.List;
/**
* 生成码服务类
* @author LiuLin
* @date 2023-12-14
*/
public interface IGenerateCodeService {
/**
* 生成申请单编号(13位,GZ20231214000)
* @param type 枚举类型
* @param batchSize 生成个数
* @return List
*/
List<String> createApplicationFormCode(String type, int batchSize);
/**
* 生成设备注册编码(20位)
* @param key key
* @return 顺序编号
*/
String createDeviceRegistrationCode(String key);
/**
* 生成使用登记证编号(13位,起11陕C00001(23))
* @param key key
* @return 顺序编号
*/
String createUseRegistrationCode(String key);
/**
* 96333编码生成(7位)
* @param key key
* @return 96333顺序码
*/
String createElevatorCode(String key);
/**
* 回退顺序码
* @param key redisKey
* @return bool
*/
boolean reduceElevatorCode(String key);
/**
* 监管编码生成(7位)
* @param key key
* @return 7位监管编码生成
*/
String createSupervisoryCode(String key);
}
package com.yeejoin.amos.boot.module.ymt.biz.controller;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.module.ymt.api.service.IGenerateCodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.List;
/**
*
* 生成顺序码
* @author LiuLin
* @date 2023-12-14
*/
@RestController
@Api(tags = "生成顺序码")
@RequestMapping(value = "/generate-code")
public class GenerateCodeController extends BaseController {
@Autowired
private IGenerateCodeService generateCodeService;
/**
* 申请单编号生成
* @param type type
* @param batchSize batchSize
* @return List
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/applicationFormCode")
@ApiOperation(httpMethod = "POST", value = "申请单编号生成", notes = "申请单编号生成")
public ResponseModel<List<String>> createApplicationFormCode(@RequestParam("type") String type,
@RequestParam("batchSize") int batchSize) {
return ResponseHelper.buildResponse(generateCodeService.createApplicationFormCode(type,batchSize));
}
/**
* 生成设备注册编码
* @param key key
* @return String
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/deviceRegistrationCode")
@ApiOperation(httpMethod = "POST", value = "生成设备注册编码", notes = "生成设备注册编码")
public ResponseModel<String> createDeviceRegistrationCode(@RequestParam("key") String key) {
return ResponseHelper.buildResponse(generateCodeService.createDeviceRegistrationCode(key));
}
/**
* 使用登记证生成
* @param key key
* @return String
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/useRegistrationCode")
@ApiOperation(httpMethod = "POST", value = "使用登记证生成", notes = "使用登记证生成")
public ResponseModel<String> createUseRegistrationCode(@RequestParam("key") String key) {
return ResponseHelper.buildResponse(generateCodeService.createUseRegistrationCode(key));
}
}
...@@ -59,6 +59,7 @@ import com.yeejoin.amos.boot.module.ymt.api.mapper.IdxBizJgTechParamsVesselMappe ...@@ -59,6 +59,7 @@ import com.yeejoin.amos.boot.module.ymt.api.mapper.IdxBizJgTechParamsVesselMappe
import com.yeejoin.amos.boot.module.ymt.api.mapper.SuperviseInfoMapper; import com.yeejoin.amos.boot.module.ymt.api.mapper.SuperviseInfoMapper;
import com.yeejoin.amos.boot.module.ymt.api.mapper.SupervisoryCodeInfoMapper; import com.yeejoin.amos.boot.module.ymt.api.mapper.SupervisoryCodeInfoMapper;
import com.yeejoin.amos.boot.module.ymt.api.service.IEquipmentCategoryService; import com.yeejoin.amos.boot.module.ymt.api.service.IEquipmentCategoryService;
import com.yeejoin.amos.boot.module.ymt.api.service.IGenerateCodeService;
import com.yeejoin.amos.boot.module.ymt.api.vo.EquipExportVo; import com.yeejoin.amos.boot.module.ymt.api.vo.EquipExportVo;
import com.yeejoin.amos.boot.module.ymt.biz.dao.ESElavtorRepository; import com.yeejoin.amos.boot.module.ymt.biz.dao.ESElavtorRepository;
import com.yeejoin.amos.boot.module.ymt.biz.dao.ESEquipmentCategory; import com.yeejoin.amos.boot.module.ymt.biz.dao.ESEquipmentCategory;
...@@ -105,7 +106,6 @@ import org.typroject.tyboot.core.rdbms.service.BaseService; ...@@ -105,7 +106,6 @@ import org.typroject.tyboot.core.rdbms.service.BaseService;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest; import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import org.typroject.tyboot.core.restful.utils.ResponseHelper; import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.io.IOException; import java.io.IOException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
...@@ -126,7 +126,6 @@ import java.util.concurrent.ExecutorService; ...@@ -126,7 +126,6 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
import static com.alibaba.fastjson.JSON.toJSONString; import static com.alibaba.fastjson.JSON.toJSONString;
/** /**
...@@ -269,6 +268,9 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -269,6 +268,9 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
IdxFeignService idxFeignService; IdxFeignService idxFeignService;
@Autowired @Autowired
IGenerateCodeService generateCodeService;
@Autowired
private static final String TABLENAME = "tableName"; private static final String TABLENAME = "tableName";
@Autowired @Autowired
private ESElavtorRepository esElavtorRepository; private ESElavtorRepository esElavtorRepository;
...@@ -707,12 +709,12 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -707,12 +709,12 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
* 具体生成监管码和电梯96333识别码逻辑 * 具体生成监管码和电梯96333识别码逻辑
*/ */
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
public synchronized Map<String, String> creatCode(String isNotXiXian,String city, String county, String equipCategory, String code96333, String supervisionCode) { public Map<String, String> creatCode(String isNotXiXian,String city, String county, String equipCategory, String code96333, String supervisionCode) {
RLock lock = redissonClient.getLock(LOCK_KEY); //RLock lock = redissonClient.getLock(LOCK_KEY);
Map<String, String> resultMap = null; Map<String, String> resultMap = null;
try { try {
lock.lock(); // 获取锁 //lock.lock(); // 获取锁
log.info("加锁成功"); //log.info("加锁成功");
resultMap = new HashMap<>(); resultMap = new HashMap<>();
StringBuilder supervisorCode = new StringBuilder(); StringBuilder supervisorCode = new StringBuilder();
StringBuilder elevatorCode = new StringBuilder(); StringBuilder elevatorCode = new StringBuilder();
...@@ -731,7 +733,7 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -731,7 +733,7 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
//查询未使用的电梯码 //查询未使用的电梯码
categoryOtherInfo = categoryOtherInfoMapper.selectElevatorCode(prefix, EquipmentCategoryEnum.WSY.getCode()); categoryOtherInfo = categoryOtherInfoMapper.selectElevatorCode(prefix, EquipmentCategoryEnum.WSY.getCode());
//如果存在未使用的电梯码则启用未使用的否则创建 //如果存在未使用的电梯码则启用未使用的否则创建
String elevator = ObjectUtils.isEmpty(categoryOtherInfo) ? createElevatorCode(prefix) : categoryOtherInfo.getCode(); String elevator = ObjectUtils.isEmpty(categoryOtherInfo) ? generateCodeService.createElevatorCode("96333_"+ prefix) : categoryOtherInfo.getCode();
if (!ObjectUtils.isEmpty(categoryOtherInfo)) { if (!ObjectUtils.isEmpty(categoryOtherInfo)) {
supervisoryCodeInfoMapper.delete(new QueryWrapper<SupervisoryCodeInfo>().eq("code96333", categoryOtherInfo.getCode())); supervisoryCodeInfoMapper.delete(new QueryWrapper<SupervisoryCodeInfo>().eq("code96333", categoryOtherInfo.getCode()));
} }
...@@ -775,10 +777,11 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -775,10 +777,11 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
resultMap.put("qrCode", ObjectUtils.isEmpty(supervisorCode) ? null : supervisorCode.toString()); resultMap.put("qrCode", ObjectUtils.isEmpty(supervisorCode) ? null : supervisorCode.toString());
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally {
lock.unlock(); // 释放锁
log.info("释放锁");
} }
//finally {
// lock.unlock(); // 释放锁
// log.info("释放锁");
//}
return resultMap; return resultMap;
} }
...@@ -803,34 +806,39 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -803,34 +806,39 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
Map<String, Object> divisionMap = equipmentCategoryMapper.getAdministrativeDivision(EquipmentCategoryEnum.XZQH.getCode(), county); 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(); division = ObjectUtils.isEmpty(divisionMap) ? equipmentCategoryMapper.getAdministrativeDivision(EquipmentCategoryEnum.XZQH.getCode(), city).get("code").toString() : divisionMap.get("code").toString();
} }
supervisorCode.append(division).append(equipCategory).append("-"); //supervisorCode.append(division).append(equipCategory).append("-");
supervisorCode.append(division).append(equipCategory);
return generateCodeService.createSupervisoryCode(String.valueOf(supervisorCode));
//获取行政区划区县、市是否存在历史监管码 //获取行政区划区县、市是否存在历史监管码
CategoryOtherInfo supervisor = categoryOtherInfoMapper.selectSupervisorCode(supervisorCode.toString()); //CategoryOtherInfo supervisor = categoryOtherInfoMapper.selectSupervisorCode(supervisorCode.toString());
//生成对应监管码 //生成对应监管码
if (!ObjectUtils.isEmpty(supervisor) && supervisor.getSupervisoryCode() != null) { //if (!ObjectUtils.isEmpty(supervisor) && supervisor.getSupervisoryCode() != null) {
//获取补零位长度 // //获取补零位长度
String supervisoryCode = supervisor.getSupervisoryCode().substring(6); // String supervisoryCode = supervisor.getSupervisoryCode().substring(6);
long num = Long.valueOf(supervisoryCode) + 1; // long num = Long.valueOf(supervisoryCode) + 1;
int numLength = String.valueOf(num).length(); // int numLength = String.valueOf(num).length();
int a = 7 - numLength; // int a = 7 - numLength;
StringBuilder zero = new StringBuilder(); // StringBuilder zero = new StringBuilder();
for (int i = 0; i < a; i++) { // for (int i = 0; i < a; i++) {
zero.append(EquipmentCategoryEnum.BLW.getCode()); // zero.append(EquipmentCategoryEnum.BLW.getCode());
} // }
zero.append(num); // zero.append(num);
supervisorCode.append(zero); // supervisorCode.append(zero);
} else { //} else {
supervisorCode.append(EquipmentCategoryEnum.JGM.getCode()); // supervisorCode.append(EquipmentCategoryEnum.JGM.getCode());
} //}
return supervisorCode.toString(); //return supervisorCode.toString();
} }
/** /**
*
* 生成96333电梯识别码 * 生成96333电梯识别码
* *
* @param prefix 电梯码前缀 * @param prefix 电梯码前缀
* @return 96333电梯识别码 * @return 96333电梯识别码
*/ */
@Deprecated
public String createElevatorCode(String prefix) { public String createElevatorCode(String prefix) {
StringBuilder elevatorCode = new StringBuilder(); StringBuilder elevatorCode = new StringBuilder();
//生成生成96333电梯码前缀 //生成生成96333电梯码前缀
...@@ -1622,7 +1630,8 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -1622,7 +1630,8 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
supervisoryCodeInfo.setStatus(EquipmentCategoryEnum.YSY.getCode()); supervisoryCodeInfo.setStatus(EquipmentCategoryEnum.YSY.getCode());
if (category.startsWith("3")) { if (category.startsWith("3")) {
if ("null".equals(map.get("code"))) { if ("null".equals(map.get("code"))) {
code96333 = createElevatorCode("31"); //code96333 = createElevatorCode("31");
code96333 = generateCodeService.createElevatorCode("96333_31");
supervisoryCodeInfo.setCreateStatus(CREATE); supervisoryCodeInfo.setCreateStatus(CREATE);
} else { } else {
supervisoryCodeInfo.setCreateStatus(NOT_CREATE); supervisoryCodeInfo.setCreateStatus(NOT_CREATE);
......
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