admin
2021-06-26 6b2670dfa68af9ce2e36a5f9580125f4fc6da570
service-goldcorn/src/main/java/com/ks/goldcorn/service/GoldCornAppManager.java
@@ -3,9 +3,14 @@
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 {
@@ -14,6 +19,84 @@
    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