role_controller.go 52KB

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