123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- package controller
- import (
- "github.com/gin-gonic/gin"
- "project_management/app/e"
- "project_management/app/model"
- "project_management/app/services"
- "project_management/unity"
- "strconv"
- )
- var AppUser services.AppUser = &model.AppUser{}
- func RegistApply(c *gin.Context) {
- var appuser model.AppUserRegist
- if err := c.ShouldBindJSON(&appuser); err != nil {
- e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
- return
- }
- if !model.IsRegist(appuser.AppID) {
- e.ResponseWithMsg(c, e.TheSystemCannotBeRegistered, e.TheSystemCannotBeRegistered.GetMsg())
- return
- }
- user := AppUser.RegistAppUser(appuser)
- if user == e.SUCCESS {
- e.ResponseWithMsg(c, e.SUCCESS, e.SUCCESS.GetMsg())
- return
- }
- e.ResponseWithMsg(c, user, user.GetMsg())
- }
- func AddAppUser(c *gin.Context) {
- var appuser model.AppUser
- if err := c.ShouldBindJSON(&appuser); err != nil {
- e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
- return
- }
-
- err := unity.Validate.Struct(appuser)
- if err != nil {
- e.ResponseWithMsg(c, e.JSONParsingFailed, err.Error())
- }
-
-
-
-
- user := AppUser.AddAppUser(appuser)
- if user == e.SUCCESS {
- e.ResponseWithMsg(c, e.SUCCESS, e.SUCCESS.GetMsg())
- return
- }
- e.ResponseWithMsg(c, user, user.GetMsg())
- }
- func GetAppUserList(c *gin.Context) {
- var params unity.QueryPageParams
- if err := c.ShouldBindJSON(¶ms); err != nil {
- e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
- return
- }
- app_id := c.Query("app_id")
- err := unity.Validate.Var(app_id, "required")
- if err != nil {
- e.ResponseWithMsg(c, e.JSONParsingFailed, "缺少appid")
- return
- }
- tableName := "appuser_" + app_id
- queryCond := "username like ?"
- params.Query = "%" + params.Query + "%"
- result, total, err := AppUser.GetAppUserList(params, tableName, queryCond)
- if err != nil {
- e.ResponseWithMsg(c, e.PaginationFailed, e.PaginationFailed.GetMsg())
- return
- }
- e.ResPonsePage(c, result, total, params)
- }
- func UpdateAppUser(c *gin.Context) {
- var appuser model.AppUser
- if err := c.ShouldBindJSON(&appuser); err != nil {
- e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
- return
- }
- app_id := c.Query("app_id")
- if err := unity.Validate.Var(app_id, "required"); err != nil {
- e.ResponseWithMsg(c, e.JSONParsingFailed, "缺少appid")
- return
- }
- tablename := "appuser_" + app_id
- user := AppUser.UpdateAppUser(appuser, tablename)
- if user == e.SUCCESS {
- e.ResponseSuccess(c, "")
- return
- }
- e.ResponseWithMsg(c, user, user.GetMsg())
- }
- func DeleteAppUserByID(c *gin.Context) {
- id := c.PostForm("id")
- app_id := c.PostForm("app_id")
- if err := unity.Validate.Var(id, "required"); err != nil {
- e.ResponseWithMsg(c, e.JSONParsingFailed, "缺少id")
- return
- }
- if err := unity.Validate.Var(app_id, "required"); err != nil {
- e.ResponseWithMsg(c, e.JSONParsingFailed, "缺少appid")
- return
- }
- tablename := "appuser_" + app_id
- atoi, err := strconv.Atoi(id)
- if err != nil {
- e.ResponseWithMsg(c, e.JSONParsingFailed, "id格式错误")
- return
- }
- byID := AppUser.DeleteAppUserByID(atoi, tablename)
- if byID == e.SUCCESS {
- e.ResponseSuccess(c, "")
- return
- }
- e.ResponseWithMsg(c, byID, byID.GetMsg())
- }
|