补齐父手机客户

This commit is contained in:
2026-05-19 09:31:13 +08:00
parent b73f5505bf
commit 893af21ce2
4 changed files with 47 additions and 3 deletions

View File

@@ -177,4 +177,8 @@ public class LbUser implements Serializable {
@TableField("pname") @TableField("pname")
@Schema(description = "上级用户昵称") @Schema(description = "上级用户昵称")
private String pname; private String pname;
@TableField("pmobile")
@Schema(description = "上级用户手机号")
private String pmobile;
} }

View File

@@ -14,4 +14,9 @@ public interface LbUserMapper extends BaseMapper<LbUser> {
* 按用户 id 批量 upsert同步外部用户数据 * 按用户 id 批量 upsert同步外部用户数据
*/ */
int upsertBatch(@Param("list") List<LbUser> list); int upsertBatch(@Param("list") List<LbUser> list);
/**
* 按 pid 关联同租户上级用户,将其 mobile 写入当前用户的 pmobile。
*/
int fillPmobileByTenantId(@Param("tenantId") String tenantId);
} }

View File

@@ -376,9 +376,21 @@ public class LbUserServiceImpl extends ServiceImpl<LbUserMapper, LbUser> impleme
page++; page++;
} }
int pmobileFilled = fillParentMobile(tid);
if (pmobileFilled < 0) {
result.put("success", false);
result.put("message", "用户已同步,但补齐上级手机号失败");
result.put("synced", totalSynced);
result.put("pmobileFilled", 0);
result.put("remoteCount", firstBody != null ? firstBody.count() : 0);
result.put("pages", page);
return result;
}
result.put("success", true); result.put("success", true);
result.put("message", totalSynced == 0 ? "接口成功,无用户数据" : "同步完成"); result.put("message", totalSynced == 0 ? "接口成功,无用户数据" : "同步完成");
result.put("synced", totalSynced); result.put("synced", totalSynced);
result.put("pmobileFilled", pmobileFilled);
result.put("remoteCount", firstBody != null ? firstBody.count() : 0); result.put("remoteCount", firstBody != null ? firstBody.count() : 0);
result.put("pages", page); result.put("pages", page);
return result; return result;
@@ -398,6 +410,20 @@ public class LbUserServiceImpl extends ServiceImpl<LbUserMapper, LbUser> impleme
} }
} }
/**
* 同步完成后,按 pid 查找上级用户并将其 mobile 写入 pmobile。
*
* @return 受影响行数;失败返回 -1
*/
private int fillParentMobile(String tenantId) {
try {
return baseMapper.fillPmobileByTenantId(tenantId);
} catch (Exception e) {
log.error("fillParentMobile failed, tenantId={}", tenantId, e);
return -1;
}
}
/** /**
* @return 实际 upsert 条数;无有效 id 时返回 0失败返回 -1 * @return 实际 upsert 条数;无有效 id 时返回 0失败返回 -1
*/ */

View File

@@ -9,7 +9,7 @@
last_time, last_ip, join_time, join_ip, token, created_at, updated_at, last_time, last_ip, join_time, join_ip, token, created_at, updated_at,
status, viptime, is_vip, contract, max_order, is_resell, status, viptime, is_vip, contract, max_order, is_resell,
yesterday_sell_count, today_buy_count, today_buy_total, today_sell_total, yesterday_sell_count, today_buy_count, today_buy_total, today_sell_total,
poor, pname poor, pname, pmobile
) VALUES ) VALUES
<foreach collection="list" item="item" separator=","> <foreach collection="list" item="item" separator=",">
( (
@@ -21,7 +21,8 @@
#{item.createdAt}, #{item.updatedAt}, #{item.createdAt}, #{item.updatedAt},
#{item.status}, #{item.viptime}, #{item.isVip}, #{item.contract}, #{item.maxOrder}, #{item.status}, #{item.viptime}, #{item.isVip}, #{item.contract}, #{item.maxOrder},
#{item.isResell}, #{item.yesterdaySellCount}, #{item.todayBuyCount}, #{item.isResell}, #{item.yesterdaySellCount}, #{item.todayBuyCount},
#{item.todayBuyTotal}, #{item.todaySellTotal}, #{item.poor}, #{item.pname} #{item.todayBuyTotal}, #{item.todaySellTotal}, #{item.poor}, #{item.pname},
#{item.pmobile}
) )
</foreach> </foreach>
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
@@ -60,7 +61,15 @@
today_buy_total = VALUES(today_buy_total), today_buy_total = VALUES(today_buy_total),
today_sell_total = VALUES(today_sell_total), today_sell_total = VALUES(today_sell_total),
poor = VALUES(poor), poor = VALUES(poor),
pname = VALUES(pname) pname = VALUES(pname),
pmobile = VALUES(pmobile)
</insert> </insert>
<update id="fillPmobileByTenantId">
UPDATE lb_user u
LEFT JOIN lb_user p ON u.pid = p.id AND u.tenant_id = p.tenant_id
SET u.pmobile = p.mobile
WHERE u.tenant_id = #{tenantId}
</update>
</mapper> </mapper>