From c1d3bdee289e338dbb1fc4d3d27d425136923144 Mon Sep 17 00:00:00 2001 From: yinzuomei <576302893@qq.com> Date: Fri, 17 Feb 2023 17:05:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=81=94=E5=BB=BA=E5=8D=95=E4=BD=8D=E5=AF=BC?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/epmet/dto/IcPartyUnitDTO.java | 5 ++ .../com/epmet/dto/form/PartyUnitFormDTO.java | 7 +- .../controller/IcPartyUnitController.java | 67 ++++++++++++------- .../com/epmet/excel/IcPartyUnitExcel.java | 41 ++++++++---- .../service/impl/IcPartyUnitServiceImpl.java | 6 ++ 5 files changed, 83 insertions(+), 43 deletions(-) diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/IcPartyUnitDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/IcPartyUnitDTO.java index 1aed3be19f..b269fa0d5b 100644 --- a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/IcPartyUnitDTO.java +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/IcPartyUnitDTO.java @@ -86,6 +86,11 @@ public class IcPartyUnitDTO implements Serializable { */ private List serviceMatterNameList; + /** + * 服务事项名称多个按照中文顿号隔开 + */ + private String serviceMatterName; + /** * 联系人 */ diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/PartyUnitFormDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/PartyUnitFormDTO.java index ec4a1751dd..f238e5dbe1 100644 --- a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/PartyUnitFormDTO.java +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/PartyUnitFormDTO.java @@ -1,5 +1,6 @@ package com.epmet.dto.form; +import com.epmet.commons.tools.dto.form.PageFormDTO; import lombok.Data; import lombok.NoArgsConstructor; @@ -12,7 +13,7 @@ import java.io.Serializable; */ @NoArgsConstructor @Data -public class PartyUnitFormDTO implements Serializable { +public class PartyUnitFormDTO extends PageFormDTO implements Serializable { private static final long serialVersionUID = 1256798619648265622L; private String customerId; @@ -22,8 +23,8 @@ public class PartyUnitFormDTO implements Serializable { private String type; private String contact; private String contactMobile; - private Integer pageNo; - private Integer pageSize; + // private Integer pageNo; + // private Integer pageSize; /** * 工作端当前登录人员 diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcPartyUnitController.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcPartyUnitController.java index dfa0808fce..2832d0009d 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcPartyUnitController.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcPartyUnitController.java @@ -1,16 +1,24 @@ package com.epmet.controller; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.write.metadata.WriteSheet; import com.epmet.commons.rocketmq.messages.ServerSatisfactionCalFormDTO; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.aop.NoRepeatSubmit; import com.epmet.commons.tools.constant.AppClientConstant; +import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.dto.result.OptionDataResultDTO; import com.epmet.commons.tools.exception.ExceptionUtils; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.utils.DateUtils; import com.epmet.commons.tools.utils.ExcelUtils; import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.utils.poi.excel.handler.FreezeAndFilter; import com.epmet.commons.tools.validator.AssertUtils; import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.commons.tools.validator.group.AddGroup; @@ -28,6 +36,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.web.bind.annotation.*; @@ -40,11 +49,9 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InputStream; import java.net.URLEncoder; -import java.nio.file.Path; -import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @@ -64,11 +71,6 @@ public class IcPartyUnitController { @Resource private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient; - /** - * 联建单位上传临时目录 - */ - private Path IC_PARTY_UNIT_UPLOAD_DIR; - /** * 联建单位-列表查询 @@ -122,25 +124,38 @@ public class IcPartyUnitController { @PostMapping("export") public void export(@LoginUser TokenDto tokenDto, @RequestBody PartyUnitFormDTO formDTO, HttpServletResponse response) throws Exception { formDTO.setCustomerId(tokenDto.getCustomerId()); - List list = icPartyUnitService.list(formDTO); - List excelList = new ArrayList<>(); - AtomicInteger i = new AtomicInteger(1); - if (CollectionUtils.isNotEmpty(list)) { - excelList = list.stream().map(item -> { - IcPartyUnitExcel excel = new IcPartyUnitExcel(); - excel.setIndex(i.getAndIncrement()); - excel.setUnitName(item.getUnitName()); - excel.setContact(item.getContact()); - excel.setContactMobile(item.getContactMobile()); - excel.setType(item.getType()); - excel.setMemberCount(item.getMemberCount()); - excel.setRemark(item.getRemark()); - excel.setSatisfaction(item.getSatisfaction()); - excel.setServiceMatter(String.join(String.valueOf((char) 10), item.getServiceMatterList())); - return excel; - }).collect(Collectors.toList()); + formDTO.setIsPage(false); + formDTO.setCurrentStaffId(tokenDto.getUserId()); + ExcelWriter excelWriter = null; + formDTO.setPageSize(NumConstant.TEN_THOUSAND); + int pageNo = formDTO.getPageNo(); + try { + // 这里 需要指定写用哪个class去写 + String today= DateUtils.format(new Date(),DateUtils.DATE_PATTERN_MMDD); + String fileName = "行程上报信息".concat(today); + excelWriter = EasyExcel.write(ExcelUtils.getOutputStreamForExcel(fileName, response), IcPartyUnitExcel.class).build(); + WriteSheet writeSheet = EasyExcel.writerSheet("Sheet1").registerWriteHandler(new FreezeAndFilter()).build(); + PageData data = null; + List list = null; + do { + data = icPartyUnitService.search(formDTO); + data.getList().stream().map(item -> { + item.setServiceMatterName(StringUtils.join(item.getServiceMatterList(), StrConstant.COMMA_ZH)); + return item; + }).collect(Collectors.toList()); + list = ConvertUtils.sourceToTarget(data.getList(), IcPartyUnitExcel.class); + formDTO.setPageNo(++pageNo); + excelWriter.write(list, writeSheet); + } while (CollectionUtils.isNotEmpty(data.getList()) && data.getList().size() == formDTO.getPageSize()); + + } catch (Exception e) { + log.error("export exception", e); + } finally { + // 千万别忘记finish 会帮忙关闭流 + if (excelWriter != null) { + excelWriter.finish(); + } } - ExcelUtils.exportExcelToTarget(response, null, excelList, IcPartyUnitExcel.class); } /** diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/IcPartyUnitExcel.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/IcPartyUnitExcel.java index 652542ef62..36e9484acc 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/IcPartyUnitExcel.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/IcPartyUnitExcel.java @@ -17,7 +17,8 @@ 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 lombok.Data; /** @@ -29,30 +30,42 @@ import lombok.Data; @Data public class IcPartyUnitExcel { - @Excel(name = "序号") - private Integer index; - - @Excel(name = "单位名称") + @ColumnWidth(30) + @ExcelProperty(value = "单位名称") private String unitName; - @Excel(name = "分类") - private String type; + @ColumnWidth(25) + @ExcelProperty(value = "所属组织") + private String agencyName; + + @ColumnWidth(25) + @ExcelProperty(value = "分类") + private String typeName; - @Excel(name = "服务事项") - private String serviceMatter; + /** + * 服务事项名称多个按照中文顿号隔开 + */ + @ColumnWidth(100) + @ExcelProperty(value = "服务事项") + private String serviceMatterName; - @Excel(name = "联系人") + @ColumnWidth(16) + @ExcelProperty(value = "联系人") private String contact; - @Excel(name = "联系电话") + @ColumnWidth(16) + @ExcelProperty(value = "联系电话") private String contactMobile; - @Excel(name = "在职党员") + @ColumnWidth(18) + @ExcelProperty(value = "在职党员数") private Integer memberCount; - @Excel(name = "群众满意度") + @ColumnWidth(18) + @ExcelProperty(value = "群众满意度") private String satisfaction; - @Excel(name = "备注") + @ColumnWidth(100) + @ExcelProperty(value = "备注") private String remark; } \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcPartyUnitServiceImpl.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcPartyUnitServiceImpl.java index 0f31a1287d..f430f2b711 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcPartyUnitServiceImpl.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcPartyUnitServiceImpl.java @@ -145,6 +145,8 @@ public class IcPartyUnitServiceImpl extends BaseServiceImpl pointMap = icUserDemandRecService.getServicePoint(formDTO.getCustomerId(), UserDemandConstant.PARTY_UNIT); dtoList.forEach(item -> { + item.setTypeName(unitTypeMap.getData().get(item.getType())); + //这是错误的,应该是赋值type,遗留bug, 先不改了.... item.setType(unitTypeMap.getData().get(item.getType())); if (StringUtils.isNotBlank(item.getServiceMatter())) { List matters = Arrays.asList(item.getServiceMatter().split(StrConstant.COMMA)); @@ -183,6 +185,8 @@ public class IcPartyUnitServiceImpl extends BaseServiceImpl pointMap = icUserDemandRecService.getServicePoint(formDTO.getCustomerId(), UserDemandConstant.PARTY_UNIT); dtoList.forEach(item -> { + item.setTypeName(unitTypeMap.getData().get(item.getType())); + //这是错误的,应该是赋值type,遗留bug, 先不改了.... item.setType(unitTypeMap.getData().get(item.getType())); if (StringUtils.isNotBlank(item.getServiceMatter())) { List matters = Arrays.asList(item.getServiceMatter().split(StrConstant.COMMA)); @@ -217,6 +221,8 @@ public class IcPartyUnitServiceImpl extends BaseServiceImpl> typeDictMapRes=epmetAdminOpenFeignClient.dictMap(DictTypeEnum.PARTY_UNIT_TYPE.getCode()); Map typeDictMap = typeDictMapRes.success() && MapUtils.isNotEmpty(typeDictMapRes.getData()) ? typeDictMapRes.getData() : new HashMap<>(); + dto.setTypeName(MapUtils.isNotEmpty(typeDictMap) && typeDictMap.containsKey(dto.getType()) ? typeDictMap.get(dto.getType()) : StrConstant.EPMETY_STR); + //这是错误的,应该是赋值type,遗留bug, 先不改了.... dto.setType(MapUtils.isNotEmpty(typeDictMap) && typeDictMap.containsKey(dto.getType()) ? typeDictMap.get(dto.getType()) : StrConstant.EPMETY_STR); // 服务事项 if(CollectionUtils.isNotEmpty(dto.getServiceMatterList())){