package com.nantian.cloud.jly.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nantian.cloud.jly.entity.CheckBasis;
import com.nantian.cloud.jly.entity.MeasureDisparity;
import com.nantian.cloud.jly.service.CheckBasisService;
import com.nantian.cloud.jly.service.MeasureDisparityService;
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("/measureDisparity")
@Api(value = "measureDisparity", tags = "审批意见表")
public class MeasureDisparityController {
    private final MeasureDisparityService measureDisparityService;
    /**
     * 根据审查计划id查询
     * @param checkPlanId
     * @return
     */
    @SysLog("审批意见表-根据审查计划id查询")
    @GetMapping("/getBycheckPlanId")
    public R getBycheckPlanId(BigInteger checkPlanId,String epc) {
        QueryWrapper<MeasureDisparity> queryWrapper = new QueryWrapper<MeasureDisparity>();
        queryWrapper.eq("check_plan_id",checkPlanId);
        queryWrapper.eq("epc",epc);
        List<MeasureDisparity> list = measureDisparityService.list(queryWrapper);
        return R.ok(list);
    }

    /**
     * 保存
     *
     * @param measureDisparity
     * @return R
     */
    @SysLog("审批意见表-保存")
    @ApiOperation(value = "用能单位概况", notes = "用能单位概况")
    @ApiImplicitParam(name = "measureDisparity", value = "用能单位概况", required = true, dataType = "json", paramType = "path")
    @PostMapping("/save")
    public R save(@RequestBody MeasureDisparity measureDisparity) {
        measureDisparityService.deleteByPlanId(measureDisparity.getCheckPlanId(),measureDisparity.getEpc());
        return R.ok(measureDisparityService.save(measureDisparity));
    }

}
