product_controller.go
4.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/product/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/product/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/product/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
type ProductController struct {
beego.BaseController
}
func (controller *ProductController) CreateProduct() {
productService := service.NewProductService(nil)
createProductCommand := &command.CreateProductCommand{}
Must(controller.Unmarshal(createProductCommand))
op := ParseOperateInfo(controller.BaseController)
createProductCommand.CompanyId = op.CompanyId
createProductCommand.OrgId = op.OrgId
data, err := productService.CreateProduct(ParseOperateInfo(controller.BaseController), createProductCommand)
controller.Response(data, err)
}
func (controller *ProductController) UpdateProduct() {
productService := service.NewProductService(nil)
updateProductCommand := &command.UpdateProductCommand{}
Must(controller.Unmarshal(updateProductCommand))
productId, _ := controller.GetInt(":productId")
updateProductCommand.ProductId = productId
data, err := productService.UpdateProduct(ParseOperateInfo(controller.BaseController), updateProductCommand)
controller.Response(data, err)
}
func (controller *ProductController) GetProduct() {
productService := service.NewProductService(nil)
getProductQuery := &query.GetProductQuery{}
productId, _ := controller.GetInt(":productId")
getProductQuery.ProductId = productId
data, err := productService.GetProduct(getProductQuery)
controller.Response(data, err)
}
func (controller *ProductController) RemoveProduct() {
productService := service.NewProductService(nil)
removeProductCommand := &command.RemoveProductCommand{}
controller.Unmarshal(removeProductCommand)
productId, _ := controller.GetInt(":productId")
removeProductCommand.ProductId = productId
data, err := productService.RemoveProduct(removeProductCommand)
controller.Response(data, err)
}
func (controller *ProductController) BatchRemoveProduct() {
productService := service.NewProductService(nil)
removeProductCommand := &command.BatchRemoveProductCommand{}
Must(controller.Unmarshal(removeProductCommand))
data, err := productService.BatchRemoveProduct(removeProductCommand)
controller.Response(data, err)
}
func (controller *ProductController) ListProduct() {
productService := service.NewProductService(nil)
listProductQuery := &query.ListProductQuery{}
offset, _ := controller.GetInt("offset")
listProductQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listProductQuery.Limit = limit
data, err := productService.ListProduct(listProductQuery)
controller.Response(data, err)
}
func (controller *ProductController) SearchProduct() {
productService := service.NewProductService(nil)
cmd := &query.SearchProductQuery{}
Must(controller.Unmarshal(cmd))
operateInfo := ParseOperateInfo(controller.BaseController)
//cmd.OrgId = operateInfo.OrgId
cmd.CompanyId = operateInfo.CompanyId
cmd.InOrgIds = operateInfo.OrgIds
total, data, err := productService.SearchProduct(ParseOperateInfo(controller.BaseController), cmd)
ResponseGrid(controller.BaseController, total, data, err)
}
func (controller *ProductController) BatchAddProduct() {
productService := service.NewProductService(nil)
cmd := &struct {
List []*domain.ImportProductItem `json:"list"`
}{}
Must(controller.Unmarshal(cmd))
data, err := productService.BatchAddProduct(ParseOperateInfo(controller.BaseController), cmd.List)
controller.Response(data, err)
}
func (controller *ProductController) GenProductCode() {
productService := service.NewProductService(nil)
cmd := &query.GenProductCodeQuery{}
Must(controller.Unmarshal(cmd))
op := ParseOperateInfo(controller.BaseController)
cmd.CompanyId = op.CompanyId
data, err := productService.GenProductCode(cmd)
controller.Response(data, err)
}