package cn.com.ctop.bytedance.controller;


import cn.com.ctop.bytedance.service.IMaterialReportService;
import cn.com.ctop.common.module.entity.UserAllocation;
import cn.com.ctop.common.module.utils.Check;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/materialReport")
public class MaterialReportController {
    @Autowired
    private IMaterialReportService materialReportService;


    @PostMapping(value = "/getKuaiShouMaterialMarket")
    public Result<List<JSONObject>> getKuaiShouMaterialMarket(@RequestBody JSONObject json) {
        Result<List<JSONObject>> result = new Result<>();
        try {
            List<JSONObject> marketJson = materialReportService.getKuaiShouMaterialMarket(json);
            result.setResult(marketJson);
            result.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            result.setSuccess(false);
        }

        return result;
    }


    @PostMapping(value = "/getKuaiShouChainRatio")
    public Result<JSONObject> getKuaiShouChainRatio(@RequestBody JSONObject json) {

        Result<JSONObject> result = new Result<>();
        try {
            JSONObject marketJson = materialReportService.getKuaiShouChainRatio(json);
            result.setResult(marketJson);
            result.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            result.setSuccess(false);
        }

        return result;

    }


    @PostMapping(value = "/getMaterialAccount")
    public Result<List<UserAllocation>> getKuaiShouChainRatio(@RequestBody String userId) {
        Result<List<UserAllocation>> result = new Result<>();
        try {
            if (Check.isNull(userId)) {
                throw new Exception("用户id为空");
            }
            List<UserAllocation> accountIdList = materialReportService.selectAccountIds(userId);
            result.setResult(accountIdList);
            result.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            result.setSuccess(false);

        }
        return result;

    }


    @PostMapping(value = "/getMaterialReportByAccount")
    public Result<List<JSONObject>> getMaterialReportByAccount(@RequestBody JSONObject json) {
        Result<List<JSONObject>> result = new Result<>();
        try {
            List<JSONObject> reportList = materialReportService.selectReportByAccountIds(json);
            result.setResult(reportList);
            result.setSuccess(true);
        } catch (Exception e) {
            result.setSuccess(false);
        }

        return result;

    }

}
