package api import ( "encoding/json" "fmt" operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation" "gitee.com/xuyiping_admin/pkg/apierr" "gitee.com/xuyiping_admin/pkg/ginutil" "gitee.com/xuyiping_admin/pkg/valid" "gitee.com/xuyiping_admin/pkg/xerr" "github.com/gin-gonic/gin" "github.com/jmoiron/sqlx" "github.com/pkg/errors" "kpt.xdmy/apiserver/model" modelHttp "kpt.xdmy/apiserver/model/http" "kpt.xdmy/apiserver/service" "kpt.xdmy/pkg/app" "kpt.xdmy/pkg/e" "kpt.xdmy/pkg/log" "net/http" modernPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/xdmy" ) var svc *service.Service func Init(s *service.Service) { svc = s } type nextServiceInfo struct { laidType int64 useType int64 } func NextService(p []map[string]interface{}, tx *sqlx.Tx, vendor int64) error { isTransfer := false for _, v := range p { if v["name"] == nil || v["parammaps"] == nil { continue } sqlname := v["name"].(string) if sqlname == "updateBigPartTransfer" { isTransfer = true } else if sqlname == "insertBigPartUse" { pf := v["parammaps"].(map[string]interface{}) if pf["useType"].(float64) < 5 { if _, ok := pf["oddCode"]; !ok { return errors.New("oddCode 不能为空 !!!") } } } } if isTransfer { var bigPartTransferid float64 insertBigPartlaid := false for _, v := range p { if v["name"] == nil || v["parammaps"] == nil { continue } pf := v["parammaps"].(map[string]interface{}) sqlname := v["name"].(string) if sqlname == "updateBigPartTransfer" { bigPartTransferid = pf["id"].(float64) } else if sqlname == "insertBigPartlaid" { insertBigPartlaid = true } } if bigPartTransferid > 0 && insertBigPartlaid { //if laidType == 2 { partTransfer := make([]*model.PartTransferStr, 0) partsByte, err := service.GetDataList(tx, `select * from parttransfer where bigid = ? `, []interface{}{bigPartTransferid}) if err != nil { return errors.New("无调拨信息!!!") } if partsByte != nil { err := json.Unmarshal(partsByte, &partTransfer) if err != nil { return errors.New("调拨信息转码出错!!!") } } for _, part := range partTransfer { prByte, err := service.MapStr(tx, `select * from part_repertory where id = ? and reportery >= ? `, part.PartRepID, part.Amount) if err != nil { return errors.New("库存信息出错!!!") } if prByte != nil { data := make(map[string]interface{}) err := json.Unmarshal(prByte, &data) if err != nil { return errors.New("库存信息出错!!!") } if _, ok := data["id"]; !ok { return errors.New("库存信息出错!!!") } } else { return errors.New("库存信息出错!!!") } _, err = tx.Exec(` update part_repertory set reportery = reportery - ? where id = ? `, part.Amount, part.PartRepID) if err != nil { return errors.New("库存调整出错!!!") } } if vendor == 1 { err = service.ManualTransfer(bigPartTransferid, tx) if err != nil { return err } } } } else if vendor == 1 { for _, v := range p { if v["name"] == nil || v["parammaps"] == nil { continue } pf := v["parammaps"].(map[string]interface{}) sqlname := v["name"].(string) fmt.Println(sqlname) switch sqlname { case "insertBigPartlaid": laidType := pf["laidType"].(float64) log.Info(v) //b, _ := json.Marshal(p) //pnext := new(nextServiceInfo) //json.Unmarshal(b, &pnext) //switch pnext.laidType { //手动出库没有采购单号,所以不能传SAP //case 0: // 入库-申购、采购(申购、线上、寄售) if laidType != 2 { pr := new(modelHttp.ProofPartReq) pr.LaidCode = pf["laidCode"].(string) pr.StorageTime = pf["storageTime"].(string) err := svc.LaidProof(pr, tx) if err != nil { return err } } case "insertBigPartUse": //b, _ := json.Marshal(p) //pnext := new(nextServiceInfo) //json.Unmarshal(b, &pnext) log.Info(v) pr := new(modelHttp.ProofPartReq) pr.UseForm = pf["useForm"].(string) pr.StorageTime = pf["receiveTime"].(string) err := svc.UseProof(pf, tx) if err != nil { return err } //} case "updatePartRepertoryTHS": log.Info(v) // 退货 err := svc.RefundProof(pf, tx) if err != nil { return err } case "insertBigPartquit": log.Info(v) // 退库 err := svc.QuitProof(pf, tx) if err != nil { return err } } } } return nil } // SparePartsRequisitions 备件申购-特殊申购 func SparePartsRequisitions(c *gin.Context) { var req modernPb.SparePartsRequisitionsRequest if err := ginutil.BindProto(c, &req); err != nil { apierr.AbortBadRequest(c, http.StatusBadRequest, err) return } if err := valid.ValidateStruct(&req, valid.Field(&req.OrderNumber, valid.Required, valid.Length(1, 100)), valid.Field(&req.PastureId, valid.Required), valid.Field(&req.DepartmentId, valid.Required), valid.Field(&req.EmployeId, valid.Required), valid.Field(&req.CreateTime, valid.Required), valid.Field(&req.PurchaseType, valid.Required), //valid.Field(&req.ProviderName, valid.Required, valid.Length(1, 100)), ); err != nil { apierr.AbortBadRequest(c, http.StatusBadRequest, err) return } if req.PurchaseType != modernPb.PurchaseType_Advance_Payment { if err := valid.ValidateStruct(&req, valid.Field(&req.ProviderId, valid.Required), ); err != nil { apierr.AbortBadRequest(c, http.StatusBadRequest, err) return } } if len(req.SpotList) <= 0 { apierr.AbortBadRequest(c, http.StatusBadRequest, xerr.Custom("备件列表不能为空")) return } if err := service.CreateSpecialtyPurchase(c, &req); err != nil { //apierr.ClassifiedAbort(c, err) appG := app.Gin{C: c} appG.Response(200, e.ERROR, err.Error()) return } ginutil.JSONResp(c, &operationPb.CommonOK{ Code: http.StatusOK, Msg: "ok", Data: &operationPb.Success{Success: true}, }) } func GetDieselTypeList(c *gin.Context) { res := &modernPb.DieselTypeListResponse{ Code: http.StatusOK, Msg: "ok", Data: &modernPb.DieselTypeList{ DieselType: make([]*modernPb.DieselTypeEnum, 0), }, } res.Data.DieselType = append(res.Data.DieselType, &modernPb.DieselTypeEnum{ Value: modernPb.DieselType_Zero, Label: "0号", }, &modernPb.DieselTypeEnum{ Value: modernPb.DieselType_Ten, Label: "10号", }, &modernPb.DieselTypeEnum{ Value: modernPb.DieselType_Twenty, Label: "20号", }, &modernPb.DieselTypeEnum{ Value: modernPb.DieselType_Thirty, Label: "30号", }, &modernPb.DieselTypeEnum{ Value: modernPb.DieselType_Thirty_Five, Label: "35号", }) ginutil.JSONResp(c, res) }