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-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/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/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/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/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/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(); 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; +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarServiceImpl.java index 90fadf4..33117de 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarServiceImpl.java @@ -29,10 +29,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.math.BigDecimal; import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; /** @@ -254,7 +251,11 @@ public class CarServiceImpl extends ServiceImpl implements .registerConverter(new LongStringConverter()) .registerWriteHandler(new SimpleColumnWidthStyleStrategy(25)) .build(); + // 排除时间字段 + Set excludeSets = new HashSet<>(); + excludeSets.add("createTime"); WriteSheet writeSheet = EasyExcel.writerSheet(1, "年度里程统计表").head(CarMilesYearVO.class) + .excludeColumnFieldNames(excludeSets) .build(); excelWriter.write(list, writeSheet); excelWriter.finish();