gobal_config_api_controller.go 65KB

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