houyaf 3 lat temu
rodzic
commit
fdbbed6f67

+ 10 - 3
repositories/data_bus_rebo.go

@@ -3,6 +3,8 @@ package repositories
 import (
     "errors"
     "fmt"
+    "math"
+    "strconv"
     "time"
     "xorm.io/xorm"
     "xps/cache"
@@ -23,11 +25,15 @@ func (d *DataBusRepo) GetPage(sqlStatement, sqlCount string, m map[string]interf
     limit := m["limit"].(int)
     page  := m["page"].(int)
     
-    res, err1 := d.engine.Exec(sqlCount)
+    res, err1 := d.engine.Query(sqlCount)
     if err1 != nil {
         return nil, err1
     }
-    fmt.Print(res.LastInsertId())
+    
+    total := int64(0)
+    for _, v := range res[0] {
+        total, _ = strconv.ParseInt(string(v), 10, 64)
+    }
     
     pageStart  := (page - 1) * limit
     sqlLimit   := fmt.Sprintf(" LIMIT %d OFFSET %d ", limit, pageStart)
@@ -39,9 +45,10 @@ func (d *DataBusRepo) GetPage(sqlStatement, sqlCount string, m map[string]interf
     
     pageResult := &viewmodels.PageResult{}
     pageResult.Data     = results
-    pageResult.Total    = 0
+    pageResult.Total    = total
     pageResult.PageSize = limit
     pageResult.Page     = page
+    pageResult.TotalPage= int64(math.Ceil(float64(total / int64(limit))))
     return pageResult, nil
 }
 

+ 3 - 3
service/api_gateway_service.go

@@ -131,15 +131,15 @@ func (a *apiGatewayService) Mapping2ModelObjectAttr(objectCode string, m map[str
     }
     
     bizObjectAttrs := bzObject.Attrs
-    params := make(map[string]interface{}, 0)
     for _, bzAttr := range bizObjectAttrs {
         bzAttrCode    := bzAttr.AttrCode
         bzMappingCode := bzAttr.MappingCode
         if bzAttrValue, ok := m[bzAttrCode]; ok {
-            params[bzMappingCode] = bzAttrValue
+            m[bzMappingCode] = bzAttrValue
+            delete(m, bzAttrCode)
         }
     }
-    return params, nil
+    return m, nil
 }
 
 func (a *apiGatewayService) Mapping2BizObjectAttr(objectCode string, m map[string]interface{})(map[string]interface{}, error) {

+ 89 - 0
utils/type_conv.go

@@ -0,0 +1,89 @@
+package utils
+
+import (
+    "bytes"
+    "encoding/binary"
+    "fmt"
+)
+
+// isSymbol表示有无符号
+func BytesToInt(b []byte, isSymbol bool)  (int, error){
+    if isSymbol {
+        return bytesToIntS(b)
+    }
+    return bytesToIntU(b)
+}
+
+
+//字节数(大端)组转成int(无符号的)
+func bytesToIntU(b []byte) (int, error) {
+    if len(b) == 3 {
+        b = append([]byte{0},b...)
+    }
+    bytesBuffer := bytes.NewBuffer(b)
+    switch len(b) {
+    case 1:
+        var tmp uint8
+        err := binary.Read(bytesBuffer, binary.BigEndian, &tmp)
+        return int(tmp), err
+    case 2:
+        var tmp uint16
+        err := binary.Read(bytesBuffer, binary.BigEndian, &tmp)
+        return int(tmp), err
+    case 4:
+        var tmp uint32
+        err := binary.Read(bytesBuffer, binary.BigEndian, &tmp)
+        return int(tmp), err
+    default:
+        return 0,fmt.Errorf("%s", "BytesToInt bytes lenth is invaild!")
+    }
+}
+
+
+
+//字节数(大端)组转成int(有符号)
+func bytesToIntS(b []byte) (int, error) {
+    if len(b) == 3 {
+        b = append([]byte{0},b...)
+    }
+    bytesBuffer := bytes.NewBuffer(b)
+    switch len(b) {
+    case 1:
+        var tmp int8
+        err := binary.Read(bytesBuffer, binary.BigEndian, &tmp)
+        return int(tmp), err
+    case 2:
+        var tmp int16
+        err := binary.Read(bytesBuffer, binary.BigEndian, &tmp)
+        return int(tmp), err
+    case 4:
+        var tmp int32
+        err := binary.Read(bytesBuffer, binary.BigEndian, &tmp)
+        return int(tmp), err
+    default:
+        return 0,fmt.Errorf("%s", "BytesToInt bytes lenth is invaild!")
+    }
+}
+
+
+//整形转换成字节
+func IntToBytes(n int,b byte) ([]byte,error) {
+    switch b {
+    case 1:
+        tmp := int8(n)
+        bytesBuffer := bytes.NewBuffer([]byte{})
+        binary.Write(bytesBuffer, binary.BigEndian, &tmp)
+        return bytesBuffer.Bytes(),nil
+    case 2:
+        tmp := int16(n)
+        bytesBuffer := bytes.NewBuffer([]byte{})
+        binary.Write(bytesBuffer, binary.BigEndian, &tmp)
+        return bytesBuffer.Bytes(),nil
+    case 3,4:
+        tmp := int32(n)
+        bytesBuffer := bytes.NewBuffer([]byte{})
+        binary.Write(bytesBuffer, binary.BigEndian, &tmp)
+        return bytesBuffer.Bytes(),nil
+    }
+    return nil,fmt.Errorf("IntToBytes b param is invaild")
+}

+ 1 - 1
viewmodels/page_result.go

@@ -4,6 +4,6 @@ type PageResult struct {
 	Total     int64       `json:"total"`
 	PageSize  int         `json:"limit"`
 	Page      int         `json:"page"`
-	TotalPage int         `json:"totalPage"`
+	TotalPage int64       `json:"totalPage"`
 	Data      interface{} `json:"data"`
 }

+ 11 - 11
web/controllers/biz_controller.go

@@ -12,13 +12,13 @@ type BizController struct {
 }
 
 func (c *BizController) BeforeActivation(b mvc.BeforeActivation) {
-    b.Handle("GET",         "/",                    "GetList"    )
-    b.Handle("GET",         "/data",                "GetTreeData")
-    b.Handle("GET",         "/page",                "GetPage"    )
-    b.Handle("GET",         "/{modelId:int64}",     "GetById"    )
-    b.Handle("POST",        "/add",                 "Create"     )
-    b.Handle("PUT",         "/update",              "Update"     )
-    b.Handle("DELETE",      "/{modelId:int64}",     "DeleteByID" )
+    b.Handle("GET",         "/",                    "GetList"     )
+    b.Handle("GET",         "/data",                "GetTreeData" )
+    b.Handle("GET",         "/page",                "GetPage"     )
+    b.Handle("GET",         "/{modelId:int64}",     "GetById"     )
+    b.Handle("POST",        "/add",                 "Create"      )
+    b.Handle("PUT",         "/update",              "Update"      )
+    b.Handle("DELETE",      "/{modelId:int64}",     "DeleteByID"  )
 }
 
 func (c *BizController) GetList() *JsonResult {
@@ -50,7 +50,7 @@ func (c *BizController) GetPage() *JsonResult {
     }
 }
 
-func (c *BizController) GetById(modelId int64) *JsonResult {
+func (c *BizController) GetById(modelId int64)*JsonResult {
     
     data, err := c.Service.GetById(modelId)
     if err != nil {
@@ -60,7 +60,7 @@ func (c *BizController) GetById(modelId int64) *JsonResult {
     }
 }
 
-func (c *BizController) Create() *JsonResult {
+func (c *BizController) Create()*JsonResult {
     userId := c.GetCurUserId()
     
     mod := datamodels.Biz{}
@@ -77,7 +77,7 @@ func (c *BizController) Create() *JsonResult {
     }
 }
 
-func (c *BizController) Update() *JsonResult {
+func (c *BizController) Update()*JsonResult {
     userId := c.GetCurUserId()
     
     mod  := datamodels.Biz{}
@@ -93,7 +93,7 @@ func (c *BizController) Update() *JsonResult {
     }
 }
 
-func (c *BizController) DeleteByID(modelId int64) *JsonResult {
+func (c *BizController) DeleteByID(modelId int64)*JsonResult {
     userId := c.GetCurUserId()
     
     m := make(map[string]interface{})