package com.hdl.photovoltaic.other; 
 | 
  
 | 
import android.text.TextUtils; 
 | 
  
 | 
import com.google.gson.Gson; 
 | 
import com.google.gson.JsonObject; 
 | 
import com.google.gson.reflect.TypeToken; 
 | 
import com.hdl.linkpm.sdk.core.exception.HDLException; 
 | 
import com.hdl.photovoltaic.HDLApp; 
 | 
import com.hdl.photovoltaic.R; 
 | 
import com.hdl.photovoltaic.bean.PageNumberObject; 
 | 
import com.hdl.photovoltaic.internet.HttpClient; 
 | 
import com.hdl.photovoltaic.internet.api.HttpApi; 
 | 
import com.hdl.photovoltaic.listener.CloudCallBeak; 
 | 
import com.hdl.photovoltaic.ui.bean.CloudInverterDeviceBean; 
 | 
import com.hdl.photovoltaic.ui.bean.DeviceRemoteInfo; 
 | 
import com.hdl.photovoltaic.ui.bean.MemberBean; 
 | 
import com.hdl.photovoltaic.ui.bean.StaffBean; 
 | 
import com.hdl.photovoltaic.ui.bean.UserRightTypeBean; 
 | 
import com.hdl.photovoltaic.utils.AesUtils; 
 | 
import com.hdl.photovoltaic.utils.Md5Utils; 
 | 
  
 | 
import java.io.File; 
 | 
import java.io.FileOutputStream; 
 | 
import java.io.InputStream; 
 | 
import java.lang.reflect.Type; 
 | 
import java.util.ArrayList; 
 | 
import java.util.List; 
 | 
import java.util.concurrent.atomic.AtomicInteger; 
 | 
  
 | 
import okhttp3.ResponseBody; 
 | 
  
 | 
/** 
 | 
 * 成员逻辑 
 | 
 */ 
 | 
public class HdlMemberLogic { 
 | 
    private static volatile HdlMemberLogic sHdlMemberLogic; 
 | 
  
 | 
    /** 
 | 
     * 获取当前对象 
 | 
     * 
 | 
     * @return HdlAccountLogic 
 | 
     */ 
 | 
    public static synchronized HdlMemberLogic getInstance() { 
 | 
        if (sHdlMemberLogic == null) { 
 | 
            synchronized (HdlMemberLogic.class) { 
 | 
                if (sHdlMemberLogic == null) { 
 | 
                    sHdlMemberLogic = new HdlMemberLogic(); 
 | 
                } 
 | 
            } 
 | 
  
 | 
        } 
 | 
        return sHdlMemberLogic; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 获取当前账号在公司的身份 
 | 
     * 
 | 
     * @param cloudCallBeak - 
 | 
     */ 
 | 
    public void getUserRightType(CloudCallBeak<UserRightTypeBean> cloudCallBeak) { 
 | 
        String requestUrl = HttpApi.B_POST_GET_USERRIGHTTYPE; 
 | 
        JsonObject json = new JsonObject(); 
 | 
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { 
 | 
            @Override 
 | 
            public void onSuccess(String jsonStr) { 
 | 
                if (TextUtils.isEmpty(jsonStr)) { 
 | 
                    if (cloudCallBeak != null) { 
 | 
                        cloudCallBeak.onSuccess(new UserRightTypeBean()); 
 | 
                    } 
 | 
                } 
 | 
                Gson gson = new Gson(); 
 | 
  
 | 
                UserRightTypeBean userRightTypeBean = gson.fromJson(jsonStr, UserRightTypeBean.class); 
 | 
                if (cloudCallBeak != null) { 
 | 
                    cloudCallBeak.onSuccess(userRightTypeBean); 
 | 
                } 
 | 
            } 
 | 
  
 | 
            @Override 
 | 
            public void onFailure(HDLException e) { 
 | 
                if (cloudCallBeak != null) { 
 | 
                    cloudCallBeak.onFailure(e); 
 | 
                } 
 | 
            } 
 | 
        }); 
 | 
  
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 获取员工列表(B端) 
 | 
     * 
 | 
     * @param pageNo        页码 
 | 
     * @param pageSize      页数(一页多少数据) 
 | 
     * @param cloudCallBeak - 
 | 
     */ 
 | 
    public void getStaffList(long pageNo, long pageSize, CloudCallBeak<PageNumberObject<StaffBean>> cloudCallBeak) { 
 | 
        String requestUrl = HttpApi.B_POST_GET_LISTBYPAGE; 
 | 
        JsonObject json = new JsonObject(); 
 | 
        json.addProperty("pageNo", pageNo); 
 | 
        json.addProperty("pageSize", pageSize); 
 | 
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { 
 | 
            @Override 
 | 
            public void onSuccess(String jsonStr) { 
 | 
                if (TextUtils.isEmpty(jsonStr)) { 
 | 
                    if (cloudCallBeak != null) { 
 | 
                        cloudCallBeak.onSuccess(new PageNumberObject<>()); 
 | 
                    } 
 | 
                } 
 | 
                Gson gson = new Gson(); 
 | 
                Type type = new TypeToken<PageNumberObject<StaffBean>>() { 
 | 
                }.getType(); 
 | 
                PageNumberObject<StaffBean> pageNumberObject = gson.fromJson(jsonStr, type); 
 | 
                if (cloudCallBeak != null) { 
 | 
                    cloudCallBeak.onSuccess(pageNumberObject); 
 | 
                } 
 | 
            } 
 | 
  
 | 
            @Override 
 | 
            public void onFailure(HDLException e) { 
 | 
                if (cloudCallBeak != null) { 
 | 
                    cloudCallBeak.onFailure(e); 
 | 
                } 
 | 
            } 
 | 
        }); 
 | 
  
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 获取员工详情(B端) 
 | 
     * 
 | 
     * @param userId        - 
 | 
     * @param cloudCallBeak - 
 | 
     */ 
 | 
    public void getStaffInfo(String userId, CloudCallBeak<StaffBean> cloudCallBeak) { 
 | 
        String requestUrl = HttpApi.B_POST_GET_MANAGE_INFO; 
 | 
        JsonObject json = new JsonObject(); 
 | 
        json.addProperty("userId", userId); 
 | 
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { 
 | 
            @Override 
 | 
            public void onSuccess(String jsonStr) { 
 | 
                if (TextUtils.isEmpty(jsonStr)) { 
 | 
                    if (cloudCallBeak != null) { 
 | 
                        cloudCallBeak.onSuccess(new StaffBean()); 
 | 
                    } 
 | 
                } 
 | 
                Gson gson = new Gson(); 
 | 
  
 | 
                StaffBean staffBean = gson.fromJson(jsonStr, StaffBean.class); 
 | 
                if (cloudCallBeak != null) { 
 | 
                    cloudCallBeak.onSuccess(staffBean); 
 | 
                } 
 | 
            } 
 | 
  
 | 
            @Override 
 | 
            public void onFailure(HDLException e) { 
 | 
                if (cloudCallBeak != null) { 
 | 
                    cloudCallBeak.onFailure(e); 
 | 
                } 
 | 
            } 
 | 
        }); 
 | 
  
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 员工添加(B端) 
 | 
     * 
 | 
     * @param staffBean     员工对象 
 | 
     * @param cloudCallBeak - 
 | 
     */ 
 | 
    public void getStaffAdd(StaffBean staffBean, CloudCallBeak<Boolean> cloudCallBeak) { 
 | 
        String requestUrl = HttpApi.B_POST_GET_MANAGE_CREATE; 
 | 
        JsonObject json = new JsonObject(); 
 | 
        if (!TextUtils.isEmpty(staffBean.getUserName())) { 
 | 
            json.addProperty("userName", staffBean.getUserName()); 
 | 
        } 
 | 
        if (staffBean.getUserSex() != 0) { 
 | 
            json.addProperty("userSex", staffBean.getUserSex()); 
 | 
        } 
 | 
        if (!TextUtils.isEmpty(staffBean.getUserPhone())) { 
 | 
            json.addProperty("userPhone", staffBean.getUserPhone()); 
 | 
        } 
 | 
        if (!TextUtils.isEmpty(staffBean.getUserEmail())) { 
 | 
            json.addProperty("userEmail", staffBean.getUserEmail()); 
 | 
        } 
 | 
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { 
 | 
            @Override 
 | 
            public void onSuccess(String jsonStr) { 
 | 
                if (cloudCallBeak != null) { 
 | 
                    cloudCallBeak.onSuccess(true); 
 | 
                } 
 | 
            } 
 | 
  
 | 
            @Override 
 | 
            public void onFailure(HDLException e) { 
 | 
                if (cloudCallBeak != null) { 
 | 
                    cloudCallBeak.onFailure(e); 
 | 
                } 
 | 
            } 
 | 
        }); 
 | 
  
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 员工编辑(B端) 
 | 
     * 
 | 
     * @param staffBean     员工对象 
 | 
     * @param cloudCallBeak - 
 | 
     */ 
 | 
    public void getStaffEdit(StaffBean staffBean, CloudCallBeak<Boolean> cloudCallBeak) { 
 | 
        String requestUrl = HttpApi.B_POST_GET_MANAGE_EDIT; 
 | 
        JsonObject json = new JsonObject(); 
 | 
        if (!TextUtils.isEmpty(staffBean.getUserId())) { 
 | 
            json.addProperty("userId", staffBean.getUserId()); 
 | 
        } 
 | 
        if (!TextUtils.isEmpty(staffBean.getUserName())) { 
 | 
            json.addProperty("userName", staffBean.getUserName()); 
 | 
        } 
 | 
        if (staffBean.getUserSex() != 0) { 
 | 
            json.addProperty("userSex", staffBean.getUserSex()); 
 | 
        } 
 | 
        if (!TextUtils.isEmpty(staffBean.getUserPhone())) { 
 | 
            json.addProperty("userPhone", staffBean.getUserPhone()); 
 | 
        } 
 | 
        if (!TextUtils.isEmpty(staffBean.getUserEmail())) { 
 | 
            json.addProperty("userEmail", staffBean.getUserEmail()); 
 | 
        } 
 | 
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { 
 | 
            @Override 
 | 
            public void onSuccess(String jsonStr) { 
 | 
                if (cloudCallBeak != null) { 
 | 
                    cloudCallBeak.onSuccess(true); 
 | 
                } 
 | 
            } 
 | 
  
 | 
            @Override 
 | 
            public void onFailure(HDLException e) { 
 | 
                if (cloudCallBeak != null) { 
 | 
                    cloudCallBeak.onFailure(e); 
 | 
                } 
 | 
            } 
 | 
        }); 
 | 
  
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 员工删除(B端) 
 | 
     * 
 | 
     * @param staffBean     员工对象 
 | 
     * @param cloudCallBeak - 
 | 
     */ 
 | 
    public void getStaffDelete(StaffBean staffBean, CloudCallBeak<Boolean> cloudCallBeak) { 
 | 
        String requestUrl = HttpApi.B_POST_GET_MANAGE_DELETE; 
 | 
        JsonObject json = new JsonObject(); 
 | 
        json.addProperty("userId", staffBean.getUserId()); 
 | 
  
 | 
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { 
 | 
            @Override 
 | 
            public void onSuccess(String jsonStr) { 
 | 
                if (cloudCallBeak != null) { 
 | 
                    cloudCallBeak.onSuccess(true); 
 | 
                } 
 | 
            } 
 | 
  
 | 
            @Override 
 | 
            public void onFailure(HDLException e) { 
 | 
                if (cloudCallBeak != null) { 
 | 
                    cloudCallBeak.onFailure(e); 
 | 
                } 
 | 
            } 
 | 
        }); 
 | 
  
 | 
    } 
 | 
  
 | 
  
 | 
    /** 
 | 
     * 获取成员列表(C端) 
 | 
     * 
 | 
     * @param memberBean    成员对象 
 | 
     * @param cloudCallBeak - 
 | 
     */ 
 | 
    public void getMemberList(MemberBean memberBean, CloudCallBeak<List<MemberBean>> cloudCallBeak) { 
 | 
        String requestUrl = HttpApi.C_POST_MEMBER_LIST; 
 | 
        JsonObject json = new JsonObject(); 
 | 
        json.addProperty("homeId", memberBean.getHomeId()); 
 | 
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { 
 | 
            @Override 
 | 
            public void onSuccess(String jsonStr) { 
 | 
                if (TextUtils.isEmpty(jsonStr)) { 
 | 
                    if (cloudCallBeak != null) { 
 | 
                        cloudCallBeak.onSuccess(new ArrayList<>()); 
 | 
                    } 
 | 
                } 
 | 
                Gson gson = new Gson(); 
 | 
                Type type = new TypeToken<List<MemberBean>>() { 
 | 
                }.getType(); 
 | 
                List<MemberBean> memberBeanList = gson.fromJson(jsonStr, type); 
 | 
                if (cloudCallBeak != null) { 
 | 
                    cloudCallBeak.onSuccess(memberBeanList); 
 | 
                } 
 | 
            } 
 | 
  
 | 
            @Override 
 | 
            public void onFailure(HDLException e) { 
 | 
                if (cloudCallBeak != null) { 
 | 
                    cloudCallBeak.onFailure(e); 
 | 
                } 
 | 
            } 
 | 
        }); 
 | 
  
 | 
  
 | 
    } 
 | 
  
 | 
  
 | 
    /** 
 | 
     * 添加成员(C端) 
 | 
     * 
 | 
     * @param memberBean    成员对象 
 | 
     * @param cloudCallBeak - 
 | 
     */ 
 | 
    public void getMemberAdd(MemberBean memberBean, CloudCallBeak<Boolean> cloudCallBeak) { 
 | 
        String requestUrl = HttpApi.C_POST_MEMBER_ADD; 
 | 
        JsonObject json = new JsonObject(); 
 | 
        json.addProperty("homeId", memberBean.getHomeId()); 
 | 
        json.addProperty("account", memberBean.getAccount()); 
 | 
        json.addProperty("childAccountType", memberBean.getChildAccountType());////子账户类型(ORDINARY :普通成员,DEBUG : 调试人员,ADMIN : 管理员,VIEW : 仅查看) 
 | 
        json.addProperty("nickName", memberBean.getNickName()); 
 | 
  
 | 
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { 
 | 
            @Override 
 | 
            public void onSuccess(String jsonStr) { 
 | 
                if (cloudCallBeak != null) { 
 | 
                    cloudCallBeak.onSuccess(true); 
 | 
                } 
 | 
            } 
 | 
  
 | 
            @Override 
 | 
            public void onFailure(HDLException e) { 
 | 
                if (cloudCallBeak != null) { 
 | 
                    cloudCallBeak.onFailure(e); 
 | 
                } 
 | 
            } 
 | 
        }); 
 | 
  
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 编辑成员(C端) 
 | 
     * 
 | 
     * @param memberBean    成员对象 
 | 
     * @param cloudCallBeak - 
 | 
     */ 
 | 
    public void getMemberEdit(MemberBean memberBean, CloudCallBeak<Boolean> cloudCallBeak) { 
 | 
        String requestUrl = HttpApi.C_POST_MEMBER_EDIT; 
 | 
        JsonObject json = new JsonObject(); 
 | 
        json.addProperty("homeId", memberBean.getHomeId()); 
 | 
        json.addProperty("childAccountId", memberBean.getChildAccountId()); 
 | 
        json.addProperty("childId", memberBean.getId());//查找子账号接口获取到的数据(主键id==childId) 
 | 
        json.addProperty("childAccountType", memberBean.getChildAccountType());////子账户类型(ORDINARY :普通成员,DEBUG : 调试人员,ADMIN : 管理员,VIEW : 仅查看) 
 | 
        json.addProperty("nickName", memberBean.getNickName()); 
 | 
//        json.addProperty("isRemoteControl", memberBean.getNickName());//远程控制 
 | 
//        json.addProperty("isAllowCreateScene", memberBean.getNickName());//创建场景 
 | 
  
 | 
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { 
 | 
            @Override 
 | 
            public void onSuccess(String jsonStr) { 
 | 
                if (cloudCallBeak != null) { 
 | 
                    cloudCallBeak.onSuccess(true); 
 | 
                } 
 | 
            } 
 | 
  
 | 
            @Override 
 | 
            public void onFailure(HDLException e) { 
 | 
                if (cloudCallBeak != null) { 
 | 
                    cloudCallBeak.onFailure(e); 
 | 
                } 
 | 
            } 
 | 
        }); 
 | 
  
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 删除成员(C端) 
 | 
     * 
 | 
     * @param memberBean    成员对象 
 | 
     * @param cloudCallBeak - 
 | 
     */ 
 | 
    public void getMemberDelete(MemberBean memberBean, CloudCallBeak<Boolean> cloudCallBeak) { 
 | 
        String requestUrl = HttpApi.C_POST_MEMBER_DELETE; 
 | 
        JsonObject json = new JsonObject(); 
 | 
        json.addProperty("homeId", memberBean.getHomeId()); 
 | 
        json.addProperty("childAccountId", memberBean.getChildAccountId()); 
 | 
        json.addProperty("childId", memberBean.getId());//查找子账号接口获取到的数据(主键id==childId) 
 | 
  
 | 
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { 
 | 
            @Override 
 | 
            public void onSuccess(String jsonStr) { 
 | 
                if (cloudCallBeak != null) { 
 | 
                    cloudCallBeak.onSuccess(true); 
 | 
                } 
 | 
            } 
 | 
  
 | 
            @Override 
 | 
            public void onFailure(HDLException e) { 
 | 
                if (cloudCallBeak != null) { 
 | 
                    cloudCallBeak.onFailure(e); 
 | 
                } 
 | 
            } 
 | 
        }); 
 | 
  
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 下载成员(子账号)头像  已丢弃 
 | 
     */ 
 | 
    public void getHeadPIortrait(MemberBean memberBean, CloudCallBeak<byte[]> cloudCallBeak) { 
 | 
        String requestUrl = HttpApi.C_POST_HOME_GETHEADPÏORTRAIT; 
 | 
        JsonObject json = new JsonObject(); 
 | 
        json.addProperty("homeId", memberBean.getHomeId()); 
 | 
        json.addProperty("childAccountId", memberBean.getChildAccountId()); 
 | 
//        json.addProperty("childId", memberBean.getChildAccountId());//查找子账号接口获取到的数据(主键id==childId) 
 | 
        HttpClient.getInstance().downLoadFile(requestUrl, new CloudCallBeak<ResponseBody>() { 
 | 
            @Override 
 | 
            public void onSuccess(ResponseBody zipData) { 
 | 
                HdlThreadLogic.runSubThread(new Runnable() { 
 | 
                    @Override 
 | 
                    public void run() { 
 | 
                        byte[] buf = new byte[1204 * 4]; 
 | 
                        int len = 0; 
 | 
                        try { 
 | 
                            long total = zipData.contentLength(); 
 | 
                            if (total == 0) { 
 | 
                                if (cloudCallBeak != null) { 
 | 
                                    cloudCallBeak.onSuccess(new byte[]{}); 
 | 
                                } 
 | 
                                return; 
 | 
                            } 
 | 
                            List<Byte> byteList = new ArrayList<>(); 
 | 
                            InputStream is = zipData.byteStream(); 
 | 
                            while ((len = is.read(buf)) != -1) { 
 | 
                                for (int i = 0; i < len; i++) { 
 | 
                                    byteList.add(buf[i]); 
 | 
                                } 
 | 
                            } 
 | 
                            is.close(); 
 | 
                            if (byteList.size() == 0) { 
 | 
                                if (cloudCallBeak != null) { 
 | 
                                    cloudCallBeak.onSuccess(new byte[]{}); 
 | 
                                } 
 | 
                                return; 
 | 
                            } 
 | 
                            byte[] newByte = new byte[byteList.size()]; 
 | 
                            for (int i = 0; i < byteList.size(); i++) { 
 | 
                                newByte[i] = byteList.get(i); 
 | 
                            } 
 | 
                            if (cloudCallBeak != null) { 
 | 
                                cloudCallBeak.onSuccess(newByte); 
 | 
                            } 
 | 
                        } catch (Exception e) { 
 | 
                            if (cloudCallBeak != null) { 
 | 
                                cloudCallBeak.onSuccess(new byte[]{}); 
 | 
                            } 
 | 
                        } 
 | 
                    } 
 | 
                }); 
 | 
            } 
 | 
  
 | 
            @Override 
 | 
            public void onFailure(HDLException e) { 
 | 
                if (cloudCallBeak != null) { 
 | 
                    cloudCallBeak.onSuccess(new byte[]{}); 
 | 
                } 
 | 
            } 
 | 
        }); 
 | 
    } 
 | 
  
 | 
  
 | 
} 
 |