From 002cc7ec376b52b0dad5337a37bba0f8e8b13b02 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Mon, 5 Aug 2024 21:15:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B7=A5=E5=85=B7=E9=A2=86=E7=94=A8?= =?UTF-8?q?=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 --- .../com/hnac/hzims/spare/vo/WtSpToolBasicVO.java | 14 ++++ .../spare/controller/WtSpBasicController.java | 8 ++ .../spare/controller/WtSpToolBasicController.java | 7 ++ .../com/hnac/hzims/spare/dto/WtSpBasicDto.java | 32 ++++++++ .../hzims/spare/mapper/WtSpToolBasicMapper.java | 1 + .../hzims/spare/service/IWtSpBasicService.java | 3 + .../hzims/spare/service/IWtSpToolBasicService.java | 3 + .../spare/service/impl/SpReceiveServiceImpl.java | 15 +--- .../spare/service/impl/WtSpBasicServiceImpl.java | 70 +++++++++++++++- .../service/impl/WtSpToolBasicServiceImpl.java | 93 +++++++++++++++++++++- .../com/hnac/hzims/spare/vo/WtSpBasicExportVO.java | 36 +++++++++ .../hnac/hzims/spare/vo/WtSpToolBasicExportVO.java | 83 +++++++++++++++++++ 12 files changed, 346 insertions(+), 19 deletions(-) create mode 100644 hzims-service/assets/src/main/java/com/hnac/hzims/spare/dto/WtSpBasicDto.java create mode 100644 hzims-service/assets/src/main/java/com/hnac/hzims/spare/vo/WtSpBasicExportVO.java create mode 100644 hzims-service/assets/src/main/java/com/hnac/hzims/spare/vo/WtSpToolBasicExportVO.java diff --git a/hzims-service-api/assets-api/src/main/java/com/hnac/hzims/spare/vo/WtSpToolBasicVO.java b/hzims-service-api/assets-api/src/main/java/com/hnac/hzims/spare/vo/WtSpToolBasicVO.java index 1239f0b..c9f065d 100644 --- a/hzims-service-api/assets-api/src/main/java/com/hnac/hzims/spare/vo/WtSpToolBasicVO.java +++ b/hzims-service-api/assets-api/src/main/java/com/hnac/hzims/spare/vo/WtSpToolBasicVO.java @@ -1,5 +1,6 @@ package com.hnac.hzims.spare.vo; +import com.alibaba.excel.annotation.ExcelProperty; import com.hnac.hzims.spare.entity.WtSpToolBasicEntity; import com.hnac.hzims.spare.vo.WtSpBasicVO; import io.swagger.annotations.ApiModelProperty; @@ -19,47 +20,60 @@ public class WtSpToolBasicVO extends WtSpToolBasicEntity { * 名称 */ @ApiModelProperty(value = "名称") + @ExcelProperty(value = "工具名称",index = 1) private String name; /** * 编码 */ @ApiModelProperty(value = "编码") + @ExcelProperty(value = "工具台账",index = 0) private String code; /** * 规格 */ @ApiModelProperty(value = "规格") + @ExcelProperty(value = "规格/型号",index = 2) private String specifications; /** * 单位 */ @ApiModelProperty(value = "单位") + @ExcelProperty(value = "单位",index = 3) private String unit; /** * 总数量 */ @ApiModelProperty(value = "总数量") + @ExcelProperty(value = "总数量",index = 4) private Long totalAmount; /** * 在库数量 */ @ApiModelProperty(value = "在库数量") + @ExcelProperty(value = "在库数量",index = 5) private Integer notUseAmount; /** * 已领数量 */ @ApiModelProperty(value = "已领数量") + @ExcelProperty(value = "已领数量",index = 6) private Integer useAmount; /** * 所属仓库 */ @ApiModelProperty(value = "所属仓库") + @ExcelProperty(value = "仓库",index = 9) private String warehouseName; /** * 入库人 */ @ApiModelProperty(value = "入库人") + @ExcelProperty(value = "领用人",index = 8) private String userName; + + @ApiModelProperty(value = "最近领用时间") + @ExcelProperty(value = "最近领用时间",index = 7) + private String lastNeckTime; /** * 单位名称 */ diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/controller/WtSpBasicController.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/controller/WtSpBasicController.java index a796a88..839a5d5 100644 --- a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/controller/WtSpBasicController.java +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/controller/WtSpBasicController.java @@ -7,6 +7,7 @@ import com.hnac.hzims.AssetsConstants; import com.hnac.hzims.common.logs.annotation.OperationAnnotation; import com.hnac.hzims.common.logs.enums.BusinessType; import com.hnac.hzims.common.logs.enums.OperatorType; +import com.hnac.hzims.spare.dto.WtSpBasicDto; import com.hnac.hzims.spare.entity.SpTemporaryStockDetailEntity; import com.hnac.hzims.spare.entity.SpTemporaryStockEntity; import com.hnac.hzims.spare.entity.WtSpBasicEntity; @@ -117,6 +118,13 @@ public class WtSpBasicController extends BladeController { return R.data(pages); } + @GetMapping("/export") + @ApiOperationSupport(order = 3) + @ApiOperation(value = "导出工具台账", notes = "传入SP_BASIC") + public void export(WtSpBasicDto request, HttpServletResponse response) { + SP_BASICService.export(request,response); + } + @GetMapping("/getlist") @ApiImplicitParams({ @ApiImplicitParam(name = "code", value = "编码", paramType = "query", dataType = "string"), diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/controller/WtSpToolBasicController.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/controller/WtSpToolBasicController.java index 4a339e3..9a3b2fe 100644 --- a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/controller/WtSpToolBasicController.java +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/controller/WtSpToolBasicController.java @@ -24,6 +24,7 @@ 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; import java.util.List; @@ -82,6 +83,12 @@ public class WtSpToolBasicController extends BladeController { return R.data(pages); } + @GetMapping("/exportWtSpToolBasic") + @ApiOperationSupport(order = 2) + @ApiOperation(value = "导出工具台账", notes = "传入toolBasicEntity") + public void exportWtSpToolBasic(WtSpToolBasicVO toolBasicVO, HttpServletResponse response) { + SP_TOOL_BASICService.exportWtSpToolBasic(toolBasicVO,response); + } /** * 新增 代码自定义代号 */ diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/dto/WtSpBasicDto.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/dto/WtSpBasicDto.java new file mode 100644 index 0000000..d869e59 --- /dev/null +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/dto/WtSpBasicDto.java @@ -0,0 +1,32 @@ +package com.hnac.hzims.spare.dto; + +import com.hnac.hzinfo.api.annotation.ApiInterface; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/08/05 18:48 + */ +@Data +@ApiModel(value = "工具台账查询DTO",description = "工具台账查询DTO") +@EqualsAndHashCode +public class WtSpBasicDto implements Serializable { + + @ApiModelProperty(value = "仓库ID") + private Long warehouseId; + + @ApiModelProperty(value = "工具名称") + private String nameQuery; + + @ApiModelProperty(value = "制单时间查询开始时间") + private String startDate; + + @ApiModelProperty(value = "制单时间查询结束时间") + private String endDate; + +} diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/mapper/WtSpToolBasicMapper.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/mapper/WtSpToolBasicMapper.java index 716d4a5..0cca6b0 100644 --- a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/mapper/WtSpToolBasicMapper.java +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/mapper/WtSpToolBasicMapper.java @@ -26,4 +26,5 @@ public interface WtSpToolBasicMapper extends UserDataScopeBaseMapper selectPageList(IPage page,@Param(value = "params") Map params); + } diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/IWtSpBasicService.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/IWtSpBasicService.java index ac9faaf..6e70960 100644 --- a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/IWtSpBasicService.java +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/IWtSpBasicService.java @@ -2,6 +2,7 @@ package com.hnac.hzims.spare.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; +import com.hnac.hzims.spare.dto.WtSpBasicDto; import com.hnac.hzims.spare.entity.SpTemporaryStockDetailEntity; import com.hnac.hzims.spare.entity.SpTemporaryStockEntity; import com.hnac.hzims.spare.entity.WtSpBasicEntity; @@ -29,6 +30,8 @@ public interface IWtSpBasicService extends IService { * @return */ IPage selectPage(WtSpBasicEntity SP_BASIC, Query query, Long warehouseId, String sign); + + void export(WtSpBasicDto request,HttpServletResponse response); /** * 根据备件id和库存id查询备件已使用总数量 * @param params diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/IWtSpToolBasicService.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/IWtSpToolBasicService.java index be1f326..3e5367c 100644 --- a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/IWtSpToolBasicService.java +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/IWtSpToolBasicService.java @@ -7,6 +7,7 @@ import com.hnac.hzims.spare.vo.WtSpToolBasicVO; import org.springblade.core.mp.support.Query; +import javax.servlet.http.HttpServletResponse; import java.util.List; /** @@ -36,4 +37,6 @@ public interface IWtSpToolBasicService extends IService { * @return */ IPage selectPageList(IPage page, WtSpToolBasicVO toolBasicVO) ; + + void exportWtSpToolBasic(WtSpToolBasicVO toolBasicVO, HttpServletResponse response); } diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/SpReceiveServiceImpl.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/SpReceiveServiceImpl.java index b3afb96..a013be4 100644 --- a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/SpReceiveServiceImpl.java +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/SpReceiveServiceImpl.java @@ -27,6 +27,7 @@ import org.springblade.core.tool.utils.Func; import org.springblade.system.entity.Dept; import org.springblade.system.feign.IDictBizClient; import org.springblade.system.feign.ISysClient; +import org.springblade.system.user.cache.UserCache; import org.springblade.system.user.entity.User; import org.springblade.system.user.feign.IUserClient; import org.springframework.stereotype.Service; @@ -34,10 +35,7 @@ import org.springframework.transaction.annotation.Transactional; 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.*; /** * 服务实现类 @@ -170,13 +168,8 @@ public class SpReceiveServiceImpl extends ServiceImpl user = userClient.userInfoById(detail.getCreateUser()); - if(null!=user){ - receiveVO.setUserName(user.getData().getName()); - } - } + String userName = Optional.ofNullable(detail.getCreateUser()).map(UserCache::getUser).map(User::getName).orElse(null); + receiveVO.setUserName(userName); List basicList = spRecordMapper.selectByBusinessId(detail.getId()); List basicVOList = new ArrayList<>(); for (int i = 0; i < basicList.size(); i++) { diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/WtSpBasicServiceImpl.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/WtSpBasicServiceImpl.java index b605167..a04a7b1 100644 --- a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/WtSpBasicServiceImpl.java +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/WtSpBasicServiceImpl.java @@ -1,10 +1,13 @@ package com.hnac.hzims.spare.service.impl; +import ch.qos.logback.classic.jmx.MBeanUtil; import cn.afterturn.easypoi.excel.entity.ImportParams; 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.metadata.style.WriteCellStyle; +import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; @@ -16,6 +19,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.equipment.feign.IEmInfoClient; +import com.hnac.hzims.operational.maintenance.vo.MaintenanceTaskQueryVO; +import com.hnac.hzims.spare.dto.WtSpBasicDto; import com.hnac.hzims.spare.entity.*; import com.hnac.hzims.spare.enume.WarehouseInType; import com.hnac.hzims.spare.enume.WarehouseOutType; @@ -32,15 +37,20 @@ import com.hnac.hzims.spare.utils.SheetWriteStyleHandler; import com.hnac.hzims.spare.vo.SparePartVO; import com.hnac.hzims.spare.vo.WtSpBasicVO; import com.hnac.hzims.ticket.allTicket.fegin.ITicketInfoAllClient; +import com.hnac.hzinfo.exception.HzServiceException; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.poi.ss.usermodel.BorderStyle; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; import org.springblade.core.secure.utils.AuthUtil; +import org.springblade.core.tool.api.IResultCode; import org.springblade.core.tool.api.R; +import org.springblade.core.tool.api.ResultCode; +import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.ObjectUtil; @@ -55,10 +65,7 @@ import org.springframework.util.CollectionUtils; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.net.URLEncoder; import java.util.*; import java.util.stream.Collectors; @@ -259,6 +266,61 @@ public class WtSpBasicServiceImpl extends ServiceImpl basicWrapper = Wrappers.lambdaQuery() + .like(StringUtils.isNotEmpty(request.getNameQuery()),WtSpBasicEntity::getName, request.getNameQuery()); + List wtBasicList = this.list(basicWrapper); + Assert.isTrue(CollectionUtil.isNotEmpty(wtBasicList),() -> { + throw new HzServiceException(ResultCode.FAILURE,"暂无数据!"); + }); + List basicVOList = wtBasicList.stream().map(b -> this.getBasicVO(b, request.getWarehouseId())).collect(Collectors.toList()); + String fileName; + try { + fileName = URLEncoder.encode("工具台账报表", "UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding("UTF-8"); + WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); + contentWriteCellStyle.setBorderLeft(BorderStyle.THIN); + contentWriteCellStyle.setBorderTop(BorderStyle.THIN); + contentWriteCellStyle.setBorderRight(BorderStyle.THIN); + contentWriteCellStyle.setBorderBottom(BorderStyle.THIN); + contentWriteCellStyle.setWrapped(true); + try { + EasyExcel.write(response.getOutputStream(), WtSpBasicVO.class) + .registerWriteHandler(new HorizontalCellStyleStrategy(new WriteCellStyle(), contentWriteCellStyle)) + .autoCloseStream(Boolean.FALSE).sheet("工具台账") + .doWrite(basicVOList); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private WtSpBasicVO getBasicVO(WtSpBasicEntity basicEntity,Long warehouseId) { + WtSpBasicVO basicVO = BeanUtil.copy(basicEntity,WtSpBasicVO.class); + if(Func.isEmpty(warehouseId)) { + WtSpManagementEntity managementEntity = managementMapper.selectById(basicEntity.getManagementId()); + basicVO.setSparePartsName(Optional.ofNullable(managementEntity).map(WtSpManagementEntity::getName).orElse(null)); + List totalList = totalService.list(Wrappers.query().lambda().eq(WtSpTotalEntity::getSpBasicId, basicEntity.getId())); + basicVO.setStock(CollectionUtil.isNotEmpty(totalList) ? totalList.get(0).getStock() : 0L); + } else { + WtSpManagementEntity managementEntity = managementMapper.selectById(basicEntity.getManagementId()); + basicVO.setSparePartsName(Optional.ofNullable(managementEntity).map(WtSpManagementEntity::getName).orElse(null)); + LambdaQueryWrapper totalWrapper = Wrappers.lambdaQuery() + .eq(Func.isNotEmpty(basicEntity.getId()), WtSpTotalEntity::getSpBasicId, basicEntity.getId()) + .eq(WtSpTotalEntity::getWarehouseId, warehouseId); + if(CollectionUtil.isNotEmpty(totalMapper.selectList(totalWrapper))) { + List totalList = totalService.list(Wrappers.query().lambda().eq(WtSpTotalEntity::getSpBasicId, basicEntity.getId())); + basicVO.setStock(CollectionUtil.isNotEmpty(totalList) ? totalList.get(0).getStock() : 0L); + } + } + return basicVO; + } + + @Override public Integer selectTotal(Map params) { return baseMapper.selectTotal(params); } diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/WtSpToolBasicServiceImpl.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/WtSpToolBasicServiceImpl.java index 099a784..fa80c32 100644 --- a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/WtSpToolBasicServiceImpl.java +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/WtSpToolBasicServiceImpl.java @@ -1,5 +1,8 @@ package com.hnac.hzims.spare.service.impl; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.write.metadata.style.WriteCellStyle; +import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -8,22 +11,29 @@ import com.hnac.hzims.spare.enume.BusinessType; import com.hnac.hzims.spare.mapper.*; import com.hnac.hzims.spare.service.IWtSpBasicService; import com.hnac.hzims.spare.service.IWtSpToolBasicService; +import com.hnac.hzims.spare.vo.WtSpBasicVO; +import com.hnac.hzims.spare.vo.WtSpToolBasicExportVO; import com.hnac.hzims.spare.vo.WtSpToolBasicVO; import lombok.AllArgsConstructor; +import org.apache.poi.ss.usermodel.BorderStyle; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.BeanUtil; +import org.springblade.core.tool.utils.DateUtil; import org.springblade.system.entity.Dept; import org.springblade.system.feign.ISysClient; +import org.springblade.system.user.cache.UserCache; import org.springblade.system.user.entity.User; import org.springblade.system.user.feign.IUserClient; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.*; /** * 服务实现类 @@ -160,4 +170,79 @@ public class WtSpToolBasicServiceImpl extends ServiceImpl params = new HashMap<>(); + if(null !=toolBasicVO.getCode()){ + params.put("code",toolBasicVO.getCode()); + } + if(null !=toolBasicVO.getNameQuery()){ + params.put("name",toolBasicVO.getNameQuery()); + } + if(null !=toolBasicVO.getStartDate()){ + params.put("startDate",toolBasicVO.getStartDate()); + } + if(null !=toolBasicVO.getEndDate()){ + params.put("endDate",toolBasicVO.getEndDate()); + } + List longList = new ArrayList<>(); + if(null!=toolBasicVO.getDeptId()){ + R> deptList = sysClient.getDeptChild(toolBasicVO.getDeptId()); + for (int i = 0; i < deptList.getData().size(); i++) { + longList.add(deptList.getData().get(i).getId()); + } + longList.add(toolBasicVO.getDeptId()); + } + if(!longList.isEmpty()){ + params.put("deptList",longList); + } + if(null!=toolBasicVO.getWarehouseId()){ + params.put("warehouseId",toolBasicVO.getWarehouseId()); + } + params.put("tenantId", AuthUtil.getTenantId()); + List list = baseMapper.selectPageList(null,params); + List result = new ArrayList<>(); + for (int i = 0; i < list.size(); i++) { + WtSpToolBasicVO wtSpToolBasicVO = list.get(i); + WtSpToolBasicExportVO exportVO = BeanUtil.copy(list.get(i), WtSpToolBasicExportVO.class); + String userName = Optional.ofNullable(wtSpToolBasicVO.getCreateUser()).map(UserCache::getUser).map(User::getName).orElse(null); + exportVO.setUserName(userName); + Map map = new HashMap<>(); + map.put("spBasicId",wtSpToolBasicVO.getSpBasicId()); + map.put("warehouseId",wtSpToolBasicVO.getWarehouseId()); + Integer res = spBasicService.selectTotal(map); + wtSpToolBasicVO.setUseAmount(res); + WtSpTotalEntity spTotalEntity = spTotalMapper.selectByBasicId(map); + Long stock = Optional.ofNullable(spTotalEntity).map(WtSpTotalEntity::getStock).orElse(0L); + Long amount = Optional.ofNullable(wtSpToolBasicVO).map(WtSpToolBasicVO::getUseAmount).map(Long::valueOf).orElse(0L); + exportVO.setTotalAmount(stock + amount); + exportVO.setNotUseAmount(Optional.ofNullable(spTotalEntity).map(WtSpTotalEntity::getStock).map(s -> s.intValue()).orElse(0)); + exportVO.setLastNeckTime(DateUtil.format(wtSpToolBasicVO.getCreateTime(),DateUtil.PATTERN_DATETIME)); + result.add(exportVO); + } + String fileName; + try { + fileName = URLEncoder.encode("工具台账报表", "UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding("UTF-8"); + WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); + contentWriteCellStyle.setBorderLeft(BorderStyle.THIN); + contentWriteCellStyle.setBorderTop(BorderStyle.THIN); + contentWriteCellStyle.setBorderRight(BorderStyle.THIN); + contentWriteCellStyle.setBorderBottom(BorderStyle.THIN); + contentWriteCellStyle.setWrapped(true); + try { + EasyExcel.write(response.getOutputStream(), WtSpToolBasicExportVO.class) + .registerWriteHandler(new HorizontalCellStyleStrategy(new WriteCellStyle(), contentWriteCellStyle)) + .autoCloseStream(Boolean.FALSE).sheet("工具台账") + .doWrite(result); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/vo/WtSpBasicExportVO.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/vo/WtSpBasicExportVO.java new file mode 100644 index 0000000..e0b379b --- /dev/null +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/vo/WtSpBasicExportVO.java @@ -0,0 +1,36 @@ +package com.hnac.hzims.spare.vo; + +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/08/05 19:44 + */ +@Data +@EqualsAndHashCode +public class WtSpBasicExportVO implements Serializable { + + @ExcelProperty(value = "物品编码",index = 0) + @ApiModelProperty(value = "编码") + private String code; + + @ExcelProperty(value = "工具名称",index = 1 ) + @ApiModelProperty(value = "名称") + private String name; + + @ExcelProperty(value = "规格/型号",index = 2 ) + @ApiModelProperty(value = "规格") + private String specifications; + + @ExcelProperty(value = "单位",index = 3) + @ApiModelProperty(value = "单位") + private String unit; + + + +} diff --git a/hzims-service/assets/src/main/java/com/hnac/hzims/spare/vo/WtSpToolBasicExportVO.java b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/vo/WtSpToolBasicExportVO.java new file mode 100644 index 0000000..2dc0c0d --- /dev/null +++ b/hzims-service/assets/src/main/java/com/hnac/hzims/spare/vo/WtSpToolBasicExportVO.java @@ -0,0 +1,83 @@ +package com.hnac.hzims.spare.vo; + +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/08/05 20:50 + */ +@Data +@EqualsAndHashCode +public class WtSpToolBasicExportVO implements Serializable { + /** + * 名称 + */ + @ApiModelProperty(value = "名称") + @ExcelProperty(value = "工具名称",index = 1) + @ColumnWidth(15) + private String name; + /** + * 编码 + */ + @ApiModelProperty(value = "编码") + @ExcelProperty(value = "工具台账",index = 0) + @ColumnWidth(15) + private String code; + /** + * 规格 + */ + @ApiModelProperty(value = "规格") + @ExcelProperty(value = "规格/型号",index = 2) + @ColumnWidth(20) + private String specifications; + /** + * 单位 + */ + @ApiModelProperty(value = "单位") + @ExcelProperty(value = "单位",index = 3) + private String unit; + /** + * 总数量 + */ + @ApiModelProperty(value = "总数量") + @ExcelProperty(value = "总数量",index = 4) + private Long totalAmount; + /** + * 在库数量 + */ + @ApiModelProperty(value = "在库数量") + @ExcelProperty(value = "在库数量",index = 5) + @ColumnWidth(15) + private Integer notUseAmount; + /** + * 已领数量 + */ + @ApiModelProperty(value = "已领数量") + @ColumnWidth(15) + @ExcelProperty(value = "已领数量",index = 6) + private Integer useAmount; + /** + * 所属仓库 + */ + @ApiModelProperty(value = "所属仓库") + @ExcelProperty(value = "仓库",index = 9) + @ColumnWidth(15) + private String warehouseName; + /** + * 入库人 + */ + @ApiModelProperty(value = "入库人") + @ExcelProperty(value = "领用人",index = 8) + private String userName; + + @ApiModelProperty(value = "最近领用时间") + @ExcelProperty(value = "最近领用时间",index = 7) + @ColumnWidth(20) + private String lastNeckTime; +}