gobal_config_api_controller.go 59KB

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