|
@@ -11,6 +11,10 @@ import com.management.platform.service.FinanceMonthlyWorktimeService;
|
|
import com.management.platform.service.FmwDetailService;
|
|
import com.management.platform.service.FmwDetailService;
|
|
import com.management.platform.task.DataCollectTask;
|
|
import com.management.platform.task.DataCollectTask;
|
|
import com.management.platform.util.HttpRespMsg;
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.core.ParameterizedTypeReference;
|
|
import org.springframework.core.ParameterizedTypeReference;
|
|
import org.springframework.http.*;
|
|
import org.springframework.http.*;
|
|
@@ -21,6 +25,7 @@ import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import java.io.FileOutputStream;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
@@ -385,4 +390,178 @@ public class FinanceMonthlyWorktimeServiceImpl extends ServiceImpl<FinanceMonthl
|
|
financeMonthlyWorktimeMapper.updateById(financeMonthlyWorktime);
|
|
financeMonthlyWorktimeMapper.updateById(financeMonthlyWorktime);
|
|
return new HttpRespMsg();
|
|
return new HttpRespMsg();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional
|
|
|
|
+ public HttpRespMsg exportByMonth(Integer companyId, String ymonth, Integer reGenerate, HttpServletRequest request) throws Exception {
|
|
|
|
+ //获取该月份的数据,如果没有自动生成
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ String token = request.getHeader("token");
|
|
|
|
+ User user = userMapper.selectById(token);
|
|
|
|
+ HttpRespMsg respMsg = getByMonth(companyId, ymonth, reGenerate, request);
|
|
|
|
+ FinanceMonthlyWorktime financeMonthlyWorktime = (FinanceMonthlyWorktime) respMsg.getData();
|
|
|
|
+ List<FmwDetail> detailList = financeMonthlyWorktime.getDetailList();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 1. 创建工作簿和工作表
|
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
|
+ Sheet sheet = workbook.createSheet("工程工时表");
|
|
|
|
+
|
|
|
|
+ // 2. 创建样式
|
|
|
|
+ CellStyle headerStyle = createHeaderStyle(workbook);
|
|
|
|
+ CellStyle dataStyle = createDataStyle(workbook);
|
|
|
|
+
|
|
|
|
+ // 3. 创建多级表头
|
|
|
|
+ // 第一行表头(主标题)
|
|
|
|
+ Row headerRow1 = sheet.createRow(0);
|
|
|
|
+ String[] mainHeaders = {
|
|
|
|
+ "项目号", "工单号", "行号", "车间组装/维修工时(h)","","","",
|
|
|
|
+ "项目工时(h)", "协助工时(h)", "公摊工时(h)", "工时合计(h)"
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ // 第二行表头(子标题)
|
|
|
|
+ Row headerRow2 = sheet.createRow(1);
|
|
|
|
+ String[] subHeaders = {
|
|
|
|
+ "", "", "", "组装工时(h)", "维修工时(h)", "调试工时(h)", "等料工时(h)",
|
|
|
|
+ "", "", "", ""
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ // 设置主标题
|
|
|
|
+ for (int i = 0; i < mainHeaders.length; i++) {
|
|
|
|
+ Cell cell = headerRow1.createCell(i);
|
|
|
|
+ cell.setCellValue(mainHeaders[i]);
|
|
|
|
+ cell.setCellStyle(headerStyle);
|
|
|
|
+ // 合并"车间组装/维修工时(h)"下方的4个单元格
|
|
|
|
+ if (i == 3) {
|
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(0, 0, 3, 6));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 设置子标题
|
|
|
|
+ for (int i = 0; i < subHeaders.length; i++) {
|
|
|
|
+ Cell cell = headerRow2.createCell(i);
|
|
|
|
+ cell.setCellValue(subHeaders[i]);
|
|
|
|
+ cell.setCellStyle(headerStyle);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < 3; i++) {
|
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(0, 1, i, i));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (int i = 7; i < 11; i++) {
|
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(0, 1, i, i));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 5. 自动调整列宽
|
|
|
|
+ for (int i = 0; i < mainHeaders.length ; i++) {
|
|
|
|
+ sheet.setColumnWidth(i, 18 * 256); // 0表示第一列
|
|
|
|
+ }
|
|
|
|
+ if (!detailList.isEmpty()) {
|
|
|
|
+ for (int i = 0; i < detailList.size(); i++) {
|
|
|
|
+ Row row = sheet.createRow(i + 2);
|
|
|
|
+ Cell cell1 = row.createCell(0);
|
|
|
|
+ FmwDetail fmwDetail = detailList.get(i);
|
|
|
|
+ cell1.setCellValue(StringUtils.isEmpty(fmwDetail.getProjectCode())?"":fmwDetail.getProjectCode());
|
|
|
|
+ cell1.setCellStyle(dataStyle);
|
|
|
|
+
|
|
|
|
+ // 2. 工单号
|
|
|
|
+ Cell cell2 = row.createCell(1);
|
|
|
|
+ cell2.setCellValue(StringUtils.isEmpty(fmwDetail.getExtraField4()) ? "" : fmwDetail.getExtraField4());
|
|
|
|
+ cell2.setCellStyle(dataStyle);
|
|
|
|
+
|
|
|
|
+ // 3. 行号
|
|
|
|
+ Cell cell3 = row.createCell(2);
|
|
|
|
+ cell3.setCellValue(StringUtils.isEmpty(fmwDetail.getExtraField5()) ? "" : fmwDetail.getExtraField5());
|
|
|
|
+ cell3.setCellStyle(dataStyle);
|
|
|
|
+
|
|
|
|
+ // 4. 车间组装/维修工时(子分类)
|
|
|
|
+ // 4.1 组装工时
|
|
|
|
+ Cell cell4 = row.createCell(3);
|
|
|
|
+ cell4.setCellValue(fmwDetail.getComposeTime() == null ? 0 : fmwDetail.getComposeTime());
|
|
|
|
+ cell4.setCellStyle(dataStyle);
|
|
|
|
+
|
|
|
|
+ // 4.2 维修工时
|
|
|
|
+ Cell cell5 = row.createCell(4);
|
|
|
|
+ cell5.setCellValue(fmwDetail.getRepairTime() == null ? 0 : fmwDetail.getRepairTime());
|
|
|
|
+ cell5.setCellStyle(dataStyle);
|
|
|
|
+
|
|
|
|
+ // 4.3 调试工时
|
|
|
|
+ Cell cell6 = row.createCell(5);
|
|
|
|
+ cell6.setCellValue(fmwDetail.getDebugTime() == null ? 0 : fmwDetail.getDebugTime());
|
|
|
|
+ cell6.setCellStyle(dataStyle);
|
|
|
|
+
|
|
|
|
+ // 4.4 等料工时
|
|
|
|
+ Cell cell7 = row.createCell(6);
|
|
|
|
+ cell7.setCellValue(fmwDetail.getWaitingTime() == null ? 0 : fmwDetail.getWaitingTime());
|
|
|
|
+ cell7.setCellStyle(dataStyle);
|
|
|
|
+
|
|
|
|
+ // 5. 项目工时
|
|
|
|
+ Cell cell8 = row.createCell(7);
|
|
|
|
+// cell8.setCellValue(fmwDetail.getProjectWorkingHours() == null ? 0 : fmwDetail.getProjectWorkingHours());
|
|
|
|
+ cell8.setCellValue(3);
|
|
|
|
+ cell8.setCellStyle(dataStyle);
|
|
|
|
+
|
|
|
|
+ // 6. 协助工时
|
|
|
|
+ Cell cell9 = row.createCell(8);
|
|
|
|
+ cell9.setCellValue(fmwDetail.getAssistTime() == null ? 0 : fmwDetail.getAssistTime());
|
|
|
|
+ cell9.setCellStyle(dataStyle);
|
|
|
|
+
|
|
|
|
+ // 7. 公摊工时
|
|
|
|
+ Cell cell10 = row.createCell(9);
|
|
|
|
+ cell10.setCellValue(fmwDetail.getPublicTime() == null ? 0 : fmwDetail.getPublicTime());
|
|
|
|
+ cell10.setCellStyle(dataStyle);
|
|
|
|
+
|
|
|
|
+ // 8. 工时合计(计算字段)
|
|
|
|
+ double totalHours = 0
|
|
|
|
+// (fmwDetail.getMaintanceTime() != null ? fmwDetail.getMaintanceTime() : 0)
|
|
|
|
+ + (fmwDetail.getDebugTime() != null ? fmwDetail.getDebugTime() : 0)
|
|
|
|
+ + (fmwDetail.getWaitingTime() != null ? fmwDetail.getWaitingTime() : 0)
|
|
|
|
+ + (fmwDetail.getAssistTime() != null ? fmwDetail.getAssistTime() : 0)
|
|
|
|
+ + (fmwDetail.getPublicTime() != null ? fmwDetail.getPublicTime() : 0)
|
|
|
|
+ + (fmwDetail.getComposeTime() != null ? fmwDetail.getComposeTime() : 0);
|
|
|
|
+
|
|
|
|
+ Cell cell11 = row.createCell(10);
|
|
|
|
+ cell11.setCellValue(totalHours);
|
|
|
|
+ cell11.setCellStyle(dataStyle);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 6. 写入文件
|
|
|
|
+ try (FileOutputStream outputStream = new FileOutputStream("C:/upload/"+"工程工时表.xlsx")) {
|
|
|
|
+ workbook.write(outputStream);
|
|
|
|
+ }
|
|
|
|
+ workbook.close();
|
|
|
|
+ System.out.println("Excel文件已生成!");
|
|
|
|
+
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static CellStyle createHeaderStyle(Workbook workbook) {
|
|
|
|
+ CellStyle style = workbook.createCellStyle();
|
|
|
|
+ style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
|
|
|
|
+ style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
|
+ style.setBorderBottom(BorderStyle.THIN);
|
|
|
|
+ style.setBorderTop(BorderStyle.THIN);
|
|
|
|
+ style.setBorderLeft(BorderStyle.THIN);
|
|
|
|
+ style.setBorderRight(BorderStyle.THIN);
|
|
|
|
+ Font font = workbook.createFont();
|
|
|
|
+ font.setBold(true);
|
|
|
|
+ style.setFont(font);
|
|
|
|
+ style.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
|
+ return style;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static CellStyle createDataStyle(Workbook workbook) {
|
|
|
|
+ CellStyle style = workbook.createCellStyle();
|
|
|
|
+ style.setBorderBottom(BorderStyle.THIN);
|
|
|
|
+ style.setBorderTop(BorderStyle.THIN);
|
|
|
|
+ style.setBorderLeft(BorderStyle.THIN);
|
|
|
|
+ style.setBorderRight(BorderStyle.THIN);
|
|
|
|
+ style.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
+ DataFormat format = workbook.createDataFormat();
|
|
|
|
+ style.setDataFormat(format.getFormat("0.0"));
|
|
|
|
+ return style;
|
|
|
|
+ }
|
|
}
|
|
}
|