package org.dromara.web.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.config.RuoYiConfig;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.domain.model.LoginUser;
import org.dromara.common.core.utils.DateUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.system.domain.bo.SysDeptBo;
import org.dromara.system.domain.bo.SysPictureBo;
import org.dromara.system.domain.bo.SysUserBo;
import org.dromara.system.domain.vo.SysPictureVo;
import org.dromara.system.domain.vo.SysUserVo;
import org.dromara.system.service.ISysPictureService;
import org.dromara.system.service.ISysUserService;
import org.dromara.web.utils.WxXcxUtils;
import org.dromara.work.domain.TpReceipt;
import org.dromara.work.domain.bo.OrderRankingBo;
import org.dromara.work.domain.bo.TpProdBo;
import org.dromara.work.domain.bo.TpReceiptBo;
import org.dromara.work.domain.bo.TpWechatBo;
import org.dromara.work.domain.vo.*;
import org.dromara.work.service.*;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * 首页
 *
 * @author Lion Li
 */
@SaIgnore
@RequiredArgsConstructor
@RestController
public class IndexController {

    /**
     * 系统基础配置
     */
    private final RuoYiConfig ruoyiConfig;

    private final ITpOrderService tpOrderService;

    private final ISysUserService sysUserService;

    private final ITpWechatService tpWechatService;

    private final ITpReceiptService tpReceiptService;

    private final IOrderService orderService;

    private final ITpNewOrderService tpNewOrderService;

    private final ISysPictureService sysPictureService;

    private final ITpProdService tpProdService;

    /**
     * 访问首页，提示语
     */
    @GetMapping("/")
    public String index() {
        return StringUtils.format("欢迎使用{}后台管理框架，当前版本：v{}，请通过前端地址访问。", ruoyiConfig.getName(), ruoyiConfig.getVersion());
    }

    /**
     * 分页获取画册列表
     */
    @GetMapping("/banner")
    public R<TableDataInfo<SysPictureVo>> list(SysPictureBo bo, PageQuery pageQuery) {
        bo.setStatus(1L);
        return R.ok(sysPictureService.selectPageList(bo, pageQuery));
    }

    /**
     * 根据ID获取画册详情
     */
    @GetMapping("/banner/{id}")
    public R<SysPictureVo> getSysPictureInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(sysPictureService.queryById(id));
    }

    /**
     * 分页获取商品列表
     */
    @GetMapping("/prod")
    public R<TableDataInfo<TpProdVo>> list(TpProdBo bo, PageQuery pageQuery) {
        bo.setStatus(1L);
        return R.ok(tpProdService.queryPageList(bo, pageQuery));
    }

    /**
     * 根据ID获取商品详情
     */
    @GetMapping("/prod/{id}")
    public R<TpProdVo> getTpProdInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(tpProdService.queryById(id));
    }

    /**
     * 根据url获取微信JS-SDK使用权限签名
     */
    @PostMapping("/wx/jssdk")
    public R<Map<String, String>> getWxJssdk(@RequestParam String url) {
        return R.ok(WxXcxUtils.generateSignature(url));
    }

    /**
     * 银盛支付回调
     * @param params
     * @return
     */
    /**
     * 银盛支付回调
     * @param params
     * @return
     */
    @PostMapping(value = "/notifyCheckSign")
    @RepeatSubmit(interval = 1, timeUnit = TimeUnit.SECONDS, message = "重复请求")
    public String notifyCheckSign(@RequestParam Map<String, String> params) {
        try {
            // 校验输入参数并清理潜在危险字符
            validateAndSanitizeParams(params);
            String outTradeNo = params.get("out_trade_no");
            if (outTradeNo == null || outTradeNo.isEmpty()) {
                return "failure";
            }
            // 检查订单是否存在
            boolean exists = tpReceiptService.exists(new LambdaQueryWrapper<TpReceipt>().eq(TpReceipt::getOutTradeNo, outTradeNo));
            if (exists) {
                // 订单已存在
                return "success";
            }

            // 订单不存在且交易状态为成功时，插入新记录
            String tradeStatus = params.get("trade_status");
            if ("TRADE_SUCCESS".equals(tradeStatus)) {
                TpReceiptBo tpReceipt = new TpReceiptBo();
                tpReceipt.setQid(80);
                tpReceipt.setRemark("小程序收银台T1订单");
                tpReceipt.setOutTradeNo(outTradeNo);
                tpReceipt.setTradeNo(params.get("trade_no"));
                tpReceipt.setPrice(new BigDecimal(params.get("total_amount")));
                tpReceipt.setHkTime(DateUtils.parseDate(params.get("notify_time")));
                tpReceipt.setAddTime(new Date());

                // 插入新记录并捕获异常
                try {
                    tpReceiptService.insertReceipt(tpReceipt);
                    return "success";
                } catch (Exception e) {
                    return "failure";
                }
            }
            return "failure";
        } catch (Exception e) {
            return "failure";
        }
    }

    private void validateAndSanitizeParams(Map<String, String> params) {
        // 实现严格的参数校验和清理逻辑
        // 例如：去除特殊字符、检查长度、格式等
        // 确保所有参数都是安全的
        if (params == null || params.isEmpty()) {
            throw new IllegalArgumentException("参数不能为空");
        }
        if (!params.containsKey("out_trade_no") || !params.containsKey("trade_status")) {
            throw new IllegalArgumentException("缺少必要参数");
        }
    }


    /**
     * 首页统计
     * @return
     */
    @GetMapping("/indexSum")
    public R<IndexSumVo> indexSum() {
        LoginUser loginUser = LoginHelper.getLoginUser();
        if (loginUser.getIdentity() == 2){
            return R.ok(tpOrderService.getJsTarget());
        }else if (loginUser.getIdentity() == 3){
            return R.ok(tpOrderService.getKfTarget());
        }
        return R.ok();
    }

    /**
     * 更新订单部门状态
     */
    @SaCheckPermission("system:user:edit")
    @RepeatSubmit
    @PostMapping("/updateOrder")
    public R<Boolean> updateOrder(SysUserBo bo) {
        return R.ok(orderService.updateOrder(bo));
    }


    /**
     * 客服排行榜
     */
    @SaCheckPermission("index:order:rankingListKF")
    @GetMapping("/rankingListKF")
    public TableDataInfo<OrderRankingVo> rankingListKF(OrderRankingBo bo, PageQuery pageQuery) {
        bo.setType(1);
        return tpNewOrderService.rankingList(bo, pageQuery);
    }

    /**
     * 客服排行榜统计
     */
    @SaCheckPermission("index:order:rankingListKF")
    @GetMapping("/rankingListKFSum")
    public R<OrderRankingSumVo> rankingListKFSum(OrderRankingBo bo) {
        bo.setType(1);
        return R.ok(tpNewOrderService.rankingListKFSum(bo));
    }

    /**
     * 技术排行榜
     */
    @SaCheckPermission("index:order:rankingListJS")
    @GetMapping("/rankingListJS")
    public TableDataInfo<OrderRankingVo> rankingListJS(OrderRankingBo bo, PageQuery pageQuery) {
        bo.setType(2);
        return tpNewOrderService.rankingListJS(bo, pageQuery);
    }

    /**
     * 技术排行榜统计
     */
    @SaCheckPermission("index:order:rankingListJS")
    @GetMapping("/rankingListJSSum")
    public R<OrderRankingSumVo> rankingListJSSum(OrderRankingBo bo) {
        bo.setType(2);
        return R.ok(tpNewOrderService.rankingListJSSum(bo));
    }

    /**
     * 部门排行榜(客服)
     */
    @SaCheckPermission("index:order:deptRankingList")
    @GetMapping("/deptRankingList")
    public R<List<DeptRankingVo>> deptRankingList(SysDeptBo bo) {
        return R.ok(orderService.deptRankingList(bo));
    }

    /**
     * 部门排行榜(客服单个)
     */
    @SaCheckPermission("index:order:deptRankingList")
    @GetMapping("/deptRankingList1")
    public R<List<DeptRankingVo>> deptRankingList1(SysDeptBo bo) {
        return R.ok(orderService.deptRankingList1(bo));
    }

    /**
     * 部门排行榜(技术)
     */
    @SaCheckPermission("index:order:deptRankingJSList")
    @GetMapping("/deptRankingJSList")
    public R<List<DeptRankingVo>> deptRankingJSList(SysDeptBo bo) {
        return R.ok(orderService.deptRankingJSList(bo));
    }

    /**
     * 部门排行榜(技术/单个)
     */
    @SaCheckPermission("index:order:deptRankingJSList")
    @GetMapping("/deptRankingJSList1")
    public R<List<DeptRankingVo>> deptRankingJSList1(SysDeptBo bo) {
        return R.ok(orderService.deptRankingJSList1(bo));
    }

    /**
     * 客户下单排行榜
     */
    @SaCheckPermission("index:order:khRankingList")
    @GetMapping("/khRankingList")
    public TableDataInfo<OrderRankingVo> khRankingList(OrderRankingBo bo, PageQuery pageQuery) {
        return tpNewOrderService.khRankingList(bo, pageQuery);
    }

    /**
     * 客户下单排行榜统计
     */
    @SaCheckPermission("index:order:khRankingList")
    @GetMapping("/khRankingListSum")
    public R<OrderRankingSumVo> khRankingListSum(OrderRankingBo bo) {
        return R.ok(tpNewOrderService.khRankingListSum(bo));
    }

    /**
     * 客服部数据分析（日）
     * @param bo
     * @return
     */
    @SaCheckPermission("index:order:kfDayList")
    @GetMapping("/kfDayList")
    public TableDataInfo<KfDayListVo> kfDayList(OrderRankingBo bo, PageQuery pageQuery) {
        SysUserBo user = new SysUserBo();
        user.setIdentity(3);
        user.setStatus("0");

        if(ObjectUtil.isNotNull(bo.getUserName())){
            user.setNickName(bo.getUserName());
        }
        if(bo.getDeptId() != null){
            user.setDeptId(bo.getDeptId());
        }
        if (bo.getDeptIds() != null){
            user.setDeptIds(bo.getDeptIds());
        }
        /*else {
            int scope = getDataScope();
            if(scope == 2){
                List<Long> deptIds = getDeptIds();
                lqw.in(TpOrder::getDeptId,deptIds);
            }else if(scope == 3){
                lqw.eq(TpOrder::getDeptId,loginUser.getDeptId());
            }else if(scope == 4){
                List<Long> deptIds = deptMapper.selectList(new LambdaQueryWrapper<SysDept>().like(SysDept::getAncestors, loginUser.getDeptId())).stream().map(SysDept::getDeptId).collect(Collectors.toList());
                deptIds.add(loginUser.getDeptId());
                lqw.in(TpOrder::getDeptId,deptIds);
            }else if(scope == 5){
                lqw.eq(TpOrder::getSid,loginUser.getUserId());
            }
        }*/
        TableDataInfo<SysUserVo> list = sysUserService.selectPageGetUserList(user, pageQuery);
        List<Long> userIds = list.getRows().stream().map(SysUserVo::getUserId).collect(Collectors.toList());
        List<OrderDayListVo> listVoList = orderService.kfDayList(bo,userIds);

        TableDataInfo<KfDayListVo> kfDayListVoList = new TableDataInfo<>();
        kfDayListVoList.setCode(list.getCode());
        kfDayListVoList.setMsg(list.getMsg());
        kfDayListVoList.setTotal(list.getTotal());
        List<KfDayListVo> kfList = new ArrayList<>();
        for (SysUserVo vo : list.getRows()){
            KfDayListVo kfDayListVo = new KfDayListVo();
            kfDayListVo.setSid(vo.getUserId());
            kfDayListVo.setName(vo.getNickName());
            kfDayListVo.setList(listVoList.stream().filter(item -> item.getSid().equals(vo.getUserId())).collect(Collectors.toList()));
            kfList.add(kfDayListVo);
        }
        kfDayListVoList.setRows(kfList);
        return kfDayListVoList;
    }


    /**
     * 微信好友分析（日）
     * @param bo
     * @return
     */
    @SaCheckPermission("index:order:wxDayList")
    @GetMapping("/wxDayList")
    public TableDataInfo<WxDayListVo> wxDayList(OrderRankingBo bo, PageQuery pageQuery) {
        TpWechatBo wechatBo = new TpWechatBo();
        if(bo.getDeptId() != null){
            wechatBo.setCreateDept(bo.getDeptId());
        }
        if(ObjectUtil.isNotNull(bo.getUserName())){
            wechatBo.setCode(bo.getUserName());
        }
        if(ObjectUtil.isNotNull(bo.getRealName())){
            wechatBo.setUser(bo.getRealName());
        }
        TableDataInfo<TpWechatVo> list = tpWechatService.queryPageList(wechatBo, pageQuery);
        List<Long> wxIds = list.getRows().stream().map(TpWechatVo::getId).collect(Collectors.toList());
        List<WxNumDayListVo> listVoList = tpWechatService.wxDayList(bo,wxIds);

        TableDataInfo<WxDayListVo> wxDayListVoList = new TableDataInfo<>();
        wxDayListVoList.setCode(list.getCode());
        wxDayListVoList.setMsg(list.getMsg());
        wxDayListVoList.setTotal(list.getTotal());
        List<WxDayListVo> wxList = new ArrayList<>();
        for (TpWechatVo vo : list.getRows()){
            WxDayListVo wxDayListVo = new WxDayListVo();
            wxDayListVo.setId(vo.getId());
            wxDayListVo.setCode(vo.getCode());
            wxDayListVo.setName(vo.getUser());
            wxDayListVo.setList(listVoList.stream().filter(item -> item.getWid().equals(vo.getId())).collect(Collectors.toList()));
            wxList.add(wxDayListVo);

        }
        wxDayListVoList.setRows(wxList);
        return wxDayListVoList;
    }

    /**
     * 微信好友分析（日）
     * @param bo
     * @return
     */
    @SaCheckPermission("index:order:wxDayList")
    @GetMapping("/wxDayList1")
    public TableDataInfo<WxDayListVo> wxDayList1(OrderRankingBo bo, PageQuery pageQuery) {
        SysUserBo user = new SysUserBo();
        user.setIdentity(3);
        user.setStatus("0");

        if(ObjectUtil.isNotNull(bo.getUserName())){
            user.setNickName(bo.getUserName());
        }
        if(bo.getDeptId() != null){
            user.setDeptId(bo.getDeptId());
        }
        if (bo.getDeptIds() != null){
            user.setDeptIds(bo.getDeptIds());
        }
        TableDataInfo<SysUserVo> list = sysUserService.selectPageGetUserList(user, pageQuery);
        if (!list.getRows().isEmpty()) {
            List<Long> userIds = list.getRows().stream().map(SysUserVo::getUserId).collect(Collectors.toList());

            List<TpWechatVo> list1 = tpWechatService.queryListByIds(userIds);
            List<Long> wxIds = list1.stream().map(TpWechatVo::getId).collect(Collectors.toList());
            List<WxNumDayListVo> listVoList = tpWechatService.wxDayList(bo,wxIds);


            TableDataInfo<WxDayListVo> wxDayListVoList = new TableDataInfo<>();
            wxDayListVoList.setCode(list.getCode());
            wxDayListVoList.setMsg(list.getMsg());
            wxDayListVoList.setTotal(list.getTotal());
            List<WxDayListVo> wxList = new ArrayList<>();
            for (TpWechatVo vo : list1){
                WxDayListVo wxDayListVo = new WxDayListVo();
                wxDayListVo.setId(vo.getId());
                wxDayListVo.setCode(vo.getCode());
                wxDayListVo.setUid(vo.getUid());
                wxDayListVo.setName(vo.getUser());
                wxDayListVo.setList(listVoList.stream().filter(item -> item.getWid().equals(vo.getId())).collect(Collectors.toList()));
                wxList.add(wxDayListVo);
            }
            wxDayListVoList.setRows(wxList);
            return wxDayListVoList;
        }
        return TableDataInfo.build();
    }


    /**
     * 微信好友分析（月）
     * @param bo
     * @return
     */
    @SaCheckPermission("index:order:wxMonthList")
    @GetMapping("/wxMonthList")
    public TableDataInfo<WxDayListVo> wxMonthList(OrderRankingBo bo, PageQuery pageQuery) {
        TpWechatBo wechatBo = new TpWechatBo();
        if(bo.getDeptId() != null){
            wechatBo.setCreateDept(bo.getDeptId());
        }
        if(ObjectUtil.isNotNull(bo.getUserName())){
            wechatBo.setCode(bo.getUserName());
        }
        if(ObjectUtil.isNotNull(bo.getRealName())){
            wechatBo.setUser(bo.getRealName());
        }
        TableDataInfo<TpWechatVo> list = tpWechatService.queryPageList(wechatBo, pageQuery);
        List<Long> wxIds = list.getRows().stream().map(TpWechatVo::getId).collect(Collectors.toList());
        List<WxNumDayListVo> listVoList = tpWechatService.wxMonthList(bo,wxIds);

        TableDataInfo<WxDayListVo> wxDayListVoList = new TableDataInfo<>();
        wxDayListVoList.setCode(list.getCode());
        wxDayListVoList.setMsg(list.getMsg());
        wxDayListVoList.setTotal(list.getTotal());
        List<WxDayListVo> wxList = new ArrayList<>();
        for (TpWechatVo vo : list.getRows()){
            WxDayListVo wxDayListVo = new WxDayListVo();
            wxDayListVo.setId(vo.getId());
            wxDayListVo.setCode(vo.getCode());
            wxDayListVo.setName(vo.getUser());
            wxDayListVo.setList(listVoList.stream().filter(item -> item.getWid().equals(vo.getId())).collect(Collectors.toList()));
            wxList.add(wxDayListVo);

        }
        wxDayListVoList.setRows(wxList);
        return wxDayListVoList;
    }


    /**
     * 技术部数据分析（分图）
     * @param bo
     * @return
     */
    @SaCheckPermission("index:order:ftDayList")
    @GetMapping("/ftDayList")
    public TableDataInfo<KfDayListVo> ftDayList(OrderRankingBo bo, PageQuery pageQuery) {
        SysUserBo user = new SysUserBo();
        user.setIsFty(1);
        if(bo.getDeptId() != null){
            user.setDeptId(bo.getDeptId());
        }
        if (bo.getDeptIds() != null){
            user.setDeptIds(bo.getDeptIds());
        }
        if(ObjectUtil.isNotNull(bo.getUserName())){
            user.setNickName(bo.getUserName());
        }
        TableDataInfo<SysUserVo> list = sysUserService.selectPageGetUserList(user, pageQuery);
        List<Long> userIds = list.getRows().stream().map(SysUserVo::getUserId).collect(Collectors.toList());
        List<OrderDayListVo> listVoList = orderService.ftDayList(bo,userIds);

        TableDataInfo<KfDayListVo> kfDayListVoList = new TableDataInfo<>();
        kfDayListVoList.setCode(list.getCode());
        kfDayListVoList.setMsg(list.getMsg());

        int i = 0;
        List<KfDayListVo> kfList = new ArrayList<>();
        for (SysUserVo vo : list.getRows()){
            boolean containsUserId = listVoList.stream()
                .map(OrderDayListVo::getFid).anyMatch(userId -> userId.equals(vo.getUserId()));
            if (containsUserId) {
                KfDayListVo kfDayListVo = new KfDayListVo();
                kfDayListVo.setSid(vo.getUserId());
                kfDayListVo.setName(vo.getNickName());
                kfDayListVo.setList(listVoList.stream().filter(item -> item.getFid().equals(vo.getUserId())).collect(Collectors.toList()));
                kfList.add(kfDayListVo);
            } else {
                i++;
            }
        }
        kfDayListVoList.setTotal(list.getTotal()-i);
        kfDayListVoList.setRows(kfList);
        return kfDayListVoList;
    }


    /**
     * 技术部数据分析（月）
     * @param bo
     * @return
     */
    @SaCheckPermission("index:order:jsDayList")
    @GetMapping("/jsDayList")
    public TableDataInfo<KfDayListVo> jsDayList(OrderRankingBo bo, PageQuery pageQuery) {
        SysUserBo user = new SysUserBo();
        user.setIdentity(2);
        user.setStatus("0");
        if(bo.getDeptId() != null){
            user.setDeptId(bo.getDeptId());
        }
        if (bo.getDeptIds() != null){
            user.setDeptIds(bo.getDeptIds());
        }
        if(ObjectUtil.isNotNull(bo.getUserName())){
            user.setNickName(bo.getUserName());
        }
        TableDataInfo<SysUserVo> list = sysUserService.selectPageGetUserList(user, pageQuery);
        List<Long> userIds = list.getRows().stream().map(SysUserVo::getUserId).collect(Collectors.toList());
        List<OrderDayListVo> listVoList = orderService.jsDayList(bo,userIds);

        TableDataInfo<KfDayListVo> kfDayListVoList = new TableDataInfo<>();
        kfDayListVoList.setCode(list.getCode());
        kfDayListVoList.setMsg(list.getMsg());

        int i = 0;
        List<KfDayListVo> kfList = new ArrayList<>();
        for (SysUserVo vo : list.getRows()){
            boolean containsUserId = listVoList.stream()
                .map(OrderDayListVo::getBid).anyMatch(userId -> userId.equals(vo.getUserId()));
            if (containsUserId) {
                KfDayListVo kfDayListVo = new KfDayListVo();
                kfDayListVo.setSid(vo.getUserId());
                kfDayListVo.setName(vo.getNickName());
                kfDayListVo.setList(listVoList.stream().filter(item -> item.getBid().equals(vo.getUserId())).collect(Collectors.toList()));
                kfList.add(kfDayListVo);
            } else {
                i++;
            }
        }
        kfDayListVoList.setTotal(list.getTotal()-i);
        kfDayListVoList.setRows(kfList);
        return kfDayListVoList;
    }


    /**
     * 业绩按月统计
     */
    @SaCheckPermission("index:order:monthArrivedPer")
    @PostMapping("/monthArrivedPer")
    @Parameters({
        @Parameter(name = "month", description = "日期 如：2024-09", required = true),
        @Parameter(name = "deptId", description = "部门ID", required = false)
    })
    public R<List<PerSumVo>> monthArrivedPer(@RequestParam(value = "month") String month, @RequestParam(value = "deptId") Long deptId) {
        return R.ok(orderService.monthArrivedPer(month,deptId));
    }

    /**
     * 业绩按年统计
     */
    @SaCheckPermission("index:order:yearArrivedPer")
    @PostMapping("/yearArrivedPer")
    @Parameters({
        @Parameter(name = "year", description = "日期 如：2024", required = true),
        @Parameter(name = "deptId", description = "部门ID", required = false)
    })
    public R<List<PerSumVo>> yearArrivedPer(@RequestParam(value = "year") String year, @RequestParam(value = "deptId") Long deptId) {
        return R.ok(orderService.yearArrivedPer(year,deptId));
    }


    /**
     * 订单类型统计
     */
    @SaCheckPermission("index:order:monthOrderType")
    @PostMapping("/monthOrderType")
    @Parameters({
        @Parameter(name = "month", description = "日期 如：2024-09", required = true),
        @Parameter(name = "deptId", description = "部门ID", required = false)
    })
    public R<List<PerCountVo>> monthOrderType(@RequestParam(value = "month") String month, @RequestParam(value = "deptId") Long deptId) {
        return R.ok(orderService.monthOrderType(month,deptId));
    }

    /**
     * 订单空间统计
     */
    @SaCheckPermission("index:order:monthOrderSpace")
    @PostMapping("/monthOrderSpace")
    @Parameters({
        @Parameter(name = "month", description = "日期 如：2024-09", required = true),
        @Parameter(name = "deptId", description = "部门ID", required = false)
    })
    public R<List<PerCountVo>> monthOrderSpace(@RequestParam(value = "month") String month, @RequestParam(value = "deptId") Long deptId) {
        return R.ok(orderService.monthOrderSpace(month,deptId));
    }

    /**
     * 订单风格统计
     */
    @SaCheckPermission("index:order:monthOrderStyle")
    @PostMapping("/monthOrderStyle")
    @Parameters({
        @Parameter(name = "month", description = "日期 如：2024-09", required = true),
        @Parameter(name = "deptId", description = "部门ID", required = false)
    })
    public R<List<PerCountVo>> monthOrderStyle(@RequestParam(value = "month") String month, @RequestParam(value = "deptId") Long deptId) {
        return R.ok(orderService.monthOrderStyle(month,deptId));
    }


    /**
     * 新老客户占比
     */
    @SaCheckPermission("index:order:newOldOrderPer")
    @PostMapping("/newOldOrderPer")
    @Parameters({
        @Parameter(name = "month", description = "日期 如：2024-09", required = true),
        @Parameter(name = "deptId", description = "部门ID", required = false)
    })
    public R<List<PerCountVo>> newOldOrderPer(@RequestParam(value = "month") String month, @RequestParam(value = "deptId") Long deptId) {
        return R.ok(orderService.newOldOrderPer(month,deptId));
    }
}
