Commit a9f7b20e authored by 王果's avatar 王果

21052 维修告知限制设备不能多次出现在执行的流程中

parent 70458668
package com.yeejoin.amos.boot.module.jg.api.mapper; package com.yeejoin.amos.boot.module.jg.api.mapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.jg.api.dto.CompanyEquipCountDto;
import com.yeejoin.amos.boot.module.jg.api.dto.JgMaintainNoticeDto; import com.yeejoin.amos.boot.module.jg.api.dto.JgMaintainNoticeDto;
import com.yeejoin.amos.boot.module.jg.api.entity.JgMaintainNotice; import com.yeejoin.amos.boot.module.jg.api.entity.JgMaintainNotice;
import com.yeejoin.amos.boot.module.jg.api.vo.SortVo; import com.yeejoin.amos.boot.module.jg.api.vo.SortVo;
...@@ -44,4 +45,5 @@ public interface JgMaintainNoticeMapper extends CustomBaseMapper<JgMaintainNotic ...@@ -44,4 +45,5 @@ public interface JgMaintainNoticeMapper extends CustomBaseMapper<JgMaintainNotic
Map<String, Object> getEquipInfoByRecord(String record); Map<String, Object> getEquipInfoByRecord(String record);
List<CompanyEquipCountDto> queryForFlowingEquipList();
} }
...@@ -274,5 +274,16 @@ ...@@ -274,5 +274,16 @@
LEFT JOIN idx_biz_jg_factory_info fi ON fi.record = oi.record LEFT JOIN idx_biz_jg_factory_info fi ON fi.record = oi.record
WHERE oi.record = #{record} ORDER BY oi."rec_date" DESC LIMIT 1 WHERE oi.record = #{record} ORDER BY oi."rec_date" DESC LIMIT 1
</select> </select>
<select id="queryForFlowingEquipList" resultType="com.yeejoin.amos.boot.module.jg.api.dto.CompanyEquipCountDto">
select
a.install_unit_credit_code as companyCode,
group_concat(b.equ_id) as records
from
tzs_jg_maintain_notice a,
tzs_jg_maintain_notice_eq b
where
a.sequence_nbr = b.equip_transfer_id
and a.notice_status not in('6614','6615','6610','6617','6616')
GROUP BY a.install_unit_credit_code
</select>
</mapper> </mapper>
...@@ -25,6 +25,9 @@ import com.yeejoin.amos.boot.module.jg.api.mapper.JgRegistrationHistoryMapper; ...@@ -25,6 +25,9 @@ import com.yeejoin.amos.boot.module.jg.api.mapper.JgRegistrationHistoryMapper;
import com.yeejoin.amos.boot.module.jg.api.service.IJgInstallationNoticeService; import com.yeejoin.amos.boot.module.jg.api.service.IJgInstallationNoticeService;
import com.yeejoin.amos.boot.module.jg.api.service.IJgMaintainNoticeService; import com.yeejoin.amos.boot.module.jg.api.service.IJgMaintainNoticeService;
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.biz.utils.WordTemplateUtils; import com.yeejoin.amos.boot.module.jg.biz.utils.WordTemplateUtils;
...@@ -156,11 +159,11 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto ...@@ -156,11 +159,11 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
if (!ValidationUtil.isEmpty(notice.getStreet()) && !ValidationUtil.isEmpty(notice.getStreetName())) { if (!ValidationUtil.isEmpty(notice.getStreet()) && !ValidationUtil.isEmpty(notice.getStreetName())) {
maintainInfo.put("street", notice.getStreet() + "_" + notice.getStreetName()); maintainInfo.put("street", notice.getStreet() + "_" + notice.getStreetName());
} }
if(Integer.parseInt(notice.getNoticeStatus()) == FlowStatusEnum.TO_BE_FINISHED.getCode()){ if (Integer.parseInt(notice.getNoticeStatus()) == FlowStatusEnum.TO_BE_FINISHED.getCode()) {
// 完成时显示历史数据 // 完成时显示历史数据
JSONObject hisData = commonService.queryHistoryData(notice.getSequenceNbr()); JSONObject hisData = commonService.queryHistoryData(notice.getSequenceNbr());
// 兼容老数据 // 兼容老数据
if(hisData == null){ if (hisData == null) {
// 老数据逻辑 // 老数据逻辑
setNewEquipInfo(sequenceNbr, maintainInfo); setNewEquipInfo(sequenceNbr, maintainInfo);
return new HashMap<String, Map<String, Object>>() {{ return new HashMap<String, Map<String, Object>>() {{
...@@ -182,6 +185,38 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto ...@@ -182,6 +185,38 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
} }
} }
private void checkRepeatUsed(String submitType, JgMaintainNotice notice) {
if (SUBMIT_TYPE_FLOW.equals(submitType)) {
// 流程中校验
LambdaQueryWrapper<JgMaintainNoticeEq> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(JgMaintainNoticeEq::getEquipTransferId, notice.getSequenceNbr());
JgMaintainNoticeEq noticeEq = jgMaintainNoticeEqMapper.selectOne(queryWrapper);
EquipUsedCheckStrategyContext.getUsedStrategy(PROCESS_DEFINITION_KEY)
.equipRepeatUsedCheck(noticeEq.getEquId(), notice.getInstallUnitCreditCode());
}
}
private void repeatUsedEquipCheck(List<Map<String, Object>> equipList, String companyCode) {
equipList.forEach(equipMap -> EquipUsedCheckStrategyContext.getUsedStrategy(PROCESS_DEFINITION_KEY).equipRepeatUsedCheck(String.valueOf(equipMap.get("SEQUENCE_NBR")), companyCode));
}
/**
* 删除 redis校验重复引用设备的数据
*/
private void delRepeatUseEquipData(JgMaintainNotice notice) {
LambdaQueryWrapper<JgMaintainNoticeEq> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(JgMaintainNoticeEq::getEquipTransferId, notice.getSequenceNbr());
JgMaintainNoticeEq noticeEq = jgMaintainNoticeEqMapper.selectOne(queryWrapper);
EquipUsedCheckStrategyContext.getUsedStrategy(PROCESS_DEFINITION_KEY)
.delDataForCheckEquipRepeatUsed(Collections.singletonList(noticeEq.getEquId()), notice.getInstallUnitCreditCode());
}
private void rollBackForDelRedisData() {
FlowingEquipRedisContext.getContext().forEach(e -> {
EquipUsedCheckStrategyContext.getUsedStrategy(PROCESS_DEFINITION_KEY)
.delDataForCheckWithKey(e.getData(), e.getRedisKey());
});
}
private void setNewEquipInfo(Long sequenceNbr, Map<String, Object> maintainInfo) { private void setNewEquipInfo(Long sequenceNbr, Map<String, Object> maintainInfo) {
JgMaintainNoticeEq jgMaintainNoticeEq = jgMaintainNoticeEqMapper.selectOne(new LambdaQueryWrapper<JgMaintainNoticeEq>().eq(JgMaintainNoticeEq::getEquipTransferId, sequenceNbr)); JgMaintainNoticeEq jgMaintainNoticeEq = jgMaintainNoticeEqMapper.selectOne(new LambdaQueryWrapper<JgMaintainNoticeEq>().eq(JgMaintainNoticeEq::getEquipTransferId, sequenceNbr));
Map<String, Object> map = idxBizJgRegisterInfoService.getDetailFieldCamelCaseByRecord(jgMaintainNoticeEq.getEquId()); Map<String, Object> map = idxBizJgRegisterInfoService.getDetailFieldCamelCaseByRecord(jgMaintainNoticeEq.getEquId());
...@@ -201,113 +236,127 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto ...@@ -201,113 +236,127 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
@SuppressWarnings({"rawtypes", "Duplicates"}) @SuppressWarnings({"rawtypes", "Duplicates"})
@Transactional @Transactional
public JgMaintainNoticeDto updateMaintainNotice(String submitType, JgMaintainNoticeDto noticeDto, String op) { public JgMaintainNoticeDto updateMaintainNotice(String submitType, JgMaintainNoticeDto noticeDto, String op) {
if (Objects.isNull(noticeDto) || StringUtils.isEmpty(submitType)) {
throw new IllegalArgumentException("参数不能为空"); try {
} if (Objects.isNull(noticeDto) || StringUtils.isEmpty(submitType)) {
// 字段转换 throw new IllegalArgumentException("参数不能为空");
this.convertField(noticeDto); }
JgMaintainNotice notice = jgMaintainNoticeMapper.selectById(noticeDto.getSequenceNbr()); // 字段转换
// submitType=1为流程提交否则仅为保存业务数据 this.convertField(noticeDto);
if (SUBMIT_TYPE_FLOW.equals(submitType)) { JgMaintainNotice notice = jgMaintainNoticeMapper.selectById(noticeDto.getSequenceNbr());
ProcessTaskDTO processTaskDTO = new ProcessTaskDTO(); this.checkRepeatUsed(submitType, notice);
WorkflowResultDto workflowResultDto = new WorkflowResultDto(); // submitType=1为流程提交否则仅为保存业务数据
// 如果没有实例ID,说明是启动并执行一步 if (SUBMIT_TYPE_FLOW.equals(submitType)) {
// 直接调用工作流 启动并执行API - 可以拿到两个节点的信息,用于填充业务字段 ProcessTaskDTO processTaskDTO = new ProcessTaskDTO();
// 如果有实例ID,为撤回或者驳回后重新提交 WorkflowResultDto workflowResultDto = new WorkflowResultDto();
if (!StringUtils.hasText(noticeDto.getInstanceId())) { // 如果没有实例ID,说明是启动并执行一步
// 发起流程 // 直接调用工作流 启动并执行API - 可以拿到两个节点的信息,用于填充业务字段
ActWorkflowBatchDTO actWorkflowBatchDTO = new ActWorkflowBatchDTO(); // 如果有实例ID,为撤回或者驳回后重新提交
List<ActWorkflowStartDTO> list = new ArrayList<>(); if (!StringUtils.hasText(noticeDto.getInstanceId())) {
ActWorkflowStartDTO dto = new ActWorkflowStartDTO(); // 发起流程
dto.setProcessDefinitionKey(PROCESS_DEFINITION_KEY); ActWorkflowBatchDTO actWorkflowBatchDTO = new ActWorkflowBatchDTO();
dto.setBusinessKey(String.valueOf(noticeDto.getSequenceNbr())); List<ActWorkflowStartDTO> list = new ArrayList<>();
dto.setCompleteFirstTask(Boolean.TRUE); ActWorkflowStartDTO dto = new ActWorkflowStartDTO();
//下一节点执行人单位(下节点接收机构code) dto.setProcessDefinitionKey(PROCESS_DEFINITION_KEY);
dto.setNextExecuteUserCompanyCode(notice.getReceiveCompanyCode()); dto.setBusinessKey(String.valueOf(noticeDto.getSequenceNbr()));
list.add(dto); dto.setCompleteFirstTask(Boolean.TRUE);
actWorkflowBatchDTO.setProcess(list); //下一节点执行人单位(下节点接收机构code)
processTaskDTO = cmWorkflowService.startBatch(actWorkflowBatchDTO).get(0); dto.setNextExecuteUserCompanyCode(notice.getReceiveCompanyCode());
// 提取节点等信息 list.add(dto);
workflowResultDto = commonService.buildWorkFlowInfo(Collections.singletonList(processTaskDTO)).get(0); actWorkflowBatchDTO.setProcess(list);
BeanUtils.copyProperties(noticeDto, notice); processTaskDTO = cmWorkflowService.startBatch(actWorkflowBatchDTO).get(0);
if (!ObjectUtils.isEmpty(notice.getInstanceStatus())) { // 提取节点等信息
notice.setInstanceStatus(notice.getInstanceStatus() + "," + workflowResultDto.getNextExecutorRoleIds()); workflowResultDto = commonService.buildWorkFlowInfo(Collections.singletonList(processTaskDTO)).get(0);
} else { BeanUtils.copyProperties(noticeDto, notice);
notice.setInstanceStatus(workflowResultDto.getNextExecutorRoleIds()); if (!ObjectUtils.isEmpty(notice.getInstanceStatus())) {
} notice.setInstanceStatus(notice.getInstanceStatus() + "," + workflowResultDto.getNextExecutorRoleIds());
notice.setNextExecuteUserIds(workflowResultDto.getNextExecutorUserIds()); } else {
notice.setPromoter(RequestContext.getExeUserId()); notice.setInstanceStatus(workflowResultDto.getNextExecutorRoleIds());
notice.setNextExecuteIds(String.join(",", workflowResultDto.getNextExecutorRoleIds())); }
notice.setNoticeStatus(String.valueOf(FlowStatusEnum.TO_BE_PROCESSED.getCode())); notice.setNextExecuteUserIds(workflowResultDto.getNextExecutorUserIds());
notice.setInstanceId(workflowResultDto.getInstanceId()); notice.setPromoter(RequestContext.getExeUserId());
notice.setNextTaskId(workflowResultDto.getNextTaskId()); notice.setNextExecuteIds(String.join(",", workflowResultDto.getNextExecutorRoleIds()));
jgMaintainNoticeMapper.updateById(notice); notice.setNoticeStatus(String.valueOf(FlowStatusEnum.TO_BE_PROCESSED.getCode()));
// 如果为保存并提交,则创建代办 notice.setInstanceId(workflowResultDto.getInstanceId());
buildTask(Collections.singletonList(notice), Collections.singletonList(workflowResultDto), Boolean.TRUE); notice.setNextTaskId(workflowResultDto.getNextTaskId());
} else { jgMaintainNoticeMapper.updateById(notice);
// 只调用执行API,返回下个节点信息,用于填充业务字段
//组装信息
TaskResultDTO dto = new TaskResultDTO();
dto.setResultCode("approvalStatus");
dto.setTaskId(notice.getNextTaskId());
HashMap<String, Object> commMap = new HashMap<>();
if (notice.getNoticeStatus().equals("6614") || notice.getNoticeStatus().equals("6615")) {
commMap.put("approvalStatus", "提交");
} else {
commMap.put("approvalStatus", op);
}
//下一节点执行人单位(下节点接收机构code)
dto.setNextExecuteUserCompanyCode(notice.getReceiveCompanyCode());
dto.setVariable(commMap);
processTaskDTO = cmWorkflowService.completeOrReject(notice.getNextTaskId(), dto, op);
// 提取节点等信息
workflowResultDto = commonService.buildWorkFlowInfo(Collections.singletonList(processTaskDTO)).get(0);
BeanUtils.copyProperties(noticeDto, notice);
if (!ObjectUtils.isEmpty(notice.getInstanceStatus())) {
notice.setInstanceStatus(notice.getInstanceStatus() + "," + workflowResultDto.getNextExecutorRoleIds());
} else {
notice.setInstanceStatus(workflowResultDto.getNextExecutorRoleIds());
}
notice.setNextExecuteUserIds(workflowResultDto.getNextExecutorUserIds());
notice.setPromoter(RequestContext.getExeUserId());
notice.setNextExecuteIds(String.join(",", workflowResultDto.getNextExecutorRoleIds()));
notice.setNoticeStatus(String.valueOf(FlowStatusEnum.TO_BE_PROCESSED.getCode()));
notice.setNextTaskId(workflowResultDto.getNextTaskId());
jgMaintainNoticeMapper.updateById(notice);
// 上个代办改为已办
HashMap<String, Object> map = new HashMap<>();
map.put("taskStatus", FlowStatusEnum.TO_BE_PROCESSED.getCode());
map.put("taskStatusLabel", FlowStatusEnum.TO_BE_PROCESSED.getName());
map.put("relationId", notice.getInstanceId());
map.put("flowStatus", FlowStatusEnum.TO_BE_PROCESSED.getCode());
map.put("flowStatusLabel", FlowStatusEnum.TO_BE_PROCESSED.getName());
TaskV2Model taskV2Model = commonService.updateTaskModel(map);
if (ObjectUtils.isEmpty(taskV2Model)) {
// 如果为保存并提交,则创建代办 // 如果为保存并提交,则创建代办
buildTask(Collections.singletonList(notice), Collections.singletonList(workflowResultDto), Boolean.FALSE); buildTask(Collections.singletonList(notice), Collections.singletonList(workflowResultDto), Boolean.TRUE);
} else { } else {
TaskModelDto taskModelDto = new TaskModelDto(); // 只调用执行API,返回下个节点信息,用于填充业务字段
BeanUtils.copyProperties(taskV2Model, taskModelDto); //组装信息
// 创建新的代办 TaskResultDTO dto = new TaskResultDTO();
TaskMessageDto taskMessageDto = new TaskMessageDto(); dto.setResultCode("approvalStatus");
BeanUtils.copyProperties(notice, taskMessageDto); dto.setTaskId(notice.getNextTaskId());
taskModelDto.setModel(taskMessageDto); HashMap<String, Object> commMap = new HashMap<>();
taskModelDto.setTaskName(workflowResultDto.getNextTaskName()); if (notice.getNoticeStatus().equals("6614") || notice.getNoticeStatus().equals("6615")) {
taskModelDto.setExecuteUserIds(workflowResultDto.getNextExecutorUserIds()); commMap.put("approvalStatus", "提交");
taskModelDto.setFlowStatus(FlowStatusEnum.TO_BE_PROCESSED.getCode()); } else {
taskModelDto.setFlowStatusLabel(FlowStatusEnum.TO_BE_PROCESSED.getName()); commMap.put("approvalStatus", op);
taskModelDto.setFlowCode(notice.getNextTaskId()); }
taskModelDto.setNextExecuteUser(workflowResultDto.getNextExecutorRoleIds()); //下一节点执行人单位(下节点接收机构code)
commonService.buildTaskModel(Collections.singletonList(taskModelDto)); dto.setNextExecuteUserCompanyCode(notice.getReceiveCompanyCode());
dto.setVariable(commMap);
processTaskDTO = cmWorkflowService.completeOrReject(notice.getNextTaskId(), dto, op);
// 提取节点等信息
workflowResultDto = commonService.buildWorkFlowInfo(Collections.singletonList(processTaskDTO)).get(0);
BeanUtils.copyProperties(noticeDto, notice);
if (!ObjectUtils.isEmpty(notice.getInstanceStatus())) {
notice.setInstanceStatus(notice.getInstanceStatus() + "," + workflowResultDto.getNextExecutorRoleIds());
} else {
notice.setInstanceStatus(workflowResultDto.getNextExecutorRoleIds());
}
notice.setNextExecuteUserIds(workflowResultDto.getNextExecutorUserIds());
notice.setPromoter(RequestContext.getExeUserId());
notice.setNextExecuteIds(String.join(",", workflowResultDto.getNextExecutorRoleIds()));
notice.setNoticeStatus(String.valueOf(FlowStatusEnum.TO_BE_PROCESSED.getCode()));
notice.setNextTaskId(workflowResultDto.getNextTaskId());
jgMaintainNoticeMapper.updateById(notice);
// 上个代办改为已办
HashMap<String, Object> map = new HashMap<>();
map.put("taskStatus", FlowStatusEnum.TO_BE_PROCESSED.getCode());
map.put("taskStatusLabel", FlowStatusEnum.TO_BE_PROCESSED.getName());
map.put("relationId", notice.getInstanceId());
map.put("flowStatus", FlowStatusEnum.TO_BE_PROCESSED.getCode());
map.put("flowStatusLabel", FlowStatusEnum.TO_BE_PROCESSED.getName());
TaskV2Model taskV2Model = commonService.updateTaskModel(map);
if (ObjectUtils.isEmpty(taskV2Model)) {
// 如果为保存并提交,则创建代办
buildTask(Collections.singletonList(notice), Collections.singletonList(workflowResultDto), Boolean.FALSE);
} else {
TaskModelDto taskModelDto = new TaskModelDto();
BeanUtils.copyProperties(taskV2Model, taskModelDto);
// 创建新的代办
TaskMessageDto taskMessageDto = new TaskMessageDto();
BeanUtils.copyProperties(notice, taskMessageDto);
taskModelDto.setModel(taskMessageDto);
taskModelDto.setTaskName(workflowResultDto.getNextTaskName());
taskModelDto.setExecuteUserIds(workflowResultDto.getNextExecutorUserIds());
taskModelDto.setFlowStatus(FlowStatusEnum.TO_BE_PROCESSED.getCode());
taskModelDto.setFlowStatusLabel(FlowStatusEnum.TO_BE_PROCESSED.getName());
taskModelDto.setFlowCode(notice.getNextTaskId());
taskModelDto.setNextExecuteUser(workflowResultDto.getNextExecutorRoleIds());
commonService.buildTaskModel(Collections.singletonList(taskModelDto));
}
} }
commonService.saveExecuteFlowData2Redis(notice.getInstanceId(), this.buildInstanceRuntimeData(notice));
} else {
JgMaintainNotice bean = new JgMaintainNotice();
BeanUtils.copyProperties(noticeDto, bean);
jgMaintainNoticeMapper.updateById(bean);
} }
commonService.saveExecuteFlowData2Redis(notice.getInstanceId(),this.buildInstanceRuntimeData(notice)); return noticeDto;
} else { } catch (BadRequest | LocalBadRequest e) {
JgMaintainNotice bean = new JgMaintainNotice(); log.error(e.getMessage(), e);
BeanUtils.copyProperties(noticeDto, bean); this.rollBackForDelRedisData();
jgMaintainNoticeMapper.updateById(bean); throw e;
} catch (Exception e) {
log.error(e.getMessage(), e);
this.rollBackForDelRedisData();
throw new BadRequest("安装告知保存失败!");
} finally {
FlowingEquipRedisContext.clean();
} }
return noticeDto;
} }
...@@ -319,14 +368,14 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto ...@@ -319,14 +368,14 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
* @return 维修告知列表 * @return 维修告知列表
*/ */
@Override @Override
public Page<Map<String,Object>> queryForJgMaintainNoticePage(Page<JgMaintainNotice> page, String sort, JgMaintainNoticeDto model, ReginParams reginParams) { public Page<Map<String, Object>> queryForJgMaintainNoticePage(Page<JgMaintainNotice> page, String sort, JgMaintainNoticeDto model, ReginParams reginParams) {
String orgCode = reginParams.getCompany().getCompanyCode(); String orgCode = reginParams.getCompany().getCompanyCode();
String type = reginParams.getCompany().getLevel(); String type = reginParams.getCompany().getLevel();
String userId = reginParams.getUserModel().getUserId(); String userId = reginParams.getUserModel().getUserId();
SortVo sortMap = commonService.sortFieldConversion(sort); SortVo sortMap = commonService.sortFieldConversion(sort);
List<DataDictionary> dictionaries = dataDictionaryService.getByType("WXLX"); List<DataDictionary> dictionaries = dataDictionaryService.getByType("WXLX");
Page<Map<String,Object>> noticePage = jgMaintainNoticeMapper.queryForPage(page,sortMap, model, type, orgCode, userId); Page<Map<String, Object>> noticePage = jgMaintainNoticeMapper.queryForPage(page, sortMap, model, type, orgCode, userId);
List<Map<String, Object>> mappedRecords = noticePage.getRecords().stream().peek(notice -> { List<Map<String, Object>> mappedRecords = noticePage.getRecords().stream().peek(notice -> {
Optional<Long> noticeStatusOpt = Optional.ofNullable((String) notice.get("noticeStatus")).map(Long::valueOf); Optional<Long> noticeStatusOpt = Optional.ofNullable((String) notice.get("noticeStatus")).map(Long::valueOf);
noticeStatusOpt.ifPresent(status -> { noticeStatusOpt.ifPresent(status -> {
...@@ -364,7 +413,7 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto ...@@ -364,7 +413,7 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
if (Objects.isNull(JgMaintainNotice) || CollectionUtils.isEmpty(informationList)) { if (Objects.isNull(JgMaintainNotice) || CollectionUtils.isEmpty(informationList)) {
throw new IllegalArgumentException("维修告知单不存在"); throw new IllegalArgumentException("维修告知单不存在");
} }
Map<String, Object> placeholders = jgInstallationNoticeService.fullFillTemplateObj(informationList, BusinessTypeEnum.JG_MAINTENANCE_NOTIFICATION.getName().substring(0,2)); Map<String, Object> placeholders = jgInstallationNoticeService.fullFillTemplateObj(informationList, BusinessTypeEnum.JG_MAINTENANCE_NOTIFICATION.getName().substring(0, 2));
String tempFileName = "维修告知单_" + System.currentTimeMillis() + "_temp"; String tempFileName = "维修告知单_" + System.currentTimeMillis() + "_temp";
// String url = WordTemplateUtils.templateToPdf(tempFileName, "installation-notification-report.ftl", placeholders); // String url = WordTemplateUtils.templateToPdf(tempFileName, "installation-notification-report.ftl", placeholders);
...@@ -380,7 +429,7 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto ...@@ -380,7 +429,7 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
for (Long sequenceNbr : sequenceNbrs) { for (Long sequenceNbr : sequenceNbrs) {
JgMaintainNotice jgMaintainNotice = this.baseMapper.selectById(sequenceNbr); JgMaintainNotice jgMaintainNotice = this.baseMapper.selectById(sequenceNbr);
// 删除待办 + 中止流程 // 删除待办 + 中止流程
commonService.deleteTaskModel(sequenceNbr + "",jgMaintainNotice.getInstanceId()); commonService.deleteTaskModel(sequenceNbr + "", jgMaintainNotice.getInstanceId());
// 删除业务单 // 删除业务单
this.baseMapper.deleteById(sequenceNbr); this.baseMapper.deleteById(sequenceNbr);
// 删除对应equ // 删除对应equ
...@@ -397,87 +446,102 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto ...@@ -397,87 +446,102 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
@SuppressWarnings({"Duplicates", "rawtypes"}) @SuppressWarnings({"Duplicates", "rawtypes"})
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public List<JgMaintainNotice> saveNotice(String submitType, Map<String, Object> jgMaintainNoticeDtoMap, ReginParams reginParams) { public List<JgMaintainNotice> saveNotice(String submitType, Map<String, Object> jgMaintainNoticeDtoMap, ReginParams reginParams) {
try {
JgMaintainNoticeDto model = JSON.parseObject(JSONObject.toJSONString(jgMaintainNoticeDtoMap.get(TABLE_PAGE_ID)), JgMaintainNoticeDto.class);
// 字段转换
convertField(model);
// 获取告知设备列表
List<Map<String, Object>> deviceList = model.getDeviceList();
if (CollectionUtils.isEmpty(deviceList)) {
throw new BadRequest("请选择设备");
}
JgMaintainNoticeDto model = JSON.parseObject(JSONObject.toJSONString(jgMaintainNoticeDtoMap.get(TABLE_PAGE_ID)), JgMaintainNoticeDto.class); // 提交时对设备状态进行校验(处理并发问题,一个未被使用的设备同时被多个使用这打开,同时提交发起申请)
if (SUBMIT_TYPE_FLOW.equals(submitType)) {
// 字段转换 this.repeatUsedEquipCheck(deviceList, reginParams.getCompany().getCompanyCode());
convertField(model); }
// 获取告知设备列表 // 获取告知单号
List<Map<String, Object>> deviceList = model.getDeviceList(); ResponseModel<List<String>> applyNoResult = tzsServiceFeignClient.applicationFormCode(ApplicationFormTypeEnum.WXGZ.getCode(), deviceList.size());
if (CollectionUtils.isEmpty(deviceList)) {
throw new BadRequest("请选择设备");
}
// 获取告知单号
ResponseModel<List<String>> applyNoResult = tzsServiceFeignClient.applicationFormCode(ApplicationFormTypeEnum.WXGZ.getCode(), deviceList.size());
if (CollectionUtils.isEmpty(applyNoResult.getResult())) { if (CollectionUtils.isEmpty(applyNoResult.getResult())) {
log.error(" 获取告知单号失败"); log.error(" 获取告知单号失败");
throw new RuntimeException(); throw new RuntimeException();
} }
List<String> applyNoList = applyNoResult.getResult(); List<String> applyNoList = applyNoResult.getResult();
List<WorkflowResultDto> workflowResultDtoList = workFlowInfo(submitType, deviceList, model.getReceiveCompanyCode()); List<WorkflowResultDto> workflowResultDtoList = workFlowInfo(submitType, deviceList, model.getReceiveCompanyCode());
List<JgMaintainNotice> list = new ArrayList<>(); List<JgMaintainNotice> list = new ArrayList<>();
List<JgMaintainNoticeEq> equipList = new ArrayList<>(); List<JgMaintainNoticeEq> equipList = new ArrayList<>();
CompanyBo companyBo = commonService.getOneCompany(model.getReceiveCompanyCode()); CompanyBo companyBo = commonService.getOneCompany(model.getReceiveCompanyCode());
deviceList.forEach(obj -> { deviceList.forEach(obj -> {
JgMaintainNoticeEq jgRelationEquip = new JgMaintainNoticeEq(); JgMaintainNoticeEq jgRelationEquip = new JgMaintainNoticeEq();
JgMaintainNotice dto = new JgMaintainNotice(); JgMaintainNotice dto = new JgMaintainNotice();
BeanUtils.copyProperties(model, dto); BeanUtils.copyProperties(model, dto);
int i = deviceList.indexOf(obj); int i = deviceList.indexOf(obj);
String applyNo = applyNoList.get(i); String applyNo = applyNoList.get(i);
dto.setApplyNo(applyNo); dto.setApplyNo(applyNo);
// 统计使用 // 统计使用
dto.setReceiveCompanyOrgCode(companyBo.getOrgCode()); dto.setReceiveCompanyOrgCode(companyBo.getOrgCode());
dto.setNoticeDate(new Date()); dto.setNoticeDate(new Date());
dto.setEquCategory(String.valueOf(obj.get("EQU_CATEGORY"))); dto.setEquCategory(String.valueOf(obj.get("EQU_CATEGORY")));
dto.setEquListCode(String.valueOf(obj.get("EQU_LIST_CODE"))); dto.setEquListCode(String.valueOf(obj.get("EQU_LIST_CODE")));
dto.setCreateUserCompanyName(reginParams.getCompany().getCompanyName()); dto.setCreateUserCompanyName(reginParams.getCompany().getCompanyName());
if (SUBMIT_TYPE_FLOW.equals(submitType)) {
dto.setNextExecuteIds(workflowResultDtoList.get(i).getNextExecutorRoleIds());
dto.setInstanceStatus(workflowResultDtoList.get(i).getNextExecutorRoleIds() + "," + workflowResultDtoList.get(i).getExecutorRoleIds());
dto.setPromoter(reginParams.getUserModel().getUserId());
dto.setNextExecuteUserIds(workflowResultDtoList.get(i).getNextExecutorUserIds());
dto.setNextTaskId(workflowResultDtoList.get(i).getNextTaskId());
dto.setInstanceId(workflowResultDtoList.get(i).getInstanceId());
dto.setNoticeStatus(String.valueOf(FlowStatusEnum.TO_BE_PROCESSED.getCode()));
} else {
dto.setNextExecuteUserIds(reginParams.getUserModel().getUserId());
dto.setNoticeStatus(String.valueOf(FlowStatusEnum.TO_BE_SUBMITTED.getCode()));
}
dto.setEquList(String.valueOf(obj.get("EQU_LIST")));
dto.setSupervisoryCode(String.valueOf(obj.get("SUPERVISORY_CODE")));
dto.setInstallUnitName(reginParams.getCompany().getCompanyName());
dto.setInstallUnitCreditCode(reginParams.getCompany().getCompanyCode());
jgRelationEquip.setEquId(String.valueOf(obj.get("SEQUENCE_NBR")));
jgRelationEquip.setEquipTransferId(applyNo);
dto.setCreateUserName(reginParams.getUserModel().getRealName());
dto.setCreateUserId(reginParams.getUserModel().getUserId());
DataDictionary dictionary = iDataDictionaryService.getByCode(dto.getMaintainType(), "WXLX");
dto.setMaintainTypeDesc(dictionary.getName());
dto.setFullAddress(dto.getProvinceName() + dto.getCityName() + dto.getCountyName() + dto.getStreetName() + dto.getAddress());
list.add(dto);
equipList.add(jgRelationEquip);
});
jgMaintainNoticeMapper.insertBatchSomeColumn(list);
if (SUBMIT_TYPE_FLOW.equals(submitType)) { if (SUBMIT_TYPE_FLOW.equals(submitType)) {
dto.setNextExecuteIds(workflowResultDtoList.get(i).getNextExecutorRoleIds()); buildTask(list, workflowResultDtoList, Boolean.TRUE);
dto.setInstanceStatus(workflowResultDtoList.get(i).getNextExecutorRoleIds() + "," + workflowResultDtoList.get(i).getExecutorRoleIds());
dto.setPromoter(reginParams.getUserModel().getUserId());
dto.setNextExecuteUserIds(workflowResultDtoList.get(i).getNextExecutorUserIds());
dto.setNextTaskId(workflowResultDtoList.get(i).getNextTaskId());
dto.setInstanceId(workflowResultDtoList.get(i).getInstanceId());
dto.setNoticeStatus(String.valueOf(FlowStatusEnum.TO_BE_PROCESSED.getCode()));
} else { } else {
dto.setNextExecuteUserIds(reginParams.getUserModel().getUserId()); // 暂存任务
dto.setNoticeStatus(String.valueOf(FlowStatusEnum.TO_BE_SUBMITTED.getCode())); buildTaskDraft(list);
} }
dto.setEquList(String.valueOf(obj.get("EQU_LIST"))); List<JgMaintainNoticeEq> jgRelationEquipList = equipList.stream().map(jgRelationEquip -> {
dto.setSupervisoryCode(String.valueOf(obj.get("SUPERVISORY_CODE"))); List<JgMaintainNotice> collect = list.stream().filter(JgMaintainNotice -> jgRelationEquip.getEquipTransferId().equals(JgMaintainNotice.getApplyNo())).collect(Collectors.toList());
dto.setInstallUnitName(reginParams.getCompany().getCompanyName()); Long sequenceNbr = collect.get(0).getSequenceNbr();
dto.setInstallUnitCreditCode(reginParams.getCompany().getCompanyCode()); return jgRelationEquip.setEquipTransferId(String.valueOf(sequenceNbr));
}).collect(Collectors.toList());
jgRelationEquip.setEquId(String.valueOf(obj.get("SEQUENCE_NBR"))); jgMaintainNoticeEqMapper.insertBatchSomeColumn(jgRelationEquipList);
jgRelationEquip.setEquipTransferId(applyNo); this.updateRedisBatch(list);
return list;
dto.setCreateUserName(reginParams.getUserModel().getRealName()); } catch (BadRequest | LocalBadRequest e) {
dto.setCreateUserId(reginParams.getUserModel().getUserId()); log.error(e.getMessage(), e);
DataDictionary dictionary = iDataDictionaryService.getByCode(dto.getMaintainType(), "WXLX"); this.rollBackForDelRedisData();
dto.setMaintainTypeDesc(dictionary.getName()); throw e;
dto.setFullAddress(dto.getProvinceName() + dto.getCityName() + dto.getCountyName() + dto.getStreetName() + dto.getAddress()); } catch (Exception e) {
list.add(dto); log.error(e.getMessage(), e);
equipList.add(jgRelationEquip); this.rollBackForDelRedisData();
}); throw new BadRequest("安装告知保存失败!");
jgMaintainNoticeMapper.insertBatchSomeColumn(list); } finally {
if (SUBMIT_TYPE_FLOW.equals(submitType)) { FlowingEquipRedisContext.clean();
buildTask(list, workflowResultDtoList, Boolean.TRUE);
} else {
// 暂存任务
buildTaskDraft(list);
} }
List<JgMaintainNoticeEq> jgRelationEquipList = equipList.stream().map(jgRelationEquip -> {
List<JgMaintainNotice> collect = list.stream().filter(JgMaintainNotice -> jgRelationEquip.getEquipTransferId().equals(JgMaintainNotice.getApplyNo())).collect(Collectors.toList());
Long sequenceNbr = collect.get(0).getSequenceNbr();
return jgRelationEquip.setEquipTransferId(String.valueOf(sequenceNbr));
}).collect(Collectors.toList());
jgMaintainNoticeEqMapper.insertBatchSomeColumn(jgRelationEquipList);
this.updateRedisBatch(list);
return list;
} }
private void updateRedisBatch(List<JgMaintainNotice> jgMaintainNotices) { private void updateRedisBatch(List<JgMaintainNotice> jgMaintainNotices) {
...@@ -542,7 +606,7 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto ...@@ -542,7 +606,7 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
taskMessageDto.setNextTaskId(item.getNextTaskId()); taskMessageDto.setNextTaskId(item.getNextTaskId());
taskModelDto.setModel(taskMessageDto); taskModelDto.setModel(taskMessageDto);
taskModelDto.setNextExecuteUser(item.getNextExecuteIds()); taskModelDto.setNextExecuteUser(item.getNextExecuteIds());
taskModelDto.setTaskContent(String.format("来自%s【%s】的业务办理,【申请单号:%s】", item.getEquList(), StringUtils.isEmpty(item.getSupervisoryCode()) ? "" : item.getSupervisoryCode(), item.getApplyNo())); taskModelDto.setTaskContent(String.format("来自%s【%s】的业务办理,【申请单号:%s】", item.getEquList(), StringUtils.isEmpty(item.getSupervisoryCode()) ? "" : item.getSupervisoryCode(), item.getApplyNo()));
taskModelDtoList.add(taskModelDto); taskModelDtoList.add(taskModelDto);
if (bool) { if (bool) {
// 删除暂存时生成的待办 // 删除暂存时生成的待办
...@@ -574,7 +638,7 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto ...@@ -574,7 +638,7 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
} }
return new ArrayList<>(); return new ArrayList<>();
} }
private void convertField(JgMaintainNoticeDto model) { private void convertField(JgMaintainNoticeDto model) {
if (null == model) { if (null == model) {
...@@ -722,6 +786,7 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto ...@@ -722,6 +786,7 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
commonService.rollbackTask(jgMaintainNotice.getInstanceId(), jsonObject); commonService.rollbackTask(jgMaintainNotice.getInstanceId(), jsonObject);
commonService.saveExecuteFlowData2Redis(instanceId, this.buildInstanceRuntimeData(jgMaintainNotice)); commonService.saveExecuteFlowData2Redis(instanceId, this.buildInstanceRuntimeData(jgMaintainNotice));
this.delRepeatUseEquipData(jgMaintainNotice);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
...@@ -864,10 +929,10 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto ...@@ -864,10 +929,10 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
taskModelDto.setNextExecuteUser(workflowResultDto.getNextExecutorRoleIds()); taskModelDto.setNextExecuteUser(workflowResultDto.getNextExecutorRoleIds());
taskModelDto.setPageType("edit"); taskModelDto.setPageType("edit");
commonService.buildTaskModel(Collections.singletonList(taskModelDto)); commonService.buildTaskModel(Collections.singletonList(taskModelDto));
jgMaintainNotice.setNextExecuteUserIds(workflowResultDto.getNextExecutorUserIds()); jgMaintainNotice.setNextExecuteUserIds(workflowResultDto.getNextExecutorUserIds());
jgMaintainNotice.setNextTaskId(workflowResultDto.getNextTaskId()); jgMaintainNotice.setNextTaskId(workflowResultDto.getNextTaskId());
jgMaintainNoticeMapper.updateById(jgMaintainNotice); jgMaintainNoticeMapper.updateById(jgMaintainNotice);
this.delRepeatUseEquipData(jgMaintainNotice);
} }
commonService.saveExecuteFlowData2Redis(instanceId, this.buildInstanceRuntimeData(jgMaintainNotice)); commonService.saveExecuteFlowData2Redis(instanceId, this.buildInstanceRuntimeData(jgMaintainNotice));
} catch (InterruptedException e) { } catch (InterruptedException e) {
......
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.JgMaintainNoticeMapper;
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 MaintainNoticeEquipUsedCheckImpl extends BaseEquipUsedCheckService {
private RedissonClient redissonClient;
private String bizType = "maintainNotice";
private JgMaintainNoticeMapper maintainNoticeMapper;
public MaintainNoticeEquipUsedCheckImpl(RedissonClient redissonClient, JgMaintainNoticeMapper maintainNoticeMapper) {
this.redissonClient = redissonClient;
this.maintainNoticeMapper = maintainNoticeMapper;
}
@Override
public RedissonClient getRedisClient() {
return redissonClient;
}
@Override
public String getApplyBizType() {
return bizType;
}
@Override
public void init() {
// 初始化已经完成或者在流程中安装告知的设备数据
List<CompanyEquipCountDto> companyEquipCountDtos = maintainNoticeMapper.queryForFlowingEquipList();
companyEquipCountDtos.forEach(c -> {
RBucket<Set<String>> rBucket = redissonClient.getBucket(getFlowingEquipRedisKey(c.getCompanyCode(), bizType));
rBucket.set(Arrays.stream(c.getRecords().split(",")).collect(Collectors.toSet()));
});
}
}
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