Pārlūkot izejas kodu

feat: 朴津地图上传&提醒

HeWang 8 mēneši atpakaļ
vecāks
revīzija
cf6e650943

+ 31 - 0
biz/dal/mysql/device.go

@@ -0,0 +1,31 @@
+package mysql
+
+import (
+	"context"
+	"pji_desktop_http/biz/dal/query"
+	"pji_desktop_http/biz/model"
+)
+
+func AddDeviceOneRecord(ctx context.Context, record model.Device) error {
+	r := query.Device
+	err := r.WithContext(ctx).Create(&record)
+	return err
+}
+
+func QueryAllDevices(ctx context.Context) ([]*model.Device, error) {
+	r := query.Device
+	devices, err := r.WithContext(ctx).Find()
+	if err != nil {
+		return nil, err
+	}
+	return devices, nil
+}
+
+func QueryDeviceByDeviceNo(ctx context.Context, deviceNo string) (*model.Device, error) {
+	r := query.Device
+	device, err := r.WithContext(ctx).Where(r.DeviceNo.Eq(deviceNo)).First()
+	if err != nil {
+		return nil, err
+	}
+	return device, nil
+}

+ 29 - 2
biz/dal/mysql/device_map.go

@@ -34,7 +34,25 @@ func QueryValidDeviceMapByMapId(ctx context.Context, mapId string) ([]*model.Dev
 	return deviceMaps, nil
 }
 
-func QueryValidDeviceMapByDevice(ctx context.Context, mapId string, deviceNo string) ([]*model.DeviceMap, error) {
+func QueryValidDeviceMapByDeviceNo(ctx context.Context, deviceNo string) ([]*model.DeviceMap, error) {
+	r := query.DeviceMap
+	deviceMaps, err := r.WithContext(ctx).Where(r.DeviceNo.Eq(deviceNo), r.MapValidFlag.Eq(config.MAP_VALID_FLAG)).Find()
+	if err != nil {
+		return nil, err
+	}
+	return deviceMaps, nil
+}
+
+//func QueryValidDeviceMapByMapIdAndDevice(ctx context.Context, mapId string, deviceNo string) ([]*model.DeviceMap, error) {
+//	r := query.DeviceMap
+//	deviceMaps, err := r.WithContext(ctx).Where(r.MapID.Eq(mapId), r.DeviceNo.Eq(deviceNo), r.MapValidFlag.Eq(config.MAP_VALID_FLAG)).Find()
+//	if err != nil {
+//		return nil, err
+//	}
+//	return deviceMaps, nil
+//}
+
+func QueryValidDeviceMapByMapIdAndDeviceNo(ctx context.Context, mapId string, deviceNo string) ([]*model.DeviceMap, error) {
 	r := query.DeviceMap
 	deviceMaps, err := r.WithContext(ctx).Where(r.MapID.Eq(mapId), r.DeviceNo.Eq(deviceNo), r.MapValidFlag.Eq(config.MAP_VALID_FLAG)).Find()
 	if err != nil {
@@ -52,7 +70,16 @@ func UpdateDeviceMapValidFlagByMapId(ctx context.Context, mapId string, flag int
 	return info, nil
 }
 
-func UpdateDeviceMapValidFlagByDevice(ctx context.Context, mapId string, deviceNo string, flag int) (gen.ResultInfo, error) {
+func UpdateDeviceMapValidFlagByDeviceNo(ctx context.Context, deviceNo string, flag int) (gen.ResultInfo, error) {
+	r := query.DeviceMap
+	info, err := r.WithContext(ctx).Where(r.DeviceNo.Eq(deviceNo)).Update(r.MapValidFlag, flag)
+	if err != nil {
+		return info, err
+	}
+	return info, nil
+}
+
+func UpdateDeviceMapValidFlagByMapIdAndDevice(ctx context.Context, mapId string, deviceNo string, flag int) (gen.ResultInfo, error) {
 	r := query.DeviceMap
 	info, err := r.WithContext(ctx).Where(r.MapID.Eq(mapId), r.DeviceNo.Eq(deviceNo)).Update(r.MapValidFlag, flag)
 	if err != nil {

+ 24 - 2
biz/dal/mysql/map_update.go

@@ -3,6 +3,7 @@ package mysql
 import (
 	"context"
 	"fmt"
+	"gorm.io/gen"
 	"pji_desktop_http/biz/dal/query"
 	"pji_desktop_http/biz/model"
 )
@@ -13,6 +14,27 @@ func AddMapUpdateOneRecord(ctx context.Context, record model.MapUpdate) error {
 	return err
 }
 
+func UpdateMapUpdateOneRecord(ctx context.Context, record model.MapUpdate) (gen.ResultInfo, error) {
+	r := query.MapUpdate
+	info, err := r.WithContext(ctx).Where(r.ID.Eq(record.ID)).Updates(record)
+	if err != nil {
+		return info, err
+	}
+	return info, nil
+}
+
+func QueryMapUpdateRecordById(ctx context.Context, id string) (*model.MapUpdate, error) {
+	r := query.MapUpdate
+
+	record, err := r.WithContext(ctx).Where(r.ID.Eq(id)).First()
+	if err != nil {
+		return &model.MapUpdate{}, err
+	}
+
+	fmt.Println("Query map update records successfully:", &record)
+	return record, err
+}
+
 func QueryMapUpdateRecords(ctx context.Context, record *model.MapUpdate, pageFlag bool, page, pageSize int) ([]*model.MapUpdate, int64, error) {
 	r := query.MapUpdate
 	q := r.WithContext(ctx)
@@ -34,10 +56,10 @@ func QueryMapUpdateRecords(ctx context.Context, record *model.MapUpdate, pageFla
 	}
 
 	if err != nil {
-		fmt.Println("Query simulation records failed:", err.Error())
+		fmt.Println("Query map update records failed:", err.Error())
 		return nil, 0, err
 	}
 
-	fmt.Println("Query simulation records successfully:", len(records))
+	fmt.Println("Query map update records successfully:", len(records))
 	return records, count, err
 }

+ 26 - 0
biz/dal/mysql/system_config.go

@@ -0,0 +1,26 @@
+package mysql
+
+import (
+	"context"
+	"gorm.io/gen"
+	"pji_desktop_http/biz/dal/query"
+	"pji_desktop_http/biz/model"
+)
+
+func QuerySystemConfig(ctx context.Context) (*model.SystemConfig, error) {
+	r := query.SystemConfig
+	config, err := r.WithContext(ctx).First()
+	if err != nil {
+		return &model.SystemConfig{}, err
+	}
+	return config, nil
+}
+
+func UpdateSystemConfig(ctx context.Context, config *model.SystemConfig) (gen.ResultInfo, error) {
+	r := query.SystemConfig
+	info, err := r.WithContext(ctx).Where(r.DeletedAt.Eq(nil)).Update(r.RescanReminderThreshold, config.RescanReminderThreshold)
+	if err != nil {
+		return info, err
+	}
+	return info, nil
+}

+ 408 - 0
biz/dal/query/device.gen.go

@@ -0,0 +1,408 @@
+// Code generated by gorm.io/gen. DO NOT EDIT.
+// Code generated by gorm.io/gen. DO NOT EDIT.
+// Code generated by gorm.io/gen. DO NOT EDIT.
+
+package query
+
+import (
+	"context"
+
+	"gorm.io/gorm"
+	"gorm.io/gorm/clause"
+	"gorm.io/gorm/schema"
+
+	"gorm.io/gen"
+	"gorm.io/gen/field"
+
+	"gorm.io/plugin/dbresolver"
+
+	"pji_desktop_http/biz/model"
+)
+
+func newDevice(db *gorm.DB, opts ...gen.DOOption) device {
+	_device := device{}
+
+	_device.deviceDo.UseDB(db, opts...)
+	_device.deviceDo.UseModel(&model.Device{})
+
+	tableName := _device.deviceDo.TableName()
+	_device.ALL = field.NewAsterisk(tableName)
+	_device.DeviceNo = field.NewString(tableName, "device_no")
+	_device.DeviceName = field.NewString(tableName, "device_name")
+	_device.DeviceType = field.NewString(tableName, "device_type")
+	_device.CreatedAt = field.NewTime(tableName, "created_at")
+	_device.UpdatedAt = field.NewTime(tableName, "updated_at")
+	_device.DeletedAt = field.NewField(tableName, "deleted_at")
+
+	_device.fillFieldMap()
+
+	return _device
+}
+
+type device struct {
+	deviceDo deviceDo
+
+	ALL        field.Asterisk
+	DeviceNo   field.String
+	DeviceName field.String
+	DeviceType field.String
+	CreatedAt  field.Time
+	UpdatedAt  field.Time
+	DeletedAt  field.Field
+
+	fieldMap map[string]field.Expr
+}
+
+func (d device) Table(newTableName string) *device {
+	d.deviceDo.UseTable(newTableName)
+	return d.updateTableName(newTableName)
+}
+
+func (d device) As(alias string) *device {
+	d.deviceDo.DO = *(d.deviceDo.As(alias).(*gen.DO))
+	return d.updateTableName(alias)
+}
+
+func (d *device) updateTableName(table string) *device {
+	d.ALL = field.NewAsterisk(table)
+	d.DeviceNo = field.NewString(table, "device_no")
+	d.DeviceName = field.NewString(table, "device_name")
+	d.DeviceType = field.NewString(table, "device_type")
+	d.CreatedAt = field.NewTime(table, "created_at")
+	d.UpdatedAt = field.NewTime(table, "updated_at")
+	d.DeletedAt = field.NewField(table, "deleted_at")
+
+	d.fillFieldMap()
+
+	return d
+}
+
+func (d *device) WithContext(ctx context.Context) IDeviceDo { return d.deviceDo.WithContext(ctx) }
+
+func (d device) TableName() string { return d.deviceDo.TableName() }
+
+func (d device) Alias() string { return d.deviceDo.Alias() }
+
+func (d device) Columns(cols ...field.Expr) gen.Columns { return d.deviceDo.Columns(cols...) }
+
+func (d *device) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
+	_f, ok := d.fieldMap[fieldName]
+	if !ok || _f == nil {
+		return nil, false
+	}
+	_oe, ok := _f.(field.OrderExpr)
+	return _oe, ok
+}
+
+func (d *device) fillFieldMap() {
+	d.fieldMap = make(map[string]field.Expr, 6)
+	d.fieldMap["device_no"] = d.DeviceNo
+	d.fieldMap["device_name"] = d.DeviceName
+	d.fieldMap["device_type"] = d.DeviceType
+	d.fieldMap["created_at"] = d.CreatedAt
+	d.fieldMap["updated_at"] = d.UpdatedAt
+	d.fieldMap["deleted_at"] = d.DeletedAt
+}
+
+func (d device) clone(db *gorm.DB) device {
+	d.deviceDo.ReplaceConnPool(db.Statement.ConnPool)
+	return d
+}
+
+func (d device) replaceDB(db *gorm.DB) device {
+	d.deviceDo.ReplaceDB(db)
+	return d
+}
+
+type deviceDo struct{ gen.DO }
+
+type IDeviceDo interface {
+	gen.SubQuery
+	Debug() IDeviceDo
+	WithContext(ctx context.Context) IDeviceDo
+	WithResult(fc func(tx gen.Dao)) gen.ResultInfo
+	ReplaceDB(db *gorm.DB)
+	ReadDB() IDeviceDo
+	WriteDB() IDeviceDo
+	As(alias string) gen.Dao
+	Session(config *gorm.Session) IDeviceDo
+	Columns(cols ...field.Expr) gen.Columns
+	Clauses(conds ...clause.Expression) IDeviceDo
+	Not(conds ...gen.Condition) IDeviceDo
+	Or(conds ...gen.Condition) IDeviceDo
+	Select(conds ...field.Expr) IDeviceDo
+	Where(conds ...gen.Condition) IDeviceDo
+	Order(conds ...field.Expr) IDeviceDo
+	Distinct(cols ...field.Expr) IDeviceDo
+	Omit(cols ...field.Expr) IDeviceDo
+	Join(table schema.Tabler, on ...field.Expr) IDeviceDo
+	LeftJoin(table schema.Tabler, on ...field.Expr) IDeviceDo
+	RightJoin(table schema.Tabler, on ...field.Expr) IDeviceDo
+	Group(cols ...field.Expr) IDeviceDo
+	Having(conds ...gen.Condition) IDeviceDo
+	Limit(limit int) IDeviceDo
+	Offset(offset int) IDeviceDo
+	Count() (count int64, err error)
+	Scopes(funcs ...func(gen.Dao) gen.Dao) IDeviceDo
+	Unscoped() IDeviceDo
+	Create(values ...*model.Device) error
+	CreateInBatches(values []*model.Device, batchSize int) error
+	Save(values ...*model.Device) error
+	First() (*model.Device, error)
+	Take() (*model.Device, error)
+	Last() (*model.Device, error)
+	Find() ([]*model.Device, error)
+	FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Device, err error)
+	FindInBatches(result *[]*model.Device, batchSize int, fc func(tx gen.Dao, batch int) error) error
+	Pluck(column field.Expr, dest interface{}) error
+	Delete(...*model.Device) (info gen.ResultInfo, err error)
+	Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
+	UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
+	Updates(value interface{}) (info gen.ResultInfo, err error)
+	UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
+	UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
+	UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
+	UpdateFrom(q gen.SubQuery) gen.Dao
+	Attrs(attrs ...field.AssignExpr) IDeviceDo
+	Assign(attrs ...field.AssignExpr) IDeviceDo
+	Joins(fields ...field.RelationField) IDeviceDo
+	Preload(fields ...field.RelationField) IDeviceDo
+	FirstOrInit() (*model.Device, error)
+	FirstOrCreate() (*model.Device, error)
+	FindByPage(offset int, limit int) (result []*model.Device, count int64, err error)
+	ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
+	Scan(result interface{}) (err error)
+	Returning(value interface{}, columns ...string) IDeviceDo
+	UnderlyingDB() *gorm.DB
+	schema.Tabler
+}
+
+func (d deviceDo) Debug() IDeviceDo {
+	return d.withDO(d.DO.Debug())
+}
+
+func (d deviceDo) WithContext(ctx context.Context) IDeviceDo {
+	return d.withDO(d.DO.WithContext(ctx))
+}
+
+func (d deviceDo) ReadDB() IDeviceDo {
+	return d.Clauses(dbresolver.Read)
+}
+
+func (d deviceDo) WriteDB() IDeviceDo {
+	return d.Clauses(dbresolver.Write)
+}
+
+func (d deviceDo) Session(config *gorm.Session) IDeviceDo {
+	return d.withDO(d.DO.Session(config))
+}
+
+func (d deviceDo) Clauses(conds ...clause.Expression) IDeviceDo {
+	return d.withDO(d.DO.Clauses(conds...))
+}
+
+func (d deviceDo) Returning(value interface{}, columns ...string) IDeviceDo {
+	return d.withDO(d.DO.Returning(value, columns...))
+}
+
+func (d deviceDo) Not(conds ...gen.Condition) IDeviceDo {
+	return d.withDO(d.DO.Not(conds...))
+}
+
+func (d deviceDo) Or(conds ...gen.Condition) IDeviceDo {
+	return d.withDO(d.DO.Or(conds...))
+}
+
+func (d deviceDo) Select(conds ...field.Expr) IDeviceDo {
+	return d.withDO(d.DO.Select(conds...))
+}
+
+func (d deviceDo) Where(conds ...gen.Condition) IDeviceDo {
+	return d.withDO(d.DO.Where(conds...))
+}
+
+func (d deviceDo) Order(conds ...field.Expr) IDeviceDo {
+	return d.withDO(d.DO.Order(conds...))
+}
+
+func (d deviceDo) Distinct(cols ...field.Expr) IDeviceDo {
+	return d.withDO(d.DO.Distinct(cols...))
+}
+
+func (d deviceDo) Omit(cols ...field.Expr) IDeviceDo {
+	return d.withDO(d.DO.Omit(cols...))
+}
+
+func (d deviceDo) Join(table schema.Tabler, on ...field.Expr) IDeviceDo {
+	return d.withDO(d.DO.Join(table, on...))
+}
+
+func (d deviceDo) LeftJoin(table schema.Tabler, on ...field.Expr) IDeviceDo {
+	return d.withDO(d.DO.LeftJoin(table, on...))
+}
+
+func (d deviceDo) RightJoin(table schema.Tabler, on ...field.Expr) IDeviceDo {
+	return d.withDO(d.DO.RightJoin(table, on...))
+}
+
+func (d deviceDo) Group(cols ...field.Expr) IDeviceDo {
+	return d.withDO(d.DO.Group(cols...))
+}
+
+func (d deviceDo) Having(conds ...gen.Condition) IDeviceDo {
+	return d.withDO(d.DO.Having(conds...))
+}
+
+func (d deviceDo) Limit(limit int) IDeviceDo {
+	return d.withDO(d.DO.Limit(limit))
+}
+
+func (d deviceDo) Offset(offset int) IDeviceDo {
+	return d.withDO(d.DO.Offset(offset))
+}
+
+func (d deviceDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IDeviceDo {
+	return d.withDO(d.DO.Scopes(funcs...))
+}
+
+func (d deviceDo) Unscoped() IDeviceDo {
+	return d.withDO(d.DO.Unscoped())
+}
+
+func (d deviceDo) Create(values ...*model.Device) error {
+	if len(values) == 0 {
+		return nil
+	}
+	return d.DO.Create(values)
+}
+
+func (d deviceDo) CreateInBatches(values []*model.Device, batchSize int) error {
+	return d.DO.CreateInBatches(values, batchSize)
+}
+
+// Save : !!! underlying implementation is different with GORM
+// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
+func (d deviceDo) Save(values ...*model.Device) error {
+	if len(values) == 0 {
+		return nil
+	}
+	return d.DO.Save(values)
+}
+
+func (d deviceDo) First() (*model.Device, error) {
+	if result, err := d.DO.First(); err != nil {
+		return nil, err
+	} else {
+		return result.(*model.Device), nil
+	}
+}
+
+func (d deviceDo) Take() (*model.Device, error) {
+	if result, err := d.DO.Take(); err != nil {
+		return nil, err
+	} else {
+		return result.(*model.Device), nil
+	}
+}
+
+func (d deviceDo) Last() (*model.Device, error) {
+	if result, err := d.DO.Last(); err != nil {
+		return nil, err
+	} else {
+		return result.(*model.Device), nil
+	}
+}
+
+func (d deviceDo) Find() ([]*model.Device, error) {
+	result, err := d.DO.Find()
+	return result.([]*model.Device), err
+}
+
+func (d deviceDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Device, err error) {
+	buf := make([]*model.Device, 0, batchSize)
+	err = d.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
+		defer func() { results = append(results, buf...) }()
+		return fc(tx, batch)
+	})
+	return results, err
+}
+
+func (d deviceDo) FindInBatches(result *[]*model.Device, batchSize int, fc func(tx gen.Dao, batch int) error) error {
+	return d.DO.FindInBatches(result, batchSize, fc)
+}
+
+func (d deviceDo) Attrs(attrs ...field.AssignExpr) IDeviceDo {
+	return d.withDO(d.DO.Attrs(attrs...))
+}
+
+func (d deviceDo) Assign(attrs ...field.AssignExpr) IDeviceDo {
+	return d.withDO(d.DO.Assign(attrs...))
+}
+
+func (d deviceDo) Joins(fields ...field.RelationField) IDeviceDo {
+	for _, _f := range fields {
+		d = *d.withDO(d.DO.Joins(_f))
+	}
+	return &d
+}
+
+func (d deviceDo) Preload(fields ...field.RelationField) IDeviceDo {
+	for _, _f := range fields {
+		d = *d.withDO(d.DO.Preload(_f))
+	}
+	return &d
+}
+
+func (d deviceDo) FirstOrInit() (*model.Device, error) {
+	if result, err := d.DO.FirstOrInit(); err != nil {
+		return nil, err
+	} else {
+		return result.(*model.Device), nil
+	}
+}
+
+func (d deviceDo) FirstOrCreate() (*model.Device, error) {
+	if result, err := d.DO.FirstOrCreate(); err != nil {
+		return nil, err
+	} else {
+		return result.(*model.Device), nil
+	}
+}
+
+func (d deviceDo) FindByPage(offset int, limit int) (result []*model.Device, count int64, err error) {
+	result, err = d.Offset(offset).Limit(limit).Find()
+	if err != nil {
+		return
+	}
+
+	if size := len(result); 0 < limit && 0 < size && size < limit {
+		count = int64(size + offset)
+		return
+	}
+
+	count, err = d.Offset(-1).Limit(-1).Count()
+	return
+}
+
+func (d deviceDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
+	count, err = d.Count()
+	if err != nil {
+		return
+	}
+
+	err = d.Offset(offset).Limit(limit).Scan(result)
+	return
+}
+
+func (d deviceDo) Scan(result interface{}) (err error) {
+	return d.DO.Scan(result)
+}
+
+func (d deviceDo) Delete(models ...*model.Device) (result gen.ResultInfo, err error) {
+	return d.DO.Delete(models)
+}
+
+func (d *deviceDo) withDO(do gen.Dao) *deviceDo {
+	d.DO = *do.(*gen.DO)
+	return d
+}

+ 8 - 0
biz/dal/query/gen.go

@@ -17,6 +17,7 @@ import (
 
 var (
 	Q                    = new(Query)
+	Device               *device
 	DeviceMap            *deviceMap
 	MapUpdate            *mapUpdate
 	SimulationTestRecord *simulationTestRecord
@@ -26,6 +27,7 @@ var (
 
 func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
 	*Q = *Use(db, opts...)
+	Device = &Q.Device
 	DeviceMap = &Q.DeviceMap
 	MapUpdate = &Q.MapUpdate
 	SimulationTestRecord = &Q.SimulationTestRecord
@@ -36,6 +38,7 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
 func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
 	return &Query{
 		db:                   db,
+		Device:               newDevice(db, opts...),
 		DeviceMap:            newDeviceMap(db, opts...),
 		MapUpdate:            newMapUpdate(db, opts...),
 		SimulationTestRecord: newSimulationTestRecord(db, opts...),
@@ -47,6 +50,7 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
 type Query struct {
 	db *gorm.DB
 
+	Device               device
 	DeviceMap            deviceMap
 	MapUpdate            mapUpdate
 	SimulationTestRecord simulationTestRecord
@@ -59,6 +63,7 @@ func (q *Query) Available() bool { return q.db != nil }
 func (q *Query) clone(db *gorm.DB) *Query {
 	return &Query{
 		db:                   db,
+		Device:               q.Device.clone(db),
 		DeviceMap:            q.DeviceMap.clone(db),
 		MapUpdate:            q.MapUpdate.clone(db),
 		SimulationTestRecord: q.SimulationTestRecord.clone(db),
@@ -78,6 +83,7 @@ func (q *Query) WriteDB() *Query {
 func (q *Query) ReplaceDB(db *gorm.DB) *Query {
 	return &Query{
 		db:                   db,
+		Device:               q.Device.replaceDB(db),
 		DeviceMap:            q.DeviceMap.replaceDB(db),
 		MapUpdate:            q.MapUpdate.replaceDB(db),
 		SimulationTestRecord: q.SimulationTestRecord.replaceDB(db),
@@ -87,6 +93,7 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
 }
 
 type queryCtx struct {
+	Device               IDeviceDo
 	DeviceMap            IDeviceMapDo
 	MapUpdate            IMapUpdateDo
 	SimulationTestRecord ISimulationTestRecordDo
@@ -96,6 +103,7 @@ type queryCtx struct {
 
 func (q *Query) WithContext(ctx context.Context) *queryCtx {
 	return &queryCtx{
+		Device:               q.Device.WithContext(ctx),
 		DeviceMap:            q.DeviceMap.WithContext(ctx),
 		MapUpdate:            q.MapUpdate.WithContext(ctx),
 		SimulationTestRecord: q.SimulationTestRecord.WithContext(ctx),

+ 13 - 1
biz/dal/query/map_update.gen.go

@@ -45,6 +45,9 @@ func newMapUpdate(db *gorm.DB, opts ...gen.DOOption) mapUpdate {
 	_mapUpdate.CreatedAt = field.NewTime(tableName, "created_at")
 	_mapUpdate.UpdatedAt = field.NewTime(tableName, "updated_at")
 	_mapUpdate.DeletedAt = field.NewField(tableName, "deleted_at")
+	_mapUpdate.UpdateMapURL = field.NewString(tableName, "update_map_url")
+	_mapUpdate.UploadVersion = field.NewString(tableName, "upload_version")
+	_mapUpdate.UploadedAt = field.NewTime(tableName, "uploaded_at")
 
 	_mapUpdate.fillFieldMap()
 
@@ -73,6 +76,9 @@ type mapUpdate struct {
 	CreatedAt            field.Time
 	UpdatedAt            field.Time
 	DeletedAt            field.Field
+	UpdateMapURL         field.String
+	UploadVersion        field.String
+	UploadedAt           field.Time
 
 	fieldMap map[string]field.Expr
 }
@@ -107,6 +113,9 @@ func (m *mapUpdate) updateTableName(table string) *mapUpdate {
 	m.CreatedAt = field.NewTime(table, "created_at")
 	m.UpdatedAt = field.NewTime(table, "updated_at")
 	m.DeletedAt = field.NewField(table, "deleted_at")
+	m.UpdateMapURL = field.NewString(table, "update_map_url")
+	m.UploadVersion = field.NewString(table, "upload_version")
+	m.UploadedAt = field.NewTime(table, "uploaded_at")
 
 	m.fillFieldMap()
 
@@ -133,7 +142,7 @@ func (m *mapUpdate) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
 }
 
 func (m *mapUpdate) fillFieldMap() {
-	m.fieldMap = make(map[string]field.Expr, 18)
+	m.fieldMap = make(map[string]field.Expr, 21)
 	m.fieldMap["id"] = m.ID
 	m.fieldMap["map_id"] = m.MapID
 	m.fieldMap["device_id"] = m.DeviceID
@@ -152,6 +161,9 @@ func (m *mapUpdate) fillFieldMap() {
 	m.fieldMap["created_at"] = m.CreatedAt
 	m.fieldMap["updated_at"] = m.UpdatedAt
 	m.fieldMap["deleted_at"] = m.DeletedAt
+	m.fieldMap["update_map_url"] = m.UpdateMapURL
+	m.fieldMap["upload_version"] = m.UploadVersion
+	m.fieldMap["uploaded_at"] = m.UploadedAt
 }
 
 func (m mapUpdate) clone(db *gorm.DB) mapUpdate {

+ 47 - 0
biz/handler/config_service/config_service.go

@@ -0,0 +1,47 @@
+package config_service
+
+import (
+	"context"
+	"fmt"
+	"github.com/cloudwego/hertz/pkg/app"
+	"github.com/cloudwego/hertz/pkg/protocol/consts"
+	"pji_desktop_http/biz/dal/mysql"
+	"pji_desktop_http/common/entity"
+	"strconv"
+)
+
+// QueryRescanReminderThreshold 查询续扫阈值
+// @router /config/query/rescanReminderThreshold [GET]
+func QueryRescanReminderThreshold(ctx context.Context, c *app.RequestContext) {
+	config, err := mysql.QuerySystemConfig(ctx)
+	if err != nil {
+		c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "1002", Message: "获取系统配置失败"})
+		return
+	}
+	c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "", Message: "获取续扫阈值成功", Data: strconv.FormatFloat(float64(config.RescanReminderThreshold), 'f', 2, 32)})
+}
+
+// UpdateRescanReminderThreshold 更新续扫阈值
+// @router /config/update/rescanReminderThreshold [GET]
+func UpdateRescanReminderThreshold(ctx context.Context, c *app.RequestContext) {
+	threshold := c.Query("threshold")
+	fmt.Println("threshold", threshold)
+	config, err := mysql.QuerySystemConfig(ctx)
+	if err != nil {
+		c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "获取系统配置失败"})
+		return
+	}
+	newVal, err := strconv.ParseFloat(threshold, 32)
+	if err != nil {
+		c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "数据格式转换失败"})
+		return
+	}
+	config.RescanReminderThreshold = float32(newVal)
+	_, err = mysql.UpdateSystemConfig(ctx, config)
+	if err != nil {
+		c.JSON(consts.StatusOK, entity.Response{Status: false, Code: "", Message: "更新续扫阈值失败"})
+		return
+	}
+
+	c.JSON(consts.StatusOK, entity.Response{Status: true, Code: "", Message: "更新续扫阈值成功"})
+}

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 385 - 40
biz/handler/map_service/map_service.go


+ 28 - 0
biz/model/device.go

@@ -0,0 +1,28 @@
+// Code generated by gorm.io/gen. DO NOT EDIT.
+// Code generated by gorm.io/gen. DO NOT EDIT.
+// Code generated by gorm.io/gen. DO NOT EDIT.
+
+package model
+
+import (
+	"time"
+
+	"gorm.io/gorm"
+)
+
+const TableNameDevice = "device"
+
+// Device mapped from table <device>
+type Device struct {
+	DeviceNo   string         `gorm:"column:device_no;type:varchar(100);primaryKey" json:"device_no"`
+	DeviceName string         `gorm:"column:device_name;type:varchar(100);not null" json:"device_name"`
+	DeviceType string         `gorm:"column:device_type;type:varchar(100);not null" json:"device_type"`
+	CreatedAt  time.Time      `gorm:"column:created_at;type:datetime;not null" json:"created_at"`
+	UpdatedAt  *time.Time     `gorm:"column:updated_at;type:datetime" json:"updated_at"`
+	DeletedAt  gorm.DeletedAt `gorm:"column:deleted_at;type:datetime" json:"deleted_at"`
+}
+
+// TableName Device's table name
+func (*Device) TableName() string {
+	return TableNameDevice
+}

+ 3 - 0
biz/model/map_update.go

@@ -32,6 +32,9 @@ type MapUpdate struct {
 	CreatedAt            time.Time      `gorm:"column:created_at;type:datetime;not null" json:"created_at"`
 	UpdatedAt            *time.Time     `gorm:"column:updated_at;type:datetime" json:"updated_at"`
 	DeletedAt            gorm.DeletedAt `gorm:"column:deleted_at;type:datetime" json:"deleted_at"`
+	UpdateMapURL         string         `gorm:"column:update_map_url;type:varchar(255);not null" json:"update_map_url"`
+	UploadVersion        *string        `gorm:"column:upload_version;type:varchar(50)" json:"upload_version"`
+	UploadedAt           *time.Time     `gorm:"column:uploaded_at;type:datetime" json:"uploaded_at"`
 }
 
 // TableName MapUpdate's table name

+ 12 - 0
biz/model/map_upload.go

@@ -0,0 +1,12 @@
+package model
+
+type MapUploadRes struct {
+	Msg  string    `json:"msg"`
+	Code int       `json:"code"`
+	Data MapUpload `json:"data"`
+}
+
+type MapUpload struct {
+	MapId   string `json:"mapId"`
+	Version int    `json:"version"`
+}

+ 22 - 0
common/util/u_map.go

@@ -3,8 +3,10 @@ package util
 import (
 	"encoding/json"
 	"fmt"
+	"io"
 	"io/ioutil"
 	"net/http"
+	"os"
 	"pji_desktop_http/common/config/c_pji"
 	"sync"
 )
@@ -126,3 +128,23 @@ func GetRosFileById(id string) (file string, err error) {
 
 	return rosField, nil
 }
+
+func Downloadfile(url, filepath string) error {
+	r, err := http.Get(url)
+	if err != nil {
+		fmt.Println("err", err.Error())
+	}
+
+	defer r.Body.Close()
+
+	f, err := os.Create(filepath)
+	if err != nil {
+		fmt.Println("err", err.Error())
+	}
+
+	defer f.Close()
+
+	n, err := io.Copy(f, r.Body)
+	fmt.Println(n, err)
+	return err
+}

+ 2 - 1
gen/main.go

@@ -50,11 +50,12 @@ func main() {
 	MapUpdate := g.GenerateModel("map_update")
 	World := g.GenerateModel("world")
 	SimulationTestRecord := g.GenerateModel("simulation_test_record")
+	Device := g.GenerateModel("device")
 	DeviceMap := g.GenerateModel("device_map")
 	SystemConfig := g.GenerateModel("system_config")
 
 	// 创建模型的方法,生成文件在 query 目录; 先创建结果不会被后创建的覆盖
-	g.ApplyBasic(MapUpdate, World, SimulationTestRecord, DeviceMap, SystemConfig)
+	g.ApplyBasic(MapUpdate, World, SimulationTestRecord, Device, DeviceMap, SystemConfig)
 	//g.ApplyBasic(World)
 
 	g.Execute()

+ 2 - 0
main.go

@@ -9,6 +9,7 @@ import (
 	"pji_desktop_http/common/config"
 	"pji_desktop_http/common/config/c_log"
 	"pji_desktop_http/pji_client"
+	"time"
 )
 
 func main() {
@@ -19,6 +20,7 @@ func main() {
 	//h := server.Default()
 	h := server.New(
 		server.WithStreamBody(true),
+		server.WithIdleTimeout(time.Minute*10),
 	)
 	h.Use(cors.New(cors.Config{
 		AllowOrigins:     []string{"*"},

+ 10 - 10
pji_client/pji_client.go

@@ -131,23 +131,23 @@ func sortMapByKey(m map[string]interface{}) map[string]interface{} {
 
 // 生成SHA-256哈希并进行RSA签名
 func (c *SysUserApiClient) generateSignature(val string) (string, error) {
-	fmt.Println("val", val)
+	//fmt.Println("val", val)
 	// 签名摘要
 	hash := sha256.New()
 	hash.Write([]byte(val))
 	hashed := hash.Sum(nil)
-	fmt.Println("hashed", hashed)
+	//fmt.Println("hashed", hashed)
 	str := hex.EncodeToString(hashed)
 	bytes := []byte(str)
-	fmt.Println("str", str)
-	fmt.Println("bytes", bytes)
+	//fmt.Println("str", str)
+	//fmt.Println("bytes", bytes)
 	signedData, err := rsa.SignPKCS1v15(rand.Reader, c.PrivateKey, 0, bytes)
 	str = hex.EncodeToString(signedData)
 	if err != nil {
 		return "", err
 	}
-	fmt.Println("base64", str)
-	fmt.Println("base64 signedData", base64.StdEncoding.EncodeToString([]byte(str)))
+	//fmt.Println("base64", str)
+	//fmt.Println("base64 signedData", base64.StdEncoding.EncodeToString([]byte(str)))
 	return base64.StdEncoding.EncodeToString([]byte(str)), nil
 }
 
@@ -169,7 +169,7 @@ func (c *SysUserApiClient) JsonPostRequest(url string, paramMap map[string]inter
 	paramMap = sortMapByKey(paramMap)
 
 	jsonData, err := json.Marshal(paramMap)
-	fmt.Println("jsonData", string(jsonData))
+	//fmt.Println("jsonData", string(jsonData))
 	if err != nil {
 		return nil, err
 	}
@@ -198,7 +198,7 @@ func (c *SysUserApiClient) JsonPostRequest(url string, paramMap map[string]inter
 func (c *SysUserApiClient) GetRequest(url string, paramMap map[string]interface{}, secretId string) (*protocol.Response, error) {
 	paramMap = sortMapByKey(paramMap)
 	jsonData, err := json.Marshal(paramMap)
-	fmt.Println("jsonData", string(jsonData))
+	//fmt.Println("jsonData", string(jsonData))
 	if err != nil {
 		return nil, err
 	}
@@ -223,7 +223,7 @@ func (c *SysUserApiClient) GetRequest(url string, paramMap map[string]interface{
 func (c *SysUserApiClient) UploadRequest(url string, paramMap map[string]interface{}, secretId string, file []byte) (*protocol.Response, error) {
 	paramMap = sortMapByKey(paramMap)
 	jsonData, err := json.Marshal(paramMap)
-	fmt.Println("jsonData", string(jsonData))
+	//fmt.Println("jsonData", string(jsonData))
 	if err != nil {
 		return nil, err
 	}
@@ -243,7 +243,7 @@ func (c *SysUserApiClient) UploadRequest(url string, paramMap map[string]interfa
 	//req.Header.Set("Content-Type", writer.FormDataContentType())
 	req.Header.Set("Content-Type", writer.FormDataContentType())
 
-	fmt.Println("req", req.Header.String())
+	//fmt.Println("req", req.Header.String())
 
 	// 添加表单字段
 	for key, val := range paramMap {

+ 12 - 1
router.go

@@ -5,6 +5,7 @@ package main
 import (
 	"github.com/cloudwego/hertz/pkg/app/server"
 	handler "pji_desktop_http/biz/handler"
+	"pji_desktop_http/biz/handler/config_service"
 	"pji_desktop_http/biz/handler/map_service"
 	"pji_desktop_http/biz/handler/simulation_service"
 	"pji_desktop_http/biz/handler/user_service"
@@ -19,6 +20,8 @@ func customizedRegister(r *server.Hertz) {
 
 	r.POST("/map/check/mapbuf/consistency", map_service.CheckMapBufConsistency)
 
+	r.GET("/map/check/deviceMap/status", map_service.CheckDeviceMapStatus)
+
 	r.GET("/map/download/oss", map_service.DownloadOSSFile)
 
 	r.GET("/map/download/zip", map_service.DownloadMapZipFile)
@@ -33,7 +36,10 @@ func customizedRegister(r *server.Hertz) {
 	r.POST("/map/query/update/record", map_service.QueryMapUpdateRecord)
 	r.POST("/map/upload/update/map", map_service.TestUploadUpdateMap)
 
-	r.GET("/map/update/deviceMap/record", map_service.UpdateDeviceMapById)
+	r.GET("/map/update/deviceMap/test", map_service.UpdateDeviceMapById)
+	r.GET("/map/update/deviceMap/record", map_service.UpdateDeviceMap)
+
+	r.GET("/map/update/pji/upload", map_service.UploadPjiMapAndNotify)
 
 	r.GET("/world/upload/world", world_service.UploadWorldFile)
 	r.POST("/world/upload/world", world_service.UploadWorldFile)
@@ -61,4 +67,9 @@ func customizedRegister(r *server.Hertz) {
 	r.POST("/simulation/query/test/record", simulation_service.QueryTestRecord)
 
 	r.POST("/simulation/download/oss/key", simulation_service.DownloadFileByKeys)
+
+	r.GET("/config/query/rescanReminderThreshold", config_service.QueryRescanReminderThreshold)
+
+	r.GET("/config/update/rescanReminderThreshold", config_service.UpdateRescanReminderThreshold)
+
 }

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels