CommunityManagerController.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package com.zoniot.ccrc.controller.system;
  2. import com.zoniot.ccrc.commom.model.AjaxMessage;
  3. import com.zoniot.ccrc.commom.model.Pagination;
  4. import com.zoniot.ccrc.commom.model.ResultStatus;
  5. import com.zoniot.ccrc.commom.utils.UserUtil;
  6. import com.zoniot.ccrc.dto.BuildingSelectDto;
  7. import com.zoniot.ccrc.dto.CommunityDto;
  8. import com.zoniot.ccrc.dto.LoginUser;
  9. import com.zoniot.ccrc.entity.Community;
  10. import com.zoniot.ccrc.service.CommunityService;
  11. import io.swagger.annotations.Api;
  12. import io.swagger.annotations.ApiOperation;
  13. import io.swagger.annotations.ApiParam;
  14. import org.apache.commons.lang3.StringUtils;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.security.access.prepost.PreAuthorize;
  17. import org.springframework.stereotype.Controller;
  18. import org.springframework.validation.annotation.Validated;
  19. import org.springframework.web.bind.annotation.*;
  20. import java.util.List;
  21. @Controller
  22. @ResponseBody
  23. @RequestMapping("system/community")
  24. @Api(tags = "小区管理")
  25. public class CommunityManagerController {
  26. @Autowired
  27. CommunityService communityService;
  28. @GetMapping("getAreaTree")
  29. @ApiOperation(value = "获取区域树形列表")
  30. public AjaxMessage<List<BuildingSelectDto>> getAreaTree() {
  31. List<BuildingSelectDto> list = communityService.getAreaTree();
  32. return new AjaxMessage<>(ResultStatus.OK, list);
  33. }
  34. @GetMapping("queryCommunity")
  35. @ApiOperation(value = "查询小区")
  36. public AjaxMessage<List<CommunityDto>> queryCommunity(
  37. @ApiParam(value = "小区名称", required = false) @RequestParam(required = false) String name,
  38. @ApiParam(value = "省", required = false) @RequestParam(required = false) Integer province,
  39. @ApiParam(value = "市", required = false) @RequestParam(required = false) Integer city,
  40. @ApiParam(value = "区", required = false) @RequestParam(required = false) Integer region,
  41. @ApiParam(value = "小区", required = false) @RequestParam(required = false) Integer communityId,
  42. @ApiParam(value = "机构", required = false) @RequestParam(required = false) Integer orgId) {
  43. // 1,判断用户的站点信息
  44. LoginUser loginUser = UserUtil.getCurrentUser();
  45. Community param = new Community();
  46. param.setSiteId(loginUser.getSiteId());
  47. param.setProvince(province);
  48. param.setCity(city);
  49. param.setCity(city);
  50. param.setRegion(region);
  51. param.setId(communityId);
  52. param.setCustomerId(loginUser.getCustomerId());
  53. if(StringUtils.isNotBlank(name)) {
  54. param.setName("%"+name+"%");
  55. }
  56. param.setOrgId(orgId);
  57. List<CommunityDto> list = communityService.queryCommunity(param);
  58. return new AjaxMessage<>(ResultStatus.OK, list);
  59. }
  60. @GetMapping("getCommunityPage")
  61. @ApiOperation(value = "获取小区列表分页", notes = "权限:sys:community:query")
  62. public AjaxMessage<Pagination<CommunityDto>> getCommunityPage(
  63. @ApiParam(value = "小区名称", required = false) @RequestParam(required = false) String communityName,
  64. @ApiParam(value = "省", required = false) @RequestParam(required = false) Integer province,
  65. @ApiParam(value = "市", required = false) @RequestParam(required = false) Integer city,
  66. @ApiParam(value = "区", required = false) @RequestParam(required = false) Integer region,
  67. @ApiParam(value = "机构", required = false) @RequestParam(required = false) Integer orgId,
  68. @ApiParam(value = "页数,非必传,默认第一页", required = false, defaultValue = "1") @RequestParam(required = false, defaultValue = "1") int pageNum,
  69. @ApiParam(value = "条数,非必传,默认15条", required = false, defaultValue = "15") @RequestParam(required = false, defaultValue = "15") int pageSize
  70. ) {
  71. Pagination<CommunityDto> pageInfo = communityService.getCommunityPage(StringUtils.trim(communityName), province, city, region,orgId, pageNum, pageSize);
  72. return new AjaxMessage<>(ResultStatus.OK, pageInfo);
  73. }
  74. @PostMapping("add")
  75. @ApiOperation(value = "添加小区", notes = "权限:sys:community:add")
  76. //@PreAuthorize("hasAuthority('sys:community:add')")
  77. public AjaxMessage addCommunity(
  78. @ApiParam(value = "小区", required = true) @RequestBody(required = true) @Validated CommunityDto communityDto
  79. ) {
  80. communityService.addCommunity(communityDto);
  81. return new AjaxMessage(ResultStatus.OK);
  82. }
  83. @PutMapping("edit")
  84. @ApiOperation(value = "编辑小区", notes = "权限:sys:community:edit")
  85. //@PreAuthorize("hasAuthority('sys:community:edit')")
  86. public AjaxMessage editCommunity(
  87. @ApiParam(value = "小区", required = true) @RequestBody(required = true) @Validated Community community
  88. ) {
  89. communityService.editCommunity(community);
  90. return new AjaxMessage(ResultStatus.OK);
  91. }
  92. @DeleteMapping("delete")
  93. @ApiOperation(value = "删除小区", notes = "权限: sys:community:del")
  94. @PreAuthorize("hasAuthority('sys:community:del')")
  95. public AjaxMessage deleteCommunity(
  96. @ApiParam(value = "小区Id", required = true) @RequestParam(required = true) Integer communityId
  97. ) {
  98. communityService.deleteCommunity(communityId);
  99. return new AjaxMessage(ResultStatus.OK);
  100. }
  101. @GetMapping("getOrgCommunity")
  102. @ApiOperation(value = "获取机构小区")
  103. public AjaxMessage getOrgCommunity(
  104. @ApiParam(value = "小区Id") @RequestParam(required = false) Integer orgId,
  105. @ApiParam(value = "区域Id") @RequestParam(required = false) Integer areaId
  106. ) {
  107. List<Community>communities=communityService.getOrgCommunity(orgId,areaId);
  108. return new AjaxMessage(ResultStatus.OK,communities);
  109. }
  110. }