package com.cmvr.web.controller.system;

import com.cmvr.common.annotation.Log;
import com.cmvr.common.core.controller.BaseController;
import com.cmvr.common.core.domain.AjaxResult;
import com.cmvr.common.core.domain.entity.SysGroup;
import com.cmvr.common.core.page.TableDataInfo;
import com.cmvr.common.enums.BusinessType;
import com.cmvr.system.service.ISysGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "通用--分组配置")
@RestController
@RequestMapping("/system/group")
@RequiredArgsConstructor
public class SysGroupController extends BaseController {
    private final ISysGroupService sysGroupService;

    @ApiOperation("查询通用分组配置列表")
    @PreAuthorize("@ss.hasPermi('system:group:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysGroup sysGroup) {
        startPage();
        List<SysGroup> list = sysGroupService.selectSysGroupList(sysGroup);
        return getDataTable(list);
    }

    @ApiOperation("获取通用分组配置详细信息")
    @PreAuthorize("@ss.hasPermi('system:group:query')")
    @GetMapping(value = "/{groupId}")
    public AjaxResult getInfo(@PathVariable("groupId") Long groupId) {
        return success(sysGroupService.selectSysGroupByGroupId(groupId));
    }

    @ApiOperation("新增通用分组配置")
    @PreAuthorize("@ss.hasPermi('system:group:add')")
    @Log(title = "通用分组配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysGroup sysGroup) {
        return toAjax(sysGroupService.insertSysGroup(sysGroup));
    }

    @ApiOperation("修改通用分组配置")
    @PreAuthorize("@ss.hasPermi('system:group:edit')")
    @Log(title = "通用分组配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysGroup sysGroup) {
        return toAjax(sysGroupService.updateSysGroup(sysGroup));
    }

    @ApiOperation("删除通用分组配置")
    @PreAuthorize("@ss.hasPermi('system:group:remove')")
    @Log(title = "通用分组配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{groupIds}")
    public AjaxResult remove(@PathVariable Long[] groupIds) {
        return toAjax(sysGroupService.deleteSysGroupByGroupIds(groupIds));
    }
}
