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 org.yeshi.utils.StringUtil;
|
|
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 ChannelAgent 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();
|
agent.setAlias(update.getAlias());
|
channelAgentMapper.updateByPrimaryKeySelective(update);
|
}
|
|
return agent;
|
|
}
|
|
@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 ChannelAgent selectByPrimaryKey(Long agengId) {
|
return channelAgentMapper.selectByPrimaryKey(agengId);
|
}
|
|
@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);
|
}
|
|
@Override
|
public void delete(Long id) {
|
channelAgentMapper.deleteByPrimaryKey(id);
|
}
|
|
@Override
|
public ChannelAgent login(String account, String pwd) throws ChannelAgentException {
|
|
ChannelAgentMapper.DaoQuery query = new ChannelAgentMapper.DaoQuery();
|
query.account = account;
|
query.count = 1;
|
List<ChannelAgent> list = channelAgentMapper.list(query);
|
if (list.isEmpty()) {
|
throw new ChannelAgentException("账户不存在");
|
}
|
if (!list.get(0).getPwd().equalsIgnoreCase(StringUtil.Md5(pwd))) {
|
throw new ChannelAgentException("密码错误");
|
}
|
|
|
return list.get(0);
|
}
|
|
@Override
|
public ChannelAgent selectByAlias(String alias) {
|
ChannelAgentMapper.DaoQuery query = new ChannelAgentMapper.DaoQuery();
|
query.alias = alias;
|
query.count = 1;
|
List<ChannelAgent> list = channelAgentMapper.list(query);
|
if (list.isEmpty()) {
|
return null;
|
}
|
return list.get(0);
|
}
|
}
|