123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- package controller
- import (
- "github.com/gin-gonic/gin"
- "github.com/go-playground/validator/v10"
- "project_management/app/e"
- "project_management/app/model"
- "project_management/app/services"
- "project_management/unity"
- "strings"
- )
- var AppUser services.AppUser = &model.AppUser{}
- // RegistApply 注册app用户
- 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())
- }
- // LoginAppUser 用户登录-账号密码登录
- func LoginAppUser(c *gin.Context) {
- var appuser model.AppUserRegist
- if err := c.ShouldBindJSON(&appuser); err != nil {
- e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
- return
- }
- validate := validator.New()
- err := validate.Struct(appuser)
- if err != nil {
- e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg())
- return
- }
- login, token := AppUser.AccountLogin(appuser)
- if login == e.NOTTABLE {
- e.ResponseWithMsg(c, e.SUCCESS, e.NOTTABLE.GetMsg())
- return
- }
- if login == e.SUCCESS {
- e.ResponseSuccess(c, token)
- return
- }
- e.ResponseWithMsg(c, login, login.GetMsg())
- }
- // LoginAppUserByCode 验证码登录
- func LoginAppUserByCode(c *gin.Context) {
- var appuser model.AppUserRegist
- if err := c.ShouldBindJSON(&appuser); err != nil {
- e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
- return
- }
- validate := validator.New()
- err := validate.Var(appuser.Code, "required")
- err = validate.Var(appuser.Phone, "required")
- err = validate.Var(appuser.AppID, "required")
- if err != nil {
- e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg())
- return
- }
- login, s := AppUser.CodeLogin(appuser)
- if login == e.SUCCESS {
- e.ResponseSuccess(c, s)
- return
- }
- e.ResponseWithMsg(c, login, login.GetMsg())
- }
- // AddAppUser 添加用户
- 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
- }
- validate := validator.New()
- err := 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())
- }
- // GetAppUserList 获取用户列表
- func GetAppUserList(c *gin.Context) {
- var params unity.CapQueryPageParams
- if err := c.ShouldBindJSON(¶ms); err != nil {
- e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
- return
- }
- tableName := "appuser_" + params.AppId
- queryCond := "username like ?"
- params.Query = "%" + params.Query + "%"
- result, total, err := AppUser.GetAppUserList(params, tableName, queryCond)
- if err != nil {
- if strings.Contains(err.Error(), "当前系统没有该表") {
- e.ResponseWithMsg(c, e.SUCCESS, "当前用户为空")
- return
- }
- e.ResponseWithMsg(c, e.PaginationFailed, e.PaginationFailed.GetMsg())
- return
- }
- e.CapResPonsePage(c, result, total, params)
- }
- // UpdateAppUser 更新用户信息
- 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
- }
- validate := validator.New()
- if err := validate.Struct(appuser); err != nil {
- e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg())
- return
- }
- tablename := "appuser_" + appuser.AppID
- user := AppUser.UpdateAppUser(appuser, tablename)
- if user == e.SUCCESS {
- e.ResponseSuccess(c, "")
- return
- }
- e.ResponseWithMsg(c, user, user.GetMsg())
- }
- // DeleteAppUserByID 删除用户
- func DeleteAppUserByID(c *gin.Context) {
- var deldate model.AppUserDel
- err := c.ShouldBindJSON(&deldate)
- if err != nil {
- e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
- return
- }
- validate := validator.New()
- err = validate.Struct(deldate)
- if err != nil {
- e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg())
- }
- tablename := "appuser_" + deldate.AppID
- if err != nil {
- e.ResponseWithMsg(c, e.JSONParsingFailed, "id格式错误")
- return
- }
- byID := AppUser.DeleteAppUserByID(deldate.ID, tablename)
- if byID == e.SUCCESS {
- e.ResponseSuccess(c, "")
- return
- }
- e.ResponseWithMsg(c, byID, byID.GetMsg())
- }
|