Browse Source

#定时任务抽离

zhongwei
yang_shj 1 year ago
parent
commit
407c7c5f52
  1. 6
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/entity/OperAccessPlanEntity.java
  2. 17
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/AccessPlanV4ClientFallback.java
  3. 17
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/AccessTaskV4ClientFallback.java
  4. 25
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/IAccessPlanV4Client.java
  5. 25
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/IAccessTaskV4Client.java
  6. 1
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/ShowScheduledTask.java
  7. 34
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/ticket/impl/WorkTicketServiceImpl.java
  8. 38
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/controller/AccessPlanV4Controller.java
  9. 19
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/controller/AccessV4Controller.java
  10. 24
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/dto/AccessPlanV4DTO.java
  11. 39
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/dto/AccessTaskV4DTO.java
  12. 34
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/feign/AccessPlanV4Client.java
  13. 35
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/feign/AccessTaskV4Client.java
  14. 14
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/AccessPlanV4Service.java
  15. 14
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/AccessTaskV4Service.java
  16. 212
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/AccessPlanV4ServiceImpl.java
  17. 160
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/AccessTaskV4ServiceImpl.java

6
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/entity/OperAccessPlanEntity.java

@ -135,4 +135,10 @@ public class OperAccessPlanEntity extends TenantEntity {
@ApiModelProperty("票据模板ID")
private Long ticketTemplateId;
@ApiModelProperty("当前步骤任务名称")
private String taskName;
@ApiModelProperty("当前环节处理人")
private String nextStepOperator;
}

17
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/AccessPlanV4ClientFallback.java

@ -0,0 +1,17 @@
package com.hnac.hzims.operational.access.feign;
import com.hnac.hzims.common.to.process.ProcessWorkFlowResponse;
import org.springblade.core.tool.api.R;
import org.springframework.stereotype.Component;
/**
* @author ysj
*/
@Component
public class AccessPlanV4ClientFallback implements IAccessPlanV4Client {
@Override
public R<Boolean> listener(ProcessWorkFlowResponse processWorkFlowResponse) {
return R.fail("执行失败!");
}
}

17
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/AccessTaskV4ClientFallback.java

@ -0,0 +1,17 @@
package com.hnac.hzims.operational.access.feign;
import com.hnac.hzims.common.to.process.ProcessWorkFlowResponse;
import org.springblade.core.tool.api.R;
import org.springframework.stereotype.Component;
/**
* @author ysj
*/
@Component
public class AccessTaskV4ClientFallback implements IAccessTaskV4Client {
@Override
public R<Boolean> listener(ProcessWorkFlowResponse processWorkFlowResponse) {
return R.fail("执行失败!");
}
}

25
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/IAccessPlanV4Client.java

@ -0,0 +1,25 @@
package com.hnac.hzims.operational.access.feign;
import com.hnac.hzims.common.to.process.ProcessWorkFlowResponse;
import com.hnac.hzims.operational.OperationalConstants;
import org.springblade.core.tool.api.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
/**
* @author ysj
*/
@FeignClient(
value = OperationalConstants.APP_NAME,
fallback = AccessTaskClientFallback.class
)
public interface IAccessPlanV4Client {
String API_PREFIX = "/feign/accessPlanV4";
String PLAN_PROCESS_LISTENER = API_PREFIX + "listener";
@PostMapping(PLAN_PROCESS_LISTENER)
R<Boolean> listener(@RequestBody ProcessWorkFlowResponse processWorkFlowResponse);
}

25
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/access/feign/IAccessTaskV4Client.java

@ -0,0 +1,25 @@
package com.hnac.hzims.operational.access.feign;
import com.hnac.hzims.common.to.process.ProcessWorkFlowResponse;
import com.hnac.hzims.operational.OperationalConstants;
import org.springblade.core.tool.api.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
/**
* @author ysj
*/
@FeignClient(
value = OperationalConstants.APP_NAME,
fallback = AccessTaskClientFallback.class
)
public interface IAccessTaskV4Client {
String API_PREFIX = "/feign/accessTaskV4";
String PLAN_PROCESS_LISTENER = API_PREFIX + "listener";
@PostMapping(PLAN_PROCESS_LISTENER)
R<Boolean> listener(@RequestBody ProcessWorkFlowResponse processWorkFlowResponse);
}

1
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/ShowScheduledTask.java

@ -42,6 +42,7 @@ public class ShowScheduledTask {
* 首页-区域班组数据
*/
@XxlJob(REGIONAL_DUTY_INFO)
//@Scheduled(cron = "0/40 * * * * ? ")
public ReturnT<String> loadRegionalDuty(String param) {
if (Func.isBlank(param)) {
param = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss");

34
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/ticket/impl/WorkTicketServiceImpl.java

@ -12,6 +12,7 @@ import com.hnac.hzims.ticket.workTicket.entity.WorkTicketDelayEntity;
import com.hnac.hzims.ticket.workTicket.entity.WorkTicketInfoEntity;
import com.hnac.hzims.ticket.workTicket.entity.WorkTicketPrincipalChangeEntity;
import com.hnac.hzims.ticket.workTicket.vo.WorkTicketStatisticVO;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.mp.base.BaseServiceImpl;
@ -29,12 +30,12 @@ import java.util.stream.Collectors;
*/
@Service
@Slf4j
@RequiredArgsConstructor
@AllArgsConstructor
@DS("ticket")
public class WorkTicketServiceImpl extends BaseServiceImpl<WorkTicketMapper, WorkTicketInfoEntity> implements WorkTicketService {
private WorkPrincipalService workPrincipalService;
private WorkDelayService workDelayService;
private final WorkPrincipalService workPrincipalService;
private final WorkDelayService workDelayService;
@Override
public WorkTicketStatisticVO work(String start, String end, List<Long> areas) {
@ -55,31 +56,22 @@ public class WorkTicketServiceImpl extends BaseServiceImpl<WorkTicketMapper, Wor
List<WorkTicketInfoEntity> completeList = infoList.stream().filter(w -> TicketConstants.FirstWorkTicketFlowStatusEnum.FINISH.getStatus().equals(w.getStatus()))
.collect(Collectors.toList());
work.setComplete(CollectionUtil.isNotEmpty(completeList) ? completeList.size() : 0);
//工作票移交
FutureTask transferTask = new FutureTask(() -> {
int transferTask = 0;
int delayTask = 0;
List<WorkTicketPrincipalChangeEntity> moveList = workPrincipalService.list(new LambdaQueryWrapper<WorkTicketPrincipalChangeEntity>() {{
in(WorkTicketPrincipalChangeEntity::getTicketId, infoIdList);
}});
return CollectionUtil.isNotEmpty(moveList) ? moveList.size() : 0;
});
new Thread(transferTask, "工作票移交Thread").start();
//工作票延期
FutureTask delayTask = new FutureTask(() -> {
log.info("开始工作票延期");
if(CollectionUtil.isNotEmpty(moveList)){
transferTask = moveList.size();
}
List<WorkTicketDelayEntity> delayEntityList = workDelayService.list(Wrappers.<WorkTicketDelayEntity>lambdaQuery()
.in(WorkTicketDelayEntity::getTicketId, infoIdList)
);
return CollectionUtil.isNotEmpty(delayEntityList) ? delayEntityList.size() : 0;
});
new Thread(delayTask, "工作票延期Thread").start();
try {
work.setDelay((Integer) delayTask.get());
work.setTransfer((Integer) transferTask.get());
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
if(CollectionUtil.isNotEmpty(delayEntityList)){
delayTask = delayEntityList.size();
}
work.setDelay(delayTask);
work.setTransfer(transferTask);
}
return work;
}

38
hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/controller/AccessPlanV4Controller.java

@ -0,0 +1,38 @@
package com.hnac.hzims.operational.access.controller;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hnac.hzims.operational.access.dto.AccessPlanV4DTO;
import com.hnac.hzims.operational.access.service.AccessPlanV4Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author ysj
*/
@RestController
@AllArgsConstructor
@RequestMapping("/overhaul_plan")
@Api(tags = "v4检修计划流程")
public class AccessPlanV4Controller extends BladeController {
private final AccessPlanV4Service service;
/**
* v4检修计划流程开启
* @return
*/
@PostMapping("/overhaul_start_v4")
@ApiOperationSupport(order = 1)
@ApiOperation(value = "v4检修计划流程开启")
public R startV4(AccessPlanV4DTO entity) {
return R.status(service.startProcessV4(entity));
}
}

19
hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/controller/AccessV4Controller.java

@ -0,0 +1,19 @@
package com.hnac.hzims.operational.access.controller;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author ysj
*/
@RestController
@AllArgsConstructor
@RequestMapping("/overhaul_task")
@Api(tags = "v4检修计划流程")
public class AccessV4Controller extends BladeController {
}

24
hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/dto/AccessPlanV4DTO.java

@ -0,0 +1,24 @@
package com.hnac.hzims.operational.access.dto;
import com.hnac.hzims.operational.access.entity.OperAccessPlanEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
/**
* @author ysj
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class AccessPlanV4DTO extends OperAccessPlanEntity {
private static final long serialVersionUID = 1L;
@ApiModelProperty("检修材料列表")
private List<OperAccessMaterialDTO> accessMaterials;
@ApiModelProperty("检修内容列表")
private List<OperAccessContentDTO> accessContents;
}

39
hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/dto/AccessTaskV4DTO.java

@ -0,0 +1,39 @@
package com.hnac.hzims.operational.access.dto;
import com.hnac.hzims.operational.access.entity.OperAccessTaskEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
/**
* @author ysj
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class AccessTaskV4DTO extends OperAccessTaskEntity {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "创建机构集合")
private List<Long> deptIds;
@ApiModelProperty(value = "工作流Key")
private String procDefId;
@ApiModelProperty("为1时排除票据ID为空的数据")
private Long excludeNullTicket;
@ApiModelProperty("检修任务详情")
private List<OperAccessTaskDetailDTO> accessTaskDetails;
@ApiModelProperty("检修材料列表")
private List<OperAccessMaterialDTO> accessMaterials;
@ApiModelProperty("开始时间")
private String startTime;
@ApiModelProperty("结束时间")
private String endTime;
}

34
hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/feign/AccessPlanV4Client.java

@ -0,0 +1,34 @@
package com.hnac.hzims.operational.access.feign;
import com.hnac.hzims.common.to.process.ProcessWorkFlowResponse;
import com.hnac.hzims.operational.access.service.AccessPlanV4Service;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author ysj
*/
@RestController
@RequestMapping("/feign/accessPlanV4")
@Slf4j
@RequiredArgsConstructor
public class AccessPlanV4Client implements IAccessPlanV4Client {
private final AccessPlanV4Service service;
/**
* 检修计划流程监听
* @param processWorkFlowResponse
* @return
*/
@Override
@PostMapping("/listener")
public R<Boolean> listener(@RequestBody ProcessWorkFlowResponse processWorkFlowResponse) {
return R.status(service.listener(processWorkFlowResponse));
}
}

35
hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/feign/AccessTaskV4Client.java

@ -0,0 +1,35 @@
package com.hnac.hzims.operational.access.feign;
import com.hnac.hzims.common.to.process.ProcessWorkFlowResponse;
import com.hnac.hzims.operational.access.service.AccessPlanV4Service;
import com.hnac.hzims.operational.access.service.AccessTaskV4Service;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author ysj
*/
@RestController
@RequestMapping("/feign/accessTaskV4")
@Slf4j
@RequiredArgsConstructor
public class AccessTaskV4Client implements IAccessPlanV4Client {
private final AccessTaskV4Service service;
/**
* 检修任务流程监听
* @param processWorkFlowResponse
* @return
*/
@Override
@PostMapping("/listener")
public R<Boolean> listener(@RequestBody ProcessWorkFlowResponse processWorkFlowResponse) {
return R.status(service.listener(processWorkFlowResponse));
}
}

14
hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/AccessPlanV4Service.java

@ -0,0 +1,14 @@
package com.hnac.hzims.operational.access.service;
import com.hnac.hzims.common.to.process.ProcessWorkFlowResponse;
import com.hnac.hzims.operational.access.dto.AccessPlanV4DTO;
/**
* @author ysj
*/
public interface AccessPlanV4Service{
boolean startProcessV4(AccessPlanV4DTO entity);
boolean listener(ProcessWorkFlowResponse processWorkFlowResponse);
}

14
hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/AccessTaskV4Service.java

@ -0,0 +1,14 @@
package com.hnac.hzims.operational.access.service;
import com.hnac.hzims.common.to.process.ProcessWorkFlowResponse;
import com.hnac.hzims.operational.access.dto.AccessTaskV4DTO;
/**
* @author ysj
*/
public interface AccessTaskV4Service {
boolean startProcessV4(AccessTaskV4DTO entity);
boolean listener(ProcessWorkFlowResponse processWorkFlowResponse);
}

212
hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/AccessPlanV4ServiceImpl.java

@ -0,0 +1,212 @@
package com.hnac.hzims.operational.access.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hnac.hzims.common.to.process.ProcessWorkFlowResponse;
import com.hnac.hzims.operational.access.dto.*;
import com.hnac.hzims.operational.access.entity.OperAccessContentEntity;
import com.hnac.hzims.operational.access.entity.OperAccessMaterialEntity;
import com.hnac.hzims.operational.access.service.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomUtils;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.DateUtil;
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.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author ysj
*/
@Service
@Slf4j
@RequiredArgsConstructor
public class AccessPlanV4ServiceImpl implements AccessPlanV4Service{
private final IOperAccessPlanService planService;
private final IOperAccessMaterialService materialService;
private final IOperAccessContentService contentService;
private final AccessTaskV4Service accessTaskV4Service;
private final IFlowClient flowClient;
/**
* 开启检修计划流程
* @param entity
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean startProcessV4(AccessPlanV4DTO entity) {
// 步骤1.保存检修计划
this.saveAccess(entity);
// 步骤2.保存检修材料
this.saveAccessMaterial(entity);
// 步骤3.保存检修明细
this.saveAccessContent(entity);
// 步骤2.开启检修计划流程
this.startProcess(entity);
return true;
}
/**
* 保存检修计划
* @param entity
*/
private void saveAccess(AccessPlanV4DTO entity) {
// 检修计划保存
entity.setCode("PLAN_" + DateUtil.format(DateUtil.now(), DateUtil.PATTERN_DATETIME_MINI) + new DecimalFormat("###").format(RandomUtils.nextInt(0, 999)));
planService.save(entity);
}
/**
* 保存检修材料
* @param entity
*/
private void saveAccessMaterial(AccessPlanV4DTO entity) {
if(CollectionUtils.isEmpty(entity.getAccessMaterials())){
return;
}
// 查询计划是否绑定检修材料
List<OperAccessMaterialEntity> existsDetails = materialService.list(new LambdaQueryWrapper<OperAccessMaterialEntity>() {{
eq(OperAccessMaterialEntity::getPlanId, entity.getId());
eq(OperAccessMaterialEntity::getIsDeleted, 0L);
}});
Set<Long> detailIds = entity.getAccessMaterials().stream().map(OperAccessMaterialDTO::getId).filter(Objects::nonNull).collect(Collectors.toSet());
List<Long> ids = existsDetails.stream().map(OperAccessMaterialEntity::getId).filter(id -> !detailIds.contains(id)).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(ids)) {
materialService.deleteLogic(ids);
}
// 材料添加/修改
for (OperAccessMaterialDTO material : entity.getAccessMaterials()) {
material.setPlanId(entity.getId());
if (ObjectUtil.isEmpty(material.getId())) {
materialService.doSave(material);
continue;
}
materialService.updateById(material);
}
}
/**
* 保存检修明细
* @param entity
*/
private void saveAccessContent(AccessPlanV4DTO entity) {
if(CollectionUtils.isEmpty(entity.getAccessContents())){
return;
}
// 查询计划是否绑定任务明细
List<OperAccessContentEntity> existsDetails = contentService.list(new LambdaQueryWrapper<OperAccessContentEntity>() {{
eq(OperAccessContentEntity::getPlanId, entity.getId());
eq(OperAccessContentEntity::getIsDeleted, 0L);
}});
Set<Long> detailIds = entity.getAccessContents().stream().map(OperAccessContentDTO::getId).filter(Objects::nonNull).collect(Collectors.toSet());
List<Long> ids = existsDetails.stream().map(OperAccessContentEntity::getId).filter(id -> !detailIds.contains(id)).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(ids)) {
contentService.deleteLogic(ids);
}
// 明细添加/修改
for (OperAccessContentDTO content : entity.getAccessContents()) {
content.setPlanId(entity.getId());
if (ObjectUtil.isEmpty(content.getId())) {
contentService.doSave(content);
continue;
}
contentService.doUpdateById(content);
}
}
/**
* 开启检修计划流程
* @param entity
*/
private void startProcess(AccessPlanV4DTO entity) {
Map<String, Object> variables = JSONObject.parseObject(JSONObject.toJSONString(entity), Map.class);
R<BladeFlow> result = flowClient.startProcessInstanceContainNameByKey("overhaul_plan", FlowUtil.getBusinessKey("access_plan_v4",String.valueOf(entity.getId())), entity.getName(), variables);
// 更新任务流程Id
if (result.isSuccess()) {
BladeFlow flow = result.getData();
entity.setProcessInstanceId(flow.getProcessInstanceId());
planService.updateById(entity);
} else {
throw new ServiceException("开启检修计划流程失败,code=" + result.getCode());
}
}
/**
* 检修计划流程监听
* @param processWorkFlowResponse
* @return
*/
@Override
public boolean listener(ProcessWorkFlowResponse processWorkFlowResponse) {
Map<String, Object> variables = (Map<String, Object>) processWorkFlowResponse.getVariables();
AccessPlanV4DTO entity = JSONObject.parseObject(variables.toString(), AccessPlanV4DTO.class);
entity.setTaskName(processWorkFlowResponse.getTaskName());
entity.setNextStepOperator(processWorkFlowResponse.getNextStepOperator());
if((Boolean) variables.get("pass")){
entity.setTaskName("流程结束");
entity.setNextStepOperator("流程结束,不需要人员处理");
// 开启检修任务
this.startTaskProcess(entity);
}
this.saveAccess(entity);
this.saveAccessMaterial(entity);
this.saveAccessContent(entity);
return true;
}
/**
* 开启检修任务
* @param entity
*/
private void startTaskProcess(AccessPlanV4DTO entity) {
for(OperAccessContentDTO item : entity.getAccessContents()){
//任务参数
AccessTaskV4DTO task = BeanUtil.copy(item, AccessTaskV4DTO.class);
task.setCreateTime(new Date());
task.setCreateUser(entity.getCreateUser());
task.setProcDefId(entity.getProcDefId());
task.setHandler(item.getManager());
task.setPlanId(entity.getId());
task.setContentId(item.getId());
task.setEmCode(item.getEmCode());
// 任务详情
if(CollectionUtil.isNotEmpty(item.getAccessContentDetails())){
task.setAccessTaskDetails(item.getAccessContentDetails().stream().map(content -> {
OperAccessTaskDetailDTO detail = new OperAccessTaskDetailDTO();
detail.setContentDetailId(content.getId());
detail.setContent(content.getContent());
detail.setName(content.getName());
return detail;
}).collect(Collectors.toList()));
}
// 材料
if(CollectionUtil.isNotEmpty(entity.getAccessMaterials())){
task.setAccessMaterials(entity.getAccessMaterials().stream().map(o-> BeanUtil.copy(o,OperAccessMaterialDTO.class)).collect(Collectors.toList()));
}
accessTaskV4Service.startProcessV4(task);
}
}
}

160
hzims-service/operational/src/main/java/com/hnac/hzims/operational/access/service/impl/AccessTaskV4ServiceImpl.java

@ -0,0 +1,160 @@
package com.hnac.hzims.operational.access.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hnac.hzims.common.to.process.ProcessWorkFlowResponse;
import com.hnac.hzims.operational.access.dto.AccessTaskV4DTO;
import com.hnac.hzims.operational.access.dto.OperAccessTaskDetailDTO;
import com.hnac.hzims.operational.access.entity.OperAccessMaterialEntity;
import com.hnac.hzims.operational.access.entity.OperAccessTaskDetailEntity;
import com.hnac.hzims.operational.access.service.AccessTaskV4Service;
import com.hnac.hzims.operational.access.service.IOperAccessMaterialService;
import com.hnac.hzims.operational.access.service.IOperAccessTaskDetailService;
import com.hnac.hzims.operational.access.service.IOperAccessTaskService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomUtils;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.DateUtil;
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.flow.core.utils.TaskUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @author ysj
*/
@Service
@Slf4j
@RequiredArgsConstructor
public class AccessTaskV4ServiceImpl implements AccessTaskV4Service {
private final IOperAccessTaskService taskService;
private final IOperAccessMaterialService materialService;
private final IOperAccessTaskDetailService detailService;
private final IFlowClient flowClient;
/**
* 开启检修任务流程
* @param entity
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean startProcessV4(AccessTaskV4DTO entity) {
// 步骤1.保存检修任务
this.save(entity);
// 步骤2.保存检修材料
this.saveMaterial(entity);
// 步骤3.保存检修详情
this.saveDetails(entity);
// 步骤4.开启检修任务流程
this.startProcess(entity);
return true;
}
/**
* 开启检修流程
* @param entity
*/
private void startProcess(AccessTaskV4DTO entity) {
Map<String, Object> variables = JSONObject.parseObject(JSONObject.toJSONString(entity), Map.class);
variables.put("handler",TaskUtil.getTaskUser(entity.getHandler().toString()));
R<BladeFlow> result = flowClient.startProcessInstanceContainNameByKey("overhaul_task", FlowUtil.getBusinessKey("access_task_v4", String.valueOf(entity.getId())), entity.getName(),variables);
// 更新任务流程Id
if (result.isSuccess()) {
BladeFlow flow = result.getData();
entity.setProcessInstanceId(flow.getProcessInstanceId());
taskService.updateById(entity);
} else {
throw new ServiceException("开启检修任务流程失败,code=" + result.getCode());
}
}
/**
* 检修任务保存
* @param entity
*/
private void save(AccessTaskV4DTO entity) {
entity.setCode("TASK" + DateUtil.format(DateUtil.now(), DateUtil.PATTERN_DATETIME_MINI) + new DecimalFormat("###").format(RandomUtils.nextInt(0, 999)));
List<OperAccessMaterialEntity> materialEntityList = JSONObject.parseArray(JSON.toJSONString(entity.getAccessMaterials()), OperAccessMaterialEntity.class);
taskService.save(entity);
}
/**
* 保存检修材料
* @param entity
*/
private void saveMaterial(AccessTaskV4DTO entity) {
if (CollectionUtil.isNotEmpty(entity.getAccessMaterials())) {
return;
}
materialService.saveOrUpdateBatch(entity.getAccessMaterials().stream().peek(material -> {
material.setPlanId(null);
material.setId(null);
material.setTaskId(entity.getId());
}).collect(Collectors.toList()));
}
/**
* 保存检修对象
* @param entity
*
*/
private void saveDetails(AccessTaskV4DTO entity) {
if(CollectionUtil.isEmpty(entity.getAccessTaskDetails())){
return;
}
// 查询检修任务关联的检修对象
List<OperAccessTaskDetailEntity> existsDetails = detailService.list(new LambdaQueryWrapper<OperAccessTaskDetailEntity>() {{
eq(OperAccessTaskDetailEntity::getTaskId, entity.getId());
eq(OperAccessTaskDetailEntity::getIsDeleted, 0L);
}});
Set<Long> detailIds = entity.getAccessTaskDetails().stream().map(OperAccessTaskDetailDTO::getId).filter(Objects::nonNull).collect(Collectors.toSet());
List<Long> ids = existsDetails.stream().map(OperAccessTaskDetailEntity::getId).filter(id -> !detailIds.contains(id)).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(ids)) {
detailService.deleteLogic(ids);
}
// 检修任务对象
Set<Long> existsIds = existsDetails.stream().map(OperAccessTaskDetailEntity::getId).collect(Collectors.toSet());
for (OperAccessTaskDetailDTO details : entity.getAccessTaskDetails()) {
details.setTaskId(entity.getId());
if (ObjectUtil.isNotEmpty(entity.getId())) {
detailService.updateById(details);
continue;
}
detailService.doSave(details);
}
}
/**
* 检修任务流程监听
* @param processWorkFlowResponse
* @return
*/
@Override
public boolean listener(ProcessWorkFlowResponse processWorkFlowResponse) {
return false;
}
}
Loading…
Cancel
Save