package com.muyu.server.controller;

import javax.annotation.Resource;

import com.muyu.common.domain.WarnStrategy;
import com.muyu.common.domain.req.WarnStrategyReq;
import com.muyu.server.service.WarnStrategyService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.domain.Result;

/**
 * 预警策略Controller
 *
 * @author sx
 * @date 2024-09-20
 */
@RestController
@RequestMapping("/strategy")
public class WarnStrategyController extends BaseController
{
    @Resource
    private WarnStrategyService warnStrategyService;

    /**
     * 查询预警策略列表
     */
    @PostMapping("/selectWarnStrategyList")
    public Result selectWarnStrategyList(@RequestBody WarnStrategyReq warnStrategyReq)
    {
      return Result.success(warnStrategyService.selectWarnStrategyList(warnStrategyReq));
    }


    /**
     * 获取预警策略详细信息
     */
    @GetMapping( "selectById/{id}")
    public Result selectById(@PathVariable("id") Long id)
    {
        return success(warnStrategyService.selectWarnStrategyById(id));
    }

    /**
     * 新增预警策略
     */
    @PostMapping("/addWarnStrategy")
    public Result addWarnStrategy(@RequestBody WarnStrategy warnStrategy)
    {
        Integer i = warnStrategyService.addWarnStrategy(warnStrategy);
        return i>0?Result.success():Result.error();
    }

    /**
     * 修改预警策略
     */
    @PostMapping("/updWarnStrategy")
    public Result updWarnStrategy(@RequestBody WarnStrategy warnStrategy)
    {
        Integer i = warnStrategyService.updWarnStrategy(warnStrategy);
        return i>0?Result.success():Result.error();
    }

    /**
     * 删除预警策略
     */
	@DeleteMapping("deleteWarnStrategy/{id}")
    public Result deleteWarnStrategy(@PathVariable("id") Long id)
    {
        Integer i = warnStrategyService.deleteWarnStrategy(id);
        return i>0?Result.success():Result.error();
    }



    /**
     * 根据车辆类型ID查询策略
     */
    @GetMapping("/selectListByCarType/{carTypeId}")
    public Result selectListByCarType(@PathVariable("carTypeId") Long carTypeId) {
        return Result.success(warnStrategyService.selectListByCarType(carTypeId));
    }
}
