修改材料设备出入库逻辑

This commit is contained in:
lcj
2025-09-01 17:33:19 +08:00
parent 711c473749
commit 96e6c75949
14 changed files with 201 additions and 67 deletions

View File

@ -18,7 +18,6 @@ import org.dromara.materials.domain.dto.materialissue.MatMaterialIssueUpdateReq;
import org.dromara.materials.domain.vo.materialissue.MatMaterialIssueVo;
import org.dromara.materials.domain.vo.materialsinventory.MatMaterialsInventoryListVo;
import org.dromara.materials.service.IMatMaterialIssueService;
import org.dromara.materials.service.IMatMaterialsInventoryService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@ -37,8 +36,6 @@ public class MatMaterialIssueController extends BaseController {
@Resource
private IMatMaterialIssueService matMaterialIssueService;
@Resource
private IMatMaterialsInventoryService materialsInventoryService;
/**
* 查询物料领料单列表

View File

@ -19,6 +19,7 @@ import org.dromara.materials.domain.dto.materials.MatMaterialsCreateReq;
import org.dromara.materials.domain.dto.materials.MatMaterialsGisReq;
import org.dromara.materials.domain.dto.materials.MatMaterialsQueryReq;
import org.dromara.materials.domain.dto.materials.MatMaterialsUpdateReq;
import org.dromara.materials.domain.vo.materials.MatMaterialsByFormCodeVo;
import org.dromara.materials.domain.vo.materials.MatMaterialsGisVo;
import org.dromara.materials.domain.vo.materials.MatMaterialsNumberVo;
import org.dromara.materials.domain.vo.materials.MatMaterialsVo;
@ -81,6 +82,18 @@ public class MatMaterialsController extends BaseController {
return R.ok(materialsService.queryInventoryList(projectId));
}
/**
* 获取材料列表
*
* @param projectId 项目id
*/
@SaCheckPermission("materials:materials:listByFormCode")
@GetMapping("/listByFormCode/{projectId}")
public R<List<MatMaterialsByFormCodeVo>> listMaterialsByFormCode(@NotNull(message = "项目id不能为空")
@PathVariable Long projectId) {
return R.ok(materialsService.queryMaterialsByFormCode(projectId));
}
/**
* 获取材料详细信息
*

View File

@ -43,6 +43,11 @@ public class MatMaterials extends BaseEntity {
*/
private Long projectId;
/**
* 表单编号
*/
private String formCode;
/**
* 规格型号名称
*/
@ -53,11 +58,6 @@ public class MatMaterials extends BaseEntity {
*/
private String fileOssId;
/**
* 使用部位
*/
private String usePart;
/**
* 计量单位
*/

View File

@ -1,5 +1,7 @@
package org.dromara.materials.domain.dto.materialreceive;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.dromara.materials.domain.dto.materialreceiveitem.MatMaterialReceiveItemDto;
@ -20,26 +22,31 @@ public class MatMaterialReceiveCreateReq implements Serializable {
/**
* 项目id
*/
@NotNull(message = "项目id不能为空")
private Long projectId;
/**
* 材料来源(1甲供 2乙供)
*/
@NotBlank(message = "材料来源不能为空")
private String materialSource;
/**
* 表单编号
*/
@NotBlank(message = "表单编号不能为空")
private String formCode;
/**
* 工程名称
*/
@NotBlank(message = "工程名称不能为空")
private String projectName;
/**
* 设备材料名称
*/
@NotBlank(message = "设备材料名称不能为空")
private String materialName;
/**

View File

@ -31,6 +31,11 @@ public class MatMaterialsCreateReq implements Serializable {
*/
private Long projectId;
/**
* 表单编号
*/
private String formCode;
/**
* 规格型号名称
*/

View File

@ -4,7 +4,6 @@ import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.Map;
/**
* @author lilemy
@ -36,31 +35,21 @@ public class MatMaterialsQueryReq implements Serializable {
*/
private Long projectId;
/**
* 表单编号
*/
private String formCode;
/**
* 规格型号名称
*/
private String typeSpecificationName;
/**
* 文件对象存储id列表
*/
private Map<String, Long> fileOssIdMap;
/**
* 使用部位
*/
private String usePart;
/**
* 计量单位
*/
private String weightId;
/**
* 备注
*/
private String remark;
/**
* 预计材料数量
*/

View File

@ -0,0 +1,48 @@
package org.dromara.materials.domain.vo.materials;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
/**
* @author lilemy
* @date 2025-09-01 16:24
*/
@Data
public class MatMaterialsByFormCodeVo implements Serializable {
@Serial
private static final long serialVersionUID = -2113420582630471078L;
/**
* 表单编号
*/
private String formCode;
/**
* 工程名称
*/
private String projectName;
/**
* 设备材料名称
*/
private String materialName;
/**
* 订货单位
*/
private String orderingUnit;
/**
* 供货单位
*/
private String supplierUnit;
/**
* 设备材料列表
*/
private List<MatMaterialsNumberVo> materials;
}

View File

@ -59,6 +59,12 @@ public class MatMaterialsVo implements Serializable {
@ExcelProperty(value = "项目id")
private Long projectId;
/**
* 表单编号
*/
@ExcelProperty(value = "表单编号")
private String formCode;
/**
* 规格型号名称
*/
@ -70,12 +76,6 @@ public class MatMaterialsVo implements Serializable {
*/
private Map<String, Long> fileOssMap;
/**
* 使用部位
*/
@ExcelProperty(value = "使用部位")
private String usePart;
/**
* 计量单位
*/

View File

@ -11,6 +11,7 @@ import org.dromara.materials.domain.dto.materials.MatMaterialsCreateReq;
import org.dromara.materials.domain.dto.materials.MatMaterialsGisReq;
import org.dromara.materials.domain.dto.materials.MatMaterialsQueryReq;
import org.dromara.materials.domain.dto.materials.MatMaterialsUpdateReq;
import org.dromara.materials.domain.vo.materials.MatMaterialsByFormCodeVo;
import org.dromara.materials.domain.vo.materials.MatMaterialsGisVo;
import org.dromara.materials.domain.vo.materials.MatMaterialsNumberVo;
import org.dromara.materials.domain.vo.materials.MatMaterialsVo;
@ -111,7 +112,7 @@ public interface IMatMaterialsService extends IService<MatMaterials> {
/**
* 生成材料并入库
*/
void create(Long projectId, List<MatMaterialReceiveItemDto> itemList,String nickname);
void create(Long projectId, List<MatMaterialReceiveItemDto> itemList, String formCode, String nickname);
/**
* 获取材料库存数据列表
@ -121,4 +122,11 @@ public interface IMatMaterialsService extends IService<MatMaterials> {
*/
List<MatMaterialsNumberVo> queryInventoryList(Long projectId);
/**
* 获取材料库存数据列表
*
* @param projectId 项目id
* @return 材料库存数据列表
*/
List<MatMaterialsByFormCodeVo> queryMaterialsByFormCode(Long projectId);
}

View File

@ -23,6 +23,7 @@ import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.oss.core.OssClient;
import org.dromara.common.oss.exception.OssException;
import org.dromara.common.oss.factory.OssFactory;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.common.utils.DocumentUtil;
import org.dromara.materials.constants.MatMaterialsConstant;
import org.dromara.materials.domain.MatMaterialIssue;
@ -35,6 +36,7 @@ import org.dromara.materials.domain.dto.materialissue.MatMaterialIssueUpdateReq;
import org.dromara.materials.domain.dto.materialissue.MatMaterialIssueWordDto;
import org.dromara.materials.domain.dto.materialissueitem.MatMaterialIssueItemDto;
import org.dromara.materials.domain.dto.materialissueitem.MatMaterialIssueItemWordDto;
import org.dromara.materials.domain.enums.MatMaterialsInventoryOutPutEnum;
import org.dromara.materials.domain.vo.materialissue.MatMaterialIssueVo;
import org.dromara.materials.domain.vo.materialsinventory.MatMaterialsInventoryListVo;
import org.dromara.materials.mapper.MatMaterialIssueMapper;
@ -238,6 +240,7 @@ public class MatMaterialIssueServiceImpl extends ServiceImpl<MatMaterialIssueMap
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean insertByBo(MatMaterialIssueCreateReq req) {
String nickname = LoginHelper.getLoginUser().getNickname();
MatMaterialIssue materialIssue = new MatMaterialIssue();
BeanUtils.copyProperties(req, materialIssue);
validEntityBeforeSave(materialIssue, true);
@ -264,14 +267,14 @@ public class MatMaterialIssueServiceImpl extends ServiceImpl<MatMaterialIssueMap
throw new ServiceException("物料领料单明细项新增失败", HttpStatus.ERROR);
}
// 创建设备材料出库记录
/*List<MatMaterialsInventory> inventoryList = itemList.stream().map(item -> {
List<MatMaterialsInventory> inventoryList = itemList.stream().map(item -> {
MatMaterialsInventory inventory = new MatMaterialsInventory();
inventory.setNumber(item.getIssuedQuantity().longValue());
inventory.setOutPutTime(new Date());
inventory.setResidue(item.getRemainingQuantity().longValue());
inventory.setOperator(LoginHelper.getLoginUser().getNickname());
inventory.setOperator(nickname);
inventory.setRecipient(materialIssue.getIssueUnit());
inventory.setShipper(LoginHelper.getLoginUser().getNickname());
inventory.setShipper(nickname);
inventory.setMaterialsId(item.getMaterialsId());
inventory.setProjectId(materialIssue.getProjectId());
inventory.setOutPut(MatMaterialsInventoryOutPutEnum.OUT.getValue());
@ -281,7 +284,7 @@ public class MatMaterialIssueServiceImpl extends ServiceImpl<MatMaterialIssueMap
boolean saved = materialsInventoryService.saveBatch(inventoryList);
if (!saved) {
throw new ServiceException("物料出库记录新增失败", HttpStatus.ERROR);
}*/
}
}
return true;
}

View File

@ -272,7 +272,7 @@ public class MatMaterialReceiveServiceImpl extends ServiceImpl<MatMaterialReceiv
purchaseDocService.create(materialReceive.getDocId(), map);
}
//生成库存
materialsService.create(materialReceive.getProjectId(), itemList, nickname);
materialsService.create(materialReceive.getProjectId(), itemList, materialReceive.getFormCode(), nickname);
}
return true;
}

View File

@ -5,7 +5,6 @@ import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
@ -17,6 +16,7 @@ import org.dromara.common.json.utils.JsonUtils;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.materials.domain.MatMaterialReceive;
import org.dromara.materials.domain.MatMaterials;
import org.dromara.materials.domain.MatMaterialsInventory;
import org.dromara.materials.domain.dto.materialreceiveitem.MatMaterialReceiveItemDto;
@ -26,11 +26,13 @@ import org.dromara.materials.domain.dto.materials.MatMaterialsQueryReq;
import org.dromara.materials.domain.dto.materials.MatMaterialsUpdateReq;
import org.dromara.materials.domain.dto.materialsinventory.MatMaterialsInventoryCreateReq;
import org.dromara.materials.domain.enums.MatMaterialsInventoryOutPutEnum;
import org.dromara.materials.domain.vo.materials.MatMaterialsByFormCodeVo;
import org.dromara.materials.domain.vo.materials.MatMaterialsGisVo;
import org.dromara.materials.domain.vo.materials.MatMaterialsNumberVo;
import org.dromara.materials.domain.vo.materials.MatMaterialsVo;
import org.dromara.materials.mapper.MatMaterialsMapper;
import org.dromara.materials.service.IMatCompanyService;
import org.dromara.materials.service.IMatMaterialReceiveService;
import org.dromara.materials.service.IMatMaterialsInventoryService;
import org.dromara.materials.service.IMatMaterialsService;
import org.dromara.project.domain.BusProject;
@ -65,6 +67,10 @@ public class MatMaterialsServiceImpl extends ServiceImpl<MatMaterialsMapper, Mat
@Resource
private IMatMaterialsInventoryService materialsInventoryService;
@Lazy
@Resource
private IMatMaterialReceiveService materialReceiveService;
/**
* 查询材料名称
@ -310,16 +316,12 @@ public class MatMaterialsServiceImpl extends ServiceImpl<MatMaterialsMapper, Mat
Long companyId = req.getCompanyId();
Long projectId = req.getProjectId();
String typeSpecificationName = req.getTypeSpecificationName();
String usePart = req.getUsePart();
String weightId = req.getWeightId();
String remark = req.getRemark();
String quantityCount = req.getQuantityCount();
String status = req.getStatus();
// 模糊查询
lqw.like(StringUtils.isNotBlank(materialsName), MatMaterials::getMaterialsName, materialsName);
lqw.like(StringUtils.isNotBlank(typeSpecificationName), MatMaterials::getTypeSpecificationName, typeSpecificationName);
lqw.like(StringUtils.isNotBlank(usePart), MatMaterials::getUsePart, usePart);
lqw.like(StringUtils.isNotBlank(remark), MatMaterials::getRemark, remark);
lqw.like(StringUtils.isNotBlank(weightId), MatMaterials::getWeightId, weightId);
lqw.like(StringUtils.isNotBlank(quantityCount), MatMaterials::getQuantityCount, quantityCount);
// 精确查询
@ -353,33 +355,18 @@ public class MatMaterialsServiceImpl extends ServiceImpl<MatMaterialsMapper, Mat
@Override
@Async
public void create(Long projectId, List<MatMaterialReceiveItemDto> itemList, String nickname) {
public void create(Long projectId, List<MatMaterialReceiveItemDto> itemList, String formCode, String nickname) {
for (MatMaterialReceiveItemDto item : itemList) {
Long materialsId;
MatMaterials one = this.getOne(Wrappers.<MatMaterials>lambdaQuery()
.eq(MatMaterials::getMaterialsName, item.getName())
.eq(MatMaterials::getTypeSpecificationName, item.getSpecification()));
if (one != null) {
materialsId = one.getId();
BigDecimal bigDecimal = new BigDecimal(one.getQuantityCount());
BigDecimal add = item.getQuantity().add(bigDecimal);
one.setQuantityCount(add.toString());
} else {
MatMaterials matMaterials = new MatMaterials();
matMaterials.setMaterialsName(item.getName());
matMaterials.setProjectId(projectId);
matMaterials.setTypeSpecificationName(item.getSpecification());
matMaterials.setWeightId(item.getUnit());
matMaterials.setQuantityCount(item.getQuantity().toString());
matMaterials.setFormCode(formCode);
save(matMaterials);
materialsId = matMaterials.getId();
}
Long materialsId = matMaterials.getId();
MatMaterialsInventoryCreateReq req = new MatMaterialsInventoryCreateReq();
req.setMaterialsId(materialsId);
req.setProjectId(projectId);
req.setOutPut(MatMaterialsInventoryOutPutEnum.PUT.getValue());
@ -418,4 +405,75 @@ public class MatMaterialsServiceImpl extends ServiceImpl<MatMaterialsMapper, Mat
return vo;
}).toList();
}
/**
* 获取材料库存数据列表
*
* @param projectId 项目id
* @return 材料库存数据列表
*/
@Override
public List<MatMaterialsByFormCodeVo> queryMaterialsByFormCode(Long projectId) {
List<MatMaterials> materials = this.lambdaQuery()
.eq(MatMaterials::getProjectId, projectId)
.eq(MatMaterials::getStatus, "0")
.list();
if (CollUtil.isEmpty(materials)) {
return null;
}
List<Long> materialIds = materials.stream()
.filter(material -> StringUtils.isNotBlank(material.getFormCode()))
.map(MatMaterials::getId)
.toList();
List<MatMaterialsInventory> materialsInventories = materialsInventoryService.selectLatestByMaterialIds(materialIds);
Map<Long, MatMaterialsInventory> inventoryMap = materialsInventories.stream().collect(Collectors.toMap(
MatMaterialsInventory::getMaterialsId,
Function.identity(),
(a, b) -> a));
Map<String, List<MatMaterials>> formCodeMap = materials.stream()
.collect(Collectors.groupingBy(MatMaterials::getFormCode));
Set<String> formCodeList = materials.stream().map(MatMaterials::getFormCode).collect(Collectors.toSet());
List<MatMaterialReceive> receiveList = materialReceiveService.lambdaQuery()
.in(MatMaterialReceive::getFormCode, formCodeList)
.list();
Map<String, MatMaterialReceive> receiveMap = receiveList.stream().collect(Collectors.toMap(
MatMaterialReceive::getFormCode,
Function.identity(),
(a, b) -> a));
List<MatMaterialsByFormCodeVo> resultList = new ArrayList<>();
for (Map.Entry<String, List<MatMaterials>> entry : formCodeMap.entrySet()) {
String key = entry.getKey();
List<MatMaterials> value = entry.getValue();
List<MatMaterials> list = value.stream().filter(material -> {
Long materialId = material.getId();
if (inventoryMap.containsKey(materialId)) {
MatMaterialsInventory inventory = inventoryMap.get(materialId);
Long residue = inventory.getResidue();
return residue > 0;
}
return false;
}).toList();
if (CollUtil.isEmpty(list)) {
continue;
}
MatMaterialsByFormCodeVo vo = new MatMaterialsByFormCodeVo();
vo.setFormCode(key);
if (receiveMap.containsKey(key)) {
MatMaterialReceive receive = receiveMap.get(key);
BeanUtils.copyProperties(receive, vo);
}
List<MatMaterialsNumberVo> numberVos = value.stream().map(material -> {
MatMaterialsNumberVo numberVo = new MatMaterialsNumberVo();
BeanUtils.copyProperties(material, numberVo);
Long materialId = material.getId();
if (inventoryMap.containsKey(materialId)) {
numberVo.setInventoryNumber(BigDecimal.valueOf(inventoryMap.get(materialId).getNumber()));
}
return numberVo;
}).toList();
vo.setMaterials(numberVos);
resultList.add(vo);
}
return resultList;
}
}

View File

@ -156,4 +156,9 @@ public class BusProject extends BaseEntity {
@TableLogic
private Long isDelete;
/**
* go项目id
*/
private Long goId;
}

View File

@ -308,7 +308,7 @@ public class BusUserProjectRelevancyServiceImpl extends ServiceImpl<BusUserProje
return new ArrayList<>();
}
Map<Long, List<BusProject>> projectMap = projectService.lambdaQuery()
.select(BusProject::getId, BusProject::getPId, BusProject::getProjectName, BusProject::getShortName)
.select(BusProject::getId, BusProject::getPId, BusProject::getProjectName, BusProject::getShortName, BusProject::getGoId)
.in(BusProject::getId, projectIdList)
.eq(BusProject::getPId, BusProjectConstant.PARENT_ID)
.list()
@ -328,6 +328,7 @@ public class BusUserProjectRelevancyServiceImpl extends ServiceImpl<BusUserProje
loginUserProjectRelevancy.setProjectId(projectId);
loginUserProjectRelevancy.setProjectName(project.getProjectName());
loginUserProjectRelevancy.setShortName(project.getShortName());
loginUserProjectRelevancy.setGoId(project.getGoId());
return loginUserProjectRelevancy;
}
return null;