| | |
| | | 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.iplatform.model.po.S_role; |
| | | import com.walker.infrastructure.utils.CollectionUtils; |
| | | import com.walker.jdbc.service.BaseServiceImpl; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | /** |
| | | * @Description 物品分类 |
| | |
| | | @Autowired |
| | | private FinSysTenantUserServiceImpl 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 -> item.getRole_name().equals("仓库管理员")).findFirst().orElse(null); |
| | | if (sRole != null) { |
| | | roleId = sRole.getRole_id(); |
| | | } |
| | |
| | | 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("用户不存在"); |
| | | } |
| | |
| | | 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) { |
| | |
| | | baseWarehouseManager.setManagerName(managerName); |
| | | this.insert(baseWarehouseManager); |
| | | |
| | | FinSysTenantUser finSysTenantUser = finSysTenantUserService.queryOneById(String.valueOf(managerId)); |
| | | FinSysTenantUser finSysTenantUser = finSysTenantUserService.queryOneBySysId(String.valueOf(managerId)); |
| | | if (finSysTenantUser == null) { |
| | | throw new Exception("用户不存在"); |
| | | } |
| | | Long sysUserId = finSysTenantUser.getSysUserId(); |
| | | // 先判断是否拥有该角色 |
| | | 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; |
| | | } |
| | | String saveUserRole = "insert into s_role_user(user_id, role_id, org_id) values(:managerId,:roleId,0)"; |
| | | Map<String, Object> userRoleParam = new HashMap<>(); |
| | | userRoleParam.put("managerId", sysUserId); |
| | | userRoleParam.put("roleId", roleId); |
| | | this.execute(saveUserRole, userRoleParam); |
| | | |
| | | sysUserIds.add(finSysTenantUser.getSysUserId()); |
| | | } |
| | | } |
| | | |
| | | return sysUserIds; |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @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 " |
| | | + "where 1=1 "); |
| | | 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) { |
| | | param.put("warehouseId", warehouseId); |
| | |
| | | List<BaseWarehouseManager> select = this.select(sql.toString(), param, new BaseWarehouseManager()); |
| | | return select; |
| | | } |
| | | |
| | | |
| | | } |