diff --git a/src/main/java/cn/com/tenlion/usercenter/controller/app/api/userexpand/UserExpandAppController.java b/src/main/java/cn/com/tenlion/usercenter/controller/app/api/userexpand/UserExpandAppController.java index 4540329..c97521d 100644 --- a/src/main/java/cn/com/tenlion/usercenter/controller/app/api/userexpand/UserExpandAppController.java +++ b/src/main/java/cn/com/tenlion/usercenter/controller/app/api/userexpand/UserExpandAppController.java @@ -1,5 +1,7 @@ package cn.com.tenlion.usercenter.controller.app.api.userexpand; +import cn.com.tenlion.usercenter.pojo.dtos.userexpand.CountAreaGridMemberDTO; +import cn.com.tenlion.usercenter.pojo.dtos.userexpand.CountGridMemberDTO; import cn.com.tenlion.usercenter.pojo.dtos.userexpand.OnlineGridMemberDTO; import cn.com.tenlion.usercenter.pojo.dtos.userexpand.UserExpandDTO; import cn.com.tenlion.usercenter.pojo.vos.userexpand.UserExpandVO; @@ -10,11 +12,13 @@ import ink.wgink.interfaces.consts.ISystemConstant; import ink.wgink.pojo.dtos.user.UserDTO; import ink.wgink.pojo.result.ErrorResult; import ink.wgink.pojo.result.SuccessResult; +import ink.wgink.pojo.result.SuccessResultData; import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.List; +import java.util.Map; /** * @ClassName: UserExpandController @@ -83,4 +87,42 @@ public class UserExpandAppController extends DefaultBaseController { return userExpandService.listOnlineGridMemberReleaseByAreaCode(areaCode); } + @ApiOperation(value = "通过角色ID和区域编码统计用户", notes = "通过角色ID和区域编码统计用户") + @ApiImplicitParams({ + @ApiImplicitParam(name = "roleId", value = "角色ID", paramType = "path", required = true), + @ApiImplicitParam(name = "areaCode", value = "地区编码", paramType = "path", required = true) + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("count/role-id/{roleId}/area-code-like/{areaCodeLike}") + public SuccessResultData countByRoleIdAndAreaCode(@PathVariable("roleId") String roleId, + @PathVariable("areaCodeLike") String areaCodeLike) { + Integer count = userExpandService.countByRoleIdAndAreaCode(roleId, areaCodeLike); + return new SuccessResultData<>(count); + } + + @ApiOperation(value = "通过区域编码统计网格员角色用户", notes = "通过区域编码统计网格员角色用户") + @ApiImplicitParams({ + @ApiImplicitParam(name = "areaCode", value = "地区编码", paramType = "path", required = true) + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("count-grid-member/area-code-like/{areaCode}") + public SuccessResultData countGridMemberByAreaCode(@RequestHeader("token") String token, + @PathVariable("areaCode") String areaCode) { + CountGridMemberDTO countGridMemberDTO = userExpandService.countGridMemberUserByAreaCode(areaCode); + return new SuccessResultData<>(countGridMemberDTO); + } + + @ApiOperation(value = "通过区域编码统计下级区域网格员角色用户", notes = "通过区域编码统计网格员角色用户") + @ApiImplicitParams({ + @ApiImplicitParam(name = "areaCode", value = "地区编码", paramType = "path", required = true) + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("count-sub-area-grid-member/area-code/{areaCode}") + public SuccessResultData> countSubAreaGridMemberByAreaCode(@RequestHeader("token") String token, + @PathVariable("areaCode") String areaCode) { + List countSubAreaGridMemberByAreaCodes = userExpandService.listCountSubAreaGridMemberByAreaCode(areaCode); + return new SuccessResultData<>(countSubAreaGridMemberByAreaCodes); + } + + } \ No newline at end of file diff --git a/src/main/java/cn/com/tenlion/usercenter/pojo/dtos/userexpand/CountAreaGridMemberDTO.java b/src/main/java/cn/com/tenlion/usercenter/pojo/dtos/userexpand/CountAreaGridMemberDTO.java new file mode 100644 index 0000000..0b61c52 --- /dev/null +++ b/src/main/java/cn/com/tenlion/usercenter/pojo/dtos/userexpand/CountAreaGridMemberDTO.java @@ -0,0 +1,71 @@ +package cn.com.tenlion.usercenter.pojo.dtos.userexpand; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.apache.poi.ss.formula.functions.Count; + +@ApiModel +public class CountAreaGridMemberDTO implements Comparable { + + @ApiModelProperty(name = "areaId", value = "区域ID") + private String areaId; + @ApiModelProperty(name = "areaCode", value = "区域编码") + private String areaCode; + @ApiModelProperty(name = "areaName", value = "区域名") + private String areaName; + @ApiModelProperty(name = "total", value = "总数") + private Integer total; + + public CountAreaGridMemberDTO() { + } + + public CountAreaGridMemberDTO(String areaId, String areaCode, String areaName, Integer total) { + this.areaId = areaId; + this.areaCode = areaCode; + this.areaName = areaName; + this.total = total; + } + + public String getAreaId() { + return areaId; + } + + public void setAreaId(String areaId) { + this.areaId = areaId; + } + + public String getAreaCode() { + return areaCode; + } + + public void setAreaCode(String areaCode) { + this.areaCode = areaCode; + } + + public String getAreaName() { + return areaName; + } + + public void setAreaName(String areaName) { + this.areaName = areaName; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + @Override + public int compareTo(CountAreaGridMemberDTO o) { + if (this.getTotal().compareTo(o.getTotal()) > 0) { + return -1; + } + if (this.getTotal().compareTo(o.getTotal()) < 0) { + return 1; + } + return 0; + } +} diff --git a/src/main/java/cn/com/tenlion/usercenter/pojo/dtos/userexpand/CountGridMemberDTO.java b/src/main/java/cn/com/tenlion/usercenter/pojo/dtos/userexpand/CountGridMemberDTO.java new file mode 100644 index 0000000..6686740 --- /dev/null +++ b/src/main/java/cn/com/tenlion/usercenter/pojo/dtos/userexpand/CountGridMemberDTO.java @@ -0,0 +1,38 @@ +package cn.com.tenlion.usercenter.pojo.dtos.userexpand; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel +public class CountGridMemberDTO { + + @ApiModelProperty(name = "count", value = "数量") + private Integer count; + @ApiModelProperty(name = "total;", value = "总数") + private Integer total; + + public CountGridMemberDTO() { + } + + public CountGridMemberDTO(Integer count, Integer total) { + this.count = count; + this.total = total; + } + + public Integer getCount() { + return count; + } + + public void setCount(Integer count) { + this.count = count; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + +} diff --git a/src/main/java/cn/com/tenlion/usercenter/service/userexpand/IUserExpandService.java b/src/main/java/cn/com/tenlion/usercenter/service/userexpand/IUserExpandService.java index 99dfb72..2720624 100644 --- a/src/main/java/cn/com/tenlion/usercenter/service/userexpand/IUserExpandService.java +++ b/src/main/java/cn/com/tenlion/usercenter/service/userexpand/IUserExpandService.java @@ -1,18 +1,16 @@ package cn.com.tenlion.usercenter.service.userexpand; -import cn.com.tenlion.usercenter.pojo.dtos.userexpand.GridUserAuthBindDTO; -import cn.com.tenlion.usercenter.pojo.dtos.userexpand.OnlineGridMemberDTO; -import cn.com.tenlion.usercenter.pojo.dtos.userexpand.UserExpandDTO; +import cn.com.tenlion.usercenter.pojo.dtos.userexpand.*; import cn.com.tenlion.usercenter.pojo.pos.userexpand.UserExpandPO; import cn.com.tenlion.usercenter.pojo.vos.userexpand.GridUserAuthBindVO; import cn.com.tenlion.usercenter.pojo.vos.userexpand.UserExpandVO; import ink.wgink.interfaces.user.IUserExpandBaseService; import ink.wgink.pojo.ListPage; import ink.wgink.pojo.dtos.user.UserDTO; -import ink.wgink.pojo.result.SuccessResultData; import ink.wgink.pojo.result.SuccessResultList; import java.util.List; +import java.util.Map; /** * @ClassName: IUserExpandService @@ -118,4 +116,7 @@ public interface IUserExpandService extends IUserExpandBaseService listCountSubAreaGridMemberByAreaCode(String areaCode); } diff --git a/src/main/java/cn/com/tenlion/usercenter/service/userexpand/impl/UserExpandServiceImpl.java b/src/main/java/cn/com/tenlion/usercenter/service/userexpand/impl/UserExpandServiceImpl.java index 9620974..a29f9c5 100644 --- a/src/main/java/cn/com/tenlion/usercenter/service/userexpand/impl/UserExpandServiceImpl.java +++ b/src/main/java/cn/com/tenlion/usercenter/service/userexpand/impl/UserExpandServiceImpl.java @@ -5,9 +5,7 @@ import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts; import cn.com.tenlion.usercenter.dao.userexpand.IUserExpandDao; import cn.com.tenlion.usercenter.manager.HuaWeiSMCManager; import cn.com.tenlion.usercenter.pojo.dtos.remote.huawei.SMCMeetingDTO; -import cn.com.tenlion.usercenter.pojo.dtos.userexpand.GridUserAuthBindDTO; -import cn.com.tenlion.usercenter.pojo.dtos.userexpand.OnlineGridMemberDTO; -import cn.com.tenlion.usercenter.pojo.dtos.userexpand.UserExpandDTO; +import cn.com.tenlion.usercenter.pojo.dtos.userexpand.*; import cn.com.tenlion.usercenter.pojo.pos.userexpand.UserExpandPO; import cn.com.tenlion.usercenter.pojo.vos.userexpand.GridUserAuthBindVO; import cn.com.tenlion.usercenter.pojo.vos.userexpand.UserExpandVO; @@ -21,11 +19,13 @@ import ink.wgink.exceptions.SearchException; import ink.wgink.interfaces.department.IDepartmentBaseService; import ink.wgink.interfaces.department.IDepartmentUserBaseService; import ink.wgink.interfaces.role.IRoleUserBaseService; +import ink.wgink.module.dictionary.pojo.dtos.AreaDTO; import ink.wgink.module.dictionary.pojo.dtos.DataDTO; import ink.wgink.module.instantmessage.websocket.manager.WebSocketChannelManager; import ink.wgink.module.map.pojo.dtos.grid.GridDTO; import ink.wgink.module.map.service.grid.IGridRelationService; import ink.wgink.module.map.service.grid.IGridService; +import ink.wgink.mongo.module.dictionary.service.IMongoAreaService; import ink.wgink.mongo.module.dictionary.service.IMongoDataService; import ink.wgink.pojo.ListPage; import ink.wgink.pojo.dtos.department.DepartmentDTO; @@ -45,10 +45,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; /** @@ -78,6 +75,8 @@ public class UserExpandServiceImpl extends DefaultBaseService implements IUserEx @Autowired private IGridService gridService; @Autowired + private IMongoAreaService mongoAreaService; + @Autowired private IMongoDataService mongoDataService; @Autowired private PasswordEncoder passwordEncoder; @@ -493,6 +492,28 @@ public class UserExpandServiceImpl extends DefaultBaseService implements IUserEx return count == null ? 0 : count; } + @Override + public CountGridMemberDTO countGridMemberUserByAreaCode(String areaCode) { + String areaCodeLike = WStringUtil.cutContinuityRepeatCharDesc(areaCode, '0', 3); + Integer gridMember = countByRoleIdAndAreaCode(paramsConfigProperties.getRoleGridMember(), areaCodeLike); + Integer totalGridMember = countByRoleIdAndGridCode(paramsConfigProperties.getRoleGridMember(), null); + return new CountGridMemberDTO(gridMember, totalGridMember); + } + + @Override + public List listCountSubAreaGridMemberByAreaCode(String areaCode) { + AreaDTO areaDTO = mongoAreaService.getByCode(areaCode); + if (areaDTO == null) { + return new ArrayList<>(); + } + List areaDTOS = mongoAreaService.listByParentId(areaDTO.getAreaId()); + return areaDTOS.parallelStream().map(subArea -> { + String areaCodeLike = WStringUtil.cutContinuityRepeatCharDesc(subArea.getAreaCode(), '0', 3); + Integer gridMember = countByRoleIdAndAreaCode(paramsConfigProperties.getRoleGridMember(), areaCodeLike); + return new CountAreaGridMemberDTO(subArea.getAreaId(), subArea.getAreaCode(), subArea.getAreaName(), gridMember); + }).sorted().collect(Collectors.toList()); + } + /** * 设置用户 * diff --git a/src/main/resources/mybatis/mapper/user-expand/user-expand-mapper.xml b/src/main/resources/mybatis/mapper/user-expand/user-expand-mapper.xml index b75d810..7d49d3b 100644 --- a/src/main/resources/mybatis/mapper/user-expand/user-expand-mapper.xml +++ b/src/main/resources/mybatis/mapper/user-expand/user-expand-mapper.xml @@ -327,9 +327,9 @@ sue.user_id = su.user_id su.is_delete = 0 - + AND - area_code LIKE CONCAT(#{areaCodeLike}, '%') + area_code = #{areaCode} AND