package jnpf.permission.service.impl; import cn.hutool.core.collection.CollectionUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.yulichang.toolkit.JoinWrappers; import com.github.yulichang.wrapper.MPJLambdaWrapper; import jnpf.base.service.SuperServiceImpl; import jnpf.constant.CodeConst; import jnpf.constant.PermissionConst; import jnpf.permission.entity.*; import jnpf.permission.mapper.StandingMapper; import jnpf.permission.model.standing.StandingPagination; import jnpf.permission.service.CodeNumService; import jnpf.permission.service.PositionService; import jnpf.permission.service.RoleService; import jnpf.permission.service.StandingService; import jnpf.util.DateUtil; import jnpf.util.RandomUtil; import jnpf.util.StringUtil; import jnpf.util.UserProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.Collections; import java.util.List; /** * 身份管理impl * * @author JNPF开发平台组 * @version v6.0.0 * @copyright 引迈信息技术有限公司 * @date 2025/3/4 18:24:09 */ @Service public class StandingServiceImpl extends SuperServiceImpl implements StandingService { @Autowired private CodeNumService codeNumService; @Autowired private RoleService roleService; @Autowired private PositionService positionService; @Override public List getList(StandingPagination pagination) { boolean flag = false; QueryWrapper queryWrapper = new QueryWrapper<>(); if (StringUtil.isNotEmpty(pagination.getKeyword())) { flag = true; queryWrapper.lambda().and( t -> t.like(StandingEntity::getFullName, pagination.getKeyword()) .or().like(StandingEntity::getEnCode, pagination.getKeyword()) ); } //排序 queryWrapper.lambda().orderByAsc(StandingEntity::getSortCode).orderByAsc(StandingEntity::getCreatorTime); if (flag) { queryWrapper.lambda().orderByDesc(StandingEntity::getLastModifyTime); } return this.list(queryWrapper); } @Override public void crete(StandingEntity entity) { entity.setId(RandomUtil.uuId()); if (StringUtil.isEmpty(entity.getEnCode())) { entity.setEnCode(codeNumService.getCodeFunction(() -> codeNumService.getCodeOnce(CodeConst.SF), code -> this.isExistByEnCode(code, null))); } entity.setCreatorUserId(UserProvider.getUser().getUserId()); entity.setCreatorTime(DateUtil.getNowDate()); entity.setIsSystem(2); entity.setEnabledMark(1); this.save(entity); } @Override public Boolean update(String id, StandingEntity entity) { entity.setId(id); if (StringUtil.isEmpty(entity.getEnCode())) { entity.setEnCode(codeNumService.getCodeFunction(() -> codeNumService.getCodeOnce(CodeConst.SF), code -> this.isExistByEnCode(code, id))); } entity.setLastModifyUserId(UserProvider.getUser().getUserId()); entity.setLastModifyTime(DateUtil.getNowDate()); entity.setEnabledMark(1); return this.updateById(entity); } @Override public StandingEntity getInfo(String id) { return this.getById(id); } @Override public void delete(StandingEntity entity) { this.removeById(entity.getId()); //todo 绑定关系删除 } @Override public Boolean isExistByFullName(String fullName, String id) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(StandingEntity::getFullName, fullName); if (!StringUtil.isEmpty(id)) { queryWrapper.lambda().ne(StandingEntity::getId, id); } return this.count(queryWrapper) > 0 ? true : false; } @Override public Boolean isExistByEnCode(String enCode, String id) { if (StringUtil.isEmpty(enCode)) return false; QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(StandingEntity::getEnCode, enCode); if (!StringUtil.isEmpty(id)) { queryWrapper.lambda().ne(StandingEntity::getId, id); } return this.count(queryWrapper) > 0 ? true : false; } @Override public List getListByIds(List idList) { if (CollectionUtil.isEmpty(idList)) return Collections.EMPTY_LIST; QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().in(StandingEntity::getId, idList); queryWrapper.lambda().eq(StandingEntity::getEnabledMark, 1); queryWrapper.lambda().orderByAsc(StandingEntity::getSortCode).orderByAsc(StandingEntity::getCreatorTime); return this.list(queryWrapper); } @Override public List getRolePage(StandingPagination pagination) { MPJLambdaWrapper queryWrapper = JoinWrappers.lambda(RoleEntity.class); queryWrapper.leftJoin(AuthorizeEntity.class, AuthorizeEntity::getObjectId, RoleEntity::getId); queryWrapper.selectAll(RoleEntity.class); if (!StringUtil.isEmpty(pagination.getKeyword())) { queryWrapper.and( t -> t.like(RoleEntity::getEnCode, pagination.getKeyword()) .or().like(RoleEntity::getFullName, pagination.getKeyword()) ); } queryWrapper.eq(AuthorizeEntity::getItemId, pagination.getId()); queryWrapper.eq(AuthorizeEntity::getObjectType, PermissionConst.ROLE); queryWrapper.isNotNull(RoleEntity::getId); queryWrapper.orderByAsc(RoleEntity::getGlobalMark).orderByDesc(AuthorizeEntity::getId); Page page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize()); IPage data = roleService.selectJoinListPage(page, RoleEntity.class, queryWrapper); return pagination.setData(data.getRecords(), page.getTotal()); } @Override public List getPosPage(StandingPagination pagination) { MPJLambdaWrapper queryWrapper = JoinWrappers.lambda(PositionEntity.class); queryWrapper.leftJoin(AuthorizeEntity.class, AuthorizeEntity::getObjectId, PositionEntity::getId); queryWrapper.selectAll(PositionEntity.class); if (!StringUtil.isEmpty(pagination.getKeyword())) { queryWrapper.and( t -> t.like(PositionEntity::getEnCode, pagination.getKeyword()) .or().like(PositionEntity::getFullName, pagination.getKeyword()) ); } queryWrapper.eq(AuthorizeEntity::getItemId, pagination.getId()); queryWrapper.eq(AuthorizeEntity::getObjectType, PermissionConst.POSITION); queryWrapper.isNotNull(PositionEntity::getId); queryWrapper.orderByDesc(AuthorizeEntity::getId); Page page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize()); IPage data = positionService.selectJoinListPage(page, PositionEntity.class, queryWrapper); return pagination.setData(data.getRecords(), page.getTotal()); } }