product_plan_controller.go 5.0 KB
package controllers

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

type ProductPlanController struct {
	beego.BaseController
}

func (controller *ProductPlanController) CreateProductPlan() {
	productPlanService := service.NewProductPlanService(nil)
	cmd := &command.CreateProductPlanCommand{}
	Must(controller.Unmarshal(cmd))
	operateInfo := ParseOperateInfo(controller.BaseController)
	cmd.CompanyId = operateInfo.CompanyId
	cmd.OrgId = operateInfo.OrgId
	data, err := productPlanService.CreateProductPlan(cmd)
	controller.Response(data, err)
}

func (controller *ProductPlanController) UpdateProductPlan() {
	productPlanService := service.NewProductPlanService(nil)
	updateProductPlanCommand := &command.UpdateProductPlanCommand{}
	Must(controller.Unmarshal(updateProductPlanCommand))
	productPlanId, _ := controller.GetInt(":productPlanId")
	updateProductPlanCommand.ProductPlanId = productPlanId
	data, err := productPlanService.UpdateProductPlan(updateProductPlanCommand)
	controller.Response(data, err)
}

func (controller *ProductPlanController) GetProductPlan() {
	productPlanService := service.NewProductPlanService(nil)
	getProductPlanQuery := &query.GetProductPlanQuery{}
	productPlanId, _ := controller.GetInt(":productPlanId")
	getProductPlanQuery.ProductPlanId = productPlanId
	data, err := productPlanService.GetProductPlan(getProductPlanQuery)
	controller.Response(data, err)
}

func (controller *ProductPlanController) RemoveProductPlan() {
	productPlanService := service.NewProductPlanService(nil)
	removeProductPlanCommand := &command.RemoveProductPlanCommand{}
	controller.Unmarshal(removeProductPlanCommand)
	productPlanId, _ := controller.GetInt(":productPlanId")
	removeProductPlanCommand.ProductPlanId = productPlanId
	data, err := productPlanService.RemoveProductPlan(removeProductPlanCommand)
	controller.Response(data, err)
}

func (controller *ProductPlanController) ListProductPlan() {
	productPlanService := service.NewProductPlanService(nil)
	listProductPlanQuery := &query.ListProductPlanQuery{}
	offset, _ := controller.GetInt("offset")
	listProductPlanQuery.Offset = offset
	limit, _ := controller.GetInt("limit")
	listProductPlanQuery.Limit = limit
	data, err := productPlanService.ListProductPlan(listProductPlanQuery)
	controller.Response(data, err)
}

func (controller *ProductPlanController) ReceiveMaterial() {
	productPlanService := service.NewProductPlanService(nil)
	receiveMaterialCommand := &command.ReceiveMaterialCommand{}
	Must(controller.Unmarshal(receiveMaterialCommand))
	data, err := productPlanService.ReceiveMaterial(receiveMaterialCommand)
	controller.Response(data, err)
}

func (controller *ProductPlanController) ReturnMaterial() {
	productPlanService := service.NewProductPlanService(nil)
	returnMaterialCommand := &command.ReturnMaterialCommand{}
	Must(controller.Unmarshal(returnMaterialCommand))
	data, err := productPlanService.ReturnMaterial(returnMaterialCommand)
	controller.Response(data, err)
}

func (controller *ProductPlanController) SetOnline() {
	productPlanService := service.NewProductPlanService(nil)
	setOnlineCommand := &command.SetOnlineCommand{}
	Must(controller.Unmarshal(setOnlineCommand))
	data, err := productPlanService.SetOnline(setOnlineCommand)
	controller.Response(data, err)
}

func (controller *ProductPlanController) SetOffline() {
	productPlanService := service.NewProductPlanService(nil)
	setOnlineCommand := &command.SetOfflineCommand{}
	Must(controller.Unmarshal(setOnlineCommand))
	data, err := productPlanService.SetOffline(setOnlineCommand)
	controller.Response(data, err)
}

func (controller *ProductPlanController) Switch() {
	productPlanService := service.NewProductPlanService(nil)
	switchCommand := &command.SwitchCommand{}
	Must(controller.Unmarshal(switchCommand))
	data, err := productPlanService.Exchange(switchCommand)
	controller.Response(data, err)
}

func (controller *ProductPlanController) SubmitProductRecord() {
	productPlanService := service.NewProductPlanService(nil)
	submitProductRecordCommand := &command.SubmitProductRecordCommand{}
	Must(controller.Unmarshal(submitProductRecordCommand))
	data, err := productPlanService.SubmitProductRecord(submitProductRecordCommand)
	controller.Response(data, err)
}

func (controller *ProductPlanController) SearchProductPlan() {
	productPlanService := service.NewProductPlanService(nil)
	cmd := &query.SearchProductPlanQuery{}
	Must(controller.Unmarshal(cmd))
	operateInfo := ParseOperateInfo(controller.BaseController)
	//cmd.OrgId = operateInfo.OrgId
	cmd.CompanyId = operateInfo.CompanyId
	cmd.InOrgIds = operateInfo.OrgIds
	total, data, err := productPlanService.SearchProductPlan(ParseOperateInfo(controller.BaseController), cmd)
	ResponseGrid(controller.BaseController, total, data, err)
}