//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.huimv.acquisition.socket.eartagrecive.service.impl;

import com.huimv.acquisition.socket.eartagrecive.service.IClientDataPacketService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;

@Service
public class ClientDataPacketServiceImpl implements IClientDataPacketService {
    private static final Logger log = LoggerFactory.getLogger(ClientDataPacketServiceImpl.class);
    @Autowired
    private ReceivePackageSerivce receivePackageSerivce;
    @Autowired
    private SendPackageService sendPackageService;

    public ClientDataPacketServiceImpl() {
    }

    public String handleClientSendPacket(String clientMessageTxt) throws ParseException {

        if (clientMessageTxt != null && !clientMessageTxt.isEmpty()) {
            String matcher = "[+]";
            String[] clientMessageArray = clientMessageTxt.split(matcher);
            String cmd = clientMessageArray[2];
            //比较head
            String codHead = clientMessageArray[0];
            log.info("本次执行命令>>" + cmd);
            System.out.println(clientMessageTxt);

            if (codHead.equals("zj")) {
                return this.receivePackageSerivce.handleEartagData(clientMessageArray ,clientMessageTxt);
            } else if (Integer.parseInt(cmd) == 0) {
                System.out.println("绑定设备使用厂家的IP和端口");
                return this.sendPackageService.getDeviceIp(clientMessageArray);
            } else if (Integer.parseInt(cmd) == 1) {
                System.out.println("绑定序列号返回的设备id");
                return this.sendPackageService.getDeviceId(clientMessageArray);
            } else if (Integer.parseInt(cmd) == 2) {
                System.out.println("处理获取服务器时间");
                return this.sendPackageService.getServerDateTime(clientMessageArray);
            } else if (Integer.parseInt(cmd) == 3) {
                System.out.println("心跳");
                return this.sendPackageService.getHeartbeatBag(clientMessageArray);
            } else if (Integer.parseInt(cmd) == 4) {
                System.out.println("环境温度");
                return this.receivePackageSerivce.handleEartagTemperature(clientMessageArray);
            } else if (Integer.parseInt(cmd) == 5) {
                return this.receivePackageSerivce.handleEartagDampness(clientMessageArray);
            } else {
                log.error("出错：当前命令cmd>>[" + cmd + "]未做任何处理.");
                return "null";
            }
        } else {
            log.error("本地提交数据包为空.");
            return "null";
        }
    }
}
