package com.nantian.cloud.jly.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nantian.cloud.jly.entity.CheckAudit;
import com.nantian.cloud.jly.entity.CheckLevelDegreeReport;
import com.nantian.cloud.jly.service.CheckAuditService;
import com.nantian.sc.cloud.common.core.util.R;
import com.nantian.sc.cloud.common.log.annotation.SysLog;
import com.nantian.sc.cloud.common.security.annotation.Inner;
import com.nantian.sc.cloud.common.security.service.ScUser;
import com.nantian.sc.cloud.common.security.util.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.runtime.regexp.joni.Warnings;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.util.Date;


/**
 * 审批意见表
 */
@CrossOrigin
@RestController
@AllArgsConstructor
@RequestMapping("/checkAudit")
@Api(value = "checkAudit", tags = "审批意见表")
public class CheckAuditController {
    private final CheckAuditService checkAuditService;

    /**
     * 分页查询
     */
    @SysLog("查询审批意见表")
    @ApiOperation(value = "查询审批意见表", notes = "条件查询审批意见表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "CheckPersons", value = "审批意见表对象", required = false, dataType = "json", paramType = "path"),
            @ApiImplicitParam(name = "Page", value = "分页对象", required = false, dataType = "json", paramType = "path")
    })
    @GetMapping("/page")
    public R getCheckAuditPage(Page page, CheckAudit checkAudit) {
        checkAudit.setDelFlag("1"); //查询未删除数据
        return R.ok(checkAuditService.page(page, Wrappers.query(checkAudit)));
    }

    /**
     * 根据审查计划id查询
     * @param checkPlanId
     * @return
     */
    @SysLog("根据审查计划id查询")
    @GetMapping("/getBycheckPlanId")
    public R getBycheckPlanId(BigInteger checkPlanId) {
        QueryWrapper<CheckAudit> queryWrapper = new QueryWrapper<CheckAudit>();
        queryWrapper.lambda().eq(CheckAudit::getCheckPlanId,checkPlanId);
        return R.ok(queryWrapper);
    }

    /**
     * 保存
     *
     * @param checkAudit
     * @return R
     */
    @SysLog("保存审批意见表")
    @ApiOperation(value = "保存审批意见表", notes = "保存审批意见表")
    @ApiImplicitParam(name = "checkAudit", value = "保存审批意见表", required = true, dataType = "json", paramType = "path")
    @PostMapping("/save")
    public R save(@RequestBody CheckAudit checkAudit) {
        if (checkAudit.getId() != null) {
            checkAuditService.removeById(checkAudit.getId());
        }
        return R.ok(checkAuditService.save(checkAudit));
    }


    /**
     * 信息
     *
     * @param checkAuditId
     * @return R
     */
    @SysLog("通过ID查询审批意见表")
    @ApiOperation(value = "通过ID查询审批意见表", notes = "通过ID条件查询审批意见表")
    @ApiImplicitParam(name = "CheckAuditId", value = "审批意见表id", required = true, dataType = "int", paramType = "path")
    @GetMapping("/{checkAuditId}")
    public R getById(@PathVariable("checkAuditId") Integer checkAuditId) {
        return R.ok(checkAuditService.getById(checkAuditId));
    }


    /**
     * 查找审批结果
     */
    @SysLog("查找审批结果")
    @GetMapping("/auditInfo")
    @ApiOperation(value = "查找审批结果", notes = "查找审批结果")
/*    @ApiImplicitParams({
            @ApiImplicitParam(name = "epc", value = "社会信用代码", required = true, dataType = "string", paramType = "path"),
            @ApiImplicitParam(name = "planId", value = "计划id", required = true, dataType = "int", paramType = "path"),
            @ApiImplicitParam(name = "type", value = "第n项资料序号", required = false, dataType = "type", paramType = "path")
    })*/
    public R getByPecAnd(CheckAudit checkAudit) {
        checkAudit.setDelFlag("1"); //查询未删除数据
        return R.ok(checkAuditService.getMap(Wrappers.query(checkAudit)));
    }

}
