package org.jeecg.ctop.material.controller;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.ctop.material.constants.Check;
import org.jeecg.ctop.material.service.ISysManagerCompanyService;
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;

/**
 * 总经理&公司记录表
 */
@Slf4j
@Api(tags = "总经理&公司记录表")
@RestController
@RequestMapping("/manager/company")
public class SysManagerCompanyController {
    @Autowired
    private ISysManagerCompanyService sysManagerCompanyService;

    /**
     * 列表查询
     */
    @GetMapping(value = "/getCompanyList")
    public Result<Object> queryPageList() {
        return Result.ok(sysManagerCompanyService.list());
    }


    /**
     * 素材产出
     */
    @GetMapping(value = "/getMaterialProduce")
    public Result<Object> getMaterialProduce(String startTime, String endTime, String companyId, int mediaId) {
        if (Check.isNull(companyId) || Check.isNull(mediaId)) {
            return Result.error("缺少参数");
        }
        return sysManagerCompanyService.getMaterialProduce(startTime, endTime, companyId, mediaId);
    }

    /**
     * 素材产出消耗
     */
    @GetMapping(value = "/getMaterialProduceConsume")
    public Result<Object> getMaterialProduceConsume(String startTime, String endTime, String companyId, int mediaId) {
        if (Check.isNull(companyId) || Check.isNull(mediaId)) {
            return Result.error("缺少参数");
        }
        return sysManagerCompanyService.getMaterialProduceConsume(startTime, endTime, companyId, mediaId);
    }

    /**
     * 运营消耗情况
     */
    @GetMapping(value = "/getOperaterConsume")
    public Result<Object> getOperaterConsume(String startTime, String endTime, String companyId, int mediaId) {
        if (Check.isNull(companyId) || Check.isNull(mediaId)) {
            return Result.error("缺少参数");
        }
        return sysManagerCompanyService.getOperaterConsume(startTime, endTime, companyId, mediaId);
    }

    /**
     * 设置本月消耗完成度
     */
    @GetMapping(value = "/setConsumeValue")
    public Result<Object> setConsumeValue(String companyId, String targetValue, int mediaId) {
        if (Check.isNull(companyId) || Check.isNull(mediaId) || Check.isNull(targetValue)) {
            return Result.error("缺少参数");
        }
        try {
            sysManagerCompanyService.setConsumeValue(companyId, targetValue, mediaId);
            return Result.ok("success");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("修改失败");
        }
    }

    /**
     * 项目消耗Top10
     */
    @GetMapping(value = "/getProjectConsumeTop")
    public Result<Object> getProjectConsumeTop(String startTime, String endTime, String companyId, int mediaId) {
        if (Check.isNull(companyId) || Check.isNull(mediaId)) {
            return Result.error("缺少参数");
        }
        try {
            return sysManagerCompanyService.getProjectConsumeTop(startTime, endTime, companyId, mediaId);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败");
        }
    }


    /**
     * 分媒体投放数据
     */
    @GetMapping(value = "/getMediaData")
    public Result<Object> getMediaData(String companyId) {
        if (Check.isNull(companyId)) {
            return Result.error("缺少参数");
        }
        try {
            return sysManagerCompanyService.getMediaData(companyId);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败");
        }
    }

    /**
     * 当日实时整体数据概览
     */
    @GetMapping(value = "/getRealTimeData")
    public Result<Object> getRealTimeData(String companyId,int mediaId) {
        if (Check.isNull(companyId)||Check.isNull(mediaId)) {
            return Result.error("缺少参数");
        }
        try {
            return sysManagerCompanyService.getRealTimeData(companyId,mediaId);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败");
        }
    }

    /**
     * 查询本月总消耗
     */
    @GetMapping(value = "/getTotalConsume")
    public Result<Object> getTotalConsume(String companyId,int mediaId) {
        if (Check.isNull(companyId)||Check.isNull(mediaId)) {
            return Result.error("缺少参数");
        }
        try {
            return sysManagerCompanyService.getTotalConsume(companyId,mediaId);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败");
        }
    }

}
