|
|
@ -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; |
|
|
@ -27,19 +35,23 @@ import com.epmet.service.IcPartyUnitService; |
|
|
|
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.*; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.IOException; |
|
|
|
import java.nio.file.Path; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.net.URLEncoder; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
@ -59,11 +71,6 @@ public class IcPartyUnitController { |
|
|
|
@Resource |
|
|
|
private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient; |
|
|
|
|
|
|
|
/** |
|
|
|
* 联建单位上传临时目录 |
|
|
|
*/ |
|
|
|
private Path IC_PARTY_UNIT_UPLOAD_DIR; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 联建单位-列表查询 |
|
|
@ -117,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<IcPartyUnitDTO> list = icPartyUnitService.list(formDTO); |
|
|
|
List<IcPartyUnitExcel> 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<IcPartyUnitDTO> data = null; |
|
|
|
List<IcPartyUnitExcel> 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); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -330,4 +350,27 @@ public class IcPartyUnitController { |
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 下载联建单位导入模板 |
|
|
|
* @param response |
|
|
|
* @throws IOException |
|
|
|
*/ |
|
|
|
@RequestMapping(value = "import-template-download", method = {RequestMethod.GET, RequestMethod.POST}) |
|
|
|
public void downloadTemplate(HttpServletResponse response) throws IOException { |
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
response.addHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, "Content-Disposition"); |
|
|
|
//response.setHeader(HttpHeaders.CONTENT_TYPE, "application/vnd.ms-excel");
|
|
|
|
response.setHeader(HttpHeaders.CONTENT_TYPE, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
|
|
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("联建单位导入模板", "UTF-8") + ".xlsx"); |
|
|
|
|
|
|
|
InputStream is = this.getClass().getClassLoader().getResourceAsStream("templates/icpartyunit_impoort_tem.xlsx"); |
|
|
|
try { |
|
|
|
ServletOutputStream os = response.getOutputStream(); |
|
|
|
IOUtils.copy(is, os); |
|
|
|
} finally { |
|
|
|
if (is != null) { |
|
|
|
is.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|