商家用户登录之后,补偿创建店铺遗漏的信息。 增加打烊状态兼顾时间段逻辑,账号体系优化 getOne 异常处理

This commit is contained in:
Jack 2025-09-02 00:00:26 +08:00
parent 497df13540
commit e45a1df7a1
7 changed files with 229 additions and 82 deletions

View File

@ -2426,20 +2426,35 @@ public class AccountUserBaseServiceImpl extends BaseServiceImpl<AccountUserBaseM
/** /**
* 根据账号和账号类型获取一条记录 * 根据账号和账号类型获取一条记录
* *
* @param user_account * @param userAccount 用户账号
* @param user_is_admin * @param userIsAdmin 用户类型: null-普通用户; 1-管理员; 2-入驻商家;
* @return * @return AccountUserBase 用户基础信息如果未找到则返回null
*/ */
public AccountUserBase getByAccountAndType(String user_account, Integer user_is_admin) { public AccountUserBase getByAccountAndType(String userAccount, Integer userIsAdmin) {
QueryWrapper<AccountUserBase> queryWrapper = new QueryWrapper<>(); // 参数校验
if (user_is_admin == null) { if (StrUtil.isBlank(userAccount)) {
user_is_admin = CommonConstant.USER_TYPE_NORMAL; return null;
} }
queryWrapper.eq("user_account", user_account)
.eq("user_is_admin", user_is_admin) try {
// 如果用户类型为null默认设置为普通用户类型
if (userIsAdmin == null) {
userIsAdmin = CommonConstant.USER_TYPE_NORMAL;
}
// 构建查询条件
QueryWrapper<AccountUserBase> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_account", userAccount)
.eq("user_is_admin", userIsAdmin)
.orderByAsc("user_id"); .orderByAsc("user_id");
AccountUserBase data = findOne(queryWrapper);
return data; // 执行查询并返回结果
return getOne(queryWrapper);
} catch (Exception e) {
// 记录异常日志避免影响主流程
logger.error("根据账号和类型查询用户信息时发生异常userAccount: {}, userIsAdmin: {}", userAccount, userIsAdmin, e);
return null;
}
} }
@Override @Override

View File

@ -173,17 +173,20 @@ public class AccountUserBindConnectServiceImpl extends BaseServiceImpl<AccountUs
public boolean checkAccessToken(Integer bind_type, AccountUserBindConnect bind_data, Integer user_id) { public boolean checkAccessToken(Integer bind_type, AccountUserBindConnect bind_data, Integer user_id) {
String bind_id = bind_data.getBind_id(); String bind_id = bind_data.getBind_id();
Integer user_type = bind_data.getUser_type() == null ? CommonConstant.USER_TYPE_NORMAL : bind_data.getUser_type();
// todo 验证验证码 // todo 验证验证码
bind_data.setBind_active(CommonConstant.Enable); bind_data.setBind_active(CommonConstant.Enable);
bind_data.setUser_id(user_id); bind_data.setUser_id(user_id);
bind_data.setBind_type(bind_type); bind_data.setBind_type(bind_type);
bind_data.setUser_type(user_type);
// 判断是否已经绑定 // 判断是否已经绑定
QueryWrapper<AccountUserBindConnect> queryWrapper = new QueryWrapper<>(); QueryWrapper<AccountUserBindConnect> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("bind_id", bind_id).eq("bind_type", bind_type).orderByAsc("bind_time"); queryWrapper.eq("bind_id", bind_id).eq("bind_type", bind_type)
.eq("user_type", user_type).orderByAsc("bind_time");
AccountUserBindConnect bind_row = findOne(queryWrapper); AccountUserBindConnect bind_row = findOne(queryWrapper);
//getBindByBindId(bind_id, bind_type, user_id, CommonConstant.USER_TYPE_NORMAL); //findOne(queryWrapper);
if (bind_row != null) { if (bind_row != null) {
Integer bind_active = bind_row.getBind_active(); Integer bind_active = bind_row.getBind_active();
@ -334,10 +337,11 @@ public class AccountUserBindConnectServiceImpl extends BaseServiceImpl<AccountUs
*/ */
@Override @Override
public Integer getUserBindConnectUserIdByCondition(String bindId, Integer bindType, Integer userType) { public Integer getUserBindConnectUserIdByCondition(String bindId, Integer bindType, Integer userType) {
if (StrUtil.isEmpty(bindId) || ObjectUtil.isEmpty(bindType)) { if (StrUtil.isBlank(bindId) || ObjectUtil.isEmpty(bindType)) {
return null; return null;
} }
try {
bindId = bindType == BindCode.MOBILE ? PhoneNumberUtils.convZhPhoneNumber(bindId) : bindId; bindId = bindType == BindCode.MOBILE ? PhoneNumberUtils.convZhPhoneNumber(bindId) : bindId;
QueryWrapper<AccountUserBindConnect> queryWrapper = new QueryWrapper<>(); QueryWrapper<AccountUserBindConnect> queryWrapper = new QueryWrapper<>();
@ -346,11 +350,19 @@ public class AccountUserBindConnectServiceImpl extends BaseServiceImpl<AccountUs
queryWrapper.eq("user_type", userType); queryWrapper.eq("user_type", userType);
} }
// 只查询 user_id 字段以提高性能
queryWrapper.select("user_id").orderByAsc("bind_time"); queryWrapper.select("user_id").orderByAsc("bind_time");
AccountUserBindConnect accountUserBindConnect = getOne(queryWrapper); AccountUserBindConnect accountUserBindConnect = getOne(queryWrapper);
return accountUserBindConnect != null ? accountUserBindConnect.getUser_id() : null; // 确保 accountUserBindConnect 不为 null user_id 不为 null
return (accountUserBindConnect != null && accountUserBindConnect.getUser_id() != null)
? accountUserBindConnect.getUser_id()
: null;
} catch (Exception e) {
// 记录异常日志避免影响主流程
log.error("查询用户绑定信息时发生异常bindId: {}, bindType: {}, userType: {}", bindId, bindType, userType, e);
return null;
}
} }
/** /**

View File

@ -5,10 +5,7 @@ import org.springframework.data.util.Pair;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.DateTimeException; import java.time.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder; import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.ChronoField; import java.time.temporal.ChronoField;
@ -233,6 +230,61 @@ public class DateTimeUtils {
return count; return count;
} }
/**
* 判断指定时间是否在两个时间点之间包含边界
*
* @param startTimeStr 开始时间字符串格式为 HH:mm
* @param endTimeStr 结束时间字符串格式为 HH:mm
* @param currentTime 要判断的时间点
* @return 如果在时间段内返回true否则返回false出现异常时返回false不影响主流程
*/
public static boolean isTimeInRange(String startTimeStr, String endTimeStr, LocalDateTime currentTime) {
try {
// 参数校验
if (startTimeStr == null || endTimeStr == null || currentTime == null) {
log.warn("时间参数不能为空startTimeStr: {}, endTimeStr: {}, currentTime: {}",
startTimeStr, endTimeStr, currentTime);
return false;
}
// 解析开始时间
LocalTime startTime = LocalTime.parse(startTimeStr, DateTimeFormatter.ofPattern("HH:mm"));
// 解析结束时间
LocalTime endTime = LocalTime.parse(endTimeStr, DateTimeFormatter.ofPattern("HH:mm"));
// 获取当前时间的时间部分
LocalTime nowTime = currentTime.toLocalTime();
// 处理跨天情况例如 22:00 - 06:00
if (endTime.isBefore(startTime)) {
// 如果结束时间小于开始时间说明跨越了午夜
// 当前时间需要满足大于等于开始时间 或者 小于等于结束时间
return !nowTime.isBefore(startTime) || !nowTime.isAfter(endTime);
} else {
// 正常情况不跨天当前时间需要在开始时间和结束时间之间包含边界
return !nowTime.isBefore(startTime) && !nowTime.isAfter(endTime);
}
} catch (Exception e) {
// 捕获解析异常记录日志并返回false避免影响主流程
log.error("判断时间是否在范围内时发生异常startTimeStr: {}, endTimeStr: {}, currentTime: {}",
startTimeStr, endTimeStr, currentTime, e);
return false;
}
}
/**
* 判断当前时间是否在两个时间点之间包含边界
*
* @param startTimeStr 开始时间字符串格式为 HH:mm
* @param endTimeStr 结束时间字符串格式为 HH:mm
* @return 如果在时间段内返回true否则返回false
* @throws IllegalArgumentException 当时间字符串格式不正确时抛出异常
*/
public static boolean isCurrentTimeInRange(String startTimeStr, String endTimeStr) {
return isTimeInRange(startTimeStr, endTimeStr, LocalDateTime.now());
}
public static void main(String[] args) { public static void main(String[] args) {
// System.out.println(convertLklDate("2021-02-19")); // 2025-01-02 // System.out.println(convertLklDate("2021-02-19")); // 2025-01-02
@ -249,9 +301,19 @@ public class DateTimeUtils {
// System.out.println(convertLklDate("永久")); // 9999-12-31 // System.out.println(convertLklDate("永久")); // 9999-12-31
// System.out.println(convertLklDate(null)); // 9999-12-31 // System.out.println(convertLklDate(null)); // 9999-12-31
// System.out.println(convertLklDate("2025.2.30")); // 9999-12-31无效日期 // System.out.println(convertLklDate("2025.2.30")); // 9999-12-31无效日期
System.out.println(convertLklDate("2045-01-10")); // 2025-01-10 // System.out.println(convertLklDate("2045-01-10")); // 2025-01-10
// System.out.println(formatLocalDate(LocalDate.now(), "yyyy-MM-dd")); // System.out.println(formatLocalDate(LocalDate.now(), "yyyy-MM-dd"));
// 判断当前时间是否在工作时间9:00-18:00
boolean isWorkTime = isCurrentTimeInRange("09:00", "22:36");
// 判断特定时间是否在夜间时间22:00-06:00
LocalDateTime testTime = LocalDateTime.of(2025, 1, 1, 23, 30);
boolean isNight = isTimeInRange("22:00", "06:00", testTime);
System.out.println("当前时间是否在工作时间内:" + isWorkTime);
System.out.println("特定时间是否在夜间时间段内:" + isNight);
} }
} }

View File

@ -56,7 +56,6 @@ import com.suisung.mall.shop.product.mapper.ShopProductItemMapper;
import com.suisung.mall.shop.product.pojo.vo.ProductVo; import com.suisung.mall.shop.product.pojo.vo.ProductVo;
import com.suisung.mall.shop.product.service.*; import com.suisung.mall.shop.product.service.*;
import com.suisung.mall.shop.store.service.*; import com.suisung.mall.shop.store.service.*;
import com.suisung.mall.shop.sync.keymanage.RedisKey;
import com.suisung.mall.shop.user.service.ShopUserFavoritesItemService; import com.suisung.mall.shop.user.service.ShopUserFavoritesItemService;
import com.suisung.mall.shop.user.service.ShopUserProductBrowseService; import com.suisung.mall.shop.user.service.ShopUserProductBrowseService;
import io.seata.spring.annotation.GlobalTransactional; import io.seata.spring.annotation.GlobalTransactional;
@ -484,6 +483,11 @@ public class ShopProductItemServiceImpl extends BaseServiceImpl<ShopProductItemM
Integer im_enable = accountBaseConfigService.getConfig("im_enable", 0); Integer im_enable = accountBaseConfigService.getConfig("im_enable", 0);
baseMap.put("im_chat", im_enable); baseMap.put("im_chat", im_enable);
data.put("product_analytics", analytics_row); data.put("product_analytics", analytics_row);
// 营业时间段直接影响到 营业状态字段
// store_biz_state 店铺营业状态1-营业中2-已打烊
baseMap.put("store_biz_state", shopStoreBaseService.getStoreBizState(shopStoreBase, shopStoreInfo));
data.put("store_info", baseMap); data.put("store_info", baseMap);
data.put("multishop_enable", multishop_enable); data.put("multishop_enable", multishop_enable);

View File

@ -10,6 +10,7 @@ import com.suisung.mall.common.modules.base.ShopBaseProductType;
import com.suisung.mall.common.modules.base.ShopBaseStoreCategory; import com.suisung.mall.common.modules.base.ShopBaseStoreCategory;
import com.suisung.mall.common.modules.store.ShopStoreBase; import com.suisung.mall.common.modules.store.ShopStoreBase;
import com.suisung.mall.common.modules.store.ShopStoreCompany; import com.suisung.mall.common.modules.store.ShopStoreCompany;
import com.suisung.mall.common.modules.store.ShopStoreInfo;
import com.suisung.mall.common.pojo.dto.StandardAddressDTO; import com.suisung.mall.common.pojo.dto.StandardAddressDTO;
import com.suisung.mall.core.web.service.IBaseService; import com.suisung.mall.core.web.service.IBaseService;
import org.springframework.data.util.Pair; import org.springframework.data.util.Pair;
@ -227,6 +228,15 @@ public interface ShopStoreBaseService extends IBaseService<ShopStoreBase> {
*/ */
BigDecimal getStorePackingFee(Integer storeId); BigDecimal getStorePackingFee(Integer storeId);
/**
* 根据当前时间检查并获取店铺营业状态
*
* @param shopStoreBase 店铺基础信息
* @param shopStoreInfo 店铺详细信息
* @return 店铺营业状态1-营业中2-已打烊
*/
Integer getStoreBizState(ShopStoreBase shopStoreBase, ShopStoreInfo shopStoreInfo);
// Page<ShopStoreBase> getMobileStoreList(Integer page, Integer rows); // Page<ShopStoreBase> getMobileStoreList(Integer page, Integer rows);
} }

View File

@ -756,8 +756,8 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl<ShopMchEntryMapper,
// 4.2 检查入驻状态 // 4.2 检查入驻状态
boolean isValidStatus = boolean isValidStatus =
CommonConstant.MCH_APPR_STA_PASS.equals(entry.getApproval_status()) || CommonConstant.MCH_APPR_STA_PASS.equals(entry.getApproval_status()) &&
CommonConstant.Enable.equals(entry.getHas_ec_signed()) || CommonConstant.Enable.equals(entry.getHas_ec_signed()) &&
CommonConstant.Enable.equals(entry.getHas_apply_mer()); CommonConstant.Enable.equals(entry.getHas_apply_mer());
if (!isValidStatus) { if (!isValidStatus) {
@ -773,20 +773,23 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl<ShopMchEntryMapper,
} }
// 4.4 获取店铺员工信息 // 4.4 获取店铺员工信息
ShopStoreEmployee storeEmployee = shopStoreEmployeeService.getStoreEmployeeByUserId( ShopStoreEmployee storeEmployee = null;
if (StrUtil.isNotBlank(entry.getStore_id())) {
storeEmployee = shopStoreEmployeeService.getStoreEmployeeByUserId(
Convert.toInt(entry.getStore_id()), Convert.toInt(entry.getStore_id()),
currentUser.getId() currentUser.getId()
); );
}
// 4.5 检查店铺关联关系 // 4.5 检查店铺关联关系
boolean hasStoreRelation = userBase.getStore_ids() != null && boolean hasStoreRelation = StrUtil.isNotBlank(userBase.getStore_ids()) &&
userBase.getStore_ids().contains(entry.getStore_id()); userBase.getStore_ids().contains(entry.getStore_id());
// 4.6 检查权限组信息 // 4.6 检查权限组信息
boolean hasPermission = storeEmployee != null && boolean hasPermission = storeEmployee != null &&
StrUtil.isNotBlank(storeEmployee.getRights_group_id()); StrUtil.isNotBlank(storeEmployee.getRights_group_id());
// 4.7 只有当不满足以下条件时才需要修复 // 4.7 当以下任一条件满足时需要进行修复
// - 无店铺员工信息 // - 无店铺员工信息
// - 无权限组信息 // - 无权限组信息
// - 无店铺关联 // - 无店铺关联
@ -800,7 +803,7 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl<ShopMchEntryMapper,
fixCount++; fixCount++;
log.warn("商户信息修复成功入驻ID: {}", entry.getId()); log.warn("商户信息修复成功入驻ID: {}", entry.getId());
} else { } else {
log.error("商户信息修复失败入驻ID: {}, 错误信息:{}", entry.getId(), result.getSecond()); log.error("商户信息修复失败入驻ID: {}, 错误信息:{}", entry.getId(), result != null ? result.getSecond() : "未知错误");
} }
} }
} }

View File

@ -3980,6 +3980,47 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
return BigDecimal.ZERO; return BigDecimal.ZERO;
} }
/**
* 根据当前时间检查并获取店铺营业状态
*
* @param shopStoreBase 店铺基础信息
* @param shopStoreInfo 店铺详细信息
* @return 店铺营业状态1-营业中2-已打烊
*/
@Override
public Integer getStoreBizState(ShopStoreBase shopStoreBase, ShopStoreInfo shopStoreInfo) {
try {
// 参数校验
if (shopStoreBase == null || shopStoreInfo == null) {
log.warn("店铺基础信息或详细信息为空,无法确定营业状态");
return CommonConstant.Enable;
}
Integer storeBizState = shopStoreBase.getStore_biz_state();
String openingHours = shopStoreInfo.getStore_opening_hours();
String closingHours = shopStoreInfo.getStore_close_hours();
// 检查店铺是否营业中且营业时间已设置
if (CommonConstant.Enable.equals(storeBizState)
&& StrUtil.isNotEmpty(openingHours)
&& StrUtil.isNotEmpty(closingHours)) {
// 检查当前时间是否在营业时间内
if (!DateTimeUtils.isCurrentTimeInRange(openingHours, closingHours)) {
// 不在营业时间内返回已打烊状态
return CommonConstant.Disable2;
}
}
// 返回原始营业状态
return storeBizState;
} catch (Exception e) {
// 处理异常避免影响主流程
log.error("检查店铺营业状态时发生异常shopStoreBase: {}, shopStoreInfo: {}",
shopStoreBase, shopStoreInfo, e);
return CommonConstant.Enable;
}
}
// @Override // @Override
// public Page<ShopStoreBase> getMobileStoreList(Integer page, Integer rows) { // public Page<ShopStoreBase> getMobileStoreList(Integer page, Integer rows) {
// QueryWrapper<ShopStoreBase> queryWrapper=new QueryWrapper<>(); // QueryWrapper<ShopStoreBase> queryWrapper=new QueryWrapper<>();