package com.muyu.openbusiness.controller;

import com.muyu.openbusiness.domain.SysCorpuscle;
import com.muyu.openbusiness.service.ISysCorpuscleService;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 电子围栏Controller
 *
 * @author muyu
 * @date 2024-09-17
 */
@RestController
@RequestMapping("/carRail")
public class SysCorpuscleController extends BaseController
{
    @Autowired
    private ISysCorpuscleService sysCorpuscleService;

    /**
     * 查询电子围栏列表
     */
    @RequiresPermissions("carRail:carRail:list")
    @GetMapping("/list")
    public Result<TableDataInfo<SysCorpuscle>> list(SysCorpuscle sysCorpuscle)
    {
        startPage();
        List<SysCorpuscle> list = sysCorpuscleService.selectSysCorpuscleList(sysCorpuscle);
        return getDataTable(list);
    }

    @RequiresPermissions("carRail:corpuscle:add")
    @PostMapping
    public Result<Integer> add(
            @Validated @RequestBody SysCorpuscle sysCorpuscle)
    {

        return toAjax(sysCorpuscleService.save(sysCorpuscle));
    }

    /**
     * 修改电子围栏
     */
    @RequiresPermissions("carRail:corpuscle:edit")
    @PutMapping
    public Result<Integer> edit(
            @Validated @RequestBody SysCorpuscle sysCorpuscle)
    {

        return toAjax(sysCorpuscleService.updateById(sysCorpuscle));
    }



    /**
     * 删除电子围栏
     */
    @RequiresPermissions("carRail:corpuscle:remove")
    @DeleteMapping("/{ids}")
    public Result<Integer> remove(@PathVariable("ids") Long[] ids)
    {
        sysCorpuscleService.removeBatchByIds(Arrays.asList(ids));
        return success();
    }

}
