package com.iailab.module.data.gateway.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.iailab.framework.common.constant.Constant;
|
import com.iailab.module.data.common.utils.PageUtils;
|
import com.iailab.module.data.common.utils.Query;
|
import com.iailab.module.data.gateway.dao.ApiAppDao;
|
import com.iailab.module.data.gateway.entity.ApiAppEntity;
|
import com.iailab.module.data.gateway.service.ApiAppService;
|
import org.apache.commons.lang3.RandomStringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.stereotype.Service;
|
|
import java.util.Map;
|
import java.util.UUID;
|
|
/**
|
* @author PanZhibao
|
* @Description
|
* @createTime 2022年07月15日 14:02:00
|
*/
|
@Service("apiAppService")
|
public class ApiAppServiceImpl extends ServiceImpl<ApiAppDao, ApiAppEntity> implements ApiAppService {
|
|
@Override
|
public PageUtils queryPage(Map<String, Object> params) {
|
String appName = (String)params.get("appName");
|
String appKey = (String)params.get("appKey");
|
IPage<ApiAppEntity> page = this.page(
|
new Query<ApiAppEntity>().getPage(params),
|
new QueryWrapper<ApiAppEntity>()
|
.like(StringUtils.isNotBlank(appName),"app_name", appName)
|
.like(StringUtils.isNotBlank(appKey),"app_key", appKey)
|
.orderByDesc("create_time")
|
);
|
return new PageUtils(page);
|
}
|
|
@Override
|
public void add(ApiAppEntity entity) {
|
entity.setId(UUID.randomUUID().toString().replace("-", ""));
|
//apiAppEntity.setAppKey(UUID.randomUUID().toString().replace("-", "").substring(0, 16));
|
entity.setAppSecret(StringUtils.isNotBlank(entity.getAppSecret()) ? entity.getAppSecret() : RandomStringUtils.randomAlphanumeric(8));
|
entity.setStatus(Constant.EnableStatus.NORMAL.getValue());
|
this.save(entity);
|
}
|
|
@Override
|
public void update(ApiAppEntity apiAppEntity) {
|
this.updateById(apiAppEntity);
|
}
|
|
@Override
|
public void deleteById(String id) {
|
this.getBaseMapper().delete(new QueryWrapper<ApiAppEntity>().eq("id", id));
|
}
|
|
@Override
|
public ApiAppEntity getInfoById(String id) {
|
return this.getById(id);
|
}
|
|
@Override
|
public ApiAppEntity getInfoByAppKey(String appKey) {
|
return this.getOne(new QueryWrapper<ApiAppEntity>().eq("app_key", appKey));
|
}
|
|
@Override
|
public int cheack(ApiAppEntity apiAppEntity) {
|
String id = apiAppEntity.getId();
|
String appName = apiAppEntity.getAppName();
|
String appKey = apiAppEntity.getAppKey();
|
QueryWrapper<ApiAppEntity> queryWrapper = new QueryWrapper<>();
|
queryWrapper.ne(StringUtils.isNotBlank(id), "id", id);
|
queryWrapper.and(wrapper -> wrapper.eq("app_name", appName).or().
|
eq(StringUtils.isNotBlank(appKey),"app_key", appKey));
|
return (int)this.count(queryWrapper);
|
}
|
}
|