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

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.elephant.framework.galaxy.aroad.module.emergencyevent.entity.Evendeal;
import com.elephant.framework.galaxy.aroad.module.emergencyevent.mapper.EvendealMapper;
import com.elephant.framework.galaxy.aroad.module.emergencyevent.service.EmergencyEventService;
import com.elephant.framework.galaxy.aroad.module.emergencyevent.service.EvendealService;
import com.elephant.framework.galaxy.aroad.module.system.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 事件处置表
 *
 * @author songwenjie
 * @date 2019-05-08 14:43:56
 */
@Service
public class EvendealServiceImpl extends ServiceImpl<EvendealMapper, Evendeal> implements EvendealService {
    @Autowired
    private DeptService deptService;

    @Autowired
    private EmergencyEventService emergencyEventService;

    /** 
    * @Description: 新增事件处理信息
    * @param: [eventdeal]
    * @return: boolean 
    * @Author: songwenjie
    * @Date: 2019/5/15 
    */ 
    @Transactional
    public boolean saveEventDeal(Evendeal eventdeal){
        int reportingDeptId = eventdeal.getDeptId();
        String dept = deptService.getDeptName(reportingDeptId);
        eventdeal.setDept(dept);

        int dealType = eventdeal.getDealType();
        if(dealType == 0){
            emergencyEventService.updateStatus(eventdeal.getEventId(),"已下达","未处理");
        }
        if(dealType == 1){
            emergencyEventService.updateStatus(eventdeal.getEventId(),"已反馈","已下达");
        }

        return save(eventdeal);
    }
}
