From 40bf6c9d658c70294bc55fc7daaf4bfcfd075355 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期五, 12 九月 2025 15:57:23 +0800
Subject: [PATCH] 供应商erp

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TErpSupplierWarehousingController.java    |   11 ++
 ruoyi-system/src/main/java/com/ruoyi/system/mapper/TErpGoodsMapper.java                          |    3 
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpSupplierWarehousingServiceImpl.java |   94 +++++++++++++++++++++--
 ruoyi-system/src/main/java/com/ruoyi/system/dto/OutboundGoodsDto.java                            |   34 ++++++++
 ruoyi-system/src/main/resources/mapper/system/TErpGoodsMapper.xml                                |    3 
 ruoyi-system/src/main/java/com/ruoyi/system/service/TErpSupplierWarehousingService.java          |    3 
 ruoyi-system/src/main/java/com/ruoyi/system/query/TErpGoodsInventoryQuery.java                   |    2 
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpGoodsServiceImpl.java               |    8 +
 ruoyi-system/src/main/java/com/ruoyi/system/model/TErpSupplierOutbound.java                      |    6 
 ruoyi-system/src/main/java/com/ruoyi/system/dto/OutboundGoodsNextDto.java                        |   27 ++++++
 10 files changed, 176 insertions(+), 15 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TErpSupplierWarehousingController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TErpSupplierWarehousingController.java
index 84d697f..c2d34f1 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TErpSupplierWarehousingController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TErpSupplierWarehousingController.java
@@ -9,6 +9,7 @@
 import com.ruoyi.framework.web.service.TokenService;
 import com.ruoyi.system.dto.InventoryDto;
 import com.ruoyi.system.dto.InventoryGoodsDto;
+import com.ruoyi.system.dto.OutboundGoodsDto;
 import com.ruoyi.system.dto.WarehousingGoodsDto;
 import com.ruoyi.system.model.TCrmClinic;
 import com.ruoyi.system.model.TCrmSupplier;
@@ -117,6 +118,14 @@
         return R.ok();
     }
 
+    @ApiOperation(value = "供应商库存出库")
+    @PostMapping(value = "/outbountGoods")
+    public R<?> outbountGoods(@RequestBody @Valid OutboundGoodsDto dto) {
+        SysUser user = tokenService.getLoginUser().getUser();
+        erpSupplierWarehousingService.outbountGoods(dto,user);
+        return R.ok();
+    }
+
 
     @ApiOperation(value = "有效期预警")
     @PostMapping(value = "/validityPeriodWarning")
@@ -145,7 +154,7 @@
     }
 
 
-    @ApiOperation(value = "供应商 盘点 商品选择")
+    @ApiOperation(value = "供应商 盘点 出库 商品选择")
     @PostMapping(value = "/pageInventoryGoodsPageList")
     public R<PageInfo<TErpGoodsInventoryVO>> pageInventoryGoodsPageList(@RequestBody @Valid TErpGoodsInventoryQuery query) {
         SysUser user = tokenService.getLoginUser().getUser();
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/dto/OutboundGoodsDto.java b/ruoyi-system/src/main/java/com/ruoyi/system/dto/OutboundGoodsDto.java
new file mode 100644
index 0000000..5691d6b
--- /dev/null
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/dto/OutboundGoodsDto.java
@@ -0,0 +1,34 @@
+package com.ruoyi.system.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import java.math.BigDecimal;
+import java.util.List;
+
+@Data
+@ApiModel(value = "商品出库dto")
+public class OutboundGoodsDto {
+
+    @ApiModelProperty(value = "入库仓库id")
+    @NotBlank(message = "入库仓库id不能为空")
+    private String warehouseId;
+
+    @ApiModelProperty(value = "出库原因")
+    @NotBlank(message = "出库原因不能为空")
+    private String outboundReason;
+
+    @ApiModelProperty(value = "出库类型 1=报损 2=到期 3=失效 4=召回 5=其他 6=盘点出库 7=购买出库")
+    @NotNull(message = "出库类型不能为空")
+    private Integer outboundType;
+
+
+    @ApiModelProperty(value = "商品出库二级dto")
+    private List<OutboundGoodsNextDto> outboundGoodsNextDtos;
+
+
+
+}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/dto/OutboundGoodsNextDto.java b/ruoyi-system/src/main/java/com/ruoyi/system/dto/OutboundGoodsNextDto.java
new file mode 100644
index 0000000..c03641b
--- /dev/null
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/dto/OutboundGoodsNextDto.java
@@ -0,0 +1,27 @@
+package com.ruoyi.system.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+@Data
+@ApiModel(value = "商品出库二级dto")
+public class OutboundGoodsNextDto {
+
+    @ApiModelProperty(value = "批次id")
+    @NotBlank(message = "入库仓库id不能为空")
+    private String batchId;
+
+    @ApiModelProperty(value = "出库数量")
+    @NotNull(message = "出库数量不能为空")
+    private Integer num;
+
+
+
+
+
+}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TErpGoodsMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TErpGoodsMapper.java
index c64a758..6916c7d 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TErpGoodsMapper.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/TErpGoodsMapper.java
@@ -10,6 +10,7 @@
 import com.ruoyi.system.vo.TErpGoodsVO;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -26,5 +27,5 @@
 
     List<TErpGoodsVO> listExport(@Param("query") TErpGoodsQuery query, @Param("user") SysUser user);
 
-    List<TErpGoodsInventoryVO> pageInventoryGoodsPageList(@Param("query") TErpGoodsInventoryQuery query, @Param("pageInfo") PageInfo<TErpGoodsInventoryVO> pageInfo, @Param("user") SysUser user, @Param("supplierClinicId") String supplierClinicId);
+    List<TErpGoodsInventoryVO> pageInventoryGoodsPageList(@Param("query") TErpGoodsInventoryQuery query, @Param("pageInfo") PageInfo<TErpGoodsInventoryVO> pageInfo, @Param("user") SysUser user, @Param("supplierClinicId") String supplierClinicId, @Param("time") Date time);
 }
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/model/TErpSupplierOutbound.java b/ruoyi-system/src/main/java/com/ruoyi/system/model/TErpSupplierOutbound.java
index 9c9e189..a9a6af8 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/model/TErpSupplierOutbound.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/model/TErpSupplierOutbound.java
@@ -54,9 +54,9 @@
     @TableField("outbound_reason")
     private String outboundReason;
 
-    @ApiModelProperty(value = "商品id")
-    @TableField("goods_id")
-    private String goodsId;
+//    @ApiModelProperty(value = "商品id")
+//    @TableField("goods_id")
+//    private String goodsId;
 
 
 }
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/query/TErpGoodsInventoryQuery.java b/ruoyi-system/src/main/java/com/ruoyi/system/query/TErpGoodsInventoryQuery.java
index e647ec4..bf24c79 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/query/TErpGoodsInventoryQuery.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/query/TErpGoodsInventoryQuery.java
@@ -33,6 +33,8 @@
     @NotBlank(message = "仓库id不能为空")
     private String warehouseId;
 
+    @ApiModelProperty(value = "有效期预警 出库使用 条件1  其他不传")
+    private Integer type;
 
 
 }
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/TErpSupplierWarehousingService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/TErpSupplierWarehousingService.java
index de8134c..82493e8 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/TErpSupplierWarehousingService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/TErpSupplierWarehousingService.java
@@ -3,6 +3,7 @@
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.ruoyi.common.basic.PageInfo;
 import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.system.dto.OutboundGoodsDto;
 import com.ruoyi.system.dto.WarehousingGoodsDto;
 import com.ruoyi.system.model.TErpSupplierWarehousing;
 import com.ruoyi.system.query.TErpGoodsQuery;
@@ -38,4 +39,6 @@
 
     List<InventoryDetailVo> detailInventory(String id, SysUser user);
 
+    void outbountGoods(@Valid OutboundGoodsDto dto, SysUser user);
+
 }
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpGoodsServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpGoodsServiceImpl.java
index 646aef0..2a29529 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpGoodsServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpGoodsServiceImpl.java
@@ -21,7 +21,9 @@
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.time.LocalDateTime;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -145,8 +147,12 @@
                     .last("LIMIT 1"));
             supplierClinicId =crmClinic.getId();
         }
+
+        // 当前时间一个月后
+        Date endDate = DateUtils.addMonths(DateUtils.getNowDate(), 1);
+
         PageInfo<TErpGoodsInventoryVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
-        List<TErpGoodsInventoryVO> list = this.baseMapper.pageInventoryGoodsPageList(query, pageInfo, user,supplierClinicId);
+        List<TErpGoodsInventoryVO> list = this.baseMapper.pageInventoryGoodsPageList(query, pageInfo, user,supplierClinicId,endDate);
         if (list.isEmpty()) {
             return pageInfo;
         }
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpSupplierWarehousingServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpSupplierWarehousingServiceImpl.java
index 63c6b2b..49a3e7b 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpSupplierWarehousingServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpSupplierWarehousingServiceImpl.java
@@ -4,8 +4,11 @@
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.ruoyi.common.basic.PageInfo;
 import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.core.exception.ServiceException;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.uuid.IdUtils;
+import com.ruoyi.system.dto.OutboundGoodsDto;
+import com.ruoyi.system.dto.OutboundGoodsNextDto;
 import com.ruoyi.system.dto.WarehousingGoodsDto;
 import com.ruoyi.system.dto.WarehousingGoodsNextDto;
 import com.ruoyi.system.mapper.*;
@@ -378,32 +381,43 @@
                 BigDecimal subtract = BigDecimal.ZERO;
             List<TErpSupplierInventoryGoods> tErpSupplierInventoryGoodsList = tErpSupplierInventoryGoods.stream().filter(t -> t.getInventoryId().equals(pageInventoryListVo.getId())).collect(Collectors.toList());
             for (TErpSupplierInventoryGoods tErpSupplierInventoryGoods1 : tErpSupplierInventoryGoodsList) {
+
+
                 if(tErpSupplierInventoryGoods1!=null){
                     // 盘盈 查入库
                     if(tErpSupplierInventoryGoods1.getInventoryType()==1){
                         TErpSupplierWarehousing tErpSupplierWarehousing = erpSupplierWarehousingMapper.selectById(tErpSupplierInventoryGoods1.getWarehousingId());
-                        List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousingBatch>().eq(TErpSupplierWarehousingBatch::getWarehousingId, tErpSupplierWarehousing.getId()));
-                        int sum = tErpSupplierWarehousingBatches.stream().mapToInt(TErpSupplierWarehousingBatch::getWarehousingNumber).sum();
+//                        List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousingBatch>().eq(TErpSupplierWarehousingBatch::getWarehousingId, tErpSupplierWarehousing.getId()));
+//                        int sum = tErpSupplierWarehousingBatches.stream().mapToInt(TErpSupplierWarehousingBatch::getWarehousingNumber).sum();
                         String goodsId = tErpSupplierWarehousing.getGoodsId();
                         TErpGoods goods = erpGoodsMapper.selectById(goodsId);
-                        BigDecimal multiply = goods.getSalesAmount().multiply(new BigDecimal(sum));
+                        int count = tErpSupplierInventoryGoods1.getInventoryCount() - tErpSupplierInventoryGoods1.getDamagedCount();
+                        BigDecimal multiply = goods.getSalesAmount().multiply(new BigDecimal(count));
                         add = add.add(multiply);
                     }else {
                         // 盘亏 查出库
                         TErpSupplierOutbound tErpSupplierOutbound = erpSupplierOutboundMapper.selectById(tErpSupplierInventoryGoods1.getWarehousingId());
 
                         List<TErpSupplierOutboundGoods> tErpSupplierOutboundGoods = erpSupplierOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierOutboundGoods>().eq(TErpSupplierOutboundGoods::getOutboundId, tErpSupplierOutbound.getId()));
-                        int sum = tErpSupplierOutboundGoods.stream().mapToInt(TErpSupplierOutboundGoods::getOutboundCount).sum();
-                        String goodsId = tErpSupplierOutbound.getGoodsId();
-                        TErpGoods goods = erpGoodsMapper.selectById(goodsId);
-                        BigDecimal multiply = goods.getSalesAmount().multiply(new BigDecimal(sum));
-                        subtract = subtract.add(multiply);
+                        for (TErpSupplierOutboundGoods tErpSupplierOutboundGood : tErpSupplierOutboundGoods) {
+                            TErpSupplierWarehousing tErpSupplierWarehousing = erpSupplierWarehousingMapper.selectById(tErpSupplierOutboundGood.getWarehousingId());
+                            String goodsId = tErpSupplierWarehousing.getGoodsId();
+                            TErpGoods goods = erpGoodsMapper.selectById(goodsId);
+                            int count = tErpSupplierInventoryGoods1.getInventoryCount() - tErpSupplierInventoryGoods1.getDamagedCount();
+                            BigDecimal multiply = goods.getSalesAmount().multiply(new BigDecimal(count));
+                            add = add.add(multiply);
+                        }
+//                        int sum = tErpSupplierOutboundGoods.stream().mapToInt(TErpSupplierOutboundGoods::getOutboundCount).sum();
+//                        String goodsId = tErpSupplierOutbound.getGoodsId();
+//                        TErpGoods goods = erpGoodsMapper.selectById(goodsId);
+//                        BigDecimal multiply = goods.getSalesAmount().multiply(new BigDecimal(sum));
+//                        subtract = subtract.add(multiply);
                     }
                 }
             }
             int size = tErpSupplierInventoryGoodsList.stream().map(TErpSupplierInventoryGoods::getGoodsId).collect(Collectors.toSet()).size();
             pageInventoryListVo.setNum(size);
-            pageInventoryListVo.setTotalPrice(add.subtract(subtract));
+            pageInventoryListVo.setTotalPrice(add);
 
         }
 
@@ -456,4 +470,66 @@
 
         return Collections.emptyList();
     }
+
+    @Override
+    public void outbountGoods(OutboundGoodsDto dto, SysUser user) {
+        Integer roleType = user.getRoleType();
+        String supplierClinicId = null;
+        if(roleType == 4){
+            // 供应商
+            TCrmSupplier crmSupplier = crmSupplierMapper.selectOne(Wrappers.lambdaQuery(TCrmSupplier.class)
+                    .eq(TCrmSupplier::getUserId, user.getUserId())
+                    .last("LIMIT 1"));
+            supplierClinicId =crmSupplier.getId();
+        }
+        if(roleType == 5){
+            // 诊所
+            TCrmClinic crmClinic = crmClinicMapper.selectOne(Wrappers.lambdaQuery(TCrmClinic.class)
+                    .eq(TCrmClinic::getUserId, user.getUserId())
+                    .last("LIMIT 1"));
+            supplierClinicId =crmClinic.getId();
+        }
+        BigDecimal add = new BigDecimal(0);
+        ArrayList<TErpSupplierOutboundGoods> arrayList = new ArrayList<>();
+        // 1 判断库存是否足够  2添加出库记录 3添加出库子记录
+        List<OutboundGoodsNextDto> outboundGoodsNextDtos = dto.getOutboundGoodsNextDtos();
+        for (OutboundGoodsNextDto outboundGoodsNextDto : outboundGoodsNextDtos) {
+            TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch = erpSupplierWarehousingBatchMapper.selectById(outboundGoodsNextDto.getBatchId());
+            List<TErpSupplierOutboundGoods> tErpSupplierOutboundGoods = erpSupplierOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierOutboundGoods>().eq(TErpSupplierOutboundGoods::getWarehousingBatchId, outboundGoodsNextDto.getBatchId()));
+            int sum = tErpSupplierOutboundGoods.stream().mapToInt(TErpSupplierOutboundGoods::getOutboundCount).sum();
+
+            int count = tErpSupplierWarehousingBatch.getWarehousingNumber() - sum;
+            if(count<outboundGoodsNextDto.getNum()){
+                throw new ServiceException("批次号:"+tErpSupplierWarehousingBatch.getBatchNumber()+"库存不足");
+            }
+            TErpSupplierWarehousing tErpSupplierWarehousing = erpSupplierWarehousingMapper.selectById(tErpSupplierWarehousingBatch.getWarehousingId());
+            TErpGoods goods = erpGoodsMapper.selectById(tErpSupplierWarehousing.getGoodsId());
+            BigDecimal multiply = goods.getSalesAmount().multiply(BigDecimal.valueOf(outboundGoodsNextDto.getNum()));
+
+            TErpSupplierOutboundGoods tErpSupplierOutboundGoods1 = new TErpSupplierOutboundGoods();
+            tErpSupplierOutboundGoods1.setWarehousingId(dto.getWarehouseId());
+            tErpSupplierOutboundGoods1.setWarehousingBatchId(outboundGoodsNextDto.getBatchId());
+            tErpSupplierOutboundGoods1.setOutboundCount(outboundGoodsNextDto.getNum());
+            tErpSupplierOutboundGoods1.setTotalPrice(multiply);
+            arrayList.add(tErpSupplierOutboundGoods1);
+            add  = add.add(multiply);
+        }
+
+        TErpSupplierOutbound tErpSupplierOutbound = new TErpSupplierOutbound();
+        tErpSupplierOutbound.setOutboundType(dto.getOutboundType());
+        tErpSupplierOutbound.setOutboundReason(dto.getOutboundReason());
+        tErpSupplierOutbound.setWarehouseId(dto.getWarehouseId());
+        tErpSupplierOutbound.setSupplierId(supplierClinicId);
+        tErpSupplierOutbound.setTotalMoney(add);
+        String s = DateUtils.dateTimeNow();
+        tErpSupplierOutbound.setOutboundNumber("G" + s);
+        erpSupplierOutboundMapper.insert(tErpSupplierOutbound);
+
+        for (TErpSupplierOutboundGoods tErpSupplierOutboundGoods : arrayList) {
+            tErpSupplierOutboundGoods.setOutboundId(tErpSupplierOutbound.getId());
+            erpSupplierOutboundGoodsMapper.insert(tErpSupplierOutboundGoods);
+        }
+
+
+    }
 }
diff --git a/ruoyi-system/src/main/resources/mapper/system/TErpGoodsMapper.xml b/ruoyi-system/src/main/resources/mapper/system/TErpGoodsMapper.xml
index 44047a4..4b1c59c 100644
--- a/ruoyi-system/src/main/resources/mapper/system/TErpGoodsMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/TErpGoodsMapper.xml
@@ -131,6 +131,9 @@
         LEFT JOIN t_crm_supplier t4 on t3.supplier_clinic_id = t4.id
         LEFT JOIN t_erp_supplier_outbound_goods t5 on t5.warehousing_batch_id =t1.id
         where t2.disabled = 0 and t2.warehouse_id = #{query.warehouseId}
+        <if test="query.type != null and query.type ==1">
+            and #{time} > t1.expiry_date
+        </if>
         <if test="query.goodsName != null and query.goodsName != ''">
             and t3.goods_name like concat('%',#{query.goodsName},'%')
         </if>

--
Gitblit v1.7.1