public_api_controller.go 30KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "encoding/json"
  7. "fmt"
  8. "os"
  9. "path"
  10. "runtime"
  11. "strings"
  12. "time"
  13. "github.com/astaxie/beego"
  14. )
  15. type PublicApiController struct {
  16. BaseAPIController
  17. }
  18. func PublicApiRegistRouters() {
  19. beego.Router("/api/public/getadviceconfig", &PublicApiController{}, "Get:GetDoctorAdviceConfig")
  20. beego.Router("/api/public/servertime", &PublicApiController{}, "Get:GetServerTime")
  21. beego.Router("/api/app/release", &PublicApiController{}, "Get:AppRelease")
  22. beego.Router("/api/get", &PublicApiController{}, "Get:GetJson")
  23. beego.Router("/api/public/handledata", &PublicApiController{}, "get:HandleData")
  24. beego.Router("/api/public/handlestockdata", &PublicApiController{}, "get:HandleStockData")
  25. beego.Router("/api/public/handlecomdata", &PublicApiController{}, "get:HandleComData")
  26. }
  27. func (c *PublicApiController) GetDoctorAdviceConfig() {
  28. drugs, _, _ := service.GetPublicDrugDics()
  29. drugways, _, _ := service.GetPublicDrugWayDics()
  30. efs, _, _ := service.GetPublicExecutionFrequencyDics()
  31. c.ServeSuccessJSON(map[string]interface{}{
  32. "drugs": drugs,
  33. "drugways": drugways,
  34. "efs": efs,
  35. })
  36. }
  37. func (c *PublicApiController) GetServerTime() {
  38. timeNow := time.Now()
  39. timeNowStamp := timeNow.Unix()
  40. timeNowStr := timeNow.Format("2006-01-02 15:04:05")
  41. c.ServeSuccessJSON(map[string]interface{}{
  42. "time": timeNowStr,
  43. "timestamp": timeNowStamp,
  44. })
  45. }
  46. func (c *PublicApiController) AppRelease() {
  47. // appId := c.GetString("appid")
  48. version := c.GetString("version")
  49. appType, _ := c.GetInt64("app_type", 0)
  50. appVersion, err := service.GetAppVersionByAppType(appType)
  51. if err != nil {
  52. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  53. return
  54. }
  55. if appVersion == nil {
  56. c.ServeSuccessJSON(map[string]interface{}{
  57. "version": nil,
  58. "state": 2,
  59. })
  60. return
  61. }
  62. state := strings.Compare(version, appVersion.Version)
  63. // state := 1
  64. if state < 0 {
  65. c.ServeSuccessJSON(map[string]interface{}{
  66. "version": appVersion,
  67. "state": appVersion.Status,
  68. })
  69. return
  70. }
  71. c.ServeSuccessJSON(map[string]interface{}{
  72. "version": nil,
  73. "state": 2,
  74. })
  75. return
  76. }
  77. func (this *PublicApiController) GetJson() {
  78. type Global struct {
  79. DeviceSN string
  80. Version string
  81. Timestamp string
  82. InterfaceSource string
  83. }
  84. type RBPResultModel struct {
  85. Sys string
  86. Dia string
  87. HR string
  88. MeasureTime string
  89. }
  90. type ScannerResultModel struct {
  91. Code string
  92. }
  93. type IDCardResultModel struct {
  94. IDCardNo string
  95. UserName string
  96. Age string
  97. Female string
  98. Male string
  99. SocialSecurityNo string
  100. }
  101. type JsonTemp struct {
  102. Global Global
  103. RBPResultModel RBPResultModel
  104. ScannerResultModel ScannerResultModel
  105. IDCardResultModel IDCardResultModel
  106. }
  107. var person JsonTemp
  108. err3 := json.Unmarshal([]byte(this.GetString("params")), &person)
  109. fmt.Println(err3)
  110. fmt.Println(person.Global)
  111. //temp := JsonTemp{
  112. // Global:Global{
  113. // DeviceSN:"1122",
  114. // Version:"1122",
  115. // Timestamp:"1222",
  116. // InterfaceSource:"1233",
  117. // },
  118. // RBPResultModel: RBPResultModel{
  119. // Sys:"12",
  120. // Dia:"22",
  121. // HR:"23",
  122. // MeasureTime:"123",
  123. // },
  124. // ScannerResultModel:ScannerResultModel{
  125. // Code:"1233",
  126. // },
  127. // IDCardResultModel:IDCardResultModel{
  128. // IDCardNo:"123",
  129. // UserName:"123",
  130. // Age:"123",
  131. // Female:"123",
  132. // Male:"123",
  133. // SocialSecurityNo:"123",
  134. // },
  135. //}
  136. //
  137. //jsonBytes, err := json.Marshal(temp)
  138. //if err != nil {
  139. // fmt.Println(err)
  140. //}
  141. //fmt.Println(string(jsonBytes))
  142. }
  143. func (c *PublicApiController) HandleData() {
  144. //service.HandleData()
  145. org_app, _ := service.GetAllAppOrg()
  146. //org_role, _ := service.GetAllRole()
  147. //
  148. //var org_ids []int64
  149. for _, apps := range org_app {
  150. xt_org_app, _ := service.GetAppByType(int64(apps.OrgId), 3)
  151. //org_app_6, _ := service.GetAppByType(int64(apps.OrgId), 6)
  152. //org_app_7, _ := service.GetAppByType(int64(apps.OrgId), 7)
  153. //org_app_8, _ := service.GetAppByType(int64(apps.OrgId), 8)
  154. //org_app_9, _ := service.GetAppByType(int64(apps.OrgId), 9)
  155. //org_app_10, _ := service.GetAppByType(int64(apps.OrgId), 10)
  156. //org_app_11, _ := service.GetAppByType(int64(apps.OrgId), 11)
  157. //org_app_12, _ := service.GetAppByType(int64(apps.OrgId), 12)
  158. //org_app_13, _ := service.GetAppByType(int64(apps.OrgId), 13)
  159. //org_app_14, _ := service.GetAppByType(int64(apps.OrgId), 14)
  160. //org_app_15, _ := service.GetAppByType(int64(apps.OrgId), 15)
  161. //org_app_16, _ := service.GetAppByType(int64(apps.OrgId), 16)
  162. //org_app_17, _ := service.GetAppByType(int64(apps.OrgId), 17)
  163. org_app_18, _ := service.GetAppByType(int64(apps.OrgId), 18)
  164. var xt_temp_org_app *models.OrgApp
  165. //var mall_temp_org_app *models.OrgApp
  166. if xt_org_app == nil || xt_org_app.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  167. app, _ := service.GetOrgAppA(0, 3)
  168. org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  169. if org == nil || org.Id == 0 {
  170. continue
  171. }
  172. app.Id = 0
  173. app.OrgId = apps.OrgId
  174. app.Creator = int(org.Creator)
  175. app.Number = 0
  176. app.Status = 1
  177. app.ModifyTime = time.Now().Unix()
  178. app.CreateTime = time.Now().Unix()
  179. service.CreateOrgApp(app)
  180. xt_temp_org_app = app
  181. } else {
  182. xt_temp_org_app = xt_org_app
  183. }
  184. //if scrm_org_app == nil || scrm_org_app.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  185. //
  186. // app, _ := service.GetOrgAppA(0, 1)
  187. // //org, _ := service.GetOrgById(int64(12))
  188. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  189. // if org == nil || org.Id == 0 {
  190. // continue
  191. // }
  192. //
  193. //
  194. // app.OrgId = apps.OrgId
  195. // app.Id = 0
  196. //
  197. // app.Creator = int(org.Creator)
  198. // app.Number = 0
  199. // app.Status = 1
  200. // app.ModifyTime = time.Now().Unix()
  201. // app.CreateTime = time.Now().Unix()
  202. // service.CreateOrgApp(app)
  203. //
  204. //}
  205. //
  206. //if cdm_org_app == nil || cdm_org_app.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  207. // app, _ := service.GetOrgAppA(0, 4)
  208. // //org, _ := service.GetOrgById(int64(12))
  209. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  210. // if org == nil || org.Id == 0 {
  211. // continue
  212. // }
  213. //
  214. //
  215. // app.OrgId = apps.OrgId
  216. // app.Creator = int(org.Creator)
  217. // app.Number = 0
  218. // app.Id = 0
  219. //
  220. // app.Status = 1
  221. // app.ModifyTime = time.Now().Unix()
  222. // app.CreateTime = time.Now().Unix()
  223. // service.CreateOrgApp(app)
  224. //}
  225. //
  226. //if mall_org_app == nil || mall_org_app.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  227. // app, _ := service.GetOrgAppA(0, 5)
  228. // //org, _ := service.GetOrgById(int64(12))
  229. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  230. //
  231. // if org == nil || org.Id == 0 {
  232. // continue
  233. // }
  234. //
  235. // app.OrgId = apps.OrgId
  236. // app.Creator = int(org.Creator)
  237. // app.Number = 0
  238. // app.Id = 0
  239. //
  240. // app.Status = 1
  241. // app.ModifyTime = time.Now().Unix()
  242. // app.CreateTime = time.Now().Unix()
  243. // service.CreateOrgApp(app)
  244. // mall_temp_org_app = app
  245. //} else {
  246. // mall_temp_org_app = mall_org_app
  247. //}
  248. //
  249. //if org_app_16 == nil || org_app_16.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  250. // app, _ := service.GetOrgAppA(0, 16)
  251. // //org, _ := service.GetOrgById(int64(12))
  252. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  253. // if org == nil || org.Id == 0 {
  254. // continue
  255. // }
  256. //
  257. // app.OrgId = apps.OrgId
  258. // app.Creator = int(org.Creator)
  259. // app.Number = 11
  260. // app.Id = 0
  261. // app.Status = 1
  262. // app.ModifyTime = time.Now().Unix()
  263. // app.CreateTime = time.Now().Unix()
  264. // app.Pid = xt_temp_org_app.Id
  265. // service.CreateOrgApp(app)
  266. //
  267. //}
  268. //
  269. //if org_app_17 == nil || org_app_17.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  270. // app, _ := service.GetOrgAppA(0, 17)
  271. // //org, _ := service.GetOrgById(int64(12))
  272. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  273. // if org == nil || org.Id == 0 {
  274. // continue
  275. // }
  276. //
  277. // app.OrgId = apps.OrgId
  278. // app.Creator = int(org.Creator)
  279. // app.Number = 12
  280. // app.Id = 0
  281. // app.Status = 1
  282. // app.ModifyTime = time.Now().Unix()
  283. // app.CreateTime = time.Now().Unix()
  284. // app.Pid = xt_temp_org_app.Id
  285. // service.CreateOrgApp(app)
  286. //
  287. //}
  288. if org_app_18 == nil || org_app_18.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  289. app, _ := service.GetOrgAppA(0, 18)
  290. //org, _ := service.GetOrgById(int64(12))
  291. org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  292. if org == nil || org.Id == 0 {
  293. continue
  294. }
  295. app.OrgId = apps.OrgId
  296. app.Creator = int(org.Creator)
  297. app.Number = 5
  298. app.Id = 0
  299. app.Status = 1
  300. app.ModifyTime = time.Now().Unix()
  301. app.CreateTime = time.Now().Unix()
  302. app.Pid = xt_temp_org_app.Id
  303. service.CreateOrgApp(app)
  304. }
  305. //if org_app_7 == nil || org_app_7.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  306. // app, _ := service.GetOrgAppA(0, 7)
  307. // //org, _ := service.GetOrgById(int64(12))
  308. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  309. // if org == nil || org.Id == 0 {
  310. // continue
  311. // }
  312. //
  313. //
  314. // app.OrgId = apps.OrgId
  315. // app.Creator = int(org.Creator)
  316. // app.Number = 2
  317. // app.Status = 2
  318. // app.Id = 0
  319. //
  320. // app.ModifyTime = time.Now().Unix()
  321. // app.CreateTime = time.Now().Unix()
  322. // app.Pid = xt_temp_org_app.Id
  323. //
  324. // service.CreateOrgApp(app)
  325. //}
  326. //if org_app_8 == nil || org_app_8.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  327. // app, _ := service.GetOrgAppA(0, 8)
  328. // //org, _ := service.GetOrgById(int64(12))
  329. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  330. // if org == nil || org.Id == 0 {
  331. // continue
  332. // }
  333. //
  334. //
  335. // app.OrgId = apps.OrgId
  336. // app.Creator = int(org.Creator)
  337. // app.Number = 3
  338. // app.Id = 0
  339. //
  340. // app.Pid = mall_temp_org_app.Id
  341. //
  342. // app.Status = 1
  343. // app.ModifyTime = time.Now().Unix()
  344. // app.CreateTime = time.Now().Unix()
  345. // service.CreateOrgApp(app)
  346. //}
  347. //if org_app_9 == nil || org_app_9.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  348. // app, _ := service.GetOrgAppA(0, 9)
  349. // //org, _ := service.GetOrgById(int64(12))
  350. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  351. // if org == nil || org.Id == 0 {
  352. // continue
  353. // }
  354. //
  355. //
  356. // app.OrgId = apps.OrgId
  357. // app.Pid = xt_temp_org_app.Id
  358. //
  359. // app.Creator = int(org.Creator)
  360. // app.Number = 4
  361. // app.Id = 0
  362. //
  363. // app.Status = 1
  364. // app.ModifyTime = time.Now().Unix()
  365. // app.CreateTime = time.Now().Unix()
  366. // service.CreateOrgApp(app)
  367. //
  368. //}
  369. //if org_app_10 == nil || org_app_10.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  370. // app, _ := service.GetOrgAppA(0, 10)
  371. // //org, _ := service.GetOrgById(int64(12))
  372. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  373. // if org == nil || org.Id == 0 {
  374. // continue
  375. // }
  376. //
  377. //
  378. // app.OrgId = apps.OrgId
  379. // app.Creator = int(org.Creator)
  380. // app.Pid = xt_temp_org_app.Id
  381. //
  382. // app.Number = 5
  383. // app.Id = 0
  384. //
  385. // app.Status = 1
  386. // app.ModifyTime = time.Now().Unix()
  387. // app.CreateTime = time.Now().Unix()
  388. // service.CreateOrgApp(app)
  389. //}
  390. //if org_app_11 == nil || org_app_11.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  391. // app, _ := service.GetOrgAppA(0, 11)
  392. // //org, _ := service.GetOrgById(int64(12))
  393. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  394. // if org == nil || org.Id == 0 {
  395. // continue
  396. // }
  397. //
  398. //
  399. // app.OrgId = apps.OrgId
  400. // app.Creator = int(org.Creator)
  401. // app.Pid = xt_temp_org_app.Id
  402. // app.Id = 0
  403. //
  404. // app.Number = 6
  405. // app.Status = 1
  406. // app.ModifyTime = time.Now().Unix()
  407. // app.CreateTime = time.Now().Unix()
  408. // service.CreateOrgApp(app)
  409. //}
  410. //if org_app_12 == nil || org_app_12.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  411. // app, _ := service.GetOrgAppA(0, 12)
  412. // //org, _ := service.GetOrgById(int64(12))
  413. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  414. // if org == nil || org.Id == 0 {
  415. // continue
  416. // }
  417. //
  418. //
  419. // app.OrgId = apps.OrgId
  420. // app.Creator = int(org.Creator)
  421. // app.Pid = xt_temp_org_app.Id
  422. // app.Number = 7
  423. // app.Status = 1
  424. // app.Id = 0
  425. //
  426. // app.ModifyTime = time.Now().Unix()
  427. // app.CreateTime = time.Now().Unix()
  428. // service.CreateOrgApp(app)
  429. //}
  430. //if org_app_13 == nil || org_app_13.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  431. // app, _ := service.GetOrgAppA(0, 13)
  432. // //org, _ := service.GetOrgById(int64(12))
  433. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  434. // if org == nil || org.Id == 0 {
  435. // continue
  436. // }
  437. //
  438. //
  439. // app.OrgId = apps.OrgId
  440. // app.Creator = int(org.Creator)
  441. // app.Pid = xt_temp_org_app.Id
  442. // app.Number = 8
  443. // app.Id = 0
  444. // app.Status = 1
  445. // app.ModifyTime = time.Now().Unix()
  446. // app.CreateTime = time.Now().Unix()
  447. // service.CreateOrgApp(app)
  448. //}
  449. //if org_app_14 == nil || org_app_14.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  450. // app, _ := service.GetOrgAppA(0, 14)
  451. // //org, _ := service.GetOrgById(int64(12))
  452. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  453. // if org == nil || org.Id == 0 {
  454. // continue
  455. // }
  456. //
  457. //
  458. // app.OrgId = apps.OrgId
  459. // app.Creator = int(org.Creator)
  460. // app.Pid = xt_temp_org_app.Id
  461. // app.Id = 0
  462. // app.Number = 9
  463. // app.Status = 1
  464. // app.ModifyTime = time.Now().Unix()
  465. // app.CreateTime = time.Now().Unix()
  466. // service.CreateOrgApp(app)
  467. //}
  468. //if org_app_15 == nil || org_app_15.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  469. // app, _ := service.GetOrgAppA(0, 15)
  470. // //org, _ := service.GetOrgById(int64(12))
  471. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  472. // if org == nil || org.Id == 0 {
  473. // continue
  474. // }
  475. //
  476. // app.OrgId = apps.OrgId
  477. // app.Creator = int(org.Creator)
  478. // app.Pid = xt_temp_org_app.Id
  479. // app.Number = 10
  480. // app.Status = 1
  481. // app.Id = 0
  482. // app.ModifyTime = time.Now().Unix()
  483. // app.CreateTime = time.Now().Unix()
  484. // service.CreateOrgApp(app)
  485. //}
  486. }
  487. //for _, role := range org_role {
  488. // org_ids = append(org_ids, role.OrgId)
  489. //}
  490. //
  491. //
  492. ////创建内置角色
  493. //InitRoleAndPurviews(org_ids)
  494. //var org_id int = 0
  495. //管理员
  496. //app_roles := service.GetAllUserRoleByUserTypeOne(org_id)
  497. //for _, item := range app_roles{
  498. // var ids string
  499. // if len(item.RoleIds) == 0{
  500. // ids = strconv.FormatInt( item.RoleId,10)
  501. // }else{
  502. // ids = item.RoleIds + ","+strconv.FormatInt( item.RoleId,10)
  503. // }
  504. // service.UpdateRoleIds(item.Id, ids)
  505. //}
  506. //护士医生
  507. //app_roles2 := service.GetAllUserRoleByUserTypeOther()
  508. // for _, item := range app_roles2{
  509. // var ids string
  510. // if len(item.RoleIds) == 0{
  511. // ids = strconv.FormatInt( item.RoleId,10)
  512. // }else{
  513. // ids = item.RoleIds + ","+strconv.FormatInt( item.RoleId,10)
  514. // }
  515. // if item.UserType == 2{
  516. // role := service.FindRoleByUserTypeOne(item.OrgId)
  517. // ids = ids +"," + strconv.FormatInt(role.Id,10)
  518. //
  519. // } else if item.UserType == 3{
  520. // role := service.FindRoleByUserTypeTwo(item.OrgId)
  521. // ids = ids +"," + strconv.FormatInt(role.Id,10)
  522. // }
  523. // service.UpdateRoleIds(item.Id, ids)
  524. // }
  525. //c.ServeSuccessJSON(map[string]interface{}{
  526. // "msg": "ok",
  527. //})
  528. }
  529. func InitRoleAndPurviews(org_ids []int64) {
  530. roles := LoadRoleConfig("./role.json").Roles
  531. for _, org_id := range org_ids {
  532. app, _ := service.GetOrgAppB(org_id, 3)
  533. role, _ := service.GetSystemRole(org_id)
  534. if app == nil || app.Id == 0 {
  535. continue
  536. }
  537. if len(role) == 0 {
  538. for _, item := range roles {
  539. role := &models.Role{
  540. RoleName: item.RoleName,
  541. RoleIntro: item.RoleIntroduction,
  542. Creator: 0,
  543. OrgId: org_id,
  544. AppId: app.Id,
  545. IsSuperAdmin: false,
  546. Status: 1,
  547. CreateTime: time.Now().Unix(),
  548. ModifyTime: time.Now().Unix(),
  549. Number: item.Number,
  550. IsSystem: item.IsSystem,
  551. }
  552. err := service.CreateOrgRoleB(role)
  553. if err == nil {
  554. purview := &models.RolePurview{
  555. RoleId: role.Id,
  556. OrgId: org_id,
  557. AppId: role.AppId,
  558. PurviewIds: item.PurviewIds,
  559. Status: 1,
  560. CreateTime: time.Now().Unix(),
  561. ModifyTime: time.Now().Unix(),
  562. }
  563. func_purview := &models.SgjUserRoleFuncPurview{
  564. RoleId: role.Id,
  565. OrgId: org_id,
  566. AppId: role.AppId,
  567. PurviewIds: item.FuncIds,
  568. Status: 1,
  569. Ctime: time.Now().Unix(),
  570. Mtime: time.Now().Unix(),
  571. }
  572. service.CreateRolePurviewB(purview)
  573. service.CreateFuncRolePurviewB(func_purview)
  574. }
  575. }
  576. }
  577. }
  578. }
  579. type RoleConfig struct {
  580. Roles []*models.VMUserRoleAndPurview "json:roles"
  581. }
  582. func LoadRoleConfig(dataFile string) *RoleConfig {
  583. var config RoleConfig
  584. _, filename, _, _ := runtime.Caller(1)
  585. datapath := path.Join(path.Dir(filename), dataFile)
  586. config_file, err := os.Open(datapath)
  587. if err != nil {
  588. emit("Failed to open config file '%s': %s\n", datapath, err)
  589. return &config
  590. }
  591. fi, _ := config_file.Stat()
  592. buffer := make([]byte, fi.Size())
  593. _, err = config_file.Read(buffer)
  594. buffer, err = StripComments(buffer) //去掉注释
  595. if err != nil {
  596. emit("Failed to strip comments from json: %s\n", err)
  597. return &config
  598. }
  599. buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
  600. err = json.Unmarshal(buffer, &config) //解析json格式数据
  601. if err != nil {
  602. emit("Failed unmarshalling json: %s\n", err)
  603. return &config
  604. }
  605. return &config
  606. }
  607. type GoodTypesConfig struct {
  608. GoodTypes []*models.VMGoodsType "json:list"
  609. }
  610. func LoadGoodTypeConfig(dataFile string) *GoodTypesConfig {
  611. var config GoodTypesConfig
  612. _, filename, _, _ := runtime.Caller(1)
  613. datapath := path.Join(path.Dir(filename), dataFile)
  614. config_file, err := os.Open(datapath)
  615. if err != nil {
  616. emit("Failed to open config file '%s': %s\n", datapath, err)
  617. return &config
  618. }
  619. fi, _ := config_file.Stat()
  620. buffer := make([]byte, fi.Size())
  621. _, err = config_file.Read(buffer)
  622. buffer, err = StripComments(buffer) //去掉注释
  623. if err != nil {
  624. emit("Failed to strip comments from json: %s\n", err)
  625. return &config
  626. }
  627. buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
  628. err = json.Unmarshal(buffer, &config) //解析json格式数据
  629. if err != nil {
  630. emit("Failed unmarshalling json: %s\n", err)
  631. return &config
  632. }
  633. return &config
  634. }
  635. func (c *PublicApiController) HandleStockData() {
  636. org, _ := service.FindAllOrgByImportType()
  637. for _, item := range org {
  638. goodTypes := &models.GoodsType{
  639. TypeCode: "14000000",
  640. TypeName: "穿刺针",
  641. Remark: "",
  642. Ctime: time.Now().Unix(),
  643. Mtime: time.Now().Unix(),
  644. Creater: 0,
  645. Modifier: 0,
  646. OrgId: item.Id,
  647. Status: 1,
  648. Type: 1,
  649. Number: 1,
  650. }
  651. service.AddSigleGoodType(goodTypes)
  652. goodTypes1 := &models.GoodsType{
  653. TypeCode: "14000001",
  654. TypeName: "透析器",
  655. Remark: "",
  656. Ctime: time.Now().Unix(),
  657. Mtime: time.Now().Unix(),
  658. Creater: 0,
  659. Modifier: 0,
  660. OrgId: item.Id,
  661. Status: 1,
  662. Type: 1,
  663. Number: 2,
  664. }
  665. service.AddSigleGoodType(goodTypes1)
  666. goodTypes2 := &models.GoodsType{
  667. TypeCode: "14000002",
  668. TypeName: "灌流器",
  669. Remark: "",
  670. Ctime: time.Now().Unix(),
  671. Mtime: time.Now().Unix(),
  672. Creater: 0,
  673. Modifier: 0,
  674. OrgId: item.Id,
  675. Status: 1,
  676. Type: 1,
  677. Number: 3,
  678. }
  679. service.AddSigleGoodType(goodTypes2)
  680. goodTypes3 := &models.GoodsType{
  681. TypeCode: "14000003",
  682. TypeName: "血路管",
  683. Remark: "",
  684. Ctime: time.Now().Unix(),
  685. Mtime: time.Now().Unix(),
  686. Creater: 0,
  687. Modifier: 0,
  688. OrgId: item.Id,
  689. Status: 1,
  690. Type: 1,
  691. Number: 4,
  692. }
  693. service.AddSigleGoodType(goodTypes3)
  694. goodTypes4 := &models.GoodsType{
  695. TypeCode: "14000004",
  696. TypeName: "血滤补液管",
  697. Remark: "",
  698. Ctime: time.Now().Unix(),
  699. Mtime: time.Now().Unix(),
  700. Creater: 0,
  701. Modifier: 0,
  702. OrgId: item.Id,
  703. Status: 1,
  704. Type: 1,
  705. Number: 5,
  706. }
  707. service.AddSigleGoodType(goodTypes4)
  708. goodTypes5 := &models.GoodsType{
  709. TypeCode: "14000005",
  710. TypeName: "注射器",
  711. Remark: "",
  712. Ctime: time.Now().Unix(),
  713. Mtime: time.Now().Unix(),
  714. Creater: 0,
  715. Modifier: 0,
  716. OrgId: item.Id,
  717. Status: 1,
  718. Type: 1,
  719. Number: 6,
  720. }
  721. service.AddSigleGoodType(goodTypes5)
  722. goodTypes6 := &models.GoodsType{
  723. TypeCode: "14000006",
  724. TypeName: "护理包(内瘘穿刺包)",
  725. Remark: "",
  726. Ctime: time.Now().Unix(),
  727. Mtime: time.Now().Unix(),
  728. Creater: 0,
  729. Modifier: 0,
  730. OrgId: item.Id,
  731. Status: 1,
  732. Type: 1,
  733. Number: 7,
  734. }
  735. service.AddSigleGoodType(goodTypes6)
  736. goodTypes7 := &models.GoodsType{
  737. TypeCode: "14000007",
  738. TypeName: "细菌过滤器",
  739. Remark: "",
  740. Ctime: time.Now().Unix(),
  741. Mtime: time.Now().Unix(),
  742. Creater: 0,
  743. Modifier: 0,
  744. OrgId: item.Id,
  745. Status: 1,
  746. Type: 1,
  747. Number: 8,
  748. }
  749. service.AddSigleGoodType(goodTypes7)
  750. goodTypes8 := &models.GoodsType{
  751. TypeCode: "14000008",
  752. TypeName: "血液透析干粉",
  753. Remark: "",
  754. Ctime: time.Now().Unix(),
  755. Mtime: time.Now().Unix(),
  756. Creater: 0,
  757. Modifier: 0,
  758. OrgId: item.Id,
  759. Status: 1,
  760. Type: 1,
  761. Number: 9,
  762. }
  763. service.AddSigleGoodType(goodTypes8)
  764. goodTypes9 := &models.GoodsType{
  765. TypeCode: "14000009",
  766. TypeName: "A液",
  767. Remark: "",
  768. Ctime: time.Now().Unix(),
  769. Mtime: time.Now().Unix(),
  770. Creater: 0,
  771. Modifier: 0,
  772. OrgId: item.Id,
  773. Status: 1,
  774. Type: 1,
  775. Number: 10,
  776. }
  777. service.AddSigleGoodType(goodTypes9)
  778. goodTypes10 := &models.GoodsType{
  779. TypeCode: "14000010",
  780. TypeName: "B液",
  781. Remark: "",
  782. Ctime: time.Now().Unix(),
  783. Mtime: time.Now().Unix(),
  784. Creater: 0,
  785. Modifier: 0,
  786. OrgId: item.Id,
  787. Status: 1,
  788. Type: 1,
  789. Number: 11,
  790. }
  791. service.AddSigleGoodType(goodTypes10)
  792. goodTypes11 := &models.GoodsType{
  793. TypeCode: "14000011",
  794. TypeName: "导管包",
  795. Remark: "",
  796. Ctime: time.Now().Unix(),
  797. Mtime: time.Now().Unix(),
  798. Creater: 0,
  799. Modifier: 0,
  800. OrgId: item.Id,
  801. Status: 1,
  802. Type: 1,
  803. Number: 12,
  804. }
  805. service.AddSigleGoodType(goodTypes11)
  806. goodTypes12 := &models.GoodsType{
  807. TypeCode: "14000012",
  808. TypeName: "血液透析导管",
  809. Remark: "",
  810. Ctime: time.Now().Unix(),
  811. Mtime: time.Now().Unix(),
  812. Creater: 0,
  813. Modifier: 0,
  814. OrgId: item.Id,
  815. Status: 1,
  816. Type: 1,
  817. Number: 13,
  818. }
  819. service.AddSigleGoodType(goodTypes12)
  820. }
  821. }
  822. func (c *PublicApiController) HandleComData() {
  823. org_ids := []int64{3907}
  824. for _, id := range org_ids {
  825. //查处所有处方记录
  826. prescriptions, _ := service.FindAllPrescription(id)
  827. if id == 3907 {
  828. for _, item := range prescriptions {
  829. before := &models.DialysisBeforePrepare{
  830. UserOrgId: id,
  831. PatientId: item.PatientId,
  832. RecordDate: item.RecordDate,
  833. Count: 1,
  834. Ctime: item.RecordDate,
  835. Mtime: item.RecordDate,
  836. Creater: item.Creater,
  837. Modifier: item.Creater,
  838. Status: 1,
  839. }
  840. if item.Niprocart > 0 {
  841. before.GoodId = item.Niprocart
  842. before.GoodTypeId = 241
  843. service.AddSigleDialysisBeforePre(before)
  844. }
  845. if item.Jms > 0 {
  846. before.GoodId = item.Jms
  847. before.GoodTypeId = 233
  848. service.AddSigleDialysisBeforePre(before)
  849. }
  850. if item.FistulaNeedleSet > 0 {
  851. before.GoodId = item.FistulaNeedleSet
  852. before.GoodTypeId = 233
  853. service.AddSigleDialysisBeforePre(before)
  854. }
  855. if item.FistulaNeedleSet16 > 0 {
  856. before.GoodId = item.FistulaNeedleSet16
  857. before.GoodTypeId = 233
  858. service.AddSigleDialysisBeforePre(before)
  859. }
  860. if item.Hemoperfusion > 0 {
  861. before.GoodId = item.Hemoperfusion
  862. before.GoodTypeId = 235
  863. service.AddSigleDialysisBeforePre(before)
  864. }
  865. if item.DialyserSterilised > 0 {
  866. before.GoodId = item.DialyserSterilised
  867. before.GoodTypeId = 234
  868. service.AddSigleDialysisBeforePre(before)
  869. }
  870. if item.Filtryzer > 0 {
  871. before.GoodId = item.Filtryzer
  872. before.GoodTypeId = 234
  873. service.AddSigleDialysisBeforePre(before)
  874. }
  875. if item.Dialyzers > 0 {
  876. before.GoodId = item.Dialyzers
  877. before.GoodTypeId = 234
  878. service.AddSigleDialysisBeforePre(before)
  879. }
  880. if item.Injector > 0 {
  881. before.GoodId = item.Injector
  882. before.GoodTypeId = 238
  883. service.AddSigleDialysisBeforePre(before)
  884. }
  885. if item.Bloodlines > 0 {
  886. before.GoodId = item.Bloodlines
  887. before.GoodTypeId = 236
  888. service.AddSigleDialysisBeforePre(before)
  889. }
  890. if item.TubingHemodialysis > 0 {
  891. before.GoodId = item.TubingHemodialysis
  892. before.GoodTypeId = 237
  893. service.AddSigleDialysisBeforePre(before)
  894. }
  895. if item.Package > 0 {
  896. before.GoodId = item.Package
  897. before.GoodTypeId = 239
  898. service.AddSigleDialysisBeforePre(before)
  899. }
  900. if item.ALiquid > 0 {
  901. before.GoodId = item.ALiquid
  902. before.GoodTypeId = 242
  903. service.AddSigleDialysisBeforePre(before)
  904. }
  905. }
  906. } else if id == 9779 {
  907. for _, item := range prescriptions {
  908. before := &models.DialysisBeforePrepare{
  909. UserOrgId: id,
  910. PatientId: item.PatientId,
  911. RecordDate: item.RecordDate,
  912. Count: 1,
  913. Ctime: item.RecordDate,
  914. Mtime: item.RecordDate,
  915. Creater: item.Creater,
  916. Modifier: item.Creater,
  917. Status: 1,
  918. }
  919. if item.Niprocart > 0 {
  920. before.GoodId = item.Niprocart
  921. before.GoodTypeId = 2
  922. service.AddSigleDialysisBeforePre(before)
  923. }
  924. if item.Jms > 0 {
  925. before.GoodId = item.Jms
  926. before.GoodTypeId = 233
  927. service.AddSigleDialysisBeforePre(before)
  928. }
  929. if item.FistulaNeedleSet > 0 {
  930. before.GoodId = item.FistulaNeedleSet
  931. before.GoodTypeId = 233
  932. service.AddSigleDialysisBeforePre(before)
  933. }
  934. if item.FistulaNeedleSet16 > 0 {
  935. before.GoodId = item.FistulaNeedleSet16
  936. before.GoodTypeId = 233
  937. service.AddSigleDialysisBeforePre(before)
  938. }
  939. if item.Hemoperfusion > 0 {
  940. before.GoodId = item.Hemoperfusion
  941. before.GoodTypeId = 235
  942. service.AddSigleDialysisBeforePre(before)
  943. }
  944. if item.DialyserSterilised > 0 {
  945. before.GoodId = item.DialyserSterilised
  946. before.GoodTypeId = 234
  947. service.AddSigleDialysisBeforePre(before)
  948. }
  949. if item.Filtryzer > 0 {
  950. before.GoodId = item.Filtryzer
  951. before.GoodTypeId = 234
  952. service.AddSigleDialysisBeforePre(before)
  953. }
  954. if item.Dialyzers > 0 {
  955. before.GoodId = item.Dialyzers
  956. before.GoodTypeId = 234
  957. service.AddSigleDialysisBeforePre(before)
  958. }
  959. if item.Injector > 0 {
  960. before.GoodId = item.Injector
  961. before.GoodTypeId = 238
  962. service.AddSigleDialysisBeforePre(before)
  963. }
  964. if item.Bloodlines > 0 {
  965. before.GoodId = item.Bloodlines
  966. before.GoodTypeId = 236
  967. service.AddSigleDialysisBeforePre(before)
  968. }
  969. if item.TubingHemodialysis > 0 {
  970. before.GoodId = item.TubingHemodialysis
  971. before.GoodTypeId = 237
  972. service.AddSigleDialysisBeforePre(before)
  973. }
  974. if item.Package > 0 {
  975. before.GoodId = item.Package
  976. before.GoodTypeId = 239
  977. service.AddSigleDialysisBeforePre(before)
  978. }
  979. if item.ALiquid > 0 {
  980. before.GoodId = item.ALiquid
  981. before.GoodTypeId = 242
  982. service.AddSigleDialysisBeforePre(before)
  983. }
  984. }
  985. } else if id == 9883 {
  986. for _, item := range prescriptions {
  987. before := &models.DialysisBeforePrepare{
  988. UserOrgId: id,
  989. PatientId: item.PatientId,
  990. RecordDate: item.RecordDate,
  991. Count: 1,
  992. Ctime: item.RecordDate,
  993. Mtime: item.RecordDate,
  994. Creater: item.Creater,
  995. Modifier: item.Creater,
  996. Status: 1,
  997. }
  998. if item.Niprocart > 0 {
  999. before.GoodId = item.Niprocart
  1000. before.GoodTypeId = 241
  1001. service.AddSigleDialysisBeforePre(before)
  1002. }
  1003. if item.Jms > 0 {
  1004. before.GoodId = item.Jms
  1005. before.GoodTypeId = 233
  1006. service.AddSigleDialysisBeforePre(before)
  1007. }
  1008. if item.FistulaNeedleSet > 0 {
  1009. before.GoodId = item.FistulaNeedleSet
  1010. before.GoodTypeId = 233
  1011. service.AddSigleDialysisBeforePre(before)
  1012. }
  1013. if item.FistulaNeedleSet16 > 0 {
  1014. before.GoodId = item.FistulaNeedleSet16
  1015. before.GoodTypeId = 233
  1016. service.AddSigleDialysisBeforePre(before)
  1017. }
  1018. if item.Hemoperfusion > 0 {
  1019. before.GoodId = item.Hemoperfusion
  1020. before.GoodTypeId = 235
  1021. service.AddSigleDialysisBeforePre(before)
  1022. }
  1023. if item.DialyserSterilised > 0 {
  1024. before.GoodId = item.DialyserSterilised
  1025. before.GoodTypeId = 234
  1026. service.AddSigleDialysisBeforePre(before)
  1027. }
  1028. if item.Filtryzer > 0 {
  1029. before.GoodId = item.Filtryzer
  1030. before.GoodTypeId = 234
  1031. service.AddSigleDialysisBeforePre(before)
  1032. }
  1033. if item.Dialyzers > 0 {
  1034. before.GoodId = item.Dialyzers
  1035. before.GoodTypeId = 234
  1036. service.AddSigleDialysisBeforePre(before)
  1037. }
  1038. if item.Injector > 0 {
  1039. before.GoodId = item.Injector
  1040. before.GoodTypeId = 238
  1041. service.AddSigleDialysisBeforePre(before)
  1042. }
  1043. if item.Bloodlines > 0 {
  1044. before.GoodId = item.Bloodlines
  1045. before.GoodTypeId = 236
  1046. service.AddSigleDialysisBeforePre(before)
  1047. }
  1048. if item.TubingHemodialysis > 0 {
  1049. before.GoodId = item.TubingHemodialysis
  1050. before.GoodTypeId = 237
  1051. service.AddSigleDialysisBeforePre(before)
  1052. }
  1053. if item.Package > 0 {
  1054. before.GoodId = item.Package
  1055. before.GoodTypeId = 239
  1056. service.AddSigleDialysisBeforePre(before)
  1057. }
  1058. if item.ALiquid > 0 {
  1059. before.GoodId = item.ALiquid
  1060. before.GoodTypeId = 242
  1061. service.AddSigleDialysisBeforePre(before)
  1062. }
  1063. }
  1064. }
  1065. }
  1066. }