package cn.ey.biz.module.external.api.smarthub.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;

import cn.ey.biz.module.external.api.smarthub.feign.ISmartHubFeignService;
import cn.ey.biz.module.external.api.smarthub.feign.reqdto.CodeGroupRequestDTO;
import cn.ey.biz.module.external.api.smarthub.feign.resdto.CodeGroupResponseDTO;
import cn.ey.biz.module.external.api.smarthub.feign.resdto.DummyCodeListResponseDTO;
import cn.ey.biz.module.external.api.smarthub.feign.resdto.EngagementDetailResponseDTO;
import cn.ey.biz.module.external.api.smarthub.feign.resdto.EngagementResponseDTO;
import cn.ey.biz.module.external.api.smarthub.service.ISmartHubService;
import cn.ey.biz.module.external.api.smarthub.service.requestdto.CodeGroupReqDTO;
import cn.ey.biz.module.external.api.smarthub.service.responsedto.CodeGroupResDTO;
import cn.ey.biz.module.external.api.smarthub.service.responsedto.EngagementDetailResDTO;
import cn.ey.biz.module.external.api.smarthub.service.responsedto.EngagementResDTO;

@Service
public class SmartHubServiceImpl implements ISmartHubService{
	
	private final Logger log = LoggerFactory.getLogger(getClass());
	
	@Autowired
	private ISmartHubFeignService smartHubFeignService;

	@Override
	public List<String> getDummyCodeList(String opportunityId, String paceId) {
		long startTime = System.currentTimeMillis();
		DummyCodeListResponseDTO dummyCodeList = smartHubFeignService.getDummyCodeList(opportunityId, paceId);
		long endTime = System.currentTimeMillis();
		log.info("DummyCodeList查询消耗时间s:"+(endTime-startTime)/1000);
		return dummyCodeList.getData();
	}

	@Override
	public EngagementResDTO getGroupBudgetByDummyCode(String code) {
		long startTime = System.currentTimeMillis();
		EngagementResponseDTO groupBudgetByDummyCode = smartHubFeignService.getGroupBudgetByDummyCode(code);
		long endTime = System.currentTimeMillis();
		log.info("GroupBudget查询消耗时间s:"+(endTime-startTime)/1000);
		return JSON.parseObject(JSON.toJSONString(groupBudgetByDummyCode.getData()), EngagementResDTO.class);
		
	}

	@Override
	public EngagementDetailResDTO getDummyCodeDetail(String code) {
		long startTime = System.currentTimeMillis();
		EngagementDetailResponseDTO dummyCodeDetail = smartHubFeignService.getDummyCodeDetail(code);
		long endTime = System.currentTimeMillis();
		log.info("DummyCodeDetail查询消耗时间s:"+(endTime-startTime)/1000);
		return JSON.parseObject(JSON.toJSONString(dummyCodeDetail.getData()), EngagementDetailResDTO.class);
	}

	@Override
	public List<CodeGroupResDTO> getDummyCodeMasterSlaveRelationship(CodeGroupReqDTO req) {
		long startTime = System.currentTimeMillis();
		CodeGroupRequestDTO request = new CodeGroupRequestDTO();
		request.setPage(req.getPage());
		request.setPageSize(req.getPageSize());
		CodeGroupResponseDTO dummyCodeMasterSlaveRelationships = smartHubFeignService.getDummyCodeMasterSlaveRelationship(request);
		long endTime = System.currentTimeMillis();
		log.info("DummyCodeMasterSlaveRelationship查询消耗时间s:"+(endTime-startTime)/1000);
		return JSON.parseArray(JSON.toJSONString(dummyCodeMasterSlaveRelationships.getData()), CodeGroupResDTO.class);
	}
	
	
	
	
	
	
}
