|
@@ -1,4 +1,4 @@
|
|
|
-package shop.alien.util;
|
|
|
|
|
|
|
+package shop.alien.lawyer.util;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -19,16 +19,11 @@ import shop.alien.util.type.TypeUtil;
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * life_like_record 点赞人身份工具。
|
|
|
|
|
- * <p>
|
|
|
|
|
- * 入参:兼容前端 legacy {@code dianzanId}(user_/store_/lawyer_ 或纯数字 life_user.id)。<br>
|
|
|
|
|
- * 库表:查询/新增/修改只使用 {@code dianzan_user_type} + {@code dianzan_ref_id},不读写 {@code dianzan_id} 列。<br>
|
|
|
|
|
- * 响应:由 type+refId 合成 {@code dianzanId} 返回给前端。
|
|
|
|
|
- * </p>
|
|
|
|
|
|
|
+ * alien-lawyer:life_like_record 点赞人身份工具。
|
|
|
*/
|
|
*/
|
|
|
@Component
|
|
@Component
|
|
|
@RequiredArgsConstructor
|
|
@RequiredArgsConstructor
|
|
|
-public class LifeLikeIdentityHelper {
|
|
|
|
|
|
|
+public class LawyerLikeRecordIdentityHelper {
|
|
|
|
|
|
|
|
public static final int TYPE_USER = 1;
|
|
public static final int TYPE_USER = 1;
|
|
|
public static final int TYPE_STORE = 2;
|
|
public static final int TYPE_STORE = 2;
|
|
@@ -39,12 +34,12 @@ public class LifeLikeIdentityHelper {
|
|
|
private final StoreUserMapper storeUserMapper;
|
|
private final StoreUserMapper storeUserMapper;
|
|
|
private final LawyerUserMapper lawyerUserMapper;
|
|
private final LawyerUserMapper lawyerUserMapper;
|
|
|
|
|
|
|
|
- public static final class LikerScope {
|
|
|
|
|
|
|
+ public static final class LawyerLikerScope {
|
|
|
private final String legacyDianzanId;
|
|
private final String legacyDianzanId;
|
|
|
private final Integer dianzanUserType;
|
|
private final Integer dianzanUserType;
|
|
|
private final Integer dianzanRefId;
|
|
private final Integer dianzanRefId;
|
|
|
|
|
|
|
|
- public LikerScope(String legacyDianzanId, Integer dianzanUserType, Integer dianzanRefId) {
|
|
|
|
|
|
|
+ public LawyerLikerScope(String legacyDianzanId, Integer dianzanUserType, Integer dianzanRefId) {
|
|
|
this.legacyDianzanId = legacyDianzanId;
|
|
this.legacyDianzanId = legacyDianzanId;
|
|
|
this.dianzanUserType = dianzanUserType;
|
|
this.dianzanUserType = dianzanUserType;
|
|
|
this.dianzanRefId = dianzanRefId;
|
|
this.dianzanRefId = dianzanRefId;
|
|
@@ -67,63 +62,60 @@ public class LifeLikeIdentityHelper {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** 将前端传入的 legacy dianzanId 解析为 type+refId(仅入参侧兼容)。 */
|
|
|
|
|
- public LikerScope resolveFromDianzanId(String dianzanId) {
|
|
|
|
|
|
|
+ public LawyerLikerScope resolveFromDianzanId(String dianzanId) {
|
|
|
if (!StringUtils.hasText(dianzanId)) {
|
|
if (!StringUtils.hasText(dianzanId)) {
|
|
|
- return new LikerScope(null, null, null);
|
|
|
|
|
|
|
+ return new LawyerLikerScope(null, null, null);
|
|
|
}
|
|
}
|
|
|
String trimmed = dianzanId.trim();
|
|
String trimmed = dianzanId.trim();
|
|
|
if (typeUtil.containsUnderscore(trimmed)) {
|
|
if (typeUtil.containsUnderscore(trimmed)) {
|
|
|
PhoneTypeIdResult resolved = typeUtil.resolveTypeAndId(trimmed);
|
|
PhoneTypeIdResult resolved = typeUtil.resolveTypeAndId(trimmed);
|
|
|
if (resolved != null) {
|
|
if (resolved != null) {
|
|
|
- return new LikerScope(trimmed, resolved.getType(), resolved.getId());
|
|
|
|
|
|
|
+ return new LawyerLikerScope(trimmed, resolved.getType(), resolved.getId());
|
|
|
}
|
|
}
|
|
|
- return new LikerScope(trimmed, null, null);
|
|
|
|
|
|
|
+ return new LawyerLikerScope(trimmed, null, null);
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
|
int refId = Integer.parseInt(trimmed);
|
|
int refId = Integer.parseInt(trimmed);
|
|
|
- return new LikerScope(trimmed, TYPE_USER, refId);
|
|
|
|
|
|
|
+ return new LawyerLikerScope(trimmed, TYPE_USER, refId);
|
|
|
} catch (NumberFormatException e) {
|
|
} catch (NumberFormatException e) {
|
|
|
- return new LikerScope(trimmed, null, null);
|
|
|
|
|
|
|
+ return new LawyerLikerScope(trimmed, null, null);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public LikerScope fromLifeUserId(Integer lifeUserId) {
|
|
|
|
|
|
|
+ public LawyerLikerScope fromLifeUserId(Integer lifeUserId) {
|
|
|
if (lifeUserId == null) {
|
|
if (lifeUserId == null) {
|
|
|
- return new LikerScope(null, null, null);
|
|
|
|
|
|
|
+ return new LawyerLikerScope(null, null, null);
|
|
|
}
|
|
}
|
|
|
- return new LikerScope(String.valueOf(lifeUserId), TYPE_USER, lifeUserId);
|
|
|
|
|
|
|
+ return new LawyerLikerScope(String.valueOf(lifeUserId), TYPE_USER, lifeUserId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public LikerScope fromStoreUserId(Integer storeUserId) {
|
|
|
|
|
|
|
+ public LawyerLikerScope fromStoreUserId(Integer storeUserId) {
|
|
|
if (storeUserId == null) {
|
|
if (storeUserId == null) {
|
|
|
- return new LikerScope(null, null, null);
|
|
|
|
|
|
|
+ return new LawyerLikerScope(null, null, null);
|
|
|
}
|
|
}
|
|
|
StoreUser storeUser = storeUserMapper.selectById(storeUserId);
|
|
StoreUser storeUser = storeUserMapper.selectById(storeUserId);
|
|
|
String legacy = storeUser != null && StringUtils.hasText(storeUser.getPhone())
|
|
String legacy = storeUser != null && StringUtils.hasText(storeUser.getPhone())
|
|
|
? "store_" + storeUser.getPhone()
|
|
? "store_" + storeUser.getPhone()
|
|
|
: String.valueOf(storeUserId);
|
|
: String.valueOf(storeUserId);
|
|
|
- return new LikerScope(legacy, TYPE_STORE, storeUserId);
|
|
|
|
|
|
|
+ return new LawyerLikerScope(legacy, TYPE_STORE, storeUserId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** 从库表记录解析点赞人(仅认 dianzan_user_type + dianzan_ref_id)。 */
|
|
|
|
|
- public LikerScope resolveFromRecord(LifeLikeRecord record) {
|
|
|
|
|
|
|
+ public LawyerLikerScope resolveFromRecord(LifeLikeRecord record) {
|
|
|
if (record == null
|
|
if (record == null
|
|
|
|| record.getDianzanUserType() == null
|
|
|| record.getDianzanUserType() == null
|
|
|
|| record.getDianzanRefId() == null) {
|
|
|| record.getDianzanRefId() == null) {
|
|
|
- return new LikerScope(null, null, null);
|
|
|
|
|
|
|
+ return new LawyerLikerScope(null, null, null);
|
|
|
}
|
|
}
|
|
|
String legacy = buildLegacyDianzanId(record.getDianzanUserType(), record.getDianzanRefId());
|
|
String legacy = buildLegacyDianzanId(record.getDianzanUserType(), record.getDianzanRefId());
|
|
|
- return new LikerScope(legacy, record.getDianzanUserType(), record.getDianzanRefId());
|
|
|
|
|
|
|
+ return new LawyerLikerScope(legacy, record.getDianzanUserType(), record.getDianzanRefId());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** 写入前:由入参 dianzanId 或显式 type+refId 填充新字段,不落库 dianzan_id。 */
|
|
|
|
|
public void normalizeBeforeSave(LifeLikeRecord record) {
|
|
public void normalizeBeforeSave(LifeLikeRecord record) {
|
|
|
if (record == null) {
|
|
if (record == null) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
if (record.getDianzanUserType() == null || record.getDianzanRefId() == null) {
|
|
if (record.getDianzanUserType() == null || record.getDianzanRefId() == null) {
|
|
|
- LikerScope scope = resolveFromDianzanId(record.getDianzanId());
|
|
|
|
|
|
|
+ LawyerLikerScope scope = resolveFromDianzanId(record.getDianzanId());
|
|
|
if (scope.hasTypeRef()) {
|
|
if (scope.hasTypeRef()) {
|
|
|
record.setDianzanUserType(scope.getDianzanUserType());
|
|
record.setDianzanUserType(scope.getDianzanUserType());
|
|
|
record.setDianzanRefId(scope.getDianzanRefId());
|
|
record.setDianzanRefId(scope.getDianzanRefId());
|
|
@@ -132,7 +124,7 @@ public class LifeLikeIdentityHelper {
|
|
|
record.setDianzanId(null);
|
|
record.setDianzanId(null);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void applyLikerFilter(LambdaQueryWrapper<LifeLikeRecord> wrapper, LikerScope scope) {
|
|
|
|
|
|
|
+ public void applyLikerFilter(LambdaQueryWrapper<LifeLikeRecord> wrapper, LawyerLikerScope scope) {
|
|
|
if (wrapper == null || scope == null || !scope.hasTypeRef()) {
|
|
if (wrapper == null || scope == null || !scope.hasTypeRef()) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -140,7 +132,7 @@ public class LifeLikeIdentityHelper {
|
|
|
.eq(LifeLikeRecord::getDianzanRefId, scope.getDianzanRefId());
|
|
.eq(LifeLikeRecord::getDianzanRefId, scope.getDianzanRefId());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void applyLikerFilter(LambdaUpdateWrapper<LifeLikeRecord> wrapper, LikerScope scope) {
|
|
|
|
|
|
|
+ public void applyLikerFilter(LambdaUpdateWrapper<LifeLikeRecord> wrapper, LawyerLikerScope scope) {
|
|
|
if (wrapper == null || scope == null || !scope.hasTypeRef()) {
|
|
if (wrapper == null || scope == null || !scope.hasTypeRef()) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -148,11 +140,11 @@ public class LifeLikeIdentityHelper {
|
|
|
.eq(LifeLikeRecord::getDianzanRefId, scope.getDianzanRefId());
|
|
.eq(LifeLikeRecord::getDianzanRefId, scope.getDianzanRefId());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void applyLikerFilter(QueryWrapper<LifeLikeRecord> wrapper, LikerScope scope) {
|
|
|
|
|
|
|
+ public void applyLikerFilter(QueryWrapper<LifeLikeRecord> wrapper, LawyerLikerScope scope) {
|
|
|
applyLikerFilter(wrapper, scope, null);
|
|
applyLikerFilter(wrapper, scope, null);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void applyLikerFilter(QueryWrapper<LifeLikeRecord> wrapper, LikerScope scope, String tableAlias) {
|
|
|
|
|
|
|
+ public void applyLikerFilter(QueryWrapper<LifeLikeRecord> wrapper, LawyerLikerScope scope, String tableAlias) {
|
|
|
if (wrapper == null || scope == null || !scope.hasTypeRef()) {
|
|
if (wrapper == null || scope == null || !scope.hasTypeRef()) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -161,9 +153,8 @@ public class LifeLikeIdentityHelper {
|
|
|
.eq(prefix + "dianzan_ref_id", scope.getDianzanRefId());
|
|
.eq(prefix + "dianzan_ref_id", scope.getDianzanRefId());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** 与 life_fans 等仍使用 legacy 字符串的模块比对。 */
|
|
|
|
|
public String resolveComparableDianzanId(LifeLikeRecord record) {
|
|
public String resolveComparableDianzanId(LifeLikeRecord record) {
|
|
|
- LikerScope scope = resolveFromRecord(record);
|
|
|
|
|
|
|
+ LawyerLikerScope scope = resolveFromRecord(record);
|
|
|
if (scope.hasTypeRef()) {
|
|
if (scope.hasTypeRef()) {
|
|
|
String legacy = buildLegacyDianzanId(scope.getDianzanUserType(), scope.getDianzanRefId());
|
|
String legacy = buildLegacyDianzanId(scope.getDianzanUserType(), scope.getDianzanRefId());
|
|
|
if (legacy != null) {
|
|
if (legacy != null) {
|
|
@@ -201,7 +192,6 @@ public class LifeLikeIdentityHelper {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** 响应侧:由 type+refId 合成 dianzanId,不读库表 dianzan_id。 */
|
|
|
|
|
public void ensureEntityLegacyDianzanId(LifeLikeRecord record) {
|
|
public void ensureEntityLegacyDianzanId(LifeLikeRecord record) {
|
|
|
if (record == null || record.getDianzanUserType() == null || record.getDianzanRefId() == null) {
|
|
if (record == null || record.getDianzanUserType() == null || record.getDianzanRefId() == null) {
|
|
|
return;
|
|
return;
|