InterfaceOauthServiceImpl.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package jnpf.base.service.impl;
  2. import jnpf.base.service.SuperServiceImpl;
  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 jnpf.base.entity.InterfaceOauthEntity;
  7. import jnpf.base.mapper.InterfaceOauthMapper;
  8. import jnpf.base.model.InterfaceOauth.PaginationOauth;
  9. import jnpf.base.service.InterfaceOauthService;
  10. import jnpf.exception.DataException;
  11. import jnpf.util.DateUtil;
  12. import jnpf.util.RandomUtil;
  13. import jnpf.util.StringUtil;
  14. import jnpf.util.UserProvider;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Service;
  17. import java.util.List;
  18. /**
  19. * 接口认证服务
  20. *
  21. * @author JNPF开发平台组
  22. * @version V3.4.2
  23. * @copyright 引迈信息技术有限公司
  24. * @date 2022/6/8 9:50
  25. */
  26. @Service
  27. public class InterfaceOauthServiceImpl extends SuperServiceImpl<InterfaceOauthMapper, InterfaceOauthEntity> implements InterfaceOauthService {
  28. @Override
  29. public boolean isExistByAppName(String appName, String id) {
  30. QueryWrapper<InterfaceOauthEntity> queryWrapper = new QueryWrapper<>();
  31. queryWrapper.lambda().eq(InterfaceOauthEntity::getAppName, appName);
  32. if (!StringUtil.isEmpty(id)) {
  33. queryWrapper.lambda().ne(InterfaceOauthEntity::getId, id);
  34. }
  35. return this.count(queryWrapper) > 0 ? true : false;
  36. }
  37. @Override
  38. public boolean isExistByAppId(String appId, String id) {
  39. QueryWrapper<InterfaceOauthEntity> queryWrapper = new QueryWrapper<>();
  40. queryWrapper.lambda().eq(InterfaceOauthEntity::getAppId, appId);
  41. if (!StringUtil.isEmpty(id)) {
  42. queryWrapper.lambda().ne(InterfaceOauthEntity::getId, id);
  43. }
  44. return this.count(queryWrapper) > 0 ? true : false;
  45. }
  46. @Override
  47. public List<InterfaceOauthEntity> getList(PaginationOauth pagination) {
  48. boolean flag = false;
  49. QueryWrapper<InterfaceOauthEntity> queryWrapper = new QueryWrapper<>();
  50. //查询关键字
  51. if (StringUtil.isNotEmpty(pagination.getKeyword())) {
  52. flag = true;
  53. queryWrapper.lambda().and(
  54. t -> t.like(InterfaceOauthEntity::getAppId, pagination.getKeyword())
  55. .or().like(InterfaceOauthEntity::getAppName, pagination.getKeyword())
  56. );
  57. }
  58. if (pagination.getEnabledMark() != null) {
  59. queryWrapper.lambda().eq(InterfaceOauthEntity::getEnabledMark, pagination.getEnabledMark());
  60. }
  61. //排序
  62. queryWrapper.lambda().orderByAsc(InterfaceOauthEntity::getSortCode)
  63. .orderByDesc(InterfaceOauthEntity::getCreatorTime);
  64. if (flag) {
  65. queryWrapper.lambda().orderByDesc(InterfaceOauthEntity::getLastModifyTime);
  66. }
  67. Page<InterfaceOauthEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
  68. IPage<InterfaceOauthEntity> iPage = this.page(page, queryWrapper);
  69. return pagination.setData(iPage.getRecords(), iPage.getTotal());
  70. }
  71. @Override
  72. public InterfaceOauthEntity getInfo(String id) {
  73. QueryWrapper<InterfaceOauthEntity> queryWrapper = new QueryWrapper<>();
  74. queryWrapper.lambda().eq(InterfaceOauthEntity::getId, id);
  75. return this.getOne(queryWrapper);
  76. }
  77. @Override
  78. public void create(InterfaceOauthEntity entity) {
  79. if (entity.getId() == null) {
  80. entity.setId(RandomUtil.uuId());
  81. entity.setCreatorUserId(UserProvider.getUser().getUserId());
  82. entity.setCreatorTime(DateUtil.getNowDate());
  83. }
  84. this.save(entity);
  85. }
  86. @Override
  87. public boolean update(InterfaceOauthEntity entity, String id) throws DataException {
  88. entity.setId(id);
  89. entity.setLastModifyUserId(UserProvider.getUser().getUserId());
  90. entity.setLastModifyTime(DateUtil.getNowDate());
  91. return this.updateById(entity);
  92. }
  93. @Override
  94. public void delete(InterfaceOauthEntity entity) {
  95. this.removeById(entity.getId());
  96. }
  97. @Override
  98. public InterfaceOauthEntity getInfoByAppId(String appId) {
  99. QueryWrapper<InterfaceOauthEntity> queryWrapper = new QueryWrapper<>();
  100. queryWrapper.lambda().eq(InterfaceOauthEntity::getAppId, appId);
  101. return this.getOne(queryWrapper);
  102. }
  103. }