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

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("ai_prompts"); // AI 提示词全局配置,表无 tenant_id 字段
ignoreTables.add("lb_third_integration_config"); // 每租户一条,按 tenant_id 显式查询,不走插件自动拼接
ignoreTables.add("lb_buy_account"); // 抢单账号跨租户管理;分页/批量抢单按记录 tenant_id 业务处理
return new TenantLineHandler() {

View File

@@ -5,13 +5,29 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.rj.entity.LbBuyAccount;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.time.LocalDateTime;
import java.util.List;
@Mapper
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 行。
*/

View File

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