package com.bonus.material.main.controller;

import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.material.main.domain.DemandAndSupplyVo;
import com.bonus.material.main.domain.MaTypeHomeVo;
import com.bonus.material.main.service.MainService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

import static com.bonus.common.core.web.domain.AjaxResult.success;


@Api(tags = "机具设备首页接口")
@RestController
@RequestMapping("/mainPage")
@Slf4j
public class MainController {

    @Resource
    private MainService mainService;

    /**
     * 查询机具需求供应情况
     */
    @GetMapping("/demandAndSupply")
    public AjaxResult demandAndSupply(DemandAndSupplyVo demandAndSupplyVo)
    {
        DemandAndSupplyVo demandAndSupplyVoRes = new DemandAndSupplyVo();
        try {
            //需求量
            BigDecimal demandNum = mainService.getDemandNum(demandAndSupplyVo);
//            //需求增长量
//            BigDecimal demandIncrease = mainService.getDemandIncrease(demandAndSupplyVo);
            //已供应数量
            BigDecimal suppliedQuantityNum = mainService.getSuppliedQuantityNum(demandAndSupplyVo);
//            //已供应增长量
//            BigDecimal suppliedQuantityIncrease = mainService.getSuppliedQuantityIncrease(demandAndSupplyVo);
            //待供应量
            BigDecimal suppliedToBeQuantityNum = mainService.getSuppliedToBeQuantityNum(demandAndSupplyVo);
//            //待供应量增长量
//            BigDecimal suppliedToBeQuantityIncrease = mainService.getSuppliedToBeQuantityIncrease(demandAndSupplyVo);
            //获取未结算工程总数量
            Integer projectNum = mainService.getProjectNum(demandAndSupplyVo);
            //供应总件数(机具出库数量，不带条件查询)
            BigDecimal outNum = mainService.getSuppliedQuantityNum(new DemandAndSupplyVo());
            // 供应总价值
            BigDecimal suppliedQuantityPrice = mainService.getSuppliedQuantityPrice(new DemandAndSupplyVo());
            demandAndSupplyVoRes.setDemandNum(demandNum);
//            demandAndSupplyVoRes.setDemandIncrease(demandIncrease);
            demandAndSupplyVoRes.setSuppliedQuantityNum(suppliedQuantityNum);
//            demandAndSupplyVoRes.setSuppliedQuantityIncrease(suppliedQuantityIncrease);
            demandAndSupplyVoRes.setSuppliedToBeQuantityNum(suppliedToBeQuantityNum);
//            demandAndSupplyVoRes.setSuppliedToBeQuantityIncrease(suppliedToBeQuantityIncrease);
            demandAndSupplyVoRes.setProjectNum(projectNum);
            demandAndSupplyVoRes.setSuppliedQuantityAllNum(outNum);
            demandAndSupplyVoRes.setSuppliedQuantityPrice(suppliedQuantityPrice);
        } catch (Exception e) {
            return AjaxResult.error("查询机具需求供应情况失败");
        }
        return success(demandAndSupplyVoRes);
    }

    /**
     * 查询机具仓储状态首页
     * @param dto
     * @return
     */
    @GetMapping("/getMaTypeHomeList")
    public AjaxResult getMaTypeHome(MaTypeHomeVo dto) {
        // 根据时间段查询当前仓储状态详情数据
        try {
            return mainService.getInStockNum(dto);
        } catch (Exception e) {
            return AjaxResult.error("查询机具仓储状态首页失败");
        }
    }

    /**
     * todo 查询机具状态统计占比饼图（暂时弃用）
     * @param dto
     * @return
     */
    @GetMapping("/getMaTypeStatusTotal")
    public AjaxResult getMaTypeStatusTotal(MaTypeHomeVo dto) {
        // 根据时间段查询当前仓储状态详情数据
        try {
            return mainService.getMaTypeStatusTotal(dto);
        } catch (Exception e) {
            return AjaxResult.error("查询机具状态统计占比饼图失败");
        }
    }

    /**
     * 查询机具需求供应情况统计占比饼图
     * @param demandAndSupplyVo
     * @return
     */
    @GetMapping("/getDemandTotal")
    public AjaxResult getDemandTotal(DemandAndSupplyVo demandAndSupplyVo) {
        DemandAndSupplyVo vo = null;
        try {
            vo = new DemandAndSupplyVo();
            //需求量
            BigDecimal demandNum = mainService.getDemandNum(demandAndSupplyVo);
            //已供应数量
            BigDecimal suppliedQuantityNum = mainService.getSuppliedQuantityNum(demandAndSupplyVo);
            //待供应量
            BigDecimal suppliedToBeQuantityNum = mainService.getSuppliedToBeQuantityNum(demandAndSupplyVo);
            vo.setDemandNum(demandNum);
            vo.setSuppliedQuantityNum(suppliedQuantityNum);
            vo.setSuppliedToBeQuantityNum(suppliedToBeQuantityNum);
        } catch (Exception e) {
            return AjaxResult.error("查询机具需求供应情况统计占比饼图失败");
        }
        return success(vo);
    }

    /**
     * 查询机具需求供应情况统计柱状图
     * @param demandAndSupplyVo
     * @return
     */
    @GetMapping("/getDemandList")
    public AjaxResult getDemandList(DemandAndSupplyVo demandAndSupplyVo) {
        try {
            return mainService.getDemandList(demandAndSupplyVo);
        } catch (Exception e) {
            return AjaxResult.error("查询机具需求供应情况统计柱状图失败");
        }
    }
}
