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.
26 lines
1.1 KiB
26 lines
1.1 KiB
package comm
|
|
|
|
import "strings"
|
|
|
|
// ScopeToProduct 把「只看这个产品」这层过滤显式拼进查询条件。
|
|
//
|
|
// device_mac 合表之后(2026-09-04 由 license_<pid十六进制> 分表合并而来),
|
|
// productid 不再由表名承担。原先每个函数都靠 license_<pid> 这张表**隐含**了
|
|
// 产品作用域,合表后**每一处按产品语义的读写都必须显式带上 productid**——
|
|
// 漏一处就跨产品操作:查询多列出别的产品的设备还只是难看,
|
|
// 批量禁用 / 按批次删除漏掉就是直接误伤别人的数据。
|
|
//
|
|
// pid == 0 表示不限产品(后台「全部产品」视图),此时原样返回。
|
|
func ScopeToProduct(pid uint32, query string, args []interface{}) (string, []interface{}) {
|
|
if pid == 0 {
|
|
return query, args
|
|
}
|
|
scoped := make([]interface{}, 0, len(args)+1)
|
|
scoped = append(scoped, pid)
|
|
scoped = append(scoped, args...)
|
|
if strings.TrimSpace(query) == "" {
|
|
return "productid=?", scoped
|
|
}
|
|
// 原条件整体括起来:调用方传的可能是 "a=? or b=?",不括会让 or 把 productid 短路掉。
|
|
return "productid=? and (" + query + ")", scoped
|
|
}
|
|
|