admin
2021-06-24 df4441322e9801c102299451da41d7c40b4502e9
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
package com.ks.app.service;
 
import com.ks.app.entity.AppInfo;
import com.ks.app.exception.AppException;
import com.ks.app.mapper.AppInfoMapper;
import com.ks.app.query.AppQuery;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
@Component
public class AppInfoManager {
 
    @Resource
    private AppInfoMapper appInfoMapper;
 
    public AppInfo selectByAppKey(String appKey) {
        return appInfoMapper.selectByAppKey(appKey);
    }
 
 
    public AppInfo selectByPrimaryKey(Long id) {
        return appInfoMapper.selectByPrimaryKey(id);
    }
 
    /**
     * 通过名称查询
     *
     * @param name
     * @param page
     * @param pageSize
     * @return
     */
    public List<AppInfo> 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 appInfoMapper.list(query);
    }
 
    /**
     * 通过名称计数
     *
     * @param name
     * @return
     */
    public long countSearchByName(String name) {
        AppQuery query = new AppQuery();
        query.setNameKey(name);
        return appInfoMapper.count(query);
    }
 
    /**
     * 添加APP
     *
     * @param appInfo
     * @throws AppException
     */
    @Validated
    public void addApp(AppInfo appInfo) throws AppException {
        AppInfo app = selectByAppKey(appInfo.getAppKey());
        if (app != null) {
            throw new AppException(AppException.CODE_EXIST, "appKey已经存在");
        }
 
        if (appInfo.getCreateTime() == null) {
            appInfo.setCreateTime(new Date());
        }
        appInfo.setId(null);
        appInfoMapper.insertSelective(appInfo);
    }
 
 
}