package com.muyu.enterprise.controller;

import com.muyu.enterprise.service.IFencegroupService;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.domain.FenceGroup;
import com.muyu.domain.req.FenceGroupAddReq;
import com.muyu.domain.req.FenceGroupReq;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 围栏组Controller
 *
 * @author muyu
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/fencegroup")
@Log4j2
public class FencegroupController extends BaseController{

    @Autowired
    private IFencegroupService fencegroupService;


    /**
     * 单个删除
     */
    @DeleteMapping("/{id}")
    @Operation(description = "根据id删除")
    public Result<Integer> delete(@PathVariable("id") Integer id) {
        fencegroupService.removeById(id);
        return Result.success(null,"操作成功");
    }

    /**
     * 修改
     */
    @PutMapping("/{id}")
    @Operation(description = "根据id修改围栏组信息")
    public Result<String> updateGroup(
            @Validated @RequestBody FenceGroup group,
            @Schema(title = "ID",defaultValue = "1",type = "Long",description = "修改信息的唯一条件")
            @PathVariable Long id) {
        fencegroupService.updateById(group);
        return Result.success(null,"操作成功");
    }

    /**
     * 围栏组信息展示(多对多)
     */
    @PostMapping(path = "/showList")
    @Operation(description = "围栏组信息展示")
    public Result<List<FenceGroup>> showList(@RequestBody @Validated FenceGroupReq req) {
        List<FenceGroup> fenceGroups = fencegroupService.showGroupList(req);
        System.out.println(fenceGroups);
        return Result.success(fenceGroups);
    }

    /**
     * 添加围栏组
     */
    @PostMapping("/add")
    @Operation(description = "添加围栏组信息")
    public Result<Integer> addGroup(@Validated @RequestBody FenceGroupAddReq addReq) {
        fencegroupService.addGroup(addReq);
        //打印日志
        log.info(addReq);
        return Result.success(null,"操作成功");
    }

    /**
     * 批删
     */
    @DeleteMapping("/delMore")
    @Operation(description = "根据id进行批量删除")
    public Result delMore(@RequestBody List<Long> fenceGroupIds) {
//        fencegroupService.delMore(fenceGroupIds);
        fencegroupService.removeBatchByIds(fenceGroupIds);
        return Result.success(null,"操作成功");
    }

}
