From 3737ab3dd0cc753be986638316c96cb3114601e4 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期日, 29 九月 2024 16:20:46 +0800
Subject: [PATCH] fix db column

---
 db/repository.go |  300 -----------------------------------------------------------
 1 files changed, 1 insertions(+), 299 deletions(-)

diff --git a/db/repository.go b/db/repository.go
index 1353cf1..f948b01 100644
--- a/db/repository.go
+++ b/db/repository.go
@@ -1,312 +1,14 @@
 package db
 
-import (
-	"basic.com/valib/logger.git"
-	"errors"
-	"gorm.io/gorm"
-)
-
 // 鏌ヨ灏忓尯琛�
 func GetCommunityIDs() ([]string, error) {
 	// 鏌ヨ鏁版嵁
 	var db = DB
 	var communityIDs []string
-	result := db.Table("domain_unit").Where("domainType = ?", 1).Pluck("id", &communityIDs)
+	result := db.Table("domain_unit").Where("domain_type = ?", 1).Pluck("id", &communityIDs)
 	if result.Error != nil {
 		return nil, result.Error
 	}
 
 	return communityIDs, nil
-}
-
-// 鏌ヨ璁惧琛�
-func GetDeviceData() ([]Device, error) {
-	// 鏌ヨ鏁版嵁
-	var db = DB
-	var device []Device
-	result := db.Table("device").Where("communityID != ?", "").Find(&device)
-	if result.Error != nil {
-		return nil, result.Error
-	}
-
-	return device, nil
-}
-
-// 鏌ヨ鍏ㄩ儴鏁版嵁
-func GetAllTaskData() ([]Task, error) {
-	var db = DB
-	var task []Task
-	if err := db.Find(&task).Error; err != nil {
-		return nil, err
-	}
-
-	return task, nil
-}
-
-// 鏌ヨ鍏ㄩ儴鏁版嵁
-func GetAllData() ([]PersonnelStatusRule, error) {
-	var db = DB
-	var rules []PersonnelStatusRule
-	if err := db.Find(&rules).Error; err != nil {
-		return nil, err
-	}
-
-	return rules, nil
-}
-
-// 鏌ヨ浣忔埛鏃堕棿鏁版嵁
-func GetResidentData(status, communityID string) ([]Resident, error) {
-	var residents []Resident
-	//var db = DB.Debug()
-	var db = DB
-	// 鎵ц鏌ヨ
-	rows, err := db.Table("snapshot_count_summary").
-		Select("document_number", "community_id", "last_appearance_time", "created_at").
-		Where("status = ? AND community_id = ?", status, communityID).
-		//Where("snapshot_count_summary.created_at is not null").
-		Rows()
-	if err != nil {
-		return nil, err
-	}
-	defer rows.Close()
-
-	// 閬嶅巻鏌ヨ缁撴灉
-	for rows.Next() {
-		var resident Resident
-		err := rows.Scan(&resident.DocumentNumber, &resident.CommunityId, &resident.LastAppearanceTime, &resident.CreateAt)
-		if err != nil {
-			logger.Error("err: ", err)
-			return nil, err
-		}
-		//fmt.Println("resident111: ", resident)
-		residents = append(residents, resident)
-	}
-	if err := rows.Err(); err != nil {
-		return nil, err
-	}
-
-	return residents, nil
-}
-
-// 鏌ヨ浜虹墿灞炴��
-func GetDBPersonStatusData(id string) ([]PersonStatus, error) {
-	var db = DB
-	// 鏌ヨ鏁版嵁
-	var personStatusList []PersonStatus
-	if err := db.Table("person_status").
-		Select("documentNumber, status, frequentAddress").
-		Where("communityID = ?", id).
-		Find(&personStatusList).Error; err != nil {
-		return nil, err
-	}
-
-	return personStatusList, nil
-}
-
-// 鏌ヨ浜虹墿骞撮緞
-func GetAgeById(id string) (int, error) {
-	var db = DB
-	// 鏌ヨ鏁版嵁
-	var age int
-	if err := db.Table("dbtablepersons").
-		Select("age").
-		Where("id = ?", id).
-		Find(&age).Error; err != nil {
-		return 0, err
-	}
-
-	return age, nil
-}
-
-//// 鏍规嵁绀惧尯id鍜屼綇鎴峰睘鎬ф煡璇綇鎴锋。妗堢紪鍙�
-//func GetDocNumberFromPersonStatus(id, status string) ([]string, error) {
-//	var db = DB
-//	// 鏌ヨ鏁版嵁
-//	var personStatusList []PersonStatus
-//	if err := db.Table("person_status").
-//		Select("documentNumber, status, frequentAddress").
-//		Where("communityID = ? AND status = ?", id, status).
-//		Find(&personStatusList).Error; err != nil {
-//		return nil, err
-//	}
-//
-//	docNum := make([]string, 0)
-//	for _, ps := range personStatusList {
-//		docNum = append(docNum, ps.DocumentNumber)
-//	}
-//
-//	return docNum, nil
-//}
-
-// 鏌ヨ浜虹墿韬唤灞炴�ц〃
-func GetLabelManageIdentity(IdentityType int) ([]LabelManage, error) {
-	var db = DB
-	// 鏌ヨ鏁版嵁
-	var labelManageIdentity []LabelManage
-	if err := db.Table("label_manage").
-		Select("id, name, valid_days").
-		Where("type = ?", IdentityType).
-		Find(&labelManageIdentity).Error; err != nil {
-		return nil, err
-	}
-
-	return labelManageIdentity, nil
-}
-
-// 鏍规嵁dbtablepersons琛╥d鏌ヨ鐩爣妗f骞撮緞
-func QueryAgeById(id string) (int, error) {
-	var db = DB
-	var age int
-	err := db.Table("dbtablepersons").
-		Select("age").
-		Where("id = ?", id).
-		Scan(&age).Error
-	if err != nil {
-		return 0, err
-	}
-	return age, nil
-}
-
-// UpdatePersonInfo 鏇存柊鎴栨彃鍏ュ涓汉鍛樹俊鎭�
-func UpdateMoveInout(personsMoveInout []MoveInout) error {
-	var db = DB
-	// 閬嶅巻浜哄憳淇℃伅
-	for _, personMoveInout := range personsMoveInout {
-
-		// 妫�鏌ヨ褰曟槸鍚﹀瓨鍦�
-		var existingPerson MoveInout
-		err := db.Where("document_number = ? AND community_id = ?", personMoveInout.DocumentNumber, personMoveInout.CommunityID).First(&existingPerson).Error
-		if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
-			logger.Error("Query person error:", err, personMoveInout.DocumentNumber, personMoveInout.CommunityID)
-			//fmt.Println("asdasfasfasf")
-			continue
-			//return err
-		}
-
-		// 濡傛灉璁板綍瀛樺湪锛屽垯鏇存柊
-		if existingPerson.DocumentNumber != "" {
-			//fmt.Println("existingPerson.DocumentNumber: ", existingPerson.DocumentNumber)
-			if existingPerson.Status != "Verified" {
-				err := db.Model(&MoveInout{}).
-					Where("document_number = ? AND community_id = ?", personMoveInout.DocumentNumber, personMoveInout.CommunityID).
-					Updates(map[string]interface{}{
-						"status":        personMoveInout.Status,
-						"move_out_date": personMoveInout.MoveOutDate,
-					}).Error
-				if err != nil {
-					return err
-				}
-			} else {
-				err := db.Model(&MoveInout{}).
-					Where("document_number = ? AND community_id = ?", personMoveInout.DocumentNumber, personMoveInout.CommunityID).
-					Updates(map[string]interface{}{
-						"move_out_date": personMoveInout.MoveOutDate,
-					}).Error
-				if err != nil {
-					return err
-				}
-			}
-		} else {
-			// 濡傛灉璁板綍涓嶅瓨鍦紝鍒欐彃鍏ユ柊璁板綍
-			//fmt.Println("鎻掑叆璁板綍澶辫触")
-			//fmt.Println("data", &personMoveInout)
-			err := db.Create(&personMoveInout).Error
-			if err != nil {
-				return err
-			}
-		}
-
-	}
-
-	return nil
-}
-
-// UpdatePersonInfo 鏇存柊鎴栨彃鍏ュ涓汉鍛樿韩浠戒俊鎭�
-func UpdateDBPersonLabel(personsIdentity []Identity) error {
-	var db = DB
-	// 閬嶅巻浜哄憳淇℃伅
-	for _, personIdentity := range personsIdentity {
-
-		// 妫�鏌ヨ褰曟槸鍚﹀瓨鍦�
-		var existingPerson Identity
-		err := db.Where("dbtablepersons_id = ? AND community_id = ? AND label_id = ?",
-			personIdentity.DocumentNumber,
-			personIdentity.CommunityID,
-			personIdentity.LabelId,
-		).First(&existingPerson).Error
-		if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
-			logger.Error("Query person error:", err,
-				personIdentity.DocumentNumber,
-				personIdentity.CommunityID,
-				personIdentity.LabelId)
-			//fmt.Println("asdasfasfasf")
-			continue
-			//return err
-		}
-
-		// 濡傛灉璁板綍瀛樺湪锛屽垯鏇存柊
-		if existingPerson.DocumentNumber != "" {
-			err := db.Model(&Identity{}).
-				Where("dbtablepersons_id = ? AND community_id = ? AND label_id = ?",
-					personIdentity.DocumentNumber,
-					personIdentity.CommunityID,
-					personIdentity.LabelId,
-				).
-				Updates(map[string]interface{}{
-					"expire_time": personIdentity.ExpireTime,
-				}).Error
-			if err != nil {
-				return err
-			}
-		} else {
-			// 濡傛灉璁板綍涓嶅瓨鍦紝鍒欐彃鍏ユ柊璁板綍
-			err := db.Create(&personIdentity).Error
-			if err != nil {
-				return err
-			}
-		}
-
-	}
-
-	return nil
-}
-
-// UpdatePersonInfo 鏇存柊鎴栨彃鍏ュ涓汉鍛樹俊鎭�
-func UpdatePersonInfo(persons []PersonStatus, communityID string) error {
-	var db = DB
-	// 閬嶅巻浜哄憳淇℃伅
-	for _, person := range persons {
-
-		// 妫�鏌ヨ褰曟槸鍚﹀瓨鍦�
-		var existingPerson PersonStatus
-		err := db.Where("document_number = ? AND community_id = ?", person.DocumentNumber, communityID).First(&existingPerson).Error
-		if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
-			logger.Error("Query person error:", err, person.DocumentNumber, communityID)
-			//fmt.Println("asdasfasfasf")
-			continue
-			//return err
-		}
-
-		// 濡傛灉璁板綍瀛樺湪锛屽垯鏇存柊
-		if existingPerson.DocumentNumber != "" {
-			err := db.Model(&PersonStatus{}).
-				Where("document_number = ? AND community_id = ?", person.DocumentNumber, communityID).
-				Updates(map[string]interface{}{
-					"status":           person.Status,
-					"frequent_address": person.FrequentAddress,
-				}).Error
-			if err != nil {
-				return err
-			}
-		} else {
-			// 濡傛灉璁板綍涓嶅瓨鍦紝鍒欐彃鍏ユ柊璁板綍
-			err := db.Create(&person).Error
-			if err != nil {
-				return err
-			}
-		}
-
-	}
-
-	return nil
 }

--
Gitblit v1.8.0