package com.ho.user.controller;

import com.ho.common.tools.annotation.LogAnnotation;
import com.ho.common.tools.constant.ContextConstant;
import com.ho.common.tools.exception.DataResult;
import com.ho.user.api.entity.PermStationRelation;
import com.ho.user.service.PermStationRelationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author gyan
 * @desc: 电站关联菜单
 * @DateTime: 2023/6/14 9:04
 */
@RequestMapping(ContextConstant.SYS + "/station/permission")
@RestController
@Api(tags = "系统管理-电站和菜单关联接口")
public class StationPermissionController {
    @Autowired
    private PermStationRelationService permStationRelationService;

/*    @PostMapping("page")
    @ApiOperation(value = "分页获取角色信息接口")
    //@LogAnnotation(title = "角色管理",action = "分页获取角色信息")
    //@RequiresPermissions("sys:role:list")
    public DataResult<PageVO<StationPermissionRespVo>> pageInfo(@RequestBody StationPermissionReqVo vo) {
        DataResult<PageVO<StationPermissionRespVo>> result = DataResult.success();
        result.setData(permStationRelationService.pageInfo(vo));
        return result;
    }*/


    @GetMapping("{id}")
    @ApiOperation(value = "查询角色详情接口")
    public DataResult<PermStationRelation> detailInfo(@PathVariable("id") Integer id) {
        DataResult<PermStationRelation> result = DataResult.success();
        //返回结果只有当前电站所关联的菜单数据
        result.setData(permStationRelationService.detailInfo(id));
        return result;
    }

    @PostMapping("add")
    @ApiOperation(value = "新增电站关联菜单接口")
    @LogAnnotation(title = "电站菜单管理", action = "新增关联关系")
    public DataResult add(@RequestBody @Valid PermStationRelation  vo) {
        //入参电站id和菜单idList
        permStationRelationService.insertSelective(vo);
        return DataResult.success();
    }

    @PutMapping("update")
    @ApiOperation(value = "更新电站菜单信息接口")
    @LogAnnotation(title = "电站菜单管理", action = "更新电站菜单信息接口")
    public DataResult update(@RequestBody @Valid PermStationRelation  vo) {
        //入参电站id和菜单idList
        //先删除后进行插入
        permStationRelationService.update(vo);
        return DataResult.success();
    }

    @PostMapping("delete")
    @ApiOperation(value = "删除电站关联菜单信息接口")
    public DataResult delete(@RequestBody @Valid PermStationRelation vo) {
        //根据电站id进行删除
        permStationRelationService.deleteBatch(vo.getPermissions());
        return DataResult.success();
    }
}
