2869994387
1. RequestInfoControllerV1 save 接口对 RequestInfo 参数做 @Valid 校验; 2. RequestInfoControllerV1 去除批量操作中的置匿名/去匿名,因为对于 RequestInfo 而言,当前已无字段标记匿名与否,仅凭是否配置用户名和密码来判断是否为匿名; 3. RequestInfoService 查找不到默认配置时创建 new RequestInfo(),虽数据表有触发器置 isDefault = true,但此处仍手动 set,确保一致性; 4. RequestInfo 一些依赖 DeviceInfo 的字段,不做冗余,直接从 DeviceInfo <- fingerprint/deviceName/softwareType 恢复。
54 lines
1.9 KiB
Java
54 lines
1.9 KiB
Java
package quant.rich.emoney.service.sqlite;
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.stereotype.Service;
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import jakarta.annotation.PostConstruct;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import quant.rich.emoney.entity.sqlite.RequestInfo;
|
|
import quant.rich.emoney.mapper.sqlite.RequestInfoMapper;
|
|
import quant.rich.emoney.patch.okhttp.PatchOkHttp;
|
|
import quant.rich.emoney.patch.okhttp.PatchOkHttpRule;
|
|
|
|
@DS("sqlite")
|
|
@Service
|
|
@Slf4j
|
|
@Lazy(false)
|
|
public class RequestInfoService extends SqliteServiceImpl<RequestInfoMapper, RequestInfo> {
|
|
|
|
private volatile Integer userAgentPatchRuleId;
|
|
|
|
@PostConstruct
|
|
void postConstruct() {
|
|
userAgentPatchRuleId = PatchOkHttp.apply(
|
|
PatchOkHttpRule.when()
|
|
.hostEndsWith("emoney.cn")
|
|
.not(r -> r.hostMatches("appstatic"))
|
|
.or(a -> a.hostContains("emapp"))
|
|
.or(b -> b.hasHeaderName("X-Protocol-Id"))
|
|
.overrideHeader("User-Agent", new Supplier<String>() {
|
|
@Override
|
|
public String get() {
|
|
log.debug("触发获取请求配置的 OkHttpUserAgent");
|
|
return getDefaultRequestInfo().getOkHttpUserAgent();
|
|
}
|
|
}).build().setId(userAgentPatchRuleId));
|
|
}
|
|
|
|
public RequestInfo getDefaultRequestInfo() {
|
|
RequestInfo requestInfo = getOne(
|
|
new LambdaQueryWrapper<RequestInfo>().eq(RequestInfo::getIsDefault, true)
|
|
);
|
|
if (requestInfo == null) {
|
|
requestInfo = new RequestInfo();
|
|
requestInfo.setIsDefault(true);
|
|
save(requestInfo);
|
|
}
|
|
return requestInfo;
|
|
}
|
|
|
|
}
|