|
@@ -1,7 +1,6 @@
|
|
|
package org.springblade.business.controller;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
-import com.aspose.cells.Workbook;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.BeanUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
@@ -11,6 +10,7 @@ import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.SneakyThrows;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
import org.springblade.business.dto.EKeyDto;
|
|
|
import org.springblade.business.dto.NeiYeLedgerDto1;
|
|
|
import org.springblade.business.entity.ConstructionLedger;
|
|
@@ -23,6 +23,7 @@ import org.springblade.business.vo.NeiYeLedgerVO1;
|
|
|
import org.springblade.business.vo.NeiYeQueryVO;
|
|
|
import org.springblade.business.vo.QueryProcessDataVO;
|
|
|
import org.springblade.common.utils.CommonUtil;
|
|
|
+import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
import org.springblade.core.mp.support.Condition;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.utils.BeanUtil;
|
|
@@ -35,12 +36,19 @@ import org.springblade.manager.feign.ContractClient;
|
|
|
import org.springblade.manager.feign.WbsTreeContractClient;
|
|
|
import org.springblade.manager.feign.WbsTreePrivateClient;
|
|
|
import org.springblade.manager.vo.WbsTreeContractTreeVOS;
|
|
|
+import org.springframework.core.io.ByteArrayResource;
|
|
|
+import org.springframework.core.io.Resource;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.jdbc.core.SingleColumnRowMapper;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springblade.core.mp.support.Query;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.InputStream;
|
|
@@ -436,6 +444,7 @@ public class NeiYeController {
|
|
|
}
|
|
|
}
|
|
|
if(type==2){
|
|
|
+ vo2.setId(SnowFlakeUtil.getId());
|
|
|
voList.add(vo2);
|
|
|
}
|
|
|
}
|
|
@@ -447,6 +456,7 @@ public class NeiYeController {
|
|
|
vo1.setGoodCount(goodCount);
|
|
|
vo1.setPassCount(passCount);
|
|
|
vo1.setGoodRate(calculatePercentage(goodCount,unitCount));
|
|
|
+ vo1.setId(SnowFlakeUtil.getId());
|
|
|
voList.add(vo1);
|
|
|
return R.data(voList);
|
|
|
}
|
|
@@ -456,12 +466,44 @@ public class NeiYeController {
|
|
|
}
|
|
|
|
|
|
@SneakyThrows
|
|
|
- @GetMapping("/downloadNeiYe")
|
|
|
+ @PostMapping ("/downloadNeiYe")
|
|
|
@ApiOperationSupport(order = 13)
|
|
|
@ApiOperation(value = "客户端-下载元素表对应的excel模板")
|
|
|
- public void downloadNeiYe(@RequestBody List<NeiYeLedgerVO1> list){
|
|
|
+ public ResponseEntity<Resource> downloadNeiYe(@RequestBody List<NeiYeLedgerVO1> list, HttpServletResponse response){
|
|
|
+ String templatePath="/mnt/sdc/Users/hongchuangyanfa/Desktop/excel/neiye.xlsx";
|
|
|
+ //String templatePath="E:\\html\\neiye.xlsx";
|
|
|
+ // 1. 从服务器读取模板文件
|
|
|
+ InputStream templateStream = new FileInputStream(new File(templatePath));
|
|
|
+ org.apache.poi.ss.usermodel.Workbook workbook = WorkbookFactory.create(templateStream);
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ // 3. 填充数据(假设数据从第2行开始填充)
|
|
|
+ int startRow = 1; // 第2行开始填充数据
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ Row row = sheet.createRow(startRow + i);
|
|
|
+ NeiYeLedgerVO1 vo1 = list.get(i);
|
|
|
+ // 填充各列数据
|
|
|
+ row.createCell(0).setCellValue(i + 1); // 序号
|
|
|
+ row.createCell(1).setCellValue(vo1.getClassName()); // 单位工程
|
|
|
+ row.createCell(2).setCellValue(vo1.getPartName()); // 分部工程
|
|
|
+ row.createCell(3).setCellValue(vo1.getSubPartName()); // 子分部工程
|
|
|
+ row.createCell(4).setCellValue(vo1.getUnitName()); // 单元工程
|
|
|
+ row.createCell(5).setCellValue(vo1.getUnitCount().toString()); // 单元工程个数
|
|
|
+ row.createCell(6).setCellValue(vo1.getPassCount().toString()); // 合格个数
|
|
|
+ row.createCell(7).setCellValue(vo1.getGoodCount().toString()); // 优良个数
|
|
|
+ row.createCell(8).setCellValue(vo1.getGoodRate()); // 优良率
|
|
|
+ }
|
|
|
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
+ workbook.write(outputStream);
|
|
|
+ workbook.close();
|
|
|
+ ByteArrayResource resource = new ByteArrayResource(outputStream.toByteArray());
|
|
|
|
|
|
+ return ResponseEntity.ok()
|
|
|
+ .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=neiye.xlsx")
|
|
|
+ .contentType(MediaType.APPLICATION_OCTET_STREAM)
|
|
|
+ .contentLength(resource.contentLength())
|
|
|
+ .body(resource);
|
|
|
}
|
|
|
+
|
|
|
public static String calculatePercentage(Integer numerator, Integer denominator) {
|
|
|
if (denominator == null || denominator == 0) {
|
|
|
return "0%";
|