gobal_config_api_controller.go 53KB

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