gobal_config_api_controller.go 55KB

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