From edfd1006d0fee2f3f52cf1c92ef6a9bb5648508c Mon Sep 17 00:00:00 2001 From: liwen Date: Mon, 5 Aug 2024 21:12:07 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E6=96=B0=E5=A2=9E=E5=85=A5=E5=BA=93?= =?UTF-8?q?=E5=8D=95=E5=AF=BC=E5=87=BA=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hnac/hzims/spare/vo/SpWarehouseInExportVO.java | 42 ++++++++ .../com/hnac/hzims/spare/vo/SpWarehouseInVO.java | 1 + .../spare/controller/SpWarehouseInController.java | 10 +- .../hzims/spare/service/ISpWarehouseInService.java | 9 ++ .../service/impl/SpWarehouseInServiceImpl.java | 112 ++++++++++++++++++++- 5 files changed, 172 insertions(+), 2 deletions(-) create mode 100644 hzims-service-api/assets-api/src/main/java/com/hnac/hzims/spare/vo/SpWarehouseInExportVO.java diff --git a/hzims-service-api/assets-api/src/main/java/com/hnac/hzims/spare/vo/SpWarehouseInExportVO.java b/hzims-service-api/assets-api/src/main/java/com/hnac/hzims/spare/vo/SpWarehouseInExportVO.java new file mode 100644 index 0000000..0521643 --- /dev/null +++ b/hzims-service-api/assets-api/src/main/java/com/hnac/hzims/spare/vo/SpWarehouseInExportVO.java @@ -0,0 +1,42 @@ +package com.hnac.hzims.spare.vo; + +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + +/** + * 入库单导出VO类 + * + * @author liwen + */ +@Data +@ExcelIgnoreUnannotated +public class SpWarehouseInExportVO { + + @ExcelProperty(value = "单据号", index = 0) + @ApiModelProperty(value = "单据号") + private String code; + + @ExcelProperty(value = "仓库名称", index = 1) + @ApiModelProperty(value = "仓库名称") + private String warehouseName; + + @ApiModelProperty(value = "入库类型") + private Long type; + + @ExcelProperty(value = "入库类型名", index = 2) + @ApiModelProperty(value = "入库类型名") + private String typeName; + + + @ExcelProperty(value = "入库人", index = 3) + @ApiModelProperty(value = "入库人") + private String userName; + + @ExcelProperty(value = "创建时间", index = 4) + @ApiModelProperty(value = "创建时间") + private Date createTime; +} diff --git a/hzims-service-api/assets-api/src/main/java/com/hnac/hzims/spare/vo/SpWarehouseInVO.java b/hzims-service-api/assets-api/src/main/java/com/hnac/hzims/spare/vo/SpWarehouseInVO.java index 721b99e..6d0b9ed 100644 --- a/hzims-service-api/assets-api/src/main/java/com/hnac/hzims/spare/vo/SpWarehouseInVO.java +++ b/hzims-service-api/assets-api/src/main/java/com/hnac/hzims/spare/vo/SpWarehouseInVO.java @@ -46,6 +46,7 @@ public class SpWarehouseInVO extends SpWarehouseInEntity { @ApiModelProperty(value = "结束时间") private String endDate; + /** * 备品备件列表 */ diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/controller/SpWarehouseInController.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/controller/SpWarehouseInController.java index f25ec10..2c94f4c 100644 --- a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/controller/SpWarehouseInController.java +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/controller/SpWarehouseInController.java @@ -24,9 +24,9 @@ import org.springblade.core.tool.utils.Func; import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; +import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; - /** * 控制器 * @@ -126,6 +126,14 @@ public class SpWarehouseInController extends BladeController { return R.status(sp_warehouse_inService.removeBatchByIds(Func.toLongList(ids))); } + @GetMapping("/exportSpWarehouseData") + @ApiOperationSupport(order = 8) + @ApiOperation(value = "入库单导出") + @Operate(label = "入库单导出", type = com.hnac.hzinfo.log.contants.BusinessType.EXPORT) + public void exportSpWarehouseData(SpWarehouseInVO warehouseInVO, HttpServletResponse response) { + sp_warehouse_inService.exportSpWarehouseData(warehouseInVO, response); + } + /** * 完成流程 修改状态 */ diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/ISpWarehouseInService.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/ISpWarehouseInService.java index d770930..c98ecb4 100644 --- a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/ISpWarehouseInService.java +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/ISpWarehouseInService.java @@ -7,6 +7,8 @@ import com.hnac.hzims.spare.vo.SpWarehouseInVO; import org.springblade.core.mp.support.Query; +import javax.servlet.http.HttpServletResponse; + /** * 服务类 * @@ -34,6 +36,13 @@ public interface ISpWarehouseInService extends IService { * @return */ IPage selectPageList(IPage page, SpWarehouseInVO warehouseInVO) ; + + /** + * 入库单导出 + * @param warehouseInVO + * @param response + */ + void exportSpWarehouseData(SpWarehouseInVO warehouseInVO, HttpServletResponse response); /** *完成流程 * @param flow diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/SpWarehouseInServiceImpl.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/SpWarehouseInServiceImpl.java index 53a3cdf..c065580 100644 --- a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/SpWarehouseInServiceImpl.java +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/SpWarehouseInServiceImpl.java @@ -1,5 +1,10 @@ package com.hnac.hzims.spare.service.impl; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.converters.longconverter.LongStringConverter; +import com.alibaba.excel.write.metadata.WriteSheet; +import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -12,6 +17,7 @@ import com.hnac.hzims.spare.mapper.SpRecordMapper; import com.hnac.hzims.spare.mapper.SpWarehouseInMapper; import com.hnac.hzims.spare.mapper.WtSpWarehouseMapper; import com.hnac.hzims.spare.service.*; +import com.hnac.hzims.spare.vo.SpWarehouseInExportVO; import com.hnac.hzims.spare.vo.SpWarehouseInVO; import com.hnac.hzims.spare.vo.WtSpBasicVO; import com.hnac.hzims.spare.vo.WtSpManagementVO; @@ -28,16 +34,20 @@ import org.springblade.system.feign.IDictBizClient; import org.springblade.system.feign.ISysClient; import org.springblade.system.user.entity.User; import org.springblade.system.user.feign.IUserClient; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.net.URLEncoder; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; /** * 服务实现类 @@ -251,6 +261,106 @@ public class SpWarehouseInServiceImpl extends ServiceImpl params = new HashMap<>(); + if (null !=warehouseInVO.getCode()) { + params.put("code",warehouseInVO.getCode()); + } + if (null !=warehouseInVO.getType()) { + params.put("type",warehouseInVO.getType()); + } + if (null !=warehouseInVO.getStatus()) { + params.put("status",warehouseInVO.getStatus()); + } + if (null !=warehouseInVO.getStartDate()) { + params.put("startDate",warehouseInVO.getStartDate()); + } + if (null !=warehouseInVO.getEndDate()) { + params.put("endDate",warehouseInVO.getEndDate()); + } + List longList = new ArrayList<>(); + if (null!=warehouseInVO.getDeptId()) { + R> deptList = sysClient.getDeptChild(warehouseInVO.getDeptId()); + for (int i = 0; i < deptList.getData().size(); i++) { + longList.add(deptList.getData().get(i).getId()); + } + longList.add(warehouseInVO.getDeptId()); + } + if (longList.size()>0) { + params.put("deptList",longList); + } + if (null!=warehouseInVO.getStorageRoom()) { + params.put("warehouseId",warehouseInVO.getStorageRoom()); + } + params.put("tenantId", AuthUtil.getTenantId()); + IPage page = new Page<>(); + List warehouseInPage = baseMapper.selectPageList(page, params); + // 导入列表 + List warehouseInExportList = new ArrayList<>(); + // 数据处理 + warehouseInPage.forEach(warehouse -> { + SpWarehouseInExportVO exportVO = new SpWarehouseInExportVO(); + BeanUtils.copyProperties(warehouse, exportVO); + int type = warehouse.getType().intValue(); + // 入库类型 + String typeName; + if (type == WarehouseInType.BUY.getType()) { + typeName = WarehouseInType.BUY.getName(); + } else if (type == WarehouseInType.BACK.getType()) { + typeName = WarehouseInType.BACK.getName(); + } else if (type == WarehouseInType.ALLOT.getType()) { + typeName = WarehouseInType.ALLOT.getName(); + } else { + typeName = WarehouseInType.OLD.getName(); + } + warehouse.setTypeName(typeName); + // 时间格式 +// warehouse.setStartTime(DateUtil.format(plan.getScheduledStartTime(), DateUtil.PATTERN_DATE)); +// warehouse.setEndTime(DateUtil.format(plan.getScheduledEndTime(), DateUtil.PATTERN_DATE)); + }); + // 设置响应头 + // URLEncoder.encode防止中文乱码 + String fileName = URLEncoder.encode("入库单", "UTF-8"); + response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding("UTF-8"); + // ExcelWriter初始化 + ExcelWriter excelWriter = EasyExcel + .write(response.getOutputStream()) + .autoCloseStream(Boolean.TRUE) + .registerConverter(new LongStringConverter()) + .registerWriteHandler(new SimpleColumnWidthStyleStrategy(25)) + .build(); + WriteSheet writeSheet = EasyExcel.writerSheet(1, "入库单").head(SpWarehouseInExportVO.class) + .build(); + excelWriter.write(warehouseInExportList, writeSheet); + excelWriter.finish(); + } catch (Exception e) { + // 重置response + response.reset(); + response.setContentType("application/json"); + response.setCharacterEncoding("utf-8"); + throw new ServiceException("入库单数据导出异常: " + e.getMessage()); + } finally { + if (outputStream != null) { + try { + outputStream.close(); + } catch (IOException e) { + log.error("入库单数据导出输出流关闭异常: " + e.getMessage()); + } + } + } + } + + + // @Override // public boolean completeTask(BladeFlow flow) { // ComleteTask task = new ComleteTask();