package com.dsk.system.dskService;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.dsk.common.core.domain.R;
import com.dsk.common.core.domain.model.*;
import com.dsk.common.core.page.TableDataInfo;
import com.dsk.common.utils.DskOpenApiUtil;
import org.apache.commons.collections4.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class EnterpriseProjectService {

    private static final Logger log = LoggerFactory.getLogger(EnterpriseService.class);

    @Autowired
    private DskOpenApiUtil dskOpenApiUtil;


    public TableDataInfo landTransactionPage(EnterpriseProjectLandTransactionPageBody body) throws Exception {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/operate/enterpriseProject/landTransactionPage", BeanUtil.beanToMap(body, false, false));
        return dskOpenApiUtil.responsePage(map);
    }


    public R landUse(EnterpriseProjectLandUseBody body) throws Exception {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/operate/enterpriseProject/landUse", BeanUtil.beanToMap(body, false, false));
        return BeanUtil.toBean(map, R.class);
    }


    public R landDetail(EnterpriseProjectLandDetailBody body) throws Exception {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/operate/enterpriseProject/landDetail", BeanUtil.beanToMap(body, false, false));
        return BeanUtil.toBean(map, R.class);
    }


    public TableDataInfo approvalProjectPage(EnterpriseProjectApprovalProjectPageBody body) throws Exception {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/operate/enterpriseProject/approvalProjectPage", BeanUtil.beanToMap(body, false, false));
        return dskOpenApiUtil.responsePage(map);
    }


    public R approvalInfoDetail(EnterpriseProjectApprovalInfoDetailBody body) throws Exception {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/operate/enterpriseProject/approvalInfoDetail", BeanUtil.beanToMap(body, false, false));
        return BeanUtil.toBean(map, R.class);
    }


    public TableDataInfo approvalExaminePage(EnterpriseProjectApprovalExaminePageBody body) throws Exception {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/operate/enterpriseProject/approvalExaminePage", BeanUtil.beanToMap(body, false, false));
        return dskOpenApiUtil.responsePage(map);
    }


    public TableDataInfo approvalMarketingPage(EnterpriseProjectApprovalMarketingPageBody body) throws Exception {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/operate/enterpriseProject/approvalMarketingPage", BeanUtil.beanToMap(body, false, false));
        return dskOpenApiUtil.responsePage(map);
    }


    public TableDataInfo specialDebtProjectPage(Object body) throws Exception {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/operate/enterpriseProject/specialDebtProjectPage", BeanUtil.beanToMap(body, false, false));
        return dskOpenApiUtil.responsePage(map);
    }


    public R specialDebtProjectDetail(Object body) throws Exception {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/operate/enterpriseProject/specialDebtProjectDetail", BeanUtil.beanToMap(body, false, false));
        return BeanUtil.toBean(map, R.class);
    }

    public TableDataInfo specialDebtPage(Object body) throws Exception {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/operate/enterpriseProject/specialDebtPage", BeanUtil.beanToMap(body, false, false));
        return dskOpenApiUtil.responsePage(map);
    }

    public TableDataInfo bidNoticePage(EnterpriseProjectBidNoticePageBody body) throws Exception {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/operate/enterpriseProject/bidNoticePage", BeanUtil.beanToMap(body, false, false));
        return dskOpenApiUtil.responsePage(map);
    }


    public R bidNoticeTenderStage(EnterpriseProjectBidNoticeTenderStageBody body) throws Exception {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/operate/enterpriseProject/bidNoticeTenderStage", BeanUtil.beanToMap(body, false, false));
        return BeanUtil.toBean(map, R.class);
    }


    public R bidNoticeArea(EnterpriseProjectBidNoticeAreaBody body) throws Exception {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/operate/enterpriseProject/bidNoticeArea", BeanUtil.beanToMap(body, false, false));
        return BeanUtil.toBean(map, R.class);
    }


    public R bidNoticeDetail(EnterpriseProjectBidNoticeDetailBody body) throws Exception {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/operate/enterpriseProject/bidNoticeDetail", BeanUtil.beanToMap(body, false, false));
        return BeanUtil.toBean(map, R.class);
    }


    public TableDataInfo bidPlanPage(Object body) throws Exception {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/operate/enterpriseProject/bidPlanPage", BeanUtil.beanToMap(body, false, false));
        return dskOpenApiUtil.responsePage(map);
    }


    public R bidPlanDetail(Object body) throws Exception {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/operate/enterpriseProject/bidPlanDetail", BeanUtil.beanToMap(body, false, false));
        Map data = MapUtils.getMap(map, "data", null);
        String contentId = MapUtils.getString(data, "contentId");
        if (ObjectUtil.isEmpty(contentId)) {
            return BeanUtil.toBean(map, R.class);
        }

        HashMap<String, Object> contentParam = new HashMap<>();
        contentParam.put("data_type", "bid_plan");
        contentParam.put("filter_type", 2);
        contentParam.put("strategy_id", contentId);
        Map<String, Object> contentMap = dskOpenApiUtil.requestBody("/mongocontent/v1/cjb/mongo_content", BeanUtil.beanToMap(contentParam, false, false));

        Map contentData = MapUtils.getMap(contentMap, "data", null);

        if (200 != MapUtils.getInteger(contentMap, "code", 300)) {
            return BeanUtil.toBean(map, R.class);
        }

        String htmlContent = MapUtils.getString(contentData, "htmlContent");

        map.put("content", htmlContent);

        return BeanUtil.toBean(map, R.class);
    }


    public TableDataInfo bidNoticeProPage(EnterpriseProjectBidNoticeProPageBody body) throws Exception {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/operate/enterpriseProject/bidNoticeProPage", BeanUtil.beanToMap(body, false, false));
        return dskOpenApiUtil.responsePage(map);
    }

    public R bidNoticeProProjectType(EnterpriseProjectBidNoticeProProjectTypeBody body) throws Exception {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/operate/enterpriseProject/bidNoticeProProjectType", BeanUtil.beanToMap(body, false, false));
        return BeanUtil.toBean(map, R.class);
    }

    public R bidNoticeProProjectPurposes(EnterpriseProjectBidNoticeProProjectPurposesBody body) throws Exception {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/operate/enterpriseProject/bidNoticeProProjectPurposes", BeanUtil.beanToMap(body, false, false));
        return BeanUtil.toBean(map, R.class);
    }

    public R bidNoticeProAssessmentWay(EnterpriseProjectBidNoticeProAssessmentWayBody body) throws Exception {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/operate/enterpriseProject/bidNoticeProAssessmentWay", BeanUtil.beanToMap(body, false, false));
        return BeanUtil.toBean(map, R.class);
    }


    public R bidNoticeProDetail(EnterpriseProjectBidNoticeProDetailBody body) throws Exception {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/operate/enterpriseProject/bidNoticeProDetail", BeanUtil.beanToMap(body, false, false));
        return BeanUtil.toBean(map, R.class);
    }


    public TableDataInfo creditXzxkPage(EnterpriseProjectCreditXzxkPageBody body) throws Exception {
        Map<String, Object> map = dskOpenApiUtil.requestBody("/operate/enterpriseProject/creditXzxkPage", BeanUtil.beanToMap(body, false, false));
        return dskOpenApiUtil.responsePage(map);
    }
}
