PersonController.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. package com.iden.bms.controller;
  2. import com.baomidou.mybatisplus.core.metadata.IPage;
  3. import com.iden.bms.service.PersonService;
  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.PersonStaVO;
  12. import com.iden.common.vo.PersonVO;
  13. import com.iden.common.vo.PageReqVO;
  14. import com.iden.common.vo.UserLoginedConvertVO;
  15. import io.swagger.annotations.*;
  16. import lombok.extern.slf4j.Slf4j;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.web.bind.annotation.*;
  19. import org.springframework.web.multipart.MultipartFile;
  20. import javax.servlet.http.HttpServletRequest;
  21. import javax.servlet.http.HttpServletResponse;
  22. import java.util.List;
  23. /**
  24. * @Author: lilt
  25. * @Date: 2021/5/26
  26. * @Desc:
  27. */
  28. @RestController
  29. @Api(value = "PersonController", tags = { "人员管理" })
  30. @Slf4j
  31. @RequestMapping("/bms/person")
  32. @Permission
  33. public class PersonController {
  34. @Autowired
  35. private PersonService personService;
  36. @GetMapping("/getPersonStaVO")
  37. @ApiOperation(value = "查询人员统计值 ")
  38. @ApiImplicitParams(value = {
  39. @ApiImplicitParam(paramType = "query", name = "type", value = "类型:1、重点人员,2、小区人员"),
  40. @ApiImplicitParam(paramType = "query", name = "nameOrCred", value = "名称/身份证"),
  41. @ApiImplicitParam(paramType = "query", name = "district", value = "所属区域"),
  42. @ApiImplicitParam(paramType = "query", name = "subdistrict", value = "所属街道"),
  43. @ApiImplicitParam(paramType = "query", name = "communityId", value = "小区ID"),
  44. @ApiImplicitParam(paramType = "query", name = "crowdId", value = "人群id"),
  45. @ApiImplicitParam(paramType = "query", name = "address", value = "详细地址"),
  46. @ApiImplicitParam(paramType = "query", name = "gender", value = "性别:M:男 W:女"),
  47. @ApiImplicitParam(paramType = "query", name = "populationType", value = "人口类型:1:常住人口 2:暂住人口 3:境外长住人口 4:流动人口 5:寄住人口 6: 临时住宿人口 99其他")
  48. })
  49. public Result<PersonStaVO> getPersonStaVO(HttpServletRequest request, @RequestHeader(value = "token") String token,
  50. @RequestParam(value = "type", required = true) String type,
  51. @RequestParam(value = "nameOrCred", required = false) String nameOrCred,
  52. @RequestParam(value = "district", required = false) String district,
  53. @RequestParam(value = "subdistrict", required = false) String subdistrict,
  54. @RequestParam(value = "communityId", required = false) Long communityId,
  55. @RequestParam(value = "crowdId", required = false) Long crowdId,
  56. @RequestParam(value = "address", required = false) String address,
  57. @RequestParam(value = "gender", required = false) String gender,
  58. @RequestParam(value = "populationType", required = false) String populationType){
  59. try {
  60. UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request);
  61. PersonStaVO personStaVO = this.personService.getPersonStaVO(type,nameOrCred,district,subdistrict,communityId,crowdId,address,gender,populationType,loginUser );
  62. return Result.success("查询成功!",personStaVO);
  63. }catch (BDException e) {
  64. log.error("查询人员统计值-出现异常",e);
  65. return PageResult.error(e.getMessage());
  66. } catch (Exception e) {
  67. log.error("小区管理: 查询人员统计值出现异常",e);
  68. return PageResult.error( "获取数据失败");
  69. }
  70. }
  71. @GetMapping("/listPerson")
  72. @ApiOperation(value = "人员列表分页 ")
  73. @ApiImplicitParams(value = {
  74. @ApiImplicitParam(paramType = "query", name = "type", value = "类型:1、重点人员,2、小区人员"),
  75. @ApiImplicitParam(paramType = "query", name = "nameOrCred", value = "名称/身份证"),
  76. @ApiImplicitParam(paramType = "query", name = "district", value = "所属区域"),
  77. @ApiImplicitParam(paramType = "query", name = "subdistrict", value = "所属街道"),
  78. @ApiImplicitParam(paramType = "query", name = "communityId", value = "小区ID"),
  79. @ApiImplicitParam(paramType = "query", name = "crowdId", value = "人群id"),
  80. @ApiImplicitParam(paramType = "query", name = "address", value = "详细地址"),
  81. @ApiImplicitParam(paramType = "query", name = "gender", value = "性别:M:男 W:女"),
  82. @ApiImplicitParam(paramType = "query", name = "populationType", value = "人口类型:1:常住人口 2:暂住人口 3:境外长住人口 4:流动人口 5:寄住人口 6: 临时住宿人口 99其他")
  83. })
  84. public PageResult<List<PersonVO>> listPerson(HttpServletRequest request, @RequestHeader(value = "token") String token,
  85. @RequestParam(value = "type", required = true) String type,
  86. @RequestParam(value = "nameOrCred", required = false) String nameOrCred,
  87. @RequestParam(value = "district", required = false) String district,
  88. @RequestParam(value = "subdistrict", required = false) String subdistrict,
  89. @RequestParam(value = "communityId", required = false) Long communityId,
  90. @RequestParam(value = "crowdId", required = false) Long crowdId,
  91. @RequestParam(value = "address", required = false) String address,
  92. @RequestParam(value = "gender", required = false) String gender,
  93. @RequestParam(value = "populationType", required = false) String populationType,
  94. PageReqVO pageReqVo){
  95. try {
  96. UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request);
  97. IPage<PersonVO> pageResponse = this.personService.listPerson(type,nameOrCred,district,subdistrict,communityId,crowdId,address,gender,populationType,loginUser ,pageReqVo);
  98. return PageResult.success(pageResponse.getRecords(),pageResponse.getCurrent(),pageResponse.getSize(),pageResponse.getTotal());
  99. }catch (BDException e) {
  100. log.error("人员列表查询-分页列表出现异常",e);
  101. return PageResult.error(e.getMessage());
  102. } catch (Exception e) {
  103. log.error("人员管理: 人员列表查询出现异常",e);
  104. return PageResult.error( "获取列表失败");
  105. }
  106. }
  107. /**
  108. * 导出列表
  109. * @param
  110. * @return
  111. */
  112. @ApiOperation(value = "导出Excel")
  113. @ApiImplicitParams(value = {
  114. @ApiImplicitParam(paramType = "query", name = "type", value = "类型:1、重点人员,2、小区人员"),
  115. @ApiImplicitParam(paramType = "query", name = "nameOrCred", value = "名称/身份证"),
  116. @ApiImplicitParam(paramType = "query", name = "district", value = "所属区域"),
  117. @ApiImplicitParam(paramType = "query", name = "subdistrict", value = "所属街道"),
  118. @ApiImplicitParam(paramType = "query", name = "communityId", value = "小区ID"),
  119. @ApiImplicitParam(paramType = "query", name = "crowdId", value = "人群id"),
  120. @ApiImplicitParam(paramType = "query", name = "address", value = "详细地址"),
  121. @ApiImplicitParam(paramType = "query", name = "gender", value = "性别:M:男 W:女"),
  122. @ApiImplicitParam(paramType = "query", name = "populationType", value = "人口类型:1:常住人口 2:暂住人口 3:境外长住人口 4:流动人口 5:寄住人口 6: 临时住宿人口 99其他")
  123. })
  124. @GetMapping({"/exportToExcel"})
  125. @LogAnnotation(
  126. type = OperateType.EXPORT,
  127. moduleName = "导出人员列表",
  128. description = "导出人员列表"
  129. )
  130. public void exportToExcel(HttpServletRequest request,@RequestHeader(name = "token", required = true) String token,
  131. @RequestParam(value = "type", required = true) String type,
  132. @RequestParam(value = "nameOrCred", required = false) String nameOrCred,
  133. @RequestParam(value = "district", required = false) String district,
  134. @RequestParam(value = "subdistrict", required = false) String subdistrict,
  135. @RequestParam(value = "communityId", required = false) Long communityId,
  136. @RequestParam(value = "crowdId", required = false) Long crowdId,
  137. @RequestParam(value = "address", required = false) String address,
  138. @RequestParam(value = "gender", required = false) String gender,
  139. @RequestParam(value = "populationType", required = false) String populationType,
  140. HttpServletResponse response) {
  141. try {
  142. UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request);
  143. this.personService.exportToExcel(type,nameOrCred,district,subdistrict,communityId,crowdId,address,gender,populationType,loginUser, response);
  144. } catch (BDException e) {
  145. log.error("导出人员列表出现异常",e);
  146. } catch (Exception e) {
  147. log.error("人员管理: 导出人员列表出现异常",e);
  148. }
  149. }
  150. @ApiOperation(value = "导入Excel")
  151. @PostMapping(value = "/importWithExcel", headers = "content-type=multipart/form-data")
  152. public Result<Object> importWithExcel(@RequestParam(value = "file") MultipartFile multipartFile) {
  153. try {
  154. personService.importWithExcel(multipartFile);
  155. return Result.success("导入成功!");
  156. } catch (BDException e) {
  157. log.error("导入人员列表出现异常",e);
  158. return Result.error(e.getMessage());
  159. } catch (Exception e) {
  160. log.error("人员管理: 导入人员列表出现异常",e);
  161. return Result.error("导入人员失败!");
  162. }
  163. }
  164. @ApiOperation(value = "图像上传")
  165. @ApiImplicitParams({
  166. @ApiImplicitParam(name = "token", value = "放在请求头中的令牌",
  167. dataType = "String", paramType = "header",
  168. required = true)
  169. })
  170. @CrossOrigin
  171. @PostMapping(value = "/uploadImage", headers="content-type=multipart/form-data",produces = "application/json;charset=UTF-8")
  172. public Result<String> uploadImage(
  173. @RequestHeader(name = "token") String token,
  174. @ApiParam(value="图像", required=true) MultipartFile file,
  175. @RequestParam(value = "communityId", required = true) Long communityId
  176. ) {
  177. try {
  178. String image = personService.uploadImage(file,communityId);
  179. return Result.success("上传成功!",image);
  180. } catch (BDException e) {
  181. log.error("图像上传出现异常",e);
  182. return Result.error(e.getMessage());
  183. } catch (Exception e) {
  184. log.error("人员管理: 图像上传出现异常",e);
  185. return Result.error("图像上传失败!");
  186. }
  187. }
  188. @PostMapping("/addPerson")
  189. @ApiOperation(value = "新增人员")
  190. @LogAnnotation(
  191. type = OperateType.ADD,
  192. moduleName = "新增人员",
  193. description = "新增人员"
  194. )
  195. public Result<Object> addPerson(HttpServletRequest request,@RequestHeader("token") String token,
  196. @RequestBody PersonVO vo){
  197. try {
  198. UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request);
  199. this.personService.createPerson(vo,loginUser);
  200. return Result.success("新增成功!");
  201. }catch (BDException e) {
  202. log.error("新增人员-出现异常",e);
  203. return Result.error(e.getMessage());
  204. } catch (Exception e) {
  205. log.error("人员管理: 新增人员出现异常",e);
  206. return Result.error("新增失败!");
  207. }
  208. }
  209. @PostMapping("/updatePerson")
  210. @ApiOperation(value = "修改人员")
  211. @LogAnnotation(
  212. type = OperateType.MODIFY,
  213. moduleName = "修改人员",
  214. description = "修改人员"
  215. )
  216. public Result<Object> updatePerson(HttpServletRequest request,@RequestHeader("token") String token,
  217. @RequestBody PersonVO vo){
  218. try {
  219. this.personService.updatePerson(vo);
  220. return Result.success("修改成功!");
  221. }catch (BDException e) {
  222. log.error("修改人员-出现异常",e);
  223. return Result.error(e.getMessage());
  224. } catch (Exception e) {
  225. log.error("人员管理: 修改人员出现异常",e);
  226. return Result.error("修改失败!");
  227. }
  228. }
  229. @GetMapping("/getPersonInfo/{id}")
  230. @ApiOperation(value = "人员详情")
  231. public Result<PersonVO> getPersonInfo(HttpServletRequest request, @RequestHeader("token") String token, @PathVariable("id") Long id){
  232. PersonVO orderInfo = this.personService.getPersonById(id);
  233. return Result.success("查询成功!",orderInfo);
  234. }
  235. @PostMapping("/deletePerson/{id}")
  236. @ApiOperation(value = "删除人员")
  237. @LogAnnotation(
  238. type = OperateType.REMOVE,
  239. moduleName = "删除人员",
  240. description = "删除人员"
  241. )
  242. public Result<Object> deletePerson(HttpServletRequest request,@RequestHeader("token") String token,
  243. @PathVariable("id") Long id){
  244. try {
  245. if( this.personService.deleteById(id)){
  246. return Result.success("删除成功!");
  247. } else {
  248. return Result.error("人员被引用,删除失败!");
  249. }
  250. } catch (Exception e) {
  251. log.error("人员管理: 删除出现异常",e);
  252. return Result.error("删除失败!");
  253. }
  254. }
  255. }