CommunityController.java 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. package com.iden.bms.controller;
  2. import com.baomidou.mybatisplus.core.metadata.IPage;
  3. import com.iden.bms.service.CommunityService;
  4. import com.iden.common.annotation.Permission;
  5. import com.iden.common.exception.BDException;
  6. import com.iden.common.logaspect.LogAnnotation;
  7. import com.iden.common.logaspect.OperateType;
  8. import com.iden.common.util.PageResult;
  9. import com.iden.common.util.Result;
  10. import com.iden.common.util.WebPageUtils;
  11. import com.iden.common.vo.PageReqVO;
  12. import com.iden.common.vo.CommunityVO;
  13. import com.iden.common.vo.UserLoginedConvertVO;
  14. import io.swagger.annotations.Api;
  15. import io.swagger.annotations.ApiImplicitParam;
  16. import io.swagger.annotations.ApiImplicitParams;
  17. import io.swagger.annotations.ApiOperation;
  18. import lombok.extern.slf4j.Slf4j;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.web.bind.annotation.*;
  21. import org.springframework.web.multipart.MultipartFile;
  22. import javax.servlet.http.HttpServletRequest;
  23. import javax.servlet.http.HttpServletResponse;
  24. import java.util.List;
  25. /**
  26. * @Author: lilt
  27. * @Date: 2021/5/26
  28. * @Desc:
  29. */
  30. @RestController
  31. @Api(value = "CommunityController", tags = { "小区管理" })
  32. @Slf4j
  33. @RequestMapping("/bms/community")
  34. @Permission
  35. public class CommunityController {
  36. @Autowired
  37. private CommunityService communityService;
  38. @GetMapping("/countCommunity")
  39. @ApiOperation(value = "当前小区个数查询")
  40. @ApiImplicitParams(value = {
  41. @ApiImplicitParam(paramType = "query", name = "district", value = "所属区域"),
  42. @ApiImplicitParam(paramType = "query", name = "subdistrict", value = "所属街道"),
  43. @ApiImplicitParam(paramType = "query", name = "name", value = "小区名称")
  44. })
  45. public Result<Integer> countCommunity(HttpServletRequest request, @RequestHeader(value = "token") String token,
  46. @RequestParam(value = "district", required = false) String district,
  47. @RequestParam(value = "subdistrict", required = false) String subdistrict,
  48. @RequestParam(value = "name", required = false) String name){
  49. try {
  50. UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request);
  51. Integer count = this.communityService.countCommunity(district,subdistrict,name,loginUser);
  52. return Result.success("查询成功!",count);
  53. }catch (BDException e) {
  54. log.error("当前小区个数查询-出现异常",e);
  55. return PageResult.error(e.getMessage());
  56. } catch (Exception e) {
  57. log.error("小区管理: 当前小区个数查询出现异常",e);
  58. return PageResult.error( "获取数据失败");
  59. }
  60. }
  61. @GetMapping("/listCommunity")
  62. @ApiOperation(value = "小区列表分页 ")
  63. @ApiImplicitParams(value = {
  64. @ApiImplicitParam(paramType = "query", name = "district", value = "所属区域"),
  65. @ApiImplicitParam(paramType = "query", name = "subdistrict", value = "所属街道"),
  66. @ApiImplicitParam(paramType = "query", name = "name", value = "小区名称")
  67. })
  68. public PageResult<List<CommunityVO>> listCommunity(HttpServletRequest request, @RequestHeader(value = "token") String token,
  69. @RequestParam(value = "district", required = false) String district,
  70. @RequestParam(value = "subdistrict", required = false) String subdistrict,
  71. @RequestParam(value = "name", required = false) String name,
  72. PageReqVO pageReqVo){
  73. try {
  74. UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request);
  75. IPage<CommunityVO> pageResponse = this.communityService.listCommunity(district,subdistrict,name,loginUser ,pageReqVo);
  76. return PageResult.success(pageResponse.getRecords(),pageResponse.getCurrent(),pageResponse.getSize(),pageResponse.getTotal());
  77. }catch (BDException e) {
  78. log.error("小区列表查询-分页列表出现异常",e);
  79. return PageResult.error(e.getMessage());
  80. } catch (Exception e) {
  81. log.error("小区管理: 小区列表查询出现异常",e);
  82. return PageResult.error( "获取列表失败");
  83. }
  84. }
  85. /**
  86. * 导出列表
  87. * @param
  88. * @return
  89. */
  90. @ApiOperation(value = "导出Excel")
  91. @ApiImplicitParams(value = {
  92. @ApiImplicitParam(paramType = "query", name = "district", value = "所属区域"),
  93. @ApiImplicitParam(paramType = "query", name = "subdistrict", value = "所属街道"),
  94. @ApiImplicitParam(paramType = "query", name = "name", value = "小区名称")
  95. })
  96. @GetMapping({"/exportToExcel"})
  97. @LogAnnotation(
  98. type = OperateType.EXPORT,
  99. moduleName = "导出小区列表",
  100. description = "导出小区列表"
  101. )
  102. public void exportToExcel(HttpServletRequest request,@RequestHeader(name = "token", required = true) String token,
  103. @RequestParam(value = "district", required = false) String district,
  104. @RequestParam(value = "subdistrict", required = false) String subdistrict,
  105. @RequestParam(value = "name", required = false) String name,
  106. HttpServletResponse response) {
  107. try {
  108. UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request);
  109. this.communityService.exportToExcel(district,subdistrict,name,loginUser ,response);
  110. } catch (BDException e) {
  111. log.error("导出小区列表出现异常",e);
  112. } catch (Exception e) {
  113. log.error("小区管理: 导出小区列表出现异常",e);
  114. }
  115. }
  116. @ApiOperation(value = "导入Excel")
  117. @PostMapping(value = "/importWithExcel", headers = "content-type=multipart/form-data")
  118. public Result<Object> importWithExcel(
  119. @RequestHeader(name = "token") String token,
  120. @RequestParam(value = "file") MultipartFile multipartFile) {
  121. try {
  122. boolean flag = communityService.importWithExcel(multipartFile);
  123. if(flag){
  124. return Result.success("导入成功!");
  125. } else {
  126. return Result.error("导入失败");
  127. }
  128. } catch (BDException e) {
  129. log.error("导入小区列表出现异常",e);
  130. return Result.error(e.getMessage());
  131. } catch (Exception e) {
  132. log.error("小区管理: 导入小区列表出现异常",e);
  133. return Result.error("导入小区失败!");
  134. }
  135. }
  136. @PostMapping("/addCommunity")
  137. @ApiOperation(value = "新增小区")
  138. @LogAnnotation(
  139. type = OperateType.ADD,
  140. moduleName = "新增小区",
  141. description = "新增小区"
  142. )
  143. public Result<Object> addCommunity(HttpServletRequest request,@RequestHeader("token") String token,
  144. @RequestBody CommunityVO vo){
  145. try {
  146. UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request);
  147. int flag = this.communityService.createCommunity(vo,loginUser);
  148. if (flag == 1) {
  149. return Result.error("名称已存在!");
  150. } if (flag == 2) {
  151. return Result.error("编码已存在!");
  152. } else if (flag == 0) {
  153. return Result.success("新增成功!");
  154. } else {
  155. return Result.error("新增失败!");
  156. }
  157. }catch (BDException e) {
  158. log.error("新增小区-出现异常",e);
  159. return Result.error(e.getMessage());
  160. } catch (Exception e) {
  161. log.error("小区管理: 新增小区出现异常",e);
  162. return Result.error("新增失败!");
  163. }
  164. }
  165. @PostMapping("/updateCommunity")
  166. @ApiOperation(value = "修改小区")
  167. @LogAnnotation(
  168. type = OperateType.EDIT,
  169. moduleName = "修改小区",
  170. description = "修改小区"
  171. )
  172. public Result<Object> updateCommunity(HttpServletRequest request,@RequestHeader("token") String token,
  173. @RequestBody CommunityVO vo){
  174. try {
  175. this.communityService.updateCommunity(vo);
  176. return Result.success("修改成功!");
  177. }catch (BDException e) {
  178. log.error("修改小区-出现异常",e);
  179. return Result.error(e.getMessage());
  180. } catch (Exception e) {
  181. log.error("小区管理: 修改小区出现异常",e);
  182. return Result.error("修改失败!");
  183. }
  184. }
  185. @GetMapping("/getCommunityInfo/{id}")
  186. @ApiOperation(value = "小区详情")
  187. public Result<CommunityVO> getCommunityInfo(HttpServletRequest request, @RequestHeader("token") String token, @PathVariable("id") Long id){
  188. CommunityVO orderInfo = this.communityService.getCommunityById(id);
  189. return Result.success("查询成功!",orderInfo);
  190. }
  191. @PostMapping("/deleteCommunity/{id}")
  192. @ApiOperation(value = "删除小区")
  193. @LogAnnotation(
  194. type = OperateType.REMOVE,
  195. moduleName = "删除小区",
  196. description = "删除小区"
  197. )
  198. public Result<Object> deleteCommunity(HttpServletRequest request,@RequestHeader("token") String token,
  199. @PathVariable("id") Long id){
  200. try {
  201. if( this.communityService.deleteById(id)){
  202. return Result.success("删除成功!");
  203. } else {
  204. return Result.error("小区被引用,删除失败!");
  205. }
  206. } catch (Exception e) {
  207. log.error("小区管理: 删除出现异常",e);
  208. return Result.error("删除失败!");
  209. }
  210. }
  211. }