gobal_config_api_controller.go 38KB

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