admin
2021-05-06 42f05d2b835ed1ee41ca32cf76fe11849a890cb4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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;
    }
}