gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
исправь этО // enablePeopleSkudHandler - Персоны. Активировать учетную запись СКУД func…
- User
исправь этО
// enablePeopleSkudHandler - Персоны. Активировать учетную запись СКУД func enablePeopleSkudHandler(c *gin.Context) { var respBody ResponseBody
// requestBindData - структура запроса клиента type requestBindData struct { ID int `json:"id" binding:"required"` GroupID int `json:"group_id" binding:"required"` } // Принимаем данные клиента var requestData requestBindData if err := c.ShouldBindJSON(&requestData); err != nil { respBody.Status = msgStatusClientError4000 respBody.Message = errMes4000 if _debugEnable { respBody.Message += err.Error() } c.AbortWithStatusJSON(httpStatusClientError, respBody) return } // Обработка данных клиента rID := requestData.ID rGroupID := requestData.GroupID // Database workflow type People struct { ID int SkudID string } result := People{} sqlError := DB.Find(&result, rID).Error // Check SQL Errors if sqlError != nil { if gorm.IsRecordNotFoundError(sqlError) { respBody.Status = msgStatusClientError4003 respBody.Message = errMes4003 c.AbortWithStatusJSON(httpStatusClientForbidden, respBody) return } else { logger.Println(errorSQL, sqlError) respBody.Status = httpStatusServerError if _debugSQLErrorsForClientsEnable { respBody.Payload = sqlError } respBody.Message = errMesInternalServerError c.AbortWithStatusJSON(respBody.Status, respBody) return } } // Структура запроса к СКУД data := SkudPerson{ IsLocked: false, PersonID: result.SkudID, } // Database workflow type SecurityGroup struct { ID int UUID string } group := SecurityGroup{} sqlError = DB.Find(&group, rGroupID).Error // Check SQL Errors if sqlError != nil { if gorm.IsRecordNotFoundError(sqlError) { respBody.Status = msgStatusClientError4003 respBody.Message = errMes4003 c.AbortWithStatusJSON(httpStatusClientForbidden, respBody) return } else { logger.Println(errorSQL, sqlError) respBody.Status = httpStatusServerError if _debugSQLErrorsForClientsEnable { respBody.Payload = sqlError } respBody.Message = errMesInternalServerError c.AbortWithStatusJSON(respBody.Status, respBody) return } } // Добавить данные в персону data.GroupID = group.UUID // Разблокируем персону err := skudEnablePerson(&data) if err != nil { logger.Println(errorApp, err) respBody.Status = httpStatusServerError respBody.Message = errMesInternalServerError c.AbortWithStatusJSON(respBody.Status, respBody) return } // SecurityAccount - учетная запись СКУД type SecurityAccount struct { PeopleID int GroupID int Active string Updated time.Time } security := SecurityAccount{ Active: "1", Updated: time.Now(), } sqlError = DB.Model(&security).Where("`people_id` = ?", rID).Updates(&security).Error // Check SQL Errors if sqlError != nil { if gorm.IsRecordNotFoundError(sqlError) { respBody.Status = msgStatusClientError4003 respBody.Message = errMes4003 c.AbortWithStatusJSON(httpStatusClientForbidden, respBody) return } else { logger.Println(errorSQL, sqlError) respBody.Status = httpStatusServerError if _debugSQLErrorsForClientsEnable { respBody.Payload = sqlError } respBody.Message = errMesInternalServerError c.AbortWithStatusJSON(respBody.Status, respBody) return } } // Send Response respBody.Status = httpStatusOK c.JSON(respBody.Status, respBody) - Assistant