Browse Source

修改:工作流补偿

zhongwei
ty 5 months ago
parent
commit
c30bc7dd23
  1. 32
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskSchedule.java
  2. 30
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceServiceImpl.java
  3. 61
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/flow/service/impl/InnerDangerFlowServiceImpl.java
  4. 56
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/repair/service/impl/WorkTaskServiceImpl.java
  5. 71
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/impl/OperationTicketServiceImpl.java
  6. 79
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java
  7. 4
      hzims-service/ticket/src/main/resources/db/3.0.0.sql

32
hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskSchedule.java

@ -1,12 +1,17 @@
package com.hnac.hzims.operational.maintenance.scheduled; package com.hnac.hzims.operational.maintenance.scheduled;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hnac.hzims.alarm.config.constants.AlarmHandleConstant;
import com.hnac.hzims.alarm.config.entity.AlarmHandleFlowEntity;
import com.hnac.hzims.common.flow.StartProcessService; import com.hnac.hzims.common.flow.StartProcessService;
import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.common.logs.utils.StringUtils;
import com.hnac.hzims.equipment.entity.EmInfoEntity; import com.hnac.hzims.equipment.entity.EmInfoEntity;
import com.hnac.hzims.equipment.feign.IEmInfoClient; import com.hnac.hzims.equipment.feign.IEmInfoClient;
import com.hnac.hzims.middle.process.feign.ICompensateProcessClient;
import com.hnac.hzims.operational.constants.FlowKeyConstants; import com.hnac.hzims.operational.constants.FlowKeyConstants;
import com.hnac.hzims.operational.constants.RedisKeyConstants; import com.hnac.hzims.operational.constants.RedisKeyConstants;
import com.hnac.hzims.operational.duty.entity.ImsDutyMainEntity; import com.hnac.hzims.operational.duty.entity.ImsDutyMainEntity;
@ -28,6 +33,7 @@ import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.*; import org.springblade.core.tool.utils.*;
import org.springblade.flow.core.entity.BladeFlow; import org.springblade.flow.core.entity.BladeFlow;
import org.springblade.flow.core.feign.IFlowClient; import org.springblade.flow.core.feign.IFlowClient;
import org.springblade.flow.core.utils.FlowUtil;
import org.springblade.system.user.cache.UserCache; import org.springblade.system.user.cache.UserCache;
import org.springblade.system.user.entity.User; import org.springblade.system.user.entity.User;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
@ -41,6 +47,7 @@ import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import static com.hnac.hzims.operational.constants.FlowKeyConstants.MAINTENANCE_TASK_FLOW_KEY;
import static com.hnac.hzims.operational.maintenance.constants.ScheduledConstant.GENERATE_MAINTENANCE_TASK_SCHEDULE; import static com.hnac.hzims.operational.maintenance.constants.ScheduledConstant.GENERATE_MAINTENANCE_TASK_SCHEDULE;
/** /**
@ -57,6 +64,7 @@ public class MaintenanceTaskSchedule implements StartProcessService {
private final IImsDutyMainService dutyMainService; private final IImsDutyMainService dutyMainService;
private final RedisTemplate redisTemplate; private final RedisTemplate redisTemplate;
private final IEmInfoClient emInfoClient; private final IEmInfoClient emInfoClient;
private final ICompensateProcessClient compensateProcessClient;
@XxlJob(GENERATE_MAINTENANCE_TASK_SCHEDULE) @XxlJob(GENERATE_MAINTENANCE_TASK_SCHEDULE)
public ReturnT<String> execute(String param) throws Exception { public ReturnT<String> execute(String param) throws Exception {
@ -173,10 +181,11 @@ public class MaintenanceTaskSchedule implements StartProcessService {
*/ */
private void startProcessInstance(OperMaintenanceTaskEntity task) { private void startProcessInstance(OperMaintenanceTaskEntity task) {
String s = saveEntity(JSONObject.toJSONString(task)); String s = saveEntity(JSONObject.toJSONString(task));
startProcess(s,FlowKeyConstants.MAINTENANCE_TASK_FLOW_KEY,null); startProcess(s, MAINTENANCE_TASK_FLOW_KEY,null);
} }
@Override @Override
//没有保存多张表,不单独开启事务
public String saveEntity(String entity) { public String saveEntity(String entity) {
return entity; return entity;
} }
@ -202,8 +211,13 @@ public class MaintenanceTaskSchedule implements StartProcessService {
}); });
put("operMaintenanceTaskEntityVo",vo); put("operMaintenanceTaskEntityVo",vo);
}}; }};
R<BladeFlow> flowResult = flowClient.startProcessInstanceContainNameByKey(dictValue, String.valueOf(task.getId()), task.getTitle(), params); if (StringUtils.isNotBlank(param)){
if (!flowResult.isSuccess()){ params=JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(param,DateUtil.PATTERN_DATETIME), Map.class);
}
String businessKey = FlowUtil.getBusinessKey("hzims_oper_maintenance_task", "" +task.getId());
R flowResult = compensateProcessClient.startFlow(AuthUtil.getUserId().toString(), dictValue, businessKey, task.getTitle(), params);
// R<BladeFlow> flowResult = flowClient.startProcessInstanceContainNameByKey(dictValue, String.valueOf(task.getId()), task.getTitle(), params);
if (200!=flowResult.getCode()){
task.setIsNormal(false); task.setIsNormal(false);
task.setRemark(JSONObject.toJSONString(params)); task.setRemark(JSONObject.toJSONString(params));
taskService.updateById(task); taskService.updateById(task);
@ -213,14 +227,22 @@ public class MaintenanceTaskSchedule implements StartProcessService {
r.setData(params); r.setData(params);
log.error(task.getId()+"日常维护任务启动流程失败{}", task); log.error(task.getId()+"日常维护任务启动流程失败{}", task);
return r; return r;
}else {
task.setIsNormal(true);
task.setProcessInstanceId(flowResult.getData().toString());
taskService.updateById(task);
} }
String s = Optional.ofNullable(flowResult).filter(r -> r.isSuccess()).map(R::getData).map(BladeFlow::getProcessInstanceId).orElse(null); String s = flowResult.getData().toString();
log.info(task.getId()+"日常维护任务启动成功{}", s); log.info(task.getId()+"日常维护任务启动成功{}", s);
return R.success("启动流程成功"); return R.success("启动流程成功");
} }
@Override @Override
public R compensationProcess(String id) { public R compensationProcess(String id) {
return null; OperMaintenanceTaskEntity operMaintenanceTaskEntity = taskService.getById(id);
if (ObjectUtils.isNotEmpty(operMaintenanceTaskEntity)){
return this.startProcess(JSON.toJSONString(operMaintenanceTaskEntity), MAINTENANCE_TASK_FLOW_KEY,operMaintenanceTaskEntity.getRemark());
}
return R.fail("找不到对应流程数据,请稍后重试!");
} }
} }

30
hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceServiceImpl.java

@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.common.logs.utils.StringUtils;
import com.hnac.hzims.common.utils.DateUtil; import com.hnac.hzims.common.utils.DateUtil;
import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse;
import com.hnac.hzims.operational.access.entity.OperAccessPlanEntity;
import com.hnac.hzims.operational.duty.entity.ImsDutyMainEntity; import com.hnac.hzims.operational.duty.entity.ImsDutyMainEntity;
import com.hnac.hzims.operational.duty.service.IImsDutyMainService; import com.hnac.hzims.operational.duty.service.IImsDutyMainService;
import com.hnac.hzims.operational.maintenance.entity.OperMaintenancePlanEntity; import com.hnac.hzims.operational.maintenance.entity.OperMaintenancePlanEntity;
@ -125,12 +126,17 @@ public class MaintenanceServiceImpl implements MaintenanceService {
log.error("获取表单出现异常了~~~~"+response); log.error("获取表单出现异常了~~~~"+response);
throw new IllegalArgumentException(e.getMessage()); throw new IllegalArgumentException(e.getMessage());
} }
if(ObjectUtils.isNotEmpty(response.getCode())&&700==response.getCode()){
handException(response);
return;
}
OperMaintenanceTaskEntity entity = new OperMaintenanceTaskEntity(); OperMaintenanceTaskEntity entity = new OperMaintenanceTaskEntity();
BeanUtils.copyProperties(standardTicketInfoVo, entity); BeanUtils.copyProperties(standardTicketInfoVo, entity);
//1.查询日常维护信息 //1.查询日常维护信息
//有Id才进行生成操作 //有Id才进行生成操作
if (StringUtils.isNotBlank(response.getBusinessKey())) { if (StringUtils.isNotBlank(response.getBusinessKey())) {
Long id = NumberUtils.toLong(response.getBusinessKey()); String str = response.getBusinessKey().split(":")[1];
Long id = NumberUtils.toLong(str);
OperMaintenanceTaskEntity dbOperMaintenanceTaskEntity = taskService.getById(id); OperMaintenanceTaskEntity dbOperMaintenanceTaskEntity = taskService.getById(id);
if (ObjectUtils.isEmpty(dbOperMaintenanceTaskEntity)) { if (ObjectUtils.isEmpty(dbOperMaintenanceTaskEntity)) {
log.error("获取日常维护数据不存在" + response); log.error("获取日常维护数据不存在" + response);
@ -178,6 +184,28 @@ public class MaintenanceServiceImpl implements MaintenanceService {
} }
} }
private R handException(ProcessWorkFlowResponse response) {
String[] split = response.getBusinessKey().split(":");
if (StringUtils.isBlank(split[1])){
log.error("异常消息转换失败,未找到BusinessKey:"+ response);
return R.fail("异常消息处理失败");
}
OperMaintenanceTaskEntity entity = taskService.getOne(new LambdaQueryWrapper<OperMaintenanceTaskEntity>() {{
eq(OperMaintenanceTaskEntity::getId, split[1]);
}});
entity.setIsNormal(false);
entity.setRemark(JSONObject.toJSONString(response.getVariables()));
entity.setFlowTaskName(response.getTaskName());
entity.setProcessInstanceId(response.getTaskId());
entity.setNextStepOperator("");
boolean flag = taskService.updateById(entity);
if (!flag){
log.info("异常状态消息保存失败"+ response);
return R.success("消息保存失败");
}
return R.fail("消息保存成功");
}
/** /**
* 填充日常维护信息 * 填充日常维护信息

61
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/flow/service/impl/InnerDangerFlowServiceImpl.java

@ -13,7 +13,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnac.hzims.common.flow.StartProcessService; import com.hnac.hzims.common.flow.StartProcessService;
import com.hnac.hzims.common.logs.utils.StringUtils; 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.middle.process.to.ProcessWorkFlowResponse;
import com.hnac.hzims.operational.access.entity.OperAccessPlanEntity;
import com.hnac.hzims.safeproduct.dto.InnerDangerDTO; import com.hnac.hzims.safeproduct.dto.InnerDangerDTO;
import com.hnac.hzims.safeproduct.entity.InnerDangerEntity; import com.hnac.hzims.safeproduct.entity.InnerDangerEntity;
import com.hnac.hzims.safeproduct.flow.mapper.InnerDangerMapper; import com.hnac.hzims.safeproduct.flow.mapper.InnerDangerMapper;
@ -31,6 +33,7 @@ import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.Func;
import org.springblade.flow.core.entity.BladeFlow; import org.springblade.flow.core.entity.BladeFlow;
import org.springblade.flow.core.feign.IFlowClient; import org.springblade.flow.core.feign.IFlowClient;
import org.springblade.flow.core.utils.FlowUtil;
import org.springblade.message.dto.BusinessMessageDTO; import org.springblade.message.dto.BusinessMessageDTO;
import org.springblade.message.fegin.IMessageClient; import org.springblade.message.fegin.IMessageClient;
import org.springblade.system.feign.ISysClient; import org.springblade.system.feign.ISysClient;
@ -61,6 +64,8 @@ public class InnerDangerFlowServiceImpl extends ServiceImpl<InnerDangerMapper, I
@Autowired @Autowired
private IMessageClient messageClient; private IMessageClient messageClient;
@Autowired
private ICompensateProcessClient compensateProcessClient;
@ -73,7 +78,7 @@ public class InnerDangerFlowServiceImpl extends ServiceImpl<InnerDangerMapper, I
@Override @Override
public R startHiddenDanger(InnerDangerVo hiddenDangerVo) { public R startHiddenDanger(InnerDangerVo hiddenDangerVo) {
String saved = saveEntity(JSONObject.toJSONString(hiddenDangerVo)); String saved = saveEntity(JSONObject.toJSONString(hiddenDangerVo));
R r = this.startProcess(saved, HIDDEN_DANGER_CHECK); R r = this.startProcess(saved, HIDDEN_DANGER_CHECK,null);
return r; return r;
} }
@Override @Override
@ -104,6 +109,7 @@ public class InnerDangerFlowServiceImpl extends ServiceImpl<InnerDangerMapper, I
innerDangerEntity.setHiddenDangerDeptName(deptNameR.getData()); innerDangerEntity.setHiddenDangerDeptName(deptNameR.getData());
} }
} }
//只有一张表,不使用事务
boolean save = this.save(innerDangerEntity); boolean save = this.save(innerDangerEntity);
if (!save) { if (!save) {
throw new ServiceException("隐患保存失败,请稍后重试!"); throw new ServiceException("隐患保存失败,请稍后重试!");
@ -114,15 +120,6 @@ public class InnerDangerFlowServiceImpl extends ServiceImpl<InnerDangerMapper, I
@Override @Override
public R startProcess(String entity, String dictValue, String param) { public R startProcess(String entity, String dictValue, String param) {
return null;
}
@Override
public R compensationProcess(String id) {
return null;
}
public R startProcess(String entity, String dictValue) {
InnerDangerVo innerDangerVo= JSONObject.parseObject(entity, InnerDangerVo.class); InnerDangerVo innerDangerVo= JSONObject.parseObject(entity, InnerDangerVo.class);
InnerDangerEntity innerDangerEntity = new InnerDangerEntity(); InnerDangerEntity innerDangerEntity = new InnerDangerEntity();
BeanUtil.copy(innerDangerVo, innerDangerEntity); BeanUtil.copy(innerDangerVo, innerDangerEntity);
@ -132,12 +129,14 @@ public class InnerDangerFlowServiceImpl extends ServiceImpl<InnerDangerMapper, I
String processName = "[" + userName + "] 发起 " + "【风险点:" + innerDangerVo.getRiskPointName() + "】隐患处理流程" + "——>" + innerDangerEntity.getHiddenDangerName(); String processName = "[" + userName + "] 发起 " + "【风险点:" + innerDangerVo.getRiskPointName() + "】隐患处理流程" + "——>" + innerDangerEntity.getHiddenDangerName();
// 开启新的隐患处理流程 // 开启新的隐患处理流程
Map<String, Object> variable = JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(innerDangerVo, DateUtil.PATTERN_DATETIME), Map.class); Map<String, Object> variable = JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(innerDangerVo, DateUtil.PATTERN_DATETIME), Map.class);
R<BladeFlow> result = processClient.startProcessInstanceContainNameByKey(dictValue, innerDangerVo.getId().toString(), processName, variable); R result = compensateProcessClient.startFlow(AuthUtil.getUserId().toString(),
dictValue, FlowUtil.getBusinessKey("hzims_inner_danger_info", String.valueOf(innerDangerVo.getId())),
processName, variable);
// 流程开启失败 // 流程开启失败
if (!result.isSuccess()) { if (200!=result.getCode()) {
innerDangerEntity.setIsNormal(false); innerDangerEntity.setIsNormal(false);
innerDangerEntity.setRemark(JSONObject.toJSONString(variable)); innerDangerEntity.setRemark(JSONObject.toJSONString(variable));
this.baseMapper.updateById(innerDangerVo); this.baseMapper.updateById(innerDangerEntity);
log.error("隐患处理流程开启失败,错误描述 : {}", result); log.error("隐患处理流程开启失败,错误描述 : {}", result);
R r=new R(); R r=new R();
r.setCode(result.getCode()); r.setCode(result.getCode());
@ -146,19 +145,28 @@ public class InnerDangerFlowServiceImpl extends ServiceImpl<InnerDangerMapper, I
return r; return r;
} else { } else {
// 关联流程唯一键 // 关联流程唯一键
innerDangerEntity.setProcessInstanceId(result.getData().getProcessInstanceId()); innerDangerEntity.setProcessInstanceId(result.getData().toString());
innerDangerEntity.setTaskId(result.getData().getTaskId()); innerDangerEntity.setIsNormal(true);
this.baseMapper.updateById(innerDangerEntity); this.baseMapper.updateById(innerDangerEntity);
}
return R.success("启动流程成功"); return R.success("启动流程成功");
} }
}
@Override
public R compensationProcess(String id) {
InnerDangerEntity entity = this.baseMapper.selectById(id);
if (ObjectUtils.isNotEmpty(entity)){
return this.startProcess(JSON.toJSONString(entity), HIDDEN_DANGER_CHECK,entity.getRemark());
}
return R.fail("找不到对应流程数据,请稍后重试!");
}
/** /**
* @param processWorkFlowResponse * @param processWorkFlowResponse
*/ */
@Override @Override
public R listenAndUpdateDefect(ProcessWorkFlowResponse processWorkFlowResponse) { public R listenAndUpdateDefect(ProcessWorkFlowResponse processWorkFlowResponse) {
InnerDangerVo hiddenDangerVo; InnerDangerVo hiddenDangerVo;
log.warn("隐患处理流程消息开始转换"); log.warn("隐患处理流程消息开始转换");
try { try {
@ -170,6 +178,9 @@ public class InnerDangerFlowServiceImpl extends ServiceImpl<InnerDangerMapper, I
log.error("隐患处理流程消息转换失败:" + e.getMessage()); log.error("隐患处理流程消息转换失败:" + e.getMessage());
return R.fail("隐患处理流程消息转换失败"); return R.fail("隐患处理流程消息转换失败");
} }
if(ObjectUtils.isNotEmpty(processWorkFlowResponse.getCode())&&700==processWorkFlowResponse.getCode()){
return handException(processWorkFlowResponse);
}
InnerDangerEntity saveEntity = this.getOne(new LambdaQueryWrapper<InnerDangerEntity>() {{ InnerDangerEntity saveEntity = this.getOne(new LambdaQueryWrapper<InnerDangerEntity>() {{
eq(InnerDangerEntity::getCode, hiddenDangerVo.getCode()); eq(InnerDangerEntity::getCode, hiddenDangerVo.getCode());
last("limit 1"); last("limit 1");
@ -193,6 +204,21 @@ public class InnerDangerFlowServiceImpl extends ServiceImpl<InnerDangerMapper, I
return R.success("消息保存成功"); return R.success("消息保存成功");
} }
private R handException(ProcessWorkFlowResponse processWorkFlowResponse) {
String[] split = processWorkFlowResponse.getBusinessKey().split(":");
if (StringUtils.isBlank(split[1])){
log.error("异常消息转换失败,未找到BusinessKey:"+ processWorkFlowResponse);
return R.fail("异常消息处理失败");
}
InnerDangerEntity innerDangerEntity = this.baseMapper.selectById(split[1]);
innerDangerEntity.setIsNormal(false);
innerDangerEntity.setRemark(JSONObject.toJSONString(processWorkFlowResponse.getVariables()));
innerDangerEntity.setCurrentOperator(processWorkFlowResponse.getTaskName());
innerDangerEntity.setProcessInstanceId(processWorkFlowResponse.getTaskId());
innerDangerEntity.setCurrentLinkHandler("");
this.baseMapper.updateById(innerDangerEntity);
return R.fail("消息保存成功");
}
@Override @Override
public IPage<HiddenDangerBaseVo> getHiddenDangerBase(HiddenDangerBaseVo hiddenDangerBaseVo, Query query) { public IPage<HiddenDangerBaseVo> getHiddenDangerBase(HiddenDangerBaseVo hiddenDangerBaseVo, Query query) {
InnerDangerEntity innerDangerEntity = new InnerDangerEntity(); InnerDangerEntity innerDangerEntity = new InnerDangerEntity();
@ -292,6 +318,7 @@ public class InnerDangerFlowServiceImpl extends ServiceImpl<InnerDangerMapper, I
}else { }else {
iPage.setRecords(new ArrayList<>()); iPage.setRecords(new ArrayList<>());
} }
return iPage; return iPage;
} }

56
hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/repair/service/impl/WorkTaskServiceImpl.java

@ -2,13 +2,18 @@ package com.hnac.hzims.ticket.repair.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnac.hzims.common.constant.CommonConstant; import com.hnac.hzims.common.constant.CommonConstant;
import com.hnac.hzims.common.flow.StartProcessService; 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.middle.process.to.ProcessWorkFlowResponse;
import com.hnac.hzims.operational.access.entity.OperAccessPlanEntity;
import com.hnac.hzims.ticket.repair.constants.WorkTaskConstants; import com.hnac.hzims.ticket.repair.constants.WorkTaskConstants;
import com.hnac.hzims.ticket.repair.entity.WorkTaskEntity; import com.hnac.hzims.ticket.repair.entity.WorkTaskEntity;
import com.hnac.hzims.ticket.repair.mapper.WorkTaskMapper; import com.hnac.hzims.ticket.repair.mapper.WorkTaskMapper;
@ -42,6 +47,8 @@ import org.springblade.system.user.entity.User;
import org.springblade.system.user.feign.IUserClient; import org.springblade.system.user.feign.IUserClient;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
@ -58,6 +65,8 @@ public class WorkTaskServiceImpl extends ServiceImpl<WorkTaskMapper, WorkTaskEnt
private final IWorkTicketInfoService workTicketInfoService; private final IWorkTicketInfoService workTicketInfoService;
private final ICompensateProcessClient compensateProcessClient;
private final IFlowClient flowClient; private final IFlowClient flowClient;
private final ISysClient sysClient; private final ISysClient sysClient;
@ -86,7 +95,6 @@ public class WorkTaskServiceImpl extends ServiceImpl<WorkTaskMapper, WorkTaskEnt
R r = this.startProcess(saved, "work_task",""); R r = this.startProcess(saved, "work_task","");
return r; return r;
} }
@Override @Override
public String saveEntity(String entity) { public String saveEntity(String entity) {
WorkTaskVO workTask= JSONObject.parseObject(entity, WorkTaskVO.class); WorkTaskVO workTask= JSONObject.parseObject(entity, WorkTaskVO.class);
@ -116,19 +124,29 @@ public class WorkTaskServiceImpl extends ServiceImpl<WorkTaskMapper, WorkTaskEnt
if(result.isSuccess() && ObjectUtil.isNotEmpty(result.getData())){ if(result.isSuccess() && ObjectUtil.isNotEmpty(result.getData())){
workTask.setDeptName(result.getData().getDeptName()); workTask.setDeptName(result.getData().getDeptName());
} }
//保存步骤只涉及到一张表,不加事务
this.save(workTask); this.save(workTask);
return JSON.toJSONString(workTask); return JSON.toJSONString(workTask);
} }
@Override @Override
public R compensationProcess(String id) { public R compensationProcess(String id) {
return null; WorkTaskEntity entity = this.baseMapper.selectById(id);
if (ObjectUtils.isNotEmpty(entity)){
return this.startProcess(JSON.toJSONString(entity), "work_task",entity.getRemark());
}
return R.fail("找不到对应流程数据,请稍后重试!");
} }
@Override @Override
public R startProcess(String entity, String dictValue,String param) { public R startProcess(String entity, String dictValue,String param) {
WorkTaskVO workTask= JSONObject.parseObject(entity, WorkTaskVO.class); WorkTaskVO workTask= JSONObject.parseObject(entity, WorkTaskVO.class);
Map<String, Object> variables = JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(workTask, DateUtil.PATTERN_DATETIME), Map.class); Map<String, Object> variables;
if (StringUtil.isNotBlank(param)) {
variables = JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(param, DateUtil.PATTERN_DATETIME), Map.class);
}else {
variables = JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(workTask, DateUtil.PATTERN_DATETIME), Map.class);
}
variables.put("head", TaskUtil.getTaskUser(String.valueOf(workTask.getHead()))); variables.put("head", TaskUtil.getTaskUser(String.valueOf(workTask.getHead())));
// 班组成员 // 班组成员
String[] member = workTask.getMember().split(","); String[] member = workTask.getMember().split(",");
@ -139,13 +157,16 @@ public class WorkTaskServiceImpl extends ServiceImpl<WorkTaskMapper, WorkTaskEnt
variables.put("duty" + i, TaskUtil.getTaskUser(member[i-1])); variables.put("duty" + i, TaskUtil.getTaskUser(member[i-1]));
} }
} }
R<BladeFlow> result = flowClient.startProcessInstanceContainNameByKey(dictValue, FlowUtil.getBusinessKey("work_task_v4",String.valueOf(workTask.getId())), workTask.getCode(), variables); R result = compensateProcessClient.startFlow(AuthUtil.getUserId().toString(),
dictValue,FlowUtil.getBusinessKey("work_task_v4",String.valueOf(workTask.getId()))
, workTask.getCode(), variables);
log.error("work_task_start_process_result :{}",result); log.error("work_task_start_process_result :{}",result);
// 更新任务流程Id // 更新任务流程Id
if (result.isSuccess()) { if (200==result.getCode()) {
BladeFlow flow = result.getData(); workTask.setIsNormal(true);
workTask.setProcessInstanceId(flow.getProcessInstanceId()); workTask.setProcessInstanceId(result.getData().toString());
this.updateById(workTask); this.updateById(workTask);
return R.success("启动流程成功");
} else { } else {
workTask.setIsNormal(false); workTask.setIsNormal(false);
workTask.setRemark(JSONObject.toJSONString(variables)); workTask.setRemark(JSONObject.toJSONString(variables));
@ -156,7 +177,6 @@ public class WorkTaskServiceImpl extends ServiceImpl<WorkTaskMapper, WorkTaskEnt
r.setData(variables); r.setData(variables);
return r; return r;
} }
return R.success("启动流程成功");
} }
@ -168,6 +188,10 @@ public class WorkTaskServiceImpl extends ServiceImpl<WorkTaskMapper, WorkTaskEnt
@Override @Override
public boolean listener(ProcessWorkFlowResponse processWorkFlowResponse) { public boolean listener(ProcessWorkFlowResponse processWorkFlowResponse) {
Map<String, Object> variables = (Map<String, Object>) processWorkFlowResponse.getVariables(); Map<String, Object> variables = (Map<String, Object>) processWorkFlowResponse.getVariables();
if(ObjectUtils.isNotEmpty(processWorkFlowResponse.getCode())&&700==processWorkFlowResponse.getCode()){
handException(processWorkFlowResponse);
return false;
}
log.error("work_task_listener_variables : {}",variables); log.error("work_task_listener_variables : {}",variables);
Object head = variables.get("head"); Object head = variables.get("head");
if(ObjectUtil.isNotEmpty(head)){ if(ObjectUtil.isNotEmpty(head)){
@ -176,6 +200,7 @@ public class WorkTaskServiceImpl extends ServiceImpl<WorkTaskMapper, WorkTaskEnt
WorkTaskVO entity = JSONObject.parseObject(JSONObject.toJSONString(variables), new TypeReference<WorkTaskVO>(){}); WorkTaskVO entity = JSONObject.parseObject(JSONObject.toJSONString(variables), new TypeReference<WorkTaskVO>(){});
// 当前流程名称 // 当前流程名称
entity.setTaskName(processWorkFlowResponse.getTaskName()); entity.setTaskName(processWorkFlowResponse.getTaskName());
entity.setIsNormal(true);
// 流程阶段执行人员名称 // 流程阶段执行人员名称
entity.setNextStepOperator(processWorkFlowResponse.getNextStepOperator()); entity.setNextStepOperator(processWorkFlowResponse.getNextStepOperator());
entity.setHeadHandleTime(new Date()); entity.setHeadHandleTime(new Date());
@ -198,6 +223,21 @@ public class WorkTaskServiceImpl extends ServiceImpl<WorkTaskMapper, WorkTaskEnt
return true; return true;
} }
private R handException(ProcessWorkFlowResponse processWorkFlowResponse) {
String[] split = processWorkFlowResponse.getBusinessKey().split(":");
if (StringUtils.isBlank(split[1])){
log.error("异常消息转换失败,未找到BusinessKey:"+ processWorkFlowResponse);
return R.fail("异常消息处理失败");
}
WorkTaskEntity workTaskEntity = this.baseMapper.selectById(split[1]);
workTaskEntity.setIsNormal(false);
workTaskEntity.setRemark(JSONObject.toJSONString(processWorkFlowResponse.getVariables()));
workTaskEntity.setTaskName(processWorkFlowResponse.getTaskName());
workTaskEntity.setProcessInstanceId(processWorkFlowResponse.getTaskId());
workTaskEntity.setNextStepOperator("");
this.baseMapper.updateById(workTaskEntity);
return R.success("消息保存成功");
}
/** /**
* 工作任务单-分页查询 * 工作任务单-分页查询
* @param page * @param page

71
hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/standardTicket/service/impl/OperationTicketServiceImpl.java

@ -4,12 +4,15 @@ import cn.afterturn.easypoi.word.WordExportUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.hnac.hzims.common.flow.StartProcessService; import com.hnac.hzims.common.flow.StartProcessService;
import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.common.logs.utils.StringUtils;
import com.hnac.hzims.middle.process.feign.ICompensateProcessClient;
import com.hnac.hzims.middle.process.feign.ProcessDictFeignService; import com.hnac.hzims.middle.process.feign.ProcessDictFeignService;
import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse;
import com.hnac.hzims.operational.access.entity.OperAccessPlanEntity;
import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.entity.StationEntity;
import com.hnac.hzims.operational.station.feign.IStationClient; import com.hnac.hzims.operational.station.feign.IStationClient;
import com.hnac.hzims.ticket.constants.TicketConstants; import com.hnac.hzims.ticket.constants.TicketConstants;
@ -36,9 +39,11 @@ import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.flow.core.entity.BladeFlow; import org.springblade.flow.core.entity.BladeFlow;
import org.springblade.flow.core.feign.IFlowClient; import org.springblade.flow.core.feign.IFlowClient;
import org.springblade.flow.core.utils.FlowUtil;
import org.springblade.message.MessageConstants; import org.springblade.message.MessageConstants;
import org.springblade.message.dto.BusinessMessageDTO; import org.springblade.message.dto.BusinessMessageDTO;
import org.springblade.message.fegin.IMessageClient; import org.springblade.message.fegin.IMessageClient;
@ -47,7 +52,9 @@ import org.springblade.system.user.cache.UserCache;
import org.springblade.system.user.entity.User; import org.springblade.system.user.entity.User;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionTemplate;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -86,7 +93,7 @@ public class OperationTicketServiceImpl implements OperationTicketService , Star
private final ProcessDictFeignService processDictFeignService; private final ProcessDictFeignService processDictFeignService;
private final IFlowClient flowClient; private final ICompensateProcessClient compensateProcessClient;
private final IMessageClient messageClient; private final IMessageClient messageClient;
@ -117,6 +124,8 @@ public class OperationTicketServiceImpl implements OperationTicketService , Star
//启动流程 //启动流程
return this.startProcess(standardTicketInfoVoBySave, dictValue,""); return this.startProcess(standardTicketInfoVoBySave, dictValue,"");
} }
private final PlatformTransactionManager transactionManager;
private final TransactionTemplate transactionTemplate;
@Override @Override
public String saveEntity(String entity) { public String saveEntity(String entity) {
StandardTicketInfoVo standardTicketInfoVo= JSONObject.parseObject(entity, StandardTicketInfoVo.class); StandardTicketInfoVo standardTicketInfoVo= JSONObject.parseObject(entity, StandardTicketInfoVo.class);
@ -153,7 +162,10 @@ public class OperationTicketServiceImpl implements OperationTicketService , Star
if (StringUtils.isBlank(code)) { if (StringUtils.isBlank(code)) {
throw new ServiceException("服务器异常,请联系管理员"); throw new ServiceException("服务器异常,请联系管理员");
} }
//多张表开启事务
standardTicketInfoVo.setCode(code); standardTicketInfoVo.setCode(code);
transactionTemplate.setTransactionManager(transactionManager);
String res = transactionTemplate.execute(status -> {
//3. 保存操作对象 //3. 保存操作对象
StandardTicketInfoEntity standardTicketInfo = getStandardTicketInfoEntity(standardTicketInfoVo); StandardTicketInfoEntity standardTicketInfo = getStandardTicketInfoEntity(standardTicketInfoVo);
standardTicketInfo.setStatus(1); standardTicketInfo.setStatus(1);
@ -167,6 +179,8 @@ public class OperationTicketServiceImpl implements OperationTicketService , Star
standardTicketInfoVo.setStandardTicketMeasureVos(standardTicketInfoVos); standardTicketInfoVo.setStandardTicketMeasureVos(standardTicketInfoVos);
log.info("保存操作对象 :{}", standardTicketInfoVo); log.info("保存操作对象 :{}", standardTicketInfoVo);
return JSON.toJSONString(standardTicketInfoVo); return JSON.toJSONString(standardTicketInfoVo);
});
return res;
} }
@ -175,20 +189,23 @@ public class OperationTicketServiceImpl implements OperationTicketService , Star
public R startProcess(String entity, String dictValue,String param) { public R startProcess(String entity, String dictValue,String param) {
StandardTicketInfoVo standardTicketInfoVo= JSONObject.parseObject(entity, StandardTicketInfoVo.class); StandardTicketInfoVo standardTicketInfoVo= JSONObject.parseObject(entity, StandardTicketInfoVo.class);
StandardTicketInfoEntity standardTicketInfoEntity = getStandardTicketInfoEntity(standardTicketInfoVo); StandardTicketInfoEntity standardTicketInfoEntity = getStandardTicketInfoEntity(standardTicketInfoVo);
Instant start = Instant.now();
Map<String, Object> params = new HashMap<>(4); Map<String, Object> params = new HashMap<>(4);
params.put("standardTicketInfoVo", standardTicketInfoVo); params.put("standardTicketInfoVo", standardTicketInfoVo);
params.put("taskId", standardTicketInfoVo.getId()); params.put("taskId", standardTicketInfoVo.getId());
if (ObjectUtils.isNotEmpty(standardTicketInfoVo.getGuardian())) { if (ObjectUtils.isNotEmpty(standardTicketInfoVo.getGuardian())) {
params.put("guardianUserIds", "taskUser_".concat(standardTicketInfoVo.getGuardian().toString())); params.put("guardianUserIds", "taskUser_".concat(standardTicketInfoVo.getGuardian().toString()));
} }
if (StringUtils.isNotBlank(param)){
params=JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(param, DateUtil.PATTERN_DATETIME), Map.class);
}
//已开启流程 //已开启流程
R<BladeFlow> processInstanceContainNameByKey = flowClient.startProcessInstanceContainNameByKey(dictValue, String.valueOf(standardTicketInfoVo.getId()), R processInstanceContainNameByKey = compensateProcessClient.startFlow(AuthUtil.getUserId().toString(),
standardTicketInfoVo.getTitle(), params); dictValue, FlowUtil.getBusinessKey("hzims_standard_ticket_info",
if (!processInstanceContainNameByKey.isSuccess()) { String.valueOf(standardTicketInfoVo.getId())),standardTicketInfoVo.getTitle(), params);
if (200!=processInstanceContainNameByKey.getCode()) {
standardTicketInfoEntity.setIsNormal(false); standardTicketInfoEntity.setIsNormal(false);
standardTicketInfoEntity.setRemarkFlow(JSONObject.toJSONString(params)); standardTicketInfoEntity.setRemarkFlow(JSONObject.toJSONString(params));
standardTicketInfoService.save(standardTicketInfoEntity); standardTicketInfoService.updateById(standardTicketInfoEntity);
R r=new R(); R r=new R();
r.setCode(processInstanceContainNameByKey.getCode()); r.setCode(processInstanceContainNameByKey.getCode());
r.setMsg(processInstanceContainNameByKey.getMsg()); r.setMsg(processInstanceContainNameByKey.getMsg());
@ -196,17 +213,21 @@ public class OperationTicketServiceImpl implements OperationTicketService , Star
log.error("开启流程失败 {}", processInstanceContainNameByKey.getMsg()); log.error("开启流程失败 {}", processInstanceContainNameByKey.getMsg());
return r; return r;
} }
Duration between = Duration.between(start, Instant.now()); standardTicketInfoEntity.setProcessInstanceId(processInstanceContainNameByKey.getData().toString());
log.info("================================================================"); standardTicketInfoEntity.setIsNormal(true);
log.info("耗时: " + (between.getSeconds()) + "秒"); standardTicketInfoService.updateById(standardTicketInfoEntity);
log.info("耗时: " + (between.toMillis()) + "毫秒");
log.info("================================================================");
return R.success("启动流程成功"); return R.success("启动流程成功");
} }
@Override @Override
public R compensationProcess(String id) { public R compensationProcess(String id) {
return null; //查询流程对应value
String dictValue = processDictFeignService.selectDictValueByKey(OPERATION_TICKET_KEY);
StandardTicketInfoEntity entity = standardTicketInfoService.getById(id);
if (ObjectUtils.isNotEmpty(entity)){
return this.startProcess(JSON.toJSONString(entity), dictValue,entity.getRemark());
}
return R.fail("找不到对应流程数据,请稍后重试!");
} }
/** /**
@ -227,6 +248,10 @@ public class OperationTicketServiceImpl implements OperationTicketService , Star
String formData = JSON.toJSONString(response.getVariables()); String formData = JSON.toJSONString(response.getVariables());
log.info("获取表单的数据:{}", formData); log.info("获取表单的数据:{}", formData);
StandardTicketInfoVo standardTicketInfoVo = null; StandardTicketInfoVo standardTicketInfoVo = null;
if(ObjectUtils.isNotEmpty(response.getCode())&&700==response.getCode()){
handException(response);
return ;
}
try { try {
JSONObject jsonObject = JSONObject.parseObject(formData); JSONObject jsonObject = JSONObject.parseObject(formData);
// standardTicketInfoVo = JSONObject.toJavaObject(jsonObject, StandardTicketInfoVo.class); // standardTicketInfoVo = JSONObject.toJavaObject(jsonObject, StandardTicketInfoVo.class);
@ -238,6 +263,7 @@ public class OperationTicketServiceImpl implements OperationTicketService , Star
e.printStackTrace(); e.printStackTrace();
throw new IllegalArgumentException(e.getMessage()); throw new IllegalArgumentException(e.getMessage());
} }
//1.查询操作票信息 //1.查询操作票信息
Long id = NumberUtils.toLong(response.getBusinessKey()); Long id = NumberUtils.toLong(response.getBusinessKey());
StandardTicketInfoEntity standardTicketInfoEntity = standardTicketInfoService.getById(id); StandardTicketInfoEntity standardTicketInfoEntity = standardTicketInfoService.getById(id);
@ -310,6 +336,27 @@ public class OperationTicketServiceImpl implements OperationTicketService , Star
} }
} }
private R handException(ProcessWorkFlowResponse processWorkFlowResponse) {
String[] split = processWorkFlowResponse.getBusinessKey().split(":");
if (StringUtils.isBlank(split[1])){
log.error("异常消息转换失败,未找到BusinessKey:"+ processWorkFlowResponse);
return R.fail("异常消息处理失败");
}
StandardTicketInfoEntity entity = standardTicketInfoService.getOne(new LambdaQueryWrapper<StandardTicketInfoEntity>() {{
eq(StandardTicketInfoEntity::getId, split[1]);
}});
entity.setIsNormal(false);
entity.setRemark(JSONObject.toJSONString(processWorkFlowResponse.getVariables()));
entity.setTaskName(processWorkFlowResponse.getTaskName());
entity.setProcessInstanceId(processWorkFlowResponse.getTaskId());
entity.setNextStepOperator("");
boolean flag = standardTicketInfoService.updateById(entity);
if (!flag){
log.info("异常状态消息保存失败"+ processWorkFlowResponse);
return R.success("消息保存失败");
}
return R.fail("消息保存成功");
}
/** /**
* 填充数据 * 填充数据

79
hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/twoTicket/service/impl/TicketProcessServiceImpl.java

@ -3,13 +3,16 @@ package com.hnac.hzims.ticket.twoTicket.service.impl;
import cn.afterturn.easypoi.word.WordExportUtil; import cn.afterturn.easypoi.word.WordExportUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.hnac.hzims.common.flow.StartProcessService; import com.hnac.hzims.common.flow.StartProcessService;
import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.common.logs.utils.StringUtils;
import com.hnac.hzims.middle.process.feign.ICompensateProcessClient;
import com.hnac.hzims.middle.process.feign.ProcessDictFeignService; import com.hnac.hzims.middle.process.feign.ProcessDictFeignService;
import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse;
import com.hnac.hzims.operational.access.entity.OperAccessPlanEntity;
import com.hnac.hzims.operational.access.entity.OperAccessTaskEntity; import com.hnac.hzims.operational.access.entity.OperAccessTaskEntity;
import com.hnac.hzims.operational.access.feign.IOperAccessTaskClient; import com.hnac.hzims.operational.access.feign.IOperAccessTaskClient;
import com.hnac.hzims.operational.feign.IAccessTaskClient; import com.hnac.hzims.operational.feign.IAccessTaskClient;
@ -51,6 +54,7 @@ import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.core.tool.utils.StringUtil; import org.springblade.core.tool.utils.StringUtil;
import org.springblade.flow.core.entity.BladeFlow; import org.springblade.flow.core.entity.BladeFlow;
import org.springblade.flow.core.feign.IFlowClient; import org.springblade.flow.core.feign.IFlowClient;
import org.springblade.flow.core.utils.FlowUtil;
import org.springblade.message.MessageConstants; import org.springblade.message.MessageConstants;
import org.springblade.message.dto.BusinessMessageDTO; import org.springblade.message.dto.BusinessMessageDTO;
import org.springblade.message.fegin.IMessageClient; import org.springblade.message.fegin.IMessageClient;
@ -60,7 +64,9 @@ import org.springblade.system.user.entity.User;
import org.springblade.system.user.feign.IUserClient; import org.springblade.system.user.feign.IUserClient;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
@ -140,6 +146,7 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc
@Value("${hzims.ticket.path.word.templatePath}") @Value("${hzims.ticket.path.word.templatePath}")
private String templatePath; private String templatePath;
private final ICompensateProcessClient compensateProcessClient;
private final TicketInfoDangerService ticketInfoDangerService; private final TicketInfoDangerService ticketInfoDangerService;
@ -162,7 +169,7 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc
*/ */
// @SneakyThrows // @SneakyThrows
@Override @Override
@Transactional // @Transactional
public R startUp(WorkTicketVo workTicketVo) { public R startUp(WorkTicketVo workTicketVo) {
log.info("ticket:start:request",JSON.toJSONString(workTicketVo)); log.info("ticket:start:request",JSON.toJSONString(workTicketVo));
log.info("执行 com.hnac.hzims.ticket.twoTicket.service.impl【startUp】 。。。方法"); log.info("执行 com.hnac.hzims.ticket.twoTicket.service.impl【startUp】 。。。方法");
@ -179,7 +186,8 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc
R r = this.startProcess(saveEntity, dictValue,""); R r = this.startProcess(saveEntity, dictValue,"");
return r; return r;
} }
private final PlatformTransactionManager transactionManager;
private final TransactionTemplate transactionTemplate;
@Override @Override
public String saveEntity(String entity) { public String saveEntity(String entity) {
WorkTicketVo workTicketVo= JSONObject.parseObject(entity, WorkTicketVo.class); WorkTicketVo workTicketVo= JSONObject.parseObject(entity, WorkTicketVo.class);
@ -208,7 +216,6 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc
throw new ServiceException("票据抬头未配置,请您到站点管理配置"); throw new ServiceException("票据抬头未配置,请您到站点管理配置");
} }
//signage = signage.length() == 2 ? station.getSignage() : station.getSignage().substring(0, 2); //signage = signage.length() == 2 ? station.getSignage() : station.getSignage().substring(0, 2);
workTicketVo.getWorkTicket().setSignage(station.getSignage()); workTicketVo.getWorkTicket().setSignage(station.getSignage());
workTicketVo.getWorkTicket().setSignageCode(station.getCode()); workTicketVo.getWorkTicket().setSignageCode(station.getCode());
//2. 获取编码 //2. 获取编码
@ -217,6 +224,8 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc
if (StringUtils.isBlank(code)) { if (StringUtils.isBlank(code)) {
throw new ServiceException("服务器异常,请联系管理员"); throw new ServiceException("服务器异常,请联系管理员");
} }
transactionTemplate.setTransactionManager(transactionManager);
String res = transactionTemplate.execute(status -> {
workTicketVo.getWorkTicket().setCode(code); workTicketVo.getWorkTicket().setCode(code);
//保存工作对象 //保存工作对象
log.info("ticket:start:vo",JSON.toJSONString(workTicketVo.getWorkTicket())); log.info("ticket:start:vo",JSON.toJSONString(workTicketVo.getWorkTicket()));
@ -231,6 +240,8 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc
//保存工作任务 //保存工作任务
this.saveWorkTicketContentDto(workTicketVo.getWorkTicketContentDtoList(), workTicketVo.getWorkTicket()); this.saveWorkTicketContentDto(workTicketVo.getWorkTicketContentDtoList(), workTicketVo.getWorkTicket());
return JSONObject.toJSONString(workTicketVo); return JSONObject.toJSONString(workTicketVo);
});
return res;
} }
@ -245,7 +256,7 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc
if (status.intValue() != workTicketVo.getWorkTicket().getFlowStatus().intValue()) { if (status.intValue() != workTicketVo.getWorkTicket().getFlowStatus().intValue()) {
return R.success("线下流程,开票成功"); return R.success("线下流程,开票成功");
} }
Map<String, Object> params = new HashMap<>(4); Map<String, Object> params = new HashMap<>();
params.put("workTicketVo", workTicketVo); params.put("workTicketVo", workTicketVo);
//获取当前登录人 //获取当前登录人
Long userId = AuthUtil.getUserId(); Long userId = AuthUtil.getUserId();
@ -255,7 +266,10 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc
params.put("principal", "taskUser_" + workTicketVo.getWorkTicket().getPrincipal()); params.put("principal", "taskUser_" + workTicketVo.getWorkTicket().getPrincipal());
} }
//已开启流程 //已开启流程
R<BladeFlow> processInstanceContainNameByKey = flowClient.startProcessInstanceContainNameByKey(dictValue, String.valueOf(workTicketVo.getWorkTicket().getId()), workTicketVo.getWorkTicket().getWorkContent(), params); R processInstanceContainNameByKey = compensateProcessClient.startFlow(
AuthUtil.getUserId().toString(),dictValue,
FlowUtil.getBusinessKey("hzims_work_ticket_info",String.valueOf(workTicketVo.getWorkTicket().getId())),
workTicketVo.getWorkTicket().getWorkContent(),params);
log.info("processInstanceContainNameByKey.isSuccess() : {}", processInstanceContainNameByKey.isSuccess()); log.info("processInstanceContainNameByKey.isSuccess() : {}", processInstanceContainNameByKey.isSuccess());
if (!processInstanceContainNameByKey.isSuccess()) { if (!processInstanceContainNameByKey.isSuccess()) {
//保存流程开始失败情况 //保存流程开始失败情况
@ -272,20 +286,24 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc
r.setMsg("流程开启失败,请检查流程和用户权限后重试!"); r.setMsg("流程开启失败,请检查流程和用户权限后重试!");
r.setData(params); r.setData(params);
return r; return r;
} }else {
log.info("获取启动流程数据 : {}", processInstanceContainNameByKey); workTicket.setProcessInstanceId(processInstanceContainNameByKey.getData().toString());
Duration between = Duration.between(start, Instant.now()); workTicket.setIsNormal(true);
firstWorkTicketService.updateById(workTicket);
log.info("================================================================");
log.info("耗时: " + (between.getSeconds()) + "秒");
log.info("耗时: " + (between.toMillis()) + "毫秒");
log.info("================================================================");
return R.success("启动流程成功"); return R.success("启动流程成功");
} }
}
@Override @Override
public R compensationProcess(String id) { public R compensationProcess(String id) {
return null; WorkTicketInfoEntity entity = firstWorkTicketService.getById(id);
if (ObjectUtils.isNotEmpty(entity)){
WorkTicketVo workTicketVo = new WorkTicketVo();
workTicketVo.setWorkTicket(entity);
String dictValue = getDictValue(workTicketVo);
return this.startProcess(JSON.toJSONString(entity), dictValue,entity.getRemark());
}
return R.fail("找不到对应流程数据,请稍后重试!");
} }
/** /**
@ -321,7 +339,6 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void findPending(ProcessWorkFlowResponse response) { public void findPending(ProcessWorkFlowResponse response) {
try { try {
log.info("获取待处理的数据 {}", response); log.info("获取待处理的数据 {}", response);
log.info("获取businessKey: {}", response.getBusinessKey()); log.info("获取businessKey: {}", response.getBusinessKey());
@ -332,6 +349,10 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc
log.info("获取根据handleType区分是用户还是候选组角色: {}", response.getHandleType()); log.info("获取根据handleType区分是用户还是候选组角色: {}", response.getHandleType());
//json转换表单 //json转换表单
String formData = JSON.toJSONString(response.getVariables()); String formData = JSON.toJSONString(response.getVariables());
if(ObjectUtils.isNotEmpty(response.getCode())&&700==response.getCode()){
handException(response);
return ;
}
log.info("获取表单的数据:{}", formData); log.info("获取表单的数据:{}", formData);
FristWorkTicketVo fristWorkFlowResponse = null; FristWorkTicketVo fristWorkFlowResponse = null;
try { try {
@ -343,6 +364,7 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc
//获取表单数据 //获取表单数据
WorkTicketVo workTicketVo = fristWorkFlowResponse.getWorkTicketVo(); WorkTicketVo workTicketVo = fristWorkFlowResponse.getWorkTicketVo();
WorkTicketInfoEntity workTicket = workTicketVo.getWorkTicket(); WorkTicketInfoEntity workTicket = workTicketVo.getWorkTicket();
workTicket.setIsNormal(true);
//2.流程处理 //2.流程处理
String businessKey = response.getBusinessKey(); String businessKey = response.getBusinessKey();
WorkTicketInfoEntity workTicketInfo = ticketInfoService.getById(businessKey); WorkTicketInfoEntity workTicketInfo = ticketInfoService.getById(businessKey);
@ -503,10 +525,33 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error("工作票流转失败,失败原因:{}",e);
} }
} }
private R handException(ProcessWorkFlowResponse processWorkFlowResponse) {
String[] split = processWorkFlowResponse.getBusinessKey().split(":");
if (StringUtils.isBlank(split[1])){
log.error("异常消息转换失败,未找到BusinessKey:"+ processWorkFlowResponse);
return R.fail("异常消息处理失败");
}
WorkTicketInfoEntity workTicketInfoEntity = ticketInfoService.getOne(new LambdaQueryWrapper<WorkTicketInfoEntity>() {{
eq(WorkTicketInfoEntity::getId, split[1]);
}});
workTicketInfoEntity.setIsNormal(false);
workTicketInfoEntity.setRemark(JSONObject.toJSONString(processWorkFlowResponse.getVariables()));
workTicketInfoEntity.setTaskName(processWorkFlowResponse.getTaskName());
workTicketInfoEntity.setProcessInstanceId(processWorkFlowResponse.getTaskId());
workTicketInfoEntity.setNextStepOperator("");
boolean flag = ticketInfoService.updateById(workTicketInfoEntity);
if (!flag){
log.info("异常状态消息保存失败"+ processWorkFlowResponse);
return R.success("消息保存失败");
}
return R.fail("消息保存成功");
}
@Override @Override
public Boolean offlineTicketFindPending(ProcessWorkFlowResponse response) { public Boolean offlineTicketFindPending(ProcessWorkFlowResponse response) {
log.info("线下工作票接收到的工作票数据为:{}",JSON.toJSONString(response)); log.info("线下工作票接收到的工作票数据为:{}",JSON.toJSONString(response));
@ -515,6 +560,10 @@ public class TicketProcessServiceImpl implements TicketProcessService, StartProc
log.error("接收到的数据为:{}",JSON.toJSONString(response.getVariables())); log.error("接收到的数据为:{}",JSON.toJSONString(response.getVariables()));
throw new ServiceException("线下工作票处理流程环节接收数据失败,请联系管理员"); throw new ServiceException("线下工作票处理流程环节接收数据失败,请联系管理员");
}); });
if(ObjectUtils.isNotEmpty(response.getCode())&&700==response.getCode()){
handException(response);
return false;
}
WorkTicketVo workTicketVo = ticketResponse.getWorkTicketVo(); WorkTicketVo workTicketVo = ticketResponse.getWorkTicketVo();
WorkTicketInfoEntity workTicket = workTicketVo.getWorkTicket(); WorkTicketInfoEntity workTicket = workTicketVo.getWorkTicket();
WorkTicketInfoEntity info = firstWorkTicketService.getById(workTicket.getId()); WorkTicketInfoEntity info = firstWorkTicketService.getById(workTicket.getId());

4
hzims-service/ticket/src/main/resources/db/3.0.0.sql

@ -2,11 +2,15 @@ ALTER TABLE `hzims_standard_ticket_info`
ADD COLUMN `remark_flow` text NULL ; ADD COLUMN `remark_flow` text NULL ;
ALTER TABLE `hzims_work_ticket_info` ALTER TABLE `hzims_work_ticket_info`
ADD COLUMN `remark` text NULL ; ADD COLUMN `remark` text NULL ;
ALTER TABLE `hzims_work_task`
ADD COLUMN `remark` text NULL ;
ALTER TABLE `hzims_standard_ticket_info` ALTER TABLE `hzims_standard_ticket_info`
ADD COLUMN `is_normal` tinyint(2) NULL DEFAULT 1 ; ADD COLUMN `is_normal` tinyint(2) NULL DEFAULT 1 ;
ALTER TABLE `hzims_work_ticket_info` ALTER TABLE `hzims_work_ticket_info`
ADD COLUMN `is_normal` tinyint(2) NULL DEFAULT 1 ; ADD COLUMN `is_normal` tinyint(2) NULL DEFAULT 1 ;
ALTER TABLE `hzims_work_task`
ADD COLUMN `is_normal` tinyint(2) NULL DEFAULT 1 ;
ALTER TABLE `hzims_standard_ticket_info` ALTER TABLE `hzims_standard_ticket_info`
ADD COLUMN `em_code` varchar(255) NULL COMMENT '设备编号' , ADD COLUMN `em_code` varchar(255) NULL COMMENT '设备编号' ,

Loading…
Cancel
Save