gobal_config_api_controller.go 41KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295
  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. }
  51. //provinces, _ := service.GetDistrictsByUpid(0)21
  52. func (c *GobalConfigApiController) PostStockConfig() {
  53. is_open, _ := c.GetInt64("is_open", 0)
  54. adminUserInfo := c.GetAdminUserInfo()
  55. org_id := adminUserInfo.CurrentOrgId
  56. config := models.GobalConfig{
  57. OrgId: org_id,
  58. IsOpen: is_open,
  59. Status: 1,
  60. CreateTime: time.Now().Unix(),
  61. UpdateTime: time.Now().Unix(),
  62. IsOpenRemind: 0,
  63. }
  64. errs, configs := service.FindAutomaticReduceRecordByOrgId(org_id)
  65. if errs == gorm.ErrRecordNotFound {
  66. err := service.CreateAutomaticReduceRecord(&config)
  67. if err != nil {
  68. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  69. return
  70. }
  71. } else if errs == nil {
  72. modifyConfig := models.GobalConfig{
  73. ID: configs.ID,
  74. OrgId: org_id,
  75. IsOpen: is_open,
  76. Status: 1,
  77. CreateTime: time.Now().Unix(),
  78. UpdateTime: time.Now().Unix(),
  79. IsOpenRemind: configs.IsOpenRemind,
  80. }
  81. err := service.UpdateAutomaticReduceRecord(&modifyConfig)
  82. if err != nil {
  83. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  84. return
  85. }
  86. }
  87. c.ServeSuccessJSON(map[string]interface{}{
  88. "is_open": is_open,
  89. })
  90. return
  91. }
  92. func (c *GobalConfigApiController) PostDrugStockConfig() {
  93. is_open, _ := c.GetInt64("is_open", 0)
  94. adminUserInfo := c.GetAdminUserInfo()
  95. org_id := adminUserInfo.CurrentOrgId
  96. config := models.DrugStockConfig{
  97. OrgId: org_id,
  98. IsOpen: is_open,
  99. Status: 1,
  100. CreateTime: time.Now().Unix(),
  101. UpdateTime: time.Now().Unix(),
  102. }
  103. errs, configs := service.FindDrugStockAutomaticReduceRecordByOrgId(org_id)
  104. if errs == gorm.ErrRecordNotFound {
  105. err := service.CreateDrugAutomaticReduceRecord(&config)
  106. if err != nil {
  107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  108. return
  109. }
  110. } else if errs == nil {
  111. modifyConfig := models.DrugStockConfig{
  112. ID: configs.ID,
  113. OrgId: org_id,
  114. IsOpen: is_open,
  115. Status: 1,
  116. CreateTime: time.Now().Unix(),
  117. UpdateTime: time.Now().Unix(),
  118. }
  119. err := service.UpdateDrugStockAutomaticReduceRecord(&modifyConfig)
  120. if err != nil {
  121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  122. return
  123. }
  124. }
  125. c.ServeSuccessJSON(map[string]interface{}{
  126. "is_open": is_open,
  127. })
  128. return
  129. }
  130. func (c *GobalConfigApiController) GetConfig() {
  131. adminUserInfo := c.GetAdminUserInfo()
  132. _, config := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  133. c.ServeSuccessJSON(map[string]interface{}{
  134. "config": config,
  135. })
  136. }
  137. func (c *GobalConfigApiController) GetDrugStockConfig() {
  138. adminUserInfo := c.GetAdminUserInfo()
  139. _, config := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  140. c.ServeSuccessJSON(map[string]interface{}{
  141. "config": config,
  142. })
  143. }
  144. func (c *GobalConfigApiController) PostPrintTemplate() {
  145. template_id, _ := c.GetInt64("template_id", 0)
  146. adminUserInfo := c.GetAdminUserInfo()
  147. org_id := adminUserInfo.CurrentOrgId
  148. template := models.GobalTemplate{
  149. OrgId: org_id,
  150. TemplateId: template_id,
  151. Status: 1,
  152. Ctime: time.Now().Unix(),
  153. Mtime: time.Now().Unix(),
  154. }
  155. errs, templates := service.FindPrintTemplateByOrgId(org_id)
  156. if errs == gorm.ErrRecordNotFound {
  157. err := service.CreatePrintTemplateRecord(&template)
  158. if err != nil {
  159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  160. return
  161. }
  162. } else if errs == nil {
  163. templates := models.GobalTemplate{
  164. ID: templates.ID,
  165. OrgId: org_id,
  166. TemplateId: template_id,
  167. Status: 1,
  168. Ctime: templates.Ctime,
  169. Mtime: time.Now().Unix(),
  170. }
  171. err := service.UpdatePrintTemplate(&templates)
  172. if err != nil {
  173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  174. return
  175. }
  176. }
  177. c.ServeSuccessJSON(map[string]interface{}{
  178. "template_id": template_id,
  179. })
  180. return
  181. }
  182. func (c *GobalConfigApiController) PostPrintTemplateTwo() {
  183. template_id, _ := c.GetInt64("template_id", 0)
  184. adminUserInfo := c.GetAdminUserInfo()
  185. org_id := adminUserInfo.CurrentOrgId
  186. template := models.GobalTemplate{
  187. OrgId: org_id,
  188. TemplateId: template_id,
  189. Status: 1,
  190. Ctime: time.Now().Unix(),
  191. Mtime: time.Now().Unix(),
  192. }
  193. errs, templates := service.FindPrintTemplateByOrgId(org_id)
  194. if errs == gorm.ErrRecordNotFound {
  195. err := service.CreatePrintTemplateRecord(&template)
  196. if err != nil {
  197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  198. return
  199. }
  200. if err == nil { //处理模版切换,显示配置处理逻辑
  201. //service.FindAllConfig
  202. //先将所有数据设置为显示
  203. updateErr := service.UpdateFiledConfig(adminUserInfo.CurrentOrgId)
  204. if updateErr == nil {
  205. //查出该模版对应显示配置字段中所有隐藏的字段
  206. _, config := service.FindAllHideFiledConfig(template_id)
  207. var fileds []string
  208. for _, item := range config {
  209. fileds = append(fileds, item.FiledName)
  210. }
  211. service.UpdateShowFieldConfig(adminUserInfo.CurrentOrgId, fileds)
  212. }
  213. }
  214. FiledList, _ := service.FindFiledByOrgId(adminUserInfo.CurrentOrgId)
  215. c.ServeSuccessJSON(map[string]interface{}{
  216. "template_id": template_id,
  217. "fileds": FiledList,
  218. })
  219. } else if errs == nil {
  220. templates := models.GobalTemplate{
  221. ID: templates.ID,
  222. OrgId: org_id,
  223. TemplateId: template_id,
  224. Status: 1,
  225. Ctime: templates.Ctime,
  226. Mtime: time.Now().Unix(),
  227. }
  228. err := service.UpdatePrintTemplate(&templates)
  229. if err != nil {
  230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  231. return
  232. }
  233. if err == nil { //处理模版切换,显示配置处理逻辑
  234. //service.FindAllConfig
  235. //先将所有数据设置为显示
  236. updateErr := service.UpdateFiledConfig(adminUserInfo.CurrentOrgId)
  237. if updateErr == nil {
  238. //查出该模版对应显示配置字段中所有隐藏的字段
  239. _, config := service.FindAllHideFiledConfig(template_id)
  240. var fileds []string
  241. for _, item := range config {
  242. fileds = append(fileds, item.FiledName)
  243. }
  244. service.UpdateShowFieldConfig(adminUserInfo.CurrentOrgId, fileds)
  245. }
  246. }
  247. FiledList, _ := service.FindFiledByOrgId(adminUserInfo.CurrentOrgId)
  248. c.ServeSuccessJSON(map[string]interface{}{
  249. "template_id": template_id,
  250. "fileds": FiledList,
  251. })
  252. return
  253. }
  254. }
  255. func (c *GobalConfigApiController) GetPrintTemplate() {
  256. adminUserInfo := c.GetAdminUserInfo()
  257. _, template := service.FindPrintTemplateByOrgId(adminUserInfo.CurrentOrgId)
  258. c.ServeSuccessJSON(map[string]interface{}{
  259. "template": template,
  260. })
  261. }
  262. func (c *GobalConfigApiController) PostConfig() {
  263. gateway_address := c.GetString("gateway_address")
  264. app_id := c.GetString("app_id")
  265. key := c.GetString("key")
  266. config_type, _ := c.GetInt64("config_type")
  267. time_type, _ := c.GetInt64("time_type")
  268. province, _ := c.GetInt64("province")
  269. city, _ := c.GetInt64("city")
  270. if config_type > 1 {
  271. _, err := service.GetDockingStatus(config_type, province, city)
  272. if err == gorm.ErrRecordNotFound {
  273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotDocking)
  274. return
  275. }
  276. }
  277. adminUserInfo := c.GetAdminUserInfo()
  278. org_id := adminUserInfo.CurrentOrgId
  279. config := &models.DataUploadConfig{
  280. OrgId: org_id,
  281. ProvinceId: province,
  282. CityId: city,
  283. GatewayAddress: gateway_address,
  284. AppId: app_id,
  285. Key: key,
  286. Status: 1,
  287. CreateTime: time.Now().Unix(),
  288. ModifyTime: time.Now().Unix(),
  289. TimeQuantum: time_type,
  290. ConfigType: config_type,
  291. }
  292. err := service.CreateConfigData(config)
  293. if err == nil {
  294. c.ServeSuccessJSON(map[string]interface{}{
  295. "config": config,
  296. })
  297. } else {
  298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  299. return
  300. }
  301. }
  302. func (c *GobalConfigApiController) GetDataUploadConfig() {
  303. config_type, _ := c.GetInt64("config_type")
  304. adminUserInfo := c.GetAdminUserInfo()
  305. org_id := adminUserInfo.CurrentOrgId
  306. config, err := service.GetConfigData(org_id, config_type)
  307. fmt.Println(err)
  308. if err == nil {
  309. c.ServeSuccessJSON(map[string]interface{}{
  310. "config": config,
  311. })
  312. } else {
  313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  314. return
  315. }
  316. }
  317. func (c *GobalConfigApiController) GetDataUploadIsDocking() {
  318. config_type, _ := c.GetInt64("config_type")
  319. province, _ := c.GetInt64("province")
  320. city, _ := c.GetInt64("city")
  321. config, err := service.GetDockingStatus(config_type, province, city)
  322. fmt.Println(config)
  323. fmt.Println(err)
  324. if err == gorm.ErrRecordNotFound {
  325. c.ServeSuccessJSON(map[string]interface{}{
  326. "is_docking": 2,
  327. })
  328. } else if err == nil {
  329. if config.ID > 0 {
  330. c.ServeSuccessJSON(map[string]interface{}{
  331. "is_docking": 1,
  332. })
  333. } else {
  334. c.ServeSuccessJSON(map[string]interface{}{
  335. "is_docking": 2,
  336. })
  337. }
  338. }
  339. }
  340. func (c *GobalConfigApiController) ModifyConfig() {
  341. id, _ := c.GetInt64("id")
  342. gateway_address := c.GetString("gateway_address")
  343. app_id := c.GetString("app_id")
  344. key := c.GetString("key")
  345. config_type, _ := c.GetInt64("config_type")
  346. time_type, _ := c.GetInt64("time_type")
  347. province, _ := c.GetInt64("province")
  348. city, _ := c.GetInt64("city")
  349. adminUserInfo := c.GetAdminUserInfo()
  350. org_id := adminUserInfo.CurrentOrgId
  351. if config_type > 1 {
  352. _, err := service.GetDockingStatus(config_type, province, city)
  353. if err == gorm.ErrRecordNotFound {
  354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotDocking)
  355. return
  356. }
  357. }
  358. tempConfig, _ := service.GetConfigDataById(id)
  359. config := &models.DataUploadConfig{
  360. ID: tempConfig.ID,
  361. OrgId: org_id,
  362. ProvinceId: province,
  363. CityId: city,
  364. GatewayAddress: gateway_address,
  365. AppId: app_id,
  366. Key: key,
  367. Status: 1,
  368. CreateTime: tempConfig.CreateTime,
  369. ModifyTime: time.Now().Unix(),
  370. TimeQuantum: time_type,
  371. ConfigType: config_type,
  372. }
  373. err := service.SaveConfigData(config)
  374. if err == nil {
  375. c.ServeSuccessJSON(map[string]interface{}{
  376. "config": config,
  377. })
  378. } else {
  379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  380. return
  381. }
  382. }
  383. func (c *GobalConfigApiController) PostDoctorAdviceConfig() {
  384. is_open_remind, _ := c.GetInt64("is_open_remind", 0)
  385. adminUserInfo := c.GetAdminUserInfo()
  386. org_id := adminUserInfo.CurrentOrgId
  387. config := models.DoctorAdviceConfig{
  388. UserOrgId: org_id,
  389. IsOpenRemind: is_open_remind,
  390. Status: 1,
  391. CreateTime: time.Now().Unix(),
  392. UpdateTime: time.Now().Unix(),
  393. }
  394. errs, configs := service.FindDoctorAdviceRecordByOrgId(org_id)
  395. if errs == gorm.ErrRecordNotFound {
  396. err := service.CreateDoctorAdviceRecord(&config)
  397. if err != nil {
  398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  399. return
  400. }
  401. } else if errs == nil {
  402. modifyConfig := models.DoctorAdviceConfig{
  403. ID: configs.ID,
  404. UserOrgId: org_id,
  405. Status: 1,
  406. CreateTime: time.Now().Unix(),
  407. UpdateTime: time.Now().Unix(),
  408. IsOpenRemind: is_open_remind,
  409. }
  410. err := service.UpdateDoctorAdviceRecord(&modifyConfig)
  411. if err != nil {
  412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  413. return
  414. }
  415. }
  416. c.ServeSuccessJSON(map[string]interface{}{
  417. "is_open_remind": is_open_remind,
  418. })
  419. return
  420. }
  421. func (c *GobalConfigApiController) GetDoctorAdviceConfig() {
  422. adminUserInfo := c.GetAdminUserInfo()
  423. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  424. c.ServeSuccessJSON(map[string]interface{}{
  425. "config": config,
  426. })
  427. }
  428. //SF6090214798525
  429. func (c *GobalConfigApiController) Load(filename string, v interface{}) {
  430. //ReadFile函数会读取文件的全部内容,并将结果以[]byte类型返回
  431. data, err := ioutil.ReadFile(filename)
  432. if err != nil {
  433. return
  434. }
  435. //读取的数据为json格式,需要进行解码
  436. err = json.Unmarshal(data, v)
  437. if err != nil {
  438. return
  439. }
  440. }
  441. type Config struct {
  442. Parent_template []*models.VMDoctorAdviceParentTemplate "json:parent_template"
  443. }
  444. func LoadConfig(dataFile string) *Config {
  445. var config Config
  446. _, filename, _, _ := runtime.Caller(1)
  447. datapath := path.Join(path.Dir(filename), dataFile)
  448. config_file, err := os.Open(datapath)
  449. if err != nil {
  450. emit("Failed to open config file '%s': %s\n", datapath, err)
  451. return &config
  452. }
  453. fi, _ := config_file.Stat()
  454. buffer := make([]byte, fi.Size())
  455. _, err = config_file.Read(buffer)
  456. buffer, err = StripComments(buffer) //去掉注释
  457. if err != nil {
  458. emit("Failed to strip comments from json: %s\n", err)
  459. return &config
  460. }
  461. buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
  462. err = json.Unmarshal(buffer, &config) //解析json格式数据
  463. if err != nil {
  464. emit("Failed unmarshalling json: %s\n", err)
  465. return &config
  466. }
  467. return &config
  468. }
  469. func StripComments(data []byte) ([]byte, error) {
  470. data = bytes.Replace(data, []byte("\r"), []byte(""), 0) // Windows
  471. lines := bytes.Split(data, []byte("\n")) //split to muli lines
  472. filtered := make([][]byte, 0)
  473. for _, line := range lines {
  474. match, err := regexp.Match(`^\s*#`, line)
  475. if err != nil {
  476. return nil, err
  477. }
  478. if !match {
  479. filtered = append(filtered, line)
  480. }
  481. }
  482. return bytes.Join(filtered, []byte("\n")), nil
  483. }
  484. func emit(msgfmt string, args ...interface{}) {
  485. log.Printf(msgfmt, args...)
  486. }
  487. func (c *GobalConfigApiController) GetAdviceInitConfig() {
  488. adminUserInfo := c.GetAdminUserInfo()
  489. advice_init, _ := service.FindAdviceInitConfig(adminUserInfo.CurrentOrgId)
  490. c.ServeSuccessJSON(map[string]interface{}{
  491. "advice_init": advice_init,
  492. })
  493. }
  494. func (c *GobalConfigApiController) PostInitAdviceTemplate() {
  495. is_init, _ := c.GetInt64("is_init")
  496. adminUserInfo := c.GetAdminUserInfo()
  497. adviceInit := &models.AdviceInit{
  498. UserOrgId: adminUserInfo.CurrentOrgId,
  499. CreateTime: time.Now().Unix(),
  500. UpdateTime: time.Now().Unix(),
  501. Status: 1,
  502. IsInit: is_init,
  503. }
  504. adviceParentTemplate := LoadConfig("./advice_template.json").Parent_template
  505. for _, item := range adviceParentTemplate {
  506. parentTemplate := &models.DoctorAdviceParentTemplate{
  507. OrgId: adminUserInfo.CurrentOrgId,
  508. Name: item.Name,
  509. Status: 1,
  510. CreatedTime: time.Now().Unix(),
  511. UpdatedTime: time.Now().Unix(),
  512. AdviceType: item.AdviceType,
  513. }
  514. createErr := service.CreateDoctorParentTemplate(parentTemplate)
  515. fmt.Println(parentTemplate.ID)
  516. if createErr == nil {
  517. for _, adviceTemplateItem := range item.DoctorAdviceTemplate {
  518. adviceTeplate := &models.DoctorAdviceTemplate{
  519. OrgId: adminUserInfo.CurrentOrgId,
  520. AdviceName: adviceTemplateItem.AdviceName,
  521. AdviceDesc: adviceTemplateItem.AdviceDesc,
  522. SingleDose: adviceTemplateItem.SingleDose,
  523. SingleDoseUnit: adviceTemplateItem.SingleDoseUnit,
  524. PrescribingNumber: adviceTemplateItem.PrescribingNumber,
  525. PrescribingNumberUnit: adviceTemplateItem.PrescribingNumberUnit,
  526. DeliveryWay: adviceTemplateItem.DeliveryWay,
  527. ExecutionFrequency: adviceTemplateItem.ExecutionFrequency,
  528. AdviceDoctor: adviceTemplateItem.AdviceDoctor,
  529. Status: 1,
  530. CreatedTime: time.Now().Unix(),
  531. UpdatedTime: time.Now().Unix(),
  532. TemplateId: parentTemplate.ID,
  533. DrugSpec: adviceTemplateItem.DrugSpec,
  534. DrugSpecUnit: adviceTemplateItem.DrugSpecUnit,
  535. ParentId: adviceTemplateItem.ParentId,
  536. AdviceType: adviceTemplateItem.AdviceType,
  537. DayCount: adviceTemplateItem.DayCount,
  538. WeekDays: adviceTemplateItem.WeekDays,
  539. FrequencyType: adviceTemplateItem.FrequencyType,
  540. }
  541. createErr := service.CreateDoctorTemplate(adviceTeplate)
  542. if createErr == nil {
  543. for _, childItem := range adviceTemplateItem.SubDoctorAdviceTemplate {
  544. adviceTeplate := &models.DoctorAdviceTemplate{
  545. OrgId: adminUserInfo.CurrentOrgId,
  546. AdviceName: childItem.AdviceName,
  547. AdviceDesc: childItem.AdviceDesc,
  548. SingleDose: childItem.SingleDose,
  549. SingleDoseUnit: childItem.SingleDoseUnit,
  550. PrescribingNumber: childItem.PrescribingNumber,
  551. PrescribingNumberUnit: childItem.PrescribingNumberUnit,
  552. DeliveryWay: childItem.DeliveryWay,
  553. ExecutionFrequency: childItem.ExecutionFrequency,
  554. AdviceDoctor: childItem.AdviceDoctor,
  555. Status: 1,
  556. CreatedTime: time.Now().Unix(),
  557. UpdatedTime: time.Now().Unix(),
  558. TemplateId: parentTemplate.ID,
  559. DrugSpec: childItem.DrugSpec,
  560. DrugSpecUnit: childItem.DrugSpecUnit,
  561. ParentId: adviceTeplate.ID,
  562. AdviceType: childItem.AdviceType,
  563. DayCount: childItem.DayCount,
  564. WeekDays: childItem.WeekDays,
  565. FrequencyType: childItem.FrequencyType,
  566. }
  567. service.CreateDoctorTemplate(adviceTeplate)
  568. }
  569. }
  570. }
  571. }
  572. }
  573. err := service.CreateAdviceInitConfig(adviceInit)
  574. if err == nil {
  575. c.ServeSuccessJSON(map[string]interface{}{
  576. "init_config": adviceInit,
  577. })
  578. } else {
  579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  580. return
  581. }
  582. }
  583. func (c *GobalConfigApiController) CreateSystemPrescription() {
  584. adminUserInfo := c.GetAdminUserInfo()
  585. var solution models.SystemPrescription
  586. code := defaultSystemSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  587. if code > 0 {
  588. c.ServeFailJSONWithSGJErrorCode(code)
  589. return
  590. }
  591. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  592. solution.Doctor = adminUserInfo.AdminUser.Id
  593. solution.Status = 1
  594. solution.CreatedTime = time.Now().Unix()
  595. solution.UserOrgId = adminUserInfo.CurrentOrgId
  596. solution.UpdatedTime = time.Now().Unix()
  597. err := service.CreateSystemDialysisSolution(&solution)
  598. if err != nil {
  599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  600. return
  601. }
  602. prescriptions, _ := service.FindAllSystemPrescription(adminUserInfo.CurrentOrgId)
  603. c.ServeSuccessJSON(map[string]interface{}{
  604. "prescription": solution,
  605. "prescriptions": prescriptions,
  606. })
  607. return
  608. }
  609. func (c *GobalConfigApiController) UpdateSystemPrescription() {
  610. id, _ := c.GetInt64("id", 0)
  611. if id <= 0 {
  612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  613. return
  614. }
  615. adminUserInfo := c.GetAdminUserInfo()
  616. solution, _ := service.FindSystemDialysisSolution(adminUserInfo.CurrentOrgId, id)
  617. if solution.ID == 0 {
  618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  619. return
  620. }
  621. code := defaultSystemSolutionFormData(&solution, c.Ctx.Input.RequestBody, "edit")
  622. if code > 0 {
  623. c.ServeFailJSONWithSGJErrorCode(code)
  624. return
  625. }
  626. solution.UpdatedTime = time.Now().Unix()
  627. solution.Doctor = adminUserInfo.AdminUser.Id
  628. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  629. err := service.UpdateSystemDialysisSolution(&solution)
  630. if err != nil {
  631. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  632. return
  633. }
  634. c.ServeSuccessJSON(map[string]interface{}{
  635. "msg": "ok",
  636. "prescription": solution,
  637. })
  638. return
  639. }
  640. func (c *GobalConfigApiController) GetAllSystemPrescription() {
  641. adminUserInfo := c.GetAdminUserInfo()
  642. prescriptions, _ := service.FindAllSystemPrescription(adminUserInfo.CurrentOrgId)
  643. c.ServeSuccessJSON(map[string]interface{}{
  644. "prescriptions": prescriptions,
  645. })
  646. }
  647. func (c *GobalConfigApiController) GetSystemPrescription() {
  648. adminUserInfo := c.GetAdminUserInfo()
  649. id, _ := c.GetInt64("id", 0)
  650. prescription, _ := service.FindSystemDialysisPrescriptionByMode(adminUserInfo.CurrentOrgId, id)
  651. c.ServeSuccessJSON(map[string]interface{}{
  652. "prescription": prescription,
  653. })
  654. }
  655. func defaultSystemSolutionFormData(solution *models.SystemPrescription, data []byte, method string) (code int) {
  656. dataBody := make(map[string]interface{}, 0)
  657. err := json.Unmarshal(data, &dataBody)
  658. utils.InfoLog(string(data))
  659. if err != nil {
  660. utils.ErrorLog(err.Error())
  661. code = enums.ErrorCodeParamWrong
  662. return
  663. }
  664. if method == "create" {
  665. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  666. utils.ErrorLog("mode")
  667. code = enums.ErrorCodeParamWrong
  668. return
  669. }
  670. mode := int64(dataBody["mode"].(float64))
  671. if mode <= 0 {
  672. utils.ErrorLog("mode <= 0")
  673. code = enums.ErrorCodeParamWrong
  674. return
  675. }
  676. solution.ModeId = mode
  677. }
  678. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  679. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  680. solution.DialysisDuration = dialysisDuration
  681. }
  682. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  683. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  684. solution.TargetUltrafiltration = targetUltrafiltration
  685. }
  686. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  687. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  688. solution.DialysateFormulation = dialysateFormulation
  689. }
  690. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  691. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  692. solution.DialysisDurationHour = int64(dialysisDurationHour)
  693. }
  694. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  695. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  696. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  697. }
  698. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  699. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  700. solution.HemodialysisMachine = hemodialysisMachine
  701. }
  702. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  703. dialyzer := int64(dataBody["dialyzer"].(float64))
  704. solution.Dialyzer = dialyzer
  705. }
  706. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  707. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  708. solution.PerfusionApparatus = perfusionApparatus
  709. }
  710. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  711. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  712. solution.BloodFlowVolume = bloodFlowVolume
  713. }
  714. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  715. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  716. solution.Dewater = dewater
  717. }
  718. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  719. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  720. solution.DisplaceLiqui = displaceLiqui
  721. }
  722. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  723. replacementWay := int64(dataBody["replacement_way"].(float64))
  724. solution.ReplacementWay = replacementWay
  725. }
  726. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  727. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  728. solution.Anticoagulant = anticoagulant
  729. }
  730. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  731. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  732. solution.AnticoagulantShouji = anticoagulantShouji
  733. }
  734. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  735. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  736. solution.AnticoagulantWeichi = anticoagulantWeichi
  737. }
  738. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  739. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  740. solution.AnticoagulantZongliang = anticoagulantZongliang
  741. }
  742. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  743. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  744. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  745. }
  746. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  747. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  748. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  749. }
  750. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  751. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  752. solution.Kalium = kalium
  753. }
  754. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  755. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  756. solution.Sodium = sodium
  757. }
  758. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  759. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  760. solution.Calcium = calcium
  761. }
  762. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  763. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  764. solution.Bicarbonate = bicarbonate
  765. }
  766. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  767. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  768. solution.Glucose = glucose
  769. }
  770. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  771. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  772. // solution.DryWeight = dryWeight
  773. // }
  774. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  775. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  776. solution.DialysateFlow = dialysateFlow
  777. }
  778. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  779. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  780. solution.DialysateTemperature = dialysateTemperature
  781. }
  782. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  783. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  784. solution.Conductivity = conductivity
  785. }
  786. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  787. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  788. solution.ReplacementTotal = replacementTotal
  789. }
  790. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  791. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  792. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  793. }
  794. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  795. body_fluid := int64(dataBody["body_fluid"].(float64))
  796. solution.BodyFluid = body_fluid
  797. }
  798. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  799. body_fluid_other := dataBody["body_fluid_other"].(string)
  800. solution.BodyFluidOther = body_fluid_other
  801. }
  802. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  803. special_medicine := int64(dataBody["special_medicine"].(float64))
  804. solution.SpecialMedicine = special_medicine
  805. }
  806. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  807. special_medicine_other := dataBody["special_medicine_other"].(string)
  808. solution.SpecialMedicineOther = special_medicine_other
  809. }
  810. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  811. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  812. solution.DisplaceLiquiPart = displace_liqui_part
  813. }
  814. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  815. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  816. solution.DisplaceLiquiValue = displace_liqui_value
  817. }
  818. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  819. blood_access := int64(dataBody["blood_access"].(float64))
  820. solution.BloodAccess = blood_access
  821. }
  822. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  823. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  824. solution.Ultrafiltration = ultrafiltration
  825. }
  826. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  827. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  828. solution.TargetKtv = target_ktv
  829. }
  830. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  831. remark := dataBody["remark"].(string)
  832. solution.Remark = remark
  833. }
  834. return
  835. }
  836. func (c *GobalConfigApiController) GetPrintInfo() {
  837. adminUserInfo := c.GetAdminUserInfo()
  838. OrgID := adminUserInfo.CurrentOrgId
  839. dataBody := make(map[string]interface{}, 0)
  840. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  841. idsInters := dataBody["ids"].([]interface{})
  842. if len(idsInters) == 0 {
  843. if err != nil {
  844. c.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
  845. return
  846. }
  847. }
  848. ids := make([]int64, 0)
  849. for _, idsInter := range idsInters {
  850. id := int64(idsInter.(float64))
  851. ids = append(ids, id)
  852. }
  853. getPrint, err := service.GetPrint(ids, OrgID)
  854. c.ServeSuccessJSON(map[string]interface{}{
  855. "doctoradvice": getPrint,
  856. })
  857. }
  858. func (c *GobalConfigApiController) GetOrgs() {
  859. adminUserInfo := c.GetAdminUserInfo()
  860. //获取当前人姓名
  861. var id = adminUserInfo.AdminUser.Id
  862. orgId := adminUserInfo.CurrentOrgId
  863. var orgs []*models.Org
  864. adminUser, err := service.GetHomeData(adminUserInfo.AdminUser.Id)
  865. creator, err := service.GetCreator(id, orgId)
  866. admin, err := service.GetSuperAdmin(id)
  867. if err != nil {
  868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  869. return
  870. }
  871. for _, item := range adminUser.Org {
  872. orgs = append(orgs, item)
  873. }
  874. for _, item := range adminUser.VMApp_Role {
  875. for _, subItem := range item.Org {
  876. orgs = append(orgs, subItem)
  877. }
  878. }
  879. orgs = RemoveRepeatedOrgElement(orgs)
  880. c.ServeSuccessJSON(map[string]interface{}{
  881. "orgs": orgs,
  882. "adminUser": adminUser,
  883. "creator": creator,
  884. "admin": admin,
  885. })
  886. }
  887. func (this *GobalConfigApiController) ChangeOrg() {
  888. org_id, _ := this.GetInt64("org_id")
  889. adminUserInfo := this.GetAdminUserInfo()
  890. tempOrg, err := service.GetOrgById(org_id)
  891. if err != nil {
  892. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  893. return
  894. }
  895. if tempOrg == nil {
  896. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrgNoExist)
  897. return
  898. }
  899. mobile := adminUserInfo.AdminUser.Mobile
  900. // 只取最近被创建的 admin_role
  901. adminUser, getAdminErr := service.GetValidAdminUserByMobileReturnErr(mobile) //账号信息唯一值
  902. if getAdminErr != nil {
  903. utils.ErrorLog("获取管理员失败:%v", getAdminErr)
  904. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  905. this.ServeJSON()
  906. return
  907. } else if adminUser == nil {
  908. utils.ErrorLog("查找不到 mobile = %v 的用户", mobile)
  909. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeAccountOrPasswordWrong)
  910. this.ServeJSON()
  911. return
  912. } else {
  913. adminUserInfo.CurrentOrgId = tempOrg.Id
  914. orgApp, _ := service.GetOrgApp(tempOrg.Id, 3)
  915. subscibe, _ := service.GetOrgSubscibe(tempOrg.Id)
  916. adminUserInfo.CurrentAppId = orgApp.Id
  917. appRole, _ := service.GetAppRole(tempOrg.Id, orgApp.Id, adminUserInfo.AdminUser.Id)
  918. var FiledList []*models.FiledConfig
  919. FiledList, _ = service.FindFiledByOrgId(tempOrg.Id)
  920. if len(FiledList) == 0 {
  921. err := service.BatchInsertFiledConfig(tempOrg.Id)
  922. if err == nil {
  923. FiledList, _ = service.FindFiledByOrgId(tempOrg.Id)
  924. } else {
  925. utils.ErrorLog("字段批量插入失败:%v", err)
  926. }
  927. }
  928. //产寻该机构是否有收缩压和舒张压
  929. pressure, err := service.GetDefaultSystolicPressure(tempOrg.Id)
  930. fmt.Println(err)
  931. if len(pressure) == 0 {
  932. err = service.BathInsertQualityControlTwo(tempOrg.Id)
  933. } else {
  934. utils.ErrorLog("字段批量插入失败:%v", err)
  935. }
  936. major, err := service.GetInspectionMajor(tempOrg.Id)
  937. if len(major) == 0 {
  938. QualityeList, err := service.FindQualityByOrgId(tempOrg.Id)
  939. if len(QualityeList) == 0 {
  940. err = service.BatchInsertQualityControl(tempOrg.Id)
  941. } else {
  942. utils.ErrorLog("字段批量插入失败:%v", err)
  943. }
  944. InspectionList, err := service.FindeInspectionByOrgId(tempOrg.Id)
  945. if len(InspectionList) == 0 {
  946. err = service.BatchInspectionConfiguration(tempOrg.Id)
  947. } else {
  948. utils.ErrorLog("字段批量插入失败:%v", err)
  949. }
  950. } else {
  951. utils.ErrorLog("字段批量插入失败:%v", err)
  952. }
  953. //查询该机构是否存在医护排班
  954. _, errcode := service.GetDoctorScheduleByOrgId(tempOrg.Id)
  955. //如果没有就插入
  956. if errcode == gorm.ErrRecordNotFound {
  957. err = service.BatchInsertDoctorSchedule(tempOrg.Id)
  958. } else {
  959. utils.ErrorLog("医护排班默认数据插入失败:%v", err)
  960. }
  961. var didRegistedForSCRM bool = false
  962. var didRegistedForCDM bool = false
  963. var didRegistedForMall bool = false
  964. var curAppUrlfors []string
  965. var pruviews []*models.Purview
  966. if len(curAppUrlfors) == 0 {
  967. if adminUser.Id == tempOrg.Creator {
  968. urlfors_xt, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(3)
  969. urlfors_cdm, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(4)
  970. urlfors_scrm, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(6)
  971. urlfors_mall, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(7)
  972. curAppUrlfors = append(curAppUrlfors, urlfors_xt...)
  973. curAppUrlfors = append(curAppUrlfors, urlfors_scrm...)
  974. curAppUrlfors = append(curAppUrlfors, urlfors_cdm...)
  975. curAppUrlfors = append(curAppUrlfors, urlfors_mall...)
  976. didRegistedForSCRM = true
  977. didRegistedForCDM = true
  978. didRegistedForMall = true
  979. } else {
  980. appRole, _ := service.FindAdminUserIDA(appRole.Id)
  981. if appRole.Id > 0 && len(appRole.RoleIds) > 0 {
  982. role_arr := strings.Split(appRole.RoleIds, ",")
  983. var ids string
  984. for _, role_id := range role_arr {
  985. id, _ := strconv.ParseInt(role_id, 10, 64)
  986. purview_ids, _ := service.GetRolePurviewIds(id)
  987. if len(ids) == 0 {
  988. ids = purview_ids
  989. } else {
  990. ids = ids + "," + purview_ids
  991. }
  992. }
  993. if len(ids) != 0 {
  994. pruviews, _ = service.GetPurviewById(ids)
  995. for _, item := range pruviews {
  996. if item.Module == 3 && item.Parentid > 0 {
  997. fmt.Println(item.Urlfor)
  998. curAppUrlfors = append(curAppUrlfors, item.Urlfor)
  999. }
  1000. }
  1001. } else {
  1002. curAppUrlfors = append(curAppUrlfors, "")
  1003. }
  1004. } else {
  1005. curAppUrlfors = append(curAppUrlfors, "")
  1006. }
  1007. for _, item := range pruviews {
  1008. if item.Module == 6 {
  1009. didRegistedForSCRM = true
  1010. }
  1011. if item.Module == 4 {
  1012. didRegistedForCDM = true
  1013. }
  1014. if item.Module == 7 {
  1015. didRegistedForMall = true
  1016. }
  1017. }
  1018. }
  1019. }
  1020. userInfo := map[string]interface{}{
  1021. "id": adminUser.Id,
  1022. "mobile": adminUser.Mobile,
  1023. "user_name": appRole.UserName,
  1024. "avatar": appRole.Avatar,
  1025. "intro": appRole.Intro,
  1026. "user_type": appRole.UserType,
  1027. "user_title": appRole.UserTitle,
  1028. }
  1029. org := map[string]interface{}{
  1030. "id": tempOrg.Id,
  1031. "org_name": tempOrg.OrgName,
  1032. "org_short_name": tempOrg.OrgShortName,
  1033. "org_intro": tempOrg.OrgIntroduction,
  1034. "org_logo": tempOrg.OrgLogo,
  1035. "province": tempOrg.Province,
  1036. "city": tempOrg.City,
  1037. "district": tempOrg.District,
  1038. "address": tempOrg.Address,
  1039. }
  1040. tempInfo, _ := service.GetOrgInfoTemplate(tempOrg.Id)
  1041. template_info := map[string]interface{}{
  1042. "id": tempInfo.ID,
  1043. "org_id": tempInfo.OrgId,
  1044. "template_id": tempInfo.TemplateId,
  1045. }
  1046. if tempOrg != nil && appRole != nil {
  1047. // 插入一条登录记录
  1048. ip := this.GetString("ip")
  1049. loginLog := &models.AdminUserLoginLog{
  1050. AdminUserId: adminUser.Id,
  1051. OrgId: tempOrg.Id,
  1052. AppId: appRole.AppId,
  1053. IP: ip,
  1054. OperateType: 3,
  1055. AppType: 3,
  1056. CreateTime: time.Now().Unix(),
  1057. }
  1058. if insertErr := service.InsertLoginLog(loginLog); insertErr != nil {
  1059. utils.ErrorLog("为手机号为%v的用户插入一条登录记录失败:%v", mobile, insertErr)
  1060. }
  1061. }
  1062. this.SetSession("admin_user_info", adminUserInfo)
  1063. this.ServeSuccessJSON(map[string]interface{}{
  1064. "user": userInfo,
  1065. "org": org,
  1066. "urlfors": curAppUrlfors,
  1067. "current_org_id": adminUserInfo.CurrentOrgId,
  1068. "current_app_id": adminUserInfo.CurrentAppId,
  1069. "subscibe": subscibe,
  1070. "template_info": template_info,
  1071. "fileds": FiledList,
  1072. "scrm_role_exist": didRegistedForSCRM,
  1073. "cdm_role_exist": didRegistedForCDM,
  1074. "mall_role_exist": didRegistedForMall,
  1075. })
  1076. }
  1077. }
  1078. func RemoveRepeatedOrgElement(orgs []*models.Org) (newOrgs []*models.Org) {
  1079. newOrgs = make([]*models.Org, 0)
  1080. for i := 0; i < len(orgs); i++ {
  1081. repeat := false
  1082. for j := i + 1; j < len(orgs); j++ {
  1083. if orgs[i].Id == orgs[j].Id {
  1084. repeat = true
  1085. break
  1086. }
  1087. }
  1088. if !repeat {
  1089. newOrgs = append(newOrgs, orgs[i])
  1090. }
  1091. }
  1092. return
  1093. }
  1094. func (this *GobalConfigApiController) GenerateLog() {
  1095. log_type, _ := this.GetInt64("log_type", 0)
  1096. logs, err := service.GetExportLogByType(this.GetAdminUserInfo().CurrentOrgId, log_type)
  1097. if err != nil {
  1098. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1099. return
  1100. }
  1101. this.ServeSuccessJSON(map[string]interface{}{
  1102. "logs": logs,
  1103. })
  1104. }
  1105. func (this *GobalConfigApiController) GetPatientsByKeyWord() {
  1106. keyWord := this.GetString("keyword")
  1107. adminUserInfo := this.GetAdminUserInfo()
  1108. patient, err := service.GetPatientsByKey(adminUserInfo.CurrentOrgId, keyWord)
  1109. if err != nil {
  1110. utils.ErrorLog(err.Error())
  1111. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1112. return
  1113. }
  1114. this.ServeSuccessJSON(map[string]interface{}{
  1115. "patient": patient,
  1116. })
  1117. }