New file |
| | |
| | | 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.linkpm.sdk.user.HDLLinkPMUser; |
| | | import com.hdl.linkpm.sdk.user.bean.HDLLoginBean; |
| | | import com.hdl.linkpm.sdk.user.callback.ILoginCallBack; |
| | | import com.hdl.photovoltaic.bean.PageNumberObject; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | 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.StaffBean; |
| | | |
| | | import java.lang.reflect.Type; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 成员逻辑 |
| | | */ |
| | | 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 pageNo 页码 |
| | | * @param pageSize 页数(一页多少数据) |
| | | * @param cloudCallBeak - |
| | | */ |
| | | public void getStaffList(long pageNo, long pageSize, CloudCallBeak<PageNumberObject<List<StaffBean>>> cloudCallBeak) { |
| | | String requestUrl = "/home-wisdom/app/powerStation/user/manage/listByPage";// HttpApi.POST_PowerStation_List; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("pageNo", pageNo); |
| | | json.addProperty("pageSize", pageNo); |
| | | 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<List<StaffBean>>>() { |
| | | }.getType(); |
| | | PageNumberObject<List<StaffBean>> pageNumberObject = gson.fromJson(jsonStr, type); |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(pageNumberObject); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 获取员工详情 |
| | | * |
| | | * @param userId - |
| | | * @param cloudCallBeak - |
| | | */ |
| | | public void getStaffInfo(String userId, CloudCallBeak<PageNumberObject<StaffBean>> cloudCallBeak) { |
| | | String requestUrl = "/home-wisdom/app/powerStation/user/manage/info";// HttpApi.POST_PowerStation_List; |
| | | 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 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); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 员工添加 |
| | | * |
| | | * @param staffBean 员工对象 |
| | | * @param cloudCallBeak - |
| | | */ |
| | | public void getStaffAdd(StaffBean staffBean, CloudCallBeak<Boolean> cloudCallBeak) { |
| | | String requestUrl = "/home-wisdom/app/powerStation/user/manage/create";// HttpApi.POST_PowerStation_List; |
| | | 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); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 员工编辑 |
| | | * |
| | | * @param staffBean 员工对象 |
| | | * @param cloudCallBeak - |
| | | */ |
| | | public void getStaffEdit(StaffBean staffBean, CloudCallBeak<Boolean> cloudCallBeak) { |
| | | String requestUrl = "/home-wisdom/app/powerStation/user/manage/edit";// HttpApi.POST_PowerStation_List; |
| | | 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); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 员工删除 |
| | | * |
| | | * @param staffBean 员工对象 |
| | | * @param cloudCallBeak - |
| | | */ |
| | | public void getStaffDelete(StaffBean staffBean, CloudCallBeak<Boolean> cloudCallBeak) { |
| | | String requestUrl = "/home-wisdom/app/powerStation/user/manage/delete";// HttpApi.POST_PowerStation_List; |
| | | 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); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } |