| | |
| | | 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;
|
| | | }
|
| | |
|
| | | }
|
| | | 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(String auctionId, String pid) { |
| | | TaoBaoToken token = taoBaoTokenMapper.selectByAuctionId(auctionId, pid); |
| | | if (token != null && token.getExpireTime().getTime() >= System.currentTimeMillis()) |
| | | return token; |
| | | else |
| | | return null; |
| | | } |
| | | |
| | | } |