gobal_config_api_controller.go 70KB

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