package com.njcn.serviceimpl.tiansu;

import com.njcn.mapper.tiansu.TokenMapper;
import com.njcn.pojo.tiansu.Tokenif;
import com.njcn.service.tiansu.TokenService;
import com.njcn.utils.PubUtils;
import com.njcn.utils.ThreeDes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author hongawen
 * @Date: 2018/7/16 14:09
 */
@Service
public class TokenServiceImpl implements TokenService {

    @Autowired
    private TokenMapper tokenMapper;

    /**
     * 动态保存ticket
     * @param suiteId 应用ID
     * @param timeStamp 时间戳
     * @param suiteTicket 动态码
     */
    @Override
    public void saveToken(String suiteId, Long timeStamp, String suiteTicket) {
        Tokenif tokenif=new Tokenif();
        tokenif.setSuiteid(suiteId);
        tokenif=tokenMapper.selectOne(tokenif);
        //第一次，进行插入操作
        if(null==tokenif){
            throw new NullPointerException();
        }else{
            //更新操作
            tokenif.setSuteticket(suiteTicket);
            tokenif.setTimestamps(timeStamp);
            tokenMapper.updateByPrimaryKey(tokenif);
        }
    }

    /**
     * 根据平台商ID查询动态码信息
     * @param suiteId 平台商ID
     */
    @Override
    public Tokenif selectOne(String suiteId) {
        Tokenif tokenif=new Tokenif();
        tokenif.setSuiteid(suiteId);
        tokenif=tokenMapper.selectOne(tokenif);
        return tokenif;
    }


}
