sys_admin.go 36 KB

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