Commit caab6266 authored by 王果's avatar 王果

27994 注销报废限制设备不能多次出现在执行的流程中

parent 41e16c4c
...@@ -3,6 +3,7 @@ package com.yeejoin.amos.boot.module.jg.api.mapper; ...@@ -3,6 +3,7 @@ package com.yeejoin.amos.boot.module.jg.api.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.common.api.dto.DPFilterParamDto; import com.yeejoin.amos.boot.module.common.api.dto.DPFilterParamDto;
import com.yeejoin.amos.boot.module.jg.api.dto.CompanyEquipCountDto;
import com.yeejoin.amos.boot.module.jg.api.dto.EquipBizCountDto; import com.yeejoin.amos.boot.module.jg.api.dto.EquipBizCountDto;
import com.yeejoin.amos.boot.module.jg.api.dto.JgScrapCancelDto; import com.yeejoin.amos.boot.module.jg.api.dto.JgScrapCancelDto;
import com.yeejoin.amos.boot.module.jg.api.entity.JgScrapCancel; import com.yeejoin.amos.boot.module.jg.api.entity.JgScrapCancel;
...@@ -48,4 +49,6 @@ public interface JgScrapCancelMapper extends BaseMapper<JgScrapCancel> { ...@@ -48,4 +49,6 @@ public interface JgScrapCancelMapper extends BaseMapper<JgScrapCancel> {
List<EquipBizCountDto> queryScrappedDeviceStaticListData(DPFilterParamDto dpFilterParamDto); List<EquipBizCountDto> queryScrappedDeviceStaticListData(DPFilterParamDto dpFilterParamDto);
Integer getScrappedDeviceCount(@Param("dpFilterParamDto") DPFilterParamDto dpFilterParamDto); Integer getScrappedDeviceCount(@Param("dpFilterParamDto") DPFilterParamDto dpFilterParamDto);
List<CompanyEquipCountDto> queryForFlowingEquipList();
} }
...@@ -281,4 +281,13 @@ ...@@ -281,4 +281,13 @@
c.equ_category c.equ_category
</select> </select>
<select id="queryForFlowingEquipList" resultType="com.yeejoin.amos.boot.module.jg.api.dto.CompanyEquipCountDto">
select a.use_unit_code as companyCode,
group_concat(b.equ_id ) as records
from tzs_jg_scrap_cancel a,
tzs_jg_scrap_cancel_eq b
where a.sequence_nbr = b.equip_transfer_id
and a.audit_status in ('三级待受理', '二级待受理', '一级待受理')
GROUP BY a.use_unit_code
</select>
</mapper> </mapper>
package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import com.yeejoin.amos.boot.module.jg.api.dto.CompanyEquipCountDto;
import com.yeejoin.amos.boot.module.jg.api.mapper.JgScrapCancelMapper;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @author Administrator
*/
@Component
@Slf4j
public class JgScrapCancelEquipUsedCheckImpl extends BaseEquipUsedCheckService {
private RedissonClient redissonClient;
private String bizType = "jgScrapCancelAdd";
private JgScrapCancelMapper mapper;
public JgScrapCancelEquipUsedCheckImpl(RedissonClient redissonClient, JgScrapCancelMapper mapper) {
this.redissonClient = redissonClient;
this.mapper = mapper;
}
@Override
public RedissonClient getRedisClient() {
return redissonClient;
}
@Override
public String getApplyBizType() {
return bizType;
}
@Override
public void init() {
// 初始化已经完成或者在流程中安装告知的设备数据
List<CompanyEquipCountDto> companyEquipCountDtos = mapper.queryForFlowingEquipList();
companyEquipCountDtos.forEach(c -> {
RBucket<Set<String>> rBucket = redissonClient.getBucket(getFlowingEquipRedisKey(c.getCompanyCode(), bizType));
rBucket.set(Arrays.stream(c.getRecords().split(",")).collect(Collectors.toSet()));
});
}
}
...@@ -23,6 +23,9 @@ import com.yeejoin.amos.boot.module.jg.api.mapper.JgScrapCancelMapper; ...@@ -23,6 +23,9 @@ import com.yeejoin.amos.boot.module.jg.api.mapper.JgScrapCancelMapper;
import com.yeejoin.amos.boot.module.jg.api.mapper.JgUseRegistrationManageMapper; import com.yeejoin.amos.boot.module.jg.api.mapper.JgUseRegistrationManageMapper;
import com.yeejoin.amos.boot.module.jg.api.service.IJgScrapCancelService; import com.yeejoin.amos.boot.module.jg.api.service.IJgScrapCancelService;
import com.yeejoin.amos.boot.module.jg.api.vo.SortVo; import com.yeejoin.amos.boot.module.jg.api.vo.SortVo;
import com.yeejoin.amos.boot.module.jg.biz.config.LocalBadRequest;
import com.yeejoin.amos.boot.module.jg.biz.context.EquipUsedCheckStrategyContext;
import com.yeejoin.amos.boot.module.jg.biz.context.FlowingEquipRedisContext;
import com.yeejoin.amos.boot.module.jg.biz.feign.TzsServiceFeignClient; import com.yeejoin.amos.boot.module.jg.biz.feign.TzsServiceFeignClient;
import com.yeejoin.amos.boot.module.jg.biz.service.IIdxBizJgRegisterInfoService; import com.yeejoin.amos.boot.module.jg.biz.service.IIdxBizJgRegisterInfoService;
import com.yeejoin.amos.boot.module.jg.flc.api.fegin.WorkFlowFeignService; import com.yeejoin.amos.boot.module.jg.flc.api.fegin.WorkFlowFeignService;
...@@ -71,6 +74,8 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc ...@@ -71,6 +74,8 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc
private static final String SUBMIT_TYPE_FLOW = "1"; private static final String SUBMIT_TYPE_FLOW = "1";
private static final String PAGE_KEY = "jgScrapCancelAdd"; private static final String PAGE_KEY = "jgScrapCancelAdd";
private static final String template = "%s发起%s%s业务申请,【申请单号:%s】"; private static final String template = "%s发起%s%s业务申请,【申请单号:%s】";
private final List<String> NOT_FLOWING_STATE = Arrays.asList("使用单位待提交", "一级受理已驳回", "使用单位已撤回", "已作废", "已完成");
@Autowired @Autowired
WorkFlowFeignService workFlowFeginService; WorkFlowFeignService workFlowFeginService;
@Autowired @Autowired
...@@ -178,6 +183,7 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc ...@@ -178,6 +183,7 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@GlobalTransactional(rollbackFor = Exception.class) @GlobalTransactional(rollbackFor = Exception.class)
public JgScrapCancelDto save(String submitType, Map<String, Object> mapParams) { public JgScrapCancelDto save(String submitType, Map<String, Object> mapParams) {
try {
ReginParams reginParams = this.getSelectedOrgInfo(); ReginParams reginParams = this.getSelectedOrgInfo();
Map<String, Object> noticeParams = (Map) mapParams.get(PAGE_KEY); Map<String, Object> noticeParams = (Map) mapParams.get(PAGE_KEY);
String[] receiveOrg = String.valueOf(noticeParams.get("receiveOrgCreditCode")).split("_"); String[] receiveOrg = String.valueOf(noticeParams.get("receiveOrgCreditCode")).split("_");
...@@ -209,6 +215,8 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc ...@@ -209,6 +215,8 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc
// 判断当前是否为提交 // 判断当前是否为提交
List<WorkflowResultDto> workflowResultDtos = null; List<WorkflowResultDto> workflowResultDtos = null;
if (SUBMIT_TYPE_FLOW.equals(submitType)) { if (SUBMIT_TYPE_FLOW.equals(submitType)) {
List<JgScrapCancelEq> JgScrapCancelEqList = getCancelEqs(noticeParams);
this.repeatUsedEquipCheck(JgScrapCancelEqList, reginParams.getCompany().getCompanyCode());
// 发起流程 // 发起流程
ActWorkflowBatchDTO actWorkflowBatchDTO = new ActWorkflowBatchDTO(); ActWorkflowBatchDTO actWorkflowBatchDTO = new ActWorkflowBatchDTO();
List<ActWorkflowStartDTO> list = new ArrayList<>(); List<ActWorkflowStartDTO> list = new ArrayList<>();
...@@ -266,6 +274,73 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc ...@@ -266,6 +274,73 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc
BeanUtil.copyProperties(jgScrapCancel, dto); BeanUtil.copyProperties(jgScrapCancel, dto);
dto.setEquListName(equListName); dto.setEquListName(equListName);
return dto; return dto;
} catch (BadRequest | LocalBadRequest e) {
log.error(e.getMessage(), e);
this.rollBackForDelRedisData();
throw e;
} catch (Exception e) {
log.error(e.getMessage(), e);
this.rollBackForDelRedisData();
throw new BadRequest("保存失败!");
} finally {
FlowingEquipRedisContext.clean();
}
}
private List<JgScrapCancelEq> getCancelEqs(Map<String, Object> noticeParams) {
List<JgScrapCancelEq> JgScrapCancelEqList = new ArrayList<>();
// 判断是否是报废气瓶业务处理
if (CancelTypeEnum.SCRAPPED.getCode().equals(noticeParams.get("cancelType")) &&
CylinderTypeEnum.CYLINDER.getCode().equals(noticeParams.get("EQU_CATEGORY_CODE"))) {
List<Map<String, Object>> list = (List<Map<String, Object>>) noticeParams.get("equipments");
for (Map<String, Object> equip : list) {
JgScrapCancelEq jgScrapCancelEq = new JgScrapCancelEq();
jgScrapCancelEq.setEquId(equip.get("SEQUENCE_NBR").toString());
JgScrapCancelEqList.add(jgScrapCancelEq);
}
} else {
List<Map<String, Object>> certificates;
// 证列表
if (CylinderTypeEnum.SPECIAL_CYLINDER.getCode().equals(noticeParams.get("EQU_CATEGORY_CODE"))) {
certificates = (List<Map<String, Object>>) noticeParams.get("cylCertificates");
} else {
certificates = (List<Map<String, Object>>) noticeParams.get("certificates");
}
// 使用登记证表idList
List<String> registrationIdList = certificates.stream().map(item -> item.get("sequenceNbr").toString()).collect(Collectors.toList());
List<JSONObject> equipmentList = jgUseRegistrationManageService.queryEquByCertificateSeqList(registrationIdList.stream().map(Long::parseLong).collect(Collectors.toList()));
for (JSONObject equip : equipmentList) {
JgScrapCancelEq jgScrapCancelEq = new JgScrapCancelEq();
jgScrapCancelEq.setEquId(equip.getString("SEQUENCE_NBR"));
JgScrapCancelEqList.add(jgScrapCancelEq);
}
}
return JgScrapCancelEqList;
}
private void repeatUsedEquipCheck(List<JgScrapCancelEq> eqList, String companyCode) {
eqList.forEach(cancelEq -> EquipUsedCheckStrategyContext.getUsedStrategy(PAGE_KEY)
.registrationRepeatUsedCheck(cancelEq.getEquId(), companyCode));
}
/**
* 删除 redis校验重复引用设备的数据
*/
private void delRepeatUseEquipData(JgScrapCancel notice) {
if (NOT_FLOWING_STATE.contains(notice.getAuditStatus())) {
LambdaQueryWrapper<JgScrapCancelEq> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(JgScrapCancelEq::getEquipTransferId, notice.getSequenceNbr());
List<JgScrapCancelEq> noticeEqList = jgScrapCancelEqService.list(queryWrapper);
noticeEqList.forEach(noticeEq -> EquipUsedCheckStrategyContext.getUsedStrategy(PAGE_KEY)
.delDataForCheckEquipRepeatUsed(Collections.singletonList(noticeEq.getEquId()), notice.getUseUnitCode())
);
}
}
private void rollBackForDelRedisData() {
FlowingEquipRedisContext.getContext().forEach(
e -> EquipUsedCheckStrategyContext.getUsedStrategy(PAGE_KEY)
.delDataForCheckWithKey(e.getData(), e.getRedisKey()));
} }
/** /**
...@@ -435,6 +510,8 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc ...@@ -435,6 +510,8 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc
@GlobalTransactional(rollbackFor = Exception.class) @GlobalTransactional(rollbackFor = Exception.class)
public JgScrapCancelDto updateInfo(String submitType, JgScrapCancelDto jgScrapCancelDto, String op, JSONObject pageData) { public JgScrapCancelDto updateInfo(String submitType, JgScrapCancelDto jgScrapCancelDto, String op, JSONObject pageData) {
try {
if (Objects.isNull(jgScrapCancelDto) || StringUtils.isEmpty(submitType)) { if (Objects.isNull(jgScrapCancelDto) || StringUtils.isEmpty(submitType)) {
throw new IllegalArgumentException("参数不能为空"); throw new IllegalArgumentException("参数不能为空");
} }
...@@ -443,6 +520,9 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc ...@@ -443,6 +520,9 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc
List<String> roleListNext = new ArrayList<>(); List<String> roleListNext = new ArrayList<>();
List<String> roleListAll = new ArrayList<>(); List<String> roleListAll = new ArrayList<>();
if (SUBMIT_TYPE_FLOW.equals(submitType)) { if (SUBMIT_TYPE_FLOW.equals(submitType)) {
ReginParams reginParams = JSONObject.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId(), RequestContext.getToken())).toString(), ReginParams.class);
List<JgScrapCancelEq> JgScrapCancelEqList = getCancelEqs(pageData);
this.repeatUsedEquipCheck(JgScrapCancelEqList, reginParams.getCompany().getCompanyCode());
// 更新并提交 // 更新并提交
// 发起流程 // 发起流程
if (!StringUtils.hasText(jgScrapCancelDto.getInstanceId())) { if (!StringUtils.hasText(jgScrapCancelDto.getInstanceId())) {
...@@ -519,6 +599,17 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc ...@@ -519,6 +599,17 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc
} }
commonService.saveOrUpdateHistory(getRegistrationClass(jgScrapCancelDto.getCancelType()), pageData, "", jgScrapCancelDto.getSequenceNbr().toString()); commonService.saveOrUpdateHistory(getRegistrationClass(jgScrapCancelDto.getCancelType()), pageData, "", jgScrapCancelDto.getSequenceNbr().toString());
return jgScrapCancelDto; return jgScrapCancelDto;
} catch (BadRequest | LocalBadRequest e) {
log.error(e.getMessage(), e);
this.rollBackForDelRedisData();
throw e;
} catch (Exception e) {
log.error(e.getMessage(), e);
this.rollBackForDelRedisData();
throw new BadRequest("保存失败!");
} finally {
FlowingEquipRedisContext.clean();
}
} }
private void insertJgScrapCancelEqAfterDelete(JgScrapCancel jgScrapCancel, JSONObject pageData) { private void insertJgScrapCancelEqAfterDelete(JgScrapCancel jgScrapCancel, JSONObject pageData) {
...@@ -723,6 +814,7 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc ...@@ -723,6 +814,7 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc
// redis流程实时数据更新 // redis流程实时数据更新
commonService.saveExecuteFlowData2Redis(instanceId, this.buildInstanceRuntimeData(jgScrapCancel)); commonService.saveExecuteFlowData2Redis(instanceId, this.buildInstanceRuntimeData(jgScrapCancel));
this.delRepeatUseEquipData(jgScrapCancel);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
...@@ -780,6 +872,7 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc ...@@ -780,6 +872,7 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc
// redis流程实时数据更新 // redis流程实时数据更新
commonService.saveExecuteFlowData2Redis(instanceId, this.buildInstanceRuntimeData(jgScrapCancel)); commonService.saveExecuteFlowData2Redis(instanceId, this.buildInstanceRuntimeData(jgScrapCancel));
this.delRepeatUseEquipData(jgScrapCancel);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
......
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