修正导出同事特权,从订单表校验数据

This commit is contained in:
2026-06-02 23:12:47 +08:00
parent 228c4cf732
commit bdad17d77a
4 changed files with 59 additions and 37 deletions

View File

@@ -61,6 +61,7 @@ public class MybatisPlusConfig {
ignoreTables.add("menu"); // 菜单表(不需要租户隔离) ignoreTables.add("menu"); // 菜单表(不需要租户隔离)
ignoreTables.add("ai_prompts"); // AI 提示词全局配置,表无 tenant_id 字段 ignoreTables.add("ai_prompts"); // AI 提示词全局配置,表无 tenant_id 字段
ignoreTables.add("lb_third_integration_config"); // 每租户一条,按 tenant_id 显式查询,不走插件自动拼接 ignoreTables.add("lb_third_integration_config"); // 每租户一条,按 tenant_id 显式查询,不走插件自动拼接
ignoreTables.add("lb_buy_account"); // 抢单账号跨租户管理;分页/批量抢单按记录 tenant_id 业务处理
return new TenantLineHandler() { return new TenantLineHandler() {

View File

@@ -5,13 +5,29 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.rj.entity.LbBuyAccount; import com.rj.entity.LbBuyAccount;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update; import org.apache.ibatis.annotations.Update;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List;
@Mapper @Mapper
public interface LbBuyAccountMapper extends BaseMapper<LbBuyAccount> { public interface LbBuyAccountMapper extends BaseMapper<LbBuyAccount> {
/**
* 按主键批量查询;跳过多租户拦截,避免 rushBuyByIds 因当前租户上下文过滤查不到账号。
*/
@InterceptorIgnore(tenantLine = "true")
@Select("""
<script>
SELECT * FROM lb_buy_account WHERE id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</script>
""")
List<LbBuyAccount> selectByIdsIgnoreTenant(@Param("ids") List<String> ids);
/** /**
* 按主键更新抢单结果与时间;跳过多租户拦截,避免批量抢单 worker 线程无租户上下文导致更新 0 行。 * 按主键更新抢单结果与时间;跳过多租户拦截,避免批量抢单 worker 线程无租户上下文导致更新 0 行。
*/ */

View File

@@ -143,12 +143,12 @@ public class LbBuyAccountServiceImpl
} }
LambdaQueryWrapper<LbBuyAccount> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<LbBuyAccount> queryWrapper = new LambdaQueryWrapper<>();
if (tenantId != null && !tenantId.trim().isEmpty()) { // if (tenantId != null && !tenantId.trim().isEmpty()) {
queryWrapper.eq(LbBuyAccount::getTenantId, tenantId.trim()); // queryWrapper.eq(LbBuyAccount::getTenantId, tenantId.trim());
} // }
if (tenantName != null && !tenantName.trim().isEmpty()) { // if (tenantName != null && !tenantName.trim().isEmpty()) {
queryWrapper.like(LbBuyAccount::getTenantName, tenantName.trim()); // queryWrapper.like(LbBuyAccount::getTenantName, tenantName.trim());
} // }
if (loginAccount != null && !loginAccount.trim().isEmpty()) { if (loginAccount != null && !loginAccount.trim().isEmpty()) {
queryWrapper.like(LbBuyAccount::getLoginAccount, loginAccount.trim()); queryWrapper.like(LbBuyAccount::getLoginAccount, loginAccount.trim());
} }
@@ -223,7 +223,7 @@ public class LbBuyAccountServiceImpl
return result; return result;
} }
List<LbBuyAccount> accounts = this.listByIds(normalizedIds); List<LbBuyAccount> accounts = baseMapper.selectByIdsIgnoreTenant(normalizedIds);
Map<String, LbBuyAccount> accountMap = new LinkedHashMap<>(); Map<String, LbBuyAccount> accountMap = new LinkedHashMap<>();
for (LbBuyAccount account : accounts) { for (LbBuyAccount account : accounts) {
if (account != null && account.getId() != null) { if (account != null && account.getId() != null) {

View File

@@ -13,13 +13,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.rj.dto.hxr.HxrAdminUserApiContext; import com.rj.dto.hxr.HxrAdminUserApiContext;
import com.rj.dto.hxr.HxrUserRow; import com.rj.dto.hxr.HxrUserRow;
import com.rj.entity.LbDailyUserTrade;
import com.rj.entity.LbDailyUserTradeReport; import com.rj.entity.LbDailyUserTradeReport;
import com.rj.entity.LbOrderRow; import com.rj.entity.LbOrderRow;
import com.rj.entity.LbPurchaseApply; import com.rj.entity.LbPurchaseApply;
import com.rj.entity.LbUser; import com.rj.entity.LbUser;
import com.rj.util.IsoWorkdayUtils; import com.rj.util.IsoWorkdayUtils;
import com.rj.mapper.LbDailyUserTradeMapper;
import com.rj.mapper.LbDailyUserTradeReportMapper; import com.rj.mapper.LbDailyUserTradeReportMapper;
import com.rj.mapper.LbOrderRowMapper; import com.rj.mapper.LbOrderRowMapper;
import com.rj.mapper.LbPurchaseApplyMapper; import com.rj.mapper.LbPurchaseApplyMapper;
@@ -67,9 +65,6 @@ public class LbPurchaseApplyServiceImpl
@Autowired @Autowired
private LbDailyUserTradeReportMapper lbDailyUserTradeReportMapper; private LbDailyUserTradeReportMapper lbDailyUserTradeReportMapper;
@Autowired
private LbDailyUserTradeMapper lbDailyUserTradeMapper;
@Autowired @Autowired
private HxrAdminUserService hxrAdminUserService; private HxrAdminUserService hxrAdminUserService;
@@ -1025,7 +1020,7 @@ public class LbPurchaseApplyServiceImpl
} }
HxrAdminUserApiContext apiContext = apiContextOpt.get(); HxrAdminUserApiContext apiContext = apiContextOpt.get();
Set<String> tradeMatchedNicknames = ctx.tradeMatchedNicknames(); Set<String> tradeMatchedApplyPhones = ctx.tradeMatchedApplyPhones();
List<Map<String, Object>> details = new ArrayList<>(); List<Map<String, Object>> details = new ArrayList<>();
int ok = 0; int ok = 0;
int fail = 0; int fail = 0;
@@ -1037,7 +1032,7 @@ public class LbPurchaseApplyServiceImpl
one.put("applyUserName", applyUserName); one.put("applyUserName", applyUserName);
String phone = row.getColleaguePhone() != null ? row.getColleaguePhone().trim() : ""; String phone = row.getColleaguePhone() != null ? row.getColleaguePhone().trim() : "";
one.put("colleaguePhone", phone); one.put("colleaguePhone", phone);
String skipReason = colleagueVipSkipReason(row, tradeMatchedNicknames); String skipReason = colleagueVipSkipReason(row, tradeMatchedApplyPhones);
if (skipReason != null) { if (skipReason != null) {
one.put("success", false); one.put("success", false);
one.put("message", skipReason); one.put("message", skipReason);
@@ -1118,7 +1113,7 @@ public class LbPurchaseApplyServiceImpl
List<LbPurchaseApply> exportRows = new ArrayList<>(); List<LbPurchaseApply> exportRows = new ArrayList<>();
for (LbPurchaseApply row : ctx.rows()) { for (LbPurchaseApply row : ctx.rows()) {
if (colleagueVipSkipReason(row, ctx.tradeMatchedNicknames()) == null) { if (colleagueVipSkipReason(row, ctx.tradeMatchedApplyPhones()) == null) {
exportRows.add(row); exportRows.add(row);
} }
} }
@@ -1187,7 +1182,7 @@ public class LbPurchaseApplyServiceImpl
private record ColleagueVipContext( private record ColleagueVipContext(
String validationError, String validationError,
List<LbPurchaseApply> rows, List<LbPurchaseApply> rows,
Set<String> tradeMatchedNicknames) {} Set<String> tradeMatchedApplyPhones) {}
private ColleagueVipContext resolveColleagueVipContext( private ColleagueVipContext resolveColleagueVipContext(
LocalDate applyDateStart, LocalDate applyDateEnd, String tenantId) { LocalDate applyDateStart, LocalDate applyDateEnd, String tenantId) {
@@ -1210,36 +1205,46 @@ public class LbPurchaseApplyServiceImpl
rows = List.of(); rows = List.of();
} }
Set<String> applyUserNames = new HashSet<>(); Set<String> applyPhones = new HashSet<>();
for (LbPurchaseApply row : rows) { for (LbPurchaseApply row : rows) {
if (row.getColleagueName() != null && !row.getColleagueName().trim().isEmpty() String applyPhone = trimToNull(row.getApplyPhone());
&& row.getApplyUser() != null && !row.getApplyUser().trim().isEmpty()) { if (applyPhone != null) {
applyUserNames.add(row.getApplyUser().trim()); applyPhones.add(applyPhone);
} }
} }
Set<String> tradeMatchedNicknames = new HashSet<>(); Set<String> tradeMatchedApplyPhones = new HashSet<>();
if (!applyUserNames.isEmpty()) { if (!applyPhones.isEmpty()) {
LambdaQueryWrapper<LbDailyUserTrade> tradeQuery = new LambdaQueryWrapper<>(); String buyTimeStart = applyDateStart.atStartOfDay().format(ORDER_DAY_TIME_FMT);
tradeQuery.eq(LbDailyUserTrade::getTenantId, tenantId.trim()) String buyTimeEnd = applyDateEnd.atTime(23, 59, 59).format(ORDER_DAY_TIME_FMT);
.in(LbDailyUserTrade::getNickname, applyUserNames) LambdaQueryWrapper<LbOrderRow> orderQuery = new LambdaQueryWrapper<>();
.select(LbDailyUserTrade::getNickname); orderQuery.eq(LbOrderRow::getTenantId, tenantId.trim())
List<LbDailyUserTrade> matchedTrades = lbDailyUserTradeMapper.selectList(tradeQuery); .eq(LbOrderRow::getDataType, ORDER_DATA_TYPE_DETAIL)
for (LbDailyUserTrade trade : matchedTrades) { .ge(LbOrderRow::getBuyTime, buyTimeStart)
if (trade.getNickname() != null && !trade.getNickname().trim().isEmpty()) { .le(LbOrderRow::getBuyTime, buyTimeEnd)
tradeMatchedNicknames.add(trade.getNickname().trim()); .in(LbOrderRow::getBuyerPhone, applyPhones)
.isNotNull(LbOrderRow::getPayTime)
.select(LbOrderRow::getBuyerPhone);
List<LbOrderRow> orderRows = lbOrderRowMapper.selectList(orderQuery);
if (orderRows != null) {
for (LbOrderRow orderRow : orderRows) {
String buyerPhone = trimToNull(orderRow.getBuyerPhone());
if (buyerPhone != null) {
tradeMatchedApplyPhones.add(buyerPhone);
} }
} }
} }
return new ColleagueVipContext(null, rows, tradeMatchedNicknames); }
return new ColleagueVipContext(null, rows, tradeMatchedApplyPhones);
} }
private static String colleagueVipSkipReason(LbPurchaseApply row, Set<String> tradeMatchedNicknames) { private static String colleagueVipSkipReason(LbPurchaseApply row, Set<String> tradeMatchedApplyPhones) {
String applyUserName = row.getApplyUser() != null ? row.getApplyUser().trim() : ""; String applyPhone = row.getApplyPhone() != null ? row.getApplyPhone().trim() : "";
if (applyUserName.isEmpty()) { if (applyPhone.isEmpty()) {
return "colleague_name 为空,跳过"; return "apply_phone 为空,跳过";
} }
if (!tradeMatchedNicknames.contains(applyUserName)) { if (!tradeMatchedApplyPhones.contains(applyPhone)) {
return "申请人姓名在 lb_daily_user_trade 中未找到 ,说明今天没进货 ,推荐人不能享受特权,跳过开通特权"; return "申请人手机号在 lb_order_rowbuyer_phone中未找到已支付订单说明未进货,推荐人不能享受特权,跳过开通特权";
} }
String phone = row.getColleaguePhone() != null ? row.getColleaguePhone().trim() : ""; String phone = row.getColleaguePhone() != null ? row.getColleaguePhone().trim() : "";
if (phone.isEmpty()) { if (phone.isEmpty()) {