package com.tax.token.service.impl;

import com.tax.token.model.*;
import com.tax.token.service.api.SignService;
import com.yxcheng.token.common.model.JsonResult;
import com.yxcheng.token.common.template.ApiTemplate;
import com.yxcheng.token.utils.*;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;

@Transactional
@Component
@ComponentScan(basePackages = {"com.tax.sign.dao"})
public class SignServiceImpl implements SignService {
    @Override
    public JsonResult<SignModel> getLoginSign(SignReq signReq, HttpServletRequest request) {
        return new ApiTemplate<JsonResult<SignModel>>("getLoginSign") {
            @Override
            protected JsonResult<SignModel> process() throws Exception {
                JsonResult<SignModel>jsonResult = new JsonResult<SignModel>();
                String taxno = signReq.getTaxno();
                Long time = DateUtils.getDate().getTime();
                String timeSec = String.valueOf(time);
                String result = MD5Util.MD5Encode(UUIDGenerator.gen());
                logger.info("sign:" + result);
                SignModel model = new SignModel();
                model.setSign(result);
                model.setTaxno(taxno);
                model.setTs(timeSec);
                jsonResult.setData(model);
                return jsonResult;
            }
        }.execute();
    }


}
