gobal_config_api_controller.go 64KB

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