Commit 5eb3e947 authored by 王果's avatar 王果

21052 移装告知检验设备是否在流程中

parent 69eb8a3f
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.JgTransferNoticeDto; import com.yeejoin.amos.boot.module.jg.api.dto.JgTransferNoticeDto;
import com.yeejoin.amos.boot.module.jg.api.entity.JgTransferNotice; import com.yeejoin.amos.boot.module.jg.api.entity.JgTransferNotice;
import com.yeejoin.amos.boot.module.jg.api.vo.SortVo; import com.yeejoin.amos.boot.module.jg.api.vo.SortVo;
...@@ -26,4 +27,6 @@ public interface JgTransferNoticeMapper extends CustomBaseMapper<JgTransferNotic ...@@ -26,4 +27,6 @@ public interface JgTransferNoticeMapper extends CustomBaseMapper<JgTransferNotic
@MapKey("sequenceNbr") @MapKey("sequenceNbr")
List<Map<String, Object>> queryEquipInformation(@Param("sequenceNbr") long sequenceNbr); List<Map<String, Object>> queryEquipInformation(@Param("sequenceNbr") long sequenceNbr);
List<CompanyEquipCountDto> queryForFlowingEquipList();
} }
...@@ -217,4 +217,16 @@ ...@@ -217,4 +217,16 @@
tjtn.sequence_nbr = #{sequenceNbr} tjtn.sequence_nbr = #{sequenceNbr}
LIMIT 1 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_transfer_notice a,
tzs_jg_transfer_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>
...@@ -24,6 +24,9 @@ import com.yeejoin.amos.boot.module.jg.api.mapper.JgTransferNoticeMapper; ...@@ -24,6 +24,9 @@ import com.yeejoin.amos.boot.module.jg.api.mapper.JgTransferNoticeMapper;
import com.yeejoin.amos.boot.module.jg.api.mapper.JgUseRegistrationMapper; import com.yeejoin.amos.boot.module.jg.api.mapper.JgUseRegistrationMapper;
import com.yeejoin.amos.boot.module.jg.api.service.IJgTransferNoticeService; import com.yeejoin.amos.boot.module.jg.api.service.IJgTransferNoticeService;
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.ICmWorkflowService; import com.yeejoin.amos.boot.module.jg.biz.service.ICmWorkflowService;
import com.yeejoin.amos.boot.module.jg.biz.utils.WordTemplateUtils; import com.yeejoin.amos.boot.module.jg.biz.utils.WordTemplateUtils;
...@@ -141,7 +144,7 @@ public class JgTransferNoticeServiceImpl extends BaseService<JgTransferNoticeDto ...@@ -141,7 +144,7 @@ public class JgTransferNoticeServiceImpl extends BaseService<JgTransferNoticeDto
transferNotice.put("constructionContractList", ObjectUtils.isEmpty(transferNotice.get(s)) ? new JSONArray() : JSON.parseArray(transferNotice.get(s).toString())); transferNotice.put("constructionContractList", ObjectUtils.isEmpty(transferNotice.get(s)) ? new JSONArray() : JSON.parseArray(transferNotice.get(s).toString()));
} else if ("otherAccessories".equalsIgnoreCase(s)) { } else if ("otherAccessories".equalsIgnoreCase(s)) {
transferNotice.put("otherAccessoriesList", ObjectUtils.isEmpty(transferNotice.get(s)) ? new JSONArray() : JSON.parseArray(transferNotice.get(s).toString())); transferNotice.put("otherAccessoriesList", ObjectUtils.isEmpty(transferNotice.get(s)) ? new JSONArray() : JSON.parseArray(transferNotice.get(s).toString()));
}else { } else {
transferNotice.put(s, ObjectUtils.isEmpty(transferNotice.get(s)) ? new JSONArray() : JSON.parseArray(transferNotice.get(s).toString())); transferNotice.put(s, ObjectUtils.isEmpty(transferNotice.get(s)) ? new JSONArray() : JSON.parseArray(transferNotice.get(s).toString()));
} }
} }
...@@ -172,6 +175,39 @@ public class JgTransferNoticeServiceImpl extends BaseService<JgTransferNoticeDto ...@@ -172,6 +175,39 @@ public class JgTransferNoticeServiceImpl extends BaseService<JgTransferNoticeDto
} }
private void checkRepeatUsed(String submitType, JgTransferNotice notice) {
if (SUBMIT_TYPE_FLOW.equals(submitType)) {
// 流程中校验
LambdaQueryWrapper<JgTransferNoticeEq> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(JgTransferNoticeEq::getEquipTransferId, notice.getSequenceNbr());
JgTransferNoticeEq noticeEq = jgTransferNoticeEqMapper.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(JgTransferNotice notice) {
LambdaQueryWrapper<JgTransferNoticeEq> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(JgTransferNoticeEq::getEquipTransferId, notice.getSequenceNbr());
JgTransferNoticeEq noticeEq = jgTransferNoticeEqMapper.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 Map<String, Object> getEquipInfoNew(String companyLevel, Map<String, Object> transferNotice, List<Map<String, Object>> equipmentInfos) { private Map<String, Object> getEquipInfoNew(String companyLevel, Map<String, Object> transferNotice, List<Map<String, Object>> equipmentInfos) {
Map<String, Object> detail = equipmentInfos.get(0); Map<String, Object> detail = equipmentInfos.get(0);
Map<String, Object> equInfo = idxBizJgRegisterInfoService.getDetailFieldCamelCaseByRecord(detail.get("equId").toString()); Map<String, Object> equInfo = idxBizJgRegisterInfoService.getDetailFieldCamelCaseByRecord(detail.get("equId").toString());
...@@ -199,7 +235,7 @@ public class JgTransferNoticeServiceImpl extends BaseService<JgTransferNoticeDto ...@@ -199,7 +235,7 @@ public class JgTransferNoticeServiceImpl extends BaseService<JgTransferNoticeDto
for (Long sequenceNbr : sequenceNbrs) { for (Long sequenceNbr : sequenceNbrs) {
// 删除待办 及 中止流程 // 删除待办 及 中止流程
JgTransferNotice jgTransferNotice = this.getBaseMapper().selectById(sequenceNbr); JgTransferNotice jgTransferNotice = this.getBaseMapper().selectById(sequenceNbr);
commonService.deleteTaskModel(String.valueOf(sequenceNbr),jgTransferNotice.getInstanceId()); commonService.deleteTaskModel(String.valueOf(sequenceNbr), jgTransferNotice.getInstanceId());
// 删除业务单 // 删除业务单
this.getBaseMapper().deleteById(sequenceNbr); this.getBaseMapper().deleteById(sequenceNbr);
// 删除对应eq // 删除对应eq
...@@ -251,6 +287,7 @@ public class JgTransferNoticeServiceImpl extends BaseService<JgTransferNoticeDto ...@@ -251,6 +287,7 @@ public class JgTransferNoticeServiceImpl extends BaseService<JgTransferNoticeDto
@SuppressWarnings({"rawtypes", "Duplicates"}) @SuppressWarnings({"rawtypes", "Duplicates"})
@Transactional @Transactional
public JgTransferNoticeDto updateTransferNotice(String submitType, JgTransferNoticeDto noticeDto, String op) { public JgTransferNoticeDto updateTransferNotice(String submitType, JgTransferNoticeDto noticeDto, String op) {
try {
ReginParams reginParams = JSONObject.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId(), RequestContext.getToken())).toString(), ReginParams.class); ReginParams reginParams = JSONObject.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId(), RequestContext.getToken())).toString(), ReginParams.class);
if (Objects.isNull(noticeDto) || StringUtils.isEmpty(submitType)) { if (Objects.isNull(noticeDto) || StringUtils.isEmpty(submitType)) {
throw new IllegalArgumentException("参数不能为空"); throw new IllegalArgumentException("参数不能为空");
...@@ -258,8 +295,8 @@ public class JgTransferNoticeServiceImpl extends BaseService<JgTransferNoticeDto ...@@ -258,8 +295,8 @@ public class JgTransferNoticeServiceImpl extends BaseService<JgTransferNoticeDto
// 字段转换 // 字段转换
this.convertField(noticeDto); this.convertField(noticeDto);
noticeDto.setPromoter(reginParams.getUserModel().getUserId()); noticeDto.setPromoter(reginParams.getUserModel().getUserId());
JgTransferNotice notice = this.getById(noticeDto.getSequenceNbr()); JgTransferNotice notice = this.getById(noticeDto.getSequenceNbr());
this.checkRepeatUsed(submitType, notice);//校验设备是否在流程中
if (SUBMIT_TYPE_FLOW.equals(submitType)) { if (SUBMIT_TYPE_FLOW.equals(submitType)) {
if (!StringUtils.hasText(noticeDto.getInstanceId())) { if (!StringUtils.hasText(noticeDto.getInstanceId())) {
// 发起流程 // 发起流程
...@@ -360,17 +397,28 @@ public class JgTransferNoticeServiceImpl extends BaseService<JgTransferNoticeDto ...@@ -360,17 +397,28 @@ public class JgTransferNoticeServiceImpl extends BaseService<JgTransferNoticeDto
jgTransferNoticeMapper.updateById(bean); jgTransferNoticeMapper.updateById(bean);
} }
return noticeDto; 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();
}
} }
/** /**
* 分页查询 * 分页查询
*/ */
@Override @Override
public Page<Map<String,Object>> queryForJgTransferNoticePage(Page<JgTransferNotice> page,String sort, JgTransferNoticeDto model, String type, ReginParams reginParams) { public Page<Map<String, Object>> queryForJgTransferNoticePage(Page<JgTransferNotice> page, String sort, JgTransferNoticeDto model, String type, ReginParams reginParams) {
String orgCode = reginParams.getCompany().getCompanyCode(); String orgCode = reginParams.getCompany().getCompanyCode();
SortVo sortMap = commonService.sortFieldConversion(sort); SortVo sortMap = commonService.sortFieldConversion(sort);
model.setTransferToUserIds(reginParams.getUserModel().getUserId()); model.setTransferToUserIds(reginParams.getUserModel().getUserId());
Page<Map<String,Object>> noticePage = jgTransferNoticeMapper.queryForPage(page,sortMap, model, type, orgCode); Page<Map<String, Object>> noticePage = jgTransferNoticeMapper.queryForPage(page, sortMap, model, type, orgCode);
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);
...@@ -388,6 +436,7 @@ public class JgTransferNoticeServiceImpl extends BaseService<JgTransferNoticeDto ...@@ -388,6 +436,7 @@ public class JgTransferNoticeServiceImpl extends BaseService<JgTransferNoticeDto
@SuppressWarnings({"Duplicates", "rawtypes"}) @SuppressWarnings({"Duplicates", "rawtypes"})
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public List<JgTransferNotice> saveNotice(String submitType, Map<String, Object> jgTransferNoticeDtoMap, ReginParams reginParams) { public List<JgTransferNotice> saveNotice(String submitType, Map<String, Object> jgTransferNoticeDtoMap, ReginParams reginParams) {
try {
JgTransferNoticeDto model = JSON.parseObject(JSONObject.toJSONString(jgTransferNoticeDtoMap.get(TABLE_PAGE_ID)), JgTransferNoticeDto.class); JgTransferNoticeDto model = JSON.parseObject(JSONObject.toJSONString(jgTransferNoticeDtoMap.get(TABLE_PAGE_ID)), JgTransferNoticeDto.class);
// 字段转换 // 字段转换
convertField(model); convertField(model);
...@@ -396,6 +445,10 @@ public class JgTransferNoticeServiceImpl extends BaseService<JgTransferNoticeDto ...@@ -396,6 +445,10 @@ public class JgTransferNoticeServiceImpl extends BaseService<JgTransferNoticeDto
if (CollectionUtils.isEmpty(deviceList)) { if (CollectionUtils.isEmpty(deviceList)) {
return new ArrayList<>(); return new ArrayList<>();
} }
// 提交时对设备状态进行校验(处理并发问题,一个未被使用的设备同时被多个使用这打开,同时提交发起申请)
if (SUBMIT_TYPE_FLOW.equals(submitType)) {
this.repeatUsedEquipCheck(deviceList, reginParams.getCompany().getCompanyCode());
}
// 获取告知单号 // 获取告知单号
ResponseModel<List<String>> responseModel = tzsServiceFeignClient.applicationFormCode(ApplicationFormTypeEnum.YZGZ.getCode(), deviceList.size()); ResponseModel<List<String>> responseModel = tzsServiceFeignClient.applicationFormCode(ApplicationFormTypeEnum.YZGZ.getCode(), deviceList.size());
if (CollectionUtils.isEmpty(responseModel.getResult())) { if (CollectionUtils.isEmpty(responseModel.getResult())) {
...@@ -423,6 +476,17 @@ public class JgTransferNoticeServiceImpl extends BaseService<JgTransferNoticeDto ...@@ -423,6 +476,17 @@ public class JgTransferNoticeServiceImpl extends BaseService<JgTransferNoticeDto
jgTransferNoticeEqMapper.insertBatchSomeColumn(jgRelationEquipList); jgTransferNoticeEqMapper.insertBatchSomeColumn(jgRelationEquipList);
this.updateRedisBatch(list); this.updateRedisBatch(list);
return 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<JgTransferNotice> jgTransferNotices) { private void updateRedisBatch(List<JgTransferNotice> jgTransferNotices) {
...@@ -685,6 +749,7 @@ public class JgTransferNoticeServiceImpl extends BaseService<JgTransferNoticeDto ...@@ -685,6 +749,7 @@ public class JgTransferNoticeServiceImpl extends BaseService<JgTransferNoticeDto
jsonObject.put("nextTaskId", jgTransferNotice.getNextTaskId()); jsonObject.put("nextTaskId", jgTransferNotice.getNextTaskId());
commonService.rollbackTask(jgTransferNotice.getInstanceId(), jsonObject); commonService.rollbackTask(jgTransferNotice.getInstanceId(), jsonObject);
commonService.saveExecuteFlowData2Redis(instanceId, this.buildInstanceRuntimeData(jgTransferNotice)); commonService.saveExecuteFlowData2Redis(instanceId, this.buildInstanceRuntimeData(jgTransferNotice));
this.delRepeatUseEquipData(jgTransferNotice);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
......
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 com.yeejoin.amos.boot.module.jg.api.mapper.JgTransferNoticeMapper;
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 TransferNoticeEquipUsedCheckImpl extends BaseEquipUsedCheckService {
private RedissonClient redissonClient;
private String bizType = "transferNotice";
private JgTransferNoticeMapper noticeMapper;
public TransferNoticeEquipUsedCheckImpl(RedissonClient redissonClient, JgTransferNoticeMapper noticeMapper) {
this.redissonClient = redissonClient;
this.noticeMapper = noticeMapper;
}
@Override
public RedissonClient getRedisClient() {
return redissonClient;
}
@Override
public String getApplyBizType() {
return bizType;
}
@Override
public void init() {
// 初始化已经完成或者在流程中安装告知的设备数据
List<CompanyEquipCountDto> companyEquipCountDtos = noticeMapper.queryForFlowingEquipList();
companyEquipCountDtos.forEach(c -> {
RBucket<Set<String>> rBucket = redissonClient.getBucket(getFlowingEquipRedisKey(c.getCompanyCode(), bizType));
rBucket.set(Arrays.stream(c.getRecords().split(",")).collect(Collectors.toSet()));
});
}
}
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
"name": "移装告知", "name": "移装告知",
"code": "GZ_YZ", "code": "GZ_YZ",
"image": "upload/tzs/common/image/移装告知.png", "image": "upload/tzs/common/image/移装告知.png",
"disabled": true "disabled": false
} }
], ],
"DJGL": [ "DJGL": [
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
"name": "移装变更登记", "name": "移装变更登记",
"code": "DJ_YZ", "code": "DJ_YZ",
"image": "upload/tzs/common/image/移装变更登记.png", "image": "upload/tzs/common/image/移装变更登记.png",
"disabled": true "disabled": false
}, },
{ {
"name": "单位变更登记", "name": "单位变更登记",
...@@ -88,16 +88,16 @@ ...@@ -88,16 +88,16 @@
"image": "upload/tzs/common/image/注销报废.png" "image": "upload/tzs/common/image/注销报废.png"
}, },
{ {
"name": "设备启用", "name": "启用",
"code": "SB_QY", "code": "SB_QY",
"image": "upload/tzs/common/image/设备启用.png", "image": "upload/tzs/common/image/设备启用.png",
"disabled": true "disabled": false
}, },
{ {
"name": "设备停用", "name": "停用",
"code": "SB_TY", "code": "SB_TY",
"image": "upload/tzs/common/image/设备停用.png", "image": "upload/tzs/common/image/设备停用.png",
"disabled": true "disabled": false
} }
], ],
"XZSB": [ "XZSB": [
......
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