admin
2019-07-25 eee931dfb53af971d79329f294fe18958f15c0de
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
package com.yeshi.fanli.service.impl.taobao;
 
import java.util.Date;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoTokenMapper;
import com.yeshi.fanli.entity.taobao.TaoBaoToken;
import com.yeshi.fanli.exception.taobao.TaoBaoTokenException;
import com.yeshi.fanli.service.inter.taobao.TaoBaoTokenService;
import com.yeshi.fanli.util.StringUtil;
 
@Service
public class TaoBaoTokenServiceImpl implements TaoBaoTokenService {
    @Resource
    private TaoBaoTokenMapper taoBaoTokenMapper;
 
    @Override
    public void addTaoBaoToken(TaoBaoToken token) throws TaoBaoTokenException {
        if (token == null || token.getAuctionId() == null || StringUtil.isNullOrEmpty(token.getPid())
                || StringUtil.isNullOrEmpty(token.getToken()))
            throw new TaoBaoTokenException(1, "数据不完整");
 
        token.setCreateTime(new Date());
        // 淘口令设置29天有效
        token.setExpireTime(new Date(token.getCreateTime().getTime() + 1000 * 60 * 60 * 24 * 29L));
 
        TaoBaoToken old = taoBaoTokenMapper.selectByAuctionId(token.getAuctionId(), token.getPid());
        if (old != null) {
            TaoBaoToken update = new TaoBaoToken();
            update.setId(old.getId());
            update.setToken(token.getToken());
            update.setExpireTime(token.getExpireTime());
            taoBaoTokenMapper.updateByPrimaryKeySelective(update);
        } else {
            taoBaoTokenMapper.insertSelective(token);
        }
 
    }
 
    @Override
    public TaoBaoToken getTaoBaoToken(Long auctionId, String pid) {
        TaoBaoToken token = taoBaoTokenMapper.selectByAuctionId(auctionId, pid);
        if (token != null && token.getExpireTime().getTime() >= System.currentTimeMillis())
            return token;
        else
            return null;
    }
 
}