package org.jeecg.ctop.material.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.jeecg.common.api.vo.Result;
import org.jeecg.ctop.material.mapper.MaterialDataMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Service
public class MaterialDataServiceImpl implements IMaterialDataService {
    @Autowired
    private MaterialDataMapper materialDataMapper;

    @Override
    public String getRoleCodeByUserId(String userId) {
        return materialDataMapper.getRoleCodeByUserId(userId);
    }

    @Override
    public String getCompanyIdByUserId(String userId) {
        return materialDataMapper.getCompanyIdByUserId(userId);
    }

    // 头条汇总信息
    @Override
    public JSONObject getByteDanceTotalInfo(Map<String, Object> requestMap) {
        JSONObject returnJson = new JSONObject();
        BigDecimal totalCharge = materialDataMapper.getByteDanceTotalCharge(requestMap); // 总消耗
        JSONObject helpInfo = materialDataMapper.getByteDanceHelpInfo(requestMap); //上传助手信息
        Integer pushMediaCount = materialDataMapper.getByteDancePushMediaCount(requestMap); //推送媒体数量
        Integer firstChargeCount = materialDataMapper.getByteDanceFirstChargeCount(requestMap); //产生消耗量
        Integer effectCount = materialDataMapper.getByteDanceEffectCount(requestMap); //有效素材量
        returnJson.put("totalCharge", totalCharge);
        returnJson.put("helpInfo", helpInfo);
        returnJson.put("pushMediaCount", pushMediaCount);
        returnJson.put("firstChargeCount", firstChargeCount);
        returnJson.put("effectCount", effectCount);
        return returnJson;
    }

    // 快手汇总信息
    @Override
    public JSONObject getKuaiShouTotalInfo(Map<String, Object> requestMap) {
        JSONObject returnJson = new JSONObject();
        BigDecimal totalCharge = materialDataMapper.getKuaiShouTotalCharge(requestMap); // 总消耗
        JSONObject helpInfo = materialDataMapper.getKuaiShouHelpInfo(requestMap); //上传助手信息
        Integer pushMediaCount = materialDataMapper.getKuaiShouPushMediaCount(requestMap); //推送媒体数量
        Integer firstChargeCount = materialDataMapper.getKuaiShouFirstChargeCount(requestMap); //产生消耗量
        Integer effectCount = materialDataMapper.getKuaiShouEffectCount(requestMap); //有效素材量
        returnJson.put("totalCharge", totalCharge);
        returnJson.put("helpInfo", helpInfo);
        returnJson.put("pushMediaCount", pushMediaCount);
        returnJson.put("firstChargeCount", firstChargeCount);
        returnJson.put("effectCount", effectCount);
        return returnJson;
    }

    // 头条折线图信息
    @Override
    public List<JSONObject> getByteDanceChartData(Map<String, Object> requestMap, Integer type) {
        if (type == 1) {
            return materialDataMapper.getByteDanceTotalChargeChart(requestMap); // 总消耗
        }
        if (type == 2) {
            return materialDataMapper.getByteDanceHelpChart(requestMap); //上传助手信息
        }
        if (type == 3) {
            return materialDataMapper.getByteDancePushMediaChart(requestMap); //推送媒体数量
        }
        if (type == 4) {
            return materialDataMapper.getByteDanceFirstChargeChart(requestMap); //产生消耗量
        }
        if (type == 5) {
            return materialDataMapper.getByteDanceEffectChart(requestMap); //有效素材量
        }

        return null;
    }

    @Override
    public List<JSONObject> getKuaiShouChartData(Map<String, Object> requestMap, Integer type) {
        if (type == 1) {
            return materialDataMapper.getKuaiShouTotalChargeChart(requestMap); // 总消耗
        }
        if (type == 2) {
            return materialDataMapper.getKuaiShouHelpChart(requestMap); //上传助手信息
        }
        if (type == 3) {
            return materialDataMapper.getKuaiShouPushMediaChart(requestMap); //推送媒体数量
        }
        if (type == 4) {
            return materialDataMapper.getKuaiShouFirstChargeChart(requestMap); //产生消耗量
        }
        if (type == 5) {
            return materialDataMapper.getKuaiShouEffectChart(requestMap); //有效素材量
        }

        return null;
    }

    // 头条分项目
    @Override
    public Result<Object> getByteDanceProjectData(Map<String, Object> requestMap, Integer pageNo, Integer pageSize) {
//        PageHelper.startPage(pageNo, pageSize);
        List<JSONObject> data = materialDataMapper.getByteDanceProjectData(requestMap);
        return Result.ok(new PageInfo<>(data));
    }

    // 快手分项目
    @Override
    public Result<Object> getKuaiShouProjectData(Map<String, Object> requestMap, Integer pageNo, Integer pageSize) {
//        PageHelper.startPage(pageNo, pageSize);
        List<JSONObject> data = materialDataMapper.getKuaiShouProjectData(requestMap);
        return Result.ok(new PageInfo<>(data));
    }

    // 头条分团队
    @Override
    public Result<Object> getByteDanceTeamData(Map<String, Object> requestMap, Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        List<JSONObject> data = materialDataMapper.getByteDanceTeamData(requestMap);
        return Result.ok(new PageInfo<>(data));
    }

    // 快手分团队数据
    @Override
    public Result<Object> getKuaiShouTeamData(Map<String, Object> requestMap, Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        List<JSONObject> data = materialDataMapper.getKuaiShouTeamData(requestMap);
        return Result.ok(new PageInfo<>(data));
    }

    @Override
    public Result<Object> getByteDanceUserData(Map<String, Object> requestMap, Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        List<JSONObject> data = materialDataMapper.getByteDanceUserData(requestMap);
        return Result.ok(new PageInfo<>(data));
    }

    @Override
    public Result<Object> getKuaiShouUserData(Map<String, Object> requestMap, Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        List<JSONObject> data = materialDataMapper.getKuaiShouUserData(requestMap);
        return Result.ok(new PageInfo<>(data));
    }

    @Override
    public Result<Object> getByteDanceVideoData(Map<String, Object> requestMap, Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        List<JSONObject> data = materialDataMapper.getByteDanceVideoData(requestMap);
        return Result.ok(new PageInfo<>(data));
    }

    @Override
    public Result<Object> getKuaiShouVideoData(Map<String, Object> requestMap, Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        List<JSONObject> data = materialDataMapper.getKuaiShouVideoData(requestMap);
        return Result.ok(new PageInfo<>(data));
    }
}
