| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- package controllers
- import (
- "github.com/kataras/iris/v12/mvc"
- "xps/service"
- "xps/viewmodels"
- )
- type UserController struct {
- Base
- Service service.UserService
- }
- func (c *UserController) BeforeActivation(b mvc.BeforeActivation) {
- b.Handle("GET", "/permit", "GetPermit" )
- b.Handle("GET", "/page", "GetPage" )
- b.Handle("GET", "/", "GetList" )
- b.Handle("GET", "/{groupId:int64}/{accountId:int64}", "GetById" )
- b.Handle("POST", "/add", "Create" )
- b.Handle("PUT", "/update", "Update" )
- b.Handle("PUT", "/updatePassword/{pwd: string}", "UpdatePassword" )
- b.Handle("PUT", "/resetPassword/{userId:int64}", "ResetPassword" )
- b.Handle("PUT", "/updateStatus/{userId:int64}/{status:int64}", "UpdateStatus" )
- b.Handle("DELETE", "/{accountId:int64}", "DeleteById" )
- b.Handle("GET", "/IsUserNameExist/{userName: string}", "IsUserNameExist" )
- b.Handle("GET", "/IsUserPhoneExist/{userPhone: string}", "IsUserPhoneExist")
- b.Handle("GET", "/IsStaffNoExist/{staffNo: string}", "IsStaffNoExist" )
- b.Handle("GET", "/IsEmailExist/{email: string}", "IsEmailExist" )
- b.Handle("GET", "/select", "SelectUser" )
- }
- func (c *UserController) GetPage()*JsonResult {
- params := c.buildParams()
- data, err := c.Service.GetPage(params)
- if err != nil {
- return ResultErr(err.Error(), nil)
- } else {
- return ResultOk("获取成功", data)
- }
- }
- func (c *UserController) GetList() *JsonResult {
- params := c.buildParams()
- data, err := c.Service.GetList(params)
- if err != nil {
- return ResultErr(err.Error(), nil)
- } else {
- return ResultOk("获取成功", data)
- }
- }
- func (c *UserController) GetById(groupId, accountId int64)*JsonResult {
- ocId := c.GetCurOcId()
- data, err := c.Service.GetById(ocId, groupId, accountId)
- if err != nil {
- return ResultErr(err.Error(), nil)
- } else {
- return ResultOk("获取成功", data)
- }
- }
- func (c *UserController) Create() *JsonResult {
- ocId := c.GetCurOcId()
- ocTypeId := c.GetOcTypeId()
-
- user := &viewmodels.UserInfo{}
- if err := c.Ctx.ReadJSON(user); err != nil {
- return ResultErr("读取数据失败", nil)
- }
-
- user.OcId = ocId
-
- if err := c.Service.Create(ocTypeId, user); err != nil {
- return ResultErr(err.Error(), nil)
- } else {
- return ResultOk("新增成功", nil)
- }
- }
- func (c *UserController) Update() *JsonResult {
- user := &viewmodels.UserInfo{}
- if err := c.Ctx.ReadJSON(user); err != nil {
- return ResultErr("读取数据失败", nil)
- }
-
- if err := c.Service.Update(user); err != nil {
- return ResultErr(err.Error(), nil)
- } else {
- return ResultOk("更新成功", nil)
- }
- }
- func (c *UserController) UpdatePassword(psw string)*JsonResult{
- ocId := c.GetCurOcId()
- userId := c.GetCurUserId()
-
- if err := c.Service.UpdatePassword(ocId, userId, psw); err != nil {
- return ResultErr(err.Error(), nil)
- } else {
- return ResultOk("密码更新成功", nil)
- }
- }
- func (c *UserController) ResetPassword(userId int64)*JsonResult{
- ocId := c.GetCurOcId()
-
- if err := c.Service.ResetPassword(ocId, userId); err != nil {
- return ResultErr(err.Error(), nil)
- } else {
- return ResultOk("密码重置成功", nil)
- }
- }
- func (c *UserController) UpdateStatus(userId, status int64)*JsonResult{
- ocId := c.GetCurOcId()
-
- if err := c.Service.ChangeStatus(ocId, userId, status); err != nil {
- return ResultErr(err.Error(), nil)
- } else {
- return ResultOk("状态变更成功", nil)
- }
- }
- func (c *UserController) DeleteById(accountId int64)*JsonResult {
- ocId := c.GetCurOcId()
- userId := c.GetCurUserId()
-
- m := make(map[string]interface{})
- m["ocId"] = ocId
- m["accountId"] = accountId
- m["deletedBy"] = userId
-
- if err := c.Service.Delete(m); err != nil {
- return ResultErr(err.Error(), nil)
- } else {
- return ResultOk("删除成功", nil)
- }
- }
- func (c *UserController) IsUserNameExist(userName string) *JsonResult {
- ocId := c.GetCurOcId()
- bExist, err := c.Service.IsUserNameExist(ocId, userName)
- if err != nil {
- return ResultErr(err.Error(), nil)
- }
-
- if bExist {
- return ResultErr("帐号名称已存在", nil)
- } else {
- return ResultOk("帐号名称不重复", nil)
- }
- }
- func (c *UserController) IsUserPhoneExist(userPhone string) *JsonResult {
- ocId := c.GetCurOcId()
-
- bExist, err := c.Service.IsUserPhoneExist(ocId, userPhone)
- if err != nil {
- return ResultErr(err.Error(), nil)
- }
- if bExist {
- return ResultErr("电话号码已注册", nil)
- } else {
- return ResultOk("电话号码无重复", nil)
- }
- }
- func (c *UserController) IsStaffNoExist(staffNo string) *JsonResult {
- ocId := c.GetCurOcId()
-
- bExist, err := c.Service.IsStaffNoExist(ocId, staffNo)
- if err != nil {
- return ResultErr(err.Error(), nil)
- }
- if bExist {
- return ResultErr("工号已存在", nil)
- } else {
- return ResultOk("工号无重复", nil)
- }
- }
- func (c *UserController) IsEmailExist(email string) *JsonResult {
- ocId := c.GetCurOcId()
-
- bExist, err := c.Service.IsEmailExist(ocId, email)
- if err != nil {
- return ResultErr(err.Error(), nil)
- }
- if bExist {
- return ResultErr("email已存在", nil)
- } else {
- return ResultOk("email无重复", nil)
- }
- }
- func (c *UserController) SelectUser() *JsonResult {
- ocId := c.GetCurOcId()
-
- data, err := c.Service.SelectUser(ocId)
- if err != nil {
- return ResultErr(err.Error(), nil)
- } else {
- return ResultOk("获取成功", data)
- }
- }
- func (c *UserController) GetPermit()*JsonResult {
- userId := c.GetCurUserId()
-
- appKey := c.GetAppKey()
- data, err := c.Service.GetPermit(userId, appKey)
- if err != nil {
- return ResultErr(err.Error(), nil)
- } else {
- return ResultOk("获取成功", data)
- }
- }
|