|  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Collection; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  | import javax.annotation.PostConstruct; | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import javax.validation.Validator; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.ruoyi.alarm.config.domain.ArdAlarmTypeConfig; | 
|---|
|  |  |  | import com.ruoyi.alarm.config.mapper.ArdAlarmTypeConfigMapper; | 
|---|
|  |  |  | import com.ruoyi.common.constant.CacheConstants; | 
|---|
|  |  |  | import com.ruoyi.common.core.redis.RedisCache; | 
|---|
|  |  |  | import com.ruoyi.common.utils.DateUtils; | 
|---|
|  |  |  | import com.ruoyi.common.utils.DictUtils; | 
|---|
|  |  |  | import com.ruoyi.common.utils.uuid.IdUtils; | 
|---|
|  |  |  | import org.slf4j.Logger; | 
|---|
|  |  |  | import org.slf4j.LoggerFactory; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | 
|---|
|  |  |  | protected Validator validator; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private RedisCache redisCache; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private ArdAlarmTypeConfigMapper ardAlarmTypeConfigMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 项目启动时,初始化参数到缓存 | 
|---|
|  |  |  | 
|---|
|  |  |  | public List<SysUser> selectUserList(SysUser user) { | 
|---|
|  |  |  | return userMapper.selectUserList(user); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取App单兵和指挥端用户列表 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param user APP用户信息 | 
|---|
|  |  |  | * @return 用户信息集合信息 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @DataScope(deptAlias = "d", userAlias = "u") | 
|---|
|  |  |  | public List<SysUser> selectAppUserList(SysUser user) { | 
|---|
|  |  |  | return userMapper.selectAppUserList(user); | 
|---|
|  |  |  | //    @DataScope(deptAlias = "d", userAlias = "u") | 
|---|
|  |  |  | public List<SysUser> selectAllAppUserList(SysUser user) { | 
|---|
|  |  |  | return userMapper.selectAllAppUserList(user); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据条件分页查询已分配用户角色列表 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | 
|---|
|  |  |  | insertUserPost(user); | 
|---|
|  |  |  | // 新增用户与角色管理 | 
|---|
|  |  |  | insertUserRole(user); | 
|---|
|  |  |  | // 新增用户与报警类型关联 | 
|---|
|  |  |  | insertAlarmTypeConfig(user); | 
|---|
|  |  |  | return rows; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public int updateUser(SysUser user) { | 
|---|
|  |  |  | String userId = user.getUserId(); | 
|---|
|  |  |  | // 删除用户与报警类型关联 | 
|---|
|  |  |  | ardAlarmTypeConfigMapper.deleteArdAlarmTypeConfigByUserId(userId); | 
|---|
|  |  |  | // 新增用户与报警类型关联 | 
|---|
|  |  |  | insertAlarmTypeConfig(user); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 删除用户与角色关联 | 
|---|
|  |  |  | userRoleMapper.deleteUserRoleByUserId(userId); | 
|---|
|  |  |  | // 新增用户与角色管理 | 
|---|
|  |  |  | 
|---|
|  |  |  | public void insertUserRole(SysUser user) { | 
|---|
|  |  |  | this.insertUserRole(user.getUserId(), user.getRoleIds()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 新增用户报警类型信息 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param user 用户对象 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void insertAlarmTypeConfig(SysUser user) { | 
|---|
|  |  |  | this.insertAlarmTypeConfig(user.getUserId(), user.getCommands()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 新增用户岗位信息 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | 
|---|
|  |  |  | userRoleMapper.batchUserRole(list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 新增用户报警类型 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param userId  用户ID | 
|---|
|  |  |  | * @param commands 报警类型组 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void insertAlarmTypeConfig(String userId, List<String> commands) { | 
|---|
|  |  |  | if (StringUtils.isNotEmpty(commands)) { | 
|---|
|  |  |  | // 新增用户与角色管理 | 
|---|
|  |  |  | List<ArdAlarmTypeConfig> list = new ArrayList<ArdAlarmTypeConfig>(commands.size()); | 
|---|
|  |  |  | for (String command : commands) { | 
|---|
|  |  |  | ArdAlarmTypeConfig ur = new ArdAlarmTypeConfig(); | 
|---|
|  |  |  | ur.setUserId(userId); | 
|---|
|  |  |  | ur.setCommand(command); | 
|---|
|  |  |  | String alarm_type = DictUtils.getDictLabel("alarm_type", command); | 
|---|
|  |  |  | ur.setAlarmType(alarm_type); | 
|---|
|  |  |  | list.add(ur); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ardAlarmTypeConfigMapper.batchAlarmTypeConfig(list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 通过用户ID删除用户 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | 
|---|
|  |  |  | checkUserAllowed(new SysUser(userId)); | 
|---|
|  |  |  | checkUserDataScope(userId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 删除用户与报警类型关联 | 
|---|
|  |  |  | ardAlarmTypeConfigMapper.deleteArdAlarmTypeConfigByIds(userIds); | 
|---|
|  |  |  | // 删除用户与角色关联 | 
|---|
|  |  |  | userRoleMapper.deleteUserRole(userIds); | 
|---|
|  |  |  | // 删除用户与岗位关联 | 
|---|
|  |  |  | 
|---|
|  |  |  | private String getCacheKey(String configKey) { | 
|---|
|  |  |  | return CacheConstants.USER_LIST_KEY + configKey; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<SysUser> userByDeptList(List<Long> deptList) { | 
|---|
|  |  |  | QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | queryWrapper.in("dept_id",deptList); | 
|---|
|  |  |  | return userMapper.selectList(queryWrapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|