role_controller.go 56KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734
  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. _, _, 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. fmt.Println("active_status", active_status)
  1000. if len(mobile) == 0 || len(name) == 0 || (userType != 2 && userType != 3 && userType != 4) || len(roleIds) <= 0 {
  1001. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1002. return
  1003. }
  1004. // 判断是否已存在该手机号
  1005. if adminUser, err := service.GetValidAdminUserByMobileReturnErr(mobile); err != nil {
  1006. //beego.Error("查询用户是否已被添加为管理员时失败:", err)
  1007. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1008. return
  1009. } else {
  1010. if adminUser == nil { //新增账号和用户
  1011. _, 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)
  1012. if createErr != nil {
  1013. //beego.Error("创建管理员失败:", createErr)
  1014. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1015. return
  1016. } else {
  1017. sendSMSErr := service.SMSSendInviteMobileToJoinOrgAdmin(name, mobile, password)
  1018. if sendSMSErr != nil {
  1019. }
  1020. this.ServeSuccessJSON(nil)
  1021. return
  1022. }
  1023. } else {
  1024. total, _ := service.FindAdminUserByID(adminUser.Id, adminUserInfo.CurrentOrgId)
  1025. if total <= 0 {
  1026. //新增用户
  1027. app_role := &models.App_Role{
  1028. AdminUserId: adminUser.Id,
  1029. OrgId: adminUserInfo.CurrentOrgId,
  1030. AppId: adminUserInfo.CurrentAppId,
  1031. Avatar: "",
  1032. UserName: name,
  1033. UserTitleName: user_title_name,
  1034. Status: 1,
  1035. UserType: int8(userType),
  1036. UserTitle: int8(userTitle),
  1037. CreateTime: time.Now().Unix(),
  1038. ModifyTime: time.Now().Unix(),
  1039. RoleIds: roleIds,
  1040. Department: department,
  1041. DepartmentId: department_id,
  1042. Sex: sex,
  1043. Age: age,
  1044. Nation: nation,
  1045. CardType: card_type,
  1046. IdCard: id_card,
  1047. Education: education,
  1048. StudyMajorName: study_major_name,
  1049. WorkMajorName: work_major_name,
  1050. RoleType: role_type,
  1051. MedicalCode: medical_code,
  1052. DoctorCode: doctor_code,
  1053. Licensing: licensing,
  1054. JobNumber: job_number,
  1055. PrescriptionQualificationIdentification: prescription_qualification_identification,
  1056. IdentificationOutpatients: identification_outpatients,
  1057. StartTime: theStartTime.Unix(),
  1058. MedicalRangeCode: medical_range_code,
  1059. MedicalLevel: medical_level,
  1060. MedicalTypeJob: medical_type_job,
  1061. PharmacistRegistrationNumber: pharmacist_registration_number,
  1062. DoctorRangeCode: doctor_range_code,
  1063. DoctorLevel: doctor_level,
  1064. DoctorTypeJob: doctor_type_job,
  1065. DoctorNumber: doctor_number,
  1066. OutpatientIllnesscategory: outpatient_illnessCategory,
  1067. IsActive: is_active,
  1068. ActiveStatus: active_status,
  1069. }
  1070. err := service.CreateUserRole(app_role)
  1071. if err != nil {
  1072. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1073. return
  1074. }
  1075. this.ServeSuccessJSON(nil)
  1076. } else {
  1077. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRepeatCreateStaffException)
  1078. return
  1079. }
  1080. return
  1081. }
  1082. }
  1083. }
  1084. // /api/admin/editinit [get]
  1085. // @param uid:int
  1086. func (this *RoleAPIController) EditAdminInitData() {
  1087. adminUserInfo := this.GetAdminUserInfo()
  1088. admin_user_id, _ := this.GetInt64("uid")
  1089. if admin_user_id <= 0 {
  1090. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1091. return
  1092. }
  1093. appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, admin_user_id)
  1094. if getAppRoleErr != nil {
  1095. //beego.Error("查询管理员信息时失败:", getAppRoleErr)
  1096. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1097. return
  1098. }
  1099. if appRole == nil {
  1100. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
  1101. return
  1102. }
  1103. roles, getRoleErr := service.GetAllValidRoles(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  1104. if getRoleErr != nil {
  1105. //beego.Error("获取所有角色失败:", getRoleErr)
  1106. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1107. return
  1108. }
  1109. var isSubSuperAdmin bool = false
  1110. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  1111. if len(adminUserRole.RoleIds) > 0 {
  1112. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  1113. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1114. if adminUserInfo.AdminUser.Id != org.Creator {
  1115. for _, item := range role_ids {
  1116. id, _ := strconv.ParseInt(item, 10, 64)
  1117. if id != 0 {
  1118. role, _ := service.GetRoleByRoleID(id)
  1119. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  1120. isSubSuperAdmin = true
  1121. }
  1122. }
  1123. }
  1124. }
  1125. }
  1126. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1127. redisClient := service.RedisClient()
  1128. defer redisClient.Close()
  1129. qntoken, _ := redisClient.Get("qn_token").Result()
  1130. this.ServeSuccessJSON(map[string]interface{}{
  1131. "admin": appRole,
  1132. "roles": roles,
  1133. "qntoken": qntoken,
  1134. "isSubSuperAdmin": isSubSuperAdmin,
  1135. "org": org,
  1136. })
  1137. }
  1138. // /api/admin/edit [post]
  1139. // @param uid:int
  1140. // @param name:string
  1141. // @param type:int
  1142. // @param title:int
  1143. // @param role:int
  1144. // @param intro?:string
  1145. func (this *RoleAPIController) EditAdmin() {
  1146. adminUserInfo := this.GetAdminUserInfo()
  1147. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  1148. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  1149. // return
  1150. //}
  1151. adminUserId, _ := this.GetInt64("uid")
  1152. name := this.GetString("name")
  1153. userType, _ := this.GetInt("type")
  1154. userTitle, _ := this.GetInt("title")
  1155. roleIds := this.GetString("role")
  1156. intro := this.GetString("intro")
  1157. user_title_name := this.GetString("user_title_name")
  1158. department := this.GetString("department")
  1159. department_id, _ := this.GetInt64("department_id")
  1160. sort, _ := this.GetInt64("sort")
  1161. sex, _ := this.GetInt64("sex")
  1162. age, _ := this.GetInt64("age")
  1163. nation := this.GetString("nation")
  1164. card_type, _ := this.GetInt64("card_type")
  1165. id_card := this.GetString("id_card")
  1166. education, _ := this.GetInt64("education")
  1167. study_major_name := this.GetString("study_major_name")
  1168. work_major_name := this.GetString("work_major_name")
  1169. role_type, _ := this.GetInt64("role_type")
  1170. medical_code := this.GetString("medical_code")
  1171. doctor_code := this.GetString("doctor_code")
  1172. licensing, _ := this.GetInt64("licensing")
  1173. job_number := this.GetString("job_number")
  1174. prescription_qualification_identification, _ := this.GetInt64("prescription_qualification_identification")
  1175. identification_outpatients, _ := this.GetInt64("identification_outpatients")
  1176. timeLayout := "2006-01-02"
  1177. loc, _ := time.LoadLocation("Local")
  1178. start_time := this.GetString("start_time")
  1179. fmt.Println("start_time22222222222", start_time)
  1180. theStartTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1181. medical_range_code, _ := this.GetInt64("medical_range_code")
  1182. medical_level, _ := this.GetInt64("medical_level")
  1183. medical_type_job, _ := this.GetInt64("medical_type_job")
  1184. pharmacist_registration_number := this.GetString("pharmacist_registration_number")
  1185. doctor_range_code, _ := this.GetInt64("doctor_range_code")
  1186. doctor_level, _ := this.GetInt64("doctor_level")
  1187. doctor_type_job, _ := this.GetInt64("doctor_type_job")
  1188. doctor_number := this.GetString("doctor_number")
  1189. outpatient_illnessCategory := this.GetString("outpatient_illnessCategory")
  1190. is_active, _ := this.GetInt64("is_active")
  1191. active_status, _ := this.GetInt64("active_status")
  1192. _, titleExist := models.UserTitle[userTitle]
  1193. fmt.Println(titleExist)
  1194. if adminUserId <= 0 || len(name) == 0 || (userType != 2 && userType != 3 && userType != 4) || !titleExist || len(roleIds) <= 0 {
  1195. fmt.Println("进来了吗")
  1196. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1197. return
  1198. }
  1199. appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserId)
  1200. if getAppRoleErr != nil {
  1201. //beego.Error("查询管理员信息时失败:", getAppRoleErr)
  1202. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1203. return
  1204. }
  1205. if appRole == nil {
  1206. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
  1207. return
  1208. }
  1209. appRole.OrgId = this.GetAdminUserInfo().CurrentOrgId
  1210. appRole.Department = department
  1211. appRole.DepartmentId = department_id
  1212. appRole.UserName = name
  1213. appRole.UserType = int8(userType)
  1214. appRole.UserTitle = int8(userTitle)
  1215. appRole.RoleIds = roleIds
  1216. appRole.Intro = intro
  1217. appRole.UserTitleName = user_title_name
  1218. appRole.ModifyTime = time.Now().Unix()
  1219. appRole.Sort = sort
  1220. appRole.Age = age
  1221. appRole.Nation = nation
  1222. appRole.CardType = card_type
  1223. appRole.IdCard = id_card
  1224. appRole.Education = education
  1225. appRole.StudyMajorName = study_major_name
  1226. appRole.WorkMajorName = work_major_name
  1227. appRole.RoleType = role_type
  1228. appRole.MedicalCode = medical_code
  1229. appRole.DoctorCode = doctor_code
  1230. appRole.Licensing = licensing
  1231. appRole.JobNumber = job_number
  1232. appRole.PrescriptionQualificationIdentification = prescription_qualification_identification
  1233. appRole.IdentificationOutpatients = identification_outpatients
  1234. appRole.StartTime = theStartTime.Unix()
  1235. appRole.MedicalCode = medical_code
  1236. appRole.MedicalRangeCode = medical_range_code
  1237. appRole.MedicalLevel = medical_level
  1238. appRole.MedicalTypeJob = medical_type_job
  1239. appRole.PharmacistRegistrationNumber = pharmacist_registration_number
  1240. appRole.DoctorRangeCode = doctor_range_code
  1241. appRole.DoctorLevel = doctor_level
  1242. appRole.DoctorTypeJob = doctor_type_job
  1243. appRole.DoctorNumber = doctor_number
  1244. appRole.OutpatientIllnesscategory = outpatient_illnessCategory
  1245. appRole.IsActive = is_active
  1246. appRole.ActiveStatus = active_status
  1247. appRole.Sex = sex
  1248. saveErr := service.SaveAppRole(appRole)
  1249. if saveErr != nil {
  1250. //beego.Error("修改App_Role失败:", saveErr)
  1251. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1252. } else {
  1253. //判断当前角色是否为机构管理员
  1254. this.ServeSuccessJSON(map[string]interface{}{
  1255. "approle": appRole,
  1256. })
  1257. this.ServeSuccessJSON(nil)
  1258. }
  1259. }
  1260. // /api/admin/setstatus [post]
  1261. // @param uid:int
  1262. // @param enable:bool
  1263. func (this *RoleAPIController) AdminSetStatus() {
  1264. adminUserInfo := this.GetAdminUserInfo()
  1265. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  1266. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  1267. // return
  1268. //}
  1269. userID, _ := this.GetInt64("uid")
  1270. if userID <= 0 {
  1271. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1272. return
  1273. }
  1274. appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, userID)
  1275. if getAppRoleErr != nil {
  1276. //beego.Error("查询管理员信息失败:", getAppRoleErr)
  1277. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1278. return
  1279. } else if appRole == nil {
  1280. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
  1281. return
  1282. }
  1283. enable, _ := this.GetBool("enable")
  1284. if enable {
  1285. appRole.Status = 1
  1286. } else {
  1287. appRole.Status = 0
  1288. }
  1289. appRole.ModifyTime = time.Now().Unix()
  1290. saveErr := service.SaveAppRole(appRole)
  1291. if saveErr != nil {
  1292. //beego.Error("保存AppRole失败:", saveErr)
  1293. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1294. } else {
  1295. this.ServeSuccessJSON(nil)
  1296. }
  1297. }
  1298. // /api/admin/specialpermission/initdata [get]
  1299. func (this *RoleAPIController) SpecialPermissionInitData() {
  1300. adminUserInfo := this.GetAdminUserInfo()
  1301. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  1302. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  1303. // return
  1304. //}
  1305. adminUsers, getAdminUsersErr := service.GetAllGeneralAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  1306. if getAdminUsersErr != nil {
  1307. this.ErrorLog("获取所有普通用户失败:%v", getAdminUsersErr)
  1308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1309. return
  1310. }
  1311. headNurses, getAllHeadNursesErr := service.GetAllValidAdminUsersWithSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
  1312. if getAllHeadNursesErr != nil {
  1313. this.ErrorLog("获取所有拥有护士长特殊权限的用户失败:%v", getAllHeadNursesErr)
  1314. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1315. return
  1316. }
  1317. this.ServeSuccessJSON(map[string]interface{}{
  1318. "users": adminUsers,
  1319. "head_nurses": headNurses,
  1320. })
  1321. }
  1322. // /api/admin/specialpermission/dialysisrecord/submit [post]
  1323. // @param ids:string ("1,2,5")
  1324. func (this *RoleAPIController) SubmitDialysisRecordPermission() {
  1325. adminUserInfo := this.GetAdminUserInfo()
  1326. //if adminUserInfo.AdminUser.IsSuperAdmin == false {
  1327. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
  1328. // return
  1329. //}
  1330. idsString := this.GetString("ids")
  1331. if len(idsString) == 0 {
  1332. // 取消所有用户的护士长权限
  1333. cancelErr := service.CancelAllSpecialPermissionAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
  1334. if cancelErr != nil {
  1335. this.ErrorLog("取消所有用户的护士长权限失败:%v", cancelErr)
  1336. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1337. return
  1338. } else {
  1339. this.ServeSuccessJSON(nil)
  1340. return
  1341. }
  1342. } else {
  1343. ids := make([]int64, 0)
  1344. idStrs := strings.Split(idsString, ",")
  1345. for _, idStr := range idStrs {
  1346. id, parseErr := strconv.Atoi(idStr)
  1347. if parseErr != nil {
  1348. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1349. return
  1350. }
  1351. ids = append(ids, int64(id))
  1352. }
  1353. headNurses, getAllHeadNursesErr := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, models.SpecialPermissionTypeHeadNurse)
  1354. if getAllHeadNursesErr != nil {
  1355. this.ErrorLog("获取所有拥有或曾拥有护士长特殊权限的用户失败:%v", getAllHeadNursesErr)
  1356. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1357. return
  1358. }
  1359. cancelList := make([]*models.AdminUserSpecialPermission, 0)
  1360. addList := make([]*models.AdminUserSpecialPermission, 0)
  1361. for _, id := range ids {
  1362. exit := false
  1363. for _, headNurse := range headNurses {
  1364. if headNurse.AdminUserID == id {
  1365. exit = true
  1366. if headNurse.Status != 1 {
  1367. headNurse.Status = 1
  1368. headNurse.ModifyTime = time.Now().Unix()
  1369. addList = append(addList, headNurse)
  1370. }
  1371. break
  1372. }
  1373. }
  1374. if exit == false {
  1375. newHeadNurse := &models.AdminUserSpecialPermission{
  1376. OrgID: adminUserInfo.CurrentOrgId,
  1377. AppID: adminUserInfo.CurrentAppId,
  1378. AdminUserID: id,
  1379. Permission: int64(models.SpecialPermissionTypeHeadNurse),
  1380. Status: 1,
  1381. CreateTime: time.Now().Unix(),
  1382. ModifyTime: time.Now().Unix(),
  1383. }
  1384. addList = append(addList, newHeadNurse)
  1385. }
  1386. }
  1387. for _, headNurse := range headNurses {
  1388. cancel := true
  1389. for _, willAdd := range addList {
  1390. if willAdd.AdminUserID == headNurse.AdminUserID {
  1391. cancel = false
  1392. break
  1393. }
  1394. }
  1395. if cancel {
  1396. headNurse.Status = 0
  1397. headNurse.ModifyTime = time.Now().Unix()
  1398. cancelList = append(cancelList, headNurse)
  1399. }
  1400. }
  1401. addErr := service.BatchSaveSpecialPermissionAdminUsers(addList)
  1402. if addErr != nil {
  1403. this.ErrorLog("授权失败:%v", addErr)
  1404. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1405. return
  1406. }
  1407. cancelErr := service.BatchSaveSpecialPermissionAdminUsers(cancelList)
  1408. if cancelErr != nil {
  1409. this.ErrorLog("取消授权失败:%v", cancelErr)
  1410. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1411. return
  1412. }
  1413. this.ServeSuccessJSON(nil)
  1414. }
  1415. }
  1416. func (this *RoleAPIController) GetAllOrgRole() {
  1417. adminUserInfo := this.GetAdminUserInfo()
  1418. var isSubSuperAdmin bool = false
  1419. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  1420. if len(adminUserRole.RoleIds) > 0 {
  1421. //app_role, _ := service.GetAppRoleById(adminUserInfo.)
  1422. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  1423. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1424. if adminUserInfo.AdminUser.Id != org.Creator {
  1425. for _, item := range role_ids {
  1426. id, _ := strconv.ParseInt(item, 10, 64)
  1427. if id != 0 {
  1428. role, _ := service.GetRoleByRoleID(id)
  1429. if role != nil {
  1430. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  1431. isSubSuperAdmin = true
  1432. }
  1433. }
  1434. }
  1435. }
  1436. }
  1437. }
  1438. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1439. roles, err := service.GetAllOrgValidRoles(adminUserInfo.CurrentOrgId, isSubSuperAdmin)
  1440. if err != nil {
  1441. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1442. return
  1443. } else {
  1444. this.ServeSuccessJSON(map[string]interface{}{
  1445. "roles": roles,
  1446. "isSubSuperAdmin": isSubSuperAdmin,
  1447. "org": org,
  1448. })
  1449. }
  1450. }
  1451. func (this *RoleAPIController) GetAllOrgUser() {
  1452. adminUserInfo := this.GetAdminUserInfo()
  1453. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1454. var isSubSuperAdmin bool = false
  1455. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  1456. if len(adminUserRole.RoleIds) > 0 {
  1457. //app_role, _ := service.GetAppRoleById(adminUserInfo.)
  1458. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  1459. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1460. if adminUserInfo.AdminUser.Id != org.Creator {
  1461. for _, item := range role_ids {
  1462. id, _ := strconv.ParseInt(item, 10, 64)
  1463. if id != 0 {
  1464. role, _ := service.GetRoleByRoleID(id)
  1465. if role != nil {
  1466. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  1467. isSubSuperAdmin = true
  1468. }
  1469. }
  1470. }
  1471. }
  1472. }
  1473. }
  1474. viewModels, _, _ := service.GetAllAdminUsersAndRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  1475. this.ServeSuccessJSON(map[string]interface{}{
  1476. "admins": viewModels,
  1477. "org": org,
  1478. "isSubSuperAdmin": isSubSuperAdmin,
  1479. })
  1480. }
  1481. func (this *RoleAPIController) AddRoleStaff() {
  1482. //adminUserInfo := this.GetMobileAdminUserInfo()
  1483. role_id, _ := this.GetInt64("id", 0)
  1484. staff_ids := this.GetString("ids")
  1485. ids := strings.Split(staff_ids, ",")
  1486. for _, item := range ids {
  1487. id, _ := strconv.ParseInt(item, 10, 64)
  1488. role, _ := service.FindAdminUserID(id)
  1489. role.RoleIds = role.RoleIds + "," + strconv.FormatInt(role_id, 10)
  1490. service.SaveAdminUser(&role)
  1491. }
  1492. this.ServeSuccessJSON(map[string]interface{}{
  1493. "msg": "添加成功",
  1494. })
  1495. }
  1496. func (this *RoleAPIController) GetRoleStaff() {
  1497. adminUserInfo := this.GetAdminUserInfo()
  1498. var isSubSuperAdmin bool = false
  1499. adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
  1500. if len(adminUserRole.RoleIds) > 0 {
  1501. role_ids := strings.Split(adminUserRole.RoleIds, ",")
  1502. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1503. if adminUserInfo.AdminUser.Id != org.Creator {
  1504. for _, item := range role_ids {
  1505. id, _ := strconv.ParseInt(item, 10, 64)
  1506. if id != 0 {
  1507. role, _ := service.GetRoleByRoleID(id)
  1508. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  1509. isSubSuperAdmin = true
  1510. }
  1511. }
  1512. }
  1513. }
  1514. }
  1515. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  1516. viewModels, _, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
  1517. if getAdminsErr != nil {
  1518. //beego.Error("获取管理员列表失败:", getAdminsErr)
  1519. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1520. return
  1521. }
  1522. this.ServeSuccessJSON(map[string]interface{}{
  1523. "admins": viewModels,
  1524. "org": org,
  1525. "isSubSuperAdmin": isSubSuperAdmin,
  1526. })
  1527. }
  1528. func (this *RoleAPIController) GetRoleInfo() {
  1529. roleId, _ := this.GetInt64("role_id")
  1530. if roleId <= 0 {
  1531. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1532. return
  1533. }
  1534. role, _ := service.GetRoleByRoleID(roleId)
  1535. this.ServeSuccessJSON(map[string]interface{}{
  1536. "role": role,
  1537. })
  1538. }