From e9493844b02626537d0e8a7dd29160212216292c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=B5=B7?= <10402852@qq.com> Date: Mon, 4 Jan 2021 17:14:09 +0800 Subject: [PATCH] commit --- .../BaseMenu/BaseMenuDao/BaseMenuDao.go | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/dsBaseRpc/RpcService/BaseMenu/BaseMenuDao/BaseMenuDao.go b/dsBaseRpc/RpcService/BaseMenu/BaseMenuDao/BaseMenuDao.go index 5e8016f2..139407b6 100644 --- a/dsBaseRpc/RpcService/BaseMenu/BaseMenuDao/BaseMenuDao.go +++ b/dsBaseRpc/RpcService/BaseMenu/BaseMenuDao/BaseMenuDao.go @@ -52,12 +52,45 @@ func UpdateBaseMenu(model models.TBaseMenu, ForceUpdateFields []string) (int64, //分页查询 func PageBaseMenu(in *BaseMenuProto.QueryArg) ([]map[string]interface{}, int32, error) { + //判断这个in.AppId是不是已经在t_base_menu中存在根,如果没有,需要先创建 + sql := `select count(1) from t_base_menu where b_use=1 and app_id=? and identity_id=? and parent_id='00000000-0000-0000-0000-000000000000'` + list, err := db.SQL(sql, in.AppId, in.IdentityId).Query().List() + if err != nil { + return nil, 0, err + } + c := list[0]["c"].(int64) + if c == 0 { + sql = `select * from t_app_base where app_id=? and b_use=1` + list2, err := db.SQL(sql, in.AppId).Query().List() + if err != nil { + return nil, 0, err + } + var appName string + if len(list2) == 0 { + return nil, 0, errors.New("没有找到合法的app_id") + } else { + appName = list2[0]["app_name"].(string) + } + //创建 + var model = new(models.TBaseMenu) + model.MenuId = CommonUtil.GetUUID() + model.AppId = in.AppId + model.ParentId = "00000000-0000-0000-0000-000000000000" + model.IdentityId = in.IdentityId + model.MenuName = appName + model.MenuCode = "" + model.MenuUrl = "#" + model.MenuIcon = "" + model.SortId = 1 + model.BUse = 1 + } + //接收传入参数 var myBuilder = builder.Dialect(builder.MYSQL).Select("t1.*").From("t_base_menu as t1") myBuilder.And(builder.Eq{"t1.app_id": in.AppId}) myBuilder.And(builder.Eq{"t1.identity_id": in.IdentityId}) //获取拼接完成的SQL语句 - sql, err := myBuilder.OrderBy("t1.sort_id").ToBoundSQL() + sql, err = myBuilder.OrderBy("t1.sort_id").ToBoundSQL() if err != nil { return nil, 0, err }