Browse Source

# 日常维护任务执行情况统计

zhongwei
haungxing 11 months ago
parent
commit
0ea0397d6f
  1. 14
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/vo/MaintenanceTaskQueryVO.java
  2. 26
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/controller/MaintenanceTaskQueryController.java
  3. 10
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/IMaintenanceTaskQueryService.java
  4. 133
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceTaskQueryServiceImpl.java
  5. 19
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/ObjectUtils.java
  6. 3
      hzims-service/operational/src/main/resources/db/1.0.1.sql

14
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/vo/MaintenanceTaskQueryVO.java

@ -1,6 +1,7 @@
package com.hnac.hzims.operational.maintenance.vo; package com.hnac.hzims.operational.maintenance.vo;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@ -19,36 +20,37 @@ public class MaintenanceTaskQueryVO implements Serializable {
@ApiModelProperty(value = "创建机构名称") @ApiModelProperty(value = "创建机构名称")
@ExcelProperty("单位") @ExcelProperty("单位")
@ColumnWidth(20)
private String deptName; private String deptName;
@ApiModelProperty(value = "维护类型 01=定期试验 02=定期保养 03=定期操作 04=其他")
private String typeCode;
@ExcelProperty("维护类型") @ExcelProperty("维护类型")
@ApiModelProperty(value = "维护类型名称") @ApiModelProperty(value = "维护类型名称")
@ColumnWidth(15)
private String typeName; private String typeName;
@ApiModelProperty(value = "设备编号")
private String emCode;
@ApiModelProperty(value = "维护设备") @ApiModelProperty(value = "维护设备")
@ExcelProperty("维护设备") @ExcelProperty("维护设备")
@ColumnWidth(25)
private String emName; private String emName;
@ApiModelProperty(value = "维护内容") @ApiModelProperty(value = "维护内容")
@ExcelProperty("维护内容") @ExcelProperty("维护内容")
@ColumnWidth(40)
private String content; private String content;
@ApiModelProperty(value = "计划执行时间") @ApiModelProperty(value = "计划执行时间")
@ExcelProperty("计划执行时间") @ExcelProperty("计划执行时间")
@ColumnWidth(20)
private String planDisposeTime; private String planDisposeTime;
@ApiModelProperty(value = "实际执行时间") @ApiModelProperty(value = "实际执行时间")
@ExcelProperty("实际执行时间") @ExcelProperty("实际执行时间")
@ColumnWidth(20)
private String disposeTime; private String disposeTime;
@ApiModelProperty(value = "执行人") @ApiModelProperty(value = "执行人")
@ExcelProperty("执行人") @ExcelProperty("执行人")
@ColumnWidth(20)
private String disposerName; private String disposerName;
@ApiModelProperty(value = "逾期状态") @ApiModelProperty(value = "逾期状态")

26
hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/controller/MaintenanceTaskQueryController.java

@ -1,11 +1,19 @@
package com.hnac.hzims.operational.maintenance.controller; package com.hnac.hzims.operational.maintenance.controller;
import io.swagger.annotations.Api; import com.hnac.hzims.operational.maintenance.service.IMaintenanceTaskQueryService;
import com.hnac.hzims.operational.maintenance.vo.MaintenanceTaskQueryVO;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController; import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/** /**
* @ClassName MaintenanceTaskQueryController * @ClassName MaintenanceTaskQueryController
* @description: * @description:
@ -19,6 +27,22 @@ import org.springframework.web.bind.annotation.RestController;
@AllArgsConstructor @AllArgsConstructor
public class MaintenanceTaskQueryController extends BladeController { public class MaintenanceTaskQueryController extends BladeController {
private final IMaintenanceTaskQueryService maintenanceTaskQueryService;
@GetMapping("/getMaintenanceTaskQuery")
@ApiOperation("查询日常维护任务")
@ApiOperationSupport(order = 1)
public R<List<MaintenanceTaskQueryVO>> getMaintenanceTaskQuery(@RequestParam("month") @ApiParam(value = "查询月份",required = true) String month,
@RequestParam(value = "deptId",required = false) @ApiParam("查询机构") Long deptId) {
return R.data(maintenanceTaskQueryService.getMaintenanceTaskQuery(month, deptId));
}
@GetMapping("/exportMaintenanceTaskQuery")
@ApiOperation("导出日常维护任务")
@ApiOperationSupport(order = 1)
public void exportMaintenanceTaskQuery(@RequestParam("month") @ApiParam(value = "查询月份",required = true) String month,
@RequestParam(value = "deptId",required = false) @ApiParam("查询机构") Long deptId, HttpServletResponse response) {
maintenanceTaskQueryService.exportMaintenanceTaskQuery(month,deptId,response);
}
} }

10
hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/IMaintenanceTaskQueryService.java

@ -1,4 +1,14 @@
package com.hnac.hzims.operational.maintenance.service; package com.hnac.hzims.operational.maintenance.service;
import com.hnac.hzims.operational.maintenance.vo.MaintenanceTaskQueryVO;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
public interface IMaintenanceTaskQueryService { public interface IMaintenanceTaskQueryService {
List<MaintenanceTaskQueryVO> getMaintenanceTaskQuery(String month,Long deptId);
void exportMaintenanceTaskQuery(String month, Long deptId, HttpServletResponse response);
} }

133
hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/service/impl/MaintenanceTaskQueryServiceImpl.java

@ -1,14 +1,145 @@
package com.hnac.hzims.operational.maintenance.service.impl; package com.hnac.hzims.operational.maintenance.service.impl;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.converters.longconverter.LongStringConverter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import com.hnac.hzims.equipment.entity.EmInfoEntity;
import com.hnac.hzims.equipment.feign.IEmInfoClient;
import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceTaskEntity;
import com.hnac.hzims.operational.maintenance.service.IMaintenanceTaskQueryService; import com.hnac.hzims.operational.maintenance.service.IMaintenanceTaskQueryService;
import com.hnac.hzims.operational.maintenance.service.IOperMaintenanceTaskService; import com.hnac.hzims.operational.maintenance.service.IOperMaintenanceTaskService;
import com.hnac.hzims.operational.maintenance.vo.MaintenanceTaskQueryVO;
import com.hnac.hzims.operational.util.ObjectUtils;
import com.hnac.hzims.spare.entity.WtSpBasicEntity;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.BorderStyle;
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.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.system.cache.DictCache;
import org.springblade.system.entity.Dept;
import org.springblade.system.feign.ISysClient;
import org.springblade.system.user.cache.UserCache;
import org.springblade.system.user.entity.User;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.IntUnaryOperator;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@Service @Service
@AllArgsConstructor @AllArgsConstructor
@Slf4j
public class MaintenanceTaskQueryServiceImpl implements IMaintenanceTaskQueryService { public class MaintenanceTaskQueryServiceImpl implements IMaintenanceTaskQueryService {
private final IOperMaintenanceTaskService operMaintenanceTaskService; private final IOperMaintenanceTaskService maintenanceTaskService;
private final ISysClient sysClient;
private final IEmInfoClient emInfoClient;
@Override
public List<MaintenanceTaskQueryVO> getMaintenanceTaskQuery(String month,Long deptId) {
LambdaQueryWrapper<OperMaintenanceTaskEntity> wq = Wrappers.<OperMaintenanceTaskEntity>lambdaQuery()
.like(OperMaintenanceTaskEntity::getDisposeTime, month)
.like(Func.isNotEmpty(deptId),OperMaintenanceTaskEntity::getCreateDept,deptId)
.orderByAsc(OperMaintenanceTaskEntity::getDisposeTime);
List<OperMaintenanceTaskEntity> taskList = maintenanceTaskService.list(wq);
if(CollectionUtil.isEmpty(taskList)) {
return Lists.newArrayList();
}
return this.fillTaskQuery(taskList);
}
@Override
public void exportMaintenanceTaskQuery(String month, Long deptId, HttpServletResponse response) {
List<MaintenanceTaskQueryVO> maintenanceTaskQuery = this.getMaintenanceTaskQuery(month, deptId);
// 设置响应头
// URLEncoder.encode防止中文乱码
String fileName;
try {
fileName = URLEncoder.encode("日常维护执行情况报表", "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("UTF-8");
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
contentWriteCellStyle.setBorderLeft(BorderStyle.THIN);
contentWriteCellStyle.setBorderTop(BorderStyle.THIN);
contentWriteCellStyle.setBorderRight(BorderStyle.THIN);
contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);
contentWriteCellStyle.setWrapped(true);
try {
EasyExcel.write(response.getOutputStream(), MaintenanceTaskQueryVO.class)
.registerWriteHandler(new HorizontalCellStyleStrategy(new WriteCellStyle(), contentWriteCellStyle))
.autoCloseStream(Boolean.FALSE).sheet("日常维护执行情况报表")
.doWrite(maintenanceTaskQuery);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
/**
* 填充查询结果
* @param taskList 任务列表
* @return 填充任务结果
*/
private List<MaintenanceTaskQueryVO> fillTaskQuery(List<OperMaintenanceTaskEntity> taskList) {
R<List<Dept>> deptListR = sysClient.getDeptList();
List<Dept> deptList = deptListR.isSuccess() ? deptListR.getData() : Lists.newArrayList();
List<EmInfoEntity> emList = emInfoClient.list();
IntFunction<MaintenanceTaskQueryVO> convert = index -> {
OperMaintenanceTaskEntity task = taskList.get(index);
MaintenanceTaskQueryVO result = new MaintenanceTaskQueryVO();
result.setIndex(index + 1);
// 获取机构名称
result.setDeptName(deptList.stream().filter(
dept -> dept.getId().equals(task.getCreateDept())
).findFirst().map(Dept::getDeptName).orElse(""));
// 获取维护类型
result.setTypeName(DictCache.getValue("typeCode",task.getTypeCode()));
// 获取维护设备
result.setEmName(emList.stream().filter(
em -> em.getNumber().equals(task.getEmCode())
).findFirst().map(EmInfoEntity::getName).orElse(""));
// 获取执行时间
result.setPlanDisposeTime(DateUtil.formatDateTime(task.getDisposeTime()));
result.setDisposeTime(Optional.ofNullable(task.getExecuteTime()).map(DateUtil::formatDateTime).orElse(""));
// 获取执行人
String disposerName = Optional.ofNullable(task.getDisposer()).map(ObjectUtils::getUserNameByUserIds).orElse("");
result.setDisposerName(disposerName);
// 获取维护内容
result.setContent(task.getContent());
// 获取延期状态
result.setDelayStatus(task.getIsDelay() ? "逾期" : "未逾期");
// 获取状态
result.setStatus("结束".equals(task.getFlowTaskName()) ? "已完成" : "进行中");
return result;
};
List<MaintenanceTaskQueryVO> result = IntStream.iterate(0,index -> index+1).limit(taskList.size()).mapToObj(convert).collect(Collectors.toList());
return result;
}
} }

19
hzims-service/operational/src/main/java/com/hnac/hzims/operational/util/ObjectUtils.java

@ -3,7 +3,12 @@ package com.hnac.hzims.operational.util;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.system.user.cache.UserCache;
import org.springblade.system.user.entity.User;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -16,6 +21,20 @@ import java.util.stream.Collectors;
public class ObjectUtils { public class ObjectUtils {
/** /**
* 根据用户Id获取用户名称
* @param userIds 用户IDs
* @return 用户名称
*/
public static String getUserNameByUserIds(String userIds) {
if(StringUtil.isBlank(userIds)) {
return "";
}
return Arrays.stream(userIds.split(",")).filter(StringUtil::isNotBlank).map(Long::valueOf).filter(Func::isNotEmpty)
.map(UserCache::getUser).filter(Func::isNotEmpty).map(User::getName).collect(Collectors.joining(","));
}
/**
* 对象转为map * 对象转为map
* @param obj * @param obj
* @return * @return

3
hzims-service/operational/src/main/resources/db/1.0.1.sql

@ -1 +1,2 @@
alter table hzims_oper_maintenance_plan add column station_code varchar(60) comment '站点编码' alter table hzims_oper_maintenance_plan add column station_code varchar(60) comment '站点编码';
alter table `hzims_oper_maintenance_task` add column `is_delay` tinyint(2) DEFAULT 0 COMMENT '是否逾期';
Loading…
Cancel
Save