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