gobal_config_api_controller.go 37KB

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