package com.mortals.xhx.module.alarm.web;

import com.mortals.framework.model.Context;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.common.code.AlarmPusW1ayEnum;
import com.mortals.xhx.common.code.EnabledEnum;
import com.mortals.xhx.module.alarm.model.AlarmConfigEntity;
import com.mortals.xhx.module.alarm.service.AlarmConfigService;
import com.mortals.xhx.module.product.model.ProductEntity;
import com.mortals.xhx.module.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.stream.Collectors;

/**
*
* 设备告警配置
*
* @author zxfei
* @date 2022-06-27
*/
@RestController
@RequestMapping("alarm/config")
public class AlarmConfigController extends BaseCRUDJsonBodyMappingController<AlarmConfigService,AlarmConfigEntity,Long> {

    @Autowired
    private ParamService paramService;
    @Autowired
    private ProductService productService;

    public AlarmConfigController(){
        super.setModuleDesc( "设备告警配置");
    }

    @Override
    protected void init(Map<String, Object> model, Context context) {
        this.addDict(model, "alarmType", paramService.getParamBySecondOrganize("AlarmConfig","alarmType"));
        this.addDict(model, "alarmLevel", paramService.getParamBySecondOrganize("AlarmConfig","alarmLevel"));
        this.addDict(model, "alarmPusW1ay", AlarmPusW1ayEnum.getEnumMap());
        this.addDict(model, "enabled", EnabledEnum.getEnumMap());
        this.addDict(model, "productId", productService.find(new ProductEntity()).stream().collect(Collectors.toMap(x -> x.getId().toString(), y -> y.getProductName())));

        super.init(model, context);
    }
    public static void main(String[] args) {
        String input = "example//path//to//file//with/////multiple////slashes//";

        // 将多个斜杠替换为单个斜杠
        String result = input.replaceAll("/+", "/");

        System.out.println("处理前: " + input);
        System.out.println("处理后: " + result);
    }

}