Browse Source

add: 新增入库单导出接口

zhongwei
liwen 4 months ago
parent
commit
edfd1006d0
  1. 42
      hzims-service-api/assets-api/src/main/java/com/hnac/hzims/spare/vo/SpWarehouseInExportVO.java
  2. 1
      hzims-service-api/assets-api/src/main/java/com/hnac/hzims/spare/vo/SpWarehouseInVO.java
  3. 10
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/controller/SpWarehouseInController.java
  4. 9
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/ISpWarehouseInService.java
  5. 112
      hzims-service/assets/src/main/java/com/hnac/hzims/spare/service/impl/SpWarehouseInServiceImpl.java

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

1
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;
/**
* 备品备件列表
*/

10
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);
}
/**
* 完成流程 修改状态
*/

9
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<SpWarehouseInEntity> {
* @return
*/
IPage<SpWarehouseInVO> selectPageList(IPage<SpWarehouseInVO> page, SpWarehouseInVO warehouseInVO) ;
/**
* 入库单导出
* @param warehouseInVO
* @param response
*/
void exportSpWarehouseData(SpWarehouseInVO warehouseInVO, HttpServletResponse response);
/**
*完成流程
* @param flow

112
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<SpWarehouseInMapper, S
return page.setRecords(result);
}
/**
* 入库单导出
*/
@Override
public void exportSpWarehouseData(SpWarehouseInVO warehouseInVO, HttpServletResponse response) {
ServletOutputStream outputStream = null;
try {
outputStream = response.getOutputStream();
Map<String,Object> 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<Long> longList = new ArrayList<>();
if (null!=warehouseInVO.getDeptId()) {
R<List<Dept>> 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<SpWarehouseInVO> page = new Page<>();
List<SpWarehouseInVO> warehouseInPage = baseMapper.selectPageList(page, params);
// 导入列表
List<SpWarehouseInExportVO> 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();

Loading…
Cancel
Save