diff --git a/mailbox-lan/src/main/java/com/biutag/lan/controller/system/DeptController.java b/mailbox-lan/src/main/java/com/biutag/lan/controller/system/DeptController.java index 2aacf42..f9fd52c 100644 --- a/mailbox-lan/src/main/java/com/biutag/lan/controller/system/DeptController.java +++ b/mailbox-lan/src/main/java/com/biutag/lan/controller/system/DeptController.java @@ -35,6 +35,7 @@ public class DeptController { return AjaxResult.success(list); } + @NotPower @GetMapping("/list") @ApiOperation(value="部门列表") public AjaxResult list(@Validated DeptSearchValidate searchValidate) { diff --git a/mailbox-lan/src/main/java/com/biutag/lan/controller/work/WorkController.java b/mailbox-lan/src/main/java/com/biutag/lan/controller/work/WorkController.java index 5cdaa41..66e8eea 100644 --- a/mailbox-lan/src/main/java/com/biutag/lan/controller/work/WorkController.java +++ b/mailbox-lan/src/main/java/com/biutag/lan/controller/work/WorkController.java @@ -1,18 +1,22 @@ package com.biutag.lan.controller.work; +import com.alibaba.fastjson2.JSON; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.biutag.aop.NotPower; import com.biutag.core.AjaxResult; import com.biutag.lan.domain.Work; import com.biutag.lan.domain.bo.MailQuery; import com.biutag.lan.domain.vo.WorkVo; +import com.biutag.lan.service.MailSourceService; import com.biutag.lan.service.WorkService; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; +import java.util.List; @RequestMapping("api/work") @RequiredArgsConstructor @@ -20,6 +24,7 @@ import java.io.IOException; public class WorkController { private final WorkService workService; + private final MailSourceService mailSourceService; @NotPower @GetMapping("{workState}") @@ -41,9 +46,16 @@ public class WorkController { @NotPower @PostMapping("import") - public AjaxResult importExcel(MultipartFile file) throws IOException { - workService.importExcel(file); - return AjaxResult.success(); + @Transactional(rollbackFor = Exception.class) + public AjaxResult importExcel(@RequestBody String workVoList) { + List data = JSON.parseArray(workVoList, WorkVo.class); + return workService.saveExcelBatch(data) && mailSourceService.saveExcelBatch(data) ? AjaxResult.success() : AjaxResult.failed("导入失败"); + } + + @NotPower + @PostMapping("check") + public AjaxResult> check(MultipartFile file, MailQuery mailQuery) throws IOException { + return workService.checkExcel(file, mailQuery); } @NotPower diff --git a/mailbox-lan/src/main/java/com/biutag/lan/domain/vo/WorkVo.java b/mailbox-lan/src/main/java/com/biutag/lan/domain/vo/WorkVo.java index 14965fc..4887c5d 100644 --- a/mailbox-lan/src/main/java/com/biutag/lan/domain/vo/WorkVo.java +++ b/mailbox-lan/src/main/java/com/biutag/lan/domain/vo/WorkVo.java @@ -1,6 +1,5 @@ package com.biutag.lan.domain.vo; -import com.alibaba.excel.annotation.ExcelIgnore; import com.alibaba.excel.annotation.ExcelProperty; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Getter; @@ -12,7 +11,7 @@ import java.time.LocalDateTime; @Getter public class WorkVo { - @ExcelIgnore + @ExcelProperty("工作流ID") private Integer id; /** @@ -27,7 +26,7 @@ public class WorkVo { @ExcelProperty("联系电话") private String contactPhone; - @ExcelIgnore + @ExcelProperty("联系人身份证号") private String contactIdCard; /** @@ -52,13 +51,13 @@ public class WorkVo { /** * 信件ID */ - + @ExcelProperty("信件ID") private String mailId; /** * 信件等级 */ - @ExcelIgnore + @ExcelProperty("信件等级") private String mailLevel; /** @@ -76,7 +75,7 @@ public class WorkVo { /** * 信件流程节点 */ - @ExcelIgnore + @ExcelProperty("流程节点ID") private String flowKey; /** @@ -94,7 +93,7 @@ public class WorkVo { /** * 办理单位ID(三级单位) */ - @ExcelIgnore + @ExcelProperty("办理单位ID-三级") private Integer threeDeptId; @ExcelProperty("办理单位") @@ -103,7 +102,7 @@ public class WorkVo { /** * 工作类型 */ - @ExcelIgnore + @ExcelProperty("工作类型") private String workType; /** diff --git a/mailbox-lan/src/main/java/com/biutag/lan/mapper/WorkMapper.java b/mailbox-lan/src/main/java/com/biutag/lan/mapper/WorkMapper.java index 71109d0..6192540 100644 --- a/mailbox-lan/src/main/java/com/biutag/lan/mapper/WorkMapper.java +++ b/mailbox-lan/src/main/java/com/biutag/lan/mapper/WorkMapper.java @@ -16,4 +16,6 @@ public interface WorkMapper extends BaseMapper { @Select("select count(w.id) from work w left join mail m on w.mail_id = m.id where m.flow_key = #{flowKey} and w.sign_dept_id = #{deptId}") Integer selectCount(String flowKey, Integer deptId); + @Select("select count(w.mail_id) from work w where w.mail_id = #{mailId}") + Integer countByFilter(String mailId); } diff --git a/mailbox-lan/src/main/java/com/biutag/lan/service/ExcelService.java b/mailbox-lan/src/main/java/com/biutag/lan/service/ExcelService.java index 763e5c3..02ee12f 100644 --- a/mailbox-lan/src/main/java/com/biutag/lan/service/ExcelService.java +++ b/mailbox-lan/src/main/java/com/biutag/lan/service/ExcelService.java @@ -1,35 +1,52 @@ package com.biutag.lan.service; +import cn.hutool.core.util.StrUtil; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.read.listener.ReadListener; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.biutag.lan.domain.Work; +import com.biutag.lan.domain.bo.MailQuery; import com.biutag.lan.domain.vo.WorkVo; -import lombok.extern.slf4j.Slf4j; +import com.biutag.lan.mapper.WorkMapper; +import lombok.Getter; -import java.sql.Connection; -import java.sql.PreparedStatement; import java.util.ArrayList; import java.util.List; -@Slf4j +@Getter public class ExcelService implements ReadListener { - // 定义一个批量插入的大小 - private static final int BATCH_SIZE = 100; - // 定义一个缓存的列表,用于存储读取到的数据 - private List dataList = new ArrayList<>(BATCH_SIZE); - // 定义一个数据库连接对象 - private Connection connection; - // 定义一个预编译的SQL语句对象 - private PreparedStatement preparedStatement; - public ExcelService(WorkService workService) { + private List dbDatalist; + private List excelDatalist = new ArrayList<>(); + + private List result; + + private final WorkMapper workMapper; + private final MailQuery mailQuery; + + public ExcelService(WorkMapper workMapper, MailQuery mailQuery) { + this.workMapper = workMapper; + this.mailQuery = mailQuery; } @Override public void invoke(WorkVo workVo, AnalysisContext analysisContext) { - + excelDatalist.add(workVo); } @Override public void doAfterAllAnalysed(AnalysisContext analysisContext) { - + QueryWrapper queryWrapper = new QueryWrapper() + .ge(StrUtil.isNotBlank(mailQuery.getMailTimeStart()), "TO_CHAR(m.mail_time, 'YYYY-MM-DD')", mailQuery.getMailTimeStart()) + .le(StrUtil.isNotBlank(mailQuery.getMailTimeStartEnd()), "TO_CHAR(m.mail_time, 'YYYY-MM-DD')", mailQuery.getMailTimeStartEnd()); + dbDatalist = workMapper.selectList(queryWrapper); + for (WorkVo workVo : excelDatalist) { + for (Work work : dbDatalist) { + if (work.getMailId().equals(workVo.getMailId())) { + excelDatalist.remove(workVo); + break; + } + } + } + result = excelDatalist; } } diff --git a/mailbox-lan/src/main/java/com/biutag/lan/service/MailSourceService.java b/mailbox-lan/src/main/java/com/biutag/lan/service/MailSourceService.java index e77288b..3d48320 100644 --- a/mailbox-lan/src/main/java/com/biutag/lan/service/MailSourceService.java +++ b/mailbox-lan/src/main/java/com/biutag/lan/service/MailSourceService.java @@ -5,11 +5,15 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.biutag.lan.domain.MailSource; import com.biutag.lan.domain.bo.MailOuter; +import com.biutag.lan.domain.vo.WorkVo; import com.biutag.lan.mapper.MailSourceMapper; +import jakarta.annotation.Resource; import lombok.RequiredArgsConstructor; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; import java.util.List; import java.util.stream.Collectors; @@ -18,6 +22,8 @@ import java.util.stream.Collectors; public class MailSourceService extends ServiceImpl { private final WorkService workService; + @Resource + private MailSourceMapper mailSourceMapper; @Transactional(rollbackFor = Exception.class) public boolean saveBatch(List mailOuterList) { @@ -37,4 +43,18 @@ public class MailSourceService extends ServiceImpl return count(queryWrapper); } + public boolean saveExcelBatch(List mailSources) { + LocalDateTime now = LocalDateTime.now(); + List list = mailSources.stream().map(mail -> { + MailSource mail1 = new MailSource(); + BeanUtils.copyProperties(mail, mail1); + return mail1; + }).filter(mail -> { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("id", mail.getId()); + return !(mailSourceMapper.selectCount(queryWrapper) > 0); + }).collect(Collectors.toList()); + + return saveBatch(list); + } } diff --git a/mailbox-lan/src/main/java/com/biutag/lan/service/WorkService.java b/mailbox-lan/src/main/java/com/biutag/lan/service/WorkService.java index 7def5bc..b144c07 100644 --- a/mailbox-lan/src/main/java/com/biutag/lan/service/WorkService.java +++ b/mailbox-lan/src/main/java/com/biutag/lan/service/WorkService.java @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.biutag.core.AjaxResult; import com.biutag.enums.RoleEnum; import com.biutag.lan.AdminThreadLocal; import com.biutag.lan.domain.Mail; @@ -39,6 +40,9 @@ public class WorkService extends ServiceImpl { @Resource private MailLabelMapper mailLabelMapper; + @Resource + private WorkMapper workMapper; + public boolean saveBatch(List mailSources) { LocalDateTime now = LocalDateTime.now(); List list = mailSources.stream().map(mail -> { @@ -57,6 +61,17 @@ public class WorkService extends ServiceImpl { return saveBatch(list); } + public boolean saveExcelBatch(List mailSources) { + LocalDateTime now = LocalDateTime.now(); + List list = mailSources.stream().map(mail -> { + Work work = new Work(); + BeanUtils.copyProperties(mail, work); + return work; + }).filter(mail -> !(workMapper.countByFilter(mail.getMailId()) > 0)).collect(Collectors.toList()); + + return saveBatch(list); + } + public boolean save(Mail mail, String empNo, LocalDateTime time) { Work work = new Work(); BeanUtils.copyProperties(mail, work); @@ -324,10 +339,6 @@ public class WorkService extends ServiceImpl { EasyExcel.write(response.getOutputStream(), WorkVo.class).sheet("模板").doWrite(data); } - public void importExcel(MultipartFile file) throws IOException { - EasyExcel.read(file.getInputStream(), WorkVo.class, new ExcelService(this)).sheet().doRead(); - } - public Page dissatisfied(Page page, MailQuery todoQuery) { QueryWrapper queryWrapper = new QueryWrapper() .ge(StrUtil.isNotBlank(todoQuery.getMailTimeStart()), "TO_CHAR(m.mail_time, 'YYYY-MM-DD')", todoQuery.getMailTimeStart()) @@ -337,9 +348,9 @@ public class WorkService extends ServiceImpl { .eq(StrUtil.isNotBlank(todoQuery.getMailCategory()), "m.mail_category", todoQuery.getMailCategory()) .like(StrUtil.isNotBlank(todoQuery.getThreeDeptName()), "m.three_dept_name", todoQuery.getThreeDeptName()) // .eq(StrUtil.isNotBlank(todoQuery.getAppealState()), "m.appeal_state", todoQuery.getAppealState()) - .eq("m.satisfaction_status","不满意") + .eq("m.satisfaction_status", "不满意") .or() - .eq("m.verify_feedback","不满意"); + .eq("m.verify_feedback", "不满意"); Integer roleId = AdminThreadLocal.getRoleId(); // 与角色相关的件 if (roleId.equals(RoleEnum.MUNICIPAL_DEPT_CLASSES.getRoleId()) || @@ -371,4 +382,10 @@ public class WorkService extends ServiceImpl { queryWrapper.orderByDesc("w.update_time"); return baseMapper.selectPageTodo(page, queryWrapper); } + + public AjaxResult> checkExcel(MultipartFile file, MailQuery mailQuery) throws IOException { + ExcelService excelService = new ExcelService(workMapper, mailQuery); + EasyExcel.read(file.getInputStream(), WorkVo.class, excelService).sheet().doRead(); + return AjaxResult.success(excelService.getResult()); + } }