Commit b610efe6 authored by 王果's avatar 王果

Merge remote-tracking branch 'origin/develop_tzs_register' into develop_tzs_register

parents 98c36010 11a79d9e
...@@ -225,4 +225,15 @@ public class JgInstallationNoticeDto extends BaseDto { ...@@ -225,4 +225,15 @@ public class JgInstallationNoticeDto extends BaseDto {
@ApiModelProperty(value = "设备使用地点-街道(镇)") @ApiModelProperty(value = "设备使用地点-街道(镇)")
private String streetName; private String streetName;
private List<String> roleIds;
private String dataType ;
private String nextExecuteIds;
private String promoter;
private String instanceStatus;
} }
...@@ -367,4 +367,15 @@ public class JgInstallationNotice extends BaseEntity { ...@@ -367,4 +367,15 @@ public class JgInstallationNotice extends BaseEntity {
@TableField(value ="\"street_name\"") @TableField(value ="\"street_name\"")
private String streetName; private String streetName;
@TableField("next_execute_ids")
private String nextExecuteIds;
@TableField(value = "promoter")
private String promoter;
@TableField("instance_status")
private String instanceStatus;
} }
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
isn.city_name AS cityName, isn.city_name AS cityName,
isn.county_name AS countyName, isn.county_name AS countyName,
isn.instance_id AS instanceId, isn.instance_id AS instanceId,
isn.promoter,
isn.next_execute_ids AS nextExecuteIds,
isn.instance_status AS instanceStatus,
isn.notice_report_url AS noticeReportUrl isn.notice_report_url AS noticeReportUrl
FROM FROM
tzs_jg_installation_notice isn tzs_jg_installation_notice isn
...@@ -41,7 +44,7 @@ ...@@ -41,7 +44,7 @@
</if> </if>
</if> </if>
<if test="type == 'supervision'"> <if test="type == 'supervision'">
AND (isn.notice_status in ('6612', '6613', '6614') or isn.status in('6614') ) AND (isn.notice_status in ('6612', '6613', '6610') )
AND isn.receive_org_credit_code = #{orgCode} AND isn.receive_org_credit_code = #{orgCode}
</if> </if>
<if test="type == 'enterprise'"> <if test="type == 'enterprise'">
......
...@@ -6,11 +6,11 @@ import org.springframework.cloud.openfeign.FeignClient; ...@@ -6,11 +6,11 @@ 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 =
{FeignConfiguration.class}) {FeignConfiguration.class})
public interface TzsServiceFeignClient { public interface TzsServiceFeignClient {
...@@ -33,4 +33,32 @@ public interface TzsServiceFeignClient { ...@@ -33,4 +33,32 @@ 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 参考ApplicationFormTypeEnum中的枚举
* @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);
/**
* 生成设备注册编码
* @param key 16位
* @return 生成设备注册编码(20位)
*/
@RequestMapping(value = "/generate-code/deviceRegistrationCode", method = RequestMethod.POST)
ResponseModel<String> deviceRegistrationCode(@RequestParam("key") String key);
/**
* 使用登记证生成
* @param key 起11陕C
* @return 生成使用登记证编号(13位,起11陕C00001(23))
*/
@RequestMapping(value = "/generate-code/useRegistrationCode", method = RequestMethod.POST)
ResponseModel<String> useRegistrationCode(@RequestParam("key") String key);
} }
package com.yeejoin.amos.boot.module.jg.biz.service.impl; package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.aspose.words.SaveFormat; import com.aspose.words.SaveFormat;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
...@@ -9,6 +10,7 @@ import com.yeejoin.amos.boot.biz.common.bo.ReginParams; ...@@ -9,6 +10,7 @@ import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils; import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.module.jg.api.dto.ByteArrayMultipartFile; import com.yeejoin.amos.boot.module.jg.api.dto.ByteArrayMultipartFile;
import com.yeejoin.amos.boot.module.jg.api.dto.JgInstallationNoticeDto; import com.yeejoin.amos.boot.module.jg.api.dto.JgInstallationNoticeDto;
import com.yeejoin.amos.boot.module.jg.api.entity.JgInstallationNotice; import com.yeejoin.amos.boot.module.jg.api.entity.JgInstallationNotice;
...@@ -44,6 +46,7 @@ import org.springframework.util.Assert; ...@@ -44,6 +46,7 @@ import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil; import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService; import org.typroject.tyboot.core.rdbms.service.BaseService;
...@@ -174,10 +177,11 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN ...@@ -174,10 +177,11 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
if (Objects.isNull(noticeDto) || StringUtils.isEmpty(submitType)) { if (Objects.isNull(noticeDto) || StringUtils.isEmpty(submitType)) {
throw new IllegalArgumentException("参数不能为空"); throw new IllegalArgumentException("参数不能为空");
} }
String[] taskName = new String[]{"流程结束"};
// 字段转换 // 字段转换
this.convertField(noticeDto); this.convertField(noticeDto);
ArrayList<String> roleListFirst = new ArrayList<>();
ArrayList<String> roleListSecond = new ArrayList<>();
if (SUBMIT_TYPE_FLOW.equals(submitType)) { if (SUBMIT_TYPE_FLOW.equals(submitType)) {
AjaxResult ajaxResult; AjaxResult ajaxResult;
// 发起流程 // 发起流程
...@@ -189,34 +193,32 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN ...@@ -189,34 +193,32 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
ajaxResult = Workflow.taskClient.startByVariable(dto); ajaxResult = Workflow.taskClient.startByVariable(dto);
String instanceId = ((Map) ajaxResult.get("data")).get("id").toString(); String instanceId = ((Map) ajaxResult.get("data")).get("id").toString();
noticeDto.setInstanceId(instanceId); noticeDto.setInstanceId(instanceId);
// 查询下节点任务
getNext(roleListFirst, instanceId,taskName);
noticeDto.setInstanceStatus(String.join(",", roleListFirst));
} catch (Exception e) { } catch (Exception e) {
log.error("提交失败:{}", e); log.error("提交失败:{}", e);
} }
} }
ajaxResult = Workflow.taskClient.getTask(noticeDto.getInstanceId()); JgInstallationNotice notice = new JgInstallationNotice();
JSONObject dataObject = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data"))); BeanUtils.copyProperties(noticeDto,notice);
String taskId = dataObject.getString("id");
//组装信息 boolean submit = submit(notice, op);
TaskResultDTO taskResultDTO = new TaskResultDTO();
taskResultDTO.setResultCode("approvalStatus"); if(submit) {
taskResultDTO.setTaskId(taskId); // 查询下节点任务
taskResultDTO.setComment("提交流程"); getNext(roleListSecond, notice.getInstanceId(),taskName);
HashMap<String, Object> map = new HashMap<>(); notice.setStatus(taskName[0]);
map.put("approvalStatus", op); if (!ObjectUtils.isEmpty(notice.getInstanceStatus())) {
taskResultDTO.setVariable(map); notice.setInstanceStatus(notice.getInstanceStatus() + "," + roleListSecond);
//执行流程 } else {
AjaxResult ajaxResult1; notice.setInstanceStatus(String.join(",", roleListSecond));
try {
ajaxResult1 = Workflow.taskClient.completeByTask(taskId, taskResultDTO);
if (ajaxResult1.get("code").equals(200)) {
noticeDto.setNoticeStatus(String.valueOf(FlowStatusEnum.TO_BE_PROCESSED.getCode()));
JgInstallationNotice bean = new JgInstallationNotice();
BeanUtils.copyProperties(noticeDto, bean);
jgInstallationNoticeMapper.updateById(bean);
} }
} catch (Exception e) { notice.setPromoter(RequestContext.getExeUserId());
log.error("提交失败:{}", e); notice.setNextExecuteIds(String.join(",", roleListSecond));
notice.setNoticeStatus(String.valueOf(FlowStatusEnum.TO_BE_PROCESSED.getCode()));
jgInstallationNoticeMapper.updateById(notice);
} }
} else { } else {
JgInstallationNotice bean = new JgInstallationNotice(); JgInstallationNotice bean = new JgInstallationNotice();
...@@ -401,6 +403,8 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN ...@@ -401,6 +403,8 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
@SuppressWarnings({"Duplicates", "rawtypes"}) @SuppressWarnings({"Duplicates", "rawtypes"})
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void saveNotice(String submitType, Map<String, JgInstallationNoticeDto> jgInstallationNoticeDtoMap, ReginParams reginParams) { public void saveNotice(String submitType, Map<String, JgInstallationNoticeDto> jgInstallationNoticeDtoMap, ReginParams reginParams) {
String[] taskName = new String[]{"流程结束"};
JgInstallationNoticeDto model = jgInstallationNoticeDtoMap.get(TABLE_PAGE_ID); JgInstallationNoticeDto model = jgInstallationNoticeDtoMap.get(TABLE_PAGE_ID);
// 字段转换 // 字段转换
convertField(model); convertField(model);
...@@ -417,6 +421,8 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN ...@@ -417,6 +421,8 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
return; return;
} }
ArrayList<String> roleListFirst = new ArrayList<>();
ArrayList<String> roleListSecond = new ArrayList<>();
// 判断当前是否为提交 // 判断当前是否为提交
List<String> instanceIdList = new ArrayList<>(); List<String> instanceIdList = new ArrayList<>();
if (SUBMIT_TYPE_FLOW.equals(submitType)) { if (SUBMIT_TYPE_FLOW.equals(submitType)) {
...@@ -429,7 +435,7 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN ...@@ -429,7 +435,7 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
ActWorkflowStartDTO dto = new ActWorkflowStartDTO(); ActWorkflowStartDTO dto = new ActWorkflowStartDTO();
dto.setProcessDefinitionKey(PROCESS_DEFINITION_KEY); dto.setProcessDefinitionKey(PROCESS_DEFINITION_KEY);
dto.setBusinessKey(String.valueOf(i)); dto.setBusinessKey(String.valueOf(i));
dto.setCompleteFirstTask(true); // dto.setCompleteFirstTask(true);
list.add(dto); list.add(dto);
} }
actWorkflowBatchDTO.setProcess(list); actWorkflowBatchDTO.setProcess(list);
...@@ -440,11 +446,39 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN ...@@ -440,11 +446,39 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
for (Object obj :returnList for (Object obj :returnList
) { ) {
JSONObject jsonObject = JSON.parseObject(JSONObject.toJSONString(obj)); JSONObject jsonObject = JSON.parseObject(JSONObject.toJSONString(obj));
instanceIdList.add(jsonObject.getString("id")); String instanceId = jsonObject.getString("id");
instanceIdList.add(instanceId);
// 查询下节点任务
if(returnList.get(0).equals(obj)) {
getNext(roleListFirst, instanceId,taskName);
}
// 推动下一个节点
AjaxResult ajaxResult = Workflow.taskClient.getTask(instanceId);
JSONObject dataObject = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")));
String taskId = dataObject.getString("id");
//组装信息
TaskResultDTO dto = new TaskResultDTO();
dto.setResultCode("approvalStatus");
dto.setTaskId(taskId);
dto.setComment("提交流程");
HashMap<String, Object> map = new HashMap<>();
map.put("approvalStatus", "0");
dto.setVariable(map);
//执行流程
AjaxResult ajaxResult1 = null;
try {
ajaxResult1 = Workflow.taskClient.completeByTask(taskId, dto);
if (ajaxResult1.get("code").equals(200)) {
getNext(roleListSecond, instanceId,taskName);
} else {
log.error("提交失败");
}
} catch (Exception e) {
log.error("提交失败:{}", e);
}
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.error("提交失败:{}", e);
} }
} }
...@@ -458,6 +492,10 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN ...@@ -458,6 +492,10 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
String applyNo = applyNoList.get(i); String applyNo = applyNoList.get(i);
dto.setApplyNo(applyNo); dto.setApplyNo(applyNo);
dto.setNoticeDate(new Date()); dto.setNoticeDate(new Date());
dto.setNextExecuteIds(String.join(",", roleListSecond));
dto.setInstanceStatus(String.join(",", roleListFirst));
dto.setPromoter(reginParams.getUserModel().getUserId());
dto.setStatus(taskName[0]);
dto.setInstallUnitName(reginParams.getCompany().getCompanyName()); dto.setInstallUnitName(reginParams.getCompany().getCompanyName());
dto.setInstallUnitCreditCode(reginParams.getCompany().getCompanyCode()); dto.setInstallUnitCreditCode(reginParams.getCompany().getCompanyCode());
jgRelationEquip.setEquId(String.valueOf(obj.get("SEQUENCE_NBR"))); jgRelationEquip.setEquId(String.valueOf(obj.get("SEQUENCE_NBR")));
...@@ -484,6 +522,22 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN ...@@ -484,6 +522,22 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
} }
void getNext(ArrayList<String> roleListFirst, String instanceId, String[] taskName) {
AjaxResult aj = Workflow.taskClient.getTaskNoAuth(instanceId);
JSONObject taskNoAuth = JSON.parseObject(JSON.toJSONString(aj.get("data")));
if (!ObjectUtils.isEmpty(taskNoAuth)) {
String nextTaskId = taskNoAuth.getString("id");
AjaxResult taskGroupName = Workflow.taskClient.getTaskGroupName(nextTaskId);
taskName[0] = taskNoAuth.getString("name");
JSONArray data = JSON.parseArray(JSON.toJSONString(taskGroupName.get("data")));
for (Object datum : data) {
if (((Map) datum).containsKey("groupId")) {
roleListFirst.add(((Map) datum).get("groupId").toString());
}
}
}
}
private void convertField(JgInstallationNoticeDto model) { private void convertField(JgInstallationNoticeDto model) {
// 处理图片 // 处理图片
if(!ValidationUtil.isEmpty(model.getProxyStatementAttachmentList())) { if(!ValidationUtil.isEmpty(model.getProxyStatementAttachmentList())) {
...@@ -596,16 +650,23 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN ...@@ -596,16 +650,23 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
} }
public void cancel(JgInstallationNoticeDto noticeDto) { public void cancel(JgInstallationNoticeDto noticeDto) {
String[] taskName = new String[]{"流程结束"};
FeignClientResult ajaxResult = Workflow.taskV2Client.rollBack(noticeDto.getInstanceId()); FeignClientResult ajaxResult = Workflow.taskV2Client.rollBack(noticeDto.getInstanceId());
JgInstallationNotice jgInstallationNotice = this.baseMapper.selectById(noticeDto.getSequenceNbr()); JgInstallationNotice jgInstallationNotice = this.baseMapper.selectById(noticeDto.getSequenceNbr());
ArrayList<String> roleList = new ArrayList<>();
if(ajaxResult.getStatus() == 200) { if(ajaxResult.getStatus() == 200) {
getNext(roleList, noticeDto.getInstanceId(),taskName);
jgInstallationNotice.setStatus(taskName[0]);
jgInstallationNotice.setPromoter("");
jgInstallationNotice.setNextExecuteIds(String.join(",", roleList));
jgInstallationNotice.setNoticeStatus(String.valueOf(FlowStatusEnum.TO_BE_SUBMITTED.getCode())); jgInstallationNotice.setNoticeStatus(String.valueOf(FlowStatusEnum.TO_BE_SUBMITTED.getCode()));
jgInstallationNoticeMapper.updateById(jgInstallationNotice); jgInstallationNoticeMapper.updateById(jgInstallationNotice);
} }
} }
public void accept(JgInstallationNoticeDto dto,String op) { public void accept(JgInstallationNoticeDto dto,String op) {
String[] taskName = new String[]{"流程结束"};
String userId = RequestContext.getExeUserId();
JgInstallationNotice jgInstallationNotice = this.jgInstallationNoticeMapper.selectById(dto.getSequenceNbr()); JgInstallationNotice jgInstallationNotice = this.jgInstallationNoticeMapper.selectById(dto.getSequenceNbr());
// 组装设备注册代码 // 组装设备注册代码
StringBuffer stringBuffer = new StringBuffer(); StringBuffer stringBuffer = new StringBuffer();
...@@ -616,93 +677,80 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN ...@@ -616,93 +677,80 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
log.error("日期转换失败:{}", e); log.error("日期转换失败:{}", e);
} }
LambdaQueryWrapper<JgInstallationNoticeEq> queryWrapper = new LambdaQueryWrapper<>(); ArrayList<String> roleList = new ArrayList<>();
queryWrapper.eq(JgInstallationNoticeEq::getEquipTransferId,dto.getSequenceNbr());
JgInstallationNoticeEq jgRelationEquip = jgInstallationNoticeEqMapper.selectOne(queryWrapper);
LambdaQueryWrapper<OtherInfo> queryWrapper1 = new LambdaQueryWrapper<>();
queryWrapper1.eq(OtherInfo::getRecord,jgRelationEquip.getEquId());
OtherInfo tzsJgOtherInfo = tzsJgOtherInfoMapper.selectOne(queryWrapper1);
LambdaQueryWrapper<RegistrationInfo> queryWrapper2 = new LambdaQueryWrapper<>();
queryWrapper2.eq(RegistrationInfo::getRecord,jgRelationEquip.getEquId());
RegistrationInfo tzsJgRegistrationInfo = tzsJgRegistrationInfoMapper.selectOne(queryWrapper2);
stringBuffer.append(tzsJgRegistrationInfo.getEquCategory()).append(jgInstallationNotice.getCity()).append(ym);
String equCode = stringBuffer.toString();
String deviceRegistrationCode = iCreateCodeService.createDeviceRegistrationCode(equCode);
Map<String, Object> map = new HashMap<>();
map.put("cityCode",jgInstallationNotice.getCity());
map.put("countyCode",jgInstallationNotice.getCounty());
map.put("equCategory",tzsJgRegistrationInfo.getEquCategory());
map.put("isXiXian", jgInstallationNotice.getIsXixian() == null ? "0" : jgInstallationNotice.getIsXixian());
Map<String, Object> mapCode;
ResponseModel<Map<String, Object>> code = tzsServiceFeignClient.createCode(map);
mapCode = code.getResult();
LambdaQueryWrapper<SupervisoryCodeInfo> queryWrapper3 = new LambdaQueryWrapper<>();
queryWrapper3.eq(SupervisoryCodeInfo::getSupervisoryCode,mapCode.get("superviseCode").toString());
SupervisoryCodeInfo supervisoryCodeInfo = supervisoryCodeInfoMapper.selectOne(queryWrapper3);
supervisoryCodeInfo.setStatus("1");
supervisoryCodeInfoMapper.updateById(supervisoryCodeInfo);
boolean submit = submit(jgInstallationNotice, op); boolean submit = submit(jgInstallationNotice, op);
if(submit) { if(submit) {
getNext(roleList, dto.getInstanceId(),taskName);
jgInstallationNotice.setStatus(taskName[0]);
if("0".equals(op)) { if("0".equals(op)) {
jgInstallationNotice.setNoticeStatus(String.valueOf(FlowStatusEnum.HAVE_PROCESSED.getCode())); if(roleList.size() == 0) {
this.generateInstallationNoticeReport(jgInstallationNotice.getSequenceNbr());
// 更新其他业务表 LambdaQueryWrapper<JgInstallationNoticeEq> queryWrapper = new LambdaQueryWrapper<>();
tzsJgOtherInfo.setCode96333(mapCode.get("code96333").toString()); queryWrapper.eq(JgInstallationNoticeEq::getEquipTransferId,dto.getSequenceNbr());
tzsJgOtherInfo.setSupervisoryCode(mapCode.get("superviseCode").toString()); JgInstallationNoticeEq jgRelationEquip = jgInstallationNoticeEqMapper.selectOne(queryWrapper);
tzsJgRegistrationInfo.setEquCode(deviceRegistrationCode);
jgInstallationNotice.setEquRegisterCode(deviceRegistrationCode); LambdaQueryWrapper<OtherInfo> queryWrapper1 = new LambdaQueryWrapper<>();
jgInstallationNotice.setSupervisoryCode(mapCode.get("superviseCode").toString()); queryWrapper1.eq(OtherInfo::getRecord,jgRelationEquip.getEquId());
Map<String,Map<String,Object>> objMap = new HashMap<>(); OtherInfo tzsJgOtherInfo = tzsJgOtherInfoMapper.selectOne(queryWrapper1);
Map<String,Object> map1 =new HashMap<>();
map1.put("CODE96333",tzsJgOtherInfo.getCode96333() ); LambdaQueryWrapper<RegistrationInfo> queryWrapper2 = new LambdaQueryWrapper<>();
map1.put("EQU_CODE",tzsJgRegistrationInfo.getEquCode() ); queryWrapper2.eq(RegistrationInfo::getRecord,jgRelationEquip.getEquId());
map1.put("SUPERVISORY_CODE",tzsJgOtherInfo.getSupervisoryCode()); RegistrationInfo tzsJgRegistrationInfo = tzsJgRegistrationInfoMapper.selectOne(queryWrapper2);
objMap.put(tzsJgOtherInfo.getRecord(),map1);
tzsServiceFeignClient.commonUpdateEsDataByIds(objMap); stringBuffer.append(tzsJgRegistrationInfo.getEquCategory()).append(jgInstallationNotice.getCity()).append(ym);
tzsJgOtherInfoMapper.updateById(tzsJgOtherInfo); String equCode = stringBuffer.toString();
tzsJgRegistrationInfoMapper.updateById(tzsJgRegistrationInfo);
ResponseModel<String> responseModel = tzsServiceFeignClient.deviceRegistrationCode(equCode);
String deviceRegistrationCode = responseModel.getResult();
Map<String, Object> map = new HashMap<>();
map.put("cityCode",jgInstallationNotice.getCity());
map.put("countyCode",jgInstallationNotice.getCounty());
map.put("equCategory",tzsJgRegistrationInfo.getEquCategory());
map.put("isXiXian", jgInstallationNotice.getIsXixian() == null ? "0" : jgInstallationNotice.getIsXixian());
Map<String, Object> mapCode;
ResponseModel<Map<String, Object>> code = tzsServiceFeignClient.createCode(map);
mapCode = code.getResult();
LambdaQueryWrapper<SupervisoryCodeInfo> queryWrapper3 = new LambdaQueryWrapper<>();
queryWrapper3.eq(SupervisoryCodeInfo::getSupervisoryCode,mapCode.get("superviseCode").toString());
SupervisoryCodeInfo supervisoryCodeInfo = supervisoryCodeInfoMapper.selectOne(queryWrapper3);
supervisoryCodeInfo.setStatus("1");
supervisoryCodeInfoMapper.updateById(supervisoryCodeInfo);
jgInstallationNotice.setNoticeStatus(String.valueOf(FlowStatusEnum.HAVE_PROCESSED.getCode()));
this.generateInstallationNoticeReport(jgInstallationNotice.getSequenceNbr());
// 更新其他业务表
tzsJgOtherInfo.setCode96333(mapCode.get("code96333").toString());
tzsJgOtherInfo.setSupervisoryCode(mapCode.get("superviseCode").toString());
tzsJgRegistrationInfo.setEquCode(deviceRegistrationCode);
jgInstallationNotice.setEquRegisterCode(deviceRegistrationCode);
jgInstallationNotice.setSupervisoryCode(mapCode.get("superviseCode").toString());
Map<String,Map<String,Object>> objMap = new HashMap<>();
Map<String,Object> map1 =new HashMap<>();
map1.put("CODE96333",tzsJgOtherInfo.getCode96333() );
map1.put("EQU_CODE",tzsJgRegistrationInfo.getEquCode() );
map1.put("SUPERVISORY_CODE",tzsJgOtherInfo.getSupervisoryCode());
objMap.put(tzsJgOtherInfo.getRecord(),map1);
jgInstallationNotice.setPromoter("");
tzsServiceFeignClient.commonUpdateEsDataByIds(objMap);
tzsJgOtherInfoMapper.updateById(tzsJgOtherInfo);
tzsJgRegistrationInfoMapper.updateById(tzsJgRegistrationInfo);
} else {
jgInstallationNotice.setNextExecuteIds(String.join(",", roleList));
if (!ObjectUtils.isEmpty(jgInstallationNotice.getInstanceStatus())) {
jgInstallationNotice.setInstanceStatus(jgInstallationNotice.getInstanceStatus() + "," + String.join(",", roleList));
} else {
jgInstallationNotice.setInstanceStatus(String.join(",", roleList));
}
jgInstallationNotice.setPromoter(userId);
jgInstallationNotice.setNoticeStatus(String.valueOf(FlowStatusEnum.TO_BE_PROCESSED.getCode()));
}
} else { } else {
jgInstallationNotice.setPromoter("");
jgInstallationNotice.setNoticeStatus(String.valueOf(FlowStatusEnum.TO_BE_SUBMITTED.getCode())); jgInstallationNotice.setNoticeStatus(String.valueOf(FlowStatusEnum.TO_BE_SUBMITTED.getCode()));
jgInstallationNotice.setStatus(String.valueOf(FlowStatusEnum.REJECTED.getCode()));
} }
jgInstallationNoticeMapper.updateById(jgInstallationNotice); jgInstallationNoticeMapper.updateById(jgInstallationNotice);
} }
// // 组装监管码
// String division = "";
// if (((XIAN.equals(dto.getCity()) || XIAN_YANG.equals(dto.getCity())) && "1".equals(dto.getIsXixian()))) {
// division = "X";
// } else {
// //生成监管码前缀
// Map<String, Object> divisionMap = equipmentCategoryMapper.getAdministrativeDivision(EquipmentCategoryEnum.XZQH.getCode(), dto.getCounty());
// division = ObjectUtils.isEmpty(divisionMap) ? equipmentCategoryMapper.getAdministrativeDivision(EquipmentCategoryEnum.XZQH.getCode(), dto.getCity()).get("code").toString() : divisionMap.get("code").toString();
// }
//
// // 组装96333码
// String prefix = "";
// if (((XIAN.equals(dto.getCity()) || XIAN_YANG.equals(dto.getCity())) && "1".equals(dto.getIsXixian()))) {
// prefix = EquipmentCategoryEnum.XXCSM.getValue();
// } else {
// Map<String, Object> elevatorMap = equipmentCategoryMapper.getAdministrativeDivision(EquipmentCategoryEnum.XZQHDT.getCode(), dto.getCounty());
// prefix = ObjectUtils.isEmpty(elevatorMap) ? equipmentCategoryMapper.getAdministrativeDivision(EquipmentCategoryEnum.XZQHDT.getCode(), dto.getCity()).get("code").toString() : elevatorMap.get("code").toString();
// }
} }
} }
\ No newline at end of file
...@@ -323,7 +323,7 @@ public class JyjcInspectionApplicationServiceImpl extends BaseService<JyjcInspec ...@@ -323,7 +323,7 @@ public class JyjcInspectionApplicationServiceImpl extends BaseService<JyjcInspec
List<JSONObject> records = response.getResult().getRecords(); List<JSONObject> records = response.getResult().getRecords();
ArrayList<Map<String, Object>> arrayList = new ArrayList<>(); ArrayList<Map<String, Object>> arrayList = new ArrayList<>();
records.forEach(item -> { records.forEach(item -> {
item.remove("SEQUENCE_NBR"); // item.remove("SEQUENCE_NBR");
HashMap<String, Object> objectHashMap = new HashMap<>(); HashMap<String, Object> objectHashMap = new HashMap<>();
for (Map.Entry<String, Object> stringObjectEntry : item.entrySet()) { for (Map.Entry<String, Object> stringObjectEntry : item.entrySet()) {
objectHashMap.put(stringObjectEntry.getKey(), stringObjectEntry.getValue()); objectHashMap.put(stringObjectEntry.getKey(), stringObjectEntry.getValue());
......
//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);
......
package com.yeejoin.amos.boot.module.ymt.biz.service.impl;
import com.yeejoin.amos.boot.module.ymt.api.common.DateUtils;
import com.yeejoin.amos.boot.module.ymt.api.enums.ApplicationFormTypeEnum;
import com.yeejoin.amos.boot.module.ymt.api.enums.EquipmentCategoryEnum;
import com.yeejoin.amos.boot.module.ymt.api.service.IGenerateCodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* @author LiuLin
* @date 2023-12-14
*/
@Slf4j
@Service
public class GenerateCodeServiceImpl implements IGenerateCodeService {
private static final String LOCK_VALUE = "locked";
private static final String LOCK_KEY_AF = "sequence_lock_af";
private static final String SEQUENCE_TYPE_AF = "%03d";
private static final String LOCK_KEY_DR = "sequence_lock_dr";
private static final String SEQUENCE_TYPE_DR = "%04d";
private static final String LOCK_KEY_UR = "sequence_lock_ur";
private static final String LOCK_KEY_ELEVATOR = "sequence_lock_elevator";
private static final String LOCK_KEY_SUPERVISORY = "sequence_lock_supervisory";
private static final String SEQUENCE_TYPE_UR = "%05d";
private static final String SEQUENCE_TYPE = "%07d";
private final RedisTemplate<String, String> redisTemplate;
private String rulePrefix = "";
public GenerateCodeServiceImpl(RedisTemplate<String, String> redisTemplate) {
this.redisTemplate = redisTemplate;
}
/**
* 生成申请单编号(13位,GZ20231214000)
*
* @param type 枚举类型
* @param batchSize 生成个数
* @return List
*/
@Override
public List<String> createApplicationFormCode(String type, int batchSize) {
if (!isValueInEnum(type)) {
return Collections.emptyList();
}
rulePrefix = type + LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
return generateBatchSequence(type, batchSize);
}
/**
* 生成设备注册编码(20位)
*
* @param key key
* @return 顺序编号
*/
@Override
public String createDeviceRegistrationCode(String key) {
return (key.length() == 16) ? generateSequence(key, SEQUENCE_TYPE_DR, LOCK_KEY_DR) : "生成码规则不对!";
}
/**
* 生成使用登记证编号(13位,起11陕C00001(23))
*
* @param key key
* @return 顺序编号
*/
@Override
public String createUseRegistrationCode(String key) {
rulePrefix = "(" + LocalDate.now().format(DateTimeFormatter.ofPattern("yy")) + ")";
return generateSequence(key, SEQUENCE_TYPE_UR, LOCK_KEY_UR);
}
@Override
public String createElevatorCode(String key) {
return (key.length() == 8) ? generateElevatorSequence(key, SEQUENCE_TYPE, LOCK_KEY_ELEVATOR) : "生成码规则不对!";
}
@Override
public boolean reduceElevatorCode(String key) {
return reduceSequence(key, SEQUENCE_TYPE, LOCK_KEY_ELEVATOR);
}
@Override
public String createSupervisoryCode(String key) {
return (key.length() == 5) ? generateSupervisorySequence(key) : "生成码规则不对!";
}
private String generateSupervisorySequence(String sequenceKey) {
// 使用分布式锁,确保在并发情况下只有一个线程能够生成顺序码
Boolean lockAcquired = obtainLock(GenerateCodeServiceImpl.LOCK_KEY_SUPERVISORY);
if (Boolean.TRUE.equals(lockAcquired)) {
try {
// 获取当前顺序码
ValueOperations<String, String> valueOps = redisTemplate.opsForValue();
String currentSequenceStr = valueOps.get(sequenceKey);
// 如果为空,则初始化为0
Long currentSequence = (currentSequenceStr != null) ? Long.parseLong(currentSequenceStr) : 0L;
log.info("===================>获取《{}》当前顺序码:{}<===================", sequenceKey, currentSequenceStr);
currentSequence++;
// 生成顺序码
String formattedSequence = String.format(GenerateCodeServiceImpl.SEQUENCE_TYPE, currentSequence);
log.info("===================>更新《{}》顺序码:{}<===================", sequenceKey, formattedSequence);
// 更新顺序码
valueOps.set(sequenceKey, formattedSequence);
return sequenceKey + "-" + formattedSequence;
} finally {
releaseLock(GenerateCodeServiceImpl.LOCK_KEY_SUPERVISORY);
}
} else {
throw new RuntimeException("Failed to acquire lock for sequence generation");
}
}
/**
* 校验枚举合法性
*
* @param value value
* @return bool
*/
public boolean isValueInEnum(String value) {
return EnumSet.allOf(ApplicationFormTypeEnum.class)
.stream()
.anyMatch(enumValue -> enumValue.name().equals(value));
}
/**
* 批量生成顺序码
*
* @param sequenceKey sequenceKey
* @param batchSize 批量生成个数
* @return List
*/
public List<String> generateBatchSequence(String sequenceKey, int batchSize) {
// 使用分布式锁,确保在并发情况下只有一个线程能够生成顺序码
Boolean lockAcquired = redisTemplate.opsForValue().setIfAbsent(LOCK_KEY_AF, LOCK_VALUE);
if (Boolean.TRUE.equals(lockAcquired)) {
try {
// 获取当前顺序码
ValueOperations<String, String> valueOps = redisTemplate.opsForValue();
String currentSequenceStr = valueOps.get(sequenceKey);
// 如果为空,则初始化为0
Long currentSequence = (currentSequenceStr != null) ? Long.parseLong(currentSequenceStr) : 0L;
log.info("===================>获取《{}》当前顺序码:{}<===================", sequenceKey, currentSequenceStr);
// 生成批量顺序码
List<String> sequenceList = new ArrayList<>();
log.info("===================>批量生成{}个《{}》顺序码<===================", batchSize, sequenceKey);
for (int i = 0; i < batchSize; i++) {
currentSequence++;
// 生成3位顺序码
String formattedSequence = String.format(SEQUENCE_TYPE_AF, currentSequence);
sequenceList.add(rulePrefix + formattedSequence);
// 更新顺序码
log.info("===================>更新《{}》顺序码:{}<===================", sequenceKey, formattedSequence);
setValueWithDailyExpiration(sequenceKey, String.valueOf(formattedSequence));
}
return sequenceList;
} finally {
redisTemplate.delete(LOCK_KEY_AF);
}
} else {
// 获取锁失败,可以选择重试或采取其他策略
throw new RuntimeException("Failed to acquire lock for sequence generation");
}
}
/**
* 生成顺序码
*
* @param sequenceKey redisKey
* @param sequenceType 生成码类型
* @param lockKey redis锁
* @return s
*/
public String generateSequence(String sequenceKey, String sequenceType, String lockKey) {
// 使用分布式锁,确保在并发情况下只有一个线程能够生成顺序码
Boolean lockAcquired = obtainLock(lockKey);
if (Boolean.TRUE.equals(lockAcquired)) {
try {
// 获取当前顺序码
ValueOperations<String, String> valueOps = redisTemplate.opsForValue();
String currentSequenceStr = valueOps.get(sequenceKey);
// 如果为空,则初始化为0
Long currentSequence = (currentSequenceStr != null) ? Long.parseLong(currentSequenceStr) : 0L;
log.info("===================>获取《{}》当前顺序码:{}<===================", sequenceKey, currentSequenceStr);
currentSequence++;
// 生成顺序码
String formattedSequence = String.format(sequenceType, currentSequence);
log.info("===================>更新《{}》顺序码:{}<===================", sequenceKey, formattedSequence);
// 更新顺序码
if (lockKey.equals(LOCK_KEY_DR)) {
setValueWithMonthlyExpiration(sequenceKey, String.valueOf(formattedSequence));
} else {
setValueWithYearlyExpiration(sequenceKey, String.valueOf(formattedSequence));
}
String generatedSequence = sequenceKey + formattedSequence;
String result = generatedSequence + (lockKey.equals(LOCK_KEY_DR) ? "" : rulePrefix);
log.info("===================>返回《{}》顺序码:{}<===================", sequenceKey, result);
return result;
} finally {
releaseLock(lockKey);
}
} else {
throw new RuntimeException("Failed to acquire lock for sequence generation");
}
}
/**
* 生成顺序码
*
* @param sequenceKey redisKey
* @param sequenceType 生成码类型
* @param lockKey redis锁
* @return s
*/
public String generateElevatorSequence(String sequenceKey, String sequenceType, String lockKey) {
// 使用分布式锁,确保在并发情况下只有一个线程能够生成顺序码
Boolean lockAcquired = obtainLock(lockKey);
if (Boolean.TRUE.equals(lockAcquired)) {
try {
// 获取当前顺序码
ValueOperations<String, String> valueOps = redisTemplate.opsForValue();
String currentSequenceStr = valueOps.get(sequenceKey);
// 如果为空,则初始化为0
if (currentSequenceStr == null) {
currentSequenceStr = EquipmentCategoryEnum.getCodeByValue(sequenceKey);
log.info("===================>获取《{}》初始码:{}<===================", sequenceKey, currentSequenceStr);
return currentSequenceStr;
}
Long currentSequence = Long.parseLong(currentSequenceStr);
log.info("===================>获取《{}》当前顺序码:{}<===================", sequenceKey, currentSequenceStr);
currentSequence++;
// 生成顺序码
String formattedSequence = String.format(sequenceType, currentSequence);
log.info("===================>更新《{}》顺序码:{}<===================", sequenceKey, formattedSequence);
// 更新顺序码
valueOps.set(sequenceKey, formattedSequence);
return formattedSequence;
} finally {
releaseLock(lockKey);
}
} else {
throw new RuntimeException("Failed to acquire lock for sequence generation");
}
}
/**
* 回退顺序码
*
* @param sequenceKey redisKey
* @param sequenceType 码类型
* @param lockKey 分布锁
* @return 操作是否成功
*/
public boolean reduceSequence(String sequenceKey, String sequenceType, String lockKey) {
// 使用分布式锁,确保在并发情况下只有一个线程能够生成顺序码
Boolean lockAcquired = obtainLock(lockKey);
if (Boolean.TRUE.equals(lockAcquired)) {
try {
// 获取当前顺序码
ValueOperations<String, String> valueOps = redisTemplate.opsForValue();
String currentSequenceStr = valueOps.get(sequenceKey);
// 如果为空,则初始化为0
long currentSequence = (currentSequenceStr != null) ? Long.parseLong(currentSequenceStr) : 0L;
log.info("===================>获取《{}》当前顺序码:{}<===================", sequenceKey, currentSequenceStr);
// 判断是否有可回退的操作
if (currentSequence > 0) {
currentSequence--;
// 生成顺序码
String formattedSequence = String.format(sequenceType, currentSequence);
log.info("===================>回退《{}》顺序码:{}<===================", sequenceKey, formattedSequence);
// 更新顺序码
valueOps.set(sequenceKey, String.valueOf(formattedSequence));
return true; // 回退成功
} else {
log.warn("===================>无法回退《{}》顺序码,当前顺序码已为0<===================", sequenceKey);
return false; // 无法回退,当前顺序码已为0
}
} finally {
releaseLock(lockKey);
}
} else {
throw new RuntimeException("Failed to acquire lock for sequence generation");
}
}
/**
* 分布式锁
*
* @param lockKey lockKey
* @return bool
*/
private Boolean obtainLock(String lockKey) {
return redisTemplate.opsForValue().setIfAbsent(lockKey, LOCK_VALUE);
}
/**
* 释放锁
*
* @param lockKey lockKey
*/
private void releaseLock(String lockKey) {
redisTemplate.delete(lockKey);
}
/**
* redis 根据自然日过期
*
* @param key key
* @param value value
*/
public void setValueWithDailyExpiration(String key, String value) {
Date endOfDay = DateUtils.calculateEndOfDay(new Date());
setValueWithExpiration(key, value, endOfDay);
}
/**
* redis 根据自然月过期
*
* @param key key
* @param value value
*/
public void setValueWithMonthlyExpiration(String key, String value) {
Date endOfMonth = DateUtils.calculateEndOfMonth(new Date());
setValueWithExpiration(key, value, endOfMonth);
}
/**
* redis 根据自然年过期
*
* @param key key
* @param value value
*/
public void setValueWithYearlyExpiration(String key, String value) {
Date endOfYear = DateUtils.calculateEndOfYear(new Date());
setValueWithExpiration(key, value, endOfYear);
}
/**
* redis设置key
*
* @param key key
* @param value value
* @param expirationDate 过期时间
*/
public void setValueWithExpiration(String key, String value, Date expirationDate) {
ValueOperations<String, String> valueOps = redisTemplate.opsForValue();
valueOps.set(key, value);
long expirationTimeInSeconds = expirationDate.getTime() - System.currentTimeMillis();
redisTemplate.expire(key, expirationTimeInSeconds, TimeUnit.MILLISECONDS);
}
}
\ 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