Commit eff9e3eb by jiangxuming

feat: 孙主任提的导出表

parent 2f8c62b5
...@@ -645,6 +645,21 @@ public class EntrustSampleController extends ServiceController { ...@@ -645,6 +645,21 @@ public class EntrustSampleController extends ServiceController {
return success(entrustSampleService.getAlGradeStatsQuery(statsQueryDTO)); return success(entrustSampleService.getAlGradeStatsQuery(statsQueryDTO));
} }
@ApiOperation("导出原铝台账(总厂)")
@PostMapping("/labor_hour_statistics_table")
public void laborHourStatisticsTable(StatsQueryDTO statsQueryDTO) {
entrustSampleService.laborHourStatisticsTable(statsQueryDTO,response);
}
@ApiOperation("导出原铝台账(总厂)")
@PostMapping("/labor_hour_statistics_table_sub")
public void laborHourStatisticsTableSub(StatsQueryDTO statsQueryDTO) {
entrustSampleService.laborHourStatisticsTableSub(statsQueryDTO,response);
}
@ApiOperation("电解质分子比统计查询") @ApiOperation("电解质分子比统计查询")
@PostMapping("/electrolyte_ratio_stats_query") @PostMapping("/electrolyte_ratio_stats_query")
public RestResult<List<ElectrolyteRatioStatsVO>> getElectrolyteRatioStatsQuery(QueryDTO queryDTO) { public RestResult<List<ElectrolyteRatioStatsVO>> getElectrolyteRatioStatsQuery(QueryDTO queryDTO) {
......
...@@ -587,6 +587,13 @@ public class EntrustSampleItemController extends ServiceController { ...@@ -587,6 +587,13 @@ public class EntrustSampleItemController extends ServiceController {
return success(entrustSampleItemService.deviatePass(ids, getAccount())); return success(entrustSampleItemService.deviatePass(ids, getAccount()));
} }
@Login(action = Action.Skip)
@ApiOperation("外部查询,供SAP系统查询")
@PostMapping("/get_data")
public RestResult<List<EntrustSampleItemVO>> getData(EntrustSampleItemVO entrustSampleItem) {
return success(entrustSampleItemService.getData(entrustSampleItem));
}
@ApiOperation("偏离审批驳回") @ApiOperation("偏离审批驳回")
@PostMapping("/deviate_back") @PostMapping("/deviate_back")
......
...@@ -91,5 +91,6 @@ public interface EntrustSampleItemMapper extends BatchMapper<EntrustSampleItem> ...@@ -91,5 +91,6 @@ public interface EntrustSampleItemMapper extends BatchMapper<EntrustSampleItem>
Integer deletePhysicalByEntrustIds(@Param("entrustIds") List<Long> entrustIds); Integer deletePhysicalByEntrustIds(@Param("entrustIds") List<Long> entrustIds);
@SqlParser(filter = true)
List<EntrustSampleItemVO> getData(@Param("vo") EntrustSampleItemVO vo);
} }
...@@ -54,4 +54,6 @@ public interface EntrustSampleMapper extends BatchMapper<EntrustSample> { ...@@ -54,4 +54,6 @@ public interface EntrustSampleMapper extends BatchMapper<EntrustSample> {
int isRepeatSampleCode(@Param("vo") EntrustSample sample); int isRepeatSampleCode(@Param("vo") EntrustSample sample);
Integer deletePhysicalByEntrustIds(@Param("entrustIds") List<Long> entrustIds); Integer deletePhysicalByEntrustIds(@Param("entrustIds") List<Long> entrustIds);
List<EntrustSampleItemVO> laborHourStatisticsTable(@Param("dto") StatsQueryDTO queryDTO);
} }
...@@ -141,4 +141,6 @@ public interface IEntrustSampleItemService extends IBaseService<EntrustSampleIte ...@@ -141,4 +141,6 @@ public interface IEntrustSampleItemService extends IBaseService<EntrustSampleIte
boolean deletePhysicalByEntrustIds(List<Long> ids); boolean deletePhysicalByEntrustIds(List<Long> ids);
Boolean sendErpData(List<Long> entrustIds); Boolean sendErpData(List<Long> entrustIds);
List<EntrustSampleItemVO> getData(EntrustSampleItemVO entrustSampleItem);
} }
...@@ -68,6 +68,9 @@ public interface IEntrustSampleService extends IBaseService<EntrustSample> { ...@@ -68,6 +68,9 @@ public interface IEntrustSampleService extends IBaseService<EntrustSample> {
List<AlGradeStatsVO> getAlGradeStatsQuery(StatsQueryDTO queryDTO); List<AlGradeStatsVO> getAlGradeStatsQuery(StatsQueryDTO queryDTO);
void laborHourStatisticsTable(StatsQueryDTO queryDTO, HttpServletResponse response);
void laborHourStatisticsTableSub(StatsQueryDTO queryDTO, HttpServletResponse response);
List<ElectrolyteRatioStatsVO> getElectrolyteRatioStatsQuery(QueryDTO queryDTO); List<ElectrolyteRatioStatsVO> getElectrolyteRatioStatsQuery(QueryDTO queryDTO);
Map<String, Object> getPMakeFeStatsQuery(QueryDTO queryDTO); Map<String, Object> getPMakeFeStatsQuery(QueryDTO queryDTO);
......
...@@ -1817,6 +1817,11 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI ...@@ -1817,6 +1817,11 @@ public class EntrustSampleItemServiceImpl extends BaseServiceImpl<EntrustSampleI
return false; return false;
} }
@Override
public List<EntrustSampleItemVO> getData(EntrustSampleItemVO entrustSampleItem) {
return baseMapper.getData(entrustSampleItem);
}
private String getCellValue(XSSFRow xssfRow, int cellIndex) { private String getCellValue(XSSFRow xssfRow, int cellIndex) {
XSSFCell cell = xssfRow.getCell(cellIndex); XSSFCell cell = xssfRow.getCell(cellIndex);
String value = HSSFWorkbookUtil.getJavaValue(cell).toString(); String value = HSSFWorkbookUtil.getJavaValue(cell).toString();
......
...@@ -22,17 +22,21 @@ import com.patzn.cloud.service.hmhj.dto.*; ...@@ -22,17 +22,21 @@ import com.patzn.cloud.service.hmhj.dto.*;
import com.patzn.cloud.service.hmhj.entity.*; import com.patzn.cloud.service.hmhj.entity.*;
import com.patzn.cloud.service.hmhj.enums.*; import com.patzn.cloud.service.hmhj.enums.*;
import com.patzn.cloud.service.hmhj.vo.*; import com.patzn.cloud.service.hmhj.vo.*;
import com.patzn.cloud.service.lims.collection.entity.LmsCollectionConfig;
import com.patzn.cloud.service.lims.common.BeanUtils; import com.patzn.cloud.service.lims.common.BeanUtils;
import com.patzn.cloud.service.lims.common.StringHandleUtils; import com.patzn.cloud.service.lims.common.StringHandleUtils;
import com.patzn.cloud.service.lims.hmhj.common.HSSFWorkbookUtil; import com.patzn.cloud.service.lims.hmhj.common.HSSFWorkbookUtil;
import com.patzn.cloud.service.lims.hmhj.mapper.EntrustSampleMapper; import com.patzn.cloud.service.lims.hmhj.mapper.EntrustSampleMapper;
import com.patzn.cloud.service.lims.hmhj.original.OriginalUtil; import com.patzn.cloud.service.lims.hmhj.original.OriginalUtil;
import com.patzn.cloud.service.lims.hmhj.service.*; import com.patzn.cloud.service.lims.hmhj.service.*;
import com.patzn.poibox.excel.diff.info.Files;
import com.patzn.poibox.xwpf.PoiUtil2007; import com.patzn.poibox.xwpf.PoiUtil2007;
import com.patzn.poibox.xwpf.WorkbookUtils;
import com.patzn.poibox.xwpf.XWPFTemplate; import com.patzn.poibox.xwpf.XWPFTemplate;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.RowBounds;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.*; import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
...@@ -49,6 +53,7 @@ import java.math.BigDecimal; ...@@ -49,6 +53,7 @@ import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -94,6 +99,32 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe ...@@ -94,6 +99,32 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
private IContractSampleRecordService contractSampleRecordService; private IContractSampleRecordService contractSampleRecordService;
@Autowired @Autowired
private IEntrustSampleBackupService entrustSampleBackupService; private IEntrustSampleBackupService entrustSampleBackupService;
// 直接定义每个区域的范围
private static final Map<String, int[]> ZONE_RANGE_MAP = new HashMap<>();
static {
ZONE_RANGE_MAP.put("1.1区", new int[]{1001, 1048});
ZONE_RANGE_MAP.put("1.2区", new int[]{1049, 1094});
ZONE_RANGE_MAP.put("1.3区", new int[]{1095, 1142});
ZONE_RANGE_MAP.put("2.1区", new int[]{2001, 2048});
ZONE_RANGE_MAP.put("2.2区", new int[]{2049, 2094});
ZONE_RANGE_MAP.put("2.3区", new int[]{2095,2142});
ZONE_RANGE_MAP.put("3.1区", new int[]{3001, 3045});
ZONE_RANGE_MAP.put("3.2区", new int[]{3049, 3094});
ZONE_RANGE_MAP.put("3.3区", new int[]{3094, 3142});
ZONE_RANGE_MAP.put("4.1区", new int[]{4001, 4048});
ZONE_RANGE_MAP.put("4.2区", new int[]{4049, 4094});
ZONE_RANGE_MAP.put("4.3区", new int[]{4095, 4142});
ZONE_RANGE_MAP.put("5.1区", new int[]{5001, 5045});
ZONE_RANGE_MAP.put("5.2区", new int[]{5046, 5090});
ZONE_RANGE_MAP.put("5.3区", new int[]{5091, 5135});
ZONE_RANGE_MAP.put("5.4区", new int[]{5136, 5180});
ZONE_RANGE_MAP.put("6.1区", new int[]{6001, 6045});
ZONE_RANGE_MAP.put("6.2区", new int[]{6046, 6090});
ZONE_RANGE_MAP.put("6.3区", new int[]{6091, 6135});
ZONE_RANGE_MAP.put("6.4区", new int[]{6136, 6180});
}
@Override @Override
public Page<EntrustSample> page(Page<EntrustSample> page, EntrustSample entrustSample) { public Page<EntrustSample> page(Page<EntrustSample> page, EntrustSample entrustSample) {
...@@ -331,6 +362,415 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe ...@@ -331,6 +362,415 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
resultList.add(alGradeStatsVO); resultList.add(alGradeStatsVO);
return resultList; return resultList;
} }
@Override
public void laborHourStatisticsTableSub(StatsQueryDTO queryDTO, HttpServletResponse response){
List<File> downFiles = new ArrayList<>();
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("templates/excel/YLExport2.xlsx");
Workbook workbook;
File file = null;
try {
// 创建工作簿
workbook = WorkbookFactory.create(inputStream);
int numberOfSheets = workbook.getNumberOfSheets();
// 获取数据
List<EntrustSampleItemVO> list = baseMapper.laborHourStatisticsTable(queryDTO);
for (int i = 1; i < numberOfSheets; i++) {
Sheet sheet = workbook.getSheetAt(i);
String sheetName = sheet.getSheetName();
int[] ints = ZONE_RANGE_MAP.get(sheetName.trim());
List<EntrustSampleItemVO> collect = list.stream().filter(s -> Integer.parseInt(s.getSlotNo()) >= ints[0] && Integer.parseInt(s.getSlotNo()) <= ints[1]).collect(Collectors.toList());
if(CollectionUtils.isEmpty(collect)){
continue;
}
Integer day = collect.get(0).getDay();
//判断奇数偶数
int m = 0;
if (day % 2 == 0) {
for (int k = 0; k < 6; k++) {
sheet.getRow(1).getCell(m + 1).setCellValue(2);
sheet.getRow(1).getCell(m + 2).setCellValue(4);
sheet.getRow(1).getCell(m + 3).setCellValue(6);
sheet.getRow(1).getCell(m + 4).setCellValue(8);
sheet.getRow(1).getCell(m + 5).setCellValue(10);
sheet.getRow(1).getCell(m + 6).setCellValue(12);
sheet.getRow(1).getCell(m + 7).setCellValue(14);
sheet.getRow(1).getCell(m + 8).setCellValue(16);
sheet.getRow(1).getCell(m + 9).setCellValue(18);
sheet.getRow(1).getCell(m + 10).setCellValue(20);
sheet.getRow(1).getCell(m + 11).setCellValue(22);
sheet.getRow(1).getCell(m + 12).setCellValue(24);
sheet.getRow(1).getCell(m + 13).setCellValue(26);
sheet.getRow(1).getCell(m + 14).setCellValue(28);
sheet.getRow(1).getCell(m + 15).setCellValue(30);
sheet.getRow(1).getCell(m + 16).setCellValue("--");
m += 17;
}
} else {
for (int k = 0; k < 6; k++) {
sheet.getRow(1).getCell(m + 1).setCellValue(1);
sheet.getRow(1).getCell(m + 2).setCellValue(3);
sheet.getRow(1).getCell(m + 3).setCellValue(5);
sheet.getRow(1).getCell(m + 4).setCellValue(7);
sheet.getRow(1).getCell(m + 5).setCellValue(9);
sheet.getRow(1).getCell(m + 6).setCellValue(11);
sheet.getRow(1).getCell(m + 7).setCellValue(13);
sheet.getRow(1).getCell(m + 8).setCellValue(15);
sheet.getRow(1).getCell(m + 9).setCellValue(17);
sheet.getRow(1).getCell(m + 10).setCellValue(19);
sheet.getRow(1).getCell(m + 11).setCellValue(21);
sheet.getRow(1).getCell(m + 12).setCellValue(23);
sheet.getRow(1).getCell(m + 13).setCellValue(25);
sheet.getRow(1).getCell(m + 14).setCellValue(27);
sheet.getRow(1).getCell(m + 15).setCellValue(29);
sheet.getRow(1).getCell(m + 16).setCellValue(31);
m += 17;
}
}
}
//构建品味数据
HashMap<String, String> gradingMap = new HashMap<>();
for (EntrustSampleItemVO vo : list) {
gradingMap.putIfAbsent(vo.getDay() + "#" + vo.getSlotNo(), vo.getSampleGrading());
}
//填充数据
for (int i = 1; i < numberOfSheets; i++) {
Sheet sheet = workbook.getSheetAt(i);
int lastRowNum = sheet.getLastRowNum();
Row row = sheet.getRow(0);
short lastCellNum = row.getLastCellNum();
for (int i1 = 0; i1 < lastCellNum; i1++) {
String cellValue = WorkbookUtils.getCellValue(row.getCell(i1));
if(StringUtils.isNotEmpty(cellValue) && StringUtils.contains(cellValue, "MM")) {
String replace = cellValue.replace("MM", DateUtils.formatToString(new Date(), "MM"));
row.getCell(i1).setCellValue(replace);
}
}
for (int j = 2; j <= lastRowNum; j++) {
String sltoNoCel = WorkbookUtils.getCellValue(sheet.getRow(j).getCell(0));
if(null ==sltoNoCel || Objects.isNull(sltoNoCel)) {
break;
}
for (int k = 1; k <= 16; k++) {
String day = WorkbookUtils.getCellValue(sheet.getRow(1).getCell(k));
sheet.getRow(j).getCell(k).setCellValue(gradingMap.get(day + "#" + sltoNoCel));
}
}
}
//构建原铝其他指标数据
HashMap<String, Double> itemMap = new HashMap<>();
for (EntrustSampleItemVO vo : list) {
itemMap.putIfAbsent(vo.getDay() + "#" + vo.getSlotNo() + "#" + vo.getName(), Double.parseDouble(vo.getTestValue()));
}
//填充数据
for (int i = 1; i < numberOfSheets; i++) {
Sheet sheet = workbook.getSheetAt(i);
int lastRowNum = sheet.getLastRowNum();
for (int j = 2; j <= lastRowNum; j++) {
String sltoNoCel = WorkbookUtils.getCellValue(sheet.getRow(j).getCell(0));
if(null ==sltoNoCel || Objects.isNull(sltoNoCel)) {
break;
}
for (int k = 18; k <= 33; k++) {
String day = WorkbookUtils.getCellValue(sheet.getRow(1).getCell(k));
setCellValue(sheet.getRow(j).getCell(k),itemMap.get(day + "#" + sltoNoCel + "#" + "原铝Fe"));
}
for (int k = 35; k <= 50; k++) {
String day = WorkbookUtils.getCellValue(sheet.getRow(1).getCell(k));
setCellValue(sheet.getRow(j).getCell(k),itemMap.get(day + "#" + sltoNoCel + "#" + "原铝Si"));
}
for (int k = 52; k <= 67; k++) {
String day = WorkbookUtils.getCellValue(sheet.getRow(1).getCell(k));
setCellValue(sheet.getRow(j).getCell(k),itemMap.get(day + "#" + sltoNoCel + "#" + "原铝Ni"));
}
for (int k = 69; k <= 84; k++) {
String day = WorkbookUtils.getCellValue(sheet.getRow(1).getCell(k));
setCellValue(sheet.getRow(j).getCell(k),itemMap.get(day + "#" + sltoNoCel + "#" + "原铝Zn"));
}
for (int k = 86; k <= 101; k++) {
String day = WorkbookUtils.getCellValue(sheet.getRow(1).getCell(k));
setCellValue(sheet.getRow(j).getCell(k),itemMap.get(day + "#" + sltoNoCel + "#" + "原铝V"));
}
}
}
// 刷新公式
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
// 遍历所有工作表
for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
Sheet sheet = workbook.getSheetAt(i);
// 遍历所有行
for (int j = 0; j <= sheet.getLastRowNum(); j++) {
Row row = sheet.getRow(j);
if (row != null) { // 检查行是否存在
// 遍历所有单元格
for (int k = 0; k < row.getLastCellNum(); k++) {
Cell cell = row.getCell(k);
if (cell != null && cell.getCellType() == CellType.FORMULA) { // 检查单元格是否存在且是公式类型
try {
evaluator.evaluateFormulaCell(cell);
} catch (Exception e) {
e.printStackTrace();
// 可以选择跳过或替换为默认值
cell.setCellType(CellType.NUMERIC);
cell.setCellValue(0);
}
}
}
}
}
}
file = File.createTempFile("总厂原铝统计表", ".xlsx");
OutputStream out = new FileOutputStream(file);
workbook.write(out);
out.flush();
/*---------------------------------------------------------------------------------------------------------------------------------------------------------------*/
downFiles.add(file);
if (org.apache.commons.collections.CollectionUtils.isEmpty(downFiles)) {
RestAssert.fail("导出失败!");
} else if (downFiles.size() == 1) {
FileUtils.download(new FileInputStream(downFiles.get(0)), downFiles.get(0).getName(), response);
} else {
FileUtils.downLoadFiles(downFiles, DateUtils.dateTransfer(new Date(), "yyyy-MM") + "月份原铝统计表.zip", response);
}
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (null != file && file.exists()) {
file.delete();
}
}
}
@Override
public void laborHourStatisticsTable(StatsQueryDTO queryDTO, HttpServletResponse response) {
List<File> downFiles = new ArrayList<>();
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("templates/excel/YLExport1.xlsx");
Workbook workbook;
File file = null;
try {
// 创建工作簿
workbook = WorkbookFactory.create(inputStream);
int numberOfSheets = workbook.getNumberOfSheets();
// 获取数据
List<EntrustSampleItemVO> list = baseMapper.laborHourStatisticsTable(queryDTO);
for (int i = 1; i < numberOfSheets; i++) {
Sheet sheet = workbook.getSheetAt(i);
String sheetName = sheet.getSheetName();
int[] ints = ZONE_RANGE_MAP.get(sheetName.trim());
List<EntrustSampleItemVO> collect = list.stream().filter(s -> Integer.parseInt(s.getSlotNo()) >= ints[0] && Integer.parseInt(s.getSlotNo()) <= ints[1]).collect(Collectors.toList());
if(CollectionUtils.isEmpty(collect)){
continue;
}
Integer day = collect.get(0).getDay();
//判断奇数偶数
int m = 0;
if (day % 2 == 0) {
for (int k = 0; k < 6; k++) {
sheet.getRow(1).getCell(m + 1).setCellValue(2);
sheet.getRow(1).getCell(m + 2).setCellValue(4);
sheet.getRow(1).getCell(m + 3).setCellValue(6);
sheet.getRow(1).getCell(m + 4).setCellValue(8);
sheet.getRow(1).getCell(m + 5).setCellValue(10);
sheet.getRow(1).getCell(m + 6).setCellValue(12);
sheet.getRow(1).getCell(m + 7).setCellValue(14);
sheet.getRow(1).getCell(m + 8).setCellValue(16);
sheet.getRow(1).getCell(m + 9).setCellValue(18);
sheet.getRow(1).getCell(m + 10).setCellValue(20);
sheet.getRow(1).getCell(m + 11).setCellValue(22);
sheet.getRow(1).getCell(m + 12).setCellValue(24);
sheet.getRow(1).getCell(m + 13).setCellValue(26);
sheet.getRow(1).getCell(m + 14).setCellValue(28);
sheet.getRow(1).getCell(m + 15).setCellValue(30);
sheet.getRow(1).getCell(m + 16).setCellValue("--");
m += 17;
}
} else {
for (int k = 0; k < 6; k++) {
sheet.getRow(1).getCell(m + 1).setCellValue(1);
sheet.getRow(1).getCell(m + 2).setCellValue(3);
sheet.getRow(1).getCell(m + 3).setCellValue(5);
sheet.getRow(1).getCell(m + 4).setCellValue(7);
sheet.getRow(1).getCell(m + 5).setCellValue(9);
sheet.getRow(1).getCell(m + 6).setCellValue(11);
sheet.getRow(1).getCell(m + 7).setCellValue(13);
sheet.getRow(1).getCell(m + 8).setCellValue(15);
sheet.getRow(1).getCell(m + 9).setCellValue(17);
sheet.getRow(1).getCell(m + 10).setCellValue(19);
sheet.getRow(1).getCell(m + 11).setCellValue(21);
sheet.getRow(1).getCell(m + 12).setCellValue(23);
sheet.getRow(1).getCell(m + 13).setCellValue(25);
sheet.getRow(1).getCell(m + 14).setCellValue(27);
sheet.getRow(1).getCell(m + 15).setCellValue(29);
sheet.getRow(1).getCell(m + 16).setCellValue(31);
m += 17;
}
}
}
//构建品味数据
HashMap<String, String> gradingMap = new HashMap<>();
for (EntrustSampleItemVO vo : list) {
gradingMap.putIfAbsent(vo.getDay() + "#" + vo.getSlotNo(), vo.getSampleGrading());
}
//填充数据
for (int i = 1; i < numberOfSheets; i++) {
Sheet sheet = workbook.getSheetAt(i);
int lastRowNum = sheet.getLastRowNum();
Row row = sheet.getRow(0);
short lastCellNum = row.getLastCellNum();
for (int i1 = 0; i1 < lastCellNum; i1++) {
String cellValue = WorkbookUtils.getCellValue(row.getCell(i1));
if(StringUtils.isNotEmpty(cellValue) && StringUtils.contains(cellValue, "MM")) {
String replace = cellValue.replace("MM", DateUtils.formatToString(new Date(), "MM"));
row.getCell(i1).setCellValue(replace);
}
}
for (int j = 2; j <= lastRowNum; j++) {
String sltoNoCel = WorkbookUtils.getCellValue(sheet.getRow(j).getCell(0));
if(null ==sltoNoCel || Objects.isNull(sltoNoCel)) {
break;
}
for (int k = 1; k <= 16; k++) {
String day = WorkbookUtils.getCellValue(sheet.getRow(1).getCell(k));
sheet.getRow(j).getCell(k).setCellValue(gradingMap.get(day + "#" + sltoNoCel));
}
}
}
//构建原铝其他指标数据
HashMap<String, Double> itemMap = new HashMap<>();
for (EntrustSampleItemVO vo : list) {
itemMap.putIfAbsent(vo.getDay() + "#" + vo.getSlotNo() + "#" + vo.getName(), Double.parseDouble(vo.getTestValue()));
}
//填充数据
for (int i = 1; i < numberOfSheets; i++) {
Sheet sheet = workbook.getSheetAt(i);
int lastRowNum = sheet.getLastRowNum();
for (int j = 2; j <= lastRowNum; j++) {
String sltoNoCel = WorkbookUtils.getCellValue(sheet.getRow(j).getCell(0));
if(null ==sltoNoCel || Objects.isNull(sltoNoCel)) {
break;
}
for (int k = 18; k <= 33; k++) {
String day = WorkbookUtils.getCellValue(sheet.getRow(1).getCell(k));
setCellValue(sheet.getRow(j).getCell(k),itemMap.get(day + "#" + sltoNoCel + "#" + "原铝Fe"));
}
for (int k = 35; k <= 50; k++) {
String day = WorkbookUtils.getCellValue(sheet.getRow(1).getCell(k));
setCellValue(sheet.getRow(j).getCell(k),itemMap.get(day + "#" + sltoNoCel + "#" + "原铝Si"));
}
for (int k = 52; k <= 67; k++) {
String day = WorkbookUtils.getCellValue(sheet.getRow(1).getCell(k));
setCellValue(sheet.getRow(j).getCell(k),itemMap.get(day + "#" + sltoNoCel + "#" + "原铝Ni"));
}
for (int k = 69; k <= 84; k++) {
String day = WorkbookUtils.getCellValue(sheet.getRow(1).getCell(k));
setCellValue(sheet.getRow(j).getCell(k),itemMap.get(day + "#" + sltoNoCel + "#" + "原铝Zn"));
}
for (int k = 86; k <= 101; k++) {
String day = WorkbookUtils.getCellValue(sheet.getRow(1).getCell(k));
setCellValue(sheet.getRow(j).getCell(k),itemMap.get(day + "#" + sltoNoCel + "#" + "原铝V"));
}
}
}
// 刷新公式
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
// 遍历所有工作表
for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
Sheet sheet = workbook.getSheetAt(i);
// 遍历所有行
for (int j = 0; j <= sheet.getLastRowNum(); j++) {
Row row = sheet.getRow(j);
if (row != null) { // 检查行是否存在
// 遍历所有单元格
for (int k = 0; k < row.getLastCellNum(); k++) {
Cell cell = row.getCell(k);
if (cell != null && cell.getCellType() == CellType.FORMULA) { // 检查单元格是否存在且是公式类型
try {
evaluator.evaluateFormulaCell(cell);
} catch (Exception e) {
e.printStackTrace();
// 可以选择跳过或替换为默认值
cell.setCellType(CellType.NUMERIC);
cell.setCellValue(0);
}
}
}
}
}
}
file = File.createTempFile("总厂原铝统计表", ".xlsx");
OutputStream out = new FileOutputStream(file);
workbook.write(out);
out.flush();
/*---------------------------------------------------------------------------------------------------------------------------------------------------------------*/
downFiles.add(file);
if (org.apache.commons.collections.CollectionUtils.isEmpty(downFiles)) {
RestAssert.fail("导出失败!");
} else if (downFiles.size() == 1) {
FileUtils.download(new FileInputStream(downFiles.get(0)), downFiles.get(0).getName(), response);
} else {
FileUtils.downLoadFiles(downFiles, DateUtils.dateTransfer(new Date(), "yyyy-MM") + "月份原铝统计表.zip", response);
}
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (null != file && file.exists()) {
file.delete();
}
}
}
private void setCellValue(Cell cell, Double s) {
if (null != s) {
cell.setCellType(CellType.NUMERIC);
cell.setCellValue(s);
}
}
@Override @Override
public List<ElectrolyteRatioStatsVO> getElectrolyteRatioStatsQuery(QueryDTO queryDTO) { public List<ElectrolyteRatioStatsVO> getElectrolyteRatioStatsQuery(QueryDTO queryDTO) {
......
...@@ -803,6 +803,36 @@ ...@@ -803,6 +803,36 @@
</if> </if>
order by e.code, i.name, s.code order by e.code, i.name, s.code
</select> </select>
<select id="getData" resultType="com.patzn.cloud.service.hmhj.vo.EntrustSampleItemVO">
SELECT
i.name,
s.slot_no,
s.sample_from,
ii.test_value,
i.test_time,
i.*,
s.*,
e.*
FROM
entrust_sample_item_index ii
join entrust_sample_item i on ii.entrust_sample_item_id = i.id
JOIN entrust_sample s ON i.entrust_sample_id = s.ID
JOIN entrust e ON s.entrust_id = e.ID
where s.deleted = 0
AND i.deleted = 0 and e.deleted = 0 and ii.deleted = 0
ANd i.name = '电解质分子比' and i.status > 49
<if test="null != vo.slotNo">
AND s.slot_no LIKE CONCAT ('%',#{vo.slotNo},'%')
</if>
<if test="null != vo.sampleFrom">
AND s.sample_from LIKE CONCAT ('%',#{vo.sampleFrom},'%')
</if>
<if test="vo.testTimeBegin != null and vo.testTimeEnd != null">
AND date_trunc('day',i.test_time) between #{vo.testTimeBegin} and #{vo.testTimeEnd}
</if>
order by i.test_time desc
LIMIT 1000
</select>
<update id="updateBatchByData" parameterType="java.util.List"> <update id="updateBatchByData" parameterType="java.util.List">
<foreach collection="itemList" item="item" index="index" open="" close="" separator=";"> <foreach collection="itemList" item="item" index="index" open="" close="" separator=";">
......
...@@ -517,6 +517,26 @@ ...@@ -517,6 +517,26 @@
and s.id != #{vo.id} and s.id != #{vo.id}
</if> </if>
</select> </select>
<select id="laborHourStatisticsTable" resultType="com.patzn.cloud.service.hmhj.vo.EntrustSampleItemVO">
SELECT
EXTRACT(DAY FROM s.ctime) AS day,
s.sample_grading,
slot_no ,
i.name,
ii.test_value
FROM
"entrust_sample" s join entrust_sample_item i on i.entrust_sample_id = s.id join entrust_sample_item_index ii on ii.entrust_sample_item_id = i.id
WHERE
s.NAME IN ( '原铝', '原铝重取' )
AND s.ctime > date_trunc('month', CURRENT_DATE)
AND s.ctime &lt; date_trunc('month', CURRENT_DATE) + INTERVAL '1 month'
AND CAST(TRIM(slot_no) AS INTEGER) >= 1001
AND CAST(TRIM(slot_no) AS INTEGER) &lt;= 7000
ORDER BY
s.name desc,
s.ctime,
s.slot_no
</select>
<update id="updateBatchByData" parameterType="java.util.List"> <update id="updateBatchByData" parameterType="java.util.List">
<foreach collection="sampleList" item="item" index="index" open="" close="" separator=";"> <foreach collection="sampleList" item="item" index="index" open="" close="" separator=";">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment