提交 a012575d 编写于 作者: 街头小贩's avatar 街头小贩

修正会员上次登录显示错误

上级 ce880679
......@@ -136,7 +136,12 @@ public class MemberActiveRecordsDaoImpl implements MemberActiveRecordsDao{
.setMaxResults(showSize)
.getResultStream();
}
/**
* @deprecated
* @param memberId
* @param memberNames
* @return
*/
@Override
public Optional<MemberActiveRecords> findOneForLastLogin(long memberId, String memberNames) {
logger.info("[MemberActiveRecordsDao]args member/id:" + memberId + ",names:" + memberNames);
......@@ -157,6 +162,16 @@ public class MemberActiveRecordsDaoImpl implements MemberActiveRecordsDao{
return Optional.empty(); //.failure("没有找到可以匹配的登录记录");
}
@Override
public Stream<MemberActiveRecords> findAllLoginAction(long memberId, String memberNames, int showSize) {
return entityManager.createQuery("SELECT mar FROM MemberActiveRecords mar WHERE mar.memberNames = ?1 AND mar.action = ?2 AND mar.succeed = ?3 ORDER BY mar.id DESC", MemberActiveRecords.class)
.setParameter(1, memberNames)
.setParameter(2, ForumActionEnum.MEMBER_LOGIN)
.setParameter(3, true)
.setMaxResults(showSize)
.getResultStream();
}
@Override
public Map<ForumActionEnum, Long> statsMemberAction(long memberId) {
Member m = entityManager.find(Member.class, memberId);
......
......@@ -6,9 +6,12 @@ import com.apobates.forum.member.service.MemberActiveRecordsService;
import com.apobates.forum.utils.persistence.Page;
import com.apobates.forum.utils.persistence.Pageable;
import java.time.LocalDateTime;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -47,8 +50,13 @@ public class MemberActiveRecordsServiceImpl implements MemberActiveRecordsServic
}
@Override
public Optional<MemberActiveRecords> getLastLoginRecord(long memberId, String memberNames) {
return memberActiveRecordsDao.findOneForLastLogin(memberId, memberNames);
public Optional<MemberActiveRecords> getPreviousLoginRecord(long memberId, String memberNames) {
List<MemberActiveRecords> rs = memberActiveRecordsDao.findAllLoginAction(memberId, memberNames, 2).sorted(Comparator.comparing(MemberActiveRecords::getActiveDateTime).reversed()).collect(Collectors.toList());
try{
return Optional.ofNullable(rs.get(1));
}catch(IndexOutOfBoundsException e){
return Optional.empty();
}
}
@Override
......
......@@ -59,13 +59,23 @@ public interface MemberActiveRecordsDao extends PagingAndSortingRepository<Membe
/**
* 查看指定会员最近的一条登录记录
*
* @deprecated
* @param memberId 会员ID
* @param memberNames 登录帐号
* @return
*/
Optional<MemberActiveRecords> findOneForLastLogin(long memberId, String memberNames);
/**
* 查看指定会员最近的几次登录记录,只显示成功的
*
* @param memberId 会员ID
* @param memberNames 登录帐号
* @param showSize 显示的数量
* @return
*/
Stream<MemberActiveRecords> findAllLoginAction(long memberId, String memberNames, int showSize);
/**
* 统计会员的动作,包括登录,注册数
*
......
......@@ -52,13 +52,13 @@ public interface MemberActiveRecordsService {
Optional<MemberActiveRecords> get(long id);
/**
* 查看指定会员最近的一条登录记录
* 查看指定会员上次登录记录
*
* @param memberId 会员ID
* @param memberNames 登录帐号
* @return
*/
Optional<MemberActiveRecords> getLastLoginRecord(long memberId, String memberNames);
Optional<MemberActiveRecords> getPreviousLoginRecord(long memberId, String memberNames);
/**
* 保存会员操作记录
......
......@@ -127,11 +127,11 @@ public class MemberHomeController {
data.put("logonDateTime", DateTimeUtils.formatClock(m.getRegisteDateTime()));
//上次登录日期
try {
MemberActiveRecords lastLoginRecord = memberActiveRecordsService.getLastLoginRecord(mbean.getMid(), mbean.getNames()).orElse(null);
MemberActiveRecords lastLoginRecord = memberActiveRecordsService.getPreviousLoginRecord(mbean.getMid(), mbean.getNames()).orElse(null);
String lldt = DateTimeUtils.formatClock(lastLoginRecord.getActiveDateTime());
data.put("lastLoginDateTime", lldt);
data.put("prevLoginDateTime", lldt);
} catch (NullPointerException e) {
data.put("lastLoginDateTime", "-");
data.put("prevLoginDateTime", "-");
}
data.put("names", mbean.getNames());
model.addAttribute("member", memberProfile.toMergeMap(data));
......
......@@ -30,7 +30,7 @@
<div class="member-profile-avatar"><span><img class="rounded-circle" src="${BASE}/member/avatar/${member.id}.png" width="100px" height="100px"/></span></div>
<div class="member-profile-info">
<h4 style="margin-bottom:0">${member.names} @u${member.id}</h4>
<p>上次登录: ${member.lastLoginDateTime}</p>
<p>上次登录: ${member.prevLoginDateTime}</p>
</div>
</div>
<div class="col-md-6 member-profile-ext">
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册