Explorar o código

添加组织接口

huangyh %!s(int64=6) %!d(string=hai) anos
pai
achega
2e5685ca44
Modificáronse 3 ficheiros con 354 adicións e 54 borrados
  1. 208 9
      controllers/SystemController.go
  2. 105 45
      controllers/SystemController_gen.go
  3. 41 0
      routers/router_gen.go

+ 208 - 9
controllers/SystemController.go

@@ -413,8 +413,9 @@ func System_UpdateUser(c *SystemController) {
 
 	//2、修改角色
 	userRoles := []models.SysUserRole{}
+	roles := []string{}
 	if userInfo.UserRole != "" {
-		err = json.Unmarshal([]byte(userInfo.UserRole), &userRoles)
+		err = json.Unmarshal([]byte(userInfo.UserRole), &roles)
 		if err != nil {
 			session.Rollback()
 			c.Ctx.JSON(200, sysmodel.SysReturn{500, err.Error(), nil})
@@ -422,13 +423,17 @@ func System_UpdateUser(c *SystemController) {
 		}
 	}
 
-	for i, _ := range userRoles {
-		userRoles[i].Id = utils.NewUUID()
-		userRoles[i].CreateBy = user_id
-		userRoles[i].LastUpdateBy = user_id
-		userRoles[i].CreateTime = time.Now()
-		userRoles[i].LastUpdateDate = time.Now()
-		userRoles[i].DelFlag = 0
+	for _, role := range roles {
+		userRole := models.SysUserRole{}
+		userRole.Id = utils.NewUUID()
+		userRole.RoleId = role
+		userRole.UserId = userInfo.Id
+		userRole.CreateBy = user_id
+		userRole.LastUpdateBy = user_id
+		userRole.CreateTime = time.Now()
+		userRole.LastUpdateDate = time.Now()
+		userRole.DelFlag = 0
+		userRoles = append(userRoles,userRole)
 	}
 	_, err = c.Db.Insert(userRoles)
 	if err != nil {
@@ -556,7 +561,7 @@ func System_FindRolePage(c *SystemController) {
 	var getpageinfo models.GetPageInfo
 	c.Ctx.BindJSON(&getpageinfo)
 
-	page := sysmodel.SysRolePageInfo{}
+	page := sysmodel.PageResult{}
 	var roles []sysmodel.SysRole
 	err := c.Db.SQL(sysmodel.Selectall_sys_role).Limit(getpageinfo.PageSize, (getpageinfo.PageNum-1)*getpageinfo.PageSize).Find(&roles)
 	if err != nil {
@@ -800,6 +805,200 @@ func System_UpdateMenu(c *SystemController) {
 	}
 }
 
+// _AddOrg
+// @Title _AddOrg
+// @Description 添加组织
+// @Param	    string  false  "组织"
+// @Success 200 {object} models.Account
+// @Failure 403 :id is empty
+func System_AddOrg(c *SystemController) {
+	var sysorg models.SysOrg
+	c.Ctx.BindJSON(&sysorg)
+
+	user_id := c.Ctx.GetString("user_id")
+
+	sysorg.Id = utils.NewUUID()
+	sysorg.CreateBy = user_id
+	sysorg.LastUpdateBy = user_id
+	sysorg.LastUpdateDate = time.Now()
+	sysorg.CreateTime = time.Now()
+	sysorg.DelFlag = 0
+
+	_, err := c.Db.Insert(&sysorg)
+	if err != nil {
+		c.Ctx.JSON(500, sysmodel.SysReturn{500, err.Error(), nil})
+		return
+	}
+
+	ret := __none_func_system__(sysorg)
+	if ret {
+		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", nil})
+	} else {
+		c.Ctx.JSON(500, sysmodel.SysReturn{500, "", nil})
+	}
+}
+
+// _DelOrg
+// @Title _DelOrg
+// @Description 删除组织
+// @Param	id    string  false  "组织ID"
+// @Success 200 {object} models.Account
+// @Failure 403 :id is empty
+func System_DelOrg(c *SystemController) {
+	type Param struct {
+		Id string `json:"id"`
+	}
+
+	var params []Param
+	c.Ctx.BindJSON(&params)
+	fmt.Println(params, "-----------")
+	ids := []string{}
+	for _, param := range params {
+		ids = append(ids, param.Id)
+	}
+
+	_, err := c.Db.Table(new(models.SysOrg)).In("id", ids).Update(map[string]interface{}{"del_flag": 0})
+	if err != nil {
+		c.Ctx.JSON(200, sysmodel.SysReturn{500, err.Error(), nil})
+		return
+	}
+
+	ret := __none_func_system__()
+	if ret {
+		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", nil})
+	} else {
+		c.Ctx.JSON(200, sysmodel.SysReturn{500, "", nil})
+	}
+}
+
+// _UpdateOrg
+// @Title _UpdateOrg
+// @Description 更新组织
+// @Param	    string  false  "组织"
+// @Success 200 {object} models.Account
+// @Failure 403 :id is empty
+func System_UpdateOrg(c *SystemController) {
+	var sysorg models.SysOrg
+	c.Ctx.BindJSON(&sysorg)
+
+	user_id := c.Ctx.GetString("user_id")
+
+	sysorg.LastUpdateBy = user_id
+	sysorg.LastUpdateDate = time.Now()
+
+	_, err := c.Db.ID(sysorg.Id).Update(&sysorg)
+
+	if err != nil {
+		c.Ctx.JSON(200, sysmodel.SysReturn{500, err.Error(), nil})
+		return
+	}
+
+	ret := __none_func_system__(sysorg)
+	if ret {
+		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", nil})
+	} else {
+		c.Ctx.JSON(200, sysmodel.SysReturn{500, "", nil})
+	}
+}
+
+// _GetOrg
+// @Title _GetOrg
+// @Description 根据ID获取组织
+// @Param	    string  false  "组织ID"
+// @Success 200 {object} models.Account
+// @Failure 403 :id is empty
+func System_GetOrg(c *SystemController) {
+	var param struct {
+		Id string `json:"id"`
+	}
+
+	c.Ctx.BindJSON(&param)
+	fmt.Println(param, "-----------")
+
+	org := models.SysOrg{}
+	err := c.Db.Table(new(sysmodel.SysOrg)).ID(param.Id).Find(&org)
+	if err != nil {
+		c.Ctx.JSON(200, sysmodel.SysReturn{500, err.Error(), nil})
+		return
+	}
+
+	ret := __none_func_system__()
+	if ret {
+		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", org})
+	} else {
+		c.Ctx.JSON(200, sysmodel.SysReturn{500, "", nil})
+	}
+}
+
+// _PageOrg
+// @Title _PageOrg
+// @Description 分页获取组织
+// @Param	    string  false  "组织"
+// @Success 200 {object} models.Account
+// @Failure 403 :id is empty
+func System_PageOrg(c *SystemController) {
+	var getpageinfo models.GetPageInfo
+	c.Ctx.BindJSON(&getpageinfo)
+
+	ret := __none_func_system__(getpageinfo)
+
+	page := sysmodel.PageResult{}
+	var orgs []sysmodel.SysOrg
+	dbSession := c.Db.Table("sys_org")
+	dbSession = dbSession.Select("sys_org.*")
+
+	countSession := c.Db.Table("sys_org")
+
+	JoinTables := []sysmodel.Join{}
+	//JoinTables = append(JoinTables, sysmodel.Join{TabelName: "subject", Condition: "lesson.subject_id = subject.id", JoinOperator: "left"})
+
+	for _, join := range JoinTables {
+		dbSession = dbSession.Join(join.JoinOperator, join.TabelName, join.Condition)
+		countSession = countSession.Join(join.JoinOperator, join.TabelName, join.Condition)
+	}
+
+	whereStr, datas, err := getpageinfo.Filter.Parse("")
+
+	if err != nil {
+		c.Ctx.JSON(200, sysmodel.SysReturn{500, err.Error(), nil})
+		return
+	}
+
+	dbSession = dbSession.Where(whereStr, datas...)
+	countSession = countSession.Where(whereStr, datas...)
+
+	sidx := strings.Split(getpageinfo.Sidx, ",")
+	for _, order := range sidx {
+		order = strings.TrimSpace(order)
+		if len(order) == 0 {
+			continue
+		}
+
+		if strings.ToLower(getpageinfo.Sord) == "desc" {
+			dbSession = dbSession.OrderBy(order + " desc")
+		} else {
+			dbSession = dbSession.OrderBy(order + " asc")
+		}
+
+	}
+
+	totalPage, _ := countSession.Count()
+	err = dbSession.Limit(getpageinfo.PageSize, (getpageinfo.PageNum-1)*getpageinfo.PageSize).Find(&orgs)
+	if err != nil {
+		c.Ctx.JSON(200, sysmodel.SysReturn{500, err.Error(), nil})
+	}
+	page.Content = orgs
+	page.PageSize = getpageinfo.PageSize
+	page.PageNum = getpageinfo.PageNum
+	page.TotalSize = int(totalPage)
+
+	if ret {
+		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", page})
+	} else {
+		c.Ctx.JSON(200, sysmodel.SysReturn{500, "", nil})
+	}
+}
+
 func __none_func_system__(params ...interface{}) bool {
 	return true
 }

+ 105 - 45
controllers/SystemController_gen.go

@@ -23,8 +23,8 @@ func NewSystemController(c *gin.Context, e *engine.ApiEngine) *SystemController
 
 // Login
 // @Title Login
-// @Description 用户登录         
-// @Param	logininfo      false  "登录信息"  
+// @Description 用户登录
+// @Param	logininfo      false  "登录信息"
 // @Success 200 {object} models.Account
 // @Failure 403 :id is empty
 // @router /login  [post,get,put]
@@ -35,7 +35,7 @@ func (c *SystemController) Login() {
 
 // Logout
 // @Title Logout
-// @Description 用户退出         
+// @Description 用户退出
 // @Success 200 {object} models.Account
 // @Failure 403 :id is empty
 // @router /logout  [post,get]
@@ -46,8 +46,8 @@ func (c *SystemController) Logout() {
 
 // GetNavTree
 // @Title GetNavTree
-// @Description 获取导航菜单         
-// @Param	user    string  false  "用户id"  
+// @Description 获取导航菜单
+// @Param	user    string  false  "用户id"
 // @Success 200 {object} models.Account
 // @Failure 403 :id is empty
 // @router /get_nav_tree  [post,get]
@@ -58,8 +58,8 @@ func (c *SystemController) GetNavTree() {
 
 // GetMenuTree
 // @Title GetMenuTree
-// @Description 获取系统菜单         
-// @Param	user    string  false  "用户id"  
+// @Description 获取系统菜单
+// @Param	user    string  false  "用户id"
 // @Success 200 {object} models.Account
 // @Failure 403 :id is empty
 // @router /get_menu_tree  [post,get]
@@ -70,8 +70,8 @@ func (c *SystemController) GetMenuTree() {
 
 // FindUserPage
 // @Title FindUserPage
-// @Description 获取用户分布数据         
-// @Param	page      false  "分页参数"  
+// @Description 获取用户分布数据
+// @Param	page      false  "分页参数"
 // @Success 200 {object} models.Account
 // @Failure 403 :id is empty
 // @router /find_user_page  [post,get]
@@ -82,7 +82,7 @@ func (c *SystemController) FindUserPage() {
 
 // GetOrgTree
 // @Title GetOrgTree
-// @Description 获取组织架构树         
+// @Description 获取组织架构树
 // @Success 200 {object} models.Account
 // @Failure 403 :id is empty
 // @router /get_org_tree  [post,get]
@@ -93,11 +93,11 @@ func (c *SystemController) GetOrgTree() {
 
 // AddUser
 // @Title AddUser
-// @Description 添加用户         
-// @Param	login_id    string  false  "登录ID"  
-// @Param	password    string  false  "密码"  
-// @Param	org_id    string  false  "组织ID"  
-// @Param	email    string  false  "邮箱"  
+// @Description 添加用户
+// @Param	login_id    string  false  "登录ID"
+// @Param	password    string  false  "密码"
+// @Param	org_id    string  false  "组织ID"
+// @Param	email    string  false  "邮箱"
 // @Success 200 {object} models.Account
 // @Failure 403 :id is empty
 // @router /add_user  [post,get,put]
@@ -108,8 +108,8 @@ func (c *SystemController) AddUser() {
 
 // DelUser
 // @Title DelUser
-// @Description 删除用户         
-// @Param	id    string  false  "用户ID"  
+// @Description 删除用户
+// @Param	id    string  false  "用户ID"
 // @Success 200 {object} models.Account
 // @Failure 403 :id is empty
 // @router /del_user  [post,get,put]
@@ -120,11 +120,11 @@ func (c *SystemController) DelUser() {
 
 // UpdateUser
 // @Title UpdateUser
-// @Description 修改用户         
-// @Param	login_id    string  false  "登录ID"  
-// @Param	password    string  false  "密码"  
-// @Param	org_id    string  false  "组织ID"  
-// @Param	email    string  false  "邮箱"  
+// @Description 修改用户
+// @Param	login_id    string  false  "登录ID"
+// @Param	password    string  false  "密码"
+// @Param	org_id    string  false  "组织ID"
+// @Param	email    string  false  "邮箱"
 // @Success 200 {object} models.Account
 // @Failure 403 :id is empty
 // @router /update_user  [post,get,put]
@@ -135,9 +135,9 @@ func (c *SystemController) UpdateUser() {
 
 // AddRole
 // @Title AddRole
-// @Description 添加角色         
-// @Param	name    string  false  "角色名称"  
-// @Param	remark    string  false  "备注"  
+// @Description 添加角色
+// @Param	name    string  false  "角色名称"
+// @Param	remark    string  false  "备注"
 // @Success 200 {object} models.Account
 // @Failure 403 :id is empty
 // @router /add_role  [post,get,put]
@@ -148,8 +148,8 @@ func (c *SystemController) AddRole() {
 
 // DelRole
 // @Title DelRole
-// @Description 添加角色         
-// @Param	id    string  false  "角色ID"  
+// @Description 添加角色
+// @Param	id    string  false  "角色ID"
 // @Success 200 {object} models.Account
 // @Failure 403 :id is empty
 // @router /del_role  [post,get,put]
@@ -160,10 +160,10 @@ func (c *SystemController) DelRole() {
 
 // UpdateRole
 // @Title UpdateRole
-// @Description 修改角色         
-// @Param	id    string  false  "角色ID"  
-// @Param	name    string  false  "角色名称"  
-// @Param	remark    string  false  "备注"  
+// @Description 修改角色
+// @Param	id    string  false  "角色ID"
+// @Param	name    string  false  "角色名称"
+// @Param	remark    string  false  "备注"
 // @Success 200 {object} models.Account
 // @Failure 403 :id is empty
 // @router /update_role  [post,get,put]
@@ -174,8 +174,8 @@ func (c *SystemController) UpdateRole() {
 
 // FindRolePage
 // @Title FindRolePage
-// @Description 角色分页         
-// @Param	page      false  "分页参数"  
+// @Description 角色分页
+// @Param	page      false  "分页参数"
 // @Success 200 {object} models.Account
 // @Failure 403 :id is empty
 // @router /find_role_page  [post,get,put]
@@ -186,8 +186,8 @@ func (c *SystemController) FindRolePage() {
 
 // FindRoleMenu
 // @Title FindRoleMenu
-// @Description 查找角色权限         
-// @Param	role_id    string  false  "角色id"  
+// @Description 查找角色权限
+// @Param	role_id    string  false  "角色id"
 // @Success 200 {object} models.Account
 // @Failure 403 :id is empty
 // @router /find_role_menu  [post,get,put]
@@ -198,8 +198,8 @@ func (c *SystemController) FindRoleMenu() {
 
 // SaveRoleMenu
 // @Title SaveRoleMenu
-// @Description 保存角色权限         
-// @Param	role_menu    string  false  "角色权限"  
+// @Description 保存角色权限
+// @Param	role_menu    string  false  "角色权限"
 // @Success 200 {object} models.Account
 // @Failure 403 :id is empty
 // @router /save_role_menu  [post,get,put]
@@ -210,7 +210,7 @@ func (c *SystemController) SaveRoleMenu() {
 
 // RoleAll
 // @Title RoleAll
-// @Description 查找所有角色         
+// @Description 查找所有角色
 // @Success 200 {object} models.Account
 // @Failure 403 :id is empty
 // @router /role_all  [post,get,put]
@@ -221,7 +221,7 @@ func (c *SystemController) RoleAll() {
 
 // FindPermissions
 // @Title FindPermissions
-// @Description 查找用户权限         
+// @Description 查找用户权限
 // @Success 200 {object} models.Account
 // @Failure 403 :id is empty
 // @router /find_permissions  [post,get,put]
@@ -232,8 +232,8 @@ func (c *SystemController) FindPermissions() {
 
 // AddMenu
 // @Title AddMenu
-// @Description 添加菜单         
-// @Param	    string  false  "菜单"  
+// @Description 添加菜单
+// @Param	    string  false  "菜单"
 // @Success 200 {object} models.Account
 // @Failure 403 :id is empty
 // @router /add_menu  [post,get,put]
@@ -244,8 +244,8 @@ func (c *SystemController) AddMenu() {
 
 // DelMenu
 // @Title DelMenu
-// @Description 删除菜单         
-// @Param	id    string  false  "菜单ID"  
+// @Description 删除菜单
+// @Param	id    string  false  "菜单ID"
 // @Success 200 {object} models.Account
 // @Failure 403 :id is empty
 // @router /del_menu  [post,get,put]
@@ -256,8 +256,8 @@ func (c *SystemController) DelMenu() {
 
 // UpdateMenu
 // @Title UpdateMenu
-// @Description 更新菜单         
-// @Param	    string  false  "菜单"  
+// @Description 更新菜单
+// @Param	    string  false  "菜单"
 // @Success 200 {object} models.Account
 // @Failure 403 :id is empty
 // @router /update_menu  [post,get,put]
@@ -266,3 +266,63 @@ func (c *SystemController) UpdateMenu() {
 	System_UpdateMenu(c)
 }
 
+// AddOrg
+// @Title AddOrg
+// @Description 添加组织
+// @Param	    string  false  "组织"
+// @Success 200 {object} models.Account
+// @Failure 403 :id is empty
+// @router /add_org  [post,get,put]
+func (c *SystemController) AddOrg() {
+	//
+	System_AddOrg(c)
+}
+
+// DelOrg
+// @Title DelOrg
+// @Description 删除组织
+// @Param	id    string  false  "组织ID"
+// @Success 200 {object} models.Account
+// @Failure 403 :id is empty
+// @router /del_org  [post,get,put]
+func (c *SystemController) DelOrg() {
+	//
+	System_DelOrg(c)
+}
+
+// UpdateOrg
+// @Title UpdateOrg
+// @Description 更新组织
+// @Param	    string  false  "组织"
+// @Success 200 {object} models.Account
+// @Failure 403 :id is empty
+// @router /update_org  [post,get,put]
+func (c *SystemController) UpdateOrg() {
+	//
+	System_UpdateOrg(c)
+}
+
+// GetOrg
+// @Title GetOrg
+// @Description 根据ID获取组织
+// @Param	    string  false  "组织"
+// @Success 200 {object} models.Account
+// @Failure 403 :id is empty
+// @router /get_org  [post,get,put]
+func (c *SystemController) GetOrg() {
+	//
+	System_GetOrg(c)
+}
+
+// UpdateOrg
+// @Title UpdateOrg
+// @Description 更新组织
+// @Param	    string  false  "组织"
+// @Success 200 {object} models.Account
+// @Failure 403 :id is empty
+// @router /page_org  [post,get,put]
+func (c *SystemController) PageOrg() {
+	//
+	System_PageOrg(c)
+}
+

+ 41 - 0
routers/router_gen.go

@@ -104,6 +104,27 @@ func systemController_update_menu(c *gin.Context) {
 	controllers.NewSystemController(c, g_engine).UpdateMenu()
 }
 
+
+func systemController_add_org(c *gin.Context) {
+	controllers.NewSystemController(c, g_engine).AddOrg()
+}
+
+func systemController_del_org(c *gin.Context) {
+	controllers.NewSystemController(c, g_engine).DelOrg()
+}
+
+func systemController_update_org(c *gin.Context) {
+	controllers.NewSystemController(c, g_engine).UpdateOrg()
+}
+
+func systemController_get_org(c *gin.Context) {
+	controllers.NewSystemController(c, g_engine).GetOrg()
+}
+
+func systemController_page_org(c *gin.Context) {
+	controllers.NewSystemController(c, g_engine).PageOrg()
+}
+
 func apiController_api_doc(c *gin.Context) {
 	controllers.NewApiController(c, g_engine).ApiDoc()
 }
@@ -236,6 +257,26 @@ func InitRouter(e *engine.ApiEngine) {
 	v1.POST("/system/update_menu", systemController_update_menu)
 	v1.PUT("/system/update_menu", systemController_update_menu)
 
+	v1.GET("/system/add_org", systemController_add_org)
+	v1.POST("/system/add_org", systemController_add_org)
+	v1.PUT("/system/add_org", systemController_add_org)
+
+	v1.GET("/system/del_org", systemController_del_org)
+	v1.POST("/system/del_org", systemController_del_org)
+	v1.PUT("/system/del_org", systemController_del_org)
+
+	v1.GET("/system/update_org", systemController_update_org)
+	v1.POST("/system/update_org", systemController_update_org)
+	v1.PUT("/system/update_org", systemController_update_org)
+
+	v1.GET("/system/get_org", systemController_get_org)
+	v1.POST("/system/get_org", systemController_get_org)
+	v1.PUT("/system/get_org", systemController_get_org)
+
+	v1.GET("/system/page_org", systemController_page_org)
+	v1.POST("/system/page_org", systemController_page_org)
+	v1.PUT("/system/page_org", systemController_page_org)
+
 	v1.GET("/api/api_doc", apiController_api_doc)
 	//v1.POST("/api/api_doc",apiController_api_doc)
 	//v1.PUT("/api/api_doc",apiController_api_doc)