gobal_config_api_controller.go 53KB

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