2322977d03b272d7fce225d8d6cd3c1ab3979785.svn-base 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. package com.yihu.jkedu.action;
  2. import javax.servlet.http.HttpServletRequest;
  3. import javax.servlet.http.HttpServletResponse;
  4. import net.sf.json.JSONArray;
  5. import net.sf.json.JSONObject;
  6. import org.apache.commons.lang.StringUtils;
  7. import org.springframework.stereotype.Controller;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import com.yihu.base.ConfigUtil;
  10. import com.yihu.base.Constant;
  11. import com.yihu.utils.ApiUtil;
  12. import com.yihu.utils.StringUtil;
  13. import com.yihu.wsgw.api.ServiceBus;
  14. @Controller
  15. @RequestMapping("/behavior")
  16. public class BehaviorControl
  17. { /**
  18. * @Title: cancelBehavior
  19. * @Description: 取消点赞
  20. * @param @param request
  21. * @param @param response
  22. * @param @throws Exception 设定文件
  23. * @return void 返回类型
  24. * @throws
  25. */
  26. @RequestMapping(value = "/cancelBehavior")
  27. public void cancelBehavior(HttpServletRequest request,
  28. HttpServletResponse response) throws Exception {
  29. try {
  30. response.setContentType("application/json;charset=UTF-8");
  31. String articleId = StringUtil.isEmpty(request.getParameter("articleId")) ? null : request.getParameter("articleId");
  32. String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId");
  33. if(StringUtil.isEmpty(userId)){
  34. response.getWriter().write(ApiUtil.jsonResult(-10000, "用户userId不能为空").toString());
  35. return;
  36. }
  37. if(StringUtil.isEmpty(articleId)){
  38. response.getWriter().write(ApiUtil.jsonResult(-10000, "文章articleId不能为空").toString());
  39. return;
  40. }
  41. JSONObject params = new JSONObject();
  42. params.put("articleId", articleId);
  43. params.put("userId", userId);
  44. String result = ServiceBus.getInstance(
  45. null,
  46. ConfigUtil.getInstance().getAppId()).call(
  47. "JkEdu.Behavior.cancelBehavior", params.toString(), false);
  48. JSONObject formResultObj = JSONObject.fromObject(result);
  49. int code = formResultObj.getInt("Code");
  50. String msg = formResultObj.getString("Message");
  51. JSONObject resultJson = new JSONObject();
  52. if (code == 10000) {// 成功
  53. resultJson.put("Code", 10000);
  54. resultJson.put("Message", msg);
  55. }else{
  56. resultJson.put("Code", code);
  57. resultJson.put("Message", msg);
  58. }
  59. response.getWriter().write(resultJson.toString());
  60. return;
  61. } catch (Exception e) {
  62. e.printStackTrace();
  63. response.getWriter().write(ApiUtil.jsonResult(-14444, "取消点赞异常").toString());
  64. return;
  65. }
  66. }
  67. /**
  68. * @Title: saveBehavior
  69. * @Description: 保存用户行为记录
  70. * @param @param request
  71. * @param @param response
  72. * @param @throws Exception 设定文件
  73. * @return void 返回类型
  74. * @throws
  75. */
  76. @RequestMapping(value = "/saveBehavior")
  77. public void saveBehavior(HttpServletRequest request,
  78. HttpServletResponse response) throws Exception {
  79. try {
  80. response.setContentType("application/json;charset=UTF-8");
  81. String articleId = StringUtil.isEmpty(request.getParameter("articleId")) ? null : request.getParameter("articleId");
  82. String behaviorAction = StringUtil.isEmpty(request.getParameter("behaviorAction")) ? null : request.getParameter("behaviorAction");
  83. String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId");
  84. if(StringUtil.isEmpty(userId)){
  85. response.getWriter().write(ApiUtil.jsonResult(-10000, "用户userId不能为空").toString());
  86. return;
  87. }
  88. if(StringUtil.isEmpty(articleId)){
  89. response.getWriter().write(ApiUtil.jsonResult(-10000, "文章id不能为空").toString());
  90. return;
  91. }
  92. if(StringUtil.isEmpty(behaviorAction)){
  93. response.getWriter().write(ApiUtil.jsonResult(-10000, "用户的行为类型不能为空").toString());
  94. return;
  95. }
  96. String cName=null;
  97. JSONObject userparams = new JSONObject();
  98. userparams.put("userId", userId);
  99. String userresult = ServiceBus.getInstance(
  100. null,
  101. ConfigUtil.getInstance().getAppId()).call(
  102. "UserMgmt.User.queryUserInfoByID", userparams.toString(), false);
  103. JSONObject userResultObj = JSONObject.fromObject(userresult);
  104. int userCode=userResultObj.getInt("Code");
  105. String usermsg=userResultObj.getString("Message");
  106. if(userCode ==10000){
  107. JSONObject arrform = userResultObj.getJSONObject("Result");
  108. if(null!=arrform && arrform.size()>0){
  109. cName=arrform.getString("CName");
  110. if(StringUtil.isEmpty(cName)){
  111. response.getWriter().write(ApiUtil.jsonResult(-10000, "获取不了用户信息").toString());
  112. return;
  113. }
  114. }else{
  115. response.getWriter().write(ApiUtil.jsonResult(-10000, "获取不了用户信息").toString());
  116. return;
  117. }
  118. }else{
  119. response.getWriter().write(ApiUtil.jsonResult(-10000, "获取不了用户信息").toString());
  120. return;
  121. }
  122. JSONObject params = new JSONObject();
  123. params.put("articleId", articleId);
  124. params.put("behaviorAction", behaviorAction);
  125. params.put("userId", userId);
  126. params.put("cName", cName);
  127. String result = ServiceBus.getInstance(
  128. null,
  129. ConfigUtil.getInstance().getAppId()).call(
  130. "JkEdu.Behavior.saveBehavior", params.toString(), false);
  131. JSONObject formResultObj = JSONObject.fromObject(result);
  132. int code = formResultObj.getInt("Code");
  133. String msg = formResultObj.getString("Message");
  134. JSONObject resultJson = new JSONObject();
  135. if (code == 10000) {// 成功
  136. resultJson.put("Code", 10000);
  137. resultJson.put("Message", msg);
  138. }else{
  139. resultJson.put("Code", -10000);
  140. resultJson.put("Message", msg);
  141. }
  142. response.getWriter().write(resultJson.toString());
  143. return;
  144. } catch (Exception e) {
  145. e.printStackTrace();
  146. response.getWriter().write(ApiUtil.jsonResult(-14444, "保存用户的行为记录异常").toString());
  147. return;
  148. }
  149. }
  150. /**
  151. * @Title: cancelArticle
  152. * @Description: 取消收藏
  153. * @param @param request
  154. * @param @param response
  155. * @param @throws Exception 设定文件
  156. * @return void 返回类型
  157. * @throws
  158. */
  159. @RequestMapping(value = "/cancelArticle")
  160. public void cancelArticle(HttpServletRequest request,
  161. HttpServletResponse response) throws Exception {
  162. try {
  163. response.setContentType("application/json;charset=UTF-8");
  164. String articleId = StringUtil.isEmpty(request.getParameter("articleId")) ? null : request.getParameter("articleId");
  165. String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId");
  166. if(StringUtil.isEmpty(userId)){
  167. response.getWriter().write(ApiUtil.jsonResult(-10000, "用户userId不能为空").toString());
  168. return;
  169. }
  170. if(StringUtil.isEmpty(articleId)){
  171. response.getWriter().write(ApiUtil.jsonResult(-10000, "文章articleId不能为空").toString());
  172. return;
  173. }
  174. JSONObject params = new JSONObject();
  175. params.put("articleId", articleId);
  176. params.put("userType", Constant.USERTYPE_RESIDENT);
  177. params.put("userId", userId);
  178. String result = ServiceBus.getInstance(
  179. null,
  180. ConfigUtil.getInstance().getAppId()).call(
  181. "JkEdu.Behavior.cancelArticleCollection", params.toString(), false);
  182. JSONObject formResultObj = JSONObject.fromObject(result);
  183. int code = formResultObj.getInt("Code");
  184. String msg = formResultObj.getString("Message");
  185. JSONObject resultJson = new JSONObject();
  186. if (code == 10000) {// 成功
  187. resultJson.put("Code", 10000);
  188. resultJson.put("Message", msg);
  189. resultJson.put("articleId", articleId);
  190. }else{
  191. resultJson.put("Code", code);
  192. resultJson.put("Message", msg);
  193. resultJson.put("articleId", articleId);
  194. }
  195. response.getWriter().write(resultJson.toString());
  196. return;
  197. } catch (Exception e) {
  198. e.printStackTrace();
  199. response.getWriter().write(ApiUtil.jsonResult(-14444, "取消收藏异常").toString());
  200. return;
  201. }
  202. }
  203. /**
  204. * @Title: saveArticleCollection
  205. * @Description: 保存收藏
  206. * @param @param request
  207. * @param @param response
  208. * @param @throws Exception 设定文件
  209. * @return void 返回类型
  210. * @throws
  211. */
  212. @RequestMapping(value = "/saveArticleCollection")
  213. public void saveArticleCollection(HttpServletRequest request,
  214. HttpServletResponse response) throws Exception {
  215. try {
  216. response.setContentType("application/json;charset=UTF-8");
  217. String articleId = StringUtil.isEmpty(request.getParameter("articleId")) ? null : request.getParameter("articleId");
  218. String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId");
  219. String articleCategoryId = StringUtil.isEmpty(request.getParameter("articleCategoryId")) ? null : request.getParameter("articleCategoryId");
  220. String articleCategoryName = StringUtil.isEmpty(request.getParameter("articleCategoryName")) ? null : request.getParameter("articleCategoryName");
  221. if(StringUtil.isEmpty(userId)){
  222. response.getWriter().write(ApiUtil.jsonResult(-10000, "用户userId不能为空").toString());
  223. return;
  224. }
  225. if(StringUtil.isEmpty(articleId)){
  226. response.getWriter().write(ApiUtil.jsonResult(-10000, "文章articleId不能为空").toString());
  227. return;
  228. }
  229. if(StringUtil.isEmpty(articleCategoryId)){
  230. response.getWriter().write(ApiUtil.jsonResult(-10000, "文章articleCategoryId不能为空").toString());
  231. return;
  232. }
  233. if(StringUtil.isEmpty(articleCategoryName)){
  234. response.getWriter().write(ApiUtil.jsonResult(-10000, "文章articleCategoryName不能为空").toString());
  235. return;
  236. }
  237. String cName=null;
  238. JSONObject userparams = new JSONObject();
  239. userparams.put("userId", userId);
  240. String userresult = ServiceBus.getInstance(
  241. null,
  242. ConfigUtil.getInstance().getAppId()).call(
  243. "UserMgmt.User.queryUserInfoByID", userparams.toString(), false);
  244. JSONObject userResultObj = JSONObject.fromObject(userresult);
  245. int userCode=userResultObj.getInt("Code");
  246. String usermsg=userResultObj.getString("Message");
  247. if(userCode ==10000){
  248. JSONObject arrform = userResultObj.getJSONObject("Result");
  249. if(null!=arrform && arrform.size()>0){
  250. cName=arrform.getString("CName");
  251. if(StringUtil.isEmpty(cName)){
  252. response.getWriter().write(ApiUtil.jsonResult(-10000, "获取不了用户信息").toString());
  253. return;
  254. }
  255. }else{
  256. response.getWriter().write(ApiUtil.jsonResult(-10000, "获取不了用户信息").toString());
  257. return;
  258. }
  259. }else{
  260. response.getWriter().write(ApiUtil.jsonResult(-10000, "获取不了用户信息").toString());
  261. return;
  262. }
  263. JSONObject params = new JSONObject();
  264. params.put("articleId", articleId);
  265. params.put("userType", Constant.USERTYPE_RESIDENT);
  266. params.put("userId", userId);
  267. params.put("cName", cName);
  268. params.put("articleCategoryId", articleCategoryId);
  269. params.put("articleCategoryName", articleCategoryName);
  270. String result = ServiceBus.getInstance(
  271. null,
  272. ConfigUtil.getInstance().getAppId()).call(
  273. "JkEdu.Behavior.saveArticleCollection", params.toString(), false);
  274. JSONObject formResultObj = JSONObject.fromObject(result);
  275. int code = formResultObj.getInt("Code");
  276. String msg = formResultObj.getString("Message");
  277. JSONObject resultJson = new JSONObject();
  278. if (code == 10000) {// 成功
  279. resultJson.put("Code", 10000);
  280. resultJson.put("Message", msg);
  281. }else{
  282. resultJson.put("Code", -10000);
  283. resultJson.put("Message", msg);
  284. }
  285. response.getWriter().write(resultJson.toString());
  286. return;
  287. } catch (Exception e) {
  288. e.printStackTrace();
  289. response.getWriter().write(ApiUtil.jsonResult(-14444, "保存收藏异常").toString());
  290. return;
  291. }
  292. }
  293. /**
  294. * @Title: getArticleCommentList
  295. * @Description: 查看评价
  296. * @param @param request
  297. * @param @param response
  298. * @param @throws Exception 设定文件
  299. * @return void 返回类型
  300. * @throws
  301. */
  302. @RequestMapping(value = "/getArticleCommentList")
  303. public void getArticleCommentList(HttpServletRequest request,
  304. HttpServletResponse response) throws Exception {
  305. try {
  306. response.setContentType("application/json;charset=UTF-8");
  307. String articleId = StringUtil.isEmpty(request.getParameter("articleId")) ? null : request.getParameter("articleId");
  308. int pageSize = StringUtil.isEmpty(request.getParameter("pageSize")) ? 0 : Integer.valueOf(request.getParameter("pageSize"));
  309. int pageIndex = StringUtil.isEmpty(request.getParameter("pageIndex")) ? 0 : Integer.valueOf(request.getParameter("pageIndex"));
  310. if(StringUtil.isEmpty(articleId)){
  311. response.getWriter().write(ApiUtil.jsonResult(-10000, "articleId参数不能为空").toString());
  312. return;
  313. }
  314. JSONObject params = new JSONObject();
  315. params.put("pageSize", pageSize);
  316. params.put("pageIndex", pageIndex);
  317. params.put("articleId", articleId);
  318. String formResult = ServiceBus.getInstance(
  319. null,
  320. ConfigUtil.getInstance().getAppId()).call(
  321. "JkEdu.Behavior.getArticleCommentList", params.toString(), false);
  322. JSONObject resultJson = new JSONObject();
  323. JSONObject formResultObj = JSONObject.fromObject(formResult);
  324. int code = formResultObj.getInt("Code");
  325. String msg = formResultObj.getString("Message");
  326. if (code == 10000) {// 成功
  327. int Count=formResultObj.getInt("Count");
  328. if(Count>0){
  329. JSONArray arrt=formResultObj.getJSONArray("Result");
  330. resultJson.put("Code", 10000);
  331. resultJson.put("Message", msg);
  332. resultJson.put("Result", arrt);
  333. resultJson.put("Count", Count);
  334. response.getWriter().write(resultJson.toString());
  335. return ;
  336. }else{
  337. resultJson.put("Code", 10000);
  338. resultJson.put("Message", msg);
  339. resultJson.put("Result", null);
  340. resultJson.put("Count", Count);
  341. response.getWriter().write(resultJson.toString());
  342. return ;
  343. }
  344. }
  345. resultJson.put("Code", -10000);
  346. resultJson.put("Message", msg);
  347. resultJson.put("Result", null);
  348. response.getWriter().write(resultJson.toString());
  349. return ;
  350. } catch (Exception e) {
  351. e.printStackTrace();
  352. response.getWriter().write(ApiUtil.jsonResult(-14444, "获取文章列表异常").toString());
  353. return ;
  354. }
  355. }
  356. /**
  357. * @Title: saveArticleComment
  358. * @Description: 保存用户评价
  359. * @param @param request
  360. * @param @param response
  361. * @param @throws Exception 设定文件
  362. * @return void 返回类型
  363. * @throws
  364. */
  365. @RequestMapping(value = "/saveArticleComment")
  366. public void saveArticleComment(HttpServletRequest request,
  367. HttpServletResponse response) throws Exception {
  368. try {
  369. response.setContentType("application/json;charset=UTF-8");
  370. String userId = StringUtil.isEmpty(request.getParameter("userId")) ? null : request.getParameter("userId");
  371. String commentContent = StringUtil.isEmpty(request.getParameter("commentContent")) ? null : request.getParameter("commentContent");
  372. String articleId = StringUtil.isEmpty(request.getParameter("articleId")) ? null : request.getParameter("articleId");
  373. if(StringUtil.isEmpty(userId)){
  374. response.getWriter().write(ApiUtil.jsonResult(-10000, "用户userId不能为空").toString());
  375. return;
  376. }
  377. if(StringUtil.isEmpty(commentContent)){
  378. response.getWriter().write(ApiUtil.jsonResult(-10000, "评价内容不能为空").toString());
  379. return;
  380. }
  381. if(StringUtil.isEmpty(articleId)){
  382. response.getWriter().write(ApiUtil.jsonResult(-10000, "文章id不能为空").toString());
  383. return;
  384. }
  385. String cName=null;
  386. String PhotoUri=null;
  387. JSONObject userparams = new JSONObject();
  388. userparams.put("userId", userId);
  389. String userresult = ServiceBus.getInstance(
  390. null,
  391. ConfigUtil.getInstance().getAppId()).call(
  392. "UserMgmt.User.queryUserInfoByID", userparams.toString(), false);
  393. JSONObject userResultObj = JSONObject.fromObject(userresult);
  394. int userCode=userResultObj.getInt("Code");
  395. String usermsg=userResultObj.getString("Message");
  396. if(userCode ==10000){
  397. JSONObject arrform = userResultObj.getJSONObject("Result");
  398. if(null!=arrform && arrform.size()>0){
  399. cName=arrform.getString("CName");
  400. PhotoUri=arrform.getString("PhotoUri");
  401. if(StringUtil.isEmpty(cName)){
  402. response.getWriter().write(ApiUtil.jsonResult(-10000, "获取不了用户信息").toString());
  403. return;
  404. }
  405. }else{
  406. response.getWriter().write(ApiUtil.jsonResult(-10000, "获取不了用户信息").toString());
  407. return;
  408. }
  409. }else{
  410. response.getWriter().write(ApiUtil.jsonResult(-10000, "获取不了用户信息").toString());
  411. return;
  412. }
  413. JSONObject params = new JSONObject();
  414. String result = ServiceBus.getInstance(
  415. null,
  416. ConfigUtil.getInstance().getAppId()).call(
  417. "JkEdu.ConfigSys.getConfigSys", params.toString(), false);
  418. JSONObject formResultObj = JSONObject.fromObject(result);
  419. int code = formResultObj.getInt("Code");
  420. String msg = formResultObj.getString("Message");
  421. JSONObject resultjson = new JSONObject();
  422. if (code == 10000) {// 成功
  423. JSONArray array=formResultObj.getJSONArray("Result");
  424. if(null!=array && array.size()>0){
  425. JSONObject json=array.getJSONObject(0);
  426. if(null !=json){
  427. int switchType=json.getInt("switchType");
  428. int switchState=json.getInt("switchState");
  429. if(switchType==1 && switchState==1){
  430. JSONObject articleparams = new JSONObject();
  431. articleparams.put("articleId", articleId);
  432. articleparams.put("commentContent", commentContent);
  433. articleparams.put("cName", cName);
  434. articleparams.put("userId", userId);
  435. if(StringUtils.isNotEmpty(PhotoUri)){
  436. articleparams.put("userImg", PhotoUri);
  437. }
  438. String articleresult = ServiceBus.getInstance(
  439. null,
  440. ConfigUtil.getInstance().getAppId()).call(
  441. "JkEdu.Behavior.saveArticleComment", articleparams.toString(), false);
  442. JSONObject articleresultObj = JSONObject.fromObject(articleresult);
  443. int articleCode = articleresultObj.getInt("Code");
  444. String articlemsg = articleresultObj.getString("Message");
  445. if(articleCode == 10000){
  446. resultjson.put("Code", 10000);
  447. resultjson.put("Message", articlemsg);
  448. response.getWriter().write(resultjson.toString());
  449. return ;
  450. }else{
  451. resultjson.put("Code", -10000);
  452. resultjson.put("Message", articlemsg);
  453. response.getWriter().write(resultjson.toString());
  454. return ;
  455. }
  456. }else if(switchType==1 && switchState==2){
  457. response.getWriter().write(ApiUtil.jsonResult(-10000, "用户不能评价该文章").toString());
  458. return;
  459. }
  460. }else{
  461. response.getWriter().write(ApiUtil.jsonResult(-10000, "未设置评价配置").toString());
  462. return;
  463. }
  464. }else{
  465. response.getWriter().write(ApiUtil.jsonResult(-10000, "未设置评价配置").toString());
  466. return;
  467. }
  468. }else{
  469. resultjson.put("Code", -10000);
  470. resultjson.put("Message", msg);
  471. response.getWriter().write(resultjson.toString());
  472. return;
  473. }
  474. } catch (Exception e) {
  475. e.printStackTrace();
  476. response.getWriter().write(ApiUtil.jsonResult(-14444, "保存用户的评价异常").toString());
  477. return;
  478. }
  479. }
  480. }