|
|
|
|
@ -4,23 +4,32 @@ package org.springblade.modules.business.service.impl; |
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
|
import com.alibaba.excel.ExcelWriter; |
|
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet; |
|
|
|
|
import com.alibaba.excel.write.metadata.WriteTable; |
|
|
|
|
import com.alibaba.excel.write.metadata.fill.FillConfig; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import jakarta.servlet.ServletOutputStream; |
|
|
|
|
import jakarta.servlet.http.HttpServletResponse; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
|
import org.springblade.modules.business.excel.CustomCellWriteHeightConfig; |
|
|
|
|
import org.springblade.modules.business.excel.CustomCellWriteWidthConfig; |
|
|
|
|
import org.springblade.modules.business.excel.MergeColumnStrategy; |
|
|
|
|
import org.springblade.modules.business.pojo.entity.BigTitle; |
|
|
|
|
import org.springblade.modules.business.pojo.entity.Device; |
|
|
|
|
import org.springblade.modules.business.pojo.entity.DeviceVO; |
|
|
|
|
import org.springblade.modules.business.pojo.entity.maintenance.MaintenancePlan; |
|
|
|
|
import org.springblade.modules.business.pojo.entity.maintenance.MaintenancePlanOutputData; |
|
|
|
|
import org.springblade.modules.business.service.IDeviceService; |
|
|
|
|
import org.springblade.modules.business.service.IMaintenancePlanDetailService; |
|
|
|
|
import org.springblade.modules.business.mapper.MaintenancePlanDetailMapper; |
|
|
|
|
import org.springblade.modules.business.pojo.entity.maintenance.MaintenancePlanDetail; |
|
|
|
|
import org.springblade.modules.system.pojo.entity.Dept; |
|
|
|
|
import org.springblade.modules.system.service.IDeptService; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.OutputStream; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.zip.ZipOutputStream; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 巡检计划详情 服务实现类 |
|
|
|
|
@ -31,6 +40,8 @@ import java.util.zip.ZipOutputStream; |
|
|
|
|
@Service |
|
|
|
|
@AllArgsConstructor |
|
|
|
|
public class MaintenancePlanDetailServiceImpl extends BaseServiceImpl<MaintenancePlanDetailMapper, MaintenancePlanDetail> implements IMaintenancePlanDetailService { |
|
|
|
|
private final IDeviceService deviceService; |
|
|
|
|
private final IDeptService deptService; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void maintenancePlanReport(MaintenancePlan maintenancePlan, HttpServletResponse response) throws IOException { |
|
|
|
|
@ -38,11 +49,22 @@ public class MaintenancePlanDetailServiceImpl extends BaseServiceImpl<Maintenanc |
|
|
|
|
String templateFile = "./src/main/resources/excel/MaintenancePlanReport.xlsx"; |
|
|
|
|
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); |
|
|
|
|
List<MaintenancePlanDetail> maintenancePlanDetailsList = baseMapper.selectList(Wrappers.lambdaQuery(MaintenancePlanDetail.class).eq(MaintenancePlanDetail::getPlanId, maintenancePlan.getId())); |
|
|
|
|
List<DeviceVO> deviceVOList = new ArrayList<>(); |
|
|
|
|
List<MaintenancePlanOutputData> maintenancePlanOutputDataList = new ArrayList<>(); |
|
|
|
|
for (MaintenancePlanDetail maintenancePlanDetail : maintenancePlanDetailsList) { |
|
|
|
|
//sheet1数据获取
|
|
|
|
|
MaintenancePlanOutputData maintenancePlanOutputData = new MaintenancePlanOutputData(); |
|
|
|
|
maintenancePlanOutputData.setMajorName(maintenancePlanDetail.getMajorName()); |
|
|
|
|
maintenancePlanOutputData.setAddress(maintenancePlan.getAddress()); |
|
|
|
|
Device device = deviceService.getById(maintenancePlanDetail.getDeviceId()); |
|
|
|
|
maintenancePlanOutputData.setMajorName(device.getName()); |
|
|
|
|
Long limsId = device.getLimsId(); |
|
|
|
|
String deptAddress = ""; |
|
|
|
|
Dept lims = deptService.getById(limsId); |
|
|
|
|
deptAddress = deptAddress + lims.getDeptName(); |
|
|
|
|
Dept floor = deptService.getById(device.getFloorId()); |
|
|
|
|
deptAddress = deptAddress + "/" + floor.getDeptName(); |
|
|
|
|
Dept dept = deptService.getById(device.getRoomId()); |
|
|
|
|
deptAddress = deptAddress + "/" + dept.getDeptName(); |
|
|
|
|
maintenancePlanOutputData.setAddress(deptAddress); |
|
|
|
|
maintenancePlanOutputData.setCraft(maintenancePlanDetail.getCraft()); |
|
|
|
|
maintenancePlanOutputData.setCheckContent(maintenancePlanDetail.getCheckContent()); |
|
|
|
|
Optional<Integer> period = Optional.ofNullable(maintenancePlanDetail.getPeriod()); |
|
|
|
|
@ -58,12 +80,61 @@ public class MaintenancePlanDetailServiceImpl extends BaseServiceImpl<Maintenanc |
|
|
|
|
maintenancePlanOutputData.setPeriod(null); |
|
|
|
|
} |
|
|
|
|
maintenancePlanOutputDataList.add(maintenancePlanOutputData); |
|
|
|
|
|
|
|
|
|
//sheet2数据获取
|
|
|
|
|
DeviceVO deviceVO = new DeviceVO(); |
|
|
|
|
deviceVO.setFloor(floor.getDeptName()); |
|
|
|
|
deviceVO.setDept(dept.getDeptName()); |
|
|
|
|
deviceVO.setDeviceName(device.getName()); |
|
|
|
|
deviceVO.setUnit("套"); |
|
|
|
|
deviceVO.setNum(1); |
|
|
|
|
deviceVO.setCheckContent(maintenancePlanDetail.getCheckContent()); |
|
|
|
|
deviceVO.setCraft(maintenancePlanDetail.getCraft()); |
|
|
|
|
deviceVO.setType(device.getType()); |
|
|
|
|
if (period.isPresent()) { |
|
|
|
|
if (period.get() == 1) { |
|
|
|
|
deviceVO.setPeriod("每月"); |
|
|
|
|
} else if (period.get() == 2) { |
|
|
|
|
deviceVO.setPeriod("每季"); |
|
|
|
|
} else if (period.get() == 3) { |
|
|
|
|
deviceVO.setPeriod("每半年"); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
deviceVO.setPeriod(null); |
|
|
|
|
} |
|
|
|
|
deviceVOList.add(deviceVO); |
|
|
|
|
} |
|
|
|
|
Map<String, List<DeviceVO>> deviceVOGroups = deviceVOList.stream().collect(Collectors.groupingBy(DeviceVO::getType)); |
|
|
|
|
int tableNo = 0; |
|
|
|
|
//导出到Excel中
|
|
|
|
|
ServletOutputStream outputStream = response.getOutputStream(); |
|
|
|
|
try (ExcelWriter excelWriter = EasyExcel.write(outputStream).withTemplate(templateFile).build()) { |
|
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet().build(); |
|
|
|
|
excelWriter.fill(maintenancePlanOutputDataList, fillConfig, writeSheet); |
|
|
|
|
WriteSheet firstSheet = EasyExcel.writerSheet(0).build(); |
|
|
|
|
WriteSheet secondSheet = EasyExcel |
|
|
|
|
.writerSheet(1) |
|
|
|
|
.registerWriteHandler(new CustomCellWriteHeightConfig()) |
|
|
|
|
.registerWriteHandler(new CustomCellWriteWidthConfig()) |
|
|
|
|
.build(); |
|
|
|
|
excelWriter.fill(maintenancePlanOutputDataList, fillConfig, firstSheet); |
|
|
|
|
for (Map.Entry<String, List<DeviceVO>> entry : deviceVOGroups.entrySet()) { |
|
|
|
|
List<BigTitle> bigTitleList = new ArrayList<>(); |
|
|
|
|
BigTitle bigTitle = new BigTitle(); |
|
|
|
|
bigTitle.setTitle(entry.getValue().get(0).getType() + "维保清单"); |
|
|
|
|
bigTitleList.add(bigTitle); |
|
|
|
|
WriteTable writeTable1 = EasyExcel.writerTable() |
|
|
|
|
.tableNo(tableNo++) |
|
|
|
|
.registerWriteHandler(new MergeColumnStrategy(0, 7)) |
|
|
|
|
.needHead(false) |
|
|
|
|
.head(BigTitle.class) |
|
|
|
|
.build(); |
|
|
|
|
excelWriter.write(bigTitleList, secondSheet, writeTable1); |
|
|
|
|
WriteTable writeTable = EasyExcel.writerTable() |
|
|
|
|
.tableNo(tableNo++) |
|
|
|
|
.needHead(true) |
|
|
|
|
.head(DeviceVO.class) |
|
|
|
|
.build(); |
|
|
|
|
excelWriter.write(entry.getValue(), secondSheet, writeTable); |
|
|
|
|
} |
|
|
|
|
excelWriter.finish(); |
|
|
|
|
outputStream.flush(); |
|
|
|
|
outputStream.close(); |
|
|
|
|
|