by Robin at 20240702
This commit is contained in:
parent
8d170ef8ef
commit
7dcde6a448
|
@ -13,7 +13,9 @@ import (
|
|||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/qiniu/qmgo"
|
||||
"github.com/qiniu/qmgo/options"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
options2 "go.mongodb.org/mongo-driver/mongo/options"
|
||||
|
||||
accountproto "service/api/proto/account/proto"
|
||||
account_cancellationproto "service/api/proto/account_cancellation/proto"
|
||||
|
@ -5330,6 +5332,44 @@ func (m *Mongo) GetWorkerIdByMid(ctx *gin.Context, req *workeridproto.OpListByMi
|
|||
return workerId, err
|
||||
}
|
||||
|
||||
func (m *Mongo) UpsertWorkerIdByWorkerId(ctx *gin.Context, worker_id *dbstruct.WorkerId) error {
|
||||
col := m.getColWorkerId()
|
||||
|
||||
query := qmgo.M{
|
||||
"worker_id": worker_id.GetWorkerId(),
|
||||
}
|
||||
|
||||
set := util.EntityToM(worker_id)
|
||||
set["_id"] = worker_id.GetId()
|
||||
|
||||
up := qmgo.M{
|
||||
"$setOnInsert": set,
|
||||
}
|
||||
|
||||
opts := options2.Update().SetUpsert(true)
|
||||
|
||||
err := col.UpdateOne(ctx, query, up, options.UpdateOptions{
|
||||
UpdateHook: qmgo.M{},
|
||||
UpdateOptions: opts,
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *Mongo) UpdateWorkerIdByWorkerId(ctx *gin.Context, worker_id *dbstruct.WorkerId, workerId string) error {
|
||||
col := m.getColWorkerId()
|
||||
set := util.EntityToM(worker_id)
|
||||
set["ut"] = time.Now().Unix()
|
||||
up := qmgo.M{
|
||||
"$set": set,
|
||||
}
|
||||
filter := qmgo.M{
|
||||
"worker_id": workerId,
|
||||
}
|
||||
err := col.UpdateOne(ctx, filter, up)
|
||||
return err
|
||||
}
|
||||
|
||||
// 慧用工下发打款历史表相关
|
||||
func (m *Mongo) CreateSingleDistributeHis(ctx *gin.Context, single_distribute_his *dbstruct.SingleDistributeHis) error {
|
||||
col := m.getColSingleDistributeHis()
|
||||
|
|
|
@ -63,3 +63,25 @@ func (p *WorkerId) OpListByMid(ctx *gin.Context, req *worker_idproto.OpListByMid
|
|||
}
|
||||
return workerId, nil
|
||||
}
|
||||
|
||||
func (p *WorkerId) OpUpsert(ctx *gin.Context, req *worker_idproto.OpCreateReq) error {
|
||||
req.WorkerId.Id = goproto.Int64(idgenerator.GenWorkerIdId())
|
||||
req.WorkerId.Ct = goproto.Int64(time.Now().Unix())
|
||||
req.WorkerId.Ut = goproto.Int64(time.Now().Unix())
|
||||
req.WorkerId.DelFlag = goproto.Int64(consts.Exist)
|
||||
err := p.store.UpsertWorkerIdByWorkerId(ctx, req.WorkerId)
|
||||
if err != nil {
|
||||
logger.Error("UpsertWorkerIdByWorkerId fail, err: %v", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *WorkerId) OpUpdateByWorkerId(ctx *gin.Context, req *worker_idproto.OpUpdateReq, workerId string) error {
|
||||
err := p.store.UpdateWorkerIdByWorkerId(ctx, req.WorkerId, workerId)
|
||||
if err != nil {
|
||||
logger.Error("UpdateWorkerIdByWorkerId fail, err: %v", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -4168,8 +4168,8 @@ func (s *Service) SaveAgreeCallback(ctx *gin.Context, req *hvyogoproto.ExtAgreeC
|
|||
return
|
||||
}
|
||||
|
||||
// 存入数据
|
||||
err = _DefaultWorkerId.OpCreate(ctx, &workeridproto.OpCreateReq{
|
||||
// 预创建
|
||||
err = _DefaultWorkerId.OpUpsert(ctx, &workeridproto.OpCreateReq{
|
||||
WorkerId: &dbstruct.WorkerId{
|
||||
Mid: list[0].Mid,
|
||||
WorkerId: goproto.String(vo.WorkerId),
|
||||
|
@ -4181,6 +4181,18 @@ func (s *Service) SaveAgreeCallback(ctx *gin.Context, req *hvyogoproto.ExtAgreeC
|
|||
return
|
||||
}
|
||||
|
||||
// 重写
|
||||
err = _DefaultWorkerId.OpUpdateByWorkerId(ctx, &workeridproto.OpUpdateReq{
|
||||
WorkerId: &dbstruct.WorkerId{
|
||||
Mid: list[0].Mid,
|
||||
},
|
||||
}, vo.WorkerId)
|
||||
if err != nil {
|
||||
logger.Error("_DefaultWorkerId OpUpdateByWorkerId fail, req: %v, err: %v", util.ToJson(req), err)
|
||||
ec = errcode.ErrCodeWorkerIdSrvFail
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,13 @@ type WorkerId struct {
|
|||
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记
|
||||
}
|
||||
|
||||
func (p *WorkerId) GetId() int64 {
|
||||
if p == nil || p.Id == nil {
|
||||
return 0
|
||||
}
|
||||
return *p.Id
|
||||
}
|
||||
|
||||
func (p *WorkerId) GetWorkerId() string {
|
||||
if p == nil || p.WorkerId == nil {
|
||||
return ""
|
||||
|
|
Loading…
Reference in New Issue