sys_admin.go 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333
  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.CheckPwd(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. pwd = utils.MD5(pwd)
  1195. adminInfo.Password = pwd
  1196. adminInfo.LastUpdatedPasswordTime = time.Now().Format(utils.FormatDateTime)
  1197. adminInfo.LastUpdatedTime = time.Now().Format(utils.FormatDateTime)
  1198. adminInfo.LastLoginTime = time.Now().Format(utils.FormatDateTime)
  1199. if e := adminInfo.Update([]string{"Password", "LastUpdatedPasswordTime", "LastUpdatedTime", "LastLoginTime"}); e != nil {
  1200. br.Msg = "操作失败"
  1201. br.ErrMsg = "更新系统用户分组失败, Err: " + e.Error()
  1202. return
  1203. }
  1204. // 同步用户缓存
  1205. if utils.BusinessCode == utils.BusinessCodeRelease {
  1206. var syncData system.SyncAdminData
  1207. syncData.Source = utils.SOURCE_ETA_FLAG
  1208. syncData.AdminName = adminInfo.AdminName
  1209. _ = utils.Rc.LPush(utils.CACHE_SYNC_ADMIN, syncData)
  1210. }
  1211. // 清除系统用户列表缓存key及异常登录缓存
  1212. _ = utils.Rc.Delete(utils.CACHE_KEY_ADMIN)
  1213. _ = utils.Rc.Delete(utils.CACHE_KEY_ADMIN_ID)
  1214. abnormalKey := fmt.Sprint(utils.CACHE_ABNORMAL_LOGIN, adminInfo.AdminName)
  1215. errPassKey := fmt.Sprint(utils.CACHE_LOGIN_ERR_PASS, adminInfo.AdminName)
  1216. _ = utils.Rc.Delete(abnormalKey)
  1217. _ = utils.Rc.Delete(errPassKey)
  1218. br.Ret = 200
  1219. br.Success = true
  1220. br.IsAddLog = true
  1221. br.Msg = "重置密码成功"
  1222. }
  1223. // Add
  1224. // @Title 用户详情信息
  1225. // @Description 用户详情信息
  1226. // @Param request body system.SysuserAddReq true "type json string"
  1227. // @Success 200 新增成功
  1228. // @router /sysuser/detail [get]
  1229. func (this *SysAdminController) Detail() {
  1230. br := new(models.BaseResponse).Init()
  1231. defer func() {
  1232. this.Data["json"] = br
  1233. this.ServeJSON()
  1234. }()
  1235. br.Data = this.SysUser
  1236. br.Ret = 200
  1237. br.Success = true
  1238. br.Msg = "获取成功"
  1239. }