sys_admin.go 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  1. package controllers
  2. import (
  3. "encoding/base64"
  4. "encoding/json"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/company"
  7. "eta/eta_api/models/data_manage"
  8. "eta/eta_api/models/system"
  9. "eta/eta_api/services"
  10. "eta/eta_api/utils"
  11. "fmt"
  12. "github.com/rdlucklib/rdluck_tools/paging"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. // 系统用户
  18. type SysAdminController struct {
  19. BaseAuthController
  20. }
  21. // @Title 根据分组或者部门获取系统用户列表
  22. // @Description 根据分组或者部门获取系统用户列表接口
  23. // @Param PageSize query int true "每页数据条数"
  24. // @Param CurrentIndex query int true "当前页页码,从1开始"
  25. // @Param DepartmentId query int true "部门ID"
  26. // @Param GroupId query int true "分组ID"
  27. // @Param TeamId query int true "小组ID"
  28. // @Param RoleId query int true "角色ID"
  29. // @Param KeyWord query string true "搜索关键词"
  30. // @Success 200 {object} system.SysuserListResp
  31. // @router /sysuser/list [get]
  32. func (this *SysAdminController) ListSysuser() {
  33. br := new(models.BaseResponse).Init()
  34. defer func() {
  35. this.Data["json"] = br
  36. this.ServeJSON()
  37. }()
  38. sysUser := this.SysUser
  39. if sysUser == nil {
  40. br.Msg = "请登录"
  41. br.ErrMsg = "请登录,SysUser Is Empty"
  42. return
  43. }
  44. pageSize, _ := this.GetInt("PageSize")
  45. currentIndex, _ := this.GetInt("CurrentIndex")
  46. departmentId, _ := this.GetInt("DepartmentId")
  47. groupId, _ := this.GetInt("GroupId")
  48. teamId, _ := this.GetInt("TeamId")
  49. roleId, _ := this.GetInt("RoleId")
  50. keyWord := this.GetString("KeyWord")
  51. var startSize int
  52. if pageSize <= 0 {
  53. pageSize = utils.PageSize20
  54. }
  55. if currentIndex <= 0 {
  56. currentIndex = 1
  57. }
  58. startSize = utils.StartIndex(currentIndex, pageSize)
  59. var condition string
  60. var pars []interface{}
  61. if departmentId > 0 {
  62. condition += ` AND department_id=? `
  63. pars = append(pars, departmentId)
  64. }
  65. if roleId > 0 {
  66. condition += ` AND role_id=? `
  67. pars = append(pars, roleId)
  68. }
  69. if keyWord != "" {
  70. condition += ` AND (real_name LIKE '%` + keyWord + `%' OR admin_name LIKE '%` + keyWord + `%' OR mobile LIKE '%` + keyWord + `%' ) `
  71. }
  72. var total int
  73. var err error
  74. if teamId <= 0 {
  75. if groupId > 0 {
  76. ids, err := system.GetGroupIdByParentId(groupId)
  77. if err != nil {
  78. br.Msg = "获取失败"
  79. br.ErrMsg = "获取失败,Err:" + err.Error()
  80. return
  81. }
  82. sGroupId := strconv.Itoa(groupId)
  83. ids = append(ids, &sGroupId)
  84. var idList []string
  85. for _, id := range ids {
  86. idList = append(idList, *id)
  87. }
  88. sid := strings.Join(idList, ",")
  89. condition += ` AND group_id IN (` + sid + `) `
  90. }
  91. total, err = system.GetSysuserListCount(condition, pars)
  92. if err != nil {
  93. br.Msg = "获取失败"
  94. br.ErrMsg = "获取失败,Err:" + err.Error()
  95. return
  96. }
  97. } else {
  98. nCondition := condition + ` AND group_id=? `
  99. nPars := append(pars, teamId)
  100. total, err = system.GetSysuserListCount(nCondition, nPars)
  101. if err != nil {
  102. br.Msg = "获取失败"
  103. br.ErrMsg = "获取失败,Err:" + err.Error()
  104. return
  105. }
  106. }
  107. var list []*system.AdminItem
  108. adminIdArr := make([]int, 0)
  109. if teamId <= 0 {
  110. //if groupId > 0 {
  111. // ids, err := system.GetGroupIdByParentId(groupId, startSize, pageSize)
  112. // if err != nil {
  113. // br.Msg = "获取失败"
  114. // br.ErrMsg = "获取失败,Err:" + err.Error()
  115. // return
  116. // }
  117. // sGroupId := strconv.Itoa(groupId)
  118. // ids = append(ids, &sGroupId)
  119. // var idList []string
  120. // for _, id := range ids {
  121. // idList = append(idList, *id)
  122. // }
  123. // sid := strings.Join(idList,",")
  124. //
  125. // condition += ` AND group_id IN (` + sid + `) `
  126. //}
  127. list, err = system.GetSysuserList(condition, pars, startSize, pageSize)
  128. if err != nil {
  129. br.Msg = "获取失败"
  130. br.ErrMsg = "获取失败,Err:" + err.Error()
  131. return
  132. }
  133. lenList := len(list)
  134. for i := 0; i < lenList; i++ {
  135. item := list[i]
  136. //adminIdArr = append(adminIdArr, strconv.Itoa(item.AdminId))
  137. adminIdArr = append(adminIdArr, item.AdminId)
  138. var secondName *string
  139. if item.GroupId != 0 {
  140. pid, err := company.GetParentIdFromGroup(item.GroupId)
  141. if err != nil {
  142. br.Msg = "获取失败"
  143. br.ErrMsg = "查询父级id异常" + err.Error()
  144. return
  145. }
  146. if pid != nil && *pid != 0 {
  147. secondName, err = company.GetGroupNamesById(*pid)
  148. if err != nil {
  149. br.Msg = "获取失败"
  150. br.ErrMsg = "查询二级组名异常" + err.Error()
  151. return
  152. }
  153. }
  154. if *pid > 0 {
  155. list[i].TeamId = list[i].GroupId
  156. list[i].GroupId = *pid
  157. }
  158. }
  159. if item.DepartmentName != "" {
  160. if item.GroupName == "" {
  161. list[i].DepartmentGroup = item.DepartmentName
  162. } else if secondName != nil {
  163. list[i].DepartmentGroup = item.DepartmentName + "/" + *secondName + "/" + item.GroupName
  164. } else {
  165. list[i].DepartmentGroup = item.DepartmentName + "/" + item.GroupName
  166. }
  167. }
  168. labelVal := 0
  169. fmt.Println("item.RoleTypeCode:", item.RoleTypeCode)
  170. fmt.Println("item.Authority:", item.Authority)
  171. if item.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  172. labelVal = 1
  173. } else if item.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  174. item.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  175. labelVal = 2
  176. } else {
  177. if item.Authority == 1 {
  178. labelVal = 3
  179. } else if item.Authority == 2 && item.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  180. labelVal = 4
  181. } else if item.Authority == 2 && item.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  182. labelVal = 5
  183. } else if item.Authority == 4 {
  184. labelVal = 4
  185. }
  186. }
  187. list[i].LabelVal = labelVal
  188. }
  189. } else {
  190. condition += ` AND group_id=? `
  191. pars = append(pars, teamId)
  192. list, err = system.GetSysuserList(condition, pars, startSize, pageSize)
  193. if err != nil {
  194. br.Msg = "获取失败"
  195. br.ErrMsg = "获取失败,Err:" + err.Error()
  196. return
  197. }
  198. groupItem, err := system.GetSysGroupById(groupId)
  199. if err != nil {
  200. br.Msg = "获取失败"
  201. br.ErrMsg = "获取失败,Err:" + err.Error()
  202. return
  203. }
  204. lenList := len(list)
  205. for i := 0; i < lenList; i++ {
  206. item := list[i]
  207. //adminIdArr = append(adminIdArr, strconv.Itoa(item.AdminId))
  208. adminIdArr = append(adminIdArr, item.AdminId)
  209. if item.DepartmentName != "" {
  210. if item.GroupName == "" {
  211. list[i].DepartmentGroup = item.DepartmentName
  212. } else if item.GroupName != "" {
  213. list[i].DepartmentGroup = item.DepartmentName + "/" + groupItem.GroupName + "/" + item.GroupName
  214. } else {
  215. list[i].DepartmentGroup = item.DepartmentName + "/" + item.GroupName
  216. }
  217. }
  218. labelVal := 0
  219. if item.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  220. labelVal = 1
  221. } else if item.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  222. item.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  223. labelVal = 2
  224. } else {
  225. if item.Authority == 1 {
  226. labelVal = 3
  227. } else if item.Authority == 2 && item.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  228. labelVal = 4
  229. } else if item.Authority == 2 && item.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  230. labelVal = 5
  231. } else if item.Authority == 4 {
  232. labelVal = 4
  233. }
  234. }
  235. list[i].LabelVal = labelVal
  236. }
  237. }
  238. //if teamId > 0 {
  239. // var groupIdSlice []string
  240. // var groupIds string
  241. // for _, item := range list {
  242. // groupIdSlice = append(groupIdSlice, strconv.Itoa(groupId))
  243. // }
  244. // groupIds = strings.Join(groupIdSlice, ",")
  245. // fmt.Println("groupIds:", groupIds)
  246. //}
  247. if teamId > 0 {
  248. for _, item := range list {
  249. item.TeamId = teamId
  250. item.GroupId = groupId
  251. }
  252. }
  253. // 研究方向分组
  254. if len(adminIdArr) > 0 && (utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox) {
  255. //adminIds := strings.Join(adminIdArr, ",")
  256. //researchGroupList, e := system.GetAdminResearchGroupListByAdminId(adminIds)
  257. researchGroupList, e := models.GetAdminVarietyTagRelationListByAdminId(adminIdArr)
  258. if e != nil {
  259. br.Msg = "获取失败"
  260. br.ErrMsg = "获取研究方向分组列表失败, Err:" + e.Error()
  261. return
  262. }
  263. researchGroupAdminIdName := make(map[int]string, 0)
  264. for _, g := range researchGroupList {
  265. researchGroupAdminIdName[g.AdminId] = g.GroupNameStr
  266. }
  267. for _, v := range list {
  268. v.ResearchGroupName = researchGroupAdminIdName[v.AdminId]
  269. }
  270. }
  271. fmt.Println("teamId:", teamId)
  272. page := paging.GetPaging(currentIndex, pageSize, total)
  273. resp := new(system.SysuserListResp)
  274. resp.List = list
  275. resp.Paging = page
  276. br.Ret = 200
  277. br.Success = true
  278. br.Msg = "获取成功"
  279. br.Data = resp
  280. }
  281. // Add
  282. // @Title 新增系统用户
  283. // @Description 新增系统用户接口
  284. // @Param request body system.SysuserAddReq true "type json string"
  285. // @Success 200 新增成功
  286. // @router /sysuser/add [post]
  287. func (this *SysAdminController) Add() {
  288. br := new(models.BaseResponse).Init()
  289. defer func() {
  290. this.Data["json"] = br
  291. this.ServeJSON()
  292. }()
  293. var req system.SysuserAddReq
  294. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  295. if err != nil {
  296. br.Msg = "参数解析异常!"
  297. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  298. return
  299. }
  300. if req.RoleId <= 0 {
  301. br.Msg = "请选择角色"
  302. br.ErrMsg = "角色ID小于等于0"
  303. return
  304. }
  305. count, err := system.GetSysAdminCount(req.AdminName)
  306. if err != nil {
  307. br.Msg = "获取数据失败"
  308. br.ErrMsg = "获取数据失败"
  309. return
  310. }
  311. if count > 0 {
  312. br.Msg = "账号已存在,请重新输入"
  313. br.IsSendEmail = false
  314. return
  315. }
  316. // 手机号和邮箱必填一个
  317. req.Mobile = strings.TrimSpace(req.Mobile)
  318. req.Email = strings.TrimSpace(req.Email)
  319. if req.Mobile == "" && req.Email == "" {
  320. br.Msg = "至少输入一个手机号或邮箱"
  321. return
  322. }
  323. if req.Mobile != "" {
  324. if req.TelAreaCode == "86" {
  325. if !utils.ValidateMobileFormatat(req.Mobile) {
  326. br.Msg = "手机号格式有误, 请检查"
  327. return
  328. }
  329. }
  330. mobileCount, err := system.GetSysAdminCountByMobile(req.Mobile, 0)
  331. if err != nil {
  332. br.Msg = "判断手机号是否存在失败"
  333. br.ErrMsg = "判断手机号是否存在失败,Err:" + err.Error()
  334. return
  335. }
  336. if mobileCount > 0 {
  337. br.Msg = "手机号已存在,请重新填写"
  338. br.IsSendEmail = false
  339. return
  340. }
  341. }
  342. if req.Email != "" {
  343. if !utils.ValidateEmailFormatat(req.Email) {
  344. br.Msg = "邮箱格式有误, 请检查"
  345. return
  346. }
  347. _, e := system.GetSysUserByEmail(req.Email)
  348. if e.Error() != utils.ErrNoRow() {
  349. br.Msg = "邮箱已存在, 请重新填写"
  350. return
  351. }
  352. }
  353. var roleName, departmentName, groupName, teamName string
  354. roleItem, err := system.GetSysRoleById(req.RoleId)
  355. if err != nil {
  356. if err.Error() == utils.ErrNoRow() {
  357. br.Msg = "所选角色不存在"
  358. return
  359. }
  360. br.Msg = "获取数据失败"
  361. br.ErrMsg = "获取角色数据失败,Err:" + err.Error()
  362. return
  363. }
  364. if roleItem != nil {
  365. roleName = roleItem.RoleName
  366. }
  367. if req.DepartmentId > 0 {
  368. departmentItem, err := system.GetSysDepartmentById(req.DepartmentId)
  369. if err != nil {
  370. if err.Error() == utils.ErrNoRow() {
  371. br.Msg = "所选部门不存在"
  372. return
  373. }
  374. br.Msg = "获取数据失败"
  375. br.ErrMsg = "获取部门数据失败,Err:" + err.Error()
  376. return
  377. }
  378. if departmentItem != nil {
  379. departmentName = departmentItem.DepartmentName
  380. }
  381. }
  382. if req.GroupId > 0 {
  383. groupItem, err := system.GetSysGroupById(req.GroupId)
  384. if err != nil {
  385. if err.Error() == utils.ErrNoRow() {
  386. br.Msg = "所选分组不存在"
  387. return
  388. }
  389. br.Msg = "获取数据失败"
  390. br.ErrMsg = "获取分组数据失败,Err:" + err.Error()
  391. return
  392. }
  393. if groupItem != nil {
  394. groupName = groupItem.GroupName
  395. }
  396. }
  397. if req.TeamId > 0 {
  398. teamItem, err := system.GetSysGroupById(req.TeamId)
  399. if err != nil {
  400. if err.Error() == utils.ErrNoRow() {
  401. br.Msg = "所选小组不存在"
  402. return
  403. }
  404. br.Msg = "获取数据失败"
  405. br.ErrMsg = "获取小组数据失败,Err:" + err.Error()
  406. return
  407. }
  408. if teamItem != nil {
  409. teamName = teamItem.GroupName
  410. }
  411. }
  412. pwdByte, err := base64.StdEncoding.DecodeString(req.Password)
  413. if err != nil {
  414. br.Msg = "解析数据失败"
  415. br.ErrMsg = "解析数据失败,Err:" + err.Error()
  416. return
  417. }
  418. pwdStr := string(pwdByte)
  419. //pwdStr = strings.ToLower(pwdStr)
  420. if pwdStr == "" {
  421. br.Msg = "请输入密码"
  422. return
  423. }
  424. if !utils.CheckPwd(pwdStr) {
  425. br.Msg = "密码格式错误,请重新输入"
  426. return
  427. }
  428. // 员工工号
  429. req.EmployeeId = strings.TrimSpace(req.EmployeeId)
  430. admin := new(system.Admin)
  431. admin.AdminName = req.AdminName
  432. admin.RealName = req.RealName
  433. admin.Password = utils.MD5(pwdStr)
  434. admin.LastUpdatedPasswordTime = time.Now().Format(utils.FormatDateTime)
  435. admin.Enabled = 1
  436. admin.LastLoginTime = time.Now().Format(utils.FormatDateTime)
  437. admin.CreatedTime = time.Now()
  438. admin.LastUpdatedTime = time.Now().Format(utils.FormatDateTime)
  439. admin.Mobile = req.Mobile
  440. admin.RoleType = 0
  441. admin.RoleId = req.RoleId
  442. admin.RoleName = roleName
  443. admin.RoleTypeCode = roleItem.RoleTypeCode
  444. admin.DepartmentId = req.DepartmentId
  445. admin.DepartmentName = departmentName
  446. admin.AdminAvatar = req.AdminAvatar
  447. if req.TeamId <= 0 {
  448. admin.GroupId = req.GroupId
  449. admin.GroupName = groupName
  450. } else {
  451. admin.GroupId = req.TeamId
  452. admin.GroupName = teamName
  453. }
  454. if strings.Contains(admin.RoleTypeCode, "researcher") {
  455. admin.Role = "researcher"
  456. } else if strings.Contains(admin.RoleTypeCode, "seller") {
  457. admin.Role = "sales"
  458. } else {
  459. admin.Role = "admin"
  460. }
  461. admin.EmployeeId = req.EmployeeId
  462. admin.Email = req.Email
  463. var authority int
  464. if roleItem.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  465. authority = 3
  466. } else if roleItem.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
  467. authority = 4
  468. } else if roleItem.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  469. authority = 2
  470. } else {
  471. if strings.Contains(roleItem.RoleType, "销售主管") {
  472. authority = 2
  473. } else if strings.Contains(roleItem.RoleType, "部门经理") {
  474. authority = 1
  475. } else {
  476. authority = 0
  477. }
  478. }
  479. admin.Authority = authority
  480. admin.Position = req.Position
  481. admin.Province = req.Province
  482. admin.ProvinceCode = req.ProvinceCode
  483. admin.City = req.City
  484. admin.CityCode = req.CityCode
  485. admin.TelAreaCode = req.TelAreaCode
  486. err = system.AddAdmin(admin)
  487. if err != nil {
  488. br.Msg = "新增失败"
  489. br.ErrMsg = "新增失败,Err:" + err.Error()
  490. return
  491. }
  492. // 同步用户缓存
  493. if utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox {
  494. var syncData system.SyncAdminData
  495. syncData.Source = utils.SOURCE_ETA_FLAG
  496. syncData.AdminName = admin.AdminName
  497. _ = utils.Rc.LPush(utils.CACHE_SYNC_ADMIN, syncData)
  498. }
  499. err = services.UpdateResearcherTagGroup(admin.AdminId, req.ResearchGroupIds)
  500. if err != nil {
  501. br.Msg = "新增失败"
  502. br.ErrMsg = "新增失败,Err:" + err.Error()
  503. return
  504. }
  505. // 清楚系统用户列表缓存key
  506. utils.Rc.Delete(utils.CACHE_KEY_ADMIN)
  507. utils.Rc.Delete(utils.CACHE_KEY_ADMIN_ID)
  508. //thirdGroupId := 0 //角色:2=研究员,3=机构销售
  509. if admin.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR ||
  510. admin.RoleTypeCode == utils.ROLE_TYPE_CODE_RESEARCHR ||
  511. admin.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR ||
  512. admin.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  513. admin.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT {
  514. //thirdGroupId = 2
  515. } else if admin.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  516. admin.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  517. admin.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  518. admin.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  519. //thirdGroupId = 3
  520. }
  521. //if thirdGroupId > 0 {
  522. // go roadshow.CreateOaUser(admin.Mobile, admin.RealName, thirdGroupId)
  523. //}
  524. // 新增弘则联系人
  525. //go services.AddHzCompanyUser(admin.Mobile, admin.RealName, this.SysUser.AdminId, this.SysUser.RealName)
  526. br.Ret = 200
  527. br.Success = true
  528. br.Msg = "新增成功"
  529. }
  530. // Edit
  531. // @Title 编辑系统用户
  532. // @Description 编辑系统用户接口
  533. // @Param request body system.SysuserEditReq true "type json string"
  534. // @Success 200 编辑成功
  535. // @router /sysuser/edit [post]
  536. func (this *SysAdminController) Edit() {
  537. br := new(models.BaseResponse).Init()
  538. defer func() {
  539. this.Data["json"] = br
  540. this.ServeJSON()
  541. }()
  542. var req system.SysuserEditReq
  543. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  544. if err != nil {
  545. br.Msg = "参数解析异常!"
  546. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  547. return
  548. }
  549. if req.RoleId <= 0 {
  550. br.Msg = "请选择角色"
  551. br.ErrMsg = "角色ID小于等于0"
  552. return
  553. }
  554. //根据用户id获取用户信息
  555. adminInfo, err := system.GetSysAdminById(req.AdminId)
  556. if err != nil {
  557. if err.Error() == utils.ErrNoRow() {
  558. br.Msg = "用户已被删除, 请刷新页面"
  559. return
  560. }
  561. br.Msg = "获取数据失败"
  562. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error() + ";AdminId:" + fmt.Sprint(req.AdminId)
  563. return
  564. }
  565. // 根据用户登录用户名获取用户信息
  566. item, err := system.GetSysAdminByName(req.AdminName)
  567. if err != nil && err.Error() != utils.ErrNoRow() {
  568. br.Msg = "获取数据失败"
  569. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error() + ";AdminName:" + req.AdminName
  570. return
  571. }
  572. if item != nil && item.AdminId != req.AdminId {
  573. br.Msg = "账号名称已存在,请重新输入"
  574. return
  575. }
  576. // 手机号和邮箱必填一个
  577. req.Mobile = strings.TrimSpace(req.Mobile)
  578. req.Email = strings.TrimSpace(req.Email)
  579. if req.Mobile == "" && req.Email == "" {
  580. br.Msg = "至少输入一个手机号或邮箱"
  581. return
  582. }
  583. if req.Mobile != "" {
  584. if req.TelAreaCode == "86" {
  585. if !utils.ValidateMobileFormatat(req.Mobile) {
  586. br.Msg = "手机号格式有误, 请检查"
  587. return
  588. }
  589. }
  590. mobileCount, e := system.GetSysAdminCountByMobile(req.Mobile, adminInfo.AdminId)
  591. if e != nil {
  592. br.Msg = "判断手机号是否存在失败"
  593. br.ErrMsg = "判断手机号是否存在失败,Err:" + e.Error()
  594. return
  595. }
  596. if mobileCount > 0 {
  597. br.Msg = "手机号已存在,请重新填写"
  598. br.IsSendEmail = false
  599. return
  600. }
  601. }
  602. if req.Email != "" {
  603. if !utils.ValidateEmailFormatat(req.Email) {
  604. br.Msg = "邮箱格式有误, 请检查"
  605. return
  606. }
  607. emailUser, e := system.GetSysUserByEmail(req.Email)
  608. if e != nil && e.Error() != utils.ErrNoRow() {
  609. br.Msg = "操作失败"
  610. br.ErrMsg = "邮箱获取用户信息失败, Err: " + e.Error()
  611. return
  612. }
  613. if emailUser != nil && emailUser.AdminId != adminInfo.AdminId {
  614. br.Msg = "邮箱已存在, 请检查"
  615. return
  616. }
  617. }
  618. // 角色
  619. var roleName string
  620. roleItem, err := system.GetSysRoleById(req.RoleId)
  621. if err != nil {
  622. if err.Error() == utils.ErrNoRow() {
  623. br.Msg = "角色不存在,请重新选择"
  624. br.ErrMsg = "角色不存在"
  625. return
  626. }
  627. br.Msg = "获取数据失败"
  628. br.ErrMsg = "获取角色数据失败,Err:" + err.Error()
  629. return
  630. }
  631. if roleItem != nil {
  632. roleName = roleItem.RoleName
  633. }
  634. // 员工工号
  635. req.EmployeeId = strings.TrimSpace(req.EmployeeId)
  636. if req.EmployeeId != "" && (utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox) {
  637. // 去重
  638. countOB := new(system.Admin)
  639. countCond := ` AND employee_id = ? AND admin_id <> ?`
  640. countPars := make([]interface{}, 0)
  641. countPars = append(countPars, req.EmployeeId, req.AdminId)
  642. countEmployee, e := countOB.GetCountByCondition(countCond, countPars)
  643. if e != nil {
  644. br.Msg = "工号去重查询失败"
  645. br.ErrMsg = "工号去重查询失败, Err: " + e.Error()
  646. return
  647. }
  648. if countEmployee > 0 {
  649. br.Msg = "工号已存在"
  650. return
  651. }
  652. }
  653. // 管理权限
  654. var authority int
  655. if roleItem.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  656. authority = 3
  657. } else if roleItem.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
  658. authority = 4
  659. } else if roleItem.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  660. authority = 2
  661. } else {
  662. if strings.Contains(roleItem.RoleType, "销售主管") {
  663. authority = 2
  664. } else if strings.Contains(roleItem.RoleType, "部门经理") {
  665. authority = 1
  666. } else {
  667. authority = 0
  668. }
  669. }
  670. adminInfo.AdminName = req.AdminName
  671. adminInfo.RealName = req.RealName
  672. adminInfo.LastUpdatedTime = time.Now().Format(utils.FormatDateTime)
  673. adminInfo.Mobile = req.Mobile
  674. adminInfo.RoleId = req.RoleId
  675. adminInfo.RoleName = roleName
  676. adminInfo.Enabled = req.Enabled
  677. adminInfo.Authority = authority
  678. adminInfo.Position = req.Position
  679. adminInfo.RoleTypeCode = roleItem.RoleTypeCode
  680. adminInfo.Province = req.Province
  681. adminInfo.ProvinceCode = req.ProvinceCode
  682. adminInfo.City = req.City
  683. adminInfo.CityCode = req.CityCode
  684. adminInfo.EmployeeId = req.EmployeeId
  685. adminInfo.Email = req.Email
  686. adminInfo.TelAreaCode = req.TelAreaCode
  687. cols := []string{
  688. "AdminName", "RealName", "LastUpdatedTime", "Mobile", "RoleId", "RoleName", "Enabled", "Authority",
  689. "Position", "RoleTypeCode", "Province", "ProvinceCode", "City", "CityCode", "EmployeeId", "Email", "TelAreaCode",
  690. }
  691. if e := adminInfo.Update(cols); e != nil {
  692. br.Msg = "编辑失败"
  693. br.ErrMsg = "更新用户信息失败, Err:" + e.Error()
  694. return
  695. }
  696. // 同步用户缓存
  697. if utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox {
  698. var syncData system.SyncAdminData
  699. syncData.Source = utils.SOURCE_ETA_FLAG
  700. syncData.AdminName = adminInfo.AdminName
  701. _ = utils.Rc.LPush(utils.CACHE_SYNC_ADMIN, syncData)
  702. }
  703. // 用户登出
  704. logOutSystemUser(adminInfo.AdminId)
  705. // 研究方向分组
  706. if e := services.UpdateResearcherTagGroup(req.AdminId, req.ResearchGroupIds); e != nil {
  707. br.Msg = "编辑失败"
  708. br.ErrMsg = "更新用户研究方向失败, Err:" + e.Error()
  709. return
  710. }
  711. // 清楚系统用户列表缓存key
  712. utils.Rc.Delete(utils.CACHE_KEY_ADMIN)
  713. utils.Rc.Delete(utils.CACHE_KEY_ADMIN_ID)
  714. br.Ret = 200
  715. br.Success = true
  716. br.IsAddLog = true
  717. br.Msg = "编辑成功"
  718. }
  719. // @Title 开启/禁用系统用户
  720. // @Description 开启/禁用系统用户接口
  721. // @Param request body system.SysuserEditReq true "type json string"
  722. // @Success 200 操作成功
  723. // @router /sysuser/editEnabled [post]
  724. func (this *SysAdminController) EditEnabled() {
  725. br := new(models.BaseResponse).Init()
  726. defer func() {
  727. this.Data["json"] = br
  728. this.ServeJSON()
  729. }()
  730. var req system.SysuserEditEnabledReq
  731. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  732. if err != nil {
  733. br.Msg = "参数解析异常!"
  734. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  735. return
  736. }
  737. adminItem, err := system.GetSysAdminById(req.AdminId)
  738. if err != nil {
  739. br.Msg = "获取数据失败"
  740. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
  741. return
  742. }
  743. if req.Enabled == 0 {
  744. //禁用
  745. err = system.DisableAdmin(req.AdminId)
  746. if err != nil {
  747. br.Msg = "修改失败"
  748. br.ErrMsg = "修改系统用户数据失败,Err:" + err.Error()
  749. return
  750. }
  751. } else {
  752. admin := new(system.Admin)
  753. admin.Enabled = req.Enabled
  754. admin.AdminId = req.AdminId
  755. err = system.EditAdminEnabled(admin)
  756. if err != nil {
  757. br.Msg = "修改失败"
  758. br.ErrMsg = "修改系统用户数据失败,Err:" + err.Error()
  759. return
  760. }
  761. }
  762. // 同步用户缓存
  763. if utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox {
  764. var syncData system.SyncAdminData
  765. syncData.Source = utils.SOURCE_ETA_FLAG
  766. syncData.AdminName = adminItem.AdminName
  767. _ = utils.Rc.LPush(utils.CACHE_SYNC_ADMIN, syncData)
  768. }
  769. //用户被禁用的情况下,需要将他对应的token给过期
  770. if adminItem.Enabled == 1 && req.Enabled == 0 {
  771. logOutSystemUser(adminItem.AdminId)
  772. }
  773. // 联动弘则研究公司下的联系人启禁用
  774. {
  775. go services.SwitchHzUserEnabledByMobile(req.Enabled, adminItem.Mobile)
  776. }
  777. if err != nil {
  778. br.Msg = "操作失败"
  779. br.ErrMsg = "操作失败,Err:" + err.Error()
  780. return
  781. }
  782. br.Ret = 200
  783. br.Success = true
  784. br.IsAddLog = true
  785. br.Msg = "操作成功"
  786. }
  787. // @Title 删除系统用户
  788. // @Description 删除系统用户接口
  789. // @Param request body system.SysuserDeleteReq true "type json string"
  790. // @Success 200 删除成功
  791. // @router /sysuser/delete [post]
  792. func (this *SysAdminController) Delete() {
  793. br := new(models.BaseResponse).Init()
  794. defer func() {
  795. this.Data["json"] = br
  796. this.ServeJSON()
  797. }()
  798. var req system.SysuserDeleteReq
  799. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  800. if err != nil {
  801. br.Msg = "参数解析异常!"
  802. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  803. return
  804. }
  805. if req.AdminId <= 0 {
  806. br.Msg = "参数错误"
  807. br.ErrMsg = "参数错误,GroupId 小于等于0 "
  808. return
  809. }
  810. mobile := ""
  811. adminInfo, _ := system.GetSysUserById(req.AdminId)
  812. if adminInfo != nil {
  813. mobile = adminInfo.Mobile
  814. }
  815. err = system.DeleteSysuser(req.AdminId)
  816. if err != nil {
  817. br.Msg = "删除失败"
  818. br.ErrMsg = "删除失败,Err:" + err.Error()
  819. return
  820. }
  821. // 同步用户缓存
  822. if utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox {
  823. var syncData system.SyncAdminData
  824. syncData.Source = utils.SOURCE_ETA_FLAG
  825. syncData.AdminName = adminInfo.AdminName
  826. _ = utils.Rc.LPush(utils.CACHE_SYNC_ADMIN, syncData)
  827. }
  828. // 删除手工数据关联用户
  829. {
  830. go data_manage.DeleteManualUser(req.AdminId)
  831. }
  832. // 删除弘则研究公司下的相同手机号联系人
  833. {
  834. go services.DeleteHzUserByMobile(mobile)
  835. }
  836. // 清楚系统用户列表缓存key
  837. utils.Rc.Delete(utils.CACHE_KEY_ADMIN)
  838. utils.Rc.Delete(utils.CACHE_KEY_ADMIN_ID)
  839. br.Ret = 200
  840. br.Success = true
  841. br.IsAddLog = true
  842. br.Msg = "删除成功"
  843. }
  844. /*
  845. func init() {
  846. fmt.Println("start")
  847. pwdStr:=`11111`
  848. //compile := `(\d+.*[^a-zA-Z]+){6,12}|([^a-zA-Z]+.*\d+){6,12}`
  849. compile := `([0-9a-z]+){6,12}|(a-z0-9]+){6,12}`
  850. ///^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$/
  851. ///^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$/
  852. reg := regexp.MustCompile(compile)
  853. flag := reg.MatchString(pwdStr)
  854. fmt.Println(flag)
  855. fmt.Println("end")
  856. }*/
  857. // SetConfig
  858. // @Title 用户信息配置接口
  859. // @Description 用户信息配置接口
  860. // @Success 200 {object} system.SetAdminConfigReq
  861. // @router /sysuser/config/set [post]
  862. func (this *SysAdminController) SetConfig() {
  863. br := new(models.BaseResponse).Init()
  864. defer func() {
  865. this.Data["json"] = br
  866. this.ServeJSON()
  867. }()
  868. sysUser := this.SysUser
  869. if sysUser == nil {
  870. br.Msg = "请登录"
  871. br.ErrMsg = "请登录,SysUser Is Empty"
  872. br.Ret = 408
  873. return
  874. }
  875. var req system.SetAdminConfigReq
  876. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  877. if err != nil {
  878. br.Msg = "参数解析异常!"
  879. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  880. return
  881. }
  882. item, err := system.GetConfigDetailByCode(this.SysUser.AdminId, req.ConfigCode)
  883. if err != nil {
  884. if err.Error() != utils.ErrNoRow() {
  885. br.Msg = "设置失败"
  886. br.ErrMsg = "设置失败,Err:" + err.Error()
  887. return
  888. }
  889. // 获取默认配置
  890. defaultConfig, err := system.GetDefaultConfigDetailByCode(req.ConfigCode)
  891. if err != nil {
  892. br.Msg = "设置失败"
  893. br.ErrMsg = "获取默认配置失败,Err:" + err.Error()
  894. return
  895. }
  896. adminConfigItem := &system.AdminConfig{
  897. //ConfigId: 0,
  898. AdminId: this.SysUser.AdminId,
  899. ConfigCode: req.ConfigCode,
  900. ConfigValue: req.ConfigValue,
  901. Remark: defaultConfig.Remark,
  902. CreateTime: time.Now(),
  903. }
  904. err = adminConfigItem.Create()
  905. if err != nil {
  906. br.Msg = "设置失败"
  907. br.ErrMsg = "设置失败,Err:" + err.Error()
  908. return
  909. }
  910. } else {
  911. // 存在配置,那么就修改
  912. item.ConfigValue = req.ConfigValue
  913. err = item.Update([]string{"ConfigValue"})
  914. if err != nil {
  915. br.Msg = "设置失败"
  916. br.ErrMsg = "设置失败,Err:" + err.Error()
  917. return
  918. }
  919. }
  920. br.Ret = 200
  921. br.Success = true
  922. br.Msg = "设置成功"
  923. }
  924. // logOutSystemUser 用户登出
  925. func logOutSystemUser(adminId int) {
  926. // 退出管理后台
  927. _ = system.ExpiredSysSessionByAdminId(adminId)
  928. // 退出随手办公小程序
  929. _ = system.UnBindAdminRecordByUserId(adminId)
  930. }
  931. // Move
  932. // @Title 移动分组
  933. // @Description 移动分组
  934. // @Param request body system.SysUserMoveReq true "type json string"
  935. // @Success 200 编辑成功
  936. // @router /sysuser/move [post]
  937. func (this *SysAdminController) Move() {
  938. br := new(models.BaseResponse).Init()
  939. defer func() {
  940. this.Data["json"] = br
  941. this.ServeJSON()
  942. }()
  943. var req system.SysUserMoveReq
  944. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  945. if err != nil {
  946. br.Msg = "参数解析异常!"
  947. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  948. return
  949. }
  950. if req.AdminId <= 0 {
  951. br.Msg = "参数有误"
  952. br.ErrMsg = "参数有误, AdminId"
  953. return
  954. }
  955. if req.DepartmentId <= 0 {
  956. br.Msg = "请选择部门"
  957. return
  958. }
  959. adminInfo, err := system.GetSysAdminById(req.AdminId)
  960. if err != nil && err.Error() != utils.ErrNoRow() {
  961. br.Msg = "获取数据失败"
  962. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error() + ";AdminId:" + fmt.Sprint(req.AdminId)
  963. return
  964. }
  965. var departmentName, groupName, teamName string
  966. if req.DepartmentId > 0 {
  967. departmentItem, err := system.GetSysDepartmentById(req.DepartmentId)
  968. if err != nil {
  969. br.Msg = "获取数据失败"
  970. br.ErrMsg = "获取部门数据失败,Err:" + err.Error()
  971. return
  972. }
  973. if departmentItem != nil {
  974. departmentName = departmentItem.DepartmentName
  975. }
  976. }
  977. if req.GroupId > 0 {
  978. groupItem, err := system.GetSysGroupById(req.GroupId)
  979. if err != nil {
  980. br.Msg = "获取数据失败"
  981. br.ErrMsg = "获取分组数据失败,Err:" + err.Error()
  982. return
  983. }
  984. if groupItem != nil {
  985. groupName = groupItem.GroupName
  986. }
  987. }
  988. if req.TeamId > 0 {
  989. teamItem, err := system.GetSysGroupById(req.TeamId)
  990. if err != nil {
  991. br.Msg = "获取数据失败"
  992. br.ErrMsg = "获取小组数据失败,Err:" + err.Error()
  993. return
  994. }
  995. if teamItem != nil {
  996. teamName = teamItem.GroupName
  997. }
  998. }
  999. adminInfo.DepartmentId = req.DepartmentId
  1000. adminInfo.DepartmentName = departmentName
  1001. if req.TeamId <= 0 {
  1002. adminInfo.GroupId = req.GroupId
  1003. adminInfo.GroupName = groupName
  1004. } else {
  1005. adminInfo.GroupId = req.TeamId
  1006. adminInfo.GroupName = teamName
  1007. }
  1008. adminInfo.LastUpdatedTime = time.Now().Format(utils.FormatDateTime)
  1009. if e := adminInfo.Update([]string{"DepartmentId", "DepartmentName", "GroupId", "GroupName", "LastUpdatedTime"}); e != nil {
  1010. br.Msg = "操作失败"
  1011. br.ErrMsg = "更新系统用户分组失败, Err: " + e.Error()
  1012. return
  1013. }
  1014. // 修改客户关联的分组
  1015. {
  1016. if req.TeamId > 0 {
  1017. if req.TeamId != adminInfo.GroupId {
  1018. err = company.ModifyCompanyGroupId(req.AdminId, req.TeamId)
  1019. if err != nil {
  1020. br.Msg = "编辑失败"
  1021. br.ErrMsg = "ModifyCompanyGroupId,Err:" + err.Error()
  1022. return
  1023. }
  1024. }
  1025. } else {
  1026. if req.GroupId != adminInfo.GroupId {
  1027. err = company.ModifyCompanyGroupId(req.AdminId, req.GroupId)
  1028. if err != nil {
  1029. br.Msg = "编辑失败"
  1030. br.ErrMsg = "ModifyCompanyGroupId,Err:" + err.Error()
  1031. return
  1032. }
  1033. }
  1034. }
  1035. if req.DepartmentId != adminInfo.DepartmentId {
  1036. err = company.ModifyCompanyDepartmentId(req.AdminId, req.DepartmentId)
  1037. if err != nil {
  1038. br.Msg = "编辑失败"
  1039. br.ErrMsg = "ModifyCompanyDepartmentId,Err:" + err.Error()
  1040. return
  1041. }
  1042. }
  1043. }
  1044. // 同步用户缓存
  1045. if utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox {
  1046. var syncData system.SyncAdminData
  1047. syncData.Source = utils.SOURCE_ETA_FLAG
  1048. syncData.AdminName = adminInfo.AdminName
  1049. _ = utils.Rc.LPush(utils.CACHE_SYNC_ADMIN, syncData)
  1050. }
  1051. // 清除系统用户列表缓存key
  1052. _ = utils.Rc.Delete(utils.CACHE_KEY_ADMIN)
  1053. _ = utils.Rc.Delete(utils.CACHE_KEY_ADMIN_ID)
  1054. br.Ret = 200
  1055. br.Success = true
  1056. br.IsAddLog = true
  1057. br.Msg = "操作成功"
  1058. }
  1059. // ResetPass
  1060. // @Title 重置密码
  1061. // @Description 重置密码
  1062. // @Param request body system.SysUserResetPassReq true "type json string"
  1063. // @Success 200 编辑成功
  1064. // @router /sysuser/reset_pass [post]
  1065. func (this *SysAdminController) ResetPass() {
  1066. br := new(models.BaseResponse).Init()
  1067. defer func() {
  1068. this.Data["json"] = br
  1069. this.ServeJSON()
  1070. }()
  1071. var req system.SysUserResetPassReq
  1072. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1073. if err != nil {
  1074. br.Msg = "参数解析异常!"
  1075. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1076. return
  1077. }
  1078. if req.AdminId <= 0 {
  1079. br.Msg = "参数有误"
  1080. br.ErrMsg = "参数有误, AdminId"
  1081. return
  1082. }
  1083. req.Password = strings.TrimSpace(req.Password)
  1084. if req.Password == "" {
  1085. br.Msg = "新密码不能为空"
  1086. return
  1087. }
  1088. req.RePassword = strings.TrimSpace(req.RePassword)
  1089. if req.RePassword == "" {
  1090. br.Msg = "确认密码不能为空"
  1091. return
  1092. }
  1093. if req.Password != req.RePassword {
  1094. br.Msg = "两次输入密码不一致,请重新填写"
  1095. return
  1096. }
  1097. adminInfo, err := system.GetSysAdminById(req.AdminId)
  1098. if err != nil {
  1099. if err.Error() == utils.ErrNoRow() {
  1100. br.Msg = "用户已被删除, 请刷新页面"
  1101. return
  1102. }
  1103. br.Msg = "获取数据失败"
  1104. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error() + ";AdminId:" + fmt.Sprint(req.AdminId)
  1105. return
  1106. }
  1107. b, err := base64.StdEncoding.DecodeString(req.Password)
  1108. if err != nil {
  1109. br.Msg = "解析数据失败"
  1110. br.ErrMsg = "解析数据失败,Err:" + err.Error()
  1111. return
  1112. }
  1113. pwd := string(b)
  1114. //pwd = strings.ToLower(pwd)
  1115. pwd = utils.MD5(pwd)
  1116. adminInfo.Password = pwd
  1117. adminInfo.LastUpdatedPasswordTime = time.Now().Format(utils.FormatDateTime)
  1118. adminInfo.LastUpdatedTime = time.Now().Format(utils.FormatDateTime)
  1119. if e := adminInfo.Update([]string{"Password", "LastUpdatedPasswordTime", "LastUpdatedTime"}); e != nil {
  1120. br.Msg = "操作失败"
  1121. br.ErrMsg = "更新系统用户分组失败, Err: " + e.Error()
  1122. return
  1123. }
  1124. // 同步用户缓存
  1125. if utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox {
  1126. var syncData system.SyncAdminData
  1127. syncData.Source = utils.SOURCE_ETA_FLAG
  1128. syncData.AdminName = adminInfo.AdminName
  1129. _ = utils.Rc.LPush(utils.CACHE_SYNC_ADMIN, syncData)
  1130. }
  1131. // 清除系统用户列表缓存key
  1132. _ = utils.Rc.Delete(utils.CACHE_KEY_ADMIN)
  1133. _ = utils.Rc.Delete(utils.CACHE_KEY_ADMIN_ID)
  1134. br.Ret = 200
  1135. br.Success = true
  1136. br.IsAddLog = true
  1137. br.Msg = "重置密码成功"
  1138. }