sunty
2024-09-09 28c5cf41c5064579dd62f79fd40dc5990e9565b2
Merge remote-tracking branch 'origin/master'
7个文件已修改
266 ■■■■ 已修改文件
.idea/workspace.xml 144 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cache/device.go 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
db/database.go 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
db/models.go 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
db/repository.go 53 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main.go 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
task/engine.go 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.idea/workspace.xml
@@ -1,17 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ChangeListManager">
    <list default="true" id="919111b8-f2aa-4154-8db0-88e76c9af55d" name="Default Changelist" comment="1、修改查询策略&#10;2、修改地址统计策略">
      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
      <change beforePath="$PROJECT_DIR$/config/config.go" beforeDir="false" afterPath="$PROJECT_DIR$/config/config.go" afterDir="false" />
      <change beforePath="$PROJECT_DIR$/config/rulemodelengine.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/config/rulemodelengine.yaml" afterDir="false" />
      <change beforePath="$PROJECT_DIR$/data/prepare.go" beforeDir="false" afterPath="$PROJECT_DIR$/data/prepare.go" afterDir="false" />
      <change beforePath="$PROJECT_DIR$/db/elastic.go" beforeDir="false" afterPath="$PROJECT_DIR$/db/elastic.go" afterDir="false" />
      <change beforePath="$PROJECT_DIR$/rule/engine.go" beforeDir="false" afterPath="$PROJECT_DIR$/rule/engine.go" afterDir="false" />
      <change beforePath="$PROJECT_DIR$/rule/service.go" beforeDir="false" afterPath="$PROJECT_DIR$/rule/service.go" afterDir="false" />
    <list default="true" id="919111b8-f2aa-4154-8db0-88e76c9af55d" name="Default Changelist" comment="">
      <change beforePath="$PROJECT_DIR$/cache/device.go" beforeDir="false" afterPath="$PROJECT_DIR$/cache/device.go" afterDir="false" />
    </list>
    <ignored path="$PROJECT_DIR$/out/" />
    <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
    <option name="SHOW_DIALOG" value="false" />
    <option name="HIGHLIGHT_CONFLICTS" value="true" />
    <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@@ -19,109 +11,6 @@
  </component>
  <component name="FavoritesManager">
    <favorites_list name="ruleModelEngine" />
  </component>
  <component name="FileEditorManager">
    <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
      <file pinned="false" current-in-tab="false">
        <entry file="file://$PROJECT_DIR$/rule/service.go">
          <provider selected="true" editor-type-id="text-editor">
            <state relative-caret-position="179">
              <caret line="11" column="4" selection-start-line="11" selection-start-column="4" selection-end-line="11" selection-end-column="4" />
            </state>
          </provider>
        </entry>
      </file>
      <file pinned="false" current-in-tab="true">
        <entry file="file://$PROJECT_DIR$/data/prepare.go">
          <provider selected="true" editor-type-id="text-editor">
            <state relative-caret-position="71">
              <caret line="17" column="36" lean-forward="true" selection-start-line="17" selection-start-column="36" selection-end-line="17" selection-end-column="36" />
              <folding>
                <element signature="e#14#61#0" expanded="true" />
              </folding>
            </state>
          </provider>
        </entry>
      </file>
      <file pinned="false" current-in-tab="false">
        <entry file="file://$PROJECT_DIR$/rule/identityEngine.go">
          <provider selected="true" editor-type-id="text-editor">
            <state relative-caret-position="48">
              <caret line="5" column="1" lean-forward="true" selection-start-line="5" selection-start-column="1" selection-end-line="5" selection-end-column="1" />
            </state>
          </provider>
        </entry>
      </file>
      <file pinned="false" current-in-tab="false">
        <entry file="file://$PROJECT_DIR$/config/config.go">
          <provider selected="true" editor-type-id="text-editor">
            <state relative-caret-position="737">
              <caret line="46" column="48" lean-forward="true" selection-start-line="46" selection-start-column="48" selection-end-line="46" selection-end-column="48" />
              <folding>
                <element signature="e#16#89#0" expanded="true" />
              </folding>
            </state>
          </provider>
        </entry>
      </file>
      <file pinned="false" current-in-tab="false">
        <entry file="file://$PROJECT_DIR$/config/rulemodelengine.yaml">
          <provider selected="true" editor-type-id="text-editor">
            <state relative-caret-position="337">
              <caret line="30" column="19" selection-start-line="30" selection-start-column="17" selection-end-line="30" selection-end-column="19" />
            </state>
          </provider>
        </entry>
      </file>
      <file pinned="false" current-in-tab="false">
        <entry file="file://$PROJECT_DIR$/db/elastic.go">
          <provider selected="true" editor-type-id="text-editor">
            <state relative-caret-position="192">
              <caret line="29" column="70" selection-start-line="29" selection-start-column="70" selection-end-line="29" selection-end-column="70" />
            </state>
          </provider>
        </entry>
      </file>
      <file pinned="false" current-in-tab="false">
        <entry file="file://$PROJECT_DIR$/db/elasticScriptToId.go">
          <provider selected="true" editor-type-id="text-editor">
            <state relative-caret-position="840">
              <caret line="39" column="46" lean-forward="true" selection-start-line="39" selection-start-column="46" selection-end-line="39" selection-end-column="46" />
            </state>
          </provider>
        </entry>
      </file>
      <file pinned="false" current-in-tab="false">
        <entry file="file://$PROJECT_DIR$/rule/engine.go">
          <provider selected="true" editor-type-id="text-editor">
            <state relative-caret-position="189">
              <caret line="8" column="4" selection-start-line="8" selection-start-column="4" selection-end-line="8" selection-end-column="4" />
            </state>
          </provider>
        </entry>
      </file>
      <file pinned="false" current-in-tab="false">
        <entry file="file://$PROJECT_DIR$/db/models.go">
          <provider selected="true" editor-type-id="text-editor">
            <state relative-caret-position="193">
              <caret line="152" column="11" selection-start-line="152" selection-start-column="11" selection-end-line="152" selection-end-column="11" />
            </state>
          </provider>
        </entry>
      </file>
      <file pinned="false" current-in-tab="false">
        <entry file="file://$PROJECT_DIR$/db/repository.go">
          <provider selected="true" editor-type-id="text-editor">
            <state relative-caret-position="162">
              <caret line="105" column="5" selection-start-line="105" selection-start-column="5" selection-end-line="105" selection-end-column="5" />
              <folding>
                <element signature="e#12#78#0" expanded="true" />
              </folding>
            </state>
          </provider>
        </entry>
      </file>
    </leaf>
  </component>
  <component name="FileTemplateManagerImpl">
    <option name="RECENT_TEMPLATES">
@@ -164,9 +53,17 @@
      <find>time</find>
    </findStrings>
  </component>
  <component name="GOROOT" path="C:/Program Files/Go" />
  <component name="GOROOT" url="file://D:/Go" />
  <component name="Git.Settings">
    <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
  </component>
  <component name="GitSEFilterConfiguration">
    <file-type-list>
      <filtered-out-file-type name="LOCAL_BRANCH" />
      <filtered-out-file-type name="REMOTE_BRANCH" />
      <filtered-out-file-type name="TAG" />
      <filtered-out-file-type name="COMMIT_BY_MESSAGE" />
    </file-type-list>
  </component>
  <component name="IdeDocumentHistory">
    <option name="CHANGED_PATHS">
@@ -292,7 +189,7 @@
    <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
    <property name="nodejs_npm_path_reset_for_default_project" value="true" />
    <property name="restartRequiresConfirmation" value="false" />
    <property name="settings.editor.selected.configurable" value="go.sdk" />
    <property name="settings.editor.selected.configurable" value="watcher.settings" />
  </component>
  <component name="RecentsManager">
    <key name="MoveFile.RECENT_KEYS">
@@ -301,18 +198,6 @@
    <key name="CopyFile.RECENT_KEYS">
      <recent name="F:\workspace\golang\cloud_ai\ruleModelEngine" />
    </key>
  </component>
  <component name="RunDashboard">
    <option name="ruleStates">
      <list>
        <RuleState>
          <option name="name" value="ConfigurationTypeDashboardGroupingRule" />
        </RuleState>
        <RuleState>
          <option name="name" value="StatusDashboardGroupingRule" />
        </RuleState>
      </list>
    </option>
  </component>
  <component name="RunManager" selected="Go Build.go build main.go">
    <configuration name="go build elastic.go" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true" nameIsGenerated="true">
@@ -550,6 +435,11 @@
  </component>
  <component name="VgoProject">
    <integration-enabled>true</integration-enabled>
    <environment>
      <map>
        <entry key="GOPROXY" value="https://goproxy.cn,direct" />
      </map>
    </environment>
    <proxy>https://goproxy.cn,direct</proxy>
  </component>
  <component name="XDebuggerManager">
cache/device.go
@@ -6,6 +6,8 @@
)
var Device = make(map[string]db.Device)
var PublicHouse = make(map[string]map[string]string, 0)  // 公租房数据 身份证号:小区
var PublicHouseAlarmCache = make(map[string]struct{}, 0) // 保存申住不一的数据, 同一个身份证号暂时报警一次
func DeviceCacheInit() error {
    var err error
@@ -20,3 +22,21 @@
    }
    return nil
}
func PublicHouseCacheInit() error {
    ph, err := db.GetPublicHouseData()
    if err != nil {
        logger.Error("GetDeviceData", err)
        return err
    }
    for _, v := range ph {
        if _, ok := PublicHouse[v.CommunityID]; !ok {
            PublicHouse[v.CommunityID] = make(map[string]string, 0)
        }
        PublicHouse[v.CommunityID][v.IdCard] = v.EndTime
    }
    return nil
}
db/database.go
@@ -34,6 +34,9 @@
    sqlDb.SetMaxOpenConns(1)
    sqlDb.SetConnMaxLifetime(time.Duration(120) * time.Second)
    sqlDb.SetConnMaxIdleTime(time.Duration(1800) * time.Second)
    db.AutoMigrate(&PublicHouse{})
    DB = db
    return nil
}
db/models.go
@@ -164,3 +164,18 @@
    CaptureAddress string `json:"captureAddress"`
    Direction      string `json:"direction"`
}
type PublicHouse struct {
    ID              int    `gorm:"primaryKey;autoIncrement" json:"id"`                        // 主键ID
    CommunityID     string `gorm:"column:community_id;type:varchar(255)" json:"community_id"` // 小区ID
    Applicant       string `gorm:"column:applicant;type:varchar(255)" json:"applicant"`       // 申请人
    IdCard          string `gorm:"column:id_card;type:varchar(50)" json:"id_card"`            // 证件编号
    PhoneNumber     string `gorm:"column:phone_number;type:varchar(20)" json:"phone_number"`  // 联系电话
    Address         string `gorm:"column:address;type:varchar(255)" json:"address"`           // 房屋地址
    ApplicationTime string `gorm:"column:application_time" json:"application_time"`           // 申请时间
    EndTime         string `gorm:"column:end_time" json:"end_time"`                           // 结束时间
}
func (PublicHouse) TableName() string {
    return "public_house"
}
db/repository.go
@@ -4,6 +4,7 @@
    "basic.com/valib/logger.git"
    "errors"
    "gorm.io/gorm"
    "strconv"
)
// 查询小区表
@@ -29,6 +30,17 @@
        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
}
// 查询全部数据
@@ -88,18 +100,17 @@
}
// 查询人物属性
func GetDBPersonStatusData(id string) ([]PersonStatus, error) {
func GetDBPersonStatus(id, communityId string) string {
    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
    // 查询数据
    var personStatus string
    db.Table("snapshot_count_summary").
        Select("status").
        Where("community_id = ? and document_number = ?", communityId, id).
        Find(&personStatus)
    return personStatus
}
// 查询小区档案表 (原查询任务属性)
@@ -120,7 +131,7 @@
func GetAgeById(id string) (int, error) {
    var db = DB
    // 查询数据
    var age int
    var age string
    if err := db.Table("dbtablepersons").
        Select("age").
        Where("id = ?", id).
@@ -128,7 +139,20 @@
        return 0, err
    }
    return age, nil
    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和住户属性查询住户档案编号
@@ -169,7 +193,7 @@
// 根据dbtablepersons表id查询目标档案年龄
func QueryAgeById(id string) (int, error) {
    var db = DB
    var age int
    var age string
    err := db.Table("dbtablepersons").
        Select("age").
        Where("id = ?", id).
@@ -177,7 +201,8 @@
    if err != nil {
        return 0, err
    }
    return age, nil
    return strconv.Atoi(age)
}
// UpdatePersonInfo 更新或插入多个人员信息
main.go
@@ -36,7 +36,12 @@
        logger.Error("设备表缓存失败", cacheErr)
        return
    }
    logger.Info("cache device success !")
    cacheErr = cache.PublicHouseCacheInit()
    if cacheErr != nil {
        logger.Error("公租房数据缓存失败", cacheErr)
        return
    }
    logger.Info("cache init success !")
}
func initApiServer() {
task/engine.go
@@ -62,5 +62,29 @@
}
func registeredAddressNotMatchActualResidence(taskPerson db.TaskPerson) bool {
    idCard := db.GetIdCardById(taskPerson.DocumentNumber)
    if idCard == "" {
        return false
    }
    if _, ok := cache.PublicHouse[taskPerson.CommunityId]; !ok {
        return false
    }
    // 有身份证号, 小区属于公租房, 公租房登记身份证号没有该条记录, 返回true
    personStatus := db.GetDBPersonStatus(taskPerson.DocumentNumber, taskPerson.CommunityId)
    logger.Debugf("Actual residence get person id:%s status: %s", taskPerson.DocumentNumber, personStatus)
    if personStatus == "resident" || personStatus == "permanent_resident" {
        if _, ok := cache.PublicHouse[taskPerson.CommunityId][idCard]; !ok {
            // 控制程序运行期间只输出一次报警
            if _, ok := cache.PublicHouseAlarmCache[idCard]; ok {
                return false
            } else {
                cache.PublicHouseAlarmCache[idCard] = struct{}{}
                return true
            }
        }
    }
    return false
}