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.
 
 
 
 
 
 

54 lines
1.2 KiB

package api
import (
"yunyan/comm"
"yunyan/pb"
)
// 查询生产批次台账(生产授权码日志统计)
func (this *apiComp) GetProductionBatches(session comm.IUserSession, req *pb.ApiGetProductionBatchesReq) (resp *pb.ApiGetProductionBatchesResp, errdata *pb.ErrorData) {
query := "1=1"
args := make([]interface{}, 0)
if req.Brandid > 0 {
query += " AND brandid = ?"
args = append(args, req.Brandid)
}
if req.Productid > 0 {
query += " AND productid = ?"
args = append(args, req.Productid)
}
if req.Start > 0 {
query += " AND ts >= ?"
args = append(args, req.Start)
}
if req.End > 0 {
query += " AND ts <= ?"
args = append(args, req.End)
}
limit := int(req.Limit)
if limit <= 0 || limit > 2000 {
limit = 500
}
query += " ORDER BY ts DESC LIMIT ?"
args = append(args, limit)
notes, err := this.module.model.productionbatches(query, args...)
if err != nil {
errdata = &pb.ErrorData{Code: pb.ErrorCode_DBError, Message: err.Error()}
return
}
var totalDevices int64
for _, n := range notes {
totalDevices += int64(n.Devicenum)
}
resp = &pb.ApiGetProductionBatchesResp{
Notes: notes,
TotalBatch: int64(len(notes)),
TotalDevices: totalDevices,
}
return
}