admin
2024-07-27 65aaf1c05bd06cefa82ebc40cc3e01cf4ac233c0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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);
    }
}