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 bb91055..d8b92aa 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 @@ -6,12 +6,15 @@ import cn.com.tenlion.usercenter.service.userexpand.IUserExpandService; import ink.wgink.annotation.CheckRequestBodyAnnotation; import ink.wgink.common.base.DefaultBaseController; 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 io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.List; + /** * @ClassName: UserExpandController * @Description: 用户拓展 @@ -59,4 +62,14 @@ public class UserExpandAppController extends DefaultBaseController { return userExpandService.getWhole(userId); } + @ApiOperation(value = "在线用户列表", notes = "通过区域获取在线用户列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "areaCode", value = "地区编码", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("list-online-release/{areaCode}") + public List listOnlineReleaseByAreaCode(@PathVariable("areaCode") String areaCode) { + return userExpandService.listUserOnlineReleaseByAreaCode(areaCode); + } + } \ No newline at end of file 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 5475c80..b7ad79d 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 @@ -4,6 +4,7 @@ import cn.com.tenlion.usercenter.pojo.dtos.userexpand.UserExpandDTO; import cn.com.tenlion.usercenter.pojo.pos.userexpand.UserExpandPO; import cn.com.tenlion.usercenter.pojo.vos.userexpand.UserExpandVO; import ink.wgink.interfaces.user.IUserExpandBaseService; +import ink.wgink.pojo.dtos.user.UserDTO; import java.util.List; @@ -66,4 +67,12 @@ public interface IUserExpandService extends IUserExpandBaseService listUserOnlineReleaseByAreaCode(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 dae40c4..d3ee517 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 @@ -1,5 +1,6 @@ package cn.com.tenlion.usercenter.service.userexpand.impl; +import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts; import cn.com.tenlion.usercenter.dao.userexpand.IUserExpandDao; import cn.com.tenlion.usercenter.pojo.dtos.userexpand.UserExpandDTO; import cn.com.tenlion.usercenter.pojo.pos.userexpand.UserExpandPO; @@ -12,6 +13,7 @@ import ink.wgink.interfaces.department.IDepartmentUserBaseService; import ink.wgink.interfaces.role.IRoleUserBaseService; import ink.wgink.interfaces.user.IUserBaseService; import ink.wgink.module.dictionary.pojo.dtos.DataDTO; +import ink.wgink.module.instantmessage.websocket.manager.WebSocketChannelManager; import ink.wgink.mongo.module.dictionary.service.IMongoDataService; import ink.wgink.pojo.ListPage; import ink.wgink.pojo.dtos.department.DepartmentDTO; @@ -19,8 +21,10 @@ import ink.wgink.pojo.dtos.department.DepartmentUserDTO; import ink.wgink.pojo.dtos.user.UserDTO; import ink.wgink.pojo.pos.DepartmentPO; import ink.wgink.pojo.result.SuccessResultList; +import ink.wgink.pojo.session.WebSocketSession; import ink.wgink.util.ArrayListUtil; import ink.wgink.util.map.HashMapUtil; +import ink.wgink.util.string.WStringUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -217,6 +221,25 @@ public class UserExpandServiceImpl extends DefaultBaseService implements IUserEx return userExpandDTO; } + @Override + public List listUserOnlineReleaseByAreaCode(String areaCode) { + Map params = getHashMap(2); + params.put("areaCodeLike", WStringUtil.cutContinuityRepeatCharDesc(areaCode, '0', 3)); + List userExpandDTOs = list(params); + if (userExpandDTOs.isEmpty()) { + LOG.debug("area code: {}, user count: 0"); + return new ArrayList<>(); + } + List userIds = ArrayListUtil.listBeanStringIdValue(userExpandDTOs, "userId", UserExpandDTO.class); + List webSocketSessions = WebSocketChannelManager.getInstance().listOnlineUser(userIds, ISmartCityUserCenterConsts.APP_CLIENT_NAME); + List onlineUserIds = new ArrayList<>(); + webSocketSessions.forEach(webSocketSession -> { + onlineUserIds.add(webSocketSession.getUserId()); + }); + LOG.debug("area code: {}, user count: {}, online user count", areaCode, userExpandDTOs.size(), webSocketSessions.size()); + return userBaseService.listByUserIds(onlineUserIds); + } + /** * 设置用户 * diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index e931fb0..0c31fc1 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -27,7 +27,7 @@ spring: max-request-size: 1GB datasource: druid: - url: jdbc:mysql://127.0.0.1:3306/db_smart_city_usercenter?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=UTC&nullCatalogMeansCurrent=true + url: jdbc:mysql://192.168.0.103:3306/db_smart_city_usercenter?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=UTC&nullCatalogMeansCurrent=true db-type: mysql driver-class-name: com.mysql.cj.jdbc.Driver username: root @@ -57,7 +57,7 @@ spring: uri: mongodb://smartcity:smartcity@127.0.0.1:27017/smartcity redis: database: 6 - host: 127.0.0.1 + host: 192.168.0.103 port: 6379 password: 666 timeout: 3000ms @@ -68,7 +68,7 @@ spring: max-idle: 8 min-idle: 0 kafka: - bootstrap-servers: 127.0.0.1:9092 + bootstrap-servers: 192.168.0.103:9092 producer: # 写入失败时,重试次数。当leader节点失效,一个repli节点会替代成为leader节点,此时可能出现写入失败, # 当retris为0时,produce不会重复。retirs重发,此时repli节点完全成为leader节点,不会产生消息丢失。 @@ -111,7 +111,7 @@ file: use-min-io: true # 与use-min-io配套使用 min-io: - endpoint: http://127.0.0.1:9900 + endpoint: http://192.168.0.103:9900 access-key: smartcity secret-key: smartcity diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index da0588f..661b2bd 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -130,8 +130,8 @@ map: zoom: 8 base-map-url: https://iserver.supermap.io/iserver/services/map-china400/rest/maps/China baidu-map: - center-lat: 40.98896497581636 - center-lng: 113.11412662267688 + center-lat: 41.000587 + center-lng: 113.138723 zoom: 11 boundary: 乌兰察布市 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 ca7b992..d1544e5 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 @@ -247,6 +247,10 @@ t1.area_code = #{areaCode} + + AND + t1.area_code LIKE CONCAT(#{areaCodeLike}, '%') + AND t1.user_id IN