|
@@ -7,6 +7,8 @@ import (
|
7
|
7
|
"XT_New/service"
|
8
|
8
|
"encoding/json"
|
9
|
9
|
"fmt"
|
|
10
|
+ "github.com/jinzhu/gorm"
|
|
11
|
+ "strconv"
|
10
|
12
|
"time"
|
11
|
13
|
)
|
12
|
14
|
|
|
@@ -28,7 +30,6 @@ func (this *CommonApiController) GetInspectionMajor() {
|
28
|
30
|
|
29
|
31
|
func (this *CommonApiController) GetInspectionMinor() {
|
30
|
32
|
id, _ := this.GetInt64("id")
|
31
|
|
- fmt.Println("id----------------------------------------", id)
|
32
|
33
|
minor, err := service.GetInspectionMinor(id)
|
33
|
34
|
if err != nil {
|
34
|
35
|
this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
|
|
@@ -55,8 +56,6 @@ func (this *CommonApiController) GetInspectionRange() {
|
55
|
56
|
func (this *CommonApiController) SaveConfiguration() {
|
56
|
57
|
adminInfo := this.GetAdminUserInfo()
|
57
|
58
|
orgid := adminInfo.CurrentOrgId
|
58
|
|
- fmt.Println(orgid)
|
59
|
|
- fmt.Println("触发-------------------0")
|
60
|
59
|
dataBody := make(map[string]interface{}, 0)
|
61
|
60
|
err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
|
62
|
61
|
fmt.Println("err", err)
|
|
@@ -69,13 +68,14 @@ func (this *CommonApiController) SaveConfiguration() {
|
69
|
68
|
largerange := dataBody["large_range"].(string)
|
70
|
69
|
fmt.Println("largerange", largerange)
|
71
|
70
|
sort := dataBody["sort"].(string)
|
|
71
|
+ sorts, err := strconv.ParseInt(sort, 10, 64)
|
72
|
72
|
fmt.Println("sort", sort)
|
73
|
73
|
standard := models.XtQualityControlStandard{
|
74
|
74
|
InspectionMajor: inspectionmajor,
|
75
|
75
|
InspectionMinor: inspectionMinor,
|
76
|
76
|
MinRange: minrange,
|
77
|
77
|
LargeRange: largerange,
|
78
|
|
- Sort: sort,
|
|
78
|
+ Sort: sorts,
|
79
|
79
|
UserOrgId: orgid,
|
80
|
80
|
Status: 1,
|
81
|
81
|
CreatedTime: time.Now().Unix(),
|
|
@@ -106,3 +106,217 @@ func (this *CommonApiController) GetConfigurationlist() {
|
106
|
106
|
"total": total,
|
107
|
107
|
})
|
108
|
108
|
}
|
|
109
|
+
|
|
110
|
+func (this *CommonApiController) GetConfigurationDetail() {
|
|
111
|
+ id, _ := this.GetInt64("id")
|
|
112
|
+ fmt.Println("id是", id)
|
|
113
|
+ detail, err := service.GetConfigurationDetail(id)
|
|
114
|
+ if err != nil {
|
|
115
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
|
|
116
|
+ return
|
|
117
|
+ }
|
|
118
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
119
|
+ "configurationdetail": detail,
|
|
120
|
+ })
|
|
121
|
+}
|
|
122
|
+
|
|
123
|
+func (this *CommonApiController) GetAllInspectionminor() {
|
|
124
|
+
|
|
125
|
+ minor, err := service.GetAllInspectionMinor(0)
|
|
126
|
+ if err != nil {
|
|
127
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
|
|
128
|
+ return
|
|
129
|
+ }
|
|
130
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
131
|
+ "minor": minor,
|
|
132
|
+ })
|
|
133
|
+}
|
|
134
|
+
|
|
135
|
+func (this *CommonApiController) UpdateConfiguration() {
|
|
136
|
+ id, _ := this.GetInt64("id")
|
|
137
|
+ fmt.Println("id", id)
|
|
138
|
+ dataBody := make(map[string]interface{}, 0)
|
|
139
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
|
|
140
|
+ fmt.Println("err", err)
|
|
141
|
+ inspectionmajor := int64(dataBody["inspectionMajor"].(float64))
|
|
142
|
+ fmt.Println("大项", inspectionmajor)
|
|
143
|
+ inspectionMinor := int64(dataBody["inspectionMinor"].(float64))
|
|
144
|
+ fmt.Println("小项", inspectionMinor)
|
|
145
|
+ minrange := dataBody["min_range"].(string)
|
|
146
|
+ fmt.Println("minragne", minrange)
|
|
147
|
+ largerange := dataBody["large_range"].(string)
|
|
148
|
+ fmt.Println("largerange", largerange)
|
|
149
|
+ sort := int64(dataBody["sort"].(float64))
|
|
150
|
+
|
|
151
|
+ standard := models.XtQualityControlStandard{
|
|
152
|
+ InspectionMajor: inspectionmajor,
|
|
153
|
+ InspectionMinor: inspectionMinor,
|
|
154
|
+ MinRange: minrange,
|
|
155
|
+ LargeRange: largerange,
|
|
156
|
+ Sort: sort,
|
|
157
|
+ }
|
|
158
|
+ err = service.UpdarteConfiguration(&standard, id)
|
|
159
|
+ if err != nil {
|
|
160
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
|
|
161
|
+ return
|
|
162
|
+ }
|
|
163
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
164
|
+ "standard": standard,
|
|
165
|
+ })
|
|
166
|
+}
|
|
167
|
+
|
|
168
|
+func (this *CommonApiController) DeleteConfiguration() {
|
|
169
|
+ id, _ := this.GetInt64("id")
|
|
170
|
+ err := service.DeleteConfiguration(id)
|
|
171
|
+ if err != nil {
|
|
172
|
+ this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败")
|
|
173
|
+ return
|
|
174
|
+ }
|
|
175
|
+ returnData := make(map[string]interface{}, 0)
|
|
176
|
+ returnData["msg"] = "ok"
|
|
177
|
+ this.ServeSuccessJSON(returnData)
|
|
178
|
+ return
|
|
179
|
+}
|
|
180
|
+
|
|
181
|
+func (this *CommonApiController) GetAllInspectiondata() {
|
|
182
|
+ adminUser := this.GetAdminUserInfo()
|
|
183
|
+ orgid := adminUser.CurrentOrgId
|
|
184
|
+
|
|
185
|
+ //查询该机构是否有数据
|
|
186
|
+ _, errcode := service.GetAllInspectionData(orgid)
|
|
187
|
+ if errcode == gorm.ErrRecordNotFound {
|
|
188
|
+ inspection, err := service.GetAllInspectiondatatwo(0)
|
|
189
|
+ if err != nil {
|
|
190
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
|
|
191
|
+ return
|
|
192
|
+ }
|
|
193
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
194
|
+ "inspection": inspection,
|
|
195
|
+ })
|
|
196
|
+ } else if errcode == nil {
|
|
197
|
+ inspection, err := service.GetAllInspectiondatatwo(orgid)
|
|
198
|
+ if err != nil {
|
|
199
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
|
|
200
|
+ return
|
|
201
|
+ }
|
|
202
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
203
|
+ "inspection": inspection,
|
|
204
|
+ })
|
|
205
|
+ }
|
|
206
|
+
|
|
207
|
+}
|
|
208
|
+
|
|
209
|
+func (this *CommonApiController) SaveCheckConfiguration() {
|
|
210
|
+ dataBody := make(map[string]interface{}, 0)
|
|
211
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
|
|
212
|
+ fmt.Println("err", err)
|
|
213
|
+ adminUser := this.GetAdminUserInfo()
|
|
214
|
+ orgid := adminUser.CurrentOrgId
|
|
215
|
+ inspectionmajor := int64(dataBody["inspectionMajor"].(float64))
|
|
216
|
+ fmt.Println("大项", inspectionmajor)
|
|
217
|
+ frequency := dataBody["frequency"].(string)
|
|
218
|
+ fmt.Println("凭次", frequency)
|
|
219
|
+ sort := dataBody["sort"].(string)
|
|
220
|
+ sorts, err := strconv.ParseInt(sort, 10, 64)
|
|
221
|
+ fmt.Println("sort", sort)
|
|
222
|
+ _, errcode := service.GetInspectionMajorById(inspectionmajor)
|
|
223
|
+ if errcode == gorm.ErrRecordNotFound {
|
|
224
|
+ configuration := models.XtCheckConfiguration{
|
|
225
|
+ InspectionMajor: inspectionmajor,
|
|
226
|
+ InspectionFrequency: frequency,
|
|
227
|
+ Sort: sorts,
|
|
228
|
+ UserOrgId: orgid,
|
|
229
|
+ Status: 1,
|
|
230
|
+ CreatedTime: time.Now().Unix(),
|
|
231
|
+ }
|
|
232
|
+ err := service.CreateCheckConfiguration(&configuration)
|
|
233
|
+ if err != nil {
|
|
234
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
|
|
235
|
+ return
|
|
236
|
+ }
|
|
237
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
238
|
+ "configuration": configuration,
|
|
239
|
+ })
|
|
240
|
+ } else if errcode == nil {
|
|
241
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
242
|
+ return
|
|
243
|
+ }
|
|
244
|
+}
|
|
245
|
+
|
|
246
|
+func (this *CommonApiController) GetAllCheckList() {
|
|
247
|
+ adminUser := this.GetAdminUserInfo()
|
|
248
|
+ orgid := adminUser.CurrentOrgId
|
|
249
|
+ fmt.Println("org", orgid)
|
|
250
|
+ page, _ := this.GetInt64("page")
|
|
251
|
+ limit, _ := this.GetInt64("limit")
|
|
252
|
+ checkList, total, err := service.GetAllCheckList(orgid, page, limit)
|
|
253
|
+ if err != nil {
|
|
254
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
|
|
255
|
+ return
|
|
256
|
+ }
|
|
257
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
258
|
+ "checklist": checkList,
|
|
259
|
+ "total": total,
|
|
260
|
+ })
|
|
261
|
+}
|
|
262
|
+
|
|
263
|
+func (this *CommonApiController) GetCheckdetail() {
|
|
264
|
+
|
|
265
|
+ id, _ := this.GetInt64("id")
|
|
266
|
+ detail, err := service.GetCheckDetail(id)
|
|
267
|
+ if err != nil {
|
|
268
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
|
|
269
|
+ return
|
|
270
|
+ }
|
|
271
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
272
|
+ "checkdetail": detail,
|
|
273
|
+ })
|
|
274
|
+}
|
|
275
|
+
|
|
276
|
+func (this *CommonApiController) UpdateCheck() {
|
|
277
|
+ id, _ := this.GetInt64("id")
|
|
278
|
+ fmt.Println(id)
|
|
279
|
+ dataBody := make(map[string]interface{}, 0)
|
|
280
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
|
|
281
|
+ fmt.Println(err)
|
|
282
|
+ inspectionmajor := int64(dataBody["inspectionMajor"].(float64))
|
|
283
|
+ fmt.Println("大项", inspectionmajor)
|
|
284
|
+ frequency := dataBody["frequency"].(string)
|
|
285
|
+ fmt.Println("凭次", frequency)
|
|
286
|
+ sort := int64(dataBody["sort"].(float64))
|
|
287
|
+ fmt.Println("sort", sort)
|
|
288
|
+
|
|
289
|
+ Inspection, err := service.GetInspectionMajorById(inspectionmajor)
|
|
290
|
+ if Inspection.ID > 0 && Inspection.ID != id {
|
|
291
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
|
|
292
|
+ return
|
|
293
|
+ }
|
|
294
|
+
|
|
295
|
+ configuration := models.XtCheckConfiguration{
|
|
296
|
+ InspectionMajor: inspectionmajor,
|
|
297
|
+ InspectionFrequency: frequency,
|
|
298
|
+ Sort: sort,
|
|
299
|
+ }
|
|
300
|
+
|
|
301
|
+ err = service.UpdateCheck(&configuration, id)
|
|
302
|
+ if err != nil {
|
|
303
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
|
|
304
|
+ return
|
|
305
|
+ }
|
|
306
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
307
|
+ "configuration": configuration,
|
|
308
|
+ })
|
|
309
|
+}
|
|
310
|
+
|
|
311
|
+func (this *CommonApiController) DeleteCheck() {
|
|
312
|
+ id, _ := this.GetInt64("id")
|
|
313
|
+ err := service.DeleteCheck(id)
|
|
314
|
+ if err != nil {
|
|
315
|
+ this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败")
|
|
316
|
+ return
|
|
317
|
+ }
|
|
318
|
+ returnData := make(map[string]interface{}, 0)
|
|
319
|
+ returnData["msg"] = "ok"
|
|
320
|
+ this.ServeSuccessJSON(returnData)
|
|
321
|
+ return
|
|
322
|
+}
|