sys_admin.go 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337
  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. if adminInfo.RoleName == "admin" && adminInfo.RealName == "admin" {
  696. adminInfo.LastUpdatedTime = time.Now().Format(utils.FormatDateTime)
  697. adminInfo.Mobile = req.Mobile
  698. adminInfo.Position = req.Position
  699. adminInfo.Province = req.Province
  700. adminInfo.ProvinceCode = req.ProvinceCode
  701. adminInfo.City = req.City
  702. adminInfo.CityCode = req.CityCode
  703. adminInfo.EmployeeId = req.EmployeeId
  704. adminInfo.Email = req.Email
  705. adminInfo.TelAreaCode = req.TelAreaCode
  706. adminInfo.IsLdap = req.IsLdap
  707. cols := []string{
  708. "LastUpdatedTime", "Mobile", "Position", "Province", "ProvinceCode",
  709. "City", "CityCode", "EmployeeId", "Email", "TelAreaCode", "IsLdap",
  710. }
  711. if e := adminInfo.Update(cols); e != nil {
  712. br.Msg = "编辑失败"
  713. br.ErrMsg = "更新用户信息失败, Err:" + e.Error()
  714. return
  715. }
  716. } else {
  717. adminInfo.AdminName = req.AdminName
  718. adminInfo.RealName = req.RealName
  719. adminInfo.LastUpdatedTime = time.Now().Format(utils.FormatDateTime)
  720. adminInfo.Mobile = req.Mobile
  721. adminInfo.RoleId = req.RoleId
  722. adminInfo.RoleName = roleName
  723. adminInfo.Enabled = req.Enabled
  724. adminInfo.Authority = authority
  725. adminInfo.Position = req.Position
  726. adminInfo.RoleTypeCode = roleItem.RoleTypeCode
  727. adminInfo.Province = req.Province
  728. adminInfo.ProvinceCode = req.ProvinceCode
  729. adminInfo.City = req.City
  730. adminInfo.CityCode = req.CityCode
  731. adminInfo.EmployeeId = req.EmployeeId
  732. adminInfo.Email = req.Email
  733. adminInfo.TelAreaCode = req.TelAreaCode
  734. adminInfo.IsLdap = req.IsLdap
  735. cols := []string{
  736. "AdminName", "RealName", "LastUpdatedTime", "Mobile", "RoleId", "RoleName", "Enabled", "Authority",
  737. "Position", "RoleTypeCode", "Province", "ProvinceCode", "City", "CityCode", "EmployeeId", "Email", "TelAreaCode", "IsLdap",
  738. }
  739. if e := adminInfo.Update(cols); e != nil {
  740. br.Msg = "编辑失败"
  741. br.ErrMsg = "更新用户信息失败, Err:" + e.Error()
  742. return
  743. }
  744. }
  745. // 同步用户缓存
  746. if utils.BusinessCode == utils.BusinessCodeRelease {
  747. var syncData system.SyncAdminData
  748. syncData.Source = utils.SOURCE_ETA_FLAG
  749. syncData.AdminName = adminInfo.AdminName
  750. _ = utils.Rc.LPush(utils.CACHE_SYNC_ADMIN, syncData)
  751. // 研究方向分组
  752. if e := services.UpdateResearcherTagGroup(req.AdminId, req.ResearchGroupIds); e != nil {
  753. br.Msg = "编辑失败"
  754. br.ErrMsg = "更新用户研究方向失败, Err:" + e.Error()
  755. return
  756. }
  757. }
  758. // 用户登出
  759. logOutSystemUser(adminInfo.AdminId)
  760. // 清楚系统用户列表缓存key
  761. utils.Rc.Delete(utils.CACHE_KEY_ADMIN)
  762. utils.Rc.Delete(utils.CACHE_KEY_ADMIN_ID)
  763. // 试用客户更新对应信息
  764. if utils.BusinessCode == utils.BusinessCodeSandbox && adminInfo.DepartmentName == "ETA试用客户" {
  765. go func() {
  766. var r etaTrialService.EtaTrialUserEditReq
  767. r.RealName = req.RealName
  768. r.Position = req.Position
  769. r.Mobile = adminInfo.Mobile
  770. r.Enabled = req.Enabled
  771. _, _ = etaTrialService.EditEtaTrialUser(r)
  772. }()
  773. }
  774. go eta_forum.AdminSave(adminInfo.AdminId)
  775. br.Ret = 200
  776. br.Success = true
  777. br.IsAddLog = true
  778. br.Msg = "编辑成功"
  779. }
  780. // @Title 开启/禁用系统用户
  781. // @Description 开启/禁用系统用户接口
  782. // @Param request body system.SysuserEditReq true "type json string"
  783. // @Success 200 操作成功
  784. // @router /sysuser/editEnabled [post]
  785. func (this *SysAdminController) EditEnabled() {
  786. br := new(models.BaseResponse).Init()
  787. defer func() {
  788. this.Data["json"] = br
  789. this.ServeJSON()
  790. }()
  791. var req system.SysuserEditEnabledReq
  792. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  793. if err != nil {
  794. br.Msg = "参数解析异常!"
  795. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  796. return
  797. }
  798. adminItem, err := system.GetSysAdminById(req.AdminId)
  799. if err != nil {
  800. br.Msg = "获取数据失败"
  801. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
  802. return
  803. }
  804. if adminItem.RoleName == "admin" && adminItem.RealName == "admin" {
  805. br.Msg = "禁止对admin使用<禁用>功能"
  806. return
  807. }
  808. if req.Enabled == 0 {
  809. //禁用
  810. err = system.DisableAdmin(req.AdminId)
  811. if err != nil {
  812. br.Msg = "修改失败"
  813. br.ErrMsg = "修改系统用户数据失败,Err:" + err.Error()
  814. return
  815. }
  816. // 更新试用平台客户
  817. if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
  818. go func() {
  819. var r etaTrialService.EtaTrialUserReq
  820. r.Mobile = adminItem.Mobile
  821. _, _ = etaTrialService.DisableEtaTrialUser(r)
  822. }()
  823. }
  824. } else {
  825. admin := new(system.Admin)
  826. admin.Enabled = req.Enabled
  827. admin.AdminId = req.AdminId
  828. err = system.EditAdminEnabled(admin)
  829. if err != nil {
  830. br.Msg = "修改失败"
  831. br.ErrMsg = "修改系统用户数据失败,Err:" + err.Error()
  832. return
  833. }
  834. }
  835. // 同步用户缓存
  836. if utils.BusinessCode == utils.BusinessCodeRelease {
  837. var syncData system.SyncAdminData
  838. syncData.Source = utils.SOURCE_ETA_FLAG
  839. syncData.AdminName = adminItem.AdminName
  840. _ = utils.Rc.LPush(utils.CACHE_SYNC_ADMIN, syncData)
  841. // 联动弘则研究公司下的联系人启禁用
  842. go services.SwitchHzUserEnabledByMobile(req.Enabled, adminItem.Mobile)
  843. }
  844. //用户被禁用的情况下,需要将他对应的token给过期
  845. if adminItem.Enabled == 1 && req.Enabled == 0 {
  846. logOutSystemUser(adminItem.AdminId)
  847. }
  848. if err != nil {
  849. br.Msg = "操作失败"
  850. br.ErrMsg = "操作失败,Err:" + err.Error()
  851. return
  852. }
  853. go eta_forum.AdminSave(adminItem.AdminId)
  854. br.Ret = 200
  855. br.Success = true
  856. br.IsAddLog = true
  857. br.Msg = "操作成功"
  858. }
  859. // @Title 删除系统用户
  860. // @Description 删除系统用户接口
  861. // @Param request body system.SysuserDeleteReq true "type json string"
  862. // @Success 200 删除成功
  863. // @router /sysuser/delete [post]
  864. func (this *SysAdminController) Delete() {
  865. br := new(models.BaseResponse).Init()
  866. defer func() {
  867. this.Data["json"] = br
  868. this.ServeJSON()
  869. }()
  870. var req system.SysuserDeleteReq
  871. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  872. if err != nil {
  873. br.Msg = "参数解析异常!"
  874. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  875. return
  876. }
  877. if req.AdminId <= 0 {
  878. br.Msg = "参数错误"
  879. br.ErrMsg = "参数错误,GroupId 小于等于0 "
  880. return
  881. }
  882. mobile := ""
  883. adminInfo, _ := system.GetSysUserById(req.AdminId)
  884. if adminInfo != nil {
  885. mobile = adminInfo.Mobile
  886. }
  887. err = system.DeleteSysuser(req.AdminId)
  888. if err != nil {
  889. br.Msg = "删除失败"
  890. br.ErrMsg = "删除失败,Err:" + err.Error()
  891. return
  892. }
  893. // 同步用户缓存
  894. if utils.BusinessCode == utils.BusinessCodeRelease {
  895. var syncData system.SyncAdminData
  896. syncData.Source = utils.SOURCE_ETA_FLAG
  897. syncData.AdminName = adminInfo.AdminName
  898. _ = utils.Rc.LPush(utils.CACHE_SYNC_ADMIN, syncData)
  899. // 删除弘则研究公司下的相同手机号联系人
  900. go services.DeleteHzUserByMobile(mobile)
  901. }
  902. // 删除手工数据关联用户
  903. {
  904. go data_manage.DeleteManualUser(req.AdminId)
  905. }
  906. // 清楚系统用户列表缓存key
  907. utils.Rc.Delete(utils.CACHE_KEY_ADMIN)
  908. utils.Rc.Delete(utils.CACHE_KEY_ADMIN_ID)
  909. // 删除试用平台客户
  910. if utils.BusinessCode == utils.BusinessCodeSandbox && adminInfo.DepartmentName == "ETA试用客户" {
  911. go func() {
  912. var r etaTrialService.EtaTrialUserReq
  913. r.Mobile = mobile
  914. _, _ = etaTrialService.RemoveEtaTrialUser(r)
  915. }()
  916. }
  917. go eta_forum.AdminDelete(adminInfo.AdminName)
  918. br.Ret = 200
  919. br.Success = true
  920. br.IsAddLog = true
  921. br.Msg = "删除成功"
  922. }
  923. /*
  924. func init() {
  925. fmt.Println("start")
  926. pwdStr:=`11111`
  927. //compile := `(\d+.*[^a-zA-Z]+){6,12}|([^a-zA-Z]+.*\d+){6,12}`
  928. compile := `([0-9a-z]+){6,12}|(a-z0-9]+){6,12}`
  929. ///^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$/
  930. ///^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$/
  931. reg := regexp.MustCompile(compile)
  932. flag := reg.MatchString(pwdStr)
  933. fmt.Println(flag)
  934. fmt.Println("end")
  935. }*/
  936. // SetConfig
  937. // @Title 用户信息配置接口
  938. // @Description 用户信息配置接口
  939. // @Success 200 {object} system.SetAdminConfigReq
  940. // @router /sysuser/config/set [post]
  941. func (this *SysAdminController) SetConfig() {
  942. br := new(models.BaseResponse).Init()
  943. defer func() {
  944. this.Data["json"] = br
  945. this.ServeJSON()
  946. }()
  947. sysUser := this.SysUser
  948. if sysUser == nil {
  949. br.Msg = "请登录"
  950. br.ErrMsg = "请登录,SysUser Is Empty"
  951. br.Ret = 408
  952. return
  953. }
  954. var req system.SetAdminConfigReq
  955. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  956. if err != nil {
  957. br.Msg = "参数解析异常!"
  958. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  959. return
  960. }
  961. item, err := system.GetConfigDetailByCode(this.SysUser.AdminId, req.ConfigCode)
  962. if err != nil {
  963. if err.Error() != utils.ErrNoRow() {
  964. br.Msg = "设置失败"
  965. br.ErrMsg = "设置失败,Err:" + err.Error()
  966. return
  967. }
  968. // 获取默认配置
  969. defaultConfig, err := system.GetDefaultConfigDetailByCode(req.ConfigCode)
  970. if err != nil {
  971. br.Msg = "设置失败"
  972. br.ErrMsg = "获取默认配置失败,Err:" + err.Error()
  973. return
  974. }
  975. adminConfigItem := &system.AdminConfig{
  976. //ConfigId: 0,
  977. AdminId: this.SysUser.AdminId,
  978. ConfigCode: req.ConfigCode,
  979. ConfigValue: req.ConfigValue,
  980. Remark: defaultConfig.Remark,
  981. CreateTime: time.Now(),
  982. }
  983. err = adminConfigItem.Create()
  984. if err != nil {
  985. br.Msg = "设置失败"
  986. br.ErrMsg = "设置失败,Err:" + err.Error()
  987. return
  988. }
  989. } else {
  990. // 存在配置,那么就修改
  991. item.ConfigValue = req.ConfigValue
  992. err = item.Update([]string{"ConfigValue"})
  993. if err != nil {
  994. br.Msg = "设置失败"
  995. br.ErrMsg = "设置失败,Err:" + err.Error()
  996. return
  997. }
  998. }
  999. br.Ret = 200
  1000. br.Success = true
  1001. br.Msg = "设置成功"
  1002. }
  1003. // logOutSystemUser 用户登出
  1004. func logOutSystemUser(adminId int) {
  1005. // 退出管理后台
  1006. _ = system.ExpiredSysSessionByAdminId(adminId)
  1007. // 退出随手办公小程序
  1008. _ = system.UnBindAdminRecordByUserId(adminId)
  1009. }
  1010. // Move
  1011. // @Title 移动分组
  1012. // @Description 移动分组
  1013. // @Param request body system.SysUserMoveReq true "type json string"
  1014. // @Success 200 编辑成功
  1015. // @router /sysuser/move [post]
  1016. func (this *SysAdminController) Move() {
  1017. br := new(models.BaseResponse).Init()
  1018. defer func() {
  1019. this.Data["json"] = br
  1020. this.ServeJSON()
  1021. }()
  1022. var req system.SysUserMoveReq
  1023. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1024. if err != nil {
  1025. br.Msg = "参数解析异常!"
  1026. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1027. return
  1028. }
  1029. if req.AdminId <= 0 {
  1030. br.Msg = "参数有误"
  1031. br.ErrMsg = "参数有误, AdminId"
  1032. return
  1033. }
  1034. if req.DepartmentId <= 0 {
  1035. br.Msg = "请选择部门"
  1036. return
  1037. }
  1038. adminInfo, err := system.GetSysAdminById(req.AdminId)
  1039. if err != nil && err.Error() != utils.ErrNoRow() {
  1040. br.Msg = "获取数据失败"
  1041. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error() + ";AdminId:" + fmt.Sprint(req.AdminId)
  1042. return
  1043. }
  1044. var departmentName, groupName, teamName string
  1045. if req.DepartmentId > 0 {
  1046. departmentItem, err := system.GetSysDepartmentById(req.DepartmentId)
  1047. if err != nil {
  1048. br.Msg = "获取数据失败"
  1049. br.ErrMsg = "获取部门数据失败,Err:" + err.Error()
  1050. return
  1051. }
  1052. if departmentItem != nil {
  1053. departmentName = departmentItem.DepartmentName
  1054. }
  1055. }
  1056. if req.GroupId > 0 {
  1057. groupItem, err := system.GetSysGroupById(req.GroupId)
  1058. if err != nil {
  1059. br.Msg = "获取数据失败"
  1060. br.ErrMsg = "获取分组数据失败,Err:" + err.Error()
  1061. return
  1062. }
  1063. if groupItem != nil {
  1064. groupName = groupItem.GroupName
  1065. }
  1066. }
  1067. if req.TeamId > 0 {
  1068. teamItem, err := system.GetSysGroupById(req.TeamId)
  1069. if err != nil {
  1070. br.Msg = "获取数据失败"
  1071. br.ErrMsg = "获取小组数据失败,Err:" + err.Error()
  1072. return
  1073. }
  1074. if teamItem != nil {
  1075. teamName = teamItem.GroupName
  1076. }
  1077. }
  1078. adminInfo.DepartmentId = req.DepartmentId
  1079. adminInfo.DepartmentName = departmentName
  1080. if req.TeamId <= 0 {
  1081. adminInfo.GroupId = req.GroupId
  1082. adminInfo.GroupName = groupName
  1083. } else {
  1084. adminInfo.GroupId = req.TeamId
  1085. adminInfo.GroupName = teamName
  1086. }
  1087. adminInfo.LastUpdatedTime = time.Now().Format(utils.FormatDateTime)
  1088. if e := adminInfo.Update([]string{"DepartmentId", "DepartmentName", "GroupId", "GroupName", "LastUpdatedTime"}); e != nil {
  1089. br.Msg = "操作失败"
  1090. br.ErrMsg = "更新系统用户分组失败, Err: " + e.Error()
  1091. return
  1092. }
  1093. // 修改客户关联的分组
  1094. {
  1095. if req.TeamId > 0 {
  1096. if req.TeamId != adminInfo.GroupId {
  1097. err = company.ModifyCompanyGroupId(req.AdminId, req.TeamId)
  1098. if err != nil {
  1099. br.Msg = "编辑失败"
  1100. br.ErrMsg = "ModifyCompanyGroupId,Err:" + err.Error()
  1101. return
  1102. }
  1103. }
  1104. } else {
  1105. if req.GroupId != adminInfo.GroupId {
  1106. err = company.ModifyCompanyGroupId(req.AdminId, req.GroupId)
  1107. if err != nil {
  1108. br.Msg = "编辑失败"
  1109. br.ErrMsg = "ModifyCompanyGroupId,Err:" + err.Error()
  1110. return
  1111. }
  1112. }
  1113. }
  1114. if req.DepartmentId != adminInfo.DepartmentId {
  1115. err = company.ModifyCompanyDepartmentId(req.AdminId, req.DepartmentId)
  1116. if err != nil {
  1117. br.Msg = "编辑失败"
  1118. br.ErrMsg = "ModifyCompanyDepartmentId,Err:" + err.Error()
  1119. return
  1120. }
  1121. }
  1122. }
  1123. // 同步用户缓存
  1124. if utils.BusinessCode == utils.BusinessCodeRelease {
  1125. var syncData system.SyncAdminData
  1126. syncData.Source = utils.SOURCE_ETA_FLAG
  1127. syncData.AdminName = adminInfo.AdminName
  1128. _ = utils.Rc.LPush(utils.CACHE_SYNC_ADMIN, syncData)
  1129. }
  1130. // 清除系统用户列表缓存key
  1131. _ = utils.Rc.Delete(utils.CACHE_KEY_ADMIN)
  1132. _ = utils.Rc.Delete(utils.CACHE_KEY_ADMIN_ID)
  1133. br.Ret = 200
  1134. br.Success = true
  1135. br.IsAddLog = true
  1136. br.Msg = "操作成功"
  1137. }
  1138. // ResetPass
  1139. // @Title 重置密码
  1140. // @Description 重置密码
  1141. // @Param request body system.SysUserResetPassReq true "type json string"
  1142. // @Success 200 编辑成功
  1143. // @router /sysuser/reset_pass [post]
  1144. func (this *SysAdminController) ResetPass() {
  1145. br := new(models.BaseResponse).Init()
  1146. defer func() {
  1147. this.Data["json"] = br
  1148. this.ServeJSON()
  1149. }()
  1150. var req system.SysUserResetPassReq
  1151. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1152. if err != nil {
  1153. br.Msg = "参数解析异常!"
  1154. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1155. return
  1156. }
  1157. if req.AdminId <= 0 {
  1158. br.Msg = "参数有误"
  1159. br.ErrMsg = "参数有误, AdminId"
  1160. return
  1161. }
  1162. req.Password = strings.TrimSpace(req.Password)
  1163. if req.Password == "" {
  1164. br.Msg = "新密码不能为空"
  1165. return
  1166. }
  1167. req.RePassword = strings.TrimSpace(req.RePassword)
  1168. if req.RePassword == "" {
  1169. br.Msg = "确认密码不能为空"
  1170. return
  1171. }
  1172. if req.Password != req.RePassword {
  1173. br.Msg = "两次输入密码不一致,请重新填写"
  1174. return
  1175. }
  1176. adminInfo, err := system.GetSysAdminById(req.AdminId)
  1177. if err != nil {
  1178. if err.Error() == utils.ErrNoRow() {
  1179. br.Msg = "用户已被删除, 请刷新页面"
  1180. return
  1181. }
  1182. br.Msg = "获取数据失败"
  1183. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error() + ";AdminId:" + fmt.Sprint(req.AdminId)
  1184. return
  1185. }
  1186. b, err := base64.StdEncoding.DecodeString(req.Password)
  1187. if err != nil {
  1188. br.Msg = "解析数据失败"
  1189. br.ErrMsg = "解析数据失败,Err:" + err.Error()
  1190. return
  1191. }
  1192. pwd := string(b)
  1193. //pwd = strings.ToLower(pwd)
  1194. if !utils.CheckPwdV2(pwd) {
  1195. br.Msg = "密码格式错误,请重新输入"
  1196. return
  1197. }
  1198. pwd = utils.MD5(pwd)
  1199. adminInfo.Password = pwd
  1200. adminInfo.LastUpdatedPasswordTime = time.Now().Format(utils.FormatDateTime)
  1201. adminInfo.LastUpdatedTime = time.Now().Format(utils.FormatDateTime)
  1202. adminInfo.LastLoginTime = time.Now().Format(utils.FormatDateTime)
  1203. if e := adminInfo.Update([]string{"Password", "LastUpdatedPasswordTime", "LastUpdatedTime", "LastLoginTime"}); e != nil {
  1204. br.Msg = "操作失败"
  1205. br.ErrMsg = "更新系统用户分组失败, Err: " + e.Error()
  1206. return
  1207. }
  1208. // 同步用户缓存
  1209. if utils.BusinessCode == utils.BusinessCodeRelease {
  1210. var syncData system.SyncAdminData
  1211. syncData.Source = utils.SOURCE_ETA_FLAG
  1212. syncData.AdminName = adminInfo.AdminName
  1213. _ = utils.Rc.LPush(utils.CACHE_SYNC_ADMIN, syncData)
  1214. }
  1215. // 清除系统用户列表缓存key及异常登录缓存
  1216. _ = utils.Rc.Delete(utils.CACHE_KEY_ADMIN)
  1217. _ = utils.Rc.Delete(utils.CACHE_KEY_ADMIN_ID)
  1218. abnormalKey := fmt.Sprint(utils.CACHE_ABNORMAL_LOGIN, adminInfo.AdminName)
  1219. errPassKey := fmt.Sprint(utils.CACHE_LOGIN_ERR_PASS, adminInfo.AdminName)
  1220. _ = utils.Rc.Delete(abnormalKey)
  1221. _ = utils.Rc.Delete(errPassKey)
  1222. br.Ret = 200
  1223. br.Success = true
  1224. br.IsAddLog = true
  1225. br.Msg = "重置密码成功"
  1226. }
  1227. // Add
  1228. // @Title 用户详情信息
  1229. // @Description 用户详情信息
  1230. // @Param request body system.SysuserAddReq true "type json string"
  1231. // @Success 200 新增成功
  1232. // @router /sysuser/detail [get]
  1233. func (this *SysAdminController) Detail() {
  1234. br := new(models.BaseResponse).Init()
  1235. defer func() {
  1236. this.Data["json"] = br
  1237. this.ServeJSON()
  1238. }()
  1239. br.Data = this.SysUser
  1240. br.Ret = 200
  1241. br.Success = true
  1242. br.Msg = "获取成功"
  1243. }