作者 唐旭辉

角色授权

@@ -29,8 +29,8 @@ log_level = "${LOG_LEVEL||debug}" @@ -29,8 +29,8 @@ log_level = "${LOG_LEVEL||debug}"
29 ##统一用户中心相关配置 29 ##统一用户中心相关配置
30 ucenter_check_alt = "rsF0pL!6DwjBO735" 30 ucenter_check_alt = "rsF0pL!6DwjBO735"
31 ucenter_base_url = "http://suplus-ucenter-dev.fjmaimaimai.com" 31 ucenter_base_url = "http://suplus-ucenter-dev.fjmaimaimai.com"
32 -ucenter_app_key = "0692f2b7e8d6dbd8526579864b87e3bfbc5d5c31"  
33 -ucenter_secret = "0692f2b7e8d6dbd8526579864b87e3bfbc5d5c31" 32 +ucenter_app_key = "39aefef9e22744a3b2d2d3791824ae7b"
  33 +ucenter_secret = "cykbjnfqgctn"
34 # 审批流程修改 消息发布 34 # 审批流程修改 消息发布
35 message_publish = "audit_change" 35 message_publish = "audit_change"
36 #---自定义配置 结束---- 36 #---自定义配置 结束----
@@ -59,8 +59,15 @@ func (c *AuthController) Login() { @@ -59,8 +59,15 @@ func (c *AuthController) Login() {
59 msg = protocol.NewReturnResponse(nil, err) 59 msg = protocol.NewReturnResponse(nil, err)
60 return 60 return
61 } 61 }
  62 + err = serveauth.ResetLoginToken(logintoken)
  63 + if err != nil {
  64 + log.Error("token 信息记录数据库失败")
  65 + }
62 err = serveauth.ResetLoginTokenRedis(logintoken) 66 err = serveauth.ResetLoginTokenRedis(logintoken)
63 - msg = protocol.NewReturnResponse(logintoken, err) 67 + if err != nil {
  68 + log.Error("token 信息记录redis失败")
  69 + }
  70 + msg = protocol.NewReturnResponse(logintoken, nil)
64 return 71 return
65 } 72 }
66 73
@@ -226,6 +226,7 @@ func (c *RbacController) RoleHasMenu() { @@ -226,6 +226,7 @@ func (c *RbacController) RoleHasMenu() {
226 return 226 return
227 } 227 }
228 228
  229 +//TODO
229 func (c *RbacController) GetRoleMenuAll() { 230 func (c *RbacController) GetRoleMenuAll() {
230 var msg *protocol.ResponseMessage 231 var msg *protocol.ResponseMessage
231 defer func() { 232 defer func() {
@@ -237,6 +238,25 @@ func (c *RbacController) GetRoleMenuAll() { @@ -237,6 +238,25 @@ func (c *RbacController) GetRoleMenuAll() {
237 return 238 return
238 } 239 }
239 240
  241 +//RoleMenuEdit 设置角色的菜单
  242 +//@router /role/menu/edit
240 func (c *RbacController) RoleMenuEdit() { 243 func (c *RbacController) RoleMenuEdit() {
  244 + var msg *protocol.ResponseMessage
  245 + defer func() {
  246 + c.ResposeJson(msg)
  247 + }()
  248 + type Parameter struct {
  249 + RoleId int64 `json:"role_id"`
  250 + MenuIds []int64 `json:"menu_ids"`
  251 + }
  252 + var param Parameter
  253 + if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  254 + log.Error("json 解析失败 err:%s", err)
  255 + msg = protocol.BadRequestParam("1")
  256 + return
  257 + }
  258 + companyid := c.GetCompanyId()
  259 + err := serverbac.RoleMenuEdit(companyid, param.RoleId, param.MenuIds)
  260 + msg = protocol.NewReturnResponse(nil, err)
241 return 261 return
242 } 262 }
@@ -89,7 +89,7 @@ var AllowOption = func(ctx *context.Context) { @@ -89,7 +89,7 @@ var AllowOption = func(ctx *context.Context) {
89 }) 89 })
90 f(ctx) 90 f(ctx)
91 ctx.Output.SetStatus(204) 91 ctx.Output.SetStatus(204)
92 - ctx.Output.Body([]byte("{}")) 92 + ctx.Output.Body(nil)
93 return 93 return
94 } 94 }
95 95
@@ -38,3 +38,14 @@ func GetMenuById(id int) (v *Menu, err error) { @@ -38,3 +38,14 @@ func GetMenuById(id int) (v *Menu, err error) {
38 } 38 }
39 return nil, err 39 return nil, err
40 } 40 }
  41 +
  42 +func GetMenuByIds(ids []int64) (v []*Menu, err error) {
  43 + o := orm.NewOrm()
  44 + _, err = o.QueryTable(&Menu{}).
  45 + Filter("id__in", ids).
  46 + All(&v)
  47 + if err == orm.ErrNoRows {
  48 + return v, nil
  49 + }
  50 + return v, nil
  51 +}
@@ -7,7 +7,7 @@ import ( @@ -7,7 +7,7 @@ import (
7 type RoleMenu struct { 7 type RoleMenu struct {
8 Id int64 `orm:"column(id);auto" description:"主键"` 8 Id int64 `orm:"column(id);auto" description:"主键"`
9 RoleId int64 `orm:"column(role_id);null" description:"role.id"` 9 RoleId int64 `orm:"column(role_id);null" description:"role.id"`
10 - MenuId int64 `orm:"column(menu_id);null" description:"menu.id"` 10 + MenuId int `orm:"column(menu_id);null" description:"menu.id"`
11 Opption string `orm:"column(opption);size(500);null" description:"配置"` 11 Opption string `orm:"column(opption);size(500);null" description:"配置"`
12 Code string `orm:"column(code)"` 12 Code string `orm:"column(code)"`
13 } 13 }
@@ -20,14 +20,6 @@ func init() { @@ -20,14 +20,6 @@ func init() {
20 orm.RegisterModel(new(RoleMenu)) 20 orm.RegisterModel(new(RoleMenu))
21 } 21 }
22 22
23 -// AddRoleMenu insert a new RoleMenu into database and returns  
24 -// last inserted Id on success.  
25 -func AddRoleMenu(m *RoleMenu) (id int64, err error) {  
26 - o := orm.NewOrm()  
27 - id, err = o.Insert(m)  
28 - return  
29 -}  
30 -  
31 func GetRoleMenuByRole(roleid int64) ([]RoleMenu, error) { 23 func GetRoleMenuByRole(roleid int64) ([]RoleMenu, error) {
32 var ( 24 var (
33 list []RoleMenu 25 list []RoleMenu
@@ -16,6 +16,7 @@ type User struct { @@ -16,6 +16,7 @@ type User struct {
16 CsAccount int64 `orm:"column(cs_account)" description:"客服有话说ID"` 16 CsAccount int64 `orm:"column(cs_account)" description:"客服有话说ID"`
17 IsKefu int8 `orm:"column(is_kefu)" description:"是否是客服 0:否 1:是"` 17 IsKefu int8 `orm:"column(is_kefu)" description:"是否是客服 0:否 1:是"`
18 ImToken string `orm:"column(im_token);size(128)" description:"网易云token"` 18 ImToken string `orm:"column(im_token);size(128)" description:"网易云token"`
  19 + Accid int64 `orm:"column(accid)" description:"网易云id"`
19 LastLoginTime time.Time `orm:"column(last_login_time);type(timestamp)" description:"最后一次登录时间"` 20 LastLoginTime time.Time `orm:"column(last_login_time);type(timestamp)" description:"最后一次登录时间"`
20 CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now_add" description:"创建时间"` 21 CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now_add" description:"创建时间"`
21 EnableStatus int8 `orm:"column(enable_status)" description:"是否有效"` 22 EnableStatus int8 `orm:"column(enable_status)" description:"是否有效"`
@@ -131,7 +131,7 @@ type TemplateItem struct { @@ -131,7 +131,7 @@ type TemplateItem struct {
131 131
132 type VisibleObject struct { 132 type VisibleObject struct {
133 Id string `json:"id"` 133 Id string `json:"id"`
134 - Name string `json:"name",omitempty` 134 + Name string `json:"name,omitempty"`
135 Type int `json:"type"` //1:部门 2:指定人员 135 Type int `json:"type"` //1:部门 2:指定人员
136 } 136 }
137 137
@@ -7,6 +7,7 @@ var errmessge ErrorMap = map[string]string{ @@ -7,6 +7,7 @@ var errmessge ErrorMap = map[string]string{
7 //角色相关 7 //角色相关
8 "10001": "请先删除该分组下的其他角色", 8 "10001": "请先删除该分组下的其他角色",
9 "10002": "请先删除该角色下的人员", 9 "10002": "请先删除该角色下的人员",
  10 + "10003": "无效角色",
10 //职位相关 11 //职位相关
11 "10011": "该职位已被使用无法删除", 12 "10011": "该职位已被使用无法删除",
12 //安全认证相关 13 //安全认证相关
@@ -38,6 +38,7 @@ func init() { @@ -38,6 +38,7 @@ func init() {
38 beego.NSRouter("/role/list", &controllers.RbacController{}, "post:RoleList"), 38 beego.NSRouter("/role/list", &controllers.RbacController{}, "post:RoleList"),
39 beego.NSRouter("/menu/list", &controllers.RbacController{}, "post:MenuList"), 39 beego.NSRouter("/menu/list", &controllers.RbacController{}, "post:MenuList"),
40 beego.NSRouter("/role/menu", &controllers.RbacController{}, "post:RoleHasMenu"), 40 beego.NSRouter("/role/menu", &controllers.RbacController{}, "post:RoleHasMenu"),
  41 + beego.NSRouter("/role/menu/edit", &controllers.RbacController{}, "post:RoleMenuEdit"),
41 ), 42 ),
42 beego.NSNamespace("/user", 43 beego.NSNamespace("/user",
43 beego.NSRouter("/list", &controllers.CompanyController{}, "post:UserList"), 44 beego.NSRouter("/list", &controllers.CompanyController{}, "post:UserList"),
@@ -3,11 +3,13 @@ package auth @@ -3,11 +3,13 @@ package auth
3 import ( 3 import (
4 "crypto/sha1" 4 "crypto/sha1"
5 "encoding/hex" 5 "encoding/hex"
  6 + "encoding/json"
6 "fmt" 7 "fmt"
7 "io" 8 "io"
8 "oppmg/common/log" 9 "oppmg/common/log"
9 "oppmg/models" 10 "oppmg/models"
10 "oppmg/protocol" 11 "oppmg/protocol"
  12 + "oppmg/services/ucenter"
11 "oppmg/storage/redisdata" 13 "oppmg/storage/redisdata"
12 "oppmg/utils" 14 "oppmg/utils"
13 "strings" 15 "strings"
@@ -79,7 +81,7 @@ func ResetLoginToken(loginToken protocol.LoginAuthToken) error { @@ -79,7 +81,7 @@ func ResetLoginToken(loginToken protocol.LoginAuthToken) error {
79 uAuth.RefreshToken = loginToken.RefreshToken 81 uAuth.RefreshToken = loginToken.RefreshToken
80 uAuth.RefreshTokenExp = time.Unix(loginToken.RefreshExpires, 0) 82 uAuth.RefreshTokenExp = time.Unix(loginToken.RefreshExpires, 0)
81 uAuth.UpdateAt = nowTime 83 uAuth.UpdateAt = nowTime
82 - upCol := []string{"CurrentCompanyId", "AccessToken", "RefreshToken", "RefreshTokenExp", "UpdateAt"} 84 + upCol := []string{"CurrentCompanyId", "AccessTokenExp", "RefreshTokenExp", "AccessToken", "RefreshToken", "RefreshTokenExp", "UpdateAt"}
83 if err = models.UpdateUserAuthById(uAuth, upCol); err != nil { 85 if err = models.UpdateUserAuthById(uAuth, upCol); err != nil {
84 e := fmt.Errorf("UpdateUserAuthById err:%s", err) 86 e := fmt.Errorf("UpdateUserAuthById err:%s", err)
85 log.Error(e.Error()) 87 log.Error(e.Error())
@@ -189,7 +191,7 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro @@ -189,7 +191,7 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro
189 } 191 }
190 if ok := userdata.IsEnable(); !ok { 192 if ok := userdata.IsEnable(); !ok {
191 log.Debug("userdata.IsEnable()==false") 193 log.Debug("userdata.IsEnable()==false")
192 - return logintoken, protocol.NewErrWithMessage("10021") 194 + return logintoken, protocol.NewErrWithMessage("10022")
193 } 195 }
194 if companys, err = getUserCompanyReal(userdata.Id); err != nil { 196 if companys, err = getUserCompanyReal(userdata.Id); err != nil {
195 log.Error("getUserCompanyReal err:%s", err) 197 log.Error("getUserCompanyReal err:%s", err)
@@ -197,33 +199,55 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro @@ -197,33 +199,55 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro
197 } 199 }
198 if len(companys) == 0 { 200 if len(companys) == 0 {
199 log.Debug("no company") 201 log.Debug("no company")
200 - return logintoken, protocol.NewErrWithMessage("10021") 202 + return logintoken, protocol.NewErrWithMessage("10022")
201 } 203 }
202 companyid = companys[0].Id 204 companyid = companys[0].Id
203 - // var uclientReturn ucenter.ResponseLogin  
204 - // param := ucenter.RequesLogin{  
205 - // Phone: account,  
206 - // Password: password,  
207 - // }  
208 - // uclient := ucenter.NewUCenterClient()  
209 - // btBody, err := uclient.Call(param)  
210 - // if err != nil {  
211 - // log.Error("统一用户中心请求失败 err:%s", err)  
212 - // return logintoken, protocol.NewErrWithMessage("1")  
213 - // }  
214 - // err = json.Unmarshal(btBody, &uclientReturn)  
215 - // if err != nil {  
216 - // log.Error("解析统一用户中心响应失败 err:%s", err)  
217 - // return logintoken, protocol.NewErrWithMessage("1")  
218 - // }  
219 - // if !(uclientReturn.Code == ucenter.ResponseCode0 &&  
220 - // uclientReturn.Msg == ucenter.ResponseMsgOk) {  
221 - // return logintoken, protocol.NewErrWithMessage("10021")  
222 - // } 205 + var uclientReturn *ucenter.ResponseLogin
  206 + uclientReturn, err = requestUCenterLogin(account, password)
  207 + if err != nil {
  208 + return logintoken, protocol.NewErrWithMessage("10021")
  209 + }
  210 + //更新用户数据
  211 + _ = uclientReturn
  212 + userdata.Accid = uclientReturn.Data.Accid
  213 + userdata.Icon = uclientReturn.Data.Avatar
  214 + userdata.ImToken = uclientReturn.Data.Imtoken
  215 + userdata.NickName = uclientReturn.Data.NickName
  216 + userdata.CsAccount = uclientReturn.Data.CustomerAccount
  217 + userdata.LastLoginTime = time.Now()
  218 + err = models.UpdateUserById(userdata, []string{"Accid", "Icon", "ImToken", "NickName", "CsAccount", "LastLoginTime"})
  219 + if err != nil {
  220 + log.Error("更新用户数据失败:%s", err)
  221 + }
223 logintoken, _ = GenerateAuthToken(userdata.Id, companyid) 222 logintoken, _ = GenerateAuthToken(userdata.Id, companyid)
224 return logintoken, err 223 return logintoken, err
225 } 224 }
226 225
  226 +func requestUCenterLogin(account, password string) (*ucenter.ResponseLogin, error) {
  227 + var uclientReturn *ucenter.ResponseLogin
  228 + param := ucenter.RequesLogin{
  229 + Type: 1,
  230 + Phone: account,
  231 + Password: password,
  232 + }
  233 + uclient := ucenter.NewUCenterClient()
  234 + btBody, err := uclient.Call(param)
  235 + if err != nil {
  236 + log.Error("统一用户中心请求失败 err:%s", err)
  237 + return nil, protocol.NewErrWithMessage("1")
  238 + }
  239 + err = json.Unmarshal(btBody, &uclientReturn)
  240 + if err != nil {
  241 + log.Error("解析统一用户中心响应失败 err:%s", err)
  242 + return nil, protocol.NewErrWithMessage("1")
  243 + }
  244 + if !(uclientReturn.Code == ucenter.ResponseCode0 &&
  245 + uclientReturn.Msg == ucenter.ResponseMsgOk) {
  246 + return nil, protocol.NewErrWithMessage("10021")
  247 + }
  248 + return uclientReturn, nil
  249 +}
  250 +
227 type companybase struct { 251 type companybase struct {
228 Id int64 `orm:"column(id)"` 252 Id int64 `orm:"column(id)"`
229 Name string `orm:"coumn(name)"` 253 Name string `orm:"coumn(name)"`
@@ -5,6 +5,8 @@ import ( @@ -5,6 +5,8 @@ import (
5 "oppmg/models" 5 "oppmg/models"
6 "oppmg/protocol" 6 "oppmg/protocol"
7 "oppmg/utils" 7 "oppmg/utils"
  8 +
  9 + "github.com/astaxie/beego/orm"
8 ) 10 )
9 11
10 //获取全部的权限菜单 12 //获取全部的权限菜单
@@ -52,7 +54,7 @@ func GetRoleHasMenu(roleid int64, companyid int64) (*protocol.ResponseRoleMenus, @@ -52,7 +54,7 @@ func GetRoleHasMenu(roleid int64, companyid int64) (*protocol.ResponseRoleMenus,
52 return nil, protocol.NewErrWithMessage("1") 54 return nil, protocol.NewErrWithMessage("1")
53 } 55 }
54 for _, v := range rolemenu { 56 for _, v := range rolemenu {
55 - ids = append(ids, v.MenuId) 57 + ids = append(ids, int64(v.MenuId))
56 } 58 }
57 data := &protocol.ResponseRoleMenus{ 59 data := &protocol.ResponseRoleMenus{
58 RoleId: roleData.Id, 60 RoleId: roleData.Id,
@@ -103,6 +105,54 @@ func GetRoleHasMenuAll(roleid int64, companyid int64) (map[string]PermissionCont @@ -103,6 +105,54 @@ func GetRoleHasMenuAll(roleid int64, companyid int64) (map[string]PermissionCont
103 return returnList, nil 105 return returnList, nil
104 } 106 }
105 107
106 -func RoleMenuEdit(companyid int64, roleid int64, menuids []int64) { 108 +func RoleMenuEdit(companyid int64, roleId int64, menuids []int64) error {
  109 + roleMenus, err := GetRoleHasMenu(companyid, roleId)
  110 + if err != nil {
  111 + return err
  112 + }
  113 + var (
  114 + oldMenuIds []int64
  115 + addMenuIds []int64
  116 + delMenuIds []int64
  117 + addMenu []*models.Menu
  118 + )
  119 + oldMenuIds = roleMenus.MenuId
  120 + addMenuIds = utils.ArrayInt64Diff(menuids, oldMenuIds)
  121 + delMenuIds = utils.ArrayInt64Diff(oldMenuIds, menuids)
  122 + if len(addMenuIds) > 0 {
  123 + addMenu, err = models.GetMenuByIds(addMenuIds)
  124 + if err != nil {
  125 + log.Error("获取菜单数据失败:%s", err)
  126 + return protocol.NewErrWithMessage("1")
  127 + }
  128 + }
  129 + o := orm.NewOrm()
  130 + o.Begin()
  131 + if len(delMenuIds) > 0 {
  132 + _, err = o.QueryTable(&models.RoleMenu{}).
  133 + Filter("role_id", roleId).
  134 + Filter("menu_id__in", delMenuIds).
  135 + Delete()
  136 + if err != nil {
  137 + log.Error("删除角色和菜单关系失败:%s", err)
  138 + o.Rollback()
  139 + return protocol.NewErrWithMessage("1")
  140 + }
  141 + }
  142 + for _, v := range addMenu {
  143 + m := models.RoleMenu{
  144 + RoleId: roleId,
  145 + MenuId: v.Id,
  146 + Code: v.Code,
  147 + Opption: "{}",
  148 + }
  149 + if _, err = o.Insert(&m); err != nil {
  150 + log.Error("添加角色和菜单关系失败:%s", err)
  151 + o.Rollback()
  152 + return protocol.NewErrWithMessage("1")
  153 + }
  154 + }
  155 + o.Commit()
  156 + return nil
107 157
108 } 158 }
@@ -158,11 +158,6 @@ func RoleGroupDelete(param protocol.RequestRoleDelete) error { @@ -158,11 +158,6 @@ func RoleGroupDelete(param protocol.RequestRoleDelete) error {
158 return nil 158 return nil
159 } 159 }
160 160
161 -//CanSetRole 操作员是否可以操作角色  
162 -func CanSetRole(adminId int64, groupId int64) bool {  
163 - return false  
164 -}  
165 -  
166 func GetRoleList(companyId int64) ([]protocol.RoleGroup, error) { 161 func GetRoleList(companyId int64) ([]protocol.RoleGroup, error) {
167 var ( 162 var (
168 roleGroups []protocol.RoleGroup 163 roleGroups []protocol.RoleGroup
@@ -213,19 +208,3 @@ func getRoleGroupByCompany(companyid int64) ([]protocol.RoleInfo, error) { @@ -213,19 +208,3 @@ func getRoleGroupByCompany(companyid int64) ([]protocol.RoleInfo, error) {
213 err = utils.ExecuteQueryAll(&roles, datasql, companyid, models.ROLETYPES_GROUP) 208 err = utils.ExecuteQueryAll(&roles, datasql, companyid, models.ROLETYPES_GROUP)
214 return roles, err 209 return roles, err
215 } 210 }
216 -  
217 -func GetRoleGroup() error {  
218 - return nil  
219 -}  
220 -  
221 -func RoleHasPermission() error {  
222 - return nil  
223 -}  
224 -  
225 -func PermissionHasRole() error {  
226 - return nil  
227 -}  
228 -  
229 -func RolsHasUser() error {  
230 - return nil  
231 -}  
@@ -14,6 +14,7 @@ type CommResponse struct { @@ -14,6 +14,7 @@ type CommResponse struct {
14 14
15 //RequesLogin 用户登录 15 //RequesLogin 用户登录
16 type RequesLogin struct { 16 type RequesLogin struct {
  17 + Type int8 `json:"type"`
17 Password string `json:"password"` 18 Password string `json:"password"`
18 Phone string `json:"phone"` 19 Phone string `json:"phone"`
19 } 20 }
@@ -27,7 +28,7 @@ func (r RequesLogin) Format() []byte { @@ -27,7 +28,7 @@ func (r RequesLogin) Format() []byte {
27 28
28 //Format 实现IUCenterParam接口 29 //Format 实现IUCenterParam接口
29 func (r RequesLogin) GetPath() (string, string) { 30 func (r RequesLogin) GetPath() (string, string) {
30 - return "/auth/login", "POST" 31 + return "/auth/serverLogin", "POST"
31 } 32 }
32 33
33 //Format 实现IUCenterParam接口 34 //Format 实现IUCenterParam接口
@@ -44,10 +45,13 @@ func (r RequesLogin) Valid() error { @@ -44,10 +45,13 @@ func (r RequesLogin) Valid() error {
44 type ResponseLogin struct { 45 type ResponseLogin struct {
45 CommResponse 46 CommResponse
46 Data struct { 47 Data struct {
47 - Id int64 `json:"id"`  
48 - Phone string `json:"phone"`  
49 - NickName string `json:"nickname"` //昵称  
50 - Avatar string `json:"avatar"` //头像 48 + Id int64 `json:"id"`
  49 + Phone string `json:"phone"`
  50 + NickName string `json:"nickname"` //昵称
  51 + Avatar string `json:"avatar"` //头像
  52 + Imtoken string `json:"imtoken"` //网易云imtoken
  53 + Accid int64 `json:"accid"`
  54 + CustomerAccount int64 `json:"customerAccount"` //客服id
51 } `json:"data"` 55 } `json:"data"`
52 } 56 }
53 57
@@ -55,7 +55,7 @@ func buildCheckSum(nowTime string) string { @@ -55,7 +55,7 @@ func buildCheckSum(nowTime string) string {
55 //httpDo post发送json 55 //httpDo post发送json
56 func (client UCenterClient) httpDo(path string, mathod string, posts []byte) ([]byte, error) { 56 func (client UCenterClient) httpDo(path string, mathod string, posts []byte) ([]byte, error) {
57 httpclient := http.Client{ 57 httpclient := http.Client{
58 - Timeout: 5 * time.Second, //请求超时时间5秒 58 + Timeout: 10 * time.Second, //请求超时时间5秒
59 } 59 }
60 reqURL := client.baseUrl + path 60 reqURL := client.baseUrl + path
61 req, err := http.NewRequest(mathod, reqURL, bytes.NewReader(posts)) 61 req, err := http.NewRequest(mathod, reqURL, bytes.NewReader(posts))
@@ -64,7 +64,9 @@ func (client UCenterClient) httpDo(path string, mathod string, posts []byte) ([] @@ -64,7 +64,9 @@ func (client UCenterClient) httpDo(path string, mathod string, posts []byte) ([]
64 } 64 }
65 req.Header = client.buildHeader() 65 req.Header = client.buildHeader()
66 resp, err := httpclient.Do(req) 66 resp, err := httpclient.Do(req)
  67 +
67 log.Info("====>Send To UCenter:%s", string(posts)) 68 log.Info("====>Send To UCenter:%s", string(posts))
  69 + // log.Info("====>Send Header:%v", req.Header)
68 if err != nil { 70 if err != nil {
69 return nil, err 71 return nil, err
70 } 72 }
@@ -14,7 +14,7 @@ func ArrayInt64Diff(arr1 []int64, arr2 []int64) []int64 { @@ -14,7 +14,7 @@ func ArrayInt64Diff(arr1 []int64, arr2 []int64) []int64 {
14 } 14 }
15 setmap := make(map[int64]bool) 15 setmap := make(map[int64]bool)
16 for i := range arr2 { 16 for i := range arr2 {
17 - setmap[arr1[i]] = true 17 + setmap[arr2[i]] = true
18 } 18 }
19 var result []int64 19 var result []int64
20 for i := range arr1 { 20 for i := range arr1 {
@@ -26,6 +26,25 @@ func ArrayInt64Diff(arr1 []int64, arr2 []int64) []int64 { @@ -26,6 +26,25 @@ func ArrayInt64Diff(arr1 []int64, arr2 []int64) []int64 {
26 return result 26 return result
27 } 27 }
28 28
  29 +//ArrayIntDiff 返回切片的差集:arr1-arr2
  30 +func ArrayIntDiff(arr1 []int, arr2 []int) []int {
  31 + if len(arr2) == 0 {
  32 + return arr1
  33 + }
  34 + setmap := make(map[int]bool)
  35 + for i := range arr2 {
  36 + setmap[arr1[i]] = true
  37 + }
  38 + var result []int
  39 + for i := range arr1 {
  40 + if _, ok := setmap[arr1[i]]; !ok {
  41 + result = append(result, arr1[i])
  42 + }
  43 + }
  44 +
  45 + return result
  46 +}
  47 +
29 //ArrayStringIn 检查s字符串是否在切片sl中 48 //ArrayStringIn 检查s字符串是否在切片sl中
30 func ArrayStringIn(arr1 []string, s string) bool { 49 func ArrayStringIn(arr1 []string, s string) bool {
31 for _, v := range arr1 { 50 for _, v := range arr1 {