package com.mortals.xhx.module.device.web;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.OrderCol;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.common.code.AlarmLevelEnum;
import com.mortals.xhx.common.code.AlarmTypeEnum;
import com.mortals.xhx.common.code.DeviceTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.mortals.framework.model.Context;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mortals.framework.web.BaseCRUDJsonMappingController;
import com.mortals.xhx.module.device.model.DeviceAlarmEntity;
import com.mortals.xhx.module.device.model.DeviceAlarmQuery;
import com.mortals.xhx.module.device.service.DeviceAlarmService;
import org.apache.commons.lang3.ArrayUtils;
import com.mortals.framework.util.StringUtils;

import java.util.*;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import static com.mortals.framework.ap.SysConstains.*;
/**
 *
 * 设备告警日志
 *
 * @author zxfei
 * @date 2022-08-04
 */
@RestController
@RequestMapping("device/alarm")
public class DeviceAlarmController extends BaseCRUDJsonMappingController<DeviceAlarmService,DeviceAlarmForm,DeviceAlarmEntity,Long> {

    @Autowired
    private ParamService paramService;

    public DeviceAlarmController(){
        super.setFormClass(DeviceAlarmForm.class);
        super.setModuleDesc( "设备告警日志");
    }


    @Override
    protected void doListBefore(HttpServletRequest request, HttpServletResponse response, DeviceAlarmForm form, Map<String, Object> model, Context context) throws AppException {

        List<OrderCol> orderColList = new ArrayList<>();
        orderColList.add(new OrderCol("createTime", OrderCol.DESCENDING));
        form.getQuery().setOrderColList(orderColList);
        super.doListBefore(request, response, form, model, context);
    }

    @Override
    protected void init(HttpServletRequest request, HttpServletResponse response, DeviceAlarmForm form, Map<String, Object> model, Context context) {
        this.addDict(model, "alarmType", AlarmTypeEnum.getEnumMap());
        this.addDict(model, "alarmLevel", AlarmLevelEnum.getEnumMap());
        this.addDict(model, "deviceType", DeviceTypeEnum.getEnumMap());
        super.init(request, response, form, model, context);
    }

}