Commit 02a6856d by MMF

MMF 2026-03-20 评委信息CRUD

parent 8f5864ca
...@@ -3,6 +3,7 @@ package com.qianhe.zqcz.jcdw.controller; ...@@ -3,6 +3,7 @@ package com.qianhe.zqcz.jcdw.controller;
import com.qianhe.common.core.controller.BaseController; import com.qianhe.common.core.controller.BaseController;
import com.qianhe.common.core.domain.AjaxResult; import com.qianhe.common.core.domain.AjaxResult;
import com.qianhe.common.core.page.TableDataInfo; import com.qianhe.common.core.page.TableDataInfo;
import com.qianhe.common.exception.BusinessException;
import com.qianhe.common.utils.poi.ExcelUtil; import com.qianhe.common.utils.poi.ExcelUtil;
import com.qianhe.zqcz.jcdw.domain.ZqczJcdw; import com.qianhe.zqcz.jcdw.domain.ZqczJcdw;
import com.qianhe.zqcz.jcdw.domain.ZqczJcdwQuery; import com.qianhe.zqcz.jcdw.domain.ZqczJcdwQuery;
...@@ -105,6 +106,9 @@ public class ZqczJcdwController extends BaseController { ...@@ -105,6 +106,9 @@ public class ZqczJcdwController extends BaseController {
if (file.isEmpty()) return warn("文件不能为空"); if (file.isEmpty()) return warn("文件不能为空");
int count = zqczJcdwService.batchAdd(zsrwid, file); int count = zqczJcdwService.batchAdd(zsrwid, file);
return success("导入成功,共导入 " + count + " 条数据"); return success("导入成功,共导入 " + count + " 条数据");
} catch (BusinessException e) {
log.warn("导入基层单位失败:" + e.getMessage());
return warn(e.getMessage());
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage()); log.error(e.getMessage());
return error(e.getMessage()); return error(e.getMessage());
......
package com.qianhe.zqcz.pwxx.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.poi.ExcelUtil;
import com.qianhe.zqcz.pwxx.domain.ZqczPwxx;
import com.qianhe.zqcz.pwxx.domain.ZqczPwxxQuery;
import com.qianhe.zqcz.pwxx.domain.ZqczPwxxVo;
import com.qianhe.zqcz.pwxx.service.ZqczPwxxService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/zqcz/zqczpwxx")
public class ZqczPwxxController extends BaseController {
@Autowired
private ZqczPwxxService zqczPwxxService;
/**
* 分页查询
*/
@GetMapping("/list")
public TableDataInfo list(ZqczPwxxQuery zqczPwxxQuery) {
startPage();
return getDataTable(zqczPwxxService.list(zqczPwxxQuery));
}
/**
* 查询详情
*/
@GetMapping("/{id}")
public AjaxResult info(@PathVariable Long id) {
try {
return success(zqczPwxxService.info(id));
} catch (Exception e) {
log.error(e.getMessage());
return error(e.getMessage());
}
}
/**
* 新增
*/
@PostMapping
public AjaxResult add(@RequestBody ZqczPwxx zqczPwxx) {
try {
return toAjax(zqczPwxxService.add(zqczPwxx, getUsername()));
} catch (Exception e) {
log.error(e.getMessage());
return error(e.getMessage());
}
}
/**
* 修改
*/
@PutMapping
public AjaxResult edit(@RequestBody ZqczPwxx zqczPwxx) {
try {
return toAjax(zqczPwxxService.edit(zqczPwxx, getUsername()));
} catch (Exception e) {
log.error(e.getMessage());
return error(e.getMessage());
}
}
/**
* 删除
*/
@DeleteMapping("/{ids}")
public AjaxResult delete(@PathVariable Long[] ids) {
try {
return toAjax(zqczPwxxService.delete(ids));
} catch (Exception e) {
log.error(e.getMessage());
return error(e.getMessage());
}
}
/**
* 导出
*/
@PostMapping("/export")
public void export(HttpServletResponse response, @RequestBody ZqczPwxxQuery zqczPwxxQuery) {
List<ZqczPwxxVo> dataList = zqczPwxxService.list(zqczPwxxQuery);
ExcelUtil<ZqczPwxxVo> util = new ExcelUtil<>(ZqczPwxxVo.class);
util.exportExcel(response, dataList, "sheetName");
}
/**
* 导入
*/
@PostMapping("/import")
public AjaxResult importExcel(@RequestParam("jcrwid") Long jcrwid, @RequestParam("file") MultipartFile file) {
try {
if (jcrwid == null) return warn("直属id不能为空");
if (file.isEmpty()) return warn("文件不能为空");
int count = zqczPwxxService.importExcel(jcrwid, file);
return success("导入成功,共导入 " + count + " 条数据");
} catch (BusinessException e) {
log.warn("导入评委失败:" + e.getMessage());
return warn(e.getMessage());
} catch (Exception e) {
log.error("导入评委失败:" + e.getMessage());
return error(e.getMessage());
}
}
}
package com.qianhe.zqcz.pwxx.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.io.Serializable;
import java.util.Date;
/**
* 评委信息 评委信息表(zqcz_pwxx)
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ZqczPwxx extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 评委ID
*/
private Long pwid;
/**
* 评委名称
*/
private String pwmc;
/**
* 基层任务ID:zqcz_jcrw.jcrwid
*/
private Long jcrwid;
/**
* 创建者
*/
private String createBy;
/**
* 创建时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/**
* 修改人
*/
private String updateBy;
/**
* 修改时间(更新时自动刷新)
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
/**
* 备注
*/
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.pwxx.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.util.Date;
/**
* 评委信息 评委信息表(zqcz_pwxx)
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ZqczPwxxQuery extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 评委名称
*/
private String pwmc;
/**
* 基层任务ID:zqcz_jcrw.jcrwid
*/
private Long jcrwid;
}
package com.qianhe.zqcz.pwxx.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.qianhe.common.annotation.Excel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Date;
/**
* 评委信息 评委信息表(zqcz_pwxx)
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ZqczPwxxVo implements Serializable {
/**
* 评委ID
*/
private Long pwid;
/**
* 评委名称
*/
@Excel(name = "评委名称")
private String pwmc;
/**
* 基层任务ID:zqcz_jcrw.jcrwid
*/
private Long jcrwid;
/**
* 备注
*/
private String remark;
}
package com.qianhe.zqcz.pwxx.mapper;
import com.qianhe.zqcz.pwxx.domain.ZqczPwxx;
import com.qianhe.zqcz.pwxx.domain.ZqczPwxxQuery;
import com.qianhe.zqcz.pwxx.domain.ZqczPwxxVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface ZqczPwxxMapper {
/**
* 条件查询
*/
List<ZqczPwxxVo> list(ZqczPwxxQuery zqczPwxxQuery);
/**
* 查询详情
*/
ZqczPwxxVo info(@Param("pwid") Long pwid);
/**
* 新增
*/
int add(ZqczPwxx zqczPwxx);
/**
* 修改
*/
int edit(ZqczPwxx zqczPwxx);
/**
* 删除
*/
int delete(Long[] ids);
/**
* 根据基层任务ID删除
*/
int deleteByJcrwid(@Param("jcrwid") Long jcrwid);
/**
* 批量插入
*/
int batchAdd(@Param("pwxxList") List<ZqczPwxx> pwxxList);
}
package com.qianhe.zqcz.pwxx.service;
import com.qianhe.zqcz.pwxx.domain.ZqczPwxx;
import com.qianhe.zqcz.pwxx.domain.ZqczPwxxQuery;
import com.qianhe.zqcz.pwxx.domain.ZqczPwxxVo;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
public interface ZqczPwxxService {
/**
* 条件查询
*/
List<ZqczPwxxVo> list(ZqczPwxxQuery zqczPwxxQuery);
/**
* 查询详情
*/
ZqczPwxxVo info(Long pwid);
/**
* 新增
*/
int add(ZqczPwxx zqczPwxx, String username);
/**
* 修改
*/
int edit(ZqczPwxx zqczPwxx, String username);
/**
* 删除
*/
int delete(Long[] ids);
/**
* 导入
*/
int importExcel(Long jcrwid, MultipartFile file);
}
package com.qianhe.zqcz.pwxx.service.impl;
import com.qianhe.common.exception.BusinessException;
import com.qianhe.common.utils.SecurityUtils;
import com.qianhe.common.utils.StringUtils;
import com.qianhe.zqcz.jcrw.mapper.ZqczJcrwMapper;
import com.qianhe.zqcz.pwxx.domain.ZqczPwxx;
import com.qianhe.zqcz.pwxx.domain.ZqczPwxxQuery;
import com.qianhe.zqcz.pwxx.domain.ZqczPwxxVo;
import com.qianhe.zqcz.pwxx.mapper.ZqczPwxxMapper;
import com.qianhe.zqcz.pwxx.service.ZqczPwxxService;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
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 org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.*;
@Slf4j
@Service
public class ZqczPwxxServiceImpl implements ZqczPwxxService {
@Autowired
private ZqczPwxxMapper zqczPwxxMapper;
/**
* 条件查询
*/
@Override
public List<ZqczPwxxVo> list(ZqczPwxxQuery zqczPwxxQuery) {
List<ZqczPwxxVo> dataList = zqczPwxxMapper.list(zqczPwxxQuery);
return dataList;
}
/**
* 查询详情
*/
@Override
public ZqczPwxxVo info(Long pwid) {
ZqczPwxxVo info = zqczPwxxMapper.info(pwid);
return info;
}
/**
* 新增
*/
@Override
public int add(ZqczPwxx zqczPwxx, String username) {
zqczPwxx.setCreateBy(username);
zqczPwxx.setUpdateBy(username);
zqczPwxx.setCreateTime(new Date());
return zqczPwxxMapper.add(zqczPwxx);
}
/**
* 修改
*/
@Override
public int edit(ZqczPwxx zqczPwxx, String username) {
zqczPwxx.setUpdateBy(username);
return zqczPwxxMapper.edit(zqczPwxx);
}
/**
* 删除
*/
@Override
public int delete(Long[] ids) {
return zqczPwxxMapper.delete(ids);
}
/**
* 导入
*/
@Transactional(rollbackFor = Exception.class)
@Override
public int importExcel(Long jcrwid, MultipartFile file) {
String username = SecurityUtils.getLoginUser().getUsername(); // 当前用户
XSSFWorkbook workbook = null;
try {
workbook = new XSSFWorkbook(file.getInputStream());
XSSFSheet sheet = workbook.getSheetAt(0);
int lastRowNum = sheet.getLastRowNum();
List<ZqczPwxx> dataList = new ArrayList<>();
for (int i = 0; i <= lastRowNum; i++) {
// 跳过标题行
if (i == 0) {
continue;
}
XSSFRow row = sheet.getRow(i);
if (row == null) {
continue;
}
// 基层单位名称(A列)
String pwmc = new DataFormatter().formatCellValue(row.getCell(0));
if (StringUtils.isEmpty(pwmc)) {
throw new BusinessException("导入失败,第" + (i + 1) + "评委名称不能为空");
}
// 封装数据
ZqczPwxx zqczPwxx = ZqczPwxx.builder()
.jcrwid(jcrwid)
.pwmc(pwmc)
.createBy(username)
.createTime(new Date())
.updateBy(username).build();
dataList.add(zqczPwxx);
}
if (Optional.ofNullable(dataList).orElse(Collections.emptyList()).isEmpty()) {
throw new BusinessException("读取Excel文件失败,上传数据为空");
}
// 先根据jcrwid删除之前的评委信息
zqczPwxxMapper.deleteByJcrwid(jcrwid);
// 在批量插入
int pwSize = zqczPwxxMapper.batchAdd(dataList);
return pwSize;
} catch (BusinessException e) {
throw e;
} catch (IOException e) {
throw new BusinessException("读取Excel文件失败,请检查文件格式");
} finally {
if (workbook != null) {
try {
workbook.close();
} catch (IOException ignored) {
}
}
}
}
}
<?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.pwxx.mapper.ZqczPwxxMapper">
<!-- 返回实体 -->
<resultMap id="ZqczPwxxResult" type="com.qianhe.zqcz.pwxx.domain.ZqczPwxxVo">
<result property="pwid" column="PWID"/>
<result property="pwmc" column="PWMC"/>
<result property="jcrwid" column="JCRWID"/>
<result property="remark" column="REMARK"/>
</resultMap>
<!-- 通用查询 -->
<sql id="selectCommon">
SELECT PWID, PWMC, JCRWID, REMARK from zqcz_pwxx
</sql>
<!-- 条件查询 -->
<select id="list" parameterType="com.qianhe.zqcz.pwxx.domain.ZqczPwxxQuery" resultMap="ZqczPwxxResult">
<include refid="selectCommon"></include>
<where>
<if test="pwmc != null and pwmc !='' ">AND PWMC like concat('%', #{pwmc}, '%')</if>
<if test="jcrwid != null ">AND JCRWID = #{jcrwid}</if>
</where>
ORDER BY UPDATE_TIME DESC
</select>
<!-- 查询详情 -->
<select id="info" parameterType="long" resultMap="ZqczPwxxResult">
<include refid="selectCommon"></include> WHERE PWID = #{pwid}
</select>
<!-- 新增 -->
<insert id="add" parameterType="com.qianhe.zqcz.pwxx.domain.ZqczPwxx">
INSERT INTO zqcz_pwxx
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="pwmc != null and pwmc != ''">PWMC,</if>
<if test="jcrwid != null ">JCRWID,</if>
<if test="createBy != null and createBy != ''">CREATE_BY,</if>
<if test="createTime != null ">CREATE_TIME,</if>
<if test="updateBy != null and updateBy != ''">UPDATE_BY,</if>
<if test="remark != null and remark != ''">REMARK,</if>
<if test="yl1 != null and yl1 != ''">YL1,</if>
<if test="yl2 != null and yl2 != ''">YL2,</if>
<if test="yl3 != null and yl3 != ''">YL3,</if>
<if test="yl4 != null and yl4 != ''">YL4,</if>
<if test="yl5 != null and yl5 != ''">YL5,</if>
UPDATE_TIME
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="pwmc != null and pwmc != ''">#{pwmc},</if>
<if test="jcrwid != null">#{jcrwid},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null and updateBy != ''">#{updateBy},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="yl1 != null">#{yl1},</if>
<if test="yl2 != null">#{yl2},</if>
<if test="yl3 != null">#{yl3},</if>
<if test="yl4 != null">#{yl4},</if>
<if test="yl5 != null">#{yl5},</if>
now()
</trim>
</insert>
<!-- 评委信息表批量插入 -->
<insert id="batchAdd" parameterType="java.util.List">
<choose>
<when test="pwxxList != null and pwxxList.size() > 0 and !pwxxList.isEmpty()">
INSERT INTO zqcz_pwxx
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="pwxxList[0].pwid != null">PWID,</if>
<if test="pwxxList[0].pwmc != null and pwxxList[0].pwmc != ''">PWMC,</if>
<if test="pwxxList[0].jcrwid != null">JCRWID,</if>
<if test="pwxxList[0].createBy != null and pwxxList[0].createBy != ''">CREATE_BY,</if>
<if test="pwxxList[0].createTime != null">CREATE_TIME,</if>
<if test="pwxxList[0].updateBy != null and pwxxList[0].updateBy != ''">UPDATE_BY,</if>
<if test="pwxxList[0].remark != null and pwxxList[0].remark != ''">REMARK,</if>
<if test="pwxxList[0].yl1 != null and pwxxList[0].yl1 != ''">YL1,</if>
<if test="pwxxList[0].yl2 != null and pwxxList[0].yl2 != ''">YL2,</if>
<if test="pwxxList[0].yl3 != null and pwxxList[0].yl3 != ''">YL3,</if>
<if test="pwxxList[0].yl4 != null and pwxxList[0].yl4 != ''">YL4,</if>
<if test="pwxxList[0].yl5 != null and pwxxList[0].yl5 != ''">YL5,</if>
UPDATE_TIME
</trim>
VALUES
<foreach collection="pwxxList" item="item" index="index" separator=",">
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="item.pwid != null">#{item.pwid},</if>
<if test="item.pwmc != null and item.pwmc != ''">#{item.pwmc},</if>
<if test="item.jcrwid != null">#{item.jcrwid},</if>
<if test="item.createBy != null and item.createBy != ''">#{item.createBy},</if>
<if test="item.createTime != null">#{item.createTime},</if>
<if test="item.updateBy != null and item.updateBy != ''">#{item.updateBy},</if>
<if test="item.remark != null and item.remark != ''">#{item.remark},</if>
<if test="item.yl1 != null and item.yl1 != ''">#{item.yl1},</if>
<if test="item.yl2 != null and item.yl2 != ''">#{item.yl2},</if>
<if test="item.yl3 != null and item.yl3 != ''">#{item.yl3},</if>
<if test="item.yl4 != null and item.yl4 != ''">#{item.yl4},</if>
<if test="item.yl5 != null and item.yl5 != ''">#{item.yl5},</if>
now()
</trim>
</foreach>
</when>
<otherwise>
SELECT 0 FROM DUAL
</otherwise>
</choose>
</insert>
<!-- 修改 -->
<update id="edit" parameterType="com.qianhe.zqcz.pwxx.domain.ZqczPwxx">
UPDATE zqcz_pwxx
<trim prefix="SET" suffixOverrides=",">
<if test="pwmc != null and pwmc != ''">PWMC = #{pwmc},</if>
<if test="jcrwid != null">JCRWID = #{jcrwid},</if>
<if test="createBy != null">CREATE_BY = #{createBy},</if>
<if test="createTime != null">CREATE_TIME = #{createTime},</if>
<if test="updateBy != null">UPDATE_BY = #{updateBy},</if>
<if test="remark != null">REMARK = #{remark},</if>
<if test="yl1 != null">YL1 = #{yl1},</if>
<if test="yl2 != null">YL2 = #{yl2},</if>
<if test="yl3 != null">YL3 = #{yl3},</if>
<if test="yl4 != null">YL4 = #{yl4},</if>
<if test="yl5 != null">YL5 = #{yl5},</if>
UPDATE_TIME = now()
</trim>
WHERE PWID = #{pwid}
</update>
<!-- 删除 -->
<delete id="delete" parameterType="long">
DELETE FROM zqcz_pwxx WHERE PWID IN
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<!-- 删除 -->
<delete id="deleteByJcrwid" parameterType="long">
DELETE FROM zqcz_pwxx 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