package com.gree.mall.miniapp.logic.charging;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gree.mall.miniapp.bean.chargingstandard.ChargingStandardBean;
import com.gree.mall.miniapp.bean.user.CurrentCompanyWechat;
import com.gree.mall.miniapp.commonmapper.CommonMapper;
import com.gree.mall.miniapp.logic.common.CommonLogic;
import com.gree.mall.miniapp.plus.entity.Brand;
import com.gree.mall.miniapp.plus.entity.ChargingStandardType;
import com.gree.mall.miniapp.plus.service.BrandService;
import com.gree.mall.miniapp.plus.service.ChargingStandardService;
import com.gree.mall.miniapp.plus.service.ChargingStandardTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChargingStandardLogic {

    @Autowired
    CommonLogic commonLogic;
    @Autowired
    ChargingStandardService chargingStandardService;
    @Autowired
    ChargingStandardTypeService chargingStandardTypeService;
    @Autowired
    CommonMapper commonMapper;
    @Autowired
    BrandService brandService;

    /**
     * 收费标准业务类型-列表
     * @return
     */
    public List<ChargingStandardType> listType(){
        CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat();
        return chargingStandardTypeService.lambdaQuery().eq(ChargingStandardType::getStatus,true)
                .eq(ChargingStandardType::getCompanyWechatId,currentCompanyWechat.getCurrentCompanyWechatId())
                .orderByAsc(ChargingStandardType::getSortNum)
                //.orderByDesc(ChargingStandardType::getCreateTime)
                .list();
    }

    /**
     * 收费标准/故障排查-列表
     */
    public IPage<ChargingStandardBean> list(String twoCateogryId,String brandId,String chargingStandardTypeId,Integer type, Integer pageNum, Integer pageSize){
        CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat();
        IPage<ChargingStandardBean> chargingStandardBeanIPage = commonMapper
                .queryChargingStandrdList(new Page(pageNum, pageSize),twoCateogryId,brandId,chargingStandardTypeId,
                        type,null,currentCompanyWechat.getCurrentCompanyWechatId());
        return chargingStandardBeanIPage;
    }

    /**
     *收费标准/故障排查-详情列表
     */
    public List<ChargingStandardBean> detaillist(String twoCateogryId, String brandId, String chargingStandardTypeId,
                                                 Integer type, String content1){
        List<ChargingStandardBean> chargingStandardBeanIPage = commonMapper
                .queryChargingStandrdDetailList(twoCateogryId,brandId,chargingStandardTypeId,type,content1);
        return chargingStandardBeanIPage;
    }

    /**
     * 收费标准/故障排查-详情
     */
    public ChargingStandardBean detail(String id){
        IPage<ChargingStandardBean> chargingStandardBeanIPage = commonMapper.queryChargingStandrdList(new Page(1, -1),null,null,null,null,id,null);
        return chargingStandardBeanIPage.getRecords().get(0);
    }
    /**
     * 品牌列表
     */
    public List<Brand> brandList(){
        CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat();
        return brandService.lambdaQuery()
                .eq(Brand::getStatus,true)
                .eq(Brand::getCompanyWechatId,currentCompanyWechat.getCompanyWechatId())
                .orderByAsc(Brand::getSortNum)
                .list();
    }


}
