package com.chushang.inspection.work.controller;

import com.chushang.common.core.web.AjaxResult;
import com.chushang.common.log.annotation.SysLog;
import com.chushang.common.log.enums.BusinessType;
import com.chushang.inspection.project.dto.AuditDTO;
import com.chushang.inspection.work.query.WrkAuditRuleQuery;
import com.chushang.inspection.work.service.WrkAuditRuleService;
import com.chushang.inspection.work.service.WrkInfoService;
import com.chushang.inspection.work.vo.WrkAuditRuleDTO;
import com.chushang.security.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;

/**
* 工单审核表(wrk_info_audit)表控制层
* 工单审核相关接口
* @author xxxxx
*/
@RestController
@RequestMapping("/wrk/rule")
public class WrkAuditRuleController {

    @Resource
    private WrkAuditRuleService wrkAuditRuleService;


    /**
     * 工单审核
     */
    @GetMapping ("/page")
    @RequiresPermissions("wrk:aduit:page")
    @SysLog(value = "审核规则列表", businessType = BusinessType.AUDIT)
    public AjaxResult page(@Validated WrkAuditRuleQuery query) {
        return AjaxResult.success(wrkAuditRuleService.queryRulePage(query));
    }


    /**
     * 新增和修改
     */
    @PostMapping ("/saveOrUpdate")
    @RequiresPermissions("wrk:aduit:su")
    @SysLog(value = "审核规则新增和修改", businessType = BusinessType.AUDIT)
    public AjaxResult saveOrUpdate(@Validated @RequestBody WrkAuditRuleDTO dto) {
        return AjaxResult.success(wrkAuditRuleService.saveOrUpdate(dto));
    }


    /**
     * 审核规则
     */
    @RequiresPermissions("wrk:aduit:remove")
    @SysLog(value = "审核规则删除", businessType = BusinessType.DELETE)
    @DeleteMapping("del/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        wrkAuditRuleService.removeBatchByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }
}
