|
@@ -0,0 +1,150 @@
|
|
1
|
+package controllers
|
|
2
|
+
|
|
3
|
+import (
|
|
4
|
+ "XT_New/enums"
|
|
5
|
+ "XT_New/service"
|
|
6
|
+ "XT_New/utils"
|
|
7
|
+ "fmt"
|
|
8
|
+ "github.com/astaxie/beego"
|
|
9
|
+ "time"
|
|
10
|
+)
|
|
11
|
+
|
|
12
|
+type NewStockApiController struct {
|
|
13
|
+ BaseAuthAPIController
|
|
14
|
+}
|
|
15
|
+
|
|
16
|
+func NewStockApiRegistRouters() {
|
|
17
|
+ beego.Router("/api/drug/stock", &NewStockApiController{}, "Get:GetDrugStock")
|
|
18
|
+ beego.Router("/api/drug/change", &NewStockApiController{}, "Get:GetDrugChange")
|
|
19
|
+ //beego.Router("/api/drug/query", &NewStockApiController{}, "Get:GetDrugQuery")
|
|
20
|
+
|
|
21
|
+}
|
|
22
|
+
|
|
23
|
+func (c *NewStockApiController) GetDrugStock() {
|
|
24
|
+ start_time := c.GetString("start_time")
|
|
25
|
+ end_time := c.GetString("end_time")
|
|
26
|
+
|
|
27
|
+ timeLayout := "2006-01-02"
|
|
28
|
+ loc, _ := time.LoadLocation("Local")
|
|
29
|
+ var startTime int64
|
|
30
|
+ if len(start_time) > 0 {
|
|
31
|
+ theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
|
|
32
|
+ if err != nil {
|
|
33
|
+ fmt.Println(err)
|
|
34
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
35
|
+ return
|
|
36
|
+ }
|
|
37
|
+ startTime = theTime.Unix()
|
|
38
|
+ }
|
|
39
|
+ var endTime int64
|
|
40
|
+ if len(end_time) > 0 {
|
|
41
|
+ theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
|
|
42
|
+ if err != nil {
|
|
43
|
+ utils.ErrorLog(err.Error())
|
|
44
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
45
|
+ return
|
|
46
|
+ }
|
|
47
|
+ endTime = theTime.Unix()
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+ admin := c.GetAdminUserInfo()
|
|
51
|
+ is_pc, _ := c.GetInt64("is_pc", 0)
|
|
52
|
+ is_bg, _ := c.GetInt64("is_bg", 0)
|
|
53
|
+ //manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
|
|
54
|
+ //dealerList, _ := service.GetAllDealerList(admin.CurrentOrgId)
|
|
55
|
+ fmt.Println(startTime)
|
|
56
|
+ fmt.Println(endTime)
|
|
57
|
+
|
|
58
|
+ warehousingInfo, err := service.FindAllDrugWarehousingInfo(admin.CurrentOrgId, is_pc, is_bg, startTime, endTime)
|
|
59
|
+ //list, _ := service.GetAll/**/StoreHouseListThree(admin.CurrentOrgId)
|
|
60
|
+ if err == nil {
|
|
61
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
62
|
+ "info": warehousingInfo,
|
|
63
|
+ //"manufacturerList": manufacturerList,
|
|
64
|
+ //"dealerList": dealerList,
|
|
65
|
+ //"list": list,
|
|
66
|
+ })
|
|
67
|
+ } else {
|
|
68
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
|
|
69
|
+ }
|
|
70
|
+}
|
|
71
|
+
|
|
72
|
+func (c *NewStockApiController) GetDrugChange() {
|
|
73
|
+ start_time := c.GetString("start_time")
|
|
74
|
+ end_time := c.GetString("end_time")
|
|
75
|
+
|
|
76
|
+ timeLayout := "2006-01-02"
|
|
77
|
+ loc, _ := time.LoadLocation("Local")
|
|
78
|
+ var startTime int64
|
|
79
|
+ if len(start_time) > 0 {
|
|
80
|
+ theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
|
|
81
|
+ if err != nil {
|
|
82
|
+ fmt.Println(err)
|
|
83
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
84
|
+ return
|
|
85
|
+ }
|
|
86
|
+ startTime = theTime.Unix()
|
|
87
|
+ }
|
|
88
|
+ var endTime int64
|
|
89
|
+ if len(end_time) > 0 {
|
|
90
|
+ theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
|
|
91
|
+ if err != nil {
|
|
92
|
+ utils.ErrorLog(err.Error())
|
|
93
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
94
|
+ return
|
|
95
|
+ }
|
|
96
|
+ endTime = theTime.Unix()
|
|
97
|
+ }
|
|
98
|
+ orgId := c.GetAdminUserInfo().CurrentOrgId
|
|
99
|
+ page, _ := c.GetInt64("page")
|
|
100
|
+ limit, _ := c.GetInt64("limit")
|
|
101
|
+ list, total, _ := service.GetNewDrugFlow(orgId, limit, page, startTime, endTime)
|
|
102
|
+ manufacturerList, _ := service.GetAllManufacturerList(orgId)
|
|
103
|
+ dealerList, _ := service.GetAllDealerList(orgId)
|
|
104
|
+ houseList, _ := service.GetAllStoreHouseList(orgId)
|
|
105
|
+ //patientList, _ := service.GetAllPatientListSix(orgId)
|
|
106
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
107
|
+ "info": list,
|
|
108
|
+ "total": total,
|
|
109
|
+ "manufacturerList": manufacturerList,
|
|
110
|
+ "dealerList": dealerList,
|
|
111
|
+ "houseList": houseList,
|
|
112
|
+ //"patientList": patientList,
|
|
113
|
+ })
|
|
114
|
+}
|
|
115
|
+func (c *NewStockApiController) GetDrugQuery() {
|
|
116
|
+ id, _ := c.GetInt64("id", 0)
|
|
117
|
+
|
|
118
|
+ if id <= 0 {
|
|
119
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
120
|
+ return
|
|
121
|
+ }
|
|
122
|
+ admin := c.GetAdminUserInfo()
|
|
123
|
+
|
|
124
|
+ warehousing, err := service.FindDrugWarehousingById(id, admin.CurrentOrgId)
|
|
125
|
+
|
|
126
|
+ manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
|
|
127
|
+ dealerList, _ := service.GetAllDealerList(admin.CurrentOrgId)
|
|
128
|
+ if err != nil {
|
|
129
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
|
|
130
|
+ return
|
|
131
|
+ }
|
|
132
|
+
|
|
133
|
+ if warehousing.ID <= 0 {
|
|
134
|
+ return
|
|
135
|
+ }
|
|
136
|
+
|
|
137
|
+ warehousingInfo, err := service.FindDrugWarehousingInfoByIdThree(id, admin.CurrentOrgId)
|
|
138
|
+ list, _ := service.GetAllStoreHouseListThree(admin.CurrentOrgId)
|
|
139
|
+ if err == nil {
|
|
140
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
141
|
+ "info": warehousingInfo,
|
|
142
|
+ "warehousing": warehousing,
|
|
143
|
+ "manufacturerList": manufacturerList,
|
|
144
|
+ "dealerList": dealerList,
|
|
145
|
+ "list": list,
|
|
146
|
+ })
|
|
147
|
+ } else {
|
|
148
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
|
|
149
|
+ }
|
|
150
|
+}
|