consum-base/src/main/java/com/consum/base/service/impl/BaseWarehouseManagerServiceImpl.java
@@ -1,22 +1,25 @@
package com.consum.base.service.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.compress.utils.Sets;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.consum.base.core.utils.IdUtil;
import com.consum.base.pojo.WarehouseManagerInfo;
import com.consum.base.pojo.request.WarehouseManagerParam;
import com.consum.base.service.BaseWarehouseManagerService;
import com.consum.base.service.FinSysTenantUserServiceImpl;
import com.consum.base.service.FinSysTenantUserService;
import com.consum.model.po.BaseWarehouseManager;
import com.consum.model.po.FinSysTenantUser;
import com.iplatform.model.po.S_role;
import com.walker.infrastructure.utils.CollectionUtils;
import com.walker.jdbc.service.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @Description 物品分类
@@ -27,25 +30,26 @@
public class BaseWarehouseManagerServiceImpl extends BaseServiceImpl implements BaseWarehouseManagerService {
    @Autowired
    private FinSysTenantUserServiceImpl finSysTenantUserService;
    private FinSysTenantUserService finSysTenantUserService;
    /**
     * @return
     * @Description 新增
     * @Author 卢庆阳
     * @Date 2023/10/26
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void add(WarehouseManagerParam list) throws Exception {
    public Set<Long> add(WarehouseManagerParam list) throws Exception {
        Set<Long> sysUserIds = Sets.newHashSet();
        Long warehouseId = list.getWarehouseId();
        // 角色id
        Long roleId = null;
        List<S_role> roleAll = finSysTenantUserService.getRoleAll();
        if (!CollectionUtils.isEmpty(roleAll)) {
            S_role sRole = roleAll.stream().filter(item -> item.getRole_name().equals("仓库管理员")).findFirst().orElse(null);
            S_role sRole =
                roleAll.stream().filter(item -> "仓库管理员".equals(item.getRole_name())).findFirst().orElse(null);
            if (sRole != null) {
                roleId = sRole.getRole_id();
            }
@@ -58,7 +62,7 @@
        String deleteRoleSql = "DELETE FROM S_ROLE_USER WHERE USER_ID =:managerId AND role_id =:roleId";
        for (BaseWarehouseManager item : baseWarehouseManagerList) {
            Long managerId = item.getManagerId();
            FinSysTenantUser finSysTenantUser = finSysTenantUserService.queryOneById(String.valueOf(managerId));
            FinSysTenantUser finSysTenantUser = finSysTenantUserService.queryOneBySysId(String.valueOf(managerId));
            if (finSysTenantUser == null) {
                throw new Exception("用户不存在");
            }
@@ -66,14 +70,16 @@
            params.put("managerId", finSysTenantUser.getSysUserId());
            params.put("roleId", roleId);
            this.execute(deleteRoleSql, params);
            sysUserIds.add(finSysTenantUser.getSysUserId());
        }
        //删除库管记录
        // 删除库管记录
        String sql = "delete from base_warehouse_manager where base_warehouse_id =:warehouseId";
        Map<String, Object> params = new HashMap<>();
        params.put("warehouseId", warehouseId);
        this.execute(sql, params);
        //重新保存
        // 重新保存
        List<WarehouseManagerInfo> warehouseManagerInfoList = list.getWarehouseManagerInfoList();
        if (!CollectionUtils.isEmpty(warehouseManagerInfoList)) {
            for (WarehouseManagerInfo warehouseManagerInfo : warehouseManagerInfoList) {
@@ -92,7 +98,8 @@
                }
                Long sysUserId = finSysTenantUser.getSysUserId();
                // 先判断是否拥有该角色
                String isHasRole = "select count(1) from s_role_user where org_id=0 and role_id=" + roleId + " and user_id=" + sysUserId;
                String isHasRole =
                    "select * from s_role_user where org_id=0 and role_id=" + roleId + " and user_id=" + sysUserId;
                List<Map<String, Object>> isHasRoleList = this.select(isHasRole, new HashMap<>());
                if (!CollectionUtils.isEmpty(isHasRoleList)) {
                    continue;
@@ -103,9 +110,10 @@
                userRoleParam.put("roleId", roleId);
                this.execute(saveUserRole, userRoleParam);
                sysUserIds.add(finSysTenantUser.getSysUserId());
            }
        }
        return sysUserIds;
    }
    @Override
@@ -118,7 +126,8 @@
    @Override
    public List<BaseWarehouseManager> selectManagerList(Long warehouseId, Long agencyId) {
        StringBuilder sql = new StringBuilder("select * from base_warehouse_manager bwm left join base_warehouse bw on bwm.base_warehouse_id = bw.id "
        StringBuilder sql = new StringBuilder(
            "select * from base_warehouse_manager bwm left join base_warehouse bw on bwm.base_warehouse_id = bw.id "
                + "where 1=1 ");
        Map<String, Object> param = new HashMap<>();
        if (warehouseId != null) {
@@ -133,5 +142,12 @@
        return select;
    }
    @Override
    public void deleteMangerBySysUserId(Long sysUserId) {
        String sql = "delete from base_warehouse_manager where MANAGER_ID =:sysUserId";
        Map<String, Object> params = new HashMap<>();
        params.put("sysUserId", sysUserId);
        this.execute(sql, params);
    }
}