package com.mortals.xhx.module.device.service.impl;

import com.mortals.framework.model.PageInfo;
import com.mortals.xhx.common.code.DeviceTypeEnum;
import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.xhx.module.device.dao.DeviceAlarmDao;
import com.mortals.xhx.module.device.model.DeviceAlarmEntity;
import com.mortals.xhx.module.device.service.DeviceAlarmService;

import java.util.List;

/**
 * DeviceAlarmService
 * 设备告警日志 service实现
 *
 * @author zxfei
 * @date 2022-08-04
 */
@Service("deviceAlarmService")
public class DeviceAlarmServiceImpl extends AbstractCRUDServiceImpl<DeviceAlarmDao, DeviceAlarmEntity, Long> implements DeviceAlarmService {

    @Autowired
    private DeviceService deviceService;

    @Override
    protected void findAfter(DeviceAlarmEntity params, PageInfo pageInfo, Context context, List<DeviceAlarmEntity> list) throws AppException {
        list.forEach(item -> {
            DeviceEntity deviceEntity = deviceService.get(item.getDeviceId());
            item.setSiteName(deviceEntity.getSiteName());
            item.setSiteNum(deviceEntity.getSiteNum());
            item.setDeviceType(DeviceTypeEnum.getByValue(deviceEntity.getDeviceType()).getDesc());
        });

        super.findAfter(params, pageInfo, context, list);
    }
}