admin
2024-09-27 17caebabf7a6a529b7039c71e21e5a324e31ea20
src/main/java/com/taoke/autopay/service/impl/agent/ChannelAgentServiceImpl.java
@@ -7,8 +7,10 @@
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.ArrayList;
import java.util.Date;
import java.util.List;
@@ -26,46 +28,53 @@
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void addChannelAgent(ChannelAgent agent) throws ChannelAgentException {
        ChannelAgentMapper.DaoQuery query=new ChannelAgentMapper.DaoQuery();
    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);
       }
        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);
       if(agent.getCreateTime()==null){
           agent.setCreateTime(new Date());
       }
       channelAgentMapper.insertSelective(agent);
       // 更新alias
        if(agent.getAlias()==null){
        // 更新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 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();
        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){
        if (agent.getUpdateTime() == null) {
            agent.setUpdateTime(new Date());
        }
        channelAgentMapper.updateByPrimaryKeySelective(agent);
@@ -80,4 +89,47 @@
    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);
    }
    @Override
    public List<ChannelAgent> listByIds(List<Long> ids) {
        if(ids==null||ids.size()==0){
            return new ArrayList<>();
        }
        return channelAgentMapper.listByIds(ids);
    }
}