package com.muyu.enterpise.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.domain.FenceGroup;
import com.muyu.domain.req.FenceGroupUpdateReq;

import com.muyu.enterpise.service.CarFenceUpdateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 围栏组的修改状态
 * @Author：yan
 * @Package：com.muyu.controller
 * @Project：plues
 * @name：CarFenceUpdateController
 * @Date：2024/9/30 09:10
 *
 */
@RestController
@RequestMapping("/fenceUpdate")
@AllArgsConstructor
@Log4j2
@Tag(name = "修改围栏组的状态")
public class CarFenceUpdateController {
    @Autowired
    private CarFenceUpdateService carFenceUpdateService;

    /**
     * 启动围栏组
     */
    @PutMapping("/activate")
    @Operation(summary = "启动围栏状态",description = "启动围栏状态")
    public Result activate(@RequestBody FenceGroupUpdateReq fenceGroupUpdateReq){
        Integer states = 0;
        boolean b = carFenceUpdateService.updateById(FenceGroup.carFenceUpdateById(states, fenceGroupUpdateReq));
        return Result.success("成功");
    }

    /**
     * 修改围栏状态为关闭
     * @param groupId
     * @return
     */
    @GetMapping("/updateFenceGroupById")
    @Operation(summary = "修改围栏状态为关闭",description = "修改围栏状态为关闭")
    public Result updateFenceGroupById(@RequestParam("groupId") Long groupId){
        Integer states = 1;
        carFenceUpdateService.updateById(FenceGroup.closeCarFenceUpdateById(states,groupId));

        return Result.success("成功");
    }

}
