package com.mortals.xhx.busiz.web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.ILogService;
import com.mortals.framework.service.impl.FileLogServiceImpl;
import com.mortals.xhx.base.system.message.impl.MessageProducer;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.busiz.req.TestReq;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.busiz.rsp.DeviceResp;
import com.mortals.xhx.common.code.ApiRespCodeEnum;
import com.mortals.xhx.common.utils.SendTaskThreadPool;
import com.mortals.xhx.feign.site.ISiteFeign;
import com.mortals.xhx.module.device.service.DeviceLogService;
import com.mortals.xhx.module.device.service.DeviceService;
import com.mortals.xhx.module.firm.service.FirmService;
import com.mortals.xhx.module.platform.service.PlatformService;
import com.mortals.xhx.module.product.service.ProductService;
import com.mortals.xhx.module.product.service.ProductVersionService;
import com.mortals.xhx.module.site.service.SiteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 设备
 *
 * @author: zxfei
 * @date: 2021/8/24 20:28
 */
@RestController
@Slf4j
@RequestMapping("/test")
public class TestSendMsgController {
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private ProductService productService;
    @Autowired
    private UserService userService;
    @Autowired
    private ProductVersionService productVersionService;
    @Autowired
    private PlatformService platformService;
    @Value("${spring..rabbitmq.virtual_host:}")
    private String virtualHost;
    @Value("${spring..rabbitmq.password:}")
    private String password;
    @Value("${spring..rabbitmq.host:}")
    private String host;
    @Value("${spring..rabbitmq.port:0}")
    private int port;
    @Value("${spring..rabbitmq.username:}")
    private String username;
    @Value("${spring..rabbitmq.queue-properties.x-message-ttl:86400000}")
    private String messageTtl;
    @Value("${token.secret}")
    private String secret;
    @Autowired
    private SendTaskThreadPool sendTaskThreadPool;
    @Autowired
    private ISiteFeign siteFeign;
    @Value("${platform.type:cloud}")
    private String platFormType;//版本，默认云服务版本
    @Autowired
    private SiteService siteService;
    @Autowired
    private FirmService firmService;
    @Autowired
    private DeviceLogService deviceLogService;
    @Autowired
    private ICacheService cacheService;
    @Autowired
    private MessageProducer messageProducer;

    @Autowired
    protected ILogService logService = FileLogServiceImpl.getInstance();

    /**
     * 发送日志消息
     *
     * @param req
     * @return
     */
    @PostMapping("log")
    public String register(@RequestBody TestReq req) {
        log.info("【测试消息】【请求体】-->  " + JSONObject.toJSONString(req));
        ApiResp<DeviceResp> rsp = new ApiResp<>();
        rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue());


        log.info("响应【设备注册】【响应体】-->  " + JSONObject.toJSONString(rsp));
        return JSON.toJSONString(rsp);
    }



}
