role_controller.go 51KB

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