public_api_controller.go 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  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. }
  26. func (c *PublicApiController) GetDoctorAdviceConfig() {
  27. drugs, _, _ := service.GetPublicDrugDics()
  28. drugways, _, _ := service.GetPublicDrugWayDics()
  29. efs, _, _ := service.GetPublicExecutionFrequencyDics()
  30. c.ServeSuccessJSON(map[string]interface{}{
  31. "drugs": drugs,
  32. "drugways": drugways,
  33. "efs": efs,
  34. })
  35. }
  36. func (c *PublicApiController) GetServerTime() {
  37. timeNow := time.Now()
  38. timeNowStamp := timeNow.Unix()
  39. timeNowStr := timeNow.Format("2006-01-02 15:04:05")
  40. c.ServeSuccessJSON(map[string]interface{}{
  41. "time": timeNowStr,
  42. "timestamp": timeNowStamp,
  43. })
  44. }
  45. func (c *PublicApiController) AppRelease() {
  46. // appId := c.GetString("appid")
  47. version := c.GetString("version")
  48. appType, _ := c.GetInt64("app_type", 0)
  49. appVersion, err := service.GetAppVersionByAppType(appType)
  50. if err != nil {
  51. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  52. return
  53. }
  54. if appVersion == nil {
  55. c.ServeSuccessJSON(map[string]interface{}{
  56. "version": nil,
  57. "state": 2,
  58. })
  59. return
  60. }
  61. state := strings.Compare(version, appVersion.Version)
  62. // state := 1
  63. if state < 0 {
  64. c.ServeSuccessJSON(map[string]interface{}{
  65. "version": appVersion,
  66. "state": appVersion.Status,
  67. })
  68. return
  69. }
  70. c.ServeSuccessJSON(map[string]interface{}{
  71. "version": nil,
  72. "state": 2,
  73. })
  74. return
  75. }
  76. func (this *PublicApiController) GetJson() {
  77. type Global struct {
  78. DeviceSN string
  79. Version string
  80. Timestamp string
  81. InterfaceSource string
  82. }
  83. type RBPResultModel struct {
  84. Sys string
  85. Dia string
  86. HR string
  87. MeasureTime string
  88. }
  89. type ScannerResultModel struct {
  90. Code string
  91. }
  92. type IDCardResultModel struct {
  93. IDCardNo string
  94. UserName string
  95. Age string
  96. Female string
  97. Male string
  98. SocialSecurityNo string
  99. }
  100. type JsonTemp struct {
  101. Global Global
  102. RBPResultModel RBPResultModel
  103. ScannerResultModel ScannerResultModel
  104. IDCardResultModel IDCardResultModel
  105. }
  106. var person JsonTemp
  107. err3 := json.Unmarshal([]byte(this.GetString("params")), &person)
  108. fmt.Println(err3)
  109. fmt.Println(person.Global)
  110. //temp := JsonTemp{
  111. // Global:Global{
  112. // DeviceSN:"1122",
  113. // Version:"1122",
  114. // Timestamp:"1222",
  115. // InterfaceSource:"1233",
  116. // },
  117. // RBPResultModel: RBPResultModel{
  118. // Sys:"12",
  119. // Dia:"22",
  120. // HR:"23",
  121. // MeasureTime:"123",
  122. // },
  123. // ScannerResultModel:ScannerResultModel{
  124. // Code:"1233",
  125. // },
  126. // IDCardResultModel:IDCardResultModel{
  127. // IDCardNo:"123",
  128. // UserName:"123",
  129. // Age:"123",
  130. // Female:"123",
  131. // Male:"123",
  132. // SocialSecurityNo:"123",
  133. // },
  134. //}
  135. //
  136. //jsonBytes, err := json.Marshal(temp)
  137. //if err != nil {
  138. // fmt.Println(err)
  139. //}
  140. //fmt.Println(string(jsonBytes))
  141. }
  142. func (c *PublicApiController) HandleData() {
  143. //service.HandleData()
  144. org_app, _ := service.GetAllAppOrg()
  145. //org_role, _ := service.GetAllRole()
  146. //
  147. //var org_ids []int64
  148. for _, apps := range org_app {
  149. xt_org_app, _ := service.GetAppByType(int64(apps.OrgId), 3)
  150. //org_app_6, _ := service.GetAppByType(int64(apps.OrgId), 6)
  151. //org_app_7, _ := service.GetAppByType(int64(apps.OrgId), 7)
  152. //org_app_8, _ := service.GetAppByType(int64(apps.OrgId), 8)
  153. //org_app_9, _ := service.GetAppByType(int64(apps.OrgId), 9)
  154. //org_app_10, _ := service.GetAppByType(int64(apps.OrgId), 10)
  155. //org_app_11, _ := service.GetAppByType(int64(apps.OrgId), 11)
  156. //org_app_12, _ := service.GetAppByType(int64(apps.OrgId), 12)
  157. //org_app_13, _ := service.GetAppByType(int64(apps.OrgId), 13)
  158. //org_app_14, _ := service.GetAppByType(int64(apps.OrgId), 14)
  159. //org_app_15, _ := service.GetAppByType(int64(apps.OrgId), 15)
  160. //org_app_16, _ := service.GetAppByType(int64(apps.OrgId), 16)
  161. //org_app_17, _ := service.GetAppByType(int64(apps.OrgId), 17)
  162. org_app_18, _ := service.GetAppByType(int64(apps.OrgId), 18)
  163. var xt_temp_org_app *models.OrgApp
  164. //var mall_temp_org_app *models.OrgApp
  165. if xt_org_app == nil || xt_org_app.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  166. app, _ := service.GetOrgAppA(0, 3)
  167. org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  168. if org == nil || org.Id == 0 {
  169. continue
  170. }
  171. app.Id = 0
  172. app.OrgId = apps.OrgId
  173. app.Creator = int(org.Creator)
  174. app.Number = 0
  175. app.Status = 1
  176. app.ModifyTime = time.Now().Unix()
  177. app.CreateTime = time.Now().Unix()
  178. service.CreateOrgApp(app)
  179. xt_temp_org_app = app
  180. } else {
  181. xt_temp_org_app = xt_org_app
  182. }
  183. //if scrm_org_app == nil || scrm_org_app.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  184. //
  185. // app, _ := service.GetOrgAppA(0, 1)
  186. // //org, _ := service.GetOrgById(int64(12))
  187. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  188. // if org == nil || org.Id == 0 {
  189. // continue
  190. // }
  191. //
  192. //
  193. // app.OrgId = apps.OrgId
  194. // app.Id = 0
  195. //
  196. // app.Creator = int(org.Creator)
  197. // app.Number = 0
  198. // app.Status = 1
  199. // app.ModifyTime = time.Now().Unix()
  200. // app.CreateTime = time.Now().Unix()
  201. // service.CreateOrgApp(app)
  202. //
  203. //}
  204. //
  205. //if cdm_org_app == nil || cdm_org_app.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  206. // app, _ := service.GetOrgAppA(0, 4)
  207. // //org, _ := service.GetOrgById(int64(12))
  208. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  209. // if org == nil || org.Id == 0 {
  210. // continue
  211. // }
  212. //
  213. //
  214. // app.OrgId = apps.OrgId
  215. // app.Creator = int(org.Creator)
  216. // app.Number = 0
  217. // app.Id = 0
  218. //
  219. // app.Status = 1
  220. // app.ModifyTime = time.Now().Unix()
  221. // app.CreateTime = time.Now().Unix()
  222. // service.CreateOrgApp(app)
  223. //}
  224. //
  225. //if mall_org_app == nil || mall_org_app.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  226. // app, _ := service.GetOrgAppA(0, 5)
  227. // //org, _ := service.GetOrgById(int64(12))
  228. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  229. //
  230. // if org == nil || org.Id == 0 {
  231. // continue
  232. // }
  233. //
  234. // app.OrgId = apps.OrgId
  235. // app.Creator = int(org.Creator)
  236. // app.Number = 0
  237. // app.Id = 0
  238. //
  239. // app.Status = 1
  240. // app.ModifyTime = time.Now().Unix()
  241. // app.CreateTime = time.Now().Unix()
  242. // service.CreateOrgApp(app)
  243. // mall_temp_org_app = app
  244. //} else {
  245. // mall_temp_org_app = mall_org_app
  246. //}
  247. //
  248. //if org_app_16 == nil || org_app_16.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  249. // app, _ := service.GetOrgAppA(0, 16)
  250. // //org, _ := service.GetOrgById(int64(12))
  251. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  252. // if org == nil || org.Id == 0 {
  253. // continue
  254. // }
  255. //
  256. // app.OrgId = apps.OrgId
  257. // app.Creator = int(org.Creator)
  258. // app.Number = 11
  259. // app.Id = 0
  260. // app.Status = 1
  261. // app.ModifyTime = time.Now().Unix()
  262. // app.CreateTime = time.Now().Unix()
  263. // app.Pid = xt_temp_org_app.Id
  264. // service.CreateOrgApp(app)
  265. //
  266. //}
  267. //
  268. //if org_app_17 == nil || org_app_17.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  269. // app, _ := service.GetOrgAppA(0, 17)
  270. // //org, _ := service.GetOrgById(int64(12))
  271. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  272. // if org == nil || org.Id == 0 {
  273. // continue
  274. // }
  275. //
  276. // app.OrgId = apps.OrgId
  277. // app.Creator = int(org.Creator)
  278. // app.Number = 12
  279. // app.Id = 0
  280. // app.Status = 1
  281. // app.ModifyTime = time.Now().Unix()
  282. // app.CreateTime = time.Now().Unix()
  283. // app.Pid = xt_temp_org_app.Id
  284. // service.CreateOrgApp(app)
  285. //
  286. //}
  287. if org_app_18 == nil || org_app_18.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  288. app, _ := service.GetOrgAppA(0, 18)
  289. //org, _ := service.GetOrgById(int64(12))
  290. org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  291. if org == nil || org.Id == 0 {
  292. continue
  293. }
  294. app.OrgId = apps.OrgId
  295. app.Creator = int(org.Creator)
  296. app.Number = 5
  297. app.Id = 0
  298. app.Status = 1
  299. app.ModifyTime = time.Now().Unix()
  300. app.CreateTime = time.Now().Unix()
  301. app.Pid = xt_temp_org_app.Id
  302. service.CreateOrgApp(app)
  303. }
  304. //if org_app_7 == nil || org_app_7.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  305. // app, _ := service.GetOrgAppA(0, 7)
  306. // //org, _ := service.GetOrgById(int64(12))
  307. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  308. // if org == nil || org.Id == 0 {
  309. // continue
  310. // }
  311. //
  312. //
  313. // app.OrgId = apps.OrgId
  314. // app.Creator = int(org.Creator)
  315. // app.Number = 2
  316. // app.Status = 2
  317. // app.Id = 0
  318. //
  319. // app.ModifyTime = time.Now().Unix()
  320. // app.CreateTime = time.Now().Unix()
  321. // app.Pid = xt_temp_org_app.Id
  322. //
  323. // service.CreateOrgApp(app)
  324. //}
  325. //if org_app_8 == nil || org_app_8.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  326. // app, _ := service.GetOrgAppA(0, 8)
  327. // //org, _ := service.GetOrgById(int64(12))
  328. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  329. // if org == nil || org.Id == 0 {
  330. // continue
  331. // }
  332. //
  333. //
  334. // app.OrgId = apps.OrgId
  335. // app.Creator = int(org.Creator)
  336. // app.Number = 3
  337. // app.Id = 0
  338. //
  339. // app.Pid = mall_temp_org_app.Id
  340. //
  341. // app.Status = 1
  342. // app.ModifyTime = time.Now().Unix()
  343. // app.CreateTime = time.Now().Unix()
  344. // service.CreateOrgApp(app)
  345. //}
  346. //if org_app_9 == nil || org_app_9.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  347. // app, _ := service.GetOrgAppA(0, 9)
  348. // //org, _ := service.GetOrgById(int64(12))
  349. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  350. // if org == nil || org.Id == 0 {
  351. // continue
  352. // }
  353. //
  354. //
  355. // app.OrgId = apps.OrgId
  356. // app.Pid = xt_temp_org_app.Id
  357. //
  358. // app.Creator = int(org.Creator)
  359. // app.Number = 4
  360. // app.Id = 0
  361. //
  362. // app.Status = 1
  363. // app.ModifyTime = time.Now().Unix()
  364. // app.CreateTime = time.Now().Unix()
  365. // service.CreateOrgApp(app)
  366. //
  367. //}
  368. //if org_app_10 == nil || org_app_10.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  369. // app, _ := service.GetOrgAppA(0, 10)
  370. // //org, _ := service.GetOrgById(int64(12))
  371. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  372. // if org == nil || org.Id == 0 {
  373. // continue
  374. // }
  375. //
  376. //
  377. // app.OrgId = apps.OrgId
  378. // app.Creator = int(org.Creator)
  379. // app.Pid = xt_temp_org_app.Id
  380. //
  381. // app.Number = 5
  382. // app.Id = 0
  383. //
  384. // app.Status = 1
  385. // app.ModifyTime = time.Now().Unix()
  386. // app.CreateTime = time.Now().Unix()
  387. // service.CreateOrgApp(app)
  388. //}
  389. //if org_app_11 == nil || org_app_11.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  390. // app, _ := service.GetOrgAppA(0, 11)
  391. // //org, _ := service.GetOrgById(int64(12))
  392. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  393. // if org == nil || org.Id == 0 {
  394. // continue
  395. // }
  396. //
  397. //
  398. // app.OrgId = apps.OrgId
  399. // app.Creator = int(org.Creator)
  400. // app.Pid = xt_temp_org_app.Id
  401. // app.Id = 0
  402. //
  403. // app.Number = 6
  404. // app.Status = 1
  405. // app.ModifyTime = time.Now().Unix()
  406. // app.CreateTime = time.Now().Unix()
  407. // service.CreateOrgApp(app)
  408. //}
  409. //if org_app_12 == nil || org_app_12.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  410. // app, _ := service.GetOrgAppA(0, 12)
  411. // //org, _ := service.GetOrgById(int64(12))
  412. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  413. // if org == nil || org.Id == 0 {
  414. // continue
  415. // }
  416. //
  417. //
  418. // app.OrgId = apps.OrgId
  419. // app.Creator = int(org.Creator)
  420. // app.Pid = xt_temp_org_app.Id
  421. // app.Number = 7
  422. // app.Status = 1
  423. // app.Id = 0
  424. //
  425. // app.ModifyTime = time.Now().Unix()
  426. // app.CreateTime = time.Now().Unix()
  427. // service.CreateOrgApp(app)
  428. //}
  429. //if org_app_13 == nil || org_app_13.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  430. // app, _ := service.GetOrgAppA(0, 13)
  431. // //org, _ := service.GetOrgById(int64(12))
  432. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  433. // if org == nil || org.Id == 0 {
  434. // continue
  435. // }
  436. //
  437. //
  438. // app.OrgId = apps.OrgId
  439. // app.Creator = int(org.Creator)
  440. // app.Pid = xt_temp_org_app.Id
  441. // app.Number = 8
  442. // app.Id = 0
  443. // app.Status = 1
  444. // app.ModifyTime = time.Now().Unix()
  445. // app.CreateTime = time.Now().Unix()
  446. // service.CreateOrgApp(app)
  447. //}
  448. //if org_app_14 == nil || org_app_14.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  449. // app, _ := service.GetOrgAppA(0, 14)
  450. // //org, _ := service.GetOrgById(int64(12))
  451. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  452. // if org == nil || org.Id == 0 {
  453. // continue
  454. // }
  455. //
  456. //
  457. // app.OrgId = apps.OrgId
  458. // app.Creator = int(org.Creator)
  459. // app.Pid = xt_temp_org_app.Id
  460. // app.Id = 0
  461. // app.Number = 9
  462. // app.Status = 1
  463. // app.ModifyTime = time.Now().Unix()
  464. // app.CreateTime = time.Now().Unix()
  465. // service.CreateOrgApp(app)
  466. //}
  467. //if org_app_15 == nil || org_app_15.Id == 0 { //判断之前是否有创建该app类型,如果没有则插入数据
  468. // app, _ := service.GetOrgAppA(0, 15)
  469. // //org, _ := service.GetOrgById(int64(12))
  470. // org, _ := service.GetOrgByIdB(int64(apps.OrgId))
  471. // if org == nil || org.Id == 0 {
  472. // continue
  473. // }
  474. //
  475. // app.OrgId = apps.OrgId
  476. // app.Creator = int(org.Creator)
  477. // app.Pid = xt_temp_org_app.Id
  478. // app.Number = 10
  479. // app.Status = 1
  480. // app.Id = 0
  481. // app.ModifyTime = time.Now().Unix()
  482. // app.CreateTime = time.Now().Unix()
  483. // service.CreateOrgApp(app)
  484. //}
  485. }
  486. //for _, role := range org_role {
  487. // org_ids = append(org_ids, role.OrgId)
  488. //}
  489. //
  490. //
  491. ////创建内置角色
  492. //InitRoleAndPurviews(org_ids)
  493. //var org_id int = 0
  494. //管理员
  495. //app_roles := service.GetAllUserRoleByUserTypeOne(org_id)
  496. //for _, item := range app_roles{
  497. // var ids string
  498. // if len(item.RoleIds) == 0{
  499. // ids = strconv.FormatInt( item.RoleId,10)
  500. // }else{
  501. // ids = item.RoleIds + ","+strconv.FormatInt( item.RoleId,10)
  502. // }
  503. // service.UpdateRoleIds(item.Id, ids)
  504. //}
  505. //护士医生
  506. //app_roles2 := service.GetAllUserRoleByUserTypeOther()
  507. // for _, item := range app_roles2{
  508. // var ids string
  509. // if len(item.RoleIds) == 0{
  510. // ids = strconv.FormatInt( item.RoleId,10)
  511. // }else{
  512. // ids = item.RoleIds + ","+strconv.FormatInt( item.RoleId,10)
  513. // }
  514. // if item.UserType == 2{
  515. // role := service.FindRoleByUserTypeOne(item.OrgId)
  516. // ids = ids +"," + strconv.FormatInt(role.Id,10)
  517. //
  518. // } else if item.UserType == 3{
  519. // role := service.FindRoleByUserTypeTwo(item.OrgId)
  520. // ids = ids +"," + strconv.FormatInt(role.Id,10)
  521. // }
  522. // service.UpdateRoleIds(item.Id, ids)
  523. // }
  524. //c.ServeSuccessJSON(map[string]interface{}{
  525. // "msg": "ok",
  526. //})
  527. }
  528. func InitRoleAndPurviews(org_ids []int64) {
  529. roles := LoadRoleConfig("./role.json").Roles
  530. for _, org_id := range org_ids {
  531. app, _ := service.GetOrgAppB(org_id, 3)
  532. role, _ := service.GetSystemRole(org_id)
  533. if app == nil || app.Id == 0 {
  534. continue
  535. }
  536. if len(role) == 0 {
  537. for _, item := range roles {
  538. role := &models.Role{
  539. RoleName: item.RoleName,
  540. RoleIntro: item.RoleIntroduction,
  541. Creator: 0,
  542. OrgId: org_id,
  543. AppId: app.Id,
  544. IsSuperAdmin: false,
  545. Status: 1,
  546. CreateTime: time.Now().Unix(),
  547. ModifyTime: time.Now().Unix(),
  548. Number: item.Number,
  549. IsSystem: item.IsSystem,
  550. }
  551. err := service.CreateOrgRoleB(role)
  552. if err == nil {
  553. purview := &models.RolePurview{
  554. RoleId: role.Id,
  555. OrgId: org_id,
  556. AppId: role.AppId,
  557. PurviewIds: item.PurviewIds,
  558. Status: 1,
  559. CreateTime: time.Now().Unix(),
  560. ModifyTime: time.Now().Unix(),
  561. }
  562. func_purview := &models.SgjUserRoleFuncPurview{
  563. RoleId: role.Id,
  564. OrgId: org_id,
  565. AppId: role.AppId,
  566. PurviewIds: item.FuncIds,
  567. Status: 1,
  568. Ctime: time.Now().Unix(),
  569. Mtime: time.Now().Unix(),
  570. }
  571. service.CreateRolePurviewB(purview)
  572. service.CreateFuncRolePurviewB(func_purview)
  573. }
  574. }
  575. }
  576. }
  577. }
  578. type RoleConfig struct {
  579. Roles []*models.VMUserRoleAndPurview "json:roles"
  580. }
  581. func LoadRoleConfig(dataFile string) *RoleConfig {
  582. var config RoleConfig
  583. _, filename, _, _ := runtime.Caller(1)
  584. datapath := path.Join(path.Dir(filename), dataFile)
  585. config_file, err := os.Open(datapath)
  586. if err != nil {
  587. emit("Failed to open config file '%s': %s\n", datapath, err)
  588. return &config
  589. }
  590. fi, _ := config_file.Stat()
  591. buffer := make([]byte, fi.Size())
  592. _, err = config_file.Read(buffer)
  593. buffer, err = StripComments(buffer) //去掉注释
  594. if err != nil {
  595. emit("Failed to strip comments from json: %s\n", err)
  596. return &config
  597. }
  598. buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
  599. err = json.Unmarshal(buffer, &config) //解析json格式数据
  600. if err != nil {
  601. emit("Failed unmarshalling json: %s\n", err)
  602. return &config
  603. }
  604. return &config
  605. }
  606. type GoodTypesConfig struct {
  607. GoodTypes []*models.VMGoodsType "json:list"
  608. }
  609. func LoadGoodTypeConfig(dataFile string) *GoodTypesConfig {
  610. var config GoodTypesConfig
  611. _, filename, _, _ := runtime.Caller(1)
  612. datapath := path.Join(path.Dir(filename), dataFile)
  613. config_file, err := os.Open(datapath)
  614. if err != nil {
  615. emit("Failed to open config file '%s': %s\n", datapath, err)
  616. return &config
  617. }
  618. fi, _ := config_file.Stat()
  619. buffer := make([]byte, fi.Size())
  620. _, err = config_file.Read(buffer)
  621. buffer, err = StripComments(buffer) //去掉注释
  622. if err != nil {
  623. emit("Failed to strip comments from json: %s\n", err)
  624. return &config
  625. }
  626. buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
  627. err = json.Unmarshal(buffer, &config) //解析json格式数据
  628. if err != nil {
  629. emit("Failed unmarshalling json: %s\n", err)
  630. return &config
  631. }
  632. return &config
  633. }
  634. func (c *PublicApiController) HandleStockData() {
  635. org, _ := service.FindAllOrgByImportType()
  636. for _, item := range org {
  637. goodTypes := &models.GoodsType{
  638. TypeCode: "14000000",
  639. TypeName: "穿刺针",
  640. Remark: "",
  641. Ctime: time.Now().Unix(),
  642. Mtime: time.Now().Unix(),
  643. Creater: 0,
  644. Modifier: 0,
  645. OrgId: item.Id,
  646. Status: 1,
  647. Type: 1,
  648. Number: 1,
  649. }
  650. service.AddSigleGoodType(goodTypes)
  651. goodTypes1 := &models.GoodsType{
  652. TypeCode: "14000001",
  653. TypeName: "透析器",
  654. Remark: "",
  655. Ctime: time.Now().Unix(),
  656. Mtime: time.Now().Unix(),
  657. Creater: 0,
  658. Modifier: 0,
  659. OrgId: item.Id,
  660. Status: 1,
  661. Type: 1,
  662. Number: 2,
  663. }
  664. service.AddSigleGoodType(goodTypes1)
  665. goodTypes2 := &models.GoodsType{
  666. TypeCode: "14000002",
  667. TypeName: "灌流器",
  668. Remark: "",
  669. Ctime: time.Now().Unix(),
  670. Mtime: time.Now().Unix(),
  671. Creater: 0,
  672. Modifier: 0,
  673. OrgId: item.Id,
  674. Status: 1,
  675. Type: 1,
  676. Number: 3,
  677. }
  678. service.AddSigleGoodType(goodTypes2)
  679. goodTypes3 := &models.GoodsType{
  680. TypeCode: "14000003",
  681. TypeName: "血路管",
  682. Remark: "",
  683. Ctime: time.Now().Unix(),
  684. Mtime: time.Now().Unix(),
  685. Creater: 0,
  686. Modifier: 0,
  687. OrgId: item.Id,
  688. Status: 1,
  689. Type: 1,
  690. Number: 4,
  691. }
  692. service.AddSigleGoodType(goodTypes3)
  693. goodTypes4 := &models.GoodsType{
  694. TypeCode: "14000004",
  695. TypeName: "血滤补液管",
  696. Remark: "",
  697. Ctime: time.Now().Unix(),
  698. Mtime: time.Now().Unix(),
  699. Creater: 0,
  700. Modifier: 0,
  701. OrgId: item.Id,
  702. Status: 1,
  703. Type: 1,
  704. Number: 5,
  705. }
  706. service.AddSigleGoodType(goodTypes4)
  707. goodTypes5 := &models.GoodsType{
  708. TypeCode: "14000005",
  709. TypeName: "注射器",
  710. Remark: "",
  711. Ctime: time.Now().Unix(),
  712. Mtime: time.Now().Unix(),
  713. Creater: 0,
  714. Modifier: 0,
  715. OrgId: item.Id,
  716. Status: 1,
  717. Type: 1,
  718. Number: 6,
  719. }
  720. service.AddSigleGoodType(goodTypes5)
  721. goodTypes6 := &models.GoodsType{
  722. TypeCode: "14000006",
  723. TypeName: "护理包(内瘘穿刺包)",
  724. Remark: "",
  725. Ctime: time.Now().Unix(),
  726. Mtime: time.Now().Unix(),
  727. Creater: 0,
  728. Modifier: 0,
  729. OrgId: item.Id,
  730. Status: 1,
  731. Type: 1,
  732. Number: 7,
  733. }
  734. service.AddSigleGoodType(goodTypes6)
  735. goodTypes7 := &models.GoodsType{
  736. TypeCode: "14000007",
  737. TypeName: "细菌过滤器",
  738. Remark: "",
  739. Ctime: time.Now().Unix(),
  740. Mtime: time.Now().Unix(),
  741. Creater: 0,
  742. Modifier: 0,
  743. OrgId: item.Id,
  744. Status: 1,
  745. Type: 1,
  746. Number: 8,
  747. }
  748. service.AddSigleGoodType(goodTypes7)
  749. goodTypes8 := &models.GoodsType{
  750. TypeCode: "14000008",
  751. TypeName: "血液透析干粉",
  752. Remark: "",
  753. Ctime: time.Now().Unix(),
  754. Mtime: time.Now().Unix(),
  755. Creater: 0,
  756. Modifier: 0,
  757. OrgId: item.Id,
  758. Status: 1,
  759. Type: 1,
  760. Number: 9,
  761. }
  762. service.AddSigleGoodType(goodTypes8)
  763. goodTypes9 := &models.GoodsType{
  764. TypeCode: "14000009",
  765. TypeName: "A液",
  766. Remark: "",
  767. Ctime: time.Now().Unix(),
  768. Mtime: time.Now().Unix(),
  769. Creater: 0,
  770. Modifier: 0,
  771. OrgId: item.Id,
  772. Status: 1,
  773. Type: 1,
  774. Number: 10,
  775. }
  776. service.AddSigleGoodType(goodTypes9)
  777. goodTypes10 := &models.GoodsType{
  778. TypeCode: "14000010",
  779. TypeName: "B液",
  780. Remark: "",
  781. Ctime: time.Now().Unix(),
  782. Mtime: time.Now().Unix(),
  783. Creater: 0,
  784. Modifier: 0,
  785. OrgId: item.Id,
  786. Status: 1,
  787. Type: 1,
  788. Number: 11,
  789. }
  790. service.AddSigleGoodType(goodTypes10)
  791. goodTypes11 := &models.GoodsType{
  792. TypeCode: "14000011",
  793. TypeName: "导管包",
  794. Remark: "",
  795. Ctime: time.Now().Unix(),
  796. Mtime: time.Now().Unix(),
  797. Creater: 0,
  798. Modifier: 0,
  799. OrgId: item.Id,
  800. Status: 1,
  801. Type: 1,
  802. Number: 12,
  803. }
  804. service.AddSigleGoodType(goodTypes11)
  805. goodTypes12 := &models.GoodsType{
  806. TypeCode: "14000012",
  807. TypeName: "血液透析导管",
  808. Remark: "",
  809. Ctime: time.Now().Unix(),
  810. Mtime: time.Now().Unix(),
  811. Creater: 0,
  812. Modifier: 0,
  813. OrgId: item.Id,
  814. Status: 1,
  815. Type: 1,
  816. Number: 13,
  817. }
  818. service.AddSigleGoodType(goodTypes12)
  819. }
  820. }