1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package com.ydd.module.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.ydd.common.core.page.PageResult;
- import com.ydd.common.exception.CustomException;
- import com.ydd.ecloud.core.enums.DeletedEnum;
- import com.ydd.module.domain.AppInfo;
- import com.ydd.module.mapper.AppInfoMapper;
- import com.ydd.module.service.IAppInfoService;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.stereotype.Service;
- import java.util.List;
- import java.util.Random;
- /**
- * Demo class
- *
- * @author 14027
- * @date 2022/2/24 9:58
- */
- @Service
- public class AppInfoServiceImpl extends ServiceImpl<AppInfoMapper, AppInfo> implements IAppInfoService {
- @Override
- public PageResult queryList(Page page, AppInfo appInfo) {
- // LambdaQueryWrapper<AppInfo> lqw = Wrappers.lambdaQuery();
- // if (StringUtils.isNotBlank(appInfo.getName())) {
- // lqw.like(AppInfo::getName, appInfo.getName());
- // }
- // if (StringUtils.isNotBlank(appInfo.getAppId())) {
- // lqw.like(AppInfo::getAppId, appInfo.getAppId());
- // }
- // if (StringUtils.isNotBlank(appInfo.getAppSecret())) {
- // lqw.like(AppInfo::getAppSecret, appInfo.getAppSecret());
- // }
- List<AppInfo> appInfoList = baseMapper.queryList(page, appInfo);
- page.setRecords(appInfoList);
- return new PageResult(page);
- }
- @Override
- public Boolean createAppInfo(AppInfo appInfo) throws Exception {
- // String appKey = getAppInfo(17);
- // appId自动增加
- String appKey = "100001";
- List<AppInfo> appInfoList = baseMapper.selectList(new QueryWrapper<AppInfo>().eq("deleted", DeletedEnum.NO.getValue()).orderByDesc("id"));
- if (CollectionUtils.isNotEmpty(appInfoList)) {
- appKey = Integer.parseInt(appInfoList.get(0).getAppId()) + 1 + "";
- }
- String appSecret = getAppInfo(32);
- if (StringUtils.isNotBlank(appKey) && StringUtils.isNotBlank(appSecret)) {
- appInfo.setAppId(appKey);
- appInfo.setAppSecret(appSecret);
- baseMapper.insert(appInfo);
- }else {
- throw new CustomException("系统内置错误,创建失败!");
- }
- return true;
- }
- public String getAppInfo(int length) {
- Random random = new Random();
- StringBuffer sb = new StringBuffer();
- String randCha = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
- int chaLength = randCha.length();
- for (int i = 0; i < length; i++) {
- int index = random.nextInt(chaLength);
- sb.append(randCha.charAt(index));
- }
- return sb.toString();
- }
- @Override
- public AppInfo getByAppId(String appId) {
- return baseMapper.selectOne(new QueryWrapper<AppInfo>()
- .eq("app_id", appId)
- .eq("deleted", 0));
- }
- }
|