|
|
|
@ -1,13 +1,15 @@
|
|
|
|
|
package com.hnac.hzims.operational.defect.service.impl; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.alibaba.fastjson.TypeReference; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.hnac.hzims.common.flow.StartProcessService; |
|
|
|
|
import com.hnac.hzims.common.logs.utils.StringUtils; |
|
|
|
|
import com.hnac.hzims.middle.process.feign.ICompensateProcessClient; |
|
|
|
|
import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; |
|
|
|
|
import com.hnac.hzims.operational.defect.constants.TreatMethodConstant; |
|
|
|
|
import com.hnac.hzims.operational.defect.entity.OperAppearanceEntity; |
|
|
|
@ -33,8 +35,6 @@ import org.springblade.core.tool.utils.BeanUtil;
|
|
|
|
|
import org.springblade.core.tool.utils.DateUtil; |
|
|
|
|
import org.springblade.core.tool.utils.Func; |
|
|
|
|
import org.springblade.core.tool.utils.ObjectUtil; |
|
|
|
|
import org.springblade.flow.core.entity.BladeFlow; |
|
|
|
|
import org.springblade.flow.core.feign.IFlowClient; |
|
|
|
|
import org.springblade.flow.core.utils.FlowUtil; |
|
|
|
|
import org.springblade.message.MessageConstants; |
|
|
|
|
import org.springblade.message.dto.BusinessMessageDTO; |
|
|
|
@ -47,7 +47,10 @@ import org.springblade.system.user.feign.IUserClient;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
import org.springframework.transaction.PlatformTransactionManager; |
|
|
|
|
import org.springframework.transaction.TransactionStatus; |
|
|
|
|
import org.springframework.transaction.support.TransactionCallbackWithoutResult; |
|
|
|
|
import org.springframework.transaction.support.TransactionTemplate; |
|
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
|
import java.beans.BeanInfo; |
|
|
|
@ -69,7 +72,7 @@ import java.util.concurrent.TimeUnit;
|
|
|
|
|
@Service |
|
|
|
|
@Slf4j |
|
|
|
|
@RequiredArgsConstructor |
|
|
|
|
public class DefectCheckServiceImpl extends ServiceImpl<OperPhenomenonMapper, OperPhenomenonEntity> implements IDefectCheckService { |
|
|
|
|
public class DefectCheckServiceImpl extends ServiceImpl<OperPhenomenonMapper, OperPhenomenonEntity> implements IDefectCheckService , StartProcessService { |
|
|
|
|
|
|
|
|
|
private final IOperDefectService defectService; |
|
|
|
|
|
|
|
|
@ -79,13 +82,15 @@ public class DefectCheckServiceImpl extends ServiceImpl<OperPhenomenonMapper, Op
|
|
|
|
|
|
|
|
|
|
private final ISysClient sysClient; |
|
|
|
|
private final IUserClient userClient; |
|
|
|
|
@Autowired |
|
|
|
|
private RedisTemplate redisTemplate; |
|
|
|
|
|
|
|
|
|
private final RedisTemplate redisTemplate; |
|
|
|
|
private final IStationClient stationClient; |
|
|
|
|
private final IFlowClient processClient; |
|
|
|
|
// private final IFlowClient processClient;
|
|
|
|
|
|
|
|
|
|
private final IMessageClient messageClient; |
|
|
|
|
|
|
|
|
|
private final ICompensateProcessClient compensateProcessClient; |
|
|
|
|
private final PlatformTransactionManager transactionManager; |
|
|
|
|
private final TransactionTemplate transactionTemplate; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 保存现象、开启缺陷处理流程 |
|
|
|
@ -94,8 +99,7 @@ public class DefectCheckServiceImpl extends ServiceImpl<OperPhenomenonMapper, Op
|
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public OperPhenomenonEntity startCheck(OperPhenomenonEntity entity) { |
|
|
|
|
public R startCheck(OperPhenomenonEntity entity) { |
|
|
|
|
if (ObjectUtil.isEmpty(entity.getCreateDept())) { |
|
|
|
|
throw new ServiceException("获取缺陷所属机构失败!"); |
|
|
|
|
} |
|
|
|
@ -108,26 +112,29 @@ public class DefectCheckServiceImpl extends ServiceImpl<OperPhenomenonMapper, Op
|
|
|
|
|
if (StringUtils.isNotBlank(AuthUtil.getNickName())){ |
|
|
|
|
entity.setCreateUserName(AuthUtil.getNickName()); |
|
|
|
|
} |
|
|
|
|
R r=new R(); |
|
|
|
|
//加锁
|
|
|
|
|
Boolean lock = redisTemplate.opsForValue().setIfAbsent("SysUserLock" + entity.getCreateDept(), entity.getCreateDept(), 30, TimeUnit.SECONDS); |
|
|
|
|
try { |
|
|
|
|
if (lock) { |
|
|
|
|
// 步骤1.保存现象
|
|
|
|
|
if (!this.savePhenomenon(entity)) { |
|
|
|
|
throw new ServiceException("保存现象失败!"); |
|
|
|
|
} |
|
|
|
|
// 步骤2.开启缺陷流程
|
|
|
|
|
OperPhenomenonEntity operPhenomenon = this.getOne(new LambdaQueryWrapper<OperPhenomenonEntity>() {{ |
|
|
|
|
eq(OperPhenomenonEntity::getDefectCode, entity.getDefectCode()); |
|
|
|
|
last("limit 1"); |
|
|
|
|
}}); |
|
|
|
|
this.startDefectCheckV2(operPhenomenon); |
|
|
|
|
String saved = saveEntity(JSONObject.toJSONString(entity)); |
|
|
|
|
// if (!this.savePhenomenon(entity)) {
|
|
|
|
|
// throw new ServiceException("保存现象失败!");
|
|
|
|
|
// }
|
|
|
|
|
// // 步骤2.开启缺陷流程
|
|
|
|
|
// OperPhenomenonEntity operPhenomenon = this.getOne(new LambdaQueryWrapper<OperPhenomenonEntity>() {{
|
|
|
|
|
// eq(OperPhenomenonEntity::getDefectCode, entity.getDefectCode());
|
|
|
|
|
// last("limit 1");
|
|
|
|
|
// }});
|
|
|
|
|
// this.startDefectCheckV2(operPhenomenon);
|
|
|
|
|
r= this.startProcess(saved, TreatMethodConstant.DEFECT_CHECK,null); |
|
|
|
|
redisTemplate.delete("SysUserLock" + entity.getCreateDept()); //删除key,释放锁
|
|
|
|
|
} else { |
|
|
|
|
// 加锁失败,抛出异常
|
|
|
|
|
throw new ServiceException("开启现象流程失败!"); |
|
|
|
|
} |
|
|
|
|
return entity; |
|
|
|
|
return r ; |
|
|
|
|
}catch (Exception e){ |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
log.error("保存现象失败!"+e); |
|
|
|
@ -138,13 +145,9 @@ public class DefectCheckServiceImpl extends ServiceImpl<OperPhenomenonMapper, Op
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 保存现象 |
|
|
|
|
* |
|
|
|
|
* @param entity |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private boolean savePhenomenon(OperPhenomenonEntity entity) { |
|
|
|
|
@Override |
|
|
|
|
public String saveEntity(String entityString) { |
|
|
|
|
OperPhenomenonEntity entity= JSONObject.parseObject(entityString, OperPhenomenonEntity.class); |
|
|
|
|
String deptId = entity.getCreateDept().toString(); |
|
|
|
|
if (StringUtils.isBlank(deptId)) { |
|
|
|
|
throw new ServiceException("获取当前用户机构失败!"); |
|
|
|
@ -193,26 +196,32 @@ public class DefectCheckServiceImpl extends ServiceImpl<OperPhenomenonMapper, Op
|
|
|
|
|
// Date discriminateDeadline = DateUtil.plusHours(entity.getUpdateTime(), DefectConfiguration.discriminateDeadline);
|
|
|
|
|
// entity.setDiscriminateDeadline(discriminateDeadline);
|
|
|
|
|
// 最后甄别时间字段弃用
|
|
|
|
|
return this.save(entity); |
|
|
|
|
|
|
|
|
|
//保存的时候单独增加事务,不妨碍其他
|
|
|
|
|
transactionTemplate.setTransactionManager(transactionManager); |
|
|
|
|
transactionTemplate.execute(new TransactionCallbackWithoutResult() { |
|
|
|
|
@Override |
|
|
|
|
public void doInTransactionWithoutResult(TransactionStatus status) { |
|
|
|
|
// 在这里执行需要事务控制的代码
|
|
|
|
|
boolean save = save(entity); |
|
|
|
|
if (!save){ |
|
|
|
|
throw new ServiceException("保存业务表单失败,请稍后重试!"); |
|
|
|
|
} |
|
|
|
|
//新增缺陷流程记录
|
|
|
|
|
OperDefectStatisticsEntity operDefectStatisticsEntity = new OperDefectStatisticsEntity(); |
|
|
|
|
BeanUtil.copy(entity, operDefectStatisticsEntity); |
|
|
|
|
statisticsService.save(operDefectStatisticsEntity); |
|
|
|
|
//新增现象记录
|
|
|
|
|
OperAppearanceEntity operAppearanceEntity = new OperAppearanceEntity(); |
|
|
|
|
BeanUtil.copy(entity, operAppearanceEntity); |
|
|
|
|
operAppearanceService.save(operAppearanceEntity); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
return JSONObject.toJSONString(entity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 启动缺陷处理流程 |
|
|
|
|
* |
|
|
|
|
* @param entity |
|
|
|
|
*/ |
|
|
|
|
private void startDefectCheckV2(OperPhenomenonEntity entity) { |
|
|
|
|
//新增缺陷流程记录
|
|
|
|
|
OperDefectStatisticsEntity operDefectStatisticsEntity = new OperDefectStatisticsEntity(); |
|
|
|
|
BeanUtil.copy(entity, operDefectStatisticsEntity); |
|
|
|
|
statisticsService.save(operDefectStatisticsEntity); |
|
|
|
|
|
|
|
|
|
//新增现象记录
|
|
|
|
|
OperAppearanceEntity operAppearanceEntity = new OperAppearanceEntity(); |
|
|
|
|
BeanUtil.copy(entity, operAppearanceEntity); |
|
|
|
|
operAppearanceService.save(operAppearanceEntity); |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R startProcess(String entityString, String dictValue,String param) { |
|
|
|
|
OperPhenomenonEntity entity= JSONObject.parseObject(entityString, OperPhenomenonEntity.class); |
|
|
|
|
// 现象发起人名字
|
|
|
|
|
String userName = Optional.ofNullable(AuthUtil.getUserName()).orElse(""); |
|
|
|
|
// 现象发起来源
|
|
|
|
@ -221,20 +230,40 @@ public class DefectCheckServiceImpl extends ServiceImpl<OperPhenomenonMapper, Op
|
|
|
|
|
String processName = "[" + userName + "] 发起 " + "【" + sourceName + "】缺陷处理流程" + "——>" + entity.getFaultName(); |
|
|
|
|
// 开启新的缺陷流程
|
|
|
|
|
String businessKey = FlowUtil.getBusinessKey("hzims_oper_phenomenon", "" + entity.getId()); |
|
|
|
|
Map<String, Object> variable = JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(entity,DateUtil.PATTERN_DATETIME), Map.class); |
|
|
|
|
// variables.put("creator", TaskUtil.getTaskUser(String.valueOf(AuthUtil.getUserId())));
|
|
|
|
|
R<BladeFlow> result = processClient.startProcessInstanceContainNameByKey(TreatMethodConstant.DEFECT_CHECK, businessKey, processName, variable); |
|
|
|
|
Map<String, Object> variables =new HashMap<>(); |
|
|
|
|
if (StringUtils.isNotBlank(param)){ |
|
|
|
|
variables=JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(param,DateUtil.PATTERN_DATETIME), Map.class); |
|
|
|
|
}else { |
|
|
|
|
variables = JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(entity, DateUtil.PATTERN_DATETIME), Map.class); |
|
|
|
|
} |
|
|
|
|
R result = compensateProcessClient.startFlow(AuthUtil.getUserId().toString(), dictValue, businessKey, processName, variables); |
|
|
|
|
// R<BladeFlow> result = processClient.startProcessInstanceContainNameByKey( dictValue,businessKey, processName, variable);
|
|
|
|
|
// 流程开启失败
|
|
|
|
|
if (!result.isSuccess()) { |
|
|
|
|
throw new ServiceException("缺陷流程开启失败,错误描述 : " + result.getMsg()); |
|
|
|
|
if (200!=result.getCode()) { |
|
|
|
|
entity.setIsNormal(false); |
|
|
|
|
entity.setRemark(JSONObject.toJSONString(variables)); |
|
|
|
|
this.baseMapper.updateById(entity); |
|
|
|
|
log.error("缺陷流程开启失败,错误描述 : " + result.getMsg()); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
// 关联流程唯一键
|
|
|
|
|
entity.setCheckProcessInstanceId(result.getData().getProcessInstanceId()); |
|
|
|
|
operDefectStatisticsEntity.setCheckProcessInstanceId(result.getData().getProcessInstanceId()); |
|
|
|
|
entity.setIsNormal(true); |
|
|
|
|
entity.setCheckProcessInstanceId(result.getData().toString()); |
|
|
|
|
OperDefectStatisticsEntity operDefectStatisticsEntity = new OperDefectStatisticsEntity(); |
|
|
|
|
BeanUtil.copy(entity, operDefectStatisticsEntity); |
|
|
|
|
operDefectStatisticsEntity.setCheckProcessInstanceId(result.getData().toString()); |
|
|
|
|
this.baseMapper.updateById(entity); |
|
|
|
|
statisticsService.updateById(operDefectStatisticsEntity); |
|
|
|
|
return R.success("启动流程成功"); |
|
|
|
|
} |
|
|
|
|
@Override |
|
|
|
|
public R compensationProcess(String id){ |
|
|
|
|
OperPhenomenonEntity operPhenomenonEntity = this.baseMapper.selectById(id); |
|
|
|
|
if (ObjectUtils.isNotEmpty(operPhenomenonEntity)){ |
|
|
|
|
return this.startProcess(JSON.toJSONString(operPhenomenonEntity), TreatMethodConstant.DEFECT_CHECK,operPhenomenonEntity.getRemark()); |
|
|
|
|
} |
|
|
|
|
return R.fail("找不到对应流程数据,请稍后重试!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 实体类转换成map |
|
|
|
|
* |
|
|
|
@ -348,6 +377,14 @@ public class DefectCheckServiceImpl extends ServiceImpl<OperPhenomenonMapper, Op
|
|
|
|
|
log.info("缺陷ID:" + operPhenomenonEntity.getDefectCode() + "入库成功"); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
//流程找不到下一个审批人处理
|
|
|
|
|
if(700==processWorkFlowResponse.getCode()){ |
|
|
|
|
operPhenomenonEntity.setIsNormal(false); |
|
|
|
|
operPhenomenonEntity.setRemark(JSONObject.toJSONString(processWorkFlowResponse.getVariables())); |
|
|
|
|
}else { |
|
|
|
|
//推送消息中心相关消息
|
|
|
|
|
sendMessage(processWorkFlowResponse, operPhenomenonEntity,taskId); |
|
|
|
|
} |
|
|
|
|
//更新数据库
|
|
|
|
|
Long statisticsEntityId = statisticsEntity.getId(); |
|
|
|
|
Long appearanceEntityId = appearanceEntity.getId(); |
|
|
|
@ -360,8 +397,6 @@ public class DefectCheckServiceImpl extends ServiceImpl<OperPhenomenonMapper, Op
|
|
|
|
|
}}); |
|
|
|
|
statisticsService.updateById(statisticsEntity); |
|
|
|
|
operAppearanceService.updateById(appearanceEntity); |
|
|
|
|
//推送消息中心相关消息
|
|
|
|
|
sendMessage(processWorkFlowResponse, operPhenomenonEntity,taskId); |
|
|
|
|
log.info("消缺消息转换结束"+processWorkFlowResponse); |
|
|
|
|
return R.success("消息保存成功"); |
|
|
|
|
} |
|
|
|
@ -421,4 +456,5 @@ public class DefectCheckServiceImpl extends ServiceImpl<OperPhenomenonMapper, Op
|
|
|
|
|
} |
|
|
|
|
return solve; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |