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.
68 lines
2.4 KiB
68 lines
2.4 KiB
package api
|
|
|
|
import (
|
|
"yunyan/comm"
|
|
"yunyan/lego/sys/log"
|
|
"yunyan/pb"
|
|
)
|
|
|
|
// RevokeProductionBatch 撤销一个生产批次:
|
|
// 1. 校验批次存在且归属指定产品;
|
|
// 2. 该批次中若已有任意一个授权码被使用(status>0 或 uid 非空),拒绝撤销;
|
|
// 3. 删除该批次全部授权码 + 删除批次台账记录。
|
|
//
|
|
// 注意:不回退 product.serialcursor(已分发出去的序号区间不重复利用,避免与历史导出冲突)。
|
|
func (this *apiComp) RevokeProductionBatch(session comm.IUserSession, req *pb.ApiRevokeProductionBatchReq) (resp *pb.ApiRevokeProductionBatchResp, errdata *pb.ErrorData) {
|
|
if req.Productid == 0 || req.Batchno == "" {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Message: "productid/batchno 不能为空",
|
|
}
|
|
return
|
|
}
|
|
|
|
batch, err := this.module.model.productionbatch(req.Batchno)
|
|
if err != nil || batch == nil || batch.Productid != req.Productid {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: "未找到指定生产批次",
|
|
}
|
|
return
|
|
}
|
|
|
|
used, err := this.module.model.countUsedAuthCodesByBatch(req.Productid, req.Batchno)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{Code: pb.ErrorCode_DBError, Message: err.Error()}
|
|
this.module.Error("RevokeProductionBatch count used Fail!", log.Field{Key: "err", Value: err.Error()})
|
|
return
|
|
}
|
|
if used > 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Message: "该批次已有授权码被激活/绑定,无法撤销",
|
|
}
|
|
return
|
|
}
|
|
|
|
affected, err := this.module.model.delAuthCodesByBatch(req.Productid, req.Batchno)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{Code: pb.ErrorCode_DBError, Message: err.Error()}
|
|
this.module.Error("RevokeProductionBatch delete authcodes Fail!", log.Field{Key: "err", Value: err.Error()})
|
|
return
|
|
}
|
|
|
|
if err = this.module.model.delproductionbatch(req.Batchno); err != nil {
|
|
errdata = &pb.ErrorData{Code: pb.ErrorCode_DBError, Message: err.Error()}
|
|
this.module.Error("RevokeProductionBatch delete batch Fail!", log.Field{Key: "err", Value: err.Error()})
|
|
return
|
|
}
|
|
|
|
this.module.Info("RevokeProductionBatch ok",
|
|
log.Field{Key: "operator", Value: session.GetUserId()},
|
|
log.Field{Key: "productid", Value: req.Productid},
|
|
log.Field{Key: "batchno", Value: req.Batchno},
|
|
log.Field{Key: "deleted", Value: affected})
|
|
|
|
resp = &pb.ApiRevokeProductionBatchResp{Deleted: uint32(affected)}
|
|
return
|
|
}
|
|
|