From 9a57fe475442739c16fb0bb0537ada939798b13a Mon Sep 17 00:00:00 2001 From: wangxianzhang Date: Wed, 24 Aug 2022 15:14:07 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=B7=A5=E4=BD=9C=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E3=80=91=E5=AE=8C=E6=88=90=E5=AF=BC=E5=87=BA=EF=BC=9B=E5=88=A0?= =?UTF-8?q?=E9=99=A4servicetype=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=AF=B9record?= =?UTF-8?q?=E7=9A=84=E5=88=A4=E6=96=AD=EF=BC=8C=E6=9C=89record=E4=BA=86?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WorkdiaryServiceController.java | 23 +++-- .../excel/WorkdiaryServiceRecordExcel.java | 93 ++++++++----------- .../WorkdiaryServiceRecordService.java | 7 ++ .../service/WorkdiaryServiceTypeService.java | 2 +- .../WorkdiaryServiceRecordServiceImpl.java | 57 +++++++++++- .../impl/WorkdiaryServiceTypeServiceImpl.java | 41 ++++++-- 6 files changed, 152 insertions(+), 71 deletions(-) diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/WorkdiaryServiceController.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/WorkdiaryServiceController.java index 4b5a574df8..cdd26b8794 100755 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/WorkdiaryServiceController.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/WorkdiaryServiceController.java @@ -2,6 +2,7 @@ package com.epmet.controller; import com.epmet.commons.tools.aop.NoRepeatSubmit; import com.epmet.commons.tools.dto.form.PageFormDTO; +import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.utils.ExcelUtils; import com.epmet.commons.tools.utils.Result; @@ -14,7 +15,6 @@ import com.epmet.dto.WorkdiaryServiceTypeDTO; import com.epmet.dto.form.workdiaryservice.WorkdiaryServiceQueryFormDTO; import com.epmet.dto.result.WorkdiaryServiceRecordDTO; import com.epmet.entity.WorkdiaryServiceTypeExcel; -import com.epmet.excel.WorkdiaryServiceRecordExcel; import com.epmet.service.WorkdiaryServiceRecordService; import com.epmet.service.WorkdiaryServiceTypeService; import org.springframework.beans.factory.annotation.Autowired; @@ -116,10 +116,15 @@ public class WorkdiaryServiceController { * 记录-导出 * @return */ - @GetMapping("/record/export") - public void recordExport(@RequestParam Map params, HttpServletResponse response) throws Exception { - List list = workdiaryServiceRecordService.list(params); - ExcelUtils.exportExcelToTarget(response, null, list, WorkdiaryServiceRecordExcel.class); + @PostMapping("/record/export") + public void recordExport(@RequestBody WorkdiaryServiceQueryFormDTO query, HttpServletResponse response) throws Exception { + String gridId = query.getGridId(); + Short serviceType = query.getServiceType(); + String applicantName = query.getApplicantName(); + String applicantAddress = query.getApplicantAddress(); + String serviceContent = query.getServiceContent(); + String applicantMobile = query.getApplicantMobile(); + workdiaryServiceRecordService.export(gridId, serviceType, applicantName, applicantAddress, serviceContent, applicantMobile, response); } /** @@ -176,8 +181,12 @@ public class WorkdiaryServiceController { public Result serviceTypeDelete(@RequestBody String[] ids){ //效验数据 AssertUtils.isArrayEmpty(ids, "id"); - workdiaryServiceTypeService.delete(ids); - return new Result(); + int failCount = workdiaryServiceTypeService.delete(ids); + if (failCount == 0) { + return new Result(); + } else { + return new Result().error(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "部分条目已经被使用,未完全删除,失败条目:" + failCount); + } } /** diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/WorkdiaryServiceRecordExcel.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/WorkdiaryServiceRecordExcel.java index e0eace7a2a..8a2f2cf454 100755 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/WorkdiaryServiceRecordExcel.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/WorkdiaryServiceRecordExcel.java @@ -1,12 +1,12 @@ package com.epmet.excel; -import cn.afterturn.easypoi.excel.annotation.Excel; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; +import com.epmet.dto.result.WorkdiaryServiceRecordDTO; import lombok.Data; -import java.util.Date; - /** - * 工作日志(服务)-记录 + * 工作日志(服务)-记录 excel * * @author generator generator@elink-cn.com * @since v1.0.0 2022-08-23 @@ -14,65 +14,52 @@ import java.util.Date; @Data public class WorkdiaryServiceRecordExcel { - @Excel(name = "主键") - private String id; - - @Excel(name = "客户id") - private String customerId; - - @Excel(name = "服务类型") - private String serviceType; - - @Excel(name = "单位ID") - private String agencyId; - - @Excel(name = "网格ID") - private String gridId; + @ColumnWidth(25) + @ExcelProperty(value = "所属网格") + private String gridName; - @Excel(name = "组织ID path") - private String orgIdPath; + @ColumnWidth(15) + @ExcelProperty(value = "服务类型") + private String serviceTypeName; - @Excel(name = "申请人ID") - private String applicantId; - - @Excel(name = "申请人姓名") + @ColumnWidth(10) + @ExcelProperty(value = "申请人") private String applicantName; - @Excel(name = "申请人住址") + @ColumnWidth(25) + @ExcelProperty(value = "住址") private String applicantAddress; - @Excel(name = "申请人联系电话") - private String applicantMobile; - - @Excel(name = "服务内容") + @ColumnWidth(25) + @ExcelProperty(value = "服务内容") private String serviceContent; - @Excel(name = "服务时间") - private Date serviceTime; - - @Excel(name = "负责人姓名") - private String principalName; - - @Excel(name = "备注") - private String remark; - - @Excel(name = "删除标识 0.未删除 1.已删除") - private Integer delFlag; - - @Excel(name = "乐观锁") - private Integer revision; - - @Excel(name = "创建人") - private String createdBy; - - @Excel(name = "创建时间") - private Date createdTime; + @ColumnWidth(15) + @ExcelProperty(value = "联系电话") + private String applicantMobile; - @Excel(name = "更新人") - private String updatedBy; + @ColumnWidth(10) + @ExcelProperty(value = "负责人") + private String principal; - @Excel(name = "更新时间") - private Date updatedTime; + @ColumnWidth(10) + @ExcelProperty(value = "服务时间") + private String serviceTime; + @ColumnWidth(20) + @ExcelProperty(value = "备注") + private String remark; + public WorkdiaryServiceRecordExcel(WorkdiaryServiceRecordDTO dto) { + this.gridName = dto.getGridName(); + this.serviceTypeName = dto.getServiceTypeName(); + this.applicantName = dto.getApplicantName(); + this.applicantAddress = dto.getApplicantAddress(); + this.serviceContent = dto.getServiceContent(); + this.serviceContent = dto.getServiceContent(); + this.principal = dto.getPrincipalName(); + this.principal = dto.getPrincipalName(); + this.serviceTime = dto.getServiceTime(); + this.remark = dto.getRemark(); + } } \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/WorkdiaryServiceRecordService.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/WorkdiaryServiceRecordService.java index 47671ea202..e6ed7578f4 100755 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/WorkdiaryServiceRecordService.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/WorkdiaryServiceRecordService.java @@ -2,9 +2,11 @@ package com.epmet.service; import com.epmet.commons.mybatis.service.BaseService; import com.epmet.commons.tools.page.PageData; +import com.epmet.dto.form.workdiaryservice.WorkdiaryServiceQueryFormDTO; import com.epmet.dto.result.WorkdiaryServiceRecordDTO; import com.epmet.entity.WorkdiaryServiceRecordEntity; +import javax.servlet.http.HttpServletResponse; import java.util.List; import java.util.Map; @@ -78,4 +80,9 @@ public interface WorkdiaryServiceRecordService extends BaseService page = this.page(gridId, serviceType, applicantName, applicantAddress, serviceContent, applicantMobile, pageNo, pageSize); + List list = page.getList(); + if (CollectionUtils.isEmpty(list)) { + // 空的,导出结束 + break; + } + + List excelObjects = list.stream().map(e -> new WorkdiaryServiceRecordExcel(e)).collect(Collectors.toList()); + writer.write(excelObjects, sheet); + } + } finally { + writer.finish(); + } + } + + @Override + public Integer selectRecordCountOfType(Short serviceType) { + LambdaQueryWrapper query = new LambdaQueryWrapper<>(); + query.eq(WorkdiaryServiceRecordEntity::getCustomerId, EpmetRequestHolder.getLoginUserCustomerId()); + query.eq(WorkdiaryServiceRecordEntity::getServiceType, serviceType); + return baseDao.selectCount(query); + } } \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/WorkdiaryServiceTypeServiceImpl.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/WorkdiaryServiceTypeServiceImpl.java index e81f8b7c30..8c34a9b93c 100755 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/WorkdiaryServiceTypeServiceImpl.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/WorkdiaryServiceTypeServiceImpl.java @@ -2,28 +2,31 @@ package com.epmet.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.commons.tools.constant.FieldConstant; +import com.epmet.commons.tools.distributedlock.DistributedLock; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.page.PageData; -import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.commons.tools.utils.ConvertUtils; -import com.epmet.commons.tools.constant.FieldConstant; import com.epmet.commons.tools.utils.EpmetRequestHolder; +import com.epmet.commons.tools.utils.SpringContextUtils; import com.epmet.dao.WorkdiaryServiceTypeDao; import com.epmet.dto.WorkdiaryServiceTypeDTO; import com.epmet.entity.WorkdiaryServiceTypeEntity; import com.epmet.redis.WorkdiaryServiceTypeRedis; +import com.epmet.service.WorkdiaryServiceRecordService; import com.epmet.service.WorkdiaryServiceTypeService; import com.github.pagehelper.PageInfo; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.RequestBody; -import java.util.Arrays; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -41,6 +44,8 @@ public class WorkdiaryServiceTypeServiceImpl extends BaseServiceImpl page(Integer pageNo, Integer pageSize) { @@ -61,6 +66,7 @@ public class WorkdiaryServiceTypeServiceImpl extends BaseServiceImpl ds = baseDao.selectList(stQuery).stream().map((e) -> { WorkdiaryServiceTypeDTO d = new WorkdiaryServiceTypeDTO(); + d.setId(e.getId()); d.setServiceType(e.getServiceType()); d.setServiceTypeName(e.getServiceTypeName()); d.setEnabled(e.getEnabled()); @@ -115,9 +121,30 @@ public class WorkdiaryServiceTypeServiceImpl extends BaseServiceImpl canDeleteIds = new ArrayList<>(); + int failCount = 0; + for (String id : ids) { + WorkdiaryServiceTypeEntity st = baseDao.selectById(id); + if (st == null) { + continue; + } + WorkdiaryServiceRecordService wsRecordService = SpringContextUtils.getBean(WorkdiaryServiceRecordService.class); + Integer recordCount = wsRecordService.selectRecordCountOfType(st.getServiceType()); + if (recordCount > 0) { + failCount++; + } else { + canDeleteIds.add(id); + } + } + + if (CollectionUtils.isNotEmpty(canDeleteIds)) { + baseDao.deleteBatchIds(canDeleteIds); + } + return failCount; } } \ No newline at end of file