Commit db396a76 by MMF

MMF 2026-03-26 新增现场抽取情况查看、导出模块

parent 11cc4a7e
......@@ -72,4 +72,28 @@ public class ZqczXmRyLsjlController extends BaseController {
ExcelUtil<ZqczXmRyLsjlVo> util = new ExcelUtil<>(ZqczXmRyLsjlVo.class);
util.exportExcel(response, dataList, "sheetName");
}
/**
* 现场抽取情况统计
*/
@GetMapping("/spotCheckStatus")
public AjaxResult spotCheckStatus(ZqczXmRyLsjlQuery zqczXmRyLsjlQuery){
try {
return success(zqczXmRyLsjlService.spotCheckStatus(zqczXmRyLsjlQuery));
} catch (BusinessException e) {
log.warn("最强操作-项目人员修改失败" + e.getMessage());
return warn(e.getMessage());
} catch (Exception e) {
log.error(e.getMessage());
return error(e.getMessage());
}
}
/**
* 现场抽取情况表导出
*/
@PostMapping("/spotCheckStatus/export")
public void spotCheckStatusExport(HttpServletResponse response, @RequestBody ZqczXmRyLsjlQuery zqczXmRyLsjlQuery) {
zqczXmRyLsjlService.spotCheckStatusExport(response, zqczXmRyLsjlQuery);
}
}
package com.qianhe.zqcz.xmrylsjl.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.qianhe.common.annotation.Excel;
import com.qianhe.zqcz.ryxx.domain.ZqczRyxxVo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Date;
/**
* 现场抽检情况统计
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class XccjqktjVo implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 基层单位名称
*/
private String jcdwmc;
/**
* 人员类型
*/
private String ryfl;
/**
* 人员名称
*/
private String rymc;
/**
* 项目类别
*/
private String xmlb;
/**
* 项目名称
*/
private String xmmc;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date update_time;
public XccjqktjVo(ZqczRyxxVo zqczRyxxVo, ZqczXmRyLsjlVo zqczXmRyLsjlVo) {
this.jcdwmc = zqczRyxxVo.getDwmc();
this.ryfl = zqczRyxxVo.getRyfl();
this.rymc = zqczRyxxVo.getRymc();
this.xmmc = zqczXmRyLsjlVo.getXmmc();
this.xmlb = zqczXmRyLsjlVo.getXmlb();
this.update_time = zqczXmRyLsjlVo.getUpdate_time();
}
}
package com.qianhe.zqcz.xmrylsjl.service;
import com.qianhe.zqcz.xmrylsjl.domain.XccjqktjVo;
import com.qianhe.zqcz.xmrylsjl.domain.ZqczXmRyLsjl;
import com.qianhe.zqcz.xmrylsjl.domain.ZqczXmRyLsjlQuery;
import com.qianhe.zqcz.xmrylsjl.domain.ZqczXmRyLsjlVo;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
public interface ZqczXmRyLsjlService {
......@@ -21,4 +23,14 @@ public interface ZqczXmRyLsjlService {
* 修改
*/
int edit(ZqczXmRyLsjl zqczXmRyLsjl, String username);
/**
* 现场抽取情况统计
*/
List<XccjqktjVo> spotCheckStatus(ZqczXmRyLsjlQuery zqczXmRyLsjlQuery);
/**
* 现场抽取情况表导出
*/
void spotCheckStatusExport(HttpServletResponse response, ZqczXmRyLsjlQuery zqczXmRyLsjlQuery);
}
......@@ -4,6 +4,7 @@ import com.qianhe.common.enums.zqcz.ZqczRyflEnum;
import com.qianhe.common.enums.zqcz.ZqczXmlbEnum;
import com.qianhe.common.enums.zqcz.ZqczXmzyEnum;
import com.qianhe.common.exception.BusinessException;
import com.qianhe.common.utils.MtTimeUtil;
import com.qianhe.common.utils.MtUtils;
import com.qianhe.common.utils.SecurityUtils;
import com.qianhe.zqcz.pwxx.domain.ZqczPwxxQuery;
......@@ -15,18 +16,28 @@ import com.qianhe.zqcz.ryxx.mapper.ZqczRyxxMapper;
import com.qianhe.zqcz.xmgl.domain.ZqczXmglQuery;
import com.qianhe.zqcz.xmgl.domain.ZqczXmglVo;
import com.qianhe.zqcz.xmgl.mapper.ZqczXmglMapper;
import com.qianhe.zqcz.xmrylsjl.domain.XccjqktjVo;
import com.qianhe.zqcz.xmrylsjl.domain.ZqczXmRyLsjl;
import com.qianhe.zqcz.xmrylsjl.domain.ZqczXmRyLsjlQuery;
import com.qianhe.zqcz.xmrylsjl.domain.ZqczXmRyLsjlVo;
import com.qianhe.zqcz.xmrylsjl.mapper.ZqczXmRyLsjlMapper;
import com.qianhe.zqcz.xmrylsjl.service.ZqczXmRyLsjlService;
import com.qianhe.zqcz.zsrw.domain.ZqczZsrwVo;
import com.qianhe.zqcz.zsrw.mapper.ZqczZsrwMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.ss.formula.functions.T;
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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
......@@ -41,6 +52,8 @@ public class ZqczXmRyLsjlServiceImpl implements ZqczXmRyLsjlService {
private ZqczRyxxMapper zqczRyxxMapper;
@Autowired
private ZqczPwxxMapper zqczPwxxMapper;
@Autowired
private ZqczZsrwMapper zqczZsrwMapper;
/**
* 条件查询
......@@ -199,6 +212,284 @@ public class ZqczXmRyLsjlServiceImpl implements ZqczXmRyLsjlService {
}
/**
* 现场抽取情况统计
*/
@Override
public List<XccjqktjVo> spotCheckStatus(ZqczXmRyLsjlQuery zqczXmRyLsjlQuery) {
if (zqczXmRyLsjlQuery.getJcrwid() == null) {
throw new BusinessException("基层任务ID不能为空");
}
List<ZqczRyxxVo> ryxxList = zqczRyxxMapper.list(ZqczRyxxQuery.builder().jcrwid(zqczXmRyLsjlQuery.getJcrwid()).build());
if (Optional.ofNullable(ryxxList).orElse(Collections.emptyList()).isEmpty()) {
throw new BusinessException("未录入在岗人员信息");
}
List<XccjqktjVo> xccjqktjVoList = new ArrayList<>();
List<ZqczXmRyLsjlVo> dataList = list(zqczXmRyLsjlQuery);
for (ZqczXmRyLsjlVo zqczXmRyLsjlVo : dataList) {
String rymcStr = zqczXmRyLsjlVo.getRymc();
List<String> rymcList = Arrays.asList(rymcStr.split(","));
for (String rymc : rymcList) {
List<ZqczRyxxVo> filterList = ryxxList.stream().filter(item -> rymc.equals(item.getRymc())).collect(Collectors.toList());
if (Optional.ofNullable(filterList).orElse(Collections.emptyList()).isEmpty()) {
continue;
}
ZqczRyxxVo zqczRyxxVo = filterList.get(0);
xccjqktjVoList.add(new XccjqktjVo(zqczRyxxVo, zqczXmRyLsjlVo));
}
}
return xccjqktjVoList;
}
/**
* 现场抽取情况表导出
*/
@Override
public void spotCheckStatusExport(HttpServletResponse response, ZqczXmRyLsjlQuery zqczXmRyLsjlQuery) {
if (zqczXmRyLsjlQuery.getZsrwid() == null) {
throw new BusinessException("直属任务ID不能为空");
}
if (zqczXmRyLsjlQuery.getJcrwid() == null) {
throw new BusinessException("基层任务ID不能为空");
}
// 查询直属任务
ZqczZsrwVo zqczZsrwVo = zqczZsrwMapper.info(zqczXmRyLsjlQuery.getZsrwid());
if (zqczZsrwVo == null) {
throw new BusinessException("暂无查询到关联的直属任务");
}
// 设置导出表格的标题
List<String> tableTitle = Arrays.asList("序号", "基层单位", "类别", "姓名", "参与项目类型", "参与项目名称", "练兵奖品", "签字", "备注");
// 拼接导出数据
List<XccjqktjVo> dataList = spotCheckStatus(zqczXmRyLsjlQuery);
List<Object[]> finalList = new ArrayList<>();
for (int i = 0; i < dataList.size(); i++) {
List<Object> rowList = new ArrayList<>();
rowList.add(i + 1); // 序号
rowList.add(dataList.get(i).getJcdwmc()); // 基层单位
String ryfl = dataList.get(i).getRyfl();
String flmc = ZqczRyflEnum.getNameByCode(ryfl);
rowList.add(flmc); // 类别
rowList.add(dataList.get(i).getRymc()); // 姓名
String xmlb = dataList.get(i).getXmlb();
String lbmc = ZqczXmlbEnum.getNameByCode(xmlb);
rowList.add(lbmc); // 参与项目类型
rowList.add(dataList.get(i).getXmmc()); // 参与项目名称
rowList.add(""); // 练兵奖品
rowList.add(""); // 签字
rowList.add(""); // 备注
finalList.add(rowList.toArray());
}
// 最终二维数组
Object[][] finalArray = finalList.toArray(new Object[0][]);
Workbook workbook = new XSSFWorkbook();
try {
Sheet sheet = workbook.createSheet(); // 创建标签页
createMainTitle(workbook, sheet, tableTitle.size() - 1);
createSubTitle(workbook, sheet, zqczZsrwVo.getDeptName());
createTableTitle(workbook, sheet, tableTitle);
writeTableData(workbook, sheet, finalArray, 3);
setExportResponseHeader(response, String.format("现场抽取情况表_%s.xlsx", new Date().getTime()));
workbook.write(response.getOutputStream());
} catch (Exception e) {
e.printStackTrace();
try {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
response.getWriter().write("导出失败:" + e.getMessage());
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
/**
* 创建大标题
*/
private void createMainTitle(Workbook workbook, Sheet sheet, Integer lastCol) {
// ====================== 创建标题样式 ======================
CellStyle mainTitleStyle = workbook.createCellStyle();
mainTitleStyle.setAlignment(HorizontalAlignment.CENTER); // 水平居中
mainTitleStyle.setVerticalAlignment(VerticalAlignment.CENTER); // 垂直居中
Font mainTitleFont = workbook.createFont(); // 设置字体
mainTitleFont.setBold(true); // 加粗
mainTitleFont.setFontHeightInPoints((short) 22); // 字体大小
mainTitleFont.setFontName("宋体"); // 字体名称
mainTitleStyle.setFont(mainTitleFont);
Row mainTitleRow = sheet.createRow(0); // 第一行
mainTitleRow.setHeightInPoints(46); // 设置行高
Cell cell = mainTitleRow.createCell(0); // 创建单元格
cell.setCellValue("现场抽取情况表"); // 设置单元格的内容
cell.setCellStyle(mainTitleStyle); // 设置单元格样式
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, lastCol)); // 单元格合并
}
/**
* 创建副标题
*/
public void createSubTitle(Workbook workbook, Sheet sheet, String subTitle) {
// ====================== 创建副标题样式 ======================
CellStyle subTitleStyle = workbook.createCellStyle();
subTitleStyle.setAlignment(HorizontalAlignment.LEFT); // 左对齐
subTitleStyle.setVerticalAlignment(VerticalAlignment.CENTER); // 垂直居中
Font subTitleFont = workbook.createFont(); // 设置字体
subTitleFont.setBold(true); // 加粗
subTitleFont.setFontHeightInPoints((short) 11); // 字体大小
subTitleFont.setFontName("宋体"); // 字体名称
subTitleStyle.setFont(subTitleFont);
Row subTitleRow = sheet.createRow(1); // 第二行
subTitleRow.setHeightInPoints(25); // 设置行高
Cell cell = subTitleRow.createCell(0); // 创建单元格
cell.setCellValue(String.format("直属单位:%s", subTitle)); // 设置单元格的内容
cell.setCellStyle(subTitleStyle); // 设置单元格样式
sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 1)); // 单元格合并
}
/**
* 创建表格标题
*/
public static void createTableTitle(Workbook workbook, Sheet sheet, List<String> tableTitle) {
CellStyle tableHeaderStyle = workbook.createCellStyle(); // 创建单元格样式类
tableHeaderStyle.setAlignment(HorizontalAlignment.CENTER); // 左对齐
tableHeaderStyle.setVerticalAlignment(VerticalAlignment.CENTER); // 垂直居中
tableHeaderStyle.setBorderTop(BorderStyle.THIN); // 上边框
tableHeaderStyle.setBorderBottom(BorderStyle.THIN); // 下边框
tableHeaderStyle.setBorderLeft(BorderStyle.THIN); // 左边框
tableHeaderStyle.setBorderRight(BorderStyle.THIN); // 右边框
Font tableHeaderFont = workbook.createFont(); // 设置字体
tableHeaderFont.setBold(true); // 加粗
tableHeaderFont.setFontHeightInPoints((short) 11); // 字体大小
tableHeaderFont.setFontName("宋体"); // 字体名称
tableHeaderStyle.setFont(tableHeaderFont);
Row tableHeaderRow = sheet.createRow(2); // 创建第三行
tableHeaderRow.setHeightInPoints(43); // 设置行高
CellStyle redStyle = workbook.createCellStyle();
redStyle.cloneStyleFrom(tableHeaderStyle);
redStyle.setAlignment(HorizontalAlignment.CENTER);
redStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
redStyle.setFillForegroundColor(IndexedColors.RED1.getIndex());
// 循环创建每一列表头
for (int i = 0; i < tableTitle.size(); i++) {
// 在当前行创建第 i 列(i 从 0 开始)
Cell cell = tableHeaderRow.createCell(i);
// 设置单元格的值为表头文字
cell.setCellValue(tableTitle.get(i));
// 将表头样式应用到该单元格
cell.setCellStyle(i == 0 ? redStyle : tableHeaderStyle);
}
}
/**
* 设置数据
*/
public static void writeTableData(Workbook workbook, Sheet sheet, Object[][] finalArray, Integer firstRow) {
if (finalArray == null || finalArray.length == 0) {
return;
}
// 1. 创建通用基础样式(边框+垂直居中)
CellStyle baseStyle = workbook.createCellStyle();
baseStyle.setVerticalAlignment(VerticalAlignment.CENTER);
baseStyle.setBorderTop(BorderStyle.THIN);
baseStyle.setBorderBottom(BorderStyle.THIN);
baseStyle.setBorderLeft(BorderStyle.THIN);
baseStyle.setBorderRight(BorderStyle.THIN);
// 2. 普通文本样式(左对齐,继承基础样式)
CellStyle dataStyle = workbook.createCellStyle();
dataStyle.cloneStyleFrom(baseStyle); // 继承边框+垂直居中
dataStyle.setAlignment(HorizontalAlignment.LEFT);
// 3. 数字千分位样式(右对齐,继承基础样式)
CellStyle numberStyle = workbook.createCellStyle();
numberStyle.cloneStyleFrom(baseStyle);
numberStyle.setAlignment(HorizontalAlignment.RIGHT);
numberStyle.setDataFormat(workbook.createDataFormat().getFormat("#,##0"));
for (int i = 0; i < finalArray.length; i++) {
Row row = sheet.createRow(i + firstRow);
row.setHeightInPoints(20); // 设置行高
for (int j = 0; j < finalArray[i].length; j++) {
// 创建单元格
Cell cell = row.createCell(j);
// 单元格赋值
Object value = finalArray[i][j];
if (value instanceof String) {
cell.setCellValue((String) value); // 设置为字符串
} else if (value instanceof Integer) {
int intValue = (Integer) value;
cell.setCellValue(intValue); // 设置为数值
} else if (value instanceof LocalDateTime) {
String timeValue = MtTimeUtil.dateTimeFormatNyr((LocalDateTime) value);
cell.setCellValue(timeValue); // 将日期类型转化为字符串类型
}
// 设置单元格样式
cell.setCellStyle(dataStyle);
}
}
// ====================== 2. 所有数据写完后,统一自动列宽(关键!) ======================
int colCount = finalArray[0].length;
for (int j = 0; j < colCount; j++) {
// 自动计算宽度
sheet.autoSizeColumn(j);
// 对中文进行加宽(关键!解决显示不全)
int width = sheet.getColumnWidth(j) * 14 / 10;
// 最大宽度限制(Excel 限制 255 个字符宽度)
int maxWidth = 255 * 256;
if (width > maxWidth) {
width = maxWidth;
}
sheet.setColumnWidth(j, width);
}
}
/**
* 设置响应头
*/
private void setExportResponseHeader(HttpServletResponse response, String fileName) throws IOException {
// 设置内容类型
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("UTF-8");
// 处理中文文件名
String encodedFileName = URLEncoder.encode(fileName, "UTF-8")
.replaceAll("\\+", "%20");
response.setHeader("Content-disposition",
"attachment;filename*=utf-8''" + encodedFileName);
// 禁用缓存
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
}
/**
* 抽检 个人应急项目(采油)
*
* @param zsrwid 直属任务ID
......@@ -505,7 +796,7 @@ public class ZqczXmRyLsjlServiceImpl implements ZqczXmRyLsjlService {
lockldbzRyxxVo = spotLdbzList.get(0);
}
if (!Optional.ofNullable(ssyzxRyxxList).orElse(Collections.emptyList()).isEmpty()) {
lockSpotCheckSsyzxRyxx = MtUtils.getRandomList(ldbzRyxxList, 1).get(0); // 抽取 三室一中心 人员信息
lockSpotCheckSsyzxRyxx = MtUtils.getRandomList(ssyzxRyxxList, 1).get(0); // 抽取 三室一中心 人员信息
}
}
......
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