CommentController.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package com.kmall.admin.controller;
  2. import com.kmall.admin.entity.CommentEntity;
  3. import com.kmall.admin.service.CommentService;
  4. import com.kmall.admin.utils.ParamUtils;
  5. import com.kmall.common.utils.PageUtils;
  6. import com.kmall.common.utils.Query;
  7. import com.kmall.common.utils.R;
  8. import org.apache.shiro.authz.annotation.RequiresPermissions;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.web.bind.annotation.*;
  11. import java.util.List;
  12. import java.util.Map;
  13. /**
  14. * Controller
  15. *
  16. * @author Scott
  17. * @email
  18. * @date 2017-08-28 17:03:40
  19. */
  20. @RestController
  21. @RequestMapping("comment")
  22. public class CommentController {
  23. @Autowired
  24. private CommentService commentService;
  25. /**
  26. * 查看列表
  27. */
  28. @RequestMapping("/list")
  29. @RequiresPermissions("comment:list")
  30. public R list(@RequestParam Map<String, Object> params) {
  31. ParamUtils.setQueryPowerByRoleType(params, "storeId", "merchSn", "thirdPartyMerchCode");
  32. String valueName = (String) params.get("valueName");
  33. if(org.apache.commons.lang3.StringUtils.isNotEmpty(valueName)){
  34. try{
  35. valueName = new String(valueName.getBytes("iso-8859-1"),"utf-8");
  36. }catch (Exception e){
  37. e.printStackTrace();
  38. }
  39. params.put("valueName", valueName);
  40. }
  41. String userName = (String) params.get("userName");
  42. if(org.apache.commons.lang3.StringUtils.isNotEmpty(userName)){
  43. try{
  44. userName = new String(userName.getBytes("iso-8859-1"),"utf-8");
  45. }catch (Exception e){
  46. e.printStackTrace();
  47. }
  48. params.put("userName", userName);
  49. }
  50. //查询列表数据
  51. Query query = new Query(params);
  52. List<CommentEntity> commentList = commentService.queryList(query);
  53. int total = commentService.queryTotal(query);
  54. PageUtils pageUtil = new PageUtils(commentList, total, query.getLimit(), query.getPage());
  55. return R.ok().put("page", pageUtil);
  56. }
  57. /**
  58. * 查看信息
  59. */
  60. @RequestMapping("/info/{id}")
  61. @RequiresPermissions("comment:info")
  62. public R info(@PathVariable("id") Integer id) {
  63. CommentEntity comment = commentService.queryObject(id);
  64. return R.ok().put("comment", comment);
  65. }
  66. /**
  67. * 保存
  68. */
  69. @RequestMapping("/save")
  70. @RequiresPermissions("comment:save")
  71. public R save(@RequestBody CommentEntity comment) {
  72. commentService.save(comment);
  73. return R.ok();
  74. }
  75. /**
  76. * 修改
  77. */
  78. @RequestMapping("/update")
  79. @RequiresPermissions("comment:update")
  80. public R update(@RequestBody CommentEntity comment) {
  81. commentService.update(comment);
  82. return R.ok();
  83. }
  84. /**
  85. * 删除
  86. */
  87. @RequestMapping("/delete")
  88. @RequiresPermissions("comment:delete")
  89. public R delete(@RequestBody Integer[] ids) {
  90. commentService.deleteBatch(ids);
  91. return R.ok();
  92. }
  93. /**
  94. * 查看所有列表
  95. */
  96. @RequestMapping("/queryAll")
  97. public R queryAll(@RequestParam Map<String, Object> params) {
  98. List<CommentEntity> list = commentService.queryList(params);
  99. return R.ok().put("list", list);
  100. }
  101. /**
  102. * 修改状态
  103. */
  104. @RequestMapping("/toggleStatus")
  105. @RequiresPermissions("comment:toggleStatus")
  106. public R toggleStatus(@RequestBody CommentEntity comment) {
  107. commentService.toggleStatus(comment);
  108. return R.ok();
  109. }
  110. /**
  111. * 修改状态
  112. */
  113. @RequestMapping("/toggleStatusBatch")
  114. @RequiresPermissions("comment:toggleStatus")
  115. public R toggleStatusBatch(@RequestBody Integer[] ids) {
  116. commentService.toggleStatusBatch(ids);
  117. return R.ok();
  118. }
  119. /**
  120. * 总计
  121. */
  122. @RequestMapping("/queryTotal")
  123. public R queryTotal(@RequestParam Map<String, Object> params) {
  124. int sum = commentService.queryTotal(params);
  125. return R.ok().put("sum", sum);
  126. }
  127. }