You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
1.0 KiB
27 lines
1.0 KiB
package user
|
|
|
|
import "yunyan/pb"
|
|
|
|
// 老客户端兼容层。
|
|
//
|
|
// 背景:厂家→品牌商迁移把 DBProduct.factoryid 改成了 brandid,但线上已发布的 App 包把
|
|
// factoryid 当「非空 int」解析(Flutter 生成代码里是 `(json['factoryid'] as num).toInt()`),
|
|
// 字段缺失即 TypeError,整个 UserGetAppConfigResp.fromJson 失败 —— 表现为设备列表、应用配置
|
|
// 统统拉不到,而不是只丢一个字段。
|
|
//
|
|
// 因此 pb 里保留了 factoryid 兼容字段(gorm:"-",不建列、不参与读写),凡是会下发到客户端的
|
|
// DBProduct 都在读取层过一遍这里,把 brandid 的值回填过去。服务端与新端一律以 brandid 为准。
|
|
// 等老包淘汰干净后,删掉本文件与 db.proto 里的 factoryid 字段即可。
|
|
func compatProduct(model *pb.DBProduct) *pb.DBProduct {
|
|
if model != nil {
|
|
model.Factoryid = model.Brandid
|
|
}
|
|
return model
|
|
}
|
|
|
|
func compatProducts(models []*pb.DBProduct) []*pb.DBProduct {
|
|
for _, v := range models {
|
|
compatProduct(v)
|
|
}
|
|
return models
|
|
}
|
|
|