package com.iden.bms.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.iden.bms.service.PersonService; import com.iden.common.annotation.Permission; import com.iden.common.exception.BDException; import com.iden.common.logaspect.LogAnnotation; import com.iden.common.logaspect.OperateType; import com.iden.common.util.PageResult; import com.iden.common.util.Result; import com.iden.common.util.WebPageUtils; import com.iden.common.vo.PersonStaVO; import com.iden.common.vo.PersonVO; import com.iden.common.vo.PageReqVO; import com.iden.common.vo.UserLoginedConvertVO; import io.swagger.annotations.*; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.List; /** * @Author: lilt * @Date: 2021/5/26 * @Desc: */ @RestController @Api(value = "PersonController", tags = { "人员管理" }) @Slf4j @RequestMapping("/bms/person") @Permission public class PersonController { @Autowired private PersonService personService; @GetMapping("/getPersonStaVO") @ApiOperation(value = "查询人员统计值 ") @ApiImplicitParams(value = { @ApiImplicitParam(paramType = "query", name = "type", value = "类型:1、重点人员,2、小区人员"), @ApiImplicitParam(paramType = "query", name = "nameOrCred", value = "名称/身份证"), @ApiImplicitParam(paramType = "query", name = "district", value = "所属区域"), @ApiImplicitParam(paramType = "query", name = "subdistrict", value = "所属街道"), @ApiImplicitParam(paramType = "query", name = "communityId", value = "小区ID"), @ApiImplicitParam(paramType = "query", name = "crowdId", value = "人群id"), @ApiImplicitParam(paramType = "query", name = "address", value = "详细地址"), @ApiImplicitParam(paramType = "query", name = "gender", value = "性别:M:男 W:女"), @ApiImplicitParam(paramType = "query", name = "populationType", value = "人口类型:1:常住人口 2:暂住人口 3:境外长住人口 4:流动人口 5:寄住人口 6: 临时住宿人口 99其他") }) public Result getPersonStaVO(HttpServletRequest request, @RequestHeader(value = "token") String token, @RequestParam(value = "type", required = true) String type, @RequestParam(value = "nameOrCred", required = false) String nameOrCred, @RequestParam(value = "district", required = false) String district, @RequestParam(value = "subdistrict", required = false) String subdistrict, @RequestParam(value = "communityId", required = false) Long communityId, @RequestParam(value = "crowdId", required = false) Long crowdId, @RequestParam(value = "address", required = false) String address, @RequestParam(value = "gender", required = false) String gender, @RequestParam(value = "populationType", required = false) String populationType){ try { UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request); PersonStaVO personStaVO = this.personService.getPersonStaVO(type,nameOrCred,district,subdistrict,communityId,crowdId,address,gender,populationType,loginUser ); return Result.success("查询成功!",personStaVO); }catch (BDException e) { log.error("查询人员统计值-出现异常",e); return PageResult.error(e.getMessage()); } catch (Exception e) { log.error("小区管理: 查询人员统计值出现异常",e); return PageResult.error( "获取数据失败"); } } @GetMapping("/listPerson") @ApiOperation(value = "人员列表分页 ") @ApiImplicitParams(value = { @ApiImplicitParam(paramType = "query", name = "type", value = "类型:1、重点人员,2、小区人员"), @ApiImplicitParam(paramType = "query", name = "nameOrCred", value = "名称/身份证"), @ApiImplicitParam(paramType = "query", name = "district", value = "所属区域"), @ApiImplicitParam(paramType = "query", name = "subdistrict", value = "所属街道"), @ApiImplicitParam(paramType = "query", name = "communityId", value = "小区ID"), @ApiImplicitParam(paramType = "query", name = "crowdId", value = "人群id"), @ApiImplicitParam(paramType = "query", name = "address", value = "详细地址"), @ApiImplicitParam(paramType = "query", name = "gender", value = "性别:M:男 W:女"), @ApiImplicitParam(paramType = "query", name = "populationType", value = "人口类型:1:常住人口 2:暂住人口 3:境外长住人口 4:流动人口 5:寄住人口 6: 临时住宿人口 99其他") }) public PageResult> listPerson(HttpServletRequest request, @RequestHeader(value = "token") String token, @RequestParam(value = "type", required = true) String type, @RequestParam(value = "nameOrCred", required = false) String nameOrCred, @RequestParam(value = "district", required = false) String district, @RequestParam(value = "subdistrict", required = false) String subdistrict, @RequestParam(value = "communityId", required = false) Long communityId, @RequestParam(value = "crowdId", required = false) Long crowdId, @RequestParam(value = "address", required = false) String address, @RequestParam(value = "gender", required = false) String gender, @RequestParam(value = "populationType", required = false) String populationType, PageReqVO pageReqVo){ try { UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request); IPage pageResponse = this.personService.listPerson(type,nameOrCred,district,subdistrict,communityId,crowdId,address,gender,populationType,loginUser ,pageReqVo); return PageResult.success(pageResponse.getRecords(),pageResponse.getCurrent(),pageResponse.getSize(),pageResponse.getTotal()); }catch (BDException e) { log.error("人员列表查询-分页列表出现异常",e); return PageResult.error(e.getMessage()); } catch (Exception e) { log.error("人员管理: 人员列表查询出现异常",e); return PageResult.error( "获取列表失败"); } } /** * 导出列表 * @param * @return */ @ApiOperation(value = "导出Excel") @ApiImplicitParams(value = { @ApiImplicitParam(paramType = "query", name = "type", value = "类型:1、重点人员,2、小区人员"), @ApiImplicitParam(paramType = "query", name = "nameOrCred", value = "名称/身份证"), @ApiImplicitParam(paramType = "query", name = "district", value = "所属区域"), @ApiImplicitParam(paramType = "query", name = "subdistrict", value = "所属街道"), @ApiImplicitParam(paramType = "query", name = "communityId", value = "小区ID"), @ApiImplicitParam(paramType = "query", name = "crowdId", value = "人群id"), @ApiImplicitParam(paramType = "query", name = "address", value = "详细地址"), @ApiImplicitParam(paramType = "query", name = "gender", value = "性别:M:男 W:女"), @ApiImplicitParam(paramType = "query", name = "populationType", value = "人口类型:1:常住人口 2:暂住人口 3:境外长住人口 4:流动人口 5:寄住人口 6: 临时住宿人口 99其他") }) @GetMapping({"/exportToExcel"}) @LogAnnotation( type = OperateType.EXPORT, moduleName = "导出人员列表", description = "导出人员列表" ) public void exportToExcel(HttpServletRequest request,@RequestHeader(name = "token", required = true) String token, @RequestParam(value = "type", required = true) String type, @RequestParam(value = "nameOrCred", required = false) String nameOrCred, @RequestParam(value = "district", required = false) String district, @RequestParam(value = "subdistrict", required = false) String subdistrict, @RequestParam(value = "communityId", required = false) Long communityId, @RequestParam(value = "crowdId", required = false) Long crowdId, @RequestParam(value = "address", required = false) String address, @RequestParam(value = "gender", required = false) String gender, @RequestParam(value = "populationType", required = false) String populationType, HttpServletResponse response) { try { UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request); this.personService.exportToExcel(type,nameOrCred,district,subdistrict,communityId,crowdId,address,gender,populationType,loginUser, response); } catch (BDException e) { log.error("导出人员列表出现异常",e); } catch (Exception e) { log.error("人员管理: 导出人员列表出现异常",e); } } @ApiOperation(value = "导入Excel") @PostMapping(value = "/importWithExcel", headers = "content-type=multipart/form-data") public Result importWithExcel(@RequestParam(value = "file") MultipartFile multipartFile) { try { personService.importWithExcel(multipartFile); return Result.success("导入成功!"); } catch (BDException e) { log.error("导入人员列表出现异常",e); return Result.error(e.getMessage()); } catch (Exception e) { log.error("人员管理: 导入人员列表出现异常",e); return Result.error("导入人员失败!"); } } @ApiOperation(value = "图像上传") @ApiImplicitParams({ @ApiImplicitParam(name = "token", value = "放在请求头中的令牌", dataType = "String", paramType = "header", required = true) }) @CrossOrigin @PostMapping(value = "/uploadImage", headers="content-type=multipart/form-data",produces = "application/json;charset=UTF-8") public Result uploadImage( @RequestHeader(name = "token") String token, @ApiParam(value="图像", required=true) MultipartFile file, @RequestParam(value = "communityId", required = true) Long communityId ) { try { String image = personService.uploadImage(file,communityId); return Result.success("上传成功!",image); } catch (BDException e) { log.error("图像上传出现异常",e); return Result.error(e.getMessage()); } catch (Exception e) { log.error("人员管理: 图像上传出现异常",e); return Result.error("图像上传失败!"); } } @PostMapping("/addPerson") @ApiOperation(value = "新增人员") @LogAnnotation( type = OperateType.ADD, moduleName = "新增人员", description = "新增人员" ) public Result addPerson(HttpServletRequest request,@RequestHeader("token") String token, @RequestBody PersonVO vo){ try { UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request); this.personService.createPerson(vo,loginUser); return Result.success("新增成功!"); }catch (BDException e) { log.error("新增人员-出现异常",e); return Result.error(e.getMessage()); } catch (Exception e) { log.error("人员管理: 新增人员出现异常",e); return Result.error("新增失败!"); } } @PostMapping("/updatePerson") @ApiOperation(value = "修改人员") @LogAnnotation( type = OperateType.MODIFY, moduleName = "修改人员", description = "修改人员" ) public Result updatePerson(HttpServletRequest request,@RequestHeader("token") String token, @RequestBody PersonVO vo){ try { this.personService.updatePerson(vo); return Result.success("修改成功!"); }catch (BDException e) { log.error("修改人员-出现异常",e); return Result.error(e.getMessage()); } catch (Exception e) { log.error("人员管理: 修改人员出现异常",e); return Result.error("修改失败!"); } } @GetMapping("/getPersonInfo/{id}") @ApiOperation(value = "人员详情") public Result getPersonInfo(HttpServletRequest request, @RequestHeader("token") String token, @PathVariable("id") Long id){ PersonVO orderInfo = this.personService.getPersonById(id); return Result.success("查询成功!",orderInfo); } @PostMapping("/deletePerson/{id}") @ApiOperation(value = "删除人员") @LogAnnotation( type = OperateType.REMOVE, moduleName = "删除人员", description = "删除人员" ) public Result deletePerson(HttpServletRequest request,@RequestHeader("token") String token, @PathVariable("id") Long id){ try { if( this.personService.deleteById(id)){ return Result.success("删除成功!"); } else { return Result.error("人员被引用,删除失败!"); } } catch (Exception e) { log.error("人员管理: 删除出现异常",e); return Result.error("删除失败!"); } } }