Browse Source

fix: 工具领用导出接口

zhongwei
haungxing 4 months ago
parent
commit
002cc7ec37
  1. 14
      hzims-service-api/assets-api/src/main/java/com/hnac/hzims/spare/vo/WtSpToolBasicVO.java
  2. 8
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/controller/WtSpBasicController.java
  3. 7
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/controller/WtSpToolBasicController.java
  4. 32
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/dto/WtSpBasicDto.java
  5. 1
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/mapper/WtSpToolBasicMapper.java
  6. 3
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/IWtSpBasicService.java
  7. 3
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/IWtSpToolBasicService.java
  8. 15
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/SpReceiveServiceImpl.java
  9. 70
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/WtSpBasicServiceImpl.java
  10. 93
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/WtSpToolBasicServiceImpl.java
  11. 36
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/vo/WtSpBasicExportVO.java
  12. 83
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/vo/WtSpToolBasicExportVO.java

14
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; package com.hnac.hzims.spare.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.hnac.hzims.spare.entity.WtSpToolBasicEntity; import com.hnac.hzims.spare.entity.WtSpToolBasicEntity;
import com.hnac.hzims.spare.vo.WtSpBasicVO; import com.hnac.hzims.spare.vo.WtSpBasicVO;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@ -19,47 +20,60 @@ public class WtSpToolBasicVO extends WtSpToolBasicEntity {
* 名称 * 名称
*/ */
@ApiModelProperty(value = "名称") @ApiModelProperty(value = "名称")
@ExcelProperty(value = "工具名称",index = 1)
private String name; private String name;
/** /**
* 编码 * 编码
*/ */
@ApiModelProperty(value = "编码") @ApiModelProperty(value = "编码")
@ExcelProperty(value = "工具台账",index = 0)
private String code; private String code;
/** /**
* 规格 * 规格
*/ */
@ApiModelProperty(value = "规格") @ApiModelProperty(value = "规格")
@ExcelProperty(value = "规格/型号",index = 2)
private String specifications; private String specifications;
/** /**
* 单位 * 单位
*/ */
@ApiModelProperty(value = "单位") @ApiModelProperty(value = "单位")
@ExcelProperty(value = "单位",index = 3)
private String unit; private String unit;
/** /**
* 总数量 * 总数量
*/ */
@ApiModelProperty(value = "总数量") @ApiModelProperty(value = "总数量")
@ExcelProperty(value = "总数量",index = 4)
private Long totalAmount; private Long totalAmount;
/** /**
* 在库数量 * 在库数量
*/ */
@ApiModelProperty(value = "在库数量") @ApiModelProperty(value = "在库数量")
@ExcelProperty(value = "在库数量",index = 5)
private Integer notUseAmount; private Integer notUseAmount;
/** /**
* 已领数量 * 已领数量
*/ */
@ApiModelProperty(value = "已领数量") @ApiModelProperty(value = "已领数量")
@ExcelProperty(value = "已领数量",index = 6)
private Integer useAmount; private Integer useAmount;
/** /**
* 所属仓库 * 所属仓库
*/ */
@ApiModelProperty(value = "所属仓库") @ApiModelProperty(value = "所属仓库")
@ExcelProperty(value = "仓库",index = 9)
private String warehouseName; private String warehouseName;
/** /**
* 入库人 * 入库人
*/ */
@ApiModelProperty(value = "入库人") @ApiModelProperty(value = "入库人")
@ExcelProperty(value = "领用人",index = 8)
private String userName; private String userName;
@ApiModelProperty(value = "最近领用时间")
@ExcelProperty(value = "最近领用时间",index = 7)
private String lastNeckTime;
/** /**
* 单位名称 * 单位名称
*/ */

8
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.annotation.OperationAnnotation;
import com.hnac.hzims.common.logs.enums.BusinessType; import com.hnac.hzims.common.logs.enums.BusinessType;
import com.hnac.hzims.common.logs.enums.OperatorType; 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.SpTemporaryStockDetailEntity;
import com.hnac.hzims.spare.entity.SpTemporaryStockEntity; import com.hnac.hzims.spare.entity.SpTemporaryStockEntity;
import com.hnac.hzims.spare.entity.WtSpBasicEntity; import com.hnac.hzims.spare.entity.WtSpBasicEntity;
@ -117,6 +118,13 @@ public class WtSpBasicController extends BladeController {
return R.data(pages); 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") @GetMapping("/getlist")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "code", value = "编码", paramType = "query", dataType = "string"), @ApiImplicitParam(name = "code", value = "编码", paramType = "query", dataType = "string"),

7
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 org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.List; import java.util.List;
@ -82,6 +83,12 @@ public class WtSpToolBasicController extends BladeController {
return R.data(pages); 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);
}
/** /**
* 新增 代码自定义代号 * 新增 代码自定义代号
*/ */

32
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;
}

1
hzims-service/assets/src/main/java/com/hnac/hzims/spare/mapper/WtSpToolBasicMapper.java

@ -26,4 +26,5 @@ public interface WtSpToolBasicMapper extends UserDataScopeBaseMapper<WtSpToolBas
*/ */
@UserDataAuth @UserDataAuth
List<WtSpToolBasicVO> selectPageList(IPage<WtSpToolBasicVO> page,@Param(value = "params") Map<String,Object> params); List<WtSpToolBasicVO> selectPageList(IPage<WtSpToolBasicVO> page,@Param(value = "params") Map<String,Object> params);
} }

3
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.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService; 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.SpTemporaryStockDetailEntity;
import com.hnac.hzims.spare.entity.SpTemporaryStockEntity; import com.hnac.hzims.spare.entity.SpTemporaryStockEntity;
import com.hnac.hzims.spare.entity.WtSpBasicEntity; import com.hnac.hzims.spare.entity.WtSpBasicEntity;
@ -29,6 +30,8 @@ public interface IWtSpBasicService extends IService<WtSpBasicEntity> {
* @return * @return
*/ */
IPage<WtSpBasicVO> selectPage(WtSpBasicEntity SP_BASIC, Query query, Long warehouseId, String sign); IPage<WtSpBasicVO> selectPage(WtSpBasicEntity SP_BASIC, Query query, Long warehouseId, String sign);
void export(WtSpBasicDto request,HttpServletResponse response);
/** /**
* 根据备件id和库存id查询备件已使用总数量 * 根据备件id和库存id查询备件已使用总数量
* @param params * @param params

3
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 org.springblade.core.mp.support.Query;
import javax.servlet.http.HttpServletResponse;
import java.util.List; import java.util.List;
/** /**
@ -36,4 +37,6 @@ public interface IWtSpToolBasicService extends IService<WtSpToolBasicEntity> {
* @return * @return
*/ */
IPage<WtSpToolBasicVO> selectPageList(IPage<WtSpToolBasicVO> page, WtSpToolBasicVO toolBasicVO) ; IPage<WtSpToolBasicVO> selectPageList(IPage<WtSpToolBasicVO> page, WtSpToolBasicVO toolBasicVO) ;
void exportWtSpToolBasic(WtSpToolBasicVO toolBasicVO, HttpServletResponse response);
} }

15
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.entity.Dept;
import org.springblade.system.feign.IDictBizClient; import org.springblade.system.feign.IDictBizClient;
import org.springblade.system.feign.ISysClient; 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.entity.User;
import org.springblade.system.user.feign.IUserClient; import org.springblade.system.user.feign.IUserClient;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -34,10 +35,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* 服务实现类 * 服务实现类
@ -170,13 +168,8 @@ public class SpReceiveServiceImpl extends ServiceImpl<SpReceiveMapper, SpReceive
receiveVO.setWarehouseName(warehouseEntity.getName()); receiveVO.setWarehouseName(warehouseEntity.getName());
receiveVO.setAffiliatedName(warehouseEntity.getAffiliatedName()); receiveVO.setAffiliatedName(warehouseEntity.getAffiliatedName());
} }
String userName = Optional.ofNullable(detail.getCreateUser()).map(UserCache::getUser).map(User::getName).orElse(null);
if(null!=detail.getCreateUser()){ receiveVO.setUserName(userName);
R<User> user = userClient.userInfoById(detail.getCreateUser());
if(null!=user){
receiveVO.setUserName(user.getData().getName());
}
}
List<SpRecordEntity> basicList = spRecordMapper.selectByBusinessId(detail.getId()); List<SpRecordEntity> basicList = spRecordMapper.selectByBusinessId(detail.getId());
List<WtSpBasicVO> basicVOList = new ArrayList<>(); List<WtSpBasicVO> basicVOList = new ArrayList<>();
for (int i = 0; i < basicList.size(); i++) { for (int i = 0; i < basicList.size(); i++) {

70
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; package com.hnac.hzims.spare.service.impl;
import ch.qos.logback.classic.jmx.MBeanUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams; import cn.afterturn.easypoi.excel.entity.ImportParams;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter; import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.converters.longconverter.LongStringConverter; import com.alibaba.excel.converters.longconverter.LongStringConverter;
import com.alibaba.excel.write.metadata.WriteSheet; 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.excel.write.style.column.SimpleColumnWidthStyleStrategy;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; 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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.common.logs.utils.StringUtils;
import com.hnac.hzims.equipment.feign.IEmInfoClient; 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.entity.*;
import com.hnac.hzims.spare.enume.WarehouseInType; import com.hnac.hzims.spare.enume.WarehouseInType;
import com.hnac.hzims.spare.enume.WarehouseOutType; 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.SparePartVO;
import com.hnac.hzims.spare.vo.WtSpBasicVO; import com.hnac.hzims.spare.vo.WtSpBasicVO;
import com.hnac.hzims.ticket.allTicket.fegin.ITicketInfoAllClient; import com.hnac.hzims.ticket.allTicket.fegin.ITicketInfoAllClient;
import com.hnac.hzinfo.exception.HzServiceException;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query; import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.utils.AuthUtil; 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.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.CollectionUtil;
import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.ObjectUtil;
@ -55,10 +65,7 @@ import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream; import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -259,6 +266,61 @@ public class WtSpBasicServiceImpl extends ServiceImpl<WtSpBasicMapper, WtSpBasic
} }
@Override @Override
public void export(WtSpBasicDto request, HttpServletResponse response) {
LambdaQueryWrapper<WtSpBasicEntity> basicWrapper = Wrappers.<WtSpBasicEntity>lambdaQuery()
.like(StringUtils.isNotEmpty(request.getNameQuery()),WtSpBasicEntity::getName, request.getNameQuery());
List<WtSpBasicEntity> wtBasicList = this.list(basicWrapper);
Assert.isTrue(CollectionUtil.isNotEmpty(wtBasicList),() -> {
throw new HzServiceException(ResultCode.FAILURE,"暂无数据!");
});
List<WtSpBasicVO> 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<WtSpTotalEntity> totalList = totalService.list(Wrappers.<WtSpTotalEntity>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<WtSpTotalEntity> totalWrapper = Wrappers.<WtSpTotalEntity>lambdaQuery()
.eq(Func.isNotEmpty(basicEntity.getId()), WtSpTotalEntity::getSpBasicId, basicEntity.getId())
.eq(WtSpTotalEntity::getWarehouseId, warehouseId);
if(CollectionUtil.isNotEmpty(totalMapper.selectList(totalWrapper))) {
List<WtSpTotalEntity> totalList = totalService.list(Wrappers.<WtSpTotalEntity>query().lambda().eq(WtSpTotalEntity::getSpBasicId, basicEntity.getId()));
basicVO.setStock(CollectionUtil.isNotEmpty(totalList) ? totalList.get(0).getStock() : 0L);
}
}
return basicVO;
}
@Override
public Integer selectTotal(Map<String, Object> params) { public Integer selectTotal(Map<String, Object> params) {
return baseMapper.selectTotal(params); return baseMapper.selectTotal(params);
} }

93
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; 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.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 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.mapper.*;
import com.hnac.hzims.spare.service.IWtSpBasicService; import com.hnac.hzims.spare.service.IWtSpBasicService;
import com.hnac.hzims.spare.service.IWtSpToolBasicService; 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 com.hnac.hzims.spare.vo.WtSpToolBasicVO;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query; import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R; 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.entity.Dept;
import org.springblade.system.feign.ISysClient; 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.entity.User;
import org.springblade.system.user.feign.IUserClient; import org.springblade.system.user.feign.IUserClient;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import javax.servlet.http.HttpServletResponse;
import java.util.HashMap; import java.io.IOException;
import java.util.List; import java.io.UnsupportedEncodingException;
import java.util.Map; import java.net.URLEncoder;
import java.util.*;
/** /**
* 服务实现类 * 服务实现类
@ -160,4 +170,79 @@ public class WtSpToolBasicServiceImpl extends ServiceImpl<WtSpToolBasicMapper, W
} }
return page.setRecords(result); return page.setRecords(result);
} }
@Override
public void exportWtSpToolBasic(WtSpToolBasicVO toolBasicVO, HttpServletResponse response) {
Map<String,Object> 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<Long> longList = new ArrayList<>();
if(null!=toolBasicVO.getDeptId()){
R<List<Dept>> 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<WtSpToolBasicVO> list = baseMapper.selectPageList(null,params);
List<WtSpToolBasicExportVO> 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<String,Object> 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);
}
}
} }

36
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;
}

83
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;
}
Loading…
Cancel
Save