zoie 1 vuosi sitten
vanhempi
commit
782d5f86d0
7 muutettua tiedostoa jossa 83 lisäystä ja 99 poistoa
  1. 31 1
      Menu/API.go
  2. 3 0
      Menu/Menu.go
  3. 6 0
      Power/Power.go
  4. 12 9
      User/User.go
  5. 1 88
      lib/Qiniu.go
  6. 25 1
      lib/libString.go
  7. 5 0
      lib/orm.go

+ 31 - 1
Menu/API.go

@@ -7,6 +7,7 @@ import (
 	"github.com/astaxie/beego/cache"
 	_ "github.com/astaxie/beego/cache/redis"
 	"github.com/beego/beego/v2/adapter/orm"
+	orm2 "github.com/beego/beego/v2/client/orm"
 	"time"
 )
 
@@ -69,7 +70,11 @@ func (m *APIDaoImpl) Read_API_List_ByPower(T_power_id string, Menu_Bind string)
 
 	qs := m.orm.QueryTable(new(API))
 
-	list := lib.SplitStringIds(Menu_Bind, "M")
+	list := lib.SplitStringToIntIds(Menu_Bind, "M")
+	AllIds := list
+	if err = m.recursiveMenu(list, &AllIds); err != nil {
+		return
+	}
 	_, err = qs.Filter("T_Menu_Id__in", list).All(&maps)
 	if err != nil {
 		return
@@ -77,3 +82,28 @@ func (m *APIDaoImpl) Read_API_List_ByPower(T_power_id string, Menu_Bind string)
 	m.Redis_API_Set(T_power_id, maps)
 	return maps, nil
 }
+
+// 获取MenuIds下父id
+func (m *APIDaoImpl) recursiveMenu(MenuIds []int, AllIds *[]int) error {
+	if len(MenuIds) == 0 {
+		return nil
+	}
+	var subMenus []Menu
+	qs := m.orm.QueryTable(new(Menu))
+	cond := orm.NewCondition()
+	cond = cond.And("Id__in", MenuIds)
+
+	_, err := qs.SetCond((*orm2.Condition)(cond)).OrderBy("T_sort", "Id").All(&subMenus)
+	if err != nil {
+		return err
+	}
+
+	subIds := make([]int, 0)
+	for _, menu := range subMenus {
+		if menu.T_mid != 0 {
+			subIds = append(subIds, menu.T_mid)
+			*AllIds = append(*AllIds, menu.T_mid)
+		}
+	}
+	return m.recursiveMenu(subIds, AllIds)
+}

+ 3 - 0
Menu/Menu.go

@@ -50,6 +50,9 @@ func (m MenuDaoImpl) Read_Menu_List() ([]Menu, error) {
 
 // 获取权限绑定菜单列表
 func (m *MenuDaoImpl) Read_Menu_List_ByPower_T_Menu(T_menu string) (maps []Menu, err error) {
+	if len(T_menu) == 0 {
+		return 
+	}
 
 	// 也可以直接使用 Model 结构体作为表名
 	qs := m.orm.QueryTable(new(Menu))

+ 6 - 0
Power/Power.go

@@ -55,6 +55,12 @@ func (m *PowerDaoImpl) Add_Power(r Power) (id int64, err error) {
 	return id, err
 }
 
+// 添加
+func (m *PowerDaoImpl) InsertMulti_Power(r []Power) (id int64, err error) {
+	id, err = orm.NewOrm().InsertMulti(len(r), r)
+	return
+}
+
 // 修改
 func (m *PowerDaoImpl) Update_Power(r Power) (int64, error) {
 	return m.orm.Update(&r, "T_name", "T_menu")

+ 12 - 9
User/User.go

@@ -1,13 +1,16 @@
 package User
 
 type User struct {
-	Id      int
-	T_uuid  string //
-	T_power string // 权限ID
-	T_name  string //
-	T_user  string //
-	T_pass  string //
-	T_dept  string //
-	T_post  string //
-	T_State int    //  0删除  1 正常
+	Id          int
+	T_uuid      string //
+	T_power     string // 权限ID
+	T_name      string //
+	T_user      string //
+	T_pass      string //
+	T_dept      int    // 部门
+	T_dept_name string // 部门
+	T_post      int    // 岗位
+	T_post_name string // 岗位
+	T_State     int    //  0删除  1 正常
+	T_cold_uuid string // 关联冷链uuid
 }

+ 1 - 88
lib/Qiniu.go

@@ -1,90 +1,3 @@
 package lib
 
-//
-//// 存储相关功能的引入包只有这两个,后面不再赘述
-//import (
-//	"context"
-//	"github.com/qiniu/go-sdk/v7/auth/qbox"
-//	"github.com/qiniu/go-sdk/v7/storage"
-//	uuid "github.com/satori/go.uuid"
-//	"strconv"
-//	"time"
-//)
-//
-//var Qiniu *qbox.Mac
-//
-//// var (
-////
-////	//BUCKET是你在存储空间的名称
-////	accessKey = "-8ezB_d-8-eUFTMvhOGbGzgeQRPeKQnaQ3DBcUxo"
-////	secretKey = "KFhkYxTAJ2ZPN3ZS3euTsfWk8-C92rKgkhAMkDRN"
-////	BUCKET    = "bzdcoldoss"
-////
-//// )
-//func init() {
-//	Qiniu = qbox.NewMac(conf.Qiniu_AccessKey, conf.Qiniu_SecretKey)
-//}
-//
-//// if !lib.Pload_qiniu("ofile/"+timeStr+".xlsx","ofile/"+timeStr+".xlsx"){
-//// c.Data["json"] = lib.JSONS{Code: 203, Msg: "oss!"}
-//// c.ServeJSON()
-//// return
-//// }
-//func Pload_qiniu(localFile string, name string) bool {
-//	//localFile := "C:\\Users\\Administrator\\Downloads\\kodo-browser-Windows-x64-v1.0.15.zip"
-//	//key := "kodo-browser-Windows-x64-v1.0.15.zip"
-//	// 自定义返回值结构体
-//	type MyPutRet struct {
-//		Key    string
-//		Hash   string
-//		Fsize  int
-//		Bucket string
-//		Name   string
-//	}
-//
-//	//key := "your file save key"
-//	// 使用 returnBody 自定义回复格式
-//	putPolicy := storage.PutPolicy{
-//		Scope:      conf.Qiniu_BUCKET,
-//		ReturnBody: `{"key":"$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)","name":"$(x:name)"}`,
-//	}
-//
-//	upToken := putPolicy.UploadToken(Qiniu)
-//	cfg := storage.Config{}
-//	formUploader := storage.NewFormUploader(&cfg)
-//	ret := MyPutRet{}
-//	putExtra := storage.PutExtra{
-//		Params: map[string]string{
-//			"x:name": "github logo",
-//		},
-//	}
-//	err := formUploader.PutFile(context.Background(), &ret, upToken, name, localFile, &putExtra)
-//	if err != nil {
-//		logs.Error("Pload_qiniu", err)
-//		return false
-//	}
-//	logs.Println("七牛云", ret.Bucket, ret.Key, ret.Fsize, ret.Hash, ret.Name)
-//	return true
-//}
-//
-//func UploadToken(T_suffix string) string {
-//	Tokey := strconv.FormatInt(time.Now().Unix(), 10) + uuid.NewV4().String()
-//	if len(T_suffix) == 0 {
-//		T_suffix = ".png"
-//	}
-//	putPolicy := storage.PutPolicy{
-//		Scope:      conf.Qiniu_BUCKET,
-//		InsertOnly: 1,    // 仅能以新增模式上传文件。
-//		Expires:    7200, //示例2小时有效期
-//		ReturnBody: `{"key":"` + conf.OssQiniu + `/$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)"}`,
-//		//{"key":"github-x.png","hash":"FqKXVdTvIx_mPjOYdjDyUSy_H1jr","fsize":6091,"bucket":"if-pbl","name":"github logo"}
-//		//{"key":"` + conf.Oss + `/$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)","name":"$(x:name)"}
-//		ForceSaveKey: true,
-//		SaveKey:      "UpImage/" + Tokey + "." + T_suffix,
-//		//FsizeLimit:   1024 * 1024 * 1,
-//		MimeLimit: "image/*;application/pdf;application/octet-stream",
-//	}
-//
-//	upToken := putPolicy.UploadToken(Qiniu)
-//	return upToken
-//}
+

+ 25 - 1
lib/libString.go

@@ -40,9 +40,24 @@ func Md5(str string) string {
 
 // 转化
 func TimeStrToTime(T_time string) (time.Time, bool) {
+	stamp, err := time.ParseInLocation("2006-01-02 15:04:05", T_time, time.Local) // +8
+	if err != nil {
+		return time.Time{}, false
+	}
 
-	stamp, err := time.Parse("2006-01-02 15:04:05", T_time)
+	return stamp, true
+}
+func DateStrToTime(T_date string) (time.Time, bool) {
+	stamp, err := time.ParseInLocation("2006-01-02", T_date, time.Local) // +8
+	if err != nil {
+		return time.Time{}, false
+	}
 
+	return stamp, true
+}
+
+func MonthStrToTime(T_month string) (time.Time, bool) {
+	stamp, err := time.ParseInLocation("2006-01", T_month, time.Local) // +8
 	if err != nil {
 		return time.Time{}, false
 	}
@@ -98,3 +113,12 @@ func IntIdsDistinct(Ids []int) (result []int) {
 	}
 	return result
 }
+
+func SplitString(str string, cutset string) (r []string) {
+	if len(str) == 0 {
+		return r
+	}
+	list := strings.Split(strings.TrimRight(str, cutset), cutset)
+
+	return list
+}

+ 5 - 0
lib/orm.go

@@ -0,0 +1,5 @@
+package lib
+
+var (
+	ErrNoRows = "<QuerySeter> no row found"
+)