package com.bonus.face.controller;

import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import com.bonus.common.security.annotation.RequiresPermissions;
import com.bonus.face.domain.FaceGroupsEntity;
import com.bonus.face.service.FaceGroupsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Controller
 *
 * @author bonus
 * @date 2024-12-06
 */
@RestController
@RequestMapping("/groups")
public class FaceGroupsController extends BaseController {
    @Resource
    private FaceGroupsService faceGroupsService;

    /**
     * 查询列表
     */
    @RequiresPermissions("face:groups:list")
    @GetMapping("/list")
    public TableDataInfo list(FaceGroupsEntity faceGroups) {
        try {
            startPage();
            List<FaceGroupsEntity> list = faceGroupsService.selectFaceGroupsList(faceGroups);
            return getDataTable(list);
        } catch (Exception e) {
            return getDataTable(new ArrayList<>());
        }

    }

    /**
     * 获取详细信息
     */
    @RequiresPermissions("face:groups:query")
    @GetMapping(value = "/{groupId}")
    public AjaxResult getInfo(@PathVariable("groupId") Long groupId) {
        return faceGroupsService.selectFaceGroupsByGroupId(groupId);
    }

    /**
     * 新增
     */
    @RequiresPermissions("face:groups:add")
    @PostMapping("/add")
    @SysLog(title = "", businessType = OperaType.INSERT, logType = 0, module = "", details = "导出列表")
    public AjaxResult add(@RequestBody FaceGroupsEntity faceGroups) {
        return faceGroupsService.insertFaceGroups(faceGroups);
    }

    /**
     * 修改
     */
    @RequiresPermissions("face:groups:edit")
    @PostMapping("/edit")
    @SysLog(title = "", businessType = OperaType.UPDATE, logType = 0, module = "", details = "导出列表")
    public AjaxResult edit(@RequestBody FaceGroupsEntity faceGroups) {
        return faceGroupsService.updateFaceGroups(faceGroups);
    }

    /**
     * 删除
     */
    @RequiresPermissions("face:groups:remove")
    @PostMapping("/delete/{groupIds}")
    @SysLog(title = "", businessType = OperaType.DELETE, logType = 0, module = "", details = "导出列表")
    public AjaxResult remove(@PathVariable Long[] groupIds) {
        return faceGroupsService.deleteFaceGroupsByGroupIds(groupIds);
    }
}
