Commit deaccab3 authored by 王果's avatar 王果

21052 启用停用校验设备是否在流程中

parent b809ee89
......@@ -2,6 +2,7 @@ package com.yeejoin.amos.boot.module.jg.api.mapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.JgEnableDisableDto;
import com.yeejoin.amos.boot.module.jg.api.entity.JgEnableDisable;
......@@ -29,4 +30,6 @@ public interface JgEnableDisableMapper extends BaseMapper<JgEnableDisable> {
Map<String, Object> getDetail(@Param("sequenceNbr") Long sequenceNbr);
List<EquipBizCountDto> queryStoppedDeviceStaticListData(DPFilterParamDto dpFilterParamDto);
List<CompanyEquipCountDto> queryForFlowingEquipList();
}
......@@ -151,4 +151,14 @@
c.equ_category,
c.equ_define
</select>
<select id="queryForFlowingEquipList" resultType="com.yeejoin.amos.boot.module.jg.api.dto.CompanyEquipCountDto">
select a.use_unit_credit_code as companyCode,
group_concat(b.certificate_seq) as records
from tzs_jg_change_registration_name a,
tzs_jg_change_registration_name_eq b
where a.sequence_nbr = b.name_change_registration_id
and a.audit_status in ('三级待受理', '二级待受理', '一级待受理')
GROUP BY a.use_unit_credit_code
</select>
</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.JgEnableDisableMapper;
import com.yeejoin.amos.boot.module.jg.api.mapper.JgInstallationNoticeMapper;
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 JgEnableDisableEquipUsedCheckImpl extends BaseEquipUsedCheckService {
private RedissonClient redissonClient;
private String bizType = "deactivateEnable";
private JgEnableDisableMapper mapper;
public JgEnableDisableEquipUsedCheckImpl(RedissonClient redissonClient, JgEnableDisableMapper 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()));
});
}
}
package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Sequence;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
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.dto.*;
import com.yeejoin.amos.boot.module.jg.api.entity.*;
import com.yeejoin.amos.boot.module.jg.api.entity.JgEnableDisable;
import com.yeejoin.amos.boot.module.jg.api.entity.JgEnableDisableEq;
import com.yeejoin.amos.boot.module.jg.api.entity.JgRegistrationHistory;
import com.yeejoin.amos.boot.module.jg.api.enums.BusinessTypeEnum;
import com.yeejoin.amos.boot.module.jg.api.enums.WorkFlowStatusEnum;
import com.yeejoin.amos.boot.module.jg.api.mapper.JgEnableDisableEqMapper;
......@@ -19,6 +22,9 @@ import com.yeejoin.amos.boot.module.jg.api.mapper.JgMaintainNoticeMapper;
import com.yeejoin.amos.boot.module.jg.api.mapper.JgRegistrationHistoryMapper;
import com.yeejoin.amos.boot.module.jg.api.service.IJgEnableDisableService;
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.service.ICmWorkflowService;
import com.yeejoin.amos.boot.module.jg.biz.service.IIdxBizJgRegisterInfoService;
......@@ -37,15 +43,13 @@ import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import com.baomidou.mybatisplus.core.toolkit.Sequence;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
......@@ -81,7 +85,7 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
@Autowired
IIdxBizJgRegisterInfoService idxBizJgRegisterInfoService;
private final List<String> NOT_FLOWING_STATE = Arrays.asList("使用单位待提交", "一级受理已驳回", "使用单位已撤回", "已作废", "已完成");
private final String PROCESS_DEFINITION_KEY = "deactivateEnable";
......@@ -117,6 +121,7 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
@Transactional(rollbackFor = Exception.class)
public List<JgEnableDisable> saveOrUpdate(JSONObject map, ReginParams reginParams) {
try {
JgEnableDisable jgEnableDisable = new JgEnableDisable();
if (!"null".equals(String.valueOf(map.get("sequenceNbr")))) {
jgEnableDisable = this.baseMapper.selectById(String.valueOf(map.get("sequenceNbr")));
......@@ -131,7 +136,10 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
String submit = String.valueOf(map.get("submit"));
String pageType = String.valueOf(map.get("formType"));
List<Map<String, Object>> equipments = (List<Map<String, Object>>) map.get("equipments");
String businessCode = ObjectUtils.isEmpty(map.get("applyType"))?String.valueOf(map.get("businessCode")):String.valueOf(map.get("applyType"));
if (SUBMIT_TYPE_FLOW.equals(submit)) {//校验设备不能再多个流程中
this.repeatUsedEquipCheck(equipments, reginParams.getCompany().getCompanyCode());
}
String businessCode = ObjectUtils.isEmpty(map.get("applyType")) ? String.valueOf(map.get("businessCode")) : String.valueOf(map.get("applyType"));
// 接收机构
String[] receiveOrgCode = String.valueOf(map.getString("receiveOrgCode")).split("_");
List<WorkflowResultDto> workflowResultList = new ArrayList<>();
......@@ -141,7 +149,7 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
jgEnableDisable.setOtherAccessories(JSONObject.toJSONString(Optional.ofNullable(map.get("otherAccessories")).orElse(Collections.emptyMap())));
if (SUBMIT_TYPE_FLOW.equals(submit)) {
if (map.containsKey("instanceId") && !ObjectUtils.isEmpty(map.get("instanceId"))){
if (map.containsKey("instanceId") && !ObjectUtils.isEmpty(map.get("instanceId"))) {
// 只调用执行API,返回下个节点信息,用于填充业务字段
//组装信息
TaskResultDTO dto = new TaskResultDTO();
......@@ -200,7 +208,7 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
}
} else {
// 启动工作流并返回信息
workflowResultList = workFlowInfo(submit, jgEnableDisable,receiveOrgCode[0]);
workflowResultList = workFlowInfo(submit, jgEnableDisable, receiveOrgCode[0]);
//业务数据组装等
businessData(submit, reginParams, jgEnableDisable, map, workflowResultList);
......@@ -239,7 +247,7 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
lambda.eq(JgEnableDisableEq::getEnableDisableApplyId, String.valueOf(map.get("sequenceNbr")));
jgEnableDisableEqService.getBaseMapper().delete(lambda);
}
if(!SUBMIT_TYPE_FLOW.equals(submit)){
if (!SUBMIT_TYPE_FLOW.equals(submit)) {
// 暂存任务
buildTaskDraft(jgEnableDisable);
} else {
......@@ -248,11 +256,47 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
// 保存历史表
commonService.saveOrUpdateHistory(this.getRegistrationClass(jgEnableDisable), map, null, jgEnableDisable.getSequenceNbr().toString());
return Collections.singletonList(jgEnableDisable);
} 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 String getRegistrationClass(JgEnableDisable jgEnableDisable){
private void repeatUsedEquipCheck(List<Map<String, Object>> equipList, String companyCode) {
equipList.forEach(equipMap -> EquipUsedCheckStrategyContext.getUsedStrategy(PROCESS_DEFINITION_KEY)
.equipRepeatUsedCheck(String.valueOf(equipMap.get("record")), companyCode));
}
/**
* 删除 redis校验重复引用设备的数据
*/
private void delRepeatUseEquipData(JgEnableDisable notice) {
if (NOT_FLOWING_STATE.contains(notice.getAuditStatus())) {
LambdaQueryWrapper<JgEnableDisableEq> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(JgEnableDisableEq::getEnableDisableApplyId, notice.getSequenceNbr());
List<JgEnableDisableEq> noticeEqList = jgEnableDisableEqService.list(queryWrapper);
noticeEqList.forEach(noticeEq -> EquipUsedCheckStrategyContext.getUsedStrategy(PROCESS_DEFINITION_KEY)
.delDataForCheckEquipRepeatUsed(Collections.singletonList(noticeEq.getEquId()), notice.getUseUnitCreditCode()));
}
}
private void rollBackForDelRedisData() {
FlowingEquipRedisContext.getContext().forEach(e -> {
EquipUsedCheckStrategyContext.getUsedStrategy(PROCESS_DEFINITION_KEY)
.delDataForCheckWithKey(e.getData(), e.getRedisKey());
});
}
private String getRegistrationClass(JgEnableDisable jgEnableDisable) {
// SB_QY启用,SB_TY停用
if(APPLY_TYPE_QY.equals(jgEnableDisable.getApplyType())){
if (APPLY_TYPE_QY.equals(jgEnableDisable.getApplyType())) {
return BusinessTypeEnum.JG_EQUIPMENT_START.getName();
} else {
return BusinessTypeEnum.JG_EQUIPMENT_STOP.getName();
......@@ -261,6 +305,7 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
/**
* 暂存任务生成待办
*
* @param jgEnableDisable 业务信息
*/
private void buildTaskDraft(JgEnableDisable jgEnableDisable) {
......@@ -327,14 +372,14 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
/**
* 插入代办
*/
private void buildTask(List<JgEnableDisable> list,String businessCode, List<WorkflowResultDto> workflowResultList,Boolean bool) {
String taskType = businessCode.equals(ApplicationFormTypeEnum.SBQY.getBusinessCode())?BusinessTypeEnum.JG_EQUIPMENT_START.getCode():BusinessTypeEnum.JG_EQUIPMENT_STOP.getCode();
String taskTypeLabel = businessCode.equals(ApplicationFormTypeEnum.SBQY.getBusinessCode())?BusinessTypeEnum.JG_EQUIPMENT_START.getName():BusinessTypeEnum.JG_EQUIPMENT_STOP.getName();
private void buildTask(List<JgEnableDisable> list, String businessCode, List<WorkflowResultDto> workflowResultList, Boolean bool) {
String taskType = businessCode.equals(ApplicationFormTypeEnum.SBQY.getBusinessCode()) ? BusinessTypeEnum.JG_EQUIPMENT_START.getCode() : BusinessTypeEnum.JG_EQUIPMENT_STOP.getCode();
String taskTypeLabel = businessCode.equals(ApplicationFormTypeEnum.SBQY.getBusinessCode()) ? BusinessTypeEnum.JG_EQUIPMENT_START.getName() : BusinessTypeEnum.JG_EQUIPMENT_STOP.getName();
List<TaskModelDto> taskModelDtoList = new ArrayList<>();
list.forEach(item -> {
TaskModelDto taskModelDto = new TaskModelDto();
taskModelDto.setFlowCreateDate(item.getCreateDate());
if(workflowResultList.size()>0){
if (workflowResultList.size() > 0) {
taskModelDto.setTaskName(workflowResultList.get(0).getNextTaskName()); // 工作流API返回
taskModelDto.setExecuteUserIds(workflowResultList.get(0).getNextExecutorUserIds()); // 工作流API返回
}
......@@ -358,17 +403,16 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
taskModelDtoList.add(taskModelDto);
if (bool) {
// 删除暂存时生成的待办
commonService.deleteTasksByRelationId(item.getSequenceNbr()+"");
commonService.deleteTasksByRelationId(item.getSequenceNbr() + "");
}
});
if(bool){
if (bool) {
commonService.buildTaskModel(taskModelDtoList);
}
}
public Page<Map<String, Object>> pageList(Page<Map<String, Object>> page,String sort, JgEnableDisableDto dto) {
public Page<Map<String, Object>> pageList(Page<Map<String, Object>> page, String sort, JgEnableDisableDto dto) {
ReginParams reginParams = JSONObject.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId(), RequestContext.getToken())).toString(), ReginParams.class);
if ("company".equals(reginParams.getCompany().getLevel())) {
dto.setUseUnitCreditCode(reginParams.getCompany().getCompanyCode());
......@@ -378,7 +422,7 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
String level = reginParams.getCompany().getLevel();
String userId = reginParams.getUserModel().getUserId();
SortVo sortMap = commonService.sortFieldConversion(sort);
return this.baseMapper.pageList(page,sortMap, dto, level,userId);
return this.baseMapper.pageList(page, sortMap, dto, level, userId);
}
......@@ -398,14 +442,14 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
}
/**
* 工作流启动并执行
*
* @param submitType 是否提交
* @param jgEnableDisable 业务数据
* @return 工作流返回相关数据
*/
private List<WorkflowResultDto> workFlowInfo(String submitType, JgEnableDisable jgEnableDisable,String receiveOrgCode) {
private List<WorkflowResultDto> workFlowInfo(String submitType, JgEnableDisable jgEnableDisable, String receiveOrgCode) {
if (SUBMIT_TYPE_FLOW.equals(submitType)) {
ActWorkflowBatchDTO actWorkflowBatchDTO = new ActWorkflowBatchDTO();
List<ActWorkflowStartDTO> list = new ArrayList<>();
......@@ -435,7 +479,7 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
try {
boolean isLocked = lock.tryLock(0, 180, TimeUnit.SECONDS);
// 解决并发问题:多个人同时操作一个流程(并发执行通过、驳回、撤回)
if(!isLocked){
if (!isLocked) {
throw new BadRequest("当前流程已经被执行!请重新打开页面查看并执行!");
}
// 流程执行时,状态及权限校验
......@@ -531,10 +575,11 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
// redis流程实时数据更新
commonService.saveExecuteFlowData2Redis(instanceId, this.buildInstanceRuntimeData(jgEnableDisable));
this.delRepeatUseEquipData(jgEnableDisable);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
if(lock.isHeldByCurrentThread()){
if (lock.isHeldByCurrentThread()) {
lock.unlock();
}
}
......@@ -546,7 +591,7 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
lambdaEq.eq(JgEnableDisableEq::getEnableDisableApplyId, jgEnableDisable.getSequenceNbr());
JgEnableDisableEq jgScrapCancelEq = jgEnableDisableEqMapper.selectOne(lambdaEq);
IdxBizJgUseInfo idxBizJgUseInfo = new IdxBizJgUseInfo();
if(APPLY_TYPE_QY.equals(jgEnableDisable.getApplyType())){
if (APPLY_TYPE_QY.equals(jgEnableDisable.getApplyType())) {
// 1启用
idxBizJgUseInfo.setEquState(String.valueOf(EquimentEnum.ZAIYONG.getCode()));
} else {
......@@ -575,6 +620,7 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
/**
* 执行工作流并返回组装好的工作流信息
*
* @param op 是否通过
* @param opinion 备注信息
* @param jgEnableDisable 业务信息
......@@ -607,7 +653,7 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
try {
boolean isLocked = lock.tryLock(0, 180, TimeUnit.SECONDS);
// 解决并发问题:多个人同时操作一个流程(并发执行通过、驳回、撤回)
if(!isLocked){
if (!isLocked) {
throw new BadRequest("当前流程已经被执行!请重新打开页面查看并执行!");
}
// 流程执行时,状态及权限校验
......@@ -623,7 +669,6 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
jgEnableDisable.setNextTaskId(workflowResultDto.getNextTaskId());
jgEnableDisable.setNextExecuteUserIds(workflowResultDto.getNextExecutorUserIds());
updateById(jgEnableDisable);
// 删除待办
JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(jgEnableDisable));
jsonObject.put("nextExecuteUser", jgEnableDisable.getNextExecutorIds());
......@@ -634,10 +679,11 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
// redis流程实时数据更新
commonService.saveExecuteFlowData2Redis(instanceId, this.buildInstanceRuntimeData(jgEnableDisable));
this.delRepeatUseEquipData(jgEnableDisable);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
if(lock.isHeldByCurrentThread()){
if (lock.isHeldByCurrentThread()) {
lock.unlock();
}
}
......@@ -710,7 +756,7 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
public void deleteMessage(Long sequenceNbr) {
JgEnableDisable jgEnableDisable = this.baseMapper.selectById(sequenceNbr);
// 删除代办 + 中止流程
commonService.deleteTaskModel(String.valueOf(sequenceNbr),jgEnableDisable.getInstanceId());
commonService.deleteTaskModel(String.valueOf(sequenceNbr), jgEnableDisable.getInstanceId());
// 删除单子
this.baseMapper.deleteById(sequenceNbr);
// 删除单子对应eq
......
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