gobal_config_api_controller.go 71KB

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