package com.ruoyi.app.utils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.system.domain.PosOrder;
import com.ruoyi.system.domain.VipQuanyi;
import com.ruoyi.system.service.IPosOrderService;
import com.ruoyi.system.service.IVipQuanyiService;
import org.springframework.stereotype.Component;

import jakarta.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Component
public class GetVipqy {
    private static IVipQuanyiService vipQuanyiService;

    private static IPosOrderService posOrderService;
    @Resource
    public void setVipQuanyiService(IVipQuanyiService vipQuanyiService) {
        GetVipqy.vipQuanyiService = vipQuanyiService;
    }
    @Resource
    public void setPosOrderService(IPosOrderService posOrderService) {
        GetVipqy.posOrderService = posOrderService;
    }

    public List<VipQuanyi> getvipqy(String id){
        QueryWrapper<VipQuanyi> queryWrapper= new QueryWrapper<>();
        queryWrapper.eq("vip",0);
        List<VipQuanyi> list = vipQuanyiService.list(queryWrapper);
        List<VipQuanyi> qulist = new ArrayList<>();
        for(int i=0;i<list.size();i++){
            VipQuanyi quanyi = new VipQuanyi();
            DateUtil date = new DateUtil();
            QueryWrapper<PosOrder> Wrapper= new QueryWrapper<>();
            Wrapper.eq("user_id",id);
            Wrapper.eq("yh_id",list.get(i).getId());
            Wrapper.apply("date_format (cretim,'%Y-%m') = date_format ({0},'%Y-%m')", date.GetDate());
            List<PosOrder> yyshul = posOrderService.list(Wrapper);
            quanyi.setId(list.get(i).getId());
            quanyi.setName(list.get(i).getName());
            quanyi.setNum(list.get(i).getNum()-yyshul.size());
            quanyi.setVip(list.get(i).getVip());
            quanyi.setShuoming(list.get(i).getShuoming());
            quanyi.setTiaojian(list.get(i).getTiaojian());
            quanyi.setYhfangs(list.get(i).getYhfangs());
            quanyi.setYhnum(list.get(i).getYhnum());
            qulist.add(quanyi);
        }
        return qulist;
    }
}
