package com.chinaztt.mes.warehouse.controller; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelWriter; import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.chinaztt.mes.common.wrapper.QueryWrapperUtil; import com.chinaztt.mes.warehouse.dto.EscortDTO; import com.chinaztt.mes.warehouse.dto.EscortDetailDTO; import com.chinaztt.mes.warehouse.entity.Escort; import com.chinaztt.mes.warehouse.excel.EscortDetailData; import com.chinaztt.mes.warehouse.service.EscortService; import com.chinaztt.ztt.common.core.util.R; import com.chinaztt.ztt.common.log.annotation.SysLog; import com.chinaztt.ztt.common.security.annotation.Inner; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.net.URLEncoder; import java.util.List; /** * 押运单主表 * * @author cxf * @date 2021-07-23 14:32:00 */ @RestController @AllArgsConstructor @RequestMapping("/escort") @Api(value = "escort", tags = "押运单主表管理") public class EscortController { private final EscortService escortService; /** * 导出 * * @param escortDetailDTO 发货完成的记录 * @return */ @ApiOperation(value = "导出", notes = "导出") @Inner(false) @GetMapping("/exportSendBackRecord") public void exportSendBackRecord(HttpServletResponse response, EscortDetailDTO escortDetailDTO) throws IOException { response.setContentType("application/vnd.ms-excel"); response.setCharacterEncoding("UTF-8"); // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 String fileName = URLEncoder.encode("发货记录", "UTF-8"); response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); try { //新建ExcelWriter ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).build(); //获取sheet0对象 WriteSheet mainSheet = EasyExcel.writerSheet(0, "发货记录").head(EscortDetailData.class).build(); //向sheet0写入数据 传入空list这样只导出表头 excelWriter.write(escortService.exportList(QueryWrapperUtil.gen(escortDetailDTO)), mainSheet); //关闭流 excelWriter.finish(); } catch (IOException e) { throw new RuntimeException("导出失败"); } } /** * 分页查询 * * @param page 分页对象 * @param escort 押运单主表 * @return */ @ApiOperation(value = "分页查询", notes = "分页查询") @GetMapping("/page") public R getEscortPage(Page page, EscortDTO escort) { return R.ok(escortService.page(page, QueryWrapperUtil.gen(escort))); } /** * 通过id查询押运单主表 * * @param id id * @return R */ @ApiOperation(value = "通过id查询", notes = "通过id查询") @GetMapping("/{id}") public R getById(@PathVariable("id") Long id) { return R.ok(escortService.getById(id)); } /** * 新增押运单主表 * * @param escort 押运单主表 * @return R */ @ApiOperation(value = "新增押运单主表", notes = "新增押运单主表") @SysLog("新增押运单主表") @PostMapping public R save(@RequestBody EscortDTO escort) { return R.ok(escortService.saveDto(escort)); } /** * 修改押运单主表 * * @param escort 押运单主表 * @return R */ @ApiOperation(value = "修改押运单主表", notes = "修改押运单主表") @SysLog("修改押运单主表") @PutMapping public R updateById(@RequestBody EscortDTO escort) { return R.ok(escortService.updateDtoById(escort)); } /** * 完成、取消 * * @param event * @param escortList * @return */ @ApiOperation(value = "更改状态", notes = "更改状态") @SysLog("更改状态") @PostMapping("/changeState/{event}") public R changeState(@PathVariable String event, @RequestBody List escortList) { return escortService.changeState(escortList, event); } /** * 通过id删除押运单主表 * * @param id id * @return R */ @ApiOperation(value = "通过id删除押运单主表", notes = "通过id删除押运单主表") @SysLog("通过id删除押运单主表") @DeleteMapping("/{id}") public R removeById(@PathVariable Long id) { return R.ok(escortService.delById(id)); } /** * 通过id删除押运单主表 * * @param ids 明细id * @return R */ @ApiOperation(value = "通过id删除押运单子表", notes = "通过id删除押运单子表") @SysLog("通过id删除押运单子表") @PostMapping("/delDetails") public R removeById(@RequestBody List ids) { return R.ok(escortService.delDetailsByIds(ids)); } /** * 根据客户订单id获取押运单的信息 * * @param customerOrderIds 客户订单ids * @return R */ @ApiOperation(value = "根据客户订单id获取押运单的信息", notes = "根据客户订单id获取押运单的信息") @SysLog("根据客户订单id获取押运单的信息") @PostMapping("/getEscortInfoByOrder") public R getEscortInfoByOrder(@RequestBody List customerOrderIds) { return R.ok(escortService.getEscortInfoByOrder(customerOrderIds)); } /** * 查询所有明细 * * @param escortDetail 押运单明细 * @return */ @ApiOperation(value = "查询所有明细", notes = "查询所有明细") @GetMapping("/detail/list") public R getEscortDetailList(EscortDetailDTO escortDetail) { return R.ok(escortService.getEscortDetailList(QueryWrapperUtil.gen(escortDetail))); } /** * 退货查询所有已完成的押运单明细 * * @param escortDetail 退货查询所有已完成的押运单明细 * @return */ @ApiOperation(value = "退货查询所有已完成的押运单明细", notes = "退货查询所有已完成的押运单明细") @GetMapping("/escortDetail/list") public R getEscortDetailListComplete(Page page, EscortDetailDTO escortDetail) { return R.ok(escortService.getEscortDetailListComplete(page, QueryWrapperUtil.gen(escortDetail))); } }