sync_data_controller.go
3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package controllers
//用于和企业平台和总后台进行数据通讯
import (
"encoding/json"
"errors"
"github.com/astaxie/beego/logs"
companyService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/company/service"
syncCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/unifiedUserCenter/command"
syncService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/unifiedUserCenter/service"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
)
type SyncDataController struct {
BaseController
}
////Prepare 重写 BaseController 的Prepare方法
func (c *SyncDataController) Prepare() {
c.BaseController.Prepare()
}
//SyncData 和企业后台同步数据
func (c *SyncDataController) SyncData() {
var (
cmd syncCmd.SyncCallbackCommand
err error
)
if err = c.BindJsonData(&cmd); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
err = syncService.NewSyncAction(cmd)
if err != nil {
logs.Error("同步数据异常;%s", err)
}
//不论子系统如何处理以及处理结果成功失败 必须返回 0
c.ResponseData(nil)
return
}
//CompanyAdminChance 变更公司主管(超级管理)
func (c *SyncDataController) CompanyAdminChance() {
var (
param syncCmd.ChanceSuperAdminCommand
err error
)
if err = c.BindJsonData(¶m); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
syncEmployeeSrv := syncService.NewSyncEmployeeService(nil)
err = syncEmployeeSrv.ChangeSuperAdmin(param)
if err != nil {
logs.Error("变更公司的主管失败;%s", err)
}
c.ResponseData(nil)
return
}
//AllowForidCompany 总后台调用
func (c *SyncDataController) AllowForidCompany() {
type Paremeter struct {
Companyid int64 `json:"company_id"`
Status int `json:"status"`
}
var param Paremeter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil {
logs.Error("json 解析失败 err:%s", err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
var (
err error
)
comanySrv := companyService.NewCompanyService(nil)
switch param.Status {
case 1:
err = comanySrv.AllowCompany(param.Companyid)
case 2:
err = comanySrv.ForbidCompany(param.Companyid)
default:
c.ResponseError(errors.New("参数错误"))
return
}
if err != nil {
c.ResponseError(err)
}
c.ResponseData(nil)
return
}
//GetCompanyInfo 总后台调用
func (c *SyncDataController) GetCompanyInfo() {
type Paremeter struct {
Companyid int64 `json:"company_id"`
}
var param Paremeter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil {
logs.Error("json 解析失败 err:%s", err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
var (
err error
companyData *domain.Company
)
comanySrv := companyService.NewCompanyService(nil)
companyData, err = comanySrv.GetCompanyData(param.Companyid)
rspData := map[string]interface{}{
"comopany_id": 0,
"exist": -1, //公司【1:存在;【-1:不存在】
"status": -1, //公司的启用状态【1:启用,-1:禁用】
}
if err != nil {
logs.Error(err)
c.ResponseData(rspData)
return
}
if companyData.EnableIsOk() {
rspData["status"] = 1
}
rspData["exist"] = 1
c.ResponseData(rspData)
return
}