product_material_controller.go 4.0 KB
package controllers

import (
	"github.com/linmadan/egglib-go/web/beego"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterial/command"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterial/query"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productMaterial/service"
)

type ProductMaterialController struct {
	beego.BaseController
}

func (controller *ProductMaterialController) CreateProductMaterial() {
	productMaterialService := service.NewProductMaterialService(nil)
	cmd := &command.CreateProductMaterialCommand{}
	controller.Unmarshal(cmd)
	operateInfo := ParseOperateInfo(controller.BaseController)
	cmd.CompanyId = operateInfo.CompanyId
	cmd.OrgId = operateInfo.OrgId
	data, err := productMaterialService.CreateProductMaterial(operateInfo, cmd)
	controller.Response(data, err)
}

func (controller *ProductMaterialController) UpdateProductMaterial() {
	productMaterialService := service.NewProductMaterialService(nil)
	updateProductMaterialCommand := &command.UpdateProductMaterialCommand{}
	controller.Unmarshal(updateProductMaterialCommand)
	productMaterialId, _ := controller.GetInt(":productMaterialId")
	updateProductMaterialCommand.ProductMaterialId = productMaterialId
	operateInfo := ParseOperateInfo(controller.BaseController)
	updateProductMaterialCommand.CompanyId = operateInfo.CompanyId
	updateProductMaterialCommand.OrgId = operateInfo.OrgId
	data, err := productMaterialService.UpdateProductMaterial(operateInfo, updateProductMaterialCommand)
	controller.Response(data, err)
}

func (controller *ProductMaterialController) GetProductMaterial() {
	productMaterialService := service.NewProductMaterialService(nil)
	getProductMaterialQuery := &query.GetProductMaterialQuery{}
	productMaterialId, _ := controller.GetInt(":productMaterialId")
	getProductMaterialQuery.ProductMaterialId = productMaterialId
	operateInfo := ParseOperateInfo(controller.BaseController)
	data, err := productMaterialService.GetProductMaterial(operateInfo, getProductMaterialQuery)
	controller.Response(data, err)
}

func (controller *ProductMaterialController) RemoveProductMaterial() {
	productMaterialService := service.NewProductMaterialService(nil)
	removeProductMaterialCommand := &command.RemoveProductMaterialCommand{}
	controller.Unmarshal(removeProductMaterialCommand)
	productMaterialId, _ := controller.GetInt(":productMaterialId")
	removeProductMaterialCommand.ProductMaterialId = productMaterialId
	operateInfo := ParseOperateInfo(controller.BaseController)
	data, err := productMaterialService.RemoveProductMaterial(operateInfo, removeProductMaterialCommand)
	controller.Response(data, err)
}

//没用到
func (controller *ProductMaterialController) ListProductMaterial() {
	productMaterialService := service.NewProductMaterialService(nil)
	listProductMaterialQuery := &query.ListProductMaterialQuery{}
	operateInfo := ParseOperateInfo(controller.BaseController)
	data, err := productMaterialService.ListProductMaterial(operateInfo, listProductMaterialQuery)
	controller.Response(data, err)
}

func (controller *ProductMaterialController) SearchProductMaterial() {
	productMaterialService := service.NewProductMaterialService(nil)
	listProductMaterialQuery := &query.ListProductMaterialQuery{}
	controller.Unmarshal(listProductMaterialQuery)
	operateInfo := ParseOperateInfo(controller.BaseController)
	total, data, err := productMaterialService.SearchProductMaterial(operateInfo, listProductMaterialQuery)
	ResponseGrid(controller.BaseController, total, data, err)
}

func (controller *ProductMaterialController) BatchRemoveProductMaterial() {
	productMaterialService := service.NewProductMaterialService(nil)
	batchremoveProductMaterialCommand := &command.BatchRemoveProductMaterialCommand{}
	controller.Unmarshal(batchremoveProductMaterialCommand)
	operateInfo := ParseOperateInfo(controller.BaseController)
	data, err := productMaterialService.BatchRemoveProductMaterial(operateInfo, batchremoveProductMaterialCommand)
	controller.Response(data, err)
}