package com.yuchen.saas.park.service.service.security.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuchen.saas.park.api.dto.security.EmergencyPlanQueryDto;
import com.yuchen.saas.park.api.entity.security.EmergencyPlan;
import com.yuchen.saas.park.service.mapper.security.EmergencyPlanMapper;
import com.yuchen.saas.park.service.service.security.IEmergencyPlanService;
import org.nest.springwrap.core.mp.base.BaseServiceImpl;
import org.nest.springwrap.core.tool.constant.NestConstant;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 应急预案表 服务实现类
 * </p>
 *
 * @author 洪铭铭
 * @since 2024-07-05
 */
@Service
public class EmergencyPlanServiceImpl extends BaseServiceImpl<EmergencyPlanMapper, EmergencyPlan> implements IEmergencyPlanService {

    public List<EmergencyPlan> getAll() {

        LambdaQueryWrapper<EmergencyPlan> qw = new LambdaQueryWrapper<>();
        List<EmergencyPlan> emergencyPlanList = baseMapper.selectList(qw);

        return emergencyPlanList;
    }
    /**
     * @description:
     * @param req
     * @return: com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<com.yuchen.saas.park.api.entity.security.EmergencyPlan>
     * @author: 洪铭铭
     * @time: 2024/7/12 15:11
     */
    private LambdaQueryWrapper<EmergencyPlan> getPageQueryParam(EmergencyPlanQueryDto req) {
        LambdaQueryWrapper<EmergencyPlan> qw = new LambdaQueryWrapper<>();
        if (Func.isNotEmpty(req.getParkId())) {
            qw.eq(EmergencyPlan::getParkId, req.getParkId());
        }
        if (Func.isNotEmpty(req.getPlanNum())) {
            qw.eq(EmergencyPlan::getPlanNum, req.getPlanNum());
        }
        if (Func.isNotEmpty(req.getPlanName())) {
            qw.eq(EmergencyPlan::getPlanName, req.getPlanName());
        }
        if (Func.isNotEmpty(req.getPlanTime())) {
            qw.eq(EmergencyPlan::getPlanTime, req.getPlanTime());
        }
        if (Func.isNotEmpty(req.getStatus())) {
            qw.eq(EmergencyPlan::getStatus, req.getStatus());
        }
        qw.eq(EmergencyPlan::getIsDeleted, NestConstant.DB_NOT_DELETED);
        return qw;
    }

    /**
     * @description:
     * @param req
     * @return: com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.yuchen.saas.park.api.entity.security.EmergencyPlan>
     * @author: 洪铭铭
     * @time: 2024/7/12 15:05
     */
    public Page<EmergencyPlan> page(EmergencyPlanQueryDto req) {
        Page<EmergencyPlan> page = new Page<>(req.getCurrent(), req.getSize());
        baseMapper.selectPage(page, this.getPageQueryParam(req));
        return page;
    }


}
