gobal_config_api_controller.go 39KB

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