package com.taoke.autopay.service.impl.agent;
|
|
import com.taoke.autopay.dao.agent.ChannelAgentMapper;
|
import com.taoke.autopay.entity.agent.ChannelAgent;
|
import com.taoke.autopay.exception.ChannelAgentException;
|
import com.taoke.autopay.service.agent.ChannelAgentService;
|
import com.taoke.autopay.utils.AgentAliasUtil;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* @author hxh
|
* @title: ChannelAgentServiceImpl
|
* @description: TODO
|
* @date 2024/7/25 22:28
|
*/
|
@Service
|
public class ChannelAgentServiceImpl implements ChannelAgentService {
|
|
@Resource
|
private ChannelAgentMapper channelAgentMapper;
|
|
@Transactional(rollbackFor = Exception.class)
|
@Override
|
public void addChannelAgent(ChannelAgent agent) throws ChannelAgentException {
|
ChannelAgentMapper.DaoQuery query=new ChannelAgentMapper.DaoQuery();
|
query.account = agent.getAccount();
|
long count = channelAgentMapper.count(query);
|
if(count>0){
|
throw new ChannelAgentException("账号已存在");
|
}
|
if(agent.getStatus()==null){
|
agent.setStatus(ChannelAgent.STATUS_NOMAL);
|
}
|
|
|
|
if(agent.getCreateTime()==null){
|
agent.setCreateTime(new Date());
|
}
|
channelAgentMapper.insertSelective(agent);
|
|
// 更新alias
|
if(agent.getAlias()==null){
|
ChannelAgent update = ChannelAgent.builder().id(agent.getId()).alias(AgentAliasUtil.createAlias(agent.getId())).updateTime(new Date()).build();
|
channelAgentMapper.updateByPrimaryKeySelective(update);
|
}
|
|
}
|
|
@Transactional(rollbackFor = Exception.class)
|
@Override
|
public void setAlipayAccount(Long agentId, String name, String account) throws ChannelAgentException {
|
ChannelAgent agent = channelAgentMapper.selectByPrimaryKeyForUpdate(agentId);
|
if(agent==null){
|
throw new ChannelAgentException("代理ID不存在");
|
}
|
ChannelAgent update= ChannelAgent.builder().id(agentId).alipayAccount(account).alipayName(name).alipayUpdateTime(new Date()).updateTime(new Date()).build();
|
updateSelective(update);
|
}
|
|
@Override
|
public void updateSelective(ChannelAgent agent) {
|
if(agent.getUpdateTime()==null){
|
agent.setUpdateTime(new Date());
|
}
|
channelAgentMapper.updateByPrimaryKeySelective(agent);
|
}
|
|
@Override
|
public List<ChannelAgent> list(ChannelAgentMapper.DaoQuery query) {
|
return channelAgentMapper.list(query);
|
}
|
|
@Override
|
public long count(ChannelAgentMapper.DaoQuery query) {
|
return channelAgentMapper.count(query);
|
}
|
}
|