Browse Source
# Conflicts: # hzims-service-api/middle-api/src/main/java/com/hnac/hzims/middle/process/constant/TicketProcessConstant.javazhongwei
tyty
1 year ago
39 changed files with 1022 additions and 92 deletions
@ -0,0 +1,17 @@
|
||||
package com.hnac.hzims.operational.access.feign; |
||||
|
||||
import com.hnac.hzims.middle.process.to.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("执行失败!"); |
||||
} |
||||
} |
@ -0,0 +1,17 @@
|
||||
package com.hnac.hzims.operational.access.feign; |
||||
|
||||
import com.hnac.hzims.middle.process.to.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("执行失败!"); |
||||
} |
||||
} |
@ -0,0 +1,25 @@
|
||||
package com.hnac.hzims.operational.access.feign; |
||||
|
||||
import com.hnac.hzims.middle.process.to.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 = AccessPlanV4ClientFallback.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); |
||||
} |
@ -0,0 +1,25 @@
|
||||
package com.hnac.hzims.operational.access.feign; |
||||
|
||||
import com.hnac.hzims.middle.process.to.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 = AccessTaskV4ClientFallback.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); |
||||
} |
@ -0,0 +1,56 @@
|
||||
package com.hnac.hzims.middle.processflow.strategy.serviceimpl; |
||||
|
||||
import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; |
||||
import com.hnac.hzims.middle.processflow.service.ProcessDictService; |
||||
import com.hnac.hzims.middle.processflow.strategy.abstracts.ProcessAbstractService; |
||||
import com.hnac.hzims.middle.processflow.strategy.entity.WorkflowQueue; |
||||
import com.hnac.hzims.operational.access.feign.IAccessPlanV4Client; |
||||
import com.hnac.hzims.operational.defect.feign.IOperDefectClient; |
||||
import lombok.RequiredArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.core.log.exception.ServiceException; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import static com.hnac.hzims.middle.process.constant.TicketProcessConstant.DEFECT_KEY; |
||||
import static com.hnac.hzims.middle.process.constant.TicketProcessConstant.OVERHAUL_PLAN; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@Slf4j |
||||
@Service |
||||
@RequiredArgsConstructor |
||||
public class OverhaulPlanServiceImpl extends ProcessAbstractService { |
||||
|
||||
|
||||
private final IAccessPlanV4Client accessPlanV4Client; |
||||
|
||||
|
||||
private final ProcessDictService processDictService; |
||||
|
||||
|
||||
/** |
||||
* 消息确认 |
||||
* @param flowQueue |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public Boolean isWorkflowProcess(WorkflowQueue flowQueue) { |
||||
String dictValue = processDictService.selectDictValueByKey(OVERHAUL_PLAN); |
||||
return dictValue.equals(flowQueue.getProcessDefinitionKey()); |
||||
} |
||||
|
||||
/** |
||||
* 两票管理业务方法 |
||||
* |
||||
* @param response |
||||
*/ |
||||
@Override |
||||
public void calculate(ProcessWorkFlowResponse response) { |
||||
R defect = accessPlanV4Client.listener(response); |
||||
if (!defect.isSuccess()) { |
||||
throw new ServiceException("检修计划业务执行异常!"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,56 @@
|
||||
package com.hnac.hzims.middle.processflow.strategy.serviceimpl; |
||||
|
||||
import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; |
||||
import com.hnac.hzims.middle.processflow.service.ProcessDictService; |
||||
import com.hnac.hzims.middle.processflow.strategy.abstracts.ProcessAbstractService; |
||||
import com.hnac.hzims.middle.processflow.strategy.entity.WorkflowQueue; |
||||
import com.hnac.hzims.operational.access.feign.IAccessPlanV4Client; |
||||
import com.hnac.hzims.operational.access.feign.IAccessTaskV4Client; |
||||
import com.hnac.hzims.operational.defect.feign.IOperDefectClient; |
||||
import lombok.RequiredArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.core.log.exception.ServiceException; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import static com.hnac.hzims.middle.process.constant.TicketProcessConstant.*; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
@Slf4j |
||||
@Service |
||||
@RequiredArgsConstructor |
||||
public class OverhaulTaskServiceImpl extends ProcessAbstractService { |
||||
|
||||
|
||||
private final IAccessTaskV4Client accessTaskV4Client; |
||||
|
||||
|
||||
private final ProcessDictService processDictService; |
||||
|
||||
|
||||
/** |
||||
* 消息确认 |
||||
* @param flowQueue |
||||
* @return |
||||
*/ |
||||
@Override |
||||
public Boolean isWorkflowProcess(WorkflowQueue flowQueue) { |
||||
String dictValue = processDictService.selectDictValueByKey(OVERHAUL_TASK); |
||||
return dictValue.equals(flowQueue.getProcessDefinitionKey()); |
||||
} |
||||
|
||||
/** |
||||
* 调用检修业务处理 |
||||
* @param response |
||||
*/ |
||||
@Override |
||||
public void calculate(ProcessWorkFlowResponse response) { |
||||
R defect = accessTaskV4Client.listener(response); |
||||
if (!defect.isSuccess()) { |
||||
throw new ServiceException("检修任务业务执行异常!"); |
||||
|
||||
} |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
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.RequestBody; |
||||
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(@RequestBody AccessPlanV4DTO entity) { |
||||
return R.status(service.startProcessV4(entity)); |
||||
} |
||||
} |
@ -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 { |
||||
|
||||
} |
@ -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; |
||||
} |
@ -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; |
||||
} |
@ -0,0 +1,34 @@
|
||||
package com.hnac.hzims.operational.access.feign; |
||||
|
||||
import com.hnac.hzims.middle.process.to.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)); |
||||
} |
||||
} |
@ -0,0 +1,34 @@
|
||||
package com.hnac.hzims.operational.access.feign; |
||||
|
||||
import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; |
||||
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 IAccessTaskV4Client { |
||||
|
||||
private final AccessTaskV4Service service; |
||||
|
||||
/** |
||||
* 检修任务流程监听 |
||||
* @param processWorkFlowResponse |
||||
* @return |
||||
*/ |
||||
@Override |
||||
@PostMapping("/listener") |
||||
public R<Boolean> listener(@RequestBody ProcessWorkFlowResponse processWorkFlowResponse) { |
||||
return R.status(service.listener(processWorkFlowResponse)); |
||||
} |
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.hnac.hzims.operational.access.service; |
||||
|
||||
import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; |
||||
import com.hnac.hzims.operational.access.dto.AccessPlanV4DTO; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
public interface AccessPlanV4Service{ |
||||
|
||||
boolean startProcessV4(AccessPlanV4DTO entity); |
||||
|
||||
boolean listener(ProcessWorkFlowResponse processWorkFlowResponse); |
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.hnac.hzims.operational.access.service; |
||||
|
||||
import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse; |
||||
import com.hnac.hzims.operational.access.dto.AccessTaskV4DTO; |
||||
|
||||
/** |
||||
* @author ysj |
||||
*/ |
||||
public interface AccessTaskV4Service { |
||||
|
||||
boolean startProcessV4(AccessTaskV4DTO entity); |
||||
|
||||
boolean listener(ProcessWorkFlowResponse processWorkFlowResponse); |
||||
} |
@ -0,0 +1,223 @@
|
||||
package com.hnac.hzims.operational.access.service.impl; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.alibaba.fastjson.TypeReference; |
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.hnac.hzims.middle.process.to.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.secure.utils.AuthUtil; |
||||
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.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.*; |
||||
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))); |
||||
entity.setProcDefId("overhaul_plan"); |
||||
entity.setActStartTime(new Date()); |
||||
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.toJSONStringWithDateFormat(entity,DateUtil.PATTERN_DATETIME), Map.class); |
||||
variables.put("creator", TaskUtil.getTaskUser(String.valueOf(AuthUtil.getUserId()))); |
||||
R<BladeFlow> result = flowClient.startProcessInstanceContainNameByKey("overhaul_plan", FlowUtil.getBusinessKey("access_plan_v4",String.valueOf(entity.getId())), entity.getName(), variables); |
||||
log.error("start_process_planV4 :{}",result); |
||||
// 更新任务流程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(JSONObject.toJSONString(variables), new TypeReference<AccessPlanV4DTO>(){}); |
||||
// 当前流程名称
|
||||
entity.setTaskName(processWorkFlowResponse.getTaskName()); |
||||
// 流程阶段执行人员名称
|
||||
entity.setNextStepOperator(processWorkFlowResponse.getNextStepOperator()); |
||||
if(ObjectUtil.isNotEmpty(variables.get("examine")) && (Boolean) variables.get("examine")){ |
||||
entity.setTaskName("流程结束"); |
||||
entity.setNextStepOperator("流程结束,无需人员处理"); |
||||
entity.setActEndTime(new Date()); |
||||
// 开启检修任务
|
||||
this.startTaskProcess(entity); |
||||
} |
||||
this.planService.updateById(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); |
||||
} |
||||
} |
||||
} |
@ -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.middle.process.to.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…
Reference in new issue