feat: 实现小程序离线巡检与可靠同步
This commit is contained in:
@@ -70,10 +70,11 @@ func createInspection(db *gorm.DB, s3 *service.S3Service, ai *service.AIClient,
|
||||
return func(c *gin.Context) {
|
||||
idemKey := strings.TrimSpace(c.GetHeader("Idempotency-Key"))
|
||||
roomID := strings.TrimSpace(c.PostForm("roomId"))
|
||||
userID := currentUserID(c)
|
||||
|
||||
if idemKey != "" {
|
||||
if idemKey != "" && userID != nil {
|
||||
var exist model.InspectionRecord
|
||||
if db.Where("idempotency_key = ?", idemKey).First(&exist).Error == nil {
|
||||
if db.Where("user_id = ? AND idempotency_key = ?", *userID, idemKey).First(&exist).Error == nil {
|
||||
c.JSON(http.StatusOK, exist)
|
||||
return
|
||||
}
|
||||
@@ -113,7 +114,7 @@ func createInspection(db *gorm.DB, s3 *service.S3Service, ai *service.AIClient,
|
||||
imageURL := s3.Endpoint() + "/" + bucket + "/" + key
|
||||
|
||||
rec := model.InspectionRecord{
|
||||
UserID: currentUserID(c),
|
||||
UserID: userID,
|
||||
ImageURL: &imageURL,
|
||||
AIStatus: "done",
|
||||
}
|
||||
@@ -221,9 +222,9 @@ func createInspection(db *gorm.DB, s3 *service.S3Service, ai *service.AIClient,
|
||||
})
|
||||
if txErr != nil {
|
||||
// 并发幂等:唯一索引冲突时返回已有记录
|
||||
if idemKey != "" {
|
||||
if idemKey != "" && userID != nil {
|
||||
var exist model.InspectionRecord
|
||||
if db.Where("idempotency_key = ?", idemKey).First(&exist).Error == nil {
|
||||
if db.Where("user_id = ? AND idempotency_key = ?", *userID, idemKey).First(&exist).Error == nil {
|
||||
c.JSON(http.StatusOK, exist)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user