gobal_config_api_controller.go 54KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "bytes"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/jinzhu/gorm"
  11. "io/ioutil"
  12. "log"
  13. "os"
  14. "path"
  15. "reflect"
  16. "regexp"
  17. "runtime"
  18. "strconv"
  19. "strings"
  20. "time"
  21. "github.com/astaxie/beego"
  22. )
  23. type GobalConfigApiController struct {
  24. BaseAuthAPIController
  25. }
  26. func GobalConfigRegistRouters() {
  27. beego.Router("/api/stock/automaticreduce/isopen", &GobalConfigApiController{}, "post:PostStockConfig")
  28. beego.Router("/api/drugstock/automaticreduce/isopen", &GobalConfigApiController{}, "post:PostDrugStockConfig")
  29. beego.Router("/api/automaticreduce/get", &GobalConfigApiController{}, "get:GetConfig")
  30. beego.Router("/api/drugstockautomaticreduce/get", &GobalConfigApiController{}, "get:GetDrugStockConfig")
  31. beego.Router("/api/print/template/commit", &GobalConfigApiController{}, "post:PostPrintTemplateTwo")
  32. beego.Router("/api/print/template/get", &GobalConfigApiController{}, "get:GetPrintTemplate")
  33. beego.Router("/api/dataupload/config/commit", &GobalConfigApiController{}, "post:PostConfig")
  34. beego.Router("/api/dataupload/config/modify", &GobalConfigApiController{}, "post:ModifyConfig")
  35. beego.Router("/api/dataupload/config/get", &GobalConfigApiController{}, "get:GetDataUploadConfig")
  36. beego.Router("/api/dataupload/is_docking/get", &GobalConfigApiController{}, "get:GetDataUploadIsDocking")
  37. beego.Router("/api/adviceconfig/isopen", &GobalConfigApiController{}, "post:PostDoctorAdviceConfig")
  38. beego.Router("/api/adviceconfig/get", &GobalConfigApiController{}, "get:GetDoctorAdviceConfig")
  39. beego.Router("/api/advicetemplate/init/commit", &GobalConfigApiController{}, "post:PostInitAdviceTemplate")
  40. beego.Router("/api/advicetemplate/init/get", &GobalConfigApiController{}, "get:GetAdviceInitConfig")
  41. beego.Router("/api/systemprescription/commit", &GobalConfigApiController{}, "post:CreateSystemPrescription")
  42. beego.Router("/api/systemprescription/update", &GobalConfigApiController{}, "post:UpdateSystemPrescription")
  43. beego.Router("/api/systemprescription/all", &GobalConfigApiController{}, "get:GetAllSystemPrescription")
  44. beego.Router("/api/systemprescription/get", &GobalConfigApiController{}, "get:GetSystemPrescription")
  45. beego.Router("/api/advicetemplate/getprintinfo", &GobalConfigApiController{}, "post:GetPrintInfo")
  46. beego.Router("/api/public/orgs", &GobalConfigApiController{}, "get:GetOrgs")
  47. beego.Router("/api/org/change", &GobalConfigApiController{}, "post:ChangeOrg")
  48. beego.Router("/api/log/generate", &GobalConfigApiController{}, "get:GenerateLog")
  49. beego.Router("/api/patients/search", &GobalConfigApiController{}, "Post:GetPatientsByKeyWord")
  50. beego.Router("/api/xtconfig/get", &GobalConfigApiController{}, "get:GetXTHisConfig")
  51. beego.Router("/api/xtconfig/isopen", &GobalConfigApiController{}, "post:PostXTHisConfig")
  52. beego.Router("/api/isopen/init", &GobalConfigApiController{}, "get:GetAllIsOpenConfig")
  53. beego.Router("/api/passdetail/export", &GobalConfigApiController{}, "get:GetPassExportData")
  54. beego.Router("/api/consumedetail/export", &GobalConfigApiController{}, "get:GetExportData")
  55. beego.Router("/api/drugstock/getdrugindetail", &GobalConfigApiController{}, "get:GetDrugInDetail")
  56. beego.Router("/api/drugstock/getdrugcancelorder", &GobalConfigApiController{}, "get:GetDrugCancelOrder")
  57. beego.Router("/api/drugstock/getdrugoutdetail", &GobalConfigApiController{}, "get:GetDrugOutDetail")
  58. beego.Router("/api/drugstock/getdrugcanceldetail", &GobalConfigApiController{}, "get:GetDrugCancelDetail")
  59. beego.Router("/api/monitor/open", &GobalConfigApiController{}, "get:AddMonitorOpen")
  60. beego.Router("/api/monitor/getmonitorconfig", &GobalConfigApiController{}, "Get:GetMonitorConfig")
  61. beego.Router("/api/order/addorderconfig", &GobalConfigApiController{}, "Get:AddOrderConfig")
  62. beego.Router("/api/order/getorderconfig", &GobalConfigApiController{}, "Get:GetOrderConfig")
  63. beego.Router("/api/drugstock/getdrugautomaticlist", &GobalConfigApiController{}, "Get:GetDrugAutoMaticList")
  64. beego.Router("/api/drugstock/getdrugwarehouseorderinfo", &GobalConfigApiController{}, "Get:GetDrugWarehuseOrderInfo")
  65. }
  66. //provinces, _ := service.GetDistrictsByUpid(0)21
  67. func (c *GobalConfigApiController) PostStockConfig() {
  68. is_open, _ := c.GetInt64("is_open", 0)
  69. adminUserInfo := c.GetAdminUserInfo()
  70. org_id := adminUserInfo.CurrentOrgId
  71. config := models.GobalConfig{
  72. OrgId: org_id,
  73. IsOpen: is_open,
  74. Status: 1,
  75. CreateTime: time.Now().Unix(),
  76. UpdateTime: time.Now().Unix(),
  77. IsOpenRemind: 0,
  78. }
  79. errs, configs := service.FindAutomaticReduceRecordByOrgId(org_id)
  80. if errs == gorm.ErrRecordNotFound {
  81. err := service.CreateAutomaticReduceRecord(&config)
  82. if err != nil {
  83. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  84. return
  85. }
  86. } else if errs == nil {
  87. modifyConfig := models.GobalConfig{
  88. ID: configs.ID,
  89. OrgId: org_id,
  90. IsOpen: is_open,
  91. Status: 1,
  92. CreateTime: time.Now().Unix(),
  93. UpdateTime: time.Now().Unix(),
  94. IsOpenRemind: configs.IsOpenRemind,
  95. }
  96. err := service.UpdateAutomaticReduceRecord(&modifyConfig)
  97. if err != nil {
  98. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  99. return
  100. }
  101. }
  102. c.ServeSuccessJSON(map[string]interface{}{
  103. "is_open": is_open,
  104. })
  105. return
  106. }
  107. func (c *GobalConfigApiController) PostDrugStockConfig() {
  108. is_open, _ := c.GetInt64("is_open", 0)
  109. adminUserInfo := c.GetAdminUserInfo()
  110. org_id := adminUserInfo.CurrentOrgId
  111. config := models.DrugStockConfig{
  112. OrgId: org_id,
  113. IsOpen: is_open,
  114. Status: 1,
  115. CreateTime: time.Now().Unix(),
  116. UpdateTime: time.Now().Unix(),
  117. }
  118. errs, configs := service.FindDrugStockAutomaticReduceRecordByOrgId(org_id)
  119. if errs == gorm.ErrRecordNotFound {
  120. err := service.CreateDrugAutomaticReduceRecord(&config)
  121. if err != nil {
  122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  123. return
  124. }
  125. } else if errs == nil {
  126. modifyConfig := models.DrugStockConfig{
  127. ID: configs.ID,
  128. OrgId: org_id,
  129. IsOpen: is_open,
  130. Status: 1,
  131. CreateTime: time.Now().Unix(),
  132. UpdateTime: time.Now().Unix(),
  133. }
  134. err := service.UpdateDrugStockAutomaticReduceRecord(&modifyConfig)
  135. if err != nil {
  136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  137. return
  138. }
  139. }
  140. c.ServeSuccessJSON(map[string]interface{}{
  141. "is_open": is_open,
  142. })
  143. return
  144. }
  145. func (c *GobalConfigApiController) GetConfig() {
  146. adminUserInfo := c.GetAdminUserInfo()
  147. _, config := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  148. c.ServeSuccessJSON(map[string]interface{}{
  149. "config": config,
  150. })
  151. }
  152. func (c *GobalConfigApiController) GetDrugStockConfig() {
  153. adminUserInfo := c.GetAdminUserInfo()
  154. _, config := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  155. c.ServeSuccessJSON(map[string]interface{}{
  156. "config": config,
  157. })
  158. }
  159. func (c *GobalConfigApiController) PostPrintTemplate() {
  160. template_id, _ := c.GetInt64("template_id", 0)
  161. adminUserInfo := c.GetAdminUserInfo()
  162. org_id := adminUserInfo.CurrentOrgId
  163. template := models.GobalTemplate{
  164. OrgId: org_id,
  165. TemplateId: template_id,
  166. Status: 1,
  167. Ctime: time.Now().Unix(),
  168. Mtime: time.Now().Unix(),
  169. }
  170. errs, templates := service.FindPrintTemplateByOrgId(org_id)
  171. if errs == gorm.ErrRecordNotFound {
  172. err := service.CreatePrintTemplateRecord(&template)
  173. if err != nil {
  174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  175. return
  176. }
  177. } else if errs == nil {
  178. templates := models.GobalTemplate{
  179. ID: templates.ID,
  180. OrgId: org_id,
  181. TemplateId: template_id,
  182. Status: 1,
  183. Ctime: templates.Ctime,
  184. Mtime: time.Now().Unix(),
  185. }
  186. err := service.UpdatePrintTemplate(&templates)
  187. if err != nil {
  188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  189. return
  190. }
  191. }
  192. c.ServeSuccessJSON(map[string]interface{}{
  193. "template_id": template_id,
  194. })
  195. return
  196. }
  197. func (c *GobalConfigApiController) PostPrintTemplateTwo() {
  198. template_id, _ := c.GetInt64("template_id", 0)
  199. adminUserInfo := c.GetAdminUserInfo()
  200. org_id := adminUserInfo.CurrentOrgId
  201. template := models.GobalTemplate{
  202. OrgId: org_id,
  203. TemplateId: template_id,
  204. Status: 1,
  205. Ctime: time.Now().Unix(),
  206. Mtime: time.Now().Unix(),
  207. }
  208. errs, templates := service.FindPrintTemplateByOrgId(org_id)
  209. if errs == gorm.ErrRecordNotFound {
  210. err := service.CreatePrintTemplateRecord(&template)
  211. if err != nil {
  212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  213. return
  214. }
  215. if err == nil { //处理模版切换,显示配置处理逻辑
  216. //service.FindAllConfig
  217. //先将所有数据设置为显示
  218. updateErr := service.UpdateFiledConfig(adminUserInfo.CurrentOrgId)
  219. if updateErr == nil {
  220. //查出该模版对应显示配置字段中所有隐藏的字段
  221. _, config := service.FindAllHideFiledConfig(template_id)
  222. var fileds []string
  223. for _, item := range config {
  224. fileds = append(fileds, item.FiledName)
  225. }
  226. service.UpdateShowFieldConfig(adminUserInfo.CurrentOrgId, fileds)
  227. }
  228. }
  229. FiledList, _ := service.FindFiledByOrgId(adminUserInfo.CurrentOrgId)
  230. c.ServeSuccessJSON(map[string]interface{}{
  231. "template_id": template_id,
  232. "fileds": FiledList,
  233. })
  234. } else if errs == nil {
  235. templates := models.GobalTemplate{
  236. ID: templates.ID,
  237. OrgId: org_id,
  238. TemplateId: template_id,
  239. Status: 1,
  240. Ctime: templates.Ctime,
  241. Mtime: time.Now().Unix(),
  242. }
  243. err := service.UpdatePrintTemplate(&templates)
  244. if err != nil {
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  246. return
  247. }
  248. if err == nil { //处理模版切换,显示配置处理逻辑
  249. //service.FindAllConfig
  250. //先将所有数据设置为显示
  251. updateErr := service.UpdateFiledConfig(adminUserInfo.CurrentOrgId)
  252. if updateErr == nil {
  253. //查出该模版对应显示配置字段中所有隐藏的字段
  254. _, config := service.FindAllHideFiledConfig(template_id)
  255. var fileds []string
  256. for _, item := range config {
  257. fileds = append(fileds, item.FiledName)
  258. }
  259. service.UpdateShowFieldConfig(adminUserInfo.CurrentOrgId, fileds)
  260. }
  261. }
  262. FiledList, _ := service.FindFiledByOrgId(adminUserInfo.CurrentOrgId)
  263. c.ServeSuccessJSON(map[string]interface{}{
  264. "template_id": template_id,
  265. "fileds": FiledList,
  266. })
  267. return
  268. }
  269. }
  270. func (c *GobalConfigApiController) GetPrintTemplate() {
  271. adminUserInfo := c.GetAdminUserInfo()
  272. _, template := service.FindPrintTemplateByOrgId(adminUserInfo.CurrentOrgId)
  273. c.ServeSuccessJSON(map[string]interface{}{
  274. "template": template,
  275. })
  276. }
  277. func (c *GobalConfigApiController) PostConfig() {
  278. gateway_address := c.GetString("gateway_address")
  279. app_id := c.GetString("app_id")
  280. key := c.GetString("key")
  281. config_type, _ := c.GetInt64("config_type")
  282. time_type, _ := c.GetInt64("time_type")
  283. province, _ := c.GetInt64("province")
  284. city, _ := c.GetInt64("city")
  285. if config_type > 1 {
  286. _, err := service.GetDockingStatus(config_type, province, city)
  287. if err == gorm.ErrRecordNotFound {
  288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotDocking)
  289. return
  290. }
  291. }
  292. adminUserInfo := c.GetAdminUserInfo()
  293. org_id := adminUserInfo.CurrentOrgId
  294. config := &models.DataUploadConfig{
  295. OrgId: org_id,
  296. ProvinceId: province,
  297. CityId: city,
  298. GatewayAddress: gateway_address,
  299. AppId: app_id,
  300. Key: key,
  301. Status: 1,
  302. CreateTime: time.Now().Unix(),
  303. ModifyTime: time.Now().Unix(),
  304. TimeQuantum: time_type,
  305. ConfigType: config_type,
  306. }
  307. err := service.CreateConfigData(config)
  308. if err == nil {
  309. c.ServeSuccessJSON(map[string]interface{}{
  310. "config": config,
  311. })
  312. } else {
  313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  314. return
  315. }
  316. }
  317. func (c *GobalConfigApiController) GetDataUploadConfig() {
  318. config_type, _ := c.GetInt64("config_type")
  319. adminUserInfo := c.GetAdminUserInfo()
  320. org_id := adminUserInfo.CurrentOrgId
  321. config, err := service.GetConfigData(org_id, config_type)
  322. fmt.Println(err)
  323. if err == nil {
  324. c.ServeSuccessJSON(map[string]interface{}{
  325. "config": config,
  326. })
  327. } else {
  328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  329. return
  330. }
  331. }
  332. func (c *GobalConfigApiController) GetDataUploadIsDocking() {
  333. config_type, _ := c.GetInt64("config_type")
  334. province, _ := c.GetInt64("province")
  335. city, _ := c.GetInt64("city")
  336. config, err := service.GetDockingStatus(config_type, province, city)
  337. fmt.Println(config)
  338. fmt.Println(err)
  339. if err == gorm.ErrRecordNotFound {
  340. c.ServeSuccessJSON(map[string]interface{}{
  341. "is_docking": 2,
  342. })
  343. } else if err == nil {
  344. if config.ID > 0 {
  345. c.ServeSuccessJSON(map[string]interface{}{
  346. "is_docking": 1,
  347. })
  348. } else {
  349. c.ServeSuccessJSON(map[string]interface{}{
  350. "is_docking": 2,
  351. })
  352. }
  353. }
  354. }
  355. func (c *GobalConfigApiController) ModifyConfig() {
  356. id, _ := c.GetInt64("id")
  357. gateway_address := c.GetString("gateway_address")
  358. app_id := c.GetString("app_id")
  359. key := c.GetString("key")
  360. config_type, _ := c.GetInt64("config_type")
  361. time_type, _ := c.GetInt64("time_type")
  362. province, _ := c.GetInt64("province")
  363. city, _ := c.GetInt64("city")
  364. adminUserInfo := c.GetAdminUserInfo()
  365. org_id := adminUserInfo.CurrentOrgId
  366. if config_type > 1 {
  367. _, err := service.GetDockingStatus(config_type, province, city)
  368. if err == gorm.ErrRecordNotFound {
  369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotDocking)
  370. return
  371. }
  372. }
  373. tempConfig, _ := service.GetConfigDataById(id)
  374. config := &models.DataUploadConfig{
  375. ID: tempConfig.ID,
  376. OrgId: org_id,
  377. ProvinceId: province,
  378. CityId: city,
  379. GatewayAddress: gateway_address,
  380. AppId: app_id,
  381. Key: key,
  382. Status: 1,
  383. CreateTime: tempConfig.CreateTime,
  384. ModifyTime: time.Now().Unix(),
  385. TimeQuantum: time_type,
  386. ConfigType: config_type,
  387. }
  388. err := service.SaveConfigData(config)
  389. if err == nil {
  390. c.ServeSuccessJSON(map[string]interface{}{
  391. "config": config,
  392. })
  393. } else {
  394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  395. return
  396. }
  397. }
  398. func (c *GobalConfigApiController) PostDoctorAdviceConfig() {
  399. is_open_remind, _ := c.GetInt64("is_open_remind", 0)
  400. adminUserInfo := c.GetAdminUserInfo()
  401. org_id := adminUserInfo.CurrentOrgId
  402. config := models.DoctorAdviceConfig{
  403. UserOrgId: org_id,
  404. IsOpenRemind: is_open_remind,
  405. Status: 1,
  406. CreateTime: time.Now().Unix(),
  407. UpdateTime: time.Now().Unix(),
  408. }
  409. errs, configs := service.FindDoctorAdviceRecordByOrgId(org_id)
  410. if errs == gorm.ErrRecordNotFound {
  411. err := service.CreateDoctorAdviceRecord(&config)
  412. if err != nil {
  413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  414. return
  415. }
  416. } else if errs == nil {
  417. modifyConfig := models.DoctorAdviceConfig{
  418. ID: configs.ID,
  419. UserOrgId: org_id,
  420. Status: 1,
  421. CreateTime: time.Now().Unix(),
  422. UpdateTime: time.Now().Unix(),
  423. IsOpenRemind: is_open_remind,
  424. }
  425. err := service.UpdateDoctorAdviceRecord(&modifyConfig)
  426. if err != nil {
  427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  428. return
  429. }
  430. }
  431. c.ServeSuccessJSON(map[string]interface{}{
  432. "is_open_remind": is_open_remind,
  433. })
  434. return
  435. }
  436. func (c *GobalConfigApiController) GetDoctorAdviceConfig() {
  437. adminUserInfo := c.GetAdminUserInfo()
  438. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  439. c.ServeSuccessJSON(map[string]interface{}{
  440. "config": config,
  441. })
  442. }
  443. //SF6090214798525
  444. func (c *GobalConfigApiController) Load(filename string, v interface{}) {
  445. //ReadFile函数会读取文件的全部内容,并将结果以[]byte类型返回
  446. data, err := ioutil.ReadFile(filename)
  447. if err != nil {
  448. return
  449. }
  450. //读取的数据为json格式,需要进行解码
  451. err = json.Unmarshal(data, v)
  452. if err != nil {
  453. return
  454. }
  455. }
  456. type Config struct {
  457. Parent_template []*models.VMDoctorAdviceParentTemplate "json:parent_template"
  458. }
  459. func LoadConfig(dataFile string) *Config {
  460. var config Config
  461. _, filename, _, _ := runtime.Caller(1)
  462. datapath := path.Join(path.Dir(filename), dataFile)
  463. config_file, err := os.Open(datapath)
  464. if err != nil {
  465. emit("Failed to open config file '%s': %s\n", datapath, err)
  466. return &config
  467. }
  468. fi, _ := config_file.Stat()
  469. buffer := make([]byte, fi.Size())
  470. _, err = config_file.Read(buffer)
  471. buffer, err = StripComments(buffer) //去掉注释
  472. if err != nil {
  473. emit("Failed to strip comments from json: %s\n", err)
  474. return &config
  475. }
  476. buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
  477. err = json.Unmarshal(buffer, &config) //解析json格式数据
  478. if err != nil {
  479. emit("Failed unmarshalling json: %s\n", err)
  480. return &config
  481. }
  482. return &config
  483. }
  484. func StripComments(data []byte) ([]byte, error) {
  485. data = bytes.Replace(data, []byte("\r"), []byte(""), 0) // Windows
  486. lines := bytes.Split(data, []byte("\n")) //split to muli lines
  487. filtered := make([][]byte, 0)
  488. for _, line := range lines {
  489. match, err := regexp.Match(`^\s*#`, line)
  490. if err != nil {
  491. return nil, err
  492. }
  493. if !match {
  494. filtered = append(filtered, line)
  495. }
  496. }
  497. return bytes.Join(filtered, []byte("\n")), nil
  498. }
  499. func emit(msgfmt string, args ...interface{}) {
  500. log.Printf(msgfmt, args...)
  501. }
  502. func (c *GobalConfigApiController) GetAdviceInitConfig() {
  503. adminUserInfo := c.GetAdminUserInfo()
  504. advice_init, _ := service.FindAdviceInitConfig(adminUserInfo.CurrentOrgId)
  505. c.ServeSuccessJSON(map[string]interface{}{
  506. "advice_init": advice_init,
  507. })
  508. }
  509. func (c *GobalConfigApiController) PostInitAdviceTemplate() {
  510. is_init, _ := c.GetInt64("is_init")
  511. adminUserInfo := c.GetAdminUserInfo()
  512. adviceInit := &models.AdviceInit{
  513. UserOrgId: adminUserInfo.CurrentOrgId,
  514. CreateTime: time.Now().Unix(),
  515. UpdateTime: time.Now().Unix(),
  516. Status: 1,
  517. IsInit: is_init,
  518. }
  519. adviceParentTemplate := LoadConfig("./advice_template.json").Parent_template
  520. for _, item := range adviceParentTemplate {
  521. parentTemplate := &models.DoctorAdviceParentTemplate{
  522. OrgId: adminUserInfo.CurrentOrgId,
  523. Name: item.Name,
  524. Status: 1,
  525. CreatedTime: time.Now().Unix(),
  526. UpdatedTime: time.Now().Unix(),
  527. AdviceType: item.AdviceType,
  528. }
  529. createErr := service.CreateDoctorParentTemplate(parentTemplate)
  530. fmt.Println(parentTemplate.ID)
  531. if createErr == nil {
  532. for _, adviceTemplateItem := range item.DoctorAdviceTemplate {
  533. adviceTeplate := &models.DoctorAdviceTemplate{
  534. OrgId: adminUserInfo.CurrentOrgId,
  535. AdviceName: adviceTemplateItem.AdviceName,
  536. AdviceDesc: adviceTemplateItem.AdviceDesc,
  537. SingleDose: adviceTemplateItem.SingleDose,
  538. SingleDoseUnit: adviceTemplateItem.SingleDoseUnit,
  539. PrescribingNumber: adviceTemplateItem.PrescribingNumber,
  540. PrescribingNumberUnit: adviceTemplateItem.PrescribingNumberUnit,
  541. DeliveryWay: adviceTemplateItem.DeliveryWay,
  542. ExecutionFrequency: adviceTemplateItem.ExecutionFrequency,
  543. AdviceDoctor: adviceTemplateItem.AdviceDoctor,
  544. Status: 1,
  545. CreatedTime: time.Now().Unix(),
  546. UpdatedTime: time.Now().Unix(),
  547. TemplateId: parentTemplate.ID,
  548. DrugSpec: adviceTemplateItem.DrugSpec,
  549. DrugSpecUnit: adviceTemplateItem.DrugSpecUnit,
  550. ParentId: adviceTemplateItem.ParentId,
  551. AdviceType: adviceTemplateItem.AdviceType,
  552. DayCount: adviceTemplateItem.DayCount,
  553. WeekDays: adviceTemplateItem.WeekDays,
  554. FrequencyType: adviceTemplateItem.FrequencyType,
  555. }
  556. createErr := service.CreateDoctorTemplate(adviceTeplate)
  557. if createErr == nil {
  558. for _, childItem := range adviceTemplateItem.SubDoctorAdviceTemplate {
  559. adviceTeplate := &models.DoctorAdviceTemplate{
  560. OrgId: adminUserInfo.CurrentOrgId,
  561. AdviceName: childItem.AdviceName,
  562. AdviceDesc: childItem.AdviceDesc,
  563. SingleDose: childItem.SingleDose,
  564. SingleDoseUnit: childItem.SingleDoseUnit,
  565. PrescribingNumber: childItem.PrescribingNumber,
  566. PrescribingNumberUnit: childItem.PrescribingNumberUnit,
  567. DeliveryWay: childItem.DeliveryWay,
  568. ExecutionFrequency: childItem.ExecutionFrequency,
  569. AdviceDoctor: childItem.AdviceDoctor,
  570. Status: 1,
  571. CreatedTime: time.Now().Unix(),
  572. UpdatedTime: time.Now().Unix(),
  573. TemplateId: parentTemplate.ID,
  574. DrugSpec: childItem.DrugSpec,
  575. DrugSpecUnit: childItem.DrugSpecUnit,
  576. ParentId: adviceTeplate.ID,
  577. AdviceType: childItem.AdviceType,
  578. DayCount: childItem.DayCount,
  579. WeekDays: childItem.WeekDays,
  580. FrequencyType: childItem.FrequencyType,
  581. }
  582. service.CreateDoctorTemplate(adviceTeplate)
  583. }
  584. }
  585. }
  586. }
  587. }
  588. err := service.CreateAdviceInitConfig(adviceInit)
  589. if err == nil {
  590. c.ServeSuccessJSON(map[string]interface{}{
  591. "init_config": adviceInit,
  592. })
  593. } else {
  594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  595. return
  596. }
  597. }
  598. func (c *GobalConfigApiController) CreateSystemPrescription() {
  599. adminUserInfo := c.GetAdminUserInfo()
  600. var solution models.SystemPrescription
  601. code := defaultSystemSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  602. if code > 0 {
  603. c.ServeFailJSONWithSGJErrorCode(code)
  604. return
  605. }
  606. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  607. solution.Doctor = adminUserInfo.AdminUser.Id
  608. solution.Status = 1
  609. solution.CreatedTime = time.Now().Unix()
  610. solution.UserOrgId = adminUserInfo.CurrentOrgId
  611. solution.UpdatedTime = time.Now().Unix()
  612. err := service.CreateSystemDialysisSolution(&solution)
  613. if err != nil {
  614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  615. return
  616. }
  617. prescriptions, _ := service.FindAllSystemPrescription(adminUserInfo.CurrentOrgId)
  618. c.ServeSuccessJSON(map[string]interface{}{
  619. "prescription": solution,
  620. "prescriptions": prescriptions,
  621. })
  622. return
  623. }
  624. func (c *GobalConfigApiController) UpdateSystemPrescription() {
  625. id, _ := c.GetInt64("id", 0)
  626. if id <= 0 {
  627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  628. return
  629. }
  630. adminUserInfo := c.GetAdminUserInfo()
  631. solution, _ := service.FindSystemDialysisSolution(adminUserInfo.CurrentOrgId, id)
  632. if solution.ID == 0 {
  633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  634. return
  635. }
  636. code := defaultSystemSolutionFormData(&solution, c.Ctx.Input.RequestBody, "edit")
  637. if code > 0 {
  638. c.ServeFailJSONWithSGJErrorCode(code)
  639. return
  640. }
  641. solution.UpdatedTime = time.Now().Unix()
  642. solution.Doctor = adminUserInfo.AdminUser.Id
  643. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  644. err := service.UpdateSystemDialysisSolution(&solution)
  645. if err != nil {
  646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  647. return
  648. }
  649. c.ServeSuccessJSON(map[string]interface{}{
  650. "msg": "ok",
  651. "prescription": solution,
  652. })
  653. return
  654. }
  655. func (c *GobalConfigApiController) GetAllSystemPrescription() {
  656. adminUserInfo := c.GetAdminUserInfo()
  657. prescriptions, _ := service.FindAllSystemPrescription(adminUserInfo.CurrentOrgId)
  658. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  659. c.ServeSuccessJSON(map[string]interface{}{
  660. "prescriptions": prescriptions,
  661. "stockType": stockType,
  662. })
  663. }
  664. func (c *GobalConfigApiController) GetSystemPrescription() {
  665. adminUserInfo := c.GetAdminUserInfo()
  666. id, _ := c.GetInt64("id", 0)
  667. prescription, _ := service.FindSystemDialysisPrescriptionByMode(adminUserInfo.CurrentOrgId, id)
  668. c.ServeSuccessJSON(map[string]interface{}{
  669. "prescription": prescription,
  670. })
  671. }
  672. func defaultSystemSolutionFormData(solution *models.SystemPrescription, data []byte, method string) (code int) {
  673. dataBody := make(map[string]interface{}, 0)
  674. err := json.Unmarshal(data, &dataBody)
  675. utils.InfoLog(string(data))
  676. if err != nil {
  677. utils.ErrorLog(err.Error())
  678. code = enums.ErrorCodeParamWrong
  679. return
  680. }
  681. if method == "create" {
  682. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  683. utils.ErrorLog("mode")
  684. code = enums.ErrorCodeParamWrong
  685. return
  686. }
  687. mode := int64(dataBody["mode"].(float64))
  688. if mode <= 0 {
  689. utils.ErrorLog("mode <= 0")
  690. code = enums.ErrorCodeParamWrong
  691. return
  692. }
  693. solution.ModeId = mode
  694. }
  695. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  696. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  697. solution.DialysisDuration = dialysisDuration
  698. }
  699. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  700. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  701. solution.TargetUltrafiltration = targetUltrafiltration
  702. }
  703. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  704. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  705. solution.DialysateFormulation = dialysateFormulation
  706. }
  707. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  708. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  709. solution.DialysisDurationHour = int64(dialysisDurationHour)
  710. }
  711. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  712. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  713. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  714. }
  715. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  716. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  717. solution.HemodialysisMachine = hemodialysisMachine
  718. }
  719. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  720. dialyzer := int64(dataBody["dialyzer"].(float64))
  721. solution.Dialyzer = dialyzer
  722. }
  723. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  724. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  725. solution.PerfusionApparatus = perfusionApparatus
  726. }
  727. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  728. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  729. solution.BloodFlowVolume = bloodFlowVolume
  730. }
  731. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  732. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  733. solution.Dewater = dewater
  734. }
  735. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  736. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  737. solution.DisplaceLiqui = displaceLiqui
  738. }
  739. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  740. replacementWay := int64(dataBody["replacement_way"].(float64))
  741. solution.ReplacementWay = replacementWay
  742. }
  743. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  744. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  745. solution.Anticoagulant = anticoagulant
  746. }
  747. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  748. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  749. solution.AnticoagulantShouji = anticoagulantShouji
  750. }
  751. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  752. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  753. solution.AnticoagulantWeichi = anticoagulantWeichi
  754. }
  755. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  756. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  757. solution.AnticoagulantZongliang = anticoagulantZongliang
  758. }
  759. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  760. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  761. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  762. }
  763. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  764. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  765. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  766. }
  767. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  768. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  769. solution.Kalium = kalium
  770. }
  771. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  772. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  773. solution.Sodium = sodium
  774. }
  775. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  776. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  777. solution.Calcium = calcium
  778. }
  779. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  780. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  781. solution.Bicarbonate = bicarbonate
  782. }
  783. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  784. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  785. solution.Glucose = glucose
  786. }
  787. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  788. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  789. // solution.DryWeight = dryWeight
  790. // }
  791. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  792. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  793. solution.DialysateFlow = dialysateFlow
  794. }
  795. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  796. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  797. solution.DialysateTemperature = dialysateTemperature
  798. }
  799. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  800. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  801. solution.Conductivity = conductivity
  802. }
  803. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  804. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  805. solution.ReplacementTotal = replacementTotal
  806. }
  807. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  808. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  809. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  810. }
  811. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  812. body_fluid := int64(dataBody["body_fluid"].(float64))
  813. solution.BodyFluid = body_fluid
  814. }
  815. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  816. body_fluid_other := dataBody["body_fluid_other"].(string)
  817. solution.BodyFluidOther = body_fluid_other
  818. }
  819. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  820. special_medicine := int64(dataBody["special_medicine"].(float64))
  821. solution.SpecialMedicine = special_medicine
  822. }
  823. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  824. special_medicine_other := dataBody["special_medicine_other"].(string)
  825. solution.SpecialMedicineOther = special_medicine_other
  826. }
  827. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  828. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  829. solution.DisplaceLiquiPart = displace_liqui_part
  830. }
  831. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  832. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  833. solution.DisplaceLiquiValue = displace_liqui_value
  834. }
  835. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  836. blood_access := int64(dataBody["blood_access"].(float64))
  837. solution.BloodAccess = blood_access
  838. }
  839. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  840. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  841. solution.Ultrafiltration = ultrafiltration
  842. }
  843. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  844. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  845. solution.TargetKtv = target_ktv
  846. }
  847. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  848. remark := dataBody["remark"].(string)
  849. solution.Remark = remark
  850. }
  851. if dataBody["dialysis_dialyszers"] != nil && reflect.TypeOf(dataBody["dialysis_dialyszers"]).String() == "string" {
  852. dialysisDialyszers := dataBody["dialysis_dialyszers"].(string)
  853. fmt.Println("dialysisDialysis22222222222", dialysisDialyszers)
  854. solution.DialysisDialyszers = dialysisDialyszers
  855. }
  856. if dataBody["dialysis_irrigation"] != nil && reflect.TypeOf(dataBody["dialysis_irrigation"]).String() == "string" {
  857. dialysisIrrigation := dataBody["dialysis_irrigation"].(string)
  858. solution.DialysisIrrigation = dialysisIrrigation
  859. }
  860. return
  861. }
  862. func (c *GobalConfigApiController) GetPrintInfo() {
  863. adminUserInfo := c.GetAdminUserInfo()
  864. OrgID := adminUserInfo.CurrentOrgId
  865. dataBody := make(map[string]interface{}, 0)
  866. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  867. idsInters := dataBody["ids"].([]interface{})
  868. if len(idsInters) == 0 {
  869. if err != nil {
  870. c.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
  871. return
  872. }
  873. }
  874. ids := make([]int64, 0)
  875. for _, idsInter := range idsInters {
  876. id := int64(idsInter.(float64))
  877. ids = append(ids, id)
  878. }
  879. getPrint, err := service.GetPrint(ids, OrgID)
  880. c.ServeSuccessJSON(map[string]interface{}{
  881. "doctoradvice": getPrint,
  882. })
  883. }
  884. func (c *GobalConfigApiController) GetOrgs() {
  885. adminUserInfo := c.GetAdminUserInfo()
  886. //获取当前人姓名
  887. var id = adminUserInfo.AdminUser.Id
  888. orgId := adminUserInfo.CurrentOrgId
  889. var orgs []*models.Org
  890. adminUser, err := service.GetHomeData(adminUserInfo.AdminUser.Id)
  891. creator, err := service.GetCreator(id, orgId)
  892. admin, err := service.GetSuperAdmin(id)
  893. if err != nil {
  894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  895. return
  896. }
  897. for _, item := range adminUser.Org {
  898. orgs = append(orgs, item)
  899. }
  900. for _, item := range adminUser.VMApp_Role {
  901. for _, subItem := range item.Org {
  902. orgs = append(orgs, subItem)
  903. }
  904. }
  905. orgs = RemoveRepeatedOrgElement(orgs)
  906. c.ServeSuccessJSON(map[string]interface{}{
  907. "orgs": orgs,
  908. "adminUser": adminUser,
  909. "creator": creator,
  910. "admin": admin,
  911. })
  912. }
  913. func (this *GobalConfigApiController) ChangeOrg() {
  914. org_id, _ := this.GetInt64("org_id")
  915. adminUserInfo := this.GetAdminUserInfo()
  916. tempOrg, err := service.GetOrgById(org_id)
  917. if err != nil {
  918. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  919. return
  920. }
  921. if tempOrg == nil {
  922. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrgNoExist)
  923. return
  924. }
  925. mobile := adminUserInfo.AdminUser.Mobile
  926. // 只取最近被创建的 admin_role
  927. adminUser, getAdminErr := service.GetValidAdminUserByMobileReturnErr(mobile) //账号信息唯一值
  928. if getAdminErr != nil {
  929. utils.ErrorLog("获取管理员失败:%v", getAdminErr)
  930. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  931. this.ServeJSON()
  932. return
  933. } else if adminUser == nil {
  934. utils.ErrorLog("查找不到 mobile = %v 的用户", mobile)
  935. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeAccountOrPasswordWrong)
  936. this.ServeJSON()
  937. return
  938. } else {
  939. adminUserInfo.CurrentOrgId = tempOrg.Id
  940. orgApp, _ := service.GetOrgApp(tempOrg.Id, 3)
  941. subscibe, _ := service.GetOrgSubscibe(tempOrg.Id)
  942. adminUserInfo.CurrentAppId = orgApp.Id
  943. appRole, _ := service.GetAppRole(tempOrg.Id, orgApp.Id, adminUserInfo.AdminUser.Id)
  944. var FiledList []*models.FiledConfig
  945. FiledList, _ = service.FindFiledByOrgId(tempOrg.Id)
  946. if len(FiledList) == 0 {
  947. err := service.BatchInsertFiledConfig(tempOrg.Id)
  948. if err == nil {
  949. FiledList, _ = service.FindFiledByOrgId(tempOrg.Id)
  950. } else {
  951. utils.ErrorLog("字段批量插入失败:%v", err)
  952. }
  953. }
  954. //产寻该机构是否有收缩压和舒张压
  955. pressure, err := service.GetDefaultSystolicPressure(tempOrg.Id)
  956. fmt.Println(err)
  957. if len(pressure) == 0 {
  958. err = service.BathInsertQualityControlTwo(tempOrg.Id)
  959. } else {
  960. utils.ErrorLog("字段批量插入失败:%v", err)
  961. }
  962. major, err := service.GetInspectionMajor(tempOrg.Id)
  963. if len(major) == 0 {
  964. QualityeList, err := service.FindQualityByOrgId(tempOrg.Id)
  965. if len(QualityeList) == 0 {
  966. err = service.BatchInsertQualityControl(tempOrg.Id)
  967. } else {
  968. utils.ErrorLog("字段批量插入失败:%v", err)
  969. }
  970. InspectionList, err := service.FindeInspectionByOrgId(tempOrg.Id)
  971. if len(InspectionList) == 0 {
  972. err = service.BatchInspectionConfiguration(tempOrg.Id)
  973. } else {
  974. utils.ErrorLog("字段批量插入失败:%v", err)
  975. }
  976. } else {
  977. utils.ErrorLog("字段批量插入失败:%v", err)
  978. }
  979. //查询该机构是否存在医护排班
  980. _, errcode := service.GetDoctorScheduleByOrgId(tempOrg.Id)
  981. //如果没有就插入
  982. if errcode == gorm.ErrRecordNotFound {
  983. err = service.BatchInsertDoctorSchedule(tempOrg.Id)
  984. } else {
  985. utils.ErrorLog("医护排班默认数据插入失败:%v", err)
  986. }
  987. var didRegistedForSCRM bool = false
  988. var didRegistedForCDM bool = false
  989. var didRegistedForMall bool = false
  990. var curAppUrlfors []string
  991. var pruviews []*models.Purview
  992. if len(curAppUrlfors) == 0 {
  993. if adminUser.Id == tempOrg.Creator {
  994. urlfors_xt, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(3)
  995. urlfors_cdm, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(4)
  996. urlfors_scrm, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(6)
  997. urlfors_mall, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(7)
  998. curAppUrlfors = append(curAppUrlfors, urlfors_xt...)
  999. curAppUrlfors = append(curAppUrlfors, urlfors_scrm...)
  1000. curAppUrlfors = append(curAppUrlfors, urlfors_cdm...)
  1001. curAppUrlfors = append(curAppUrlfors, urlfors_mall...)
  1002. didRegistedForSCRM = true
  1003. didRegistedForCDM = true
  1004. didRegistedForMall = true
  1005. } else {
  1006. appRole, _ := service.FindAdminUserIDA(appRole.Id)
  1007. if appRole.Id > 0 && len(appRole.RoleIds) > 0 {
  1008. role_arr := strings.Split(appRole.RoleIds, ",")
  1009. var ids string
  1010. for _, role_id := range role_arr {
  1011. id, _ := strconv.ParseInt(role_id, 10, 64)
  1012. purview_ids, _ := service.GetRolePurviewIds(id)
  1013. if len(ids) == 0 {
  1014. ids = purview_ids
  1015. } else {
  1016. ids = ids + "," + purview_ids
  1017. }
  1018. }
  1019. if len(ids) != 0 {
  1020. pruviews, _ = service.GetPurviewById(ids)
  1021. for _, item := range pruviews {
  1022. if item.Module == 3 && item.Parentid > 0 {
  1023. fmt.Println(item.Urlfor)
  1024. curAppUrlfors = append(curAppUrlfors, item.Urlfor)
  1025. }
  1026. }
  1027. } else {
  1028. curAppUrlfors = append(curAppUrlfors, "")
  1029. }
  1030. } else {
  1031. curAppUrlfors = append(curAppUrlfors, "")
  1032. }
  1033. for _, item := range pruviews {
  1034. if item.Module == 6 {
  1035. didRegistedForSCRM = true
  1036. }
  1037. if item.Module == 4 {
  1038. didRegistedForCDM = true
  1039. }
  1040. if item.Module == 7 {
  1041. didRegistedForMall = true
  1042. }
  1043. }
  1044. }
  1045. }
  1046. userInfo := map[string]interface{}{
  1047. "id": adminUser.Id,
  1048. "mobile": adminUser.Mobile,
  1049. "user_name": appRole.UserName,
  1050. "avatar": appRole.Avatar,
  1051. "intro": appRole.Intro,
  1052. "user_type": appRole.UserType,
  1053. "user_title": appRole.UserTitle,
  1054. }
  1055. org := map[string]interface{}{
  1056. "id": tempOrg.Id,
  1057. "org_name": tempOrg.OrgName,
  1058. "org_short_name": tempOrg.OrgShortName,
  1059. "org_intro": tempOrg.OrgIntroduction,
  1060. "org_logo": tempOrg.OrgLogo,
  1061. "province": tempOrg.Province,
  1062. "city": tempOrg.City,
  1063. "district": tempOrg.District,
  1064. "address": tempOrg.Address,
  1065. }
  1066. tempInfo, _ := service.GetOrgInfoTemplate(tempOrg.Id)
  1067. template_info := map[string]interface{}{
  1068. "id": tempInfo.ID,
  1069. "org_id": tempInfo.OrgId,
  1070. "template_id": tempInfo.TemplateId,
  1071. }
  1072. if tempOrg != nil && appRole != nil {
  1073. // 插入一条登录记录
  1074. ip := this.GetString("ip")
  1075. loginLog := &models.AdminUserLoginLog{
  1076. AdminUserId: adminUser.Id,
  1077. OrgId: tempOrg.Id,
  1078. AppId: appRole.AppId,
  1079. IP: ip,
  1080. OperateType: 3,
  1081. AppType: 3,
  1082. CreateTime: time.Now().Unix(),
  1083. }
  1084. if insertErr := service.InsertLoginLog(loginLog); insertErr != nil {
  1085. utils.ErrorLog("为手机号为%v的用户插入一条登录记录失败:%v", mobile, insertErr)
  1086. }
  1087. }
  1088. this.SetSession("admin_user_info", adminUserInfo)
  1089. this.ServeSuccessJSON(map[string]interface{}{
  1090. "user": userInfo,
  1091. "org": org,
  1092. "urlfors": curAppUrlfors,
  1093. "current_org_id": adminUserInfo.CurrentOrgId,
  1094. "current_app_id": adminUserInfo.CurrentAppId,
  1095. "subscibe": subscibe,
  1096. "template_info": template_info,
  1097. "fileds": FiledList,
  1098. "scrm_role_exist": didRegistedForSCRM,
  1099. "cdm_role_exist": didRegistedForCDM,
  1100. "mall_role_exist": didRegistedForMall,
  1101. })
  1102. }
  1103. }
  1104. func RemoveRepeatedOrgElement(orgs []*models.Org) (newOrgs []*models.Org) {
  1105. newOrgs = make([]*models.Org, 0)
  1106. for i := 0; i < len(orgs); i++ {
  1107. repeat := false
  1108. for j := i + 1; j < len(orgs); j++ {
  1109. if orgs[i].Id == orgs[j].Id {
  1110. repeat = true
  1111. break
  1112. }
  1113. }
  1114. if !repeat {
  1115. newOrgs = append(newOrgs, orgs[i])
  1116. }
  1117. }
  1118. return
  1119. }
  1120. func (this *GobalConfigApiController) GenerateLog() {
  1121. log_type, _ := this.GetInt64("log_type", 0)
  1122. logs, err := service.GetExportLogByType(this.GetAdminUserInfo().CurrentOrgId, log_type)
  1123. if err != nil {
  1124. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1125. return
  1126. }
  1127. this.ServeSuccessJSON(map[string]interface{}{
  1128. "logs": logs,
  1129. })
  1130. }
  1131. func (this *GobalConfigApiController) GetPatientsByKeyWord() {
  1132. keyWord := this.GetString("keyword")
  1133. adminUserInfo := this.GetAdminUserInfo()
  1134. patient, err := service.GetPatientsByKey(adminUserInfo.CurrentOrgId, keyWord)
  1135. if err != nil {
  1136. utils.ErrorLog(err.Error())
  1137. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1138. return
  1139. }
  1140. this.ServeSuccessJSON(map[string]interface{}{
  1141. "patient": patient,
  1142. })
  1143. }
  1144. func (c *GobalConfigApiController) PostXTHisConfig() {
  1145. is_open, _ := c.GetBool("is_open", false)
  1146. adminUserInfo := c.GetAdminUserInfo()
  1147. org_id := adminUserInfo.CurrentOrgId
  1148. isOpen := 0
  1149. if is_open {
  1150. isOpen = 1
  1151. } else {
  1152. isOpen = 2
  1153. }
  1154. config := models.XtHisConfig{
  1155. UserOrgId: org_id,
  1156. IsOpen: int64(isOpen),
  1157. Status: 1,
  1158. Ctime: time.Now().Unix(),
  1159. Mtime: time.Now().Unix(),
  1160. }
  1161. errs, configs := service.FindXTHisRecordByOrgId(org_id)
  1162. if errs == gorm.ErrRecordNotFound {
  1163. err := service.CreateXTHisRecord(&config)
  1164. if err != nil {
  1165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1166. return
  1167. }
  1168. } else if errs == nil {
  1169. modifyConfig := models.XtHisConfig{
  1170. ID: configs.ID,
  1171. UserOrgId: org_id,
  1172. Status: 1,
  1173. Ctime: time.Now().Unix(),
  1174. Mtime: time.Now().Unix(),
  1175. IsOpen: int64(isOpen),
  1176. }
  1177. err := service.UpdateXTHisRecord(&modifyConfig)
  1178. if err != nil {
  1179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1180. return
  1181. }
  1182. }
  1183. c.ServeSuccessJSON(map[string]interface{}{
  1184. "is_open": is_open,
  1185. })
  1186. return
  1187. }
  1188. func (c *GobalConfigApiController) GetXTHisConfig() {
  1189. adminUserInfo := c.GetAdminUserInfo()
  1190. _, config := service.FindXTHisRecordByOrgId(adminUserInfo.CurrentOrgId)
  1191. c.ServeSuccessJSON(map[string]interface{}{
  1192. "config": config,
  1193. })
  1194. }
  1195. func (c *GobalConfigApiController) GetAllIsOpenConfig() {
  1196. adminUserInfo := c.GetAdminUserInfo()
  1197. _, config := service.FindXTHisRecordByOrgId(adminUserInfo.CurrentOrgId)
  1198. c.ServeSuccessJSON(map[string]interface{}{
  1199. "is_open_xt_his": config.IsOpen,
  1200. })
  1201. }
  1202. func (c *GobalConfigApiController) GetPassExportData() {
  1203. }
  1204. func (c *GobalConfigApiController) GetExportData() {
  1205. start_time := c.GetString("start_time")
  1206. end_time := c.GetString("end_time")
  1207. timeLayout := "2006-01-02"
  1208. loc, _ := time.LoadLocation("Local")
  1209. var startTime int64
  1210. if len(start_time) > 0 {
  1211. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1212. if err != nil {
  1213. fmt.Println(err)
  1214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1215. return
  1216. }
  1217. startTime = theTime.Unix()
  1218. }
  1219. var endTime int64
  1220. if len(end_time) > 0 {
  1221. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1222. if err != nil {
  1223. utils.ErrorLog(err.Error())
  1224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1225. return
  1226. }
  1227. endTime = theTime.Unix()
  1228. }
  1229. adminInfo := c.GetAdminUserInfo()
  1230. order, _ := service.GetExportHisOrderList(adminInfo.CurrentOrgId, startTime, endTime)
  1231. c.ServeSuccessJSON(map[string]interface{}{
  1232. "order": order,
  1233. })
  1234. }
  1235. func (c *GobalConfigApiController) GetDrugInDetail() {
  1236. start_time := c.GetString("start_time")
  1237. end_time := c.GetString("end_time")
  1238. timeLayout := "2006-01-02"
  1239. loc, _ := time.LoadLocation("Local")
  1240. var startTime int64
  1241. if len(start_time) > 0 {
  1242. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1243. if err != nil {
  1244. fmt.Println(err)
  1245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1246. return
  1247. }
  1248. startTime = theTime.Unix()
  1249. }
  1250. var endTime int64
  1251. if len(end_time) > 0 {
  1252. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1253. if err != nil {
  1254. utils.ErrorLog(err.Error())
  1255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1256. return
  1257. }
  1258. endTime = theTime.Unix()
  1259. }
  1260. adminInfo := c.GetAdminUserInfo()
  1261. order_type, _ := c.GetInt64("order_type")
  1262. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1263. keyword := c.GetString("keyword")
  1264. page, _ := c.GetInt64("page")
  1265. limit, _ := c.GetInt64("limit")
  1266. detail, total, err := service.GetDrugInOrderDetail(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit)
  1267. if err != nil {
  1268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1269. return
  1270. }
  1271. c.ServeSuccessJSON(map[string]interface{}{
  1272. "detail": detail,
  1273. "total": total,
  1274. })
  1275. }
  1276. func (c *GobalConfigApiController) GetDrugCancelOrder() {
  1277. start_time := c.GetString("start_time")
  1278. end_time := c.GetString("end_time")
  1279. timeLayout := "2006-01-02"
  1280. loc, _ := time.LoadLocation("Local")
  1281. var startTime int64
  1282. if len(start_time) > 0 {
  1283. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1284. if err != nil {
  1285. fmt.Println(err)
  1286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1287. return
  1288. }
  1289. startTime = theTime.Unix()
  1290. }
  1291. var endTime int64
  1292. if len(end_time) > 0 {
  1293. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1294. if err != nil {
  1295. utils.ErrorLog(err.Error())
  1296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1297. return
  1298. }
  1299. endTime = theTime.Unix()
  1300. }
  1301. adminInfo := c.GetAdminUserInfo()
  1302. order_type, _ := c.GetInt64("order_type")
  1303. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1304. keyword := c.GetString("keyword")
  1305. limit, _ := c.GetInt64("limit")
  1306. page, _ := c.GetInt64("page")
  1307. order, total, err := service.GetDrugReturnOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, limit, page)
  1308. if err != nil {
  1309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1310. return
  1311. }
  1312. c.ServeSuccessJSON(map[string]interface{}{
  1313. "order": order,
  1314. "total": total,
  1315. })
  1316. }
  1317. func (c *GobalConfigApiController) GetDrugOutDetail() {
  1318. start_time := c.GetString("start_time")
  1319. end_time := c.GetString("end_time")
  1320. timeLayout := "2006-01-02"
  1321. loc, _ := time.LoadLocation("Local")
  1322. var startTime int64
  1323. if len(start_time) > 0 {
  1324. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1325. if err != nil {
  1326. fmt.Println(err)
  1327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1328. return
  1329. }
  1330. startTime = theTime.Unix()
  1331. }
  1332. var endTime int64
  1333. if len(end_time) > 0 {
  1334. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1335. if err != nil {
  1336. utils.ErrorLog(err.Error())
  1337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1338. return
  1339. }
  1340. endTime = theTime.Unix()
  1341. }
  1342. adminInfo := c.GetAdminUserInfo()
  1343. order_type, _ := c.GetInt64("order_type")
  1344. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1345. keyword := c.GetString("keyword")
  1346. limit, _ := c.GetInt64("limit")
  1347. page, _ := c.GetInt64("page")
  1348. order, total, err := service.GetDrugOutOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit)
  1349. if err != nil {
  1350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1351. return
  1352. }
  1353. c.ServeSuccessJSON(map[string]interface{}{
  1354. "order": order,
  1355. "total": total,
  1356. })
  1357. }
  1358. func (c *GobalConfigApiController) GetDrugCancelDetail() {
  1359. start_time := c.GetString("start_time")
  1360. end_time := c.GetString("end_time")
  1361. timeLayout := "2006-01-02"
  1362. loc, _ := time.LoadLocation("Local")
  1363. var startTime int64
  1364. if len(start_time) > 0 {
  1365. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1366. if err != nil {
  1367. fmt.Println(err)
  1368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1369. return
  1370. }
  1371. startTime = theTime.Unix()
  1372. }
  1373. var endTime int64
  1374. if len(end_time) > 0 {
  1375. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1376. if err != nil {
  1377. utils.ErrorLog(err.Error())
  1378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1379. return
  1380. }
  1381. endTime = theTime.Unix()
  1382. }
  1383. adminInfo := c.GetAdminUserInfo()
  1384. order_type, _ := c.GetInt64("order_type")
  1385. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1386. keyword := c.GetString("keyword")
  1387. limit, _ := c.GetInt64("limit")
  1388. page, _ := c.GetInt64("page")
  1389. order, total, err := service.GetDrugCancelOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit)
  1390. if err != nil {
  1391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1392. return
  1393. }
  1394. c.ServeSuccessJSON(map[string]interface{}{
  1395. "order": order,
  1396. "total": total,
  1397. })
  1398. }
  1399. func (c *GobalConfigApiController) AddMonitorOpen() {
  1400. is_open, _ := c.GetInt64("is_open")
  1401. fmt.Println("is_open22222222", is_open)
  1402. adminUserInfo := c.GetAdminUserInfo()
  1403. orgId := adminUserInfo.CurrentOrgId
  1404. config := models.XtMonitorConfig{
  1405. IsOpen: is_open,
  1406. UserOrgId: orgId,
  1407. Status: 1,
  1408. Ctime: time.Now().Unix(),
  1409. }
  1410. //查询该机构是否存在
  1411. _, errcode := service.GetMonitorConfigById(orgId)
  1412. if errcode == gorm.ErrRecordNotFound {
  1413. err := service.AddMonitorOpen(&config)
  1414. if err != nil {
  1415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1416. return
  1417. }
  1418. c.ServeSuccessJSON(map[string]interface{}{
  1419. "config": config,
  1420. })
  1421. } else if errcode == nil {
  1422. err := service.UpdateMonitorOpen(orgId, &config)
  1423. fmt.Println("err", err)
  1424. }
  1425. }
  1426. func (c *GobalConfigApiController) GetMonitorConfig() {
  1427. userInfo := c.GetAdminUserInfo()
  1428. orgId := userInfo.CurrentOrgId
  1429. config, err := service.GetMonitorConfig(orgId)
  1430. if err != nil {
  1431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1432. return
  1433. }
  1434. c.ServeSuccessJSON(map[string]interface{}{
  1435. "config": config,
  1436. })
  1437. }
  1438. func (c *GobalConfigApiController) AddOrderConfig() {
  1439. is_open, _ := c.GetInt64("is_open")
  1440. fmt.Println("344555555555555", is_open)
  1441. adminUserInfo := c.GetAdminUserInfo()
  1442. orgId := adminUserInfo.CurrentOrgId
  1443. config := models.XtOrderConfig{
  1444. IsOpen: is_open,
  1445. UserOrgId: orgId,
  1446. Status: 1,
  1447. Ctime: time.Now().Unix(),
  1448. }
  1449. //查询
  1450. _, errcode := service.GetOrderConfigById(orgId)
  1451. if errcode == gorm.ErrRecordNotFound {
  1452. err := service.AddOrderConfig(&config)
  1453. if err != nil {
  1454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1455. return
  1456. }
  1457. c.ServeSuccessJSON(map[string]interface{}{
  1458. "config": config,
  1459. })
  1460. } else if errcode == nil {
  1461. err := service.UpdateOrderConfig(orgId, &config)
  1462. fmt.Println("2222", err)
  1463. }
  1464. }
  1465. func (c *GobalConfigApiController) GetOrderConfig() {
  1466. adminUserInfo := c.GetAdminUserInfo()
  1467. orgId := adminUserInfo.CurrentOrgId
  1468. config, err := service.GetOrderConfig(orgId)
  1469. if err != nil {
  1470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1471. return
  1472. }
  1473. c.ServeSuccessJSON(map[string]interface{}{
  1474. "config": config,
  1475. })
  1476. }
  1477. func (c *GobalConfigApiController) GetDrugAutoMaticList() {
  1478. adminUserInfo := c.GetAdminUserInfo()
  1479. orgId := adminUserInfo.CurrentOrgId
  1480. warehous_out_id, _ := c.GetInt64("warehous_out_id")
  1481. record_time, _ := c.GetInt64("record_time")
  1482. warehouse_out_order_number := c.GetString("warehouse_out_order_number")
  1483. drugConfig, _ := service.GetDrugStockConfig(orgId)
  1484. list, err := service.GetDrugAutoMaticList(orgId, warehous_out_id, record_time, warehouse_out_order_number)
  1485. drugList, err := service.GetAllBaseDrugList(orgId)
  1486. if err != nil {
  1487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1488. return
  1489. }
  1490. c.ServeSuccessJSON(map[string]interface{}{
  1491. "list": list,
  1492. "drugConfig": drugConfig,
  1493. "drugList": drugList,
  1494. })
  1495. }
  1496. func (c *GobalConfigApiController) GetDrugWarehuseOrderInfo() {
  1497. adminUserInfo := c.GetAdminUserInfo()
  1498. orgId := adminUserInfo.CurrentOrgId
  1499. list, _ := service.GetDrugWarehuseOrderInfo(orgId)
  1500. c.ServeSuccessJSON(map[string]interface{}{
  1501. "list": list,
  1502. })
  1503. }