|
@@ -7,6 +7,7 @@ import (
|
7
|
7
|
"XT_New/service"
|
8
|
8
|
"encoding/json"
|
9
|
9
|
"fmt"
|
|
10
|
+ "github.com/jinzhu/gorm"
|
10
|
11
|
"strconv"
|
11
|
12
|
"time"
|
12
|
13
|
)
|
|
@@ -176,3 +177,146 @@ func (this *CommonApiController) DeleteConfiguration() {
|
176
|
177
|
this.ServeSuccessJSON(returnData)
|
177
|
178
|
return
|
178
|
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
|
+}
|