package com.nantian.cloud.dbcapp.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nantian.cloud.dbcapp.entity.TEnterpriseQuota;
import com.nantian.cloud.dbcapp.service.TEnterpriseQuotaService;
import com.nantian.sc.cloud.common.core.util.R;
import com.nantian.sc.cloud.common.log.annotation.SysLog;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@AllArgsConstructor
@RequestMapping("/enterpriseQuota")
public class TEnterpriseQuotaController {
    private final TEnterpriseQuotaService tEnterpriseQuotaService;

    @GetMapping("/getQuotaList")
    @SysLog("根据条件获取企业指标")
    @ApiOperation(value = "根据条件获取企业指标", notes = "根据条件获取企业指标")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "enterpriseCode", value = "信用代码", required = true, dataType = "string", paramType = "path"),
    })
    public R getQuotaList(Page page, String enterpriseCode) {
        return R.ok(tEnterpriseQuotaService.getQuotaList(page,enterpriseCode),"查询成功");
    }

    @PostMapping("/addOrUpdateQuota")
    @SysLog("新增/修改企业指标")
	@ApiOperation(value = "新增/修改企业指标", notes = "新增/修改企业指标")
	@ApiImplicitParam(name = "tConfig", value = "配置表对象", required = true, dataType = "json", paramType = "path")
	public R save(@RequestBody TEnterpriseQuota tEnterpriseQuota) {
		TEnterpriseQuota obj = new TEnterpriseQuota();
		TEnterpriseQuota t = tEnterpriseQuotaService.getById(tEnterpriseQuota.getId());
		if(t!=null){
            obj.setId(t.getId());
		}
		obj.setEnterpriseCode(tEnterpriseQuota.getEnterpriseCode());
		obj.setProductCode(tEnterpriseQuota.getProductCode());
		obj.setQuotaCode(tEnterpriseQuota.getQuotaCode());
		obj.setQuotaName(tEnterpriseQuota.getQuotaName());
		return R.ok(tEnterpriseQuotaService.saveOrUpdate(obj));
	}

	@PostMapping("/delQuota")
    @SysLog("根据id删除企业指标")
    @ApiOperation(value = "根据id删除企业指标", notes = "根据id企业指标")
    @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "String", paramType = "path")
    public R removeById(@RequestBody TEnterpriseQuota tEnterpriseQuota) {
        Integer id=tEnterpriseQuota.getId();
        return R.ok(tEnterpriseQuotaService.removeById(id));
    }
}
