feat:完善项目
This commit is contained in:
@ -47,6 +47,8 @@ func initModel() {
|
||||
// 日志管理
|
||||
&synchronized{iModel: model.NewSysLog()}, &synchronized{iModel: model.NewSysUserLoginLog()},
|
||||
&synchronized{iModel: model.NewSysBreakdown()},
|
||||
// 公告管理
|
||||
&synchronized{iModel: model.NewManageNotice()},
|
||||
// 功能信息
|
||||
&synchronized{iModel: model.NewManageSupplier()},
|
||||
&synchronized{iModel: model.NewManageEquipment()}, &synchronized{iModel: model.NewManageEquipmentMaterial()},
|
||||
@ -72,7 +74,7 @@ func initCacheMode() {
|
||||
}
|
||||
}
|
||||
function(
|
||||
&caches{iModel: model.NewSysTenant(), iValues: func() interface{} {
|
||||
&caches{iModel: model.NewSysConfig(), iValues: func() interface{} {
|
||||
out := make([]*model.SysConfig, 0)
|
||||
_ = model.Find(model.NewSysConfig(), &out)
|
||||
return out
|
||||
@ -86,6 +88,8 @@ func initCacheMode() {
|
||||
}
|
||||
|
||||
func Init() {
|
||||
initModel()
|
||||
if *config.Init {
|
||||
initModel()
|
||||
}
|
||||
initCacheMode()
|
||||
}
|
||||
|
@ -60,23 +60,22 @@ type Area struct {
|
||||
}
|
||||
|
||||
type AreaInfo struct {
|
||||
Province string `json:"province"`
|
||||
City string `json:"city"`
|
||||
District string `json:"district"`
|
||||
Address string `json:"address"`
|
||||
ProvinceName string `json:"province_name"`
|
||||
CityName string `json:"city_name"`
|
||||
DistrictName string `json:"district_name"`
|
||||
}
|
||||
|
||||
func (m *Area) Format() *AreaInfo {
|
||||
out := &AreaInfo{Address: m.Address}
|
||||
out := &AreaInfo{}
|
||||
|
||||
if m.Province != "" {
|
||||
out.Province = config.SettingAreaInfo[config.DefaultChinaAreaCode][m.Province]
|
||||
out.ProvinceName = config.SettingAreaInfo[config.DefaultChinaAreaCode][m.Province]
|
||||
}
|
||||
if m.City != "" {
|
||||
out.City = config.SettingAreaInfo[m.Province][m.City]
|
||||
out.CityName = config.SettingAreaInfo[m.Province][m.City]
|
||||
}
|
||||
if m.District != "" {
|
||||
out.District = config.SettingAreaInfo[m.City][m.District]
|
||||
out.DistrictName = config.SettingAreaInfo[m.City][m.District]
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ package model
|
||||
type ManageMaterialSupplier struct {
|
||||
Model
|
||||
MaterialID uint64 `gorm:"column:material_id;type:int(11);default:0;comment:器材ID" json:"material_id"`
|
||||
SupplierID uint64 `gorm:"column:supplier_id;type:int;default:0;comment:供应商ID" json:"-"`
|
||||
SupplierID uint64 `gorm:"column:supplier_id;type:int(11);default:0;comment:供应商ID" json:"-"`
|
||||
Stock float64 `gorm:"column:stock;type:decimal(10,2);default:0;comment:库存数" json:"stock"`
|
||||
FrozenStock float64 `gorm:"column:frozen_stock;type:decimal(10,2);default:0;comment:冻结的库存数" json:"-"`
|
||||
ModelDeleted
|
||||
|
@ -70,6 +70,9 @@ func (m *Model) GetID() uint64 {
|
||||
}
|
||||
|
||||
func (m *Model) GetEncodeID() string {
|
||||
if m.ID <= 0 {
|
||||
return ""
|
||||
}
|
||||
return utils.HASHIDEncode(int(m.ID))
|
||||
}
|
||||
|
||||
@ -338,6 +341,25 @@ func Find(model IModel, out interface{}, where ...*ModelWhereOrder) error {
|
||||
return db.Find(out).Error
|
||||
}
|
||||
|
||||
func FindLimit(model IModel, out interface{}, limit int, where ...*ModelWhereOrder) error {
|
||||
db := orm.GetDB().Table(model.TableName())
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
if wo.Where != nil {
|
||||
db = db.Where(wo.Where.Condition, wo.Where.Value)
|
||||
}
|
||||
if wo.Order != nil {
|
||||
db = db.Order(fmt.Sprintf("%s %s", wo.Order.Field, wo.Order.Mode))
|
||||
}
|
||||
}
|
||||
}
|
||||
if db.Migrator().HasColumn(model, FieldsForDeleted) {
|
||||
db = db.Where(FieldsForDeleted, DeleteStatusForNot)
|
||||
}
|
||||
return db.Offset(0).Limit(limit).Find(out).Error
|
||||
}
|
||||
|
||||
func Scan(model IModel, out interface{}, where ...*ModelWhereOrder) error {
|
||||
db := orm.GetDB().Table(model.TableName())
|
||||
|
||||
@ -376,6 +398,25 @@ func ScanFields(model IModel, out interface{}, fields []string, where ...*ModelW
|
||||
return db.Scan(out).Error
|
||||
}
|
||||
|
||||
func ScanLimitFields(model IModel, out interface{}, fields []string, limit int, where ...*ModelWhereOrder) error {
|
||||
db := orm.GetDB().Table(model.TableName()).Select(fields)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
if wo.Where != nil {
|
||||
db = db.Where(wo.Where.Condition, wo.Where.Value)
|
||||
}
|
||||
if wo.Order != nil {
|
||||
db = db.Order(fmt.Sprintf("%s %s", wo.Order.Field, wo.Order.Mode))
|
||||
}
|
||||
}
|
||||
}
|
||||
if db.Migrator().HasColumn(model, FieldsForDeleted) {
|
||||
db = db.Where(FieldsForDeleted, DeleteStatusForNot)
|
||||
}
|
||||
return db.Offset(0).Limit(limit).Scan(out).Error
|
||||
}
|
||||
|
||||
func Pluck(model IModel, field string, out interface{}, where ...*ModelWhere) error {
|
||||
db := orm.GetDB().Table(model.TableName())
|
||||
|
||||
|
@ -10,6 +10,7 @@ type WorkInstance struct {
|
||||
Model
|
||||
ModelTenant
|
||||
OrderNo string `gorm:"column:order_no;type:varchar(30);default:null;comment:工单单号" json:"order_no"`
|
||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||
Kind WorkInstanceKind `gorm:"column:kind;type:tinyint(1);default:0;comment:工单类型" json:"kind"`
|
||||
Title string `gorm:"column:title;type:varchar(30);default:null;comment:工单标题" json:"title"`
|
||||
EquipmentID uint64 `gorm:"column:equipment_id;type:int(11);default:0;comment:装备ID" json:"equipment_id"`
|
||||
|
Reference in New Issue
Block a user