package com.ruoyi.web.work.controller;

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

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.web.work.domain.NextOfKin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.work.service.INextOfKinService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 亲属关系
 * @author lsw
 * @date 2024-07-19
 */
@Api(tags = "亲属关系管理")
@RestController
@RequestMapping("/work/nk")
public class NextOfKinController extends BaseController {
    @Autowired
    private INextOfKinService nkService;

    @ApiOperation(value = "获取亲属信息列表")
    @PreAuthorize("@ss.hasPermi('work:nk:list')")
    @GetMapping("/list")
    public TableDataInfo list(NextOfKin nk){
        startPage();
        List<NextOfKin> list = nkService.selectList(nk);
        return getDataTable(list);
    }

    @ApiOperation(value = "根据id查询亲属信息")
    @PreAuthorize("@ss.hasPermi('work:nk:query')")
    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Long id){
        return AjaxResult.success(nkService.getById(id));
    }

    @ApiOperation(value = "添加亲属信息")
    @PreAuthorize("@ss.hasPermi('work:nk:add')")
    @Log(title = "亲属关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody NextOfKin nk){
        return toAjax(nkService.save(nk));
    }

    @ApiOperation(value = "修改亲属信息")
    @PreAuthorize("@ss.hasPermi('work:nk:edit')")
    @Log(title = "亲属关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody NextOfKin nk){
        return toAjax(nkService.updateById(nk));
    }

    @ApiOperation(value = "删除亲属信息")
    @PreAuthorize("@ss.hasPermi('work:nk:remove')")
    @Log(title = "亲属关系", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(nkService.removeByIds(Arrays.asList(ids)));
    }
}
