|
@@ -1,14 +1,15 @@
|
|
|
-package Account
|
|
|
|
|
|
|
+package Menu
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
"errors"
|
|
"errors"
|
|
|
|
|
+ "time"
|
|
|
|
|
+
|
|
|
"github.com/astaxie/beego/cache"
|
|
"github.com/astaxie/beego/cache"
|
|
|
_ "github.com/astaxie/beego/cache/redis"
|
|
_ "github.com/astaxie/beego/cache/redis"
|
|
|
"github.com/beego/beego/v2/adapter/orm"
|
|
"github.com/beego/beego/v2/adapter/orm"
|
|
|
orm2 "github.com/beego/beego/v2/client/orm"
|
|
orm2 "github.com/beego/beego/v2/client/orm"
|
|
|
"gogs.baozhida.cn/zoie/ERP_libs/lib"
|
|
"gogs.baozhida.cn/zoie/ERP_libs/lib"
|
|
|
- "time"
|
|
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
type API struct {
|
|
type API struct {
|
|
@@ -107,3 +108,55 @@ func (m *APIDaoImpl) recursiveMenu(MenuIds []int, AllIds *[]int) error {
|
|
|
}
|
|
}
|
|
|
return m.recursiveMenu(subIds, AllIds)
|
|
return m.recursiveMenu(subIds, AllIds)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+// 获取 ById
|
|
|
|
|
+func (m *APIDaoImpl) Read_API_ById(id int) (r API, err error) {
|
|
|
|
|
+ r.Id = id
|
|
|
|
|
+ err = m.orm.Read(&r)
|
|
|
|
|
+ return r, err
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 获取 ByMenuId - 根据菜单ID获取API列表
|
|
|
|
|
+func (m *APIDaoImpl) Read_API_List_ByMenuId(T_Menu_Id int) (maps []API, err error) {
|
|
|
|
|
+ qs := m.orm.QueryTable(new(API))
|
|
|
|
|
+ _, err = qs.Filter("T_Menu_Id", T_Menu_Id).Filter("T_enable", 1).All(&maps)
|
|
|
|
|
+ return maps, err
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 添加
|
|
|
|
|
+func (m *APIDaoImpl) Add_API(r API) (id int64, err error) {
|
|
|
|
|
+ if r.T_enable == 0 {
|
|
|
|
|
+ r.T_enable = 1
|
|
|
|
|
+ }
|
|
|
|
|
+ if len(r.T_method) == 0 {
|
|
|
|
|
+ r.T_method = "POST"
|
|
|
|
|
+ }
|
|
|
|
|
+ id, err = m.orm.Insert(&r)
|
|
|
|
|
+ return id, err
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 批量添加
|
|
|
|
|
+func (m *APIDaoImpl) InsertMulti_API(r []API) (id int64, err error) {
|
|
|
|
|
+ id, err = orm.NewOrm().InsertMulti(len(r), r)
|
|
|
|
|
+ return
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 修改
|
|
|
|
|
+func (m *APIDaoImpl) Update_API(r API, cols ...string) (int64, error) {
|
|
|
|
|
+ if len(cols) == 0 {
|
|
|
|
|
+ return m.orm.Update(&r, "T_name", "T_uri", "T_method", "T_enable")
|
|
|
|
|
+ }
|
|
|
|
|
+ return m.orm.Update(&r, cols...)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 删除(软删除,设置 T_enable = 0)
|
|
|
|
|
+func (m *APIDaoImpl) Delete_API(r API) (int64, error) {
|
|
|
|
|
+ r.T_enable = 0
|
|
|
|
|
+ return m.orm.Update(&r, "T_enable")
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 根据菜单ID删除所有关联的API(软删除)
|
|
|
|
|
+func (m *APIDaoImpl) Delete_API_ByMenuId(T_Menu_Id int) (int64, error) {
|
|
|
|
|
+ qs := m.orm.QueryTable(new(API))
|
|
|
|
|
+ return qs.Filter("T_Menu_Id", T_Menu_Id).Filter("T_enable", 1).Update(orm2.Params{"T_enable": 0})
|
|
|
|
|
+}
|