package com.hzs.sale.index.controller.manage;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzs.common.core.enums.EYesNo;
import com.hzs.common.core.utils.NumberUtil;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.domain.sale.wares.BdWares;
import com.hzs.sale.order.service.ISaOrderService;
import com.hzs.sale.wares.service.IBdWaresService;
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;

import java.math.BigDecimal;

@RestController
@RequestMapping("/manager/index")
public class IndexController extends BaseController {

    @Autowired
    private IBdWaresService waresService;
    @Autowired
    private ISaOrderService orderService;

    /**
     * 查询套组商品占比
     */
    @GetMapping("get-wares-scale")
    public AjaxResult getWaresScale() {
        // 查询单品
        QueryWrapper<BdWares> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("IS_SINGLE", EYesNo.YES.getIntValue());
        // 单品数
        int singleCount = waresService.count(queryWrapper);
        // 查询组合
        QueryWrapper<BdWares> composeWrapper = new QueryWrapper<>();
        composeWrapper.eq("IS_SINGLE", EYesNo.NO.getIntValue());
        // 套组数
        int composeCount = waresService.count(composeWrapper);
        // 单品百分比占比
        String singleRatio = NumberUtil.getRatio(singleCount + composeCount, singleCount);
        // 套组百分比占比
        String composeRatio = NumberUtil.getRatio(singleCount + composeCount, composeCount);
        // 计算销售金额

        //总收益 (统计订单总收益)
        BigDecimal priceSum = orderService.selectSum();

        JSONObject json = new JSONObject();
        //  总收益
        json.put("priceSum", priceSum);
        // 套组百分比占比
        json.put("composeRatio", composeRatio);
        // 单品百分比占比
        json.put("singleRatio", singleRatio);
        return AjaxResult.success(json);
    }


    /**
     * 产品销售比例
     */
    @GetMapping("get-product-scale")
    public AjaxResult saleProductScale() {
        //   productService.
        return AjaxResult.success();
    }
}
