device_controller.go
3.9 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
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/device/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/device/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/device/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
)
type DeviceController struct {
beego.BaseController
}
func (controller *DeviceController) CreateDevice() {
deviceService := service.NewDeviceService(nil)
createDeviceCommand := &command.CreateDeviceCommand{}
Must(controller.Unmarshal(createDeviceCommand))
data, err := deviceService.CreateDevice(ParseOperateInfo(controller.BaseController), createDeviceCommand)
controller.Response(data, err)
}
func (controller *DeviceController) UpdateDevice() {
deviceService := service.NewDeviceService(nil)
updateDeviceCommand := &command.UpdateDeviceCommand{}
Must(controller.Unmarshal(updateDeviceCommand))
deviceId, _ := controller.GetInt(":deviceId")
updateDeviceCommand.DeviceId = deviceId
data, err := deviceService.UpdateDevice(updateDeviceCommand)
controller.Response(data, err)
}
func (controller *DeviceController) GetDevice() {
deviceService := service.NewDeviceService(nil)
getDeviceQuery := &query.GetDeviceQuery{}
deviceId, _ := controller.GetInt(":deviceId")
getDeviceQuery.DeviceId = deviceId
data, err := deviceService.GetDevice(getDeviceQuery)
controller.Response(data, err)
}
func (controller *DeviceController) RemoveDevice() {
deviceService := service.NewDeviceService(nil)
removeDeviceCommand := &command.RemoveDeviceCommand{}
Must(controller.Unmarshal(removeDeviceCommand))
deviceId, _ := controller.GetInt(":deviceId")
removeDeviceCommand.DeviceId = deviceId
data, err := deviceService.RemoveDevice(removeDeviceCommand)
controller.Response(data, err)
}
func (controller *DeviceController) BatchRemoveDevice() {
deviceService := service.NewDeviceService(nil)
removeDeviceCommand := &command.BatchRemoveDeviceCommand{}
Must(controller.Unmarshal(removeDeviceCommand))
data, err := deviceService.BatchRemoveDevice(removeDeviceCommand)
controller.Response(data, err)
}
func (controller *DeviceController) ListDevice() {
deviceService := service.NewDeviceService(nil)
listDeviceQuery := &query.ListDeviceQuery{}
offset, _ := controller.GetInt("offset")
listDeviceQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listDeviceQuery.Limit = limit
data, err := deviceService.ListDevice(listDeviceQuery)
controller.Response(data, err)
}
func (controller *DeviceController) SearchDevice() {
deviceService := service.NewDeviceService(nil)
cmd := &query.SearchDeviceQuery{}
Must(controller.Unmarshal(cmd))
operateInfo := ParseOperateInfo(controller.BaseController)
//cmd.OrgId = operateInfo.OrgId
cmd.CompanyId = operateInfo.CompanyId
cmd.InOrgIds = operateInfo.OrgIds
total, data, err := deviceService.SearchDevice(ParseOperateInfo(controller.BaseController), cmd)
ResponseGrid(controller.BaseController, total, data, err)
}
func (controller *DeviceController) SelectorDeviceUnbounded() {
deviceService := service.NewDeviceService(nil)
cmd := &query.SearchDeviceQuery{}
Must(controller.Unmarshal(cmd))
operateInfo := ParseOperateInfo(controller.BaseController)
//cmd.OrgId = operateInfo.OrgId
cmd.CompanyId = operateInfo.CompanyId
cmd.InOrgIds = operateInfo.OrgIds
total, data, err := deviceService.SelectorDeviceUnbounded(ParseOperateInfo(controller.BaseController), cmd)
ResponseGrid(controller.BaseController, total, data, err)
}
func (controller *DeviceController) BatchAddDevice() {
productService := service.NewDeviceService(nil)
cmd := &struct {
List []*domain.ImportDeviceItem `json:"list"`
}{}
Must(controller.Unmarshal(cmd))
data, err := productService.BatchAddProduct(ParseOperateInfo(controller.BaseController), cmd.List)
controller.Response(data, err)
}