新增用户使用统计

This commit is contained in:
wanggeng 2021-09-28 11:46:22 +08:00
parent c9dbc26647
commit 90728bd520
11 changed files with 206 additions and 6 deletions

View File

@ -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<List<UserUseInfoDTO>> listPageUserUse(ListPage page) {
page.setParams(requestParams());
return countService.listPageUserUse(page);
}
}

View File

@ -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<LoginLoggerDTO> listLoginLogger(Map<String, Object> params) throws SearchException;
/**
* 用户登录次数统计列表
*
* @param params
* @return
* @throws SearchException
*/
List<IdCountPO> listCountLoginCountPO(Map<String, Object> params) throws SearchException;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<List<Map<String, Object>>> countLoginTypeProportion() throws SearchException;
/**
* 使用情况列表
*
* @param page
* @return
*/
SuccessResultList<List<UserUseInfoDTO>> listPageUserUse(ListPage page);
}

View File

@ -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<List<UserUseInfoDTO>> listPageUserUse(ListPage page) {
SuccessResultList<List<UserDTO>> listSuccessResultList = userService.listPageUsers(page);
List<UserDTO> userDTOs = listSuccessResultList.getRows();
if (userDTOs.isEmpty()) {
return new SuccessResultList<>(new ArrayList<>(), 1, 0L);
}
Set<String> userIdSet = new HashSet<>();
for (UserDTO userDTO : userDTOs) {
userIdSet.add(userDTO.getUserId());
}
List<IdCountPO> listCountPOs = loginLoggerService.listCountLoginCountPO(new ArrayList<>(userIdSet));
List<UserUseInfoDTO> 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());
}
/**
* 计算占比
*

View File

@ -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<List<LoginLoggerDTO>> listPageLoginLogger(ListPage page) throws SearchException;
/**
* 用户登录次数统计列表
*
* @param userIds
* @return
*/
List<IdCountPO> listCountLoginCountPO(List<String> userIds);
}

View File

@ -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<IdCountPO> listCountLoginCountPO(List<String> userIds) {
Map<String, Object> params = getHashMap(2);
params.put("userIds", userIds);
return loginLoggerDao.listCountLoginCountPO(params);
}
}

View File

@ -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

View File

@ -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

View File

@ -76,4 +76,27 @@
gmt_create DESC, id DESC
</select>
<!-- 用户登录次数统计列表 -->
<select id="listCountLoginCountPO" parameterType="map" resultType="com.cm.serviceusercenter.pojo.dtos.count.IdCountPO">
SELECT
creator userId,
count(creator) total
FROM
log_loginlogger
<where>
<if test="userId != null and userId != ''">
creator = #{userId}
</if>
<if test="userIds != null and userIds.size > 0">
AND
creator IN
<foreach collection="userIds" index="index" open="(" separator="," close=")">
#{userIds[${index}]}
</foreach>
</if>
</where>
GROUP BY
creator
</select>
</mapper>