会员
This commit is contained in:
@@ -69,5 +69,13 @@ public interface ShopUserMapper {
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteShopUserByIds(String[] ids);
|
||||
|
||||
/**
|
||||
* 更新用户在线时长
|
||||
*
|
||||
* @param shopUser 用户信息(包含userId和online字段)
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateUserOnlineTime(ShopUser shopUser);
|
||||
|
||||
}
|
||||
@@ -61,4 +61,12 @@ public interface IShopUserService
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteShopUserById(String id);
|
||||
|
||||
/**
|
||||
* 更新用户在线时长
|
||||
*
|
||||
* @param shopUser 用户信息(包含userId和online字段)
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateUserOnlineTime(ShopUser shopUser);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.domain.entity.ShopUser;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.system.config.AliConfig;
|
||||
import com.ruoyi.system.mapper.ShopUserMapper;
|
||||
import com.ruoyi.system.service.IShopUserService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -16,8 +20,9 @@ import java.util.List;
|
||||
* @date 2025-07-15
|
||||
*/
|
||||
@Service
|
||||
public class ShopUserServiceImpl implements IShopUserService
|
||||
public class ShopUserServiceImpl implements IShopUserService
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(ShopUserServiceImpl.class);
|
||||
@Autowired
|
||||
private ShopUserMapper shopUserMapper;
|
||||
|
||||
@@ -94,4 +99,61 @@ public class ShopUserServiceImpl implements IShopUserService
|
||||
{
|
||||
return shopUserMapper.deleteShopUserById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户在线时长
|
||||
*
|
||||
* @param shopUser 用户信息(包含userId和online字段)
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateUserOnlineTime(ShopUser shopUser)
|
||||
{
|
||||
if (shopUser == null || shopUser.getUserId() == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 先查询用户当前的在线时长
|
||||
ShopUser currentUser = shopUserMapper.selectShopUserByUserId(shopUser.getUserId());
|
||||
if (currentUser == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 在原有时长基础上累加新的时长
|
||||
String currentOnline = currentUser.getOnline();
|
||||
String newOnline = shopUser.getOnline();
|
||||
|
||||
// 计算累加后的在线时长
|
||||
double currentOnlineValue = 0;
|
||||
double newOnlineValue = 0;
|
||||
|
||||
try {
|
||||
if (currentOnline != null && !currentOnline.isEmpty()) {
|
||||
currentOnlineValue = Double.parseDouble(currentOnline);
|
||||
}
|
||||
|
||||
if (newOnline != null && !newOnline.isEmpty()) {
|
||||
// 接口传入的是分钟,需要转换为小时
|
||||
newOnlineValue = Double.parseDouble(newOnline) / 60.0;
|
||||
// 保留两位小数
|
||||
newOnlineValue = Math.round(newOnlineValue * 100) / 100.0;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
// 如果解析失败,使用默认值
|
||||
log.error("解析在线时长失败", e);
|
||||
}
|
||||
|
||||
// 累加时长(数据库中存储的是小时)
|
||||
double totalOnline = currentOnlineValue + newOnlineValue;
|
||||
// 保留两位小数
|
||||
totalOnline = Math.round(totalOnline * 100) / 100.0;
|
||||
|
||||
// 更新用户在线时长
|
||||
ShopUser updateUser = new ShopUser();
|
||||
updateUser.setUserId(shopUser.getUserId());
|
||||
updateUser.setOnline(String.valueOf(totalOnline));
|
||||
updateUser.setUpdateTime(DateUtils.getNowDate());
|
||||
|
||||
return shopUserMapper.updateUserOnlineTime(updateUser);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="shelf" column="shelf" />
|
||||
<result property="isDel" column="is_del" />
|
||||
<result property="img" column="img" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectActivityInfoVo">
|
||||
select id, name, content, start_time, end_time, creator, modify, shelf, is_del, img from activity_info
|
||||
select id, name, content, start_time, end_time, creator, modify, shelf, is_del, img,update_time,create_time from activity_info
|
||||
</sql>
|
||||
|
||||
<select id="selectActivityInfoList" parameterType="ActivityInfo" resultMap="ActivityInfoResult">
|
||||
|
||||
@@ -190,4 +190,14 @@
|
||||
<include refid="selectShopUserVo"/>
|
||||
where shop_user.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<!-- 更新用户在线时长 -->
|
||||
<update id="updateUserOnlineTime" parameterType="ShopUser">
|
||||
update shop_user
|
||||
<set>
|
||||
<if test="online != null">online = #{online},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
</set>
|
||||
where user_id = #{userId}
|
||||
</update>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user