role_controller.go 55KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694
  1. package controllers
  2. import (
  3. "fmt"
  4. "github.com/jinzhu/gorm"
  5. "strconv"
  6. "strings"
  7. "time"
  8. "XT_New/enums"
  9. "XT_New/models"
  10. "XT_New/service"
  11. "github.com/astaxie/beego"
  12. )
  13. func RoleAPIControllerRegistRouters() {
  14. beego.Router("/api/roles", &RoleAPIController{}, "get:GetRoles")
  15. beego.Router("/api/role/create", &RoleAPIController{}, "post:CreateRole")
  16. beego.Router("/api/role/modify", &RoleAPIController{}, "post:ModifyRole")
  17. beego.Router("/api/role/setstatus", &RoleAPIController{}, "post:ModifyRoleStatus")
  18. beego.Router("/role/purview/editinit", &RoleAPIController{}, "get:EditPurviewInitData")
  19. beego.Router("/role/purview/edit", &RoleAPIController{}, "post:EditPurview")
  20. beego.Router("/api/adminmain", &RoleAPIController{}, "get:AdminMainView")
  21. beego.Router("/api/admins", &RoleAPIController{}, "get:Admins")
  22. beego.Router("/api/admin/addinit", &RoleAPIController{}, "get:AddAdminInitData")
  23. beego.Router("/api/admin/add", &RoleAPIController{}, "get:AddAdmin")
  24. beego.Router("/api/admin/editinit", &RoleAPIController{}, "get:EditAdminInitData")
  25. beego.Router("/api/admin/edit", &RoleAPIController{}, "get:EditAdmin")
  26. beego.Router("/api/admin/setstatus", &RoleAPIController{}, "post:AdminSetStatus")
  27. beego.Router("/api/admin/specialpermission/initdata", &RoleAPIController{}, "get:SpecialPermissionInitData")
  28. beego.Router("/api/admin/specialpermission/dialysisrecord/submit", &RoleAPIController{}, "post:SubmitDialysisRecordPermission")
  29. beego.Router("/api/roles/list", &RoleAPIController{}, "get:GetAllOrgRole")
  30. beego.Router("/api/staff", &RoleAPIController{}, "get:GetAllOrgUser")
  31. beego.Router("/api/role/addStaff", &RoleAPIController{}, "post:AddRoleStaff")
  32. beego.Router("/api/role/staff", &RoleAPIController{}, "get:GetRoleStaff")
  33. beego.Router("/api/role", &RoleAPIController{}, "get:GetRoleInfo")
  34. }
  35. type RoleAPIController struct {
  36. BaseAuthAPIController
  37. }
  38. // /api/roles [get]
  39. // @param page?:int
  40. func (this *RoleAPIController) GetRoles() {
  41. page, _ := this.GetInt("page")
  42. adminUserInfo := this.GetAdminUserInfo()
  43. //beego.Alert(adminUserInfo.AdminUser)
  44. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  45. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  46. // return
  47. //}
  48. if page <= 0 {
  49. page = 1
  50. }
  51. roles, total, getRoleErr := service.GetRoles(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, page, 100)
  52. if getRoleErr != nil {
  53. //beego.Error("获取角色列表失败:", getRoleErr)
  54. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  55. } else {
  56. this.ServeSuccessJSON(map[string]interface{}{
  57. "roles": roles,
  58. "total_count": total,
  59. })
  60. }
  61. }
  62. // /api/role/create [post]
  63. // @param name:string
  64. // @param intro:string
  65. func (this *RoleAPIController) CreateRole() {
  66. name := this.GetString("name")
  67. intro := this.GetString("intro")
  68. if len(name) == 0 {
  69. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  70. return
  71. }
  72. adminUserInfo := this.GetAdminUserInfo()
  73. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  74. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  75. // return
  76. //}
  77. total := service.FindRoleRecordByRoleName(name, adminUserInfo.CurrentOrgId)
  78. if total > 0 {
  79. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNameIsExist)
  80. return
  81. }
  82. role, createErr := service.CreateRole(adminUserInfo.AdminUser.Id, adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, name, intro)
  83. if createErr != nil {
  84. //beego.Error("创建角色失败:", createErr)
  85. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  86. } else {
  87. this.ServeSuccessJSON(map[string]interface{}{
  88. "id": role.Id,
  89. "name": role.RoleName,
  90. "intro": role.RoleIntro,
  91. "status": role.Status,
  92. })
  93. }
  94. }
  95. // /api/role/modify
  96. // @param role_id:int
  97. // @param name:string
  98. // @param intro:string
  99. func (this *RoleAPIController) ModifyRole() {
  100. roleID, _ := this.GetInt64("role_id")
  101. name := this.GetString("name")
  102. intro := this.GetString("intro")
  103. if roleID <= 0 || len(name) == 0 || len(intro) == 0 {
  104. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  105. return
  106. }
  107. //adminUserInfo := this.GetAdminUserInfo()
  108. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  109. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  110. // return
  111. //}
  112. role, getRoleErr := service.GetRoleByRoleID(roleID)
  113. if getRoleErr != nil {
  114. //beego.Error("获取角色失败:", getRoleErr)
  115. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  116. return
  117. } else if role == nil {
  118. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNotExist)
  119. return
  120. }
  121. role.RoleName = name
  122. role.RoleIntro = intro
  123. role.ModifyTime = time.Now().Unix()
  124. saveErr := service.ModifyRole(role)
  125. if saveErr != nil {
  126. //beego.Error("修改角色失败:", role.Id, saveErr)
  127. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  128. } else {
  129. this.ServeSuccessJSON(nil)
  130. }
  131. }
  132. // /api/role/setstatus
  133. // @param role_id:int
  134. // @param enable:bool
  135. func (this *RoleAPIController) ModifyRoleStatus() {
  136. roleID, _ := this.GetInt64("role_id")
  137. enable, _ := this.GetBool("enable")
  138. if roleID <= 0 {
  139. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  140. return
  141. }
  142. adminUserInfo := this.GetAdminUserInfo()
  143. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  144. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  145. // return
  146. //}
  147. role, getRoleErr := service.GetRoleByRoleID(roleID)
  148. if getRoleErr != nil {
  149. //beego.Error("获取角色失败:", getRoleErr)
  150. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  151. return
  152. } else if role == nil {
  153. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNotExist)
  154. return
  155. }
  156. if enable == false {
  157. if count, _ := service.RoleAdminUserCountTwo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, roleID); count != 0 {
  158. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCannotRemoveRole)
  159. return
  160. }
  161. }
  162. if enable {
  163. role.Status = 1
  164. } else {
  165. role.Status = 2
  166. }
  167. role.ModifyTime = time.Now().Unix()
  168. saveErr := service.ModifyRole(role)
  169. if saveErr != nil {
  170. //beego.Error("修改角色失败:", role.Id, saveErr)
  171. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  172. } else {
  173. this.ServeSuccessJSON(nil)
  174. }
  175. }
  176. // /role/purview/editinit [get]
  177. // @param role_id:int
  178. func (this *RoleAPIController) EditPurviewInitData() {
  179. //adminUserInfo := this.GetAdminUserInfo()
  180. //if
  181. //}
  182. roleId, _ := this.GetInt64("role_id")
  183. if roleId <= 0 {
  184. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  185. return
  186. }
  187. role, _ := service.GetRoleByRoleID(roleId)
  188. //purviews_xt, getPurviewsErr := service.GetAllGeneralPurviewVMsProcessed(3)
  189. purviews_scrm, getPurviewsErr := service.GetAllGeneralPurviewVMsProcessed(6)
  190. purviews_cdm, getPurviewsErr := service.GetAllGeneralPurviewVMsProcessed(4)
  191. purviews_mall, getPurviewsErr := service.GetAllGeneralPurviewVMsProcessed(7)
  192. purviews_ky_mall, getPurviewsErr := service.GetAllGeneralPurviewVMsProcessed(8)
  193. purviews_func, _ := service.GetAllGeneralFuncPurviewVMsProcessed()
  194. //门诊
  195. _, _, outpatientRegistration := service.GetOtherAllGeneralPurviewVMsProcessed("/outpatientRegistration/manage")
  196. fmt.Println(outpatientRegistration)
  197. //电子病历
  198. _, _, originEle := service.GetOtherAllGeneralPurviewVMsProcessed("/patinets/ele")
  199. //透析管理
  200. _, _, originDialysis := service.GetOtherAllGeneralPurviewVMsProcessed("/dialysis/manage")
  201. //库房管理
  202. _, _, originStock := service.GetOtherAllGeneralPurviewVMsProcessed("/stock/manange")
  203. //配置管理
  204. //_, _, orginConfig := service.GetOtherAllGeneralPurviewVMsProcessed("/config/manage")
  205. //门诊管理
  206. _, _, YajinPurview := service.GetOtherAllGeneralPurviewVMsProcessed("DepositManagement")
  207. //_, _, YaofangPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/api/pharmacy")
  208. _, _, DengjiPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/hospitalRecord/index")
  209. _, _, GongjuPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/hisTool")
  210. _, _, ShoufeiPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/hospitalCharges")
  211. _, _, outpatientRegistrationPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/outpatientRegistration/index")
  212. _, _, outpatientRegistrationPurviewTwo := service.GetOtherAllGeneralPurviewVMsProcessed("/outpatientDoctorStation")
  213. _, _, outpatientRegistrationPurviewThree := service.GetOtherAllGeneralPurviewVMsProcessed("/outpatientCharges")
  214. _, _, outpatientRegistrationPurviewFour := service.GetOtherAllGeneralPurviewVMsProcessed("/hospitalStation")
  215. //透析管理
  216. _, _, originDialysisWatchPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/dialysis/watch")
  217. _, _, originWorkforcePurview := service.GetOtherAllGeneralPurviewVMsProcessed("/workforce/patient")
  218. _, _, originSignPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/sign/lineup")
  219. _, _, originMedicalSchedulingPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/medicalScheduling/index")
  220. _, _, originQcdPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/qcd/manage")
  221. _, _, originDevicePurview := service.GetOtherAllGeneralPurviewVMsProcessed("/device/manage")
  222. _, _, originDataUploadPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/data/upload")
  223. _, _, originConsumablesPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/stock/consumablesManagement")
  224. _, _, originDrugsPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/stock/drugs")
  225. _, _, originSelfPreparedMedicinePurview := service.GetOtherAllGeneralPurviewVMsProcessed("/stock/selfPreparedMedicineIndex")
  226. _, _, originOtherPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/stock/other")
  227. _, _, originCkPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/stock/warehousequery")
  228. _, _, originIntegrationPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/integration/manage")
  229. _, _, originTemplatePurview := service.GetOtherAllGeneralPurviewVMsProcessed("/template/manage")
  230. _, _, originDictMedicinePurview := service.GetOtherAllGeneralPurviewVMsProcessed("/dict/manage")
  231. _, _, originBedPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/bed/manage")
  232. //采购管理
  233. _, _, purchaseManagerPurview := service.GetOtherAllGeneralPurviewVMsProcessed("/supply/query")
  234. //门诊管理
  235. subYajinPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  236. subPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  237. subPurviewTreeViewModelTwo := []*service.PurviewTreeViewModel{}
  238. subPurviewTreeViewModelThree := []*service.PurviewTreeViewModel{}
  239. //subYaoFangPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  240. subDengjiPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  241. subPurviewTreeViewModelFour := []*service.PurviewTreeViewModel{}
  242. subPurviewTreeViewModelFive := []*service.PurviewTreeViewModel{}
  243. subGongJuPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  244. subShouFeiPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  245. for _, item := range YajinPurview {
  246. temp := &service.PurviewTreeViewModel{
  247. ID: item.Id,
  248. PID: item.Parentid,
  249. Name: item.Name,
  250. Number: 1,
  251. }
  252. subYajinPurviewTreeViewModel = append(subYajinPurviewTreeViewModel, temp)
  253. }
  254. //for _, item := range YaofangPurview {
  255. // temp := &service.PurviewTreeViewModel{
  256. // ID: item.Id,
  257. // PID: item.Parentid,
  258. // Name: item.Name,
  259. // Number: 1,
  260. // }
  261. // subYaoFangPurviewTreeViewModel = append(subYaoFangPurviewTreeViewModel, temp)
  262. //}
  263. for _, item := range DengjiPurview {
  264. temp := &service.PurviewTreeViewModel{
  265. ID: item.Id,
  266. PID: item.Parentid,
  267. Name: item.Name,
  268. Number: 1,
  269. }
  270. subDengjiPurviewTreeViewModel = append(subDengjiPurviewTreeViewModel, temp)
  271. }
  272. for _, item := range GongjuPurview {
  273. temp := &service.PurviewTreeViewModel{
  274. ID: item.Id,
  275. PID: item.Parentid,
  276. Name: item.Name,
  277. Number: 1,
  278. }
  279. subGongJuPurviewTreeViewModel = append(subGongJuPurviewTreeViewModel, temp)
  280. }
  281. for _, item := range ShoufeiPurview {
  282. temp := &service.PurviewTreeViewModel{
  283. ID: item.Id,
  284. PID: item.Parentid,
  285. Name: item.Name,
  286. Number: 1,
  287. }
  288. subShouFeiPurviewTreeViewModel = append(subShouFeiPurviewTreeViewModel, temp)
  289. }
  290. for _, item := range outpatientRegistrationPurview {
  291. temp := &service.PurviewTreeViewModel{
  292. ID: item.Id,
  293. PID: item.Parentid,
  294. Name: item.Name,
  295. Number: 1,
  296. }
  297. subPurviewTreeViewModel = append(subPurviewTreeViewModel, temp)
  298. }
  299. for _, item := range outpatientRegistrationPurviewTwo {
  300. temp := &service.PurviewTreeViewModel{
  301. ID: item.Id,
  302. PID: item.Parentid,
  303. Name: item.Name,
  304. Number: 1,
  305. }
  306. subPurviewTreeViewModelTwo = append(subPurviewTreeViewModelTwo, temp)
  307. }
  308. for _, item := range outpatientRegistrationPurviewThree {
  309. temp := &service.PurviewTreeViewModel{
  310. ID: item.Id,
  311. PID: item.Parentid,
  312. Name: item.Name,
  313. Number: 1,
  314. }
  315. subPurviewTreeViewModelThree = append(subPurviewTreeViewModelThree, temp)
  316. }
  317. for _, item := range outpatientRegistrationPurviewFour {
  318. temp := &service.PurviewTreeViewModel{
  319. ID: item.Id,
  320. PID: item.Parentid,
  321. Name: item.Name,
  322. Number: 1,
  323. }
  324. subPurviewTreeViewModelFour = append(subPurviewTreeViewModelFour, temp)
  325. }
  326. //采购管理
  327. for _, item := range purchaseManagerPurview {
  328. temp := &service.PurviewTreeViewModel{
  329. ID: item.Id,
  330. PID: item.Parentid,
  331. Name: item.Name,
  332. Number: 1,
  333. }
  334. subPurviewTreeViewModelFive = append(subPurviewTreeViewModelFive, temp)
  335. }
  336. //透析管理
  337. subOutpatientPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  338. for _, item := range outpatientRegistration {
  339. temp := &service.PurviewTreeViewModel{
  340. ID: item.Id,
  341. PID: item.Parentid,
  342. Name: item.Name,
  343. Number: 1,
  344. }
  345. subOutpatientPurviewTreeViewModel = append(subOutpatientPurviewTreeViewModel, temp)
  346. }
  347. for _, item := range subOutpatientPurviewTreeViewModel {
  348. if item.Name == "押金管理" {
  349. item.Childs = append(item.Childs, subYajinPurviewTreeViewModel...)
  350. }
  351. if item.Name == "门诊挂号" {
  352. item.Childs = append(item.Childs, subPurviewTreeViewModel...)
  353. }
  354. if item.Name == "门诊医生站" {
  355. item.Childs = append(item.Childs, subPurviewTreeViewModelTwo...)
  356. }
  357. if item.Name == "门诊收费" {
  358. item.Childs = append(item.Childs, subPurviewTreeViewModelThree...)
  359. }
  360. //if item.Name == "药房管理" {
  361. // item.Childs = append(item.Childs, subYaoFangPurviewTreeViewModel...)
  362. //}
  363. if item.Name == "住院登记" {
  364. item.Childs = append(item.Childs, subDengjiPurviewTreeViewModel...)
  365. }
  366. if item.Name == "住院工作站" {
  367. item.Childs = append(item.Childs, subPurviewTreeViewModelFour...)
  368. }
  369. if item.Name == "住院收费" {
  370. item.Childs = append(item.Childs, subShouFeiPurviewTreeViewModel...)
  371. }
  372. if item.Name == "HIS工具" {
  373. item.Childs = append(item.Childs, subGongJuPurviewTreeViewModel...)
  374. }
  375. }
  376. //电子病历
  377. subElePurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  378. for _, item := range originEle {
  379. temp := &service.PurviewTreeViewModel{
  380. ID: item.Id,
  381. PID: item.Parentid,
  382. Name: item.Name,
  383. Number: 1,
  384. }
  385. subElePurviewTreeViewModel = append(subElePurviewTreeViewModel, temp)
  386. }
  387. //透析管理
  388. subDialysisPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  389. for _, item := range originDialysis {
  390. temp := &service.PurviewTreeViewModel{
  391. ID: item.Id,
  392. PID: item.Parentid,
  393. Name: item.Name,
  394. Number: 1,
  395. }
  396. subDialysisPurviewTreeViewModel = append(subDialysisPurviewTreeViewModel, temp)
  397. }
  398. //库存管理
  399. subStockPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  400. for _, item := range originStock {
  401. temp := &service.PurviewTreeViewModel{
  402. ID: item.Id,
  403. PID: item.Parentid,
  404. Name: item.Name,
  405. Number: 1,
  406. }
  407. subStockPurviewTreeViewModel = append(subStockPurviewTreeViewModel, temp)
  408. }
  409. ////配置管理
  410. //subConfigPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  411. //for _, item := range orginConfig {
  412. // temp := &service.PurviewTreeViewModel{
  413. // ID: item.Id,
  414. // PID: item.Parentid,
  415. // Name: item.Name,
  416. // Number: 1,
  417. // }
  418. // subConfigPurviewTreeViewModel = append(subConfigPurviewTreeViewModel, temp)
  419. //}
  420. //
  421. //
  422. //监测管理
  423. subWatchPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  424. for _, item := range originDialysisWatchPurview {
  425. temp := &service.PurviewTreeViewModel{
  426. ID: item.Id,
  427. PID: item.Parentid,
  428. Name: item.Name,
  429. Number: 1,
  430. }
  431. subWatchPurviewTreeViewModel = append(subWatchPurviewTreeViewModel, temp)
  432. }
  433. //排班管理
  434. subWorkforcePurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  435. for _, item := range originWorkforcePurview {
  436. temp := &service.PurviewTreeViewModel{
  437. ID: item.Id,
  438. PID: item.Parentid,
  439. Name: item.Name,
  440. Number: 1,
  441. }
  442. subWorkforcePurviewTreeViewModel = append(subWorkforcePurviewTreeViewModel, temp)
  443. }
  444. //签到排队
  445. subSignPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  446. for _, item := range originSignPurview {
  447. temp := &service.PurviewTreeViewModel{
  448. ID: item.Id,
  449. PID: item.Parentid,
  450. Name: item.Name,
  451. Number: 1,
  452. }
  453. subSignPurviewTreeViewModel = append(subSignPurviewTreeViewModel, temp)
  454. }
  455. //医护排班
  456. subMedicalSchedulingPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  457. for _, item := range originMedicalSchedulingPurview {
  458. temp := &service.PurviewTreeViewModel{
  459. ID: item.Id,
  460. PID: item.Parentid,
  461. Name: item.Name,
  462. Number: 1,
  463. }
  464. subMedicalSchedulingPurviewTreeViewModel = append(subMedicalSchedulingPurviewTreeViewModel, temp)
  465. }
  466. subQCDPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  467. for _, item := range originQcdPurview {
  468. temp := &service.PurviewTreeViewModel{
  469. ID: item.Id,
  470. PID: item.Parentid,
  471. Name: item.Name,
  472. Number: 1,
  473. }
  474. subQCDPurviewTreeViewModel = append(subQCDPurviewTreeViewModel, temp)
  475. }
  476. subDevicePurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  477. for _, item := range originDevicePurview {
  478. temp := &service.PurviewTreeViewModel{
  479. ID: item.Id,
  480. PID: item.Parentid,
  481. Name: item.Name,
  482. Number: 1,
  483. }
  484. subDevicePurviewTreeViewModel = append(subDevicePurviewTreeViewModel, temp)
  485. }
  486. subDataUploadPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  487. for _, item := range originDataUploadPurview {
  488. temp := &service.PurviewTreeViewModel{
  489. ID: item.Id,
  490. PID: item.Parentid,
  491. Name: item.Name,
  492. Number: 1,
  493. }
  494. subDataUploadPurviewTreeViewModel = append(subDataUploadPurviewTreeViewModel, temp)
  495. }
  496. subConsumablesPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  497. for _, item := range originConsumablesPurview {
  498. temp := &service.PurviewTreeViewModel{
  499. ID: item.Id,
  500. PID: item.Parentid,
  501. Name: item.Name,
  502. Number: 1,
  503. }
  504. subConsumablesPurviewTreeViewModel = append(subConsumablesPurviewTreeViewModel, temp)
  505. }
  506. subDrugPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  507. for _, item := range originDrugsPurview {
  508. temp := &service.PurviewTreeViewModel{
  509. ID: item.Id,
  510. PID: item.Parentid,
  511. Name: item.Name,
  512. Number: 1,
  513. }
  514. subDrugPurviewTreeViewModel = append(subDrugPurviewTreeViewModel, temp)
  515. }
  516. subSelfPreparedMedicinePurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  517. for _, item := range originSelfPreparedMedicinePurview {
  518. temp := &service.PurviewTreeViewModel{
  519. ID: item.Id,
  520. PID: item.Parentid,
  521. Name: item.Name,
  522. Number: 1,
  523. }
  524. subSelfPreparedMedicinePurviewTreeViewModel = append(subSelfPreparedMedicinePurviewTreeViewModel, temp)
  525. }
  526. subOtherPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  527. for _, item := range originOtherPurview {
  528. temp := &service.PurviewTreeViewModel{
  529. ID: item.Id,
  530. PID: item.Parentid,
  531. Name: item.Name,
  532. Number: 1,
  533. }
  534. subOtherPurviewTreeViewModel = append(subOtherPurviewTreeViewModel, temp)
  535. }
  536. subCkPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  537. for _, item := range originCkPurview {
  538. temp := &service.PurviewTreeViewModel{
  539. ID: item.Id,
  540. PID: item.Parentid,
  541. Name: item.Name,
  542. Number: 1,
  543. }
  544. subCkPurviewTreeViewModel = append(subCkPurviewTreeViewModel, temp)
  545. }
  546. subIntegrationPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  547. for _, item := range originIntegrationPurview {
  548. temp := &service.PurviewTreeViewModel{
  549. ID: item.Id,
  550. PID: item.Parentid,
  551. Name: item.Name,
  552. Number: 1,
  553. }
  554. subIntegrationPurviewTreeViewModel = append(subIntegrationPurviewTreeViewModel, temp)
  555. }
  556. subTemplatePurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  557. for _, item := range originTemplatePurview {
  558. temp := &service.PurviewTreeViewModel{
  559. ID: item.Id,
  560. PID: item.Parentid,
  561. Name: item.Name,
  562. Number: 1,
  563. }
  564. subTemplatePurviewTreeViewModel = append(subTemplatePurviewTreeViewModel, temp)
  565. }
  566. subDictPurviewTreeViewModel := []*service.PurviewTreeViewModel{}
  567. for _, item := range originDictMedicinePurview {
  568. temp := &service.PurviewTreeViewModel{
  569. ID: item.Id,
  570. PID: item.Parentid,
  571. Name: item.Name,
  572. Number: 1,
  573. }
  574. subDictPurviewTreeViewModel = append(subDictPurviewTreeViewModel, temp)
  575. }
  576. subBedPrviewTreeViewModel := []*service.PurviewTreeViewModel{}
  577. for _, item := range originBedPurview {
  578. temp := &service.PurviewTreeViewModel{
  579. ID: item.Id,
  580. PID: item.Parentid,
  581. Name: item.Name,
  582. Number: 1,
  583. }
  584. subBedPrviewTreeViewModel = append(subBedPrviewTreeViewModel, temp)
  585. }
  586. for _, item := range subDialysisPurviewTreeViewModel {
  587. if item.Name == "透析记录" {
  588. item.Childs = append(item.Childs, purviews_func...)
  589. }
  590. if item.Name == "透析监控" {
  591. item.Childs = append(item.Childs, subWatchPurviewTreeViewModel...)
  592. }
  593. if item.Name == "患者排班" {
  594. item.Childs = append(item.Childs, subWorkforcePurviewTreeViewModel...)
  595. }
  596. if item.Name == "签到排队" {
  597. item.Childs = append(item.Childs, subSignPurviewTreeViewModel...)
  598. }
  599. if item.Name == "医护排班" {
  600. item.Childs = append(item.Childs, subMedicalSchedulingPurviewTreeViewModel...)
  601. }
  602. if item.Name == "质控管理" {
  603. item.Childs = append(item.Childs, subQCDPurviewTreeViewModel...)
  604. }
  605. if item.Name == "院感管理" {
  606. item.Childs = append(item.Childs, subDevicePurviewTreeViewModel...)
  607. }
  608. if item.Name == "质控上报" {
  609. item.Childs = append(item.Childs, subDataUploadPurviewTreeViewModel...)
  610. }
  611. }
  612. for _, item := range subStockPurviewTreeViewModel {
  613. if item.Name == "耗材管理" {
  614. item.Childs = append(item.Childs, subConsumablesPurviewTreeViewModel...)
  615. }
  616. if item.Name == "药库管理" {
  617. item.Childs = append(item.Childs, subDrugPurviewTreeViewModel...)
  618. }
  619. if item.Name == "自备药管理" {
  620. item.Childs = append(item.Childs, subSelfPreparedMedicinePurviewTreeViewModel...)
  621. }
  622. if item.Name == "其他管理" {
  623. item.Childs = append(item.Childs, subOtherPurviewTreeViewModel...)
  624. }
  625. if item.Name == "仓库管理" {
  626. item.Childs = append(item.Childs, subCkPurviewTreeViewModel...)
  627. }
  628. }
  629. //for _, item := range subConfigPurviewTreeViewModel {
  630. // if item.Name == "集成管理" {
  631. // item.Childs = append(item.Childs, subIntegrationPurviewTreeViewModel...)
  632. // }
  633. // if item.Name == "模版管理" {
  634. // item.Childs = append(item.Childs, subTemplatePurviewTreeViewModel...)
  635. // }
  636. // if item.Name == "字典管理" {
  637. // item.Childs = append(item.Childs, subDictPurviewTreeViewModel...)
  638. // }
  639. // if item.Name == "床位管理" {
  640. // item.Childs = append(item.Childs, subBedPrviewTreeViewModel...)
  641. // }
  642. //
  643. //}
  644. purviews := []*service.PurviewTreeViewModel{}
  645. menzhen := &service.PurviewTreeViewModel{
  646. ID: 0,
  647. PID: 0,
  648. Name: "门诊管理",
  649. Number: 3,
  650. Childs: subOutpatientPurviewTreeViewModel,
  651. }
  652. purviews = append(purviews, menzhen)
  653. dianzi := &service.PurviewTreeViewModel{
  654. ID: 0,
  655. PID: 0,
  656. Name: "电子病历",
  657. Number: 3,
  658. Childs: subElePurviewTreeViewModel,
  659. }
  660. purviews = append(purviews, dianzi)
  661. caigou := &service.PurviewTreeViewModel{
  662. ID: 0,
  663. PID: 0,
  664. Name: "采购管理",
  665. Number: 3,
  666. Childs: subPurviewTreeViewModelFive,
  667. }
  668. purviews = append(purviews, caigou)
  669. touxi := &service.PurviewTreeViewModel{
  670. ID: 0,
  671. PID: 0,
  672. Name: "透析管理",
  673. Number: 3,
  674. Childs: subDialysisPurviewTreeViewModel,
  675. }
  676. purviews = append(purviews, touxi)
  677. kufang := &service.PurviewTreeViewModel{
  678. ID: 0,
  679. PID: 0,
  680. Name: "库房管理",
  681. Number: 3,
  682. Childs: subStockPurviewTreeViewModel,
  683. }
  684. purviews = append(purviews, kufang)
  685. ky_mall := &service.PurviewTreeViewModel{
  686. ID: 0,
  687. PID: 0,
  688. Name: "酷医商城",
  689. Number: 3,
  690. Childs: purviews_ky_mall,
  691. }
  692. purviews = append(purviews, ky_mall)
  693. cdm := &service.PurviewTreeViewModel{
  694. ID: 0,
  695. PID: 0,
  696. Number: 3,
  697. Name: "慢病管理",
  698. Childs: purviews_cdm,
  699. }
  700. purviews = append(purviews, cdm)
  701. scrm := &service.PurviewTreeViewModel{
  702. ID: 0,
  703. PID: 0,
  704. Name: "营销管理",
  705. Number: 3,
  706. Childs: purviews_scrm,
  707. }
  708. purviews = append(purviews, scrm)
  709. mall := &service.PurviewTreeViewModel{
  710. ID: 0,
  711. PID: 0,
  712. Name: "分销商城",
  713. Number: 3,
  714. Childs: purviews_mall,
  715. }
  716. purviews = append(purviews, mall)
  717. //peizhi := &service.PurviewTreeViewModel{
  718. // ID: 0,
  719. // PID: 0,
  720. // Name: "配置管理",
  721. // Number: 3,
  722. // Childs: subConfigPurviewTreeViewModel,
  723. //}
  724. //purviews = append(purviews, peizhi)
  725. if getPurviewsErr != nil {
  726. //beego.Error("获取所有权限时出错:", getPurviewsErr)
  727. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  728. return
  729. }
  730. rolePurviewIdStr, getRPIdsErr := service.GetRolePurviewIds(roleId)
  731. if getRPIdsErr != nil {
  732. //beego.Error("获取角色的权限时出错:", getRPIdsErr)
  733. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  734. return
  735. }
  736. roleFuncPurview, getFuncRPIdsErr := service.GetRoleFuncPurview(roleId)
  737. if getFuncRPIdsErr == gorm.ErrRecordNotFound {
  738. //beego.Error("获取角色的权限时出错:", getRPIdsErr)
  739. if roleFuncPurview.ID == 0 {
  740. rolePurviewIdStr = rolePurviewIdStr
  741. } else {
  742. rolePurviewIdStr = rolePurviewIdStr + "," + roleFuncPurview.PurviewIds
  743. }
  744. } else if getFuncRPIdsErr != nil {
  745. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  746. return
  747. } else {
  748. if roleFuncPurview.ID == 0 {
  749. rolePurviewIdStr = rolePurviewIdStr
  750. } else {
  751. rolePurviewIdStr = rolePurviewIdStr + "," + roleFuncPurview.PurviewIds
  752. }
  753. }
  754. this.ServeSuccessJSON(map[string]interface{}{
  755. "purviews": purviews,
  756. "role": role,
  757. "role_purview_ids": rolePurviewIdStr + "," + roleFuncPurview.PurviewIds,
  758. })
  759. }
  760. // /role/purview/edit [post]
  761. // @param role_id:int
  762. // @param purview_ids:string
  763. func (this *RoleAPIController) EditPurview() {
  764. adminUserInfo := this.GetAdminUserInfo()
  765. roleId, _ := this.GetInt64("role_id")
  766. purviewIds := this.GetString("purview_ids")
  767. funcPurviewIds := this.GetString("func_purview_ids")
  768. if roleId <= 0 {
  769. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  770. return
  771. }
  772. redis := service.RedisClient()
  773. defer redis.Close()
  774. users := service.GetAllUserRole(adminUserInfo.CurrentOrgId)
  775. for _, item := range users {
  776. key := "purviews_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + strconv.FormatInt(item.AdminUserId, 10)
  777. redis.Set(key, "", time.Second)
  778. }
  779. err := service.SaveRolePurviewIds(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, roleId, purviewIds)
  780. err = service.SaveFuncRolePurviewIds(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, roleId, funcPurviewIds)
  781. if err != nil {
  782. //beego.Error("设置角色的权限时出错:", err)
  783. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  784. } else {
  785. this.ServeSuccessJSON(nil)
  786. }
  787. }
  788. // func (this *RoleAPIController) doesUserHaveAccess(userID int64) bool {
  789. // adminUser, getAdminUserErr := service.GetAdminUserByUserID(userID)
  790. // if getAdminUserErr != nil {
  791. // beego.Error("获取用户信息失败:%v", getAdminUserErr)
  792. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  793. // return false
  794. // } else if adminUser == nil {
  795. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
  796. // return false
  797. // } else if adminUser.Status == 2 {
  798. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUserWasForbidden)
  799. // return false
  800. // } else if adminUser.IsSuperAdmin == false {
  801. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  802. // return false
  803. // }
  804. // return true
  805. // }
  806. // func (this *RoleAPIController) isAppRoleExist(orgID int64, appID int64, userID int64) bool {
  807. // appRole, getAppRoleErr := service.GetAppRole(orgID, appID, userID)
  808. // if getAppRoleErr != nil {
  809. // beego.Error("检查用户和机构应用对应关系时失败:%v", getAppRoleErr)
  810. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  811. // return false
  812. // } else if appRole == nil {
  813. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  814. // return false
  815. // }
  816. // return true
  817. // }
  818. // /api/adminmain [get]
  819. func (this *RoleAPIController) AdminMainView() {
  820. adminUserInfo := this.GetAdminUserInfo()
  821. var isSubSuperAdmin bool = false
  822. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  823. if len(adminUserRole.RoleIds) > 0 {
  824. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  825. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  826. if adminUserInfo.AdminUser.Id != org.Creator {
  827. for _, item := range role_ids {
  828. id, _ := strconv.ParseInt(item, 10, 64)
  829. if id != 0 {
  830. role, _ := service.GetRoleByRoleID(id)
  831. if role != nil {
  832. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  833. isSubSuperAdmin = true
  834. }
  835. }
  836. }
  837. }
  838. }
  839. }
  840. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  841. viewModels, _, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  842. if getAdminsErr != nil {
  843. //beego.Error("获取管理员列表失败:", getAdminsErr)
  844. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  845. return
  846. }
  847. this.ServeSuccessJSON(map[string]interface{}{
  848. "admins": viewModels,
  849. "org": org,
  850. "isSubSuperAdmin": isSubSuperAdmin,
  851. })
  852. }
  853. // /api/admins [get]
  854. // @param page?:int
  855. func (this *RoleAPIController) Admins() {
  856. adminUserInfo := this.GetAdminUserInfo()
  857. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  858. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  859. // return
  860. //}
  861. page, _ := this.GetInt("page")
  862. viewModels, total, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, page, 100)
  863. if getAdminsErr != nil {
  864. //beego.Error("获取管理员列表失败:", getAdminsErr)
  865. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  866. } else {
  867. this.ServeSuccessJSON(map[string]interface{}{
  868. "admins": viewModels,
  869. "total_count": total,
  870. })
  871. }
  872. }
  873. // /api/admin/addinit [get]
  874. func (this *RoleAPIController) AddAdminInitData() {
  875. adminUserInfo := this.GetAdminUserInfo()
  876. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  877. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  878. // return
  879. //}
  880. var isSubSuperAdmin bool = false
  881. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  882. if len(adminUserRole.RoleIds) > 0 {
  883. //app_role, _ := service.GetAppRoleById(adminUserInfo.)
  884. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  885. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  886. if adminUserInfo.AdminUser.Id != org.Creator {
  887. for _, item := range role_ids {
  888. id, _ := strconv.ParseInt(item, 10, 64)
  889. if id != 0 {
  890. role, _ := service.GetRoleByRoleID(id)
  891. if role != nil {
  892. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  893. isSubSuperAdmin = true
  894. }
  895. }
  896. }
  897. }
  898. }
  899. }
  900. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  901. roles, getRoleErr := service.GetAllValidRoles(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  902. if getRoleErr != nil {
  903. //beego.Error("获取所有角色失败:", getRoleErr)
  904. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  905. return
  906. }
  907. redisClient := service.RedisClient()
  908. defer redisClient.Close()
  909. qntoken, _ := redisClient.Get("qn_token").Result()
  910. this.ServeSuccessJSON(map[string]interface{}{
  911. "roles": roles,
  912. "qntoken": qntoken,
  913. "isSubSuperAdmin": isSubSuperAdmin,
  914. "org": org,
  915. })
  916. }
  917. // /api/admin/add [post]
  918. // @param mobile:string
  919. // @param name:string
  920. // @param type:int 管理员类型:2.医生 3.护士 4.运营
  921. // @param title:int 用户职称(1.医士;2.医师;3.住院医师;4.主治医师;5.副主任医师;6.主任医师;7.护士;8.护师;9.主管护师;10.副主任护师;11.主任护师;12.运营专员;13.运营主管)
  922. // @param role:int
  923. // @param intro?:string
  924. func (this *RoleAPIController) AddAdmin() {
  925. adminUserInfo := this.GetAdminUserInfo()
  926. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  927. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  928. // return
  929. //}
  930. mobile := this.GetString("mobile")
  931. name := this.GetString("name")
  932. userType, _ := this.GetInt("type")
  933. userTitle, _ := this.GetInt("title")
  934. roleIds := this.GetString("role")
  935. user_title_name := this.GetString("user_title_name")
  936. department := this.GetString("department")
  937. department_id, _ := this.GetInt64("department_id")
  938. sex, _ := this.GetInt64("sex")
  939. age, _ := this.GetInt64("age")
  940. nation := this.GetString("nation")
  941. card_type, _ := this.GetInt64("card_type")
  942. id_card := this.GetString("id_card")
  943. education, _ := this.GetInt64("education")
  944. study_major_name := this.GetString("study_major_name")
  945. work_major_name := this.GetString("work_major_name")
  946. role_type, _ := this.GetInt64("role_type")
  947. medical_code := this.GetString("medical_code")
  948. doctor_code := this.GetString("doctor_code")
  949. licensing, _ := this.GetInt64("licensing")
  950. job_number := this.GetString("job_number")
  951. prescription_qualification_identification, _ := this.GetInt64("prescription_qualification_identification")
  952. identification_outpatients, _ := this.GetInt64("identification_outpatients")
  953. timeLayout := "2006-01-02"
  954. loc, _ := time.LoadLocation("Local")
  955. start_time := this.GetString("start_time")
  956. theStartTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  957. medical_range_code, _ := this.GetInt64("medical_range_code")
  958. medical_level, _ := this.GetInt64("medical_level")
  959. medical_type_job, _ := this.GetInt64("medical_type_job")
  960. pharmacist_registration_number := this.GetString("pharmacist_registration_number")
  961. doctor_range_code, _ := this.GetInt64("doctor_range_code")
  962. doctor_level, _ := this.GetInt64("doctor_level")
  963. doctor_type_job, _ := this.GetInt64("doctor_type_job")
  964. doctor_number := this.GetString("doctor_number")
  965. outpatient_illnessCategory := this.GetString("outpatient_illnessCategory")
  966. is_active, _ := this.GetInt64("is_active")
  967. active_status, _ := this.GetInt64("active_status")
  968. fmt.Println("active_status", active_status)
  969. if len(mobile) == 0 || len(name) == 0 || (userType != 2 && userType != 3 && userType != 4) || len(roleIds) <= 0 {
  970. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  971. return
  972. }
  973. // 判断是否已存在该手机号
  974. if adminUser, err := service.GetValidAdminUserByMobileReturnErr(mobile); err != nil {
  975. //beego.Error("查询用户是否已被添加为管理员时失败:", err)
  976. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  977. return
  978. } else {
  979. if adminUser == nil { //新增账号和用户
  980. _, password, createErr := service.CreateGeneralAdminUserOne(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, mobile, name, user_title_name, roleIds, userType, userTitle, department_id, department, sex, age, nation, card_type, id_card, education, study_major_name, work_major_name, role_type, medical_code, doctor_code, licensing, job_number, prescription_qualification_identification, identification_outpatients, theStartTime.Unix(), medical_range_code, medical_level, medical_type_job, pharmacist_registration_number, doctor_range_code, doctor_level, doctor_type_job, doctor_number, outpatient_illnessCategory, is_active, active_status)
  981. if createErr != nil {
  982. //beego.Error("创建管理员失败:", createErr)
  983. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  984. return
  985. } else {
  986. sendSMSErr := service.SMSSendInviteMobileToJoinOrgAdmin(name, mobile, password)
  987. if sendSMSErr != nil {
  988. }
  989. this.ServeSuccessJSON(nil)
  990. return
  991. }
  992. } else {
  993. total, _ := service.FindAdminUserByID(adminUser.Id, adminUserInfo.CurrentOrgId)
  994. if total <= 0 {
  995. //新增用户
  996. app_role := &models.App_Role{
  997. AdminUserId: adminUser.Id,
  998. OrgId: adminUserInfo.CurrentOrgId,
  999. AppId: adminUserInfo.CurrentAppId,
  1000. Avatar: "",
  1001. UserName: name,
  1002. UserTitleName: user_title_name,
  1003. Status: 1,
  1004. UserType: int8(userType),
  1005. UserTitle: int8(userTitle),
  1006. CreateTime: time.Now().Unix(),
  1007. ModifyTime: time.Now().Unix(),
  1008. RoleIds: roleIds,
  1009. Department: department,
  1010. DepartmentId: department_id,
  1011. Sex: sex,
  1012. Age: age,
  1013. Nation: nation,
  1014. CardType: card_type,
  1015. IdCard: id_card,
  1016. Education: education,
  1017. StudyMajorName: study_major_name,
  1018. WorkMajorName: work_major_name,
  1019. RoleType: role_type,
  1020. MedicalCode: medical_code,
  1021. DoctorCode: doctor_code,
  1022. Licensing: licensing,
  1023. JobNumber: job_number,
  1024. PrescriptionQualificationIdentification: prescription_qualification_identification,
  1025. IdentificationOutpatients: identification_outpatients,
  1026. StartTime: theStartTime.Unix(),
  1027. MedicalRangeCode: medical_range_code,
  1028. MedicalLevel: medical_level,
  1029. MedicalTypeJob: medical_type_job,
  1030. PharmacistRegistrationNumber: pharmacist_registration_number,
  1031. DoctorRangeCode: doctor_range_code,
  1032. DoctorLevel: doctor_level,
  1033. DoctorTypeJob: doctor_type_job,
  1034. DoctorNumber: doctor_number,
  1035. OutpatientIllnesscategory: outpatient_illnessCategory,
  1036. IsActive: is_active,
  1037. ActiveStatus: active_status,
  1038. }
  1039. err := service.CreateUserRole(app_role)
  1040. if err != nil {
  1041. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1042. return
  1043. }
  1044. this.ServeSuccessJSON(nil)
  1045. } else {
  1046. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRepeatCreateStaffException)
  1047. return
  1048. }
  1049. return
  1050. }
  1051. }
  1052. }
  1053. // /api/admin/editinit [get]
  1054. // @param uid:int
  1055. func (this *RoleAPIController) EditAdminInitData() {
  1056. adminUserInfo := this.GetAdminUserInfo()
  1057. admin_user_id, _ := this.GetInt64("uid")
  1058. if admin_user_id <= 0 {
  1059. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1060. return
  1061. }
  1062. appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, admin_user_id)
  1063. if getAppRoleErr != nil {
  1064. //beego.Error("查询管理员信息时失败:", getAppRoleErr)
  1065. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1066. return
  1067. }
  1068. if appRole == nil {
  1069. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
  1070. return
  1071. }
  1072. roles, getRoleErr := service.GetAllValidRoles(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  1073. if getRoleErr != nil {
  1074. //beego.Error("获取所有角色失败:", getRoleErr)
  1075. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1076. return
  1077. }
  1078. var isSubSuperAdmin bool = false
  1079. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  1080. if len(adminUserRole.RoleIds) > 0 {
  1081. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  1082. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1083. if adminUserInfo.AdminUser.Id != org.Creator {
  1084. for _, item := range role_ids {
  1085. id, _ := strconv.ParseInt(item, 10, 64)
  1086. if id != 0 {
  1087. role, _ := service.GetRoleByRoleID(id)
  1088. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  1089. isSubSuperAdmin = true
  1090. }
  1091. }
  1092. }
  1093. }
  1094. }
  1095. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1096. redisClient := service.RedisClient()
  1097. defer redisClient.Close()
  1098. qntoken, _ := redisClient.Get("qn_token").Result()
  1099. this.ServeSuccessJSON(map[string]interface{}{
  1100. "admin": appRole,
  1101. "roles": roles,
  1102. "qntoken": qntoken,
  1103. "isSubSuperAdmin": isSubSuperAdmin,
  1104. "org": org,
  1105. })
  1106. }
  1107. // /api/admin/edit [post]
  1108. // @param uid:int
  1109. // @param name:string
  1110. // @param type:int
  1111. // @param title:int
  1112. // @param role:int
  1113. // @param intro?:string
  1114. func (this *RoleAPIController) EditAdmin() {
  1115. adminUserInfo := this.GetAdminUserInfo()
  1116. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  1117. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  1118. // return
  1119. //}
  1120. adminUserId, _ := this.GetInt64("uid")
  1121. name := this.GetString("name")
  1122. userType, _ := this.GetInt("type")
  1123. userTitle, _ := this.GetInt("title")
  1124. roleIds := this.GetString("role")
  1125. intro := this.GetString("intro")
  1126. user_title_name := this.GetString("user_title_name")
  1127. department := this.GetString("department")
  1128. department_id, _ := this.GetInt64("department_id")
  1129. sort, _ := this.GetInt64("sort")
  1130. sex, _ := this.GetInt64("sex")
  1131. age, _ := this.GetInt64("age")
  1132. nation := this.GetString("nation")
  1133. card_type, _ := this.GetInt64("card_type")
  1134. id_card := this.GetString("id_card")
  1135. education, _ := this.GetInt64("education")
  1136. study_major_name := this.GetString("study_major_name")
  1137. work_major_name := this.GetString("work_major_name")
  1138. role_type, _ := this.GetInt64("role_type")
  1139. medical_code := this.GetString("medical_code")
  1140. doctor_code := this.GetString("doctor_code")
  1141. licensing, _ := this.GetInt64("licensing")
  1142. job_number := this.GetString("job_number")
  1143. prescription_qualification_identification, _ := this.GetInt64("prescription_qualification_identification")
  1144. identification_outpatients, _ := this.GetInt64("identification_outpatients")
  1145. timeLayout := "2006-01-02"
  1146. loc, _ := time.LoadLocation("Local")
  1147. start_time := this.GetString("start_time")
  1148. fmt.Println("start_time22222222222", start_time)
  1149. theStartTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1150. medical_range_code, _ := this.GetInt64("medical_range_code")
  1151. medical_level, _ := this.GetInt64("medical_level")
  1152. medical_type_job, _ := this.GetInt64("medical_type_job")
  1153. pharmacist_registration_number := this.GetString("pharmacist_registration_number")
  1154. doctor_range_code, _ := this.GetInt64("doctor_range_code")
  1155. doctor_level, _ := this.GetInt64("doctor_level")
  1156. doctor_type_job, _ := this.GetInt64("doctor_type_job")
  1157. doctor_number := this.GetString("doctor_number")
  1158. outpatient_illnessCategory := this.GetString("outpatient_illnessCategory")
  1159. is_active, _ := this.GetInt64("is_active")
  1160. active_status, _ := this.GetInt64("active_status")
  1161. _, titleExist := models.UserTitle[userTitle]
  1162. fmt.Println(titleExist)
  1163. if adminUserId <= 0 || len(name) == 0 || (userType != 2 && userType != 3 && userType != 4) || !titleExist || len(roleIds) <= 0 {
  1164. fmt.Println("进来了吗")
  1165. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1166. return
  1167. }
  1168. appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserId)
  1169. if getAppRoleErr != nil {
  1170. //beego.Error("查询管理员信息时失败:", getAppRoleErr)
  1171. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1172. return
  1173. }
  1174. if appRole == nil {
  1175. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
  1176. return
  1177. }
  1178. appRole.OrgId = this.GetAdminUserInfo().CurrentOrgId
  1179. appRole.Department = department
  1180. appRole.DepartmentId = department_id
  1181. appRole.UserName = name
  1182. appRole.UserType = int8(userType)
  1183. appRole.UserTitle = int8(userTitle)
  1184. appRole.RoleIds = roleIds
  1185. appRole.Intro = intro
  1186. appRole.UserTitleName = user_title_name
  1187. appRole.ModifyTime = time.Now().Unix()
  1188. appRole.Sort = sort
  1189. appRole.Age = age
  1190. appRole.Nation = nation
  1191. appRole.CardType = card_type
  1192. appRole.IdCard = id_card
  1193. appRole.Education = education
  1194. appRole.StudyMajorName = study_major_name
  1195. appRole.WorkMajorName = work_major_name
  1196. appRole.RoleType = role_type
  1197. appRole.MedicalCode = medical_code
  1198. appRole.DoctorCode = doctor_code
  1199. appRole.Licensing = licensing
  1200. appRole.JobNumber = job_number
  1201. appRole.PrescriptionQualificationIdentification = prescription_qualification_identification
  1202. appRole.IdentificationOutpatients = identification_outpatients
  1203. appRole.StartTime = theStartTime.Unix()
  1204. appRole.MedicalCode = medical_code
  1205. appRole.MedicalRangeCode = medical_range_code
  1206. appRole.MedicalLevel = medical_level
  1207. appRole.MedicalTypeJob = medical_type_job
  1208. appRole.PharmacistRegistrationNumber = pharmacist_registration_number
  1209. appRole.DoctorRangeCode = doctor_range_code
  1210. appRole.DoctorLevel = doctor_level
  1211. appRole.DoctorTypeJob = doctor_type_job
  1212. appRole.DoctorNumber = doctor_number
  1213. appRole.OutpatientIllnesscategory = outpatient_illnessCategory
  1214. appRole.IsActive = is_active
  1215. appRole.ActiveStatus = active_status
  1216. appRole.Sex = sex
  1217. saveErr := service.SaveAppRole(appRole)
  1218. if saveErr != nil {
  1219. //beego.Error("修改App_Role失败:", saveErr)
  1220. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1221. } else {
  1222. //判断当前角色是否为机构管理员
  1223. this.ServeSuccessJSON(map[string]interface{}{
  1224. "approle": appRole,
  1225. })
  1226. this.ServeSuccessJSON(nil)
  1227. }
  1228. }
  1229. // /api/admin/setstatus [post]
  1230. // @param uid:int
  1231. // @param enable:bool
  1232. func (this *RoleAPIController) AdminSetStatus() {
  1233. adminUserInfo := this.GetAdminUserInfo()
  1234. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  1235. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  1236. // return
  1237. //}
  1238. userID, _ := this.GetInt64("uid")
  1239. if userID <= 0 {
  1240. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1241. return
  1242. }
  1243. appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, userID)
  1244. if getAppRoleErr != nil {
  1245. //beego.Error("查询管理员信息失败:", getAppRoleErr)
  1246. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1247. return
  1248. } else if appRole == nil {
  1249. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
  1250. return
  1251. }
  1252. enable, _ := this.GetBool("enable")
  1253. if enable {
  1254. appRole.Status = 1
  1255. } else {
  1256. appRole.Status = 0
  1257. }
  1258. appRole.ModifyTime = time.Now().Unix()
  1259. saveErr := service.SaveAppRole(appRole)
  1260. if saveErr != nil {
  1261. //beego.Error("保存AppRole失败:", saveErr)
  1262. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1263. } else {
  1264. this.ServeSuccessJSON(nil)
  1265. }
  1266. }
  1267. // /api/admin/specialpermission/initdata [get]
  1268. func (this *RoleAPIController) SpecialPermissionInitData() {
  1269. adminUserInfo := this.GetAdminUserInfo()
  1270. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  1271. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  1272. // return
  1273. //}
  1274. adminUsers, getAdminUsersErr := service.GetAllGeneralAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  1275. if getAdminUsersErr != nil {
  1276. this.ErrorLog("获取所有普通用户失败:%v", getAdminUsersErr)
  1277. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1278. return
  1279. }
  1280. headNurses, getAllHeadNursesErr := service.GetAllValidAdminUsersWithSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
  1281. if getAllHeadNursesErr != nil {
  1282. this.ErrorLog("获取所有拥有护士长特殊权限的用户失败:%v", getAllHeadNursesErr)
  1283. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1284. return
  1285. }
  1286. this.ServeSuccessJSON(map[string]interface{}{
  1287. "users": adminUsers,
  1288. "head_nurses": headNurses,
  1289. })
  1290. }
  1291. // /api/admin/specialpermission/dialysisrecord/submit [post]
  1292. // @param ids:string ("1,2,5")
  1293. func (this *RoleAPIController) SubmitDialysisRecordPermission() {
  1294. adminUserInfo := this.GetAdminUserInfo()
  1295. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  1296. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  1297. // return
  1298. //}
  1299. idsString := this.GetString("ids")
  1300. if len(idsString) == 0 {
  1301. // 取消所有用户的护士长权限
  1302. cancelErr := service.CancelAllSpecialPermissionAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
  1303. if cancelErr != nil {
  1304. this.ErrorLog("取消所有用户的护士长权限失败:%v", cancelErr)
  1305. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1306. return
  1307. } else {
  1308. this.ServeSuccessJSON(nil)
  1309. return
  1310. }
  1311. } else {
  1312. ids := make([]int64, 0)
  1313. idStrs := strings.Split(idsString, ",")
  1314. for _, idStr := range idStrs {
  1315. id, parseErr := strconv.Atoi(idStr)
  1316. if parseErr != nil {
  1317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1318. return
  1319. }
  1320. ids = append(ids, int64(id))
  1321. }
  1322. headNurses, getAllHeadNursesErr := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
  1323. if getAllHeadNursesErr != nil {
  1324. this.ErrorLog("获取所有拥有或曾拥有护士长特殊权限的用户失败:%v", getAllHeadNursesErr)
  1325. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1326. return
  1327. }
  1328. cancelList := make([]*models.AdminUserSpecialPermission, 0)
  1329. addList := make([]*models.AdminUserSpecialPermission, 0)
  1330. for _, id := range ids {
  1331. exit := false
  1332. for _, headNurse := range headNurses {
  1333. if headNurse.AdminUserID == id {
  1334. exit = true
  1335. if headNurse.Status != 1 {
  1336. headNurse.Status = 1
  1337. headNurse.ModifyTime = time.Now().Unix()
  1338. addList = append(addList, headNurse)
  1339. }
  1340. break
  1341. }
  1342. }
  1343. if exit == false {
  1344. newHeadNurse := &models.AdminUserSpecialPermission{
  1345. OrgID: adminUserInfo.CurrentOrgId,
  1346. AppID: adminUserInfo.CurrentAppId,
  1347. AdminUserID: id,
  1348. Permission: int64(models.SpecialPermissionTypeHeadNurse),
  1349. Status: 1,
  1350. CreateTime: time.Now().Unix(),
  1351. ModifyTime: time.Now().Unix(),
  1352. }
  1353. addList = append(addList, newHeadNurse)
  1354. }
  1355. }
  1356. for _, headNurse := range headNurses {
  1357. cancel := true
  1358. for _, willAdd := range addList {
  1359. if willAdd.AdminUserID == headNurse.AdminUserID {
  1360. cancel = false
  1361. break
  1362. }
  1363. }
  1364. if cancel {
  1365. headNurse.Status = 0
  1366. headNurse.ModifyTime = time.Now().Unix()
  1367. cancelList = append(cancelList, headNurse)
  1368. }
  1369. }
  1370. addErr := service.BatchSaveSpecialPermissionAdminUsers(addList)
  1371. if addErr != nil {
  1372. this.ErrorLog("授权失败:%v", addErr)
  1373. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1374. return
  1375. }
  1376. cancelErr := service.BatchSaveSpecialPermissionAdminUsers(cancelList)
  1377. if cancelErr != nil {
  1378. this.ErrorLog("取消授权失败:%v", cancelErr)
  1379. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1380. return
  1381. }
  1382. this.ServeSuccessJSON(nil)
  1383. }
  1384. }
  1385. func (this *RoleAPIController) GetAllOrgRole() {
  1386. adminUserInfo := this.GetAdminUserInfo()
  1387. var isSubSuperAdmin bool = false
  1388. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  1389. if len(adminUserRole.RoleIds) > 0 {
  1390. //app_role, _ := service.GetAppRoleById(adminUserInfo.)
  1391. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  1392. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1393. if adminUserInfo.AdminUser.Id != org.Creator {
  1394. for _, item := range role_ids {
  1395. id, _ := strconv.ParseInt(item, 10, 64)
  1396. if id != 0 {
  1397. role, _ := service.GetRoleByRoleID(id)
  1398. if role != nil {
  1399. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  1400. isSubSuperAdmin = true
  1401. }
  1402. }
  1403. }
  1404. }
  1405. }
  1406. }
  1407. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1408. roles, err := service.GetAllOrgValidRoles(adminUserInfo.CurrentOrgId, isSubSuperAdmin)
  1409. if err != nil {
  1410. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1411. return
  1412. } else {
  1413. this.ServeSuccessJSON(map[string]interface{}{
  1414. "roles": roles,
  1415. "isSubSuperAdmin": isSubSuperAdmin,
  1416. "org": org,
  1417. })
  1418. }
  1419. }
  1420. func (this *RoleAPIController) GetAllOrgUser() {
  1421. adminUserInfo := this.GetAdminUserInfo()
  1422. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1423. var isSubSuperAdmin bool = false
  1424. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  1425. if len(adminUserRole.RoleIds) > 0 {
  1426. //app_role, _ := service.GetAppRoleById(adminUserInfo.)
  1427. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  1428. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1429. if adminUserInfo.AdminUser.Id != org.Creator {
  1430. for _, item := range role_ids {
  1431. id, _ := strconv.ParseInt(item, 10, 64)
  1432. if id != 0 {
  1433. role, _ := service.GetRoleByRoleID(id)
  1434. if role != nil {
  1435. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  1436. isSubSuperAdmin = true
  1437. }
  1438. }
  1439. }
  1440. }
  1441. }
  1442. }
  1443. viewModels, _, _ := service.GetAllAdminUsersAndRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  1444. this.ServeSuccessJSON(map[string]interface{}{
  1445. "admins": viewModels,
  1446. "org": org,
  1447. "isSubSuperAdmin": isSubSuperAdmin,
  1448. })
  1449. }
  1450. func (this *RoleAPIController) AddRoleStaff() {
  1451. //adminUserInfo := this.GetMobileAdminUserInfo()
  1452. role_id, _ := this.GetInt64("id", 0)
  1453. staff_ids := this.GetString("ids")
  1454. ids := strings.Split(staff_ids, ",")
  1455. for _, item := range ids {
  1456. id, _ := strconv.ParseInt(item, 10, 64)
  1457. role, _ := service.FindAdminUserID(id)
  1458. role.RoleIds = role.RoleIds + "," + strconv.FormatInt(role_id, 10)
  1459. service.SaveAdminUser(&role)
  1460. }
  1461. this.ServeSuccessJSON(map[string]interface{}{
  1462. "msg": "添加成功",
  1463. })
  1464. }
  1465. func (this *RoleAPIController) GetRoleStaff() {
  1466. adminUserInfo := this.GetAdminUserInfo()
  1467. var isSubSuperAdmin bool = false
  1468. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  1469. if len(adminUserRole.RoleIds) > 0 {
  1470. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  1471. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1472. if adminUserInfo.AdminUser.Id != org.Creator {
  1473. for _, item := range role_ids {
  1474. id, _ := strconv.ParseInt(item, 10, 64)
  1475. if id != 0 {
  1476. role, _ := service.GetRoleByRoleID(id)
  1477. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  1478. isSubSuperAdmin = true
  1479. }
  1480. }
  1481. }
  1482. }
  1483. }
  1484. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1485. viewModels, _, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  1486. if getAdminsErr != nil {
  1487. //beego.Error("获取管理员列表失败:", getAdminsErr)
  1488. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1489. return
  1490. }
  1491. this.ServeSuccessJSON(map[string]interface{}{
  1492. "admins": viewModels,
  1493. "org": org,
  1494. "isSubSuperAdmin": isSubSuperAdmin,
  1495. })
  1496. }
  1497. func (this *RoleAPIController) GetRoleInfo() {
  1498. roleId, _ := this.GetInt64("role_id")
  1499. if roleId <= 0 {
  1500. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1501. return
  1502. }
  1503. role, _ := service.GetRoleByRoleID(roleId)
  1504. this.ServeSuccessJSON(map[string]interface{}{
  1505. "role": role,
  1506. })
  1507. }