Commit fb4d6b1c authored by liming's avatar liming

增加用户登录日志接口

parent ede8e269
package com.antai.sport.http.server.repository.achievement.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* <p>
*
* </p>
*
* @author liming
* @since 2022-08-09
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class Achievement implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 分类 10 运动数值型 20 参与型
*/
private Integer type;
/**
* 级别 10 初级 20 中级 30 高级
*/
private Integer level;
/**
* 条件 10 登录天数 20 团练完成场数 30 日常赛完成场数 40 娱乐赛场数 50 里程 60 爬升高度 70 卡路里消耗
*/
private Integer condition;
/**
* 成就名称
*/
private String achievementName;
/**
* 条件数值
*/
private Integer conditionValue;
/**
* 成就名称
*/
private String name;
/**
* 成就logo
*/
private String logo;
/**
* 备注
*/
private String remark;
/**
* 排序号
*/
private Integer showOrder;
/**
* 数据版本号
*/
private Integer version;
/**
* 删除标记
*/
private Integer deleted;
/**
* 创建人
*/
private Long createBy;
/**
* 创建时间
*/
private LocalDateTime ctDate;
/**
* 修改人
*/
private Long updateBy;
/**
* 修改时间
*/
private LocalDateTime updateDate;
}
package com.antai.sport.http.server.repository.achievement.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* <p>
*
* </p>
*
* @author liming
* @since 2022-08-09
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class AchievementForSportUser implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 用户id
*/
private Long sportUserId;
/**
* 成就id
*/
private Long achievementId;
/**
* 已读状态
*/
private Boolean read;
/**
* 创建时间
*/
private LocalDateTime createTime;
}
package com.antai.sport.http.server.repository.achievement.mapper;
import com.antai.sport.http.server.repository.achievement.entity.AchievementForSportUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author liming
* @since 2022-08-09
*/
public interface AchievementForSportUserMapper extends BaseMapper<AchievementForSportUser> {
}
package com.antai.sport.http.server.repository.achievement.mapper;
import com.antai.sport.http.server.repository.achievement.entity.Achievement;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author liming
* @since 2022-08-09
*/
public interface AchievementMapper extends BaseMapper<Achievement> {
}
package com.antai.sport.http.server.repository.sport.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import java.time.LocalDate;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* <p>
*
* </p>
*
* @author liming
* @since 2022-08-09
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class SportUserContinuousLoginDays implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 用户id
*/
private Long sportUserId;
/**
* 连续登录天数
*/
private Integer days;
/**
* 最后连续登录日期
*/
private LocalDate lastLoginDate;
}
package com.antai.sport.http.server.repository.sport.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* <p>
*
* </p>
*
* @author liming
* @since 2022-08-09
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class SportUserLoginLog implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 用户id
*/
private Long sportUserId;
/**
* 创建时间
*/
private LocalDateTime createTime;
}
package com.antai.sport.http.server.repository.sport.mapper;
import com.antai.sport.http.server.repository.sport.entity.SportUserContinuousLoginDays;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author liming
* @since 2022-08-09
*/
public interface SportUserContinuousLoginDaysMapper extends BaseMapper<SportUserContinuousLoginDays> {
}
package com.antai.sport.http.server.repository.sport.mapper;
import com.antai.sport.http.server.repository.sport.entity.SportUserLoginLog;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author liming
* @since 2022-08-09
*/
public interface SportUserLoginLogMapper extends BaseMapper<SportUserLoginLog> {
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.antai.sport.http.server.repository.achievement.mapper.AchievementForSportUserMapper">
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.antai.sport.http.server.repository.achievement.mapper.AchievementMapper">
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.antai.sport.http.server.repository.sport.mapper.SportUserContinuousLoginDaysMapper">
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.antai.sport.http.server.repository.sport.mapper.SportUserLoginLogMapper">
</mapper>
......@@ -62,4 +62,11 @@ public class SportUserController {
public ResponseEntity<Result<TrainingDetailVO>> getSportUserTrainingLogRank(@PathVariable("id") Long Id) {
return success(sportUserTrainingLogService.getTrainingDetail(Id));
}
@ApiOperation("用户登录日志处理")
@GetMapping("/sign/in/{sportUserId}")
public ResponseEntity<Result> signIn(@PathVariable("sportUserId") Long sportUserId) {
sportUserService.signIn(sportUserId);
return success();
}
}
package com.antai.sport.http.server.server.api.business.user.service;
import com.antai.sport.http.server.constants.SportType;
import com.antai.sport.http.server.repository.sport.entity.SportUser;
import com.antai.sport.http.server.repository.sport.entity.SportUserSummary;
import com.antai.sport.http.server.repository.sport.entity.SportUserTrainingLog;
import com.antai.sport.http.server.repository.sport.entity.*;
import com.antai.sport.http.server.repository.sport.mapper.SportUserContinuousLoginDaysMapper;
import com.antai.sport.http.server.repository.sport.mapper.SportUserLoginLogMapper;
import com.antai.sport.http.server.repository.sport.mapper.SportUserMapper;
import com.antai.sport.http.server.server.api.business.traininglog.dto.SportUserTrainingLogSummaryVO;
import com.antai.sport.http.server.server.api.business.traininglog.service.SportUserTrainingLogService;
import com.antai.sport.http.server.server.api.business.user.dto.RespUserHomeInfo;
import com.antai.sport.http.server.server.api.business.traininglog.dto.SportUserTrainingLogSummaryVO;
import com.antai.sport.http.server.server.api.business.user.mapper.SportUserSummaryBusinessMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
@Service
public class SportUserService {
@Resource
private SportUserMapper sportUserMapper;
@Resource
private SportUserLoginLogMapper sportUserLoginLogMapper;
@Resource
private SportUserContinuousLoginDaysMapper sportUserContinuousLoginDaysMapper;
@Resource
private SportUserSummaryBusinessMapper sportUserSummaryBusinessMapper;
......@@ -29,8 +37,9 @@ public class SportUserService {
public RespUserHomeInfo getUserHomeInfo(Long userId) {
RespUserHomeInfo resp = new RespUserHomeInfo();
SportUser sportUser = sportUserMapper.selectById(userId);
SportUserSummary sportUserSummary = sportUserSummaryBusinessMapper.selectBySportTypeAndUserId(userId, SportType.BICYCLE);
if(sportUserSummary == null){
SportUserSummary sportUserSummary = sportUserSummaryBusinessMapper.selectBySportTypeAndUserId(userId,
SportType.BICYCLE);
if (sportUserSummary == null) {
sportUserSummary = new SportUserSummary();
sportUserSummary.setViews(0);
sportUserSummary.setTotalDistance(BigDecimal.ZERO);
......@@ -56,18 +65,59 @@ public class SportUserService {
totalSummary.setTotalDistance(sportUserSummary.getTotalDistance());
totalSummary.setTotalClimbDistance(sportUserSummary.getTotalClimbDistance());
totalSummary.setTotalDuration(sportUserSummary.getTotalDuration());
SportUserTrainingLog longestTrainingLog = sportUserTrainingLogService.getLongestTrainingLog(SportType.BICYCLE, userId);
if(longestTrainingLog == null){
SportUserTrainingLog longestTrainingLog = sportUserTrainingLogService.getLongestTrainingLog(SportType.BICYCLE
, userId);
if (longestTrainingLog == null) {
totalSummary.setLongestDistance(BigDecimal.ZERO);
} else {
totalSummary.setLongestDistance(longestTrainingLog.getDistance());
}
resp.setTotalSummary(totalSummary);
//查询7天数据汇总
resp.setWeekSummary(sportUserTrainingLogService.getTrainingLogSummary(SportType.BICYCLE,userId,7));
resp.setWeekSummary(sportUserTrainingLogService.getTrainingLogSummary(SportType.BICYCLE, userId, 7));
//查询30天数据汇总
resp.setMonthSummary(sportUserTrainingLogService.getTrainingLogSummary(SportType.BICYCLE,userId,30));
resp.setMonthSummary(sportUserTrainingLogService.getTrainingLogSummary(SportType.BICYCLE, userId, 30));
return resp;
}
/**
* 用户登录日志
*/
public void signIn(Long sportUserId) {
//插入登录日志
SportUserLoginLog loginLog = new SportUserLoginLog();
loginLog.setSportUserId(sportUserId);
loginLog.setCreateTime(LocalDateTime.now());
sportUserLoginLogMapper.insert(loginLog);
//查询连续登录时间
QueryWrapper<SportUserContinuousLoginDays> continuousLoginDaysQuery = new QueryWrapper<>();
continuousLoginDaysQuery.lambda().eq(SportUserContinuousLoginDays::getSportUserId, sportUserId);
SportUserContinuousLoginDays continuousLoginDays =
sportUserContinuousLoginDaysMapper.selectOne(continuousLoginDaysQuery);
if (continuousLoginDays == null) {
continuousLoginDays = new SportUserContinuousLoginDays();
continuousLoginDays.setDays(1);
continuousLoginDays.setSportUserId(sportUserId);
continuousLoginDays.setLastLoginDate(LocalDate.now());
sportUserContinuousLoginDaysMapper.insert(continuousLoginDays);
return;
}
//当最近连续登录时间相同时不做处理
if (continuousLoginDays.getLastLoginDate().isEqual(LocalDate.now())) {
return;
}
//当最近连续登录时间和当天时间间隔一天时累计连续登录时间
if (continuousLoginDays.getLastLoginDate().isEqual(LocalDate.now().minusDays(1))) {
continuousLoginDays.setDays(continuousLoginDays.getDays() + 1);
continuousLoginDays.setLastLoginDate(LocalDate.now());
sportUserContinuousLoginDaysMapper.insert(continuousLoginDays);
return;
}
//其他情况重置连续登录天数
continuousLoginDays.setDays(1);
continuousLoginDays.setLastLoginDate(LocalDate.now());
sportUserContinuousLoginDaysMapper.insert(continuousLoginDays);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment