gobal_config_api_controller.go 68KB

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