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/system/MailLabelController.java b/mailbox-lan/src/main/java/com/biutag/lan/controller/system/MailLabelController.java index 37617ae..78e4f33 100644 --- a/mailbox-lan/src/main/java/com/biutag/lan/controller/system/MailLabelController.java +++ b/mailbox-lan/src/main/java/com/biutag/lan/controller/system/MailLabelController.java @@ -33,8 +33,7 @@ public class MailLabelController { @PostMapping("/add") @ApiOperation(value="信件标签新增") public AjaxResult add(@Validated @RequestBody MailLabelValidate createValidate) { - iMailLabelService.addLabel(createValidate); - return AjaxResult.success(); + return iMailLabelService.addLabel(createValidate); } @PostMapping("/insert") 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 404eb8c..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,6 +1,5 @@ package com.biutag.lan.controller.work; -import com.alibaba.excel.EasyExcel; import com.alibaba.fastjson2.JSON; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.biutag.aop.NotPower; @@ -8,13 +7,15 @@ 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.net.URLEncoder; import java.util.List; @RequestMapping("api/work") @@ -23,6 +24,7 @@ import java.util.List; public class WorkController { private final WorkService workService; + private final MailSourceService mailSourceService; @NotPower @GetMapping("{workState}") @@ -39,12 +41,26 @@ public class WorkController { @NotPower @PostMapping("export") public void detail(HttpServletResponse response, @RequestBody String dataWorkVo) throws IOException { - List data = JSON.parseArray(dataWorkVo, WorkVo.class); - response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); - response.setCharacterEncoding("utf-8"); - // 这里URLEncoder.encode可以防止中文乱码 - String fileName = URLEncoder.encode("测试", "UTF-8").replaceAll("\\+", "%20"); - response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); - EasyExcel.write(response.getOutputStream(), WorkVo.class).sheet("模板").doWrite(data); + workService.export(response, dataWorkVo); + } + + @NotPower + @PostMapping("import") + @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 + @GetMapping("dissatisfied") + public AjaxResult> dissatisfied(Page page, MailQuery todoQuery) { + return AjaxResult.success(workService.dissatisfied(page, todoQuery)); } } 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..e862162 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 @@ -12,7 +12,7 @@ import java.time.LocalDateTime; @Getter public class WorkVo { - @ExcelIgnore + @ExcelProperty("工作流ID") private Integer id; /** @@ -27,7 +27,7 @@ public class WorkVo { @ExcelProperty("联系电话") private String contactPhone; - @ExcelIgnore + @ExcelProperty("联系人身份证号") private String contactIdCard; /** @@ -52,13 +52,13 @@ public class WorkVo { /** * 信件ID */ - + @ExcelProperty("信件ID") private String mailId; /** * 信件等级 */ - @ExcelIgnore + @ExcelProperty("信件等级") private String mailLevel; /** @@ -76,7 +76,7 @@ public class WorkVo { /** * 信件流程节点 */ - @ExcelIgnore + @ExcelProperty("流程节点ID") private String flowKey; /** @@ -94,7 +94,7 @@ public class WorkVo { /** * 办理单位ID(三级单位) */ - @ExcelIgnore + @ExcelProperty("办理单位ID-三级") private Integer threeDeptId; @ExcelProperty("办理单位") @@ -103,7 +103,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 new file mode 100644 index 0000000..78d2e53 --- /dev/null +++ b/mailbox-lan/src/main/java/com/biutag/lan/service/ExcelService.java @@ -0,0 +1,54 @@ +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 com.biutag.lan.mapper.WorkMapper; +import lombok.Getter; + +import java.util.ArrayList; +import java.util.List; + +@Getter +public class ExcelService implements ReadListener { + 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 (int i = 0; i < excelDatalist.size(); i++) { + WorkVo workVo = excelDatalist.get(i); + for (Work work : dbDatalist) { + if (work.getMailId().equals(workVo.getMailId())) { + excelDatalist.remove(workVo); + i--; // 减去索引以补偿移除的元素 + break; // 一旦找到匹配并移除,跳出内循环 + } + } + } + result = excelDatalist; + } +} diff --git a/mailbox-lan/src/main/java/com/biutag/lan/service/IMailLabelService.java b/mailbox-lan/src/main/java/com/biutag/lan/service/IMailLabelService.java index d010de3..31508a0 100644 --- a/mailbox-lan/src/main/java/com/biutag/lan/service/IMailLabelService.java +++ b/mailbox-lan/src/main/java/com/biutag/lan/service/IMailLabelService.java @@ -1,5 +1,6 @@ package com.biutag.lan.service; +import com.biutag.core.AjaxResult; import com.biutag.lan.validate.system.MailLabelInsertValidate; import com.biutag.lan.validate.system.MailLabelValidate; import com.biutag.lan.vo.system.MailLabelVO; @@ -9,7 +10,7 @@ import java.util.List; public interface IMailLabelService { List allLabels(); - void addLabel(MailLabelValidate mailLabel); + AjaxResult addLabel(MailLabelValidate mailLabel); void insertLabel(MailLabelInsertValidate mailLabel); } 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..19e6aa1 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,21 @@ 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); + mail1.setId(mail.getMailId()) + .setState(mail.getMailState()); + + 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 8262907..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 @@ -1,10 +1,13 @@ package com.biutag.lan.service; import cn.hutool.core.util.StrUtil; +import com.alibaba.excel.EasyExcel; +import com.alibaba.fastjson2.JSON; 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; @@ -17,10 +20,14 @@ import com.biutag.lan.enums.WorkType; import com.biutag.lan.mapper.MailLabelMapper; import com.biutag.lan.mapper.WorkMapper; import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; +import java.net.URLEncoder; import java.time.LocalDateTime; import java.util.List; import java.util.Objects; @@ -33,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 -> { @@ -51,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); @@ -308,7 +329,63 @@ public class WorkService extends ServiceImpl { return result; } - public WorkVo exportWork(Long id) { - return new WorkVo(); + public void export(HttpServletResponse response, String dataWorkVo) throws IOException { + List data = JSON.parseArray(dataWorkVo, WorkVo.class); + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + // 这里URLEncoder.encode可以防止中文乱码 + String fileName = URLEncoder.encode("测试", "UTF-8").replaceAll("\\+", "%20"); + response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); + EasyExcel.write(response.getOutputStream(), WorkVo.class).sheet("模板").doWrite(data); + } + + 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()) + .le(StrUtil.isNotBlank(todoQuery.getMailTimeStartEnd()), "TO_CHAR(m.mail_time, 'YYYY-MM-DD')", todoQuery.getMailTimeStartEnd()) + .eq(StrUtil.isNotBlank(todoQuery.getSource()), "m.source", todoQuery.getSource()) + .eq(StrUtil.isNotBlank(todoQuery.getMailLevel()), "m.mail_level", todoQuery.getMailLevel()) + .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", "不满意") + .or() + .eq("m.verify_feedback", "不满意"); + Integer roleId = AdminThreadLocal.getRoleId(); + // 与角色相关的件 + if (roleId.equals(RoleEnum.MUNICIPAL_DEPT_CLASSES.getRoleId()) || + roleId.equals(RoleEnum.SECOND_DEPT_CLASSES.getRoleId()) || + roleId.equals(RoleEnum.THREE_DEPT_CLASSES.getRoleId())) { + Integer deptId = AdminThreadLocal.getDeptId(); + queryWrapper.eq("w.sign_role_id", roleId) + // 如果不是市局专班,则需要查询签收部门ID + .eq(!RoleEnum.MUNICIPAL_DEPT_CLASSES.getRoleId().equals(roleId), "w.sign_dept_id", deptId); + } else { + String empNo = AdminThreadLocal.getEmpNo(); + queryWrapper.eq("w.police_emp_no", empNo); + } + if (StrUtil.isNotBlank(todoQuery.getContactField()) && StrUtil.isNotBlank(todoQuery.getContactFieldValue())) { + switch (todoQuery.getContactField()) { + case "name": + queryWrapper.like("w.contact_name", todoQuery.getContactFieldValue()); + break; + case "idCard": + queryWrapper.like("w.contactIdCard", todoQuery.getContactFieldValue()); + break; + case "phone": + queryWrapper.like("w.contactPhone", todoQuery.getContactFieldValue()); + break; + } + + } + // 排序 + 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()); } } diff --git a/mailbox-lan/src/main/java/com/biutag/lan/service/impl/MailLabelServiceImpl.java b/mailbox-lan/src/main/java/com/biutag/lan/service/impl/MailLabelServiceImpl.java index 76f9980..a0cc75b 100644 --- a/mailbox-lan/src/main/java/com/biutag/lan/service/impl/MailLabelServiceImpl.java +++ b/mailbox-lan/src/main/java/com/biutag/lan/service/impl/MailLabelServiceImpl.java @@ -1,6 +1,7 @@ package com.biutag.lan.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.biutag.core.AjaxResult; import com.biutag.lan.domain.Mail; import com.biutag.lan.domain.MailLabel; import com.biutag.lan.mapper.MailLabelMapper; @@ -47,10 +48,16 @@ public class MailLabelServiceImpl implements IMailLabelService { * @param mailLabel */ @Override - public void addLabel(MailLabelValidate mailLabel) { + public AjaxResult addLabel(MailLabelValidate mailLabel) { MailLabel label = new MailLabel(); - label.setLabelName(mailLabel.getLabelName()); - mailLabelMapper.insert(label); + MailLabel existLabel = mailLabelMapper.selectOne(new QueryWrapper().eq("label_name", mailLabel.getLabelName())); + if (existLabel == null) { + label.setLabelName(mailLabel.getLabelName()); + mailLabelMapper.insert(label); + return AjaxResult.success(); + } else { + return AjaxResult.failed("标签已存在"); + } } @Override