|
|
@ -1,23 +1,42 @@ |
|
|
|
package com.epmet.modules.partyOrg.controller; |
|
|
|
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
import com.alibaba.excel.ExcelWriter; |
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.epmet.commons.tools.annotation.LoginUser; |
|
|
|
import com.epmet.commons.tools.aop.NoRepeatSubmit; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
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.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; |
|
|
|
import com.epmet.commons.tools.validator.group.DefaultGroup; |
|
|
|
import com.epmet.commons.tools.validator.group.UpdateGroup; |
|
|
|
import com.epmet.modules.partyOrg.excel.IcScheduleListExcel; |
|
|
|
import com.epmet.modules.partyOrg.service.IcScheduleService; |
|
|
|
import com.epmet.resi.partymember.dto.IcScheduleDTO; |
|
|
|
import com.epmet.resi.partymember.dto.partyOrg.form.AddOrEditScheduleFormDTO; |
|
|
|
import com.epmet.resi.partymember.dto.partyOrg.form.IcScheduleFormDTO; |
|
|
|
import com.epmet.resi.partymember.dto.partyOrg.result.IcScheduleListDTO; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.PrintWriter; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
@ -28,15 +47,17 @@ import java.util.Map; |
|
|
|
*/ |
|
|
|
@RestController |
|
|
|
@RequestMapping("icSchedule") |
|
|
|
@Slf4j |
|
|
|
public class IcScheduleController { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IcScheduleService icScheduleService; |
|
|
|
|
|
|
|
@RequestMapping("page") |
|
|
|
public Result<PageData<IcScheduleDTO>> page(@RequestParam Map<String, Object> params){ |
|
|
|
PageData<IcScheduleDTO> page = icScheduleService.page(params); |
|
|
|
return new Result<PageData<IcScheduleDTO>>().ok(page); |
|
|
|
@RequestMapping(value = "list",method = {RequestMethod.POST,RequestMethod.GET}) |
|
|
|
public Result<PageData<IcScheduleListDTO>> list(@LoginUser TokenDto tokenDto, @RequestBody IcScheduleFormDTO formDTO){ |
|
|
|
formDTO.setCustomerId(tokenDto.getCustomerId()); |
|
|
|
formDTO.setStaffId(tokenDto.getUserId()); |
|
|
|
return new Result<PageData<IcScheduleListDTO>>().ok(icScheduleService.list(formDTO)); |
|
|
|
} |
|
|
|
|
|
|
|
@RequestMapping(value = "{id}",method = {RequestMethod.POST,RequestMethod.GET}) |
|
|
@ -98,5 +119,42 @@ public class IcScheduleController { |
|
|
|
icScheduleService.delSchedule(scheduleIds); |
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("export") |
|
|
|
public void export(@LoginUser TokenDto tokenDto, @RequestBody IcScheduleFormDTO formDTO, HttpServletResponse response) throws IOException { |
|
|
|
formDTO.setCustomerId(tokenDto.getCustomerId()); |
|
|
|
formDTO.setStaffId(tokenDto.getUserId()); |
|
|
|
formDTO.setIsPage(false); |
|
|
|
ExcelWriter excelWriter = null; |
|
|
|
formDTO.setPageNo(NumConstant.ONE); |
|
|
|
formDTO.setPageSize(NumConstant.TEN_THOUSAND); |
|
|
|
try { |
|
|
|
String fileName = "日程列表" + DateUtils.format(new Date()) + ".xlsx"; |
|
|
|
excelWriter = EasyExcel.write(ExcelUtils.getOutputStreamForExcel(fileName, response), IcScheduleListExcel.class).build(); |
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet("Sheet1").registerWriteHandler(new FreezeAndFilter()).build(); |
|
|
|
PageData<IcScheduleListDTO> data = null; |
|
|
|
List<IcScheduleListExcel> list = null; |
|
|
|
do { |
|
|
|
data = icScheduleService.list(formDTO); |
|
|
|
list = ConvertUtils.sourceToTarget(data.getList(), IcScheduleListExcel.class); |
|
|
|
formDTO.setPageNo(formDTO.getPageNo() + NumConstant.ONE); |
|
|
|
excelWriter.write(list, writeSheet); |
|
|
|
} while (CollectionUtils.isNotEmpty(list) && list.size() == formDTO.getPageSize()); |
|
|
|
} catch (EpmetException e) { |
|
|
|
response.reset(); |
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
response.setHeader("content-type", "application/json; charset=UTF-8"); |
|
|
|
PrintWriter printWriter = response.getWriter(); |
|
|
|
Result<Object> result = new Result<>().error(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),e.getMsg()); |
|
|
|
printWriter.write(JSON.toJSONString(result)); |
|
|
|
printWriter.close(); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("export exception", e); |
|
|
|
} finally { |
|
|
|
if (excelWriter != null) { |
|
|
|
excelWriter.finish(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|