| | |
| | | import cn.huge.module.client.api.impl.UtilsClientImpl; |
| | | import cn.huge.module.constant.BaseConsts; |
| | | import cn.huge.module.ctuser.dao.mapper.CtUserMapper; |
| | | import cn.huge.module.ctuser.domain.po.CtUnit; |
| | | import cn.huge.module.ctuser.domain.po.CtUser; |
| | | import cn.huge.module.cust.constant.UserBaseConsts; |
| | | import cn.huge.module.cust.dto.CtUserDTO; |
| | | import cn.huge.module.redis.constant.RedisKeyConsts; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @title: 客户用户表业务逻辑处理 |
| | |
| | | |
| | | @Autowired |
| | | private UtilsClientImpl utilsClient; |
| | | |
| | | @Autowired |
| | | private CtUnitService ctUnitService; |
| | | |
| | | @Autowired |
| | | private CtUseroleService ctUseroleService; |
| | | |
| | | /** |
| | | * 更新对象 |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 重写根据id获取用户 |
| | | * @param userId 登录用户编号 |
| | | * @return Object |
| | | */ |
| | | public CtUser getById(String userId) { |
| | | String loginUserId = ""; |
| | | if (userId.indexOf(BaseConsts.AND) != -1){ |
| | | String[] userIds = userId.split(BaseConsts.AND); |
| | | loginUserId = userIds[0]; |
| | | }else { |
| | | loginUserId = userId; |
| | | } |
| | | return mapper.selectById(loginUserId); |
| | | } |
| | | |
| | | /** |
| | | * 按条件分页查询 |
| | | * |
| | | * @param page 分页对象 |
| | | * @param terms 条件 |
| | | * @return Page |
| | | */ |
| | | public Page<CtUser> pageUserAndRole(PageRequest page, Map<String, Object> terms) { |
| | | long total = mapper.countQueryCtUser(terms); |
| | | List<CtUser> content = mapper.pageQueryCtUser(page, terms); |
| | | return new PageImpl<CtUser>(content, page, total); |
| | | } |
| | | |
| | | /** |
| | | * 获取当前登录用户,获取用户所有信息(用户信息、角色等) |
| | | * @param userId 登录用户编号 |
| | | * @return Object |
| | | */ |
| | | public CtUserDTO clientGetUserAll(String userId) { |
| | | String loginUserId = ""; |
| | | String loginRoleCode = ""; |
| | | if (userId.indexOf(BaseConsts.AND) != -1){ |
| | | String[] userIds = userId.split(BaseConsts.AND); |
| | | loginUserId = userIds[0]; |
| | | loginRoleCode = userIds[1]; |
| | | }else { |
| | | loginUserId = userId; |
| | | } |
| | | // 用户信息 |
| | | CtUser ctUser = mapper.selectById(loginUserId); |
| | | if (ObjectUtils.isNotEmpty(ctUser)){ |
| | | CtUnit ctUnit = ctUnitService.getById(ctUser.getUnitId()); |
| | | CtUserDTO ctUserDTO = new CtUserDTO(); |
| | | BeanUtils.copyProperties(ctUser, ctUserDTO); |
| | | if(ObjectUtils.isNotEmpty(ctUnit)){ |
| | | ctUserDTO.setUnitType(ctUnit.getUnitType()); |
| | | } |
| | | // 角色代码 |
| | | if (StringUtils.isEmpty(loginRoleCode)) { |
| | | List<String> roleCodeList = ctUseroleService.listRoleCode(loginUserId); |
| | | String userRole = roleCodeList.stream().map(String::valueOf).collect(Collectors.joining(",")); |
| | | ctUserDTO.setRoleCodes(userRole); |
| | | }else { |
| | | ctUserDTO.setRoleCodes(loginRoleCode); |
| | | } |
| | | return ctUserDTO; |
| | | }else { |
| | | return null; |
| | | } |
| | | } |
| | | } |