feat: management && notify
This commit is contained in:
@@ -1,63 +0,0 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type FakerDate time.Time
|
||||
|
||||
const (
|
||||
timeFormat = "2006-01-02"
|
||||
)
|
||||
|
||||
func (t *FakerDate) UnmarshalJSON(data []byte) (err error) {
|
||||
fmt.Println(string(data))
|
||||
newTime, err := time.ParseInLocation(`"`+timeFormat+`"`, string(data), time.Local)
|
||||
*t = FakerDate(newTime)
|
||||
return
|
||||
}
|
||||
|
||||
func (t FakerDate) MarshalJSON() ([]byte, error) {
|
||||
fmt.Println(time.Time(t).Format(timeFormat))
|
||||
timeStr := fmt.Sprintf("\"%s\"", time.Time(t).Format(timeFormat))
|
||||
return []byte(timeStr), nil
|
||||
}
|
||||
|
||||
func (t FakerDate) String() string {
|
||||
return time.Time(t).Format(timeFormat)
|
||||
}
|
||||
|
||||
type HotelContactRequest struct {
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age,string"`
|
||||
Sex int `json:"sex,string"`
|
||||
Phone string `json:"phone"`
|
||||
Address string `json:"address"`
|
||||
HotelCode string `json:"hotel_code"`
|
||||
HotelName string `json:"hotel_name"`
|
||||
LocateCityId string `json:"locate_city_id"`
|
||||
Identification string `json:"identification"`
|
||||
InData FakerDate `json:"in_data"`
|
||||
OutData FakerDate `json:"out_data"`
|
||||
}
|
||||
|
||||
type RailwayContactRequest struct {
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age,string"`
|
||||
Sex int `json:"sex,string"`
|
||||
Phone int `json:"phone"`
|
||||
Address string `json:"address"`
|
||||
Train string `json:"train"`
|
||||
Launch FakerDate `json:"launch"`
|
||||
Identification string `json:"identification"`
|
||||
}
|
||||
|
||||
type PatientRequest struct {
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age,string"`
|
||||
Sex int `json:"sex,string"`
|
||||
Phone string `json:"phone"`
|
||||
Address string `json:"address"`
|
||||
Identification string `json:"identification"`
|
||||
}
|
||||
156
models/management.go
Normal file
156
models/management.go
Normal file
@@ -0,0 +1,156 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type BackObservation struct {
|
||||
ID int `gorm:"primaryKey;column:id" json:"id"` // ID
|
||||
Name string `gorm:"column:name" json:"name"` // 姓名
|
||||
Age int `gorm:"column:age" json:"age"` // 年龄
|
||||
Sex int `gorm:"column:sex" json:"sex"` // 性别
|
||||
Phone string `gorm:"column:phone" json:"phone"` // 手机号码
|
||||
Identification string `gorm:"column:identification" json:"identification"` // 身份证号
|
||||
ContactPerson int `gorm:"column:contact_person" json:"contactPerson"` // 接触者id
|
||||
Region string `gorm:"column:region" json:"region"` // 受观察者所在区域
|
||||
Address string `gorm:"column:address" json:"address"` // 受观察者所在具体地点
|
||||
HealthSituation int `gorm:"column:health_situation" json:"healthSituation"` // 被观察者的疫情状况:0- 其他,1-患者,2-密接,3-次密接
|
||||
HealthChangeTime time.Time `gorm:"column:health_change_time" json:"healthChangeTime"` // 患者健康状况转化时间
|
||||
MeasureSituation int `gorm:"column:measure_situation" json:"measureSituation"` // 受观察者被采取措施状况 :0-未采取措施,1-解除风险,2-正在治疗,3-集中隔离,4-居家隔离
|
||||
Trajectory string `gorm:"column:trajectory" json:"trajectory"` // 行程轨迹
|
||||
CreateUser int `gorm:"column:create_user" json:"createUser"` // 创建者
|
||||
CreateTime time.Time `gorm:"column:create_time" json:"createTime"` // 创建时间
|
||||
ModifyUser int `gorm:"column:modify_user" json:"modifyUser"` // 修改者
|
||||
ModifyTime time.Time `gorm:"column:modify_time" json:"modifyTime"` // 修改时间
|
||||
IsDelete int `gorm:"column:is_delete" json:"isDelete"` // 删除标志
|
||||
}
|
||||
|
||||
type BackLocation struct {
|
||||
ID int `gorm:"primaryKey;column:id" json:"id"` // ID
|
||||
Name string `gorm:"column:name" json:"name"` // 地点名
|
||||
Region string `gorm:"column:region" json:"region"` // 地点所在地区
|
||||
Address string `gorm:"column:address" json:"address"` // 地点的精确地址
|
||||
PrincipalName string `gorm:"column:principal_name" json:"principalName"` // 负责人姓名
|
||||
PrincipalPhone string `gorm:"column:principal_phone" json:"principalPhone"` // 负责人电话
|
||||
CreateUser int `gorm:"column:create_user" json:"createUser"` // 创建者
|
||||
CreateTime time.Time `gorm:"column:create_time" json:"createTime"` // 创建时间
|
||||
ModifyUser int `gorm:"column:modify_user" json:"modifyUser"` // 修改者
|
||||
ModifyTime time.Time `gorm:"column:modify_time" json:"modifyTime"` // 修改时间
|
||||
IsDelete int `gorm:"column:is_delete" json:"isDelete"` // 删除标志
|
||||
}
|
||||
|
||||
type BackPcr struct {
|
||||
ID int `gorm:"primaryKey;column:id" json:"id"` // ID
|
||||
Observation int `gorm:"column:observation" json:"observation"` // 观察对象ID
|
||||
DetectTime time.Time `gorm:"column:detect_time" json:"detectTime"` // 核酸检测时间
|
||||
DetectResult int `gorm:"column:detect_result" json:"detectResult"` // 核酸检测结果:0-未检测,1-阴性,2-阳性
|
||||
CreateUser int `gorm:"column:create_user" json:"createUser"` // 创建者
|
||||
CreateTime time.Time `gorm:"column:create_time" json:"createTime"` // 创建时间
|
||||
ModifyUser int `gorm:"column:modify_user" json:"modifyUser"` // 修改者
|
||||
ModifyTime time.Time `gorm:"column:modify_time" json:"modifyTime"` // 修改时间
|
||||
IsDelete int `gorm:"column:is_delete" json:"isDelete"` // 删除标志
|
||||
}
|
||||
|
||||
type BackSituationRecord struct {
|
||||
ID int `gorm:"primaryKey;column:id" json:"id"` // ID
|
||||
Observation int `gorm:"column:observation" json:"observation"` // 观察对象
|
||||
Record string `gorm:"column:record" json:"record"` // 状态转化记录
|
||||
CreateUser int `gorm:"column:create_user" json:"createUser"` // 创建者
|
||||
CreateTime time.Time `gorm:"column:create_time" json:"createTime"` // 创建时间
|
||||
ModifyUser int `gorm:"column:modify_user" json:"modifyUser"` // 修改者
|
||||
ModifyTime time.Time `gorm:"column:modify_time" json:"modifyTime"` // 修改时间
|
||||
IsDelete int `gorm:"column:is_delete" json:"isDelete"` // 删除标志
|
||||
}
|
||||
|
||||
type ListObeservation struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"` // 姓名
|
||||
Age int `json:"age"` // 年龄
|
||||
Sex int `json:"sex"` // 性别
|
||||
Phone string `json:"phone"` // 手机号码
|
||||
Identification string `json:"identification"` // 身份证号
|
||||
ContactPerson int `json:"contactPerson"` // 接触者id
|
||||
Region string `json:"region"` // 受观察者所在区域
|
||||
Address string `json:"address"` // 受观察者所在具体地点
|
||||
HealthSituation int `json:"healthSituation"` // 被观察者的疫情状况:0- 其他,1-患者,2-密接,3-次密接
|
||||
HealthChangeTime time.Time `json:"healthChangeTime"` // 患者健康状况转化时间
|
||||
MeasureSituation int `json:"measureSituation"` // 受观察者被采取措施状况 :0-未采取措施,1-解除风险,2-正在治疗,3-集中隔离,4-居家隔离
|
||||
Trajectory string `json:"trajectory"` // 行程轨迹
|
||||
CreateUser int `json:"createUser"` // 创建者
|
||||
CreateTime time.Time `json:"createTime"` // 创建时间
|
||||
ModifyUser int `json:"modifyUser"` // 修改者
|
||||
ModifyTime time.Time `json:"modifyTime"` // 修改时间
|
||||
PcrTime time.Time `json:"pcrTime"` //核酸时间
|
||||
PcrResult int `json:"pcrResult"` //核酸结果
|
||||
RecordTime time.Time `json:"recordTime"` //状态转换时间
|
||||
Record string `json:"record"` //状态转换内容
|
||||
}
|
||||
|
||||
type QueryObservation struct {
|
||||
BackObservation
|
||||
PcrRecord []BackPcr `json:"pcrRecord"`
|
||||
SituationRecord []BackSituationRecord `json:"situationRecord"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
initJcMap[BackObservation]()
|
||||
initJcMap[BackLocation]()
|
||||
initJcMap[BackPcr]()
|
||||
initJcMap[BackSituationRecord]()
|
||||
}
|
||||
|
||||
type FakerDate time.Time
|
||||
|
||||
const (
|
||||
timeFormat = "2006-01-02"
|
||||
)
|
||||
|
||||
func (t *FakerDate) UnmarshalJSON(data []byte) (err error) {
|
||||
newTime, err := time.ParseInLocation(`"`+timeFormat+`"`, string(data), time.Local)
|
||||
*t = FakerDate(newTime)
|
||||
return
|
||||
}
|
||||
|
||||
func (t FakerDate) MarshalJSON() ([]byte, error) {
|
||||
timeStr := fmt.Sprintf("\"%s\"", time.Time(t).Format(timeFormat))
|
||||
return []byte(timeStr), nil
|
||||
}
|
||||
|
||||
func (t FakerDate) String() string {
|
||||
return time.Time(t).Format(timeFormat)
|
||||
}
|
||||
|
||||
type HotelContactRequest struct {
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age,string"`
|
||||
Sex int `json:"sex,string"`
|
||||
Phone string `json:"phone"`
|
||||
Address string `json:"address"`
|
||||
HotelCode string `json:"hotel_code"`
|
||||
HotelName string `json:"hotel_name"`
|
||||
LocateCityId string `json:"locate_city_id"`
|
||||
Identification string `json:"identification"`
|
||||
InData FakerDate `json:"in_data"`
|
||||
OutData FakerDate `json:"out_data"`
|
||||
}
|
||||
|
||||
type RailwayContactRequest struct {
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age,string"`
|
||||
Sex int `json:"sex,string"`
|
||||
Phone string `json:"phone"`
|
||||
Address string `json:"address"`
|
||||
Train string `json:"train"`
|
||||
Launch FakerDate `json:"launch"`
|
||||
Identification string `json:"identification"`
|
||||
}
|
||||
|
||||
type PatientRequest struct {
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age,string"`
|
||||
Sex int `json:"sex,string"`
|
||||
Phone string `json:"phone"`
|
||||
Address string `json:"address"`
|
||||
Identification string `json:"identification"`
|
||||
}
|
||||
9
models/notify.go
Normal file
9
models/notify.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type BackNotification struct {
|
||||
Time time.Time `json:"time"`
|
||||
Kind int `json:"kind"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
@@ -59,3 +59,42 @@ type ChinaData struct {
|
||||
ChinaAdd ChinaAdd `json:"chinaAdd"`
|
||||
ChinaTotal ChinaTotal `json:"chinaTotal"`
|
||||
}
|
||||
|
||||
type ChinaDayAdd struct {
|
||||
DeadRate string `json:"deadRate"`
|
||||
HealRate string `json:"healRate"`
|
||||
Date string `json:"date"`
|
||||
Year string `json:"y"`
|
||||
Confirm int `json:"confirm"`
|
||||
Suspect int `json:"suspect"`
|
||||
Dead int `json:"dead"`
|
||||
Infect int `json:"infect"`
|
||||
Heal int `json:"heal"`
|
||||
ImportedCase int `json:"importedCase"`
|
||||
Localinfectionadd int `json:"localinfectionadd"`
|
||||
LocalConfirmadd int `json:"localConfirmadd"`
|
||||
}
|
||||
|
||||
type ChinaDay struct {
|
||||
DeadRate string `json:"deadRate"`
|
||||
NoInfect int `json:"noInfect"`
|
||||
LocalConfirm int `json:"localConfirm"`
|
||||
ImportedCase int `json:"importedCase"`
|
||||
Date string `json:"date"`
|
||||
LocalConfirmH5 int `json:"localConfirmH5"`
|
||||
Suspect int `json:"suspect"`
|
||||
Dead int `json:"dead"`
|
||||
Heal int `json:"heal"`
|
||||
Year string `json:"y"`
|
||||
Confirm int `json:"confirm"`
|
||||
NowConfirm int `json:"nowConfirm"`
|
||||
HealRate string `json:"healRate"`
|
||||
NowSevere int `json:"nowSevere"`
|
||||
NoInfectH5 int `json:"noInfectH5"`
|
||||
LocalAccConfirm int `json:"local_acc_confirm"`
|
||||
}
|
||||
|
||||
type ChinaTrend struct {
|
||||
ChinaDayList []ChinaDay `json:"ChinaDayList"`
|
||||
ChinaDayAddList []ChinaDayAdd `json:"chinaDayAddList"`
|
||||
}
|
||||
|
||||
@@ -60,17 +60,60 @@ func MapJ2c[T any](jsonMap map[string]interface{}, ignoreNil bool) (colMap map[s
|
||||
return colMap
|
||||
}
|
||||
|
||||
func MapsJ2c[T any](jsonMaps []map[string]interface{}, ignoreNil bool) (colMaps []map[string]interface{}) {
|
||||
for _, jsonMap := range jsonMaps {
|
||||
colMap := MapJ2c[T](jsonMap, ignoreNil)
|
||||
colMaps = append(colMaps, colMap)
|
||||
}
|
||||
return colMaps
|
||||
}
|
||||
|
||||
func MapC2j[T any](colMap map[string]interface{}, ignoreNil bool) (jsonMap map[string]interface{}) {
|
||||
tName := reflect.TypeOf(new(T)).Elem().Name()
|
||||
tC2jMap := c2jMap[tName]
|
||||
if tC2jMap == nil {
|
||||
panic(tName + " is not init registered int j2cMap")
|
||||
}
|
||||
|
||||
jsonMap = make(map[string]interface{})
|
||||
for k, v := range colMap {
|
||||
//TODO 无法转换
|
||||
if jsonKey := tC2jMap[k]; jsonKey != "" && (!ignoreNil || v != nil) {
|
||||
jsonMap[jsonKey] = v
|
||||
}
|
||||
}
|
||||
return jsonMap
|
||||
}
|
||||
|
||||
func MapsC2j[T any](jsonMaps []map[string]interface{}, ignoreNil bool) (colMaps []map[string]interface{}) {
|
||||
for _, jsonMap := range jsonMaps {
|
||||
colMap := MapC2j[T](jsonMap, ignoreNil)
|
||||
colMaps = append(colMaps, colMap)
|
||||
}
|
||||
return colMaps
|
||||
}
|
||||
|
||||
// BeforeSave need to set some field while insert or update
|
||||
func BeforeSave(colMap map[string]interface{}, user int) {
|
||||
if colMap["id"] == nil {
|
||||
if colMap["id"] == nil || int(colMap["id"].(float64)) == 0 {
|
||||
colMap["create_time"] = time.Now()
|
||||
if user != -1 {
|
||||
colMap["create_user"] = user
|
||||
} else {
|
||||
colMap["create_user"] = 0
|
||||
}
|
||||
}
|
||||
colMap["modify_time"] = time.Now()
|
||||
if user != -1 {
|
||||
colMap["modify_user"] = user
|
||||
} else {
|
||||
colMap["modify_user"] = 0
|
||||
}
|
||||
}
|
||||
|
||||
func BeforeBatchSave(colMaps *[]map[string]interface{}, user int) {
|
||||
for _, colMap := range *colMaps {
|
||||
BeforeSave(colMap, user)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +124,7 @@ func BeforeSave(colMap map[string]interface{}, user int) {
|
||||
|
||||
func Upsert[T any](colMap map[string]interface{}) (ok bool, rowsAffected int64) {
|
||||
var tx *gorm.DB
|
||||
if colMap["id"] == nil {
|
||||
if colMap["id"] == nil || int(colMap["id"].(float64)) == 0 {
|
||||
tx = global.Db.Model(new(T)).Create(colMap)
|
||||
} else {
|
||||
tx = global.Db.Model(new(T)).Where("id = ?", colMap["id"]).Updates(colMap)
|
||||
@@ -93,6 +136,15 @@ func Upsert[T any](colMap map[string]interface{}) (ok bool, rowsAffected int64)
|
||||
return true, tx.RowsAffected
|
||||
}
|
||||
|
||||
func BatchInsert[T any](colMaps []map[string]interface{}) (ok bool, rowsAffected int64) {
|
||||
tx := global.Db.Model(new(T)).Create(&colMaps)
|
||||
if tx.Error != nil {
|
||||
fmt.Println(tx.Error)
|
||||
return false, 0
|
||||
}
|
||||
return true, tx.RowsAffected
|
||||
}
|
||||
|
||||
func Update[T any](queryMap []map[string]interface{}, updateMap map[string]interface{}) (ok bool, rowsAffected int64) {
|
||||
tx := global.Db.Model(new(T))
|
||||
for _, e := range queryMap {
|
||||
@@ -120,6 +172,10 @@ func DeleteById[T any](id int) (ok bool, rowsAffected int64) {
|
||||
return true, rowsAffected
|
||||
}
|
||||
|
||||
func DropById[T any](id int) {
|
||||
global.Db.Model(new(T)).Delete("id = ?", id)
|
||||
}
|
||||
|
||||
func List[T any](queryMap []map[string]interface{}) *[]map[string]interface{} {
|
||||
tx := global.Db.Model(new(T))
|
||||
for _, e := range queryMap {
|
||||
|
||||
Reference in New Issue
Block a user