package com.fdkankan.platform.feign;

import com.fdkankan.common.user.SSOUser;
import com.fdkankan.platform.goods.entity.Camera;
import com.fdkankan.platform.goods.entity.CameraDetail;
import com.fdkankan.platform.goods.entity.Company;
import com.fdkankan.platform.goods.service.ICameraDetailService;
import com.fdkankan.platform.goods.service.ICameraService;
import com.fdkankan.platform.goods.service.ICompanyService;
import com.fdkankan.platform.user.service.IUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 提供场景调用
 */
@RestController
@RequestMapping("/feign")
public class SceneFeign {

    private static Logger log = LoggerFactory.getLogger("programLog");

    @Autowired
    private ICameraService cameraService;
    @Autowired
    private ICameraDetailService cameraDetailService;
    @Autowired
    private IUserService userService;
    @Autowired
    private ICompanyService companyService;

    @PostMapping("/getCameraByChildName")
    public Camera getCameraByChildName(@RequestParam(value = "childName", required = false) String childName) {
        log.info("scene服务调用:getCameraByChildName,参数：childName:{},",childName);
        Camera camera = cameraService.getByChildName(childName);
        log.info("scene服务调用:getCameraByChildName,返回:{}",camera);
        return camera;
    }

    @PostMapping("/getCameraDetailByCameraId")
    public CameraDetail getCameraDetailByCameraId(@RequestParam(value = "cameraId", required = false) Long cameraId) {
        log.info("scene服务调用:getCameraDetailByCameraId,参数：cameraId:{},",cameraId);
        CameraDetail detail = cameraDetailService.getByCameraId(cameraId);
        log.info("scene服务调用:getCameraDetailByCameraId,返回:{}",detail);
        return detail;
    }

    @PostMapping("/updateCameraDetailByCameraIdAndSpace")
    public CameraDetail updateCameraDetailByCameraIdAndSpace(@RequestParam(value = "cameraId", required = false) Long cameraId,
                                                             @RequestParam(value = "space", required = false) Long space) {
        log.info("scene服务调用:updateCameraDetailByCameraIdAndSpace,参数：cameraId:{},space:{},",cameraId,space);
        CameraDetail detail = cameraDetailService.updateCameraDetailByCameraIdAndSpace(cameraId,space);
        log.info("scene服务调用:updateCameraDetailByCameraIdAndSpace,返回:{}",detail);
        return detail;
    }

    @PostMapping("/getCameraBySnCode")
    public Camera getCameraBySnCode(@RequestParam(value = "snCode", required = false) String snCode) {
        log.info("scene服务调用:getCameraBySnCode,参数：snCode:{},",snCode);
        Camera detail = cameraService.getBySnCode(snCode);
        log.info("scene服务调用:getCameraBySnCode,返回:{}",detail);
        return detail;
    }
    @PostMapping("/getSSOUserByUserId")
    public SSOUser getSSOUserByUserId(@RequestParam(value = "userId", required = false) Long userId) {
        log.info("scene服务调用:getSSOUserByUserId,参数：userId:{},",userId);
        SSOUser ssoUser =  userService.getSSOUserByUserId(userId);
        log.info("scene服务调用:getSSOUserByUserId,返回:{}",ssoUser);
        return ssoUser;
    }
    @PostMapping("/getCompanyById")
    public Company getCompanyById(@RequestParam(value = "companyId", required = false) Long companyId) {
        log.info("scene服务调用: getCompanyById,参数：companyId:{},",companyId);
        Company entity = companyService.getById(companyId);
        log.info("scene服务调用: getCompanyById,返回:{}",entity);
        return entity;
    }

}
