package new_mobile_api_controllers import ( "XT_New/controllers" "XT_New/enums" "XT_New/models" "XT_New/service" "encoding/json" "fmt" "github.com/jinzhu/gorm" "strconv" "time" ) type CommonApiController struct { controllers.BaseAuthAPIController } func (this *CommonApiController) GetInspectionMajor() { major, err := service.GetInspectionMajor(0) if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } this.ServeSuccessJSON(map[string]interface{}{ "inspection": major, }) } func (this *CommonApiController) GetInspectionMinor() { id, _ := this.GetInt64("id") minor, err := service.GetInspectionMinor(id) if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } this.ServeSuccessJSON(map[string]interface{}{ "inspection": minor, }) } func (this *CommonApiController) GetInspectionRange() { id, _ := this.GetInt64("id") fmt.Println("id", id) inspectionRange, err := service.GetInspectionRange(id) if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } this.ServeSuccessJSON(map[string]interface{}{ "inspectionRange": inspectionRange, }) } func (this *CommonApiController) SaveConfiguration() { adminInfo := this.GetAdminUserInfo() orgid := adminInfo.CurrentOrgId dataBody := make(map[string]interface{}, 0) err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody) fmt.Println("err", err) inspectionmajor := int64(dataBody["inspectionMajor"].(float64)) fmt.Println("大项", inspectionmajor) inspectionMinor := int64(dataBody["inspectionMinor"].(float64)) fmt.Println("小项", inspectionMinor) minrange := dataBody["min_range"].(string) fmt.Println("minragne", minrange) largerange := dataBody["large_range"].(string) fmt.Println("largerange", largerange) sort := dataBody["sort"].(string) sorts, err := strconv.ParseInt(sort, 10, 64) fmt.Println("sort", sort) standard := models.XtQualityControlStandard{ InspectionMajor: inspectionmajor, InspectionMinor: inspectionMinor, MinRange: minrange, LargeRange: largerange, Sort: sorts, UserOrgId: orgid, Status: 1, CreatedTime: time.Now().Unix(), } fmt.Println(standard) err = service.SaveInspection(&standard) if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } this.ServeSuccessJSON(map[string]interface{}{ "standard": standard, }) } func (this *CommonApiController) GetConfigurationlist() { limit, _ := this.GetInt64("limit") page, _ := this.GetInt64("page") adminUser := this.GetAdminUserInfo() orgid := adminUser.CurrentOrgId configurationlist, total, err := service.GetConfigurationlist(orgid, limit, page) if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } this.ServeSuccessJSON(map[string]interface{}{ "configurationlist": configurationlist, "total": total, }) } func (this *CommonApiController) GetConfigurationDetail() { id, _ := this.GetInt64("id") fmt.Println("id是", id) detail, err := service.GetConfigurationDetail(id) if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } this.ServeSuccessJSON(map[string]interface{}{ "configurationdetail": detail, }) } func (this *CommonApiController) GetAllInspectionminor() { minor, err := service.GetAllInspectionMinor(0) if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } this.ServeSuccessJSON(map[string]interface{}{ "minor": minor, }) } func (this *CommonApiController) UpdateConfiguration() { id, _ := this.GetInt64("id") fmt.Println("id", id) dataBody := make(map[string]interface{}, 0) err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody) fmt.Println("err", err) inspectionmajor := int64(dataBody["inspectionMajor"].(float64)) fmt.Println("大项", inspectionmajor) inspectionMinor := int64(dataBody["inspectionMinor"].(float64)) fmt.Println("小项", inspectionMinor) minrange := dataBody["min_range"].(string) fmt.Println("minragne", minrange) largerange := dataBody["large_range"].(string) fmt.Println("largerange", largerange) sort := int64(dataBody["sort"].(float64)) standard := models.XtQualityControlStandard{ InspectionMajor: inspectionmajor, InspectionMinor: inspectionMinor, MinRange: minrange, LargeRange: largerange, Sort: sort, } err = service.UpdarteConfiguration(&standard, id) if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } this.ServeSuccessJSON(map[string]interface{}{ "standard": standard, }) } func (this *CommonApiController) DeleteConfiguration() { id, _ := this.GetInt64("id") err := service.DeleteConfiguration(id) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败") return } returnData := make(map[string]interface{}, 0) returnData["msg"] = "ok" this.ServeSuccessJSON(returnData) return } func (this *CommonApiController) GetAllInspectiondata() { adminUser := this.GetAdminUserInfo() orgid := adminUser.CurrentOrgId //查询该机构是否有数据 _, errcode := service.GetAllInspectionData(orgid) if errcode == gorm.ErrRecordNotFound { inspection, err := service.GetAllInspectiondatatwo(0) if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } this.ServeSuccessJSON(map[string]interface{}{ "inspection": inspection, }) } else if errcode == nil { inspection, err := service.GetAllInspectiondatatwo(orgid) if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } this.ServeSuccessJSON(map[string]interface{}{ "inspection": inspection, }) } } func (this *CommonApiController) SaveCheckConfiguration() { dataBody := make(map[string]interface{}, 0) err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody) fmt.Println("err", err) adminUser := this.GetAdminUserInfo() orgid := adminUser.CurrentOrgId inspectionmajor := int64(dataBody["inspectionMajor"].(float64)) fmt.Println("大项", inspectionmajor) frequency := dataBody["frequency"].(string) fmt.Println("凭次", frequency) sort := dataBody["sort"].(string) sorts, err := strconv.ParseInt(sort, 10, 64) fmt.Println("sort", sort) _, errcode := service.GetInspectionMajorById(inspectionmajor) if errcode == gorm.ErrRecordNotFound { configuration := models.XtCheckConfiguration{ InspectionMajor: inspectionmajor, InspectionFrequency: frequency, Sort: sorts, UserOrgId: orgid, Status: 1, CreatedTime: time.Now().Unix(), } err := service.CreateCheckConfiguration(&configuration) if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } this.ServeSuccessJSON(map[string]interface{}{ "configuration": configuration, }) } else if errcode == nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } func (this *CommonApiController) GetAllCheckList() { adminUser := this.GetAdminUserInfo() orgid := adminUser.CurrentOrgId fmt.Println("org", orgid) page, _ := this.GetInt64("page") limit, _ := this.GetInt64("limit") checkList, total, err := service.GetAllCheckList(orgid, page, limit) if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } this.ServeSuccessJSON(map[string]interface{}{ "checklist": checkList, "total": total, }) } func (this *CommonApiController) GetCheckdetail() { id, _ := this.GetInt64("id") detail, err := service.GetCheckDetail(id) if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } this.ServeSuccessJSON(map[string]interface{}{ "checkdetail": detail, }) } func (this *CommonApiController) UpdateCheck() { id, _ := this.GetInt64("id") fmt.Println(id) dataBody := make(map[string]interface{}, 0) err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody) fmt.Println(err) inspectionmajor := int64(dataBody["inspectionMajor"].(float64)) fmt.Println("大项", inspectionmajor) frequency := dataBody["frequency"].(string) fmt.Println("凭次", frequency) sort := int64(dataBody["sort"].(float64)) fmt.Println("sort", sort) Inspection, err := service.GetInspectionMajorById(inspectionmajor) if Inspection.ID > 0 && Inspection.ID != id { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } configuration := models.XtCheckConfiguration{ InspectionMajor: inspectionmajor, InspectionFrequency: frequency, Sort: sort, } err = service.UpdateCheck(&configuration, id) if err != nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } this.ServeSuccessJSON(map[string]interface{}{ "configuration": configuration, }) } func (this *CommonApiController) DeleteCheck() { id, _ := this.GetInt64("id") err := service.DeleteCheck(id) if err != nil { this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败") return } returnData := make(map[string]interface{}, 0) returnData["msg"] = "ok" this.ServeSuccessJSON(returnData) return }