12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package api
- import (
- "box-cost/db/model"
- "box-cost/db/repo"
- "box-cost/log"
- "errors"
- "time"
- "github.com/gin-gonic/gin"
- "go.mongodb.org/mongo-driver/bson/primitive"
- )
- func Process(r *GinRouter) {
- // 获取生产计划详情
- r.GET("/process/detail/:id", ProcessDetail)
- CreateCRUD(r, "/process", &CRUDOption{
- Collection: "process",
- NewModel: func(c *gin.Context, apictx *ApiSession) (interface{}, error) {
- entity := &model.Process{}
- c.ShouldBindJSON(entity)
- entity.CreateTime = time.Now()
- entity.UpdateTime = time.Now()
- return entity, nil
- },
- EmtyModel: func(c *gin.Context, apictx *ApiSession) interface{} {
- return &model.Process{}
- },
- JWT: true,
- OnUpdate: func(c *gin.Context, apictx *ApiSession, entity interface{}) {
- process := entity.(*model.Process)
- process.UpdateTime = time.Now()
- },
- SearchProject: []string{"name", "unit", "norm", "price", "category", "remark"},
- })
- }
- func ProcessDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
- processId := c.Param("id")
- id, err := primitive.ObjectIDFromHex(processId)
- if err != nil {
- return nil, errors.New("非法id")
- }
- var process model.Process
- option := &repo.DocSearchOptions{
- CollectName: repo.CollectionProcess,
- Query: repo.Map{"_id": id},
- }
- found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), option, &process)
- if !found || err != nil {
- log.Info(err)
- return nil, errors.New("数据未找到")
- }
- return process, nil
- }
|