package cn.huge.module.ctuser.service; import cn.huge.base.common.dto.SelectTermDTO; import cn.huge.base.common.exception.ServiceException; import cn.huge.base.common.utils.DateUtils; import cn.huge.base.common.utils.IdUtils; import cn.huge.base.common.utils.ObjectUtils; import cn.huge.module.client.api.impl.UtilsClientImpl; import cn.huge.module.ctuser.dao.mapper.CtUseroleMapper; import cn.huge.module.ctuser.domain.po.CtUserole; import cn.huge.module.ctuser.dto.CtUseroleInfoDTO; import cn.huge.module.cust.constant.RoleBaseEnum; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; /** * @title: 客户用户角色表业务逻辑处理 * @Description 客户用户角色表业务逻辑处理 * @company hugeinfo * @author liyj * @Time 2024-08-19 20:04:19 * @version 1.0.0 */ @Slf4j @Service @Transactional(rollbackFor = Exception.class) public class CtUseroleService extends ServiceImpl{ @Autowired private RedisTemplate redisTemplate; @Autowired private CtUseroleMapper mapper; @Autowired private UtilsClientImpl utilsClient; /** * 更新对象 * @param entity 对象 */ public void updateCtUserole(CtUserole entity){ try{ mapper.updateCtUserole(entity); }catch (Exception e){ log.error("[CtUseroleService.updateCtUserole]调用失败,异常信息:"+e, e); throw new ServiceException("CtUseroleService.updateCtUserole", e); } } /** * 条件更新对象 * @param entity 对象 * @param terms 条件 */ public void updateCtUseroleTerms(CtUserole entity, Map terms){ try{ mapper.updateCtUseroleTerms(entity, terms); }catch (Exception e){ log.error("[CtUseroleService.updateCtUseroleTerms]调用失败,异常信息:"+e, e); throw new ServiceException("CtUseroleService.updateCtUseroleTerms", e); } } /** * 根据编号物理删除 * @param id 查询条件集合 */ public void deleteCtUserole(String id){ try{ mapper.deleteCtUserole(id); }catch (Exception e){ log.error("[CtUseroleService.deleteCtUserole]调用失败,异常信息:"+e, e); throw new ServiceException("CtUseroleService.deleteCtUserole", e); } } /** * 按条件查询 * @param terms 条件 * @return List */ public List listTerms(Map terms){ return mapper.listTerms(terms); } /** * 按条件统计 * @param terms 条件 * @return long */ public long countTerms(Map terms){ return mapper.countTerms(terms); } /** * 按条件分页查询 * @param page 分页对象 * @param terms 条件 * @return Page */ public Page pageQuery(PageRequest page, Map terms){ long total = mapper.countTerms(terms); List content = mapper.pageTerms(page, terms); return new PageImpl(content, page, total); } /** * 新增或更新对象 * @param ctUserole 实体对象 */ public void saveCtUserole(CtUserole ctUserole){ try{ Date nowDate = DateUtils.getNowDate(); // 判断是否新增 if (IdUtils.checkNewId(ctUserole.getId())){ ctUserole.setId(utilsClient.getNewTimeId()); ctUserole.setCreateTime(nowDate); } ctUserole.setUpdateTime(nowDate); this.saveOrUpdate(ctUserole); }catch (Exception e){ log.error("[CtUseroleService.saveCtUserole]调用失败,异常信息:"+e, e); throw new ServiceException("CtUseroleService.saveCtUserole", e); } } /** * 根据userId查询 * @param userId 用户编号 * @return */ public List listByUserId(String userId){ QueryWrapper ctUseroleQueryWrapper = new QueryWrapper<>(); ctUseroleQueryWrapper.eq("user_id", userId); List ctUseroleList = mapper.selectList(ctUseroleQueryWrapper); return ctUseroleList; } /** * 根据用户编号获取其角色代码 * @param userId 用户编号 * @return List */ public List listRoleCode(String userId){ return mapper.listRoleCode(userId); } /** * 根据用户编号物理删除 * @param userId 用户编号 */ public void deleteByUserId(String userId){ try{ QueryWrapper ctUseroleQueryWrapper = new QueryWrapper<>(); ctUseroleQueryWrapper.eq("user_id", userId); mapper.delete(ctUseroleQueryWrapper); }catch (Exception e){ log.error("[CtUseroleService.deleteByUserId]调用失败,异常信息:"+e, e); throw new ServiceException("CtUseroleService.deleteByUserId", e); } } /** * 根据用户编号获取其角色名称 * @param userId 用户编号 * @return List */ public List listRoleName(String userId){ return mapper.listRoleName(userId); } /** * 查询法官列表 * @param userId 用户编号 * */ public List listJudge(String userId){ List ctUseroleInfoDTOS = mapper.listUserByRoleCode(RoleBaseEnum.ROLE_6.getIndex(), null); List selectTermDTOS = new ArrayList<>(); if(ObjectUtils.isNotEmpty(ctUseroleInfoDTOS)){ for (CtUseroleInfoDTO ctUseroleInfoDTO : ctUseroleInfoDTOS) { SelectTermDTO selectTermDTO = new SelectTermDTO(); selectTermDTO.setLabel(ctUseroleInfoDTO.getUserName()); selectTermDTO.setValue(ctUseroleInfoDTO.getUserId()); selectTermDTOS.add(selectTermDTO); } } return selectTermDTOS; } /** * 查询法官列表 * @param userId 用户编号 * */ public List listAssist(String userId){ List ctUseroleInfoDTOS = mapper.listUserByRoleCode(RoleBaseEnum.ROLE_8.getIndex(), null); return ctUseroleInfoDTOS; } }