package com.usky.fire.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usky.fire.domain.PatrolInspectionPlanSiteSon;
import com.usky.fire.mapper.PatrolInspectionPlanSiteSonMapper;
import com.usky.fire.service.PatrolInspectionPlanSiteSonService;
import com.usky.common.mybatis.core.AbstractCrudService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author JCB
 * @since 2022-07-18
 */
@Service
public class PatrolInspectionPlanSiteSonServiceImpl extends AbstractCrudService<PatrolInspectionPlanSiteSonMapper, PatrolInspectionPlanSiteSon> implements PatrolInspectionPlanSiteSonService {

    @Override
    public Integer siteCount(List<Integer> planSonIdList, Integer inspectionStatus) {
        LambdaQueryWrapper<PatrolInspectionPlanSiteSon> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(PatrolInspectionPlanSiteSon::getInspectionStatus, inspectionStatus)
                .in(PatrolInspectionPlanSiteSon::getPlanId, planSonIdList);
        int count = this.count(queryWrapper);
        return count;
    }

    @Override
    public List<Integer> planSonSiteIdList(List<Integer> siteIdList){
        LambdaQueryWrapper<PatrolInspectionPlanSiteSon> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.in(PatrolInspectionPlanSiteSon::getSiteId, siteIdList)
                .groupBy(PatrolInspectionPlanSiteSon::getPlanId);
        List<PatrolInspectionPlanSiteSon> list = this.list(queryWrapper);
        List<Integer> planSonSiteIdList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            planSonSiteIdList.add(list.get(i).getPlanId());
        }
        return planSonSiteIdList;
    }
}
