AppInfoServiceImpl.java 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package com.ydd.module.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
  5. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  6. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  7. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  8. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  9. import com.ydd.common.core.page.PageResult;
  10. import com.ydd.common.exception.CustomException;
  11. import com.ydd.ecloud.core.enums.DeletedEnum;
  12. import com.ydd.module.domain.AppInfo;
  13. import com.ydd.module.mapper.AppInfoMapper;
  14. import com.ydd.module.service.IAppInfoService;
  15. import org.apache.commons.lang3.StringUtils;
  16. import org.springframework.stereotype.Service;
  17. import java.util.List;
  18. import java.util.Random;
  19. /**
  20. * Demo class
  21. *
  22. * @author 14027
  23. * @date 2022/2/24 9:58
  24. */
  25. @Service
  26. public class AppInfoServiceImpl extends ServiceImpl<AppInfoMapper, AppInfo> implements IAppInfoService {
  27. @Override
  28. public PageResult queryList(Page page, AppInfo appInfo) {
  29. // LambdaQueryWrapper<AppInfo> lqw = Wrappers.lambdaQuery();
  30. // if (StringUtils.isNotBlank(appInfo.getName())) {
  31. // lqw.like(AppInfo::getName, appInfo.getName());
  32. // }
  33. // if (StringUtils.isNotBlank(appInfo.getAppId())) {
  34. // lqw.like(AppInfo::getAppId, appInfo.getAppId());
  35. // }
  36. // if (StringUtils.isNotBlank(appInfo.getAppSecret())) {
  37. // lqw.like(AppInfo::getAppSecret, appInfo.getAppSecret());
  38. // }
  39. List<AppInfo> appInfoList = baseMapper.queryList(page, appInfo);
  40. page.setRecords(appInfoList);
  41. return new PageResult(page);
  42. }
  43. @Override
  44. public Boolean createAppInfo(AppInfo appInfo) throws Exception {
  45. // String appKey = getAppInfo(17);
  46. // appId自动增加
  47. String appKey = "100001";
  48. List<AppInfo> appInfoList = baseMapper.selectList(new QueryWrapper<AppInfo>().eq("deleted", DeletedEnum.NO.getValue()).orderByDesc("id"));
  49. if (CollectionUtils.isNotEmpty(appInfoList)) {
  50. appKey = Integer.parseInt(appInfoList.get(0).getAppId()) + 1 + "";
  51. }
  52. String appSecret = getAppInfo(32);
  53. if (StringUtils.isNotBlank(appKey) && StringUtils.isNotBlank(appSecret)) {
  54. appInfo.setAppId(appKey);
  55. appInfo.setAppSecret(appSecret);
  56. baseMapper.insert(appInfo);
  57. }else {
  58. throw new CustomException("系统内置错误,创建失败!");
  59. }
  60. return true;
  61. }
  62. public String getAppInfo(int length) {
  63. Random random = new Random();
  64. StringBuffer sb = new StringBuffer();
  65. String randCha = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  66. int chaLength = randCha.length();
  67. for (int i = 0; i < length; i++) {
  68. int index = random.nextInt(chaLength);
  69. sb.append(randCha.charAt(index));
  70. }
  71. return sb.toString();
  72. }
  73. @Override
  74. public AppInfo getByAppId(String appId) {
  75. return baseMapper.selectOne(new QueryWrapper<AppInfo>()
  76. .eq("app_id", appId)
  77. .eq("deleted", 0));
  78. }
  79. }