role_controller.go 58KB

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