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.FaceDataEntity;
import com.bonus.face.service.FaceDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * Controller
 *
 * @author bonus
 * @date 2024-12-06
 */
@RestController
@RequestMapping("/data")
public class FaceDataController extends BaseController {
    @Autowired
    private FaceDataService faceDataService;

    /**
     * 查询列表
     */
    @RequiresPermissions("face:data:list")
    @GetMapping("/list")
    public TableDataInfo list(FaceDataEntity faceData) {
        try {
            startPage();
            List<FaceDataEntity> list = faceDataService.selectFaceDataList(faceData);
            return getDataTable(list);
        } catch (Exception e) {
            return getDataTable(new ArrayList<>());
        }

    }

    /**
     * 获取详细信息
     */
    @RequiresPermissions("face:data:query")
    @GetMapping(value = "/{faceId}")
    public AjaxResult getInfo(@PathVariable("faceId") Long faceId) {
        return faceDataService.selectFaceDataByFaceId(faceId);
    }

    /**
     * 新增
     */
    @RequiresPermissions("face:data:add")
    @PostMapping("/add")
    @SysLog(title = "", businessType = OperaType.INSERT, logType = 0, module = "", details = "导出列表")
    public AjaxResult add(FaceDataEntity faceData) {
        return faceDataService.insertFaceData(faceData);
    }

    /**
     * 修改
     */
    @RequiresPermissions("face:data:edit")
    @PostMapping("/edit")
    @SysLog(title = "", businessType = OperaType.UPDATE, logType = 0, module = "", details = "导出列表")
    public AjaxResult edit(FaceDataEntity faceData) {
        return faceDataService.updateFaceData(faceData);
    }

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