package com.ks.goldcorn.service;
|
|
import com.ks.goldcorn.exception.GoldAppException;
|
import com.ks.goldcorn.mapper.GoldCornAppInfoMapper;
|
import com.ks.goldcorn.pojo.DO.GoldCornAppInfo;
|
import com.ks.goldcorn.query.AppQuery;
|
import org.springframework.stereotype.Component;
|
import org.yeshi.utils.StringUtil;
|
|
import javax.annotation.Resource;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
@Component
|
public class GoldCornAppManager {
|
|
@Resource
|
private GoldCornAppInfoMapper goldCornAppInfoMapper;
|
|
/**
|
* 通过名称查询
|
*
|
* @param name
|
* @param page
|
* @param pageSize
|
* @return
|
*/
|
public List<GoldCornAppInfo> searchByName(String name, int page, int pageSize) {
|
AppQuery query = new AppQuery();
|
query.setNameKey(name);
|
query.setStart((page - 1) * pageSize);
|
query.setCount(pageSize);
|
|
List<String> sortList = new ArrayList<>();
|
sortList.add("create_time desc");
|
query.setSortList(sortList);
|
return goldCornAppInfoMapper.list(query);
|
}
|
|
/**
|
* 通过名称计数
|
*
|
* @param name
|
* @return
|
*/
|
public long countSearchByName(String name) {
|
AppQuery query = new AppQuery();
|
query.setNameKey(name);
|
return goldCornAppInfoMapper.count(query);
|
}
|
|
/**
|
* 添加APP
|
*
|
* @param goldCornAppInfo
|
* @throws GoldAppException
|
*/
|
public void addApp(GoldCornAppInfo goldCornAppInfo) throws GoldAppException {
|
if (goldCornAppInfo == null || StringUtil.isNullOrEmpty(goldCornAppInfo.getAppCode()) || StringUtil.isNullOrEmpty(goldCornAppInfo.getAppName())) {
|
throw new GoldAppException(GoldAppException.CODE_PARAMS_NOT_ENOUGH, "参数不完整");
|
}
|
GoldCornAppInfo app = selectByAppCode(goldCornAppInfo.getAppCode());
|
if (app != null) {
|
throw new GoldAppException(GoldAppException.CODE_EXIST, "应用code已经存在");
|
}
|
|
if (goldCornAppInfo.getCreateTime() == null) {
|
goldCornAppInfo.setCreateTime(new Date());
|
}
|
goldCornAppInfo.setId(null);
|
goldCornAppInfoMapper.insertSelective(goldCornAppInfo);
|
}
|
|
/**
|
* 删除APP
|
*
|
* @param id
|
* @throws GoldAppException
|
*/
|
public void deleteApp(Long id) throws GoldAppException {
|
goldCornAppInfoMapper.deleteByPrimaryKey(id);
|
}
|
|
/**
|
* 更新APP
|
*
|
* @param appInfo
|
*/
|
public void updateApp(GoldCornAppInfo appInfo) {
|
if (appInfo == null || appInfo.getId() == null) {
|
return;
|
}
|
appInfo.setUpdateTime(new Date());
|
goldCornAppInfoMapper.updateByPrimaryKeySelective(appInfo);
|
}
|
|
|
/**
|
* 根据AppCode查询APP
|
*
|
* @param code
|
* @return
|
*/
|
public GoldCornAppInfo selectByAppCode(String code) {
|
return goldCornAppInfoMapper.selectByAppCode(code);
|
}
|
|
|
/**
|
* 根据code查询AppId
|
*
|
* @param code
|
* @return
|
*/
|
public Long selectAppIdByAppCode(String code) {
|
GoldCornAppInfo app = selectByAppCode(code);
|
if (app == null) {
|
return null;
|
}
|
return app.getId();
|
}
|
|
/**
|
* 获取appID
|
*
|
* @param appCode
|
* @return
|
* @throws GoldAppException
|
*/
|
public Long getAppId(String appCode) throws GoldAppException {
|
Long appId = selectAppIdByAppCode(appCode);
|
if (appId == null) {
|
throw new GoldAppException(GoldAppException.CODE_NOT_EXIST, "应用不存在");
|
}
|
return appId;
|
}
|
}
|