作者 tangxvhui

更新

@@ -39,6 +39,7 @@ func (c CompanyServices) addCompany(param *command.SaveCompanyCommand) error { @@ -39,6 +39,7 @@ func (c CompanyServices) addCompany(param *command.SaveCompanyCommand) error {
39 Status: param.Comapany.Status, 39 Status: param.Comapany.Status,
40 UpdateAt: nowTime, 40 UpdateAt: nowTime,
41 CreateAt: nowTime, 41 CreateAt: nowTime,
  42 + ChargeUserIds: []int64{},
42 DeleteAt: nil, 43 DeleteAt: nil,
43 } 44 }
44 45
@@ -169,3 +170,100 @@ func (c CompanyServices) editCompany(param *command.SaveCompanyCommand) error { @@ -169,3 +170,100 @@ func (c CompanyServices) editCompany(param *command.SaveCompanyCommand) error {
169 } 170 }
170 return nil 171 return nil
171 } 172 }
  173 +
  174 +func (srv CompanyServices) setCompanyCharge(param *command.SetCompanyCharge) error {
  175 + transactionContext, err := factory.CreateTransactionContext(nil)
  176 + if err != nil {
  177 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  178 + }
  179 + if err := transactionContext.StartTransaction(); err != nil {
  180 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  181 + }
  182 + defer func() {
  183 + _ = transactionContext.RollbackTransaction()
  184 + }()
  185 +
  186 + companyRepo := factory.CreateCompanyRepository(map[string]interface{}{
  187 + "transactionContext": transactionContext,
  188 + })
  189 +
  190 + _, companyList, err := companyRepo.Find(map[string]interface{}{
  191 + "id": param.CompanyId,
  192 + "limit": 1,
  193 + })
  194 +
  195 + if err != nil {
  196 + return err
  197 + }
  198 + for i := range companyList {
  199 + companyList[i].ChargeUserIds = param.ChargeUserIds
  200 + companyList[i].UpdateAt = time.Now()
  201 + _, err = companyRepo.Update(companyList[i])
  202 + if err != nil {
  203 + return err
  204 + }
  205 + }
  206 + if err := transactionContext.CommitTransaction(); err != nil {
  207 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  208 + }
  209 + return nil
  210 +}
  211 +
  212 +//changeAdmin
  213 +//从BusinessAdmins 接收消息 变更主管
  214 +func (srv CompanyServices) changeAdmin(param *command.ChangeAdminCommand) error {
  215 + transactionContext, err := factory.CreateTransactionContext(nil)
  216 + if err != nil {
  217 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  218 + }
  219 + if err := transactionContext.StartTransaction(); err != nil {
  220 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  221 + }
  222 + defer func() {
  223 + _ = transactionContext.RollbackTransaction()
  224 + }()
  225 +
  226 + userRepo := factory.CreateUserRepository(map[string]interface{}{
  227 + "transactionContext": transactionContext,
  228 + })
  229 + //查找公司对应的管理员用户
  230 + _, userList, err := userRepo.Find(map[string]interface{}{
  231 + "limit": 10,
  232 + "companyId": param.CompanyId,
  233 + "adminType": domain.UserTypeManager,
  234 + })
  235 + if err != nil {
  236 + return err
  237 + }
  238 + //修改旧管理员 为普通用户
  239 + for i := range userList {
  240 + userList[i].AdminType = domain.UserTypeCommon
  241 + userList[i].UpdateAt = time.Now()
  242 + _, err := userRepo.Update(userList[i])
  243 + if err != nil {
  244 + return err
  245 + }
  246 + }
  247 + //获取新管理员
  248 + _, userList2, err := userRepo.Find(map[string]interface{}{
  249 + "limit": 1,
  250 + "companyId": param.CompanyId,
  251 + "account": param.UserAccount,
  252 + })
  253 + if err != nil {
  254 + return err
  255 + }
  256 + //修改为管理员用户
  257 + for i := range userList2 {
  258 + userList[i].AdminType = domain.UserTypeManager
  259 + userList[i].UpdateAt = time.Now()
  260 + _, err := userRepo.Update(userList[i])
  261 + if err != nil {
  262 + return err
  263 + }
  264 + }
  265 + if err := transactionContext.CommitTransaction(); err != nil {
  266 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  267 + }
  268 + return nil
  269 +}
  1 +package command
  2 +
  3 +type AddDepartmentCommand struct {
  4 + Id int64 `json:"id" ` // 组织id
  5 + CompanyId int64 `json:"company_id"` // 公司编号
  6 + Level int `json:"level"` // 组织名称
  7 + Name string `json:"name"` // 组织名称
  8 + ParentId int64 `json:"parent_id"` // 组织父级id
  9 + ChargeUserIds []int64 `json:"charge"` // 主管uids
  10 + Path string `json:"path"` // 组织路径
  11 +}
  1 +package department
  2 +
  3 +type SyncDataDepartmentService struct{}
  4 +
  5 +//AddDepartment
  6 +//从BusinessAdmins 接收消息 添加部门
  7 +//module="department" action="add"
  8 +func (srv SyncDataDepartmentService) AddDepartment() error {
  9 + return nil
  10 +}
  11 +
  12 +//EditDepartment
  13 +//从BusinessAdmins 接收消息 编辑部门
  14 +//module="department" action="edit"
  15 +func (srv SyncDataDepartmentService) EditDepartment() error {
  16 + return nil
  17 +}
  18 +
  19 +//batchDelete
  20 +//从BusinessAdmins 接收消息 删除部门
  21 +//module="department" action="batchDelete"
  22 +func (srv SyncDataDepartmentService) batchDelete() error {
  23 + return nil
  24 +}
  25 +
  26 +//importDepartment
  27 +//从BusinessAdmins 接收消息 导入部门数据
  28 +//module="department" action="import"
  29 +func (srv SyncDataDepartmentService) importDepartment() error {
  30 + return nil
  31 +}
  1 +package command
  2 +
  3 +type BatchDeleteCommand struct {
  4 + // 用户账号
  5 + Uids []int64 `json:"ids"`
  6 +}
  1 +package command
  2 +
  3 +// 批量禁用、启用用户
  4 +type BatchForbidCommand struct {
  5 + // 用户账号
  6 + Uids []int64 `json:"ids"`
  7 + //用户状态
  8 + Status int `json:"status"`
  9 +}
  1 +package command
  2 +
  3 +type ImportUserCommand struct {
  4 + AddUsers []SaveUserCommand `json:"add"`
  5 + EditUsers []SaveUserCommand `json:"edit"`
  6 +}
@@ -9,11 +9,12 @@ import ( @@ -9,11 +9,12 @@ import (
9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
10 ) 10 )
11 11
12 -type UserService struct{} 12 +type SyncDataUserService struct{}
13 13
14 //AddUser 14 //AddUser
15 //从BusinessAdmins 接收消息 添加用户 15 //从BusinessAdmins 接收消息 添加用户
16 -func (srv UserService) addUser(param command.SaveUserCommand) error { 16 +//module="employee" action="add"
  17 +func (srv SyncDataUserService) AddUser(param command.SaveUserCommand) error {
17 transactionContext, err := factory.CreateTransactionContext(nil) 18 transactionContext, err := factory.CreateTransactionContext(nil)
18 if err != nil { 19 if err != nil {
19 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 20 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -52,7 +53,8 @@ func (srv UserService) addUser(param command.SaveUserCommand) error { @@ -52,7 +53,8 @@ func (srv UserService) addUser(param command.SaveUserCommand) error {
52 53
53 //UpdateUser 54 //UpdateUser
54 //从BusinessAdmins 接收消息 更新用户 55 //从BusinessAdmins 接收消息 更新用户
55 -func (srv UserService) updateUser(param command.SaveUserCommand) error { 56 +//module="employee" action="edit"
  57 +func (srv SyncDataUserService) UpdateUser(param command.SaveUserCommand) error {
56 transactionContext, err := factory.CreateTransactionContext(nil) 58 transactionContext, err := factory.CreateTransactionContext(nil)
57 if err != nil { 59 if err != nil {
58 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 60 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -109,9 +111,13 @@ func (srv UserService) updateUser(param command.SaveUserCommand) error { @@ -109,9 +111,13 @@ func (srv UserService) updateUser(param command.SaveUserCommand) error {
109 return nil 111 return nil
110 } 112 }
111 113
112 -//changeAdmin  
113 -//从BusinessAdmins 接收消息 变更主管  
114 -func (srv UserService) changeAdmin(param *command.ChangeAdminCommand) error { 114 +//batchDelete
  115 +//从BusinessAdmins 接收消息 删除用户
  116 +//module="employee" action="batchDelete"
  117 +func (srv SyncDataUserService) batchDelete(param command.BatchDeleteCommand) error {
  118 + if len(param.Uids) == 0 {
  119 + return nil
  120 + }
115 transactionContext, err := factory.CreateTransactionContext(nil) 121 transactionContext, err := factory.CreateTransactionContext(nil)
116 if err != nil { 122 if err != nil {
117 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 123 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -122,14 +128,64 @@ func (srv UserService) changeAdmin(param *command.ChangeAdminCommand) error { @@ -122,14 +128,64 @@ func (srv UserService) changeAdmin(param *command.ChangeAdminCommand) error {
122 defer func() { 128 defer func() {
123 _ = transactionContext.RollbackTransaction() 129 _ = transactionContext.RollbackTransaction()
124 }() 130 }()
  131 + userRepo := factory.CreateUserRepository(map[string]interface{}{
  132 + "transactionContext": transactionContext,
  133 + })
125 134
  135 + err = userRepo.Remove(param.Uids)
  136 + if err != nil {
  137 + return err
  138 + }
126 if err := transactionContext.CommitTransaction(); err != nil { 139 if err := transactionContext.CommitTransaction(); err != nil {
  140 + return err
  141 + }
  142 + return nil
  143 +}
  144 +
  145 +//batchForbid
  146 +//从BusinessAdmins 接收消息 禁用,启用用户
  147 +//module="employee" action="batchForbid"
  148 +func (srv SyncDataUserService) batchForbid(param command.BatchForbidCommand) error {
  149 + if len(param.Uids) == 0 {
  150 + return nil
  151 + }
  152 + transactionContext, err := factory.CreateTransactionContext(nil)
  153 + if err != nil {
127 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 154 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
128 } 155 }
  156 + if err := transactionContext.StartTransaction(); err != nil {
  157 + return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  158 + }
  159 + defer func() {
  160 + _ = transactionContext.RollbackTransaction()
  161 + }()
  162 + userRepo := factory.CreateUserRepository(map[string]interface{}{
  163 + "transactionContext": transactionContext,
  164 + })
  165 + _, userList, err := userRepo.Find(map[string]interface{}{
  166 + "ids": param.Uids,
  167 + "limit": len(param.Uids),
  168 + })
  169 + if err != nil {
  170 + return err
  171 + }
  172 + for i := range userList {
  173 + userList[i].Status = param.Status
  174 + _, err = userRepo.Update(userList[i])
  175 + if err != nil {
  176 + return err
  177 + }
  178 + }
  179 + if err := transactionContext.CommitTransaction(); err != nil {
  180 + return err
  181 + }
129 return nil 182 return nil
130 } 183 }
131 184
132 -func (srv UserService) setCompanyCharge(param *command.ChangeAdminCommand) error { 185 +//importUser
  186 +//从BusinessAdmins 接收消息 导入用户数据
  187 +//module="employee" action="import"
  188 +func (srv SyncDataUserService) importUser(param command.ImportUserCommand) error {
133 transactionContext, err := factory.CreateTransactionContext(nil) 189 transactionContext, err := factory.CreateTransactionContext(nil)
134 if err != nil { 190 if err != nil {
135 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 191 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -140,9 +196,64 @@ func (srv UserService) setCompanyCharge(param *command.ChangeAdminCommand) error @@ -140,9 +196,64 @@ func (srv UserService) setCompanyCharge(param *command.ChangeAdminCommand) error
140 defer func() { 196 defer func() {
141 _ = transactionContext.RollbackTransaction() 197 _ = transactionContext.RollbackTransaction()
142 }() 198 }()
  199 + userRepo := factory.CreateUserRepository(map[string]interface{}{
  200 + "transactionContext": transactionContext,
  201 + })
143 202
  203 + editUserMap := map[int64]command.SaveUserCommand{}
  204 + var editUserIds []int64
  205 + for i := range param.EditUsers {
  206 + editUserIds = append(editUserIds, param.EditUsers[i].Id)
  207 + editUserMap[param.EditUsers[i].Id] = param.EditUsers[i]
  208 + }
  209 + _, editUserList, err := userRepo.Find(map[string]interface{}{
  210 + "ids": editUserIds,
  211 + })
  212 + if err != nil {
  213 + return err
  214 + }
  215 + nowTime := time.Now()
  216 + for i := range editUserList {
  217 + mVal, ok := editUserMap[editUserList[i].Id]
  218 + if !ok {
  219 + continue
  220 + }
  221 + editUserList[i].Account = mVal.Phone
  222 + editUserList[i].AdminType = mVal.AdminType
  223 + editUserList[i].AvatarUrl = mVal.Avatar
  224 + editUserList[i].Name = mVal.Name
  225 + editUserList[i].Status = mVal.Status
  226 + editUserList[i].CompanyId = mVal.CompanyId
  227 + editUserList[i].UpdateAt = nowTime
  228 + _, err = userRepo.Update(editUserList[i])
  229 + if err != nil {
  230 + return err
  231 + }
  232 + }
  233 + var (
  234 + tempUser domain.User
  235 + )
  236 + for i := range param.AddUsers {
  237 + tempUser = domain.User{
  238 + Id: param.AddUsers[i].Id,
  239 + Account: param.AddUsers[i].Phone,
  240 + AvatarUrl: param.AddUsers[i].Avatar,
  241 + CompanyId: param.AddUsers[i].CompanyId,
  242 + AdminType: param.AddUsers[i].AdminType,
  243 + Name: param.AddUsers[i].Name,
  244 + Status: param.AddUsers[i].Status,
  245 + UpdateAt: nowTime,
  246 + DeleteAt: nil,
  247 + CreateAt: nowTime,
  248 + }
  249 + _, err := userRepo.Insert(&tempUser)
  250 + if err != nil {
  251 + return err
  252 + }
  253 + }
144 if err := transactionContext.CommitTransaction(); err != nil { 254 if err := transactionContext.CommitTransaction(); err != nil {
145 - return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 255 + return err
146 } 256 }
  257 +
147 return nil 258 return nil
148 } 259 }
@@ -4,7 +4,7 @@ package constant @@ -4,7 +4,7 @@ package constant
4 4
5 import "os" 5 import "os"
6 6
7 -var KAFKA_HOSTS = "" // 1.116.151.79:9092 7 +var KAFKA_HOSTS = "127.7.8.1:9094" // 1.116.151.79:9092
8 8
9 var KAFKA_GROUP_ID = "performance_dev" 9 var KAFKA_GROUP_ID = "performance_dev"
10 10
@@ -6,6 +6,7 @@ type Company struct { @@ -6,6 +6,7 @@ type Company struct {
6 Id int64 //公司编号 6 Id int64 //公司编号
7 Logo string //公司logo 7 Logo string //公司logo
8 Name string //公司名称 8 Name string //公司名称
  9 + ChargeUserIds []int64 //公司级别的部门主管uids
9 Status int //公司状态,1正常 2禁用 10 Status int //公司状态,1正常 2禁用
10 UpdateAt time.Time //更新时间 11 UpdateAt time.Time //更新时间
11 CreateAt time.Time //创建时间 12 CreateAt time.Time //创建时间
  1 +package domain
  2 +
  3 +import "time"
  4 +
  5 +type Department struct {
  6 + Id int64 // 组织id
  7 + CompanyId int64 // 公司编号
  8 + Level int // 组织级别
  9 + Name string // 组织名称
  10 + ParentId int64 // 组织父级id
  11 + ChargeUserIds []int64 // 主管uids
  12 + Path string // 组织路径
  13 + CreateAt time.Time // 创建时间
  14 + UpdateAt time.Time // 更新时间
  15 + DeleteAt *time.Time // 删除时间
  16 +}
  17 +type DepartmentRepository interface {
  18 + Insert(param *Department) (*Department, error)
  19 + Update(param *Department) (*Department, error)
  20 + Remove(param *Department) (*Department, error)
  21 + FindOne(queryOptions map[string]interface{}) (*Department, error)
  22 + Find(queryOptions map[string]interface{}) (int, []*Department, error)
  23 +}
1 -package domain  
2 -  
3 -import "time"  
4 -  
5 -type Organization struct {  
6 - OrganizationId int64 // 组织id  
7 - CompanyId int64 // 公司编号  
8 - OrganizationLevel int // 组织名称  
9 - OrganizationName string // 组织名称  
10 - OrganizationParentId int64 // 组织父级id  
11 - OrganizationPath []int64 // 组织路径  
12 - ChargeUserIds []int64 // 主管uids  
13 - Path string // 组织路径  
14 - CreateAt time.Time // 创建时间  
15 - UpdateAt time.Time // 更新时间  
16 -}  
@@ -15,10 +15,16 @@ type User struct { @@ -15,10 +15,16 @@ type User struct {
15 CreateAt time.Time 15 CreateAt time.Time
16 } 16 }
17 17
  18 +//1普通员工 2 主管理员
  19 +const (
  20 + UserTypeCommon int = 1
  21 + UserTypeManager int = 2
  22 +)
  23 +
18 type UserRepository interface { 24 type UserRepository interface {
19 Insert(user *User) (*User, error) 25 Insert(user *User) (*User, error)
20 Update(user *User) (*User, error) 26 Update(user *User) (*User, error)
21 - Remove(user *User) (*User, error) 27 + Remove(userId []int64) error
22 FindOne(queryOptions map[string]interface{}) (*User, error) 28 FindOne(queryOptions map[string]interface{}) (*User, error)
23 Find(queryOptions map[string]interface{}) (int, []*User, error) 29 Find(queryOptions map[string]interface{}) (int, []*User, error)
24 } 30 }
@@ -7,6 +7,7 @@ type Company struct { @@ -7,6 +7,7 @@ type Company struct {
7 Id int64 `pg:"pk:id"` //公司id 7 Id int64 `pg:"pk:id"` //公司id
8 Logo string //公司logo 8 Logo string //公司logo
9 Name string //公司名称 9 Name string //公司名称
  10 + ChargeUserIds []int64 //公司级别的部门主管uids
10 Status int //公司状态,1正常 2禁用 11 Status int //公司状态,1正常 2禁用
11 UpdateAt time.Time //更新时间 12 UpdateAt time.Time //更新时间
12 CreateAt time.Time //创建时间 13 CreateAt time.Time //创建时间
  1 +package models
  2 +
  3 +import (
  4 + "time"
  5 +)
  6 +
  7 +type Department struct {
  8 + tableName struct{} `pg:"department"`
  9 + Id int64 `pg:"pk:id"` // 组织id
  10 + CompanyId int64 // 公司编号
  11 + Level int // 组织级别
  12 + Name string // 组织名称
  13 + ParentId int64 // 组织父级id
  14 + ChargeUserIds []int64 // 主管uids
  15 + Path string // 组织路径
  16 + CreateAt time.Time // 创建时间
  17 + UpdateAt time.Time // 更新时间
  18 + DeleteAt *time.Time // 删除时间
  19 +}
@@ -27,6 +27,7 @@ func (repo *CompanyRepository) Insert(u *domain.Company) (*domain.Company, error @@ -27,6 +27,7 @@ func (repo *CompanyRepository) Insert(u *domain.Company) (*domain.Company, error
27 Logo: u.Logo, 27 Logo: u.Logo,
28 Name: u.Name, 28 Name: u.Name,
29 Status: u.Status, 29 Status: u.Status,
  30 + ChargeUserIds: u.ChargeUserIds,
30 UpdateAt: u.UpdateAt, 31 UpdateAt: u.UpdateAt,
31 CreateAt: u.CreateAt, 32 CreateAt: u.CreateAt,
32 DeleteAt: u.DeleteAt, 33 DeleteAt: u.DeleteAt,
@@ -46,6 +47,7 @@ func (repo *CompanyRepository) Update(u *domain.Company) (*domain.Company, error @@ -46,6 +47,7 @@ func (repo *CompanyRepository) Update(u *domain.Company) (*domain.Company, error
46 Logo: u.Logo, 47 Logo: u.Logo,
47 Name: u.Name, 48 Name: u.Name,
48 Status: u.Status, 49 Status: u.Status,
  50 + ChargeUserIds: u.ChargeUserIds,
49 UpdateAt: u.UpdateAt, 51 UpdateAt: u.UpdateAt,
50 CreateAt: u.CreateAt, 52 CreateAt: u.CreateAt,
51 DeleteAt: u.DeleteAt, 53 DeleteAt: u.DeleteAt,
  1 +package repository
  2 +
  3 +import (
  4 + "time"
  5 +
  6 + "github.com/go-pg/pg/v10"
  7 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  8 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
  10 +)
  11 +
  12 +type DepartmentRepository struct {
  13 + transactionContext *pgTransaction.TransactionContext
  14 +}
  15 +
  16 +var _ domain.DepartmentRepository = (*DepartmentRepository)(nil)
  17 +
  18 +func NewDepartmentRepository(tx *pgTransaction.TransactionContext) *CompanyRepository {
  19 + return &CompanyRepository{
  20 + transactionContext: tx,
  21 + }
  22 +}
  23 +
  24 +func (repo *DepartmentRepository) Insert(u *domain.Department) (*domain.Department, error) {
  25 + departmentModel := models.Department{
  26 + Id: u.Id,
  27 + CompanyId: u.CompanyId,
  28 + Level: u.Level,
  29 + Name: u.Name,
  30 + ParentId: u.ParentId,
  31 + ChargeUserIds: u.ChargeUserIds,
  32 + Path: u.Path,
  33 + CreateAt: u.CreateAt,
  34 + UpdateAt: u.UpdateAt,
  35 + DeleteAt: nil,
  36 + }
  37 + tx := repo.transactionContext.PgTx
  38 + _, err := tx.Model(&departmentModel).Insert()
  39 + if err != nil {
  40 + return nil, err
  41 + }
  42 + u.Id = departmentModel.Id
  43 + return u, nil
  44 +}
  45 +
  46 +func (repo *DepartmentRepository) Update(u *domain.Department) (*domain.Department, error) {
  47 + departmentModel := models.Department{
  48 + Id: u.Id,
  49 + CompanyId: u.CompanyId,
  50 + Level: u.Level,
  51 + Name: u.Name,
  52 + ParentId: u.ParentId,
  53 + ChargeUserIds: u.ChargeUserIds,
  54 + Path: u.Path,
  55 + CreateAt: u.CreateAt,
  56 + UpdateAt: u.UpdateAt,
  57 + DeleteAt: nil,
  58 + }
  59 + tx := repo.transactionContext.PgTx
  60 + _, err := tx.Model(&departmentModel).WherePK().Update()
  61 + if err != nil {
  62 + return nil, err
  63 + }
  64 + return u, nil
  65 +}
  66 +
  67 +func (repo *DepartmentRepository) Remove(u *domain.Department) (*domain.Department, error) {
  68 + nowTime := time.Now()
  69 + u.DeleteAt = &nowTime
  70 + _, err := repo.Update(u)
  71 + return u, err
  72 +}
  73 +
  74 +func (repo *DepartmentRepository) FindOne(queryOptions map[string]interface{}) (*domain.Department, error) {
  75 + tx := repo.transactionContext.PgTx
  76 + departmentModel := models.Department{}
  77 + query := tx.Model(&departmentModel)
  78 + if v, ok := queryOptions["id"]; ok {
  79 + query.Where("id=?", v)
  80 + }
  81 + err := query.First()
  82 + if err == pg.ErrNoRows {
  83 + return nil, ErrNoRows
  84 + }
  85 + if err != nil {
  86 + return nil, err
  87 + }
  88 + result := repo.TransformToCompanyDomain(&departmentModel)
  89 + return result, nil
  90 +}
  91 +
  92 +func (repo *DepartmentRepository) Find(queryOptions map[string]interface{}) (int, []*domain.Department, error) {
  93 + tx := repo.transactionContext.PgTx
  94 + dparmentModel := []models.Department{}
  95 + query := tx.Model(&dparmentModel).
  96 + Limit(20)
  97 + if v, ok := queryOptions["id"]; ok {
  98 + query.Where("id=?", v)
  99 + }
  100 + if v, ok := queryOptions["limit"]; ok {
  101 + query.Limit(v.(int))
  102 + }
  103 + if v, ok := queryOptions["offset"]; ok {
  104 + query.Offset(v.(int))
  105 + }
  106 + cnt, err := query.SelectAndCount()
  107 + if err != nil {
  108 + return 0, nil, err
  109 + }
  110 + var resultList []*domain.Department
  111 + for i := range dparmentModel {
  112 + result := repo.TransformToCompanyDomain(&dparmentModel[i])
  113 + resultList = append(resultList, result)
  114 + }
  115 + return cnt, resultList, nil
  116 +}
  117 +
  118 +func (repo *DepartmentRepository) TransformToCompanyDomain(u *models.Department) *domain.Department {
  119 + return &domain.Department{
  120 + Id: u.Id,
  121 + CompanyId: u.CompanyId,
  122 + Level: u.Level,
  123 + Name: u.Name,
  124 + ParentId: u.ParentId,
  125 + ChargeUserIds: u.ChargeUserIds,
  126 + Path: u.Path,
  127 + CreateAt: u.CreateAt,
  128 + UpdateAt: u.UpdateAt,
  129 + DeleteAt: u.DeleteAt,
  130 + }
  131 +}
@@ -64,11 +64,15 @@ func (repo *UserRepository) Update(user *domain.User) (*domain.User, error) { @@ -64,11 +64,15 @@ func (repo *UserRepository) Update(user *domain.User) (*domain.User, error) {
64 return user, nil 64 return user, nil
65 } 65 }
66 66
67 -func (repo *UserRepository) Remove(user *domain.User) (*domain.User, error) { 67 +func (repo *UserRepository) Remove(userId []int64) error {
68 nowTime := time.Now() 68 nowTime := time.Now()
69 - user.DeleteAt = &nowTime  
70 - _, err := repo.Update(user)  
71 - return user, err 69 + tx := repo.transactionContext.PgTx
  70 + uModel := models.User{}
  71 + _, err := tx.Model(&uModel).
  72 + Set("delete_at", nowTime).
  73 + Where("id in (?)", pg.In(userId)).
  74 + Update()
  75 + return err
72 } 76 }
73 77
74 func (repo *UserRepository) FindOne(queryOptions map[string]interface{}) (*domain.User, error) { 78 func (repo *UserRepository) FindOne(queryOptions map[string]interface{}) (*domain.User, error) {
@@ -92,17 +96,29 @@ func (repo *UserRepository) FindOne(queryOptions map[string]interface{}) (*domai @@ -92,17 +96,29 @@ func (repo *UserRepository) FindOne(queryOptions map[string]interface{}) (*domai
92 func (repo *UserRepository) Find(queryOptions map[string]interface{}) (int, []*domain.User, error) { 96 func (repo *UserRepository) Find(queryOptions map[string]interface{}) (int, []*domain.User, error) {
93 tx := repo.transactionContext.PgTx 97 tx := repo.transactionContext.PgTx
94 userModel := []models.User{} 98 userModel := []models.User{}
95 - query := tx.Model(&userModel). 99 + query := tx.Model(&userModel).Where("delete_at isnull").
96 Limit(20) 100 Limit(20)
97 if v, ok := queryOptions["id"]; ok { 101 if v, ok := queryOptions["id"]; ok {
98 query.Where("id=?", v) 102 query.Where("id=?", v)
99 } 103 }
100 - if v, ok := queryOptions["limit"]; ok {  
101 - query.Limit(v.(int)) 104 + if v, ok := queryOptions["ids"]; ok {
  105 + query.Where("id in(?)", pg.In(v))
  106 + }
  107 + if v, ok := queryOptions["companyId"]; ok {
  108 + query.Where("company_id=?", v)
  109 + }
  110 + if v, ok := queryOptions["adminType"]; ok {
  111 + query.Where("admin_type=?", v)
  112 + }
  113 + if v, ok := queryOptions["account"]; ok {
  114 + query.Where("account like ?", v)
102 } 115 }
103 if v, ok := queryOptions["offset"]; ok { 116 if v, ok := queryOptions["offset"]; ok {
104 query.Offset(v.(int)) 117 query.Offset(v.(int))
105 } 118 }
  119 + if v, ok := queryOptions["limit"]; ok {
  120 + query.Limit(v.(int))
  121 + }
106 cnt, err := query.SelectAndCount() 122 cnt, err := query.SelectAndCount()
107 if err != nil { 123 if err != nil {
108 return 0, nil, err 124 return 0, nil, err
@@ -10,7 +10,9 @@ import ( @@ -10,7 +10,9 @@ import (
10 func Run() { 10 func Run() {
11 messageHandlerMap := make(map[string]func(message *sarama.ConsumerMessage) error) 11 messageHandlerMap := make(map[string]func(message *sarama.ConsumerMessage) error)
12 messageHandlerMap["demo-v1"] = Demo 12 messageHandlerMap["demo-v1"] = Demo
13 - saramaConsumer.StartConsume(constant.KAFKA_HOSTS, constant.SERVICE_NAME, messageHandlerMap, log.Logger) 13 +
  14 + err := saramaConsumer.StartConsume(constant.KAFKA_HOSTS, constant.SERVICE_NAME, messageHandlerMap, log.Logger)
  15 + log.Logger.Error(err.Error())
14 } 16 }
15 17
16 func Demo(message *sarama.ConsumerMessage) error { 18 func Demo(message *sarama.ConsumerMessage) error {