package com.nantian.cloud.dbcapp.controller;


import com.nantian.cloud.dbcapp.service.EnergyCalculateService;
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 lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@CrossOrigin
@RestController
@AllArgsConstructor
@RequestMapping("/Calculate")
@Api(value = "Calculate", tags = "计算")
public class EnergyCalculate {
    @Autowired
    EnergyCalculateService energyCalculateService;


    /**
     * @Author ronghong wu
     * @Descript 判断当前取到的openid是否已经存到数据库
     * @param openId
     * @return
     */
    @GetMapping("/isHasOpenId")
    @SysLog("判断当前取到的openid是否已经存到数据库")
    @ApiOperation(value =  "openId",notes = "openId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "openId", value="openId",required = false, dataType = "string", paramType = "path" )
    })
    public R isHasOpenId(String openId) {
        return R.ok(energyCalculateService.isHasOpenId(openId),"查询成功");
    }//isHasOpenId

    /**
     * @Author ronghong wu
     * @Descript 保存当前取到的openid到数据库
     * @param openId
     * @param userId
     * @return
     */
    @GetMapping("/saveOpenId")
    @SysLog("保存当前取到的openid到数据库")
    @ApiOperation(value =  "openId",notes = "openId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "openId", value="openId",required = false, dataType = "string", paramType = "path" ),
            @ApiImplicitParam(name = "userid", value="userid",required = false, dataType = "string", paramType = "path" )
    })
    public  R saveOpenId(String openId,String userId){
        return R.ok(energyCalculateService.saveOpenId(openId,userId),"查询成功");
    }//saveOpenId end

    /**
     * @Author ronghong wu
     * @Descript 根据openID获取用户信息
     * @param openId
     * @return
     */
    @GetMapping("/getUserInfo")
    @SysLog("根据openID获取用户信息")
    @ApiOperation(value =  "getUserInfo",notes = "getUserInfo")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "openId", value="openId",required = false, dataType = "string", paramType = "path" )
    })
    public  R getUserInfo(String openId){
        return R.ok(energyCalculateService.getUserInfo(openId),"查询成功");
    }//getUserInfo end

    @RequestMapping ("/getEnergyCalculateInfo")
    @SysLog("修改是否参与计算标志")
    @ApiOperation(value = "修改是否参与计算标志", notes = "修改是否参与计算标志")
    public R updateDateCodeState(String enterpriseCode,String dataCode,Integer state) {
        return energyCalculateService.updateDateCodeState(enterpriseCode,dataCode,state);
    }

}
