b84e433f9a273b3ff5ab4c0c3dd2c65531cb6828.svn-base 24 KB

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