From 413d5fb8681752b7a80b1cf7b509ed2bc4bfe3ee Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期四, 11 九月 2025 18:11:05 +0800
Subject: [PATCH] 上传接口

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TErpGoodsController.java |   40 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TErpGoodsController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TErpGoodsController.java
index d81f78a..5c1c855 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TErpGoodsController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TErpGoodsController.java
@@ -8,6 +8,7 @@
 import com.alibaba.fastjson2.JSONObject;
 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.ruoyi.common.basic.PageInfo;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.R;
@@ -68,11 +69,13 @@
     private final TErpSupplierWarehousingService erpSupplierWarehousingService;
     private final TErpSupplierOutboundGoodsService erpSupplierOutboundGoodsService;
     private final TErpMaintenanceReminderService erpMaintenanceReminderService;
+    private final TCrmClinicService crmClinicService;
+    private final TCrmSupplierService crmSupplierService;
 
     @Autowired
     public TErpGoodsController(TErpGoodsService erpGoodsService, TokenService tokenService, TErpGoodsTypeService erpGoodsTypeService, TErpGoodsUnitService erpGoodsUnitService,
                                TErpSupplierWarehousingBatchService erpSupplierWarehousingBatchService, TErpSupplierWarehousingService erpSupplierWarehousingService,
-                               TErpSupplierOutboundGoodsService erpSupplierOutboundGoodsService, TErpMaintenanceReminderService erpMaintenanceReminderService) {
+                               TErpSupplierOutboundGoodsService erpSupplierOutboundGoodsService, TErpMaintenanceReminderService erpMaintenanceReminderService, TCrmClinicService crmClinicService, TCrmSupplierService crmSupplierService) {
         this.erpGoodsService = erpGoodsService;
         this.tokenService = tokenService;
         this.erpGoodsTypeService = erpGoodsTypeService;
@@ -81,6 +84,8 @@
         this.erpSupplierWarehousingService = erpSupplierWarehousingService;
         this.erpSupplierOutboundGoodsService = erpSupplierOutboundGoodsService;
         this.erpMaintenanceReminderService = erpMaintenanceReminderService;
+        this.crmClinicService = crmClinicService;
+        this.crmSupplierService = crmSupplierService;
     }
 
 
@@ -92,6 +97,21 @@
     @PostMapping(value = "/pageList")
     public R<PageInfo<TErpGoodsVO>> pageList(@RequestBody TErpGoodsQuery query) {
         SysUser user = tokenService.getLoginUser().getUser();
+        Integer roleType = user.getRoleType();
+        if(roleType == 4){
+            // 供应商
+            TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class)
+                    .eq(TCrmSupplier::getUserId, user.getUserId())
+                    .last("LIMIT 1"));
+            query.setSupplierClinicId(crmSupplier.getId());
+        }
+        if(roleType == 5){
+            // 诊所
+            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
+                    .eq(TCrmClinic::getUserId, user.getUserId())
+                    .last("LIMIT 1"));
+            query.setSupplierClinicId(crmClinic.getId());
+        }
         return R.ok(erpGoodsService.pageList(query,user));
     }
 
@@ -104,8 +124,24 @@
         if (erpGoodsService.isExit(dto.getGoodsIdCode(), dto.getQuasiNumber())) {
             return R.fail("erp商品已存在");
         }
+        Integer roleType = user.getRoleType();
         TErpGoods goods = new TErpGoods();
-        goods.setSupplierClinicId(user.getUserId().toString());
+        if(roleType == 4){
+            // 供应商
+            TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class)
+                    .eq(TCrmSupplier::getUserId, user.getUserId())
+                    .last("LIMIT 1"));
+            goods.setSupplierClinicId(crmSupplier.getId());
+            goods.setGoodsSource(1);
+        }
+        if(roleType == 5){
+            // 诊所
+            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
+                    .eq(TCrmClinic::getUserId, user.getUserId())
+                    .last("LIMIT 1"));
+            goods.setSupplierClinicId(crmClinic.getId());
+            goods.setGoodsSource(2);
+        }
         goods.setCreateId(user.getUserId().toString());
         goods.setGoodsIdCode(dto.getGoodsIdCode());
         goods.setQuasiNumber(dto.getQuasiNumber());

--
Gitblit v1.7.1