package com.zoniot.ccrc.controller.system; import com.zoniot.ccrc.commom.model.AjaxMessage; import com.zoniot.ccrc.commom.model.Pagination; import com.zoniot.ccrc.commom.model.ResultStatus; import com.zoniot.ccrc.commom.utils.UserUtil; import com.zoniot.ccrc.dto.BuildingSelectDto; import com.zoniot.ccrc.dto.CommunityDto; import com.zoniot.ccrc.dto.LoginUser; import com.zoniot.ccrc.entity.Community; import com.zoniot.ccrc.service.CommunityService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.List; @Controller @ResponseBody @RequestMapping("system/community") @Api(tags = "小区管理") public class CommunityManagerController { @Autowired CommunityService communityService; @GetMapping("getAreaTree") @ApiOperation(value = "获取区域树形列表") public AjaxMessage> getAreaTree() { List list = communityService.getAreaTree(); return new AjaxMessage<>(ResultStatus.OK, list); } @GetMapping("queryCommunity") @ApiOperation(value = "查询小区") public AjaxMessage> queryCommunity( @ApiParam(value = "小区名称", required = false) @RequestParam(required = false) String name, @ApiParam(value = "省", required = false) @RequestParam(required = false) Integer province, @ApiParam(value = "市", required = false) @RequestParam(required = false) Integer city, @ApiParam(value = "区", required = false) @RequestParam(required = false) Integer region, @ApiParam(value = "小区", required = false) @RequestParam(required = false) Integer communityId, @ApiParam(value = "机构", required = false) @RequestParam(required = false) Integer orgId) { // 1,判断用户的站点信息 LoginUser loginUser = UserUtil.getCurrentUser(); Community param = new Community(); param.setSiteId(loginUser.getSiteId()); param.setProvince(province); param.setCity(city); param.setCity(city); param.setRegion(region); param.setId(communityId); param.setCustomerId(loginUser.getCustomerId()); if(StringUtils.isNotBlank(name)) { param.setName("%"+name+"%"); } param.setOrgId(orgId); List list = communityService.queryCommunity(param); return new AjaxMessage<>(ResultStatus.OK, list); } @GetMapping("getCommunityPage") @ApiOperation(value = "获取小区列表分页", notes = "权限:sys:community:query") public AjaxMessage> getCommunityPage( @ApiParam(value = "小区名称", required = false) @RequestParam(required = false) String communityName, @ApiParam(value = "省", required = false) @RequestParam(required = false) Integer province, @ApiParam(value = "市", required = false) @RequestParam(required = false) Integer city, @ApiParam(value = "区", required = false) @RequestParam(required = false) Integer region, @ApiParam(value = "机构", required = false) @RequestParam(required = false) Integer orgId, @ApiParam(value = "页数,非必传,默认第一页", required = false, defaultValue = "1") @RequestParam(required = false, defaultValue = "1") int pageNum, @ApiParam(value = "条数,非必传,默认15条", required = false, defaultValue = "15") @RequestParam(required = false, defaultValue = "15") int pageSize ) { Pagination pageInfo = communityService.getCommunityPage(StringUtils.trim(communityName), province, city, region,orgId, pageNum, pageSize); return new AjaxMessage<>(ResultStatus.OK, pageInfo); } @PostMapping("add") @ApiOperation(value = "添加小区", notes = "权限:sys:community:add") //@PreAuthorize("hasAuthority('sys:community:add')") public AjaxMessage addCommunity( @ApiParam(value = "小区", required = true) @RequestBody(required = true) @Validated CommunityDto communityDto ) { communityService.addCommunity(communityDto); return new AjaxMessage(ResultStatus.OK); } @PutMapping("edit") @ApiOperation(value = "编辑小区", notes = "权限:sys:community:edit") //@PreAuthorize("hasAuthority('sys:community:edit')") public AjaxMessage editCommunity( @ApiParam(value = "小区", required = true) @RequestBody(required = true) @Validated Community community ) { communityService.editCommunity(community); return new AjaxMessage(ResultStatus.OK); } @DeleteMapping("delete") @ApiOperation(value = "删除小区", notes = "权限: sys:community:del") @PreAuthorize("hasAuthority('sys:community:del')") public AjaxMessage deleteCommunity( @ApiParam(value = "小区Id", required = true) @RequestParam(required = true) Integer communityId ) { communityService.deleteCommunity(communityId); return new AjaxMessage(ResultStatus.OK); } @GetMapping("getOrgCommunity") @ApiOperation(value = "获取机构小区") public AjaxMessage getOrgCommunity( @ApiParam(value = "小区Id") @RequestParam(required = false) Integer orgId, @ApiParam(value = "区域Id") @RequestParam(required = false) Integer areaId ) { Listcommunities=communityService.getOrgCommunity(orgId,areaId); return new AjaxMessage(ResultStatus.OK,communities); } }