admin
2020-12-03 55f808742eb4117dbb840955cb11bb9b9ae4f04c
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
package com.ks.daylucky.service.impl.remote;
 
import com.ks.daylucky.exception.MsgTypeConfigException;
import com.ks.daylucky.mapper.MsgTypeConfigMapper;
import com.ks.daylucky.pojo.DO.MsgTypeConfig;
import com.ks.daylucky.pojo.DO.UserMsg;
import com.ks.daylucky.query.MsgTypeConfigQuery;
import com.ks.daylucky.service.MsgTypeConfigService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.validation.annotation.Validated;
 
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;
 
@Service(version = "1.0.0")
public class MsgTypeConfigServiceImpl implements MsgTypeConfigService {
 
    @Resource
    private MsgTypeConfigMapper msgTypeConfigMapper;
 
    @Validated
    @Override
    public void addMsgTypeConfig(@Valid MsgTypeConfig config) throws MsgTypeConfigException {
        MsgTypeConfigQuery query = new MsgTypeConfigQuery();
        query.appId = config.getAppId();
        query.msgType = config.getMsgType();
        query.count = 1;
        List<MsgTypeConfig> list = msgTypeConfigMapper.list(query);
        if (list != null && list.size() > 0) {
            throw new MsgTypeConfigException(MsgTypeConfigException.CODE_EXIST, "应用的消息类型已存在");
        }
 
        if (config.getCreateTime() == null) {
            config.setCreateTime(new Date());
        }
 
        msgTypeConfigMapper.insertSelective(config);
    }
 
    @Override
    public MsgTypeConfig getConfig(Long appId, UserMsg.UserMsgType msgType) {
        MsgTypeConfigQuery query = new MsgTypeConfigQuery();
        query.appId = appId;
        query.msgType = msgType;
        query.count = 1;
        List<MsgTypeConfig> list = msgTypeConfigMapper.list(query);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
 
    @Override
    public void updateConfig(MsgTypeConfig config) {
        if (config == null || config.getId() == null) {
            return;
        }
        config.setUpdateTime(new Date());
        msgTypeConfigMapper.updateByPrimaryKeySelective(config);
    }
 
    @Override
    public void delete(Long id) {
        msgTypeConfigMapper.deleteByPrimaryKey(id);
    }
}