TpCommunityController.java 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package com.huiju.estateagents.property.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.huiju.estateagents.base.BaseController;
  6. import com.huiju.estateagents.base.ResponseBean;
  7. import com.huiju.estateagents.common.CommConstant;
  8. import io.swagger.annotations.Api;
  9. import io.swagger.annotations.ApiOperation;
  10. import io.swagger.annotations.ApiParam;
  11. import org.slf4j.Logger;
  12. import org.slf4j.LoggerFactory;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.web.bind.annotation.PathVariable;
  15. import org.springframework.web.bind.annotation.RequestBody;
  16. import org.springframework.web.bind.annotation.RequestMapping;
  17. import org.springframework.web.bind.annotation.RequestMethod;
  18. import org.springframework.web.bind.annotation.RequestParam;
  19. import com.huiju.estateagents.property.service.ITpCommunityService;
  20. import com.huiju.estateagents.property.entity.TpCommunity;
  21. import org.springframework.web.bind.annotation.RestController;
  22. import javax.servlet.http.HttpServletRequest;
  23. /**
  24. * <p>
  25. * 前端控制器
  26. * </p>
  27. *
  28. * @author yansen
  29. * @since 2021-01-19
  30. */
  31. @Api(tags = "")
  32. @RestController
  33. @RequestMapping("/api")
  34. public class TpCommunityController extends BaseController {
  35. private final Logger logger = LoggerFactory.getLogger(TpCommunityController.class);
  36. @Autowired
  37. public ITpCommunityService iTpCommunityService;
  38. /**
  39. * 分页查询列表
  40. * @param pageNum
  41. * @param pageSize
  42. * @return
  43. */
  44. @RequestMapping(value="/{client}/tpCommunity",method= RequestMethod.GET)
  45. @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
  46. public ResponseBean tpCommunityList(@ApiParam(value = "客户端", allowableValues = "wx,admin") @PathVariable("client") String client,
  47. @ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
  48. @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
  49. HttpServletRequest request) throws Exception{
  50. IPage<TpCommunity> pg = new Page<>(pageNum, pageSize);
  51. QueryWrapper<TpCommunity> queryWrapper = new QueryWrapper<>();
  52. queryWrapper.eq("org_id", getOrgId(request));
  53. queryWrapper.eq("wx".equals(client), "status", CommConstant.STATUS_NORMAL);
  54. queryWrapper.gt("admin".equals(client), "status", CommConstant.STATUS_DELETE);
  55. queryWrapper.orderByDesc("create_date");
  56. IPage<TpCommunity> result = iTpCommunityService.page(pg, queryWrapper);
  57. return ResponseBean.success(result);
  58. }
  59. /**
  60. * 保存对象
  61. * @param tpCommunity 实体对象
  62. * @return
  63. */
  64. @RequestMapping(value="/admin/tpCommunity",method= RequestMethod.POST)
  65. @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
  66. public ResponseBean tpCommunityAdd(@ApiParam("保存内容") @RequestBody TpCommunity tpCommunity,
  67. HttpServletRequest request) throws Exception{
  68. tpCommunity.setOrgId(getOrgId(request));
  69. if (iTpCommunityService.save(tpCommunity)){
  70. return ResponseBean.success(tpCommunity);
  71. }else {
  72. return ResponseBean.error("保存失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
  73. }
  74. }
  75. /**
  76. * 根据id删除对象
  77. * @param id 实体ID
  78. */
  79. @RequestMapping(value="/admin/tpCommunity/{id}", method= RequestMethod.DELETE)
  80. @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
  81. public ResponseBean tpCommunityDelete(@ApiParam("对象ID") @PathVariable Integer id,
  82. HttpServletRequest request) throws Exception{
  83. TpCommunity tpCommunity = iTpCommunityService.getById(id);
  84. if (null == tpCommunity || CommConstant.STATUS_DELETE.equals(tpCommunity.getStatus())) {
  85. return ResponseBean.error("没有找到对应的社区信息", ResponseBean.ERROR_ILLEGAL_PARAMS);
  86. }
  87. Integer orgId = getOrgId(request);
  88. if (!orgId.equals(tpCommunity.getOrgId())) {
  89. return ResponseBean.error("暂无操作权限", ResponseBean.ERROR_ILLEGAL_PARAMS);
  90. }
  91. tpCommunity.setStatus(CommConstant.STATUS_DELETE);
  92. return tpCommunityUpdate(id, tpCommunity, request);
  93. }
  94. /**
  95. * 修改对象
  96. * @param id 实体ID
  97. * @param tpCommunity 实体对象
  98. * @return
  99. */
  100. @RequestMapping(value="/admin/tpCommunity/{id}",method= RequestMethod.PUT)
  101. @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
  102. public ResponseBean tpCommunityUpdate(@ApiParam("对象ID") @PathVariable Integer id,
  103. @ApiParam("更新内容") @RequestBody TpCommunity tpCommunity,
  104. HttpServletRequest request) throws Exception{
  105. tpCommunity.setId(id);
  106. Integer orgId = getOrgId(request);
  107. if (!orgId.equals(tpCommunity.getOrgId())) {
  108. return ResponseBean.error("暂无操作权限", ResponseBean.ERROR_ILLEGAL_PARAMS);
  109. }
  110. if (iTpCommunityService.updateById(tpCommunity)){
  111. return ResponseBean.success(iTpCommunityService.getById(id));
  112. }else {
  113. return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
  114. }
  115. }
  116. /**
  117. * 根据id查询对象
  118. * @param id 实体ID
  119. */
  120. @RequestMapping(value="/{client}/tpCommunity/{id}",method= RequestMethod.GET)
  121. @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
  122. public ResponseBean tpCommunityGet(@ApiParam(value = "客户端", allowableValues = "wx,admin") @PathVariable("client") String client,
  123. @ApiParam("对象ID") @PathVariable Integer id,
  124. HttpServletRequest request) throws Exception{
  125. TpCommunity tpCommunity = iTpCommunityService.getById(id);
  126. if (null == tpCommunity || CommConstant.STATUS_DELETE.equals(tpCommunity.getStatus())) {
  127. return ResponseBean.error("没有找到对应的社区信息", ResponseBean.ERROR_ILLEGAL_PARAMS);
  128. }
  129. Integer orgId = getOrgId(request);
  130. if (!orgId.equals(tpCommunity.getOrgId())) {
  131. return ResponseBean.error("暂无操作权限", ResponseBean.ERROR_ILLEGAL_PARAMS);
  132. }
  133. return ResponseBean.success(tpCommunity);
  134. }
  135. }