|
@@ -0,0 +1,333 @@
|
|
|
+package com.zkqy.amichi.service.impl;
|
|
|
+
|
|
|
+import com.zkqy.amichi.domain.*;
|
|
|
+import com.zkqy.amichi.domain.vo.StockInOrderAndOrderDetail;
|
|
|
+import com.zkqy.amichi.mapper.*;
|
|
|
+import com.zkqy.amichi.service.IStockInOrderService;
|
|
|
+import com.zkqy.common.core.domain.AjaxResult;
|
|
|
+import com.zkqy.common.utils.DateUtils;
|
|
|
+import com.zkqy.common.utils.SecurityUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 半成品入库单主Service业务层处理
|
|
|
+ *
|
|
|
+ * @author ruoyi
|
|
|
+ * @date 2025-05-14
|
|
|
+ */
|
|
|
+@Service("StockOutOrderServiceImpl")
|
|
|
+public class StockOutOrderServiceImpl implements IStockInOrderService
|
|
|
+{
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StockInOrderMapper stockInOrderMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StockInOrderDetailMapper stockInOrderDetailMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MaterialsInventoryMapper materialsInventoryMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StockInRecordMapper stockInRecordMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StockOutRecordMapper stockOutRecordMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询半成品入库单主
|
|
|
+ *
|
|
|
+ * @param id 半成品入库单主主键
|
|
|
+ * @return 半成品入库单主
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public StockInOrderAndOrderDetail selectStockInOrderById(Long id)
|
|
|
+ {
|
|
|
+ StockInOrderAndOrderDetail andOrderDetail=new StockInOrderAndOrderDetail();
|
|
|
+ StockInOrder stockInOrder = stockInOrderMapper.selectStockInOrderById(id);
|
|
|
+ BeanUtils.copyProperties(stockInOrder,andOrderDetail);
|
|
|
+ //根据入库单号查询入库单详情信息
|
|
|
+ StockInOrderDetail stockInOrderDetail=new StockInOrderDetail();
|
|
|
+ stockInOrderDetail.setStockInOrderId(id);
|
|
|
+ List<StockInOrderDetail> stockInOrderDetails = stockInOrderDetailMapper.selectStockInOrderDetailList(stockInOrderDetail);
|
|
|
+ andOrderDetail.setOrderDetailList(stockInOrderDetails);
|
|
|
+ return andOrderDetail;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询半成品入库单主列表
|
|
|
+ *
|
|
|
+ * @param stockInOrder 半成品入库单主
|
|
|
+ * @return 半成品入库单主
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<StockInOrder> selectStockInOrderList(StockInOrder stockInOrder)
|
|
|
+ {
|
|
|
+ return stockInOrderMapper.selectStockInOrderList(stockInOrder);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增半成品入库单主
|
|
|
+ *
|
|
|
+ * @param stockInOrder 半成品入库单主
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int insertStockInOrder(StockInOrder stockInOrder)
|
|
|
+ {
|
|
|
+ stockInOrder.setCreateTime(DateUtils.getNowDate());
|
|
|
+ return stockInOrderMapper.insertStockInOrder(stockInOrder);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改半成品出库单主
|
|
|
+ *
|
|
|
+ * @param stockInOrder 半成品入库单主
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public AjaxResult updateStockInOrder(StockInOrderAndOrderDetail stockInOrder)
|
|
|
+ {
|
|
|
+ stockInOrder.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ //先查询入库明细信息
|
|
|
+ stockInOrder.getDetailList().stream().forEach(item->{
|
|
|
+ //物料编码
|
|
|
+ String materialCode = item.getMaterialCode();
|
|
|
+ //查询物料信息
|
|
|
+ MaterialsInventory materialsInventory=new MaterialsInventory();
|
|
|
+ materialsInventory.setMaterialCode(materialCode);
|
|
|
+ List<MaterialsInventory> materialsInventories = materialsInventoryMapper.selectMaterialsInventoryList(materialsInventory);
|
|
|
+ if(materialsInventories.size()>0){
|
|
|
+ Long stockQuantity = materialsInventories.get(0).getStockQuantity();
|
|
|
+ Integer hfkc=Integer.parseInt(stockQuantity.toString())+Integer.parseInt(item.getInQuantity().toString());
|
|
|
+ MaterialsInventory materialsInventoryUpdate=new MaterialsInventory();
|
|
|
+ materialsInventoryUpdate.setMaterialCode(item.getMaterialCode());
|
|
|
+ materialsInventoryUpdate.setStockQuantity(hfkc.longValue());
|
|
|
+ //修正库存
|
|
|
+ materialsInventoryMapper.updateMaterialsInventoryByMaterialCode(materialsInventoryUpdate);
|
|
|
+ }//库存数为0但是不可能是删除的
|
|
|
+ });
|
|
|
+ //先删除老的出库明细数据
|
|
|
+// List<Long> collect = stockInOrder.getOrderDetailList().stream().map(StockInOrderDetail::getId).collect(Collectors.toList());
|
|
|
+ stockInOrderDetailMapper.deleteStockInOrderDetailByStockInOrderId(stockInOrder.getId());
|
|
|
+
|
|
|
+ //删除对应的入库日志数据
|
|
|
+ stockOutRecordMapper.deleteStockInRecordByRkdbh(stockInOrder.getOrderNo());//入库单id
|
|
|
+
|
|
|
+ //新增入库明细数据
|
|
|
+ stockInOrder.getDetailList().forEach(item->{
|
|
|
+ //添加入库明细信息
|
|
|
+ stockInOrderDetailMapper.insertStockInOrderDetail(item);
|
|
|
+ //添加入库日志信息
|
|
|
+ StockOutRecord stockOutRecord=new StockOutRecord();
|
|
|
+ stockOutRecord.setMaterialCode(item.getMaterialCode());//物料编码
|
|
|
+ stockOutRecord.setMaterialName(item.getMaterialName());//物料名称
|
|
|
+ stockOutRecord.setModel(item.getModel());//型号
|
|
|
+ stockOutRecord.setSpecification(item.getSpecification());//规格
|
|
|
+ stockOutRecord.setOutQuantity(item.getInQuantity());//入库数量
|
|
|
+ stockOutRecord.setOperator(SecurityUtils.getUsername());//操作人
|
|
|
+ stockOutRecord.setCreateTime(new Date());//时间
|
|
|
+ stockOutRecord.setCreateBy(SecurityUtils.getUsername());
|
|
|
+ stockOutRecord.setCreateById(SecurityUtils.getUserId());
|
|
|
+ stockOutRecord.setInboundType("手动出库");
|
|
|
+ stockOutRecord.setRkdbh(stockInOrder.getOrderNo());
|
|
|
+ stockOutRecordMapper.insertStockOutRecord(stockOutRecord);
|
|
|
+
|
|
|
+ //更新库存信息
|
|
|
+ MaterialsInventory materialsInventory=new MaterialsInventory();
|
|
|
+ materialsInventory.setMaterialCode(item.getMaterialCode());
|
|
|
+ List<MaterialsInventory> materialsInventories = materialsInventoryMapper.selectMaterialsInventoryList(materialsInventory);
|
|
|
+ if(materialsInventories.size()>0) {
|
|
|
+ //修改库存数量
|
|
|
+ MaterialsInventory materialsInventoryUpdate = materialsInventories.get(0);
|
|
|
+ Integer newSl=Integer.parseInt(materialsInventoryUpdate.getStockQuantity().toString())-Integer.parseInt(item.getInQuantity().toString());
|
|
|
+ materialsInventoryUpdate.setStockQuantity(Long.parseLong(newSl.toString()));
|
|
|
+ materialsInventoryUpdate.setUpdateTime(new Date());//修改时间
|
|
|
+ materialsInventoryMapper.updateMaterialsInventory(materialsInventoryUpdate);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //更新入库单数据
|
|
|
+ int i = stockInOrderMapper.updateStockInOrder(stockInOrder);
|
|
|
+ if(i>0){
|
|
|
+ return AjaxResult.success("修改出库单信息成功");
|
|
|
+ }else {
|
|
|
+ return AjaxResult.error("修改出库单信息失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量删除半成品入库单主
|
|
|
+ *
|
|
|
+ * @param ids 需要删除的半成品入库单主主键
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int deleteStockInOrderByIds(Long[] ids)
|
|
|
+ {
|
|
|
+ return stockInOrderMapper.deleteStockInOrderByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除半成品入库单主信息
|
|
|
+ *
|
|
|
+ * @param id 半成品入库单主主键
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int deleteStockInOrderById(Long id)
|
|
|
+ {
|
|
|
+ return stockInOrderMapper.deleteStockInOrderById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加订单和订单明细
|
|
|
+ * @param stockInOrder
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public int insertStockInOrderAndDetail(StockInOrderAndOrderDetail stockInOrder) {
|
|
|
+ StockInOrder stockInOrderCopy=new StockInOrder();
|
|
|
+ BeanUtils.copyProperties(stockInOrder,stockInOrderCopy);
|
|
|
+ int i = stockInOrderMapper.insertStockInOrder(stockInOrderCopy);//添加入库单信息
|
|
|
+ List<String> stringList=new ArrayList<>();
|
|
|
+
|
|
|
+ //操作入库单明细信息
|
|
|
+ List<StockInOrderDetail> stockInOrderDetailList = stockInOrder.getOrderDetailList();
|
|
|
+ stockInOrderDetailList.forEach(item->{
|
|
|
+
|
|
|
+ item.setStockInOrderId(stockInOrderCopy.getId());
|
|
|
+ //添加入库单明细信息
|
|
|
+ stockInOrderDetailMapper.insertStockInOrderDetail(item);
|
|
|
+
|
|
|
+ //查询判断是这个入库是新增还是修改
|
|
|
+ MaterialsInventory materialsInventory=new MaterialsInventory();
|
|
|
+ materialsInventory.setMaterialCode(item.getMaterialCode());
|
|
|
+ List<MaterialsInventory> materialsInventories = materialsInventoryMapper.selectMaterialsInventoryList(materialsInventory);
|
|
|
+
|
|
|
+ if(materialsInventories.size()>0){
|
|
|
+ //修改入库产品库存数量
|
|
|
+ Long stockQuantity = materialsInventories.get(0).getStockQuantity();//老库存数量
|
|
|
+ Integer newStockQuantity=Integer.parseInt(stockQuantity.toString())+Integer.parseInt(item.getInQuantity().toString());
|
|
|
+ MaterialsInventory materialsInventoryUpdate=new MaterialsInventory();
|
|
|
+ materialsInventoryUpdate.setMaterialCode(materialsInventories.get(0).getMaterialCode());
|
|
|
+ materialsInventoryUpdate.setStockQuantity(Long.valueOf(newStockQuantity.toString()));
|
|
|
+ materialsInventoryMapper.updateMaterialsInventoryByMaterialCode(materialsInventoryUpdate);
|
|
|
+
|
|
|
+ StockInRecord stockInRecord=new StockInRecord();
|
|
|
+ stockInRecord.setMaterialCode(item.getMaterialCode()); //物料编码
|
|
|
+ stockInRecord.setMaterialName(item.getMaterialName()); //物料名称
|
|
|
+ stockInRecord.setModel(item.getModel());//型号
|
|
|
+ stockInRecord.setSpecification(item.getSpecification());//规格
|
|
|
+ stockInRecord.setInQuantity(item.getInQuantity());//入库数量
|
|
|
+ stockInRecord.setCreateTime(new Date());//创建时间
|
|
|
+ stockInRecord.setInventoryId(materialsInventories.get(0).getId());
|
|
|
+ stockInRecord.setCreateBy(SecurityUtils.getUsername());//操作人
|
|
|
+ stockInRecord.setCreateById(SecurityUtils.getUserId());//操作人
|
|
|
+ stockInRecord.setInboundType("手动入库");
|
|
|
+ stockInRecord.setRkdbh(stockInOrder.getOrderNo());
|
|
|
+
|
|
|
+ stockInRecordMapper.insertStockInRecord(stockInRecord);
|
|
|
+ }else {
|
|
|
+ //新增产品入库数量
|
|
|
+ MaterialsInventory materialsInventoryInsert=new MaterialsInventory();
|
|
|
+ materialsInventoryInsert.setMaterialCode(item.getMaterialCode());
|
|
|
+ materialsInventoryInsert.setMaterialName(item.getMaterialName());
|
|
|
+ materialsInventoryInsert.setModel(item.getModel());
|
|
|
+ materialsInventoryInsert.setSpecification(item.getSpecification());
|
|
|
+ materialsInventoryInsert.setStockQuantity(item.getInQuantity()); //入库数量
|
|
|
+ materialsInventoryInsert.setCreateById(SecurityUtils.getUserId());//入库人id
|
|
|
+ materialsInventoryInsert.setCreateTime(new Date());//入库时间
|
|
|
+ materialsInventoryInsert.setCreateBy(SecurityUtils.getUsername());//入库人信息
|
|
|
+ //新增入库信息
|
|
|
+ materialsInventoryMapper.insertMaterialsInventory(materialsInventoryInsert);
|
|
|
+
|
|
|
+ StockInRecord stockInRecord=new StockInRecord();
|
|
|
+ stockInRecord.setMaterialCode(item.getMaterialCode()); //物料编码
|
|
|
+ stockInRecord.setMaterialName(item.getMaterialName()); //物料名称
|
|
|
+ stockInRecord.setModel(item.getModel());//型号
|
|
|
+ stockInRecord.setSpecification(item.getSpecification());//规格
|
|
|
+ stockInRecord.setInQuantity(item.getInQuantity());//入库数量
|
|
|
+ stockInRecord.setCreateTime(new Date());//创建时间
|
|
|
+ stockInRecord.setInventoryId(stockInOrderCopy.getId());
|
|
|
+ stockInRecord.setCreateBy(SecurityUtils.getUsername());//操作人
|
|
|
+ stockInRecord.setCreateById(SecurityUtils.getUserId());//操作人
|
|
|
+ stockInRecord.setInboundType("手动入库");
|
|
|
+ stockInRecord.setRkdbh(stockInOrder.getOrderNo());
|
|
|
+ stockInRecordMapper.insertStockInRecord(stockInRecord);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return stockInOrder.getOrderDetailList().size();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public AjaxResult insertStockIOutOrderAndDetail(StockInOrderAndOrderDetail stockInOrder) {
|
|
|
+ StockInOrder stockInOrderCopy=new StockInOrder();
|
|
|
+ BeanUtils.copyProperties(stockInOrder,stockInOrderCopy);
|
|
|
+ int i = stockInOrderMapper.insertStockInOrder(stockInOrderCopy);//添加入库单信息
|
|
|
+ List<String> stringList=new ArrayList<>();
|
|
|
+ //查询当前要出库的产品信息
|
|
|
+ stockInOrder.getOrderDetailList().stream().forEach(item->{
|
|
|
+ MaterialsInventory materialsInventory=new MaterialsInventory();
|
|
|
+ materialsInventory.setMaterialCode(item.getMaterialCode());
|
|
|
+ List<MaterialsInventory> materialsInventories = materialsInventoryMapper.selectMaterialsInventoryList(materialsInventory);
|
|
|
+ if(materialsInventories.size()<=0){
|
|
|
+ stringList.add(item.getMaterialCode());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if(stringList.size()>0){
|
|
|
+ return AjaxResult.error("物料明细中,物料编码为"+stringList.stream().collect(Collectors.joining(","))+"未存在对应的库存信息");
|
|
|
+ }
|
|
|
+ //操作入库单明细信息
|
|
|
+ List<StockInOrderDetail> stockInOrderDetailList = stockInOrder.getOrderDetailList();
|
|
|
+ stockInOrderDetailList.forEach(item->{
|
|
|
+
|
|
|
+ item.setStockInOrderId(stockInOrderCopy.getId());
|
|
|
+ //添加入库单明细信息
|
|
|
+ stockInOrderDetailMapper.insertStockInOrderDetail(item);
|
|
|
+
|
|
|
+ //查询判断是这个入库是新增还是修改
|
|
|
+ MaterialsInventory materialsInventory=new MaterialsInventory();
|
|
|
+ materialsInventory.setMaterialCode(item.getMaterialCode());
|
|
|
+ List<MaterialsInventory> materialsInventories = materialsInventoryMapper.selectMaterialsInventoryList(materialsInventory);
|
|
|
+
|
|
|
+ if(materialsInventories.size()>0){
|
|
|
+ //修改入库产品库存数量
|
|
|
+ Long stockQuantity = materialsInventories.get(0).getStockQuantity();//老库存数量
|
|
|
+ Integer newStockQuantity=Integer.parseInt(stockQuantity.toString())-Integer.parseInt(item.getInQuantity().toString());
|
|
|
+ MaterialsInventory materialsInventoryUpdate=new MaterialsInventory();
|
|
|
+ materialsInventoryUpdate.setMaterialCode(materialsInventories.get(0).getMaterialCode());
|
|
|
+ materialsInventoryUpdate.setStockQuantity(Long.valueOf(newStockQuantity.toString()));
|
|
|
+ materialsInventoryMapper.updateMaterialsInventoryByMaterialCode(materialsInventoryUpdate);
|
|
|
+
|
|
|
+ StockOutRecord stockOutRecord=new StockOutRecord();
|
|
|
+ stockOutRecord.setMaterialCode(item.getMaterialCode()); //物料编码
|
|
|
+ stockOutRecord.setMaterialName(item.getMaterialName()); //物料名称
|
|
|
+ stockOutRecord.setModel(item.getModel());//型号
|
|
|
+ stockOutRecord.setSpecification(item.getSpecification());//规格
|
|
|
+ stockOutRecord.setOutQuantity(item.getInQuantity());//入库数量
|
|
|
+ stockOutRecord.setCreateTime(new Date());//创建时间
|
|
|
+ stockOutRecord.setInventoryId(materialsInventories.get(0).getId());
|
|
|
+ stockOutRecord.setCreateBy(SecurityUtils.getUsername());//操作人
|
|
|
+ stockOutRecord.setOperator(SecurityUtils.getUsername());//操作人
|
|
|
+ stockOutRecord.setCreateById(SecurityUtils.getUserId());//操作人id
|
|
|
+ stockOutRecord.setInboundType("手动出库");
|
|
|
+ stockOutRecord.setRkdbh(stockInOrder.getOrderNo());
|
|
|
+
|
|
|
+ stockOutRecordMapper.insertStockOutRecord(stockOutRecord);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return AjaxResult.success("出库成功");
|
|
|
+ }
|
|
|
+}
|