package com.nantian.cloud.dbcapp.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nantian.cloud.dbcapp.entity.EnterpriseInfo;
import com.nantian.cloud.dbcapp.service.EnterpriseInfoService;
import com.nantian.cloud.dbcapp.vo.ReportNumVo;
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.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@AllArgsConstructor
@RequestMapping("/enterpriseInfos")
public class EnterpriseInfoController {
  private final EnterpriseInfoService enterpriseInfoService;
    @PutMapping("/updateEnterpriseInfo")
    @SysLog("修改企业屏蔽企业指标")
    @ApiOperation(value = "修改企业屏蔽企业指标", notes = "修改企业屏蔽企业指标")
    @ApiImplicitParam(name = "EnterpriseInfo", value = "企业对象", required = true, dataType = "json", paramType = "path")
    public R updateById(@RequestBody EnterpriseInfo enterpriseInfo) {
        EnterpriseInfo info=new EnterpriseInfo();
        info.setQuotaShield(enterpriseInfo.getQuotaShield());
        info.setEnterpriseCode(enterpriseInfo.getEnterpriseCode());
        boolean flag= enterpriseInfoService.updateByEpc(info);
        return flag ? R.ok("修改企业屏蔽企业指标成功") : R.failed("修改企业屏蔽企业指标失败");
    }

     @GetMapping("/getShieldList")
     @SysLog("获取企业屏蔽企业指标")
    @ApiOperation(value = "获取企业屏蔽企业指标", notes = "获取企业屏蔽企业指标")
    @ApiImplicitParam(name = "enterpriseCode", value = "企业信用编码", required = true, dataType = "string", paramType = "path")
    public R getShieldList(String enterpriseCode){
        if (enterpriseCode == null) {
            return R.failed("企业信用编码为空，查询失败！");
        }
        return R.ok(enterpriseInfoService.getShieldList(enterpriseCode));
    }


    /**
     * 在线监测企业状态管理 查询接口
     * @return
     */
    @GetMapping("/page")
    @SysLog("在线监测企业状态管理 查询接口")
    public R getEnterpriseList(Page page, ReportNumVo reportNumVo){
        IPage<EnterpriseInfo> pageData = enterpriseInfoService.getPageList(page, reportNumVo);
        return R.ok(pageData);
    }

    /**
     * 在线监测企业状态管理 企业状态修改接口
     */
    @PostMapping("/updateById")
    @SysLog("在线监测企业状态管理 企业状态修改接口")
    public R uploadById(@RequestBody ReportNumVo reportNumVo){
        JSONObject obj = new JSONObject();
        obj.put("subordinateList", reportNumVo.getSubordinateList());
        obj.put("dataQualityCoding", reportNumVo.getDataQualityCoding());
        obj.put("accomplish",reportNumVo.getAccomplish());
        obj.put("finishTime", reportNumVo.getFinishTime());
        obj.put("updateTime", reportNumVo.getUpdateTime());
        EnterpriseInfo enterpriseInfo = enterpriseInfoService.getOne(new QueryWrapper<EnterpriseInfo>().eq("cmpName", reportNumVo.getCmpName()).eq("enterpriseCode", reportNumVo.getEnterpriseCode()));
        enterpriseInfo.setReportNum(obj.toJSONString());
        enterpriseInfoService.updateById(enterpriseInfo);
        return R.ok();
    }
}
