From b1d7efd8c4ab9c4bf56f62e636a358a5182c09bf Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期六, 28 九月 2024 23:43:58 +0800
Subject: [PATCH] fix db colummn

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

diff --git a/db/repository.go b/db/repository.go
index ca159f7..f948b01 100644
--- a/db/repository.go
+++ b/db/repository.go
@@ -1,330 +1,14 @@
 package db
 
-import (
-	"basic.com/valib/logger.git"
-	"errors"
-	"gorm.io/gorm"
-	"strconv"
-)
-
 // 鏌ヨ灏忓尯琛�
 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 GetPublicHouseData() ([]PublicHouse, error) {
-	// 鏌ヨ鏁版嵁
-	var db = DB
-	var ph []PublicHouse
-	result := db.Table("public_house").Where("1 = 1").Find(&ph)
-	if result.Error != nil {
-		return nil, result.Error
-	}
-	return ph, 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 GetDBPersonStatus(id, communityId string) string {
-	var db = DB
-
-	// 鏌ヨ鏁版嵁
-	var personStatus string
-	db.Table("snapshot_count_summary").
-		Select("status").
-		Where("community_id = ? and document_number = ?", communityId, id).
-		Find(&personStatus)
-
-	return personStatus
-}
-
-// 鏌ヨ灏忓尯妗f琛� (鍘熸煡璇换鍔″睘鎬�)
-func QueryPersonStatusWithPagination(community_id string, timeThreshold int64) ([]*PersonStatus, error) {
-	var db = DB
-	var personStatusList []*PersonStatus
-	result := db.Select("document_number, status, frequent_address, last_appearance_time, last_appearance_status_time").
-		Where("community_id = ? AND last_appearance_time != last_appearance_status_time AND last_appearance_time > ?", community_id, timeThreshold).
-		Find(&personStatusList)
-	if result.Error != nil {
-		logger.Error(result.Error)
-		return nil, result.Error
-	}
-	return personStatusList, nil
-}
-
-// 鏌ヨ浜虹墿骞撮緞
-func GetAgeById(id string) (int, error) {
-	var db = DB
-	// 鏌ヨ鏁版嵁
-	var age string
-	if err := db.Table("dbtablepersons").
-		Select("age").
-		Where("id = ?", id).
-		Find(&age).Error; err != nil {
-		return 0, err
-	}
-
-	return strconv.Atoi(age)
-}
-
-// 鏌ヨ浜虹墿韬唤璇佸彿
-func GetIdCardById(id string) string {
-	var db = DB
-	// 鏌ヨ鏁版嵁
-	var idCard string
-	db.Table("dbtablepersons").
-		Select("idCard").
-		Where("id = ?", id).
-		Find(&idCard)
-
-	return idCard
-}
-
-//// 鏍规嵁绀惧尯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 string
-	err := db.Table("dbtablepersons").
-		Select("age").
-		Where("id = ?", id).
-		Scan(&age).Error
-	if err != nil {
-		return 0, err
-	}
-
-	return strconv.Atoi(age)
-}
-
-// 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 {
-		err := db.Model(&PersonStatus{}).
-			Where("document_number = ? AND community_id = ?", person.DocumentNumber, communityID).
-			Updates(map[string]interface{}{
-				"status":                   person.Status,
-				"frequent_address":         person.FrequentAddress,
-				"LastAppearanceStatusTime": person.LastAppearanceStatusTime,
-			}).Error
-		if err != nil {
-			return err
-		}
-	}
-
-	return nil
 }

--
Gitblit v1.8.0