package com.gyee.runeconomy.service.auto.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gyee.common.model.StringUtils;
import com.gyee.runeconomy.mapper.auto.ProBasicCompanyMapper;
import com.gyee.runeconomy.model.auto.ProBasicCompany;
import com.gyee.runeconomy.service.auto.IProBasicCompanyService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 省公司表 服务实现类
 * </p>
 *
 * @author wang
 * @since 2022-11-22
 */
@Service
public class ProBasicCompanyServiceImpl extends ServiceImpl<ProBasicCompanyMapper, ProBasicCompany> implements IProBasicCompanyService {

    @Override
    public Double getProBasicCompanyCapacity(String regionId, String companyId) {


        QueryWrapper<ProBasicCompany> qw = new QueryWrapper<>();

        //判断后缀是区域还是公司
        if (StringUtils.isNotEmpty(companyId) && companyId.endsWith("_ZGS")) {
            qw.lambda().eq(ProBasicCompany::getId, companyId);
        }
        if (StringUtils.isNotEmpty(companyId) && companyId.endsWith("_RGN")) {
            qw.lambda().eq(ProBasicCompany::getRegionId, companyId);
        }


        //        BigDecimal sumall = new BigDecimal("0.0000");

        Double sumall = new Double(0.00);
        List<ProBasicCompany> list = getBaseMapper().selectList(qw);
        for (ProBasicCompany i : list) {
            sumall = sumall + i.getJrwindCapacity() + i.getJrCapacity();
        }

        return sumall;
    }

    @Override
    public Integer getProBasicCompanyQuantity(String regionId, String companyId) {
        QueryWrapper<ProBasicCompany> qw = new QueryWrapper<>();

        //判断后缀是区域还是公司
        if (StringUtils.isNotEmpty(companyId) && companyId.endsWith("_ZGS")) {
            qw.lambda().eq(ProBasicCompany::getId, companyId);
        }
        if (StringUtils.isNotEmpty(companyId) && companyId.endsWith("_RGN")) {
            qw.lambda().eq(ProBasicCompany::getRegionId, companyId);
        }


        Integer quantity = new Integer(0);
        List<ProBasicCompany> list = getBaseMapper().selectList(qw);
        for (ProBasicCompany i : list) {
            quantity = quantity + i.getJrquantityJz() + i.getJrquantityZc() + i.getJrwindQuantityHs() + i.getJrwindQuantityLd();
        }

        return quantity;
    }
}
