/*
 * Author: wangjian
 * 生成ServiceImpl
 */
package com.tofly.dispatch.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tofly.dispatch.common.FlowConstant;
import com.tofly.dispatch.entity.EmergencyFacilities;
import com.tofly.dispatch.entity.EmergencyHazard;
import com.tofly.dispatch.mapper.EmergencyHazardMapper;
import com.tofly.dispatch.service.EmergencyHazardService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Set;

/**
 * 事故危险源
 *
 * @author xqf
 * @date Mon Apr 25 00:00:00 CST 2022
 */
@Service("emergencyHazardService")
public class EmergencyHazardServiceImpl extends ServiceImpl<EmergencyHazardMapper, EmergencyHazard> implements EmergencyHazardService {



    public void insert(EmergencyHazard dto) {
        setDefaultValue(dto);
        if (!this.save(dto)){
            throw new RuntimeException("新增失败");
        }
    }

    @Override
    public void batchInsert(List<EmergencyHazard> dtos) {
        for (EmergencyHazard dto : dtos) {
            insert(dto);
        }
    }



    @Override
    public void deleteEmergencyId(Set<Long> emergencyIds) {
        if (CollectionUtils.isEmpty(emergencyIds)){
            throw new RuntimeException("传入数据为空");
        }
        //删除中间表
        QueryWrapper<EmergencyHazard> queryWrapperR = new QueryWrapper<>();
        queryWrapperR.in("EMERGENCY_ID",emergencyIds);
        this.baseMapper.delete(queryWrapperR);
    }




    /**
     * 设置查询条件
     * @param query 查询参数
     * @return QueryWrapper
     */






    /**
     * 设置默认值
     * @param dto 实体
     */
    private void setDefaultValue(EmergencyHazard dto) {

        dto.setIsValid(FlowConstant.SHORT_ONE);
        dto.setHazardState(FlowConstant.SHORT_TWO);
    }
}
