houyaf 3 éve
szülő
commit
6c885697e8

+ 66 - 43
repositories/system/account_repo.go

@@ -2,9 +2,7 @@ package system
 
 import (
 	"fmt"
-	"log"
 	"time"
-	"xorm.io/core"
 	"xorm.io/xorm"
 	"xps/datamodels"
 	"xps/viewmodels"
@@ -20,9 +18,7 @@ func NewAccountRepo(engine *xorm.Engine) *AccountRepo {
 	}
 }
 
-func (d *AccountRepo) GetAccountByName(accountName string) *viewmodels.AccountInfo {
-	data := &viewmodels.AccountInfo{}
-
+func (d *AccountRepo) GetAccountByName(accountName string)(*viewmodels.AccountInfo, error) {
 	sqlSelect := ` SELECT   A.oc_id,
                             B.oc_type_id,
                             B.oc_name,
@@ -42,27 +38,24 @@ func (d *AccountRepo) GetAccountByName(accountName string) *viewmodels.AccountIn
                             A.account_intro,
                             A.wx_id,
                             A.is_fixed `
-	sqlFrom := `  FROM      account AS A
-                  LEFT JOIN oc      AS B ON (A.oc_id = B.oc_id )
-               `
-	sqlWhere := `WHERE A.deleted_flag = 0  `
+	sqlFrom   := `  FROM      account AS A
+                    LEFT JOIN oc      AS B ON (A.oc_id = B.oc_id ) `
+	sqlWhere  := `  WHERE A.deleted_flag = 0  `
 
 	if accountName != "" {
-		sqlWhere += ` AND   A.account_name like ` + "'%" + accountName + "%'"
+		sqlWhere += ` AND  A.account_name like ` + "'%" + accountName + "%'"
 	}
 
-	//err2 := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).OrderBy("role_id DESC").Limit(pageSize, pageStart).Find(&datalist)
+	data := &viewmodels.AccountInfo{}
 	ok, err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).Get(data)
-
 	if !ok && err != nil {
-		return nil
+		return nil, err
 	} else {
-		return data
+		return data, nil
 	}
 }
 
 func (d *AccountRepo) GetAccountByCode(code string) (*viewmodels.AccountInfo, error) {
-	data := &viewmodels.AccountInfo{}
 	sqlSelect := ` SELECT   A.oc_id,
 							B.oc_type_id,
 							B.oc_name,
@@ -82,14 +75,15 @@ func (d *AccountRepo) GetAccountByCode(code string) (*viewmodels.AccountInfo, er
 							A.account_intro,
 							A.wx_id,
 							A.is_fixed `
-	sqlFrom := `  FROM      account AS A
+	sqlFrom  := ` FROM      account AS A
                   LEFT JOIN oc      AS B ON (A.oc_id = B.oc_id ) `
 	sqlWhere := ` WHERE A.deleted_flag = 0  `
 	sqlWhere += ` AND  (A.account_name = ` + "'" + code + "'"
 	sqlWhere += ` OR    A.account_phone = ` + "'" + code + "'"
 	sqlWhere += ` OR    A.account_mail = ` + "'" + code + "'"
 	sqlWhere += ` OR    A.account_staff_no = ` + "'" + code + "')"
-
+	
+	data := &viewmodels.AccountInfo{}
 	ok, err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).Get(data)
 	if !ok && err != nil {
 		return nil, err
@@ -97,9 +91,7 @@ func (d *AccountRepo) GetAccountByCode(code string) (*viewmodels.AccountInfo, er
 	return data, nil
 }
 
-func (d *AccountRepo) GetById(ocId int64, accountId int64) *viewmodels.AccountInfo {
-	var user = &viewmodels.AccountInfo{}
-
+func (d *AccountRepo) GetById(ocId int64, accountId int64)(*viewmodels.AccountInfo, error){
 	sqlSelect := ` SELECT   A.oc_id,
                             B.oc_type_id,
                             B.oc_name,
@@ -123,20 +115,17 @@ func (d *AccountRepo) GetById(ocId int64, accountId int64) *viewmodels.AccountIn
                   LEFT JOIN oc      AS B ON (A.oc_id = B.oc_id ) `
 	sqlWhere := ` WHERE A.deleted_flag = 0  AND A.oc_id = ` + fmt.Sprintf("%d", ocId)
 	sqlWhere += ` AND   A.account_id = ` + fmt.Sprintf("%d", accountId)
-
+	
+	user := &viewmodels.AccountInfo{}
 	has, err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).Get(user)
-
 	if !has || err != nil {
-		return nil
+		return nil, err
 	} else {
-		return user
+		return user, nil
 	}
-
 }
 
 func (d *AccountRepo) GetList(ocId int64) ([]viewmodels.AccountInfo, error) {
-	datalist := make([]viewmodels.AccountInfo, 0)
-
 	sqlSelect := ` SELECT   A.oc_id,
                             B.oc_type_id,
                             B.oc_name,
@@ -156,16 +145,17 @@ func (d *AccountRepo) GetList(ocId int64) ([]viewmodels.AccountInfo, error) {
                             A.account_intro,
                             A.wx_id,
                             A.is_fixed `
-	sqlFrom := `  FROM      account AS A
+	sqlFrom  := ` FROM      account AS A
                   LEFT JOIN oc      AS B ON (A.oc_id = B.oc_id ) `
 	sqlWhere := ` WHERE A.deleted_flag = 0  `
-
+	
+	datalist := make([]viewmodels.AccountInfo, 0)
 	err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).Asc("account_id").Find(&datalist)
 	if err != nil {
 		return nil, err
+	} else {
+		return datalist, nil
 	}
-
-	return datalist, nil
 }
 
 func (d *AccountRepo) Create(data *datamodels.Account) error {
@@ -174,7 +164,10 @@ func (d *AccountRepo) Create(data *datamodels.Account) error {
 }
 
 func (d *AccountRepo) Update(ocId, accountId int64, data *datamodels.Account) error {
-	_, err := d.engine.ID(core.PK{ocId, accountId}).Update(data)
+	_, err := d.engine.
+		Where("oc_id = ?", ocId).
+		Where("account_id = ?", accountId).
+		Update(data)
 	return err
 }
 
@@ -189,24 +182,54 @@ func (d *AccountRepo) Delete(m map[string]interface{}) error {
 		DeletedBy: deletedBy,
 		DeletedAt: time.Now(),
 	}
-	_, err := d.engine.ID(core.PK{ocId, accountId}).Update(data)
+	_, err := d.engine.
+		Where("oc_id = ?", ocId).
+		Where("account_id = ?", accountId).
+		Update(data)
 	return err
 }
 
-func (d *AccountRepo) IsUserNameExist(ocId int64, accountName string) bool {
-	count, err := d.engine.Where("deleted_flag = 0").Where("account_name = ?", accountName).Count(new(datamodels.Account))
+func (d *AccountRepo) IsUserNameExist(ocId int64, accountName string) (bool, error) {
+	count, err := d.engine.
+		Where("deleted_flag = 0").
+		Where("account_name = ?", accountName).
+		Count(new(datamodels.Account))
 	if err != nil {
-		log.Fatal(err)
-		return true
+		return false, err
 	}
-	return count > 0
+	return count > 0, nil
 }
 
-func (d *AccountRepo) IsUserPhoneExist(ocId int64, accountPhone string) bool {
-	count, err := d.engine.Where("deleted_flag = 0").Where("account_phone = ?", accountPhone).Count(new(datamodels.Account))
+func (d *AccountRepo) IsUserPhoneExist(ocId int64, accountPhone string)(bool, error){
+	count, err := d.engine.
+		Where("deleted_flag = 0").
+		Where("account_phone = ?", accountPhone).
+		Count(new(datamodels.Account))
 	if err != nil {
-		log.Fatal(err)
-		return true
+		return true, err
 	}
-	return count > 0
+	return count > 0, nil
 }
+
+
+func (d *AccountRepo) IsStaffNoExist(ocId int64, staffNo string)(bool, error){
+	count, err := d.engine.
+		Where("deleted_flag = 0").
+		Where("account_staff_no = ?", staffNo).
+		Count(new(datamodels.Account))
+	if err != nil {
+		return true, err
+	}
+	return count > 0, nil
+}
+
+func (d *AccountRepo) IsEmailExist(ocId int64, email string)(bool, error) {
+	count, err := d.engine.
+		Where("deleted_flag = 0").
+		Where("account_email = ?", email).
+		Count(new(datamodels.Account))
+	if err != nil {
+		return true, err
+	}
+	return count > 0, nil
+}

+ 36 - 16
repositories/system/group_member_position_repo.go

@@ -39,12 +39,11 @@ func (d *GroupMemberPositionRepo) GetFirstPositionByGroupIdAndAccountId(ocId, gr
                           A.position_id,
                           D.position_name 
                  `
-	sqlFrom := ` FROM      s_group_member_position AS A 
+	sqlFrom  :=  ` FROM      s_group_member_position AS A
                    LEFT JOIN s_group       AS B ON ( A.oc_id = B.oc_id AND A.group_id    = B.group_id   )
                    LEFT JOIN account       AS C ON ( A.oc_id = C.oc_id AND A.account_id  = C.account_id ) 
-                   LEFT JOIN s_position    AS D ON ( A.oc_id = D.oc_id AND A.position_id = D.position_id)
-                 `
-	sqlWhere := ` WHERE A.oc_id      = ` + fmt.Sprintf("%d", ocId)
+                   LEFT JOIN s_position    AS D ON ( A.oc_id = D.oc_id AND A.position_id = D.position_id) `
+	sqlWhere := `  WHERE A.oc_id     = ` + fmt.Sprintf("%d", ocId)
 	sqlWhere += `  AND  A.group_id   = ` + fmt.Sprintf("%d", groupId)
 	sqlWhere += `  AND  A.account_id = ` + fmt.Sprintf("%d", accountId)
 	
@@ -67,18 +66,39 @@ func (d *GroupMemberPositionRepo) GetByAccountId(ocId int64, accountId int64)(*d
 }
 
 func (d *GroupMemberPositionRepo) GetList(m map[string]interface{})([]viewmodels.GroupMemberPositionInfo, error){
-	ocId     := m["ocId"].(int64)
-	keywords := m["keywords"].(string)
-	sqlSelect := `SELECT A.gm_id,
-                         A.group_id,
-                         A.group_name,
-                         A.account_id,
-                         A.group_member_remark `
-	sqlFrom := ` FROM      s_group_member AS A
-                 LEFT JOIN s_group  AS B ON (A.group_id = B.group_id) `
-	sqlWhere := `WHERE  A.deleted_flag = 0 AND A.oc_id = ` + fmt.Sprintf("%d", ocId)
-	if keywords != "" {
-		sqlWhere += ` AND   B.group_name like ` + "'%" + keywords + "%'"
+	ocId      := m["ocId"].(int64)
+	sqlSelect := `  SELECT  A.gmp_id,
+							A.oc_id,
+					        A.group_id,
+					        B.group_name,
+					        A.account_id,
+					        D.account_name,
+					        D.account_real_name,
+					        A.position_id,
+					        C.position_name `
+	sqlFrom  := `   FROM      s_group_member_position A
+			        LEFT JOIN s_group                 B ON (A.oc_id = B.oc_id AND A.group_id     = B.group_id)
+			        LEFT JOIN s_position              C ON (A.oc_id = C.oc_id AND A.position_id  = C.position_id)
+			        LEFT JOIN   account               D ON (A.oc_id = D.oc_id AND A.account_id   = D.account_id) `
+	sqlWhere := `   WHERE A.deleted_flag = 0
+                    AND   A.oc_id = ` + fmt.Sprintf("%d", ocId)
+	if groupId, ok := m["groupId"]; ok {
+		sqlWhere += ` AND A.group_id = ` + fmt.Sprintf("%d", groupId)
+	}
+	if accountId, ok := m["accountId"]; ok {
+		sqlWhere += ` AND A.account_id = ` + fmt.Sprintf("%d", accountId)
+	}
+	if positionId, ok := m["positionId"]; ok {
+		sqlWhere += ` AND A.position_id = ` + fmt.Sprintf("%d", positionId)
+	}
+	if keywords, ok := m["keywords"]; ok {
+		sqlWhere += ` AND A.group_cat_title like '%` + fmt.Sprintf("%s", keywords) + `%'`
+	}
+	nodeLeft, ok1 := m["nodeLeft"]
+	nodeRight, ok2 := m["nodeRight"]
+	if ok1 && ok2 {
+		sqlWhere += ` AND B.node_left  >= ` + fmt.Sprintf("%d", nodeLeft)
+		sqlWhere += ` AND B.node_right <= ` + fmt.Sprintf("%d", nodeRight)
 	}
 	
 	datalist := make([]viewmodels.GroupMemberPositionInfo, 0)

+ 2 - 2
service/system/login_service.go

@@ -11,7 +11,7 @@ import (
 )
 
 type LoginService interface {
-	GetAccountByName(cond string) *viewmodels.AccountInfo
+	GetAccountByName(cond string)(*viewmodels.AccountInfo, error)
 	CheckLogin(username, password string) (bRet bool, msg string, data *viewmodels.AccessToken)
 	Logout(userId int64) error
 }
@@ -34,7 +34,7 @@ func NewLoginService() LoginService {
 	}
 }
 
-func (s *loginService) GetAccountByName(cond string) *viewmodels.AccountInfo {
+func (s *loginService) GetAccountByName(cond string)(*viewmodels.AccountInfo, error) {
 	return s.accountRepo.GetAccountByName(cond)
 }
 

+ 59 - 0
service/system/user_service.go

@@ -15,6 +15,11 @@ type UserService interface {
     Create(ocTypeId int64, user *viewmodels.UserInfo) error
     Update(user *viewmodels.UserInfo) error
     Delete(m map[string]interface{}) error
+    IsUserNameExist(ocId int64, accountName string) (bool, error)
+    IsUserPhoneExist(ocId int64, accountPhone string)(bool, error)
+    IsStaffNoExist(ocId int64, staffNo string)(bool, error)
+    IsEmailExist(ocId int64, staffNo string)(bool, error)
+    SelectUser(ocId int64)([]viewmodels.UserSelectVo, error)
 }
 
 type userService struct {
@@ -200,3 +205,57 @@ func (s *userService) Delete(m map[string]interface{}) error {
     return err
 }
 
+
+func (s *userService) IsUserNameExist(ocId int64, accountName string) (bool, error){
+    return s.accountRepo.IsUserNameExist(ocId, accountName)
+}
+
+func (s *userService) IsUserPhoneExist(ocId int64, accountPhone string)(bool, error){
+    return s.accountRepo.IsUserPhoneExist(ocId, accountPhone)
+}
+
+func (s *userService) IsStaffNoExist(ocId int64, staffNo string)(bool, error){
+    return s.accountRepo.IsStaffNoExist(ocId, staffNo)
+}
+
+func (s *userService) IsEmailExist(ocId int64, email string)(bool, error){
+    return s.accountRepo.IsEmailExist(ocId, email)
+}
+
+func (s *userService) SelectUser(ocId int64)([]viewmodels.UserSelectVo, error){
+    m := make(map[string]interface{}, 0)
+    m["ocId"] = ocId
+    memberList, err := s.groupMemberPositionRepo.GetList(m)
+    if err != nil {
+        return nil, err
+    }
+    
+    voList     := make([]viewmodels.UserSelectVo, 0)
+    itemList   := make([]viewmodels.UserSelectItemVo, 0)
+    positionId := int64(0)
+    for _, member := range memberList {
+        item := viewmodels.UserSelectItemVo{
+            Name: member.AccountName,
+            Value: member.AccountId,
+            AccountId: member.AccountId,
+            AccountName: member.AccountName,
+            PositionId: member.PositionId,
+            PositionName: member.PositionName,
+            GroupId: member.GroupId,
+            GroupName: member.GroupName,
+        }
+        itemList   = append(itemList, item)
+    
+        if positionId != 0 && positionId != member.PositionId {
+            vo := viewmodels.UserSelectVo{
+                Name: member.PositionName,
+                Children: itemList,
+            }
+            itemList = make([]viewmodels.UserSelectItemVo, 0)
+            voList = append(voList, vo)
+        }
+        positionId = member.PositionId
+    }
+    
+    return voList, nil
+}

+ 4 - 4
viewmodels/group_member_position_info.go

@@ -1,12 +1,12 @@
 package viewmodels
 
-// Role Member Info View data models
 type GroupMemberPositionInfo struct {
 	OcId         int64  `form:"ocId"         xorm:"'oc_id'         bigint not null pk comment('公司组织ID') " `
 	GmpId        int64  `form:"gmpId"        xorm:"'gmp_id'        bigint not null pk comment('公司组织ID') " `
-	GroupId      int64  `form:"groupId"      xorm:"'group_id'      bigint not null pk comment('群组ID')    " `
+	GroupId      int64  `form:"groupId"      xorm:"'group_id'      bigint not null    comment('群组ID')    " `
 	GroupName    string `form:"groupName"    xorm:"'group_name'    string not null    comment('群组名称')   " `
-	AccountId    int64  `form:"accountId"    xorm:"'account_id'    bigint not null pk comment('帐号ID')     " `
-	PositionId   int64  `form:"positionId"   xorm:"'account_id'    bigint not null pk comment('岗位ID')     " `
+	AccountId    int64  `form:"accountId"    xorm:"'account_id'    bigint not null    comment('帐号ID')     " `
+	AccountName  string `form:"accountName"  xorm:"'account_name'  string not null    comment('岗位名称')   " `
+	PositionId   int64  `form:"positionId"   xorm:"'account_id'    bigint not null    comment('岗位ID')     " `
 	PositionName string `form:"positionName" xorm:"'position_name' string not null    comment('岗位名称')   " `
 }

+ 12 - 0
viewmodels/user_select_item_vo.go

@@ -0,0 +1,12 @@
+package viewmodels
+
+type UserSelectItemVo struct {
+    Name         string `json:"name"            `
+    Value        int64  `json:"value"           `
+    AccountId    int64  `json:"accountId"       `
+    AccountName  string `json:"accountName"     `
+    PositionId   int64  `json:"positionId"      `
+    PositionName string `json:"positionName"    `
+    GroupId      int64  `json:"groupId"         `
+    GroupName    string `json:"groupName"       `
+}

+ 8 - 0
viewmodels/user_select_vo.go

@@ -0,0 +1,8 @@
+package viewmodels
+
+
+type UserSelectVo struct {
+    Name     string             `json:"name"       `
+    Children []UserSelectItemVo `json:"children"   `
+    
+}

+ 72 - 5
web/controllers/user_controller.go

@@ -12,11 +12,16 @@ type UserController struct {
 }
 
 func (c *UserController) BeforeActivation(b mvc.BeforeActivation) {
-    b.Handle("GET",         "/page",                                "GetPage"   )
-    b.Handle("GET",         "/{groupId:int64}/{accountId:int64}",   "GetById"   )
-    b.Handle("POST",        "/add",                                 "Create"    )
-    b.Handle("PUT",         "/update",                              "Update"    )
-    b.Handle("DELETE",      "/{accountId:int64}",                   "DeleteById")
+    b.Handle("GET",         "/page",                                    "GetPage"         )
+    b.Handle("GET",         "/{groupId:int64}/{accountId:int64}",       "GetById"         )
+    b.Handle("POST",        "/add",                                     "Create"          )
+    b.Handle("PUT",         "/update",                                  "Update"          )
+    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 {
@@ -87,3 +92,65 @@ func (c *UserController) DeleteById(accountId int64) *JsonResult {
     }
 }
 
+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)
+    }
+}