package com.nantian.cloud.jly.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.nantian.cloud.jly.entity.EnterpriseSituation;
import com.nantian.cloud.jly.service.EnterpriseSituationService;
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.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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


/**
 * 用能单位概况
 */
@CrossOrigin
@RestController
@AllArgsConstructor
@RequestMapping("/enterpriseSituation")
@Api(value = "enterpriseSituation", tags = "用能单位概况")
public class EnterpriseSituationController {

    @Autowired
    private EnterpriseSituationService enterpriseSituationService;


    /**
     * 根据审查计划id查询
     *
     * @param checkPlanId
     * @return
     */
    @SysLog("企业基本信息-根据审查计划id查询")
    @GetMapping("/getBycheckPlanId")
    public R getBycheckPlanId(BigInteger checkPlanId,String epc) {
        QueryWrapper<EnterpriseSituation> queryWrapper = new QueryWrapper<EnterpriseSituation>();
        queryWrapper.eq("check_plan_id", checkPlanId);
        queryWrapper.eq("epc", epc);
        List<EnterpriseSituation> list = enterpriseSituationService.list(queryWrapper);
        return R.ok(list);
    }

    /**
     *用社会信用统一代码和年份查询
     * @param epc
     * @param year
     * @return
     */
    @SysLog("企业基本信息-用社会信用统一代码和年份查询")
    @ApiOperation(value = "用社会信用统一代码和年份查询", notes = "用社会信用统一代码和年份查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "epc", value = "社会信用统一代码", required = true, dataType = "json", paramType = "path"),
            @ApiImplicitParam(name = "year", value = "年份", required = true, dataType = "json", paramType = "path")
    })
    @GetMapping("/getByEpc_Year")
    public R getByepc(String epc,String year) {
        QueryWrapper<EnterpriseSituation> queryWrapper = new QueryWrapper<EnterpriseSituation>();
        queryWrapper.eq("epc", epc);
        queryWrapper.eq("year", year);
        List<EnterpriseSituation> list = enterpriseSituationService.list(queryWrapper);
        return R.ok(list);
    }


    /**
     * 保存
     *
     * @param enterpriseSituation
     * @return R
     */
    @SysLog("企业基本信息-保存")
    @ApiOperation(value = "用能单位概况", notes = "用能单位概况")
    @ApiImplicitParam(name = "enterpriseSituation", value = "用能单位概况", required = true, dataType = "json", paramType = "path")
    @PostMapping("/save")
    public R save(@RequestBody EnterpriseSituation enterpriseSituation) {
        enterpriseSituationService.deleteByPlanId(enterpriseSituation.getCheckPlanId(),enterpriseSituation.getEpc());
        return R.ok(enterpriseSituationService.save(enterpriseSituation));
    }

    /**
     * 保存或修改
     *
     * @param enterpriseSituation
     * @return R
     */
    @SysLog("企业基本信息-保存或修改")
    @ApiOperation(value = "用能单位概况", notes = "用能单位概况")
    @ApiImplicitParam(name = "enterpriseSituation", value = "用能单位概况", required = true, dataType = "json", paramType = "path")
    @PostMapping("/saveOrUpdate")
    public R saveOrUpdate(@RequestBody EnterpriseSituation enterpriseSituation) {
        enterpriseSituationService.deleteByPlanId(enterpriseSituation.getCheckPlanId(),enterpriseSituation.getEpc());
        return R.ok(enterpriseSituationService.saveOrUpdate(enterpriseSituation));
    }

}
