package com.nantian.cloud.jly.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.nantian.cloud.jly.entity.CheckAudit;
import com.nantian.cloud.jly.entity.CheckVerdict;
import com.nantian.cloud.jly.service.CheckVerdictService;
import com.nantian.sc.cloud.common.core.util.R;
import com.nantian.sc.cloud.common.log.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.util.List;


/**
 * 审批意见表
 */
@CrossOrigin
@RestController
@AllArgsConstructor
@RequestMapping("/checkVerdict")
@Api(value = "checkVerdict", tags = "审批意见表")
public class CheckVerdictController {
    private final CheckVerdictService checkVerdictService;
    /**
     * 根据审查计划id查询
     * @param checkPlanId
     * @return
     */
    @SysLog("审批意见表-查询")
    @GetMapping("/getBycheckPlanId")
    public R getBycheckPlanId(BigInteger checkPlanId,String epc) {
        QueryWrapper<CheckVerdict> queryWrapper = new QueryWrapper<CheckVerdict>();
        queryWrapper.eq("check_plan_id",checkPlanId);
        queryWrapper.eq("epc",epc);
        List<CheckVerdict> list = checkVerdictService.list(queryWrapper);
        return R.ok(list);
    }

    /**
     * 保存
     *
     * @param checkVerdict
     * @return R
     */
    @SysLog("审批意见表-保存")
    @ApiOperation(value = "保存审批意见表", notes = "保存审批意见表")
    @ApiImplicitParam(name = "checkVerdict", value = "保存审批意见表", required = true, dataType = "json", paramType = "path")
    @PostMapping("/save")
    public R save(@RequestBody CheckVerdict checkVerdict) {
//        if (checkVerdict.getId() != null) {
////            checkVerdictService.deleteByCheckPlanId(checkVerdict.getCheckPlanId());
//        }
        return R.ok(checkVerdictService.saveOrUpdate(checkVerdict));
    }


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

}
