From 90728bd52089b11fadaea0076e30a85d6bd6ecfa Mon Sep 17 00:00:00 2001 From: wanggeng <450292408@qq.com> Date: Tue, 28 Sep 2021 11:46:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=94=A8=E6=88=B7=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/count/CountResourceController.java | 44 +++++++++++++++++++ .../dao/logger/ILoginLoggerDao.java | 10 +++++ .../pojo/dtos/count/IdCountPO.java | 22 ++++++++++ .../pojo/dtos/user/UserUseInfoDTO.java | 33 ++++++++++++++ .../service/count/ICountService.java | 11 +++++ .../service/count/impl/CountServiceImpl.java | 44 +++++++++++++++++-- .../service/logger/ILoginLoggerService.java | 9 ++++ .../logger/impl/LoginLoggerServiceImpl.java | 8 +++- .../system/sign/impl/SignServiceImpl.java | 6 +++ src/main/resources/application-test.yml | 2 +- .../mapper/logger/loginlogger-mapper.xml | 23 ++++++++++ 11 files changed, 206 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/cm/serviceusercenter/controller/resources/system/count/CountResourceController.java create mode 100644 src/main/java/com/cm/serviceusercenter/pojo/dtos/count/IdCountPO.java create mode 100644 src/main/java/com/cm/serviceusercenter/pojo/dtos/user/UserUseInfoDTO.java diff --git a/src/main/java/com/cm/serviceusercenter/controller/resources/system/count/CountResourceController.java b/src/main/java/com/cm/serviceusercenter/controller/resources/system/count/CountResourceController.java new file mode 100644 index 0000000..7634ba8 --- /dev/null +++ b/src/main/java/com/cm/serviceusercenter/controller/resources/system/count/CountResourceController.java @@ -0,0 +1,44 @@ +package com.cm.serviceusercenter.controller.resources.system.count; + +import com.cm.common.constants.ISystemConstant; +import com.cm.common.pojo.ListPage; +import com.cm.common.result.ErrorResult; +import com.cm.common.result.SuccessResultList; +import com.cm.serviceusercenter.controller.BaseController; +import com.cm.serviceusercenter.pojo.dtos.user.UserUseInfoDTO; +import com.cm.serviceusercenter.service.count.ICountService; +import io.swagger.annotations.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * @ClassName: CountResourceController + * @Description: 统计资源 + * @Author: wanggeng + * @Date: 2021/9/26 3:36 下午 + * @Version: 1.0 + */ +@Api(tags = ISystemConstant.API_TAGS_RESOURCE_PREFIX + "接口统计") +@RestController +@RequestMapping(ISystemConstant.RESOURCE_PREFIX + "/count") +public class CountResourceController extends BaseController { + + @Autowired + private ICountService countService; + + @ApiOperation(value = "用户使用情况分页列表", notes = "用户使用情况分页列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "access_token", value = "access_token", paramType = "query", dataType = "String"), + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("listpage-user-use") + public SuccessResultList> listPageUserUse(ListPage page) { + page.setParams(requestParams()); + return countService.listPageUserUse(page); + } + +} diff --git a/src/main/java/com/cm/serviceusercenter/dao/logger/ILoginLoggerDao.java b/src/main/java/com/cm/serviceusercenter/dao/logger/ILoginLoggerDao.java index 94beb87..3dc1e43 100644 --- a/src/main/java/com/cm/serviceusercenter/dao/logger/ILoginLoggerDao.java +++ b/src/main/java/com/cm/serviceusercenter/dao/logger/ILoginLoggerDao.java @@ -2,6 +2,7 @@ package com.cm.serviceusercenter.dao.logger; import com.cm.common.exception.SaveException; import com.cm.common.exception.SearchException; +import com.cm.serviceusercenter.pojo.dtos.count.IdCountPO; import com.cm.serviceusercenter.pojo.dtos.logger.LoginLoggerDTO; import org.springframework.stereotype.Repository; @@ -46,4 +47,13 @@ public interface ILoginLoggerDao { * @throws SearchException */ List listLoginLogger(Map params) throws SearchException; + + /** + * 用户登录次数统计列表 + * + * @param params + * @return + * @throws SearchException + */ + List listCountLoginCountPO(Map params) throws SearchException; } diff --git a/src/main/java/com/cm/serviceusercenter/pojo/dtos/count/IdCountPO.java b/src/main/java/com/cm/serviceusercenter/pojo/dtos/count/IdCountPO.java new file mode 100644 index 0000000..465247f --- /dev/null +++ b/src/main/java/com/cm/serviceusercenter/pojo/dtos/count/IdCountPO.java @@ -0,0 +1,22 @@ +package com.cm.serviceusercenter.pojo.dtos.count; + +import lombok.Data; +import lombok.ToString; + +import java.io.Serializable; + +/** + * @ClassName: IdCountPO + * @Description: id数量统计 + * @Author: wanggeng + * @Date: 2021/9/27 11:29 上午 + * @Version: 1.0 + */ +@Data +@ToString +public class IdCountPO implements Serializable { + + private String userId; + private Integer total; + +} diff --git a/src/main/java/com/cm/serviceusercenter/pojo/dtos/user/UserUseInfoDTO.java b/src/main/java/com/cm/serviceusercenter/pojo/dtos/user/UserUseInfoDTO.java new file mode 100644 index 0000000..e6f4cec --- /dev/null +++ b/src/main/java/com/cm/serviceusercenter/pojo/dtos/user/UserUseInfoDTO.java @@ -0,0 +1,33 @@ +package com.cm.serviceusercenter.pojo.dtos.user; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +/** + * @ClassName: UserUseInfoDTO + * @Description: 用户使用情况 + * @Author: wanggeng + * @Date: 2021/9/26 10:56 上午 + * @Version: 1.0 + */ +@ApiModel +@Data +@ToString +public class UserUseInfoDTO { + + @ApiModelProperty(name = "userId", value = "用户ID") + private String userId; + @ApiModelProperty(name = "userUsername", value = "用户名") + private String userUsername; + @ApiModelProperty(name = "userName", value = "昵称") + private String userName; + @ApiModelProperty(name = "departmentName", value = "组织机构") + private String departmentName; + @ApiModelProperty(name = "lastLoginTime", value = "最后登录时间") + private String lastLoginTime; + @ApiModelProperty(name = "loginCount", value = "登录次数") + private Integer loginCount; + +} diff --git a/src/main/java/com/cm/serviceusercenter/service/count/ICountService.java b/src/main/java/com/cm/serviceusercenter/service/count/ICountService.java index dc8d6bc..6145734 100644 --- a/src/main/java/com/cm/serviceusercenter/service/count/ICountService.java +++ b/src/main/java/com/cm/serviceusercenter/service/count/ICountService.java @@ -2,7 +2,10 @@ package com.cm.serviceusercenter.service.count; import com.alibaba.fastjson.JSONObject; import com.cm.common.exception.SearchException; +import com.cm.common.pojo.ListPage; import com.cm.common.result.SuccessResultData; +import com.cm.common.result.SuccessResultList; +import com.cm.serviceusercenter.pojo.dtos.user.UserUseInfoDTO; import java.util.List; import java.util.Map; @@ -129,4 +132,12 @@ public interface ICountService { * @throws SearchException */ SuccessResultData>> countLoginTypeProportion() throws SearchException; + + /** + * 使用情况列表 + * + * @param page + * @return + */ + SuccessResultList> listPageUserUse(ListPage page); } diff --git a/src/main/java/com/cm/serviceusercenter/service/count/impl/CountServiceImpl.java b/src/main/java/com/cm/serviceusercenter/service/count/impl/CountServiceImpl.java index e8badef..7fdc1d7 100644 --- a/src/main/java/com/cm/serviceusercenter/service/count/impl/CountServiceImpl.java +++ b/src/main/java/com/cm/serviceusercenter/service/count/impl/CountServiceImpl.java @@ -4,8 +4,13 @@ import com.alibaba.fastjson.JSONObject; import com.cm.common.base.AbstractService; import com.cm.common.exception.SearchException; import com.cm.common.plugin.service.systemlogger.ISystemLoggerService; +import com.cm.common.pojo.ListPage; import com.cm.common.result.SuccessResultData; +import com.cm.common.result.SuccessResultList; import com.cm.common.utils.DateUtil; +import com.cm.serviceusercenter.pojo.dtos.UserDTO; +import com.cm.serviceusercenter.pojo.dtos.count.IdCountPO; +import com.cm.serviceusercenter.pojo.dtos.user.UserUseInfoDTO; import com.cm.serviceusercenter.service.count.ICountService; import com.cm.serviceusercenter.service.logger.ILoginLoggerService; import com.cm.serviceusercenter.service.system.department.IDepartmentService; @@ -13,6 +18,7 @@ import com.cm.serviceusercenter.service.system.oauthclient.IOauthClientService; import com.cm.serviceusercenter.service.system.position.IPositionService; import com.cm.serviceusercenter.service.system.role.IRoleService; import com.cm.serviceusercenter.service.system.user.IUserService; +import org.apache.commons.lang3.StringUtils; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; @@ -20,10 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * When you feel like quitting. Think about why you started @@ -267,6 +270,39 @@ public class CountServiceImpl extends AbstractService implements ICountService { return new SuccessResultData<>(result); } + @Override + public SuccessResultList> listPageUserUse(ListPage page) { + SuccessResultList> listSuccessResultList = userService.listPageUsers(page); + List userDTOs = listSuccessResultList.getRows(); + if (userDTOs.isEmpty()) { + return new SuccessResultList<>(new ArrayList<>(), 1, 0L); + } + Set userIdSet = new HashSet<>(); + for (UserDTO userDTO : userDTOs) { + userIdSet.add(userDTO.getUserId()); + } + List listCountPOs = loginLoggerService.listCountLoginCountPO(new ArrayList<>(userIdSet)); + List userUseInfoDTOs = new ArrayList<>(); + for (UserDTO userDTO : userDTOs) { + UserUseInfoDTO userUseInfoDTO = new UserUseInfoDTO(); + userUseInfoDTO.setUserId(userDTO.getUserId()); + userUseInfoDTO.setUserUsername(userDTO.getUserUsername()); + userUseInfoDTO.setUserName(userDTO.getUserName()); + userUseInfoDTO.setDepartmentName(userDTO.getDepartmentNames()); + userUseInfoDTO.setLastLoginTime(userDTO.getLastLoginTime()); + userUseInfoDTO.setLoginCount(0); + for (IdCountPO idCountPO : listCountPOs) { + if (StringUtils.equals(userDTO.getUserId(), idCountPO.getUserId())) { + userUseInfoDTO.setLoginCount(idCountPO.getTotal()); + break; + } + } + userUseInfoDTOs.add(userUseInfoDTO); + } + // 部门信息 + return new SuccessResultList<>(userUseInfoDTOs, listSuccessResultList.getPage(), listSuccessResultList.getTotal()); + } + /** * 计算占比 * diff --git a/src/main/java/com/cm/serviceusercenter/service/logger/ILoginLoggerService.java b/src/main/java/com/cm/serviceusercenter/service/logger/ILoginLoggerService.java index 121eb2a..823da13 100644 --- a/src/main/java/com/cm/serviceusercenter/service/logger/ILoginLoggerService.java +++ b/src/main/java/com/cm/serviceusercenter/service/logger/ILoginLoggerService.java @@ -4,6 +4,7 @@ import com.cm.common.exception.SaveException; import com.cm.common.exception.SearchException; import com.cm.common.pojo.ListPage; import com.cm.common.result.SuccessResultList; +import com.cm.serviceusercenter.pojo.dtos.count.IdCountPO; import com.cm.serviceusercenter.pojo.dtos.logger.LoginLoggerDTO; import java.util.List; @@ -46,4 +47,12 @@ public interface ILoginLoggerService { * @throws SearchException */ SuccessResultList> listPageLoginLogger(ListPage page) throws SearchException; + + /** + * 用户登录次数统计列表 + * + * @param userIds + * @return + */ + List listCountLoginCountPO(List userIds); } diff --git a/src/main/java/com/cm/serviceusercenter/service/logger/impl/LoginLoggerServiceImpl.java b/src/main/java/com/cm/serviceusercenter/service/logger/impl/LoginLoggerServiceImpl.java index 7e3ae37..8dc2a62 100644 --- a/src/main/java/com/cm/serviceusercenter/service/logger/impl/LoginLoggerServiceImpl.java +++ b/src/main/java/com/cm/serviceusercenter/service/logger/impl/LoginLoggerServiceImpl.java @@ -6,7 +6,7 @@ import com.cm.common.exception.SearchException; import com.cm.common.pojo.ListPage; import com.cm.common.result.SuccessResultList; import com.cm.serviceusercenter.dao.logger.ILoginLoggerDao; -import com.cm.serviceusercenter.pojo.dtos.logger.DepartmentLogDTO; +import com.cm.serviceusercenter.pojo.dtos.count.IdCountPO; import com.cm.serviceusercenter.pojo.dtos.logger.LoginLoggerDTO; import com.cm.serviceusercenter.service.logger.ILoginLoggerService; import com.github.pagehelper.PageHelper; @@ -52,4 +52,10 @@ public class LoginLoggerServiceImpl extends AbstractService implements ILoginLog return new SuccessResultList<>(loginLoggerDTOs, pageInfo.getPageNum(), pageInfo.getTotal()); } + @Override + public List listCountLoginCountPO(List userIds) { + Map params = getHashMap(2); + params.put("userIds", userIds); + return loginLoggerDao.listCountLoginCountPO(params); + } } diff --git a/src/main/java/com/cm/serviceusercenter/service/system/sign/impl/SignServiceImpl.java b/src/main/java/com/cm/serviceusercenter/service/system/sign/impl/SignServiceImpl.java index 275f91c..43707a6 100644 --- a/src/main/java/com/cm/serviceusercenter/service/system/sign/impl/SignServiceImpl.java +++ b/src/main/java/com/cm/serviceusercenter/service/system/sign/impl/SignServiceImpl.java @@ -12,6 +12,7 @@ import com.cm.common.result.SuccessResultData; import com.cm.common.utils.AesUtil; import com.cm.common.utils.DateUtil; import com.cm.common.utils.RequestUtil; +import com.cm.serviceusercenter.enums.LoginType; import com.cm.serviceusercenter.manager.ConfigManager; import com.cm.serviceusercenter.pojo.dtos.appversion.AppVersionDTO; import com.cm.serviceusercenter.pojo.pos.UserAppDevicePO; @@ -20,6 +21,7 @@ import com.cm.serviceusercenter.pojo.vos.UserVO; import com.cm.serviceusercenter.pojo.vos.sign.LoginDefaultVO; import com.cm.serviceusercenter.pojo.vos.sign.LoginPhoneVO; import com.cm.serviceusercenter.pojo.vos.sign.LoginVO; +import com.cm.serviceusercenter.service.UserLoginService; import com.cm.serviceusercenter.service.appversion.IAppVersionService; import com.cm.serviceusercenter.service.system.department.IDepartmentService; import com.cm.serviceusercenter.service.system.group.IGroupService; @@ -65,6 +67,8 @@ public class SignServiceImpl extends AbstractService implements ISignService { private PasswordEncoder passwordEncoder; @Value("${user.default-password:888888}") private String defaultPassword; + @Autowired + private UserLoginService userLoginService; /** * token解密方法,先进行Base64解密,然后用aesCommonDecoder解密 @@ -149,6 +153,8 @@ public class SignServiceImpl extends AbstractService implements ISignService { } LOG.debug("更新登录信息"); updateLoginInfo(userPO, loginVO.getLongitude(), loginVO.getLatitude()); + LOG.debug("添加登录日志"); + userLoginService.updateUserLoginInfo(userPO.getUserId(), userPO.getUserName(), LoginType.USERNAME_AND_PASSWORD.getValue()); } @Override diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index 2c9e6ab..05acbf5 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -29,7 +29,7 @@ spring: datasource: druid: # url: jdbc:mysql://49.233.36.36:6688/db_cloud?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=UTC - url: jdbc:mysql://192.168.0.151:3306/db_cloud_v2_inspection?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=UTC + url: jdbc:mysql://192.168.0.151:3306/db_btyjj_usercenter?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=UTC db-type: mysql driver-class-name: com.mysql.cj.jdbc.Driver # username: wanggeng diff --git a/src/main/resources/mybatis/mapper/logger/loginlogger-mapper.xml b/src/main/resources/mybatis/mapper/logger/loginlogger-mapper.xml index bc01704..2c83d7f 100644 --- a/src/main/resources/mybatis/mapper/logger/loginlogger-mapper.xml +++ b/src/main/resources/mybatis/mapper/logger/loginlogger-mapper.xml @@ -76,4 +76,27 @@ gmt_create DESC, id DESC + + + \ No newline at end of file