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

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
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 com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.google.common.collect.Lists;

import cn.ey.biz.common.exception.ServiceException;
import cn.ey.biz.common.exception.enums.GlobalErrorCodeConstants;
import cn.ey.biz.common.pojo.PageResult;
import cn.ey.biz.common.pojo.R;
import cn.ey.biz.common.util.collection.CollectionUtils;
import cn.ey.biz.module.external.api.fd.feign.IFdExternalFeignService;
import cn.ey.biz.module.external.api.fd.feign.IFdFeignService;
import cn.ey.biz.module.external.api.fd.feign.config.FdConfig;
import cn.ey.biz.module.external.api.fd.feign.reqdto.ActivityInfoReqDTO;
import cn.ey.biz.module.external.api.fd.feign.reqdto.CommonRequest.Header;
import cn.ey.biz.module.external.api.fd.feign.reqdto.CommonRequest.OperationInfo;
import cn.ey.biz.module.external.api.fd.feign.reqdto.CommonRequest.PageInfo;
import cn.ey.biz.module.external.api.fd.feign.reqdto.DelEngagementInfoRequest;
import cn.ey.biz.module.external.api.fd.feign.reqdto.DelEngagementInfoRequest.DelEngagementInfoDataJson;
import cn.ey.biz.module.external.api.fd.feign.reqdto.DelEngagementInfoRequest.DelEngagementInfoMainTable;
import cn.ey.biz.module.external.api.fd.feign.reqdto.EngAgementRequest;
import cn.ey.biz.module.external.api.fd.feign.reqdto.EngGlobalSearchRequest;
import cn.ey.biz.module.external.api.fd.feign.reqdto.EngagementListForCodeGropRequest;
import cn.ey.biz.module.external.api.fd.feign.reqdto.EngagementStatusinfoRequest;
import cn.ey.biz.module.external.api.fd.feign.reqdto.EngagementStatusinfoRequest.EngagementStatusinfoDataJson;
import cn.ey.biz.module.external.api.fd.feign.reqdto.EngagementStatusinfoRequest.EngagementStatusinfoReqMainTable;
import cn.ey.biz.module.external.api.fd.feign.reqdto.ExistAnyEngRequestDTO;
import cn.ey.biz.module.external.api.fd.feign.reqdto.ExternalEngmentRequest;
import cn.ey.biz.module.external.api.fd.feign.reqdto.ExternalEngmentRequest.EngActivity;
import cn.ey.biz.module.external.api.fd.feign.reqdto.ExternalEngmentRequest.EngActivityRecord;
import cn.ey.biz.module.external.api.fd.feign.reqdto.ExternalEngmentRequest.EngPersonnel;
import cn.ey.biz.module.external.api.fd.feign.reqdto.ExternalEngmentRequest.EngPersonnelRecord;
import cn.ey.biz.module.external.api.fd.feign.reqdto.ExternalEngmentRequest.EngmentInfo;
import cn.ey.biz.module.external.api.fd.feign.reqdto.ExternalEngmentRequest.ExternalEngmentDataJson;
import cn.ey.biz.module.external.api.fd.feign.reqdto.ExternalEngmentRequest.ExternalEngmentReqMainTable;
import cn.ey.biz.module.external.api.fd.feign.reqdto.ExternalEngmentRequest.Operate;
import cn.ey.biz.module.external.api.fd.feign.reqdto.ExternalEngmentRoleRequest;
import cn.ey.biz.module.external.api.fd.feign.reqdto.ExternalEngmentRoleRequest.EngmentRoleInfo;
import cn.ey.biz.module.external.api.fd.feign.reqdto.ExternalEngmentRoleRequest.ExternalEngmentRoleDataJson;
import cn.ey.biz.module.external.api.fd.feign.reqdto.ExternalEngmentRoleRequest.ExternalEngmentRoleReqMainTable;
import cn.ey.biz.module.external.api.fd.feign.reqdto.ExternalEngmentRoleRequest.Role;
import cn.ey.biz.module.external.api.fd.feign.reqdto.ExternalEngmentRoleRequest.RoleRecord;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetBusinessUnitRequest;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetBusinessUnitRequest.GetBusinessUnitDataJson;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetBusinessUnitRequest.GetBusinessUnitMainTable;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetCodeBlockRequest;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetCodeBlockRequest.GetCodeBlockDataJson;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetCodeBlockRequest.GetCodeBlockMainTable;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetCompentencyRequest;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetCompentencyRequest.GetCompentencyDataJson;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetCompentencyRequest.GetCompentencyMainTable;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetCurrencyIdRequest;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetCurrencyIdRequest.GetCurrencyIdDataJson;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetCurrencyIdRequest.GetCurrencyIdMainTable;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetDictInfoRequest;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetDictInfoRequest.GetDictInfoDataJson;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetDictInfoRequest.GetDictInfoMainTable;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetFsfInfoRequest;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetFsfInfoRequest.GetFsfInfoDataJson;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetFsfInfoRequest.GetFsfInfoMainTable;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetGcrateRequest;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetGcrateRequest.GetGcrateDataJson;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetGcrateRequest.GetGcrateMainTable;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetGdsRateRequest;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetGdsRateRequest.GetGdsRateDataJson;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetGdsRateRequest.GetGdsRateMainTable;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetMercuryCompetencyRequest;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetMercuryCompetencyRequest.GetMercuryCompetencyDataJson;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetMercuryCompetencyRequest.GetMercuryCompetencyMainTable;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetSubMgmtGdsRequest;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetSubMgmtGdsRequest.GetSubMgmtGdsDataJson;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetSubMgmtGdsRequest.GetSubMgmtGdsMainTable;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetSubMgmtUnitRequest;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetSubMgmtUnitRequest.GetSubMgmtUnitDataJson;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetSubMgmtUnitRequest.GetSubMgmtUnitMainTable;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetSubServiceLineRequest;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetSubServiceLineRequest.GetSubServiceLineDataJson;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetSubServiceLineRequest.GetSubServiceLineMainTable;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetTrateInfoRequest;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetTrateInfoRequest.GetTrateInfoDataJson;
import cn.ey.biz.module.external.api.fd.feign.reqdto.GetTrateInfoRequest.GetTrateInfoMainTable;
import cn.ey.biz.module.external.api.fd.feign.reqdto.LeaveCodeRequest;
import cn.ey.biz.module.external.api.fd.feign.reqdto.TeExpenseDetailRequest;
import cn.ey.biz.module.external.api.fd.feign.reqdto.TimesheetDetailRequest;
import cn.ey.biz.module.external.api.fd.feign.resdto.ActivityInfoResponseDTO;
import cn.ey.biz.module.external.api.fd.feign.resdto.EngagementInfoResponseDTO;
import cn.ey.biz.module.external.api.fd.feign.resdto.EngagementInfoResponseDTO.EngActivityDetail;
import cn.ey.biz.module.external.api.fd.feign.resdto.EngagementInfoResponseDTO.EngTeamDetail;
import cn.ey.biz.module.external.api.fd.feign.resdto.EngagementStatusinfoResponseDTO.EngagementStatusinfoResData;
import cn.ey.biz.module.external.api.fd.feign.resdto.EngagementStatusinfoResponseDTO.EngagementStatusinfoResMainTable;
import cn.ey.biz.module.external.api.fd.feign.resdto.LeaveCodeResponseDTO;
import cn.ey.biz.module.external.api.fd.feign.resdto.SaveExternalEngmentResponseDataDTO;
import cn.ey.biz.module.external.api.fd.feign.resdto.StatisticsTeExpenseDetailResponseDTO;
import cn.ey.biz.module.external.api.fd.feign.resdto.StatisticsTimesheetDetailResponseDTO;
import cn.ey.biz.module.external.api.fd.feign.resdto.TeExpenseDetailResponseDTO;
import cn.ey.biz.module.external.api.fd.feign.resdto.TimesheetDetailResponseDTO;
import cn.ey.biz.module.external.api.fd.service.IFdService;
import cn.ey.biz.module.external.api.fd.service.enums.ActionEnum;
import cn.ey.biz.module.external.api.fd.service.enums.CountryMappingEnum;
import cn.ey.biz.module.external.api.fd.service.enums.DateConstant;
import cn.ey.biz.module.external.api.fd.service.enums.EngagementTypeEnum;
import cn.ey.biz.module.external.api.fd.service.enums.ExceptionEnum;
import cn.ey.biz.module.external.api.fd.service.enums.RateTypeEnum;
import cn.ey.biz.module.external.api.fd.service.requestdto.ARAgingReqDTO;
import cn.ey.biz.module.external.api.fd.service.requestdto.EngActivityDTO;
import cn.ey.biz.module.external.api.fd.service.requestdto.EngAgementGlobalSearchReqDTO;
import cn.ey.biz.module.external.api.fd.service.requestdto.EngPersonnelDTO;
import cn.ey.biz.module.external.api.fd.service.requestdto.EngagementActiveInfoReqDTO;
import cn.ey.biz.module.external.api.fd.service.requestdto.EngagementListForCodeGropReqDTO;
import cn.ey.biz.module.external.api.fd.service.requestdto.EngagementListReqDTO;
import cn.ey.biz.module.external.api.fd.service.requestdto.EngagementStatusReqDTO;
import cn.ey.biz.module.external.api.fd.service.requestdto.FeeSharingFactorReqDTO;
import cn.ey.biz.module.external.api.fd.service.requestdto.FinancialIndexReqDTO;
import cn.ey.biz.module.external.api.fd.service.requestdto.GetBusinessUnitReq;
import cn.ey.biz.module.external.api.fd.service.requestdto.GetCodeBlockReq;
import cn.ey.biz.module.external.api.fd.service.requestdto.GetCompentencyReq;
import cn.ey.biz.module.external.api.fd.service.requestdto.GetCurrencyIdReqDTO;
import cn.ey.biz.module.external.api.fd.service.requestdto.GetDictInfoReqDTO;
import cn.ey.biz.module.external.api.fd.service.requestdto.GetGcrateReqDTO;
import cn.ey.biz.module.external.api.fd.service.requestdto.GetGdsRateReqDTO;
import cn.ey.biz.module.external.api.fd.service.requestdto.GetMercuryCompetencyReq;
import cn.ey.biz.module.external.api.fd.service.requestdto.GetSubMgmtGdsReq;
import cn.ey.biz.module.external.api.fd.service.requestdto.GetSubMgmtUnitReq;
import cn.ey.biz.module.external.api.fd.service.requestdto.GetSubServiceLineReq;
import cn.ey.biz.module.external.api.fd.service.requestdto.RateInfoReqDTO;
import cn.ey.biz.module.external.api.fd.service.requestdto.SaveEngagementReqDTO;
import cn.ey.biz.module.external.api.fd.service.requestdto.SaveEngagementRoleReqDTO;
import cn.ey.biz.module.external.api.fd.service.requestdto.TeExpenseDetailReqDTO;
import cn.ey.biz.module.external.api.fd.service.requestdto.TimesheetDetailReqDTO;
import cn.ey.biz.module.external.api.fd.service.requestdto.WIPAgingReqDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.ARAgingResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.BusinessUnitResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.CodeBlockResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.CompentencyResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.DictInfoResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.EngActivityDetailDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.EngTeamDetailDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.EngagementActiveInfoResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.EngagementListResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.EngagementStatusResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.EngagementinfoResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.FeeSharingFactorResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.FinancialIndexResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.GetCurrencyIdResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.GetGcrateResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.GetGdsRateResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.GlobalSearchEngAgementInfoResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.MercuryCompetencyResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.RateInfoResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.StatisticsTeExpenseDetailResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.StatisticsTimesheetDetailResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.SubMgmtGdsResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.SubMgmtUnitResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.SubServiceLineResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.TeExpenseDetailResDTO;
import cn.ey.biz.module.external.api.fd.service.responsedto.TimesheetDetailResDTO;
import cn.ey.biz.module.external.common.Page;
import cn.ey.biz.module.external.utils.SpringUtils;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
/**
 * 财务中台对接api实现
 * @author ayh
 *
 */

@Service
public class FdServiceImpl implements IFdService {
	
	private final Logger log = LoggerFactory.getLogger(getClass());
	
	@Autowired
	private IFdFeignService fdFeignService;
	
	@Autowired
	private IFdExternalFeignService fdExternalFeignService;

	@Override
	public PageResult<EngagementListResDTO> getEngagementList(EngagementListReqDTO request) {
		long startTime = System.currentTimeMillis();
		EngAgementRequest engagementReq = new EngAgementRequest();
		engagementReq.setUserId(request.getUserId());
		engagementReq.setBusinessUnit(request.getBusinessUnit());
		engagementReq.setClientCode(request.getClientCode());
		engagementReq.setClientName(request.getClientName());
		engagementReq.setEngagementCode(request.getEngagementCode());
		engagementReq.setEngagementCodeLike(request.getEngagementCodeLike());
		engagementReq.setEngagementName(request.getEngagementName());
		engagementReq.setEngagementCode1(request.getEngagementCode1());
		engagementReq.setEngagementCode1Like(request.getEngagementCode1Like());
		engagementReq.setEngagementCodeOrNameLike(request.getEngagementCodeOrNameLike());
		engagementReq.setEngagementCode1OrNameLike(request.getEngagementCode1OrNameLike());
		engagementReq.setEngagementType(request.getEngagementType());
		engagementReq.setEngagementSubType(request.getEngagementSubType());
		engagementReq.setManagementUnit(request.getManagementUnit());
		engagementReq.setManagerialCntryOrLoc(request.getManagerialCntryOrLoc());
		engagementReq.setRole(request.getRole());
		engagementReq.setSubManagementUnit(request.getSubManagementUnit());
		engagementReq.setEmployeeGPN(request.getEmployeeGPN());
		engagementReq.setEmployeeName(request.getEmployeeName());
		engagementReq.setFiscalYear(request.getFiscalYear());
		engagementReq.setFiscalYears(request.getFiscalYears());
		engagementReq.setRiskLevel(request.getRiskLevel());
		engagementReq.setStatus(request.getStatus());
		engagementReq.setStatuss(request.getStatuss());
		engagementReq.setCountry(request.getCountry());
		engagementReq.setMgmtRegion(request.getMgmtRegion());
		engagementReq.setServiceLine(request.getServiceLine());
		engagementReq.setSubServiceLine(request.getSubServiceLine());
		engagementReq.setOpportunityCode(request.getOpportunityCode());
		engagementReq.setPaceId(request.getPaceId());
		engagementReq.setEngagementPartnerGpn(request.getEngagementPartnerGpn());
		engagementReq.setEngagementManagerGpn(request.getEngagementManagerGpn());
		engagementReq.setPrimaryFmaGpn(request.getPrimaryFmaGpn());
		engagementReq.setGeoRegion(request.getGeoRegion());
		engagementReq.setBlockingLevel(request.getBlockingLevel());
		engagementReq.setFirm(request.getFirm());
		engagementReq.setEngagementPartnerGpns(request.getEngagementPartnerGpns());
		engagementReq.setEngagementManagerGpns(request.getEngagementManagerGpns());
		engagementReq.setModedatacreatedate(request.getModedatacreatedate());
		engagementReq.setCreateDate(request.getCreateDate());
		engagementReq.setEffectiveDate(request.getEffectiveDate());
		engagementReq.setScopes(request.getScopes());
		engagementReq.setSortMap(request.getSortMap());
		engagementReq.setEngCodes(request.getEngCodes());
		engagementReq.setServiceLineCondition(request.getServiceLineCondition());
		engagementReq.setPageNo(request.getPageNo());
		engagementReq.setPageSize(request.getPageSize());
		engagementReq.setIsPermission(request.getIsPermission());
		R<Page<EngagementInfoResponseDTO>> page = fdExternalFeignService.getEngagementPageList(engagementReq);
		log.info("分页查询项目数据:"+JSON.toJSONString(page));
		List<EngagementInfoResponseDTO> engagements = page.getData().getRecords();
		List<EngagementListResDTO> engagementList = JSON.parseArray(JSON.toJSONString(engagements), EngagementListResDTO.class);
		long endTime = System.currentTimeMillis();
		log.info("视图查询消耗时间s:"+(endTime-startTime)/1000);
		return new PageResult<EngagementListResDTO>(engagementList, page.getData().getTotal());
	}
	
	
	
	@Override
	public PageResult<EngagementListResDTO> getEngagementListForCodeGroup(EngagementListForCodeGropReqDTO request) {
		long startTime = System.currentTimeMillis();
		EngagementListForCodeGropRequest engagementReq = new EngagementListForCodeGropRequest();
		engagementReq.setPaceId(request.getPaceId());
		engagementReq.setEngagementPartnerGpn(request.getEngagementPartnerGpn());
		engagementReq.setEngagementAttribute(request.getEngagementAttribute());
		engagementReq.setStatuss(request.getStatuss());
		engagementReq.setServiceLine(request.getServiceLine());
		engagementReq.setMgmtRegion(request.getMgmtRegion());
		engagementReq.setExcludeEngagementCode1(request.getExcludeEngagementCode1());
		engagementReq.setKeywords(request.getKeywords());
		engagementReq.setPageNo(request.getPageNo());
		engagementReq.setPageSize(request.getPageSize());
		engagementReq.setIsPermission(request.getIsPermission());
		R<Page<EngagementInfoResponseDTO>> page = fdExternalFeignService.getEngagementPageListForCodeGroup(engagementReq);
		log.info("分页查询项目数据(code组合场景):"+JSON.toJSONString(page));
		List<EngagementInfoResponseDTO> engagements = page.getData().getRecords();
		List<EngagementListResDTO> engagementList = JSON.parseArray(JSON.toJSONString(engagements), EngagementListResDTO.class);
		long endTime = System.currentTimeMillis();
		log.info("视图查询消耗时间(code组合场景)s:"+(endTime-startTime)/1000);
		return new PageResult<EngagementListResDTO>(engagementList, page.getData().getTotal());
	}



	@Override
	public List<EngagementListResDTO> getEngagementListAll(EngagementListReqDTO request) {
		EngAgementRequest engagementReq = new EngAgementRequest();
		engagementReq.setUserId(request.getUserId());
		engagementReq.setBusinessUnit(request.getBusinessUnit());
		engagementReq.setClientCode(request.getClientCode());
		engagementReq.setClientName(request.getClientName());
		engagementReq.setEngagementCode(request.getEngagementCode());
		engagementReq.setEngagementCodeLike(request.getEngagementCodeLike());
		engagementReq.setEngagementName(request.getEngagementName());
		engagementReq.setEngagementCode1(request.getEngagementCode1());
		engagementReq.setEngagementCode1Like(request.getEngagementCode1Like());
		engagementReq.setEngagementCodeOrNameLike(request.getEngagementCodeOrNameLike());
		engagementReq.setEngagementCode1OrNameLike(request.getEngagementCode1OrNameLike());
		engagementReq.setEngagementType(request.getEngagementType());
		engagementReq.setEngagementSubType(request.getEngagementSubType());
		engagementReq.setManagementUnit(request.getManagementUnit());
		engagementReq.setManagerialCntryOrLoc(request.getManagerialCntryOrLoc());
		engagementReq.setRole(request.getRole());
		engagementReq.setSubManagementUnit(request.getSubManagementUnit());
		engagementReq.setEmployeeGPN(request.getEmployeeGPN());
		engagementReq.setEmployeeName(request.getEmployeeName());
		engagementReq.setFiscalYear(request.getFiscalYear());
		engagementReq.setFiscalYears(request.getFiscalYears());
		engagementReq.setRiskLevel(request.getRiskLevel());
		engagementReq.setStatus(request.getStatus());
		engagementReq.setStatuss(request.getStatuss());
		engagementReq.setCountry(request.getCountry());
		engagementReq.setMgmtRegion(request.getMgmtRegion());
		engagementReq.setServiceLine(request.getServiceLine());
		engagementReq.setSubServiceLine(request.getSubServiceLine());
		engagementReq.setOpportunityCode(request.getOpportunityCode());
		engagementReq.setPaceId(request.getPaceId());
		engagementReq.setEngagementPartnerGpn(request.getEngagementPartnerGpn());
		engagementReq.setEngagementManagerGpn(request.getEngagementManagerGpn());
		engagementReq.setPrimaryFmaGpn(request.getPrimaryFmaGpn());
		engagementReq.setGeoRegion(request.getGeoRegion());
		engagementReq.setBlockingLevel(request.getBlockingLevel());
		engagementReq.setFirm(request.getFirm());
		engagementReq.setEngagementPartnerGpns(request.getEngagementPartnerGpns());
		engagementReq.setEngagementManagerGpns(request.getEngagementManagerGpns());
		engagementReq.setModedatacreatedate(request.getModedatacreatedate());
		engagementReq.setCreateDate(request.getCreateDate());
		engagementReq.setScopes(request.getScopes());
		engagementReq.setSortMap(request.getSortMap());
		engagementReq.setEngCodes(request.getEngCodes());
		engagementReq.setServiceLineCondition(request.getServiceLineCondition());
		engagementReq.setPageNo(request.getPageNo());
		engagementReq.setPageSize(request.getPageSize());
		engagementReq.setIsPermission(request.getIsPermission());
		log.info("全量查询项目数据入参:"+JSON.toJSONString(engagementReq));
		R<List<EngagementInfoResponseDTO>> response = fdExternalFeignService.getEngagementList(engagementReq);
		List<EngagementListResDTO> engagementList = JSON.parseArray(JSON.toJSONString(response.getData()), EngagementListResDTO.class);
		log.info("全量查询项目数据:"+JSON.toJSONString(response));
		return engagementList;
	}
	
	@Override
	public PageResult<GlobalSearchEngAgementInfoResDTO> getEngagementListGlobalSearch(EngAgementGlobalSearchReqDTO request) {
		EngGlobalSearchRequest engGlobalSearchReq = JSON.parseObject(JSON.toJSONString(request), EngGlobalSearchRequest.class);
		R<Page<EngagementInfoResponseDTO>> pageResult = fdExternalFeignService.getEngagementListGlobalSearch(engGlobalSearchReq);
		List<EngagementInfoResponseDTO> engagements = pageResult.getData().getRecords();
		List<GlobalSearchEngAgementInfoResDTO> engagementList = JSON.parseArray(JSON.toJSONString(engagements), GlobalSearchEngAgementInfoResDTO.class);
		log.info("全局检索查询项目数据:"+JSON.toJSONString(engagementList));
		return new PageResult<GlobalSearchEngAgementInfoResDTO>(engagementList, pageResult.getData().getTotal());
	}
	
	
	
	@Override
	public List<EngagementListResDTO> getEngagementsForCompletion(List<String> engCodes) {
		R<List<EngagementInfoResponseDTO>> engagementsResult = fdExternalFeignService.getEngagementsByEngCodes(engCodes);
		List<EngagementListResDTO> engagementList = JSON.parseArray(JSON.toJSONString(engagementsResult.getData()), EngagementListResDTO.class);
		return engagementList;
	}



	@Override
	public Boolean existAnyEng(List<String> engCodes, List<String> statuss) {
		ExistAnyEngRequestDTO existAnyEngRequest= new ExistAnyEngRequestDTO();
		existAnyEngRequest.setEngCodes(engCodes);
		existAnyEngRequest.setStatuss(statuss);
		R<Boolean> res = fdExternalFeignService.existAnyEng(existAnyEngRequest);
		return res.getData();
	}



	@Override
	public EngagementinfoResDTO getEngagementInfoByEngagementCode(String engagementCode) {
		long startTime = System.currentTimeMillis();
		EngAgementRequest engagementReq = new EngAgementRequest();
		engagementReq.setEngagementCode(engagementCode);
		R<EngagementInfoResponseDTO> response = fdExternalFeignService.getEngagementInfoByEngagementCode(engagementReq);
		EngagementInfoResponseDTO engagementInfoDetail = response.getData();
//		EngagementinfoResDTO engagementinfo = JSON.parseObject(JSON.toJSONString(engagementInfoDetail), EngagementinfoResDTO.class);
//		if(engagementInfoDetail != null) {
//			List<EngActivityDetail> activitys = engagementInfoDetail.getActivitys();
//			List<EngActivityDetailDTO> engActivities = JSON.parseArray(JSON.toJSONString(activitys), EngActivityDetailDTO.class);
//			engagementinfo.setEngActivities(engActivities);
//			List<EngTeamDetail> personnels = engagementInfoDetail.getPersonnels();
//			List<EngTeamDetailDTO> engTeams = JSON.parseArray(JSON.toJSONString(personnels), EngTeamDetailDTO.class);
//			engagementinfo.setEngTeams(engTeams);
//		}
		EngagementinfoResDTO engagementinfo = this.biuldEngagementinfoResDTO(engagementInfoDetail);
		long endTime = System.currentTimeMillis();
		log.info("视图项目详情查询消耗时间s:"+(endTime-startTime)/1000);
		return engagementinfo;
	}
	
	@Override
	public EngagementinfoResDTO getEngagementInfoByEngagementCode1(String engagementCode1) {
		long startTime = System.currentTimeMillis();
		EngAgementRequest engagementReq = new EngAgementRequest();
		engagementReq.setEngagementCode1(engagementCode1);
		R<EngagementInfoResponseDTO> response = fdExternalFeignService.getEngagementInfoByEngagementCode1(engagementReq);
		EngagementInfoResponseDTO engagementInfoDetail = response.getData();
//		EngagementinfoResDTO engagementinfo = JSON.parseObject(JSON.toJSONString(engagementInfoDetail), EngagementinfoResDTO.class);
//		if(engagementInfoDetail != null) {
//			List<EngActivityDetail> activitys = engagementInfoDetail.getActivitys();
//			List<EngActivityDetailDTO> engActivities = JSON.parseArray(JSON.toJSONString(activitys), EngActivityDetailDTO.class);
//			engagementinfo.setEngActivities(engActivities);
//			List<EngTeamDetail> personnels = engagementInfoDetail.getPersonnels();
//			List<EngTeamDetailDTO> engTeams = JSON.parseArray(JSON.toJSONString(personnels), EngTeamDetailDTO.class);
//			engagementinfo.setEngTeams(engTeams);
//		}
		EngagementinfoResDTO engagementinfo = this.biuldEngagementinfoResDTO(engagementInfoDetail);
		long endTime = System.currentTimeMillis();
		log.info("视图项目详情:"+JSON.toJSONString(engagementinfo));
		log.info("视图项目详情查询消耗时间s:"+(endTime-startTime)/1000);
		return engagementinfo;
	}

	@Override
	public EngagementinfoResDTO getEngagementInfoByProcessNo(String processNo) {
		long startTime = System.currentTimeMillis();
		EngAgementRequest engagementReq = new EngAgementRequest();
		engagementReq.setProcessNo(processNo);
		R<EngagementInfoResponseDTO> response = fdExternalFeignService.getEngagementInfoByProcessNo(engagementReq);
		EngagementInfoResponseDTO engagementInfoDetail = response.getData();
//		EngagementinfoResDTO engagementinfo = JSON.parseObject(JSON.toJSONString(engagementInfoDetail), EngagementinfoResDTO.class);
//		if(engagementInfoDetail != null) {
//			List<EngActivityDetail> activitys = engagementInfoDetail.getActivitys();
//			List<EngActivityDetailDTO> engActivities = JSON.parseArray(JSON.toJSONString(activitys), EngActivityDetailDTO.class);
//			engagementinfo.setEngActivities(engActivities);
//			List<EngTeamDetail> personnels = engagementInfoDetail.getPersonnels();
//			List<EngTeamDetailDTO> engTeams = JSON.parseArray(JSON.toJSONString(personnels), EngTeamDetailDTO.class);
//			engagementinfo.setEngTeams(engTeams);
//		}
		EngagementinfoResDTO engagementinfo = this.biuldEngagementinfoResDTO(engagementInfoDetail);
		long endTime = System.currentTimeMillis();
		log.info("视图项目详情查询消耗时间s:"+(endTime-startTime)/1000);
		return engagementinfo;
	}
	
	private EngagementinfoResDTO biuldEngagementinfoResDTO(EngagementInfoResponseDTO engagementInfoResponse) {
		if(engagementInfoResponse == null) {
			return null;
		}
		EngagementinfoResDTO engagementinfo = new EngagementinfoResDTO();
		engagementinfo.setId(new Long(engagementInfoResponse.getMainid()));
		engagementinfo.setProcessNo(engagementInfoResponse.getProcessNo());
		engagementinfo.setRequestid(engagementInfoResponse.getProcessNo());
		engagementinfo.setEngCode(engagementInfoResponse.getEngagementCode());
		engagementinfo.setEngCode1(engagementInfoResponse.getEngagementCode1());
		engagementinfo.setEngName(engagementInfoResponse.getEngagementName());
		engagementinfo.setCcId(engagementInfoResponse.getClientId());
		engagementinfo.setCcName(engagementInfoResponse.getClientName());
		
		if(StringUtils.isNotBlank(engagementInfoResponse.getMasterCode())) {
			engagementinfo.setIsMaster(Integer.valueOf(engagementInfoResponse.getMasterCode()));
		}
		if(StringUtils.isNotBlank(engagementInfoResponse.getEngagementCodeAttribute())) {
			engagementinfo.setEngAttr(engagementInfoResponse.getEngagementCodeAttribute());
		}
		engagementinfo.setStatus(engagementInfoResponse.getEngagementStatus());
		engagementinfo.setEpGpn(engagementInfoResponse.getEngagementPartnerGpn());
		engagementinfo.setEpName(engagementInfoResponse.getEngagementPartnerName());
		engagementinfo.setEmGpn(engagementInfoResponse.getEngagementManagerGpn());
		engagementinfo.setEmName(engagementInfoResponse.getEngagementManagerName());
		engagementinfo.setFmaGPN(engagementInfoResponse.getPrimaryFmaGpn());
		engagementinfo.setEngType(engagementInfoResponse.getEngagementType());
		engagementinfo.setEngSubType(engagementInfoResponse.getEngagementSubType());
		engagementinfo.setArea(engagementInfoResponse.getArea());
		engagementinfo.setBlockingLevel(engagementInfoResponse.getBlockingLevel());
		engagementinfo.setBusinessUnit(engagementInfoResponse.getBusinessUnit());
		//engagementinfo.setCompletion();
		engagementinfo.setCountry(engagementInfoResponse.getCountry());
		engagementinfo.setEffectiveDate(engagementInfoResponse.getEffectiveDate());
		engagementinfo.setEngDescription(engagementInfoResponse.getEngagementDescription());
		engagementinfo.setEstimatedStartDate(engagementInfoResponse.getEstimatedStartDate());
		engagementinfo.setEstimatedCloseDate(engagementInfoResponse.getEstimatedCloseDate());
		engagementinfo.setGeoRegion(engagementInfoResponse.getGeoRegion());
		engagementinfo.setGlobalServiceCode(engagementInfoResponse.getGlobalServiceCode());
		engagementinfo.setLocalServiceCode(engagementInfoResponse.getLocalServiceCode());
		engagementinfo.setLegalEntity(engagementInfoResponse.getLegalEntity());
		engagementinfo.setCodeBlock(engagementInfoResponse.getCodeBlock());
		engagementinfo.setEpCodeBlock(engagementInfoResponse.getEpCodeblock());
		engagementinfo.setManagementRegion(engagementInfoResponse.getMgmtRegion());
		engagementinfo.setManagementUnit(engagementInfoResponse.getMgmtUnit());
		engagementinfo.setSubManagementUnit(engagementInfoResponse.getSubMgmtUnit());
		engagementinfo.setOperatingUnit(engagementInfoResponse.getOperUnit());
		engagementinfo.setServiceLine(engagementInfoResponse.getServiceLine());
		engagementinfo.setSubServiceLine(engagementInfoResponse.getSubServiceLine());
		//engagementinfo.setPyErp();
		if(StringUtils.isNotBlank(engagementInfoResponse.getPartnerInvolvement())) {
			engagementinfo.setPartnerInvolvement(new BigDecimal(engagementInfoResponse.getPartnerInvolvement()));
		}
		if(StringUtils.isNotBlank(engagementInfoResponse.getHours())) {
			engagementinfo.setHours(new BigDecimal(engagementInfoResponse.getHours()));
		}
		if(StringUtils.isNotBlank(engagementInfoResponse.getExpenses())) {
			engagementinfo.setExpense(new BigDecimal(engagementInfoResponse.getExpenses()));
		}
		if(StringUtils.isNotBlank(engagementInfoResponse.getTotalRevenue())) {
			engagementinfo.setTotalRevenue(new BigDecimal(engagementInfoResponse.getTotalRevenue()));
		}
		if(StringUtils.isNotBlank(engagementInfoResponse.getCurrentFiscalYearTer())) {
			engagementinfo.setCurrentTer(new BigDecimal(engagementInfoResponse.getCurrentFiscalYearTer()));
		}
		if(StringUtils.isNotBlank(engagementInfoResponse.getMargin())) {
			engagementinfo.setMargin(new BigDecimal(engagementInfoResponse.getMargin()));
		}
		if(StringUtils.isNotBlank(engagementInfoResponse.getErp())) {
			engagementinfo.setErp(new BigDecimal(engagementInfoResponse.getErp()));
		}
		if(StringUtils.isNotBlank(engagementInfoResponse.getRealization())) {
			engagementinfo.setRealization(new BigDecimal(engagementInfoResponse.getRealization()));
		}
		engagementinfo.setBaseCurrency(engagementInfoResponse.getBaseCurrency());
		engagementinfo.setPlanId(engagementInfoResponse.getBudgetPlanId());
		engagementinfo.setPlanVersion(engagementInfoResponse.getBudgetVersionId());
		engagementinfo.setOpprId(engagementInfoResponse.getOpportunityId());
		engagementinfo.setPaceId(engagementInfoResponse.getPaceId());
		engagementinfo.setPaceEffectiveTime("");
		engagementinfo.setDataSources(engagementInfoResponse.getDataSources());
		engagementinfo.setPlanSource(engagementInfoResponse.getPlanSource());
		if(StringUtils.isNotBlank(engagementInfoResponse.getEaf())) {
			engagementinfo.setEaf(new BigDecimal(engagementInfoResponse.getEaf()));
		}
		engagementinfo.setCreateGpn(engagementInfoResponse.getCreategpn());
		engagementinfo.setModedatacreatedate(engagementInfoResponse.getModedatacreatedate());
		engagementinfo.setCreateDate(engagementInfoResponse.getCreateDate());
		engagementinfo.setActivity(engagementInfoResponse.getActivity());
		engagementinfo.setActivityDescription(engagementInfoResponse.getActivityDescription());
		engagementinfo.setOneOfFrecurringEvent(engagementInfoResponse.getOneOfFrecurringEvent());
		engagementinfo.setIsConfidential(engagementInfoResponse.getIsconfidential());
		engagementinfo.setConfidentialLevel(engagementInfoResponse.getConfidentialLevel());
		engagementinfo.setPlanSource(engagementInfoResponse.getPlanSource());
		engagementinfo.setMercuryServiceCode(engagementInfoResponse.getMercuryServiceCode());
		List<EngActivityDetailDTO> engActivities = Lists.newArrayList();
		List<EngActivityDetail> activitys = engagementInfoResponse.getActivitys();
		log.info(engagementInfoResponse.getEngagementCode1()+"活动数据 {}",activitys);
		if(!CollectionUtils.isAnyEmpty(activitys)) {
			for(EngActivityDetail activity:activitys) {
				EngActivityDetailDTO engActivity = new EngActivityDetailDTO();
				engActivity.setId(Long.valueOf(activity.getId()));
				engActivity.setEngInfoId(Long.valueOf(activity.getMainid()));
				engActivity.setCode(activity.getDtActivity());
				engActivity.setDescription(activity.getActivityDescription());
				//engActivity.setName();
				engActivities.add(engActivity);
			}
		}
		engagementinfo.setEngActivities(engActivities);
		List<EngTeamDetailDTO> engTeams = Lists.newArrayList();
		List<EngTeamDetail> personnels = engagementInfoResponse.getPersonnels();
		if(!CollectionUtils.isAnyEmpty(personnels)) {
			for(EngTeamDetail personnel:personnels) {
				EngTeamDetailDTO engTeamer = new EngTeamDetailDTO();
				engTeamer.setId(Long.valueOf(personnel.getId()));
				engTeamer.setMainid(Long.valueOf(personnel.getMainid()));
				engTeamer.setRole(personnel.getRole());
				engTeamer.setGpn(personnel.getRoleGpn());
				engTeamer.setSfyx(personnel.getSfyx());
				engTeamer.setSxsj1(personnel.getSxsj1());
				engTeamer.setSxsj2(personnel.getSxsj2());
				engTeams.add(engTeamer);
			}
		}
		engagementinfo.setEngTeams(engTeams);
		return engagementinfo;
	}


	@Override
	public boolean hasEngagementPermission(String engagementCode) {
		EngAgementRequest engagementReq = new EngAgementRequest();
		engagementReq.setEngagementCode(engagementCode);
		R<Boolean> res = fdExternalFeignService.hasEngagementPermission(engagementReq);
		return res.getData();
	}
	
	

	@Override
	public boolean hasEngagementsByBudgetPlanId(String budgetPlanId) {
		R<Boolean> res = fdExternalFeignService.hasEngagementsByBudgetPlanId(budgetPlanId);
		return res.getData();
	}



	@Override
	public ArrayList<EngagementStatusResDTO> getEngagementStatus(EngagementStatusReqDTO request) {
		EngagementStatusinfoDataJson datajson = new EngagementStatusinfoDataJson();
		datajson.setHeader(new Header(SpringUtils.getObject(FdConfig.class).getFdCrmSystemId(),SpringUtils.getObject(FdConfig.class).getFdCrmSystemPassword()));
		datajson.setOperationinfo(new OperationInfo());
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageNo(request.getCurrent());
		pageInfo.setPageSize(request.getCurrent());
		datajson.setPageInfo(pageInfo);
		EngagementStatusinfoReqMainTable reqMainTable = new EngagementStatusinfoReqMainTable();
		reqMainTable.setStatus(request.getStatus());
		reqMainTable.setIsenable(request.getIsenable());
		reqMainTable.setDescription(request.getDescription());
		datajson.setMainTable(reqMainTable);
		EngagementStatusinfoRequest engagementStatusinfoRequest = new EngagementStatusinfoRequest();
		engagementStatusinfoRequest.setDatajson(JSON.toJSONString(datajson));
		String bodyStr = fdFeignService.getEngagementStatusinfo(engagementStatusinfoRequest);
		JSONObject bodyObject = JSON.parseObject(bodyStr);
		String resultStr = bodyObject.getString("result");
		List<EngagementStatusinfoResData> result = JSON.parseArray(resultStr, EngagementStatusinfoResData.class);
		//获取项目状态，转DTO返回
		ArrayList<EngagementStatusResDTO> engagementStatus = new ArrayList<EngagementStatusResDTO>();
		for(EngagementStatusinfoResData ele:result) {
			EngagementStatusinfoResMainTable mainTable = ele.getMainTable();
			EngagementStatusResDTO eStatus = JSON.parseObject(JSON.toJSONString(mainTable), EngagementStatusResDTO.class);
			engagementStatus.add(eStatus);
		}
		return engagementStatus;
	}

	@Override
	public List<String> getEngagementFinancialCalendar() {
		R<List<String>> response = fdExternalFeignService.getEngagementFinancialCalendar();		
		return response.getData();
	}

	@Override
	public EngagementinfoResDTO saveEngagement(SaveEngagementReqDTO request) throws ServiceException {
		long startTime = System.currentTimeMillis();
		ExternalEngmentDataJson datajson = new ExternalEngmentDataJson();
		datajson.setHeader(new Header(SpringUtils.getObject(FdConfig.class).getFdCrmSystemId(),SpringUtils.getObject(FdConfig.class).getFdCrmSystemPassword()));
		
		ArrayList<EngmentInfo> engmentInfos = new ArrayList<EngmentInfo>();
		EngmentInfo engmentInfo = new EngmentInfo();
		engmentInfo.setOperationinfo(new OperationInfo());
		
		ExternalEngmentReqMainTable mainTable = new ExternalEngmentReqMainTable();
		mainTable.setId(request.getId());
		mainTable.setProcess_no(request.getProcessNo());
		mainTable.setApplication_date(DateUtil.format(request.getApplicationDate(), DatePattern.NORM_DATE_PATTERN));
		mainTable.setEffective_date(DateUtil.format(request.getEffectiveDate(), DatePattern.NORM_DATE_PATTERN));
		mainTable.setCreate_date(DateUtil.format(new Date(), DatePattern.NORM_DATE_PATTERN));
		mainTable.setApplicant_gpn(request.getApplicantGpn());
		mainTable.setEngagement_name(request.getEngagementName());
		mainTable.setEngagement_status(request.getEngagementStatus());
		mainTable.setService_line(request.getServiceLine());
		mainTable.setSub_service_line(request.getSubServiceLine());
		mainTable.setGlobal_service_code(request.getGlobalServiceCode());
		mainTable.setLocal_service_code(request.getLocalServiceCode());
		mainTable.setBase_currency(request.getBaseCurrency());
		mainTable.setEngagement_purpose(request.getEngagementPurpose());
		mainTable.setOne_of_frecurring_event(request.getOneOfFrecurringEvent()); 
		mainTable.setClient_id(request.getClientId());
		mainTable.setCountry(request.getCountry());
		mainTable.setLegal_entity(request.getLegalEntity());
		mainTable.setBranch(request.getBranch());
		mainTable.setBlocking_level(request.getBlockingLevel());
		mainTable.setEstimated_start_date(DateUtil.format(request.getEstimatedStartDate(), DatePattern.NORM_DATE_PATTERN));
		mainTable.setEstimated_close_date(DateUtil.format(request.getEstimatedCloseDate(), DatePattern.NORM_DATE_PATTERN));
		mainTable.setHours(request.getHours());
		mainTable.setEngagement_partner_gpn(request.getEngagementPartnerGpn());
		mainTable.setEngagement_manager_gpn(request.getEngagementManagerGpn());
		mainTable.setPrimary_fma_gpn(request.getPrimaryFmaGpn());
		mainTable.setActivity(request.getActivity());
		mainTable.setActivity_description(request.getActivityDescription());
		mainTable.setRealization(request.getRealization());
		mainTable.setPartner_involvement(request.getPartnerInvolvement());
		mainTable.setTotal_revenue(request.getTotalRevenue());
		mainTable.setMargin(request.getMargin());
		mainTable.setCurrent_fiscal_year_ter(request.getCurrentFiscalYearTer());
		mainTable.setFiscal_year(request.getFiscalYear());
		mainTable.setErp1(request.getErp());
		mainTable.setEngagement_description(request.getEngagementDescription());
		mainTable.setBudget_plan_id(request.getBudgetPlanId());
		mainTable.setBudget_version_id(request.getBudgetVersionId());
		mainTable.setEngagement_type(EngagementTypeEnum.TYPE_C.getCode());
		mainTable.setEngagement_sub_type(request.getEngagementType());
		mainTable.setBusiness_unit(request.getBusinessUnit());
		mainTable.setMgmt_region(request.getMgmtRegion());
		mainTable.setOper_unit(request.getOperUnit());
		mainTable.setMgmt_unit(request.getMgmtUnit());
		mainTable.setSub_mgmt_unit(request.getSubMgmtUnit());
		mainTable.setGeo_region(request.getGeoRegion());
		mainTable.setPace_id(request.getPaceId());
		mainTable.setOpportunity_id(request.getOpportunityId());
		mainTable.setPy_code(request.getPyCode());
		mainTable.setEngagement_code_attribute(request.getEngagementCodeAttribute());
		mainTable.setMaster_code(request.getMasterCode());
		mainTable.setArea(request.getArea());
		mainTable.setEaf(request.getEaf());
		mainTable.setErp_comments(request.getErpComments());
		mainTable.setExpenses(request.getExpenses());
		// 根据contry 字段判断：中国 -> 0 香港 -> 1 蒙古 -> 2
		if(CountryMappingEnum.CHN.getContryCode().equals(request.getCountry())) {
			mainTable.setReoxzk(CountryMappingEnum.CHN.getToContryCode());
		}
		if(CountryMappingEnum.HKG.getContryCode().equals(request.getCountry())) {
			mainTable.setReoxzk(CountryMappingEnum.HKG.getToContryCode());
		}
		if(CountryMappingEnum.MNG.getContryCode().equals(request.getCountry())) {
			mainTable.setReoxzk(CountryMappingEnum.MNG.getToContryCode());
		}
		mainTable.setTypexzk("0");
		mainTable.setCurrent_year_total_revenue(request.getCurrentYearTotalRevenue());
		mainTable.setStandard_engagement_revenue(request.getStandardEngagementRevenue());
		mainTable.setNet_engagement_revenue(request.getNetEngagementRevenue());
		mainTable.setMargin1(request.getMargin1());
		mainTable.setTotal_cost(request.getTotalCost());
		mainTable.setData_sources(request.getDataSources());
		mainTable.setCodeblock(request.getCodeBlock());
		mainTable.setEp_codeblock(request.getEpCodeBlock());
		mainTable.setCreatorgpn(request.getCreatorGpn());
		mainTable.setIsconfidential(request.getIsConfidential());
		mainTable.setConfidential_level(request.getConfidentialLevel());
		mainTable.setPlan_source(request.getPlanSource());
		mainTable.setMercury_service_code(request.getMercuryServiceCode());
		engmentInfo.setMainTable(mainTable);
		engmentInfo.setDetail1(null);
		
		//EngPersonnels
		List<EngPersonnelDTO> engPersonnels = request.getEngPersonnels();
		List<EngPersonnelRecord> engPersonnelRecords = new ArrayList<EngPersonnelRecord>();
		if(engPersonnels!=null) {
			for(EngPersonnelDTO personnel:engPersonnels) {
				EngPersonnelRecord engPersonnelRecord = new EngPersonnelRecord();
				EngPersonnel engPersonnel = new EngPersonnel();
				engPersonnel.setId(personnel.getId());
				engPersonnel.setRole(personnel.getRole());
				engPersonnel.setRole_gpn(personnel.getRoleGpn());
				engPersonnel.setSfyx(personnel.getSfyx());
				engPersonnel.setSxsj1(DateUtil.format(personnel.getSxsj1(), DatePattern.NORM_DATE_PATTERN));
				engPersonnel.setSxsj2(DateUtil.format(personnel.getSxsj2(), DatePattern.NORM_DATE_PATTERN));
				engPersonnelRecord.setData(engPersonnel);
				Operate operate = new Operate();
				operate.setAction(ActionEnum.SAVE.getActionCode());
				operate.setActionDescribe(ActionEnum.SAVE.getActionDescribe());
				engPersonnelRecord.setOperate(operate);
				engPersonnelRecords.add(engPersonnelRecord);
			}
		}
		//engmentInfo.setDetail2(EngPersonnelRecords);
		engmentInfo.setDetail4(engPersonnelRecords);
		
		//EngActivitys
		List<EngActivityDTO> engActivitys = request.getEngActivitys();
		List<EngActivityRecord> engActivityRecords = new ArrayList<EngActivityRecord>();
		if(engActivitys != null) {
			for(EngActivityDTO engActivity:engActivitys) {
				EngActivityRecord engActivityRecord = new EngActivityRecord();
				EngActivity activity= new EngActivity();
				activity.setId(engActivity.getId());
				activity.setActivity(engActivity.getActivityCode());
				activity.setActivity_description(engActivity.getActivityDescription());
				engActivityRecord.setData(activity);
				Operate operate = new Operate();
				operate.setAction(ActionEnum.SAVE.getActionCode());
				operate.setActionDescribe(ActionEnum.SAVE.getActionDescribe());
				engActivityRecord.setOperate(operate);
				engActivityRecords.add(engActivityRecord);
			}
		}
		//engmentInfo.setDetail3(engActivityRecords);
		engmentInfo.setDetail5(engActivityRecords);
		engmentInfos.add(engmentInfo);
		datajson.setData(engmentInfos);
		ExternalEngmentRequest externalEngmentreq = new ExternalEngmentRequest();
		externalEngmentreq.setDatajson(JSON.toJSONString(datajson));
		log.info("datajson:"+JSON.toJSONString(datajson));
		String bodyStr = fdFeignService.createOrUpdateExternalEngment(externalEngmentreq);
		long endTime = System.currentTimeMillis();
		log.info("项目新增消耗时间s:"+(endTime-startTime)/1000);
		JSONObject bodyObject = JSON.parseObject(bodyStr);
		String status = bodyObject.getString("status");
		log.info("bodyStr:"+JSON.toJSONString(bodyStr));
		if(!"1".equals(status)) {
			throw new ServiceException(ExceptionEnum.SAVE_EXCEPTION.getExceptionCode(),ExceptionEnum.SAVE_EXCEPTION.getExceptionDescribe());
		}
		JSONObject datajsonObject = bodyObject.getJSONObject("datajson");
		String dataStr = datajsonObject.getString("data");
		List<SaveExternalEngmentResponseDataDTO> resultDatas = JSON.parseArray(dataStr, SaveExternalEngmentResponseDataDTO.class);
		EngAgementRequest engagementReq = new EngAgementRequest();
		engagementReq.setMainid(resultDatas.get(0).getMainid());
		R<EngagementInfoResponseDTO> repseonse = fdExternalFeignService.getEngagementInfoBymainId(engagementReq);
		EngagementInfoResponseDTO engagementInfoDetail = repseonse.getData();
		if(repseonse.getCode()!= GlobalErrorCodeConstants.SUCCESS.getCode() ||engagementInfoDetail == null) {
			throw new ServiceException(ExceptionEnum.CURRENCY_QUERY_EXCEPTION.getExceptionCode(),ExceptionEnum.QUERY_EXCEPTION.getExceptionDescribe());
		}			
//		EngagementinfoResDTO engagementinfo = JSON.parseObject(JSON.toJSONString(engagementInfoDetail), EngagementinfoResDTO.class);
//		if(engagementInfoDetail != null) {
//			List<EngActivityDetail> activitys = engagementInfoDetail.getActivitys();
//			List<EngActivityDetailDTO> engActivities = JSON.parseArray(JSON.toJSONString(activitys), EngActivityDetailDTO.class);
//			engagementinfo.setEngActivities(engActivities);
//			List<EngTeamDetail> personnels = engagementInfoDetail.getPersonnels();
//			List<EngTeamDetailDTO> engTeams = JSON.parseArray(JSON.toJSONString(personnels), EngTeamDetailDTO.class);
//			engagementinfo.setEngTeams(engTeams);
//		}	
		EngagementinfoResDTO engagementinfo = this.biuldEngagementinfoResDTO(engagementInfoDetail);
		return engagementinfo;	
	}
	
	@Override
	public EngagementinfoResDTO updateEngagement(SaveEngagementReqDTO request) throws ServiceException {
		long startTime = System.currentTimeMillis();
		ExternalEngmentDataJson datajson = new ExternalEngmentDataJson();
		datajson.setHeader(new Header(SpringUtils.getObject(FdConfig.class).getFdCrmSystemId(),SpringUtils.getObject(FdConfig.class).getFdCrmSystemPassword()));
		
		ArrayList<EngmentInfo> engmentInfos = new ArrayList<EngmentInfo>();
		EngmentInfo engmentInfo = new EngmentInfo();
		engmentInfo.setOperationinfo(new OperationInfo());
		ExternalEngmentReqMainTable mainTable = new ExternalEngmentReqMainTable();
		mainTable.setId(request.getId());
		mainTable.setProcess_no(request.getProcessNo());
		mainTable.setApplication_date(DateUtil.format(request.getApplicationDate(), DatePattern.NORM_DATE_PATTERN));
		mainTable.setEffective_date(DateUtil.format(request.getEffectiveDate(), DatePattern.NORM_DATE_PATTERN));
		mainTable.setApplicant_gpn(request.getApplicantGpn());
		mainTable.setEngagement_name(request.getEngagementName());
		mainTable.setEngagement_code(request.getEngagementCode());
		mainTable.setEngagement_code1(request.getEngagementCode1());
		mainTable.setEngagement_status(request.getEngagementStatus());
		mainTable.setService_line(request.getServiceLine());
		mainTable.setSub_service_line(request.getSubServiceLine());
		mainTable.setGlobal_service_code(request.getGlobalServiceCode());
		mainTable.setLocal_service_code(request.getLocalServiceCode());
		mainTable.setBase_currency(request.getBaseCurrency());
		mainTable.setEngagement_purpose(request.getEngagementPurpose());
		mainTable.setOne_of_frecurring_event(request.getOneOfFrecurringEvent()); 
		mainTable.setClient_id(request.getClientId());
		mainTable.setCountry(request.getCountry());
		mainTable.setLegal_entity(request.getLegalEntity());
		mainTable.setBranch(request.getBranch());
		mainTable.setBlocking_level(request.getBlockingLevel());
		mainTable.setEstimated_start_date(DateUtil.format(request.getEstimatedStartDate(), DatePattern.NORM_DATE_PATTERN));
		mainTable.setEstimated_close_date(DateUtil.format(request.getEstimatedCloseDate(), DatePattern.NORM_DATE_PATTERN));
		mainTable.setHours(request.getHours());
		mainTable.setEngagement_partner_gpn(request.getEngagementPartnerGpn());
		mainTable.setEngagement_manager_gpn(request.getEngagementManagerGpn());
		mainTable.setPrimary_fma_gpn(request.getPrimaryFmaGpn());
		mainTable.setActivity(request.getActivity());
		mainTable.setActivity_description(request.getActivityDescription());
		mainTable.setRealization(request.getRealization());
		mainTable.setPartner_involvement(request.getPartnerInvolvement());
		mainTable.setTotal_revenue(request.getTotalRevenue());
		mainTable.setMargin(request.getMargin());
		mainTable.setCurrent_fiscal_year_ter(request.getCurrentFiscalYearTer());
		mainTable.setFiscal_year(request.getFiscalYear());
		mainTable.setErp1(request.getErp());
		mainTable.setEngagement_description(request.getEngagementDescription());
		mainTable.setBudget_plan_id(request.getBudgetPlanId());
		mainTable.setBudget_version_id(request.getBudgetVersionId());
		mainTable.setEngagement_type(EngagementTypeEnum.TYPE_C.getCode());
		mainTable.setEngagement_sub_type(request.getEngagementType());
		mainTable.setBusiness_unit(request.getBusinessUnit());
		mainTable.setMgmt_region(request.getMgmtRegion());
		mainTable.setOper_unit(request.getOperUnit());
		mainTable.setMgmt_unit(request.getMgmtUnit());
		mainTable.setSub_mgmt_unit(request.getSubMgmtUnit());
		mainTable.setGeo_region(request.getGeoRegion());
		mainTable.setPace_id(request.getPaceId());
		mainTable.setOpportunity_id(request.getOpportunityId());
		mainTable.setPy_code(request.getPyCode());
		mainTable.setEngagement_code_attribute(request.getEngagementCodeAttribute());
		mainTable.setMaster_code(request.getMasterCode());
		mainTable.setArea(request.getArea());
		mainTable.setEaf(request.getEaf());
		mainTable.setErp_comments(request.getErpComments());
		mainTable.setExpenses(request.getExpenses());
		// 根据contry 字段判断：中国 -> 0 香港 -> 1 蒙古 -> 2
		if(CountryMappingEnum.CHN.getContryCode().equals(request.getCountry())) {
			mainTable.setReoxzk(CountryMappingEnum.CHN.getToContryCode());
		}
		if(CountryMappingEnum.HKG.getContryCode().equals(request.getCountry())) {
			mainTable.setReoxzk(CountryMappingEnum.HKG.getToContryCode());
		}
		if(CountryMappingEnum.MNG.getContryCode().equals(request.getCountry())) {
			mainTable.setReoxzk(CountryMappingEnum.MNG.getToContryCode());
		}
		mainTable.setTypexzk("0");
		mainTable.setCurrent_year_total_revenue(request.getCurrentYearTotalRevenue());
		mainTable.setStandard_engagement_revenue(request.getStandardEngagementRevenue());
		mainTable.setNet_engagement_revenue(request.getNetEngagementRevenue());
		mainTable.setMargin1(request.getMargin1());
		mainTable.setTotal_cost(request.getTotalCost());
		mainTable.setData_sources(request.getDataSources());
		mainTable.setCodeblock(request.getCodeBlock());
		mainTable.setEp_codeblock(request.getEpCodeBlock());
		mainTable.setIsconfidential(request.getIsConfidential());
		mainTable.setConfidential_level(request.getConfidentialLevel());
		mainTable.setPlan_source(request.getPlanSource());
		mainTable.setMercury_service_code(request.getMercuryServiceCode());
		engmentInfo.setMainTable(mainTable);
		engmentInfo.setDetail1(null);
		
		//EngPersonnels
		List<EngPersonnelDTO> engPersonnels = request.getEngPersonnels();
		List<EngPersonnelRecord> engPersonnelRecords = new ArrayList<EngPersonnelRecord>();
		if(engPersonnels!=null) {
			for(EngPersonnelDTO personnel:engPersonnels) {
				EngPersonnelRecord engPersonnelRecord = new EngPersonnelRecord();
				EngPersonnel engPersonnel = new EngPersonnel();
				engPersonnel.setId(personnel.getId());
				engPersonnel.setRole(personnel.getRole());
				engPersonnel.setRole_gpn(personnel.getRoleGpn());
				engPersonnel.setSfyx(personnel.getSfyx());
				engPersonnel.setSxsj1(DateUtil.format(personnel.getSxsj1(), DatePattern.NORM_DATE_PATTERN));
				engPersonnel.setSxsj2(DateUtil.format(personnel.getSxsj2(), DatePattern.NORM_DATE_PATTERN));
				engPersonnelRecord.setData(engPersonnel);
				Operate operate = new Operate();
				operate.setAction(ActionEnum.UPDATE.getActionCode());
				operate.setActionDescribe(ActionEnum.UPDATE.getActionDescribe());
				engPersonnelRecord.setOperate(operate);
				engPersonnelRecords.add(engPersonnelRecord);
			}
		}
		//engmentInfo.setDetail2(engPersonnelRecords);
		engmentInfo.setDetail4(engPersonnelRecords);
		
		//EngActivitys
		List<EngActivityDTO> engActivitys = request.getEngActivitys();
		List<EngActivityRecord> engActivityRecords = new ArrayList<EngActivityRecord>();
		if(engActivitys != null) {
			for(EngActivityDTO engActivity:engActivitys) {
				EngActivityRecord engActivityRecord = new EngActivityRecord();
				EngActivity activity= new EngActivity();
				activity.setId(engActivity.getId());
				activity.setActivity(engActivity.getActivityCode());
				activity.setActivity_description(engActivity.getActivityDescription());
				engActivityRecord.setData(activity);
				Operate operate = new Operate();
				operate.setAction(ActionEnum.UPDATE.getActionCode());
				operate.setActionDescribe(ActionEnum.UPDATE.getActionDescribe());
				engActivityRecord.setOperate(operate);
				engActivityRecords.add(engActivityRecord);
			}
		}
		//engmentInfo.setDetail3(engActivityRecords);
		engmentInfo.setDetail5(engActivityRecords);
		engmentInfos.add(engmentInfo);
		datajson.setData(engmentInfos);
		ExternalEngmentRequest externalEngmentreq = new ExternalEngmentRequest();
		externalEngmentreq.setDatajson(JSON.toJSONString(datajson));
		log.info("datajson:"+JSON.toJSONString(datajson));
		String bodyStr = fdFeignService.updateExternalEngment(externalEngmentreq);
		long endTime = System.currentTimeMillis();
		log.info("项目更新消耗时间s:"+(endTime-startTime)/1000);
		JSONObject bodyObject = JSON.parseObject(bodyStr);
		String status = bodyObject.getString("status");
		log.info("bodyStr:"+JSON.toJSONString(bodyStr));
		if(!"1".equals(status)) {
			throw new ServiceException(ExceptionEnum.UPDATE_EXCEPTION.getExceptionCode(),ExceptionEnum.UPDATE_EXCEPTION.getExceptionDescribe());
		}
		JSONObject datajsonObject = bodyObject.getJSONObject("datajson");
		String dataStr = datajsonObject.getString("data");
		List<SaveExternalEngmentResponseDataDTO> resultDatas = JSON.parseArray(dataStr, SaveExternalEngmentResponseDataDTO.class);
		EngAgementRequest engagementReq = new EngAgementRequest();
		engagementReq.setMainid(resultDatas.get(0).getMainid());
		R<EngagementInfoResponseDTO> response = fdExternalFeignService.getEngagementInfoBymainId(engagementReq);
		EngagementInfoResponseDTO engagementInfoDetail = response.getData();
		if(response.getCode()!= GlobalErrorCodeConstants.SUCCESS.getCode() || engagementInfoDetail == null) {
			throw new ServiceException(ExceptionEnum.QUERY_EXCEPTION.getExceptionCode(),ExceptionEnum.QUERY_EXCEPTION.getExceptionDescribe());
		}				
//		EngagementinfoResDTO engagementinfo = JSON.parseObject(JSON.toJSONString(engagementInfoDetail), EngagementinfoResDTO.class);
//		if(engagementInfoDetail != null) {
//			List<EngActivityDetail> activitys = engagementInfoDetail.getActivitys();
//			List<EngActivityDetailDTO> engActivities = JSON.parseArray(JSON.toJSONString(activitys), EngActivityDetailDTO.class);
//			engagementinfo.setEngActivities(engActivities);
//			List<EngTeamDetail> personnels = engagementInfoDetail.getPersonnels();
//			List<EngTeamDetailDTO> engTeams = JSON.parseArray(JSON.toJSONString(personnels), EngTeamDetailDTO.class);
//			engagementinfo.setEngTeams(engTeams);
//		}
		
		EngagementinfoResDTO engagementinfo = this.biuldEngagementinfoResDTO(engagementInfoDetail);
		return engagementinfo;	
	}
	
	@Override
	public List<EngTeamDetailDTO> updateEngagementRole(SaveEngagementRoleReqDTO request) throws ServiceException {
		ExternalEngmentRoleDataJson datajson = new ExternalEngmentRoleDataJson();
		datajson.setHeader(new Header(SpringUtils.getObject(FdConfig.class).getFdCrmSystemId(),SpringUtils.getObject(FdConfig.class).getFdCrmSystemPassword()));
		
		ArrayList<EngmentRoleInfo> engmentRoleInfos = new ArrayList<EngmentRoleInfo>();
		EngmentRoleInfo engmentRoleInfo = new EngmentRoleInfo();
		engmentRoleInfo.setOperationinfo(new OperationInfo());
		ExternalEngmentRoleReqMainTable mainTable = new ExternalEngmentRoleReqMainTable();
		mainTable.setEngagement_code(request.getEngagementCode());
		mainTable.setEngagement_code1(request.getEngagementCode1());
		engmentRoleInfo.setMainTable(mainTable);
		engmentRoleInfo.setDetail1(null);
		
		//人员角色更新
		List<EngPersonnelDTO> engRoles = request.getEngPersonnels();
		List<RoleRecord> roleRecords = new ArrayList<RoleRecord>();
		if(engRoles!=null) {
			for(EngPersonnelDTO personnel:engRoles) {
				RoleRecord roleRecord = new RoleRecord();
				Role role = new Role();
				role.setId(personnel.getId());
				role.setRole(personnel.getRole());
				role.setRole_gpn(personnel.getRoleGpn());
				role.setSfyx(personnel.getSfyx());
				role.setSxsj1(DateUtil.format(personnel.getSxsj1(), DatePattern.NORM_DATE_PATTERN));
				role.setSxsj2(DateUtil.format(personnel.getSxsj2(), DatePattern.NORM_DATE_PATTERN));
				roleRecord.setData(role);
				Operate operate = new Operate();
				operate.setAction(ActionEnum.SAVE_OR_UPDATE.getActionCode());
				operate.setActionDescribe(ActionEnum.SAVE_OR_UPDATE.getActionDescribe());
				roleRecord.setOperate(operate);
				roleRecords.add(roleRecord);
			}
		}
		//engmentRoleInfo.setDetail2(roleRecords);
		engmentRoleInfo.setDetail4(roleRecords);
		engmentRoleInfos.add(engmentRoleInfo);
		datajson.setData(engmentRoleInfos);
		ExternalEngmentRoleRequest roleRequest = new ExternalEngmentRoleRequest();
		roleRequest.setDatajson(JSON.toJSONString(datajson));
		log.info("datajson:"+JSON.toJSONString(datajson));
		String bodyStr = fdFeignService.saveEngagementRole(roleRequest);
		JSONObject bodyObject = JSON.parseObject(bodyStr);
		String status = bodyObject.getString("status");
		log.info("bodyStr:"+JSON.toJSONString(bodyStr));
		if(!"1".equals(status)) {
			throw new ServiceException(ExceptionEnum.SAVE_OR_UPDATE_EXCEPTION.getExceptionCode(),ExceptionEnum.SAVE_OR_UPDATE_EXCEPTION.getExceptionDescribe());
		}
		EngAgementRequest engagementReq = new EngAgementRequest();
		engagementReq.setEngagementCode1(request.getEngagementCode1());
		R<EngagementInfoResponseDTO> response = fdExternalFeignService.getEngagementInfoByEngagementCode1(engagementReq);
		EngagementInfoResponseDTO engagementInfoDetai = response.getData();
		if(response.getCode() != GlobalErrorCodeConstants.SUCCESS.getCode()) {
			throw new ServiceException(ExceptionEnum.QUERY_EXCEPTION.getExceptionCode(),ExceptionEnum.QUERY_EXCEPTION.getExceptionDescribe());
		}
		if(engagementInfoDetai == null) {
			return null;
		}
		EngagementinfoResDTO engagementinfo = this.biuldEngagementinfoResDTO(engagementInfoDetai);
//		List<EngTeamDetail> personnels = engagementInfo.getPersonnels();
//		List<EngTeamDetailDTO> engTeams = JSON.parseArray(JSON.toJSONString(personnels), EngTeamDetailDTO.class);
		List<EngTeamDetailDTO> engTeams = engagementinfo.getEngTeams();
		return engTeams;	
	}
	
	@Override
	public List<EngTeamDetailDTO> getEngagementRoleByEngagementCode(String engagementCode) throws ServiceException {
		EngAgementRequest engagementReq = new EngAgementRequest();
		engagementReq.setEngagementCode(engagementCode);
		R<EngagementInfoResponseDTO> response = fdExternalFeignService.getEngagementInfoByEngagementCode(engagementReq);
		EngagementInfoResponseDTO engagementInfoDetai = response.getData();
		if(response.getCode() != GlobalErrorCodeConstants.SUCCESS.getCode() || engagementInfoDetai == null) {
			throw new ServiceException(ExceptionEnum.QUERY_EXCEPTION.getExceptionCode(),ExceptionEnum.QUERY_EXCEPTION.getExceptionDescribe());
		}
		EngagementinfoResDTO engagementinfo = this.biuldEngagementinfoResDTO(engagementInfoDetai);
		//List<EngTeamDetailDTO> engTeams = JSON.parseArray(JSON.toJSONString(engagementInfoDetai.getPersonnels()), EngTeamDetailDTO.class);
		return engagementinfo.getEngTeams();	
	}
	
	@Override
	public List<EngTeamDetailDTO> getEngagementRoleByEngagementCode1(String engagementCode1) throws ServiceException {
		log.info("八位code查项目详情入参："+engagementCode1);
		EngAgementRequest engagementReq = new EngAgementRequest();
		engagementReq.setEngagementCode1(engagementCode1);
		R<EngagementInfoResponseDTO> response = fdExternalFeignService.getEngagementInfoByEngagementCode1(engagementReq);
		EngagementInfoResponseDTO engagementInfoDetai = response.getData();
		if(response.getCode() != GlobalErrorCodeConstants.SUCCESS.getCode() || engagementInfoDetai == null) {
			throw new ServiceException(ExceptionEnum.QUERY_EXCEPTION.getExceptionCode(),ExceptionEnum.QUERY_EXCEPTION.getExceptionDescribe());
		}				
		//List<EngTeamDetailDTO> engTeams = JSON.parseArray(JSON.toJSONString(engagementInfoDetai.getPersonnels()), EngTeamDetailDTO.class);
		EngagementinfoResDTO engagementinfo = this.biuldEngagementinfoResDTO(engagementInfoDetai);
		return engagementinfo.getEngTeams();	
	}

	@Override
	public boolean delEngagementInfo(String engagementCode) {
		boolean delFlag = false;
		DelEngagementInfoRequest request = new DelEngagementInfoRequest();
		DelEngagementInfoDataJson delEngagementInfoDataJson = new DelEngagementInfoDataJson();
		delEngagementInfoDataJson.setHeader(new Header(SpringUtils.getObject(FdConfig.class).getFdCrmSystemId(),SpringUtils.getObject(FdConfig.class).getFdCrmSystemPassword()));
		delEngagementInfoDataJson.setOperationinfo(new OperationInfo());
		delEngagementInfoDataJson.setPageInfo(null);
		DelEngagementInfoMainTable MainTable = new DelEngagementInfoMainTable();
		MainTable.setEngagement_code(engagementCode);
		delEngagementInfoDataJson.setMainTable(MainTable );
		request.setDatajson(JSON.toJSONString(delEngagementInfoDataJson));
		String delResultStr = fdFeignService.delEngagementInfo(request);
		JSONObject delResultStrObject = JSON.parseObject(delResultStr);
		if("1".equals(delResultStrObject.getString("status"))) {
			delFlag = true;
		}else {
			delFlag = false;
		}
		return delFlag;
	}

	@Override
	public FinancialIndexResDTO getFinancialIndex(FinancialIndexReqDTO request) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ARAgingResDTO getArAging(ARAgingReqDTO request) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ARAgingResDTO WipAging(WIPAgingReqDTO request) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public LeaveCodeResponseDTO getLeaveCodes(LeaveCodeRequest request) {
		R<LeaveCodeResponseDTO> response = fdExternalFeignService.getLeaveCodes(request);
		log.info("休假编码远程调用返回结果====>\n"+JSON.toJSONString(response));
		return response.getData();
	}

	@Override
	public List<RateInfoResDTO> getRateInfo(RateInfoReqDTO request) {
		GetTrateInfoRequest rateInfoRequest = new GetTrateInfoRequest();
		GetTrateInfoDataJson datajson = new GetTrateInfoDataJson();
		datajson.setHeader(new Header(SpringUtils.getObject(FdConfig.class).getFdMmtSystemId(),SpringUtils.getObject(FdConfig.class).getFdMmtSystemPassword()));
		datajson.setOperationinfo(new OperationInfo());
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageNo(new Long(request.getPageNo()));
		pageInfo.setPageSize(new Long(request.getPageSize()));
		datajson.setPageInfo(pageInfo);
		GetTrateInfoMainTable mainTable = new GetTrateInfoMainTable();
		mainTable.setHllx(request.getHllx());
		mainTable.setBb(request.getBb());
		mainTable.setMbhb(request.getMbhb());
		if(request.getSxrqq()!=null) {
			mainTable.setSxrqq(this.computeRateQueryDate(request.getHllx(),request.getSxrqq()));
		}
		datajson.setMainTable(mainTable);
		rateInfoRequest.setDatajson(JSON.toJSONString(datajson));
		log.info(JSON.toJSONString(rateInfoRequest));
		String rateInfoStr = fdFeignService.getRateInfo(rateInfoRequest);
		JSONObject parseObject = JSON.parseObject(rateInfoStr);
		String resultData = parseObject.getString("result");
		List<JSONObject> rateInfos = JSON.parseArray(resultData, JSONObject.class);
		List<RateInfoResDTO> rateInfoList= Lists.newArrayList();
		for(JSONObject rateInfo :rateInfos) {
			String string = rateInfo.getString("mainTable");
			RateInfoResDTO rateInfoRes = JSON.parseObject(string, RateInfoResDTO.class);
			rateInfoList.add(rateInfoRes);
		}
		return rateInfoList;
	}
	
	public String computeRateQueryDate(Integer rateType,Date date) {
		if(rateType == RateTypeEnum.DAILY_RATE.getCode()) {//日汇率
			return DateUtil.format(date, DatePattern.NORM_DATE_PATTERN);
		}
		if(rateType == RateTypeEnum.WEEKLY_RATE_CN.getCode() 
		 || rateType == RateTypeEnum.WEEKLY_RATE_HK.getCode()
		 || rateType == RateTypeEnum.REPORT_FORMS_WEEKLY_RATE.getCode()) {//周汇率
			DateTime startCurrentWeekDate = DateUtil.beginOfWeek(date, true);
			long d = (date.getTime()-startCurrentWeekDate.getTime())/(24*60*60*1000);
			if(d<5) {//返回上周六
				long lastSaturdayTime = startCurrentWeekDate.getTime()-(24*60*60*1000*2);
				Date lastSaturday = new Date(lastSaturdayTime);
				return DateUtil.format(lastSaturday, DatePattern.NORM_DATE_PATTERN);
			}else {//返回本周六
				long currentSaturdayTime = startCurrentWeekDate.getTime()+(24*60*60*1000*5);
				Date currentSaturdayDate = new Date(currentSaturdayTime);
				return DateUtil.format(currentSaturdayDate, DatePattern.NORM_DATE_PATTERN);
			}	
		}
		if(rateType == RateTypeEnum.REPORT_FORMS_MONTH_RATE.getCode()) {//月汇率
			
		}
		if(rateType == RateTypeEnum.REPORT_FORMS_YEAR_RATE.getCode()) {//年汇率
			//日期与当年6月30号比较，大于传当年 7月2号，小于等于传上一年7月2号
			Calendar ca = DateUtil.calendar(date);
			int year = ca.get(Calendar.YEAR);
			DateTime criticalDate = DateUtil.parse(year+DateConstant.JUNE_30TH, DatePattern.NORM_DATE_PATTERN);
			long criticalTime = criticalDate.getTime();
			String dateStr = DateUtil.format(date, DatePattern.NORM_DATE_PATTERN);
			DateTime dateFormated = DateUtil.parse(dateStr, DatePattern.NORM_DATE_PATTERN);
			long dateTime = dateFormated.getTime();
			long difference = dateTime-criticalTime;
			if(difference>0) {
				//大于6月30 ，下一财年
				return year+DateConstant.JULY_2ND;
			}else {
				//小于等于传当前财年
				return (year-1)+DateConstant.JULY_2ND;
			}
		}
		return DateUtil.format(date, DatePattern.NORM_DATE_PATTERN);
	}
	
	@SuppressWarnings("null")
	@Override
	public GetCurrencyIdResDTO getCurrencyId(GetCurrencyIdReqDTO request) {
		GetCurrencyIdRequest currencyIdRequest = new GetCurrencyIdRequest();
		GetCurrencyIdDataJson datajson = new GetCurrencyIdDataJson();
		datajson.setHeader(new Header(SpringUtils.getObject(FdConfig.class).getFdMmtSystemId(),SpringUtils.getObject(FdConfig.class).getFdMmtSystemPassword()));
		datajson.setOperationinfo(new OperationInfo());
		PageInfo pageInfo = new PageInfo();
		datajson.setPageInfo(pageInfo);
		GetCurrencyIdMainTable mainTable = new GetCurrencyIdMainTable();
		mainTable.setCURRENCYNAME(request.getCurrencyName());
		datajson.setMainTable(mainTable );
		currencyIdRequest.setDatajson(JSON.toJSONString(datajson));
		String rateInfoStr = fdFeignService.getCurrencyId(currencyIdRequest);
		JSONObject parseObject = JSON.parseObject(rateInfoStr);
		String resultData = parseObject.getString("result");
		List<JSONObject> currencyId = JSON.parseArray(resultData, JSONObject.class);
		if(currencyId == null && currencyId.size() == 0) {
			throw new ServiceException(ExceptionEnum.CURRENCY_QUERY_EXCEPTION.getExceptionCode(), ExceptionEnum.CURRENCY_QUERY_EXCEPTION.getExceptionDescribe());
		}
		String string = currencyId.get(0).getString("mainTable");
		GetCurrencyIdResDTO currencyIdResDTO = JSON.parseObject(string, GetCurrencyIdResDTO.class);
		return currencyIdResDTO;	
	}
	
	@Override
	public List<GetGcrateResDTO> getGcrate(GetGcrateReqDTO request) {
		GetGcrateRequest getGcrateRequest = new GetGcrateRequest();
		GetGcrateDataJson datajson = new GetGcrateDataJson();
		datajson.setHeader(new Header(SpringUtils.getObject(FdConfig.class).getFdMmtSystemId(),SpringUtils.getObject(FdConfig.class).getFdMmtSystemPassword()));
		datajson.setOperationinfo(new OperationInfo());
		PageInfo pageInfo = new PageInfo();
		datajson.setPageInfo(pageInfo);
		GetGcrateMainTable mainTable = new GetGcrateMainTable();
		mainTable.setFiscal_month(request.getFiscalMonth());
		mainTable.setFiscal_year(request.getFiscalYear());
		mainTable.setSub_mgmt_unit(request.getSubMgmtUnit());
		mainTable.setService_line(request.getServiceLine());
		mainTable.setMgmt_region(request.getMgmtRegion());
		mainTable.setCountry_region(request.getCountryRegion());
		mainTable.setRank_code(request.getRankCode());
		datajson.setMainTable(mainTable );
		getGcrateRequest.setDatajson(JSON.toJSONString(datajson));
		String gcrateStr = fdFeignService.getGcrate(getGcrateRequest);
		JSONObject parseObject = JSON.parseObject(gcrateStr);
		String resultData = parseObject.getString("result");
		List<JSONObject> gcrateJSONObjects = JSON.parseArray(resultData, JSONObject.class);
		if(gcrateJSONObjects == null) {
			throw new ServiceException(ExceptionEnum.GCRATE_QUERY_EXCEPTION.getExceptionCode(), ExceptionEnum.GCRATE_QUERY_EXCEPTION.getExceptionDescribe());
		}
		List<GetGcrateResDTO> gcrates = Lists.newArrayList();
		for(JSONObject e:gcrateJSONObjects) {
			String string = e.getString("mainTable");
			GetGcrateResDTO gcrate = JSON.parseObject(string, GetGcrateResDTO.class);
			GetCurrencyIdReqDTO getCurrencyIdReq = new GetCurrencyIdReqDTO(gcrate.getBaseCurrency());
			GetCurrencyIdResDTO rateInfo = this.getCurrencyId(getCurrencyIdReq);
			gcrate.setBaseCurrencyId(rateInfo.getId());
			gcrates.add(gcrate);
		}
		return gcrates;
	}
	
	@Override
	public List<GetGdsRateResDTO> getGdsRate(GetGdsRateReqDTO request) {
		GetGdsRateRequest gdsRateRequest = new GetGdsRateRequest();
		GetGdsRateDataJson datajson = new GetGdsRateDataJson();
		datajson.setHeader(new Header(SpringUtils.getObject(FdConfig.class).getFdMmtSystemId(),SpringUtils.getObject(FdConfig.class).getFdMmtSystemPassword()));
		datajson.setOperationinfo(new OperationInfo());
		PageInfo pageInfo = new PageInfo();
		datajson.setPageInfo(pageInfo);
		GetGdsRateMainTable mainTable = new GetGdsRateMainTable();
		mainTable.setCn(request.getFiscalYear());
		mainTable.setRankgrade(request.getRankgRade());
		mainTable.setEmployeecodeblock(request.getEmployeeCodeBlock());
		mainTable.setPurchasingcountry(request.getPurchasingCountry());
		mainTable.setBubm(request.getBubm());
		mainTable.setOubm(request.getOubm());
		mainTable.setMubm(request.getMubm());
		mainTable.setSmubm(request.getSmubm());
		
		datajson.setMainTable(mainTable );
		gdsRateRequest.setDatajson(JSON.toJSONString(datajson));
		String gdsRateStr = fdFeignService.getGdsRate(gdsRateRequest);
		JSONObject parseObject = JSON.parseObject(gdsRateStr);
		String resultData = parseObject.getString("result");
		List<JSONObject> gcrateJSONObjects = JSON.parseArray(resultData, JSONObject.class);
		if(gcrateJSONObjects == null) {
			throw new ServiceException(ExceptionEnum.GDSRATE_QUERY_EXCEPTION.getExceptionCode(), ExceptionEnum.GDSRATE_QUERY_EXCEPTION.getExceptionDescribe());
		}
		List<GetGdsRateResDTO> gdsRates = Lists.newArrayList();
		for(JSONObject e:gcrateJSONObjects) {
			String string = e.getString("mainTable");
			GetGdsRateResDTO gcrate = JSON.parseObject(string, GetGdsRateResDTO.class);
			GetCurrencyIdReqDTO currencyIdRequest = new GetCurrencyIdReqDTO(gcrate.getCurrency());
			GetCurrencyIdResDTO currencyId = this.getCurrencyId(currencyIdRequest);
			gcrate.setId(currencyId.getId());
			gdsRates.add(gcrate);
		}
		return gdsRates;
	}

	@Override
	public List<FeeSharingFactorResDTO> getFeeSharingFactor(FeeSharingFactorReqDTO request) {
		GetFsfInfoRequest fsfInfoRequest = new GetFsfInfoRequest();
		GetFsfInfoDataJson datajson = new GetFsfInfoDataJson();
		datajson.setHeader(new Header(SpringUtils.getObject(FdConfig.class).getFdMmtSystemId(),SpringUtils.getObject(FdConfig.class).getFdMmtSystemPassword()));
		datajson.setOperationinfo(new OperationInfo());
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageNo(new Long(request.getPageNo()));
		pageInfo.setPageSize(new Long(request.getPageSize()));
		datajson.setPageInfo(pageInfo);
		GetFsfInfoMainTable mainTable = new GetFsfInfoMainTable();
		mainTable.setFiscalYear(request.getFiscalYear());
		mainTable.setCountry(request.getCountry());
		mainTable.setSub_service_line(request.getSubServiceLine());
		datajson.setMainTable(mainTable );
		fsfInfoRequest.setDatajson(JSON.toJSONString(datajson));
		String fsfInfoStr = fdFeignService.getFsfInfo(fsfInfoRequest);
		JSONObject parseObject = JSON.parseObject(fsfInfoStr);
		String resultData = parseObject.getString("result");
		List<JSONObject> fsfInfos = JSON.parseArray(resultData, JSONObject.class);
		List<FeeSharingFactorResDTO> fsfInfoList= Lists.newArrayList();
		for(JSONObject fsfInfo :fsfInfos) {
			String mainTableStr = fsfInfo.getString("mainTable");
			FeeSharingFactorResDTO fsfRes= new FeeSharingFactorResDTO();
			String fsf = JSON.parseObject(mainTableStr).getString("fee_sharing_factors");
			fsfRes.setFeeSharingFactors(new BigDecimal(fsf));
			fsfInfoList.add(fsfRes);
		}
		return fsfInfoList;
	}

	@Override
	public PageResult<TimesheetDetailResDTO> getTimesheetDetailPageList(TimesheetDetailReqDTO reqParam) {
		TimesheetDetailRequest timesheetDetailReq = new TimesheetDetailRequest();
		timesheetDetailReq.setEngagementCode(reqParam.getEngagementCode());
		timesheetDetailReq.setStartDate(DateUtil.format(reqParam.getStartDate(), DatePattern.NORM_DATE_PATTERN));
		timesheetDetailReq.setEndDate(DateUtil.format(reqParam.getEndDate(), DatePattern.NORM_DATE_PATTERN));
		timesheetDetailReq.setPageNo(reqParam.getPageNo());
		timesheetDetailReq.setPageSize(reqParam.getPageSize());
		R<Page<TimesheetDetailResponseDTO>> response = fdExternalFeignService.getTimesheetDetailPageList(timesheetDetailReq);
		Page<TimesheetDetailResponseDTO> timesheetDetailPageList = response.getData();
		List<TimesheetDetailResponseDTO> records = timesheetDetailPageList.getRecords();
		List<TimesheetDetailResDTO> timesheetDetails = JSON.parseArray(JSON.toJSONString(records), TimesheetDetailResDTO.class);
		return new PageResult<TimesheetDetailResDTO>(timesheetDetails, timesheetDetailPageList.getTotal());
	}

	@Override
	public List<TimesheetDetailResDTO> getTimesheetDetailAllList(TimesheetDetailReqDTO reqParam) {
		TimesheetDetailRequest timesheetDetailReq = new TimesheetDetailRequest();
		timesheetDetailReq.setEngagementCode(reqParam.getEngagementCode());
		timesheetDetailReq.setStartDate(DateUtil.format(reqParam.getStartDate(), DatePattern.NORM_DATE_PATTERN));
		timesheetDetailReq.setEndDate(DateUtil.format(reqParam.getEndDate(), DatePattern.NORM_DATE_PATTERN));
		timesheetDetailReq.setPageNo(reqParam.getPageNo());
		timesheetDetailReq.setPageSize(reqParam.getPageSize());
		R<List<TimesheetDetailResponseDTO>> response = fdExternalFeignService.getTimesheetDetailAllList(timesheetDetailReq);
		List<TimesheetDetailResponseDTO> timesheetDetailAllList = response.getData();
		List<TimesheetDetailResDTO> timesheetDetails = JSON.parseArray(JSON.toJSONString(timesheetDetailAllList), TimesheetDetailResDTO.class);
		return timesheetDetails;
	}

	@Override
	public StatisticsTimesheetDetailResDTO statisticsTimesheetDetail(TimesheetDetailReqDTO reqParam) {
		TimesheetDetailRequest timesheetDetailReq = new TimesheetDetailRequest();
		timesheetDetailReq.setEngagementCode(reqParam.getEngagementCode());
		timesheetDetailReq.setStartDate(DateUtil.format(reqParam.getStartDate(), DatePattern.NORM_DATE_PATTERN));
		timesheetDetailReq.setEndDate(DateUtil.format(reqParam.getEndDate(), DatePattern.NORM_DATE_PATTERN));
		timesheetDetailReq.setPageNo(reqParam.getPageNo());
		timesheetDetailReq.setPageSize(reqParam.getPageSize());
		R<StatisticsTimesheetDetailResponseDTO> response = fdExternalFeignService.statisticsTimesheetDetail(timesheetDetailReq);
		StatisticsTimesheetDetailResponseDTO statisticsTimesheetDetail = response.getData();
		StatisticsTimesheetDetailResDTO timesheetDetail = JSON.parseObject(JSON.toJSONString(statisticsTimesheetDetail), StatisticsTimesheetDetailResDTO.class);
		return timesheetDetail;
	}

	@Override
	public PageResult<TeExpenseDetailResDTO> getTeExpenseDetailPageList(TeExpenseDetailReqDTO reqParam) {
		TeExpenseDetailRequest teExpenseDetailReq = new TeExpenseDetailRequest();
		teExpenseDetailReq.setEngagementCode(reqParam.getEngagementCode());
		teExpenseDetailReq.setStartDate(DateUtil.format(reqParam.getStartDate(), DatePattern.NORM_DATE_PATTERN));
		teExpenseDetailReq.setEndDate(DateUtil.format(reqParam.getEndDate(), DatePattern.NORM_DATE_PATTERN));
		teExpenseDetailReq.setPageNo(reqParam.getPageNo());
		teExpenseDetailReq.setPageSize(reqParam.getPageSize());
		R<Page<TeExpenseDetailResponseDTO>> response = fdExternalFeignService.getTeExpenseDetailPageList(teExpenseDetailReq);
		Page<TeExpenseDetailResponseDTO> teExpenseDetailPageList = response.getData();
		List<TeExpenseDetailResDTO> teExpenseDetails = JSON.parseArray(JSON.toJSONString(teExpenseDetailPageList.getRecords()), TeExpenseDetailResDTO.class);
		return new PageResult<TeExpenseDetailResDTO>(teExpenseDetails, teExpenseDetailPageList.getTotal());
	}

	@Override
	public List<TeExpenseDetailResDTO> getTeExpenseDetailAllList(TeExpenseDetailReqDTO reqParam) {
		TeExpenseDetailRequest teExpenseDetailReq = new TeExpenseDetailRequest();
		teExpenseDetailReq.setEngagementCode(reqParam.getEngagementCode());
		teExpenseDetailReq.setStartDate(DateUtil.format(reqParam.getStartDate(), DatePattern.NORM_DATE_PATTERN));
		teExpenseDetailReq.setEndDate(DateUtil.format(reqParam.getEndDate(), DatePattern.NORM_DATE_PATTERN));
		teExpenseDetailReq.setPageNo(reqParam.getPageNo());
		teExpenseDetailReq.setPageSize(reqParam.getPageSize());
		R<List<TeExpenseDetailResponseDTO>> response = fdExternalFeignService.getTeExpenseDetailAllList(teExpenseDetailReq);
		List<TeExpenseDetailResponseDTO> eExpenseDetailList = response.getData();
		List<TeExpenseDetailResDTO> teExpenseDetails = JSON.parseArray(JSON.toJSONString(eExpenseDetailList), TeExpenseDetailResDTO.class);
		return teExpenseDetails;
	}

	@Override
	public StatisticsTeExpenseDetailResDTO statisticsTeExpenseDetail(TeExpenseDetailReqDTO reqParam) {
		TeExpenseDetailRequest teExpenseDetailReq = new TeExpenseDetailRequest();
		teExpenseDetailReq.setEngagementCode(reqParam.getEngagementCode());
		teExpenseDetailReq.setStartDate(DateUtil.format(reqParam.getStartDate(), DatePattern.NORM_DATE_PATTERN));
		teExpenseDetailReq.setEndDate(DateUtil.format(reqParam.getEndDate(), DatePattern.NORM_DATE_PATTERN));
		teExpenseDetailReq.setPageNo(reqParam.getPageNo());
		teExpenseDetailReq.setPageSize(reqParam.getPageSize());
		R<StatisticsTeExpenseDetailResponseDTO> response = fdExternalFeignService.statisticsTeExpenseDetail(teExpenseDetailReq);
		StatisticsTeExpenseDetailResponseDTO statisticsTeExpenseDetail = response.getData();
		StatisticsTeExpenseDetailResDTO statisticsTeExpenseDetailRes = JSON.parseObject(JSON.toJSONString(statisticsTeExpenseDetail), StatisticsTeExpenseDetailResDTO.class);
		return statisticsTeExpenseDetailRes;
	}

	@Override
	public List<String> clearDirtyEngagement(EngagementListReqDTO request) {
		EngAgementRequest engagementReq = new EngAgementRequest();
		engagementReq.setBusinessUnit(request.getBusinessUnit());
		engagementReq.setClientCode(request.getClientCode());
		engagementReq.setClientName(request.getClientName());
		engagementReq.setEngagementCode(request.getEngagementCode());
		engagementReq.setEngagementName(request.getEngagementName());
		engagementReq.setEngagementType(request.getEngagementType());
		engagementReq.setEngagementSubType(request.getEngagementSubType());
		engagementReq.setManagementUnit(request.getManagementUnit());
		engagementReq.setManagerialCntryOrLoc(request.getManagerialCntryOrLoc());
		engagementReq.setRole(request.getRole());
		engagementReq.setSubManagementUnit(request.getSubManagementUnit());
		engagementReq.setEmployeeGPN(request.getEmployeeGPN());
		engagementReq.setEmployeeName(request.getEmployeeName());
		engagementReq.setFiscalYear(request.getFiscalYear());
		engagementReq.setRiskLevel(request.getRiskLevel());
		engagementReq.setStatus(request.getStatus());
		engagementReq.setCountry(request.getCountry());
		engagementReq.setMgmtRegion(request.getMgmtRegion());
		engagementReq.setServiceLine(request.getServiceLine());
		engagementReq.setSubServiceLine(request.getSubServiceLine());
		engagementReq.setOpportunityCode(request.getOpportunityCode());
		engagementReq.setPaceId(request.getPaceId());
		engagementReq.setEngagementPartnerGpn(request.getEngagementPartnerGpn());
		engagementReq.setEngagementManagerGpn(request.getEngagementManagerGpn());
		engagementReq.setPrimaryFmaGpn(request.getPrimaryFmaGpn());
		R<List<EngagementInfoResponseDTO>> response = fdExternalFeignService.getEngagementList(engagementReq);
		List<EngagementInfoResponseDTO> resultList = response.getData();
		List<String> cleanedlist =  Lists.newArrayList();
		for(EngagementInfoResponseDTO engagementInfo:resultList) {
			if(engagementInfo.getProcessNo() == null || engagementInfo.getEngagementManagerGpn() == null
			|| engagementInfo.getEngagementPartnerGpn() == null || engagementInfo.getPrimaryFmaGpn() == null
			||engagementInfo.getPaceId() == null || engagementInfo.getOpportunityId() == null) {
				DelEngagementInfoRequest delRequest = new DelEngagementInfoRequest();
				DelEngagementInfoDataJson delEngagementInfoDataJson = new DelEngagementInfoDataJson();
				delEngagementInfoDataJson.setHeader(new Header(SpringUtils.getObject(FdConfig.class).getFdCrmSystemId(),SpringUtils.getObject(FdConfig.class).getFdCrmSystemPassword()));
				delEngagementInfoDataJson.setOperationinfo(new OperationInfo());
				delEngagementInfoDataJson.setPageInfo(null);
				DelEngagementInfoMainTable MainTable = new DelEngagementInfoMainTable();
				MainTable.setEngagement_code(engagementInfo.getEngagementCode());
				delEngagementInfoDataJson.setMainTable(MainTable );
				delRequest.setDatajson(JSON.toJSONString(delEngagementInfoDataJson));
				String delResultStr = fdFeignService.delEngagementInfo(delRequest);
				JSONObject delResultStrObject = JSON.parseObject(delResultStr);
				if("1".equals(delResultStrObject.getString("status"))) {
					cleanedlist.add(engagementInfo.getEngagementCode());
				}
				
			}
		}
		return cleanedlist;
	}

//	@Override
//	public PageResult<EngagementActiveInfoResDTO> getEngagementActiveInfo(EngagementActiveInfoReqDTO reqParam) {
//		EngagementActiveInfoRequest engagementActiveInfoRequest = new EngagementActiveInfoRequest();
//		EngagementActiveInfoDataJson datajson = new EngagementActiveInfoDataJson();
//		datajson.setHeader(new Header(SpringUtils.getObject(FdConfig.class).getFdCrmSystemId(),SpringUtils.getObject(FdConfig.class).getFdCrmSystemPassword()));
//		datajson.setOperationinfo(new OperationInfo());
//		EngagementActiveInfoMainTable mainTable = new EngagementActiveInfoMainTable();
//		mainTable.setActivity_status(reqParam.getActivityStatus());
//		datajson.setMainTable(mainTable );
//		engagementActiveInfoRequest.setDatajson(JSON.toJSONString(datajson));
//		String totalResultStr = fdFeignService.getEngagementActiveCount(engagementActiveInfoRequest);
//		JSONObject totalObject = JSON.parseObject(totalResultStr);
//		String totalResultData = totalObject.getString("result");
//		Long total = JSON.parseObject(totalResultData).getLong("pageCount");
//		
//		PageInfo pageInfo = new PageInfo();
//		pageInfo.setPageNo(new Long(reqParam.getPageNo()));
//		pageInfo.setPageSize(new Long(reqParam.getPageSize()));
//		datajson.setPageInfo(pageInfo);
//		engagementActiveInfoRequest.setDatajson(JSON.toJSONString(datajson));
//		String activeInfoStr = fdFeignService.getEngagementActiveInfo(engagementActiveInfoRequest);
//		JSONObject parseObject = JSON.parseObject(activeInfoStr);
//		String resultData = parseObject.getString("result");
//		List<JSONObject> activeInfos = JSON.parseArray(resultData, JSONObject.class);
//		List<EngagementActiveInfoResDTO> activeInfoList= Lists.newArrayList();
//		for(JSONObject activeInfo :activeInfos) {
//			String mainTableStr = activeInfo.getString("mainTable");
//			EngagementActiveInfoResDTO engagementActiveInfoResDTO = JSON.parseObject(mainTableStr,EngagementActiveInfoResDTO.class);
//			activeInfoList.add(engagementActiveInfoResDTO);
//		}
//		return new PageResult<EngagementActiveInfoResDTO>(activeInfoList, total);
//	}
	
	@Override
	public PageResult<EngagementActiveInfoResDTO> getEngagementActiveInfo(EngagementActiveInfoReqDTO reqParam) {
		ActivityInfoReqDTO activityInfoReq = new ActivityInfoReqDTO();
		activityInfoReq.setKeywords(reqParam.getKeywords());
		activityInfoReq.setPageNo(reqParam.getPageNo());
		activityInfoReq.setPageSize(reqParam.getPageSize());
		R<Page<ActivityInfoResponseDTO>> activitys = fdExternalFeignService.getActivityPageList(activityInfoReq);
		List<ActivityInfoResponseDTO> records = activitys.getData().getRecords();
		List<EngagementActiveInfoResDTO> activeInfoResDTOS = JSON.parseArray(JSON.toJSONString(records), EngagementActiveInfoResDTO.class);
		return new PageResult<EngagementActiveInfoResDTO>(activeInfoResDTOS, activitys.getData().getTotal());
	}
	
	@Override
	public List<EngagementActiveInfoResDTO> getEngagementActiveInfosByActivityCodes(List<String> activityCodes) {
		R<List<ActivityInfoResponseDTO>> activitys = fdExternalFeignService.getEngagementActiveInfosByActivityCodes(activityCodes);
		List<ActivityInfoResponseDTO> records = activitys.getData();
		List<EngagementActiveInfoResDTO> activeInfoResDTOS = JSON.parseArray(JSON.toJSONString(records), EngagementActiveInfoResDTO.class);
		return activeInfoResDTOS;
	}
	

//	@Override
//	public PageResult<EngagementListResDTO> getGdsEngagementInfos(EngagementListReqDTO reqParam) {
//		log.info("GTS项目查询入参"+JSON.toJSONString(reqParam));
//		List<EngagementListResDTO> engagementList= Lists.newArrayList();
//		GetGdsEngagementInfoRequest gdsEngagementInfoRequest = new GetGdsEngagementInfoRequest();
//		GetGdsEngagementInfoDataJson datajson = new GetGdsEngagementInfoDataJson();
//		datajson.setHeader(new Header(SpringUtils.getObject(FdConfig.class).getFdCrmSystemId(),SpringUtils.getObject(FdConfig.class).getFdCrmSystemPassword()));
//		datajson.setOperationinfo(new OperationInfo());
//		GetGdsEngagementInfoMainTable mainTable = new GetGdsEngagementInfoMainTable();
//		mainTable.setEngagement_code1(reqParam.getEngagementCode1() != null?reqParam.getEngagementCode1():reqParam.getEngagementCode1Like());
//		mainTable.setEngagement_name(reqParam.getEngagementName());
//		mainTable.setEngagement_status(reqParam.getStatus());
//		mainTable.setClient_id(reqParam.getClientCode());
//		mainTable.setClient_name(reqParam.getClientName());
//		mainTable.setLegal_entity(reqParam.getLegalEntity());
//		mainTable.setEngagement_type(reqParam.getEngagementType());
//		mainTable.setEngagement_sub_type(reqParam.getEngagementSubType());
//		mainTable.setBusiness_unit(reqParam.getBusinessUnit());
//		mainTable.setMgmt_region(reqParam.getMgmtRegion());
//		mainTable.setMgmt_unit(reqParam.getManagementUnit());
//		mainTable.setSub_mgmt_unit(reqParam.getSubManagementUnit());
//		mainTable.setGeo_region(reqParam.getManagerialCntryOrLoc());
//		datajson.setMainTable(mainTable);
//		
//		//gds项目总数
//		gdsEngagementInfoRequest.setDatajson(JSON.toJSONString(datajson,SerializerFeature.WriteNullStringAsEmpty));
//		log.info("远程调用财务中台查询GTS项目总数统计入参====>"+JSON.toJSONString(gdsEngagementInfoRequest,SerializerFeature.WriteNullStringAsEmpty));
//		String countStr = fdFeignService.getGdsEngagementCount(gdsEngagementInfoRequest);
//		log.info("远程调用财务中台查询GTS项目总数返回结果====>"+countStr);
//		JSONObject countObject = JSON.parseObject(countStr);
//		String countResultData = countObject.getString("result");
//		Long count = JSON.parseObject(countResultData).getLong("pageCount");
//	
//		//查firm项目数据
//		PageResult<EngagementListResDTO> firmMngagementList = this.getEngagementList(reqParam);
//		Long totalCount = count+Long.valueOf(firmMngagementList.getTotal());
//		if(totalCount>100) {
//			return new PageResult<EngagementListResDTO>(null,totalCount);
//		}
//		engagementList.addAll(this.getEngagementListAll(reqParam));
//		log.info("远程调用财务中台查询firm项目数据返回结果====>"+JSON.toJSONString(engagementList));
//		
//		//查GDS项目数据
//		PageInfo pageInfo = new PageInfo();
//		pageInfo.setPageNo(new Long(1));
//		pageInfo.setPageSize(new Long(count));
//		datajson.setPageInfo(pageInfo);
//		gdsEngagementInfoRequest.setDatajson(JSON.toJSONString(datajson));
//		log.info("远程调用财务中台查询GTS项目数据入参====>"+JSON.toJSONString(gdsEngagementInfoRequest));
//		String gdsEngagementInfoStr = fdFeignService.getGdsEngagementInfo(gdsEngagementInfoRequest);
//		log.info("远程调用财务中台查询GTS项目数据返回结果====>"+gdsEngagementInfoStr);
//		JSONObject parseObject = JSON.parseObject(gdsEngagementInfoStr);
//		String resultData = parseObject.getString("result");
//		List<JSONObject> gdsEngagementInfos = JSON.parseArray(resultData, JSONObject.class);
//		
//		if(gdsEngagementInfos == null) {
//			throw new ServiceException(0,gdsEngagementInfoStr);
//		}
//		for(JSONObject gdsEngagementInfo :gdsEngagementInfos) {
//			String mainTableStr = gdsEngagementInfo.getString("mainTable");
//			GetGdsEngagementInfoResponseDTO gdsEngagementInfoRes = JSON.parseObject(mainTableStr,GetGdsEngagementInfoResponseDTO.class);
//			EngagementListResDTO engagemenInfo= new EngagementListResDTO();
//			engagemenInfo.setEngCode(gdsEngagementInfoRes.getEngagement_code());
//			engagemenInfo.setEngCode1(gdsEngagementInfoRes.getEngagement_code1());
//			engagemenInfo.setEngName(gdsEngagementInfoRes.getEngagement_name());
//			engagemenInfo.setEngType(gdsEngagementInfoRes.getEngagement_type());
//			engagemenInfo.setEngDescription(gdsEngagementInfoRes.getEngagement_description());
//			engagemenInfo.setManagementRegion(gdsEngagementInfoRes.getMgmt_region());
//			engagemenInfo.setEngType(gdsEngagementInfoRes.getEngagement_type());
//			engagemenInfo.setCcId(gdsEngagementInfoRes.getClient_id());
//			engagemenInfo.setCcName(gdsEngagementInfoRes.getClient_name());
//			engagemenInfo.setBusinessUnit(gdsEngagementInfoRes.getBusiness_unit());
//			engagemenInfo.setManagementUnit(gdsEngagementInfoRes.getMgmt_unit());
//			engagemenInfo.setSubManagementUnit(gdsEngagementInfoRes.getSub_mgmt_unit());
//			engagemenInfo.setEpGpn(gdsEngagementInfoRes.getEngagement_partner_gpn());
//			engagemenInfo.setEpName(gdsEngagementInfoRes.getEngagement_partner_name());
//			engagemenInfo.setEmGpn(gdsEngagementInfoRes.getEngagement_manager_gpn());
//			engagemenInfo.setEmName(gdsEngagementInfoRes.getEngagement_manager_name());
//			engagemenInfo.setLegalEntity(gdsEngagementInfoRes.getLegal_entity());
//			engagemenInfo.setOperatingUnit(gdsEngagementInfoRes.getOper_unit());
//			engagementList.add(engagemenInfo);   
//		}
//		return new PageResult<EngagementListResDTO>(engagementList,count);
//	}
	
	
	@Override
	public PageResult<EngagementListResDTO> getGdsEngagementInfos(EngagementListReqDTO request) {
		long startTime = System.currentTimeMillis();
		EngAgementRequest engagementReq = new EngAgementRequest();
		engagementReq.setUserId(request.getUserId());
		engagementReq.setBusinessUnit(request.getBusinessUnit());
		engagementReq.setClientCode(request.getClientCode());
		engagementReq.setClientName(request.getClientName());
		engagementReq.setEngagementCode(request.getEngagementCode());
		engagementReq.setEngagementCodeLike(request.getEngagementCodeLike());
		engagementReq.setEngagementName(request.getEngagementName());
		engagementReq.setEngagementCode1(request.getEngagementCode1());
		engagementReq.setEngagementCode1Like(request.getEngagementCode1Like());
		engagementReq.setEngagementCodeOrNameLike(request.getEngagementCodeOrNameLike());
		engagementReq.setEngagementCode1OrNameLike(request.getEngagementCode1OrNameLike());
		engagementReq.setEngagementType(request.getEngagementType());
		engagementReq.setEngagementSubType(request.getEngagementSubType());
		engagementReq.setManagementUnit(request.getManagementUnit());
		engagementReq.setManagerialCntryOrLoc(request.getManagerialCntryOrLoc());
		engagementReq.setRole(request.getRole());
		engagementReq.setSubManagementUnit(request.getSubManagementUnit());
		engagementReq.setEmployeeGPN(request.getEmployeeGPN());
		engagementReq.setEmployeeName(request.getEmployeeName());
		engagementReq.setFiscalYear(request.getFiscalYear());
		engagementReq.setFiscalYears(request.getFiscalYears());
		engagementReq.setRiskLevel(request.getRiskLevel());
		engagementReq.setStatus(request.getStatus());
		engagementReq.setStatuss(request.getStatuss());
		engagementReq.setCountry(request.getCountry());
		engagementReq.setMgmtRegion(request.getMgmtRegion());
		engagementReq.setServiceLine(request.getServiceLine());
		engagementReq.setSubServiceLine(request.getSubServiceLine());
		engagementReq.setOpportunityCode(request.getOpportunityCode());
		engagementReq.setPaceId(request.getPaceId());
		engagementReq.setEngagementPartnerGpn(request.getEngagementPartnerGpn());
		engagementReq.setEngagementManagerGpn(request.getEngagementManagerGpn());
		engagementReq.setPrimaryFmaGpn(request.getPrimaryFmaGpn());
		engagementReq.setGeoRegion(request.getGeoRegion());
		engagementReq.setBlockingLevel(request.getBlockingLevel());
		engagementReq.setFirm(request.getFirm());
		engagementReq.setEngagementPartnerGpns(request.getEngagementPartnerGpns());
		engagementReq.setEngagementManagerGpns(request.getEngagementManagerGpns());
		engagementReq.setModedatacreatedate(request.getModedatacreatedate());
		engagementReq.setCreateDate(request.getCreateDate());
		engagementReq.setEffectiveDate(request.getEffectiveDate());
		engagementReq.setScopes(request.getScopes());
		engagementReq.setSortMap(request.getSortMap());
		engagementReq.setEngCodes(request.getEngCodes());
		engagementReq.setPageNo(request.getPageNo());
		engagementReq.setPageSize(request.getPageSize());
		engagementReq.setIsPermission(request.getIsPermission());
		R<Page<EngagementInfoResponseDTO>> page = fdExternalFeignService.getGdsEngagementPageList(engagementReq);
		log.info("GDS分页查询项目数据:"+JSON.toJSONString(page));
		List<EngagementInfoResponseDTO> engagements = page.getData().getRecords();
		List<EngagementListResDTO> engagementList = JSON.parseArray(JSON.toJSONString(engagements), EngagementListResDTO.class);
		long endTime = System.currentTimeMillis();
		log.info("GDS项目数据查询消耗时间s:"+(endTime-startTime)/1000);
		return new PageResult<EngagementListResDTO>(engagementList, page.getData().getTotal());
	}
	

	@Override
	public EngagementinfoResDTO getGdsEngagementInfo(String engagementCode1) {
		EngAgementRequest engagementReq = new EngAgementRequest();
		engagementReq.setEngagementCode1(engagementCode1);
		R<EngagementInfoResponseDTO> response = fdExternalFeignService.getGdsEngagementInfoByEngagementCode1(engagementReq);
		EngagementInfoResponseDTO engagementInfoDetail = response.getData();
		EngagementinfoResDTO engagementInfo = this.biuldEngagementinfoResDTO(engagementInfoDetail);
		return engagementInfo;
		
//		GetGdsEngagementInfoRequest gdsEngagementInfoRequest = new GetGdsEngagementInfoRequest();
//		GetGdsEngagementInfoDataJson datajson = new GetGdsEngagementInfoDataJson();
//		datajson.setHeader(new Header(SpringUtils.getObject(FdConfig.class).getFdCrmSystemId(),SpringUtils.getObject(FdConfig.class).getFdCrmSystemPassword()));
//		datajson.setOperationinfo(new OperationInfo());
//		GetGdsEngagementInfoMainTable mainTable = new GetGdsEngagementInfoMainTable();
//		mainTable.setEngagement_code1(engagementCode1);
//		datajson.setMainTable(mainTable);
//		gdsEngagementInfoRequest.setDatajson(JSON.toJSONString(datajson,SerializerFeature.WriteNullStringAsEmpty));
//		//查GDS项目数据
//		PageInfo pageInfo = new PageInfo();
//		pageInfo.setPageNo(new Long(1));
//		pageInfo.setPageSize(new Long(1));
//		datajson.setPageInfo(pageInfo);
//		gdsEngagementInfoRequest.setDatajson(JSON.toJSONString(datajson));
//		log.info("远程调用财务中台查询GTS项目数据入参====>"+JSON.toJSONString(gdsEngagementInfoRequest));
//		String gdsEngagementInfoStr = fdFeignService.getGdsEngagementInfo(gdsEngagementInfoRequest);
//		log.info("远程调用财务中台查询GTS项目数据返回结果====>"+gdsEngagementInfoStr);
//		if(StringUtils.isEmpty(gdsEngagementInfoStr)) {
//			return null;
//		}
//		JSONObject parseObject = JSON.parseObject(gdsEngagementInfoStr);
//		String resultData = parseObject.getString("result");
//		List<JSONObject> gdsEngagementInfos = JSON.parseArray(resultData, JSONObject.class);
//		if(CollectionUtils.isAnyEmpty(gdsEngagementInfos)) {
//			return null;
//		}
//		JSONObject gdsEngagementInfo = gdsEngagementInfos.get(0);
//		String mainTableStr = gdsEngagementInfo.getString("mainTable");
//		GetGdsEngagementInfoResponseDTO gdsEngagementInfoRes = JSON.parseObject(mainTableStr,GetGdsEngagementInfoResponseDTO.class);
//		EngagementinfoResDTO engagemenInfo= new EngagementinfoResDTO();
//		engagemenInfo.setEngCode(gdsEngagementInfoRes.getEngagement_code());
//		engagemenInfo.setEngCode1(gdsEngagementInfoRes.getEngagement_code1());
//		engagemenInfo.setEngName(gdsEngagementInfoRes.getEngagement_name());
//		engagemenInfo.setEngType(gdsEngagementInfoRes.getEngagement_type());
//		engagemenInfo.setEngDescription(gdsEngagementInfoRes.getEngagement_description());
//		engagemenInfo.setManagementRegion(gdsEngagementInfoRes.getMgmt_region());
//		engagemenInfo.setEngType(gdsEngagementInfoRes.getEngagement_type());
//		engagemenInfo.setCcId(gdsEngagementInfoRes.getClient_id());
//		engagemenInfo.setCcName(gdsEngagementInfoRes.getClient_name());
//		engagemenInfo.setBusinessUnit(gdsEngagementInfoRes.getBusiness_unit());
//		engagemenInfo.setManagementUnit(gdsEngagementInfoRes.getMgmt_unit());
//		engagemenInfo.setSubManagementUnit(gdsEngagementInfoRes.getSub_mgmt_unit());
//		engagemenInfo.setEpGpn(gdsEngagementInfoRes.getEngagement_partner_gpn());
//		engagemenInfo.setEpName(gdsEngagementInfoRes.getEngagement_partner_name());
//		engagemenInfo.setEmGpn(gdsEngagementInfoRes.getEngagement_manager_gpn());
//		engagemenInfo.setEmName(gdsEngagementInfoRes.getEngagement_manager_name());
//		engagemenInfo.setLegalEntity(gdsEngagementInfoRes.getLegal_entity());
//		engagemenInfo.setOperatingUnit(gdsEngagementInfoRes.getOper_unit());
//		
//		List<EngActivityDetailDTO> engActivities = Lists.newArrayList();
//		if(gdsEngagementInfoRes.getActivity()!=null) {
//			EngActivityDetailDTO engActivityDetail= new EngActivityDetailDTO();
//			engActivityDetail.setCode(gdsEngagementInfoRes.getActivity());
//			engActivityDetail.setDescription(gdsEngagementInfoRes.getActivity_description());
//			engActivities.add(engActivityDetail);
//			engagemenInfo.setEngActivities(engActivities);
//		}
//		
//	    List<EngTeamDetailDTO> engTeams = Lists.newArrayList();
//	    if(gdsEngagementInfoRes.getEngagement_partner_gpn()!=null) {
//	    	 EngTeamDetailDTO ep = new EngTeamDetailDTO();
//		     ep.setGpn(gdsEngagementInfoRes.getEngagement_partner_gpn());
//		     engTeams.add(ep);
//		}
//	    
//	    if(gdsEngagementInfoRes.getEngagement_manager_gpn()!=null) {
//	    	EngTeamDetailDTO em = new EngTeamDetailDTO();
//		    em.setGpn(gdsEngagementInfoRes.getEngagement_manager_gpn());
//		    engTeams.add(em);
//		}
//	    if(gdsEngagementInfoRes.getPrimary_fma_gpn()!=null) {
//	    	EngTeamDetailDTO fma = new EngTeamDetailDTO();
//		    fma.setGpn(gdsEngagementInfoRes.getPrimary_fma_gpn());
//		    engTeams.add(fma);  
//		}
//	    engagemenInfo.setEngTeams(engTeams);
//		return engagemenInfo;
	}

	@Override
	public List<DictInfoResDTO> getDictInfoByCategoryCode(GetDictInfoReqDTO reqParam) {
		GetDictInfoRequest dictInfoRequest = new GetDictInfoRequest();
		GetDictInfoDataJson datajson = new GetDictInfoDataJson();
		datajson.setHeader(new Header(SpringUtils.getObject(FdConfig.class).getFdBcpSystemId(),SpringUtils.getObject(FdConfig.class).getFdBcpSystemPassword()));
		datajson.setOperationinfo(new OperationInfo());
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageNo(new Long(reqParam.getPageNo()));
		pageInfo.setPageSize(new Long(reqParam.getPageSize()));
		datajson.setPageInfo(pageInfo );
		GetDictInfoMainTable mainTable = new GetDictInfoMainTable();
		mainTable.setCategorycode(reqParam.getCategoryCode());
		mainTable.setLastupdatetime(DateUtil.format(reqParam.getLastUpdateTime(), DatePattern.NORM_DATE_PATTERN));
		datajson.setMainTable(mainTable);
		dictInfoRequest.setDatajson(JSON.toJSONString(datajson,SerializerFeature.WriteNullStringAsEmpty));
		log.info("远程调用财务中台查询通用字典入参====>"+JSON.toJSONString(dictInfoRequest,SerializerFeature.WriteNullStringAsEmpty));
		String resultStr = fdFeignService.getDictInfoByCategoryCode(dictInfoRequest);
		log.info("远程调用财务中台查询通用字典返回结果====>"+resultStr);
		JSONObject parseObject = JSON.parseObject(resultStr);
		String resultData = parseObject.getString("result");
		List<JSONObject> dictInfos = JSON.parseArray(resultData, JSONObject.class);
		if(dictInfos == null) {
			throw new ServiceException(1,resultStr);
		}
		List<DictInfoResDTO> dictInfoList = Lists.newArrayList();
		for(JSONObject dictInfo :dictInfos) {
			String mainTableStr = dictInfo.getString("mainTable");
			DictInfoResDTO dictInfoDto = JSON.parseObject(mainTableStr,DictInfoResDTO.class);
			dictInfoList.add(dictInfoDto);
		}
		return dictInfoList;
	}

	@Override
	public List<BusinessUnitResDTO> getBusinessUnit(GetBusinessUnitReq reqParam) {
		GetBusinessUnitRequest businessUnitRequest = new GetBusinessUnitRequest();
		GetBusinessUnitDataJson datajson = new GetBusinessUnitDataJson();
		datajson.setHeader(new Header(SpringUtils.getObject(FdConfig.class).getFdBcpSystemId(),SpringUtils.getObject(FdConfig.class).getFdBcpSystemPassword()));
		datajson.setOperationinfo(new OperationInfo());
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageNo(new Long(reqParam.getPageNo()));
		pageInfo.setPageSize(new Long(reqParam.getPageSize()));
		datajson.setPageInfo(pageInfo );
		GetBusinessUnitMainTable mainTable = new GetBusinessUnitMainTable();
		mainTable.setLastupdatetime(DateUtil.format(reqParam.getLastUpdateTime(), DatePattern.NORM_DATE_PATTERN));
		datajson.setMainTable(mainTable);
		businessUnitRequest.setDatajson(JSON.toJSONString(datajson,SerializerFeature.WriteNullStringAsEmpty));
		log.info("远程调用财务中台查询 business unit入参====>"+JSON.toJSONString(businessUnitRequest,SerializerFeature.WriteNullStringAsEmpty));
		String resultStr = fdFeignService.getBusinessUnit(businessUnitRequest);
		log.info("远程调用财务中台查询 business unit返回结果====>"+resultStr);
		JSONObject parseObject = JSON.parseObject(resultStr);
		String resultData = parseObject.getString("result");
		List<JSONObject> businessUnits = JSON.parseArray(resultData, JSONObject.class);
		if(businessUnits == null) {
			throw new ServiceException(1,resultStr);
		}
		List<BusinessUnitResDTO> businessUnitList = Lists.newArrayList();
		for(JSONObject businessUnit :businessUnits) {
			String mainTableStr = businessUnit.getString("mainTable");
			BusinessUnitResDTO businessUnitDto = JSON.parseObject(mainTableStr,BusinessUnitResDTO.class);
			businessUnitList.add(businessUnitDto);
		}
		return businessUnitList;
	}

	@Override
	public List<CompentencyResDTO> getCompentency(GetCompentencyReq reqParam) {
		GetCompentencyRequest compentencyRequest = new GetCompentencyRequest();
		GetCompentencyDataJson datajson = new GetCompentencyDataJson();
		datajson.setHeader(new Header(SpringUtils.getObject(FdConfig.class).getFdBcpSystemId(),SpringUtils.getObject(FdConfig.class).getFdBcpSystemPassword()));
		datajson.setOperationinfo(new OperationInfo());
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageNo(new Long(reqParam.getPageNo()));
		pageInfo.setPageSize(new Long(reqParam.getPageSize()));
		datajson.setPageInfo(pageInfo );
		GetCompentencyMainTable mainTable = new GetCompentencyMainTable();
		mainTable.setLastupdatetime(DateUtil.format(reqParam.getLastUpdateTime(), DatePattern.NORM_DATE_PATTERN));
		datajson.setMainTable(mainTable);
		compentencyRequest.setDatajson(JSON.toJSONString(datajson,SerializerFeature.WriteNullStringAsEmpty));
		log.info("远程调用财务中台查询 compentency入参====>"+JSON.toJSONString(compentencyRequest,SerializerFeature.WriteNullStringAsEmpty));
		String resultStr = fdFeignService.getCompentency(compentencyRequest);
		log.info("远程调用财务中台查询 compentency返回结果====>"+resultStr);
		JSONObject parseObject = JSON.parseObject(resultStr);
		String resultData = parseObject.getString("result");
		List<JSONObject> compentencys = JSON.parseArray(resultData, JSONObject.class);
		if(compentencys == null) {
			throw new ServiceException(1,resultStr);
		}
		List<CompentencyResDTO> compentencyList = Lists.newArrayList();
		for(JSONObject compentency :compentencys) {
			String mainTableStr = compentency.getString("mainTable");
			CompentencyResDTO compentencyDto = JSON.parseObject(mainTableStr,CompentencyResDTO.class);
			compentencyList.add(compentencyDto);
		}
		return compentencyList;
	}

	@Override
	public List<CodeBlockResDTO> getCodeBlock(GetCodeBlockReq reqParam) {
		GetCodeBlockRequest codeBlockRequest = new GetCodeBlockRequest();
		GetCodeBlockDataJson datajson = new GetCodeBlockDataJson();
		datajson.setHeader(new Header(SpringUtils.getObject(FdConfig.class).getFdBcpSystemId(),SpringUtils.getObject(FdConfig.class).getFdBcpSystemPassword()));
		datajson.setOperationinfo(new OperationInfo());
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageNo(new Long(reqParam.getPageNo()));
		pageInfo.setPageSize(new Long(reqParam.getPageSize()));
		datajson.setPageInfo(pageInfo );
		GetCodeBlockMainTable mainTable = new GetCodeBlockMainTable();
		mainTable.setLastupdatetime(DateUtil.format(reqParam.getLastUpdateTime(), DatePattern.NORM_DATE_PATTERN));
		datajson.setMainTable(mainTable);
		codeBlockRequest.setDatajson(JSON.toJSONString(datajson,SerializerFeature.WriteNullStringAsEmpty));
		log.info("远程调用财务中台查询 CodeBlock入参====>"+JSON.toJSONString(codeBlockRequest,SerializerFeature.WriteNullStringAsEmpty));
		String resultStr = fdFeignService.getCodeBlock(codeBlockRequest);
		log.info("远程调用财务中台查询 CodeBlock返回结果====>"+resultStr);
		JSONObject parseObject = JSON.parseObject(resultStr);
		String resultData = parseObject.getString("result");
		List<JSONObject> codeBlocks = JSON.parseArray(resultData, JSONObject.class);
		if(codeBlocks == null) {
			throw new ServiceException(1,resultStr);
		}
		List<CodeBlockResDTO> codeBlockList = Lists.newArrayList();
		for(JSONObject codeBlock :codeBlocks) {
			String mainTableStr = codeBlock.getString("mainTable");
			CodeBlockResDTO codeBlockDto = JSON.parseObject(mainTableStr,CodeBlockResDTO.class);
			codeBlockList.add(codeBlockDto);
		}
		return codeBlockList;
	}

	@Override
	public List<SubMgmtUnitResDTO> getSubMgmtUnit(GetSubMgmtUnitReq reqParam) {
		GetSubMgmtUnitRequest subMgmtUnitRequest = new GetSubMgmtUnitRequest();
		GetSubMgmtUnitDataJson datajson = new GetSubMgmtUnitDataJson();
		datajson.setHeader(new Header(SpringUtils.getObject(FdConfig.class).getFdBcpSystemId(),SpringUtils.getObject(FdConfig.class).getFdBcpSystemPassword()));
		datajson.setOperationinfo(new OperationInfo());
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageNo(new Long(reqParam.getPageNo()));
		pageInfo.setPageSize(new Long(reqParam.getPageSize()));
		datajson.setPageInfo(pageInfo );
		GetSubMgmtUnitMainTable mainTable = new GetSubMgmtUnitMainTable();
		mainTable.setLastupdatetime(DateUtil.format(reqParam.getLastupdatetime(), DatePattern.NORM_DATE_PATTERN));
		datajson.setMainTable(mainTable);
		subMgmtUnitRequest.setDatajson(JSON.toJSONString(datajson,SerializerFeature.WriteNullStringAsEmpty));
		log.info("远程调用财务中台查询SMU_firm入参====>"+JSON.toJSONString(subMgmtUnitRequest,SerializerFeature.WriteNullStringAsEmpty));
		String resultStr = fdFeignService.getSubMgmtUnit(subMgmtUnitRequest);
		log.info("远程调用财务中台查询SMU_firm返回结果====>"+resultStr);
		JSONObject parseObject = JSON.parseObject(resultStr);
		String resultData = parseObject.getString("result");
		List<JSONObject> subMgmtUnits = JSON.parseArray(resultData, JSONObject.class);
		if(subMgmtUnits == null) {
			throw new ServiceException(1,resultStr);
		}
		List<SubMgmtUnitResDTO> subMgmtUnitList = Lists.newArrayList();
		for(JSONObject subMgmtUnit :subMgmtUnits) {
			String mainTableStr = subMgmtUnit.getString("mainTable");
			SubMgmtUnitResDTO subMgmtUnitDto = JSON.parseObject(mainTableStr,SubMgmtUnitResDTO.class);
			subMgmtUnitList.add(subMgmtUnitDto);
		}
		return subMgmtUnitList;
	}

	@Override
	public List<SubServiceLineResDTO> getSubServiceLine(GetSubServiceLineReq reqParam) {
		GetSubServiceLineRequest subServiceLineRequest = new GetSubServiceLineRequest();
		GetSubServiceLineDataJson datajson = new GetSubServiceLineDataJson();
		datajson.setHeader(new Header(SpringUtils.getObject(FdConfig.class).getFdBcpSystemId(),SpringUtils.getObject(FdConfig.class).getFdBcpSystemPassword()));
		datajson.setOperationinfo(new OperationInfo());
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageNo(new Long(reqParam.getPageNo()));
		pageInfo.setPageSize(new Long(reqParam.getPageSize()));
		datajson.setPageInfo(pageInfo );
		GetSubServiceLineMainTable mainTable = new GetSubServiceLineMainTable();
		mainTable.setLastupdatetime(DateUtil.format(reqParam.getLastupdatetime(), DatePattern.NORM_DATE_PATTERN));
		datajson.setMainTable(mainTable);
		subServiceLineRequest.setDatajson(JSON.toJSONString(datajson,SerializerFeature.WriteNullStringAsEmpty));
		log.info("远程调用财务中台查询SubServiceLine入参====>"+JSON.toJSONString(subServiceLineRequest,SerializerFeature.WriteNullStringAsEmpty));
		String resultStr = fdFeignService.getSubServiceLine(subServiceLineRequest);
		log.info("远程调用财务中台查询SubServiceLine返回结果====>"+resultStr);
		JSONObject parseObject = JSON.parseObject(resultStr);
		String resultData = parseObject.getString("result");
		List<JSONObject> subServiceLines = JSON.parseArray(resultData, JSONObject.class);
		if(subServiceLines == null) {
			throw new ServiceException(1,resultStr);
		}
		List<SubServiceLineResDTO> subServiceLineList = Lists.newArrayList();
		for(JSONObject subServiceLine :subServiceLines) {
			String mainTableStr = subServiceLine.getString("mainTable");
			SubServiceLineResDTO subServiceLineDto = JSON.parseObject(mainTableStr,SubServiceLineResDTO.class);
			subServiceLineList.add(subServiceLineDto);
		}
		return subServiceLineList;
	}

	@Override
	public List<SubMgmtGdsResDTO> getSubMgmtGds(GetSubMgmtGdsReq reqParam) {
		GetSubMgmtGdsRequest subMgmtGdsRequest = new GetSubMgmtGdsRequest();
		GetSubMgmtGdsDataJson datajson = new GetSubMgmtGdsDataJson();
		datajson.setHeader(new Header(SpringUtils.getObject(FdConfig.class).getFdBcpSystemId(),SpringUtils.getObject(FdConfig.class).getFdBcpSystemPassword()));
		datajson.setOperationinfo(new OperationInfo());
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageNo(new Long(reqParam.getPageNo()));
		pageInfo.setPageSize(new Long(reqParam.getPageSize()));
		datajson.setPageInfo(pageInfo );
		GetSubMgmtGdsMainTable mainTable = new GetSubMgmtGdsMainTable();
		mainTable.setLastupdatetime(DateUtil.format(reqParam.getLastupdatetime(), DatePattern.NORM_DATE_PATTERN));
		datajson.setMainTable(mainTable);
		subMgmtGdsRequest.setDatajson(JSON.toJSONString(datajson,SerializerFeature.WriteNullStringAsEmpty));
		log.info("远程调用财务中台查询SubMgmtGds入参====>"+JSON.toJSONString(subMgmtGdsRequest,SerializerFeature.WriteNullStringAsEmpty));
		String resultStr = fdFeignService.getSubMgmtGds(subMgmtGdsRequest);
		log.info("远程调用财务中台查询SubMgmtGds返回结果====>"+resultStr);
		JSONObject parseObject = JSON.parseObject(resultStr);
		String resultData = parseObject.getString("result");
		List<JSONObject> subMgmtGds = JSON.parseArray(resultData, JSONObject.class);
		if(subMgmtGds == null) {
			throw new ServiceException(1,resultStr);
		}
		List<SubMgmtGdsResDTO> subMgmtGdsList = Lists.newArrayList();
		for(JSONObject subMgmtGd :subMgmtGds) {
			String mainTableStr = subMgmtGd.getString("mainTable");
			SubMgmtGdsResDTO subMgmtGdsDto = JSON.parseObject(mainTableStr,SubMgmtGdsResDTO.class);
			subMgmtGdsList.add(subMgmtGdsDto);
		}
		return subMgmtGdsList;
	}

	@Override
	public List<MercuryCompetencyResDTO> getMercuryCompetency(GetMercuryCompetencyReq reqParam) {
		GetMercuryCompetencyRequest mercuryCompetencyRequest = new GetMercuryCompetencyRequest();
		GetMercuryCompetencyDataJson datajson = new GetMercuryCompetencyDataJson();
		datajson.setHeader(new Header(SpringUtils.getObject(FdConfig.class).getFdBcpSystemId(),SpringUtils.getObject(FdConfig.class).getFdBcpSystemPassword()));
		datajson.setOperationinfo(new OperationInfo());
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageNo(new Long(reqParam.getPageNo()));
		pageInfo.setPageSize(new Long(reqParam.getPageSize()));
		datajson.setPageInfo(pageInfo );
		GetMercuryCompetencyMainTable mainTable = new GetMercuryCompetencyMainTable();
		mainTable.setLastupdatetime(DateUtil.format(reqParam.getLastupdatetime(), DatePattern.NORM_DATE_PATTERN));
		datajson.setMainTable(mainTable);
		mercuryCompetencyRequest.setDatajson(JSON.toJSONString(datajson,SerializerFeature.WriteNullStringAsEmpty));
		log.info("远程调用财务中台查询mercury Competency入参====>"+JSON.toJSONString(mercuryCompetencyRequest,SerializerFeature.WriteNullStringAsEmpty));
		String resultStr = fdFeignService.getMercuryCompetency(mercuryCompetencyRequest);
		log.info("远程调用财务中台查询mercury Competency返回结果====>"+resultStr);
		JSONObject parseObject = JSON.parseObject(resultStr);
		String resultData = parseObject.getString("result");
		List<JSONObject> mercuryCompetencys = JSON.parseArray(resultData, JSONObject.class);
		if(mercuryCompetencys == null) {
			throw new ServiceException(1,resultStr);
		}
		List<MercuryCompetencyResDTO> mercuryCompetencyList = Lists.newArrayList();
		for(JSONObject mercuryCompetency :mercuryCompetencys) {
			String mainTableStr = mercuryCompetency.getString("mainTable");
			MercuryCompetencyResDTO mercuryCompetencyDto = JSON.parseObject(mainTableStr,MercuryCompetencyResDTO.class);
			mercuryCompetencyList.add(mercuryCompetencyDto);
		}
		return mercuryCompetencyList;
	}
	
	
}
