package com.trs.ggzyexchange.datacentercontroller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.trs.ggzyexchange.api.vo.Result;
import com.trs.ggzyexchange.entity.*;
import com.trs.ggzyexchange.entity.pagedata.*;
import com.trs.ggzyexchange.enums.CommonConstant;
import com.trs.ggzyexchange.service.*;
import com.trs.ggzyexchange.utils.DatesUtil;
import com.trs.ggzyexchange.utils.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/home-page-ms-data-controller")
public class HomePageMSDataController {

    @Autowired
    private GcProjectService gcProjectService;
    @Autowired
    private QtjyNoticeService qtjyNoticeService;

    @Autowired
    private ZrzyTdCedeNoticeService zrzyTdCedeNoticeService;

    @Autowired
    private ZcProjectService zcProjectService;

    @Autowired
    private CqGqIssueBulletinService cqGqIssueBulletinService;

    @Autowired
    private CqSwIssueBulletinService cqSwIssueBulletinService;

    @Autowired
    private YcNoticeService ycNoticeService;

    @Autowired
    private BulletinService bulletinService;

    @Autowired
    private ZtLegalinfoService ztLegalinfoService;

    @Autowired
    private GcBidpublicityService gcBidpublicityService;

    @Autowired
    private ZrzyTdBidwinnoticeService zrzyTdBidwinnoticeService;

    @Autowired
    private CqSwBargainResultService cqSwBargainResultService;

    @Autowired
    private OtherTradePubInfoService otherTradePubInfoService;

    @Autowired
    private OtherTradeResultInfoService otherTradeResultInfoService;

    @Autowired
    private JgFieldApplyService jgFieldApplyService;

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private ZcBidpublicityService zcBidpublicityService;

    @Autowired
    private ZrzyTdCedeResultService zrzyTdCedeResultService;

    @Autowired
    private GcPackageService gcPackageService;

    @Autowired
    private ZrzyTdCedeInfoService zrzyTdCedeInfoService;

    @Autowired
    private ZrzyTkqProjectInfoService zrzyTkqProjectInfoService;

    @Autowired
    private ZrzyCkqProjectInfoService zrzyCkqProjectInfoService;

    @Autowired
    private ZrzyDkProjectService zrzyDkProjectService;

    @Autowired
    private ZrzyBgStockIndexService zrzyBgStockIndexService;

    @Autowired
    private ZrzyJyzbStockIndexService zrzyJyzbStockIndexService;

    @Autowired
    private ZrzyTkqBidwinnoticeService zrzyTkqBidwinnoticeService;

    @Autowired
    private ZrzyCkqBidwinnoticeService zrzyCkqBidwinnoticeService;

    @Autowired
    private ZrzyDkBinwinNoticeService zrzyDkBinwinNoticeService;

    @Autowired
    private ZrzyBgBidwinNoticeService zrzyBgBidwinNoticeService;

    @Autowired
    private ZrzyJyzbBidwinNoticeService zrzyJyzbBidwinNoticeService;

    @Autowired
    private CqGqBargainResultService cqGqBargainResultService;

    @Autowired
    private CqGqProjectService cqGqProjectService;

    @Autowired
    private CqSwProjectService cqSwProjectService;

    @Autowired
    private AreaPlatformService areaPlatformService;

    @Autowired
    private SourceCodeNameService venueCodeNameService;

    /*
     * 内蒙古自治区首页数据中心
     * */
    @GetMapping(value = "/listTotal")
    public Result<HomePageDataCenter> queryPageListTotal(
            @RequestParam(name="platformCode", defaultValue="121500004600236091") String platformCode
    ) {
        HomePageDataCenter homePageDataCenter = new HomePageDataCenter();
        Object homePageDataCenterDataObj = redisUtil.get(platformCode+CommonConstant.MS_HOME_PAGE_DATA);
        if(!ObjectUtils.isEmpty(homePageDataCenterDataObj)){
            homePageDataCenter = JSONObject.parseObject(homePageDataCenterDataObj.toString(),HomePageDataCenter.class);
            return Result.OK(homePageDataCenter);
        }
        AreaPlatform areaPlatform = null;
        //获取区域编码对应的国标编码
        try {
            QueryWrapper<AreaPlatform> platformQueryWrapper = new QueryWrapper<AreaPlatform>();
            platformQueryWrapper.eq("PLATFORM_CODE",platformCode);
            areaPlatform = areaPlatformService.getOne(platformQueryWrapper);
            if(ObjectUtils.isEmpty(areaPlatform)){
                return Result.error("传入参数错误");
            }
        }catch (Exception e){
            e.printStackTrace();
            return Result.error("传入参数错误");
        }

        String sourceCode = null;
        String areaCode = areaPlatform.getAreaCode();
        try {
            QueryWrapper<SourceCodeName> sourceCodeNameQueryWrapper = new QueryWrapper<SourceCodeName>();
            sourceCodeNameQueryWrapper.eq("area_code",areaCode);
            Page<SourceCodeName> page = new Page<SourceCodeName>(1, 1);
            IPage<SourceCodeName> tenderDetailsVoIPage = venueCodeNameService.page(page,sourceCodeNameQueryWrapper);
            List<SourceCodeName> records = tenderDetailsVoIPage.getRecords();
            if(!ObjectUtils.isEmpty(records)){
                SourceCodeName sourceCodeName = records.get(0);
                sourceCode = sourceCodeName.getSourceCode();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        String regionCode = "";
        try {
            regionCode = areaCode.substring(0,4);
        }catch (Exception e){
            e.printStackTrace();
        }
        if(ObjectUtils.isEmpty(regionCode) || regionCode == ""){
            regionCode = "111111111111111111111";
        }
        /*入场数据总量*/
        /*入场数据总量*/
        /*入场数据总量*/
        /*入场数据总量*/
        TotalEntryData totalEntryData = new TotalEntryData();
        /*
         * 工程建设
         * */
        int totalzzq = 0;
        int total = 0;
        int totalGCJS = 0;
        int totalZFCG = 0;
        int totalZRZY = 0;
        int totalGYCQ = 0;
        int totalQTJY = 0;
        int totalYC = 0;
        try {
            QueryWrapper<GcPackage> gcProjectQueryWrapper = new QueryWrapper<GcPackage>();
            gcProjectQueryWrapper.eq("PLATFORM_CODE",platformCode);
            int countGcProject = gcPackageService.count(gcProjectQueryWrapper);
            totalGCJS =  totalGCJS + countGcProject;
            total = total + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*政府采购*/
        try {
            QueryWrapper<ZcProject> zcPurchaseBulletinQueryWrapper = new QueryWrapper<ZcProject>();
            zcPurchaseBulletinQueryWrapper.eq("PLATFORM_CODE",platformCode);
            int countZcPurchaseBulletin = zcProjectService.count(zcPurchaseBulletinQueryWrapper);
            totalZFCG = totalZFCG + countZcPurchaseBulletin;
            total = total + countZcPurchaseBulletin;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*土地矿权*/
        /*ZRZY_TD_CEDE_INFO*/
        try {
            QueryWrapper<ZrzyTdCedeInfo> zrzyTdCedeInfoQueryWrapper = new QueryWrapper<ZrzyTdCedeInfo>();
            zrzyTdCedeInfoQueryWrapper.likeRight("region_code",regionCode);
            int countZrzyTdCedeNotice = zrzyTdCedeInfoService.count(zrzyTdCedeInfoQueryWrapper);
            totalZRZY =   totalZRZY + countZrzyTdCedeNotice;
            total = total + countZrzyTdCedeNotice;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_TKQ_PROJECT_INFO*/
        try {
            QueryWrapper<ZrzyTkqProjectInfo> zrzyTkqProjectInfoQueryWrapper = new QueryWrapper<ZrzyTkqProjectInfo>();
            zrzyTkqProjectInfoQueryWrapper.likeRight("region_code",regionCode);
            int countZrzyTdCedeNotice = zrzyTkqProjectInfoService.count(zrzyTkqProjectInfoQueryWrapper);
            totalZRZY =   totalZRZY +  countZrzyTdCedeNotice;
            total = total + countZrzyTdCedeNotice;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_CKQ_PROJECT_INFO*/
        try {
            QueryWrapper<ZrzyCkqProjectInfo> zrzyTkqProjectInfoQueryWrapper = new QueryWrapper<ZrzyCkqProjectInfo>();
            zrzyTkqProjectInfoQueryWrapper.likeRight("region_code",regionCode);
            int countZrzyTdCedeNotice = zrzyCkqProjectInfoService.count(zrzyTkqProjectInfoQueryWrapper);
            totalZRZY =   totalZRZY + countZrzyTdCedeNotice;
            total = total + countZrzyTdCedeNotice;
        }catch (Exception e){
            e.printStackTrace();
        }
        if(platformCode.equals("121500004600236091")){
                try {
                    QueryWrapper<ZrzyDkProject> zrzyTkqProjectInfoQueryWrapper = new QueryWrapper<ZrzyDkProject>();
                    int countZrzyTdCedeNotice = zrzyDkProjectService.count(zrzyTkqProjectInfoQueryWrapper);
                    totalZRZY =   totalZRZY + countZrzyTdCedeNotice;
                    total = total + countZrzyTdCedeNotice;
                }catch (Exception e){
                    e.printStackTrace();
                }
        }
        /*ZRZY_BG_STOCK_INDEX*/
        try {
            QueryWrapper<ZrzyBgStockIndex> zrzyTkqProjectInfoQueryWrapper = new QueryWrapper<ZrzyBgStockIndex>();
            zrzyTkqProjectInfoQueryWrapper.likeRight("zone",regionCode);
            int countZrzyTdCedeNotice = zrzyBgStockIndexService.count(zrzyTkqProjectInfoQueryWrapper);
            totalZRZY =   totalZRZY + countZrzyTdCedeNotice;
            total = total + countZrzyTdCedeNotice;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_JYZB_STOCK_INDEX*/
        try {
            QueryWrapper<ZrzyJyzbStockIndex> zrzyTkqProjectInfoQueryWrapper = new QueryWrapper<ZrzyJyzbStockIndex>();
            zrzyTkqProjectInfoQueryWrapper.likeRight("zone",regionCode);
            int countZrzyTdCedeNotice = zrzyJyzbStockIndexService.count(zrzyTkqProjectInfoQueryWrapper);
            totalZRZY =   totalZRZY + countZrzyTdCedeNotice;
            total = total + countZrzyTdCedeNotice;
        }catch (Exception e){
            e.printStackTrace();
        }

        /*CQ_GQ_PROJECT*/
        try {
            QueryWrapper<CqGqProject> cqGqProjectQueryWrapper = new QueryWrapper<CqGqProject>();
            cqGqProjectQueryWrapper.likeRight("PROJECT_DISTRICT",regionCode);
            int countZrzyTdCedeNotice = cqGqProjectService.count(cqGqProjectQueryWrapper);
            totalGYCQ = totalGYCQ + countZrzyTdCedeNotice;
            total = total + countZrzyTdCedeNotice;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*CQ_SW_PROJECT*/
        try {
            QueryWrapper<CqSwProject> cqGqProjectQueryWrapper = new QueryWrapper<CqSwProject>();
            cqGqProjectQueryWrapper.eq("zone",regionCode);
            int countZrzyTdCedeNotice = cqSwProjectService.count(cqGqProjectQueryWrapper);
            totalGYCQ = totalGYCQ + countZrzyTdCedeNotice;
            total = total + countZrzyTdCedeNotice;
        }catch (Exception e){
            e.printStackTrace();
        }
        totalEntryData.setTotal(total);
        totalEntryData.setTotalzzq(totalzzq);
        if(total > totalzzq){
            totalEntryData.setTotalms(total - totalzzq);
        }
        homePageDataCenter.setTotalEntryData(totalEntryData);

        /*成交数据总量*/
        /*成交数据总量*/
        /*成交数据总量*/
        /*成交数据总量*/
        TotalTransactionData totalTransactionData = new TotalTransactionData();
        int totalTransaction = 0;

        /*GC_BIDPUBLICITY*/
        try {
            QueryWrapper<GcBidpublicity> gcProjectQueryWrapper = new QueryWrapper<GcBidpublicity>();
            gcProjectQueryWrapper.eq("PLATFORM_CODE",platformCode);
            int countGcProject = gcBidpublicityService.count(gcProjectQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QueryWrapper<ZcBidpublicity> zcBidpublicityQueryWrapper = new QueryWrapper<ZcBidpublicity>();
            zcBidpublicityQueryWrapper.eq("PLATFORM_CODE",platformCode);
            int countGcProject = zcBidpublicityService.count(zcBidpublicityQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }


        /*ZRZY_TD_BIDWINNOTICE*/
        try {
            QueryWrapper<ZrzyTdBidwinnotice> zcBidpublicityQueryWrapper = new QueryWrapper<ZrzyTdBidwinnotice>();
            zcBidpublicityQueryWrapper.likeRight("REGION_CODE",regionCode);
            int countGcProject = zrzyTdBidwinnoticeService.count(zcBidpublicityQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }

        /*ZRZY_TKQ_BIDWINNOTICE*/
        try {
            QueryWrapper<ZrzyTkqBidwinnotice> zcBidpublicityQueryWrapper = new QueryWrapper<ZrzyTkqBidwinnotice>();
            zcBidpublicityQueryWrapper.likeRight("REGION_CODE",regionCode);
            int countGcProject = zrzyTkqBidwinnoticeService.count(zcBidpublicityQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_CKQ_BIDWINNOTICE*/
        try {
            QueryWrapper<ZrzyCkqBidwinnotice> zcBidpublicityQueryWrapper = new QueryWrapper<ZrzyCkqBidwinnotice>();
            zcBidpublicityQueryWrapper.likeRight("REGION_CODE",regionCode);
            int countGcProject = zrzyCkqBidwinnoticeService.count(zcBidpublicityQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*Zrzy_Dk_Binwin_Notice*/
        try {
            QueryWrapper<ZrzyDkBinwinNotice> zcBidpublicityQueryWrapper = new QueryWrapper<ZrzyDkBinwinNotice>();
            zcBidpublicityQueryWrapper.likeRight("zone",regionCode);
            int countGcProject = zrzyDkBinwinNoticeService.count(zcBidpublicityQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_BG_BIDWIN_NOTICE*/
        try {
            int countGcProject = zrzyBgBidwinNoticeService.countNoticeByRegionCode(regionCode);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_JYZB_BIDWIN_NOTICE*/
        try {
            int countGcProject = zrzyJyzbBidwinNoticeService.countNoticeByRegionCode(regionCode);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }

        /*CQ_SW_BARGAIN_RESULT*/
        try {
            int countGcProject = cqSwBargainResultService.countByRegionCode(regionCode);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*CQ_GQ_BARGAIN_RESULT*/
        try {
            QueryWrapper<CqGqBargainResult> gcProjectQueryWrapper = new QueryWrapper<CqGqBargainResult>();
            gcProjectQueryWrapper.likeRight("REGION_CODE",regionCode);
            int countGcProject = cqGqBargainResultService.count(gcProjectQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }

        totalTransactionData.setTotal(totalTransaction);
        homePageDataCenter.setTotalTransactionData(totalTransactionData);
        /*交易主体数据总量*/
        /*交易主体数据总量*/
        /*交易主体数据总量*/
        /*交易主体数据总量*/
        TotalAmountTransactionData totalAmountTransactionData = new TotalAmountTransactionData();
        try {
            /*
             *主体数量
             */
            if(platformCode.equals("121500004600236091")){
                QueryWrapper<ZtLegalinfo> ztLegalinfoQueryWrapper = new QueryWrapper<ZtLegalinfo>();
                ztLegalinfoQueryWrapper.likeRight("REGION_CODE","15");
                int countzzq = ztLegalinfoService.count(ztLegalinfoQueryWrapper);
                totalAmountTransactionData.setTotal(countzzq);
            }else{
                if(!ObjectUtils.isEmpty(areaCode) && areaCode != ""){
                    QueryWrapper<ZtLegalinfo> ztLegalinfoQueryWrapper = new QueryWrapper<ZtLegalinfo>();
                    ztLegalinfoQueryWrapper.likeRight("REGION_CODE",regionCode);
                    int countzzq = ztLegalinfoService.count(ztLegalinfoQueryWrapper);
                    totalAmountTransactionData.setTotal(countzzq);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        homePageDataCenter.setTotalAmountTransactionData(totalAmountTransactionData);
        /*各交易类别 发布公告数量*/
        List<QuantityTransactionCategory> categoryList = new ArrayList<QuantityTransactionCategory>();
        try {
            QuantityTransactionCategory quantityTransactionCategory = new QuantityTransactionCategory();
            quantityTransactionCategory.setTotal(totalGCJS);
            quantityTransactionCategory.setName("工程建设");
            categoryList.add(quantityTransactionCategory);
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QuantityTransactionCategory quantityTransactionCategory = new QuantityTransactionCategory();
            quantityTransactionCategory.setTotal(totalZFCG);
            quantityTransactionCategory.setName("政府采购");
            categoryList.add(quantityTransactionCategory);
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QuantityTransactionCategory quantityTransactionCategory = new QuantityTransactionCategory();
            quantityTransactionCategory.setTotal(totalZRZY);
            quantityTransactionCategory.setName("自然资源");
            categoryList.add(quantityTransactionCategory);
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QuantityTransactionCategory quantityTransactionCategory = new QuantityTransactionCategory();
            quantityTransactionCategory.setTotal(totalGYCQ);
            quantityTransactionCategory.setName("国有产权");
            categoryList.add(quantityTransactionCategory);
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QuantityTransactionCategory quantityTransactionCategory = new QuantityTransactionCategory();
            quantityTransactionCategory.setTotal(0);
            quantityTransactionCategory.setName("疫苗交易");
            categoryList.add(quantityTransactionCategory);
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            if(platformCode.equals("121500004600236091")){
                try {
                    totalYC = ycNoticeService.count();
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
            QuantityTransactionCategory quantityTransactionCategory = new QuantityTransactionCategory();
            quantityTransactionCategory.setTotal(totalYC);
            quantityTransactionCategory.setName("药采交易");
            categoryList.add(quantityTransactionCategory);
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QuantityTransactionCategory quantityTransactionCategory = new QuantityTransactionCategory();
            quantityTransactionCategory.setTotal(totalQTJY);
            quantityTransactionCategory.setName("其他交易");
            categoryList.add(quantityTransactionCategory);
        }catch (Exception e){
            e.printStackTrace();
        }
        homePageDataCenter.setCategoryList(categoryList);
        TotalEntryDataRight totalEntryDataRight = new TotalEntryDataRight();
        try {
            Integer ProjectEntryDayTotal = getProjectTotalByTime(DatesUtil.getDayBegin(),DatesUtil.getDayEnd(),platformCode,regionCode);
            Integer ProjectEntryMoonTotal  = getProjectTotalByTime(DatesUtil.getBeginDayOfMonth(),DatesUtil.getDayEnd(),platformCode,regionCode);
            Integer ProjectEntryYearTotal  = getProjectTotalByTime(DatesUtil.getBeginDayOfYear(),DatesUtil.getDayEnd(),platformCode,regionCode);
            totalEntryDataRight.setProjectEntryDayTotal(ProjectEntryDayTotal);
            totalEntryDataRight.setProjectEntryMoonTotal(ProjectEntryMoonTotal);
            totalEntryDataRight.setProjectEntryYearTotal(ProjectEntryYearTotal);
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            Integer BidOpeningSessionsDayTotal = getFieldApplyByTime(DatesUtil.getDayBegin(),DatesUtil.getDayEnd(),sourceCode);
            Integer BidOpeningSessionsMoonTotal  = getFieldApplyByTime(DatesUtil.getBeginDayOfMonth(),DatesUtil.getDayEnd(),sourceCode);
            Integer BidOpeningSessionsYearTotal  = getFieldApplyByTime(DatesUtil.getBeginDayOfYear(),DatesUtil.getDayEnd(),sourceCode);
            totalEntryDataRight.setBidOpeningSessionsDayTotal(BidOpeningSessionsDayTotal);
            totalEntryDataRight.setBidOpeningSessionsMoonTotal(BidOpeningSessionsMoonTotal);
            totalEntryDataRight.setBidOpeningSessionsYearTotal(BidOpeningSessionsYearTotal);
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            Integer NumberTransactionsDayTotal = getEntryDataTotalByTime(DatesUtil.getDayBegin(),DatesUtil.getDayEnd(),platformCode,regionCode);
            Integer NumberTransactionsMoonTotal = getEntryDataTotalByTime(DatesUtil.getBeginDayOfMonth(),DatesUtil.getEndDayOfMonth(),platformCode,regionCode);
            Integer NumberTransactionsYearTotal = getEntryDataTotalByTime(DatesUtil.getBeginDayOfYear(),DatesUtil.getEndDayOfYear(),platformCode,regionCode);
            totalEntryDataRight.setNumberTransactionsDayTotal(NumberTransactionsDayTotal);
            totalEntryDataRight.setNumberTransactionsMoonTotal(NumberTransactionsMoonTotal);
            totalEntryDataRight.setNumberTransactionsYearTotal(NumberTransactionsYearTotal);
        }catch (Exception e){
            e.printStackTrace();
        }
        homePageDataCenter.setTotalEntryDataRight(totalEntryDataRight);
        redisUtil.set(platformCode+CommonConstant.MS_HOME_PAGE_DATA, JSONObject.toJSONString(homePageDataCenter),CommonConstant.REDIS_SAVE_TIME_TEN_MINUTES);
        return Result.OK(homePageDataCenter);
    }

    public Integer getFieldApplyByTime(Date startTime, Date endTime,String sourceCode){
        String strDateFormat = "yyyyMMddHHmmss";
        Long resultStartTime  = Long.parseLong(DateFormatUtils.format(startTime,strDateFormat));
        Long resultEndTime  = Long.parseLong(DateFormatUtils.format(endTime,strDateFormat));
        QueryWrapper<JgFieldApply> gcProjectQueryWrapper = new QueryWrapper<JgFieldApply>();
        gcProjectQueryWrapper.eq("source_data_code",sourceCode);
        gcProjectQueryWrapper.ge("BID_OPENING_TIME",resultStartTime);
        gcProjectQueryWrapper.le("BID_OPENING_TIME",resultEndTime);
        gcProjectQueryWrapper.eq("MEETING_TYPE","1");
        int count = jgFieldApplyService.count(gcProjectQueryWrapper);
        return count;
    }

    public Integer getProjectTotalByTime(Date startTime, Date endTime,String platformCode,String region_code){
        String strDateFormat = "yyyyMMddHHmmss";
        Long resultStartTime  = Long.parseLong(DateFormatUtils.format(startTime,strDateFormat));
        Long resultEndTime  = Long.parseLong(DateFormatUtils.format(endTime,strDateFormat));
        Integer total = 0;
        try {
            QueryWrapper<GcPackage> gcPackageQueryWrapper = new QueryWrapper<GcPackage>();
            gcPackageQueryWrapper.ge("CREATE_TIME",resultStartTime);
            gcPackageQueryWrapper.le("CREATE_TIME",resultEndTime);
            gcPackageQueryWrapper.eq("platform_code",platformCode);
            int countGcProject = gcPackageService.count(gcPackageQueryWrapper);
            total = total + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*政府采购*/
        try {
            QueryWrapper<ZcProject> zcPurchaseBulletinQueryWrapper = new QueryWrapper<ZcProject>();
            zcPurchaseBulletinQueryWrapper.ge("CREATE_TIME",resultStartTime);
            zcPurchaseBulletinQueryWrapper.le("CREATE_TIME",resultEndTime);
            zcPurchaseBulletinQueryWrapper.eq("platform_code",platformCode);
            int countZcPurchaseBulletin = zcProjectService.count(zcPurchaseBulletinQueryWrapper);
            total = total + countZcPurchaseBulletin;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*土地矿权*/
        /*ZRZY_TD_CEDE_INFO*/
        try {
            QueryWrapper<ZrzyTdCedeInfo> zrzyTdCedeInfoQueryWrapper = new QueryWrapper<ZrzyTdCedeInfo>();
            zrzyTdCedeInfoQueryWrapper.ge("SIGNUP_OPEN_TIME",resultStartTime);
            zrzyTdCedeInfoQueryWrapper.le("SIGNUP_OPEN_TIME",resultEndTime);
            zrzyTdCedeInfoQueryWrapper.likeRight("region_code",region_code);
            int countZrzyTdCedeNoticeSelf = zrzyTdCedeInfoService.count(zrzyTdCedeInfoQueryWrapper);
            total = total + countZrzyTdCedeNoticeSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_TKQ_PROJECT_INFO*/
        try {
            QueryWrapper<ZrzyTkqProjectInfo> zrzyTkqProjectInfoQueryWrapper = new QueryWrapper<ZrzyTkqProjectInfo>();
            zrzyTkqProjectInfoQueryWrapper.ge("SIGNUP_OPEN_TIME",resultStartTime);
            zrzyTkqProjectInfoQueryWrapper.le("SIGNUP_OPEN_TIME",resultEndTime);
            zrzyTkqProjectInfoQueryWrapper.likeRight("region_code",region_code);
            int countZrzyTdCedeNoticeSelf = zrzyTkqProjectInfoService.count(zrzyTkqProjectInfoQueryWrapper);
            total = total + countZrzyTdCedeNoticeSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_CKQ_PROJECT_INFO*/
        try {
            QueryWrapper<ZrzyCkqProjectInfo> zrzyTkqProjectInfoQueryWrapper = new QueryWrapper<ZrzyCkqProjectInfo>();
            zrzyTkqProjectInfoQueryWrapper.ge("SIGNUP_OPEN_TIME",resultStartTime);
            zrzyTkqProjectInfoQueryWrapper.le("SIGNUP_OPEN_TIME",resultEndTime);
            zrzyTkqProjectInfoQueryWrapper.likeRight("region_code",region_code);
            int countZrzyTdCedeNoticeSelf = zrzyCkqProjectInfoService.count(zrzyTkqProjectInfoQueryWrapper);
            total = total + countZrzyTdCedeNoticeSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_DK_PROJECT*/
        if(platformCode.equals("121500004600236091")){
            try {
                QueryWrapper<ZrzyDkProject> zrzyTkqProjectInfoQueryWrapper = new QueryWrapper<ZrzyDkProject>();
                zrzyTkqProjectInfoQueryWrapper.ge("NOTICE_SEND_TIME",resultStartTime);
                zrzyTkqProjectInfoQueryWrapper.le("NOTICE_SEND_TIME",resultEndTime);
                zrzyTkqProjectInfoQueryWrapper.eq("platform_code",platformCode);
                int countZrzyTdCedeNoticeSelf = zrzyDkProjectService.count(zrzyTkqProjectInfoQueryWrapper);
                total = total + countZrzyTdCedeNoticeSelf;
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        /*ZRZY_BG_STOCK_INDEX*/
        try {
            QueryWrapper<ZrzyBgStockIndex> zrzyTkqProjectInfoQueryWrapper = new QueryWrapper<ZrzyBgStockIndex>();
            zrzyTkqProjectInfoQueryWrapper.ge("IN_TIME",resultStartTime);
            zrzyTkqProjectInfoQueryWrapper.le("IN_TIME",resultEndTime);
            zrzyTkqProjectInfoQueryWrapper.likeRight("zone",region_code);
            int countZrzyTdCedeNoticeSelf = zrzyBgStockIndexService.count(zrzyTkqProjectInfoQueryWrapper);
            total = total + countZrzyTdCedeNoticeSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_JYZB_STOCK_INDEX*/
        try {
            QueryWrapper<ZrzyJyzbStockIndex> zrzyTkqProjectInfoQueryWrapper = new QueryWrapper<ZrzyJyzbStockIndex>();
            zrzyTkqProjectInfoQueryWrapper.ge("DATA_TIMESTAMP",resultStartTime);
            zrzyTkqProjectInfoQueryWrapper.le("DATA_TIMESTAMP",resultEndTime);
            zrzyTkqProjectInfoQueryWrapper.likeRight("zone",region_code);
            int countZrzyTdCedeNoticeSelf = zrzyJyzbStockIndexService.count(zrzyTkqProjectInfoQueryWrapper);
            total = total + countZrzyTdCedeNoticeSelf;
        }catch (Exception e){
            e.printStackTrace();
        }

        try {
            QueryWrapper<CqGqProject> cqGqProjectQueryWrapper = new QueryWrapper<CqGqProject>();
            cqGqProjectQueryWrapper.ge("ENTRYREGISTDATE",resultStartTime);
            cqGqProjectQueryWrapper.le("ENTRYREGISTDATE",resultEndTime);
            cqGqProjectQueryWrapper.likeRight("PROJECT_DISTRICT",region_code);
            int countZrzyTdCedeNotice = cqGqProjectService.count(cqGqProjectQueryWrapper);
            total = total + countZrzyTdCedeNotice;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*CQ_SW_PROJECT*/
        try {
            QueryWrapper<CqSwProject> cqGqProjectQueryWrapper = new QueryWrapper<CqSwProject>();
            cqGqProjectQueryWrapper.ge("ENTRYREGISTDATE",resultStartTime);
            cqGqProjectQueryWrapper.le("ENTRYREGISTDATE",resultEndTime);
            cqGqProjectQueryWrapper.eq("zone",platformCode);
            int countZrzyTdCedeNotice = cqSwProjectService.count(cqGqProjectQueryWrapper);
            total = total + countZrzyTdCedeNotice;
        }catch (Exception e){
            e.printStackTrace();
        }

        return total;
    }

    public Integer getEntryDataTotalByTime(Date startTime, Date endTime,String platformCode,String region_code){
        String strDateFormat = "yyyyMMddHHmmss";
        Long resultStartTime  = Long.parseLong(DateFormatUtils.format(startTime,strDateFormat));
        Long resultEndTime  = Long.parseLong(DateFormatUtils.format(endTime,strDateFormat));
        int totalTransaction = 0;
        /*GC_BIDPUBLICITY*/
        try {
            QueryWrapper<GcBidpublicity> gcProjectQueryWrapper = new QueryWrapper<GcBidpublicity>();
            gcProjectQueryWrapper.ge("NOTICE_SEND_TIME",resultStartTime);
            gcProjectQueryWrapper.le("NOTICE_SEND_TIME",resultEndTime);
            gcProjectQueryWrapper.eq("platform_code",platformCode);
            int countGcProject = gcBidpublicityService.count(gcProjectQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QueryWrapper<ZcBidpublicity> zcBidpublicityQueryWrapper = new QueryWrapper<ZcBidpublicity>();
            zcBidpublicityQueryWrapper.ge("WIN_BID_BULLETIN_START_TIME",resultStartTime);
            zcBidpublicityQueryWrapper.le("WIN_BID_BULLETIN_START_TIME",resultEndTime);
            zcBidpublicityQueryWrapper.eq("platform_code",platformCode);
            int countGcProject = zcBidpublicityService.count(zcBidpublicityQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_TD_BIDWINNOTICE*/
        try {
            QueryWrapper<ZrzyTdBidwinnotice> zcBidpublicityQueryWrapper = new QueryWrapper<ZrzyTdBidwinnotice>();
            zcBidpublicityQueryWrapper.ge("PUBLISHING_TIME",resultStartTime);
            zcBidpublicityQueryWrapper.le("PUBLISHING_TIME",resultEndTime);
            zcBidpublicityQueryWrapper.likeRight("region_code",region_code);
            int countGcProject = zrzyTdBidwinnoticeService.count(zcBidpublicityQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_TKQ_BIDWINNOTICE*/

        try {
            QueryWrapper<ZrzyTkqBidwinnotice> zcBidpublicityQueryWrapper = new QueryWrapper<ZrzyTkqBidwinnotice>();
            zcBidpublicityQueryWrapper.ge("PUBLISHING_TIME",resultStartTime);
            zcBidpublicityQueryWrapper.le("PUBLISHING_TIME",resultEndTime);
            zcBidpublicityQueryWrapper.likeRight("region_code",region_code);
            int countGcProject = zrzyTkqBidwinnoticeService.count(zcBidpublicityQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_CKQ_BIDWINNOTICE*/
        try {
            QueryWrapper<ZrzyCkqBidwinnotice> zcBidpublicityQueryWrapper = new QueryWrapper<ZrzyCkqBidwinnotice>();
            zcBidpublicityQueryWrapper.ge("PUBLISHING_TIME",resultStartTime);
            zcBidpublicityQueryWrapper.le("PUBLISHING_TIME",resultEndTime);
            zcBidpublicityQueryWrapper.likeRight("region_code",region_code);
            int countGcProject = zrzyCkqBidwinnoticeService.count(zcBidpublicityQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_DK_BINWIN_NOTICE*/
        try {
            QueryWrapper<ZrzyDkBinwinNotice> zcBidpublicityQueryWrapper = new QueryWrapper<ZrzyDkBinwinNotice>();
            zcBidpublicityQueryWrapper.ge("SUBMITS_TIME",resultStartTime);
            zcBidpublicityQueryWrapper.le("SUBMITS_TIME",resultEndTime);
            zcBidpublicityQueryWrapper.likeRight("zone",region_code);
            int countGcProject = zrzyDkBinwinNoticeService.count(zcBidpublicityQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_BG_BIDWIN_NOTICE*/
        try {
            int countGcProject = zrzyBgBidwinNoticeService.countNoticeByRegionCodeAndTime(region_code,resultStartTime,resultEndTime);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_JYZB_BIDWIN_NOTICE*/
        try {
            int countGcProject = zrzyJyzbBidwinNoticeService.countNoticeByRegionCodeAndTime(region_code,resultStartTime,resultEndTime);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }

        /*CQ_SW_BARGAIN_RESULT*/
        try {
            String strDateFormatYyyyMMdd = "yyyyMMdd";
            Long resultStartTimeYyyyMMdd  = Long.parseLong(DateFormatUtils.format(startTime,strDateFormatYyyyMMdd));
            Long resultEndTimeYyyyMMdd  = Long.parseLong(DateFormatUtils.format(endTime,strDateFormatYyyyMMdd));
            int countGcProject = cqSwBargainResultService.countByRegionCodeAndTime(region_code,resultStartTimeYyyyMMdd,resultEndTimeYyyyMMdd);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*CQ_GQ_BARGAIN_RESULT*/
        try {
            String strDateFormatYyyyMMdd = "yyyyMMdd";
            Long resultStartTimeYyyyMMdd  = Long.parseLong(DateFormatUtils.format(startTime,strDateFormatYyyyMMdd));
            Long resultEndTimeYyyyMMdd  = Long.parseLong(DateFormatUtils.format(endTime,strDateFormatYyyyMMdd));
            QueryWrapper<CqGqBargainResult> gcProjectQueryWrapper = new QueryWrapper<CqGqBargainResult>();
            gcProjectQueryWrapper.ge("TRADE_DATE",resultStartTimeYyyyMMdd);
            gcProjectQueryWrapper.le("TRADE_DATE",resultEndTimeYyyyMMdd);
            gcProjectQueryWrapper.likeRight("REGION_CODE",region_code);
            int countGcProject = cqGqBargainResultService.count(gcProjectQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        return totalTransaction;
    }
}
