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);
|
}
|
}
|