Commit 81a82268 authored by KeYong's avatar KeYong

提交任务流程优化

parent d8b74ae0
......@@ -9,7 +9,7 @@ import javax.persistence.Table;
/**
* The persistent class for the equipment_fire_equipment database table.
* The persistent class for the c_emergency_task_content database table.
*/
@Entity
@Table(name = "c_emergency_task_content")
......
......@@ -6,10 +6,12 @@ import com.yeejoin.amos.fas.business.feign.JcsFeign;
import com.yeejoin.amos.fas.business.service.intfc.IDictService;
import com.yeejoin.amos.fas.business.service.intfc.IEmergencyTaskService;
import com.yeejoin.amos.fas.business.vo.EmergencyRelationVo;
import com.yeejoin.amos.fas.business.vo.EmergencyTaskContentVo;
import com.yeejoin.amos.fas.core.common.request.CommonPageable;
import com.yeejoin.amos.fas.dao.entity.Dict;
import com.yeejoin.amos.fas.dao.entity.EmergencyRelation;
import com.yeejoin.amos.fas.dao.entity.EmergencyRelationTree;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.Page;
......@@ -171,6 +173,11 @@ public class EmergencyTaskController extends BaseController{
return CommonResponseUtil.success(emergencyRelationVo);
}
@ApiOperation(httpMethod = "POST",value = "新增流程任务", notes = "新增流程任务")
@PostMapping(value = "/task/add", produces = "application/json; charset=UTF-8")
public CommonResponse addTaskContent(@RequestBody String stepCode){
iEmergencyTaskService.saveTask(stepCode, null);
return CommonResponseUtil.success();
}
}
......@@ -48,4 +48,6 @@ public interface ContingencyPlanInstanceMapper extends BaseMapper<ContingencyPla
String getInstanceIdByBatchNOAndCategory(@Param("recordType") String recordType, @Param("category") String category, @Param("batchNo") String batchNo);
Boolean updateTaskStatusById(@Param("id") String id, @Param("content") String content, Boolean runStatus, @Param("userName") String userName, @Param("userId") String userId, @Param("personImg") String personImg, @Param("fileType") String fileType, @Param("roleNames") String roleNames);
Integer getPlanInstanceByRunState(@Param("stepCode") String stepCode, @Param("batchNo") String batchNo);
}
package com.yeejoin.amos.fas.business.dao.mapper;
import com.yeejoin.amos.fas.business.vo.EmergencyTaskContentVo;
import com.yeejoin.amos.fas.dao.entity.EmergencyRelation;
import com.yeejoin.amos.fas.dao.entity.EmergencyRelationTree;
import com.yeejoin.amos.fas.dao.entity.EmergencyTaskContent;
import org.apache.ibatis.annotations.Param;
import java.util.List;
......@@ -22,4 +24,8 @@ public interface EmergencyTaskMapper extends BaseMapper {
List<String> roleNames(String amosOrgId);
List<EmergencyTaskContentVo> getContentList(@Param("stepCode") String stepCode);
List<EmergencyTaskContentVo> getMustTaskList(@Param("stepCode") String stepCode);
}
......@@ -28,6 +28,7 @@ import com.yeejoin.amos.fas.common.enums.PlanReplyMessageEnum;
import com.yeejoin.amos.fas.core.util.ResponseModel;
import com.yeejoin.amos.fas.dao.entity.ContingencyOriginalData;
import com.yeejoin.amos.fas.dao.entity.ContingencyPlanInstance;
import com.yeejoin.amos.fas.dao.entity.EmergencyTaskContent;
import com.yeejoin.amos.fas.dao.entity.Equipment;
import com.yeejoin.amos.fas.datasync.bo.ContingencyOriginalDataSyncBo;
import com.yeejoin.amos.feign.privilege.Privilege;
......@@ -451,6 +452,7 @@ public class ContingencyInstanceImpl implements IContingencyInstance {
@Override
public void updateStep(String step, String batchNo) {
int update = iContingencyOriginalDataDao.updateByButtonStep(step, batchNo);
emergencyTaskService.saveTask(step, batchNo);
// 异步数据同步之消息发送
// contingencyOriginalDataDataSync(batchNo, update);
}
......@@ -514,12 +516,12 @@ public class ContingencyInstanceImpl implements IContingencyInstance {
@Override
public Optional<Equipment> clickButton(String batchNo, String stepCode, String buttonJson, String contingencyPlanId, String buttonCode, String buttonState, String stepStateOnbutton, String isExecute, String isAuto, String token, String product, String appKey,String startUserName) throws Exception {
String json;
try {
json = IOUtils.toString(planStepNodeResource.getInputStream(), String.valueOf(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new RuntimeException("获取预案节点信息失败!");
}
// String json;
// try {
// json = IOUtils.toString(planStepNodeResource.getInputStream(), String.valueOf(StandardCharsets.UTF_8));
// } catch (IOException e) {
// throw new RuntimeException("获取预案节点信息失败!");
// }
if ("0".equals(stepCode)) {
contingencyInstance.fire(batchNo, stepCode, buttonJson, contingencyPlanId,
......@@ -527,10 +529,10 @@ public class ContingencyInstanceImpl implements IContingencyInstance {
product, appKey, startUserName);
}
JSONObject jsonObject = JSONObject.parseObject(json);
List<String> nodes = Arrays.stream(jsonObject.get("nodes").toString().split(",")).collect(Collectors.toList());
// JSONObject jsonObject = JSONObject.parseObject(json);
// List<String> nodes = Arrays.stream(jsonObject.get("nodes").toString().split(",")).collect(Collectors.toList());
// List<String> strs = nodes.stream().filter(x -> x.equals(stepCode)).collect(Collectors.toList());
List<String> strs = nodes.stream().filter(x -> x.equals(stepCode)).collect(Collectors.toList());
ContingencyPlanInstance instance = contingencyPlanInstanceMapper.getMessageById(contingencyPlanId);
instance.setId(null);
instance.setRecordType("REPLYMESSAGE");
......@@ -538,7 +540,9 @@ public class ContingencyInstanceImpl implements IContingencyInstance {
instance.setContent(instance.getCategory());
ContingencyPlanInstance res = repository.save(instance);
if (!ObjectUtils.isEmpty(res)) {
if (0 < strs.size()) {
List<EmergencyTaskContentVo> mustTasks = emergencyTaskService.getMustTaskList(stepCode);
boolean flag = judgeIfConfirmed(mustTasks, batchNo);
if (!"-1".equals(stepCode) && flag) {
PlanExecuteVo vo = new PlanExecuteVo();
vo.setConfirm(buttonState);
vo.setStepState(stepStateOnbutton);
......@@ -583,10 +587,8 @@ public class ContingencyInstanceImpl implements IContingencyInstance {
planTask = Objects.requireNonNull(redisTemplate.opsForValue().get("planTask")).toString();
} else {
List<ContingencyPlanInstanceVO> lists = planVisual3dService.getTaskActionList(batchNo, 1);
if (0 < nodes.size()) {
planTask = JSON.toJSONString(lists);
}
}
JSONArray taskObjects = JSON.parseArray(planTask);
result.put("planTask", taskObjects);
webMqttComponent.publish(topic, JSON.toJSONString(result));
......@@ -602,6 +604,19 @@ public class ContingencyInstanceImpl implements IContingencyInstance {
return Optional.empty();
}
private boolean judgeIfConfirmed(List<EmergencyTaskContentVo> mustTasks, String batchNo) {
if (0 == mustTasks.size()) {
return true;
}
EmergencyTaskContentVo vo = mustTasks.get(0);
Integer count = contingencyPlanInstanceMapper.getPlanInstanceByRunState(vo.getStepCode(), batchNo);
if (0 == count) {
return true;
} else {
return false;
}
}
@Autowired
List<EventHandler> handlers;
......
......@@ -116,6 +116,9 @@ public class ContingencyPlanServiceImpl implements IContingencyPlanService {
@Autowired
private RedisTemplate<String, String> redisTemplate;
@Autowired
private IEmergencyTaskService emergencyTaskService;
@Autowired
public ContingencyPlanServiceImpl(IPlanDetailDao planDetailDao, IPlanDocDao planDocDao, IPlanEquipmentDao planEquipmentDao,
......@@ -256,6 +259,7 @@ public class ContingencyPlanServiceImpl implements IContingencyPlanService {
@Override
public void afterCommit() {
equipmentHandlerService.executeDynamicPlan(batchNo, deviceData, equipment, equipmentSpecific, toke, operationRecord.getId());
emergencyTaskService.saveTask("-2", batchNo);
}
});
......
package com.yeejoin.amos.fas.business.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.yeejoin.amos.fas.business.action.ContingencyAction;
import com.yeejoin.amos.fas.business.action.model.ContingencyRo;
import com.yeejoin.amos.fas.business.action.mq.WebMqttComponent;
import com.yeejoin.amos.fas.business.dao.mapper.ContingencyPlanInstanceMapper;
import com.yeejoin.amos.fas.business.dao.mapper.EmergencyTaskMapper;
import com.yeejoin.amos.fas.business.dao.mapper.PlanOperationRecordMapper;
import com.yeejoin.amos.fas.business.dao.repository.IContingencyPlanInstanceRepository;
import com.yeejoin.amos.fas.business.dao.repository.IPlanOperationRecordDao;
import com.yeejoin.amos.fas.business.service.intfc.IContingencyInstance;
import com.yeejoin.amos.fas.business.service.intfc.IEmergencyTaskService;
import com.yeejoin.amos.fas.business.service.intfc.IPlanStepService;
import com.yeejoin.amos.fas.business.service.intfc.IPlanVisual3dService;
import com.yeejoin.amos.fas.business.vo.ContingencyPlanInstanceVO;
import com.yeejoin.amos.fas.business.vo.EmergencyTaskContentVo;
import com.yeejoin.amos.fas.business.vo.MessageVO;
import com.yeejoin.amos.fas.core.common.request.CommonPageable;
import com.yeejoin.amos.fas.core.util.StringUtil;
import com.yeejoin.amos.fas.dao.entity.ContingencyPlanInstance;
import com.yeejoin.amos.fas.dao.entity.EmergencyRelation;
import com.yeejoin.amos.fas.dao.entity.EmergencyRelationTree;
import com.yeejoin.amos.fas.dao.entity.EmergencyTaskContent;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;
@Service
public class EmergencyTaskServiceImpl implements IEmergencyTaskService {
public static final Logger log = LoggerFactory.getLogger(EmergencyTaskServiceImpl.class);
@Autowired
EmergencyTaskMapper emergencyTaskMapper;
@Autowired
private IContingencyInstance iContingencyInstance;
@Autowired
private IPlanOperationRecordDao planOperationRecordDao;
@Autowired
private IContingencyPlanInstanceRepository contingencyPlanInstanceRepository;
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private IPlanVisual3dService planVisual3dService;
@Autowired
private IPlanStepService planStepService;
@Autowired
private WebMqttComponent webMqttComponent;
@Autowired
private PlanOperationRecordMapper planOperationRecordMapper;
@Value("${spring.application.name}")
private String serviceName;
@Value("${station.name}")
private String stationName;
@Override
public Page<EmergencyTaskContent> list(Long obligationId, CommonPageable pageable) {
int total = emergencyTaskMapper.getEmergencyTaskCount(obligationId);
......@@ -37,7 +94,7 @@ public class EmergencyTaskServiceImpl implements IEmergencyTaskService {
@Override
public void deleteTreeNode(Long obligationId, Long personId) {
emergencyTaskMapper.deleteTreeNode(obligationId , personId);
emergencyTaskMapper.deleteTreeNode(obligationId, personId);
}
@Override
......@@ -64,4 +121,84 @@ public class EmergencyTaskServiceImpl implements IEmergencyTaskService {
return emergencyTaskMapper.getPersonIds(obligationId);
}
@Override
@Async
public void saveTask(String stepCode, String batchId) {
List<EmergencyTaskContentVo> list = emergencyTaskMapper.getContentList(stepCode);
if (0 < list.size()) {
String batchNo = StringUtil.isNotEmpty(batchId) ? batchId : planOperationRecordMapper.getLastBatchNo();
if (!findByBatchNoAndStatus(batchNo)) {
for (EmergencyTaskContentVo vo : list) {
String taskName = vo.getContent();
String roleCode = vo.getRoleCode();
Integer taskNum = Integer.valueOf(vo.getTaskNum());
String buttonJson = vo.getButtonJson();
String instanceId = iContingencyInstance.getInstanceIdByBatchNOAndCategory("TASKOPERATE", taskName, batchNo);
if (!StringUtils.isEmpty(instanceId)) {
return;
}
ContingencyPlanInstance contingencyPlanInstance = new ContingencyPlanInstance();
contingencyPlanInstance.setBatchNo(batchNo);
contingencyPlanInstance.setRecordType("TASKOPERATE");
contingencyPlanInstance.setRoleCode(roleCode);
contingencyPlanInstance.setCategory(taskName);
contingencyPlanInstance.setCreateDate(new Date());
contingencyPlanInstance.setTaskSort(taskNum);
contingencyPlanInstance.setStepCode(stepCode);
contingencyPlanInstance.setContent(buttonJson);
contingencyPlanInstanceRepository.save(contingencyPlanInstance);
if ("0".equals(stepCode)) {
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
@Override
public void afterCommit() {
String planStep = "";
if (redisTemplate.hasKey("planStep")) {
planStep = Objects.requireNonNull(redisTemplate.opsForValue().get("planStep")).toString();
} else {
planStep = planStepService.getPlanStep();
}
JSONArray objects = JSON.parseArray(planStep);
String topic = String.format("/%s/%s/%s", serviceName, stationName, "plan");
Map<String, Object> result = new HashMap<>();
result.put("contingency", new ContingencyRo());
result.put("msgContext", Collections.EMPTY_MAP);
result.put("msgType", "getStepList");
result.put("planStep", objects);
String planTask = "";
if (redisTemplate.hasKey("planTask")) {
planTask = Objects.requireNonNull(redisTemplate.opsForValue().get("planTask")).toString();
} else {
List<ContingencyPlanInstanceVO> lists = planVisual3dService.getTaskActionList(batchNo, 1);
planTask = JSON.toJSONString(lists);
}
JSONArray taskObjects = JSON.parseArray(planTask);
result.put("planTask", taskObjects);
webMqttComponent.publish(topic, JSON.toJSONString(result));
}
});
}
MessageVO messageVO = new MessageVO();
messageVO.setTitle("应急处置事项提醒");
messageVO.setBody("【" + taskName + "】" + DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
messageVO.setMsgType("emergencyPlan");
messageVO.setCategory(1);
messageVO.setIsSendApp(true);
messageVO.setIsSendWeb(true);
messageVO.setRelationId(batchNo);
planVisual3dService.sendMessage(roleCode, messageVO);
}
}
}
}
private Boolean findByBatchNoAndStatus(String batchNo) {
return CollectionUtils.isEmpty(planOperationRecordDao.findByBatchNoAndStatus(batchNo, 0));
}
@Override
public List<EmergencyTaskContentVo> getMustTaskList(String stepCode) {
return emergencyTaskMapper.getMustTaskList(stepCode);
}
}
package com.yeejoin.amos.fas.business.service.intfc;
import com.yeejoin.amos.fas.business.vo.EmergencyTaskContentVo;
import com.yeejoin.amos.fas.core.common.request.CommonPageable;
import com.yeejoin.amos.fas.dao.entity.EmergencyRelation;
import com.yeejoin.amos.fas.dao.entity.EmergencyRelationTree;
......@@ -25,4 +26,7 @@ public interface IEmergencyTaskService {
String getRolesNameByUserId(String userId);
void saveTask(String stepCode, String batchNo);
List<EmergencyTaskContentVo> getMustTaskList(String stepCode);
}
package com.yeejoin.amos.fas.business.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* @author keyong
* @title: EmergencyTaskContentVo
* <pre>
* @description: TODO
* </pre>
* @date 2023/6/20 14:24
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class EmergencyTaskContentVo {
private Long id;
private String content;
private String code;
private Date createDate;
private Integer obligationId;
private String obligationName;
private String stepCode;
private String roleCode;
private String buttonJson;
private String taskNum;
private boolean isMust = false;
}
......@@ -453,4 +453,20 @@
</if>
limit 1
</select>
<select id="getPlanInstanceByRunState" resultType="Integer">
SELECT
COUNT(1)
FROM
contingency_plan_instance
<where>
runstate = false AND record_type = 'TASKOPERATE'
<if test="stepCode != null and stepCode != ''">
AND step_code = #{stepCode}
</if>
<if test="batchNo != null and batchNo != ''">
AND batch_no = #{batchNo}
</if>
</where>
</select>
</mapper>
\ No newline at end of file
......@@ -98,10 +98,36 @@
</where>
</delete>
<insert id="save" parameterType="com.yeejoin.amos.fas.dao.entity.EmergencyRelation">
INSERT INTO `c_emergency_relation`(id, `obligationId`, `person_id`, `amos_id`, `person_name`, `create_date`)
VALUES (#{id}, #{obligationId}, #{personId}, #{amosOrgId}, #{personName},#{createDate});
</insert>
<select id="getContentList" resultType="com.yeejoin.amos.fas.business.vo.EmergencyTaskContentVo">
SELECT
*
FROM
c_emergency_task_content
<where>
<if test="stepCode != null and stepCode != ''">
step_code = #{stepCode}
</if>
<if test="stepCode != null and stepCode != '' and stepCode == '-2'">
step_code = -1 OR step_code = 0
</if>
</where>
</select>
<select id="getMustTaskList" resultType="com.yeejoin.amos.fas.business.vo.EmergencyTaskContentVo">
SELECT
*
FROM
c_emergency_task_content
<where>
is_must = true
<if test="stepCode != null and stepCode != ''">
and step_code = #{stepCode}
</if>
</where>
</select>
</mapper>
\ No newline at end of file
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