Browse Source

客户端管理,增加限制一个人只能成为一个供应商

wany 1 year ago
parent
commit
d556fc6d7f

+ 56 - 0
src/main/java/com/kingtom/shengtai/app/base/session/SessionLoader.java

@@ -0,0 +1,56 @@
+package com.kingtom.shengtai.app.base.session;
+
+import java.util.List;
+
+import com.kingtom.kirin.app.auth.model.AuthRole;
+import com.kingtom.kirin.app.auth.service.IAuthService;
+import com.kingtom.kirin.app.security.base.ISessionDataLoader;
+import com.kingtom.kirin.app.security.base.SessionData;
+import com.kingtom.kirin.app.security.service.ISecurityContainerService;
+import com.kingtom.kirin.core.common.CommonConst;
+import jakarta.annotation.PostConstruct;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * 应用模块名称</p>
+ * 代码描述</p>
+ * Copyright: Copyright (C) 2023 , Inc. All rights reserved. <p>
+ * Company: 成都诚唐科技有限责任公司</p>
+ *
+ * @author wany
+ * @since 2023/12/26
+ */
+@Component
+public class SessionLoader implements ISessionDataLoader{
+
+    @Autowired
+    private ISecurityContainerService container;
+
+    @Autowired
+    private IAuthService authService;
+
+    @PostConstruct
+    public void init(){
+        container.registerSessionLoader(this);
+    }
+
+    @Override
+    public int getOrder(){
+        return CommonConst.INT_100;
+    }
+
+    @Override
+    public void onLoad(SessionData data){
+        List<AuthRole> rolesByUserId = authService.findRolesByUserId(data.getUserId(), data.getSysId());
+        data.putAttr("BusinessRole", null);
+        if(rolesByUserId.stream().anyMatch(e -> e.getCode().equals("supplier"))){
+            data.putAttr("BusinessRole", "supplier");
+        }
+        if(rolesByUserId.stream().anyMatch(e -> e.getCode().equals("businessAdmin"))){
+            data.putAttr("BusinessRole", "businessAdmin");
+        }
+        ISessionDataLoader.super.onLoad(data);
+    }
+
+}

+ 2 - 0
src/main/java/com/kingtom/shengtai/app/srm/service/ISrmSupplierService.java

@@ -25,6 +25,8 @@ public interface ISrmSupplierService extends IBaseService<SrmSupplier>{
 
     SrmSupplierDO findById(String id);
 
+    SrmSupplier findByPerson(String personId);
+
     Page<SrmSupplierDO> page(String name, String type, String state, List<String> products, Integer pageNum,
             Integer pageSize);
 

+ 21 - 0
src/main/java/com/kingtom/shengtai/app/srm/service/impl/SrmSupplierServiceImpl.java

@@ -50,6 +50,13 @@ public class SrmSupplierServiceImpl extends BaseServiceImpl<ISrmSupplierDao, Srm
         if(StringUtils.isEmpty(entity.getType())){
             throw new AppException("供应商类型为空,新建供应商失败!");
         }
+        if(StringUtils.isEmpty(entity.getPerson())){
+            throw new AppException("供应商联系人为空,新建供应商失败!");
+        }
+        SrmSupplier byPerson = findByPerson(entity.getPerson());
+        if(byPerson != null){
+            throw new AppException("供应商联系人重复,新建供应商失败!");
+        }
         entity.setGmtCreate(new Date());
         entity.setGmtModified(entity.getGmtCreate());
         entity.setSysId(SystemUtils.getCurrentSystemId());
@@ -87,6 +94,14 @@ public class SrmSupplierServiceImpl extends BaseServiceImpl<ISrmSupplierDao, Srm
         if(entity == null || entity.getId() == null){
             throw new AppException("参数错误,更新供应商失败!");
         }
+        if(StringUtils.isBlank(entity.getPerson())){
+            entity.setPerson(null);
+        } else{
+            SrmSupplier byPerson = findByPerson(entity.getPerson());
+            if(byPerson != null && !byPerson.getId().equals(entity.getId())){
+                throw new AppException("供应商联系人重复,更新供应商失败!");
+            }
+        }
         entity.setGmtModified(new Date());
         boolean f = mapper.update(entity) > 0;
         if(!f){
@@ -111,6 +126,12 @@ public class SrmSupplierServiceImpl extends BaseServiceImpl<ISrmSupplierDao, Srm
         return build;
     }
 
+
+    @Override
+    public SrmSupplier findByPerson(String personId){
+        return mapper.selectOneByCondition(SRM_SUPPLIER.PERSON.eq(personId));
+    }
+
     @Override
     public Page<SrmSupplierDO> page(String name, String type, String state, List<String> products, Integer pageNum,
             Integer pageSize){