houyaf 3 ani în urmă
părinte
comite
c47326d1e7

+ 1 - 0
cache/db_data.go

@@ -0,0 +1 @@
+package cache

+ 1 - 1
conf/db.go

@@ -23,7 +23,7 @@ var SlaveDbConfig DbConf = DbConf{
 	Port:   3306,
 	User:   "root",
 	Pwd:    "houyaf1!",
-	DbName: "xps",
+	DbName: "xps-db",
 }
 
 var IDDbConfig DbConf = DbConf{

+ 18 - 10
repositories/object_repo.go

@@ -22,8 +22,10 @@ func (d *ObjectRepo) GetPage(m map[string]interface{}) (*viewmodels.PageResult,
 	limit := m["limit"].(int)
 	page  := m["page"].(int)
 
-	sqlSelect := ` SELECT A.*                `
-	sqlFrom   := ` FROM   ds_object   AS A   `
+	sqlSelect := ` SELECT A.*,
+                          B.model_title      `
+	sqlFrom   := ` FROM   ds_object   AS A
+                   LEFT JOIN ds_model AS B ON (A.model_id = B.model_id)  `
 	sqlWhere  := ` WHERE A.deleted_flag = 0  `
 	if keywords, ok := m["keywords"]; ok {
 		sqlWhere += ` AND A.object_title like ` + "'%" + fmt.Sprintf("%s", keywords) + "%'"
@@ -55,9 +57,11 @@ func (d *ObjectRepo) GetPage(m map[string]interface{}) (*viewmodels.PageResult,
 
 func (d *ObjectRepo) GetList(m map[string]interface{}) ([]viewmodels.ObjectInfo, error) {
 	modelId   := m["modelId"].(int64)
-
-	sqlSelect := ` SELECT A.*                `
-	sqlFrom   := ` FROM  ds_object   AS A    `
+	
+	sqlSelect := ` SELECT A.*,
+                          B.model_title      `
+	sqlFrom   := ` FROM   ds_object   AS A
+                   LEFT JOIN ds_model AS B ON (A.model_id = B.model_id)  `
 	sqlWhere  := ` WHERE A.deleted_flag = 0 AND A.model_id =` + fmt.Sprintf("%d", modelId)
 	if keywords, ok := m["keywords"]; ok {
 		sqlWhere += ` AND A.object_title like ` + "'%" + fmt.Sprintf("%s", keywords) + "%'"
@@ -74,12 +78,16 @@ func (d *ObjectRepo) GetList(m map[string]interface{}) ([]viewmodels.ObjectInfo,
 }
 
 func (d *ObjectRepo) GetById(modelId, objectId int64) (*viewmodels.ObjectInfo, error) {
+	sqlSelect := ` SELECT A.*,
+                          B.model_title      `
+	sqlFrom   := ` FROM   ds_object   AS A
+                   LEFT JOIN ds_model AS B ON (A.model_id = B.model_id)  `
+	sqlWhere  := ` WHERE A.deleted_flag = 0 AND A.model_id =` + fmt.Sprintf("%d", modelId)
+	sqlWhere  += fmt.Sprintf(" AND A.object_id = %d", objectId)
+	
 	data := &viewmodels.ObjectInfo{}
-	ok, err := d.engine.
-		Where("model_id = ?", modelId).
-		Where("object_id = ?", objectId).
-		Get(data)
-	if !ok && err == nil {
+	has, err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).Get(data)
+	if !has || err != nil {
 		return nil, err
 	} else {
 		return data, nil

+ 1 - 1
service/login_service.go

@@ -119,7 +119,7 @@ func (s *loginService) CheckLogin(code, password string) (bRet bool, msg string,
 		return false, "没有生成Token", nil
 	}
 	
-	expiresIn := time.Now().Add(time.Hour*24).UnixNano() / 1e6
+	expiresIn := time.Now().Add(time.Hour*48).UnixNano()/1e6
 	tokenResult := &viewmodels.AccessToken{}
 	tokenResult.AccessToken = tokenStr
 	tokenResult.User = userData

+ 4 - 11
service/object_service.go

@@ -16,8 +16,8 @@ type ObjectService interface {
 	Update(d *datamodels.Object) error
 	Delete(m map[string]interface{}) error
 	GetObjectDataById(modelId, objectId int64) (*viewmodels.ObjectDataInfo, error)
-	CreateObjectData(d *viewmodels.ObjectDataInfo) error
-	UpdateObjectData(d *viewmodels.ObjectDataInfo) error
+	CreateObjectData(d *viewmodels.ObjectData) error
+	UpdateObjectData(d *viewmodels.ObjectData) error
 }
 
 type objectService struct {
@@ -82,20 +82,13 @@ func (s *objectService) GetObjectDataById(modelId, objectId int64) (*viewmodels.
 		ObjectCode:  objectInfo.ObjectCode,
 		Comment:     objectInfo.Comment,
 		IsFixed:     objectInfo.IsFixed,
-		CreatedBy:   objectInfo.CreatedBy,
-		CreatedAt:   objectInfo.CreatedAt,
-		UpdatedAt:   objectInfo.UpdatedAt,
-		UpdatedBy:   objectInfo.UpdatedBy,
-		DeletedAt:   objectInfo.DeletedAt,
-		DeletedBy:   objectInfo.DeletedBy,
-		DeletedFlag: 0,
 		Attrs:       attrs,
 	}
 
 	return objectDataInfo, nil
 }
 
-func (s *objectService) CreateObjectData(o *viewmodels.ObjectDataInfo) error {
+func (s *objectService) CreateObjectData(o *viewmodels.ObjectData) error {
 	modelId   := o.ModelId
 	objectId  := NewID()
 	createdBy := o.CreatedBy
@@ -144,7 +137,7 @@ func (s *objectService) CreateObjectData(o *viewmodels.ObjectDataInfo) error {
 	return nil
 }
 
-func (s *objectService) UpdateObjectData(o *viewmodels.ObjectDataInfo) error {
+func (s *objectService) UpdateObjectData(o *viewmodels.ObjectData) error {
 	modelId   := o.ModelId
 	objectId  := o.ObjectId
 	updatedBy := o.UpdatedBy

+ 4 - 4
viewmodels/model_info.go

@@ -1,10 +1,10 @@
 package viewmodels
 
 type ModelInfo struct {
-	ModelId    int64  `json:"modelId"         xorm:"'model_id'        bigint     pk comment('主键ID')         "`
-	ModelTitle string `json:"modelTitle"      xorm:"'model_title'     varchar(50)   comment('模型名称')     "`
-	ModelDesc  string `json:"modelDesc"       xorm:"'model_desc'      varchar(50)   comment('描述')            "`
-	IsFixed    int64  `json:"isFixed"         xorm:"'is_fixed'        int           comment('是否可修改')         "`
+	ModelId    int64  `json:"modelId"         xorm:"'model_id'        bigint     pk comment('主键ID')     "`
+	ModelTitle string `json:"modelTitle"      xorm:"'model_title'     varchar(50)   comment('模型名称')    "`
+	ModelDesc  string `json:"modelDesc"       xorm:"'model_desc'      varchar(50)   comment('描述')       "`
+	IsFixed    int64  `json:"isFixed"         xorm:"'is_fixed'        int           comment('是否可修改')  "`
 }
 
 func (t *ModelInfo) TableName() string {

+ 26 - 0
viewmodels/object_data.go

@@ -0,0 +1,26 @@
+package viewmodels
+
+import "time"
+
+type ObjectData struct {
+    ModelId     int64            `json:"modelId"         xorm:"'model_id'        bigint      pk comment('主键ID')      "`
+    ModelTitle  string           `json:"modelTitle"      xorm:"'model_title'     varchar(127)   comment('Model Title') "`
+    ObjectId    int64            `json:"objectId"        xorm:"'object_id'       bigint      pk comment('主键ID')      "`
+    ObjectType  int64            `json:"objectType"      xorm:"'object_type'     bigint         comment('Type')       "`
+    ObjectTitle string           `json:"objectTitle"     xorm:"'object_title'    varchar(127)   comment('模型名称')    "`
+    ObjectCode  string           `json:"objectCode"      xorm:"'object_code'     varchar(127)   comment('模型名称')    "`
+    Comment     string           `json:"comment"         xorm:"'comment'         varchar(255)   comment('描述')       "`
+    IsFixed     int64            `json:"isFixed"         xorm:"'is_fixed'        int            comment('是否可修改')  "`
+    CreatedBy   int64            `json:"createdBy"       xorm:"'created_by'"`
+    CreatedAt   time.Time        `json:"createdAt"       xorm:"'created_at'"`
+    UpdatedBy   int64            `json:"updatedBy"       xorm:"'updated_by'"`
+    UpdatedAt   time.Time        `json:"updatedAt"       xorm:"'updated_at'"`
+    DeletedFlag int64            `json:"deletedFlag"     xorm:"'deleted_flag'"`
+    DeletedBy   int64            `json:"deletedBy"       xorm:"'deleted_by'"`
+    DeletedAt   time.Time        `json:"deletedAt"       xorm:"'deleted_at'"`
+    Attrs       []ObjectAttrInfo `json:"attrs"`
+}
+
+func (t *ObjectData) TableName() string {
+    return "ds_object"
+}

+ 8 - 16
viewmodels/object_data_info.go

@@ -1,22 +1,14 @@
 package viewmodels
 
-import "time"
-
 type ObjectDataInfo struct {
-	ModelId     int64            `json:"modelId"         xorm:"'model_id'        bigint      pk comment('主键ID')         "`
-	ObjectId    int64            `json:"objectId"        xorm:"'object_id'       bigint      pk comment('主键ID')         "`
-	ObjectType  int64            `json:"objectType"      xorm:"'object_type'     bigint         comment('Type')           "`
-	ObjectTitle string           `json:"objectTitle"     xorm:"'object_title'    varchar(127)   comment('模型名称')        "`
-	ObjectCode  string           `json:"objectCode"      xorm:"'object_code'     varchar(127)   comment('模型名称')        "`
-	Comment     string           `json:"comment"         xorm:"'comment'         varchar(255)   comment('描述')            "`
-	IsFixed     int64            `json:"isFixed"         xorm:"'is_fixed'        int            comment('是否可修改')       "`
-	CreatedBy   int64            `json:"createdBy"       xorm:"'created_by'"`
-	CreatedAt   time.Time        `json:"createdAt"       xorm:"'created_at'"`
-	UpdatedBy   int64            `json:"updatedBy"       xorm:"'updated_by'"`
-	UpdatedAt   time.Time        `json:"updatedAt"       xorm:"'updated_at'"`
-	DeletedFlag int64            `json:"deletedFlag"     xorm:"'deleted_flag'"`
-	DeletedBy   int64            `json:"deletedBy"       xorm:"'deleted_by'"`
-	DeletedAt   time.Time        `json:"deletedAt"       xorm:"'deleted_at'"`
+	ModelId     int64            `json:"modelId"         xorm:"'model_id'        bigint      pk comment('主键ID')     "`
+	ModelTitle  string           `json:"modelTitle"      xorm:"'model_title'     varchar(127)   comment('Model Title')"`
+	ObjectId    int64            `json:"objectId"        xorm:"'object_id'       bigint      pk comment('主键ID')     "`
+	ObjectType  int64            `json:"objectType"      xorm:"'object_type'     bigint         comment('Type')       "`
+	ObjectTitle string           `json:"objectTitle"     xorm:"'object_title'    varchar(127)   comment('模型名称')    "`
+	ObjectCode  string           `json:"objectCode"      xorm:"'object_code'     varchar(127)   comment('模型名称')    "`
+	Comment     string           `json:"comment"         xorm:"'comment'         varchar(255)   comment('描述')       "`
+	IsFixed     int64            `json:"isFixed"         xorm:"'is_fixed'        int            comment('是否可修改')  "`
 	Attrs       []ObjectAttrInfo `json:"attrs"`
 }
 

+ 8 - 16
viewmodels/object_info.go

@@ -1,22 +1,14 @@
 package viewmodels
 
-import "time"
-
 type ObjectInfo struct {
-	ModelId     int64     `json:"modelId"         xorm:"'model_id'        bigint      pk comment('主键ID')         "`
-	ObjectId    int64     `json:"objectId"        xorm:"'object_id'       bigint      pk comment('主键ID')         "`
-	ObjectType  int64     `json:"objectType"      xorm:"'object_type'     bigint         comment('Type')           "`
-	ObjectTitle string    `json:"objectTitle"     xorm:"'object_title'    varchar(127)   comment('模型名称')        "`
-	ObjectCode  string    `json:"objectCode"      xorm:"'object_code'     varchar(127)   comment('模型名称')        "`
-	Comment     string    `json:"comment"         xorm:"'comment'         varchar(255)   comment('描述')            "`
-	IsFixed     int64     `json:"isFixed"         xorm:"'is_fixed'        int            comment('是否可修改')       "`
-	CreatedBy   int64     `json:"createdBy"       xorm:"'created_by'"`
-	CreatedAt   time.Time `json:"createdAt"       xorm:"'created_at'"`
-	UpdatedBy   int64     `json:"updatedBy"       xorm:"'updated_by'"`
-	UpdatedAt   time.Time `json:"updatedAt"       xorm:"'updated_at'"`
-	DeletedFlag int64     `json:"deletedFlag"     xorm:"'deleted_flag'"`
-	DeletedBy   int64     `json:"deletedBy"       xorm:"'deleted_by'"`
-	DeletedAt   time.Time `json:"deletedAt"       xorm:"'deleted_at'"`
+	ModelId     int64     `json:"modelId"         xorm:"'model_id'        bigint      pk comment('Model ID')         "`
+	ModelTitle  string    `json:"modelTitle"      xorm:"'model_title'     varchar(127)   comment('Model Title')      "`
+	ObjectId    int64     `json:"objectId"        xorm:"'object_id'       bigint      pk comment('Object ID')        "`
+	ObjectType  int64     `json:"objectType"      xorm:"'object_type'     bigint         comment('Object Type')      "`
+	ObjectTitle string    `json:"objectTitle"     xorm:"'object_title'    varchar(127)   comment('Object Title')     "`
+	ObjectCode  string    `json:"objectCode"      xorm:"'object_code'     varchar(127)   comment('Object Code')      "`
+	Comment     string    `json:"comment"         xorm:"'comment'         varchar(255)   comment('Comment')          "`
+	IsFixed     int64     `json:"isFixed"         xorm:"'is_fixed'        int            comment('Is Fixed?')        "`
 }
 
 func (t *ObjectInfo) TableName() string {

+ 2 - 2
web/controllers/object_controller.go

@@ -63,7 +63,7 @@ func (c *ObjectController) GetById(modelId, objectId int64) *JsonResult {
 func (c *ObjectController) Create() *JsonResult {
 	userId     := c.GetCurUserId()
 	
-	objectData := viewmodels.ObjectDataInfo{}
+	objectData := viewmodels.ObjectData{}
 	if err := c.Ctx.ReadJSON(&objectData); err != nil {
 		return ResultErr("读取数据失败", nil)
 	}
@@ -79,7 +79,7 @@ func (c *ObjectController) Create() *JsonResult {
 func (c *ObjectController) Update() *JsonResult {
 	userId     := c.GetCurUserId()
 	
-	objectData := viewmodels.ObjectDataInfo{}
+	objectData := viewmodels.ObjectData{}
 	if err := c.Ctx.ReadJSON(&objectData); err != nil {
 		return ResultErr("读取数据失败", nil)
 	}