| | |
| | | |
| | | import cn.hutool.json.JSONUtil; |
| | | import cn.idev.excel.FastExcel; |
| | | import cn.idev.excel.ExcelWriter; |
| | | import cn.idev.excel.write.metadata.WriteSheet; |
| | | import com.tcm.training.admin.agent.excel.ProvincialAgentExcelRow; |
| | | import com.tcm.training.admin.common.DateTimes; |
| | | import com.fasterxml.jackson.databind.JsonNode; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | |
| | | return PageResponse.of(new ArrayList<ProvincialAgentListItemVO>(), 0, page, pageSize); |
| | | } |
| | | |
| | | /** 分批复用列表查询,确保导出筛选、区域名称及排序与页面一致。 */ |
| | | public void export(String regionCode, String clinicName, String contactInfo, Integer status, |
| | | HttpServletResponse response) throws IOException { |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | String filename = URLEncoder.encode("省代用户列表", "UTF-8").replace("+", "%20"); |
| | | response.setHeader("Content-Disposition", "attachment;filename*=utf-8''" + filename + ".xlsx"); |
| | | final int batchSize = 200; |
| | | long serialNo = 0; |
| | | try (ExcelWriter writer = FastExcel.write(response.getOutputStream(), ProvincialAgentExcelRow.class).build()) { |
| | | WriteSheet sheet = FastExcel.writerSheet("省代用户列表").build(); |
| | | for (int pageNumber = 1; ; pageNumber++) { |
| | | PageResponse<ProvincialAgentListItemVO> result = |
| | | page(pageNumber, batchSize, regionCode, clinicName, contactInfo, status); |
| | | List<ProvincialAgentExcelRow> rows = new ArrayList<>(); |
| | | for (ProvincialAgentListItemVO item : result.getList()) { |
| | | rows.add(toExcelRow(item, ++serialNo)); |
| | | } |
| | | writer.write(rows, sheet); |
| | | if (result.getList().isEmpty() || serialNo >= result.getTotal()) { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private ProvincialAgentExcelRow toExcelRow(ProvincialAgentListItemVO item, long serialNo) { |
| | | ProvincialAgentExcelRow row = new ProvincialAgentExcelRow(); |
| | | row.setSerialNo(serialNo); |
| | | row.setAgentName(exportText(item.getAgentName())); |
| | | row.setContactInfo(exportText(item.getContactInfo())); |
| | | row.setAddress(exportText(item.getAddress())); |
| | | row.setRegionNames(exportText(String.join("、", item.getRegionNames()))); |
| | | row.setClinicCount(item.getClinicCount() == null ? 0L : item.getClinicCount()); |
| | | row.setStatus(Integer.valueOf(1).equals(item.getStatus()) ? "启用" |
| | | : Integer.valueOf(2).equals(item.getStatus()) ? "注销" : "禁用"); |
| | | row.setCreatedAt(DateTimes.format(item.getCreatedAt())); |
| | | return row; |
| | | } |
| | | |
| | | private String exportText(String value) { |
| | | return trim(value) == null ? "-" : value; |
| | | } |
| | | |
| | | /** 查询省代理详情。 */ |
| | | public ProvincialAgentDetailVO detail(Long id) { |
| | | return toDetail(require(id)); |