role_controller.go 58KB

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