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

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

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

import com.alibaba.cloudapi.sdk.model.ApiResponse;
import com.alibaba.dt.dataphin.client.ApiClient;
import com.alibaba.dt.dataphin.schema.QueryParamRequest;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import cn.ey.biz.module.external.api.datacenter.client.DcRemoteCaller;
import cn.ey.biz.module.external.api.datacenter.client.config.DataCenterConfig;
import cn.ey.biz.module.external.api.datacenter.client.reqdto.BookingDataRequest;
import cn.ey.biz.module.external.api.datacenter.client.reqdto.ContractEngRequest;
import cn.ey.biz.module.external.api.datacenter.client.reqdto.ContractVentorRequest;
import cn.ey.biz.module.external.api.datacenter.client.reqdto.EngagementFinanceIndexSummaryRequest;
import cn.ey.biz.module.external.api.datacenter.client.reqdto.EngagementQueryRequest;
import cn.ey.biz.module.external.api.datacenter.client.reqdto.EngagementSingleIndexSummaryRequest;
import cn.ey.biz.module.external.api.datacenter.client.reqdto.PersonnelTimeMonthSumRequest;
import cn.ey.biz.module.external.api.datacenter.client.reqdto.PersonnelTimeWeeksSumRequest;
import cn.ey.biz.module.external.api.datacenter.client.reqdto.PersonnelTimeYearsSumRequest;
import cn.ey.biz.module.external.api.datacenter.client.resdto.BookingDataResponse;
import cn.ey.biz.module.external.api.datacenter.client.resdto.BookingDataResponse.BookingData;
import cn.ey.biz.module.external.api.datacenter.client.resdto.ContractBillingCollectionDetailResponse;
import cn.ey.biz.module.external.api.datacenter.client.resdto.ContractBillingCollectionDetailResponse.ContractBillingCollectionDetailData;
import cn.ey.biz.module.external.api.datacenter.client.resdto.ContractBillingCreatdetailResponse;
import cn.ey.biz.module.external.api.datacenter.client.resdto.ContractBillingCreatdetailResponse.ContractBillingCreatdetailData;
import cn.ey.biz.module.external.api.datacenter.client.resdto.ContractEngDetailResponse;
import cn.ey.biz.module.external.api.datacenter.client.resdto.ContractEngDetailResponse.ContractEngDetailData;
import cn.ey.biz.module.external.api.datacenter.client.resdto.ContractVentorQueryDetailResponse;
import cn.ey.biz.module.external.api.datacenter.client.resdto.ContractVentorQueryDetailResponse.ContractVentorQueryDetailData;
import cn.ey.biz.module.external.api.datacenter.client.resdto.EngagementComparativeExpenseResponse;
import cn.ey.biz.module.external.api.datacenter.client.resdto.EngagementComparativeExpenseResponse.EngagementComparativeExpenseData;
import cn.ey.biz.module.external.api.datacenter.client.resdto.EngagementComparatorResponse;
import cn.ey.biz.module.external.api.datacenter.client.resdto.EngagementComparatorResponse.EngagementComparatorData;
import cn.ey.biz.module.external.api.datacenter.client.resdto.EngagementFinanceIndexSummaryResponse;
import cn.ey.biz.module.external.api.datacenter.client.resdto.EngagementFinanceIndexSummaryResponse.EngagementFinanceIndexSummaryData;
import cn.ey.biz.module.external.api.datacenter.client.resdto.EngagementSingleIndexSummaryResponse;
import cn.ey.biz.module.external.api.datacenter.client.resdto.EngagementSingleIndexSummaryResponse.EngagementSingleIndexSummaryData;
import cn.ey.biz.module.external.api.datacenter.client.resdto.EngagementSurplusExpenseResponse;
import cn.ey.biz.module.external.api.datacenter.client.resdto.EngagementSurplusExpenseResponse.EngagementSurplusExpenseData;
import cn.ey.biz.module.external.api.datacenter.client.resdto.EngagementSurplusSerResponse;
import cn.ey.biz.module.external.api.datacenter.client.resdto.EngagementSurplusSerResponse.EngagementSurplusSerData;
import cn.ey.biz.module.external.api.datacenter.client.resdto.EngagementUserRecordResponse;
import cn.ey.biz.module.external.api.datacenter.client.resdto.EngagementUserRecordResponse.EngagementUserRecordData;
import cn.ey.biz.module.external.api.datacenter.client.resdto.PcolibDimworklocationResponse;
import cn.ey.biz.module.external.api.datacenter.client.resdto.PcolibDimworklocationResponse.DimworklocationData;
import cn.ey.biz.module.external.api.datacenter.client.resdto.PersonnelTimeMonthSumResponse;
import cn.ey.biz.module.external.api.datacenter.client.resdto.PersonnelTimeMonthSumResponse.PersonnelTimeMonthSumData;
import cn.ey.biz.module.external.api.datacenter.client.resdto.PersonnelTimeWeeksSumResponse;
import cn.ey.biz.module.external.api.datacenter.client.resdto.PersonnelTimeWeeksSumResponse.PersonnelTimeWeeksSumData;
import cn.ey.biz.module.external.api.datacenter.client.resdto.PersonnelTimeYearsSumResponse;
import cn.ey.biz.module.external.api.datacenter.client.resdto.PersonnelTimeYearsSumResponse.PersonnelTimeYearsSumData;
import cn.ey.biz.module.external.api.datacenter.service.IDataCenterService;
import cn.ey.biz.module.external.api.datacenter.service.requestdto.ApDetailsAllReqDTO;
import cn.ey.biz.module.external.api.datacenter.service.requestdto.ApDetailsCountReqDTO;
import cn.ey.biz.module.external.api.datacenter.service.requestdto.ApDetailsPageReqDTO;
import cn.ey.biz.module.external.api.datacenter.service.requestdto.BillingAndCollectionReqDTO;
import cn.ey.biz.module.external.api.datacenter.service.requestdto.BookingDataReqDTO;
import cn.ey.biz.module.external.api.datacenter.service.requestdto.ContractEngReqDTO;
import cn.ey.biz.module.external.api.datacenter.service.requestdto.ContractVentorReqDTO;
import cn.ey.biz.module.external.api.datacenter.service.requestdto.EngagementUserRecordReqDTO;
import cn.ey.biz.module.external.api.datacenter.service.requestdto.ExpensesCompareReqDTO;
import cn.ey.biz.module.external.api.datacenter.service.requestdto.PcolibDimworklocationReqDTO;
import cn.ey.biz.module.external.api.datacenter.service.requestdto.PersonnelChargeReqDTO;
import cn.ey.biz.module.external.api.datacenter.service.requestdto.PersonnelChargeUseRecordResDTO;
import cn.ey.biz.module.external.api.datacenter.service.requestdto.PersonnelTimeMonthSumReqDTO;
import cn.ey.biz.module.external.api.datacenter.service.requestdto.PersonnelTimeWeeksSumReqDTO;
import cn.ey.biz.module.external.api.datacenter.service.requestdto.PersonnelTimeYearsSumReqDTO;
import cn.ey.biz.module.external.api.datacenter.service.responsedto.ApPaymentDetailsCountResDTO;
import cn.ey.biz.module.external.api.datacenter.service.responsedto.ApPaymentDetailsResDTO;
import cn.ey.biz.module.external.api.datacenter.service.responsedto.BillingAndCollectionCountResDTO;
import cn.ey.biz.module.external.api.datacenter.service.responsedto.BillingAndCollectionResDTO;
import cn.ey.biz.module.external.api.datacenter.service.responsedto.BookingDataResDTO;
import cn.ey.biz.module.external.api.datacenter.service.responsedto.ContractBillingCollectionDetailResDTO;
import cn.ey.biz.module.external.api.datacenter.service.responsedto.ContractBillingCreatdetailResDTO;
import cn.ey.biz.module.external.api.datacenter.service.responsedto.ContractEngDetailResDTO;
import cn.ey.biz.module.external.api.datacenter.service.responsedto.ContractVentorQueryDetailResDTO;
import cn.ey.biz.module.external.api.datacenter.service.responsedto.EngagementComparativeExpenseResDTO;
import cn.ey.biz.module.external.api.datacenter.service.responsedto.EngagementComparatorResDTO;
import cn.ey.biz.module.external.api.datacenter.service.responsedto.EngagementFinanceIndexSummaryResDTO;
import cn.ey.biz.module.external.api.datacenter.service.responsedto.EngagementSingleIndexSummaryResDTO;
import cn.ey.biz.module.external.api.datacenter.service.responsedto.EngagementSurplusExpenseResDTO;
import cn.ey.biz.module.external.api.datacenter.service.responsedto.EngagementSurplusSerResDTO;
import cn.ey.biz.module.external.api.datacenter.service.responsedto.EngagementUserRecordResDTO;
import cn.ey.biz.module.external.api.datacenter.service.responsedto.ExpensesCompareResDTO;
import cn.ey.biz.module.external.api.datacenter.service.responsedto.PcolibDimworklocationResDTO;
import cn.ey.biz.module.external.api.datacenter.service.responsedto.PersonnelTimeMonthSumResDTO;
import cn.ey.biz.module.external.api.datacenter.service.responsedto.PersonnelTimeWeeksSumResDTO;
import cn.ey.biz.module.external.api.datacenter.service.responsedto.PersonnelTimeYearsSumResDTO;

@Service
public class DataCenterServiceImpl implements IDataCenterService{
	
	private final Logger log = LoggerFactory.getLogger(getClass());
	
	@Autowired
	private DataCenterConfig dcConfig;
	
	@Override
	public List<ApPaymentDetailsResDTO> getApDetailsPage(ApDetailsPageReqDTO request) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<ApPaymentDetailsResDTO> getApDetailsAll(ApDetailsAllReqDTO request) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ApPaymentDetailsCountResDTO getApDetailsCount(ApDetailsCountReqDTO request) {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public List<BillingAndCollectionResDTO> getBillingAndCollectionPage(BillingAndCollectionReqDTO request) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<BillingAndCollectionResDTO> getBillingAndCollectionAll(BillingAndCollectionReqDTO request) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BillingAndCollectionCountResDTO getBillingAndCollectionCount(BillingAndCollectionReqDTO request) {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public PersonnelChargeUseRecordResDTO getPersonnelChargeUsageRecord(PersonnelChargeReqDTO request) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ExpensesCompareResDTO getExpensesCompareData(ExpensesCompareReqDTO request) {
		// TODO Auto-generated method stub
		return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PersonnelTimeWeeksSumResDTO> getPersonnelTimeWeeksSum(PersonnelTimeWeeksSumReqDTO req){
		PersonnelTimeWeeksSumRequest request = new PersonnelTimeWeeksSumRequest();
		request.setGpn(req.getGpn());
		request.setWeek_end(req.getWeekEnd());
		QueryParamRequest queryParamRequest = new QueryParamRequest();
		Map<String, Object> conditions = JSON.parseObject(JSON.toJSONString(request), Map.class);
		queryParamRequest.setConditions(conditions);
		queryParamRequest.setPageStart((req.getPageNo()-1)*req.getPageSize());
		queryParamRequest.setPageSize(req.getPageSize());
		List<String> returnFields = this.getClassFieldsName(PersonnelTimeWeeksSumData.class);
		queryParamRequest.setReturnFields(returnFields);
		log.info("接口"+dcConfig.getWAppId()+"入参："+JSON.toJSONString(queryParamRequest));
		ApiClient client = DcRemoteCaller.getTimeSheetApiClient();
		ApiResponse listSync = client.listSync(dcConfig.getWAppId(), queryParamRequest);
		log.info("接口"+dcConfig.getWAppId()+"反参:"+JSON.toJSONString(listSync));
		if(200 != listSync.getCode()) {
			throw new RuntimeException(listSync.getMessage());
		}
		byte[] bodyBytes = listSync.getBody();
		log.info("接口"+dcConfig.getWAppId()+"反参body:"+new String(bodyBytes));
		PersonnelTimeWeeksSumResponse parseObject = JSON.parseObject(new String(bodyBytes), PersonnelTimeWeeksSumResponse.class);
		List<PersonnelTimeWeeksSumResDTO> parseArray = JSON.parseArray(JSON.toJSONString(parseObject.getResults()), PersonnelTimeWeeksSumResDTO.class);
		return parseArray;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PersonnelTimeMonthSumResDTO> getPersonnelTimeMonthSum(PersonnelTimeMonthSumReqDTO req) {
		PersonnelTimeMonthSumRequest request = new PersonnelTimeMonthSumRequest();
		request.setGpn(req.getGpn());
		request.setMonth(req.getMonth());
		QueryParamRequest queryParamRequest = new QueryParamRequest();
		Map<String, Object> conditions = JSON.parseObject(JSON.toJSONString(request), Map.class);
		queryParamRequest.setConditions(conditions);
		queryParamRequest.setPageStart((req.getPageNo()-1)*req.getPageSize());
		queryParamRequest.setPageSize(req.getPageSize());
		List<String> returnFields = this.getClassFieldsName(PersonnelTimeMonthSumData.class);
		queryParamRequest.setReturnFields(returnFields);
		log.info("接口"+dcConfig.getMAppId()+"入参："+JSON.toJSONString(queryParamRequest));
		ApiClient client = DcRemoteCaller.getTimeSheetApiClient();
		ApiResponse listSync = client.listSync(dcConfig.getMAppId(), queryParamRequest);
		log.info("接口"+dcConfig.getMAppId()+"反参:"+JSON.toJSONString(listSync));
		if(200 != listSync.getCode()) {
			throw new RuntimeException(listSync.getMessage());
		}
		byte[] bodyBytes = listSync.getBody();
		log.info("接口"+dcConfig.getMAppId()+"反参body:"+new String(bodyBytes));
		PersonnelTimeMonthSumResponse parseObject = JSON.parseObject(new String(bodyBytes), PersonnelTimeMonthSumResponse.class);
		List<PersonnelTimeMonthSumResDTO> parseArray = JSON.parseArray(JSON.toJSONString(parseObject.getResults()), PersonnelTimeMonthSumResDTO.class);
		return parseArray;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PersonnelTimeYearsSumResDTO> getPersonnelTimeYearsSum(PersonnelTimeYearsSumReqDTO req) {
		PersonnelTimeYearsSumRequest request = new PersonnelTimeYearsSumRequest();
		request.setGpn(req.getGpn());
		request.setFiscal_year(req.getFiscalYear());
		QueryParamRequest queryParamRequest = new QueryParamRequest();
		Map<String, Object> conditions = JSON.parseObject(JSON.toJSONString(request), Map.class);
		queryParamRequest.setConditions(conditions);
		queryParamRequest.setPageStart((req.getPageNo()-1)*req.getPageSize());
		queryParamRequest.setPageSize(req.getPageSize());
		List<String> returnFields = this.getClassFieldsName(PersonnelTimeYearsSumData.class);
		queryParamRequest.setReturnFields(returnFields);
		log.info("接口"+dcConfig.getYAppId()+"入参："+JSON.toJSONString(queryParamRequest));
		ApiClient client = DcRemoteCaller.getTimeSheetApiClient();
		ApiResponse listSync = client.listSync(dcConfig.getYAppId(), queryParamRequest);
		log.info("接口"+dcConfig.getYAppId()+"反参:"+JSON.toJSONString(listSync));
		if(200 != listSync.getCode()) {
			throw new RuntimeException(listSync.getMessage());
		}
		byte[] bodyBytes = listSync.getBody();
		log.info("接口"+dcConfig.getYAppId()+"反参body:"+new String(bodyBytes));
		PersonnelTimeYearsSumResponse parseObject = JSON.parseObject(new String(bodyBytes), PersonnelTimeYearsSumResponse.class);
		List<PersonnelTimeYearsSumResDTO> parseArray = JSON.parseArray(JSON.toJSONString(parseObject.getResults()), PersonnelTimeYearsSumResDTO.class);
		return parseArray;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<BookingDataResDTO> getbookingData(BookingDataReqDTO req) {
		BookingDataRequest request = new BookingDataRequest();
		QueryParamRequest queryParamRequest = new QueryParamRequest();
		Map<String, Object> conditions = JSON.parseObject(JSON.toJSONString(request), Map.class);
		queryParamRequest.setConditions(conditions);
		queryParamRequest.setPageStart((req.getPageNo()-1)*req.getPageSize());
		queryParamRequest.setPageSize(req.getPageSize());
		List<String> returnFields = this.getClassFieldsName(BookingData.class);
		queryParamRequest.setReturnFields(returnFields);
		log.info("接口"+dcConfig.getBookingDataAppId()+"入参："+JSON.toJSONString(queryParamRequest));
		ApiClient client = DcRemoteCaller.getTimeSheetApiClient();
		ApiResponse listSync = client.listSync(dcConfig.getBookingDataAppId(), queryParamRequest);
		log.info("接口"+dcConfig.getBookingDataAppId()+"反参:"+JSON.toJSONString(listSync));
		if(200 != listSync.getCode()) {
			throw new RuntimeException(listSync.getMessage());
		}
		byte[] bodyBytes = listSync.getBody();
		log.info("接口"+dcConfig.getBookingDataAppId()+"反参body:"+new String(bodyBytes));
		BookingDataResponse parseObject = JSON.parseObject(new String(bodyBytes), BookingDataResponse.class);
		List<BookingDataResDTO> parseArray = JSON.parseArray(JSON.toJSONString(parseObject.getResults()), BookingDataResDTO.class);
		return parseArray;
	}
	

	/**
	 * 
	 * @param t
	 * @return
	 */
   public  <T> List<String> getClassFieldsName(Class<T> t){
		Field[] fields = t.getDeclaredFields();
		ArrayList<String> fieldNames = Lists.newArrayList();
		for(int i = 0;i<fields.length;i++){
	   		fieldNames.add(fields[i].getName());
		}
		return fieldNames;
   }

	@SuppressWarnings("unchecked")
	@Override
	public List<EngagementComparatorResDTO> getEngagementComparator(String engagementCode) {
		EngagementQueryRequest request = new EngagementQueryRequest();
		request.setEngagement_code(engagementCode);
		ApiClient client = DcRemoteCaller.getEngagementApiClient();
		QueryParamRequest queryParamRequest = new QueryParamRequest();
		Map<String, Object> conditions = JSON.parseObject(JSON.toJSONString(request), Map.class);
		queryParamRequest.setConditions(conditions);
//		queryParamRequest.setPageStart((req.getPageNo()-1)*req.getPageSize());
//		queryParamRequest.setPageSize(req.getPageSize());
		List<String> returnFields = this.getClassFieldsName(EngagementComparatorData.class);
		queryParamRequest.setReturnFields(returnFields);
		log.info("接口项目实际/计划比较人员接口-CCT/MMT"+dcConfig.getAggEngAppId()+"入参："+JSON.toJSONString(queryParamRequest));
		ApiResponse listSync = client.listSync(dcConfig.getAggEngAppId(), queryParamRequest);
		log.info("接口项目实际/计划比较人员接口-CCT/MMT"+dcConfig.getAggEngAppId()+"反参:"+JSON.toJSONString(listSync));
		if(200 != listSync.getCode()) {
			throw new RuntimeException(listSync.getMessage());
		}
		byte[] bodyBytes = listSync.getBody();
		log.info("接口项目实际/计划比较人员接口-CCT/MMT"+dcConfig.getAggEngAppId()+"反参body:"+new String(bodyBytes));
		EngagementComparatorResponse parseObject = JSON.parseObject(new String(bodyBytes), EngagementComparatorResponse.class);
		List<EngagementComparatorResDTO> parseArray = JSON.parseArray(JSON.toJSONString(parseObject.getResults()), EngagementComparatorResDTO.class);
		return parseArray;
	}

	@SuppressWarnings("unchecked")
	@Override
	public EngagementSurplusSerResDTO getEngagementSurplusSer(String engagementCode) {
		EngagementQueryRequest request = new EngagementQueryRequest();
		request.setEngagement_code(engagementCode);
		ApiClient client = DcRemoteCaller.getEngagementApiClient();
		QueryParamRequest queryParamRequest = new QueryParamRequest();
		Map<String, Object> conditions = JSON.parseObject(JSON.toJSONString(request), Map.class);
		queryParamRequest.setConditions(conditions);
//		queryParamRequest.setPageStart((req.getPageNo()-1)*req.getPageSize());
//		queryParamRequest.setPageSize(req.getPageSize());
		List<String> returnFields = this.getClassFieldsName(EngagementSurplusSerData.class);
		queryParamRequest.setReturnFields(returnFields);
		log.info("接口项目的剩余可用SER"+dcConfig.getSerSummaryAppId()+"入参："+JSON.toJSONString(queryParamRequest));
		ApiResponse listSync = client.listSync(dcConfig.getSerSummaryAppId(), queryParamRequest);
		log.info("接口项目的剩余可用SER"+dcConfig.getSerSummaryAppId()+"反参:"+JSON.toJSONString(listSync));
		if(200 != listSync.getCode()) {
			throw new RuntimeException(listSync.getMessage());
		}
		byte[] bodyBytes = listSync.getBody();
		log.info("接口项目的剩余可用SER"+dcConfig.getSerSummaryAppId()+"反参body:"+new String(bodyBytes));
		EngagementSurplusSerResponse parseObject = JSON.parseObject(new String(bodyBytes), EngagementSurplusSerResponse.class);
		if(CollectionUtils.isEmpty(parseObject.getResults())) {
			return null;
		}
		EngagementSurplusSerResDTO resDTO = JSON.parseObject(JSON.toJSONString(parseObject.getResults().get(0)), EngagementSurplusSerResDTO.class);
		return resDTO;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<EngagementUserRecordResDTO> getEngagementUserRecord(EngagementUserRecordReqDTO req) {
		EngagementQueryRequest request = new EngagementQueryRequest();
		request.setEngagement_code(req.getEngagementCode());
		request.setEmployee_gpn(req.getEmployeeGpn());
		request.setEmployee_status(req.getEmployeeStatus());
		request.setDisplay_name(req.getDisplayName());
		ApiClient client = DcRemoteCaller.getEngagementApiClient();
		QueryParamRequest queryParamRequest = new QueryParamRequest();
		Map<String, Object> conditions = JSON.parseObject(JSON.toJSONString(request), Map.class);
		queryParamRequest.setConditions(conditions);
		queryParamRequest.setPageStart((req.getPageNo()-1)*req.getPageSize());
		queryParamRequest.setPageSize(req.getPageSize());
		List<String> returnFields = this.getClassFieldsName(EngagementUserRecordData.class);
		queryParamRequest.setReturnFields(returnFields);
		log.info("接口项目人员实际使用记录"+dcConfig.getSerExpenseAppId()+"入参："+JSON.toJSONString(queryParamRequest));
		ApiResponse listSync = client.listSync(dcConfig.getSerExpenseAppId(), queryParamRequest);
		log.info("接口项目人员实际使用记录"+dcConfig.getSerExpenseAppId()+"反参:"+JSON.toJSONString(listSync));
		if(200 != listSync.getCode()) {
			throw new RuntimeException(listSync.getMessage());
		}
		byte[] bodyBytes = listSync.getBody();
		log.info("接口项目人员实际使用记录"+dcConfig.getSerExpenseAppId()+"反参body:"+new String(bodyBytes));
		EngagementUserRecordResponse parseObject = JSON.parseObject(new String(bodyBytes), EngagementUserRecordResponse.class);
		List<EngagementUserRecordResDTO> parseArray = JSON.parseArray(JSON.toJSONString(parseObject.getResults()), EngagementUserRecordResDTO.class);
		return parseArray;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<EngagementComparativeExpenseResDTO> getEngagementComparativeExpense(String engagementCode) {
		EngagementQueryRequest request = new EngagementQueryRequest();
		request.setEngagement_code(engagementCode);
		ApiClient client = DcRemoteCaller.getEngagementApiClient();
		QueryParamRequest queryParamRequest = new QueryParamRequest();
		Map<String, Object> conditions = JSON.parseObject(JSON.toJSONString(request), Map.class);
		queryParamRequest.setConditions(conditions);
//		queryParamRequest.setPageStart((req.getPageNo()-1)*req.getPageSize());
//		queryParamRequest.setPageSize(req.getPageSize());
		List<String> returnFields = this.getClassFieldsName(EngagementComparativeExpenseData.class);
		queryParamRequest.setReturnFields(returnFields);
		log.info("接口项目实际/计划比较费用接口-CCT/MMT"+dcConfig.getComparativeExpenseAppId()+"入参："+JSON.toJSONString(queryParamRequest));
		ApiResponse listSync = client.listSync(dcConfig.getComparativeExpenseAppId(), queryParamRequest);
		log.info("接口项目实际/计划比较费用接口-CCT/MMT"+dcConfig.getComparativeExpenseAppId()+"反参:"+JSON.toJSONString(listSync));
		if(200 != listSync.getCode()) {
			throw new RuntimeException(listSync.getMessage());
		}
		byte[] bodyBytes = listSync.getBody();
		log.info("接口项目实际/计划比较费用接口-CCT/MMT"+dcConfig.getComparativeExpenseAppId()+"反参body:"+new String(bodyBytes));
		EngagementComparativeExpenseResponse parseObject = JSON.parseObject(new String(bodyBytes), EngagementComparativeExpenseResponse.class);
		List<EngagementComparativeExpenseResDTO> resDTO = JSON.parseArray(JSON.toJSONString(parseObject.getResults()), EngagementComparativeExpenseResDTO.class);
		return resDTO;
	}

	@SuppressWarnings("unchecked")
	@Override
	public EngagementSurplusExpenseResDTO getEngagementSurplusExpense(String engagementCode) {
		EngagementQueryRequest request = new EngagementQueryRequest();
		request.setEngagement_code(engagementCode);
		QueryParamRequest queryParamRequest = new QueryParamRequest();
		Map<String, Object> conditions = JSON.parseObject(JSON.toJSONString(request), Map.class);
		queryParamRequest.setConditions(conditions);
//		queryParamRequest.setPageStart((req.getPageNo()-1)*req.getPageSize());
//		queryParamRequest.setPageSize(req.getPageSize());
		List<String> returnFields = this.getClassFieldsName(EngagementSurplusExpenseData.class);
		queryParamRequest.setReturnFields(returnFields);
		log.info("接口项目剩余可用费用"+dcConfig.getSurplusExpenseAppId()+"入参："+JSON.toJSONString(queryParamRequest));
		ApiClient client = DcRemoteCaller.getEngagementApiClient();
		ApiResponse listSync = client.listSync(dcConfig.getSurplusExpenseAppId(), queryParamRequest);
		log.info("接口项目剩余可用费用"+dcConfig.getSurplusExpenseAppId()+"反参:"+JSON.toJSONString(listSync));
		if(200 != listSync.getCode()) {
			throw new RuntimeException(listSync.getMessage());
		}
		byte[] bodyBytes = listSync.getBody();
		log.info("接口项目剩余可用费用"+dcConfig.getSurplusExpenseAppId()+"反参body:"+new String(bodyBytes));
		EngagementSurplusExpenseResponse parseObject = JSON.parseObject(new String(bodyBytes), EngagementSurplusExpenseResponse.class);
		if(CollectionUtils.isEmpty(parseObject.getResults())) {
			return null;
		}
		EngagementSurplusExpenseResDTO resDTO = JSON.parseObject(JSON.toJSONString(parseObject.getResults().get(0)), EngagementSurplusExpenseResDTO.class);
		return resDTO;
	}
	
	

	
	@SuppressWarnings("unchecked")
	@Override
	public EngagementFinanceIndexSummaryResDTO getEngagementFinanceIndexSummary(String mbhbCurrencyname,List<String> engagementCode) {
		EngagementFinanceIndexSummaryRequest request = new EngagementFinanceIndexSummaryRequest();
		request.setMbhb_currencyname(mbhbCurrencyname);
		request.setEngagement_code(engagementCode);
		QueryParamRequest queryParamRequest = new QueryParamRequest();
		Map<String, Object> conditions = JSON.parseObject(JSON.toJSONString(request), Map.class);
		queryParamRequest.setConditions(conditions);
		List<String> returnFields = this.getClassFieldsName(EngagementFinanceIndexSummaryData.class);
		queryParamRequest.setReturnFields(returnFields);
		log.info("接口合并财务指标"+dcConfig.getSummaryAggEngAllWfAppid()+"入参："+JSON.toJSONString(queryParamRequest));
		ApiClient client = DcRemoteCaller.getEngagementApiClient();
		ApiResponse listSync = client.listSync(dcConfig.getSummaryAggEngAllWfAppid(), queryParamRequest);
		log.info("接口合并财务指标"+dcConfig.getSummaryAggEngAllWfAppid()+"反参:"+JSON.toJSONString(listSync));
		if(200 != listSync.getCode()) {
			throw new RuntimeException(listSync.getMessage());
		}
		byte[] bodyBytes = listSync.getBody();
		log.info("接口合并财务指标"+dcConfig.getSummaryAggEngAllWfAppid()+"反参body:"+new String(bodyBytes));
		EngagementFinanceIndexSummaryResponse parseObject = JSON.parseObject(new String(bodyBytes), EngagementFinanceIndexSummaryResponse.class);
		if(CollectionUtils.isEmpty(parseObject.getResults())) {
			return null;
		}
		EngagementFinanceIndexSummaryResDTO resDTO = JSON.parseObject(JSON.toJSONString(parseObject.getResults().get(0)), EngagementFinanceIndexSummaryResDTO.class);
		return resDTO;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<EngagementSingleIndexSummaryResDTO> getEngagementSingleIndexSummary(List<String> engagementCode) {
		EngagementSingleIndexSummaryRequest request = new EngagementSingleIndexSummaryRequest();
		request.setEngagement_code(engagementCode);
		QueryParamRequest queryParamRequest = new QueryParamRequest();
		Map<String, Object> conditions = JSON.parseObject(JSON.toJSONString(request), Map.class);
		queryParamRequest.setConditions(conditions);
		List<String> returnFields = this.getClassFieldsName(EngagementSingleIndexSummaryData.class);
		queryParamRequest.setReturnFields(returnFields);
		log.info("接口单Code重点指标"+dcConfig.getSummaryAggEngSingleWfAppid()+"入参："+JSON.toJSONString(queryParamRequest));
		ApiClient client = DcRemoteCaller.getEngagementApiClient();
		ApiResponse listSync = client.listSync(dcConfig.getSummaryAggEngSingleWfAppid(), queryParamRequest);
		log.info("接口单Code重点指标"+dcConfig.getSummaryAggEngSingleWfAppid()+"反参:"+JSON.toJSONString(listSync));
		if(200 != listSync.getCode()) {
			throw new RuntimeException(listSync.getMessage());
		}
		byte[] bodyBytes = listSync.getBody();
		log.info("接口单Code重点指标"+dcConfig.getSummaryAggEngSingleWfAppid()+"反参body:"+new String(bodyBytes));
		EngagementSingleIndexSummaryResponse parseObject = JSON.parseObject(new String(bodyBytes), EngagementSingleIndexSummaryResponse.class);
		List<EngagementSingleIndexSummaryResDTO> resDTO = JSON.parseArray(JSON.toJSONString(parseObject.getResults()), EngagementSingleIndexSummaryResDTO.class);
		return resDTO;
	}

	@Override
	public List<PcolibDimworklocationResDTO> getPcolibDimworklocation(PcolibDimworklocationReqDTO req) {
		ApiClient client = DcRemoteCaller.getPcolibApiClient();
		QueryParamRequest queryParamRequest = new QueryParamRequest();
		Map<String, Object> conditions = Maps.newHashMap();
		queryParamRequest.setConditions(conditions);
		queryParamRequest.setPageStart((req.getPageNo()-1)*req.getPageSize());
		queryParamRequest.setPageSize(req.getPageSize());
		List<String> returnFields = this.getClassFieldsName(DimworklocationData.class);
		queryParamRequest.setReturnFields(returnFields);
		log.info("接口"+dcConfig.getPcolibDimworklocationAppId()+"入参："+JSON.toJSONString(queryParamRequest));
		ApiResponse listSync = client.listSync(dcConfig.getPcolibDimworklocationAppId(), queryParamRequest);
		log.info("接口"+dcConfig.getPcolibDimworklocationAppId()+"反参:"+JSON.toJSONString(listSync));
		if(200 != listSync.getCode()) {
			throw new RuntimeException(listSync.getMessage());
		}
		byte[] bodyBytes = listSync.getBody();
		log.info("接口"+dcConfig.getPcolibDimworklocationAppId()+"反参body:"+new String(bodyBytes));
		PcolibDimworklocationResponse parseObject = JSON.parseObject(new String(bodyBytes), PcolibDimworklocationResponse.class);
		List<PcolibDimworklocationResDTO> resDTO = JSON.parseArray(JSON.toJSONString(parseObject.getResults()), PcolibDimworklocationResDTO.class);
		return resDTO;
	}
	
	

	@Override
	public List<PcolibDimworklocationResDTO> getPcolibDimworklocation() {
		PcolibDimworklocationReqDTO req = new PcolibDimworklocationReqDTO();
		req.setPageNo(1);
		req.setPageSize(10000);
		return this.getPcolibDimworklocation(req);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ContractEngDetailResDTO> getContractEngDetail(ContractEngReqDTO req) {
		ContractEngRequest request = new ContractEngRequest();
		request.setEngagement_code(req.getEngagementCode());
		request.setEngagement_name(req.getEngagementName());
		QueryParamRequest queryParamRequest = new QueryParamRequest();
		Map<String, Object> conditions = JSON.parseObject(JSON.toJSONString(request), Map.class);
		queryParamRequest.setConditions(conditions);
		queryParamRequest.setPageStart((req.getPageNo()-1)*req.getPageSize());
		queryParamRequest.setPageSize(req.getPageSize());
		List<String> returnFields = this.getClassFieldsName(ContractEngDetailData.class);
		queryParamRequest.setReturnFields(returnFields);
		log.info("接口"+dcConfig.getContractEngDetailDfAppId()+"入参："+JSON.toJSONString(queryParamRequest));
		ApiClient client = DcRemoteCaller.getContractApiClient();
		ApiResponse listSync = client.listSync(dcConfig.getContractEngDetailDfAppId(), queryParamRequest);
		log.info("接口"+dcConfig.getContractEngDetailDfAppId()+"反参:"+JSON.toJSONString(listSync));
		if(200 != listSync.getCode()) {
			throw new RuntimeException(listSync.getMessage());
		}
		byte[] bodyBytes = listSync.getBody();
		log.info("接口"+dcConfig.getContractEngDetailDfAppId()+"反参body:"+new String(bodyBytes));
		ContractEngDetailResponse parseObject = JSON.parseObject(new String(bodyBytes), ContractEngDetailResponse.class);
		List<ContractEngDetailResDTO> resDTO = JSON.parseArray(JSON.toJSONString(parseObject.getResults()), ContractEngDetailResDTO.class);
		return resDTO;
	}

	@Override
	public List<ContractBillingCollectionDetailResDTO> getContractBillingCollectionDetail(ContractEngReqDTO req) {
		QueryParamRequest queryParamRequest = new QueryParamRequest();
		Map<String, Object> conditions = Maps.newHashMap();
		queryParamRequest.setConditions(conditions);
		List<String> returnFields = this.getClassFieldsName(ContractBillingCollectionDetailData.class);
		queryParamRequest.setReturnFields(returnFields);
		queryParamRequest.setPageStart((req.getPageNo()-1)*req.getPageSize());
		queryParamRequest.setPageSize(req.getPageSize());
		log.info("接口"+dcConfig.getContractBillingCollectionDetailDiAppId()+"入参："+JSON.toJSONString(queryParamRequest));
		ApiClient client = DcRemoteCaller.getContractApiClient();
		ApiResponse listSync = client.listSync(dcConfig.getContractBillingCollectionDetailDiAppId(), queryParamRequest);
		log.info("接口"+dcConfig.getContractBillingCollectionDetailDiAppId()+"反参:"+JSON.toJSONString(listSync));
		if(200 != listSync.getCode()) {
			throw new RuntimeException(listSync.getMessage());
		}
		byte[] bodyBytes = listSync.getBody();
		log.info("接口"+dcConfig.getContractBillingCollectionDetailDiAppId()+"反参body:"+new String(bodyBytes));
		ContractBillingCollectionDetailResponse parseObject = JSON.parseObject(new String(bodyBytes), ContractBillingCollectionDetailResponse.class);
		List<ContractBillingCollectionDetailResDTO> resDTO = JSON.parseArray(JSON.toJSONString(parseObject.getResults()), ContractBillingCollectionDetailResDTO.class);
		return resDTO;
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ContractVentorQueryDetailResDTO> getContractVentorQueryDetail(ContractVentorReqDTO req) {
		ContractVentorRequest request = new ContractVentorRequest();
		request.setVendorid(req.getVendorid());
		request.setVendorname(req.getVendorname());
		QueryParamRequest queryParamRequest = new QueryParamRequest();
		Map<String, Object> conditions = JSON.parseObject(JSON.toJSONString(request), Map.class);
		queryParamRequest.setConditions(conditions);
		queryParamRequest.setPageStart((req.getPageNo()-1)*req.getPageSize());
		queryParamRequest.setPageSize(req.getPageSize());
		List<String> returnFields = this.getClassFieldsName(ContractVentorQueryDetailData.class);
		queryParamRequest.setReturnFields(returnFields);
		log.info("接口"+dcConfig.getContractVentorQueryDetailDiAppId()+"入参："+JSON.toJSONString(queryParamRequest));
		ApiClient client = DcRemoteCaller.getContractApiClient();
		ApiResponse listSync = client.listSync(dcConfig.getContractVentorQueryDetailDiAppId(), queryParamRequest);
		log.info("接口"+dcConfig.getContractBillingCreatdetailDiAppId()+"反参:"+JSON.toJSONString(listSync));
		if(200 != listSync.getCode()) {
			throw new RuntimeException(listSync.getMessage());
		}
		byte[] bodyBytes = listSync.getBody();
		log.info("接口"+dcConfig.getContractVentorQueryDetailDiAppId()+"反参:"+JSON.toJSONString(listSync));
		log.info("接口"+dcConfig.getContractVentorQueryDetailDiAppId()+"反参body:"+new String(bodyBytes));
		ContractVentorQueryDetailResponse parseObject = JSON.parseObject(new String(bodyBytes), ContractVentorQueryDetailResponse.class);
		List<ContractVentorQueryDetailResDTO> resDTO = JSON.parseArray(JSON.toJSONString(parseObject.getResults()), ContractVentorQueryDetailResDTO.class);
		return resDTO;
		
	}

	@Override
	public List<ContractBillingCreatdetailResDTO> getContractBillingCreatdetail(ContractEngReqDTO req) {
		QueryParamRequest queryParamRequest = new QueryParamRequest();
		Map<String, Object> conditions = Maps.newHashMap();
		queryParamRequest.setConditions(conditions);
		queryParamRequest.setPageStart((req.getPageNo()-1)*req.getPageSize());
		queryParamRequest.setPageSize(req.getPageSize());
		List<String> returnFields = this.getClassFieldsName(ContractBillingCreatdetailData.class);
		queryParamRequest.setReturnFields(returnFields);
		log.info("接口"+dcConfig.getContractBillingCreatdetailDiAppId()+"入参："+JSON.toJSONString(queryParamRequest));
		ApiClient client = DcRemoteCaller.getContractApiClient();
		ApiResponse listSync = client.listSync(dcConfig.getContractBillingCreatdetailDiAppId(), queryParamRequest);
		log.info("接口"+dcConfig.getContractBillingCreatdetailDiAppId()+"反参:"+JSON.toJSONString(listSync));
		if(200 != listSync.getCode()) {
			throw new RuntimeException(listSync.getMessage());
		}
		byte[] bodyBytes = listSync.getBody();
		log.info("接口"+dcConfig.getContractBillingCreatdetailDiAppId()+"反参body:"+new String(bodyBytes));
		ContractBillingCreatdetailResponse parseObject = JSON.parseObject(new String(bodyBytes), ContractBillingCreatdetailResponse.class);
		List<ContractBillingCreatdetailResDTO> resDTO = JSON.parseArray(JSON.toJSONString(parseObject.getResults()), ContractBillingCreatdetailResDTO.class);
		return resDTO;
		
	}
   
}
