package com.elephant.framework.galaxy.aroad.module.emergencyplan.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.elephant.framework.galaxy.aroad.module.emergencyplan.dto.EmergencyPlanDto;
import com.elephant.framework.galaxy.aroad.module.emergencyplan.entity.EmergencyPlan;
import com.elephant.framework.galaxy.aroad.module.emergencyplan.mapper.EmergencyPlanMapper;
import com.elephant.framework.galaxy.aroad.module.emergencyplan.service.EmergencyPlanService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 应急预案表
 *
 * @author songwenjie
 * @date 2019-04-25 09:47:42
 */
@Service
public class EmergencyPlanServiceImpl extends ServiceImpl<EmergencyPlanMapper, EmergencyPlan> implements EmergencyPlanService {

    /** 
    * @Description: 新增应急预案
    * @Param: [plan] 
    * @return: boolean 
    * @Author: songwenjie 
    * @Date: 2019/4/25 
    */ 
    public boolean save(EmergencyPlanDto plan){
        EmergencyPlan emergencyPlan = EmergencyPlan.builder()
                .planName(plan.getPlanName())
                .planType(plan.getPlanType())
                .planLevel(plan.getPlanLevel())
                .planDocName(plan.getPlanDoc().get(0).getName())
                .planDocUrl(plan.getPlanDoc().get(0).getUrl())
                .planKeyword(plan.getPlanKeyword())
                .publishDept(plan.getPublishDept())
                .publishTime(plan.getPublishTime())
                .publisher(plan.getPublisher())
                .publisherId(plan.getPublisherId())
                .build();
        return save(emergencyPlan);
    }

    /** 
    * @Description:  更新应急预案
    * @Param: [plan] 
    * @return: boolean 
    * @Author: songwenjie 
    * @Date: 2019/4/25 
    */ 
    public boolean updateById(EmergencyPlanDto plan){
        EmergencyPlan emergencyPlan = EmergencyPlan.builder()
                .planId(plan.getPlanId())
                .planName(plan.getPlanName())
                .planType(plan.getPlanType())
                .planLevel(plan.getPlanLevel())
                .planDocName(plan.getPlanDoc().get(0).getName())
                .planDocUrl(plan.getPlanDoc().get(0).getUrl())
                .planKeyword(plan.getPlanKeyword())
                .publishDept(plan.getPublishDept())
                .publishTime(plan.getPublishTime())
                .publisher(plan.getPublisher())
                .publisherId(plan.getPublisherId())
                .build();
        return updateById(emergencyPlan);
    }

    /**
     * @Description: 分页获取应急预案信息
     * @Param: [page, planKeyword]
     * @return: com.baomidou.mybatisplus.core.metadata.IPage<com.elephant.framework.galaxy.aroad.module.emergencyplan.dto.EmergencyPlanDto>
     * @Author: songwenjie
     * @Date: 2019/4/25
     */
    public IPage<EmergencyPlanDto> getPlanPage(Page page, EmergencyPlan emergencyPlan){
        return baseMapper.getPlanPage(page,emergencyPlan);
    }
}
