Commit 5e3d21e7 by MMF

MMF 2026-03-24 新增评分填报模块

parent c18a616f
package com.qianhe.common.utils;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
public class MtExcelUtil {
private static MtExcelUtil instance = new MtExcelUtil();
public MtExcelUtil() {
}
public static MtExcelUtil getInstance() {
return instance;
}
/**
* 将 List<Map<String,Object>> 类型的数据导出为 Excel
* 默认 Excel 文件的输出路径为 项目根目录下
* 文件名为 filename + 时间戳 + .xlsx
*
* @param mapList 数据源(通常为数据库查询数据)
* @param filename 文件名前缀, 实际文件名后会加上日期
* @param title 表格首行标题
*/
public void createExcel(HttpServletResponse response, List<Map<String, Object>> mapList, String filename, String title) {
// 获取数据源的 key, 用于获取列数及设置标题
Map<String, Object> map = mapList.get(0);
Set<String> stringSet = map.keySet();
List<String> headList = new ArrayList<>(stringSet);
Collections.sort(headList); // 表头排序
// 定义一个新的工作簿
XSSFWorkbook wb = new XSSFWorkbook();
// 创建一个Sheet页
XSSFSheet sheet = wb.createSheet();
// 设置标题样式
XSSFCellStyle headWriteCellStyle = getTitleStyle(wb);
// 设置标题
setTitle(sheet, headList, headWriteCellStyle);
// 设置内容样式
XSSFCellStyle contentWriteCellStyle = getContentStyle(wb);
// 设置内容
setContent(sheet, headList, mapList, contentWriteCellStyle);
// 导出
export(response, wb, filename);
}
public void setTitle(XSSFSheet sheet, List<String> headList, XSSFCellStyle headWriteCellStyle) {
// 设置标题
XSSFRow row = sheet.createRow(0);
sheet.autoSizeColumn(0);
for (int i = 0; i < headList.size(); i++) {
XSSFCell cell = row.createCell(i);
cell.setCellValue(headList.get(i));
cell.setCellStyle(headWriteCellStyle);
}
}
public XSSFCellStyle getTitleStyle(XSSFWorkbook wb) {
// 单元格样式类
XSSFCellStyle headWriteCellStyle = wb.createCellStyle();
// 设置单元格背景颜色
headWriteCellStyle.setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 128, 128)));
headWriteCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
// 文字水平垂直居中
headWriteCellStyle.setAlignment(HorizontalAlignment.CENTER); // 水平居中
headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); // 垂直居中
// 设置字体
XSSFFont headWriteFont = wb.createFont();
headWriteFont.setFontName("Arial"); // 字体样式
headWriteFont.setFontHeightInPoints((short) 10); // 字体大小
headWriteFont.setBold(true); // 加粗
headWriteFont.setColor(IndexedColors.WHITE.getIndex());
headWriteCellStyle.setFont(headWriteFont);
return headWriteCellStyle;
}
public void setContent(XSSFSheet sheet, List<String> headList, List<Map<String, Object>> mapList, XSSFCellStyle contentWriteCellStyle) {
XSSFRow rows;
XSSFCell cells;
// 循环拿到的数据给所有行每一列设置对应的值
for (int i = 0; i < mapList.size(); i++) {
//在这个sheet页里创建一行
rows = sheet.createRow(i + 1);
sheet.autoSizeColumn(i + 1);
//给该行数据赋值
for (int j = 0; j < headList.size(); j++) {
Map<String, Object> rowMap = mapList.get(i);
String head = headList.get(j);
String value = rowMap.get(head).toString();
cells = rows.createCell(j);
cells.setCellValue(value);
cells.setCellStyle(contentWriteCellStyle);
}
}
}
public XSSFCellStyle getContentStyle(XSSFWorkbook wb) {
// 单元格样式类
XSSFCellStyle contentWriteCellStyle = wb.createCellStyle();
// 设置单元格背景颜色
contentWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
contentWriteCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
// 文字水平垂直居中
contentWriteCellStyle.setAlignment(HorizontalAlignment.CENTER); // 水平居中
contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); // 垂直居中
// 设置边框
contentWriteCellStyle.setBorderTop(BorderStyle.THIN);
contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);
contentWriteCellStyle.setBorderLeft(BorderStyle.THIN);
contentWriteCellStyle.setBorderRight(BorderStyle.THIN);
// 设置字体
XSSFFont headWriteFont = wb.createFont();
headWriteFont.setFontName("Arial"); // 字体样式
headWriteFont.setFontHeightInPoints((short) 10); // 字体大小
contentWriteCellStyle.setFont(headWriteFont);
return contentWriteCellStyle;
}
public void export(HttpServletResponse response, XSSFWorkbook wb, String filename) {
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
try {
wb.write(response.getOutputStream());
} catch (Exception e) {
System.out.printf("导出Excel异常{}", e.getMessage());
} finally {
IOUtils.closeQuietly(wb);
}
}
}
package com.qianhe.zqcz.pftb.controller;
import com.qianhe.common.core.controller.BaseController;
import com.qianhe.common.core.domain.AjaxResult;
import com.qianhe.common.core.page.TableDataInfo;
import com.qianhe.common.exception.BusinessException;
import com.qianhe.common.utils.MtExcelUtil;
import com.qianhe.zqcz.pftb.domain.ZqczPftb;
import com.qianhe.zqcz.pftb.domain.ZqczPftbQuery;
import com.qianhe.zqcz.pftb.service.ZqczPftbService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
@Slf4j
@RestController
@RequestMapping("/zqcz/pftb")
public class ZqczPftbController extends BaseController {
@Autowired
private ZqczPftbService zqczPftbService;
/**
* 分页查询
*/
@GetMapping("/list")
public AjaxResult list(ZqczPftbQuery zqczPftbQuery) {
try {
return success(zqczPftbService.list(zqczPftbQuery));
} catch (BusinessException e) {
log.warn("最强操作-评分查询失败:" + e.getMessage());
return warn(e.getMessage());
} catch (Exception e) {
log.error("最强操作-评分查询失败:" + e.getMessage());
return error(e.getMessage());
}
}
/**
* 新增
*/
@PostMapping
public AjaxResult add(@RequestBody ZqczPftb zqczPftb) {
try {
return toAjax(zqczPftbService.add(zqczPftb, getUsername()));
} catch (Exception e) {
log.error("最强操作-评分新增失败:" + e.getMessage());
return error(e.getMessage());
}
}
/**
* 导出
*/
@PostMapping("/export")
public void export(HttpServletResponse response, ZqczPftbQuery zqczPftbQuery) {
try {
Map<String, Object> resMap = zqczPftbService.list(zqczPftbQuery);
List<Map<String, Object>> dataList = (List<Map<String, Object>>) resMap.get("dataList");
MtExcelUtil utilT = new MtExcelUtil();
utilT.createExcel(response, dataList, "", "");
} catch (BusinessException e) {
log.warn("最强操作-评分导出失败:" + e.getMessage());
} catch (Exception e) {
log.error("最强操作-评分导出失败:" + e.getMessage());
}
}
}
package com.qianhe.zqcz.pftb.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.qianhe.common.core.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.util.Date;
/**
* 最强操作 评分填报 Model
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ZqczPftb extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
private Long pfid;
/**
* 直属任务ID:zqcz_zsrw.zsrwid
*/
private Long zsrwid;
/**
* 基层任务ID:zqcz_jcrw.jcrwid
*/
private Long jcrwid;
/**
* 项目人员ID:zqcz_xm_ry.xmryid
*/
private Long xmryid;
/**
* 考核得分
*/
private BigDecimal khdf;
/**
* 评委ID:zqcz_pwxx.pwid
*/
private Long pwid;
/**
* 创建者
*/
private String create_by;
/**
* 创建时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date create_time;
/**
* 修改人
*/
private String update_by;
/**
* 修改时间(更新时自动刷新)
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date update_time;
/**
* 备注(存在问题)
*/
private String remark;
/**
* 预留1
*/
private String yl1;
/**
* 预留2
*/
private String yl2;
/**
* 预留3
*/
private String yl3;
/**
* 预留4
*/
private String yl4;
/**
* 预留5
*/
private String yl5;
}
package com.qianhe.zqcz.pftb.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.qianhe.common.core.domain.BaseEntity;
import com.qianhe.zqcz.pwxx.domain.ZqczPwxxVo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* 最强操作 评分填报 Model
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ZqczPftbQuery extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 直属任务ID:zqcz_zsrw.zsrwid
*/
private Long zsrwid;
/**
* 基层任务ID:zqcz_jcrw.jcrwid
*/
private Long jcrwid;
private List<ZqczPwxxVo> pwxxList;
}
package com.qianhe.zqcz.pftb.mapper;
import com.qianhe.zqcz.pftb.domain.ZqczPftb;
import com.qianhe.zqcz.pftb.domain.ZqczPftbQuery;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
@Mapper
public interface ZqczPftbMapper {
/**
* 条件查询
*/
List<Map<String, Object>> list(ZqczPftbQuery zqczPftbQuery);
/**
* 修改
*/
int add(ZqczPftb zqczPftb);
/**
* 根据基层任务ID删除
*/
int deleteByJcrwid(@Param("jcrwid") Long jcrwid);
}
package com.qianhe.zqcz.pftb.service;
import com.qianhe.zqcz.pftb.domain.ZqczPftb;
import com.qianhe.zqcz.pftb.domain.ZqczPftbQuery;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
public interface ZqczPftbService {
/**
* 条件查询
*/
Map<String, Object> list(ZqczPftbQuery zqczPftbQuery);
/**
* 修改
*/
int add(ZqczPftb zqczPftb, String username);
/**
* 根据基层任务ID删除
*/
int deleteByJcrwid(Long jcrwid);
}
package com.qianhe.zqcz.pftb.service.impl;
import com.qianhe.common.exception.BusinessException;
import com.qianhe.zqcz.pftb.domain.ZqczPftb;
import com.qianhe.zqcz.pftb.domain.ZqczPftbQuery;
import com.qianhe.zqcz.pftb.mapper.ZqczPftbMapper;
import com.qianhe.zqcz.pftb.service.ZqczPftbService;
import com.qianhe.zqcz.pwxx.domain.ZqczPwxxQuery;
import com.qianhe.zqcz.pwxx.domain.ZqczPwxxVo;
import com.qianhe.zqcz.pwxx.mapper.ZqczPwxxMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
@Slf4j
@Service
public class ZqczPftbServiceImpl implements ZqczPftbService {
@Autowired
private ZqczPftbMapper zqczPftbMapper;
@Autowired
private ZqczPwxxMapper zqczPwxxMapper;
/**
* 条件查询
*/
@Override
public Map<String, Object> list(ZqczPftbQuery zqczPftbQuery) {
if (zqczPftbQuery.getJcrwid() == null) {
throw new BusinessException("基层任务ID不能为空");
}
// 根据基层任务ID查询评委信息
List<ZqczPwxxVo> pwxxList = zqczPwxxMapper.list(ZqczPwxxQuery.builder().jcrwid(zqczPftbQuery.getJcrwid()).build());
if (!Optional.ofNullable(pwxxList).orElse(Collections.emptyList()).isEmpty()) {
zqczPftbQuery.setPwxxList(pwxxList);
}
List<Map<String, Object>> dataList = zqczPftbMapper.list(zqczPftbQuery);
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("dataList", dataList);
dataMap.put("fields", pwxxList);
return dataMap;
}
/**
* 新增
*/
@Override
public int add(ZqczPftb zqczPftb, String username) {
zqczPftb.setCreate_by(username);
zqczPftb.setUpdate_by(username);
zqczPftb.setCreate_time(new Date());
zqczPftb.setUpdate_time(new Date());
return zqczPftbMapper.add(zqczPftb);
}
/**
* 删除
*/
@Override
public int deleteByJcrwid(Long jcrwid) {
return zqczPftbMapper.deleteByJcrwid(jcrwid);
}
}
......@@ -32,6 +32,22 @@ public class ZqczXmRyLsjlController extends BaseController {
}
/**
* 修改
*/
@PutMapping
public AjaxResult edit(@RequestBody ZqczXmRyLsjl zqczXmRyLsjl) {
try {
return toAjax(zqczXmRyLsjlService.edit(zqczXmRyLsjl, getUsername()));
} catch (BusinessException e) {
log.warn("最强操作-项目人员修改失败" + e.getMessage());
return warn(e.getMessage());
} catch (Exception e) {
log.error(e.getMessage());
return error(e.getMessage());
}
}
/**
* 项目抽检
*/
@PostMapping("/spotCheckAdd")
......
......@@ -16,4 +16,9 @@ public interface ZqczXmRyLsjlService {
* 根据基层任务ID 开始项目抽检
*/
int spotCheckAdd(ZqczXmRyLsjlQuery zqczXmRyLsjlQuery);
/**
* 修改
*/
int edit(ZqczXmRyLsjl zqczXmRyLsjl, String username);
}
......@@ -187,6 +187,18 @@ public class ZqczXmRyLsjlServiceImpl implements ZqczXmRyLsjlService {
}
/**
* 修改
*/
@Override
public int edit(ZqczXmRyLsjl zqczXmRyLsjl, String username) {
if (zqczXmRyLsjl.getXmryid() == null) {
throw new BusinessException("项目人员ID不能为空");
}
zqczXmRyLsjl.setUpdate_by(username);
return zqczXmRyLsjlMapper.edit(zqczXmRyLsjl);
}
/**
* 抽检 个人应急项目(采油)
*
* @param zsrwid 直属任务ID
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.qianhe.zqcz.pftb.mapper.ZqczPftbMapper">
<!-- 条件查询 -->
<select id="list" parameterType="com.qianhe.zqcz.pftb.domain.ZqczPftbQuery" resultType="map">
SELECT
lsjl.xmryid,
lsjl.zsrwid,
lsjl.jcrwid,
lsjl.xmmc,
lsjl.xmlb,
lsjl.rymc,
lsjl.dwmc,
lsjl.jcdwid,
jcdw.jcdwmc,
lsjl.update_time,
IFNULL(lsjl.remark, '') AS remark,
IFNULL(ROUND(pftb.pjdf, 5), '') AS pjdf,
<foreach item="item" collection="pwxxList" separator=",">
IFNULL(pftb.`${item.pwmc}`, '') AS `${item.pwmc}`
</foreach>
FROM
zqcz_xm_ry_lsjl lsjl
LEFT JOIN zqcz_jcdw jcdw ON lsjl.jcdwid = jcdw.jcdwid
LEFT JOIN (
SELECT
pftb.zsrwid,
pftb.jcrwid,
pftb.xmryid,
AVG(pftb.khdf) AS pjdf,
<foreach item="item" collection="pwxxList" separator=",">
MAX( CASE WHEN pwxx.pwid = #{item.pwid} THEN pftb.khdf END ) AS `${item.pwmc}`
</foreach>
FROM
zqcz_pftb pftb LEFT JOIN zqcz_pwxx pwxx ON pftb.pwid = pwxx.pwid
GROUP BY
pftb.zsrwid,
pftb.jcrwid,
pftb.xmryid
) pftb ON lsjl.XMRYID = pftb.xmryid
<where>
<if test="zsrwid != null ">AND lsjl.zsrwid = #{zsrwid}</if>
<if test="jcrwid != null ">AND lsjl.jcrwid = #{jcrwid}</if>
</where>
</select>
<!-- 添加|修改 -->
<insert id="add" parameterType="com.qianhe.zqcz.pftb.domain.ZqczPftb">
REPLACE INTO zqcz_pftb (PFID, PWID, ZSRWID, JCRWID, XMRYID, KHDF, CREATE_BY, CREATE_TIME, UPDATE_BY, REMARK, YL1, YL2, YL3, YL4, YL5, UPDATE_TIME)
VALUES (#{pfid}, #{pwid}, #{zsrwid}, #{jcrwid}, #{xmryid}, #{khdf}, #{create_by}, #{create_time}, #{update_by}, #{remark}, #{yl1}, #{yl2}, #{yl3}, #{yl4}, #{yl5}, now())
</insert>
<!-- 删除 -->
<delete id="deleteByJcrwid" parameterType="long">
DELETE FROM zqcz_pftb WHERE JCRWID = #{jcrwid}
</delete>
</mapper>
\ No newline at end of file
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