TbNoticesController.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package com.pj.project.tb_notices;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import com.pj.constants.UserTypeEnum;
  4. import com.pj.current.satoken.StpUserUtil;
  5. import com.pj.project4sp.SP;
  6. import com.pj.utils.sg.AjaxError;
  7. import com.pj.utils.sg.AjaxJson;
  8. import com.pj.utils.so.SoMap;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.transaction.annotation.Transactional;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import org.springframework.web.bind.annotation.RestController;
  13. import java.util.List;
  14. /**
  15. * Controller: tb_notices -- 消息表
  16. *
  17. * @author lzm
  18. */
  19. @RestController
  20. @RequestMapping("/TbNotices/")
  21. public class TbNoticesController {
  22. /**
  23. * 底层 Service 对象
  24. */
  25. @Autowired
  26. TbNoticesService tbNoticesService;
  27. /**
  28. * 增
  29. */
  30. @RequestMapping("add")
  31. @SaCheckPermission(TbNotices.PERMISSION_CODE)
  32. @Transactional(rollbackFor = Exception.class)
  33. public AjaxJson add(TbNotices t) {
  34. tbNoticesService.add(t);
  35. t = tbNoticesService.getById(SP.publicMapper.getPrimarykey());
  36. return AjaxJson.getSuccessData(t);
  37. }
  38. /**
  39. * 删
  40. */
  41. @RequestMapping("delete")
  42. @SaCheckPermission(TbNotices.PERMISSION_CODE)
  43. public AjaxJson delete(Long id) {
  44. int line = tbNoticesService.delete(id);
  45. return AjaxJson.getByLine(line);
  46. }
  47. /**
  48. * 删 - 根据id列表
  49. */
  50. @RequestMapping("deleteByIds")
  51. @SaCheckPermission(TbNotices.PERMISSION_CODE)
  52. public AjaxJson deleteByIds() {
  53. List<Long> ids = SoMap.getRequestSoMap().getListByComma("ids", long.class);
  54. int line = SP.publicMapper.deleteByIds(TbNotices.TABLE_NAME, ids);
  55. return AjaxJson.getByLine(line);
  56. }
  57. /**
  58. * 改
  59. */
  60. @RequestMapping("update")
  61. @SaCheckPermission(TbNotices.PERMISSION_CODE)
  62. public AjaxJson update(TbNotices t) {
  63. int line = tbNoticesService.update(t);
  64. return AjaxJson.getByLine(line);
  65. }
  66. /**
  67. * 查 - 根据id
  68. */
  69. @RequestMapping("getById")
  70. public AjaxJson getById(Long id) {
  71. TbNotices t = tbNoticesService.getById(id);
  72. return AjaxJson.getSuccessData(t);
  73. }
  74. /**
  75. * 查集合 - 根据条件(参数为空时代表忽略指定条件)
  76. */
  77. @RequestMapping("getList")
  78. public AjaxJson getList() {
  79. SoMap so = SoMap.getRequestSoMap();
  80. String currentCustomerId = StpUserUtil.getCustomerId();
  81. if (!currentCustomerId.equals(UserTypeEnum.PLATFORM_ADMIN.getCustomerId())) {
  82. so.put("customerId", currentCustomerId);
  83. }
  84. List<TbNotices> list = tbNoticesService.getList(so.startPage());
  85. return AjaxJson.getPageData(so.getDataCount(), list);
  86. }
  87. // ------------------------- 前端接口 -------------------------
  88. /**
  89. * 改 - 不传不改 [G]
  90. */
  91. @RequestMapping("updateByNotNull")
  92. public AjaxJson updateByNotNull(Long id) {
  93. AjaxError.throwBy(true, "如需正常调用此接口,请删除此行代码");
  94. // 鉴别身份,是否为数据创建者
  95. long userId = SP.publicMapper.getColumnByIdToLong(TbNotices.TABLE_NAME, "user_id", id);
  96. AjaxError.throwBy(userId != StpUserUtil.getLoginIdAsLong(), "此数据您无权限修改");
  97. // 开始修改 (请只保留需要修改的字段)
  98. SoMap so = SoMap.getRequestSoMap();
  99. so.clearNotIn("id", "businessId", "customerId", "title", "content", "receiverType", "type", "updateTime").clearNull().humpToLineCase();
  100. int line = SP.publicMapper.updateBySoMapById(TbNotices.TABLE_NAME, so, id);
  101. return AjaxJson.getByLine(line);
  102. }
  103. }