Commit 6d3c32f5 authored by yangyang's avatar yangyang

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

# Conflicts: # amos-boot-system-tzs/amos-boot-module-tcm/amos-boot-module-tcm-api/src/main/java/com/yeejoin/amos/boot/module/tcm/api/controller/CreateCodeController.java
parents 516db5f9 a1047513
package com.yeejoin.amos.boot.module.jg.api.dto; package com.yeejoin.amos.boot.module.jg.api.dto;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import com.yeejoin.amos.boot.biz.common.dto.BaseDto; import com.yeejoin.amos.boot.biz.common.dto.BaseDto;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.checkerframework.checker.formatter.qual.Format;
import java.util.Date; import java.util.Date;
/** /**
...@@ -27,26 +30,29 @@ public class JgMaintenanceContractDto extends BaseDto { ...@@ -27,26 +30,29 @@ public class JgMaintenanceContractDto extends BaseDto {
@ApiModelProperty(value = "办理状态") @ApiModelProperty(value = "办理状态")
private String applyStatus; private String applyStatus;
@ApiModelProperty(value = "流程实例id")
private String instanceId;
@ApiModelProperty(value = "维保备案日期") @ApiModelProperty(value = "维保备案日期")
private Date applyDate; private Date applyDate;
@ApiModelProperty(value = "设备类型") @ApiModelProperty(value = "设备类型")
private String equType; private String equType;
@ApiModelProperty(value = "使用单位ID") @ApiModelProperty(value = "使用单位统一信用代码")
private String useUnitId; private String useUnitCode;
@ApiModelProperty(value = "使用单位") @ApiModelProperty(value = "使用单位")
private String useUnitName; private String useUnitName;
@ApiModelProperty(value = "接收机构ID") @ApiModelProperty(value = "接收机构统一信用代码")
private String receiveOrgId; private String receiveOrgCode;
@ApiModelProperty(value = "接收机构") @ApiModelProperty(value = "接收机构")
private String receiveOrgName; private String receiveOrgName;
@ApiModelProperty(value = "维保单位ID") @ApiModelProperty(value = "维保单位统一信用代码")
private String maintenanceUnitId; private String maintenanceUnitCode;
@ApiModelProperty(value = "维保单位名称") @ApiModelProperty(value = "维保单位名称")
private String maintenanceUnitName; private String maintenanceUnitName;
...@@ -69,8 +75,8 @@ public class JgMaintenanceContractDto extends BaseDto { ...@@ -69,8 +75,8 @@ public class JgMaintenanceContractDto extends BaseDto {
@ApiModelProperty(value = "24小时维保电话") @ApiModelProperty(value = "24小时维保电话")
private String maintenance24Tel; private String maintenance24Tel;
@ApiModelProperty(value = "状态") @ApiModelProperty(value = "办理流程")
private String status; private String applyFlow;
@ApiModelProperty(value = "备注") @ApiModelProperty(value = "备注")
private String remark; private String remark;
......
...@@ -29,6 +29,12 @@ public class JgMaintenanceContract extends BaseEntity { ...@@ -29,6 +29,12 @@ public class JgMaintenanceContract extends BaseEntity {
private String applyNo; private String applyNo;
/** /**
* 流程实例id
*/
@TableField("instance_id")
private String instanceId;
/**
* 办理状态 * 办理状态
*/ */
@TableField("apply_status") @TableField("apply_status")
...@@ -47,10 +53,10 @@ public class JgMaintenanceContract extends BaseEntity { ...@@ -47,10 +53,10 @@ public class JgMaintenanceContract extends BaseEntity {
private String equType; private String equType;
/** /**
* 使用单位ID * 使用单位统一信用代码
*/ */
@TableField("use_unit_id") @TableField("use_unit_code")
private String useUnitId; private String useUnitCode;
/** /**
* 使用单位 * 使用单位
...@@ -59,10 +65,10 @@ public class JgMaintenanceContract extends BaseEntity { ...@@ -59,10 +65,10 @@ public class JgMaintenanceContract extends BaseEntity {
private String useUnitName; private String useUnitName;
/** /**
* 接收机构ID * 接收机构统一信用代码
*/ */
@TableField("receive_org_id") @TableField("receive_org_code")
private String receiveOrgId; private String receiveOrgCode;
/** /**
* 接收机构 * 接收机构
...@@ -71,10 +77,10 @@ public class JgMaintenanceContract extends BaseEntity { ...@@ -71,10 +77,10 @@ public class JgMaintenanceContract extends BaseEntity {
private String receiveOrgName; private String receiveOrgName;
/** /**
* 维保单位ID * 维保单位统一信用代码
*/ */
@TableField("maintenance_unit_id") @TableField("maintenance_unit_code")
private String maintenanceUnitId; private String maintenanceUnitCode;
/** /**
* 维保单位名称 * 维保单位名称
...@@ -119,10 +125,10 @@ public class JgMaintenanceContract extends BaseEntity { ...@@ -119,10 +125,10 @@ public class JgMaintenanceContract extends BaseEntity {
private String maintenance24Tel; private String maintenance24Tel;
/** /**
* 状态 * 办理流程
*/ */
@TableField("status") @TableField("apply_flow")
private String status; private String applyFlow;
/** /**
* 备注 * 备注
......
...@@ -3,7 +3,7 @@ package com.yeejoin.amos.boot.module.jg.api.enums; ...@@ -3,7 +3,7 @@ package com.yeejoin.amos.boot.module.jg.api.enums;
/** /**
* 办理状态枚举 * 办理状态枚举
*/ */
public enum FlowStatusEnum { public enum FlowStatusEnum {
/** /**
* 待提交 * 待提交
......
package com.yeejoin.amos.boot.module.jg.api.enums; package com.yeejoin.amos.boot.module.jg.api.enums;
import io.swagger.models.auth.In;
/** /**
* 维保备案使用单位枚举 * 维保备案使用单位枚举
*/ */
...@@ -15,6 +17,16 @@ public enum MaintenanceEnum { ...@@ -15,6 +17,16 @@ public enum MaintenanceEnum {
this.code = code; this.code = code;
this.msg = msg; this.msg = msg;
} }
public static String getMsgByCode(Integer code) {
String name = null;
for (MaintenanceEnum enumOne : MaintenanceEnum.values()) {
if (enumOne.getCode() == code) {
name = enumOne.getMsg();
break;
}
}
return name;
}
public Integer getCode() { public Integer getCode() {
return code; return code;
......
...@@ -16,20 +16,20 @@ ...@@ -16,20 +16,20 @@
<if test="dto.equType != null and dto.equType != ''"> <if test="dto.equType != null and dto.equType != ''">
tjmc.equ_type = #{dto.equType}, tjmc.equ_type = #{dto.equType},
</if> </if>
<if test="dto.useUnitId != null and dto.useUnitId != ''"> <if test="dto.useUnitCode != null and dto.useUnitCode != ''">
tjmc.use_unit_id = #{dto.useUnitId}, tjmc.use_unit_code = #{dto.useUnitCode},
</if> </if>
<if test="dto.useUnitName != null and dto.useUnitName != ''"> <if test="dto.useUnitName != null and dto.useUnitName != ''">
tjmc.use_unit_name = #{dto.useUnitName}, tjmc.use_unit_name = #{dto.useUnitName},
</if> </if>
<if test="dto.receiveOrgId != null and dto.receiveOrgId != ''"> <if test="dto.receiveOrgCode != null and dto.receiveOrgCode != ''">
tjmc.receive_org_id = #{dto.receiveOrgId}, tjmc.receive_org_code = #{dto.receiveOrgCode},
</if> </if>
<if test="dto.receiveOrgName != null and dto.receiveOrgName != ''"> <if test="dto.receiveOrgName != null and dto.receiveOrgName != ''">
tjmc.receive_org_name = #{dto.receiveOrgName}, tjmc.receive_org_name = #{dto.receiveOrgName},
</if> </if>
<if test="dto.maintenanceUnitId != null and dto.maintenanceUnitId != ''"> <if test="dto.maintenanceUnitCode != null and dto.maintenanceUnitCode != ''">
tjmc.maintenance_unit_id = #{dto.maintenanceUnitId}, tjmc.maintenance_unit_code = #{dto.maintenanceUnitCode},
</if> </if>
<if test="dto.maintenanceUnitName != null and dto.maintenanceUnitName != ''"> <if test="dto.maintenanceUnitName != null and dto.maintenanceUnitName != ''">
tjmc.maintenance_unit_name = #{dto.maintenanceUnitName}, tjmc.maintenance_unit_name = #{dto.maintenanceUnitName},
...@@ -52,8 +52,8 @@ ...@@ -52,8 +52,8 @@
<if test="dto.maintenance24Tel != null and dto.maintenance24Tel != ''"> <if test="dto.maintenance24Tel != null and dto.maintenance24Tel != ''">
tjmc.maintenance_24_tel = #{dto.maintenance24Tel}, tjmc.maintenance_24_tel = #{dto.maintenance24Tel},
</if> </if>
<if test="dto.status != null and dto.status != ''"> <if test="dto.applyFlow != null and dto.applyFlow != ''">
tjmc.status = #{dto.status}, tjmc.apply_flow = #{dto.applyFlow},
</if> </if>
<if test="dto.remark != null and dto.remark != ''"> <if test="dto.remark != null and dto.remark != ''">
tjmc.remark = #{dto.remark}, tjmc.remark = #{dto.remark},
...@@ -97,19 +97,19 @@ ...@@ -97,19 +97,19 @@
apply_status, apply_status,
apply_date, apply_date,
equ_type, equ_type,
use_unit_id, use_unit_code,
use_unit_name, use_unit_name,
receive_org_id, receive_org_code,
receive_org_name, receive_org_name,
maintenance_unit_id, maintenance_unit_code,
maintenance_unit_name, maintenance_unit_name,
date_format(inform_start,'%Y-%m-%d') informStart, date_format(IFNULL(inform_start, null),'%Y-%m-%d') informStart,
date_format(inform_end,'%Y-%m-%d') informEnd, date_format(IFNULL(inform_end, null),'%Y-%m-%d') informEnd,
maintenance_manager_id, maintenance_manager_id,
maintenance_manager_card_no, maintenance_manager_card_no,
emergency_call, emergency_call,
maintenance_24_tel, maintenance_24_tel,
status, apply_flow,
remark, remark,
is_delete, is_delete,
input_unit_no, input_unit_no,
...@@ -137,6 +137,18 @@ ...@@ -137,6 +137,18 @@
<if test="contractDto.applyStatus != '' and contractDto.applyStatus != null"> <if test="contractDto.applyStatus != '' and contractDto.applyStatus != null">
and apply_status like concat('%',#{contractDto.applyStatus},'%') and apply_status like concat('%',#{contractDto.applyStatus},'%')
</if> </if>
<if test="contractDto.applyFlow != '' and contractDto.applyFlow != null">
and apply_flow like concat('%',#{contractDto.applyFlow},'%')
</if>
<if test="contractDto.useUnitCode != '' and contractDto.useUnitCode != null">
and use_unit_code = #{contractDto.useUnitCode}
</if>
<if test="contractDto.maintenanceUnitCode != '' and contractDto.maintenanceUnitCode != null">
and maintenance_unit_code = #{contractDto.maintenanceUnitCode}
</if>
<if test="contractDto.receiveOrgCode != '' and contractDto.receiveOrgCode != null">
and receive_org_code = #{contractDto.receiveOrgCode}
</if>
</where> </where>
</select> </select>
<select id="queryBySequenceNbr" <select id="queryBySequenceNbr"
......
...@@ -45,6 +45,53 @@ public class JgMaintenanceContractController extends BaseController { ...@@ -45,6 +45,53 @@ public class JgMaintenanceContractController extends BaseController {
} }
/** /**
* 提交
*
* @return
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/submit")
@ApiOperation(httpMethod = "POST", value = "维保合同提交", notes = "维保合同提交")
public ResponseModel<Object> submit(@RequestBody JgMaintenanceContractDto model) {
return ResponseHelper.buildResponse(jgMaintenanceContractServiceImpl.submit(model));
}
/**
* 撤回
*
* @return
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/revocation")
@ApiOperation(httpMethod = "POST", value = "维保合同撤回", notes = "维保合同撤回")
public ResponseModel<Object> revocation(@RequestBody JgMaintenanceContractDto model) {
return ResponseHelper.buildResponse(jgMaintenanceContractServiceImpl.revocation(model));
}
/**
* 维保合同驳回
*
* @return
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/rejected")
@ApiOperation(httpMethod = "POST", value = "维保合同驳回", notes = "维保合同驳回")
public ResponseModel<Object> rejected(@RequestBody JgMaintenanceContractDto model) {
return ResponseHelper.buildResponse(jgMaintenanceContractServiceImpl.rejected(model));
}
/**
* 维保合同受理
*
* @return
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/accepted")
@ApiOperation(httpMethod = "POST", value = "维保合同受理", notes = "维保合同受理")
public ResponseModel<Object> accepted(@RequestBody JgMaintenanceContractDto model) {
return ResponseHelper.buildResponse(jgMaintenanceContractServiceImpl.accepted(model));
}
/**
* 根据sequenceNbr更新 * 根据sequenceNbr更新
* *
* @param sequenceNbr 主键 * @param sequenceNbr 主键
......
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.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.bo.CompanyBo; import com.yeejoin.amos.boot.biz.common.bo.CompanyBo;
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.entity.DataDictionary; import com.yeejoin.amos.boot.biz.common.entity.DataDictionary;
import com.yeejoin.amos.boot.biz.common.service.impl.DataDictionaryServiceImpl; import com.yeejoin.amos.boot.biz.common.service.impl.DataDictionaryServiceImpl;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.jg.api.common.StringUtil;
import com.yeejoin.amos.boot.module.jg.api.dto.JgMaintenanceContractDto; import com.yeejoin.amos.boot.module.jg.api.dto.JgMaintenanceContractDto;
import com.yeejoin.amos.boot.module.jg.api.entity.JgMaintenanceContract; import com.yeejoin.amos.boot.module.jg.api.entity.JgMaintenanceContract;
import com.yeejoin.amos.boot.module.jg.api.entity.JgRelationEquip; import com.yeejoin.amos.boot.module.jg.api.entity.JgRelationEquip;
...@@ -21,6 +25,7 @@ import org.springframework.beans.BeanUtils; ...@@ -21,6 +25,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.rdbms.service.BaseService; import org.typroject.tyboot.core.rdbms.service.BaseService;
import java.util.Arrays; import java.util.Arrays;
...@@ -64,17 +69,21 @@ public class JgMaintenanceContractServiceImpl extends BaseService<JgMaintenanceC ...@@ -64,17 +69,21 @@ public class JgMaintenanceContractServiceImpl extends BaseService<JgMaintenanceC
*/ */
public Page<JgMaintenanceContractDto> queryForPage(Page<JgMaintenanceContract> page, int phase, JgMaintenanceContractDto dto, ReginParams reginParams) { public Page<JgMaintenanceContractDto> queryForPage(Page<JgMaintenanceContract> page, int phase, JgMaintenanceContractDto dto, ReginParams reginParams) {
Page<JgMaintenanceContractDto> contractList = new Page<>(); Page<JgMaintenanceContractDto> contractList = new Page<>();
CompanyBo company = reginParams.getCompany();
if (MaintenanceEnum.SHIYONG.getCode().equals(phase)) { if (MaintenanceEnum.SHIYONG.getCode().equals(phase)) {
//使用单位用"使用单位id"匹配数据 //使用单位用"使用单位统一信用代码"匹配数据
// TODO dto.setUseUnitCode(company.getCompanyOrgCode().toString());
dto.setApplyFlow(MaintenanceEnum.SHIYONG.getMsg());
contractList = maintenanceContractMapper.getContractList(page, dto); contractList = maintenanceContractMapper.getContractList(page, dto);
} else if (MaintenanceEnum.WEIBAO.getCode().equals(phase)) { } else if (MaintenanceEnum.WEIBAO.getCode().equals(phase)) {
//维保单位用"维保单位id"匹配数据 //维保单位用"维保单位统一信用代码"匹配数据
// TODO dto.setMaintenanceUnitCode(company.getCompanyCode());
dto.setApplyFlow(MaintenanceEnum.WEIBAO.getMsg());
contractList = maintenanceContractMapper.getContractList(page, dto); contractList = maintenanceContractMapper.getContractList(page, dto);
} else if (MaintenanceEnum.JIANGUAN.getCode().equals(phase)) { } else if (MaintenanceEnum.JIANGUAN.getCode().equals(phase)) {
//监管单位用"" //监管单位用"接收机构统一使用代码"匹配
// TODO dto.setReceiveOrgCode(company.getOrgCode());
dto.setApplyFlow(MaintenanceEnum.JIANGUAN.getMsg());
contractList = maintenanceContractMapper.getContractList(page, dto); contractList = maintenanceContractMapper.getContractList(page, dto);
} }
return contractList; return contractList;
...@@ -84,11 +93,7 @@ public class JgMaintenanceContractServiceImpl extends BaseService<JgMaintenanceC ...@@ -84,11 +93,7 @@ public class JgMaintenanceContractServiceImpl extends BaseService<JgMaintenanceC
* 根据sequenceNbr查询数据 * 根据sequenceNbr查询数据
*/ */
public JgMaintenanceContractDto queryBySequenceNbr(Long sequenceNbr) { public JgMaintenanceContractDto queryBySequenceNbr(Long sequenceNbr) {
JgMaintenanceContractDto contractDto = maintenanceContractMapper.queryBySequenceNbr(sequenceNbr); return maintenanceContractMapper.queryBySequenceNbr(sequenceNbr);
String code = contractDto.getStatus().split("-")[1];
DataDictionary dict = getDict(HANDLING_STATUS_DICTIONARY, code);
contractDto.setStatus(dict.getName());
return contractDto;
} }
/** /**
...@@ -109,6 +114,53 @@ public class JgMaintenanceContractServiceImpl extends BaseService<JgMaintenanceC ...@@ -109,6 +114,53 @@ public class JgMaintenanceContractServiceImpl extends BaseService<JgMaintenanceC
} }
/** /**
* 维保合同提交
*/
@Transactional
public Boolean submit(JgMaintenanceContractDto dto){
String[] split = dto.getApplyFlow().split("-");
String lastFlowName = split[split.length - 1];
String applyFlow = dto.getApplyFlow() + "-" + MaintenanceEnum.getMsgByCode(MaintenanceEnum.valueOf(lastFlowName).getCode()+1);
dto.setApplyFlow(applyFlow);
dto.setApplyStatus(FlowStatusEnum.TO_BE_PROCESSED.getName());
return this.updateBySequenceNbr(dto);
}
/**
* 维保合同撤回
*/
@Transactional
public Boolean revocation(JgMaintenanceContractDto dto){
dto.setApplyStatus(FlowStatusEnum.TO_BE_SUBMITTED.getName());
return this.updateBySequenceNbr(dto);
}
/**
* 维保合同驳回
*/
@Transactional
public Boolean rejected(JgMaintenanceContractDto dto){
String[] split = dto.getApplyFlow().split("-");
String lastFlowName = split[split.length - 1];
String applyFlow = dto.getApplyFlow() + "-" + MaintenanceEnum.getMsgByCode(MaintenanceEnum.valueOf(lastFlowName).getCode() - 1);
dto.setApplyFlow(applyFlow);
dto.setApplyStatus(FlowStatusEnum.REJECTED.getName());
return this.updateBySequenceNbr(dto);
}
/**
* 维保合同受理
*/
@Transactional
public Boolean accepted(JgMaintenanceContractDto dto){
String[] split = dto.getApplyFlow().split("-");
String lastFlowName = split[split.length - 1];
String applyFlow = dto.getApplyFlow() + "-" + MaintenanceEnum.getMsgByCode(MaintenanceEnum.valueOf(lastFlowName).getCode() + 1);
dto.setApplyFlow(applyFlow);
dto.setApplyStatus(FlowStatusEnum.TO_BE_PROCESSED.getName());
return this.updateBySequenceNbr(dto);
}
/**
* 根据设备批量插入 * 根据设备批量插入
*/ */
@Transactional @Transactional
...@@ -117,15 +169,31 @@ public class JgMaintenanceContractServiceImpl extends BaseService<JgMaintenanceC ...@@ -117,15 +169,31 @@ public class JgMaintenanceContractServiceImpl extends BaseService<JgMaintenanceC
CompanyBo company = reginParams.getCompany(); CompanyBo company = reginParams.getCompany();
JgMaintenanceContract contract = new JgMaintenanceContract(); JgMaintenanceContract contract = new JgMaintenanceContract();
BeanUtils.copyProperties(dto, contract); BeanUtils.copyProperties(dto, contract);
contract.setUseUnitId(company.getOrgCode()); if (StringUtil.isNotEmpty(contract.getApplyNo())){
contract.setUseUnitName(company.getCompanyName()); //更新操作
contract.setStatus(MaintenanceEnum.SHIYONG.getCode() + "-" + FlowStatusEnum.TO_BE_SUBMITTED.getCode()); LambdaQueryWrapper<JgRelationEquip> queryWrapper = new LambdaQueryWrapper<JgRelationEquip>()
.eq(JgRelationEquip::getBusinessId,contract.getApplyNo())
.eq(JgRelationEquip::getIsDelete, false);
List<Long> list = jgRelationEquipServiceImpl.list(queryWrapper).stream().map(JgRelationEquip::getSequenceNbr).collect(Collectors.toList());
jgRelationEquipServiceImpl.deleteBatchSeq(list);
}else {
//新增操作
//维保备案编号
//TODO
contract.setApplyNo("维保备案编号");
contract.setUseUnitCode(company.getCompanyCode());
contract.setUseUnitName(company.getCompanyName());
contract.setApplyFlow(MaintenanceEnum.SHIYONG.getMsg());
contract.setApplyStatus(FlowStatusEnum.TO_BE_SUBMITTED.getName());
contract.setEquNum(collect.size());
this.save(contract);
}
collect.forEach(x -> { collect.forEach(x -> {
JgRelationEquip equip = new JgRelationEquip(); JgRelationEquip equip = new JgRelationEquip();
equip.setBusinessId(contract.getApplyNo());
equip.setEquipId(String.valueOf(x)); equip.setEquipId(String.valueOf(x));
equip.setBusinessType(BusinessTypeEnum.MAINTENANCE_RECORD.getName()); equip.setBusinessType(BusinessTypeEnum.MAINTENANCE_RECORD.getName());
jgRelationEquipServiceImpl.save(equip); jgRelationEquipServiceImpl.save(equip);
this.saveOrUpdate(contract);
}); });
return true; return true;
} }
......
package com.yeejoin.amos.boot.module.tcm.api.controller; package com.yeejoin.amos.boot.module.tcm.api.controller;
import com.yeejoin.amos.boot.biz.common.controller.BaseController; import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.module.tcm.api.dto.AlertCalledDto;
import com.yeejoin.amos.boot.module.tcm.api.service.ICreateCodeService; import com.yeejoin.amos.boot.module.tcm.api.service.ICreateCodeService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -11,7 +10,6 @@ import org.typroject.tyboot.core.foundation.enumeration.UserType; ...@@ -11,7 +10,6 @@ import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation; import org.typroject.tyboot.core.restful.doc.TycloudOperation;
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.util.List; import java.util.List;
/** /**
...@@ -30,29 +28,27 @@ public class CreateCodeController extends BaseController { ...@@ -30,29 +28,27 @@ public class CreateCodeController extends BaseController {
/** /**
* 申请单编号生成 * 申请单编号生成
* @param type * @param type type
* @param num * @param batchSize batchSize
* @return * @return List
*/ */
@TycloudOperation(ApiLevel = UserType.AGENCY) @TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/ANCode") @PostMapping(value = "/ANCode")
@ApiOperation(httpMethod = "POST", value = "申请单编号生成", notes = "申请单编号生成") @ApiOperation(httpMethod = "POST", value = "申请单编号生成", notes = "申请单编号生成")
public ResponseModel<List<String>> CreateANCode(@RequestParam("type") String type, public ResponseModel<List<String>> createANCode(@RequestParam("type") String type,
@RequestParam("num") int num) { @RequestParam("batchSize") int batchSize) {
return ResponseHelper.buildResponse(createCodeService.createApplicationFormCode(type,num)); return ResponseHelper.buildResponse(createCodeService.createApplicationFormCode(type,batchSize));
} }
/** /**
* 申请单编号生成 * 生成设备注册编码
* @param type * @param key key
* @param num * @return String
* @return
*/ */
@TycloudOperation(ApiLevel = UserType.AGENCY) @TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/Device registration code") @PostMapping(value = "/DRCode")
@ApiOperation(httpMethod = "POST", value = "申请单编号生成", notes = "申请单编号生成") @ApiOperation(httpMethod = "POST", value = "申请单编号生成", notes = "申请单编号生成")
public ResponseModel<List<String>> CreateANCode1(@RequestParam("type") String type, public ResponseModel<String> createDRCode(@RequestParam("key") String key) {
@RequestParam("num") int num) { return ResponseHelper.buildResponse(createCodeService.createDeviceRegistrationCode(key));
return ResponseHelper.buildResponse(createCodeService.createApplicationFormCode(type,num));
} }
} }
...@@ -13,5 +13,11 @@ public interface ICreateCodeService { ...@@ -13,5 +13,11 @@ public interface ICreateCodeService {
List<String> createApplicationFormCode(String type, int batchSize); List<String> createApplicationFormCode(String type, int batchSize);
String createDeviceRegistrationCode(); /**
* 生成设备注册编码(20位)
* @param key key
* @return 顺序编号
*/
String createDeviceRegistrationCode(String key);
} }
...@@ -18,7 +18,8 @@ import java.util.concurrent.TimeUnit; ...@@ -18,7 +18,8 @@ import java.util.concurrent.TimeUnit;
public class CreateCodeServiceImpl implements ICreateCodeService { public class CreateCodeServiceImpl implements ICreateCodeService {
private static final String LOCK_VALUE = "locked"; private static final String LOCK_VALUE = "locked";
private static final String LOCK_KEY = "sequence_lock"; private static final String LOCK_KEY_AF = "sequence_lock_af";
private static final String LOCK_KEY_DR = "sequence_lock_dr";
private final RedisTemplate<String, String> redisTemplate; private final RedisTemplate<String, String> redisTemplate;
private String rulePrefix; private String rulePrefix;
...@@ -32,12 +33,12 @@ public class CreateCodeServiceImpl implements ICreateCodeService { ...@@ -32,12 +33,12 @@ public class CreateCodeServiceImpl implements ICreateCodeService {
return Collections.emptyList(); return Collections.emptyList();
} }
rulePrefix = type + LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); rulePrefix = type + LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
return this.generateBatchSequence(type, batchSize); return generateBatchSequence(type, batchSize);
} }
@Override @Override
public String createDeviceRegistrationCode() { public String createDeviceRegistrationCode(String key) {
return null; return generateSequence(key);
} }
public boolean isValueInEnum(String value) { public boolean isValueInEnum(String value) {
...@@ -48,7 +49,7 @@ public class CreateCodeServiceImpl implements ICreateCodeService { ...@@ -48,7 +49,7 @@ public class CreateCodeServiceImpl implements ICreateCodeService {
public List<String> generateBatchSequence(String sequenceKey, int batchSize) { public List<String> generateBatchSequence(String sequenceKey, int batchSize) {
// 使用分布式锁,确保在并发情况下只有一个线程能够生成顺序码 // 使用分布式锁,确保在并发情况下只有一个线程能够生成顺序码
Boolean lockAcquired = redisTemplate.opsForValue().setIfAbsent(LOCK_KEY, LOCK_VALUE); Boolean lockAcquired = redisTemplate.opsForValue().setIfAbsent(LOCK_KEY_AF, LOCK_VALUE);
if (Boolean.TRUE.equals(lockAcquired)) { if (Boolean.TRUE.equals(lockAcquired)) {
try { try {
// 获取当前顺序码 // 获取当前顺序码
...@@ -76,7 +77,41 @@ public class CreateCodeServiceImpl implements ICreateCodeService { ...@@ -76,7 +77,41 @@ public class CreateCodeServiceImpl implements ICreateCodeService {
return sequenceList; return sequenceList;
} finally { } finally {
redisTemplate.delete(LOCK_KEY); redisTemplate.delete(LOCK_KEY_AF);
}
} else {
// 获取锁失败,可以选择重试或采取其他策略
throw new RuntimeException("Failed to acquire lock for sequence generation");
}
}
public String generateSequence(String sequenceKey) {
// 使用分布式锁,确保在并发情况下只有一个线程能够生成顺序码
Boolean lockAcquired = redisTemplate.opsForValue().setIfAbsent(LOCK_KEY_DR, LOCK_VALUE);
if (Boolean.TRUE.equals(lockAcquired)) {
try {
// 获取当前顺序码
ValueOperations<String, String> valueOps = redisTemplate.opsForValue();
String currentSequenceStr = valueOps.get(sequenceKey);
// 如果为空,则初始化为0
if (currentSequenceStr == null) {
currentSequenceStr = "0";
}
// 将当前顺序码加1
Long currentSequence = Long.parseLong(currentSequenceStr);
currentSequence++;
// 生成10位顺序码
String formattedSequence = String.format("%04d", currentSequence);
// 更新顺序码
setValueWithMonthlyExpiration(sequenceKey, String.valueOf(formattedSequence));
return sequenceKey + formattedSequence;
} finally {
redisTemplate.delete(LOCK_KEY_DR);
} }
} else { } else {
// 获取锁失败,可以选择重试或采取其他策略 // 获取锁失败,可以选择重试或采取其他策略
......
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