Browse Source

goods: 出库单详情

Yi 4 months ago
parent
commit
2f381879d5

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20241112090416-295c2aa69dab
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20241113022812-b52528a61377
 	gitee.com/xuyiping_admin/pkg v0.0.0-20241108060137-caea58c59f5b
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/eko/gocache v1.1.0

+ 2 - 0
go.sum

@@ -58,6 +58,8 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20241112070903-def17e1caa43 h1:DotHkoSw
 gitee.com/xuyiping_admin/go_proto v0.0.0-20241112070903-def17e1caa43/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20241112090416-295c2aa69dab h1:72cBosC+SBsz5m42b47i9L+YdoL1mF8l9xd5uo81jx4=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20241112090416-295c2aa69dab/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241113022812-b52528a61377 h1:Z6WoiWxa3mqk6Dxfv0jK/DDlcdqBI7wewp4w/ELEieo=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20241113022812-b52528a61377/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/pkg v0.0.0-20241108060137-caea58c59f5b h1:w05MxH7yqveRlaRbxHhbif5YjPrJFodRPfOjYhXn7Zk=
 gitee.com/xuyiping_admin/pkg v0.0.0-20241108060137-caea58c59f5b/go.mod h1:8tF25X6pE9WkFCczlNAC0K2mrjwKvhhp02I7o0HtDxY=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=

+ 19 - 1
http/handler/goods/drugs.go

@@ -3,6 +3,7 @@ package goods
 import (
 	"kpt-pasture/http/middleware"
 	"net/http"
+	"strconv"
 
 	operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
 	"gitee.com/xuyiping_admin/pkg/valid"
@@ -168,7 +169,7 @@ func NeckRingCreateOrUpdate(c *gin.Context) {
 }
 
 func OutboundApply(c *gin.Context) {
-	var req pasturePb.OutboundApplyCreatedRequest
+	var req pasturePb.OutboundApplyItem
 	if err := ginutil.BindProto(c, &req); err != nil {
 		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
 		return
@@ -241,3 +242,20 @@ func OutboundAudit(c *gin.Context) {
 		Data: &operationPb.Success{Success: true},
 	})
 }
+
+func OutboundDetail(c *gin.Context) {
+	idStr := c.Query("id")
+	id, _ := strconv.ParseInt(idStr, 10, 64)
+	if err := valid.Validate(id, valid.Required); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
+		return
+	}
+
+	res, err := middleware.BackendOperation(c).OpsService.OutboundDetail(c, id)
+	if err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+
+	ginutil.JSONResp(c, res)
+}

+ 1 - 0
http/handler/goods/outbound.go

@@ -0,0 +1 @@
+package goods

+ 1 - 0
http/route/goods_api.go

@@ -23,5 +23,6 @@ func GoodsManageAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		goodsRoute.POST("/outbound/list", goods.OutboundList)
 		goodsRoute.POST("/outbound/audit", goods.OutboundAudit)
 		goodsRoute.POST("/outbound/cancel", goods.OutboundAudit)
+		goodsRoute.POST("/outbound/detail", goods.OutboundDetail)
 	}
 }

+ 4 - 4
model/outbound.go

@@ -29,7 +29,7 @@ func (o *Outbound) TableName() string {
 	return "outbound"
 }
 
-func NewOutbound(req *pasturePb.OutboundApplyCreatedRequest, currentUser *SystemUser) *Outbound {
+func NewOutbound(req *pasturePb.OutboundApplyItem, currentUser *SystemUser) *Outbound {
 	return &Outbound{
 		Number:           fmt.Sprintf("%s%s", util.GenerateRandomNumberString(6), time.Now().Format(LayoutTime)),
 		OutType:          req.OutType,
@@ -43,8 +43,8 @@ func NewOutbound(req *pasturePb.OutboundApplyCreatedRequest, currentUser *System
 
 type OutboundSlice []*Outbound
 
-func (o OutboundSlice) ToPB(outTypeMap map[pasturePb.OutType_Kind]string, auditStatusMap map[pasturePb.AuditStatus_Kind]string) []*pasturePb.SearchOutboundApplyList {
-	res := make([]*pasturePb.SearchOutboundApplyList, len(o))
+func (o OutboundSlice) ToPB(outTypeMap map[pasturePb.OutType_Kind]string, auditStatusMap map[pasturePb.AuditStatus_Kind]string) []*pasturePb.OutboundApplyDetail {
+	res := make([]*pasturePb.OutboundApplyDetail, len(o))
 	for i, v := range o {
 		applicantAtFormat, examineAtFormat, outTypeName, auditStatusName := "", "", "", ""
 		if v.ApplicantAt > 0 {
@@ -62,7 +62,7 @@ func (o OutboundSlice) ToPB(outTypeMap map[pasturePb.OutType_Kind]string, auditS
 			auditStatusName = auditStatus
 		}
 
-		res[i] = &pasturePb.SearchOutboundApplyList{
+		res[i] = &pasturePb.OutboundApplyDetail{
 			Id:                v.Id,
 			Number:            v.Number,
 			OutType:           v.OutType,

+ 19 - 0
model/outbound_log.go

@@ -43,3 +43,22 @@ func NewOutboundLogList(req []*pasturePb.OutboundApplyGoodsItem, unitMap map[pas
 	}
 	return res
 }
+
+type OutboundLogSlice []*OutboundLog
+
+func (o OutboundLogSlice) ToPB() []*pasturePb.OutboundApplyGoodsItem {
+	res := make([]*pasturePb.OutboundApplyGoodsItem, len(o))
+	for i, v := range o {
+		res[i] = &pasturePb.OutboundApplyGoodsItem{
+			GoodsId:     int32(v.GoodsId),
+			GoodsName:   v.GoodsName,
+			Specs:       v.Specs,
+			Producer:    v.Producer,
+			BatchNumber: v.BatchNumber,
+			Price:       float32(v.Price) / 100,
+			Unit:        v.Unit,
+			Quantity:    uint32(v.Quantity),
+		}
+	}
+	return res
+}

+ 44 - 1
module/backend/goods.go

@@ -208,7 +208,7 @@ func (s *StoreEntry) NeckRingLogList(ctx context.Context, req *pasturePb.SearchN
 	}, nil
 }
 
-func (s *StoreEntry) OutboundApply(ctx context.Context, req *pasturePb.OutboundApplyCreatedRequest) error {
+func (s *StoreEntry) OutboundApply(ctx context.Context, req *pasturePb.OutboundApplyItem) error {
 	currentUser, err := s.GetCurrentSystemUser(ctx)
 	if err != nil {
 		return xerr.Custom("登录人信息失效")
@@ -361,3 +361,46 @@ func (s *StoreEntry) OutboundAudit(ctx context.Context, req *pasturePb.OutboundA
 
 	return nil
 }
+
+func (s *StoreEntry) OutboundDetail(ctx context.Context, id int64) (*pasturePb.OutboundDetailResponse, error) {
+	outbound, err := s.GetOutboundById(ctx, id)
+	if err != nil {
+		return nil, xerr.WithStack(err)
+	}
+	outboundLogs, err := s.GetOutboundLogsByOutboundId(ctx, id)
+	if err != nil {
+		return nil, xerr.WithStack(err)
+	}
+	outTypeMap := s.OutTypeMap()
+	auditStatusMap := s.AuditStatusMap()
+	applicantAtFormat, examineAtFormat := "", ""
+	if outbound.ApplicantAt > 0 {
+		applicantAtFormat = time.Unix(outbound.ApplicantAt, 0).Format(model.LayoutTime)
+	}
+	if outbound.ExamineAt > 0 {
+		examineAtFormat = time.Unix(outbound.ExamineAt, 0).Format(model.LayoutTime)
+	}
+	return &pasturePb.OutboundDetailResponse{
+		Code:    http.StatusOK,
+		Message: "ok",
+		Data: &pasturePb.OutboundApplyDetail{
+			Id:                outbound.Id,
+			Number:            outbound.Number,
+			OutType:           outbound.OutType,
+			OutTypeName:       outTypeMap[outbound.OutType],
+			AuditStatus:       outbound.AuditStatus,
+			AuditStatusName:   auditStatusMap[outbound.AuditStatus],
+			ApplicantName:     outbound.ApplicantName,
+			ApplicantRemarks:  outbound.ApplicantRemarks,
+			ExamineName:       outbound.ExamineName,
+			ExamineRemarks:    outbound.ExamineRemarks,
+			ApplicantAtFormat: applicantAtFormat,
+			ExamineAtFormat:   examineAtFormat,
+			GoodsItem: &pasturePb.OutboundApplyItem{
+				OutType:          outbound.OutType,
+				Goods:            model.OutboundLogSlice(outboundLogs).ToPB(),
+				ApplicantRemarks: outbound.ApplicantRemarks,
+			},
+		},
+	}, nil
+}

+ 2 - 1
module/backend/interface.go

@@ -205,9 +205,10 @@ type GoodsService interface {
 	MedicalEquipmentCreateOrUpdate(ctx context.Context, req *pasturePb.SearchMedicalEquipmentList) error
 	NeckRingLogCreateOrUpdate(ctx context.Context, req *pasturePb.NeckRingCreateRequest) error
 	NeckRingLogList(ctx context.Context, req *pasturePb.SearchNeckRingRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchNeckRingResponse, error)
-	OutboundApply(ctx context.Context, req *pasturePb.OutboundApplyCreatedRequest) error
+	OutboundApply(ctx context.Context, req *pasturePb.OutboundApplyItem) error
 	OutboundList(ctx context.Context, req *pasturePb.SearchOutboundApplyRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchOutboundApplyResponse, error)
 	OutboundAudit(ctx context.Context, req *pasturePb.OutboundApplyAuditRequest) error
+	OutboundDetail(ctx context.Context, id int64) (*pasturePb.OutboundDetailResponse, error)
 }
 
 //go:generate mockgen -destination mock/AnalyseService.go -package kptservicemock kpt-pasture/module/backend AnalyseService

+ 8 - 0
module/backend/sql.go

@@ -293,3 +293,11 @@ func (s *StoreEntry) GetOutboundById(ctx context.Context, id int64) (*model.Outb
 	}
 	return res, nil
 }
+
+func (s *StoreEntry) GetOutboundLogsByOutboundId(ctx context.Context, id int64) ([]*model.OutboundLog, error) {
+	list := make([]*model.OutboundLog, 0)
+	if err := s.DB.Where("outbound_id = ?", id).Find(&list).Error; err != nil {
+		return nil, xerr.WithStack(err)
+	}
+	return list, nil
+}