sys_admin.go 36 KB

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