Browse Source

#缺陷、巡检统计

zhongwei
yang_shj 1 year ago
parent
commit
a6a9eefabc
  1. 20
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/vo/SolveHomeVO.java
  2. 4
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/AccessService.java
  3. 3
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/DefectService.java
  4. 45
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/AccessServiceImpl.java
  5. 44
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/DefectServiceImpl.java
  6. 27
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ShowServiceImpl.java
  7. 2
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/impl/ReportServiceImpl.java
  8. 33
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/IDefectCheckService.java
  9. 553
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/DefectCheckServiceImpl.java
  10. 2
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/MainTaskStatisticServiceImpl.java

20
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/vo/SolveHomeVO.java

@ -0,0 +1,20 @@
package com.hnac.hzims.operational.defect.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author ysj
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class SolveHomeVO {
@ApiModelProperty(value = "缺陷数量")
private Integer defectCount;
@ApiModelProperty(value = "消缺完成数量")
private Integer solveCount;
}

4
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/AccessService.java

@ -11,7 +11,5 @@ import java.util.List;
*/
public interface AccessService extends BaseService<OperAccessTaskEntity> {
double accessCount(List<Long> areas);
OverhaulVo overhaul(String start, String end, List<Long> areas);
OverhaulVo overhaul_count(List<Long> areas,String start, String end);
}

3
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/DefectService.java

@ -1,6 +1,7 @@
package com.hnac.hzims.scheduled.service.operation.business;
import com.hnac.hzims.operational.defect.entity.OperDefectEntity;
import com.hnac.hzims.operational.defect.vo.SolveHomeVO;
import org.springblade.core.mp.base.BaseService;
import java.util.List;
@ -10,5 +11,5 @@ import java.util.List;
*/
public interface DefectService extends BaseService<OperDefectEntity> {
Double defectCount(List<Long> areas);
SolveHomeVO solve_count(List<Long> deptIds, String start, String end);
}

45
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/AccessServiceImpl.java

@ -28,40 +28,15 @@ import java.util.stream.Collectors;
public class AccessServiceImpl extends BaseServiceImpl<AccessMapper, OperAccessTaskEntity> implements AccessService {
/**
* 查询当年检修任务数量
* 巡检数量统计
* @param areas
* @return
*/
@Override
public double accessCount(List<Long> areas) {
if(CollectionUtil.isEmpty(areas)) {
return 0;
}
LocalDate firstDay = LocalDate.now().withDayOfYear(1);
LocalDateTime firstDateTime = LocalDateTime.of(firstDay, LocalTime.MIN);
LocalDateTime now = LocalDateTime.now();
//日常维护
List<OperAccessTaskEntity> accesss = this.list(new LambdaQueryWrapper<OperAccessTaskEntity>(){{
ge(OperAccessTaskEntity::getPlanStartTime,firstDateTime);
le(OperAccessTaskEntity::getPlanStartTime,now);
in(OperAccessTaskEntity::getCreateDept,areas);
}});
if(CollectionUtil.isEmpty(accesss)){
return 0;
}
return accesss.size();
}
/**
* 时间区间机构的巡检数据查询
* @param start
* @param end
* @param areas
* @return
*/
@Override
public OverhaulVo overhaul(String start, String end, List<Long> areas) {
OverhaulVo overhaulVo = new OverhaulVo();
public OverhaulVo overhaul_count(List<Long> areas,String start, String end) {
OverhaulVo overhaul = new OverhaulVo();
// 检修总数
List<OperAccessTaskEntity> overhaulList = this.list(new LambdaQueryWrapper<OperAccessTaskEntity>(){{
ge(OperAccessTaskEntity::getPlanStartTime,start);
@ -69,18 +44,18 @@ public class AccessServiceImpl extends BaseServiceImpl<AccessMapper, OperAccessT
in(OperAccessTaskEntity::getCreateDept,areas);
}});
if(CollectionUtil.isEmpty(overhaulList)){
overhaulVo.setOverhaul(0);
overhaulVo.setOverhaulFinish(0);
return overhaulVo;
overhaul.setOverhaul(0);
overhaul.setOverhaulFinish(0);
return overhaul;
}
overhaulVo.setOverhaul(overhaulList.size());
overhaul.setOverhaul(overhaulList.size());
// 检修完成数量
List<Long> overhaulFinishTask = overhaulList.stream().filter(task-> Func.isNotEmpty(task.getStatus()) && AccessConstants.ACCESS_TASK_STATUS_4 == task.getStatus())
.map(OperAccessTaskEntity::getId).collect(Collectors.toList());
if(CollectionUtil.isEmpty(overhaulFinishTask)){
overhaulVo.setOverhaulFinish(0);
overhaul.setOverhaulFinish(0);
}
overhaulVo.setOverhaulFinish(overhaulFinishTask.size());
return overhaulVo;
overhaul.setOverhaulFinish(overhaulFinishTask.size());
return overhaul;
}
}

44
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/DefectServiceImpl.java

@ -1,12 +1,15 @@
package com.hnac.hzims.scheduled.service.operation.business.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hnac.hzims.operational.defect.entity.OperDefectEntity;
import com.hnac.hzims.operational.defect.vo.SolveHomeVO;
import com.hnac.hzims.scheduled.mapper.operation.DefectMapper;
import com.hnac.hzims.scheduled.service.operation.business.DefectService;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
@ -24,32 +27,27 @@ import java.util.stream.Collectors;
public class DefectServiceImpl extends BaseServiceImpl<DefectMapper, OperDefectEntity> implements DefectService {
/**
* 获取消缺率
* @param areas
* 消缺数量统计
* @param deptIds
* @param start
* @param end
* @return
*/
@Override
public Double defectCount(List<Long> areas) {
if(CollectionUtil.isEmpty(areas)) {
return 100.00;
public SolveHomeVO solve_count(List<Long> deptIds, String start, String end) {
SolveHomeVO solve = new SolveHomeVO();
List<OperDefectEntity> defects = this.list(Wrappers.<OperDefectEntity>lambdaQuery()
.in(OperDefectEntity::getCreateDept,deptIds)
.gt(OperDefectEntity::getCreateTime,start)
.lt(OperDefectEntity::getCreateTime,end)
);
if(cn.hutool.core.collection.CollectionUtil.isEmpty(defects)){
solve.setDefectCount(0);
solve.setSolveCount(0);
}else{
solve.setDefectCount(defects.size());
solve.setSolveCount((int) defects.stream().filter(defect-> ObjectUtil.isNotEmpty(defect.getHandleTaskId())).count());
}
LocalDate firstDay = LocalDate.now().withDayOfYear(1);
LocalDateTime firstDateTime = LocalDateTime.of(firstDay, LocalTime.MIN);
LocalDateTime now = LocalDateTime.now();
List<OperDefectEntity> pTaskList = this.list(new LambdaQueryWrapper<OperDefectEntity>(){{
ge(OperDefectEntity::getCreateTime,firstDateTime);
le(OperDefectEntity::getCreateTime,now);
in(OperDefectEntity::getCreateDept,areas);
}});
if(CollectionUtil.isEmpty(pTaskList)){
return 0.0;
}
// 缺陷处理完成数
List<OperDefectEntity> finishTask = pTaskList.stream().filter(defect -> "1".equals(defect.getHandleStatus())).collect(Collectors.toList());
if(CollectionUtil.isEmpty(finishTask)){
return 0.0;
}
// 消缺率 = (缺陷数 / 总数) * 100
return BigDecimal.valueOf(finishTask.size() / (double) pTaskList.size() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
return solve;
}
}

27
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ShowServiceImpl.java

@ -13,6 +13,7 @@ import com.hnac.hzims.operational.access.constants.AccessConstants;
import com.hnac.hzims.operational.access.entity.OperAccessTaskEntity;
import com.hnac.hzims.operational.defect.constants.DefectConstant;
import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity;
import com.hnac.hzims.operational.defect.vo.SolveHomeVO;
import com.hnac.hzims.operational.duty.vo.DutyInfoVo;
import com.hnac.hzims.operational.duty.vo.DutyTaskVo;
import com.hnac.hzims.operational.duty.vo.NextDutyInfoVo;
@ -24,10 +25,10 @@ import com.hnac.hzims.operational.station.entity.StationEntity;
import com.hnac.hzims.scheduled.service.equipment.PlanService;
import com.hnac.hzims.scheduled.service.inspect.TaskService;
import com.hnac.hzims.scheduled.service.operation.business.*;
import com.hnac.hzims.scheduled.service.operation.home.ShowService;
import com.hnac.hzims.scheduled.service.operation.fill.*;
import com.hnac.hzims.scheduled.service.operation.station.StationService;
import com.hnac.hzims.scheduled.service.operation.home.ShowService;
import com.hnac.hzims.scheduled.service.operation.plate.DataService;
import com.hnac.hzims.scheduled.service.operation.station.StationService;
import com.hnac.hzims.scheduled.service.ticket.TicketService;
import com.hnac.hzims.scheduled.service.ticket.WorkTicketService;
import com.hnac.hzims.ticket.allTicket.vo.DoublePassRateVO;
@ -377,6 +378,8 @@ public class ShowServiceImpl implements ShowService {
ScheduledExecutorService exe = new ScheduledThreadPoolExecutor(4, namedThreadFactory, new ThreadPoolExecutor.AbortPolicy());
// 监控线程执行完后返回结果
CountDownLatch countDownLatch = new CountDownLatch(4);
LocalDate firstDay = LocalDate.now().withDayOfYear(1);
LocalDateTime firstDateTime = LocalDateTime.of(firstDay, LocalTime.MIN);
// 日常维护
exe.execute(() -> {
target.setTaget_one(Double.valueOf(maintenanceService.maintenanceCount(areas)));
@ -384,18 +387,26 @@ public class ShowServiceImpl implements ShowService {
});
// 检修任务
exe.execute(() -> {
target.setTaget_two(accessService.accessCount(areas));
OverhaulVo overhaul = accessService.overhaul_count(areas,DateUtil.format(DateUtil.toDate(firstDateTime.toLocalDate()),DateUtil.PATTERN_DATETIME),DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME));
if(Math.abs(overhaul.getOverhaul()) > 0 && Math.abs(overhaul.getOverhaulFinish()) > 0){
target.setTaget_two(BigDecimal.valueOf((double)overhaul.getOverhaulFinish() / overhaul.getOverhaul() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
}else{
target.setTaget_two(0.0);
}
countDownLatch.countDown();
});
// 消缺率
exe.execute(() -> {
target.setTaget_three(defectService.defectCount(areas));
SolveHomeVO solve = defectService.solve_count(areas,DateUtil.format(DateUtil.toDate(firstDateTime.toLocalDate()),DateUtil.PATTERN_DATETIME),DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME));
if(Math.abs(solve.getSolveCount()) > 0 && Math.abs(solve.getDefectCount()) > 0){
target.setTaget_three(BigDecimal.valueOf((double)solve.getSolveCount() / solve.getDefectCount() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
}else{
target.setTaget_three(0.0);
}
countDownLatch.countDown();
});
// 双票合格率
exe.execute(() -> {
LocalDate firstDay = LocalDate.now().withDayOfYear(1);
LocalDateTime firstDateTime = LocalDateTime.of(firstDay, LocalTime.MIN);
DoublePassRateVO pass = ticketService.doublePassRate(areas, firstDateTime, LocalDateTime.now());
if (ObjectUtil.isNotEmpty(pass)) {
target.setTaget_four(Double.valueOf(pass.getDoublePassRate()));
@ -870,7 +881,7 @@ public class ShowServiceImpl implements ShowService {
});
// 检修
exe.execute(()->{
OverhaulVo overhaulVo = accessService.overhaul(start,end,list);
OverhaulVo overhaulVo = accessService.overhaul_count(list,start,end);
int overhaul = overhaulVo.getOverhaul();
int overhaulFinish = overhaulVo.getOverhaulFinish();
task.setOverhaul(overhaul);
@ -1015,7 +1026,7 @@ public class ShowServiceImpl implements ShowService {
});
// 检修
exe.execute(()->{
OverhaulVo overhaulVo = accessService.overhaul(start,end,list);
OverhaulVo overhaulVo = accessService.overhaul_count(list,start,end);
int overhaul = overhaulVo.getOverhaul();
int overhaulFinish = overhaulVo.getOverhaulFinish();
areaDutyVo.setOverhaulSumMoth(overhaul);

2
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/impl/ReportServiceImpl.java

@ -390,7 +390,7 @@ public class ReportServiceImpl implements ReportService {
// 检修
exe.execute(() -> {
OverhaulVo overhaulVo = accessService.overhaul(startTime, endTime, areas);
OverhaulVo overhaulVo = accessService.overhaul_count(areas,startTime, endTime);
int overhaul = overhaulVo.getOverhaul();
areaMonthReport.setMaintenanceTasks(overhaul);
countDownLatch.countDown();

33
hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/IDefectCheckService.java

@ -2,10 +2,13 @@ package com.hnac.hzims.operational.defect.service;
import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse;
import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity;
import com.hnac.hzims.operational.defect.vo.SolveHomeVO;
import org.springblade.core.mp.base.BaseService;
import org.springblade.core.tool.api.R;
import org.springblade.flow.core.vo.ComleteTask;
import java.util.List;
/**
* @author ysj
@ -20,31 +23,19 @@ public interface IDefectCheckService extends BaseService<OperPhenomenonEntity> {
OperPhenomenonEntity startCheck(OperPhenomenonEntity phenomenon);
/**
* 甄别缺陷
* @param task
* @return
*/
void screeDefect(ComleteTask task);
/**
* 决策处理方式
* @param task
* 监听回调消息
* @param processWorkFlowResponse
* @return
*/
void treatmentMethod(ComleteTask task);
R listenAndUpdateDefect(ProcessWorkFlowResponse processWorkFlowResponse);
/**
* 补开工作票
* @param task
*/
void makeUpTicket(ComleteTask task);
/**
* 定论
* @param task
* 消缺数量统计
* @param deptIds
* @param start
* @param end
* @return
*/
void conclusion(ComleteTask task);
R listenAndUpdateDefect(ProcessWorkFlowResponse processWorkFlowResponse);
SolveHomeVO solve_count(List<Long> deptIds,String start,String end);
}

553
hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/service/impl/DefectCheckServiceImpl.java

@ -1,6 +1,6 @@
package com.hnac.hzims.operational.defect.service.impl;
import com.alibaba.fastjson.JSON;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -8,16 +8,12 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hnac.hzims.common.logs.utils.StringUtils;
import com.hnac.hzims.fdp.feign.IFdpTaskClient;
import com.hnac.hzims.message.MessageConstants;
import com.hnac.hzims.message.dto.BusinessMessageDTO;
import com.hnac.hzims.message.fegin.IMessageClient;
import com.hnac.hzims.middle.process.to.ProcessWorkFlowResponse;
import com.hnac.hzims.operational.access.dto.OperAccessPlanDTO;
import com.hnac.hzims.operational.access.dto.OperAccessTaskDTO;
import com.hnac.hzims.operational.access.service.IOperAccessPlanService;
import com.hnac.hzims.operational.access.service.IOperAccessTaskService;
import com.hnac.hzims.operational.defect.constants.RepairConstant;
import com.hnac.hzims.operational.defect.constants.TreatMethodConstant;
import com.hnac.hzims.operational.defect.entity.OperAppearanceEntity;
import com.hnac.hzims.operational.defect.entity.OperDefectEntity;
@ -28,8 +24,8 @@ import com.hnac.hzims.operational.defect.service.IDefectCheckService;
import com.hnac.hzims.operational.defect.service.IOperAppearanceService;
import com.hnac.hzims.operational.defect.service.IOperDefectService;
import com.hnac.hzims.operational.defect.service.IOperDefectStatisticsService;
import com.hnac.hzims.operational.defect.vo.SolveHomeVO;
import com.hnac.hzims.operational.util.TimeUtils;
import com.hnac.hzims.ticket.repair.entity.RepairEntity;
import com.hnac.hzims.ticket.repair.fegin.IRepairClient;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -37,20 +33,19 @@ import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.support.Kv;
import org.springblade.core.tool.utils.*;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.flow.core.entity.BladeFlow;
import org.springblade.flow.core.feign.IFlowClient;
import org.springblade.flow.core.utils.FlowUtil;
import org.springblade.flow.core.vo.ComleteTask;
import org.springblade.system.cache.DictCache;
import org.springblade.system.feign.ISysClient;
import org.springblade.system.user.cache.UserCache;
import org.springblade.system.user.entity.User;
import org.springblade.system.user.feign.IUserClient;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.beans.BeanInfo;
import java.beans.Introspector;
@ -60,9 +55,6 @@ import java.lang.reflect.InvocationTargetException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
/**
@ -73,32 +65,18 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
public class DefectCheckServiceImpl extends BaseServiceImpl<OperPhenomenonMapper, OperPhenomenonEntity> implements IDefectCheckService {
private final IOperAccessTaskService operAccessTaskService;
private final IOperAccessPlanService operAccessPlanService;
private final IOperDefectService defectService;
private final IOperAppearanceService operAppearanceService;
private final IOperDefectStatisticsService statisticsService;
private final IOperDefectService defectService;
private final IOperAccessPlanService accessPlanService;
private final OperPhenomenonMapper phenomenonMapper;
private final ISysClient sysClient;
private final IFlowClient processClient;
private final IUserClient userClient;
private final ISysClient sysClient;
private final IMessageClient messageClient;
private final IFdpTaskClient fdpTaskClient;
private final IRepairClient repairClient;
/**
* 保存现象开启缺陷处理流程
@ -158,11 +136,6 @@ public class DefectCheckServiceImpl extends BaseServiceImpl<OperPhenomenonMapper
* @param entity
*/
private void startDefectCheckV2(OperPhenomenonEntity entity) {
// 获取机构下执行定论缺陷角色用户
// List<User> list = this.getAliasUser(entity.getTenantId(), entity.getCreateDept(), TreatMethodConstant.PHENOMENON_SCREEN_ALIAS);
// if (CollectionUtil.isEmpty(list)) {
// throw new ServiceException("请先添加甄别缺陷角色用户,再发起现象!");
// }
//新增缺陷流程记录
OperDefectStatisticsEntity operDefectStatisticsEntity = new OperDefectStatisticsEntity();
BeanUtil.copy(entity, operDefectStatisticsEntity);
@ -354,505 +327,29 @@ public class DefectCheckServiceImpl extends BaseServiceImpl<OperPhenomenonMapper
}
}
/**
* 启动缺陷处理流程
* 此端口弃用20230614
*
* @param entity
*/
@Deprecated
private void startDefectCheck(OperPhenomenonEntity entity) {
// 获取机构下执行定论缺陷角色用户
List<User> list = this.getAliasUser(entity.getTenantId(), entity.getCreateDept(), TreatMethodConstant.PHENOMENON_SCREEN_ALIAS);
if (CollectionUtil.isEmpty(list)) {
throw new ServiceException("请先添加甄别缺陷角色用户,再发起现象!");
}
List<String> userList = list.stream().map(o -> "taskUser_" + o.getId().toString()).collect(Collectors.toList());
// 现象发起人名字
String userName = Optional.ofNullable(UserCache.getUser(entity.getFinder()).getName()).orElse("");
// 现象发起来源
String sourceName = DictCache.getValue(TreatMethodConstant.SOURCE_CODE_PREFIX, entity.getSourceCode());
// 流程名称
String processName = "[" + userName + "] 发起 " + "【" + sourceName + "】缺陷处理流程" + "——>" + entity.getDefectCode();
// 设置下一步执行流程用户
Kv variables = Kv.create()
.set(TreatMethodConstant.PHENOMENON_SCREEN_USER, String.join(",", userList));
// 开启新的缺陷流程
R<BladeFlow> result = processClient.startProcessInstanceContainNameByKey(TreatMethodConstant.DEFECT_CHECK_PRIMARY_KEY, FlowUtil.getBusinessKey("hzims_oper_phenomenon", "" + entity.getId()), processName, variables);
// 流程开启失败
if (!result.isSuccess()) {
throw new ServiceException("缺陷流程开启失败,错误描述 : " + result.getCode());
}
// 关联流程唯一键
entity.setCheckProcessInstanceId(result.getData().getProcessInstanceId());
this.baseMapper.updateById(entity);
}
/**
* 获取当前机构指定角色的用户
*
* @param tenantId
* @param deptId
* @param alias
* @return
*/
public List<User> getAliasUser(String tenantId, Long deptId, String alias) {
if (Func.isEmpty(tenantId)) {
tenantId = AuthUtil.getTenantId();
}
R<List<User>> result = userClient.relationUserListByRoleAlias(tenantId, deptId, alias);
if (!result.isSuccess()) {
throw new ServiceException("查询角色用户信息失败!");
}
return result.getData();
}
/**
* 修改缺陷状态 -> 问题定论
*
* @param handleStatus
* @param defectCode
*/
private void updateDefectHandleState(String handleStatus, String defectCode) {
this.defectService.update(Wrappers.<OperDefectEntity>lambdaUpdate()
.set(OperDefectEntity::getHandleStatus, handleStatus)
.eq(OperDefectEntity::getDefectCode, defectCode)
);
}
/**
* 甄别缺陷
*
* @param task
* 消缺数量统计
* @param deptIds
* @param start
* @param end
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void screeDefect(ComleteTask task) {
// 步骤1.现象前置判断(现象状态检查)
OperPhenomenonEntity entity = this.preposePhenomenon(task.getProcessInstanceId());
// 步骤2.更新甄别状态、数据
this.screePhenomenonUpdate(task);
// 步骤3.现象添加至缺陷库
this.defectSave(entity);
// 步骤4.流程执行至甄别处理方式
processClient.completeTask(task);
}
/**
* 现象前置判断
*
* @param processInstanceId
* @return
*/
private OperPhenomenonEntity preposePhenomenon(String processInstanceId) {
LambdaQueryWrapper<OperPhenomenonEntity> wrapper = new LambdaQueryWrapper<OperPhenomenonEntity>() {{
eq(OperPhenomenonEntity::getCheckProcessInstanceId, processInstanceId);
}};
// 查询现象状态
OperPhenomenonEntity entity = this.getOne(wrapper);
if (ObjectUtil.isEmpty(entity)) {
throw new ServiceException("现象不存在");
}
// 现象已被自动甄别
if (TreatMethodConstant.AUTO_SCREENED.equals(entity.getAutoDiscriminateStatus())) {
throw new ServiceException("该现象已经自动甄别");
}
// 现象已被手动动甄别
if (TreatMethodConstant.SCREENED.equals(entity.getDiscriminateStatus())) {
throw new ServiceException("该现象已甄别");
}
return entity;
}
/**
* 缺陷保存
*
* @param phenomenon
*/
private void defectSave(OperPhenomenonEntity phenomenon) {
OperDefectEntity defect = new OperDefectEntity();
defect.setHandleStatus(RepairConstant.DEFAULT_DEFECT_STATE);
defect.setProcessInstanceId(phenomenon.getCheckProcessInstanceId());
defect.setDefectCode(phenomenon.getDefectCode());
defect.setCreateUser(phenomenon.getCreateUser());
defect.setCreateDept(phenomenon.getCreateDept());
defect.setTenantId(phenomenon.getTenantId());
this.defectService.save(defect);
}
/**
* 更新甄别状态数据
*
* @param task
*/
private void screePhenomenonUpdate(ComleteTask task) {
// 查询流程状态
String processStatus = TreatMethodConstant.RUNNING;
R<String> result = processClient.queryProcessInstanceStatus(task.getProcessInstanceId());
if (result.isSuccess() && StringUtil.isNotBlank(result.getData()) && TreatMethodConstant.PROCESS_STATE_OVER.equals(result.getData())) {
processStatus = TreatMethodConstant.PROCESS_STATE_OVER;
}
// 获取参数集
Map<String, Object> variables = task.getVariables();
boolean invalid = (boolean) variables.get("invalid");
LambdaUpdateWrapper<OperPhenomenonEntity> lambdaUpdate = Wrappers.lambdaUpdate();
if (invalid) {
lambdaUpdate
.set(OperPhenomenonEntity::getStatus, processStatus)
.set(OperPhenomenonEntity::getIsDefect, TreatMethodConstant.IS_DEFECT)
.set(OperPhenomenonEntity::getAutoDiscriminateStatus, TreatMethodConstant.ORDINARY_SCREENED)
.set(OperPhenomenonEntity::getDiscriminator, AuthUtil.getUserId())
.set(OperPhenomenonEntity::getDiscriminateTime, new Date())
.set(OperPhenomenonEntity::getDiscriminateStatus, variables.get("discriminateStatus").toString())
.set(OperPhenomenonEntity::getDiscriminateDesc, Optional.ofNullable(variables.get("discriminateDesc")).map(Object::toString).orElse(null))
.set(OperPhenomenonEntity::getSafeInfos, variables.get("safeInfos").toString())
.set(OperPhenomenonEntity::getWorkStandards, Optional.ofNullable(variables.get("workStandards")).map(Object::toString).orElse(null))
.set(OperPhenomenonEntity::getHandleProgramme, variables.get("handleProgramme").toString().substring(9))
.set(OperPhenomenonEntity::getPlanHours, variables.get("planHours").toString())
.set(OperPhenomenonEntity::getPlanStartTime, variables.get("planStartTime").toString())
.set(OperPhenomenonEntity::getPlanEndTime, variables.get("planEndTime").toString())
.set(OperPhenomenonEntity::getDefectLevel, variables.get("defectLevel").toString())
.eq(OperPhenomenonEntity::getCheckProcessInstanceId, task.getProcessInstanceId());
} else {
lambdaUpdate
.set(OperPhenomenonEntity::getStatus, processStatus)
.set(OperPhenomenonEntity::getIsDefect, TreatMethodConstant.NO_DEFECT)
.set(OperPhenomenonEntity::getDiscriminateStatus, variables.get("discriminateStatus").toString())
.set(OperPhenomenonEntity::getDiscriminator, AuthUtil.getUserId())
.set(OperPhenomenonEntity::getDiscriminateTime, new Date())
.set(OperPhenomenonEntity::getDiscriminateDesc, variables.get("discriminateDesc").toString())
.eq(OperPhenomenonEntity::getCheckProcessInstanceId, task.getProcessInstanceId());
}
this.update(lambdaUpdate);
}
/**
* 决策处理方式
*
* @param task
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void treatmentMethod(ComleteTask task) {
// 步骤1.获取参数集
Map<String, Object> variables = task.getVariables();
// 步骤2.根据处理方式进行处理
String state = RepairConstant.REPAIR_DEFECT_STATE, processKey = RepairConstant.REPAIR_PROCESS_PRIMARY_KEY, type = variables.get("type").toString();
switch (type) {
// 应急抢修处理
case TreatMethodConstant.TYPE_RUSH_TO_REPAIR:
this.startRepair(task, variables);
break;
// 检修计划处理
case TreatMethodConstant.TYPE_PLAN:
state = RepairConstant.ACCESS_PLAN_STATE;
this.startMaintenancePlan(task, variables);
break;
// 检修任务处理
case TreatMethodConstant.TYPE_TASK:
state = RepairConstant.ACCESS_TASK_STATE;
this.startMaintenanceTask(task);
break;
default:
throw new IllegalStateException("Unexpected type: " + type);
}
// 步骤3.关联处理任务
this.relationHandlerTask(variables, type, task.getProcessInstanceId(), state);
// 步骤4.缺陷库保存处理任务信息
this.saveDefectInfo(variables, task.getProcessInstanceId(), processKey, state);
// 步骤5.流程执行 -> 处理缺陷
processClient.completeTask(task);
}
/**
* 启动应急抢修流程
*
* @param variables
*/
private void startRepair(ComleteTask task, Map<String, Object> variables) {
String json = JSON.toJSONString(variables.get("repair"));
RepairEntity entity = JSONObject.parseObject(json, RepairEntity.class);
R<RepairEntity> result = repairClient.startRepair(entity);
if (!result.isSuccess()) {
throw new ServiceException("开启检修任务流程失败!");
}
variables.put("handlerTaskId", result.getData().getId());
variables.put("handlerType", TreatMethodConstant.REPAIR);
variables.put("handlerProcessInstanceId", result.getData().getProcessInstanceId());
variables.put("handlerUserId", result.getData().getCharge());
variables.put(TreatMethodConstant.DEFECT_HANDLER_USER, "taskUser_" + result.getData().getCharge());
task.setVariables(variables);
}
/**
* 开启检修计划
*
* @param variables
*/
private void startMaintenancePlan(ComleteTask task, Map<String, Object> variables) {
String json = JSON.toJSONString(variables.get("accessPlan"));
OperAccessPlanDTO accessPlan = JSONObject.parseObject(json, OperAccessPlanDTO.class);
// 查询现象
OperPhenomenonEntity phenomenon = this.getOne(new LambdaQueryWrapper<OperPhenomenonEntity>() {{
eq(OperPhenomenonEntity::getCheckProcessInstanceId, task.getProcessInstanceId());
}});
// 查询缺陷
OperDefectEntity defect = this.defectService.getOne(Wrappers.<OperDefectEntity>lambdaUpdate().eq(OperDefectEntity::getDefectCode, phenomenon.getDefectCode()));
accessPlan.setDefectId(defect.getId());
accessPlan.setPhenomenonId(phenomenon.getId());
accessPlan.setActStartTime(DateUtil.now());
// 计划草稿
R result = operAccessPlanService.doSave(accessPlan);
if (!result.isSuccess()) {
throw new ServiceException("开启检修计划失败");
}
// 计划流程开启
accessPlanService.handlePlan(accessPlan, null);
variables.put("handlerTaskId", accessPlan.getId());
variables.put("handlerProcessInstanceId", accessPlan.getProcessInstanceId());
variables.put("handlerUserId", AuthUtil.getUserId());
variables.put("handlerType", TreatMethodConstant.MAINTENANCE_PLAN);
variables.put("actStartTime", accessPlan.getActStartTime());
variables.put(TreatMethodConstant.DEFECT_HANDLER_USER, "taskUser_" + AuthUtil.getUserId());
task.setVariables(variables);
}
/**
* 开启检修任务
*
* @param comleteTask
*/
@Transactional(rollbackFor = Exception.class)
public void startMaintenanceTask(ComleteTask comleteTask) {
Assert.isTrue(CollectionUtil.isNotEmpty(comleteTask.getVariables()) && ObjectUtil.isNotEmpty(comleteTask.getVariables().get("accessTask")), () -> {
throw new ServiceException("检修任务信息不能为空!");
});
Map<String, Object> variables = comleteTask.getVariables();
OperAccessTaskDTO accessTask = JSONObject.parseObject(JSON.toJSONString(variables.get("accessTask")), OperAccessTaskDTO.class);
Assert.isTrue(Func.isNotEmpty(accessTask.getPhenomenonId()), () -> {
throw new ServiceException("检修任务信息必须传入现象Id");
});
R result = operAccessTaskService.doSave(accessTask);
if (result.isSuccess()) {
variables.put("handler", "taskUser_" + accessTask.getHandler());
}
comleteTask.setVariables(this.excludeProperties(variables, "accessTask"));
processClient.completeTask(comleteTask);
variables.put("handlerTaskId", accessTask.getId());
variables.put("handlerProcessInstanceId", accessTask.getProcessInstanceId());
variables.put("handlerUserId", accessTask.getHandler());
variables.put("handlerType", TreatMethodConstant.MAINTENANCE_TASK);
variables.put("actStartTime", accessTask.getCreateTime());
}
/**
* 保存缺陷信息
*
* @param variables
*/
private void saveDefectInfo(Map<String, Object> variables, String processInstanceId, String processKey, String state) {
// 新启线程保存缺陷
ExecutorService exe = Executors.newSingleThreadExecutor();
exe.execute(() -> {
// 查询现象
OperPhenomenonEntity entity = this.queryPhenomenon(processInstanceId);
// 保存流程信息至缺陷表
this.defectService.update(Wrappers.<OperDefectEntity>lambdaUpdate()
.set(OperDefectEntity::getProcDefId, processKey + "->" + variables.get("handlerTaskId"))
.set(OperDefectEntity::getActStartTime, variables.get("actStartTime"))
.set(OperDefectEntity::getHandleStatus, state)
.set(OperDefectEntity::getHandleType, variables.get("handlerType"))
.eq(OperDefectEntity::getDefectCode, entity.getDefectCode())
public SolveHomeVO solve_count(List<Long> deptIds, String start, String end) {
SolveHomeVO solve = new SolveHomeVO();
List<OperDefectEntity> defects = defectService.list(Wrappers.<OperDefectEntity>lambdaQuery()
.in(OperDefectEntity::getCreateDept,deptIds)
.gt(OperDefectEntity::getCreateTime,start)
.lt(OperDefectEntity::getCreateTime,end)
);
});
exe.shutdown();
}
/**
* 关联处理任务
*
* @param variables
* @param type
* @param processInstanceId
*/
private void relationHandlerTask(Map<String, Object> variables, String type, String processInstanceId, String state) {
this.update(Wrappers.<OperPhenomenonEntity>lambdaUpdate()
.set(OperPhenomenonEntity::getHandleTaskId, variables.get("handlerTaskId"))
.set(OperPhenomenonEntity::getHandler, variables.get("handlerUserId"))
.set(OperPhenomenonEntity::getHandleType, type)
.set(OperPhenomenonEntity::getHandleStatus, state)
.eq(OperPhenomenonEntity::getCheckProcessInstanceId, processInstanceId)
);
}
/**
* 补开工作票
*
* @param task
*/
@Override
public void makeUpTicket(ComleteTask task) {
// 步骤1.查询现象
OperPhenomenonEntity entity = this.queryPhenomenon(task.getProcessInstanceId());
// 步骤2.获取定论角色-用户
List<User> list = this.getAliasUser(entity.getTenantId(), entity.getCreateDept(), TreatMethodConstant.PHENOMENON_CONCLUSION_ALIAS);
if (CollectionUtil.isEmpty(list)) {
throw new ServiceException("请先添加缺陷定论角色用户,再进行补工作票");
}
List<String> userList = list.stream().map(o -> "taskUser_" + o.getId().toString()).collect(Collectors.toList());
// 步骤3.现象状态 -> 问题定论
this.updatePhenomenonState(entity);
// 步骤4.缺陷状态 -> 问题定论
this.updateDefectHandleState(RepairConstant.CONCLUSION_PROBLEM, entity.getDefectCode());
// 步骤5.设置参数
Map<String, Object> variables = task.getVariables();
variables.put(TreatMethodConstant.PHENOMENON_CONCLUSION_ALIAS, String.join(",", userList));
task.setVariables(variables);
// 步骤6.执行流程->问题定论
processClient.completeTask(task);
}
/**
* 现象状态 -> 问题定论
*
* @param entity
*/
private void updatePhenomenonState(OperPhenomenonEntity entity) {
entity.setHandleStatus(RepairConstant.CONCLUSION_PROBLEM);
this.phenomenonMapper.updateById(entity);
}
/**
* 查询现象
*
* @param processInstanceId
* @return
*/
private OperPhenomenonEntity queryPhenomenon(String processInstanceId) {
LambdaQueryWrapper<OperPhenomenonEntity> wrapper = new LambdaQueryWrapper<OperPhenomenonEntity>() {{
eq(OperPhenomenonEntity::getCheckProcessInstanceId, processInstanceId);
}};
return this.getOne(wrapper);
}
/**
* 定论
*
* @param task
*/
@Override
public void conclusion(ComleteTask task) {
// 步骤1.查询现象
OperPhenomenonEntity entity = this.queryPhenomenon(task.getProcessInstanceId());
// 步骤2.更新现象定论信息
this.defectConclusionInfo(task, entity.getId());
// 步骤3.现象加入台账
this.saveDefect(entity);
// 步骤4.故障状态更新
this.updateFaultState(entity.getFaultCode());
// 步骤5.更新缺陷状态 -> 已处理
this.updateDefectHandleState(RepairConstant.COMPLETE_DEFECT_STATE, entity.getDefectCode());
// 步骤6.缺陷流程->结束
processClient.completeTask(task);
}
/**
* 更新现象定论信息
*
* @param task
*/
private void defectConclusionInfo(ComleteTask task, Long phenomenonId) {
// 获取参数集
Map<String, Object> variables = task.getVariables();
// 修改现象定论信息
OperPhenomenonEntity entity = new OperPhenomenonEntity();
entity.setStatus(Integer.valueOf(TreatMethodConstant.OVER));
entity.setHandleStatus(RepairConstant.COMPLETE_DEFECT_STATE);
entity.setConclusionTime(new Date());
entity.setConclusionPeople(AuthUtil.getUserId());
entity.setConclusionStatus(TreatMethodConstant.CONCLUSION_COMPLETED);
entity.setConclusion((String) variables.get("conclusion"));
entity.setCheckHours(Integer.valueOf(variables.get("checkHours").toString()));
entity.setId(phenomenonId);
this.phenomenonMapper.updateById(entity);
}
/**
* 现象加入台账
*
* @param entity
*/
private void saveDefect(OperPhenomenonEntity entity) {
entity = phenomenonMapper.selectById(entity.getId());
// 复制现象数据
OperDefectStatisticsEntity statistics = BeanUtil.copy(entity, OperDefectStatisticsEntity.class);
// 查询缺陷
OperDefectEntity defect = this.defectService.getOne(Wrappers.<OperDefectEntity>lambdaUpdate().eq(OperDefectEntity::getDefectCode, entity.getDefectCode()));
if (ObjectUtil.isEmpty(statistics)) {
return;
}
// 实际执行时长
statistics.setCheckHours(entity.getCheckHours());
statistics.setConclusion(entity.getConclusion());
statistics.setConclusionPeople(entity.getConclusionPeople());
statistics.setConclusionTime(entity.getConclusionTime());
statistics.setActEndTime(defect.getActEndTime());
statistics.setActStartTime(defect.getActStartTime());
statistics.setDisposeDesc(defect.getDisposeDesc());
// 台账存储
this.statisticsService.save(statistics);
}
/**
* 故障状态更新
*
* @param faultCode
*/
private void updateFaultState(String faultCode) {
if (StringUtil.isBlank(faultCode)) {
return;
}
fdpTaskClient.updateFinishStatusByDefectCode(faultCode);
}
/**
* 排除业务中所需属性 避免传入工作流中
*
* @param variable 工作流传参map
* @param properties 不计入工作流传参的属性
* @return
*/
private Map<String, Object> excludeProperties(Map<String, Object> variable, String... properties) {
Map<String, Object> result = new HashMap<>();
variable.forEach((k, v) -> {
if (!Arrays.asList(properties).contains(k)) {
result.put(k, v);
if(CollectionUtil.isEmpty(defects)){
solve.setDefectCount(0);
solve.setSolveCount(0);
}else{
solve.setDefectCount(defects.size());
solve.setSolveCount((int) defects.stream().filter(defect->ObjectUtil.isNotEmpty(defect.getHandleTaskId())).count());
}
});
return result;
return solve;
}
}

2
hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/MainTaskStatisticServiceImpl.java

@ -173,7 +173,7 @@ public class MainTaskStatisticServiceImpl implements IMainTaskStatisticService {
return "0";
}
// 消缺率 = (缺陷数 / 总数) * 100
double finishRate = new BigDecimal(finishTask.size() / (double) pTaskList.size() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
double finishRate = BigDecimal.valueOf(finishTask.size() / (double) pTaskList.size() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
return String.valueOf(finishRate);
}

Loading…
Cancel
Save