package com.trs.ggzyexchange.datacentercontroller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.RestController;

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

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

    @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;

    /*
    * 内蒙古自治区首页数据中心
    * */
    @GetMapping(value = "/listTotal")
    public Result<HomePageDataCenter> queryPageListTotal() {
        HomePageDataCenter homePageDataCenter = new HomePageDataCenter();
        Object homePageDataCenterDataObj = redisUtil.get(CommonConstant.HOME_PAGE_DATA);
        if(!ObjectUtils.isEmpty(homePageDataCenterDataObj)){
            homePageDataCenter = JSONObject.parseObject(homePageDataCenterDataObj.toString(),HomePageDataCenter.class);
            return Result.OK(homePageDataCenter);
        }
        /*入场数据总量*/
        /*入场数据总量*/
        /*入场数据总量*/
        /*入场数据总量*/
        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> gcProjectQueryWrapperSelf = new QueryWrapper<GcPackage>();
            gcProjectQueryWrapperSelf.eq("PLATFORM_CODE","121500004600236091");
            int countGcProjectSelf = gcPackageService.count(gcProjectQueryWrapperSelf);
            totalzzq = totalzzq + countGcProjectSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QueryWrapper<GcPackage> gcProjectQueryWrapper = new QueryWrapper<GcPackage>();
            int countGcProject = gcPackageService.count(gcProjectQueryWrapper);
            totalGCJS = totalGCJS+ countGcProject;
            total = total + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*政府采购*/
        try {
            QueryWrapper<ZcProject> zcPurchaseBulletinQueryWrapperSelf = new QueryWrapper<ZcProject>();
            zcPurchaseBulletinQueryWrapperSelf.eq("PLATFORM_CODE","121500004600236091");
            int countZcPurchaseBulletinSelf = zcProjectService.count(zcPurchaseBulletinQueryWrapperSelf);
            totalzzq = totalzzq + countZcPurchaseBulletinSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QueryWrapper<ZcProject> zcPurchaseBulletinQueryWrapper = new QueryWrapper<ZcProject>();
            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","1500");
            int countZrzyTdCedeNoticeSelf = zrzyTdCedeInfoService.count(zrzyTdCedeInfoQueryWrapper);
            totalzzq = totalzzq + countZrzyTdCedeNoticeSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QueryWrapper<ZrzyTdCedeInfo> zrzyTdCedeInfoQueryWrapper = new QueryWrapper<ZrzyTdCedeInfo>();
            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","1500");
            int countZrzyTdCedeNoticeSelf = zrzyTkqProjectInfoService.count(zrzyTkqProjectInfoQueryWrapper);
            totalzzq = totalzzq + countZrzyTdCedeNoticeSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QueryWrapper<ZrzyTkqProjectInfo> zrzyTkqProjectInfoQueryWrapper = new QueryWrapper<ZrzyTkqProjectInfo>();
            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","1500");
            int countZrzyTdCedeNoticeSelf = zrzyCkqProjectInfoService.count(zrzyTkqProjectInfoQueryWrapper);
            totalzzq = totalzzq + countZrzyTdCedeNoticeSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QueryWrapper<ZrzyCkqProjectInfo> zrzyTkqProjectInfoQueryWrapper = new QueryWrapper<ZrzyCkqProjectInfo>();
            int countZrzyTdCedeNotice = zrzyCkqProjectInfoService.count(zrzyTkqProjectInfoQueryWrapper);
            totalZRZY =   totalZRZY + countZrzyTdCedeNotice;
            total = total + countZrzyTdCedeNotice;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_DK_PROJECT*/
        try {
            QueryWrapper<ZrzyDkProject> zrzyTkqProjectInfoQueryWrapper = new QueryWrapper<ZrzyDkProject>();
            int countZrzyTdCedeNoticeSelf = zrzyDkProjectService.count(zrzyTkqProjectInfoQueryWrapper);
            totalzzq = totalzzq + countZrzyTdCedeNoticeSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
        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","1500");
            int countZrzyTdCedeNoticeSelf = zrzyBgStockIndexService.count(zrzyTkqProjectInfoQueryWrapper);
            totalzzq = totalzzq + countZrzyTdCedeNoticeSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QueryWrapper<ZrzyBgStockIndex> zrzyTkqProjectInfoQueryWrapper = new QueryWrapper<ZrzyBgStockIndex>();
            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","1500");
            int countZrzyTdCedeNoticeSelf = zrzyJyzbStockIndexService.count(zrzyTkqProjectInfoQueryWrapper);
            totalzzq = totalzzq + countZrzyTdCedeNoticeSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QueryWrapper<ZrzyJyzbStockIndex> zrzyTkqProjectInfoQueryWrapper = new QueryWrapper<ZrzyJyzbStockIndex>();
            int countZrzyTdCedeNotice = zrzyJyzbStockIndexService.count(zrzyTkqProjectInfoQueryWrapper);
            totalZRZY =   totalZRZY + countZrzyTdCedeNotice;
            total = total + countZrzyTdCedeNotice;
        }catch (Exception e){
            e.printStackTrace();
        }

        try {
            QueryWrapper<CqGqProject> cqGqProjectQueryWrapper = new QueryWrapper<CqGqProject>();
            cqGqProjectQueryWrapper.likeRight("PROJECT_DISTRICT","1500");
            int countZrzyTdCedeNoticeSelf = cqGqProjectService.count(cqGqProjectQueryWrapper);
            totalzzq = totalzzq + countZrzyTdCedeNoticeSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QueryWrapper<CqGqProject> cqGqProjectQueryWrapper = new QueryWrapper<CqGqProject>();
            int countZrzyTdCedeNotice = cqGqProjectService.count(cqGqProjectQueryWrapper);
            totalGYCQ = totalGYCQ + countZrzyTdCedeNotice;
            total = total + countZrzyTdCedeNotice;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*CQ_GQ_PROJECT  无*/
        try {
            QueryWrapper<CqSwProject> cqGqProjectQueryWrapper = new QueryWrapper<CqSwProject>();
            cqGqProjectQueryWrapper.likeRight("zone","1500");
            int countZrzyTdCedeNoticeSelf = cqSwProjectService.count(cqGqProjectQueryWrapper);
            totalzzq = totalzzq + countZrzyTdCedeNoticeSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QueryWrapper<CqSwProject> cqGqProjectQueryWrapper = new QueryWrapper<CqSwProject>();
            int countZrzyTdCedeNotice = cqSwProjectService.count(cqGqProjectQueryWrapper);
            totalGYCQ = totalGYCQ + countZrzyTdCedeNotice;
            total = total + countZrzyTdCedeNotice;
        }catch (Exception e){
            e.printStackTrace();
        }

        try {
            totalYC = ycNoticeService.count();
        }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 totalTransactionzzq = 0;
        int totalTransaction = 0;

        /*GC_BIDPUBLICITY*/
        try {
            QueryWrapper<GcBidpublicity> GcBidpublicityQueryWrapperSelf = new QueryWrapper<GcBidpublicity>();
            GcBidpublicityQueryWrapperSelf.eq("PLATFORM_CODE","121500004600236091");
            int countGcProjectSelf = gcBidpublicityService.count(GcBidpublicityQueryWrapperSelf);
            totalTransactionzzq = totalTransactionzzq + countGcProjectSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QueryWrapper<GcBidpublicity> gcProjectQueryWrapper = new QueryWrapper<GcBidpublicity>();
            int countGcProject = gcBidpublicityService.count(gcProjectQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QueryWrapper<ZcBidpublicity> zcBidpublicityQueryWrapper = new QueryWrapper<ZcBidpublicity>();
            zcBidpublicityQueryWrapper.eq("PLATFORM_CODE","121500004600236091");
            int countGcProjectSelf = zcBidpublicityService.count(zcBidpublicityQueryWrapper);
            totalTransactionzzq = totalTransactionzzq + countGcProjectSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QueryWrapper<ZcBidpublicity> zcBidpublicityQueryWrapper = new QueryWrapper<ZcBidpublicity>();
            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","1500");
            int countGcProjectSelf = zrzyTdBidwinnoticeService.count(zcBidpublicityQueryWrapper);
            totalTransactionzzq = totalTransactionzzq + countGcProjectSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QueryWrapper<ZrzyTdBidwinnotice> zcBidpublicityQueryWrapper = new QueryWrapper<ZrzyTdBidwinnotice>();
            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","1500");
            int countGcProjectSelf = zrzyTkqBidwinnoticeService.count(zcBidpublicityQueryWrapper);
            totalTransactionzzq = totalTransactionzzq + countGcProjectSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QueryWrapper<ZrzyTkqBidwinnotice> zcBidpublicityQueryWrapper = new QueryWrapper<ZrzyTkqBidwinnotice>();
            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","1500");
            int countGcProjectSelf = zrzyCkqBidwinnoticeService.count(zcBidpublicityQueryWrapper);
            totalTransactionzzq = totalTransactionzzq + countGcProjectSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QueryWrapper<ZrzyCkqBidwinnotice> zcBidpublicityQueryWrapper = new QueryWrapper<ZrzyCkqBidwinnotice>();
            int countGcProject = zrzyCkqBidwinnoticeService.count(zcBidpublicityQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_DK_BIDWIN_NOTICE*/
        try {
            QueryWrapper<ZrzyDkBinwinNotice> zcBidpublicityQueryWrapper = new QueryWrapper<ZrzyDkBinwinNotice>();
            int countGcProjectSelf = zrzyDkBinwinNoticeService.count(zcBidpublicityQueryWrapper);
            totalTransactionzzq = totalTransactionzzq + countGcProjectSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
       try {
            QueryWrapper<ZrzyDkBinwinNotice> zcBidpublicityQueryWrapper = new QueryWrapper<ZrzyDkBinwinNotice>();
           zcBidpublicityQueryWrapper.likeRight("zone","1500");
            int countGcProject = zrzyDkBinwinNoticeService.count(zcBidpublicityQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_BG_BIDWIN_NOTICE*/
        try {
            int countGcProjectSelf = zrzyBgBidwinNoticeService.countNoticeByRegionCode("1500");
            totalTransactionzzq = totalTransactionzzq + countGcProjectSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QueryWrapper<ZrzyBgBidwinNotice> zcBidpublicityQueryWrapper = new QueryWrapper<ZrzyBgBidwinNotice>();
            int countGcProject = zrzyBgBidwinNoticeService.count(zcBidpublicityQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_JYZB_BIDWIN_NOTICE*/
        try {
            int countGcProjectSelf = zrzyJyzbBidwinNoticeService.countNoticeByRegionCode("1500");
            totalTransactionzzq = totalTransactionzzq + countGcProjectSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            QueryWrapper<ZrzyJyzbBidwinNotice> zcBidpublicityQueryWrapper = new QueryWrapper<ZrzyJyzbBidwinNotice>();
            int countGcProject = zrzyJyzbBidwinNoticeService.count(zcBidpublicityQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }

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

        totalTransactionData.setTotal(totalTransaction);
        totalTransactionData.setTotalzzq(totalTransactionzzq);
        if(totalTransaction > totalTransactionzzq){
            totalTransactionData.setTotalms(totalTransaction - totalTransactionzzq);
        }
        homePageDataCenter.setTotalTransactionData(totalTransactionData);
        /*交易主体数据总量*/
        /*交易主体数据总量*/
        /*交易主体数据总量*/
        /*交易主体数据总量*/
        TotalAmountTransactionData totalAmountTransactionData = new TotalAmountTransactionData();
        try {
            /*
             *主体数量
             */
            int countTotal = ztLegalinfoService.count();
            totalAmountTransactionData.setTotal(countTotal);
            QueryWrapper<ZtLegalinfo> ztLegalinfoQueryWrapper = new QueryWrapper<ZtLegalinfo>();
            ztLegalinfoQueryWrapper.likeRight("REGION_CODE","15");
            int countzzq = ztLegalinfoService.count(ztLegalinfoQueryWrapper);
            totalAmountTransactionData.setTotalzzq(countzzq);
            if(countTotal > countzzq){
                totalAmountTransactionData.setTotalms(countTotal - 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 {
            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());
            Integer ProjectEntryMoonTotal  = getProjectTotalByTime(DatesUtil.getBeginDayOfMonth(),DatesUtil.getDayEnd());
            Integer ProjectEntryYearTotal  = getProjectTotalByTime(DatesUtil.getBeginDayOfYear(),DatesUtil.getDayEnd());
            totalEntryDataRight.setProjectEntryDayTotal(ProjectEntryDayTotal);
            totalEntryDataRight.setProjectEntryMoonTotal(ProjectEntryMoonTotal);
            totalEntryDataRight.setProjectEntryYearTotal(ProjectEntryYearTotal);
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            Integer BidOpeningSessionsDayTotal = getFieldApplyByTime(DatesUtil.getDayBegin(),DatesUtil.getDayEnd());
            Integer BidOpeningSessionsMoonTotal  = getFieldApplyByTime(DatesUtil.getBeginDayOfMonth(),DatesUtil.getDayEnd());
            Integer BidOpeningSessionsYearTotal  = getFieldApplyByTime(DatesUtil.getBeginDayOfYear(),DatesUtil.getDayEnd());
            totalEntryDataRight.setBidOpeningSessionsDayTotal(BidOpeningSessionsDayTotal);
            totalEntryDataRight.setBidOpeningSessionsMoonTotal(BidOpeningSessionsMoonTotal);
            totalEntryDataRight.setBidOpeningSessionsYearTotal(BidOpeningSessionsYearTotal);
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            Integer NumberTransactionsDayTotal = getEntryDataTotalByTime(DatesUtil.getDayBegin(),DatesUtil.getDayEnd());
            Integer NumberTransactionsMoonTotal = getEntryDataTotalByTime(DatesUtil.getBeginDayOfMonth(),DatesUtil.getEndDayOfMonth());
            Integer NumberTransactionsYearTotal = getEntryDataTotalByTime(DatesUtil.getBeginDayOfYear(),DatesUtil.getEndDayOfYear());
            totalEntryDataRight.setNumberTransactionsDayTotal(NumberTransactionsDayTotal);
            totalEntryDataRight.setNumberTransactionsMoonTotal(NumberTransactionsMoonTotal);
            totalEntryDataRight.setNumberTransactionsYearTotal(NumberTransactionsYearTotal);
        }catch (Exception e){
            e.printStackTrace();
        }
        homePageDataCenter.setTotalEntryDataRight(totalEntryDataRight);
        redisUtil.set(CommonConstant.HOME_PAGE_DATA, JSONObject.toJSONString(homePageDataCenter),CommonConstant.REDIS_SAVE_TIME_TEN_MINUTES);
        return Result.OK(homePageDataCenter);
    }

    public Integer getFieldApplyByTime(Date startTime, Date endTime){
        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.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 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);
            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);
            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);
            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);
            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);
            int countZrzyTdCedeNoticeSelf = zrzyCkqProjectInfoService.count(zrzyTkqProjectInfoQueryWrapper);
            total = total + countZrzyTdCedeNoticeSelf;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_DK_PROJECT*/
        try {
            QueryWrapper<ZrzyDkProject> zrzyTkqProjectInfoQueryWrapper = new QueryWrapper<ZrzyDkProject>();
            zrzyTkqProjectInfoQueryWrapper.ge("NOTICE_SEND_TIME",resultStartTime);
            zrzyTkqProjectInfoQueryWrapper.le("NOTICE_SEND_TIME",resultEndTime);
            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);
            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);
            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);
            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);
            int countZrzyTdCedeNotice = cqSwProjectService.count(cqGqProjectQueryWrapper);
            total = total + countZrzyTdCedeNotice;
        }catch (Exception e){
            e.printStackTrace();
        }

        return total;
    }

    public Integer getEntryDataTotalByTime(Date startTime, Date endTime){
        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);
            int countGcProject = gcBidpublicityService.count(gcProjectQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZC_BIDPUBLICITY*/
        try {
            QueryWrapper<ZcBidpublicity> zcBidpublicityQueryWrapper = new QueryWrapper<ZcBidpublicity>();
            zcBidpublicityQueryWrapper.ge("WIN_BID_BULLETIN_START_TIME",resultStartTime);
            zcBidpublicityQueryWrapper.le("WIN_BID_BULLETIN_START_TIME",resultEndTime);
            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);
            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);
            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);
            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);
            int countGcProject = zrzyDkBinwinNoticeService.count(zcBidpublicityQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_BG_BIDWIN_NOTICE*/
        try {
            QueryWrapper<ZrzyBgBidwinNotice> zcBidpublicityQueryWrapper = new QueryWrapper<ZrzyBgBidwinNotice>();
            zcBidpublicityQueryWrapper.ge("ISSUE_TIME",resultStartTime);
            zcBidpublicityQueryWrapper.le("ISSUE_TIME",resultEndTime);
            int countGcProject = zrzyBgBidwinNoticeService.count(zcBidpublicityQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        /*ZRZY_JYZB_BIDWIN_NOTICE*/
        try {
            QueryWrapper<ZrzyJyzbBidwinNotice> zcBidpublicityQueryWrapper = new QueryWrapper<ZrzyJyzbBidwinNotice>();
            zcBidpublicityQueryWrapper.ge("ISSUE_TIME",resultStartTime);
            zcBidpublicityQueryWrapper.le("ISSUE_TIME",resultEndTime);
            int countGcProject = zrzyJyzbBidwinNoticeService.count(zcBidpublicityQueryWrapper);
            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));
            QueryWrapper<CqSwBargainResult> gcProjectQueryWrapper = new QueryWrapper<CqSwBargainResult>();
            gcProjectQueryWrapper.ge("TRADE_DATE",resultStartTimeYyyyMMdd);
            gcProjectQueryWrapper.le("TRADE_DATE",resultEndTimeYyyyMMdd);
            int countGcProject = cqSwBargainResultService.count(gcProjectQueryWrapper);
            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);
            int countGcProject = cqGqBargainResultService.count(gcProjectQueryWrapper);
            totalTransaction = totalTransaction + countGcProject;
        }catch (Exception e){
            e.printStackTrace();
        }
        return totalTransaction;
    }
}
