package com.muyu.enterpise.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.domain.req.CarFenceAdd;

import com.muyu.enterpise.service.CarFenceServiceMybaits;
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.*;

import java.util.List;

/**
 * 中间表添加
 *  * @Author：yan
 *  * @Package：com.muyu.car.controller
 *  * @Project：plues
 *  * @name：MiddleController
 *  * @Date：2024/9/22 10:06
 */
@RequestMapping("/middle")
@RestController
@AllArgsConstructor
@Tag(name = "中间表添加",description = "添加")
@Log4j2
public class MiddleController {
    @Autowired
    private CarFenceServiceMybaits carFenceServiceMybaits;

    /**
     * 添加围栏组 多对多
     */
    @PostMapping("/addCarFence")
    @Operation(summary = "添加中间围栏和围栏组",description = "添加中间")
    public Result addCarFence(@RequestParam("fenceGroupId") Integer fenceGroupId, @RequestBody List<CarFenceAdd> carFences){
        boolean i  = carFenceServiceMybaits.saveBatch(carFences,fenceGroupId);
        return i?Result.success("添加成功"):Result.error("失败");
    }



    /**
     * 根据围栏组的id查询绑定的围栏的中间表
     */
    @GetMapping("/BoundFenceGroup")
    @Operation(summary = "根据围栏组的id查询绑定的围栏的中间表",description = "根据围栏组的id查询绑定的围栏的中间表")
    public Result BoundFenceGroup(@RequestParam("groupId") Integer groupId){
        carFenceServiceMybaits.BoundFenceGroup(groupId);
        return Result.success();
    }



    /**
     * 获取绑定的围栏组
     */
    @GetMapping("/selectBoundGFenceGroup")
    @Operation(summary = "获取绑定的围栏组",description = "根据围栏组和车辆的id添加中间表")
    public Result selectBoundGFenceGroup(@RequestParam("carId") Integer carId){

        return Result.success(carFenceServiceMybaits.selectBoundGFenceGroup(carId));
    }


}
