gobal_config_api_controller.go 36KB

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