From c8e080d65e26158ea62c98548a11e9aa75c2112e Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期五, 26 九月 2025 18:18:13 +0800
Subject: [PATCH] 诊所erp

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TErpGoodsController.java |  275 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 262 insertions(+), 13 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 5c1c855..73441fe 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
@@ -9,16 +9,17 @@
 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.ruoyi.common.basic.PageInfo;
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.BaseModel;
+import com.ruoyi.common.core.domain.BasePage;
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.core.exception.ServiceException;
 import com.ruoyi.common.utils.WebUtils;
 import com.ruoyi.framework.web.service.TokenService;
-import com.ruoyi.system.dto.TErpGoodsAddDto;
-import com.ruoyi.system.dto.TErpGoodsInfoSaveDto;
-import com.ruoyi.system.dto.TErpGoodsUpdateStatusDto;
+import com.ruoyi.system.dto.*;
 import com.ruoyi.system.importExcel.TErpGoodsExcel;
 import com.ruoyi.system.model.*;
 import com.ruoyi.system.query.TErpGoodsQuery;
@@ -43,6 +44,7 @@
 import java.net.URLEncoder;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Set;
 import java.util.stream.Collectors;
@@ -93,7 +95,7 @@
     /**
      * 获取erp问题上报管理列表
      */
-    @ApiOperation(value = "供应商获取商品分页列表")
+    @ApiOperation(value = "供应商 诊所 获取商品分页列表")
     @PostMapping(value = "/pageList")
     public R<PageInfo<TErpGoodsVO>> pageList(@RequestBody TErpGoodsQuery query) {
         SysUser user = tokenService.getLoginUser().getUser();
@@ -117,11 +119,83 @@
 
 
 
+    /**
+     * 获取erp问题上报管理列表
+     */
+    @ApiOperation(value = "诊所 一键获取商品分页列表")
+    @PostMapping(value = "/pageAddList")
+    public R<Page<TErpGoods>> pageAddList(@RequestBody BasePage query) {
+        SysUser user = tokenService.getLoginUser().getUser();
+        Integer roleType = user.getRoleType();
+        String clinicSupplierId=null;
+        if(roleType == 5){
+            // 诊所
+            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
+                    .eq(TCrmClinic::getUserId, user.getUserId())
+                    .last("LIMIT 1"));
+            clinicSupplierId = crmClinic.getId();
+        }
+        Page<TErpGoods> tErpGoodsPage = new Page<>(query.getPageNum(), query.getPageSize());
+
+        Page<TErpGoods> page = erpGoodsService.page(tErpGoodsPage, new LambdaQueryWrapper<TErpGoods>().eq(TErpGoods::getGoodsSource, 1).eq(TErpGoods::getState,1).eq(BaseModel::getDisabled, 0).isNotNull(TErpGoods::getPlatformCommissionPrice).last("and (NOT FIND_IN_SET(" + clinicSupplierId + ",clinic_ids) or  clinic_ids is null)"));
+        for (TErpGoods record : page.getRecords()) {
+            TCrmSupplier byId = crmSupplierService.getById(record.getSupplierClinicId());
+            record.setSupplierName(byId.getSupplierName());
+
+
+            TErpGoodsType byId1 = erpGoodsTypeService.getById(record.getTypeId());
+            record.setTypeName(byId1.getTypeName());
+
+        }
+        return R.ok(page);
+    }
+
+    /**
+     * 获取erp问题上报管理列表
+     */
+    @ApiOperation(value = "诊所 一键获取商品 获取全部")
+    @PostMapping(value = "/getAllGoodsList")
+    public R<?> getAllGoodsList() {
+        SysUser user = tokenService.getLoginUser().getUser();
+        Integer roleType = user.getRoleType();
+        String clinicSupplierId=null;
+        if(roleType == 5){
+            // 诊所
+            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
+                    .eq(TCrmClinic::getUserId, user.getUserId())
+                    .last("LIMIT 1"));
+            clinicSupplierId = crmClinic.getId();
+        }
+
+        List<TErpGoods> list = erpGoodsService.list(new LambdaQueryWrapper<TErpGoods>().eq(TErpGoods::getGoodsSource, 1).eq(TErpGoods::getState,1).eq(BaseModel::getDisabled, 0).isNotNull(TErpGoods::getPlatformCommissionPrice).last("and (NOT FIND_IN_SET(" + clinicSupplierId + ",clinic_ids) or  clinic_ids is null)"));
+        for (TErpGoods goods : list) {
+            String clinicIds = goods.getClinicIds();
+            if(clinicIds == null || clinicIds.isEmpty()){
+                goods.setClinicIds(clinicSupplierId);
+            }else {
+                String[] split = clinicIds.split(",");
+                ArrayList<String> split1 = new ArrayList<>();
+                for (String s : split) {
+                    split1.add(s);
+                }
+                if(!split1.contains(clinicSupplierId)){
+                    split1.add(clinicSupplierId);
+                    goods.setClinicIds(String.join(",",split1));
+                }
+            }
+
+        }
+        erpGoodsService.updateBatchById(list);
+        return R.ok();
+    }
+
+
+
     @ApiOperation(value = "供应商添加商品")
     @PostMapping(value = "/add")
     public R<Boolean> add(@Validated @RequestBody TErpGoodsAddDto dto) {
         SysUser user = tokenService.getLoginUser().getUser();
-        if (erpGoodsService.isExit(dto.getGoodsIdCode(), dto.getQuasiNumber())) {
+        if (erpGoodsService.isExit(dto.getGoodsIdCode(), dto.getQuasiNumber(),null)) {
             return R.fail("erp商品已存在");
         }
         Integer roleType = user.getRoleType();
@@ -151,11 +225,121 @@
         goods.setGoodsName(dto.getGoodsName());
         return R.ok(erpGoodsService.save(goods));
     }
+    @ApiOperation(value = "诊所添加商品")
+    @PostMapping(value = "/clinicAdd")
+    public R<Boolean> clinicAdd(@Validated @RequestBody TErpClinicGoodsAddDto dto) {
+        SysUser user = tokenService.getLoginUser().getUser();
+        if (erpGoodsService.isExit(dto.getGoodsIdCode(), dto.getQuasiNumber(),null)) {
+            return R.fail("erp商品已存在");
+        }
+        Integer roleType = user.getRoleType();
+        TErpGoods goods = new TErpGoods();
+        BeanUtils.copyProperties(dto,goods);
+        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.setClinicPurchasePrice(dto.getSalesAmount());
+        return R.ok(erpGoodsService.save(goods));
+    }
 
-    @ApiOperation(value = "供应商删除商品")
+    @ApiOperation(value = "诊所编辑商品")
+    @PostMapping(value = "/clinicUpdate")
+    public R<Boolean> clinicUpdate(@Validated @RequestBody TErpClinicGoodsUpdateDto dto) {
+        SysUser user = tokenService.getLoginUser().getUser();
+        if (erpGoodsService.isExit(dto.getGoodsIdCode(), dto.getQuasiNumber(),dto.getId())) {
+            return R.fail("erp商品已存在");
+        }
+        Integer roleType = user.getRoleType();
+        TErpGoods goods = new TErpGoods();
+        BeanUtils.copyProperties(dto,goods);
+        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.setId(dto.getId());
+        return R.ok(erpGoodsService.updateById(goods));
+    }
+
+    @ApiOperation(value = "供应商/诊所 删除商品")
     @DeleteMapping(value = "/delete/{id}")
     public R<Boolean> delete(@PathVariable String id) {
-        return R.ok(erpGoodsService.removeById(id));
+        TErpGoods goods = erpGoodsService.getById(id);
+        SysUser user = tokenService.getLoginUser().getUser();
+        String cid = null;
+
+        if(user.getRoleType() == 5){
+            // 诊所
+            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
+                    .eq(TCrmClinic::getUserId, user.getUserId())
+                    .last("LIMIT 1"));
+            cid = crmClinic.getId();
+            if(goods.getGoodsSource()==1){
+                String clinicIds = goods.getClinicIds();
+                String[] split = clinicIds.split(",");
+                // clinicIds 移除cid
+                ArrayList<String> strings = new ArrayList<>();
+                for (String s : split) {
+                    if(!s.equals(cid)){
+                        strings.add(s);
+                    }
+                }
+                goods.setClinicIds(String.join(",",strings));
+                erpGoodsService.updateById(goods);
+            }else {
+                erpGoodsService.removeById(id);
+            }
+            return R.ok();
+        }
+        erpGoodsService.removeById(id);
+        return R.ok();
+    }
+
+    @ApiOperation(value = "诊所 一键添加商品")
+    @PostMapping(value = "/addSupplierGoods")
+    public R<Boolean> addSupplierGoods(@RequestBody AddSupplierGoodsDto dto) {
+//        List<String> split = Arrays.asList(goodsIds.split(","));
+        List<TErpGoods> list = erpGoodsService.list(new LambdaQueryWrapper<TErpGoods>().in(TErpGoods::getId, dto.getGoodsIds()));
+        SysUser user = tokenService.getLoginUser().getUser();
+        String cid = null;
+
+        if(user.getRoleType() == 5){
+            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
+                    .eq(TCrmClinic::getUserId, user.getUserId())
+                    .last("LIMIT 1"));
+            cid = crmClinic.getId();
+            for (TErpGoods goods : list) {
+                String clinicIds = goods.getClinicIds();
+                if(clinicIds==null || clinicIds.isEmpty()){
+                    goods.setClinicIds( cid);
+                }else {
+                    String[] split = clinicIds.split(",");
+                    List<String> split1 = new ArrayList<>();
+                    for (String s : split) {
+                        split1.add(s);
+                    }
+                    if(!split1.contains(cid)){
+                        split1.add(cid);
+                        goods.setClinicIds(String.join(",",split1));
+                    }
+                }
+
+            }
+            erpGoodsService.updateBatchById(list);
+        }
+        return R.ok();
     }
 
 
@@ -181,6 +365,23 @@
     @PostMapping(value = "/saveDataInfo")
     public R<Boolean> saveDataInfo(@RequestBody @Valid TErpGoodsInfoSaveDto dto) {
         SysUser user = tokenService.getLoginUser().getUser();
+        Integer roleType = user.getRoleType();
+        String clinicSupplierId=null;
+        if(roleType == 4){
+            // 供应商
+            TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class)
+                    .eq(TCrmSupplier::getUserId, user.getUserId())
+                    .last("LIMIT 1"));
+            clinicSupplierId = crmSupplier.getId();
+        }
+        if(roleType == 5){
+            // 诊所
+            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
+                    .eq(TCrmClinic::getUserId, user.getUserId())
+                    .last("LIMIT 1"));
+            clinicSupplierId =crmClinic.getId();
+        }
+
         TErpGoods goods = erpGoodsService.getById(dto.getId());
         BeanUtils.copyProperties(dto,goods);
         if(goods.getMaintenanceInterval()!=null){
@@ -195,7 +396,7 @@
                         if (tErpSupplierWarehousingBatch.getWarehousingNumber()-sum>0) {
                             // 生成保养单
                             TErpMaintenanceReminder tErpMaintenanceReminder = new TErpMaintenanceReminder();
-                            tErpMaintenanceReminder.setClinicSupplierId(user.getUserId().toString());
+                            tErpMaintenanceReminder.setClinicSupplierId(clinicSupplierId);
                             tErpMaintenanceReminder.setMaintenanceType(1);
                             tErpMaintenanceReminder.setWarehousingBatchId(tErpSupplierWarehousingBatch.getId());
                             Integer day = Integer.valueOf(goods.getMaintenanceInterval());
@@ -228,6 +429,23 @@
     public void listExport(@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());
+        }
+
         List<TErpGoodsVO> pageList = erpGoodsService.listExport(query,user);
         Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TErpGoodsVO.class, pageList);
         HttpServletResponse response = WebUtils.response();
@@ -272,12 +490,28 @@
             List<TErpGoodsExcel> carAnnuallyImportExcels = ExcelImportUtil.importExcel(inputStream, TErpGoodsExcel.class, params);
             Set<String> collect = carAnnuallyImportExcels.stream().map(TErpGoodsExcel::getGoodsIdCode).collect(Collectors.toSet());
             if (collect.size() != carAnnuallyImportExcels.size()) {
-                return AjaxResult.error("导入数据中商品标识码重复");
+                return AjaxResult.error("导入数据中商品条码重复");
             }
+            Integer roleType = user.getRoleType();
             for (TErpGoodsExcel erpGoodsExcel : carAnnuallyImportExcels) {
                 TErpGoods goods = new TErpGoods();
-                goods.setSupplierClinicId(user.getUserId().toString());
-                goods.setGoodsSource(1);
+
+                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);
+                }
 
                 // 判空
                 if(erpGoodsExcel.getGoodsName()==null || erpGoodsExcel.getGoodsName().isEmpty()){
@@ -297,10 +531,10 @@
                 }
                 goods.setGoodsName(erpGoodsExcel.getGoodsName());
                 // 判断数据是否正确
-                // 判断标识码是否重复
+                // 判断条码是否重复
                 long count = erpGoodsService.count(new QueryWrapper<TErpGoods>().eq("goods_id_code", erpGoodsExcel.getGoodsIdCode()));
                 if(count>0){
-                    names.add(erpGoodsExcel.getGoodsName() + " :标识码重复");
+                    names.add(erpGoodsExcel.getGoodsName() + " :条码重复");
                     continue;
                 }
                 goods.setGoodsIdCode(erpGoodsExcel.getGoodsIdCode());
@@ -417,5 +651,20 @@
     }
 
 
+
+
+    @ApiOperation(value = "平台设置分佣")
+    @PostMapping(value = "/setCommission")
+    public R<Boolean> setCommission(@RequestBody @Valid TErpGoodsSetCommissionDto dto) {
+
+        SysUser user = tokenService.getLoginUser().getUser();
+        if(user.getRoleType()==1){
+            TErpGoods goods = erpGoodsService.getById(dto.getId());
+            goods.setClinicPurchasePrice(BigDecimal.valueOf(dto.getClinicPurchasePrice()).setScale(2,RoundingMode.HALF_UP));
+            goods.setPlatformCommissionPrice(BigDecimal.valueOf(dto.getPlatformCommissionPrice()).setScale(2,RoundingMode.HALF_UP));
+            erpGoodsService.updateById( goods);
+        }
+        return R.ok();
+    }
 }
 

--
Gitblit v1.7.1