gobal_config_api_controller.go 69KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211
  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. advice_type, _ := c.GetInt64("advice_type")
  885. stop_type, _ := c.GetInt64("stop_type")
  886. fmt.Println("advcie_type23323232322332", advice_type)
  887. fmt.Println("stop_type33332323223232323", stop_type)
  888. if len(idsInters) == 0 {
  889. if err != nil {
  890. c.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
  891. return
  892. }
  893. }
  894. ids := make([]int64, 0)
  895. for _, idsInter := range idsInters {
  896. id := int64(idsInter.(float64))
  897. ids = append(ids, id)
  898. }
  899. getPrint, err := service.GetPrint(ids, OrgID)
  900. c.ServeSuccessJSON(map[string]interface{}{
  901. "doctoradvice": getPrint,
  902. })
  903. }
  904. func (c *GobalConfigApiController) GetOrgs() {
  905. adminUserInfo := c.GetAdminUserInfo()
  906. //获取当前人姓名
  907. var id = adminUserInfo.AdminUser.Id
  908. orgId := adminUserInfo.CurrentOrgId
  909. var orgs []*models.Org
  910. adminUser, err := service.GetHomeData(adminUserInfo.AdminUser.Id)
  911. creator, err := service.GetCreator(id, orgId)
  912. admin, err := service.GetSuperAdmin(id)
  913. if err != nil {
  914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  915. return
  916. }
  917. for _, item := range adminUser.Org {
  918. orgs = append(orgs, item)
  919. }
  920. for _, item := range adminUser.VMApp_Role {
  921. for _, subItem := range item.Org {
  922. orgs = append(orgs, subItem)
  923. }
  924. }
  925. orgs = RemoveRepeatedOrgElement(orgs)
  926. c.ServeSuccessJSON(map[string]interface{}{
  927. "orgs": orgs,
  928. "adminUser": adminUser,
  929. "creator": creator,
  930. "admin": admin,
  931. })
  932. }
  933. func (this *GobalConfigApiController) ChangeOrg() {
  934. org_id, _ := this.GetInt64("org_id")
  935. adminUserInfo := this.GetAdminUserInfo()
  936. tempOrg, err := service.GetOrgById(org_id)
  937. if err != nil {
  938. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  939. return
  940. }
  941. if tempOrg == nil {
  942. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrgNoExist)
  943. return
  944. }
  945. mobile := adminUserInfo.AdminUser.Mobile
  946. // 只取最近被创建的 admin_role
  947. adminUser, getAdminErr := service.GetValidAdminUserByMobileReturnErr(mobile) //账号信息唯一值
  948. if getAdminErr != nil {
  949. utils.ErrorLog("获取管理员失败:%v", getAdminErr)
  950. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  951. this.ServeJSON()
  952. return
  953. } else if adminUser == nil {
  954. utils.ErrorLog("查找不到 mobile = %v 的用户", mobile)
  955. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeAccountOrPasswordWrong)
  956. this.ServeJSON()
  957. return
  958. } else {
  959. adminUserInfo.CurrentOrgId = tempOrg.Id
  960. orgApp, _ := service.GetOrgApp(tempOrg.Id, 3)
  961. subscibe, _ := service.GetOrgSubscibe(tempOrg.Id)
  962. adminUserInfo.CurrentAppId = orgApp.Id
  963. appRole, _ := service.GetAppRole(tempOrg.Id, orgApp.Id, adminUserInfo.AdminUser.Id)
  964. var FiledList []*models.FiledConfig
  965. FiledList, _ = service.FindFiledByOrgId(tempOrg.Id)
  966. if len(FiledList) == 0 {
  967. err := service.BatchInsertFiledConfig(tempOrg.Id)
  968. if err == nil {
  969. FiledList, _ = service.FindFiledByOrgId(tempOrg.Id)
  970. } else {
  971. utils.ErrorLog("字段批量插入失败:%v", err)
  972. }
  973. }
  974. //产寻该机构是否有收缩压和舒张压
  975. pressure, err := service.GetDefaultSystolicPressure(tempOrg.Id)
  976. fmt.Println(err)
  977. if len(pressure) == 0 {
  978. err = service.BathInsertQualityControlTwo(tempOrg.Id)
  979. } else {
  980. utils.ErrorLog("字段批量插入失败:%v", err)
  981. }
  982. major, err := service.GetInspectionMajor(tempOrg.Id)
  983. if len(major) == 0 {
  984. QualityeList, err := service.FindQualityByOrgId(tempOrg.Id)
  985. if len(QualityeList) == 0 {
  986. err = service.BatchInsertQualityControl(tempOrg.Id)
  987. } else {
  988. utils.ErrorLog("字段批量插入失败:%v", err)
  989. }
  990. InspectionList, err := service.FindeInspectionByOrgId(tempOrg.Id)
  991. if len(InspectionList) == 0 {
  992. err = service.BatchInspectionConfiguration(tempOrg.Id)
  993. } else {
  994. utils.ErrorLog("字段批量插入失败:%v", err)
  995. }
  996. } else {
  997. utils.ErrorLog("字段批量插入失败:%v", err)
  998. }
  999. //查询该机构是否存在医护排班
  1000. _, errcode := service.GetDoctorScheduleByOrgId(tempOrg.Id)
  1001. //如果没有就插入
  1002. if errcode == gorm.ErrRecordNotFound {
  1003. err = service.BatchInsertDoctorSchedule(tempOrg.Id)
  1004. } else {
  1005. utils.ErrorLog("医护排班默认数据插入失败:%v", err)
  1006. }
  1007. var didRegistedForSCRM bool = false
  1008. var didRegistedForCDM bool = false
  1009. var didRegistedForMall bool = false
  1010. var curAppUrlfors []string
  1011. var pruviews []*models.Purview
  1012. if len(curAppUrlfors) == 0 {
  1013. if adminUser.Id == tempOrg.Creator {
  1014. urlfors_xt, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(3)
  1015. urlfors_cdm, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(4)
  1016. urlfors_scrm, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(6)
  1017. urlfors_mall, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(7)
  1018. curAppUrlfors = append(curAppUrlfors, urlfors_xt...)
  1019. curAppUrlfors = append(curAppUrlfors, urlfors_scrm...)
  1020. curAppUrlfors = append(curAppUrlfors, urlfors_cdm...)
  1021. curAppUrlfors = append(curAppUrlfors, urlfors_mall...)
  1022. didRegistedForSCRM = true
  1023. didRegistedForCDM = true
  1024. didRegistedForMall = true
  1025. } else {
  1026. appRole, _ := service.FindAdminUserIDA(appRole.Id)
  1027. if appRole.Id > 0 && len(appRole.RoleIds) > 0 {
  1028. role_arr := strings.Split(appRole.RoleIds, ",")
  1029. var ids string
  1030. for _, role_id := range role_arr {
  1031. id, _ := strconv.ParseInt(role_id, 10, 64)
  1032. purview_ids, _ := service.GetRolePurviewIds(id)
  1033. if len(ids) == 0 {
  1034. ids = purview_ids
  1035. } else {
  1036. ids = ids + "," + purview_ids
  1037. }
  1038. }
  1039. if len(ids) != 0 {
  1040. pruviews, _ = service.GetPurviewById(ids)
  1041. for _, item := range pruviews {
  1042. if item.Module == 3 && item.Parentid > 0 {
  1043. fmt.Println(item.Urlfor)
  1044. curAppUrlfors = append(curAppUrlfors, item.Urlfor)
  1045. }
  1046. }
  1047. } else {
  1048. curAppUrlfors = append(curAppUrlfors, "")
  1049. }
  1050. } else {
  1051. curAppUrlfors = append(curAppUrlfors, "")
  1052. }
  1053. for _, item := range pruviews {
  1054. if item.Module == 6 {
  1055. didRegistedForSCRM = true
  1056. }
  1057. if item.Module == 4 {
  1058. didRegistedForCDM = true
  1059. }
  1060. if item.Module == 7 {
  1061. didRegistedForMall = true
  1062. }
  1063. }
  1064. }
  1065. }
  1066. userInfo := map[string]interface{}{
  1067. "id": adminUser.Id,
  1068. "mobile": adminUser.Mobile,
  1069. "user_name": appRole.UserName,
  1070. "avatar": appRole.Avatar,
  1071. "intro": appRole.Intro,
  1072. "user_type": appRole.UserType,
  1073. "user_title": appRole.UserTitle,
  1074. }
  1075. org := map[string]interface{}{
  1076. "id": tempOrg.Id,
  1077. "org_name": tempOrg.OrgName,
  1078. "org_short_name": tempOrg.OrgShortName,
  1079. "org_intro": tempOrg.OrgIntroduction,
  1080. "org_logo": tempOrg.OrgLogo,
  1081. "province": tempOrg.Province,
  1082. "city": tempOrg.City,
  1083. "district": tempOrg.District,
  1084. "address": tempOrg.Address,
  1085. }
  1086. tempInfo, _ := service.GetOrgInfoTemplate(tempOrg.Id)
  1087. template_info := map[string]interface{}{
  1088. "id": tempInfo.ID,
  1089. "org_id": tempInfo.OrgId,
  1090. "template_id": tempInfo.TemplateId,
  1091. }
  1092. if tempOrg != nil && appRole != nil {
  1093. // 插入一条登录记录
  1094. ip := this.GetString("ip")
  1095. loginLog := &models.AdminUserLoginLog{
  1096. AdminUserId: adminUser.Id,
  1097. OrgId: tempOrg.Id,
  1098. AppId: appRole.AppId,
  1099. IP: ip,
  1100. OperateType: 3,
  1101. AppType: 3,
  1102. CreateTime: time.Now().Unix(),
  1103. }
  1104. if insertErr := service.InsertLoginLog(loginLog); insertErr != nil {
  1105. utils.ErrorLog("为手机号为%v的用户插入一条登录记录失败:%v", mobile, insertErr)
  1106. }
  1107. }
  1108. this.SetSession("admin_user_info", adminUserInfo)
  1109. this.ServeSuccessJSON(map[string]interface{}{
  1110. "user": userInfo,
  1111. "org": org,
  1112. "urlfors": curAppUrlfors,
  1113. "current_org_id": adminUserInfo.CurrentOrgId,
  1114. "current_app_id": adminUserInfo.CurrentAppId,
  1115. "subscibe": subscibe,
  1116. "template_info": template_info,
  1117. "fileds": FiledList,
  1118. "scrm_role_exist": didRegistedForSCRM,
  1119. "cdm_role_exist": didRegistedForCDM,
  1120. "mall_role_exist": didRegistedForMall,
  1121. })
  1122. }
  1123. }
  1124. func RemoveRepeatedOrgElement(orgs []*models.Org) (newOrgs []*models.Org) {
  1125. newOrgs = make([]*models.Org, 0)
  1126. for i := 0; i < len(orgs); i++ {
  1127. repeat := false
  1128. for j := i + 1; j < len(orgs); j++ {
  1129. if orgs[i].Id == orgs[j].Id {
  1130. repeat = true
  1131. break
  1132. }
  1133. }
  1134. if !repeat {
  1135. newOrgs = append(newOrgs, orgs[i])
  1136. }
  1137. }
  1138. return
  1139. }
  1140. func (this *GobalConfigApiController) GenerateLog() {
  1141. log_type, _ := this.GetInt64("log_type", 0)
  1142. logs, err := service.GetExportLogByType(this.GetAdminUserInfo().CurrentOrgId, log_type)
  1143. if err != nil {
  1144. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1145. return
  1146. }
  1147. this.ServeSuccessJSON(map[string]interface{}{
  1148. "logs": logs,
  1149. })
  1150. }
  1151. func (this *GobalConfigApiController) GetPatientsByKeyWord() {
  1152. keyWord := this.GetString("keyword")
  1153. adminUserInfo := this.GetAdminUserInfo()
  1154. patient, err := service.GetPatientsByKey(adminUserInfo.CurrentOrgId, keyWord)
  1155. if err != nil {
  1156. utils.ErrorLog(err.Error())
  1157. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1158. return
  1159. }
  1160. this.ServeSuccessJSON(map[string]interface{}{
  1161. "patient": patient,
  1162. })
  1163. }
  1164. func (c *GobalConfigApiController) PostXTHisConfig() {
  1165. is_open, _ := c.GetBool("is_open", false)
  1166. adminUserInfo := c.GetAdminUserInfo()
  1167. org_id := adminUserInfo.CurrentOrgId
  1168. isOpen := 0
  1169. if is_open {
  1170. isOpen = 1
  1171. } else {
  1172. isOpen = 2
  1173. }
  1174. config := models.XtHisConfig{
  1175. UserOrgId: org_id,
  1176. IsOpen: int64(isOpen),
  1177. Status: 1,
  1178. Ctime: time.Now().Unix(),
  1179. Mtime: time.Now().Unix(),
  1180. }
  1181. errs, configs := service.FindXTHisRecordByOrgId(org_id)
  1182. if errs == gorm.ErrRecordNotFound {
  1183. err := service.CreateXTHisRecord(&config)
  1184. if err != nil {
  1185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1186. return
  1187. }
  1188. } else if errs == nil {
  1189. modifyConfig := models.XtHisConfig{
  1190. ID: configs.ID,
  1191. UserOrgId: org_id,
  1192. Status: 1,
  1193. Ctime: time.Now().Unix(),
  1194. Mtime: time.Now().Unix(),
  1195. IsOpen: int64(isOpen),
  1196. }
  1197. err := service.UpdateXTHisRecord(&modifyConfig)
  1198. if err != nil {
  1199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1200. return
  1201. }
  1202. }
  1203. c.ServeSuccessJSON(map[string]interface{}{
  1204. "is_open": is_open,
  1205. })
  1206. return
  1207. }
  1208. func (c *GobalConfigApiController) PostXTHisProjectConfig() {
  1209. is_open, _ := c.GetBool("is_open", false)
  1210. adminUserInfo := c.GetAdminUserInfo()
  1211. org_id := adminUserInfo.CurrentOrgId
  1212. isOpen := 0
  1213. if is_open {
  1214. isOpen = 1
  1215. } else {
  1216. isOpen = 2
  1217. }
  1218. config := models.XtHisProjectConfig{
  1219. UserOrgId: org_id,
  1220. IsOpen: int64(isOpen),
  1221. Status: 1,
  1222. Ctime: time.Now().Unix(),
  1223. Mtime: time.Now().Unix(),
  1224. }
  1225. errs, configs := service.FindXTHisProjectByOrgId(org_id)
  1226. if errs == gorm.ErrRecordNotFound {
  1227. err := service.CreateXTHisProjectRecord(&config)
  1228. if err != nil {
  1229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1230. return
  1231. }
  1232. } else if errs == nil {
  1233. modifyConfig := models.XtHisProjectConfig{
  1234. ID: configs.ID,
  1235. UserOrgId: org_id,
  1236. Status: 1,
  1237. Ctime: time.Now().Unix(),
  1238. Mtime: time.Now().Unix(),
  1239. IsOpen: int64(isOpen),
  1240. }
  1241. err := service.UpdateXTHisProjectRecord(&modifyConfig)
  1242. if err != nil {
  1243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1244. return
  1245. }
  1246. }
  1247. c.ServeSuccessJSON(map[string]interface{}{
  1248. "is_open": is_open,
  1249. })
  1250. return
  1251. }
  1252. func (c *GobalConfigApiController) GetXTHisConfig() {
  1253. adminUserInfo := c.GetAdminUserInfo()
  1254. _, config := service.FindXTHisRecordByOrgId(adminUserInfo.CurrentOrgId)
  1255. _, project_config := service.FindXTHisProjectByOrgId(adminUserInfo.CurrentOrgId)
  1256. c.ServeSuccessJSON(map[string]interface{}{
  1257. "config": config,
  1258. "project_config": project_config,
  1259. })
  1260. }
  1261. func (c *GobalConfigApiController) GetAllIsOpenConfig() {
  1262. adminUserInfo := c.GetAdminUserInfo()
  1263. _, config := service.FindXTHisRecordByOrgId(adminUserInfo.CurrentOrgId)
  1264. _, project_config := service.FindXTHisProjectByOrgId(adminUserInfo.CurrentOrgId)
  1265. c.ServeSuccessJSON(map[string]interface{}{
  1266. "is_open_xt_his": config.IsOpen,
  1267. "is_open_xt_his_project": project_config.IsOpen,
  1268. })
  1269. }
  1270. func (c *GobalConfigApiController) GetPassExportData() {
  1271. }
  1272. func (c *GobalConfigApiController) GetExportData() {
  1273. start_time := c.GetString("start_time")
  1274. end_time := c.GetString("end_time")
  1275. p_type, _ := c.GetInt64("p_type")
  1276. timeLayout := "2006-01-02"
  1277. loc, _ := time.LoadLocation("Local")
  1278. var startTime int64
  1279. if len(start_time) > 0 {
  1280. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1281. if err != nil {
  1282. fmt.Println(err)
  1283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1284. return
  1285. }
  1286. startTime = theTime.Unix()
  1287. }
  1288. var endTime int64
  1289. if len(end_time) > 0 {
  1290. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1291. if err != nil {
  1292. utils.ErrorLog(err.Error())
  1293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1294. return
  1295. }
  1296. endTime = theTime.Unix()
  1297. }
  1298. adminInfo := c.GetAdminUserInfo()
  1299. order, _ := service.GetExportHisOrderList(adminInfo.CurrentOrgId, startTime, endTime, p_type)
  1300. c.ServeSuccessJSON(map[string]interface{}{
  1301. "order": order,
  1302. })
  1303. }
  1304. func (c *GobalConfigApiController) GetDrugInDetail() {
  1305. start_time := c.GetString("start_time")
  1306. end_time := c.GetString("end_time")
  1307. timeLayout := "2006-01-02"
  1308. loc, _ := time.LoadLocation("Local")
  1309. var startTime int64
  1310. if len(start_time) > 0 {
  1311. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1312. if err != nil {
  1313. fmt.Println(err)
  1314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1315. return
  1316. }
  1317. startTime = theTime.Unix()
  1318. }
  1319. var endTime int64
  1320. if len(end_time) > 0 {
  1321. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1322. if err != nil {
  1323. utils.ErrorLog(err.Error())
  1324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1325. return
  1326. }
  1327. endTime = theTime.Unix()
  1328. }
  1329. adminInfo := c.GetAdminUserInfo()
  1330. order_type, _ := c.GetInt64("order_type")
  1331. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1332. keyword := c.GetString("keyword")
  1333. page, _ := c.GetInt64("page")
  1334. limit, _ := c.GetInt64("limit")
  1335. detail, total, err := service.GetDrugInOrderDetail(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit)
  1336. if err != nil {
  1337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1338. return
  1339. }
  1340. c.ServeSuccessJSON(map[string]interface{}{
  1341. "detail": detail,
  1342. "total": total,
  1343. })
  1344. }
  1345. func (c *GobalConfigApiController) GetDrugCancelOrder() {
  1346. start_time := c.GetString("start_time")
  1347. end_time := c.GetString("end_time")
  1348. timeLayout := "2006-01-02"
  1349. loc, _ := time.LoadLocation("Local")
  1350. var startTime int64
  1351. if len(start_time) > 0 {
  1352. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1353. if err != nil {
  1354. fmt.Println(err)
  1355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1356. return
  1357. }
  1358. startTime = theTime.Unix()
  1359. }
  1360. var endTime int64
  1361. if len(end_time) > 0 {
  1362. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1363. if err != nil {
  1364. utils.ErrorLog(err.Error())
  1365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1366. return
  1367. }
  1368. endTime = theTime.Unix()
  1369. }
  1370. adminInfo := c.GetAdminUserInfo()
  1371. order_type, _ := c.GetInt64("order_type")
  1372. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1373. keyword := c.GetString("keyword")
  1374. limit, _ := c.GetInt64("limit")
  1375. page, _ := c.GetInt64("page")
  1376. order, total, err := service.GetDrugReturnOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, limit, page)
  1377. if err != nil {
  1378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1379. return
  1380. }
  1381. c.ServeSuccessJSON(map[string]interface{}{
  1382. "order": order,
  1383. "total": total,
  1384. })
  1385. }
  1386. func (c *GobalConfigApiController) GetDrugOutDetail() {
  1387. start_time := c.GetString("start_time")
  1388. end_time := c.GetString("end_time")
  1389. timeLayout := "2006-01-02"
  1390. loc, _ := time.LoadLocation("Local")
  1391. var startTime int64
  1392. if len(start_time) > 0 {
  1393. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1394. if err != nil {
  1395. fmt.Println(err)
  1396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1397. return
  1398. }
  1399. startTime = theTime.Unix()
  1400. }
  1401. var endTime int64
  1402. if len(end_time) > 0 {
  1403. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1404. if err != nil {
  1405. utils.ErrorLog(err.Error())
  1406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1407. return
  1408. }
  1409. endTime = theTime.Unix()
  1410. }
  1411. adminInfo := c.GetAdminUserInfo()
  1412. order_type, _ := c.GetInt64("order_type")
  1413. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1414. keyword := c.GetString("keyword")
  1415. limit, _ := c.GetInt64("limit")
  1416. page, _ := c.GetInt64("page")
  1417. order, total, err := service.GetDrugOutOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit)
  1418. if err != nil {
  1419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1420. return
  1421. }
  1422. c.ServeSuccessJSON(map[string]interface{}{
  1423. "order": order,
  1424. "total": total,
  1425. })
  1426. }
  1427. func (c *GobalConfigApiController) GetDrugCancelDetail() {
  1428. start_time := c.GetString("start_time")
  1429. end_time := c.GetString("end_time")
  1430. timeLayout := "2006-01-02"
  1431. loc, _ := time.LoadLocation("Local")
  1432. var startTime int64
  1433. if len(start_time) > 0 {
  1434. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1435. if err != nil {
  1436. fmt.Println(err)
  1437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1438. return
  1439. }
  1440. startTime = theTime.Unix()
  1441. }
  1442. var endTime int64
  1443. if len(end_time) > 0 {
  1444. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1445. if err != nil {
  1446. utils.ErrorLog(err.Error())
  1447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1448. return
  1449. }
  1450. endTime = theTime.Unix()
  1451. }
  1452. adminInfo := c.GetAdminUserInfo()
  1453. order_type, _ := c.GetInt64("order_type")
  1454. manufacturer_id, _ := c.GetInt64("manufacturer_id")
  1455. keyword := c.GetString("keyword")
  1456. limit, _ := c.GetInt64("limit")
  1457. page, _ := c.GetInt64("page")
  1458. orderPrint, _ := service.GetDrugCancelOrderPrint(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword)
  1459. order, total, err := service.GetDrugCancelOrder(startTime, endTime, adminInfo.CurrentOrgId, order_type, manufacturer_id, keyword, page, limit)
  1460. if err != nil {
  1461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1462. return
  1463. }
  1464. c.ServeSuccessJSON(map[string]interface{}{
  1465. "order": order,
  1466. "total": total,
  1467. "orderPrint": orderPrint,
  1468. })
  1469. }
  1470. func (c *GobalConfigApiController) AddMonitorOpen() {
  1471. is_open, _ := c.GetInt64("is_open")
  1472. fmt.Println("is_open22222222", is_open)
  1473. adminUserInfo := c.GetAdminUserInfo()
  1474. orgId := adminUserInfo.CurrentOrgId
  1475. config := models.XtMonitorConfig{
  1476. IsOpen: is_open,
  1477. UserOrgId: orgId,
  1478. Status: 1,
  1479. Ctime: time.Now().Unix(),
  1480. }
  1481. //查询该机构是否存在
  1482. _, errcode := service.GetMonitorConfigById(orgId)
  1483. if errcode == gorm.ErrRecordNotFound {
  1484. err := service.AddMonitorOpen(&config)
  1485. if err != nil {
  1486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1487. return
  1488. }
  1489. c.ServeSuccessJSON(map[string]interface{}{
  1490. "config": config,
  1491. })
  1492. } else if errcode == nil {
  1493. err := service.UpdateMonitorOpen(orgId, &config)
  1494. fmt.Println("err", err)
  1495. }
  1496. }
  1497. func (c *GobalConfigApiController) GetMonitorConfig() {
  1498. userInfo := c.GetAdminUserInfo()
  1499. orgId := userInfo.CurrentOrgId
  1500. config, err := service.GetMonitorConfig(orgId)
  1501. if err != nil {
  1502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1503. return
  1504. }
  1505. c.ServeSuccessJSON(map[string]interface{}{
  1506. "config": config,
  1507. })
  1508. }
  1509. func (c *GobalConfigApiController) AddOrderConfig() {
  1510. is_open, _ := c.GetInt64("is_open")
  1511. fmt.Println("344555555555555", is_open)
  1512. adminUserInfo := c.GetAdminUserInfo()
  1513. orgId := adminUserInfo.CurrentOrgId
  1514. config := models.XtOrderConfig{
  1515. IsOpen: is_open,
  1516. UserOrgId: orgId,
  1517. Status: 1,
  1518. Ctime: time.Now().Unix(),
  1519. }
  1520. //查询
  1521. _, errcode := service.GetOrderConfigById(orgId)
  1522. if errcode == gorm.ErrRecordNotFound {
  1523. err := service.AddOrderConfig(&config)
  1524. if err != nil {
  1525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1526. return
  1527. }
  1528. c.ServeSuccessJSON(map[string]interface{}{
  1529. "config": config,
  1530. })
  1531. } else if errcode == nil {
  1532. err := service.UpdateOrderConfig(orgId, &config)
  1533. fmt.Println("2222", err)
  1534. }
  1535. }
  1536. func (c *GobalConfigApiController) GetOrderConfig() {
  1537. adminUserInfo := c.GetAdminUserInfo()
  1538. orgId := adminUserInfo.CurrentOrgId
  1539. config, err := service.GetOrderConfig(orgId)
  1540. if err != nil {
  1541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1542. return
  1543. }
  1544. c.ServeSuccessJSON(map[string]interface{}{
  1545. "config": config,
  1546. })
  1547. }
  1548. func (c *GobalConfigApiController) GetDrugAutoMaticList() {
  1549. adminUserInfo := c.GetAdminUserInfo()
  1550. orgId := adminUserInfo.CurrentOrgId
  1551. warehous_out_id, _ := c.GetInt64("warehous_out_id")
  1552. record_time, _ := c.GetInt64("record_time")
  1553. warehouse_out_order_number := c.GetString("warehouse_out_order_number")
  1554. drugConfig, _ := service.GetDrugStockConfig(orgId)
  1555. list, err := service.GetDrugAutoMaticList(orgId, warehous_out_id, record_time, warehouse_out_order_number)
  1556. drugList, err := service.GetAllBaseDrugList(orgId)
  1557. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1558. if err != nil {
  1559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1560. return
  1561. }
  1562. c.ServeSuccessJSON(map[string]interface{}{
  1563. "list": list,
  1564. "drugConfig": drugConfig,
  1565. "drugList": drugList,
  1566. "manufacturerList": manufacturerList,
  1567. })
  1568. }
  1569. func (c *GobalConfigApiController) GetDrugWarehuseOrderInfo() {
  1570. adminUserInfo := c.GetAdminUserInfo()
  1571. orgId := adminUserInfo.CurrentOrgId
  1572. list, _ := service.GetDrugWarehuseOrderInfo(orgId)
  1573. c.ServeSuccessJSON(map[string]interface{}{
  1574. "list": list,
  1575. })
  1576. }
  1577. func (c *GobalConfigApiController) GetDrugStockList() {
  1578. page, _ := c.GetInt64("page", -1)
  1579. limit, _ := c.GetInt64("limit", -1)
  1580. keyword := c.GetString("keyword")
  1581. drug_type, _ := c.GetInt64("drug_type")
  1582. start_time := c.GetString("start_time")
  1583. end_time := c.GetString("end_time")
  1584. timeLayout := "2006-01-02"
  1585. loc, _ := time.LoadLocation("Local")
  1586. var startTime int64
  1587. if len(start_time) > 0 {
  1588. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1589. if err != nil {
  1590. fmt.Println(err)
  1591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1592. return
  1593. }
  1594. startTime = theTime.Unix()
  1595. }
  1596. var endTime int64
  1597. if len(end_time) > 0 {
  1598. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1599. if err != nil {
  1600. utils.ErrorLog(err.Error())
  1601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1602. return
  1603. }
  1604. endTime = theTime.Unix()
  1605. }
  1606. adminUserInfo := c.GetAdminUserInfo()
  1607. list, total, err := service.GetAllBaseDurgListCount(page, limit, keyword, drug_type, startTime, endTime, adminUserInfo.CurrentOrgId)
  1608. manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
  1609. if err != nil {
  1610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1611. return
  1612. }
  1613. c.ServeSuccessJSON(map[string]interface{}{
  1614. "list": list,
  1615. "total": total,
  1616. "manufacturerList": manufacturerList,
  1617. })
  1618. }
  1619. func (c *GobalConfigApiController) GetDrugStockFllow() {
  1620. drug_id, _ := c.GetInt64("drug_id")
  1621. start_time := c.GetString("start_time")
  1622. end_time := c.GetString("end_time")
  1623. stock_type, _ := c.GetInt64("stock_type")
  1624. page, _ := c.GetInt64("page")
  1625. limit, _ := c.GetInt64("limit")
  1626. timeLayout := "2006-01-02"
  1627. loc, _ := time.LoadLocation("Local")
  1628. var startTime int64
  1629. if len(start_time) > 0 {
  1630. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1631. if err != nil {
  1632. fmt.Println(err)
  1633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1634. return
  1635. }
  1636. startTime = theTime.Unix()
  1637. }
  1638. var endTime int64
  1639. if len(end_time) > 0 {
  1640. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1641. if err != nil {
  1642. utils.ErrorLog(err.Error())
  1643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1644. return
  1645. }
  1646. endTime = theTime.Unix()
  1647. }
  1648. orgId := c.GetAdminUserInfo().CurrentOrgId
  1649. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1650. //查询入库数据
  1651. if stock_type == 3 || stock_type == 0 {
  1652. list, total, err := service.GetDrugStockFlow(drug_id, startTime, endTime, page, limit, orgId)
  1653. if err != nil {
  1654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1655. return
  1656. }
  1657. c.ServeSuccessJSON(map[string]interface{}{
  1658. "list": list,
  1659. "total": total,
  1660. "manufacturerList": manufacturerList,
  1661. })
  1662. }
  1663. }
  1664. func (c *GobalConfigApiController) GetDrugOutStockFlow() {
  1665. drug_id, _ := c.GetInt64("drug_id")
  1666. start_time := c.GetString("start_time")
  1667. end_time := c.GetString("end_time")
  1668. stock_type, _ := c.GetInt64("stock_type")
  1669. page, _ := c.GetInt64("page")
  1670. limit, _ := c.GetInt64("limit")
  1671. timeLayout := "2006-01-02"
  1672. loc, _ := time.LoadLocation("Local")
  1673. var startTime int64
  1674. if len(start_time) > 0 {
  1675. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1676. if err != nil {
  1677. fmt.Println(err)
  1678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1679. return
  1680. }
  1681. startTime = theTime.Unix()
  1682. }
  1683. var endTime int64
  1684. if len(end_time) > 0 {
  1685. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1686. if err != nil {
  1687. utils.ErrorLog(err.Error())
  1688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1689. return
  1690. }
  1691. endTime = theTime.Unix()
  1692. }
  1693. orgId := c.GetAdminUserInfo().CurrentOrgId
  1694. outList, total, err := service.GetDrugStockOutFlow(drug_id, startTime, endTime, page, limit, orgId, stock_type)
  1695. fmt.Println("outList22233333333333333333333", outList)
  1696. if err != nil {
  1697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1698. return
  1699. }
  1700. c.ServeSuccessJSON(map[string]interface{}{
  1701. "outList": outList,
  1702. "total": total,
  1703. })
  1704. }
  1705. func (c *GobalConfigApiController) GetBatchOrderDetail() {
  1706. drug_id, _ := c.GetInt64("drug_id")
  1707. orgId := c.GetAdminUserInfo().CurrentOrgId
  1708. limit, _ := c.GetInt64("limit")
  1709. page, _ := c.GetInt64("page")
  1710. detail, total, err := service.GetBatchOrderDetail(drug_id, orgId, page, limit)
  1711. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1712. if err != nil {
  1713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1714. return
  1715. }
  1716. c.ServeSuccessJSON(map[string]interface{}{
  1717. "detail": detail,
  1718. "total": total,
  1719. "manufacturerList": manufacturerList,
  1720. })
  1721. }
  1722. func (c *GobalConfigApiController) GetDrugCountList() {
  1723. start_time := c.GetString("start_time")
  1724. end_time := c.GetString("end_time")
  1725. timeLayout := "2006-01-02"
  1726. loc, _ := time.LoadLocation("Local")
  1727. var startTime int64
  1728. if len(start_time) > 0 {
  1729. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1730. if err != nil {
  1731. fmt.Println(err)
  1732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1733. return
  1734. }
  1735. startTime = theTime.Unix()
  1736. }
  1737. var endTime int64
  1738. if len(end_time) > 0 {
  1739. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1740. if err != nil {
  1741. utils.ErrorLog(err.Error())
  1742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1743. return
  1744. }
  1745. endTime = theTime.Unix()
  1746. }
  1747. orgId := c.GetAdminUserInfo().CurrentOrgId
  1748. countList, err := service.GetMinCountList(startTime, endTime, orgId)
  1749. outCountList, _ := service.GetOutDrugCountList(startTime, endTime, orgId)
  1750. auCountList, err := service.GetAutoDrugCountList(startTime, endTime, orgId)
  1751. info, _ := service.GetDrugWarehouOrderInfo(startTime, endTime, orgId)
  1752. cancelCountList, _ := service.GetCancelDrugCountList(startTime, endTime, orgId)
  1753. if err != nil {
  1754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1755. return
  1756. }
  1757. c.ServeSuccessJSON(map[string]interface{}{
  1758. "outCountList": outCountList,
  1759. "auCountList": auCountList,
  1760. "minCount": countList,
  1761. "info": info,
  1762. "cancelCountList": cancelCountList,
  1763. })
  1764. }
  1765. func (c *GobalConfigApiController) GetSingleOrderDetail() {
  1766. id, _ := c.GetInt64("id")
  1767. start_time, _ := c.GetInt64("start_time")
  1768. orgId := c.GetAdminUserInfo().CurrentOrgId
  1769. list, err := service.GetSingleOrderDetail(id, orgId)
  1770. dealerList, err := service.GetAllDealerList(orgId)
  1771. manufacturerList, err := service.GetAllManufacturerList(orgId)
  1772. drugFlowList, _ := service.GetDrugStockFlowDetail(start_time, orgId)
  1773. if err != nil {
  1774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1775. return
  1776. }
  1777. c.ServeSuccessJSON(map[string]interface{}{
  1778. "list": list,
  1779. "dealerList": dealerList,
  1780. "manufacturerList": manufacturerList,
  1781. "drugFlowList": drugFlowList,
  1782. })
  1783. }
  1784. func (c *GobalConfigApiController) GetAutoDrugDetail() {
  1785. warehouse_out_id, _ := c.GetInt64("warehouse_out_id")
  1786. id, _ := c.GetInt64("drug_id")
  1787. record_time, _ := c.GetInt64("record_time")
  1788. orgId := c.GetAdminUserInfo().CurrentOrgId
  1789. //获取自动出库
  1790. list, err, total := service.FindDrugStockUserDetailByIdThree(id, record_time, orgId)
  1791. //获取手动出库
  1792. outList, err := service.FindeDrugWarehouserInfo(warehouse_out_id, id, orgId)
  1793. batchNumber, err := service.GetDrugFlowBatch(warehouse_out_id, id, orgId)
  1794. if err != nil {
  1795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  1796. return
  1797. }
  1798. c.ServeSuccessJSON(map[string]interface{}{
  1799. "list": list,
  1800. "total": total,
  1801. "outList": outList,
  1802. "batchNumber": batchNumber,
  1803. })
  1804. }
  1805. func (c *GobalConfigApiController) GetDrugOrderInPrint() {
  1806. id := c.GetString("id")
  1807. ids := strings.Split(id, ",")
  1808. admin := c.GetAdminUserInfo()
  1809. info, _ := service.FindDrugWarehousingByIdOne(ids, admin.CurrentOrgId)
  1810. manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
  1811. warehousingInfo, _ := service.FindDrugWarehousingInfoByIdOne(ids, admin.CurrentOrgId)
  1812. c.ServeSuccessJSON(map[string]interface{}{
  1813. "info": info,
  1814. "warehousing": warehousingInfo,
  1815. "manufacturerList": manufacturerList,
  1816. })
  1817. }
  1818. func (c *GobalConfigApiController) GetDrugOutOrderPrint() {
  1819. id := c.GetString("id")
  1820. ids := strings.Split(id, ",")
  1821. admin := c.GetAdminUserInfo()
  1822. info, _ := service.FindeDrugWarehouseOutOrder(ids, admin.CurrentOrgId)
  1823. //info, _ := service.GetExportOutOrderDrugListOne(ids)
  1824. manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
  1825. //warehousing, _ := service.FindeDrugWarehouseOutDetail(ids, admin.CurrentOrgId)
  1826. warehousing, _ := service.GetExportOutOrderDrugListOne(ids)
  1827. c.ServeSuccessJSON(map[string]interface{}{
  1828. "info": info,
  1829. "warehousing": warehousing,
  1830. "manufacturerList": manufacturerList,
  1831. })
  1832. }
  1833. func (c *GobalConfigApiController) GetDrugBatchNumber() {
  1834. id, _ := c.GetInt64("id")
  1835. orgId := c.GetAdminUserInfo().CurrentOrgId
  1836. list, _ := service.GetDrugBatchNumber(id, orgId)
  1837. c.ServeSuccessJSON(map[string]interface{}{
  1838. "list": list,
  1839. })
  1840. }
  1841. func (c *GobalConfigApiController) ExportDrugList() {
  1842. orderId := c.GetString("order_id")
  1843. ids := strings.Split(orderId, ",")
  1844. list, _ := service.ExportDrugList(ids)
  1845. orgId := c.GetAdminUserInfo().CurrentOrgId
  1846. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1847. dealerList, _ := service.GetAllDealerList(orgId)
  1848. c.ServeSuccessJSON(map[string]interface{}{
  1849. "list": list,
  1850. "manufacturerList": manufacturerList,
  1851. "dealerList": dealerList,
  1852. })
  1853. }
  1854. func (c *GobalConfigApiController) GetExportOutOrderDrugList() {
  1855. orderId := c.GetString("order_id")
  1856. ids := strings.Split(orderId, ",")
  1857. orgId := c.GetAdminUserInfo().CurrentOrgId
  1858. //list, _ := service.GetExportOutOrderDrugList(ids)
  1859. list, _ := service.GetExportOutOrderDrugListOne(ids)
  1860. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1861. dealerList, _ := service.GetAllDealerList(orgId)
  1862. c.ServeSuccessJSON(map[string]interface{}{
  1863. "list": list,
  1864. "manufacturerList": manufacturerList,
  1865. "dealerList": dealerList,
  1866. })
  1867. }
  1868. func (c *GobalConfigApiController) GetDrugFlow() {
  1869. start_time := c.GetString("start_time")
  1870. end_time := c.GetString("end_time")
  1871. timeLayout := "2006-01-02"
  1872. loc, _ := time.LoadLocation("Local")
  1873. var startTime int64
  1874. if len(start_time) > 0 {
  1875. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1876. if err != nil {
  1877. fmt.Println(err)
  1878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1879. return
  1880. }
  1881. startTime = theTime.Unix()
  1882. }
  1883. var endTime int64
  1884. if len(end_time) > 0 {
  1885. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1886. if err != nil {
  1887. utils.ErrorLog(err.Error())
  1888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1889. return
  1890. }
  1891. endTime = theTime.Unix()
  1892. }
  1893. orgId := c.GetAdminUserInfo().CurrentOrgId
  1894. drug_id, _ := c.GetInt64("drug_id")
  1895. page, _ := c.GetInt64("page")
  1896. limit, _ := c.GetInt64("limit")
  1897. stock_type, _ := c.GetInt64("stock_type")
  1898. list, total, _ := service.GetDrugFlow(drug_id, orgId, limit, page, startTime, endTime, stock_type)
  1899. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  1900. dealerList, _ := service.GetAllDealerList(orgId)
  1901. c.ServeSuccessJSON(map[string]interface{}{
  1902. "list": list,
  1903. "total": total,
  1904. "manufacturerList": manufacturerList,
  1905. "dealerList": dealerList,
  1906. })
  1907. }
  1908. func (c *GobalConfigApiController) GetCancelStockDetail() {
  1909. id, _ := c.GetInt64("id")
  1910. list, _ := service.GetCancelStockDetail(id)
  1911. c.ServeSuccessJSON(map[string]interface{}{
  1912. "list": list,
  1913. })
  1914. }