...
|
...
|
@@ -4,6 +4,12 @@ import ( |
|
|
"encoding/json"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
"time"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/dao"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
|
|
|
)
|
|
|
|
|
|
// UserDepartData 用户的部门数据
|
...
|
...
|
@@ -47,12 +53,32 @@ type EmployeeData struct { |
|
|
UserPositions []UserPositionData `json:"user_positions"`
|
|
|
}
|
|
|
|
|
|
//DeleteUserData 批量删除用户
|
|
|
type DeleteUserData struct {
|
|
|
CompanyId int64 `json:"companyId"`
|
|
|
Ids []int64 `json:"ids"`
|
|
|
}
|
|
|
|
|
|
//ForbidAllowUserData 禁用启用用户
|
|
|
type ForbidAllowUserData struct {
|
|
|
CompanyId int64 `json:"companyId"`
|
|
|
Ids []int64 `json:"ids"`
|
|
|
Status int8 `json:"status"`
|
|
|
}
|
|
|
|
|
|
//ImportEmployeeData 批量导入用户
|
|
|
type ImportEmployeeData struct {
|
|
|
Add []EmployeeData `json:"add"`
|
|
|
Edit []EmployeeData `json:"edit"`
|
|
|
}
|
|
|
|
|
|
//SyncEmployeeService 同步用户数据
|
|
|
type SyncEmployeeService struct{}
|
|
|
|
|
|
func (service SyncEmployeeService) DoAction(action string, byteData []byte) error {
|
|
|
switch action {
|
|
|
case "add":
|
|
|
//添加
|
|
|
var (
|
|
|
data EmployeeData
|
|
|
err error
|
...
|
...
|
@@ -61,9 +87,10 @@ func (service SyncEmployeeService) DoAction(action string, byteData []byte) erro |
|
|
if err != nil {
|
|
|
return fmt.Errorf("数据解析失败:%s", err)
|
|
|
}
|
|
|
err = service.AddEmployeeData(data)
|
|
|
err = service.addEmployeeData(data)
|
|
|
return err
|
|
|
case "edit":
|
|
|
//编辑更新
|
|
|
var (
|
|
|
data EmployeeData
|
|
|
err error
|
...
|
...
|
@@ -72,23 +99,195 @@ func (service SyncEmployeeService) DoAction(action string, byteData []byte) erro |
|
|
if err != nil {
|
|
|
return fmt.Errorf("数据解析失败:%s", err)
|
|
|
}
|
|
|
err = service.UpdateEmployeeData(data)
|
|
|
err = service.updateEmployeeData(data)
|
|
|
return err
|
|
|
case "batchDelete":
|
|
|
//批量删除
|
|
|
var (
|
|
|
err error
|
|
|
data DeleteUserData
|
|
|
)
|
|
|
err = json.Unmarshal(byteData, &data)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("数据解析失败:%s", err)
|
|
|
}
|
|
|
return service.deleteEmployeeData(data)
|
|
|
case "batchForbid":
|
|
|
//启用禁用
|
|
|
var (
|
|
|
err error
|
|
|
data ForbidAllowUserData
|
|
|
)
|
|
|
err = json.Unmarshal(byteData, &data)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("数据解析失败:%s", err)
|
|
|
}
|
|
|
return service.updateUsersStatus(data)
|
|
|
|
|
|
case "batchRemove":
|
|
|
//移动通讯录用户部门 暂时不需要
|
|
|
return nil
|
|
|
case "import":
|
|
|
//批量导入
|
|
|
var (
|
|
|
data ImportEmployeeData
|
|
|
err error
|
|
|
)
|
|
|
err = json.Unmarshal(byteData, &data)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("数据解析失败:%s", err)
|
|
|
}
|
|
|
// service.addEmployeeData(data.Add)
|
|
|
// for i := range data.Edit {
|
|
|
// UpdateEmployeeData(data.Edit[i])
|
|
|
// }
|
|
|
return nil
|
|
|
|
|
|
default:
|
|
|
return errors.New("action not found")
|
|
|
return errors.New("nothing todo")
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func (service SyncEmployeeService) AddEmployeeData(data EmployeeData) error {
|
|
|
func (service SyncEmployeeService) addEmployeeData(data EmployeeData) error {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
|
|
)
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var usersRepository domain.UsersRepository
|
|
|
if usersRepository, err = factory.CreateUsersRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
newUser := domain.Users{
|
|
|
Id: data.Id,
|
|
|
CompanyId: data.CompanyId,
|
|
|
OpenId: data.OpenId,
|
|
|
Name: data.Name,
|
|
|
Sex: data.Sex,
|
|
|
JobNum: data.JobNum,
|
|
|
Phone: data.Phone,
|
|
|
PrivatePhone: data.PrivatePhone,
|
|
|
Email: data.Email,
|
|
|
ExtensionNum: data.ExtensionNum,
|
|
|
Workspace: data.WorkSpace,
|
|
|
Status: data.Status,
|
|
|
Avatar: data.Avatar,
|
|
|
Remarks: data.Remarks,
|
|
|
ChargeStatus: data.ChargeStatus,
|
|
|
Permission: []domain.AdminPermissionBase{}, //权限
|
|
|
AccessPartners: []domain.Partner{},
|
|
|
}
|
|
|
newUser.EntryTime, _ = time.Parse("2006-01-02", data.EntryTime)
|
|
|
if err = usersRepository.Add(&newUser); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
return nil
|
|
|
func (service SyncEmployeeService) updateEmployeeData(data EmployeeData) error {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
|
|
)
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var usersRepository domain.UsersRepository
|
|
|
if usersRepository, err = factory.CreateUsersRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
var oldUser domain.Users
|
|
|
oldUser, err = usersRepository.FindOne(domain.UsersFindOneQuery{
|
|
|
Id: data.Id,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
entryTime, _ := time.Parse("2006-01-02", data.EntryTime)
|
|
|
_ = oldUser.Update(map[string]interface{}{
|
|
|
"Id": data.Id,
|
|
|
"CompanyId": data.CompanyId,
|
|
|
"OpenId": data.OpenId,
|
|
|
"Name": data.Name,
|
|
|
"Sex": data.Sex,
|
|
|
"JobNum": data.JobNum,
|
|
|
"Phone": data.Phone,
|
|
|
"PrivatePhone": data.PrivatePhone,
|
|
|
"Email": data.Email,
|
|
|
"ExtensionNum": data.ExtensionNum,
|
|
|
"Workspace": data.WorkSpace,
|
|
|
"Status": data.Status,
|
|
|
"Avatar": data.Avatar,
|
|
|
"Remarks": data.Remarks,
|
|
|
"ChargeStatus": data.ChargeStatus,
|
|
|
"EntryTime": entryTime,
|
|
|
})
|
|
|
if err = usersRepository.Edit(&oldUser); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
func (service SyncEmployeeService) UpdateEmployeeData(data EmployeeData) error {
|
|
|
return nil
|
|
|
func (service SyncEmployeeService) deleteEmployeeData(data DeleteUserData) error {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
|
|
)
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var usersRepository domain.UsersRepository
|
|
|
if usersRepository, err = factory.CreateUsersRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if err = usersRepository.Remove(data.Ids); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
//UpdateUsersStatus 批量更新用户的状态
|
|
|
func (service SyncEmployeeService) updateUsersStatus(data ForbidAllowUserData) error {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
|
|
)
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var uDao *dao.UsersDao
|
|
|
if uDao, err = factory.CreateUsersDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if err = uDao.UpdateUserStatus(data.Ids, data.Status); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return err
|
|
|
} |
...
|
...
|
|