package com.ks.goldcorn.service.remote;
|
|
import com.ks.goldcorn.exception.GoldAppException;
|
import com.ks.goldcorn.exception.GoldSourceException;
|
import com.ks.goldcorn.mapper.GoldCornGetSourceMapper;
|
import com.ks.goldcorn.pojo.DO.GoldCornGetSource;
|
import com.ks.goldcorn.query.SourceQuery;
|
import com.ks.goldcorn.service.GoldCornAppManager;
|
import io.seata.core.context.RootContext;
|
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 GoldCornGetSourceServiceImpl implements GoldCornGetSourceService {
|
@Resource
|
private GoldCornAppManager goldCornAppManager;
|
|
@Resource
|
private GoldCornGetSourceMapper goldCornGetSourceMapper;
|
|
|
@Override
|
public List<GoldCornGetSource> 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 goldCornGetSourceMapper.list(query);
|
}
|
|
@Override
|
public GoldCornGetSource selectByAppAndCode(String appCode, String code) {
|
Long appId = goldCornAppManager.selectAppIdByAppCode(appCode);
|
if (appId == null) {
|
return null;
|
}
|
return goldCornGetSourceMapper.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 goldCornGetSourceMapper.count(query);
|
}
|
|
@Override
|
public void addSource(GoldCornGetSource source) throws GoldSourceException {
|
System.out.println("开始全局事务,XID = " + RootContext.getXID());
|
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());
|
GoldCornGetSource old = goldCornGetSourceMapper.selectByAppIdAndSourceCode(source.getAppId(), source.getSourceCode());
|
if (old != null) {
|
throw new GoldSourceException(GoldSourceException.CODE_EXIST, "来源已存在");
|
}
|
goldCornGetSourceMapper.insertSelective(source);
|
}
|
|
@Override
|
public void deleteSource(Long id) {
|
goldCornGetSourceMapper.deleteByPrimaryKey(id);
|
}
|
|
@Override
|
public void updateSource(GoldCornGetSource source) throws GoldSourceException {
|
|
if (source == null || source.getId() == null) {
|
throw new GoldSourceException(GoldSourceException.CODE_PARAMS_NOT_ENOUGH, "参数不完整");
|
}
|
GoldCornGetSource old = goldCornGetSourceMapper.selectByPrimaryKey(source.getId());
|
if (old == null) {
|
throw new GoldSourceException(GoldSourceException.CODE_NOT_EXIST, "来源不存在");
|
}
|
//修改
|
source.setUpdateTime(new Date());
|
goldCornGetSourceMapper.updateByPrimaryKeySelective(source);
|
}
|
|
@Override
|
public List<GoldCornGetSource> listShow(String appCode, int page, int pageSize) throws GoldAppException {
|
Long appId = goldCornAppManager.getAppId(appCode);
|
SourceQuery query = new SourceQuery();
|
query.setAppId(appId);
|
query.setStart((page - 1) * pageSize);
|
query.setCount(pageSize);
|
query.setState(GoldCornGetSource.STATE_NORMAL);
|
return goldCornGetSourceMapper.list(query);
|
}
|
|
@Override
|
public long countShow(String appCode) throws GoldAppException {
|
Long appId = goldCornAppManager.getAppId(appCode);
|
SourceQuery query = new SourceQuery();
|
query.setAppId(appId);
|
query.setState(GoldCornGetSource.STATE_NORMAL);
|
return goldCornGetSourceMapper.count(query);
|
}
|
}
|