Commit a9f7b20e authored by 王果's avatar 王果

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

parent 70458668
package com.yeejoin.amos.boot.module.jg.api.mapper;
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.entity.JgMaintainNotice;
import com.yeejoin.amos.boot.module.jg.api.vo.SortVo;
......@@ -44,4 +45,5 @@ public interface JgMaintainNoticeMapper extends CustomBaseMapper<JgMaintainNotic
Map<String, Object> getEquipInfoByRecord(String record);
List<CompanyEquipCountDto> queryForFlowingEquipList();
}
......@@ -274,5 +274,16 @@
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
</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>
......@@ -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.IJgMaintainNoticeService;
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.IIdxBizJgRegisterInfoService;
import com.yeejoin.amos.boot.module.jg.biz.utils.WordTemplateUtils;
......@@ -156,11 +159,11 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
if (!ValidationUtil.isEmpty(notice.getStreet()) && !ValidationUtil.isEmpty(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());
// 兼容老数据
if(hisData == null){
if (hisData == null) {
// 老数据逻辑
setNewEquipInfo(sequenceNbr, maintainInfo);
return new HashMap<String, Map<String, Object>>() {{
......@@ -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) {
JgMaintainNoticeEq jgMaintainNoticeEq = jgMaintainNoticeEqMapper.selectOne(new LambdaQueryWrapper<JgMaintainNoticeEq>().eq(JgMaintainNoticeEq::getEquipTransferId, sequenceNbr));
Map<String, Object> map = idxBizJgRegisterInfoService.getDetailFieldCamelCaseByRecord(jgMaintainNoticeEq.getEquId());
......@@ -201,12 +236,15 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
@SuppressWarnings({"rawtypes", "Duplicates"})
@Transactional
public JgMaintainNoticeDto updateMaintainNotice(String submitType, JgMaintainNoticeDto noticeDto, String op) {
try {
if (Objects.isNull(noticeDto) || StringUtils.isEmpty(submitType)) {
throw new IllegalArgumentException("参数不能为空");
}
// 字段转换
this.convertField(noticeDto);
JgMaintainNotice notice = jgMaintainNoticeMapper.selectById(noticeDto.getSequenceNbr());
this.checkRepeatUsed(submitType, notice);
// submitType=1为流程提交否则仅为保存业务数据
if (SUBMIT_TYPE_FLOW.equals(submitType)) {
ProcessTaskDTO processTaskDTO = new ProcessTaskDTO();
......@@ -301,13 +339,24 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
commonService.buildTaskModel(Collections.singletonList(taskModelDto));
}
}
commonService.saveExecuteFlowData2Redis(notice.getInstanceId(),this.buildInstanceRuntimeData(notice));
commonService.saveExecuteFlowData2Redis(notice.getInstanceId(), this.buildInstanceRuntimeData(notice));
} else {
JgMaintainNotice bean = new JgMaintainNotice();
BeanUtils.copyProperties(noticeDto, bean);
jgMaintainNoticeMapper.updateById(bean);
}
return noticeDto;
} 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();
}
}
......@@ -319,13 +368,13 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
* @return 维修告知列表
*/
@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 type = reginParams.getCompany().getLevel();
String userId = reginParams.getUserModel().getUserId();
SortVo sortMap = commonService.sortFieldConversion(sort);
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 -> {
Optional<Long> noticeStatusOpt = Optional.ofNullable((String) notice.get("noticeStatus")).map(Long::valueOf);
......@@ -364,7 +413,7 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
if (Objects.isNull(JgMaintainNotice) || CollectionUtils.isEmpty(informationList)) {
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 url = WordTemplateUtils.templateToPdf(tempFileName, "installation-notification-report.ftl", placeholders);
......@@ -380,7 +429,7 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
for (Long sequenceNbr : sequenceNbrs) {
JgMaintainNotice jgMaintainNotice = this.baseMapper.selectById(sequenceNbr);
// 删除待办 + 中止流程
commonService.deleteTaskModel(sequenceNbr + "",jgMaintainNotice.getInstanceId());
commonService.deleteTaskModel(sequenceNbr + "", jgMaintainNotice.getInstanceId());
// 删除业务单
this.baseMapper.deleteById(sequenceNbr);
// 删除对应equ
......@@ -397,7 +446,7 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
@SuppressWarnings({"Duplicates", "rawtypes"})
@Transactional(rollbackFor = Exception.class)
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);
// 字段转换
......@@ -408,6 +457,10 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
throw new BadRequest("请选择设备");
}
// 提交时对设备状态进行校验(处理并发问题,一个未被使用的设备同时被多个使用这打开,同时提交发起申请)
if (SUBMIT_TYPE_FLOW.equals(submitType)) {
this.repeatUsedEquipCheck(deviceList, reginParams.getCompany().getCompanyCode());
}
// 获取告知单号
ResponseModel<List<String>> applyNoResult = tzsServiceFeignClient.applicationFormCode(ApplicationFormTypeEnum.WXGZ.getCode(), deviceList.size());
......@@ -478,6 +531,17 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
jgMaintainNoticeEqMapper.insertBatchSomeColumn(jgRelationEquipList);
this.updateRedisBatch(list);
return list;
} 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 updateRedisBatch(List<JgMaintainNotice> jgMaintainNotices) {
......@@ -722,6 +786,7 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
commonService.rollbackTask(jgMaintainNotice.getInstanceId(), jsonObject);
commonService.saveExecuteFlowData2Redis(instanceId, this.buildInstanceRuntimeData(jgMaintainNotice));
this.delRepeatUseEquipData(jgMaintainNotice);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
......@@ -864,10 +929,10 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
taskModelDto.setNextExecuteUser(workflowResultDto.getNextExecutorRoleIds());
taskModelDto.setPageType("edit");
commonService.buildTaskModel(Collections.singletonList(taskModelDto));
jgMaintainNotice.setNextExecuteUserIds(workflowResultDto.getNextExecutorUserIds());
jgMaintainNotice.setNextTaskId(workflowResultDto.getNextTaskId());
jgMaintainNoticeMapper.updateById(jgMaintainNotice);
this.delRepeatUseEquipData(jgMaintainNotice);
}
commonService.saveExecuteFlowData2Redis(instanceId, this.buildInstanceRuntimeData(jgMaintainNotice));
} 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