admin
2020-11-13 ae08b37317103344b9be1b9f91b6bdf7abbc839b
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
package com.ks.goldcorn.service.remote;
 
import com.ks.goldcorn.exception.GoldSourceException;
import com.ks.goldcorn.mapper.GoldCornConsumeSourceMapper;
import com.ks.goldcorn.pojo.DO.GoldCornConsumeSource;
import com.ks.goldcorn.query.SourceQuery;
import com.ks.goldcorn.service.GoldCornAppManager;
import org.apache.dubbo.config.annotation.Service;
import org.yeshi.utils.StringUtil;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
 
@Service(version = "1.0")
public class GoldCornConsumeSourceImpl implements GoldCornConsumeSourceService {
 
    @Resource
    private GoldCornConsumeSourceMapper goldCornConsumeSourceMapper;
 
    @Resource
    private GoldCornAppManager goldCornAppManager;
 
 
    @Override
    public List<GoldCornConsumeSource> searchByName(String appCode, String nameKey, int page, int pageSize) {
        Long appId = goldCornAppManager.selectAppIdByAppCode(appCode);
        if (appId == null) {
            return null;
        }
 
        SourceQuery query = new SourceQuery();
        query.setAppId(appId);
        query.setNameKey(nameKey);
        query.setStart((page - 1) * pageSize);
        query.setCount(pageSize);
        return goldCornConsumeSourceMapper.list(query);
    }
 
    @Override
    public GoldCornConsumeSource selectByAppAndCode(String appCode, String code) {
        Long appId = goldCornAppManager.selectAppIdByAppCode(appCode);
        if (appId == null) {
            return null;
        }
        return goldCornConsumeSourceMapper.selectByAppIdAndSourceCode(appId, code);
    }
 
    @Override
    public long countByName(String appCode, String nameKey) {
        Long appId = goldCornAppManager.selectAppIdByAppCode(appCode);
        if (appId == null) {
            return 0L;
        }
        SourceQuery query = new SourceQuery();
        query.setAppId(appId);
        query.setNameKey(nameKey);
        return goldCornConsumeSourceMapper.count(query);
    }
 
    @Override
    public void addSource(GoldCornConsumeSource source) throws GoldSourceException {
        if (source == null || source.getAppId() == null || source.getGoldCorn() == null || StringUtil.isNullOrEmpty(source.getSourceCode()) || StringUtil.isNullOrEmpty(source.getSourceName())) {
            throw new GoldSourceException(GoldSourceException.CODE_PARAMS_NOT_ENOUGH, "参数不完整");
        }
        source.setId(null);
        source.setCreateTime(new Date());
        GoldCornConsumeSource old = goldCornConsumeSourceMapper.selectByAppIdAndSourceCode(source.getAppId(), source.getSourceCode());
        if (old != null) {
            throw new GoldSourceException(GoldSourceException.CODE_EXIST, "来源已存在");
        }
        goldCornConsumeSourceMapper.insertSelective(source);
    }
 
    @Override
    public void deleteSource(Long id) {
        goldCornConsumeSourceMapper.deleteByPrimaryKey(id);
    }
 
    @Override
    public void updateSource(GoldCornConsumeSource source) throws GoldSourceException {
        if (source == null || source.getId() == null) {
            throw new GoldSourceException(GoldSourceException.CODE_PARAMS_NOT_ENOUGH, "参数不完整");
        }
        GoldCornConsumeSource old = goldCornConsumeSourceMapper.selectByPrimaryKey(source.getId());
        if (old == null) {
            throw new GoldSourceException(GoldSourceException.CODE_NOT_EXIST, "来源不存在");
        }
        //修改
        source.setUpdateTime(new Date());
        goldCornConsumeSourceMapper.updateByPrimaryKeySelective(source);
    }
}