admin
2020-11-12 10229cb1635c70c82dbab3aa536ffaf4fa543b63
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
package com.ks.goldcorn.service.remote;
 
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.Service;
import org.yeshi.utils.StringUtil;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
@Service
public class GoldCornAppServiceImpl implements GoldCornAppService {
 
    @Resource
    private GoldCornAppInfoMapper goldCornAppInfoMapper;
 
    @Override
    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);
    }
 
    @Override
    public long countSearchByName(String name) {
        AppQuery query = new AppQuery();
        query.setNameKey(name);
        return goldCornAppInfoMapper.count(query);
    }
 
    @Override
    public GoldCornAppInfo selectByCode(String code) {
        return goldCornAppInfoMapper.selectByAppCode(code);
    }
 
    @Override
    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 = selectByCode(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);
    }
 
    @Override
    public void deleteApp(Long id) throws GoldAppException {
        goldCornAppInfoMapper.deleteByPrimaryKey(id);
    }
 
    @Override
    public void updateApp(GoldCornAppInfo appInfo) {
        if (appInfo == null || appInfo.getId() == null) {
            return;
        }
        appInfo.setUpdateTime(new Date());
        goldCornAppInfoMapper.updateByPrimaryKeySelective(appInfo);
    }
}