gobal_config_api_controller.go 68KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "bytes"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/jinzhu/gorm"
  11. "io/ioutil"
  12. "log"
  13. "os"
  14. "path"
  15. "reflect"
  16. "regexp"
  17. "runtime"
  18. "strconv"
  19. "strings"
  20. "time"
  21. "github.com/astaxie/beego"
  22. )
  23. type GobalConfigApiController struct {
  24. BaseAuthAPIController
  25. }
  26. func GobalConfigRegistRouters() {
  27. beego.Router("/api/stock/automaticreduce/isopen", &GobalConfigApiController{}, "post:PostStockConfig")
  28. beego.Router("/api/drugstock/automaticreduce/isopen", &GobalConfigApiController{}, "post:PostDrugStockConfig")
  29. beego.Router("/api/automaticreduce/get", &GobalConfigApiController{}, "get:GetConfig")
  30. beego.Router("/api/drugstockautomaticreduce/get", &GobalConfigApiController{}, "get:GetDrugStockConfig")
  31. beego.Router("/api/print/template/commit", &GobalConfigApiController{}, "post:PostPrintTemplateTwo")
  32. beego.Router("/api/print/template/get", &GobalConfigApiController{}, "get:GetPrintTemplate")
  33. beego.Router("/api/dataupload/config/commit", &GobalConfigApiController{}, "post:PostConfig")
  34. beego.Router("/api/dataupload/config/modify", &GobalConfigApiController{}, "post:ModifyConfig")
  35. beego.Router("/api/dataupload/config/get", &GobalConfigApiController{}, "get:GetDataUploadConfig")
  36. beego.Router("/api/dataupload/is_docking/get", &GobalConfigApiController{}, "get:GetDataUploadIsDocking")
  37. beego.Router("/api/adviceconfig/isopen", &GobalConfigApiController{}, "post:PostDoctorAdviceConfig")
  38. beego.Router("/api/adviceconfig/get", &GobalConfigApiController{}, "get:GetDoctorAdviceConfig")
  39. beego.Router("/api/advicetemplate/init/commit", &GobalConfigApiController{}, "post:PostInitAdviceTemplate")
  40. beego.Router("/api/advicetemplate/init/get", &GobalConfigApiController{}, "get:GetAdviceInitConfig")
  41. beego.Router("/api/systemprescription/commit", &GobalConfigApiController{}, "post:CreateSystemPrescription")
  42. beego.Router("/api/systemprescription/update", &GobalConfigApiController{}, "post:UpdateSystemPrescription")
  43. beego.Router("/api/systemprescription/all", &GobalConfigApiController{}, "get:GetAllSystemPrescription")
  44. beego.Router("/api/systemprescription/get", &GobalConfigApiController{}, "get:GetSystemPrescription")
  45. beego.Router("/api/advicetemplate/getprintinfo", &GobalConfigApiController{}, "post:GetPrintInfo")
  46. beego.Router("/api/public/orgs", &GobalConfigApiController{}, "get:GetOrgs")
  47. beego.Router("/api/org/change", &GobalConfigApiController{}, "post:ChangeOrg")
  48. beego.Router("/api/log/generate", &GobalConfigApiController{}, "get:GenerateLog")
  49. beego.Router("/api/patients/search", &GobalConfigApiController{}, "Post:GetPatientsByKeyWord")
  50. beego.Router("/api/xtconfig/get", &GobalConfigApiController{}, "get:GetXTHisConfig")
  51. beego.Router("/api/xtconfig/isopen", &GobalConfigApiController{}, "post:PostXTHisConfig")
  52. beego.Router("/api/xtconfigproject/isopen", &GobalConfigApiController{}, "post:PostXTHisProjectConfig")
  53. beego.Router("/api/isopen/init", &GobalConfigApiController{}, "get:GetAllIsOpenConfig")
  54. beego.Router("/api/passdetail/export", &GobalConfigApiController{}, "get:GetPassExportData")
  55. beego.Router("/api/consumedetail/export", &GobalConfigApiController{}, "get:GetExportData")
  56. beego.Router("/api/drugstock/getdrugindetail", &GobalConfigApiController{}, "get:GetDrugInDetail")
  57. beego.Router("/api/drugstock/getdrugcancelorder", &GobalConfigApiController{}, "get:GetDrugCancelOrder")
  58. beego.Router("/api/drugstock/getdrugoutdetail", &GobalConfigApiController{}, "get:GetDrugOutDetail")
  59. beego.Router("/api/drugstock/getdrugcanceldetail", &GobalConfigApiController{}, "get:GetDrugCancelDetail")
  60. beego.Router("/api/monitor/open", &GobalConfigApiController{}, "get:AddMonitorOpen")
  61. beego.Router("/api/monitor/getmonitorconfig", &GobalConfigApiController{}, "Get:GetMonitorConfig")
  62. beego.Router("/api/order/addorderconfig", &GobalConfigApiController{}, "Get:AddOrderConfig")
  63. beego.Router("/api/order/getorderconfig", &GobalConfigApiController{}, "Get:GetOrderConfig")
  64. beego.Router("/api/drugstock/getdrugautomaticlist", &GobalConfigApiController{}, "Get:GetDrugAutoMaticList")
  65. beego.Router("/api/drugstock/getdrugwarehouseorderinfo", &GobalConfigApiController{}, "Get:GetDrugWarehuseOrderInfo")
  66. //新接口
  67. beego.Router("/api/drugstock/drugstocklist", &GobalConfigApiController{}, "Get:GetDrugStockList")
  68. beego.Router("/api/drugstock/getdrugstockflow", &GobalConfigApiController{}, "Get:GetDrugStockFllow")
  69. beego.Router("/api/drugoutstock/getoutdrugstockflow", &GobalConfigApiController{}, "Get:GetDrugOutStockFlow")
  70. beego.Router("/api/drug/getbatchorderdetail", &GobalConfigApiController{}, "Get:GetBatchOrderDetail")
  71. beego.Router("/api/drug/getdrugcountlist", &GobalConfigApiController{}, "Get:GetDrugCountList")
  72. beego.Router("/api/drug/getsingleorderdetail", &GobalConfigApiController{}, "Get:GetSingleOrderDetail")
  73. beego.Router("/api/drug/getautodrugdetial", &GobalConfigApiController{}, "Get:GetAutoDrugDetail")
  74. beego.Router("/api/drug/getdrugorderinprint", &GobalConfigApiController{}, "Get:GetDrugOrderInPrint")
  75. beego.Router("/api/drug/getdrugoutorderdetailprint", &GobalConfigApiController{}, "Get:GetDrugOutOrderPrint")
  76. beego.Router("/api/drug/getdrugbatchnumber", &GobalConfigApiController{}, "Get:GetDrugBatchNumber")
  77. 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. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  1604. if err != nil {
  1605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1606. return
  1607. }
  1608. c.ServeSuccessJSON(map[string]interface{}{
  1609. "list": list,
  1610. "total": total,
  1611. "manufacturerList": manufacturerList,
  1612. })
  1613. }
  1614. func (c *GobalConfigApiController) GetDrugStockFllow() {
  1615. drug_id, _ := c.GetInt64("drug_id")
  1616. start_time := c.GetString("start_time")
  1617. end_time := c.GetString("end_time")
  1618. stock_type, _ := c.GetInt64("stock_type")
  1619. page, _ := c.GetInt64("page")
  1620. limit, _ := c.GetInt64("limit")
  1621. timeLayout := "2006-01-02"
  1622. loc, _ := time.LoadLocation("Local")
  1623. var startTime int64
  1624. if len(start_time) > 0 {
  1625. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1626. if err != nil {
  1627. fmt.Println(err)
  1628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1629. return
  1630. }
  1631. startTime = theTime.Unix()
  1632. }
  1633. var endTime int64
  1634. if len(end_time) > 0 {
  1635. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1636. if err != nil {
  1637. utils.ErrorLog(err.Error())
  1638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1639. return
  1640. }
  1641. endTime = theTime.Unix()
  1642. }
  1643. orgId := c.GetAdminUserInfo().CurrentOrgId
  1644. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1645. //查询入库数据
  1646. if stock_type == 3 || stock_type == 0 {
  1647. list, total, err := service.GetDrugStockFlow(drug_id, startTime, endTime, page, limit, orgId)
  1648. if err != nil {
  1649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1650. return
  1651. }
  1652. c.ServeSuccessJSON(map[string]interface{}{
  1653. "list": list,
  1654. "total": total,
  1655. "manufacturerList": manufacturerList,
  1656. })
  1657. }
  1658. }
  1659. func (c *GobalConfigApiController) GetDrugOutStockFlow() {
  1660. drug_id, _ := c.GetInt64("drug_id")
  1661. start_time := c.GetString("start_time")
  1662. end_time := c.GetString("end_time")
  1663. stock_type, _ := c.GetInt64("stock_type")
  1664. page, _ := c.GetInt64("page")
  1665. limit, _ := c.GetInt64("limit")
  1666. timeLayout := "2006-01-02"
  1667. loc, _ := time.LoadLocation("Local")
  1668. var startTime int64
  1669. if len(start_time) > 0 {
  1670. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1671. if err != nil {
  1672. fmt.Println(err)
  1673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1674. return
  1675. }
  1676. startTime = theTime.Unix()
  1677. }
  1678. var endTime int64
  1679. if len(end_time) > 0 {
  1680. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1681. if err != nil {
  1682. utils.ErrorLog(err.Error())
  1683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1684. return
  1685. }
  1686. endTime = theTime.Unix()
  1687. }
  1688. orgId := c.GetAdminUserInfo().CurrentOrgId
  1689. outList, total, err := service.GetDrugStockOutFlow(drug_id, startTime, endTime, page, limit, orgId, stock_type)
  1690. fmt.Println("outList22233333333333333333333", outList)
  1691. if err != nil {
  1692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1693. return
  1694. }
  1695. c.ServeSuccessJSON(map[string]interface{}{
  1696. "outList": outList,
  1697. "total": total,
  1698. })
  1699. }
  1700. func (c *GobalConfigApiController) GetBatchOrderDetail() {
  1701. drug_id, _ := c.GetInt64("drug_id")
  1702. orgId := c.GetAdminUserInfo().CurrentOrgId
  1703. limit, _ := c.GetInt64("limit")
  1704. page, _ := c.GetInt64("page")
  1705. detail, total, err := service.GetBatchOrderDetail(drug_id, orgId, page, limit)
  1706. if err != nil {
  1707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1708. return
  1709. }
  1710. c.ServeSuccessJSON(map[string]interface{}{
  1711. "detail": detail,
  1712. "total": total,
  1713. })
  1714. }
  1715. func (c *GobalConfigApiController) GetDrugCountList() {
  1716. start_time := c.GetString("start_time")
  1717. end_time := c.GetString("end_time")
  1718. timeLayout := "2006-01-02"
  1719. loc, _ := time.LoadLocation("Local")
  1720. var startTime int64
  1721. if len(start_time) > 0 {
  1722. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1723. if err != nil {
  1724. fmt.Println(err)
  1725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1726. return
  1727. }
  1728. startTime = theTime.Unix()
  1729. }
  1730. var endTime int64
  1731. if len(end_time) > 0 {
  1732. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1733. if err != nil {
  1734. utils.ErrorLog(err.Error())
  1735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1736. return
  1737. }
  1738. endTime = theTime.Unix()
  1739. }
  1740. orgId := c.GetAdminUserInfo().CurrentOrgId
  1741. list, err := service.GetDrugCountList(startTime, endTime, orgId)
  1742. countList, err := service.GetMinCountList(startTime, endTime, orgId)
  1743. outCountList, _ := service.GetOutDrugCountList(startTime, endTime, orgId)
  1744. auCountList, err := service.GetAutoDrugCountList(startTime, endTime, orgId)
  1745. info, _ := service.GetDrugWarehouOrderInfo(startTime, endTime, orgId)
  1746. cancelCountList, _ := service.GetCancelDrugCountList(startTime, endTime, orgId)
  1747. if err != nil {
  1748. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1749. return
  1750. }
  1751. c.ServeSuccessJSON(map[string]interface{}{
  1752. "countList": list,
  1753. "outCountList": outCountList,
  1754. "auCountList": auCountList,
  1755. "minCount": countList,
  1756. "info": info,
  1757. "cancelCountList": cancelCountList,
  1758. })
  1759. }
  1760. func (c *GobalConfigApiController) GetSingleOrderDetail() {
  1761. id, _ := c.GetInt64("id")
  1762. orgId := c.GetAdminUserInfo().CurrentOrgId
  1763. list, err := service.GetSingleOrderDetail(id, orgId)
  1764. outList, err := service.GetAllSingleDrugDetail(id, orgId)
  1765. dealerList, err := service.GetAllDealerList(orgId)
  1766. manufacturerList, err := service.GetAllManufacturerList(orgId)
  1767. if err != nil {
  1768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1769. return
  1770. }
  1771. c.ServeSuccessJSON(map[string]interface{}{
  1772. "list": list,
  1773. "dealerList": dealerList,
  1774. "manufacturerList": manufacturerList,
  1775. "outList": outList,
  1776. })
  1777. }
  1778. func (c *GobalConfigApiController) GetAutoDrugDetail() {
  1779. warehouse_out_id, _ := c.GetInt64("warehouse_out_id")
  1780. id, _ := c.GetInt64("drug_id")
  1781. record_time, _ := c.GetInt64("record_time")
  1782. orgId := c.GetAdminUserInfo().CurrentOrgId
  1783. //获取自动出库
  1784. list, err, total := service.FindDrugStockUserDetailByIdThree(id, record_time, orgId)
  1785. //获取手动出库
  1786. outList, err := service.FindeDrugWarehouserInfo(warehouse_out_id, id, orgId)
  1787. batchNumber, err := service.GetDrugFlowBatch(warehouse_out_id, id, orgId)
  1788. if err != nil {
  1789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1790. return
  1791. }
  1792. c.ServeSuccessJSON(map[string]interface{}{
  1793. "list": list,
  1794. "total": total,
  1795. "outList": outList,
  1796. "batchNumber": batchNumber,
  1797. })
  1798. }
  1799. func (c *GobalConfigApiController) GetDrugOrderInPrint() {
  1800. id := c.GetString("id")
  1801. ids := strings.Split(id, ",")
  1802. admin := c.GetAdminUserInfo()
  1803. info, _ := service.FindDrugWarehousingByIdOne(ids, admin.CurrentOrgId)
  1804. manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
  1805. warehousingInfo, _ := service.FindDrugWarehousingInfoByIdOne(ids, admin.CurrentOrgId)
  1806. c.ServeSuccessJSON(map[string]interface{}{
  1807. "info": info,
  1808. "warehousing": warehousingInfo,
  1809. "manufacturerList": manufacturerList,
  1810. })
  1811. }
  1812. func (c *GobalConfigApiController) GetDrugOutOrderPrint() {
  1813. id := c.GetString("id")
  1814. ids := strings.Split(id, ",")
  1815. admin := c.GetAdminUserInfo()
  1816. info, _ := service.FindeDrugWarehouseOutOrder(ids, admin.CurrentOrgId)
  1817. manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
  1818. warehousing, _ := service.FindeDrugWarehouseOutDetail(ids, admin.CurrentOrgId)
  1819. c.ServeSuccessJSON(map[string]interface{}{
  1820. "info": info,
  1821. "warehousing": warehousing,
  1822. "manufacturerList": manufacturerList,
  1823. })
  1824. }
  1825. func (c *GobalConfigApiController) GetDrugBatchNumber() {
  1826. id, _ := c.GetInt64("id")
  1827. orgId := c.GetAdminUserInfo().CurrentOrgId
  1828. list, _ := service.GetDrugBatchNumber(id, orgId)
  1829. c.ServeSuccessJSON(map[string]interface{}{
  1830. "list": list,
  1831. })
  1832. }
  1833. func (c *GobalConfigApiController) ExportDrugList() {
  1834. orderId := c.GetString("order_id")
  1835. ids := strings.Split(orderId, ",")
  1836. list, _ := service.ExportDrugList(ids)
  1837. orgId := c.GetAdminUserInfo().CurrentOrgId
  1838. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1839. dealerList, _ := service.GetAllDealerList(orgId)
  1840. c.ServeSuccessJSON(map[string]interface{}{
  1841. "list": list,
  1842. "manufacturerList": manufacturerList,
  1843. "dealerList": dealerList,
  1844. })
  1845. }
  1846. func (c *GobalConfigApiController) GetExportOutOrderDrugList() {
  1847. orderId := c.GetString("order_id")
  1848. ids := strings.Split(orderId, ",")
  1849. orgId := c.GetAdminUserInfo().CurrentOrgId
  1850. list, _ := service.GetExportOutOrderDrugList(ids)
  1851. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1852. dealerList, _ := service.GetAllDealerList(orgId)
  1853. c.ServeSuccessJSON(map[string]interface{}{
  1854. "list": list,
  1855. "manufacturerList": manufacturerList,
  1856. "dealerList": dealerList,
  1857. })
  1858. }
  1859. func (c *GobalConfigApiController) GetDrugFlow() {
  1860. start_time := c.GetString("start_time")
  1861. end_time := c.GetString("end_time")
  1862. timeLayout := "2006-01-02"
  1863. loc, _ := time.LoadLocation("Local")
  1864. var startTime int64
  1865. if len(start_time) > 0 {
  1866. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1867. if err != nil {
  1868. fmt.Println(err)
  1869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1870. return
  1871. }
  1872. startTime = theTime.Unix()
  1873. }
  1874. var endTime int64
  1875. if len(end_time) > 0 {
  1876. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1877. if err != nil {
  1878. utils.ErrorLog(err.Error())
  1879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1880. return
  1881. }
  1882. endTime = theTime.Unix()
  1883. }
  1884. orgId := c.GetAdminUserInfo().CurrentOrgId
  1885. drug_id, _ := c.GetInt64("drug_id")
  1886. page, _ := c.GetInt64("page")
  1887. limit, _ := c.GetInt64("limit")
  1888. stock_type, _ := c.GetInt64("stock_type")
  1889. list, total, _ := service.GetDrugFlow(drug_id, orgId, limit, page, startTime, endTime, stock_type)
  1890. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1891. dealerList, _ := service.GetAllDealerList(orgId)
  1892. c.ServeSuccessJSON(map[string]interface{}{
  1893. "list": list,
  1894. "total": total,
  1895. "manufacturerList": manufacturerList,
  1896. "dealerList": dealerList,
  1897. })
  1898. }
  1899. func (c *GobalConfigApiController) GetCancelStockDetail() {
  1900. id, _ := c.GetInt64("id")
  1901. list, _ := service.GetCancelStockDetail(id)
  1902. c.ServeSuccessJSON(map[string]interface{}{
  1903. "list": list,
  1904. })
  1905. }