package com.example.bpa.app;


import com.example.bpa.config.ConfigName;
import com.example.bpa.db.mode.BPA_USER;
import com.example.bpa.helper.ConfigUtil;
import com.example.bpa.helper.T;

/**
 * 主函数进程
 * 主要进行配置文件-系统类
 */
public class Main {
    //region 私有
    private static Main mInstance; //实例变量设置私有，防止直接通过类名访问

    public static synchronized Main getInstance() { //静态同步方法作为唯一的实例对象获取方式
        if (mInstance == null) {
            mInstance = new Main();
        }
        return mInstance;
    }

    private Main() { //默认构造函数私有，防止类外直接new创建对象
        Init();
    }
    //endregion

    //region 外部调用事件

    /**
     * 初始化
     */
    public void Init() {
        //1.加载配置
        LoadingPZ();
        //2.初始化PLC
        PLC.getInstance().InitMobus();
        //3.初始化业务
        //4.初始化日志上报
    }


    /**
     * 加载配置
     */
    public void LoadingPZ() {
        //1.店铺配置
        ConfigName.getInstance().Shop_Name = ConfigUtil.read(ConfigName.getInstance().dishesCon, "Shop_Name", ConfigName.getInstance().Shop_Name);
        ConfigName.getInstance().AutKey = ConfigUtil.read(ConfigName.getInstance().dishesCon, "AutKey", ConfigName.getInstance().AutKey);
        //2.用户名称
        ConfigName.getInstance().user.account = ConfigUtil.read(ConfigName.getInstance().dishesCon, "username", ConfigName.getInstance().user.account);
        ConfigName.getInstance().user.pass = ConfigUtil.read(ConfigName.getInstance().dishesCon, "password", ConfigName.getInstance().user.pass);
    }

    /**
     * 保存配置
     */
    public void SavePZ()
    {
        //1.店铺配置
        ConfigUtil.write(ConfigName.getInstance().dishesCon,"Shop_Name", ConfigName.getInstance().Shop_Name);
        ConfigUtil.write(ConfigName.getInstance().dishesCon,"AutKey", ConfigName.getInstance().AutKey);
        //2.用户信息
        ConfigUtil.write(ConfigName.getInstance().dishesCon,"username", ConfigName.getInstance().user.account);
        ConfigUtil.write(ConfigName.getInstance().dishesCon,"password", ConfigName.getInstance().user.pass);
    }
    //endregion
}
