| | |
| | | "github.com/gin-gonic/gin" |
| | | "gorm.io/gorm" |
| | | "srm/constvar" |
| | | "srm/model" |
| | | "srm/model/common/response" |
| | | models "srm/model/outsourcing" |
| | | outsourcingrequest "srm/model/outsourcing/request" |
| | | "srm/pkg/logx" |
| | | "srm/proto/common" |
| | | "srm/proto/inventory_order" |
| | | "srm/proto/purchase_wms" |
| | | "srm/utils" |
| | | "srm/utils/code" |
| | | "srm/utils/structx" |
| | |
| | | utils.ResponseFormat(c, code.Success, resp) |
| | | } |
| | | |
| | | // OutsourcingOrderList |
| | | // @Tags 委外企业管理 |
| | | // @Summary 委外订单列表 |
| | | // @Produce application/json |
| | | // @Param Authorization header string true "token" |
| | | // @Param object query outsourcingrequest.OutsourcingOrderList true "查询参数" |
| | | // @Success 200 {object} utils.ResponseList{data=[]models.OutsourcingOrder} "成功" |
| | | // @Router /outsourcing/order/list [get] |
| | | func (slf *OutsourcingController) OutsourcingOrderList(c *gin.Context) { |
| | | var params outsourcingrequest.OutsourcingOrderList |
| | | if err := c.BindQuery(¶ms); err != nil { |
| | | utils.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | list, total, err := models.NewOutsourcingOrderSearch().SetPage(params.Page, params.PageSize).SetKeyword(params.Keyword).SetOrder("id desc").Find() |
| | | if err != nil { |
| | | utils.ResponseFormat(c, code.InternalError, "查询错误") |
| | | return |
| | | } |
| | | utils.ResponseFormatList(c, code.Success, list, int(total)) |
| | | } |
| | | |
| | | // OrderOverview |
| | | // @Tags 委外企业管理 |
| | | // @Summary 订单统计 |
| | | // @Produce application/json |
| | | // @Param Authorization header string true "token" |
| | | // @Success 200 {object} utils.ResponseList{data=outsourcingrequest.OutsourcingOrderOverview} "成功" |
| | | // @Router /outsourcing/order/overview [get] |
| | | func (slf *OutsourcingController) OrderOverview(c *gin.Context) { |
| | | result, err := models.NewOutsourcingOrderSearch().CountGroupByStatus() |
| | | if err != nil { |
| | | utils.ResponseFormat(c, code.InternalError, "查询错误") |
| | | return |
| | | } |
| | | resp := &outsourcingrequest.OutsourcingOrderOverview{} |
| | | for _, v := range result { |
| | | resp.Total += v.Total |
| | | status := constvar.OutsourcingOrderStatus(v.Status) |
| | | if status == constvar.OutsourcingOrderStatusCreate { |
| | | resp.WaitAssigned += v.Total |
| | | } else { |
| | | resp.HasAssigned += v.Total |
| | | } |
| | | } |
| | | utils.ResponseFormat(c, code.Success, resp) |
| | | } |
| | | |
| | | // OutsourcingOrderProductList |
| | | // @Tags 委外企业管理 |
| | | // @Summary 委外订单产品列表 |
| | | // @Produce application/json |
| | | // @Param Authorization header string true "token" |
| | | // @Param object query outsourcingrequest.OutsourcingOrderProductList true "查询参数" |
| | | // @Success 200 {object} utils.ResponseList{data=[]models.OutsourcingOrderProduct} "成功" |
| | | // @Router /outsourcing/order/productList [get] |
| | | func (slf *OutsourcingController) OutsourcingOrderProductList(c *gin.Context) { |
| | | var params outsourcingrequest.OutsourcingOrderProductList |
| | | if err := c.BindQuery(¶ms); err != nil { |
| | | utils.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | if params.OutsourcingOrderId == 0 { |
| | | utils.ResponseFormat(c, code.RequestParamError, "参数缺失") |
| | | return |
| | | } |
| | | list, total, err := models.NewOutsourcingOrderProductSearch().SetPage(params.Page, params.PageSize).SetOutsourcingOrderID(params.OutsourcingOrderId).SetOrder("id desc").Find() |
| | | if err != nil { |
| | | utils.ResponseFormat(c, code.InternalError, "查询错误") |
| | | return |
| | | } |
| | | utils.ResponseFormatList(c, code.Success, list, int(total)) |
| | | } |
| | | |
| | | // OutsourcingEnterpriseProductList |
| | | // @Tags 委外企业管理 |
| | | // @Summary 委外企业供货历史 |
| | | // @Produce application/json |
| | | // @Param Authorization header string true "token" |
| | | // @Param object query outsourcingrequest.OutsourcingEnterpriseProductList true "查询参数" |
| | | // @Success 200 {object} utils.ResponseList{data=[]models.OutsourcingOrderProduct} "成功" |
| | | // @Router /outsourcing/enterprise/productList [get] |
| | | func (slf *OutsourcingController) OutsourcingEnterpriseProductList(c *gin.Context) { |
| | | var params outsourcingrequest.OutsourcingEnterpriseProductList |
| | | if err := c.BindQuery(¶ms); err != nil { |
| | | utils.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | if params.EnterpriseID == 0 { |
| | | utils.ResponseFormat(c, code.RequestParamError, "参数缺失") |
| | | return |
| | | } |
| | | list, total, err := models.NewOutsourcingOrderProductSearch().SetPage(params.Page, params.PageSize).SetEnterpriseID(params.EnterpriseID).SetOrder("id desc").Find() |
| | | if err != nil { |
| | | utils.ResponseFormat(c, code.InternalError, "查询错误") |
| | | return |
| | | } |
| | | utils.ResponseFormatList(c, code.Success, list, int(total)) |
| | | } |
| | | |
| | | // OutsourcingOrderAssign |
| | | // @Tags 委外企业管理 |
| | | // @Summary 委外订单分配企业 |
| | | // @Produce application/json |
| | | // @Param Authorization header string true "token" |
| | | // @Param object body outsourcingrequest.OutsourcingOrderAssign true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} "成功" |
| | | // @Router /outsourcing/order/assign [post] |
| | | func (slf *OutsourcingController) OutsourcingOrderAssign(c *gin.Context) { |
| | | var params outsourcingrequest.OutsourcingOrderAssign |
| | | if err := c.BindJSON(¶ms); err != nil { |
| | | utils.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | if params.EnterpriseID == 0 || params.OrderID == 0 && len(params.OrderIDs) == 0 { |
| | | utils.ResponseFormat(c, code.RequestParamError, "参数缺失") |
| | | return |
| | | } |
| | | if params.OrderID != 0 && len(params.OrderIDs) != 0 { |
| | | utils.ResponseFormat(c, code.RequestParamError, "不能同时传orderID和orderIDs") |
| | | return |
| | | } |
| | | enterprise, err := models.NewOutsourcingEnterpriseSearch().SetID(params.EnterpriseID).First() |
| | | if err != nil { |
| | | utils.ResponseFormat(c, code.RequestParamError, "查找企业失败") |
| | | return |
| | | } |
| | | if params.OrderID != 0 { |
| | | order, err := models.NewOutsourcingOrderSearch().SetID(params.OrderID).First() |
| | | if err != nil { |
| | | utils.ResponseFormat(c, code.RequestParamError, "查找订单失败") |
| | | return |
| | | } |
| | | if order.Status != constvar.OutsourcingOrderStatusCreate || order.EnterpriseID != 0 { |
| | | utils.ResponseFormat(c, code.RequestParamError, "该订单已分配企业,请检查") |
| | | return |
| | | } |
| | | } else { |
| | | for _, orderID := range params.OrderIDs { |
| | | order, err := models.NewOutsourcingOrderSearch().SetID(orderID).First() |
| | | if err != nil { |
| | | utils.ResponseFormat(c, code.RequestParamError, "查找订单失败") |
| | | return |
| | | } |
| | | if order.Status != constvar.OutsourcingOrderStatusCreate || order.EnterpriseID != 0 { |
| | | utils.ResponseFormat(c, code.RequestParamError, "存在已分配企业的订单,请检查") |
| | | return |
| | | } |
| | | } |
| | | } |
| | | |
| | | err = model.WithTransaction(func(db *gorm.DB) error { |
| | | err = models.NewOutsourcingOrderSearch().SetID(params.OrderID).SetIDs(params.OrderIDs).UpdateByMap(map[string]interface{}{ |
| | | "enterprise_id": enterprise.ID, |
| | | "enterprise_name": enterprise.Name, |
| | | "enterprise_type": enterprise.EnterpriseType, |
| | | "status": constvar.OutsourcingOrderStatusAssigned, |
| | | }) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | err = models.NewOutsourcingOrderProductSearch().SetOutsourcingOrderID(params.OrderID).SetOutsourcingOrderIDs(params.OrderIDs).UpdateByMap(map[string]interface{}{ |
| | | "enterprise_id": enterprise.ID, |
| | | }) |
| | | return err |
| | | }) |
| | | if err != nil { |
| | | utils.ResponseFormat(c, code.InternalError, "分配失败") |
| | | return |
| | | } |
| | | utils.ResponseFormat(c, code.Success, nil) |
| | | } |
| | | |
| | | // SaveMaterialApply |
| | | // @Tags 委外企业管理 |
| | | // @Summary 保存物料申请单 |
| | | // @Produce application/json |
| | | // @Param Authorization header string true "token" |
| | | // @Param object body outsourcingrequest.SaveMaterialApply true "参数" |
| | | // @Success 200 {object} utils.Response{} "成功" |
| | | // @Router /outsourcing/order/saveMaterialApply [post] |
| | | func (slf *OutsourcingController) SaveMaterialApply(c *gin.Context) { |
| | | var params outsourcingrequest.SaveMaterialApply |
| | | if err := c.BindJSON(¶ms); err != nil { |
| | | utils.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | if len(params.ApplyList) == 0 { |
| | | utils.ResponseFormat(c, code.RequestParamError, "物料申请不能为空") |
| | | return |
| | | } |
| | | var apply []*models.OutsourcingMaterialApply |
| | | err := structx.AssignTo(params.ApplyList, &apply) |
| | | if err != nil { |
| | | utils.ResponseFormat(c, code.RequestParamError, "数据转换失败") |
| | | return |
| | | } |
| | | err = model.WithTransaction(func(db *gorm.DB) error { |
| | | err = models.NewOutsourcingMaterialApplySearch().SetOrm(db).CreateBatch(apply) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | err = models.NewOutsourcingOrderSearch().SetOrm(db).SetNumber(params.ApplyList[0].OutsourcingOrderNumber). |
| | | UpdateByMap(map[string]interface{}{"status": constvar.OutsourcingOrderStatusMaterialApplying}) |
| | | return err |
| | | }) |
| | | if err != nil { |
| | | utils.ResponseFormat(c, code.RequestParamError, "保存失败") |
| | | return |
| | | } |
| | | |
| | | utils.ResponseFormat(c, code.Success, "保存成功") |
| | | } |
| | | |
| | | // GetMaterialApplyList |
| | | // @Tags 委外企业管理 |
| | | // @Summary 获取物料申请单 |
| | | // @Produce application/json |
| | | // @Param Authorization header string true "token" |
| | | // @Param object body outsourcingrequest.GetMaterialApplyList true "参数" |
| | | // @Success 200 {object} utils.ResponseList{[]models.OutsourcingMaterialApply} "成功" |
| | | // @Router /outsourcing/order/getMaterialApplyList [post] |
| | | func (slf *OutsourcingController) GetMaterialApplyList(c *gin.Context) { |
| | | var params outsourcingrequest.GetMaterialApplyList |
| | | if err := c.BindJSON(¶ms); err != nil { |
| | | utils.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | find, err := models.NewOutsourcingMaterialApplySearch().SetOutsourcingOrderNumber(params.Number).FindNotTotal() |
| | | if err != nil { |
| | | utils.ResponseFormat(c, code.RequestParamError, "查询失败") |
| | | return |
| | | } |
| | | utils.ResponseFormat(c, code.Success, find) |
| | | } |
| | | |
| | | // ChangeStatus |
| | | // @Tags 委外企业管理 |
| | | // @Summary 修改状态 |
| | | // @Produce application/json |
| | | // @Param Authorization header string true "token" |
| | | // @Param object body outsourcingrequest.ChangeStatus true "参数" |
| | | // @Success 200 {object} utils.Response "成功" |
| | | // @Router /outsourcing/order/changeStatus [post] |
| | | func (slf *OutsourcingController) ChangeStatus(c *gin.Context) { |
| | | var params outsourcingrequest.ChangeStatus |
| | | if err := c.BindJSON(¶ms); err != nil { |
| | | utils.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | //限定状态参数 |
| | | if params.Status == constvar.OutsourcingOrderStatusMaterialExamineRefused || |
| | | params.Status == constvar.OutsourcingOrderStatusProducing || |
| | | params.Status == constvar.OutsourcingOrderStatusFinish || |
| | | params.Status == constvar.OutsourcingOrderStatusReceiveFinish { |
| | | m := make(map[string]interface{}) |
| | | m["status"] = params.Status |
| | | m["reason"] = params.Reason |
| | | err := models.NewOutsourcingOrderSearch().SetNumber(params.OutsourcingOrderNumber).UpdateByMap(m) |
| | | if err != nil { |
| | | utils.ResponseFormat(c, code.RequestParamError, "状态更新失败") |
| | | return |
| | | } |
| | | utils.ResponseFormat(c, code.Success, "状态更新成功") |
| | | return |
| | | } |
| | | utils.ResponseFormat(c, code.RequestParamError, "状态参数不正确") |
| | | } |
| | | |
| | | // GetDeliveryList |
| | | // @Tags 委外企业管理 |
| | | // @Summary 获取发货列表 |
| | | // @Produce application/json |
| | | // @Param Authorization header string true "token" |
| | | // @Param object body outsourcingrequest.GetDeliveryList true "参数" |
| | | // @Success 200 {object} utils.ResponseList{[]models.OutsourcingOrderDeliveryDetails} "成功" |
| | | // @Router /outsourcing/order/deliveryList [post] |
| | | func (slf *OutsourcingController) GetDeliveryList(c *gin.Context) { |
| | | var params outsourcingrequest.GetDeliveryList |
| | | if err := c.BindJSON(¶ms); err != nil { |
| | | utils.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | |
| | | _, err := models.NewOutsourcingOrderSearch().SetID(params.OutsourcingOrderID).First() |
| | | if err != nil { |
| | | utils.ResponseFormat(c, code.RequestParamError, "订单不存在") |
| | | return |
| | | } |
| | | |
| | | list, err := models.NewOutsourcingOrderDeliveryDetailsSearch(). |
| | | SetOutsourcingOrderID(params.OutsourcingOrderID). |
| | | SetIsReceived(params.IsReceived). |
| | | SetPreload(true). |
| | | SetOrder("id desc"). |
| | | FindNotTotal() |
| | | if err != nil { |
| | | utils.ResponseFormat(c, code.RequestParamError, "查询失败") |
| | | return |
| | | } |
| | | utils.ResponseFormat(c, code.Success, list) |
| | | } |
| | | |
| | | // ConfirmReceipt |
| | | // @Tags 委外企业管理 |
| | | // @Summary 委外入库 确认入库 |
| | | // @Produce application/json |
| | | // @Param Authorization header string true "token" |
| | | // @Param object body outsourcingrequest.ConfirmDeliveryList true "参数" |
| | | // @Success 200 {object} utils.ResponseList{[]models.OutsourcingOrderDeliveryDetails} "成功" |
| | | // @Router /outsourcing/order/confirmReceipt [post] |
| | | func (slf *OutsourcingController) ConfirmReceipt(c *gin.Context) { |
| | | var params outsourcingrequest.ConfirmDeliveryList |
| | | if err := c.BindJSON(¶ms); err != nil { |
| | | utils.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | |
| | | outsourcingOrder, err := models.NewOutsourcingOrderSearch().SetID(params.OutsourcingOrderID).First() |
| | | if err != nil { |
| | | utils.ResponseFormat(c, code.RequestParamError, "订单不存在") |
| | | return |
| | | } |
| | | |
| | | list, err := models.NewOutsourcingOrderDeliveryDetailsSearch(). |
| | | SetOutsourcingOrderID(params.OutsourcingOrderID). |
| | | SetIds(params.OutsourcingOrderDeliveryDetailsIds). |
| | | SetPreload(true). |
| | | SetOrder("id desc"). |
| | | FindNotTotal() |
| | | if err != nil { |
| | | utils.ResponseFormat(c, code.RequestParamError, "查询失败") |
| | | return |
| | | } |
| | | |
| | | operationList := make([]*inventory_order.OperationList, 0) |
| | | products := make([]*inventory_order.OperationProduct, 0, len(list)) |
| | | ids := make([]uint, 0, len(list)) |
| | | for _, item := range list { |
| | | products = append(products, &inventory_order.OperationProduct{ |
| | | ProductNumber: item.OutsourcingOrderProduct.ProductId, |
| | | Amount: item.SendAmount.IntPart(), |
| | | }) |
| | | ids = append(ids, item.ID) |
| | | } |
| | | var ol inventory_order.OperationList |
| | | ol.SourceNumber = outsourcingOrder.Number |
| | | ol.Products = products |
| | | ol.SalesDetailsNumber = outsourcingOrder.SalesDetailsNumber |
| | | operationList = append(operationList, &ol) |
| | | client := inventory_order.NewInventoryOrderServiceClient(purchase_wms.PurchaseConn) |
| | | _, err = client.CreateOperationList(c, &inventory_order.CreateOperationListRequest{ |
| | | OperationType: 1, |
| | | Source: "APS_OUTSOURCING_RECEIVE", |
| | | List: operationList, |
| | | OperationSource: common.OperationSource_OperationSourceOutsourcing, |
| | | WarehouseId: params.WarehouseId, |
| | | }) |
| | | if err != nil { |
| | | logx.Errorf("outsourcing confirmReceipt CreateOperationList failed: %v", err) |
| | | utils.ResponseFormat(c, code.InternalError, "GRPC调用错误") |
| | | return |
| | | } |
| | | |
| | | err = models.NewOutsourcingOrderDeliveryDetailsSearch(). |
| | | SetOutsourcingOrderID(params.OutsourcingOrderID). |
| | | SetIds(params.OutsourcingOrderDeliveryDetailsIds).UpdateByMap(map[string]interface{}{"is_received": constvar.BoolTypeTrue}) |
| | | if err != nil { |
| | | logx.Errorf("outsourcing confirmReceipt CreateOperationList success but update receive status failed: %v, params:%+v", err, params) |
| | | utils.ResponseFormat(c, code.SaveFail, "更改状态失败") |
| | | return |
| | | } |
| | | utils.ResponseFormat(c, code.Success, nil) |
| | | } |
| | | |
| | | // GetInventoryInputDetails |
| | | // @Tags 委外企业管理 |
| | | // @Summary 获取委外入库明细 |
| | | // @Produce application/json |
| | | // @Param Authorization header string true "token" |
| | | // @Param object body outsourcingrequest.GetInventoryInputDetails true "参数" |
| | | // @Success 200 {object} utils.ResponseList{[]response.OutsourcingInputItem} "成功" |
| | | // @Router /outsourcing/order/getInventoryInputDetails [post] |
| | | func (slf *OutsourcingController) GetInventoryInputDetails(c *gin.Context) { |
| | | var params outsourcingrequest.GetInventoryInputDetails |
| | | if err := c.BindJSON(¶ms); err != nil { |
| | | utils.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | |
| | | outsourcingOrder, err := models.NewOutsourcingOrderSearch().SetID(params.OutsourcingOrderID).First() |
| | | if err != nil { |
| | | utils.ResponseFormat(c, code.RequestParamError, "订单不存在") |
| | | return |
| | | } |
| | | |
| | | client := purchase_wms.NewPurchaseServiceClient(purchase_wms.PurchaseConn) |
| | | resp, err := client.SrmGetOperationInfo(c, &purchase_wms.SrmGetOperationInfoRequest{ |
| | | Number: outsourcingOrder.Number, |
| | | OperationSource: common.OperationSource_OperationSourceOutsourcing, |
| | | SalesDetailsNumber: outsourcingOrder.SalesDetailsNumber, |
| | | }) |
| | | if err != nil { |
| | | logx.Errorf("SrmGetOperationInfo err:%v", err) |
| | | utils.ResponseFormat(c, code.Success, nil) |
| | | return |
| | | } |
| | | |
| | | orderProducts, err := models.NewOutsourcingOrderProductSearch().SetOutsourcingOrderID(params.OutsourcingOrderID).FindNotTotal() |
| | | if err != nil { |
| | | utils.ResponseFormat(c, code.InternalError, "查询订单产品失败") |
| | | return |
| | | } |
| | | productMap := models.OutsourcingOrderProductMap(orderProducts) |
| | | list := make([]*response.OutsourcingInputItem, 0, len(resp.Operations)) |
| | | for _, v := range resp.Operations { |
| | | if productMap[v.ProductId] == nil { |
| | | continue |
| | | } |
| | | list = append(list, &response.OutsourcingInputItem{ |
| | | Number: v.Number, |
| | | ProductId: v.ProductId, |
| | | ProductName: v.ProductName, |
| | | OrderAmount: productMap[v.ProductId].Amount, |
| | | InputAmount: v.Amount, |
| | | Specs: productMap[v.ProductId].Specs, |
| | | Type: productMap[v.ProductId].Type, |
| | | Unit: productMap[v.ProductId].Unit, |
| | | Status: v.Status, |
| | | CreateTime: v.OverTime, |
| | | }) |
| | | } |
| | | utils.ResponseFormat(c, code.Success, list) |
| | | |
| | | } |
| | | // |
| | | //// OutsourcingOrderList |
| | | //// @Tags 委外企业管理 |
| | | //// @Summary 委外订单列表 |
| | | //// @Produce application/json |
| | | //// @Param Authorization header string true "token" |
| | | //// @Param object query outsourcingrequest.OutsourcingOrderList true "查询参数" |
| | | //// @Success 200 {object} utils.ResponseList{data=[]models.OutsourcingOrder} "成功" |
| | | //// @Router /outsourcing/order/list [get] |
| | | //func (slf *OutsourcingController) OutsourcingOrderList(c *gin.Context) { |
| | | // var params outsourcingrequest.OutsourcingOrderList |
| | | // if err := c.BindQuery(¶ms); err != nil { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | // return |
| | | // } |
| | | // list, total, err := models.NewOutsourcingOrderSearch().SetPage(params.Page, params.PageSize).SetKeyword(params.Keyword).SetOrder("id desc").Find() |
| | | // if err != nil { |
| | | // utils.ResponseFormat(c, code.InternalError, "查询错误") |
| | | // return |
| | | // } |
| | | // utils.ResponseFormatList(c, code.Success, list, int(total)) |
| | | //} |
| | | // |
| | | //// OrderOverview |
| | | //// @Tags 委外企业管理 |
| | | //// @Summary 订单统计 |
| | | //// @Produce application/json |
| | | //// @Param Authorization header string true "token" |
| | | //// @Success 200 {object} utils.ResponseList{data=outsourcingrequest.OutsourcingOrderOverview} "成功" |
| | | //// @Router /outsourcing/order/overview [get] |
| | | //func (slf *OutsourcingController) OrderOverview(c *gin.Context) { |
| | | // result, err := models.NewOutsourcingOrderSearch().CountGroupByStatus() |
| | | // if err != nil { |
| | | // utils.ResponseFormat(c, code.InternalError, "查询错误") |
| | | // return |
| | | // } |
| | | // resp := &outsourcingrequest.OutsourcingOrderOverview{} |
| | | // for _, v := range result { |
| | | // resp.Total += v.Total |
| | | // status := constvar.OutsourcingOrderStatus(v.Status) |
| | | // if status == constvar.OutsourcingOrderStatusCreate { |
| | | // resp.WaitAssigned += v.Total |
| | | // } else { |
| | | // resp.HasAssigned += v.Total |
| | | // } |
| | | // } |
| | | // utils.ResponseFormat(c, code.Success, resp) |
| | | //} |
| | | // |
| | | //// OutsourcingOrderProductList |
| | | //// @Tags 委外企业管理 |
| | | //// @Summary 委外订单产品列表 |
| | | //// @Produce application/json |
| | | //// @Param Authorization header string true "token" |
| | | //// @Param object query outsourcingrequest.OutsourcingOrderProductList true "查询参数" |
| | | //// @Success 200 {object} utils.ResponseList{data=[]models.OutsourcingOrderProduct} "成功" |
| | | //// @Router /outsourcing/order/productList [get] |
| | | //func (slf *OutsourcingController) OutsourcingOrderProductList(c *gin.Context) { |
| | | // var params outsourcingrequest.OutsourcingOrderProductList |
| | | // if err := c.BindQuery(¶ms); err != nil { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | // return |
| | | // } |
| | | // if params.OutsourcingOrderId == 0 { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "参数缺失") |
| | | // return |
| | | // } |
| | | // list, total, err := models.NewOutsourcingOrderProductSearch().SetPage(params.Page, params.PageSize).SetOutsourcingOrderID(params.OutsourcingOrderId).SetOrder("id desc").Find() |
| | | // if err != nil { |
| | | // utils.ResponseFormat(c, code.InternalError, "查询错误") |
| | | // return |
| | | // } |
| | | // utils.ResponseFormatList(c, code.Success, list, int(total)) |
| | | //} |
| | | // |
| | | //// OutsourcingEnterpriseProductList |
| | | //// @Tags 委外企业管理 |
| | | //// @Summary 委外企业供货历史 |
| | | //// @Produce application/json |
| | | //// @Param Authorization header string true "token" |
| | | //// @Param object query outsourcingrequest.OutsourcingEnterpriseProductList true "查询参数" |
| | | //// @Success 200 {object} utils.ResponseList{data=[]models.OutsourcingOrderProduct} "成功" |
| | | //// @Router /outsourcing/enterprise/productList [get] |
| | | //func (slf *OutsourcingController) OutsourcingEnterpriseProductList(c *gin.Context) { |
| | | // var params outsourcingrequest.OutsourcingEnterpriseProductList |
| | | // if err := c.BindQuery(¶ms); err != nil { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | // return |
| | | // } |
| | | // if params.EnterpriseID == 0 { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "参数缺失") |
| | | // return |
| | | // } |
| | | // list, total, err := models.NewOutsourcingOrderProductSearch().SetPage(params.Page, params.PageSize).SetEnterpriseID(params.EnterpriseID).SetOrder("id desc").Find() |
| | | // if err != nil { |
| | | // utils.ResponseFormat(c, code.InternalError, "查询错误") |
| | | // return |
| | | // } |
| | | // utils.ResponseFormatList(c, code.Success, list, int(total)) |
| | | //} |
| | | // |
| | | //// OutsourcingOrderAssign |
| | | //// @Tags 委外企业管理 |
| | | //// @Summary 委外订单分配企业 |
| | | //// @Produce application/json |
| | | //// @Param Authorization header string true "token" |
| | | //// @Param object body outsourcingrequest.OutsourcingOrderAssign true "查询参数" |
| | | //// @Success 200 {object} contextx.Response{} "成功" |
| | | //// @Router /outsourcing/order/assign [post] |
| | | //func (slf *OutsourcingController) OutsourcingOrderAssign(c *gin.Context) { |
| | | // var params outsourcingrequest.OutsourcingOrderAssign |
| | | // if err := c.BindJSON(¶ms); err != nil { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | // return |
| | | // } |
| | | // if params.EnterpriseID == 0 || params.OrderID == 0 && len(params.OrderIDs) == 0 { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "参数缺失") |
| | | // return |
| | | // } |
| | | // if params.OrderID != 0 && len(params.OrderIDs) != 0 { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "不能同时传orderID和orderIDs") |
| | | // return |
| | | // } |
| | | // enterprise, err := models.NewOutsourcingEnterpriseSearch().SetID(params.EnterpriseID).First() |
| | | // if err != nil { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "查找企业失败") |
| | | // return |
| | | // } |
| | | // if params.OrderID != 0 { |
| | | // order, err := models.NewOutsourcingOrderSearch().SetID(params.OrderID).First() |
| | | // if err != nil { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "查找订单失败") |
| | | // return |
| | | // } |
| | | // if order.Status != constvar.OutsourcingOrderStatusCreate || order.EnterpriseID != 0 { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "该订单已分配企业,请检查") |
| | | // return |
| | | // } |
| | | // } else { |
| | | // for _, orderID := range params.OrderIDs { |
| | | // order, err := models.NewOutsourcingOrderSearch().SetID(orderID).First() |
| | | // if err != nil { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "查找订单失败") |
| | | // return |
| | | // } |
| | | // if order.Status != constvar.OutsourcingOrderStatusCreate || order.EnterpriseID != 0 { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "存在已分配企业的订单,请检查") |
| | | // return |
| | | // } |
| | | // } |
| | | // } |
| | | // |
| | | // err = model.WithTransaction(func(db *gorm.DB) error { |
| | | // err = models.NewOutsourcingOrderSearch().SetID(params.OrderID).SetIDs(params.OrderIDs).UpdateByMap(map[string]interface{}{ |
| | | // "enterprise_id": enterprise.ID, |
| | | // "enterprise_name": enterprise.Name, |
| | | // "enterprise_type": enterprise.EnterpriseType, |
| | | // "status": constvar.OutsourcingOrderStatusAssigned, |
| | | // }) |
| | | // if err != nil { |
| | | // return err |
| | | // } |
| | | // err = models.NewOutsourcingOrderProductSearch().SetOutsourcingOrderID(params.OrderID).SetOutsourcingOrderIDs(params.OrderIDs).UpdateByMap(map[string]interface{}{ |
| | | // "enterprise_id": enterprise.ID, |
| | | // }) |
| | | // return err |
| | | // }) |
| | | // if err != nil { |
| | | // utils.ResponseFormat(c, code.InternalError, "分配失败") |
| | | // return |
| | | // } |
| | | // utils.ResponseFormat(c, code.Success, nil) |
| | | //} |
| | | // |
| | | //// SaveMaterialApply |
| | | //// @Tags 委外企业管理 |
| | | //// @Summary 保存物料申请单 |
| | | //// @Produce application/json |
| | | //// @Param Authorization header string true "token" |
| | | //// @Param object body outsourcingrequest.SaveMaterialApply true "参数" |
| | | //// @Success 200 {object} utils.Response{} "成功" |
| | | //// @Router /outsourcing/order/saveMaterialApply [post] |
| | | //func (slf *OutsourcingController) SaveMaterialApply(c *gin.Context) { |
| | | // var params outsourcingrequest.SaveMaterialApply |
| | | // if err := c.BindJSON(¶ms); err != nil { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | // return |
| | | // } |
| | | // if len(params.ApplyList) == 0 { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "物料申请不能为空") |
| | | // return |
| | | // } |
| | | // var apply []*models.OutsourcingMaterialApply |
| | | // err := structx.AssignTo(params.ApplyList, &apply) |
| | | // if err != nil { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "数据转换失败") |
| | | // return |
| | | // } |
| | | // err = model.WithTransaction(func(db *gorm.DB) error { |
| | | // err = models.NewOutsourcingMaterialApplySearch().SetOrm(db).CreateBatch(apply) |
| | | // if err != nil { |
| | | // return err |
| | | // } |
| | | // err = models.NewOutsourcingOrderSearch().SetOrm(db).SetNumber(params.ApplyList[0].OutsourcingOrderNumber). |
| | | // UpdateByMap(map[string]interface{}{"status": constvar.OutsourcingOrderStatusMaterialApplying}) |
| | | // return err |
| | | // }) |
| | | // if err != nil { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "保存失败") |
| | | // return |
| | | // } |
| | | // |
| | | // utils.ResponseFormat(c, code.Success, "保存成功") |
| | | //} |
| | | // |
| | | //// GetMaterialApplyList |
| | | //// @Tags 委外企业管理 |
| | | //// @Summary 获取物料申请单 |
| | | //// @Produce application/json |
| | | //// @Param Authorization header string true "token" |
| | | //// @Param object body outsourcingrequest.GetMaterialApplyList true "参数" |
| | | //// @Success 200 {object} utils.ResponseList{[]models.OutsourcingMaterialApply} "成功" |
| | | //// @Router /outsourcing/order/getMaterialApplyList [post] |
| | | //func (slf *OutsourcingController) GetMaterialApplyList(c *gin.Context) { |
| | | // var params outsourcingrequest.GetMaterialApplyList |
| | | // if err := c.BindJSON(¶ms); err != nil { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | // return |
| | | // } |
| | | // find, err := models.NewOutsourcingMaterialApplySearch().SetOutsourcingOrderNumber(params.Number).FindNotTotal() |
| | | // if err != nil { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "查询失败") |
| | | // return |
| | | // } |
| | | // utils.ResponseFormat(c, code.Success, find) |
| | | //} |
| | | // |
| | | //// ChangeStatus |
| | | //// @Tags 委外企业管理 |
| | | //// @Summary 修改状态 |
| | | //// @Produce application/json |
| | | //// @Param Authorization header string true "token" |
| | | //// @Param object body outsourcingrequest.ChangeStatus true "参数" |
| | | //// @Success 200 {object} utils.Response "成功" |
| | | //// @Router /outsourcing/order/changeStatus [post] |
| | | //func (slf *OutsourcingController) ChangeStatus(c *gin.Context) { |
| | | // var params outsourcingrequest.ChangeStatus |
| | | // if err := c.BindJSON(¶ms); err != nil { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | // return |
| | | // } |
| | | // //限定状态参数 |
| | | // if params.Status == constvar.OutsourcingOrderStatusMaterialExamineRefused || |
| | | // params.Status == constvar.OutsourcingOrderStatusProducing || |
| | | // params.Status == constvar.OutsourcingOrderStatusFinish || |
| | | // params.Status == constvar.OutsourcingOrderStatusReceiveFinish { |
| | | // m := make(map[string]interface{}) |
| | | // m["status"] = params.Status |
| | | // m["reason"] = params.Reason |
| | | // err := models.NewOutsourcingOrderSearch().SetNumber(params.OutsourcingOrderNumber).UpdateByMap(m) |
| | | // if err != nil { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "状态更新失败") |
| | | // return |
| | | // } |
| | | // utils.ResponseFormat(c, code.Success, "状态更新成功") |
| | | // return |
| | | // } |
| | | // utils.ResponseFormat(c, code.RequestParamError, "状态参数不正确") |
| | | //} |
| | | // |
| | | //// GetDeliveryList |
| | | //// @Tags 委外企业管理 |
| | | //// @Summary 获取发货列表 |
| | | //// @Produce application/json |
| | | //// @Param Authorization header string true "token" |
| | | //// @Param object body outsourcingrequest.GetDeliveryList true "参数" |
| | | //// @Success 200 {object} utils.ResponseList{[]models.OutsourcingOrderDeliveryDetails} "成功" |
| | | //// @Router /outsourcing/order/deliveryList [post] |
| | | //func (slf *OutsourcingController) GetDeliveryList(c *gin.Context) { |
| | | // var params outsourcingrequest.GetDeliveryList |
| | | // if err := c.BindJSON(¶ms); err != nil { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | // return |
| | | // } |
| | | // |
| | | // _, err := models.NewOutsourcingOrderSearch().SetID(params.OutsourcingOrderID).First() |
| | | // if err != nil { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "订单不存在") |
| | | // return |
| | | // } |
| | | // |
| | | // list, err := models.NewOutsourcingOrderDeliveryDetailsSearch(). |
| | | // SetOutsourcingOrderID(params.OutsourcingOrderID). |
| | | // SetIsReceived(params.IsReceived). |
| | | // SetPreload(true). |
| | | // SetOrder("id desc"). |
| | | // FindNotTotal() |
| | | // if err != nil { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "查询失败") |
| | | // return |
| | | // } |
| | | // utils.ResponseFormat(c, code.Success, list) |
| | | //} |
| | | // |
| | | //// ConfirmReceipt |
| | | //// @Tags 委外企业管理 |
| | | //// @Summary 委外入库 确认入库 |
| | | //// @Produce application/json |
| | | //// @Param Authorization header string true "token" |
| | | //// @Param object body outsourcingrequest.ConfirmDeliveryList true "参数" |
| | | //// @Success 200 {object} utils.ResponseList{[]models.OutsourcingOrderDeliveryDetails} "成功" |
| | | //// @Router /outsourcing/order/confirmReceipt [post] |
| | | //func (slf *OutsourcingController) ConfirmReceipt(c *gin.Context) { |
| | | // var params outsourcingrequest.ConfirmDeliveryList |
| | | // if err := c.BindJSON(¶ms); err != nil { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | // return |
| | | // } |
| | | // |
| | | // outsourcingOrder, err := models.NewOutsourcingOrderSearch().SetID(params.OutsourcingOrderID).First() |
| | | // if err != nil { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "订单不存在") |
| | | // return |
| | | // } |
| | | // |
| | | // list, err := models.NewOutsourcingOrderDeliveryDetailsSearch(). |
| | | // SetOutsourcingOrderID(params.OutsourcingOrderID). |
| | | // SetIds(params.OutsourcingOrderDeliveryDetailsIds). |
| | | // SetPreload(true). |
| | | // SetOrder("id desc"). |
| | | // FindNotTotal() |
| | | // if err != nil { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "查询失败") |
| | | // return |
| | | // } |
| | | // |
| | | // operationList := make([]*inventory_order.OperationList, 0) |
| | | // products := make([]*inventory_order.OperationProduct, 0, len(list)) |
| | | // ids := make([]uint, 0, len(list)) |
| | | // for _, item := range list { |
| | | // products = append(products, &inventory_order.OperationProduct{ |
| | | // ProductNumber: item.OutsourcingOrderProduct.ProductId, |
| | | // Amount: item.SendAmount.IntPart(), |
| | | // }) |
| | | // ids = append(ids, item.ID) |
| | | // } |
| | | // var ol inventory_order.OperationList |
| | | // ol.SourceNumber = outsourcingOrder.Number |
| | | // ol.Products = products |
| | | // ol.SalesDetailsNumber = outsourcingOrder.SalesDetailsNumber |
| | | // operationList = append(operationList, &ol) |
| | | // client := inventory_order.NewInventoryOrderServiceClient(purchase_wms.PurchaseConn) |
| | | // _, err = client.CreateOperationList(c, &inventory_order.CreateOperationListRequest{ |
| | | // OperationType: 1, |
| | | // Source: "APS_OUTSOURCING_RECEIVE", |
| | | // List: operationList, |
| | | // OperationSource: common.OperationSource_OperationSourceOutsourcing, |
| | | // WarehouseId: params.WarehouseId, |
| | | // }) |
| | | // if err != nil { |
| | | // logx.Errorf("outsourcing confirmReceipt CreateOperationList failed: %v", err) |
| | | // utils.ResponseFormat(c, code.InternalError, "GRPC调用错误") |
| | | // return |
| | | // } |
| | | // |
| | | // err = models.NewOutsourcingOrderDeliveryDetailsSearch(). |
| | | // SetOutsourcingOrderID(params.OutsourcingOrderID). |
| | | // SetIds(params.OutsourcingOrderDeliveryDetailsIds).UpdateByMap(map[string]interface{}{"is_received": constvar.BoolTypeTrue}) |
| | | // if err != nil { |
| | | // logx.Errorf("outsourcing confirmReceipt CreateOperationList success but update receive status failed: %v, params:%+v", err, params) |
| | | // utils.ResponseFormat(c, code.SaveFail, "更改状态失败") |
| | | // return |
| | | // } |
| | | // utils.ResponseFormat(c, code.Success, nil) |
| | | //} |
| | | // |
| | | //// GetInventoryInputDetails |
| | | //// @Tags 委外企业管理 |
| | | //// @Summary 获取委外入库明细 |
| | | //// @Produce application/json |
| | | //// @Param Authorization header string true "token" |
| | | //// @Param object body outsourcingrequest.GetInventoryInputDetails true "参数" |
| | | //// @Success 200 {object} utils.ResponseList{[]response.OutsourcingInputItem} "成功" |
| | | //// @Router /outsourcing/order/getInventoryInputDetails [post] |
| | | //func (slf *OutsourcingController) GetInventoryInputDetails(c *gin.Context) { |
| | | // var params outsourcingrequest.GetInventoryInputDetails |
| | | // if err := c.BindJSON(¶ms); err != nil { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | // return |
| | | // } |
| | | // |
| | | // outsourcingOrder, err := models.NewOutsourcingOrderSearch().SetID(params.OutsourcingOrderID).First() |
| | | // if err != nil { |
| | | // utils.ResponseFormat(c, code.RequestParamError, "订单不存在") |
| | | // return |
| | | // } |
| | | // |
| | | // client := purchase_wms.NewPurchaseServiceClient(purchase_wms.PurchaseConn) |
| | | // resp, err := client.SrmGetOperationInfo(c, &purchase_wms.SrmGetOperationInfoRequest{ |
| | | // Number: outsourcingOrder.Number, |
| | | // OperationSource: common.OperationSource_OperationSourceOutsourcing, |
| | | // SalesDetailsNumber: outsourcingOrder.SalesDetailsNumber, |
| | | // }) |
| | | // if err != nil { |
| | | // logx.Errorf("SrmGetOperationInfo err:%v", err) |
| | | // utils.ResponseFormat(c, code.Success, nil) |
| | | // return |
| | | // } |
| | | // |
| | | // orderProducts, err := models.NewOutsourcingOrderProductSearch().SetOutsourcingOrderID(params.OutsourcingOrderID).FindNotTotal() |
| | | // if err != nil { |
| | | // utils.ResponseFormat(c, code.InternalError, "查询订单产品失败") |
| | | // return |
| | | // } |
| | | // productMap := models.OutsourcingOrderProductMap(orderProducts) |
| | | // list := make([]*response.OutsourcingInputItem, 0, len(resp.Operations)) |
| | | // for _, v := range resp.Operations { |
| | | // if productMap[v.ProductId] == nil { |
| | | // continue |
| | | // } |
| | | // list = append(list, &response.OutsourcingInputItem{ |
| | | // Number: v.Number, |
| | | // ProductId: v.ProductId, |
| | | // ProductName: v.ProductName, |
| | | // OrderAmount: productMap[v.ProductId].Amount, |
| | | // InputAmount: v.Amount, |
| | | // Specs: productMap[v.ProductId].Specs, |
| | | // Type: productMap[v.ProductId].Type, |
| | | // Unit: productMap[v.ProductId].Unit, |
| | | // Status: v.Status, |
| | | // CreateTime: v.OverTime, |
| | | // }) |
| | | // } |
| | | // utils.ResponseFormat(c, code.Success, list) |
| | | // |
| | | //} |