PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/familyedu/FamilyEdu/src/com/familyedu/net/JsonParse.java

https://gitlab.com/BGCX067/family-teacher-svn-to-git
Java | 522 lines | 421 code | 28 blank | 73 comment | 23 complexity | 28ae441e5c47c5e673ad4713ba74ac0e MD5 | raw file
  1. package com.familyedu.net;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Map;
  5. import com.alibaba.fastjson.JSON;
  6. import com.alibaba.fastjson.JSONArray;
  7. import com.alibaba.fastjson.JSONObject;
  8. import com.familyedu.model.HomePageAnswerListInfo;
  9. import com.familyedu.model.HomePageIssueListInfo;
  10. import com.familyedu.model.IssueCon;
  11. import com.familyedu.model.MyClassroom;
  12. import com.familyedu.model.MyConsumptionInfo;
  13. import com.familyedu.model.MyTeacher;
  14. import com.familyedu.model.MyTeacherListItemInfo;
  15. import com.familyedu.model.MyTeacherNotificationInfo;
  16. import com.familyedu.model.QuestionInfo;
  17. import com.familyedu.model.StudentCollectInfo;
  18. import com.familyedu.model.StudentLookQuestionInfo;
  19. import com.familyedu.model.TeacherAccount;
  20. import com.familyedu.model.TeacherCollectInfo;
  21. import com.familyedu.model.UserInfo;
  22. import com.familyedu.model.VersionInfo;
  23. public class JsonParse {
  24. /**
  25. * 用户登录
  26. */
  27. public static Object parseUserLogin(String str) {
  28. ResultObject ro = new ResultObject();
  29. try {
  30. Map<String, Object> map = JSON.parseObject(str);
  31. Boolean flag = (Boolean) map.get("logBln");
  32. if (flag == true) {
  33. Map<String, Object> usertype = (Map<String, Object>) map.get("userOut");
  34. UserInfo user = new UserInfo();
  35. user.birthday = (String) usertype.get("birthday");
  36. user.createTime = (String) usertype.get("createTime");
  37. user.emailAddress = (String) usertype.get("emailAddress");
  38. user.emailAddressStatus = (Integer) usertype.get("emailAddressStatus");
  39. user.headImg = (String) usertype.get("headImg");
  40. user.nickname = (String) usertype.get("nickname");
  41. user.password = (String) usertype.get("password");
  42. user.status = (Integer) usertype.get("status");
  43. user.username = (String) usertype.get("username");
  44. // user.usertype = (Integer) usertype.get("usertype");
  45. user.roleType = (String) usertype.get("roleType");
  46. ro.result = true;
  47. ro.obj = user;
  48. } else {
  49. ro.result = false;
  50. ro.obj = map.get("reason");
  51. }
  52. } catch (Exception e) {
  53. e.printStackTrace();
  54. ro.result = false;
  55. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATAREQUEST_FAIL_ERROR);
  56. }
  57. return ro;
  58. }
  59. /**
  60. * 学生注册
  61. */
  62. public static Object parseStudentRegister(String str) {
  63. ResultObject ro = new ResultObject();
  64. try {
  65. Map<String, Object> map = JSON.parseObject(str);
  66. Boolean flag = (Boolean) map.get("cpsBln");
  67. ro.result = flag;
  68. } catch (Exception e) {
  69. e.printStackTrace();
  70. ro.result = false;
  71. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATA_EXCEPTION_ERROR);
  72. }
  73. return ro;
  74. }
  75. /**
  76. * 老师注册
  77. */
  78. public static Object parseTeacherRegister(String str) {
  79. ResultObject ro = new ResultObject();
  80. try {
  81. Map<String, Object> map = JSON.parseObject(str);
  82. Boolean flag = (Boolean) map.get("cpsBln");
  83. ro.result = flag;
  84. } catch (Exception e) {
  85. e.printStackTrace();
  86. ro.result = false;
  87. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATA_EXCEPTION_ERROR);
  88. }
  89. return ro;
  90. }
  91. /**
  92. * 解析学生首页问题列表
  93. */
  94. public static Object parseMainIssueList(String str) {
  95. ResultObject ro = new ResultObject();
  96. try {
  97. ro.result = true;
  98. ro.obj = new HomePageIssueListInfo().parser(str);
  99. } catch (Exception e) {
  100. e.printStackTrace();
  101. ro.result = false;
  102. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATAREQUEST_FAIL_ERROR);
  103. }
  104. return ro;
  105. }
  106. /**
  107. * 解析老师首页回答列表
  108. */
  109. public static Object parseMainAnswerList(String str) {
  110. ResultObject ro = new ResultObject();
  111. try {
  112. ro.result = true;
  113. ro.obj = new HomePageAnswerListInfo().parser(str);
  114. } catch (Exception e) {
  115. e.printStackTrace();
  116. ro.result = false;
  117. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATAREQUEST_FAIL_ERROR);
  118. }
  119. return ro;
  120. }
  121. public static Object parseQuestionListWall(String str) {
  122. ResultObject ro = new ResultObject();
  123. try {
  124. ro.result = true;
  125. ro.obj = new HomePageIssueListInfo().parser(str);
  126. } catch (Exception e) {
  127. e.printStackTrace();
  128. ro.result = false;
  129. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATAREQUEST_FAIL_ERROR);
  130. }
  131. return ro;
  132. }
  133. /**
  134. * 教师查看问题
  135. */
  136. public static Object parseTeacherLookQuestionInfo(String str) {
  137. ResultObject ro = new ResultObject();
  138. try {
  139. JSONObject jsonObject = JSONObject.parseObject(str);
  140. boolean result = jsonObject.getBooleanValue("result");
  141. if(result) {
  142. ro.result = true;
  143. ro.obj = new QuestionInfo().parser(jsonObject);
  144. } else {
  145. ro.result = false;
  146. }
  147. } catch (Exception e) {
  148. e.printStackTrace();
  149. ro.result = false;
  150. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATAREQUEST_FAIL_ERROR);
  151. }
  152. return ro;
  153. }
  154. /**
  155. * 作文提交
  156. */
  157. public static Object parseAddCompositionInfo(String str) {
  158. ResultObject ro = new ResultObject();
  159. try {
  160. Map<String, Object> map = JSON.parseObject(str);
  161. Boolean flag = (Boolean) map.get("cpsBln");
  162. ro.result = flag;
  163. } catch (Exception e) {
  164. e.printStackTrace();
  165. ro.result = false;
  166. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATAREQUEST_FAIL_ERROR);
  167. }
  168. return ro;
  169. }
  170. /**
  171. * 提交满意or不满意
  172. */
  173. public static Object parseAttentionType(String str) {
  174. ResultObject ro = new ResultObject();
  175. try {
  176. Map<String, Object> map = JSON.parseObject(str);
  177. Boolean flag = (Boolean) map.get("result");
  178. if (flag == true) {
  179. ro.result = true;
  180. } else {
  181. ro.result = false;
  182. ro.obj = map.get("reason");
  183. }
  184. } catch (Exception e) {
  185. e.printStackTrace();
  186. ro.result = false;
  187. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATA_EXCEPTION_ERROR);
  188. }
  189. return ro;
  190. }
  191. /**
  192. * 更新学生信息
  193. */
  194. public static Object parseUpdateStudent(String str) {
  195. ResultObject ro = new ResultObject();
  196. try {
  197. Map<String, Object> map = JSON.parseObject(str);
  198. Boolean flag = (Boolean) map.get("cpsBln");
  199. ro.result = flag;
  200. } catch (Exception e) {
  201. e.printStackTrace();
  202. ro.result = false;
  203. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATA_EXCEPTION_ERROR);
  204. }
  205. return ro;
  206. }
  207. /**
  208. * 更新老师信息
  209. */
  210. public static Object parseUpdateTeacher(String str) {
  211. ResultObject ro = new ResultObject();
  212. try {
  213. Map<String, Object> map = JSON.parseObject(str);
  214. Boolean flag = (Boolean) map.get("cpsBln");
  215. ro.result = flag;
  216. } catch (Exception e) {
  217. e.printStackTrace();
  218. ro.result = false;
  219. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATA_EXCEPTION_ERROR);
  220. }
  221. return ro;
  222. }
  223. /**
  224. * 老师是否可以认领问题
  225. */
  226. public static Object parseIsQuestionClaim(String str) {
  227. ResultObject ro = new ResultObject();
  228. try {
  229. Map<String, Object> map = JSON.parseObject(str);
  230. Boolean flag = (Boolean) map.get("cpsBln");
  231. ro.result = flag;
  232. } catch (Exception e) {
  233. e.printStackTrace();
  234. ro.result = false;
  235. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATA_EXCEPTION_ERROR);
  236. }
  237. return ro;
  238. }
  239. /**
  240. * 教师放弃问题
  241. */
  242. public static Object parseIsQuestionAccept(String str) {
  243. ResultObject ro = new ResultObject();
  244. try {
  245. Map<String, Object> map = JSON.parseObject(str);
  246. Boolean flag = (Boolean) map.get("cpsBln");
  247. ro.result = flag;
  248. } catch (Exception e) {
  249. e.printStackTrace();
  250. ro.result = false;
  251. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATA_EXCEPTION_ERROR);
  252. }
  253. return ro;
  254. }
  255. /**
  256. * 教师“我的回答”
  257. */
  258. public static Object parseTeacherAnswerList(String str) {
  259. ResultObject ro = new ResultObject();
  260. try {
  261. Map<String, Object> map = JSON.parseObject(str);
  262. Boolean flag = (Boolean) map.get("cpsBln");
  263. ro.result = flag;
  264. } catch (Exception e) {
  265. e.printStackTrace();
  266. ro.result = false;
  267. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATA_EXCEPTION_ERROR);
  268. }
  269. return ro;
  270. }
  271. /**
  272. * 问题提交
  273. */
  274. public static Object parseAddQuesionInfo(String str) {
  275. ResultObject ro = new ResultObject();
  276. try {
  277. Map<String, Object> map = JSON.parseObject(str);
  278. Boolean flag = (Boolean) map.get("cpsBln");
  279. ro.result = flag;
  280. } catch (Exception e) {
  281. e.printStackTrace();
  282. ro.result = false;
  283. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATA_EXCEPTION_ERROR);
  284. }
  285. return ro;
  286. }
  287. /**
  288. * 我的教师-我的收藏
  289. */
  290. public static Object parseMyCollect(String str) {
  291. ResultObject ro = new ResultObject();
  292. try {
  293. JSONObject json = JSON.parseObject(str);
  294. boolean success = json.getBooleanValue("result");
  295. if(success) {
  296. ArrayList<TeacherCollectInfo> list = new ArrayList<TeacherCollectInfo>();
  297. JSONArray sJsonArray = json.getJSONArray("mcollect");
  298. for (Object object : sJsonArray) {
  299. list.add(new TeacherCollectInfo().parser((JSONObject) object));
  300. }
  301. ro.result = true;
  302. ro.obj = list;
  303. } else {
  304. ro.result = false;
  305. }
  306. } catch (Exception e) {
  307. e.printStackTrace();
  308. ro.result = false;
  309. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATA_EXCEPTION_ERROR);
  310. }
  311. return ro;
  312. }
  313. /**
  314. * 我的家教-我的收藏—删除选中
  315. */
  316. public static Object parseDeleteStudentCollect(String str) {
  317. ResultObject ro = new ResultObject();
  318. try {
  319. JSONObject json = JSON.parseObject(str);
  320. boolean success = json.getBooleanValue("result");
  321. ro.result = success;
  322. } catch (Exception e) {
  323. e.printStackTrace();
  324. ro.result = false;
  325. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATA_EXCEPTION_ERROR);
  326. }
  327. return ro;
  328. }
  329. /**
  330. * 解答问题
  331. */
  332. public static Object parserTeacherAnswerQuestion(String str) {
  333. ResultObject ro = new ResultObject();
  334. try {
  335. JSONObject json = JSON.parseObject(str);
  336. ro.result = json.getBooleanValue("cpsBln");
  337. } catch (Exception e) {
  338. e.printStackTrace();
  339. ro.result = false;
  340. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATA_EXCEPTION_ERROR);
  341. }
  342. return ro;
  343. }
  344. /**
  345. * 学生查看问题内容
  346. */
  347. public static Object parserStudentLookQuestion(String str) {
  348. ResultObject ro = new ResultObject();
  349. try {
  350. JSONObject json = JSON.parseObject(str);
  351. ro.result = true;
  352. ro.obj = new StudentLookQuestionInfo().parser(json);
  353. } catch (Exception e) {
  354. e.printStackTrace();
  355. ro.result = false;
  356. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATA_EXCEPTION_ERROR);
  357. }
  358. return ro;
  359. }
  360. /**
  361. * 我的家教
  362. */
  363. public static Object parserMyHomeTeacher(String str) {
  364. ResultObject ro = new ResultObject();
  365. try {
  366. JSONObject json = JSON.parseObject(str);
  367. JSONObject jsonInfo = json.getJSONObject("myinfo");
  368. ro.result = true;
  369. ro.obj = new MyTeacher().parser(jsonInfo);
  370. } catch (Exception e) {
  371. e.printStackTrace();
  372. ro.result = false;
  373. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATA_EXCEPTION_ERROR);
  374. }
  375. return ro;
  376. }
  377. /**
  378. * 我的家教-我的老师
  379. */
  380. public static Object parserMyTeacherList(String str) {
  381. ResultObject ro = new ResultObject();
  382. try {
  383. JSONObject json = JSON.parseObject(str);
  384. boolean success = json.getBooleanValue("result");
  385. if(success) {
  386. JSONArray jsonArray = json.getJSONArray("mteachers");
  387. ArrayList<MyTeacherListItemInfo> list = new ArrayList<MyTeacherListItemInfo>();
  388. for (Object object : jsonArray) {
  389. list.add(new MyTeacherListItemInfo().parser((JSONObject) object));
  390. }
  391. ro.result = true;
  392. ro.obj = list;
  393. } else {
  394. ro.result = false;
  395. }
  396. } catch (Exception e) {
  397. e.printStackTrace();
  398. ro.result = false;
  399. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATA_EXCEPTION_ERROR);
  400. }
  401. return ro;
  402. }
  403. /**
  404. * 我的家教-我的通知
  405. */
  406. public static Object parserMyTeacherNotification(String str) {
  407. ResultObject ro = new ResultObject();
  408. try {
  409. JSONObject json = JSON.parseObject(str);
  410. boolean success = json.getBooleanValue("result");
  411. if(success) {
  412. JSONArray jsonArray = json.getJSONArray("inform");
  413. ArrayList<MyTeacherNotificationInfo> list = new ArrayList<MyTeacherNotificationInfo>();
  414. for (Object object : jsonArray) {
  415. list.add(new MyTeacherNotificationInfo().parser((JSONObject) object));
  416. }
  417. ro.result = true;
  418. ro.obj = list;
  419. } else {
  420. ro.result = false;
  421. }
  422. } catch (Exception e) {
  423. e.printStackTrace();
  424. ro.result = false;
  425. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATA_EXCEPTION_ERROR);
  426. }
  427. return ro;
  428. }
  429. /**
  430. * 我的教室
  431. */
  432. public static Object parserMyClassroom(String str) {
  433. ResultObject ro = new ResultObject();
  434. try {
  435. JSONObject json = JSON.parseObject(str);
  436. boolean success = json.getBooleanValue("result");
  437. if(success) {
  438. ro.result = true;
  439. ro.obj = new MyClassroom().parser(json.getJSONObject("classroom"));
  440. } else {
  441. ro.result = false;
  442. }
  443. } catch (Exception e) {
  444. e.printStackTrace();
  445. ro.result = false;
  446. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATA_EXCEPTION_ERROR);
  447. }
  448. return ro;
  449. }
  450. /**
  451. * 老师 账户
  452. */
  453. public static Object parserTeacherAccount(String str) {
  454. ResultObject ro = new ResultObject();
  455. try {
  456. JSONObject json = JSON.parseObject(str);
  457. boolean success = json.getBooleanValue("result");
  458. if(success) {
  459. ro.result = true;
  460. ro.obj = new TeacherAccount().parser(json.getJSONObject("account"));
  461. } else {
  462. ro.result = false;
  463. ro.obj = json.getString("reason");
  464. }
  465. } catch (Exception e) {
  466. e.printStackTrace();
  467. ro.result = false;
  468. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATA_EXCEPTION_ERROR);
  469. }
  470. return ro;
  471. }
  472. /**
  473. * 我的家教-我的消费
  474. */
  475. public static Object parserMyConsumption(String str) {
  476. ResultObject ro = new ResultObject();
  477. try {
  478. JSONObject json = JSON.parseObject(str);
  479. boolean success = json.getBooleanValue("result");
  480. if(success) {
  481. ro.result = true;
  482. ro.obj = new MyConsumptionInfo().parser(json);
  483. } else {
  484. ro.result = false;
  485. ro.obj = json.getString("reason");
  486. }
  487. } catch (Exception e) {
  488. e.printStackTrace();
  489. ro.result = false;
  490. ro.obj = ErrorMessage.getErrorInfo(ErrorMessage.DATA_EXCEPTION_ERROR);
  491. }
  492. return ro;
  493. }
  494. }