浏览代码

purchase: 特殊申购

Yi 1 年之前
父节点
当前提交
5fa5424880

+ 62 - 0
apiserver/model/bigpartpurchase.go

@@ -0,0 +1,62 @@
+package model
+
+import (
+	"fmt"
+	modernPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/xdmy"
+	"time"
+)
+
+type BigPartPurchase struct {
+	Id             int64                      `gorm:"column:id"`
+	PastureId      int64                      `gorm:"column:pastureId"`
+	OrderNumber    string                     `gorm:"column:orderNumber"`
+	DepartmentId   int64                      `gorm:"column:departmentId"`
+	EmployeId      int64                      `gorm:"column:employeId"`
+	CreateTime     time.Time                  `gorm:"column:createTime"`
+	IsUrgent       int32                      `gorm:"column:isUrgent"`
+	WorkflowId     int64                      `gorm:"column:workflowId"`
+	FlowCompeleted int32                      `gorm:"column:flowCompeleted"`
+	FlowWorkNote   string                     `gorm:"column:flowworkNote"`
+	BuyStatue      int32                      `gorm:"column:buyStatu"`
+	KGChargeId     int32                      `gorm:"column:KGChargeId"`
+	KGChargeDate   time.Time                  `gorm:"column:KGChargedate"`
+	ChargeId       int64                      `gorm:"column:chargeId"`
+	ChargeDate     time.Time                  `gorm:"column:chargeDate"`
+	CGChargeId     int64                      `gorm:"column:CGChargeId"`
+	CGChargeDate   time.Time                  `gorm:"column:CGChargeDate"`
+	WorkflowNote   string                     `gorm:"column:workflowNote"`
+	Statue         int32                      `gorm:"column:statue"`
+	MatchCode      string                     `gorm:"column:matchCode"`
+	ProviderId     int64                      `gorm:"column:providerId"`
+	Equipment      string                     `gorm:"column:equipment"`
+	EquipmentDate  time.Time                  `gorm:"column:equipmentDate"`
+	Field          string                     `gorm:"column:field"`
+	FieldDate      time.Time                  `gorm:"column:fieldDate"`
+	PurchaseType   modernPb.PurchaseType_Kind `gorm:"column:purchase_type"`
+}
+
+func (b *BigPartPurchase) TableName() string {
+	return "bigpartpurchase"
+}
+
+func NewBigPartPurchase(pastureId, departmentId, employeeId, providerId int64,
+	purchaseType modernPb.PurchaseType_Kind, orderNumber, createdTime string,
+) *BigPartPurchase {
+	local, _ := time.LoadLocation("Asia/Shanghai")
+	createTime, _ := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 00:00:00", createdTime), local)
+	return &BigPartPurchase{
+		PastureId:      pastureId,
+		OrderNumber:    orderNumber,
+		DepartmentId:   departmentId,
+		EmployeId:      employeeId,
+		CreateTime:     createTime,
+		IsUrgent:       0,
+		FlowCompeleted: 1,
+		FlowWorkNote:   "",
+		BuyStatue:      0,
+		WorkflowNote:   "",
+		Statue:         2,
+		ProviderId:     providerId,
+		PurchaseType:   purchaseType,
+	}
+}

+ 48 - 0
apiserver/model/partpurchase.go

@@ -0,0 +1,48 @@
+package model
+
+type PartPurchase struct {
+	Id            int64   `gorm:"column:id"`
+	BigId         int64   `gorm:"column:bigId"`
+	PastureId     int64   `gorm:"column:pastureId"`
+	PartId        int64   `gorm:"column:partId"`
+	PartName      string  `gorm:"column:partName"`
+	PartCode      string  `gorm:"column:partCode"`
+	Amount        int64   `gorm:"column:amount"`
+	Note          string  `gorm:"column:note"`
+	IsStorage     int32   `gorm:"column:isStorage"`
+	Specification string  `gorm:"column:specification"`
+	Purpose       string  `gorm:"column:purpose"`
+	Unit          string  `gorm:"column:unit"`
+	BrandId       int64   `gorm:"column:brandId"`
+	StorageAmount float64 `gorm:"column:storageAmount"`
+	Price         string  `gorm:"column:price"`
+	ContractId    string  `gorm:"column:contractId"`
+}
+
+func (p *PartPurchase) TableName() string {
+	return "partpurchase"
+}
+
+func NewPartPurchase(
+	bigId, pastureId, partId, brandId, amount int64,
+	partCode, partName, specification, unit, purpose, price, contractId string,
+	storageAmount float64,
+) *PartPurchase {
+	return &PartPurchase{
+		BigId:         bigId,
+		PastureId:     pastureId,
+		PartId:        partId,
+		PartName:      partName,
+		PartCode:      partCode,
+		Amount:        amount,
+		Note:          "",
+		IsStorage:     1,
+		Specification: specification,
+		Purpose:       purpose,
+		Unit:          unit,
+		BrandId:       brandId,
+		StorageAmount: storageAmount,
+		Price:         price,
+		ContractId:    contractId,
+	}
+}

+ 52 - 3
apiserver/routers/api/api.go

@@ -3,12 +3,21 @@ 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"
-	"kpt.xdmy/apiserver/model/http"
+	modelHttp "kpt.xdmy/apiserver/model/http"
 	"kpt.xdmy/apiserver/service"
 	"kpt.xdmy/pkg/log"
+	"net/http"
+
+	modernPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/xdmy"
 )
 
 var svc *service.Service
@@ -125,7 +134,7 @@ func NextService(p []map[string]interface{}, tx *sqlx.Tx, vendor int64) error {
 				//case 0:
 				// 入库-申购、采购(申购、线上、寄售)
 				if laidType != 2 {
-					pr := new(http.ProofPartReq)
+					pr := new(modelHttp.ProofPartReq)
 					pr.LaidCode = pf["laidCode"].(string)
 					pr.StorageTime = pf["storageTime"].(string)
 					err := svc.LaidProof(pr, tx)
@@ -139,7 +148,7 @@ func NextService(p []map[string]interface{}, tx *sqlx.Tx, vendor int64) error {
 				//json.Unmarshal(b, &pnext)
 				log.Info(v)
 
-				pr := new(http.ProofPartReq)
+				pr := new(modelHttp.ProofPartReq)
 				pr.UseForm = pf["useForm"].(string)
 				pr.StorageTime = pf["receiveTime"].(string)
 				err := svc.UseProof(pf, tx)
@@ -166,3 +175,43 @@ func NextService(p []map[string]interface{}, tx *sqlx.Tx, vendor int64) error {
 	}
 	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.ProviderId, valid.Required),
+		valid.Field(&req.PurchaseType, 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)
+		return
+	}
+
+	ginutil.JSONResp(c, &operationPb.CommonOK{
+		Code: http.StatusOK,
+		Msg:  "ok",
+		Data: &operationPb.Success{Success: true},
+	})
+
+}

+ 2 - 1
apiserver/routers/router.go

@@ -143,7 +143,8 @@ func InitRouter() *gin.Engine {
 		apiV1.POST("/partslistSGv2", api.GetPartsListSGv2)
 
 		apiV1.POST("/waterandelectricity", api.GetWaterAndElectricity)
-
+		// 备件申购-特殊申购
+		apiV1.POST("/spare/parts/requisitions", api.SparePartsRequisitions)
 	}
 	if setting.ServerSetting.NoAuth > 0 {
 

+ 40 - 0
apiserver/service/purchase.go

@@ -0,0 +1,40 @@
+package service
+
+import (
+	"context"
+	modernPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/xdmy"
+	"gitee.com/xuyiping_admin/pkg/xerr"
+	"gorm.io/gorm"
+	"kpt.xdmy/apiserver/model"
+	"strconv"
+)
+
+// CreateSpecialtyPurchase 创建特殊申购信息
+func CreateSpecialtyPurchase(ctx context.Context, req *modernPb.SparePartsRequisitionsRequest) error {
+	return s.d.DB.Transaction(func(tx *gorm.DB) error {
+		newBigPartPurchase := model.NewBigPartPurchase(
+			int64(req.PastureId), int64(req.DepartmentId), int64(req.EmployeId),
+			int64(req.ProviderId), req.PurchaseType, req.OrderNumber, req.CreateTime,
+		)
+		if err := tx.Model(new(model.BigPartPurchase)).Create(newBigPartPurchase).Error; err != nil {
+			return xerr.WithStack(err)
+		}
+
+		partPurchaseList := make([]*model.PartPurchase, 0)
+		for _, v := range req.SpotList {
+
+			amount, _ := strconv.Atoi(v.Amount)
+			partPurchaseList = append(partPurchaseList, model.NewPartPurchase(
+				newBigPartPurchase.Id, int64(req.PastureId), int64(v.PartId), int64(v.BrandId), int64(amount),
+				v.PartCode, v.PartName, v.Specification, v.Unit, v.Purpose, v.Price, v.ContractId, float64(v.StorageAmount)))
+		}
+
+		if len(partPurchaseList) > 0 {
+			if err := tx.Model(new(model.PartPurchase)).Create(partPurchaseList).Error; err != nil {
+				return xerr.WithStack(err)
+			}
+		}
+
+		return nil
+	})
+}

+ 7 - 6
go.mod

@@ -9,9 +9,11 @@ replace (
 )
 
 require (
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20230816092635-d2c3502b7f65
+	gitee.com/xuyiping_admin/pkg v0.0.0-20230816061144-c1f079802584
 	github.com/360EntSecGroup-Skylar/excelize v1.4.1
 	github.com/Anderson-Lu/gofasion v0.0.0-20190530065914-6a05b679ee48
-	github.com/BurntSushi/toml v1.2.0
+	github.com/BurntSushi/toml v1.2.1
 	github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
 	github.com/astaxie/beego v1.12.3
 	github.com/axetroy/go-fs v1.0.0
@@ -28,7 +30,7 @@ require (
 	github.com/fastwego/wxwork v1.0.0-beta.8
 	github.com/gin-gonic/gin v1.9.0
 	github.com/go-ini/ini v1.66.6
-	github.com/go-sql-driver/mysql v1.6.0
+	github.com/go-sql-driver/mysql v1.7.0
 	github.com/jacobsa/go-serial v0.0.0-20180131005756-15cf729a72d4
 	github.com/jmoiron/sqlx v1.3.5
 	github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible
@@ -41,7 +43,7 @@ require (
 	github.com/pkg/errors v0.9.1
 	github.com/robfig/cron v1.2.0
 	github.com/robfig/cron/v3 v3.0.0
-	github.com/sirupsen/logrus v1.9.0
+	github.com/sirupsen/logrus v1.9.3
 	github.com/swaggo/files v1.0.1
 	github.com/swaggo/gin-swagger v1.6.0
 	github.com/swaggo/swag v1.8.12
@@ -49,9 +51,8 @@ require (
 	github.com/unknwon/com v1.0.1
 	github.com/xormplus/xorm v0.0.0-20210822100304-4e1d4fcc1e67
 	github.com/xuri/excelize/v2 v2.6.1
-	golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
-	gorm.io/driver/mysql v1.3.5
+	gorm.io/driver/mysql v1.5.1
 	gorm.io/driver/sqlserver v1.4.3
-	gorm.io/gorm v1.25.0
+	gorm.io/gorm v1.25.2
 
 )

文件差异内容过多而无法显示
+ 984 - 7
go.sum


+ 21 - 0
migration/v0002_alter_bigpartpurchase.sql

@@ -0,0 +1,21 @@
+ALTER TABLE `bigpartpurchase`
+    ADD COLUMN `purchase_type` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '申购类型 0 无效 1 暂估 2 垫付',
+    ADD COLUMN `funder_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '垫资人id';
+
+ALTER TABLE `bigpartuse` ADD COLUMN greenFodderNumber varchar(255) NOT NULL DEFAULT '' COMMENT '青贮单号';
+
+# SELECT * FROM apisql WHERE sqlname = 'insertBigPartUse'
+INSERT INTO bigpartuse (
+    pastureId,
+    departmentId,
+    useForm,
+    listType,
+    applicatId,
+    receiveTime,
+    empId,
+    useType,
+    oddCode,
+    note,
+    greenFodderNumber
+) VALUES ( ?,(select departmentId  from bigpartapply where applyCode = ? ),?,?,?,?,?,?,?,?,?)
+# pastureId,oddCode,useForm,listType,applicatId,receiveTime,empId,useType,oddCode,note,greenFodderNumber

部分文件因为文件数量过多而无法显示