package com.jqyd.shareInterface; import java.io.UnsupportedEncodingException; import java.net.SocketException; import java.net.SocketTimeoutException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import org.apache.http.entity.StringEntity; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.content.Context; import android.util.Log; import com.jqyd.app.SendServer; import com.jqyd.app.ShareMethod; import com.jqyd.app.WriteFile; import com.jqyd.model.CoUserModule; import com.jqyd.model.CustomerModule; import com.jqyd.model.EmpsModule; import com.jqyd.model.GroupsModule; import com.jqyd.model.LocationModule; import com.jqyd.model.ProTypeModule; public class UpdataToServer { private Context context; // private String url = "http://10.29.0.60:8080/jqgj_2.0_serv/"; private String url = "http://www.jqgj.com.cn:9090/jqgj_server_client/"; private Optdb_interfce db = null; private Optsharepre_interface share_obj = null; private WriteFile writeFile = null; private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd/HH:mm:ss"); public UpdataToServer(Context context) { this.context = context; writeFile = new WriteFile(context, "wl_记录连续上报服务日志:" + new SimpleDateFormat("yyyy-MM-dd").format(new Date())); } /** * 关闭数据库 */ public void closeSqlite3Db() { if (db != null) { db.close_SqlDb(); } } /** * 登录请求 * * @param username * @param password * @param imsi * @param gnjs * @param timeNode * @param cpmc * @return */ public String loginToServer(String username, String password, String imsi, String gnjs, String timeNode, String zdlx, String vercode ,String updatetag) { String result = "-1#请检查网络连接是否正常!";// 登录失败,网络请求失败 StringEntity entity = null; boolean needCreateTable = true; share_obj = new Optsharepre_interface(context); db = new Optdb_interfce(context); ShareMethod shareMethod = new ShareMethod(context); JSONObject object = new JSONObject(); shareMethod.recordOptTime("gnjs--------------" + gnjs); shareMethod.recordOptTime("timeNode--------------" + timeNode); if (!timeNode.equals("19000101") && !username.equals(share_obj.getDataFromPres("REGSIM"))) { db.deleteFromDb("ALL"); needCreateTable = false; shareMethod.recordOptTime("前后两次登录不一致,删除原来的数据,甚至timeNode为19000101"); Log.i("jqgj", "前后两次登录不一致,删除原来的数据,甚至timeNode为19000101"); timeNode = "19000101"; } try { JSONObject time_obj = new JSONObject(); if (!timeNode.equals("19000101")) {// 以后登录 shareMethod.recordOptTime("以后登录--------------"); time_obj.put("cousers", timeNode.split("#")[0]); time_obj.put("customers", timeNode.split("#")[1]); time_obj.put("emps", timeNode.split("#")[2]); time_obj.put("pubinfos", timeNode.split("#")[3]); time_obj.put("egroups", timeNode.split("#")[4]); time_obj.put("pro_types", timeNode.split("#")[5]); time_obj.put("lacinfo", timeNode.split("#")[6]); time_obj.put("lxsb", timeNode.split("#")[7]); time_obj.put("yjxx", timeNode.split("#")[8]); time_obj.put("dbsx", timeNode.split("#")[9]); time_obj.put("lcgz", timeNode.split("#")[10]); time_obj.put("jygk", timeNode.split("#")[11]); time_obj.put("cgroups", timeNode.split("#")[12]); time_obj.put("sgroups", timeNode.split("#")[13]); time_obj.put("jgroups", timeNode.split("#")[14]); time_obj.put("jp", timeNode.split("#")[15]); try { time_obj.put("ywtz", timeNode.split("#")[16]); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); time_obj.put("ywtz", "0"); } object.put("timeNode", time_obj); } else {// 初次登录 shareMethod.recordOptTime("初次登录--------------"); object.put("timeNode", timeNode); } System.out.println("-------------**********-------------" + time_obj.toString()); object.put("regsim", username); object.put("password", password); object.put("imsi", imsi); object.put("gnjs", gnjs); object.put("zdlx", zdlx); object.put("vercode", vercode); object.put("updatetag", updatetag); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); result = "1#数据加载出现异常!"; } url += "login!login.action";// 访问地址 try { // 绑定到请求 Entry entity = new StringEntity(switchEncode(object.toString())); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); result = "1#数据加载出现异常!!"; } System.out.println("@@@@@@@@@@@@@" + url); SendServer sendMsg = new SendServer(url); JSONObject obj_return = null; shareMethod.recordOptTime("登录-请求服务器时间:"); String resultStr = sendMsg.requestJsonFromServer(entity); shareMethod.recordOptTime("登录-服务器返回时间:"); if (resultStr != null && !resultStr.equals("-1") && !resultStr.equals("") && !resultStr.equals("500")) { try { obj_return = new JSONObject(resultStr); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); Log.e("obj_return异常", "obj_return异常"); result = "1#数据解析出现异常!"; return result; } System.out.println(timeNode + "***" + obj_return); // 判断是否初次登录 if (timeNode.equals("19000101")) {// 初次登录 System.out .println("^^^^^^^^^^^^^^^^^^^^^^^初次登陆^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"); // 自动加载所有数据 // 解析JSON数组对象 try { JSONObject jq = (JSONObject) obj_return.get("jqjg"); shareMethod.recordOptTime("登录-登录结果:初次登录"); shareMethod.recordOptTime("登录-登录结果:" + jq.getString("result") + ",初次登录"); if (jq.getString("result").equals("0")) {// 鉴权通过 // db.dropDb("ALL");//删除所有已经创建的数据库表 if (needCreateTable) { db.createTable();// 初次登录,鉴权成功,创建数据库 } // 解析JSON数组,并执行写入数据库操作 // 解析企业信息 Object couser_obj = obj_return.get("cousers"); if (couser_obj != null && !couser_obj.toString().equals("null")) { JSONObject cousers = (JSONObject) couser_obj; ArrayList<Object> coList = new ArrayList<Object>(); CoUserModule coUser = new CoUserModule(); coUser.setGuid(cousers.getString("guid")); coUser.setSjhm(cousers.getString("sjhm")); coUser.setXm(cousers.getString("xm")); coUser.setDislimit(cousers.getString("dislimit")); coUser.setJc(cousers.getString("jc")); coUser.setJclb(cousers.getString("jclb")); coUser.setQc(cousers.getString("qc")); coUser.setQydz(cousers.getString("qydz")); coUser.setXtmc(cousers.getString("xtmc")); coUser.setXxcjlb(cousers.getString("xxcjlb")); if (cousers.getString("txl") != null) { System.out.println("cousers.getString(txl)" + cousers.getString("txl")); coUser.setTxl(cousers.getString("txl")); } else { System.out.println("cousers.getString(txl)是空值"); coUser.setTxl("0"); } coList.add(coUser); db.updateToDb("T_COUSERS", coList); } // 解析客户信息 Object cust_obj = obj_return.get("customers"); if (cust_obj != null && !cust_obj.toString().equals("null")) { JSONArray customers = (JSONArray) cust_obj; ArrayList<Object> custList = new ArrayList<Object>(); for (int i = 0; i < customers.length(); i++) { CustomerModule custUser = new CustomerModule(); JSONObject custObj = (JSONObject) customers .get(i); custUser.setAddress(custObj .getString("address")); custUser.setAddtime(custObj .getString("addtime")); custUser.setCid(custObj.getString("cid")); custUser.setCname(custObj.getString("cname")); custUser.setCzjm(custObj.getString("czjm")); custUser.setGid(custObj.getString("gid")); custUser.setDepartment(custObj .getString("department")); custUser.setEmail(custObj.getString("email")); custUser.setHonor(custObj.getString("honor")); custUser.setKh_sort(custObj .getString("kh_sort")); custUser.setKh_state(custObj .getString("kh_state")); custUser.setLat(custObj.getString("lat")); custUser.setLon(custObj.getString("lon")); custUser.setClon(custObj.getString("clon")); custUser.setClat(custObj.getString("clat")); custUser.setLink_sim(custObj .getString("link_sim")); custUser.setLinkman(custObj .getString("linkman")); custUser.setQq(custObj.getString("qq")); custUser.setShort_name(custObj .getString("short_name")); custList.add(custUser); } db.updateToDb("T_CUSTOMERS", custList); } // 解析员工信息 Object emp_obj = obj_return.get("emps"); if (emp_obj != null && !emp_obj.toString().equals("null")) { JSONArray emps = (JSONArray) emp_obj; ArrayList<Object> empList = new ArrayList<Object>(); for (int i = 0; i < emps.length(); i++) { EmpsModule empUser = new EmpsModule(); JSONObject empObj = (JSONObject) emps.get(i); empUser.setGid(empObj.getString("gid")); empUser.setAddr(empObj.getString("addr")); empUser.setDepartment(empObj .getString("department")); empUser.setDwhm(empObj.getString("dwhm")); empUser.setEmail(empObj.getString("email")); empUser.setHonor(empObj.getString("honor")); empUser.setQq(empObj.getString("qq")); empUser.setXm(empObj.getString("xm")); empUser.setZcsj(empObj.getString("zcsj")); empUser.setZjm(empObj.getString("zjm")); empUser.setGuid(empObj.getString("guid")); empUser.setDwfs(empObj.getString("dwfs")); empUser.setIsshow(empObj.getString("isshow")); empList.add(empUser); } db.updateToDb("T_EMPS", empList); } // 解析分组信息 Object group_obj = obj_return.get("groups"); if (group_obj != null && !group_obj.toString().equals("null")) { JSONArray groups = (JSONArray) group_obj; ArrayList<Object> groupList = new ArrayList<Object>(); for (int i = 0; i < groups.length(); i++) { GroupsModule group = new GroupsModule(); JSONObject groupObj = (JSONObject) groups .get(i); group.setGid(Integer.parseInt(groupObj .getString("gid"))); group.setGname(groupObj.getString("gname")); group.setG_pid(Integer.parseInt(groupObj .getString("g_pid"))); group.setG_sort(Integer.parseInt(groupObj .getString("g_sort"))); groupList.add(group); } db.updateToDb("T_GROUPS", groupList); } // 解析产品规格型号信息 Object pro_obj = obj_return.get("pro_types"); if (pro_obj != null && !pro_obj.toString().equals("null")) { JSONArray pro_types = (JSONArray) pro_obj; ArrayList<Object> pro_typesList = new ArrayList<Object>(); for (int i = 0; i < pro_types.length(); i++) { ProTypeModule pro_type = new ProTypeModule(); JSONObject pro_typeObj = (JSONObject) pro_types .get(i); pro_type.setAddtime(pro_typeObj .getString("addtime")); pro_type.setCbPrise(pro_typeObj .getString("cbprise")); pro_type.setCode(pro_typeObj.getString("code")); pro_type.setZjm(pro_typeObj.getString("zjm")); pro_type.setDescription(pro_typeObj .getString("description")); pro_type.setId(pro_typeObj.getString("id")); pro_type.setIsbq(pro_typeObj.getString("isbq")); pro_type.setJxs(pro_typeObj.getString("jxs")); pro_type.setLbid(pro_typeObj.getString("lbid")); pro_type.setLsPrise(pro_typeObj .getString("lsprise")); pro_type.setModel(pro_typeObj .getString("model")); pro_type.setName(pro_typeObj.getString("name")); pro_type.setOrigin(pro_typeObj .getString("origin")); pro_type.setPfPrise(pro_typeObj .getString("pfprise")); pro_type.setProducer(pro_typeObj .getString("producer")); pro_type.setStatus(pro_typeObj .getString("status")); pro_type.setType(pro_typeObj.getString("type")); pro_type.setUnit(pro_typeObj.getString("unit")); pro_typesList.add(pro_type); } db.updateToDb("T_PRODUCTS", pro_typesList); } // 解析基站信息 Object loc_obj = obj_return.get("locations"); if (loc_obj != null && !loc_obj.toString().equals("null")) { JSONArray locations = (JSONArray) loc_obj; ArrayList<Object> locationList = new ArrayList<Object>(); for (int i = 0; i < locations.length(); i++) { LocationModule loc = new LocationModule(); JSONObject locObj = (JSONObject) locations .get(i); loc.setCcode(locObj.getString("ccode")); loc.setCell_id(locObj.getString("cell_id")); loc.setCid(locObj.getString("cid")); loc.setLac(locObj.getString("lac")); loc.setLat(Double.parseDouble(locObj .getString("lat"))); loc.setLoc_type(Integer.parseInt(locObj .getString("loc_type"))); loc.setLon(Double.parseDouble(locObj .getString("lon"))); loc.setNcode(locObj.getString("ncode")); loc.setRadius(locObj.getString("radius")); loc.setXhqd(locObj.getString("xhqd")); locationList.add(loc); } db.updateToDb("T_LACINFO", locationList); } // 解析考勤策略,写入配置文件 JSONObject userinfo = (JSONObject) obj_return .get("userinfo"); String mode = userinfo.getString("mode"); share_obj.editPres("mode", mode); String kflx = "1"; String thirdpos = "1"; try { kflx = userinfo.getString("kflx"); thirdpos = userinfo.getString("thirdpos"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } // 动态记录功能角色、登录身份、管理员、用户信息等 String msg = userinfo.getString("guid") + "#" + userinfo.getString("gnjs") + "#" + userinfo.getString("cosim") + "#" + username + "#" + userinfo.getString("ismager") + "#" + userinfo.getString("ontime") + "#" + userinfo.getString("offtime") + "#" + userinfo.getString("signtime") + "#" + userinfo.getString("endtime") + "#" + userinfo.getString("qdmode") + "#" + userinfo.getString("workmode") + "#" + password + "#" + userinfo.getString("gguid") + "#" + userinfo.getString("gid") + "#" + userinfo.getString("cpmc") + "#" + userinfo.getString("ywmc") + "#" + userinfo.getString("glfw") + "#" + userinfo.getString("kqmode") + "#" + userinfo.getString("dwzt") + "#" + userinfo.getString("kqflag") + "#" + userinfo.getString("sjzg") + "#" + userinfo.getString("wcfw") + "#" + userinfo.getString("dwmode") + "#" + kflx + "#" + thirdpos; share_obj.editPres("LOGIN", msg); String userName = db.searchEmpName(userinfo .getString("guid")); share_obj.editPres("username", userName); Log.e("userName", share_obj.getDataFromPres("username")); // 解析连续上报信息 Object task_obj = obj_return.get("tasks"); String log = ""; if (task_obj != null && !task_obj.toString().equals("null")) {// 保存任务指令 JSONObject tasks = (JSONObject) task_obj; share_obj.editPres("SBSJ", tasks.getString("ontime")); share_obj.editPres("XBSJ", tasks.getString("offtime")); share_obj.editPres("JGSJ", tasks.getString("intervaltime")); share_obj.editPres("RWZL", tasks.getString("execute")); log = "《首次登录,连续上报数据更新》*******************" + tasks.getString("ontime") + "," + tasks.getString("offtime") + "," + tasks.getString("intervaltime") + "," + tasks.getString("execute"); writeFile.writeToFile(sdf.format(new Date()) + " " + log + "\n"); } else {// 删除任务指令 share_obj.editPres("SBSJ", "-2"); share_obj.editPres("XBSJ", "-2"); share_obj.editPres("JGSJ", "-2"); share_obj.editPres("RWZL", "-2"); log = "《首次登录,连续上报任务清除》*******************-2"; writeFile.writeToFile(sdf.format(new Date()) + " " + log + "\n"); } // 写入加载数据的时间至终端数据库 String currtime = jq.getString("time"); db.updateTimeNode("ALL", currtime); result = "0";// 登录成功 String res = ""; if (jq.getString("result").equals("0")) { try { res = (String) jq.get("gxbs");// 更新标识 } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } shareMethod.recordOptTime("登录-登录结果:0,更新标识:" + result + ",初次登陆:"); String gxbs[] = res.split("#"); System.out .println("更新标识--------------------------------" + result); if (gxbs[0].equals("1")) {// -------------------有数据更新------------------- if (gxbs[1].equals("1")) {// 版本更新 System.out .println("------------------有新版本更新-----------------"); result = "-999#" + res; } } } } else {// 登录鉴权失败 String errMsg = jq.getString("detail"); result = "1#" + errMsg; } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); result = "1#数据加载出现异常!!!"; } } else {// 以后登录 try { JSONObject jq = (JSONObject) obj_return.get("jqjg"); if (jq.getString("result").equals("0")) { try { result = (String) jq.get("gxbs");// 更新标识 } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } shareMethod.recordOptTime("登录-登录结果:0,更新标识:" + result + ",以后登录:"); String gxbs[] = result.split("#"); if (gxbs[0].equals("1")) {// -------------------有数据更新------------------- if (gxbs[1].equals("1")) {// 版本更新 System.out .println("------------------有新版本更新-----------------"); result = "-999#" + result; }else{ result ="0"; } } else { shareMethod.recordOptTime("更新标识:无数据更新"); System.out .println("-----------------无数据更新---------------"); result = "0";// 无数据和版本更新,登录成功进入主界面 } // 解析考勤策略,写入配置文件 } else {// 登录鉴权失败 String errMsg = jq.getString("detail"); shareMethod .recordOptTime("登录-登录结果:" + errMsg + ",以后登录"); result = "1#" + errMsg; } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); result = "1#数据更新出现异常!"; } } db.close_SqlDb(); } else if (resultStr.equals("-1")) { result = "-1#请检查网络连接是否正常!";// } else if (resultStr.equals("500")) { result = "1#登录失败,请联系你的管理员!"; } shareMethod.recordOptTime("登录-结束:" + result + ",结束时间:" + ""); System.out.println("登录结果:" + result); System.out.println("**************登录完毕!**************"); return result; } /** * 数据更新 * * @param username * @param password * @param imsi * @param gnjs * @param timeNode * @param cpmc * @return */ public String Update(String username, String password, String imsi, String gnjs, String timeNode, String zdlx, String vercode) { String result = "-1#请检查网络连接是否正常!";// 登录失败,网络请求失败 StringEntity entity = null; boolean needCreateTable = true; share_obj = new Optsharepre_interface(context); ShareMethod shareMethod = new ShareMethod(context); JSONObject object = new JSONObject(); shareMethod.recordOptTime("gnjs--------------" + gnjs); shareMethod.recordOptTime("timeNode--------------" + timeNode); try { JSONObject time_obj = new JSONObject(); shareMethod.recordOptTime("数据更新--------------"); time_obj.put("cousers", timeNode.split("#")[0]); time_obj.put("customers", timeNode.split("#")[1]); time_obj.put("emps", timeNode.split("#")[2]); time_obj.put("pubinfos", timeNode.split("#")[3]); time_obj.put("egroups", timeNode.split("#")[4]); time_obj.put("pro_types", timeNode.split("#")[5]); time_obj.put("lacinfo", timeNode.split("#")[6]); time_obj.put("lxsb", timeNode.split("#")[7]); time_obj.put("yjxx", timeNode.split("#")[8]); time_obj.put("dbsx", timeNode.split("#")[9]); time_obj.put("lcgz", timeNode.split("#")[10]); time_obj.put("jygk", timeNode.split("#")[11]); time_obj.put("cgroups", timeNode.split("#")[12]); time_obj.put("sgroups", timeNode.split("#")[13]); time_obj.put("jgroups", timeNode.split("#")[14]); time_obj.put("jp", timeNode.split("#")[15]); try { time_obj.put("ywtz", timeNode.split("#")[16]); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); time_obj.put("ywtz", "0"); } object.put("timeNode", time_obj); System.out.println("-------------**********-------------" + time_obj.toString()); object.put("regsim", username); object.put("password", password); object.put("imsi", imsi); object.put("gnjs", gnjs); object.put("zdlx", zdlx); object.put("vercode", vercode); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); result = "1#数据加载出现异常!!!!"; shareMethod.recordOptTime("object.put"+result); } url += "login!Update.action";// 访问地址 try { // 绑定到请求 Entry entity = new StringEntity(switchEncode(object.toString())); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); result = "1#数据加载出现异常!!!!!"; shareMethod.recordOptTime("entity"+result); } System.out.println("@@@@@@@@@@@@@" + url); SendServer sendMsg = new SendServer(url); JSONObject obj_return = null; String resultStr = sendMsg.requestJsonFromServer(entity); if (resultStr != null && !resultStr.equals("-1") && !resultStr.equals("") && !resultStr.equals("500")) { try { obj_return = new JSONObject(resultStr); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); Log.e("obj_return异常", "obj_return异常"); shareMethod.recordOptTime("obj_return异常"+result+resultStr); result = "1#数据解析出现异常!"; return result; } try { JSONObject jq = (JSONObject) obj_return.get("jqjg"); if (jq.getString("result").equals("0")) { try { result = (String) jq.get("gxbs");// 更新标识 } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } String gxbs[] = result.split("#"); System.out.println("更新标识--------------------------------" + result); if (gxbs[0].equals("1")) {// -------------------有数据更新------------------- db = new Optdb_interfce(context); shareMethod.recordOptTime("数据库是否关闭1"+db.isOpen()); shareMethod.recordOptTime("更新标识:以后登录,有数据更新"); if (gxbs[2].equals("1")) {// 管理员信息 System.out.println("管理员信息更新"); shareMethod .recordOptTime("更新标识:以后登录,有数据更新,管理员信息更新"); // 解析企业信息 Object couser_obj = obj_return.get("cousers"); if (couser_obj != null && !couser_obj.toString() .equals("null")) { // 写入加载数据的时间至终端数据库 String currtime = jq.getString("time"); db.updateTimeNode("COUSERS", currtime); JSONArray cousers = (JSONArray) couser_obj; JSONObject couser = (JSONObject) cousers .get(0); ArrayList<Object> coList = new ArrayList<Object>(); CoUserModule coUser = new CoUserModule(); coUser.setGuid(couser.getString("guid")); coUser.setSjhm(couser.getString("sjhm")); coUser.setXm(couser.getString("xm")); coUser.setDislimit(couser .getString("dislimit")); coUser.setJc(couser.getString("jc")); coUser.setJclb(couser.getString("jclb")); coUser.setQc(couser.getString("qc")); coUser.setQydz(couser.getString("qydz")); coUser.setXtmc(couser.getString("xtmc")); coUser.setXxcjlb(couser.getString("xxcjlb")); if (couser.getString("txl") != null) { System.out .println("cousers.getString(txl)" + couser.getString("txl")); coUser.setTxl(couser.getString("txl")); } else { System.out .println("cousers.getString(txl)是空值"); coUser.setTxl("1"); } coList.add(coUser); db.updateToDb("T_COUSERS", coList); } else { db.deleteFromDb("T_COUSERS"); } } if (gxbs[3].equals("1")) {// 客户信息 System.out.println("客户信息更新"); shareMethod .recordOptTime("更新标识:以后登录,有数据更新,客户信息更新"); Object cust_obj = obj_return.get("customers"); if (cust_obj != null && !cust_obj.toString().equals("null")) { // 写入加载数据的时间至终端数据库 String currtime = jq.getString("time"); shareMethod.recordOptTime("数据库是否关闭2"+db.isOpen()); db.updateTimeNode("CUSTOMERS", currtime); // 解析客户信息 JSONArray customers = (JSONArray) cust_obj; ArrayList<Object> custList = new ArrayList<Object>(); for (int i = 0; i < customers.length(); i++) { CustomerModule custUser = new CustomerModule(); JSONObject custObj = (JSONObject) customers .get(i); custUser.setAddress(custObj .getString("address")); custUser.setAddtime(custObj .getString("addtime")); custUser.setCid(custObj .getString("cid")); custUser.setCname(custObj .getString("cname")); custUser.setCzjm(custObj .getString("czjm")); custUser.setGid(custObj .getString("gid")); custUser.setDepartment(custObj .getString("department")); custUser.setEmail(custObj .getString("email")); custUser.setHonor(custObj .getString("honor")); custUser.setKh_sort(custObj .getString("kh_sort")); custUser.setKh_state(custObj .getString("kh_state")); custUser.setLat(custObj .getString("lat")); custUser.setLon(custObj .getString("lon")); custUser.setClon(custObj .getString("clon")); custUser.setClat(custObj .getString("clat")); custUser.setLink_sim(custObj .getString("link_sim")); custUser.setLinkman(custObj .getString("linkman")); custUser.setQq(custObj.getString("qq")); custUser.setShort_name(custObj .getString("short_name")); custList.add(custUser); } db.updateToDb("T_CUSTOMERS", custList); } else { db.deleteFromDb("T_CUSTOMERS"); } } if (gxbs[4].equals("1")) {// 员工信息 System.out.println("员工信息更新"); shareMethod .recordOptTime("更新标识:以后登录,有数据更新,员工信息更新"); Object emp_obj = obj_return.get("emps"); if (emp_obj != null && !emp_obj.toString().equals("null")) { // 写入加载数据的时间至终端数据库 String currtime = jq.getString("time"); db.updateTimeNode("EMPS", currtime); // 解析员工信息 JSONArray emps = (JSONArray) emp_obj; ArrayList<Object> empList = new ArrayList<Object>(); for (int i = 0; i < emps.length(); i++) { EmpsModule empUser = new EmpsModule(); JSONObject empObj = (JSONObject) emps .get(i); empUser.setGid(empObj.getString("gid")); empUser.setAddr(empObj .getString("addr")); empUser.setDepartment(empObj .getString("department")); empUser.setDwhm(empObj .getString("dwhm")); empUser.setEmail(empObj .getString("email")); empUser.setHonor(empObj .getString("honor")); empUser.setQq(empObj.getString("qq")); empUser.setXm(empObj.getString("xm")); empUser.setZcsj(empObj .getString("zcsj")); empUser.setZjm(empObj.getString("zjm")); empUser.setGuid(empObj .getString("guid")); empUser.setDwfs(empObj .getString("dwfs")); empUser.setIsshow(empObj .getString("isshow")); empList.add(empUser); } db.updateToDb("T_EMPS", empList); } else { db.deleteFromDb("T_EMPS"); } } if (gxbs[5].equals("1")) {// 公共信息 } if (gxbs[6].equals("1") || gxbs[14].equals("1") || gxbs[15].equals("1") || gxbs[16].equals("1")) {// 分组信息 System.out.println("分组信息更新"); shareMethod .recordOptTime("更新标识:以后登录,有数据更新,分组信息更新"); boolean flag_kh = false; boolean flag_yg = false; boolean flag_sp = false; boolean flag_jp = false; Object group_obj = obj_return.get("groups"); if (group_obj != null && !group_obj.toString().equals("null")) { System.out.println("分组信息:" + obj_return.get("groups") .toString()); // 解析分组信息 JSONArray groups = (JSONArray) group_obj; ArrayList<Object> groupList = new ArrayList<Object>(); for (int i = 0; i < groups.length(); i++) { GroupsModule group = new GroupsModule(); JSONObject groupObj = (JSONObject) groups .get(i); group.setGid(Integer.parseInt(groupObj .getString("gid"))); group.setGname(groupObj .getString("gname")); group.setG_pid(Integer .parseInt(groupObj .getString("g_pid"))); group.setG_sort(Integer .parseInt(groupObj .getString("g_sort"))); groupList.add(group); // 写入加载数据的时间至终端数据库 String currtime = jq.getString("time"); int sort = Integer.parseInt(groupObj .getString("g_sort")); System.out.println("分组标识------" + sort); switch (sort) { case 1: if (!flag_kh) { System.out.println("客户分组信息更新"); db.updateGTimeNode("GROUP", 1, currtime); flag_kh = true; } break; case 2: if (!flag_yg) { System.out.println("员工分组信息更新"); db.updateGTimeNode("GROUP", 2, currtime); flag_yg = true; } break; case 3: if (!flag_sp) { System.out.println("产品分组信息更新"); db.updateGTimeNode("GROUP", 3, currtime); flag_sp = true; } break; case 4: if (!flag_jp) { System.out.println("竞品分组信息更新"); db.updateGTimeNode("GROUP", 4, currtime); flag_jp = true; } break; } } db.updateToDb("T_GROUPS", groupList); } else { db.deleteFromDb("T_GROUPS"); } } if (gxbs[7].equals("1") || gxbs[17].equals("1")) {// 产品规格型号信息 System.out.println("产品信息更新"); shareMethod .recordOptTime("更新标识:以后登录,有数据更新,产品信息更新"); boolean flag_sp = false; boolean flag_jp = false; Object pro_obj = obj_return.get("pro_types"); if (pro_obj != null && !pro_obj.toString().equals("null")) { // 解析产品规格型号信息 JSONArray pro_types = (JSONArray) pro_obj; ArrayList<Object> pro_typesList = new ArrayList<Object>(); for (int i = 0; i < pro_types.length(); i++) { ProTypeModule pro_type = new ProTypeModule(); JSONObject pro_typeObj = (JSONObject) pro_types .get(i); pro_type.setAddtime(pro_typeObj .getString("addtime")); pro_type.setCbPrise(pro_typeObj .getString("cbprise")); pro_type.setCode(pro_typeObj .getString("code")); pro_type.setDescription(pro_typeObj .getString("description")); pro_type.setId(pro_typeObj .getString("id")); pro_type.setIsbq(pro_typeObj .getString("isbq")); pro_type.setJxs(pro_typeObj .getString("jxs")); pro_type.setLbid(pro_typeObj .getString("lbid")); pro_type.setLsPrise(pro_typeObj .getString("lsprise")); pro_type.setModel(pro_typeObj .getString("model")); pro_type.setName(pro_typeObj .getString("name")); pro_type.setOrigin(pro_typeObj .getString("origin")); pro_type.setPfPrise(pro_typeObj .getString("pfprise")); pro_type.setProducer(pro_typeObj .getString("producer")); pro_type.setStatus(pro_typeObj .getString("status")); pro_type.setType(pro_typeObj .getString("type")); pro_type.setUnit(pro_typeObj .getString("unit")); pro_type.setZjm(pro_typeObj .getString("zjm")); pro_typesList.add(pro_type); // 写入加载数据的时间至终端数据库 String currtime = jq.getString("time"); int sort = Integer.parseInt(pro_typeObj .getString("type")); switch (sort) { case 3: if (!flag_sp) { System.out.println("本品信息更新"); db.updateGTimeNode("PRODUCT", 3, currtime); flag_sp = true; } break; case 4: if (!flag_jp) { System.out.println("竞品信息更新"); db.updateGTimeNode("PRODUCT", 4, currtime); flag_jp = true; } break; } } db.updateToDb("T_PRODUCTS", pro_typesList); } else { db.deleteFromDb("T_PRODUCTS"); } } if (gxbs[8].equals("1")) { System.out.println("基站信息更新"); shareMethod .recordOptTime("更新标识:以后登录,有数据更新,基站信息更新"); Object loc_obj = obj_return.get("locations"); if (loc_obj != null && !loc_obj.toString().equals("null")) { // 写入加载数据的时间至终端数据库 String currtime = jq.getString("time"); db.updateTimeNode("LACINFO", currtime); // 解析基站信息 JSONArray locations = (JSONArray) loc_obj; ArrayList<Object> locationList = new ArrayList<Object>(); for (int i = 0; i < locations.length(); i++) { LocationModule loc = new LocationModule(); JSONObject locObj = (JSONObject) locations .get(i); loc.setCcode(locObj.getString("ccode")); loc.setCell_id(locObj .getString("cell_id")); loc.setCid(locObj.getString("cid")); loc.setLac(locObj.getString("lac")); loc.setLat(Double.parseDouble(locObj .getString("lat"))); loc.setLoc_type(Integer.parseInt(locObj .getString("loc_type"))); loc.setLon(Double.parseDouble(locObj .getString("lon"))); loc.setNcode(locObj.getString("ncode")); loc.setRadius(locObj .getString("radius")); loc.setXhqd(locObj.getString("xhqd")); locationList.add(loc); } db.updateToDb("T_LACINFO", locationList); } else { db.deleteFromDb("T_LACINFO"); } } if (gxbs[9].equals("1")) { System.out.println("连续上报信息更新"); shareMethod .recordOptTime("更新标识:以后登录,有数据更新,连续上报信息更新"); Object task_obj = obj_return.get("tasks"); String log = ""; if (task_obj != null && !task_obj.toString().equals("null")) {// 保存任务指令 JSONObject tasks = (JSONObject) task_obj; share_obj.editPres("SBSJ", tasks.getString("ontime")); share_obj.editPres("XBSJ", tasks.getString("offtime")); share_obj.editPres("JGSJ", tasks.getString("intervaltime")); share_obj.editPres("RWZL", tasks.getString("execute")); log = "《登录,连续上报数据更新》*******************" + tasks.getString("ontime") + "," + tasks.getString("offtime") + "," + tasks.getString("intervaltime") + "," + tasks.getString("execute"); writeFile.writeToFile(sdf .format(new Date()) + " " + log + "\n"); } else {// 删除任务指令 share_obj.editPres("SBSJ", "-2"); share_obj.editPres("XBSJ", "-2"); share_obj.editPres("JGSJ", "-2"); share_obj.editPres("RWZL", "-2"); log = "《登录,连续上报任务清除》*******************-2"; writeFile.writeToFile(sdf .format(new Date()) + " " + log + "\n"); } // 写入加载数据的时间至终端数据库 String currtime = jq.getString("time"); db.updateTimeNode("LXSB", currtime); } // gxbs[10]经营管控、gxbs[11]预警信息、gxbs[12]待办事项、gxbs[13]流程跟踪、gxbs[18]业务通知等更新信息均不作处理 result = "0";// 有数据更新,登录成功进入主界面 } else { shareMethod.recordOptTime("更新标识:无数据更新"); System.out .println("-----------------无数据更新---------------"); result = "0";// 无数据和版本更新,登录成功进入主界面 } // 解析考勤策略,写入配置文件 JSONObject userinfo = (JSONObject) obj_return .get("userinfo"); System.out.println("userinfo------yhdl--------------" + userinfo.toString()); String mode = userinfo.getString("mode"); share_obj.editPres("mode", mode); // Log.e("mode", mode); String kflx = "1"; String thirdpos = "1";// ************************************************************************** // 动态记录功能角色、登录身份、管理员、用户信息等 String msg = userinfo.getString("guid") + "#" + userinfo.getString("gnjs") + "#" + userinfo.getString("cosim") + "#" + username + "#" + userinfo.getString("ismager") + "#" + userinfo.getString("ontime") + "#" + userinfo.getString("offtime") + "#" + userinfo.getString("signtime") + "#" + userinfo.getString("endtime") + "#" + userinfo.getString("qdmode") + "#" + userinfo.getString("workmode") + "#" + password + "#" + userinfo.getString("gguid") + "#" + userinfo.getString("gid") + "#" + userinfo.getString("cpmc") + "#" + userinfo.getString("ywmc") + "#" + userinfo.getString("glfw") + "#" + userinfo.getString("kqmode") + "#" + userinfo.getString("dwzt") + "#" + userinfo.getString("kqflag") + "#" + userinfo.getString("sjzg") + "#" + userinfo.getString("wcfw") + "#" + userinfo.getString("dwmode") + "#" + kflx + "#" + thirdpos; share_obj.editPres("LOGIN", msg); if(db == null){ db = new Optdb_interfce(context); } String userName = db.searchEmpName(userinfo .getString("guid")); share_obj.editPres("username", userName); Log.e("userName", share_obj.getDataFromPres("username")); } else {// 登录鉴权失败 String errMsg = jq.getString("detail"); shareMethod.recordOptTime("登录-登录结果:" + errMsg + ",以后登录"); result = "1#" + errMsg; } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); result = "1#数据更新出现异常!"; shareMethod.recordOptTime("数据解析写入数据库"+result); } if(db!=null){ db.close_SqlDb(); } } else if (resultStr.equals("-1")) { result = "-1#请检查网络连接是否正常!";// } else if (resultStr.equals("500")) { result = "1#更新失败,请联系你的管理员!"; } shareMethod.recordOptTime("更新结束-结束:" + result + ",结束时间:" + ""); return result; } /** * 上传数据的通用方法 * * @param upSort * @param obj * @return */ public String dataToServer(String upSort, JSONObject obj) { String result = "-1"; StringEntity entity = null; try { if (upSort.equals("RZSB")) { url += "login!upMyLog.action"; } else if (upSort.equals("JHAP")) { url += "login!upMyPlan.action"; } else if (upSort.equals("JHGL")) { url += "login!managerPlan.action"; } else if (upSort.equals("CCSQ")) { url += "login!upMyTravel.action"; } else if (upSort.equals("QJSQ")) { url += "login!upMyVacation.action"; } else if (upSort.equals("XXFK")) { url += "login!xxfk_position.action"; } else if (upSort.equals("XXFKCC")) { url += "login!xxfk.action"; } else if (upSort.equals("GGTZ")) {// 更新公告通知状态 url += "login!updatePubinfoState.action"; } else if (upSort.equals("QYGG")) { url += "login!fbgg.action"; } else if (upSort.equals("YWTZ")) { url += "login!fbYwtz.action"; } else if (upSort.equals("SMS")) { url += "login!dxqf.action"; } else if (upSort.equals("KQSB")) { url += "login!upQdqt.action"; } else if (upSort.equals("KHCJ")) { url += "login!khcj.action"; } else if (upSort.equals("MSBF")) { url += "login!msbf.action"; } else if (upSort.equals("KHZF")) { url += "login!khzf.action"; } else if (upSort.equals("SCJC")) { url += "login!scjc.action"; } else if (upSort.equals("WZSB")) { url += "login!wzsb.action"; } else if (upSort.equals("DWGL")) { url += "login!dwgl.action"; } else if (upSort.equals("XGMM")) { url += "login!xgmm.action"; } else if (upSort.equals("GXSP")) { url += "login!updateMyLogMark.action"; } else if (upSort.equals("SPSB")) { url += "login!dbsxsp.action"; } else if (upSort.equals("DDSB")) { url += "login!ddgl.action"; } else if (upSort.equals("CLZX")) { url += "login!clzx.action"; } else if (upSort.equals("SJCJ")) { url += "login!sjcj.action"; } else if (upSort.equals("JCLXSB")) { url += "login!getUpTask.action"; } else if (upSort.equals("LXSB")) { url += "login!lxsb_new.action"; } else if (upSort.equals("GETIME")) { url += "login!getServerTime.action"; } else if (upSort.equals("RWHF")) { url += "login!replyTask.action"; } else if (upSort.equals("WZCX")) { url += "login!wzcx.action"; } else if (upSort.equals("LJDWDETAIL")) { url += "login!showDetail.action"; } else if (upSort.equals("GJHF")) { url += "login!gjhf.action"; } else if (upSort.equals("IQ")) { url += "login!networkState.action"; } else if(upSort.equals("SENDMESS")){ url += "login!sendMessageFromJpush.action"; } else if(upSort.equals("UPFORJPUSH")){ url += "login!wzsbForJpush.action"; } // 绑定到请求 Entry entity = new StringEntity(switchEncode(obj.toString())); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } SendServer sendMsg = new SendServer(url); result = sendMsg.requestJsonFromServer(entity); System.out.println("通用上传方法请求结果------" + upSort + "--------" + result); return result; } public String dataToServerForURL(String url,String json){ this.url = url; return dataToServer(url, json); } public String dataToServer(String upSort, String json) { String result = "-1"; StringEntity entity = null; try { if (upSort.equals("RZSB")) { url += "login!upMyLog.action"; } else if (upSort.equals("JHAP")) { url += "login!upMyPlan.action"; } else if (upSort.equals("JHGL")) { url += "login!managerPlan.action"; } else if (upSort.equals("CCSQ")) { url += "login!upMyTravel.action"; } else if (upSort.equals("QJSQ")) { url += "login!upMyVacation.action"; } else if (upSort.equals("XXFK")) { url += "login!xxfk_position.action"; } else if (upSort.equals("XXFKCC")) { url += "login!xxfk.action"; } else if (upSort.equals("GGTZ")) {// 更新公告通知状态 url += "login!updatePubinfoState.action"; } else if (upSort.equals("QYGG")) { url += "login!fbgg.action"; } else if (upSort.equals("YWTZ")) { url += "login!fbYwtz.action"; } else if (upSort.equals("SMS")) { url += "login!dxqf.action"; } else if (upSort.equals("KQSB")) { url += "login!upQdqt.action"; } else if (upSort.equals("KHCJ")) { url += "login!khcj.action"; } else if (upSort.equals("MSBF")) { url += "login!msbf.action"; } else if (upSort.equals("KHZF")) { url += "login!khzf.action"; } else if (upSort.equals("SCJC")) { url += "login!scjc.action"; } else if (upSort.equals("WZSB")) { url += "login!wzsb.action"; } else if (upSort.equals("DWGL")) { url += "login!dwgl.action"; } else if (upSort.equals("XGMM")) { url += "login!xgmm.action"; } else if (upSort.equals("GXSP")) { url += "login!updateMyLogMark.action"; } else if (upSort.equals("SPSB")) { url += "login!dbsxsp.action"; } else if (upSort.equals("DDSB")) { url += "login!ddgl.action"; } else if (upSort.equals("CLZX")) { url += "login!clzx.action"; } else if (upSort.equals("SJCJ")) { url += "login!sjcj.action"; } else if (upSort.equals("JCLXSB")) { url += "login!getUpTask.action"; } else if (upSort.equals("LXSB")) { url += "login!lxsb_new.action"; } else if (upSort.equals("GETIME")) { url += "login!getServerTime.action"; } else if (upSort.equals("RWHF")) { url += "login!replyTask.action"; } else if (upSort.equals("WZCX")) { url += "login!wzcx.action"; } else if (upSort.equals("LJDWDETAIL")) { url += "login!showDetail.action"; } else if (upSort.equals("GJHF")) { url += "login!gjhf.action"; } else if (upSort.equals("IQ")) { url += "login!networkState.action"; } else if(upSort.equals("SENDMESS")){ url += "login!sendMessageFromJpush.action"; } else if(upSort.equals("UPFORJPUSH")){ url += "login!wzsbForJpush.action"; } // 绑定到请求 Entry entity = new StringEntity(json); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } SendServer sendMsg = new SendServer(url); result = sendMsg.requestJsonFromServer(entity); System.out.println("通用上传方法请求结果------" + upSort + "--------" + result); return result; } /** * 从服务器查询数据的通用方法 * * @param sort * @param obj * @return */ public String searchFromServer(String sort, Object obj) { String result = "-1"; StringEntity entity = null; try { if (sort.equals("RZCX")) { url += "login!cxMyLog.action"; } else if (sort.equals("JHCX")) { url += "login!cxMyPlan.action"; } else if (sort.equals("CLCX")) { url += "login!cxMyTravel.action"; } else if (sort.equals("QJCX")) { url += "login!cxVacation.action"; } else if (sort.equals("QYGG")) { url += "login!cxgg.action"; } else if (sort.equals("YWTZ")) { url += "login!cxYwtz.action"; } else if (sort.equals("WDZT")) { url += "login!myState.action"; } else if (sort.equals("DBCX")) { url += "login!cxdbsx.action"; } else if (sort.equals("DDCX")) { url += "login!cxOrderInfo.action"; } else if (sort.equals("LCGZ")) { url += "login!cxlcgz.action"; } else if (sort.equals("DBLC")) { url += "login!cxdblc.action"; } else if (sort.equals("GZTCX")) { url += "login!cxgztinfo.action"; } else if (sort.equals("GZTLSCX")) { url += "login!cxLsRecord.action"; } else if (sort.equals("SMS")) { url += "login!smsCx.action"; } else if (sort.equals("RWCX")) { url += "login!cxMyTask.action"; } else if (sort.equals("gztnum")) { url += "login!cxgztinfonum.action"; } // 绑定到请求 Entry entity = new StringEntity(switchEncode(obj.toString())); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } SendServer sendMsg = new SendServer(url); result = sendMsg.requestJsonFromServer(entity); System.out.println("通用查询方法请求结果------" + sort + "--------" + result); return result; } /** * 将字符串转化为字节数组进行数据传输,防止中文乱码 * * @param param * @return */ public String switchEncode(String param) { byte[] temp = param.getBytes(); String result = ""; for (int i = 0; i < temp.length; i++) { result += temp[i] + ";"; } return result; } }