StandingServiceImpl.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. package jnpf.permission.service.impl;
  2. import cn.hutool.core.collection.CollectionUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.baomidou.mybatisplus.core.metadata.IPage;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.github.yulichang.toolkit.JoinWrappers;
  7. import com.github.yulichang.wrapper.MPJLambdaWrapper;
  8. import jnpf.base.service.SuperServiceImpl;
  9. import jnpf.constant.CodeConst;
  10. import jnpf.constant.PermissionConst;
  11. import jnpf.permission.entity.*;
  12. import jnpf.permission.mapper.StandingMapper;
  13. import jnpf.permission.model.standing.StandingPagination;
  14. import jnpf.permission.service.CodeNumService;
  15. import jnpf.permission.service.PositionService;
  16. import jnpf.permission.service.RoleService;
  17. import jnpf.permission.service.StandingService;
  18. import jnpf.util.DateUtil;
  19. import jnpf.util.RandomUtil;
  20. import jnpf.util.StringUtil;
  21. import jnpf.util.UserProvider;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.stereotype.Service;
  24. import java.util.Collections;
  25. import java.util.List;
  26. /**
  27. * 身份管理impl
  28. *
  29. * @author JNPF开发平台组
  30. * @version v6.0.0
  31. * @copyright 引迈信息技术有限公司
  32. * @date 2025/3/4 18:24:09
  33. */
  34. @Service
  35. public class StandingServiceImpl extends SuperServiceImpl<StandingMapper, StandingEntity> implements StandingService {
  36. @Autowired
  37. private CodeNumService codeNumService;
  38. @Autowired
  39. private RoleService roleService;
  40. @Autowired
  41. private PositionService positionService;
  42. @Override
  43. public List<StandingEntity> getList(StandingPagination pagination) {
  44. boolean flag = false;
  45. QueryWrapper<StandingEntity> queryWrapper = new QueryWrapper<>();
  46. if (StringUtil.isNotEmpty(pagination.getKeyword())) {
  47. flag = true;
  48. queryWrapper.lambda().and(
  49. t -> t.like(StandingEntity::getFullName, pagination.getKeyword())
  50. .or().like(StandingEntity::getEnCode, pagination.getKeyword())
  51. );
  52. }
  53. //排序
  54. queryWrapper.lambda().orderByAsc(StandingEntity::getSortCode).orderByAsc(StandingEntity::getCreatorTime);
  55. if (flag) {
  56. queryWrapper.lambda().orderByDesc(StandingEntity::getLastModifyTime);
  57. }
  58. return this.list(queryWrapper);
  59. }
  60. @Override
  61. public void crete(StandingEntity entity) {
  62. entity.setId(RandomUtil.uuId());
  63. if (StringUtil.isEmpty(entity.getEnCode())) {
  64. entity.setEnCode(codeNumService.getCodeFunction(() -> codeNumService.getCodeOnce(CodeConst.SF), code -> this.isExistByEnCode(code, null)));
  65. }
  66. entity.setCreatorUserId(UserProvider.getUser().getUserId());
  67. entity.setCreatorTime(DateUtil.getNowDate());
  68. entity.setIsSystem(2);
  69. entity.setEnabledMark(1);
  70. this.save(entity);
  71. }
  72. @Override
  73. public Boolean update(String id, StandingEntity entity) {
  74. entity.setId(id);
  75. if (StringUtil.isEmpty(entity.getEnCode())) {
  76. entity.setEnCode(codeNumService.getCodeFunction(() -> codeNumService.getCodeOnce(CodeConst.SF), code -> this.isExistByEnCode(code, id)));
  77. }
  78. entity.setLastModifyUserId(UserProvider.getUser().getUserId());
  79. entity.setLastModifyTime(DateUtil.getNowDate());
  80. entity.setEnabledMark(1);
  81. return this.updateById(entity);
  82. }
  83. @Override
  84. public StandingEntity getInfo(String id) {
  85. return this.getById(id);
  86. }
  87. @Override
  88. public void delete(StandingEntity entity) {
  89. this.removeById(entity.getId());
  90. //todo 绑定关系删除
  91. }
  92. @Override
  93. public Boolean isExistByFullName(String fullName, String id) {
  94. QueryWrapper<StandingEntity> queryWrapper = new QueryWrapper<>();
  95. queryWrapper.lambda().eq(StandingEntity::getFullName, fullName);
  96. if (!StringUtil.isEmpty(id)) {
  97. queryWrapper.lambda().ne(StandingEntity::getId, id);
  98. }
  99. return this.count(queryWrapper) > 0 ? true : false;
  100. }
  101. @Override
  102. public Boolean isExistByEnCode(String enCode, String id) {
  103. if (StringUtil.isEmpty(enCode)) return false;
  104. QueryWrapper<StandingEntity> queryWrapper = new QueryWrapper<>();
  105. queryWrapper.lambda().eq(StandingEntity::getEnCode, enCode);
  106. if (!StringUtil.isEmpty(id)) {
  107. queryWrapper.lambda().ne(StandingEntity::getId, id);
  108. }
  109. return this.count(queryWrapper) > 0 ? true : false;
  110. }
  111. @Override
  112. public List<StandingEntity> getListByIds(List<String> idList) {
  113. if (CollectionUtil.isEmpty(idList)) return Collections.EMPTY_LIST;
  114. QueryWrapper<StandingEntity> queryWrapper = new QueryWrapper<>();
  115. queryWrapper.lambda().in(StandingEntity::getId, idList);
  116. queryWrapper.lambda().eq(StandingEntity::getEnabledMark, 1);
  117. queryWrapper.lambda().orderByAsc(StandingEntity::getSortCode).orderByAsc(StandingEntity::getCreatorTime);
  118. return this.list(queryWrapper);
  119. }
  120. @Override
  121. public List<RoleEntity> getRolePage(StandingPagination pagination) {
  122. MPJLambdaWrapper<RoleEntity> queryWrapper = JoinWrappers.lambda(RoleEntity.class);
  123. queryWrapper.leftJoin(AuthorizeEntity.class, AuthorizeEntity::getObjectId, RoleEntity::getId);
  124. queryWrapper.selectAll(RoleEntity.class);
  125. if (!StringUtil.isEmpty(pagination.getKeyword())) {
  126. queryWrapper.and(
  127. t -> t.like(RoleEntity::getEnCode, pagination.getKeyword())
  128. .or().like(RoleEntity::getFullName, pagination.getKeyword())
  129. );
  130. }
  131. queryWrapper.eq(AuthorizeEntity::getItemId, pagination.getId());
  132. queryWrapper.eq(AuthorizeEntity::getObjectType, PermissionConst.ROLE);
  133. queryWrapper.isNotNull(RoleEntity::getId);
  134. queryWrapper.orderByAsc(RoleEntity::getGlobalMark).orderByDesc(AuthorizeEntity::getId);
  135. Page<RoleEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
  136. IPage<RoleEntity> data = roleService.selectJoinListPage(page, RoleEntity.class, queryWrapper);
  137. return pagination.setData(data.getRecords(), page.getTotal());
  138. }
  139. @Override
  140. public List<PositionEntity> getPosPage(StandingPagination pagination) {
  141. MPJLambdaWrapper<PositionEntity> queryWrapper = JoinWrappers.lambda(PositionEntity.class);
  142. queryWrapper.leftJoin(AuthorizeEntity.class, AuthorizeEntity::getObjectId, PositionEntity::getId);
  143. queryWrapper.selectAll(PositionEntity.class);
  144. if (!StringUtil.isEmpty(pagination.getKeyword())) {
  145. queryWrapper.and(
  146. t -> t.like(PositionEntity::getEnCode, pagination.getKeyword())
  147. .or().like(PositionEntity::getFullName, pagination.getKeyword())
  148. );
  149. }
  150. queryWrapper.eq(AuthorizeEntity::getItemId, pagination.getId());
  151. queryWrapper.eq(AuthorizeEntity::getObjectType, PermissionConst.POSITION);
  152. queryWrapper.isNotNull(PositionEntity::getId);
  153. queryWrapper.orderByDesc(AuthorizeEntity::getId);
  154. Page<PositionEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
  155. IPage<PositionEntity> data = positionService.selectJoinListPage(page, PositionEntity.class, queryWrapper);
  156. return pagination.setData(data.getRecords(), page.getTotal());
  157. }
  158. }