package com.cool.store.dao;

import com.cool.store.entity.HyInspectionSettingDO;
import com.cool.store.mapper.HyInspectionSettingMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @author zhangchenbiao
 * @FileName: HyInspectionSettingDAO
 * @Description:
 * @date 2023-07-18 16:29
 */
@Repository
public class HyInspectionSettingDAO {

    @Resource
    private HyInspectionSettingMapper hyInspectionSettingMapper;

    /**
     * 获取分页
     * @param pageNum
     * @param pageSize
     * @return
     */
    public Page<HyInspectionSettingDO> getInspectionSettingPage(Integer pageNum, Integer pageSize){
        PageHelper.startPage(pageNum, pageSize);
        Page<HyInspectionSettingDO> resultPage = hyInspectionSettingMapper.getInspectionSettingPage();
        return resultPage;
    }

    /**
     * 获取稽查详情
     * @param inspectionSettingId
     * @return
     */
    public HyInspectionSettingDO getInspectionSettingDetail(Long inspectionSettingId){
        if(Objects.isNull(inspectionSettingId)){
            return null;
        }
        return hyInspectionSettingMapper.getInspectionSettingDetail(inspectionSettingId);
    }

    public Long addInspectionSetting(HyInspectionSettingDO param){
        hyInspectionSettingMapper.insertSelective(param);
        return param.getId();
    }

    public Integer updateInspectionSetting(HyInspectionSettingDO param){
        return hyInspectionSettingMapper.updateByPrimaryKeySelective(param);
    }

    public List<String> getInspectionUserIds(){
        return hyInspectionSettingMapper.getInspectionUserIds();
    }

    /**
     * 获取配置列表
     * @param inspectionSettingIds
     * @return
     */
    public List<HyInspectionSettingDO> getHyInspectionSettingByIds(List<Long> inspectionSettingIds){
        if(CollectionUtils.isEmpty(inspectionSettingIds)){
            return Lists.newArrayList();
        }
        return hyInspectionSettingMapper.getHyInspectionSettingByIds(inspectionSettingIds);
    }

    /**
     * 获取用户配置的区域  编辑的时候排除某个配置
     * @param inspectionUserId
     * @param excludeInspectionSettingId
     * @return
     */
    public List<HyInspectionSettingDO> getHyInspectionSettingByUserId(String inspectionUserId, Long excludeInspectionSettingId){
        if(StringUtils.isBlank(inspectionUserId)){
            return Lists.newArrayList();
        }
        return hyInspectionSettingMapper.getHyInspectionSettingByUserId(inspectionUserId, excludeInspectionSettingId);
    }

}
