作者 linmadan

添加同步企业用户平台接口

  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type SyncEmployeeCallbackCommand struct {
  9 + // position:职位,department:部门,employee:员工,company:公司,profile员工档案
  10 + Module string `json:"module" valid:"Required"`
  11 + // add:添加,edit:编辑,delete删除,batchDelete:批量删除,setCompanyCharge:更改公司主管,batchForbid:批量禁用用户,batchRemove:批量更改用户部门,changeAdmin换管理员
  12 + Action string `json:"action" valid:"Required"`
  13 + // 具体的对象JSON数据
  14 + Data string `json:"data" valid:"Required"`
  15 +}
  16 +
  17 +func (syncEmployeeCallbackCommand *SyncEmployeeCallbackCommand) ValidateCommand() error {
  18 + valid := validation.Validation{}
  19 + b, err := valid.Valid(syncEmployeeCallbackCommand)
  20 + if err != nil {
  21 + return err
  22 + }
  23 + if !b {
  24 + for _, validErr := range valid.Errors {
  25 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  26 + }
  27 + }
  28 + return nil
  29 +}
  1 +package service
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
  7 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/unifiedUserCenter/command"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
  10 +)
  11 +
  12 +// 统一用户中心适配服务
  13 +type UnifiedUserCenterService struct {
  14 +}
  15 +
  16 +// 同步企业员工回调
  17 +func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(syncEmployeeCallbackCommand *command.SyncEmployeeCallbackCommand) (interface{}, error) {
  18 + if err := syncEmployeeCallbackCommand.ValidateCommand(); err != nil {
  19 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  20 + }
  21 + transactionContext, err := factory.CreateTransactionContext(nil)
  22 + if err != nil {
  23 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  24 + }
  25 + if err := transactionContext.StartTransaction(); err != nil {
  26 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  27 + }
  28 + defer func() {
  29 + transactionContext.RollbackTransaction()
  30 + }()
  31 + var employeeRepository domain.EmployeeRepository
  32 + if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
  33 + "transactionContext": transactionContext,
  34 + }); err != nil {
  35 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  36 + } else {
  37 + employeeRepository = value
  38 + }
  39 + var employeeDao *dao.EmployeeDao
  40 + if value, err := factory.CreateEmployeeDao(map[string]interface{}{
  41 + "transactionContext": transactionContext,
  42 + }); err != nil {
  43 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  44 + } else {
  45 + employeeDao = value
  46 + }
  47 + var companyId int64
  48 + var uid int64
  49 + var employeeName string
  50 + var employeeAccount string
  51 + var employeeAvatarUrl string
  52 + var isPrincipal bool
  53 + var status int
  54 + var uids []int64
  55 + var data map[string]interface{}
  56 + if err := json.Unmarshal([]byte(syncEmployeeCallbackCommand.Data), &data); err != nil {
  57 + return false, err
  58 + }
  59 + if value, ok := data["company_id"]; ok {
  60 + companyId = int64(value.(float64))
  61 + }
  62 + if value, ok := data["id"]; ok {
  63 + uid = int64(value.(float64))
  64 + }
  65 + if value, ok := data["name"]; ok {
  66 + employeeName = value.(string)
  67 + }
  68 + if value, ok := data["phone"]; ok {
  69 + employeeAccount = value.(string)
  70 + }
  71 + if value, ok := data["avatar"]; ok {
  72 + employeeAvatarUrl = value.(string)
  73 + }
  74 + if value, ok := data["admin_type"]; ok {
  75 + if int(value.(float64)) == 2 {
  76 + isPrincipal = true
  77 + } else {
  78 + isPrincipal = false
  79 + }
  80 + }
  81 + if value, ok := data["status"]; ok {
  82 + status = int(value.(float64))
  83 + }
  84 + if value, ok := data["ids"]; ok {
  85 + for _, uid := range value.([]interface{}) {
  86 + uids = append(uids, int64(uid.(float64)))
  87 + }
  88 + }
  89 + if syncEmployeeCallbackCommand.Module == "employee" {
  90 + switch syncEmployeeCallbackCommand.Action {
  91 + case "add":
  92 + employee := &domain.Employee{
  93 + CompanyId: companyId,
  94 + EmployeeInfo: &domain.EmployeeInfo{
  95 + Uid: uid,
  96 + EmployeeName: employeeName,
  97 + EmployeeAccount: employeeAccount,
  98 + EmployeeAvatarUrl: employeeAvatarUrl,
  99 + IsPrincipal: isPrincipal,
  100 + },
  101 + Status: status,
  102 + SuMoney: 0,
  103 + }
  104 + if _, err := employeeRepository.Save(employee); err != nil {
  105 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  106 + }
  107 + break
  108 + case "edit":
  109 + employee, err := employeeRepository.FindOne(map[string]interface{}{"uid": uid})
  110 + if err != nil {
  111 + return false, nil
  112 + }
  113 + if employee == nil {
  114 + return false, nil
  115 + }
  116 + updateData := make(map[string]interface{})
  117 + updateData["employeeName"] = employeeName
  118 + updateData["employeeAccount"] = employeeAccount
  119 + updateData["employeeAvatarUrl"] = employeeAvatarUrl
  120 + updateData["isPrincipal"] = isPrincipal
  121 + updateData["status"] = status
  122 + if err := employee.Update(updateData); err != nil {
  123 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  124 + }
  125 + if _, err := employeeRepository.Save(employee); err != nil {
  126 + return false, nil
  127 + }
  128 + break
  129 + case "batchDelete":
  130 + err := employeeDao.BatchRemove(uids)
  131 + if err != nil {
  132 + return false, nil
  133 + }
  134 + break
  135 + case "batchForbid":
  136 + err := employeeDao.BatchSetStatus(uids, status)
  137 + if err != nil {
  138 + return false, nil
  139 + }
  140 + break
  141 + default:
  142 + return false, nil
  143 + }
  144 + if err := transactionContext.CommitTransaction(); err != nil {
  145 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  146 + }
  147 + return true, nil
  148 + } else if syncEmployeeCallbackCommand.Module == "company" {
  149 + switch syncEmployeeCallbackCommand.Action {
  150 + case "changeAdmin":
  151 + err := employeeDao.ChangePrincipal(companyId, employeeAccount)
  152 + if err != nil {
  153 + return false, nil
  154 + }
  155 + break
  156 + default:
  157 + return false, nil
  158 + }
  159 + return true, nil
  160 + } else {
  161 + return false, nil
  162 + }
  163 +}
  164 +
  165 +func NewUnifiedUserCenterService(options map[string]interface{}) *UnifiedUserCenterService {
  166 + newUnifiedUserCenterService := &UnifiedUserCenterService{}
  167 + return newUnifiedUserCenterService
  168 +}
@@ -37,6 +37,12 @@ func (employee *Employee) Update(data map[string]interface{}) error { @@ -37,6 +37,12 @@ func (employee *Employee) Update(data map[string]interface{}) error {
37 if employeeAccount, ok := data["employeeAccount"]; ok && employeeAccount != "" { 37 if employeeAccount, ok := data["employeeAccount"]; ok && employeeAccount != "" {
38 employee.EmployeeInfo.EmployeeAccount = employeeAccount.(string) 38 employee.EmployeeInfo.EmployeeAccount = employeeAccount.(string)
39 } 39 }
  40 + if employeeAvatarUrl, ok := data["employeeAvatarUrl"]; ok && employeeAvatarUrl != "" {
  41 + employee.EmployeeInfo.EmployeeAvatarUrl = employeeAvatarUrl.(string)
  42 + }
  43 + if isPrincipal, ok := data["isPrincipal"]; ok {
  44 + employee.EmployeeInfo.IsPrincipal = isPrincipal.(bool)
  45 + }
40 if status, ok := data["status"]; ok && status != 0 { 46 if status, ok := data["status"]; ok && status != 0 {
41 employee.Status = status.(int) 47 employee.Status = status.(int)
42 } 48 }
@@ -10,4 +10,6 @@ type EmployeeInfo struct { @@ -10,4 +10,6 @@ type EmployeeInfo struct {
10 EmployeeAccount string `json:"employeeAccount"` 10 EmployeeAccount string `json:"employeeAccount"`
11 // 员工头像URL 11 // 员工头像URL
12 EmployeeAvatarUrl string `json:"employeeAvatarUrl"` 12 EmployeeAvatarUrl string `json:"employeeAvatarUrl"`
  13 + // 是否公司负责人
  14 + IsPrincipal bool `json:"isPrincipal"`
13 } 15 }
@@ -12,6 +12,41 @@ type EmployeeDao struct { @@ -12,6 +12,41 @@ type EmployeeDao struct {
12 transactionContext *pgTransaction.TransactionContext 12 transactionContext *pgTransaction.TransactionContext
13 } 13 }
14 14
  15 +func (dao *EmployeeDao) BatchRemove(uids []int64) error {
  16 + tx := dao.transactionContext.PgTx
  17 + _, err := tx.QueryOne(
  18 + pg.Scan(),
  19 + "DELETE FROM employees WHERE uid IN (?)",
  20 + pg.In(uids))
  21 + return err
  22 +}
  23 +
  24 +func (dao *EmployeeDao) BatchSetStatus(uids []int64, status int) error {
  25 + tx := dao.transactionContext.PgTx
  26 + _, err := tx.QueryOne(
  27 + pg.Scan(),
  28 + "UPDATE employees SET status=? WHERE uid IN (?)",
  29 + status, pg.In(uids))
  30 + return err
  31 +}
  32 +
  33 +func (dao *EmployeeDao) ChangePrincipal(companyId int64, employeeAccount string) error {
  34 + tx := dao.transactionContext.PgTx
  35 + if _, err := tx.QueryOne(
  36 + pg.Scan(),
  37 + "UPDATE employees SET is_principal=? WHERE company_id=?",
  38 + false, companyId); err != nil {
  39 + return err
  40 + }
  41 + if _, err := tx.QueryOne(
  42 + pg.Scan(),
  43 + "UPDATE employees SET is_principal=? WHERE company_id=? AND employee_account=?",
  44 + true, companyId, employeeAccount); err != nil {
  45 + return err
  46 + }
  47 + return nil
  48 +}
  49 +
15 func (dao *EmployeeDao) TransferSuMoney(uid int64, suMoney float64) error { 50 func (dao *EmployeeDao) TransferSuMoney(uid int64, suMoney float64) error {
16 tx := dao.transactionContext.PgTx 51 tx := dao.transactionContext.PgTx
17 _, err := tx.QueryOne( 52 _, err := tx.QueryOne(
@@ -44,7 +79,7 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{ @@ -44,7 +79,7 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{
44 return nil, err 79 return nil, err
45 } 80 }
46 return map[string]interface{}{ 81 return map[string]interface{}{
47 - "incomeSuMoney": incomeSuMoney, 82 + "incomeSuMoney": incomeSuMoney,
48 "incomeSuMoneyOfYesterday": incomeSuMoneyOfYesterday, 83 "incomeSuMoneyOfYesterday": incomeSuMoneyOfYesterday,
49 }, nil 84 }, nil
50 } 85 }
@@ -14,10 +14,12 @@ type Employee struct { @@ -14,10 +14,12 @@ type Employee struct {
14 EmployeeAccount string 14 EmployeeAccount string
15 // 员工头像URL 15 // 员工头像URL
16 EmployeeAvatarUrl string 16 EmployeeAvatarUrl string
  17 + // 是否公司负责人
  18 + IsPrincipal bool `pg:",notnull,default:false"`
17 // 当前素币 19 // 当前素币
18 - SuMoney float64 20 + SuMoney float64 `pg:",notnull,default:0"`
19 // 员工状态(启用或者禁用) 21 // 员工状态(启用或者禁用)
20 - Status int 22 + Status int `pg:",notnull,default:1"`
21 // 员工权限集合 23 // 员工权限集合
22 Permissions []int `pg:",array"` 24 Permissions []int `pg:",array"`
23 } 25 }
@@ -30,16 +30,16 @@ func (repository *EmployeeRepository) Save(employee *domain.Employee) (*domain.E @@ -30,16 +30,16 @@ func (repository *EmployeeRepository) Save(employee *domain.Employee) (*domain.E
30 return employee, err 30 return employee, err
31 } 31 }
32 if _, err := tx.QueryOne( 32 if _, err := tx.QueryOne(
33 - pg.Scan(&employee.EmployeeId, &employee.CompanyId, &employee.EmployeeInfo.Uid, &employee.EmployeeInfo.EmployeeName, &employee.EmployeeInfo.EmployeeAccount, &employee.EmployeeInfo.EmployeeAvatarUrl, &employee.SuMoney, &employee.Status, pg.Array(&employee.Permissions)),  
34 - "INSERT INTO employees (id, company_id, uid, employee_name, employee_account, employee_avatar_url, su_money, status, permissions) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, company_id, uid, employee_name, employee_account, employee_avatar_url, su_money, status, permissions",  
35 - employee.EmployeeId, employee.CompanyId, employee.EmployeeInfo.Uid, employee.EmployeeInfo.EmployeeName, employee.EmployeeInfo.EmployeeAccount, employee.EmployeeInfo.EmployeeAvatarUrl, employee.SuMoney, employee.Status, pg.Array(employee.Permissions)); err != nil { 33 + pg.Scan(&employee.EmployeeId, &employee.CompanyId, &employee.EmployeeInfo.Uid, &employee.EmployeeInfo.EmployeeName, &employee.EmployeeInfo.EmployeeAccount, &employee.EmployeeInfo.EmployeeAvatarUrl, &employee.EmployeeInfo.IsPrincipal, &employee.SuMoney, &employee.Status, pg.Array(&employee.Permissions)),
  34 + "INSERT INTO employees (id, company_id, uid, employee_name, employee_account, employee_avatar_url, is_principal, su_money, status, permissions) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, company_id, uid, employee_name, employee_account, employee_avatar_url, is_principal, su_money, status, permissions",
  35 + employee.EmployeeId, employee.CompanyId, employee.EmployeeInfo.Uid, employee.EmployeeInfo.EmployeeName, employee.EmployeeInfo.EmployeeAccount, employee.EmployeeInfo.EmployeeAvatarUrl, employee.EmployeeInfo.IsPrincipal, employee.SuMoney, employee.Status, pg.Array(employee.Permissions)); err != nil {
36 return employee, err 36 return employee, err
37 } 37 }
38 } else { 38 } else {
39 if _, err := tx.QueryOne( 39 if _, err := tx.QueryOne(
40 - pg.Scan(&employee.EmployeeId, &employee.CompanyId, &employee.EmployeeInfo.Uid, &employee.EmployeeInfo.EmployeeName, &employee.EmployeeInfo.EmployeeAccount, &employee.EmployeeInfo.EmployeeAvatarUrl, &employee.SuMoney, &employee.Status, pg.Array(&employee.Permissions)),  
41 - "UPDATE employees SET employee_name=?, employee_account=?, employee_avatar_url=?, su_money=?, status=?, permissions=? WHERE uid=? RETURNING id, company_id, uid, employee_name, employee_account, employee_avatar_url, su_money, status, permissions",  
42 - employee.EmployeeInfo.EmployeeName, employee.EmployeeInfo.EmployeeAccount, &employee.EmployeeInfo.EmployeeAvatarUrl, employee.SuMoney, employee.Status, pg.Array(employee.Permissions), employee.EmployeeInfo.Uid); err != nil { 40 + pg.Scan(&employee.EmployeeId, &employee.CompanyId, &employee.EmployeeInfo.Uid, &employee.EmployeeInfo.EmployeeName, &employee.EmployeeInfo.EmployeeAccount, &employee.EmployeeInfo.EmployeeAvatarUrl, &employee.EmployeeInfo.IsPrincipal, &employee.SuMoney, &employee.Status, pg.Array(&employee.Permissions)),
  41 + "UPDATE employees SET employee_name=?, employee_account=?, employee_avatar_url=?, is_principal=?, su_money=?, status=?, permissions=? WHERE uid=? RETURNING id, company_id, uid, employee_name, employee_account, employee_avatar_url, is_principal, su_money, status, permissions",
  42 + employee.EmployeeInfo.EmployeeName, employee.EmployeeInfo.EmployeeAccount, &employee.EmployeeInfo.EmployeeAvatarUrl, employee.EmployeeInfo.IsPrincipal, employee.SuMoney, employee.Status, pg.Array(employee.Permissions), employee.EmployeeInfo.Uid); err != nil {
43 return employee, err 43 return employee, err
44 } 44 }
45 } 45 }
@@ -88,6 +88,12 @@ func (repository *EmployeeRepository) Find(queryOptions map[string]interface{}) @@ -88,6 +88,12 @@ func (repository *EmployeeRepository) Find(queryOptions map[string]interface{})
88 if employeeNameMatch, ok := queryOptions["employeeNameMatch"]; ok && (employeeNameMatch != "") { 88 if employeeNameMatch, ok := queryOptions["employeeNameMatch"]; ok && (employeeNameMatch != "") {
89 query = query.Where("employee.employee_name LIKE ?", fmt.Sprintf("%%%s%%", employeeNameMatch.(string))) 89 query = query.Where("employee.employee_name LIKE ?", fmt.Sprintf("%%%s%%", employeeNameMatch.(string)))
90 } 90 }
  91 + if status, ok := queryOptions["status"]; ok && (status != 0) {
  92 + query = query.Where(`employee.status = ?`, status)
  93 + }
  94 + if isPrincipal, ok := queryOptions["isPrincipal"]; ok && isPrincipal.(bool) != false {
  95 + query = query.Where("employee.is_principal = ? ", isPrincipal)
  96 + }
91 if offset, ok := queryOptions["offset"]; ok { 97 if offset, ok := queryOptions["offset"]; ok {
92 offset := offset.(int) 98 offset := offset.(int)
93 if offset > -1 { 99 if offset > -1 {
@@ -127,6 +133,7 @@ func (repository *EmployeeRepository) transformPgModelToDomainModel(employeeMode @@ -127,6 +133,7 @@ func (repository *EmployeeRepository) transformPgModelToDomainModel(employeeMode
127 EmployeeName: employeeModel.EmployeeName, 133 EmployeeName: employeeModel.EmployeeName,
128 EmployeeAccount: employeeModel.EmployeeAccount, 134 EmployeeAccount: employeeModel.EmployeeAccount,
129 EmployeeAvatarUrl: employeeModel.EmployeeAvatarUrl, 135 EmployeeAvatarUrl: employeeModel.EmployeeAvatarUrl,
  136 + IsPrincipal: employeeModel.IsPrincipal,
130 }, 137 },
131 SuMoney: employeeModel.SuMoney, 138 SuMoney: employeeModel.SuMoney,
132 Status: employeeModel.Status, 139 Status: employeeModel.Status,
  1 +package controllers
  2 +
  3 +import (
  4 + "encoding/json"
  5 +
  6 + "github.com/astaxie/beego"
  7 + "github.com/linmadan/egglib-go/web/beego/utils"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/unifiedUserCenter/command"
  9 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/unifiedUserCenter/service"
  10 +)
  11 +
  12 +type UnifiedUserCenterController struct {
  13 + beego.Controller
  14 +}
  15 +
  16 +func (controller *UnifiedUserCenterController) SyncEmployeeCallback() {
  17 + unifiedUserCenterService := service.NewUnifiedUserCenterService(nil)
  18 + syncEmployeeCallbackCommand := &command.SyncEmployeeCallbackCommand{}
  19 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), syncEmployeeCallbackCommand)
  20 + data, err := unifiedUserCenterService.SyncEmployeeCallback(syncEmployeeCallbackCommand)
  21 + var response utils.JsonResponse
  22 + if err != nil {
  23 + response = utils.ResponseError(controller.Ctx, err)
  24 + } else {
  25 + response = utils.ResponseData(controller.Ctx, data)
  26 + }
  27 + controller.Data["json"] = response
  28 + controller.ServeJSON()
  29 +}
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/astaxie/beego"
  5 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego/controllers"
  6 +)
  7 +
  8 +func init() {
  9 + beego.Router("/api/business/index", &controllers.UnifiedUserCenterController{}, "Post:SyncEmployeeCallback")
  10 +}
  1 +package unified_user_center
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + "github.com/go-pg/pg"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("同步企业员工回调", func() {
  14 + var employeeId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&employeeId),
  18 + "INSERT INTO employees (id, company_id, uid, employee_name, employee_account, employee_avatar_url, is_principal, su_money, status, permissions) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
  19 + 1, 101, 2499036607974745088, "employee_name", "13799999999", "employee_avatar_url", false, 1000.00, 1, pg.Array([]int{1, 3}))
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("同步企业员工回调", func() {
  23 + Context("同步添加企业员工", func() {
  24 + It("添加成功", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + body := map[string]interface{}{
  27 + "module": "employee",
  28 + "action": "add",
  29 + "data": `{
  30 + "id": 5040167991950442755,
  31 + "company_id": 1000,
  32 + "open_id": 0,
  33 + "name": "杨洲2",
  34 + "sex": 1,
  35 + "job_num": 59101419,
  36 + "phone": "15659781344",
  37 + "private_phone": "18050324007",
  38 + "email": "cczhang319@qq.com",
  39 + "extension_num": "0591-83845806",
  40 + "entry_time": "2020-02-10",
  41 + "workspace": "买买买",
  42 + "is_business": 1,
  43 + "status": 1,
  44 + "avatar": "http://suplus-business-admin-dev.fjmaimaimai.com//images/default_avatar.png",
  45 + "extra_text": "[]",
  46 + "remarks": "无",
  47 + "admin_type": 1,
  48 + "charge_status": 2,
  49 + "created_at": "2020-02-14 22:45:32",
  50 + "updated_at": "2020-02-14 22:45:32",
  51 + "deleted_at": null,
  52 + "user_departments": [
  53 + {
  54 + "id": 102,
  55 + "company_id": 1000,
  56 + "department_id": 0,
  57 + "user_id": 5040167991950442755,
  58 + "created_at": "2020-02-14 22:45:32",
  59 + "updated_at": "2020-02-14 22:45:32",
  60 + "deleted_at": null
  61 + },
  62 + {
  63 + "id": 103,
  64 + "company_id": 1000,
  65 + "department_id": 10,
  66 + "user_id": 5040167991950442755,
  67 + "created_at": "2020-02-14 22:45:32",
  68 + "updated_at": "2020-02-14 22:45:32",
  69 + "deleted_at": null
  70 + },
  71 + {
  72 + "id": 104,
  73 + "company_id": 1000,
  74 + "department_id": 11,
  75 + "user_id": 5040167991950442755,
  76 + "created_at": "2020-02-14 22:45:32",
  77 + "updated_at": "2020-02-14 22:45:32",
  78 + "deleted_at": null
  79 + },
  80 + {
  81 + "id": 105,
  82 + "company_id": 1000,
  83 + "department_id": 12,
  84 + "user_id": 5040167991950442755,
  85 + "created_at": "2020-02-14 22:45:32",
  86 + "updated_at": "2020-02-14 22:45:32",
  87 + "deleted_at": null
  88 + }
  89 + ],
  90 + "user_positions": [
  91 + {
  92 + "id": 28,
  93 + "company_id": 1000,
  94 + "position_id": 10,
  95 + "user_id": 5040167991950442755,
  96 + "created_at": "2020-02-14 22:45:32",
  97 + "updated_at": "2020-02-14 22:45:32",
  98 + "deleted_at": null
  99 + },
  100 + {
  101 + "id": 29,
  102 + "company_id": 1000,
  103 + "position_id": 11,
  104 + "user_id": 5040167991950442755,
  105 + "created_at": "2020-02-14 22:45:32",
  106 + "updated_at": "2020-02-14 22:45:32",
  107 + "deleted_at": null
  108 + },
  109 + {
  110 + "id": 30,
  111 + "company_id": 1000,
  112 + "position_id": 12,
  113 + "user_id": 5040167991950442755,
  114 + "created_at": "2020-02-14 22:45:32",
  115 + "updated_at": "2020-02-14 22:45:32",
  116 + "deleted_at": null
  117 + }
  118 + ],
  119 + "user_roles": [
  120 + {
  121 + "id": 32,
  122 + "role_id": 6,
  123 + "enable_status": 1,
  124 + "company_id": 1000,
  125 + "user_id": 5040167991950442755
  126 + },
  127 + {
  128 + "id": 33,
  129 + "role_id": 7,
  130 + "enable_status": 1,
  131 + "company_id": 1000,
  132 + "user_id": 5040167991950442755
  133 + }
  134 + ]
  135 + }`,
  136 + }
  137 + httpExpect.POST("/api/business/index").
  138 + WithJSON(body).
  139 + Expect().
  140 + Status(http.StatusOK).
  141 + JSON().
  142 + Object().
  143 + ContainsKey("code").ValueEqual("code", 0).
  144 + ContainsKey("msg").ValueEqual("msg", "ok").
  145 + ContainsKey("data").ValueEqual("data", true)
  146 + })
  147 + })
  148 + Context("同步更新企业员工", func() {
  149 + It("更新成功", func() {
  150 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  151 + body := map[string]interface{}{
  152 + "module": "employee",
  153 + "action": "edit",
  154 + "data": `{
  155 + "id": 2499036607974745088,
  156 + "company_id": 1000,
  157 + "open_id": 0,
  158 + "name": "杨洲2",
  159 + "sex": 1,
  160 + "job_num": 59101419,
  161 + "phone": "15659781344",
  162 + "private_phone": "18050324007",
  163 + "email": "cczhang319@qq.com",
  164 + "extension_num": "0591-83845806",
  165 + "entry_time": "2020-02-10",
  166 + "workspace": "买买买",
  167 + "is_business": 1,
  168 + "status": 1,
  169 + "avatar": "http://suplus-business-admin-dev.fjmaimaimai.com//images/default_avatar.png",
  170 + "extra_text": "[]",
  171 + "remarks": "无",
  172 + "admin_type": 1,
  173 + "charge_status": 2,
  174 + "created_at": "2020-02-14 22:45:32",
  175 + "updated_at": "2020-02-14 22:45:32",
  176 + "deleted_at": null,
  177 + "user_departments": [
  178 + {
  179 + "id": 102,
  180 + "company_id": 1000,
  181 + "department_id": 0,
  182 + "user_id": 5040167991950442755,
  183 + "created_at": "2020-02-14 22:45:32",
  184 + "updated_at": "2020-02-14 22:45:32",
  185 + "deleted_at": null
  186 + },
  187 + {
  188 + "id": 103,
  189 + "company_id": 1000,
  190 + "department_id": 10,
  191 + "user_id": 5040167991950442755,
  192 + "created_at": "2020-02-14 22:45:32",
  193 + "updated_at": "2020-02-14 22:45:32",
  194 + "deleted_at": null
  195 + },
  196 + {
  197 + "id": 104,
  198 + "company_id": 1000,
  199 + "department_id": 11,
  200 + "user_id": 5040167991950442755,
  201 + "created_at": "2020-02-14 22:45:32",
  202 + "updated_at": "2020-02-14 22:45:32",
  203 + "deleted_at": null
  204 + },
  205 + {
  206 + "id": 105,
  207 + "company_id": 1000,
  208 + "department_id": 12,
  209 + "user_id": 5040167991950442755,
  210 + "created_at": "2020-02-14 22:45:32",
  211 + "updated_at": "2020-02-14 22:45:32",
  212 + "deleted_at": null
  213 + }
  214 + ],
  215 + "user_positions": [
  216 + {
  217 + "id": 28,
  218 + "company_id": 1000,
  219 + "position_id": 10,
  220 + "user_id": 5040167991950442755,
  221 + "created_at": "2020-02-14 22:45:32",
  222 + "updated_at": "2020-02-14 22:45:32",
  223 + "deleted_at": null
  224 + },
  225 + {
  226 + "id": 29,
  227 + "company_id": 1000,
  228 + "position_id": 11,
  229 + "user_id": 5040167991950442755,
  230 + "created_at": "2020-02-14 22:45:32",
  231 + "updated_at": "2020-02-14 22:45:32",
  232 + "deleted_at": null
  233 + },
  234 + {
  235 + "id": 30,
  236 + "company_id": 1000,
  237 + "position_id": 12,
  238 + "user_id": 5040167991950442755,
  239 + "created_at": "2020-02-14 22:45:32",
  240 + "updated_at": "2020-02-14 22:45:32",
  241 + "deleted_at": null
  242 + }
  243 + ],
  244 + "user_roles": [
  245 + {
  246 + "id": 32,
  247 + "role_id": 6,
  248 + "enable_status": 1,
  249 + "company_id": 1000,
  250 + "user_id": 5040167991950442755
  251 + },
  252 + {
  253 + "id": 33,
  254 + "role_id": 7,
  255 + "enable_status": 1,
  256 + "company_id": 1000,
  257 + "user_id": 5040167991950442755
  258 + }
  259 + ]
  260 + }`,
  261 + }
  262 + httpExpect.POST("/api/business/index").
  263 + WithJSON(body).
  264 + Expect().
  265 + Status(http.StatusOK).
  266 + JSON().
  267 + Object().
  268 + ContainsKey("code").ValueEqual("code", 0).
  269 + ContainsKey("msg").ValueEqual("msg", "ok").
  270 + ContainsKey("data").ValueEqual("data", true)
  271 + })
  272 + })
  273 + Context("同步批量删除企业员工", func() {
  274 + It("删除成功", func() {
  275 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  276 + body := map[string]interface{}{
  277 + "module": "employee",
  278 + "action": "batchDelete",
  279 + "data": ` {
  280 + "ids": [
  281 + 2499036607974745088
  282 + ]
  283 + }`,
  284 + }
  285 + httpExpect.POST("/api/business/index").
  286 + WithJSON(body).
  287 + Expect().
  288 + Status(http.StatusOK).
  289 + JSON().
  290 + Object().
  291 + ContainsKey("code").ValueEqual("code", 0).
  292 + ContainsKey("msg").ValueEqual("msg", "ok").
  293 + ContainsKey("data").ValueEqual("data", true)
  294 + })
  295 + })
  296 + Context("同步批量设置企业员工状态", func() {
  297 + It("设置成功", func() {
  298 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  299 + body := map[string]interface{}{
  300 + "module": "employee",
  301 + "action": "batchForbid",
  302 + "data": ` {
  303 + "ids": [
  304 + 2499036607974745088
  305 + ],
  306 + "status": 2
  307 + }`,
  308 + }
  309 + httpExpect.POST("/api/business/index").
  310 + WithJSON(body).
  311 + Expect().
  312 + Status(http.StatusOK).
  313 + JSON().
  314 + Object().
  315 + ContainsKey("code").ValueEqual("code", 0).
  316 + ContainsKey("msg").ValueEqual("msg", "ok").
  317 + ContainsKey("data").ValueEqual("data", true)
  318 + })
  319 + })
  320 + Context("同步更换管理员", func() {
  321 + It("更换成功", func() {
  322 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  323 + body := map[string]interface{}{
  324 + "module": "company",
  325 + "action": "changeAdmin",
  326 + "data": ` {
  327 + "company_id": 101,
  328 + "phone": "13799999999"
  329 + }`,
  330 + }
  331 + httpExpect.POST("/api/business/index").
  332 + WithJSON(body).
  333 + Expect().
  334 + Status(http.StatusOK).
  335 + JSON().
  336 + Object().
  337 + ContainsKey("code").ValueEqual("code", 0).
  338 + ContainsKey("msg").ValueEqual("msg", "ok").
  339 + ContainsKey("data").ValueEqual("data", true)
  340 + })
  341 + })
  342 + })
  343 + AfterEach(func() {
  344 + _, err := pG.DB.Exec("DELETE FROM employees WHERE true")
  345 + Expect(err).NotTo(HaveOccurred())
  346 + })
  347 +})
  1 +package unified_user_center
  2 +
  3 +import (
  4 + "net/http"
  5 + "net/http/httptest"
  6 + "testing"
  7 +
  8 + "github.com/astaxie/beego"
  9 + . "github.com/onsi/ginkgo"
  10 + . "github.com/onsi/gomega"
  11 + _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  12 + _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego"
  13 +)
  14 +
  15 +func TestUnifiedUserCenter(t *testing.T) {
  16 + RegisterFailHandler(Fail)
  17 + RunSpecs(t, "Beego Port UnifiedUserCenter Correlations Test Case Suite")
  18 +}
  19 +
  20 +var handler http.Handler
  21 +var server *httptest.Server
  22 +
  23 +var _ = BeforeSuite(func() {
  24 + handler = beego.BeeApp.Handlers
  25 + server = httptest.NewServer(handler)
  26 +})
  27 +
  28 +var _ = AfterSuite(func() {
  29 + server.Close()
  30 +})