93 lines
2.3 KiB
Go
93 lines
2.3 KiB
Go
package logic
|
|
|
|
import (
|
|
"fmt"
|
|
"service/api/consts"
|
|
footprintproto "service/api/proto/footprint/proto"
|
|
"service/app/mix/dao"
|
|
"service/dbstruct"
|
|
"service/library/idgenerator"
|
|
"service/library/logger"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
goproto "google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
type FootPrint struct {
|
|
store *dao.Store
|
|
}
|
|
|
|
func NewFootPrint(store *dao.Store) (a *FootPrint) {
|
|
a = &FootPrint{
|
|
store: store,
|
|
}
|
|
return
|
|
}
|
|
|
|
func (p *FootPrint) OpCreate(ctx *gin.Context, req *footprintproto.OpCreateReq) error {
|
|
|
|
for _, footprint := range req.FootPrints {
|
|
footprint.Id = goproto.Int64(idgenerator.GenFootPrintId())
|
|
footprint.Ct = goproto.Int64(time.Now().Unix())
|
|
footprint.Ut = goproto.Int64(time.Now().Unix())
|
|
footprint.DelFlag = goproto.Int64(consts.Exist)
|
|
}
|
|
|
|
err := p.store.CreateFootPrint(ctx, req.FootPrints)
|
|
if err != nil {
|
|
logger.Error("CreateFootPrint fail, err: %v", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *FootPrint) OpDelete(ctx *gin.Context, req *footprintproto.OpDeleteReq) error {
|
|
err := p.store.DeleteFootPrint(ctx, req)
|
|
if err != nil {
|
|
logger.Error("DeleteFootPrint fail, err: %v", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *FootPrint) OpListView(ctx *gin.Context, req *footprintproto.OpListReq) ([]*dbstruct.FootPrint, error) {
|
|
list, err := p.store.GetViewFootPrintList(ctx, req)
|
|
if err != nil {
|
|
logger.Error("GetViewFootPrintList fail, err: %v", err)
|
|
return make([]*dbstruct.FootPrint, 0), err
|
|
}
|
|
|
|
return list, nil
|
|
}
|
|
|
|
func (p *FootPrint) OpListIsViewed(ctx *gin.Context, req *footprintproto.OpListReq) ([]*dbstruct.FootPrint, error) {
|
|
list, err := p.store.GetIsViewedFootPrintList(ctx, req)
|
|
if err != nil {
|
|
logger.Error("GetIsViewedFootPrintList fail, err: %v", err)
|
|
return make([]*dbstruct.FootPrint, 0), err
|
|
}
|
|
|
|
return list, nil
|
|
}
|
|
|
|
func (p *FootPrint) OpCount(ctx *gin.Context, req *footprintproto.OpCountReq) (map[int64]int64, error) {
|
|
countMap := make(map[int64]int64)
|
|
mapList, err := p.store.GetFootPrintCount(ctx, req)
|
|
if err != nil {
|
|
logger.Error("GetFootPrintCount fail, err: %v", err)
|
|
return nil, err
|
|
}
|
|
for _, _map := range mapList {
|
|
id, ok1 := _map["_id"].(int64)
|
|
count, ok2 := _map["count"].(int32)
|
|
if ok1 && ok2 {
|
|
countMap[id] = int64(count)
|
|
} else {
|
|
logger.Error("assertion err")
|
|
return nil, fmt.Errorf("assertion err")
|
|
}
|
|
}
|
|
return countMap, nil
|
|
}
|