package com.dcsoft.system.face.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.dcsoft.system.face.domain.FaceRule;
import com.dcsoft.system.face.service.IFaceRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
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.dcsoft.common.log.annotation.Log;
import com.dcsoft.common.log.enums.BusinessType;
import com.dcsoft.common.core.web.controller.BaseController;
import com.dcsoft.common.core.web.domain.AjaxResult;
import com.dcsoft.common.core.utils.poi.ExcelUtil;
import com.dcsoft.common.core.web.page.TableDataInfo;

/**
 * ruleController
 *
 * @author nichun
 * @date 2023-04-19
 */
@RestController
@RequestMapping("/faceRule")
public class FaceRuleController extends BaseController
{
    @Autowired
    private IFaceRuleService faceRuleService;

    /**
     * 查询rule列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FaceRule faceRule)
    {
        startPage();
        List<FaceRule> list = faceRuleService.selectFaceRuleList(faceRule);
        return getDataTable(list);
    }

    /**
     * 导出rule列表
     */
    @Log(title = "rule", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FaceRule faceRule)
    {
        List<FaceRule> list = faceRuleService.selectFaceRuleList(faceRule);
        ExcelUtil<FaceRule> util = new ExcelUtil<FaceRule>(FaceRule.class);
        util.exportExcel(response, list, "rule数据");
    }

    /**
     * 获取rule详细信息
     */
    @GetMapping(value = "/{ftrx}")
    public AjaxResult getInfo(@PathVariable("ftrx") String ftrx)
    {
        return success(faceRuleService.selectFaceRuleByFtrx(ftrx));
    }

    /**
     * 新增rule
     */
    @Log(title = "rule", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FaceRule faceRule)
    {
        faceRuleService.deleteFaceRuleByFtrx();
        return toAjax(faceRuleService.insertFaceRule(faceRule));
    }

    /**
     * 修改rule
     */
    @Log(title = "rule", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FaceRule faceRule)
    {
        return toAjax(faceRuleService.updateFaceRule(faceRule));
    }

    /**
     * 删除rule
     */
    @Log(title = "rule", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ftrxs}")
    public AjaxResult remove(@PathVariable String[] ftrxs)
    {
        return toAjax(faceRuleService.deleteFaceRuleByFtrxs(ftrxs));
    }
}
