gobal_config_api_controller.go 60KB

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