package cn.superdesk.uniorder.openapicall.superdeskmall.service;

import cn.hutool.json.JSONUtil;
import cn.superdesk.uniorder.openapicall.superdeskmall.dto.RespMall;
import cn.superdesk.uniorder.openapicall.superdeskmall.dto.ResultIEq17AndcEqentryAndmEqsuperdesk_shopv2AnddoEqmobileAndrEqpcDotxcxDotaccountDottotal;
import cn.superdesk.uniorder.openapicall.superdeskmall.restapi.FlscQchCallApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import retrofit2.Call;

import java.io.IOException;

/**
 * @Description: 侨城汇 - 福利商城
 * @Author: linjinyu
 * @CreateDate: 2021/9/26 下午3:17
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021/9/26 下午3:17
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Service
public class FlscQchCallService {

	@Autowired
	private FlscQchCallApi flscQchCallApi;

	@Value("${test.superdeskmall.flscqch.accessToken}")
	private String accessToken;
	@Value("${test.superdeskmall.flscqch.accessKeyId}")
	private String accessKeyId;
	@Value("${test.superdeskmall.flscqch.accessKeySecret}")
	private String accessKeySecret;

	/**
	 * @param token
	 * @param messageId
	 * @param status    状态 1处理成功 2处理失败
	 */
	public void receiveCallback(String token, String messageId, Integer status) {

		String response = flscQchCallApi.receiveCallback(accessToken, messageId, status);

//		log.info("{}", response);
	}




	/****************************************** 电视大屏 start ******************************************/

	public Long dashboardTvGetUserCount(String token) {

		Long count;

		RespMall<ResultIEq17AndcEqentryAndmEqsuperdesk_shopv2AnddoEqmobileAndrEqpcDotxcxDotaccountDottotal> response = null;

		try {

			Call<RespMall<ResultIEq17AndcEqentryAndmEqsuperdesk_shopv2AnddoEqmobileAndrEqpcDotxcxDotaccountDottotal>> callResponse = flscQchCallApi.dashboardTvGetUserCount();

			response = callResponse.execute().body();
			count = response.getResult().getMembers();
			log.info("dashboardTvGetUserCount response\n{}", JSONUtil.toJsonStr(response));
		} catch (com.github.lianjiatech.retrofit.spring.boot.exception.RetrofitException retrofitException){

			count = 0L;

		} catch (IOException ioe) {
			ioe.printStackTrace();
			count = 0L;
		}

		return count;
	}
}
