物资台账导出

This commit is contained in:
lcj
2025-08-23 06:26:57 +08:00
parent c9c0224145
commit fe32eb945c
10 changed files with 195 additions and 40 deletions

View File

@ -18,6 +18,7 @@ import org.dromara.common.web.core.BaseController;
import org.dromara.materials.domain.dto.materialsinventory.MatMaterialsInventoryCreateReq;
import org.dromara.materials.domain.dto.materialsinventory.MatMaterialsInventoryQueryReq;
import org.dromara.materials.domain.dto.materialsinventory.MatMaterialsInventoryUpdateReq;
import org.dromara.materials.domain.vo.materialsinventory.MatMaterialsInventoryExcelVo;
import org.dromara.materials.domain.vo.materialsinventory.MatMaterialsInventoryVo;
import org.dromara.materials.service.IMatMaterialsInventoryService;
import org.springframework.validation.annotation.Validated;
@ -55,8 +56,8 @@ public class MatMaterialsInventoryController extends BaseController {
@Log(title = "材料出/入库", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(MatMaterialsInventoryQueryReq req, HttpServletResponse response) {
List<MatMaterialsInventoryVo> list = materialsInventoryService.queryList(req);
ExcelUtil.exportExcel(list, "材料出入库", MatMaterialsInventoryVo.class, response);
List<MatMaterialsInventoryExcelVo> list = materialsInventoryService.queryList(req);
ExcelUtil.exportExcel(list, "材料出入库", MatMaterialsInventoryExcelVo.class, response);
}
/**

View File

@ -0,0 +1,77 @@
package org.dromara.materials.domain.vo.materialsinventory;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
* @author lilemy
* @date 2025-08-23 04:01
*/
@Data
@ExcelIgnoreUnannotated
public class MatMaterialsInventoryExcelVo implements Serializable {
@Serial
private static final long serialVersionUID = 5168336233433075508L;
@ExcelProperty(value = "材料名称")
private String materialsName;
@ExcelProperty(value = "计划数量")
private int quantityCount;
@ExcelProperty(value = {"入库登记", "供货单位"})
private String supplier;
@ExcelProperty(value = {"入库登记", "数量"})
private Long putNumber;
@ExcelProperty(value = {"入库登记", "签收人"})
private String signer;
@ExcelProperty(value = {"入库登记", "日期"})
private String putTime;
@ExcelProperty(value = {"出库登记", "接收单位"})
private String recipient;
@ExcelProperty(value = {"出库登记", "数量"})
private Long outNumber;
@ExcelProperty(value = {"出库登记", "出库人"})
private String operator;
@ExcelProperty(value = {"出库登记", "领用人"})
private String shipper;
@ExcelProperty(value = {"出库登记", "领用日期"})
private String receivingDate;
@ExcelProperty(value = {"到货剩余登记", "剩余量"})
private Long residue;
@ExcelProperty(value = {"到货剩余登记", "处理方式"})
private String disposition;
@ExcelProperty(value = {"使用登记", "使用部位"})
private String usePart;
@ExcelProperty(value = {"使用登记", "使用数量"})
private BigDecimal useNumber;
@ExcelProperty(value = {"使用登记", "使用日期"})
private String useTime;
@ExcelProperty(value = {"使用登记", "剩余量"})
private BigDecimal surplus;
@ExcelProperty(value = "备注")
private String remark;
}

View File

@ -1,7 +1,5 @@
package org.dromara.materials.domain.vo.materialsinventory;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import org.dromara.materials.domain.MatMaterialsInventory;
@ -18,7 +16,6 @@ import java.util.Date;
* @date 2025-03-06
*/
@Data
@ExcelIgnoreUnannotated
@AutoMapper(target = MatMaterialsInventory.class)
public class MatMaterialsInventoryVo implements Serializable {
@ -28,13 +25,11 @@ public class MatMaterialsInventoryVo implements Serializable {
/**
* 主键id
*/
@ExcelProperty(value = "主键id")
private Long id;
/**
* 材料id
*/
@ExcelProperty(value = "材料id")
private Long materialsId;
/**
@ -45,79 +40,66 @@ public class MatMaterialsInventoryVo implements Serializable {
/**
* 计划数量
*/
@ExcelProperty(value = "计划数量")
private int quantityCount;
/**
* 项目id
*/
@ExcelProperty(value = "项目id")
private Long projectId;
/**
* 出入库状态
*/
@ExcelProperty(value = "出入库状态")
private String outPut;
/**
* 出/入库的数量
*/
@ExcelProperty(value = "出入库的数量")
private Long number;
/**
* 出/入库操作时间
*/
@ExcelProperty(value = "出入库操作时间")
private Date outPutTime;
/**
* 剩余库存数量(记录最后一次操作留下的库存数)
*/
@ExcelProperty(value = "剩余库存数量")
private Long residue;
/**
* 操作人(入库人、领料人)
*/
@ExcelProperty(value = "操作人")
private String operator;
/**
* 材料出入证明
*/
@ExcelProperty(value = "材料出入证明")
private String path;
/**
* 处理方式
*/
@ExcelProperty(value = "处理方式")
private String disposition;
/**
* 交接单位(班组)
*/
@ExcelProperty(value = "交接单位")
private String recipient;
/**
* 领用人
*/
@ExcelProperty(value = "领用人")
private String shipper;
/**
* 备注
*/
@ExcelProperty(value = "备注")
private String remark;
/**
* 创建时间
*/
@ExcelProperty(value = "创建时间")
private Date createTime;
}

View File

@ -28,19 +28,16 @@ public class MatMaterialsUseRecordVo implements Serializable {
/**
* 主键ID
*/
@ExcelProperty(value = "主键ID")
private Long id;
/**
* 项目ID
*/
@ExcelProperty(value = "项目ID")
private Long projectId;
/**
* 库存ID
*/
@ExcelProperty(value = "库存ID")
private Long inventoryId;
/**

View File

@ -9,6 +9,7 @@ import org.dromara.materials.domain.MatMaterialsInventory;
import org.dromara.materials.domain.dto.materialsinventory.MatMaterialsInventoryCreateReq;
import org.dromara.materials.domain.dto.materialsinventory.MatMaterialsInventoryQueryReq;
import org.dromara.materials.domain.dto.materialsinventory.MatMaterialsInventoryUpdateReq;
import org.dromara.materials.domain.vo.materialsinventory.MatMaterialsInventoryExcelVo;
import org.dromara.materials.domain.vo.materialsinventory.MatMaterialsInventoryVo;
import java.util.Collection;
@ -45,7 +46,7 @@ public interface IMatMaterialsInventoryService extends IService<MatMaterialsInve
* @param req 查询条件
* @return 材料出/入库列表
*/
List<MatMaterialsInventoryVo> queryList(MatMaterialsInventoryQueryReq req);
List<MatMaterialsInventoryExcelVo> queryList(MatMaterialsInventoryQueryReq req);
/**
* 新增材料出/入库

View File

@ -7,7 +7,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.dromara.common.core.constant.HttpStatus;
import org.dromara.common.core.enums.FormatsType;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.DateUtils;
import org.dromara.common.core.utils.ObjectUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.PageQuery;
@ -15,16 +17,20 @@ import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.materials.domain.MatMaterials;
import org.dromara.materials.domain.MatMaterialsInventory;
import org.dromara.materials.domain.MatMaterialsUseRecord;
import org.dromara.materials.domain.dto.materialsinventory.MatMaterialsInventoryCreateReq;
import org.dromara.materials.domain.dto.materialsinventory.MatMaterialsInventoryQueryReq;
import org.dromara.materials.domain.dto.materialsinventory.MatMaterialsInventoryUpdateReq;
import org.dromara.materials.domain.enums.MatMaterialsInventoryOutPutEnum;
import org.dromara.materials.domain.vo.materialsinventory.MatMaterialsInventoryExcelVo;
import org.dromara.materials.domain.vo.materialsinventory.MatMaterialsInventoryVo;
import org.dromara.materials.mapper.MatMaterialsInventoryMapper;
import org.dromara.materials.service.IMatMaterialsInventoryService;
import org.dromara.materials.service.IMatMaterialsService;
import org.dromara.materials.service.IMatMaterialsUseRecordService;
import org.dromara.project.service.IBusProjectService;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -47,6 +53,10 @@ public class MatMaterialsInventoryServiceImpl extends ServiceImpl<MatMaterialsIn
@Resource
private IBusProjectService projectService;
@Lazy
@Resource
private IMatMaterialsUseRecordService materialsUseRecordService;
/**
* 查询材料出/入库
*
@ -82,10 +92,84 @@ public class MatMaterialsInventoryServiceImpl extends ServiceImpl<MatMaterialsIn
* @return 材料出/入库列表
*/
@Override
public List<MatMaterialsInventoryVo> queryList(MatMaterialsInventoryQueryReq req) {
public List<MatMaterialsInventoryExcelVo> queryList(MatMaterialsInventoryQueryReq req) {
LambdaQueryWrapper<MatMaterialsInventory> lqw = this.buildQueryWrapper(req);
List<MatMaterialsInventory> list = this.list(lqw);
return list.stream().map(this::getVo).toList();
// 获取材料id列表
Set<Long> materialsIdList = list.stream().map(MatMaterialsInventory::getMaterialsId).collect(Collectors.toSet());
Map<Long, List<MatMaterials>> materialsIdBusMaterialsMap = materialsService.listByIds(materialsIdList).stream()
.collect(Collectors.groupingBy(MatMaterials::getId));
// 获取使用部位列表
Set<Long> ids = list.stream().map(MatMaterialsInventory::getId).collect(Collectors.toSet());
List<MatMaterialsUseRecord> useRecordList = materialsUseRecordService.lambdaQuery()
.in(MatMaterialsUseRecord::getInventoryId, ids)
.list();
Map<Long, List<MatMaterialsUseRecord>> inventoryIdUseRecordMap = new HashMap<>();
if (CollUtil.isNotEmpty(useRecordList)) {
inventoryIdUseRecordMap = useRecordList.stream()
.collect(Collectors.groupingBy(MatMaterialsUseRecord::getInventoryId));
}
Map<Long, List<MatMaterialsUseRecord>> finalInventoryIdUseRecordMap = inventoryIdUseRecordMap;
// 对象列表 => 封装对象列表
List<MatMaterialsInventoryExcelVo> listVo = new ArrayList<>();
for (MatMaterialsInventory materialsInventory : list) {
Long id = materialsInventory.getId();
// 关联查询材料信息
Long materialsId = materialsInventory.getMaterialsId();
String materialsName = "";
int quantityCount = 0;
if (materialsIdBusMaterialsMap.containsKey(materialsId)) {
materialsName = materialsIdBusMaterialsMap.get(materialsId).getFirst().getMaterialsName();
quantityCount = Integer.parseInt(materialsIdBusMaterialsMap.get(materialsId).getFirst().getQuantityCount());
}
if (CollUtil.isNotEmpty(finalInventoryIdUseRecordMap) && finalInventoryIdUseRecordMap.containsKey(id)) {
List<MatMaterialsUseRecord> useRecords = finalInventoryIdUseRecordMap.get(id);
for (int i = 0; i < useRecords.size(); i++) {
MatMaterialsInventoryExcelVo materialsInventoryVo = new MatMaterialsInventoryExcelVo();
if (i == 0) {
materialsInventoryVo.setMaterialsName(materialsName);
materialsInventoryVo.setQuantityCount(quantityCount);
materialsInventoryVo.setRecipient(materialsInventory.getRecipient());
materialsInventoryVo.setOutNumber(materialsInventory.getNumber());
materialsInventoryVo.setOperator(materialsInventory.getOperator());
materialsInventoryVo.setShipper(materialsInventory.getShipper());
Date outPutTime = materialsInventory.getOutPutTime();
if (outPutTime != null) {
materialsInventoryVo.setReceivingDate(DateUtils.parseDateToStr(FormatsType.YYYY_MM_DD_DOT, outPutTime));
}
}
materialsInventoryVo.setResidue(materialsInventory.getResidue());
materialsInventoryVo.setDisposition(materialsInventory.getDisposition());
MatMaterialsUseRecord record = useRecords.get(i);
materialsInventoryVo.setUsePart(record.getUsePart());
materialsInventoryVo.setUseNumber(record.getUseNumber());
Date createTime = record.getCreateTime();
if (createTime != null) {
materialsInventoryVo.setUseTime(DateUtils.parseDateToStr(FormatsType.YYYY_MM_DD_DOT, createTime));
}
materialsInventoryVo.setSurplus(record.getResidueNumber());
materialsInventoryVo.setRemark(materialsInventory.getRemark());
listVo.add(materialsInventoryVo);
}
}
if (MatMaterialsInventoryOutPutEnum.PUT.getValue().equals(materialsInventory.getOutPut())) {
MatMaterialsInventoryExcelVo materialsInventoryVo = new MatMaterialsInventoryExcelVo();
materialsInventoryVo.setMaterialsName(materialsName);
materialsInventoryVo.setQuantityCount(quantityCount);
materialsInventoryVo.setSupplier(materialsInventory.getRecipient());
materialsInventoryVo.setPutNumber(materialsInventory.getNumber());
materialsInventoryVo.setSigner(materialsInventory.getOperator());
Date outPutTime = materialsInventory.getOutPutTime();
if (outPutTime != null) {
materialsInventoryVo.setPutTime(DateUtils.parseDateToStr(FormatsType.YYYY_MM_DD_DOT, outPutTime));
}
materialsInventoryVo.setResidue(materialsInventory.getResidue());
materialsInventoryVo.setDisposition(materialsInventory.getDisposition());
materialsInventoryVo.setRemark(materialsInventory.getRemark());
listVo.add(materialsInventoryVo);
}
}
return listVo;
}
/**

View File

@ -3,24 +3,20 @@ package org.dromara.progress.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.read.builder.ExcelReaderSheetBuilder;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jakarta.annotation.Resource;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.common.excel.core.DefaultExcelListener;
import org.dromara.common.excel.core.ExcelResult;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.web.core.BaseController;
import org.dromara.design.domain.BusBillofquantities;
import org.dromara.facility.service.IFacMatrixService;
import org.dromara.progress.domain.PgsProgressCategory;
import org.dromara.progress.domain.dto.progresscategory.PgsProgressCategoryCreatePriceReq;
@ -38,9 +34,10 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.stream.Collectors;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 进度类别
@ -76,13 +73,12 @@ public class PgsProgressCategoryController extends BaseController {
@Log(title = "进度类别", businessType = BusinessType.EXPORT)
@Transactional
@PostMapping("/export")
public void export(@RequestBody Map<String,List<String>>ids, HttpServletResponse response) throws IOException {
public void export(@RequestBody Map<String, List<String>> ids, HttpServletResponse response) throws IOException {
List<List<PgsProgressCategoryVo>> voList = new ArrayList<>();
List<String> sheetNames = new ArrayList<>();
List<Long> idss = new ArrayList<>();
List<String> idStrings = ids.get("ids");
for (String idString : idStrings) {
idss.add(Long.valueOf(idString));
@ -90,13 +86,13 @@ public class PgsProgressCategoryController extends BaseController {
for (Long id : idss) {
LambdaQueryWrapper<PgsProgressCategory> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PgsProgressCategory::getMatrixId,id);
queryWrapper.eq(PgsProgressCategory::getMatrixId, id);
List<PgsProgressCategoryVo> voList1 = pgsProgressCategoryService.getVoList(pgsProgressCategoryService.list(queryWrapper));
voList.add(voList1);
sheetNames.add(matrixService.getById(voList1.getFirst().getMatrixId()).getMatrixName());
}
ExcelUtil.exportMultiSheetExcelEnhanced(voList,sheetNames,PgsProgressCategoryVo.class,null,response);
ExcelUtil.exportMultiSheetExcelEnhanced(voList, sheetNames, PgsProgressCategoryVo.class, null, response);
}
/***
@ -159,9 +155,24 @@ public class PgsProgressCategoryController extends BaseController {
for (PgsProgressCategoryVo vo : allData) {
list.add(pgsProgressCategoryService.convertVoToEntity(vo));
}
// 计算产值
list.forEach(pgsProgressCategory -> {
BigDecimal ownerPrice = pgsProgressCategory.getOwnerPrice();
BigDecimal constructionPrice = pgsProgressCategory.getConstructionPrice();
BigDecimal total = pgsProgressCategory.getTotal();
if (total != null && total.compareTo(BigDecimal.ZERO) != 0) {
if (ownerPrice != null && ownerPrice.compareTo(BigDecimal.ZERO) != 0) {
pgsProgressCategory.setOwnerOutputValue(ownerPrice.multiply(total));
}
if (constructionPrice != null && constructionPrice.compareTo(BigDecimal.ZERO) != 0) {
pgsProgressCategory.setConstructionOutputValue(constructionPrice.multiply(total));
}
}
});
boolean b = pgsProgressCategoryService.updateBatchById(list);
if (!b){
if (!b) {
return R.fail("更新失败");
}

View File

@ -2,6 +2,7 @@ package org.dromara.progress.domain.vo.progresscategory;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
@ -22,6 +23,7 @@ import java.math.BigDecimal;
* @date 2025-05-26
*/
@Data
@ColumnWidth(30)
@ExcelIgnoreUnannotated
@AutoMapper(target = PgsProgressCategory.class)
public class PgsProgressCategoryVo implements Serializable {

View File

@ -145,5 +145,5 @@ public interface IPgsProgressCategoryService extends IService<PgsProgressCategor
List<Map<String,Object>> getMatrixIdAndNumber(Long projectId);
public PgsProgressCategory convertVoToEntity(PgsProgressCategoryVo vo);
PgsProgressCategory convertVoToEntity(PgsProgressCategoryVo vo);
}

View File

@ -956,7 +956,7 @@ public class PgsProgressCategoryServiceImpl extends ServiceImpl<PgsProgressCateg
}
PgsProgressCategory entity = new PgsProgressCategory();
org.springframework.beans.BeanUtils.copyProperties(vo, entity);
BeanUtils.copyProperties(vo, entity);
return entity;
}