role_controller.go 56KB

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