|
@@ -15,6 +15,7 @@ import com.zkqy.common.core.domain.AjaxResult;
|
|
|
import com.zkqy.common.utils.DateUtils;
|
|
|
import com.zkqy.common.utils.SecurityUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.security.core.parameters.P;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.zkqy.business.mapper.MaterialInventoryMapper;
|
|
|
import com.zkqy.business.domain.MaterialInventory;
|
|
@@ -41,6 +42,7 @@ public class MaterialInventoryServiceImpl implements IMaterialInventoryService
|
|
|
|
|
|
@Autowired
|
|
|
private MaterielMapper materielMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 入库
|
|
|
*
|
|
@@ -223,6 +225,152 @@ public class MaterialInventoryServiceImpl implements IMaterialInventoryService
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 入库
|
|
|
+ *
|
|
|
+ * @param materialInventoryVo 物料库存
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public AjaxResult insertMaterialInventoryTwo(List<MaterialInventoryVo> materialInventoryVo)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ materialInventoryVo.forEach(item->{
|
|
|
+ //创建时间
|
|
|
+ item.setCreateTime(DateUtils.getNowDate());
|
|
|
+ //1、如果有证明当前这个批次的码已经被扫过了
|
|
|
+ InboundRecords inboundRecords = inboundRecordsMapper.selectInboundRecordsByQtCodeNumber(item.getQtCodeNumber());
|
|
|
+ if (inboundRecords == null) {
|
|
|
+ //2、判断是第一次入库还是第二次入库这个同类商品(这是一个连表语句)(同一个批次查询)
|
|
|
+ InboundRecords inboundRecords1=new InboundRecords();
|
|
|
+ inboundRecords1.setLotNumber(item.getLotNumber());
|
|
|
+ inboundRecords1.setMaterielId(item.getMaterialId());
|
|
|
+ List<InboundRecords> inboundRecords2 = inboundRecordsMapper.selectInboundRecordsList(inboundRecords1);
|
|
|
+ //3、判断是走新增还是修改
|
|
|
+ int count = 0;
|
|
|
+ if(inboundRecords2.size()>0){
|
|
|
+ //已经入过库存了,绝对会有这个信息
|
|
|
+ MaterialInventory materialInventory=new MaterialInventory();
|
|
|
+ materialInventory.setMaterialId(item.getMaterialId());
|
|
|
+ List<MaterialInventory> materialInventories = materialInventoryMapper.selectMaterialInventoryList(materialInventory);
|
|
|
+ if(materialInventories.size()>0){
|
|
|
+ //没更新的物料信息
|
|
|
+ MaterialInventory oldMaterialInventory = materialInventories.get(0);
|
|
|
+ //更新物料信息数量
|
|
|
+ oldMaterialInventory.setQuantity(oldMaterialInventory.getQuantity()+item.getQuantity());
|
|
|
+ //执行更新操作
|
|
|
+ count = materialInventoryMapper.updateMaterialInventory(oldMaterialInventory);
|
|
|
+ }
|
|
|
+ //没有入过库走新增操作
|
|
|
+ }else {
|
|
|
+ MaterialInventory materialInventoryObj = new MaterialInventory();
|
|
|
+ materialInventoryObj.setStockNumber(String.valueOf(new Date().getTime()));//库存编号
|
|
|
+ materialInventoryObj.setWarehouseEntryNumber(UUID.randomUUID().toString());//入库单编号
|
|
|
+ materialInventoryObj.setMaterialCode(item.getMaterialCode());//物料编号
|
|
|
+ materialInventoryObj.setQuantity(item.getQuantity());//数量
|
|
|
+ materialInventoryObj.setCreateById(SecurityUtils.getUserId());
|
|
|
+ materialInventoryObj.setLotNumber(item.getLotNumber());//批号
|
|
|
+ materialInventoryObj.setMaterialId(item.getMaterialId());//物料id
|
|
|
+ materialInventoryObj.setCreateTime(new Date());
|
|
|
+ count = materialInventoryMapper.insertMaterialInventory(materialInventoryObj);
|
|
|
+ }
|
|
|
+ if(count>0){
|
|
|
+ InboundRecords inboundRecords3 = new InboundRecords();
|
|
|
+ inboundRecords3.setInboundTime(new Date());//入库时间
|
|
|
+ //物料名称需要根据物料编码查询下
|
|
|
+ Materiel materiel = materielMapper.selectMaterielById(Long.valueOf(item.getMaterialId()));
|
|
|
+ inboundRecords3.setInboundAterialsName(materiel.getMaterielName());//物料名称
|
|
|
+ inboundRecords3.setSpecifications(item.getSpecifications());//规格代号
|
|
|
+ inboundRecords3.setInboundUnit(item.getInboundUnit());//单位
|
|
|
+ inboundRecords3.setInboundQuantity(item.getQuantity().toString());//入库数量
|
|
|
+ inboundRecords3.setInboundLeader(SecurityUtils.getUsername());//仓管员
|
|
|
+ inboundRecords3.setCreateById(SecurityUtils.getUserId());//创建人
|
|
|
+ inboundRecords3.setCreateTime(new Date());//创建时间
|
|
|
+ inboundRecords3.setLotNumber(item.getLotNumber());//批号
|
|
|
+ inboundRecords3.setMaterielId(item.getMaterialId());//母粒id
|
|
|
+ inboundRecords3.setQtCodeNumber(item.getQtCodeNumber());//二维码唯一编码
|
|
|
+ inboundRecordsMapper.insertInboundRecords(inboundRecords3); //插入入库日志信息
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (Exception e) {
|
|
|
+ return AjaxResult.error("入库失败");
|
|
|
+ }
|
|
|
+ return AjaxResult.success("入库成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 出库
|
|
|
+ *
|
|
|
+ * @param materialInventoryVo 物料库存
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public AjaxResult outMaterialInventoryTwo(List<MaterialInventoryVo> materialInventoryVo)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ materialInventoryVo.forEach(item->{
|
|
|
+ item.setCreateTime(DateUtils.getNowDate());
|
|
|
+ //1、没有对应的入库记录
|
|
|
+// InboundRecords inboundRecords = inboundRecordsMapper.selectInboundRecordsByQtCodeNumber(item.getQtCodeNumber());
|
|
|
+// if (inboundRecords == null) {
|
|
|
+// return AjaxResult.error("此货品还没有入库,不能出库");
|
|
|
+// }
|
|
|
+ //2、二维码是否重复使用
|
|
|
+ // OutboundRecords outboundRecords = outboundRecordsMapper.selectOutboundRecordsByQtCodeNumber(materialInventoryVo.getQtCodeNumber());
|
|
|
+ // if (outboundRecords != null) {
|
|
|
+ // return"此货品不能重复出库";
|
|
|
+ // }
|
|
|
+ //3、根据物料编码跟规则查询库存信息
|
|
|
+ MaterialInventory materialInventory=new MaterialInventory();
|
|
|
+ materialInventory.setMaterialId(item.getMaterialId());
|
|
|
+ List<MaterialInventory> materialInventories = materialInventoryMapper.selectMaterialInventoryList(materialInventory);
|
|
|
+ if(materialInventories.size()>0){
|
|
|
+ Double oldQuantity = materialInventories.get(0).getQuantity();
|
|
|
+// if(item.getQuantity()>oldQuantity){
|
|
|
+// return AjaxResult.error("库存不足"+item.getQuantity()+"个");
|
|
|
+// }
|
|
|
+ Double outboundQuantity = item.getQuantity();
|
|
|
+ //出库后剩余数量
|
|
|
+ Double newQuantity =oldQuantity-outboundQuantity;
|
|
|
+ //更新数量
|
|
|
+ MaterialInventory doubleMaterialInventory = new MaterialInventory();
|
|
|
+ doubleMaterialInventory.setQuantity(newQuantity);
|
|
|
+ doubleMaterialInventory.setMaterialId(item.getMaterialId());
|
|
|
+ //执行sql语句
|
|
|
+ int count = materialInventoryMapper.updateMaterialInventoryByMaterialId(doubleMaterialInventory);
|
|
|
+ //代表出库成功
|
|
|
+ if(count>0){
|
|
|
+ OutboundRecords outboundRecords1 = new OutboundRecords();
|
|
|
+ outboundRecords1.setOutboundTime(new Date());//出库时间
|
|
|
+ //物料名称需要根据物料编码查询下
|
|
|
+ Materiel materiel = materielMapper.selectMaterielById(Long.valueOf(item.getMaterialId()));
|
|
|
+ outboundRecords1.setQtCodeNumber(item.getQtCodeNumber());
|
|
|
+ outboundRecords1.setOutboundAterialsName(materiel.getMaterielName());//物料名称
|
|
|
+ outboundRecords1.setOutboundNo(UUID.randomUUID().toString());//出库编号
|
|
|
+ outboundRecords1.setSpecifications(item.getSpecifications());//规格代号
|
|
|
+ outboundRecords1.setOutboundUnit(item.getInboundUnit());//单位
|
|
|
+ outboundRecords1.setOutboundQuantity(item.getQuantity().toString());//出库数量
|
|
|
+ outboundRecords1.setOutboundLeader(SecurityUtils.getUsername());//仓管员
|
|
|
+ outboundRecords1.setCreateById(SecurityUtils.getUserId());//创建人
|
|
|
+ outboundRecords1.setCreateTime(new Date());//创建时间
|
|
|
+ outboundRecords1.setLotNumber(item.getLotNumber());//批号
|
|
|
+ outboundRecords1.setQtCodeNumber(item.getQtCodeNumber());//二维码
|
|
|
+ outboundRecords1.setMaterielId(item.getMaterialId());//母粒iD
|
|
|
+ outboundRecordsMapper.insertOutboundRecords(outboundRecords1); //插出库库日志信息
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ } catch (Exception e) {
|
|
|
+// throw new RuntimeException(e);
|
|
|
+ return AjaxResult.error("出库失败");
|
|
|
+ }
|
|
|
+ return AjaxResult.success("出库成功");
|
|
|
+ }
|
|
|
/**
|
|
|
* 查询物料库存
|
|
|
*
|