mobile_regist_controller.go 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281
  1. package new_mobile_api_controllers
  2. import (
  3. "XT_New/controllers/mobile_api_controllers"
  4. "XT_New/enums"
  5. "XT_New/models"
  6. "XT_New/service"
  7. "XT_New/utils"
  8. "bytes"
  9. "encoding/json"
  10. "fmt"
  11. "github.com/astaxie/beego"
  12. "io/ioutil"
  13. "log"
  14. "net/http"
  15. "net/url"
  16. "os"
  17. "path"
  18. "regexp"
  19. "runtime"
  20. "strconv"
  21. "time"
  22. )
  23. type MobileRegistController struct {
  24. mobile_api_controllers.MobileBaseAPIController
  25. }
  26. // /mobile/regist [get]
  27. // /mobile/regist/submit [post]
  28. // @param mobile:string
  29. // @param password:string
  30. // @param code:string
  31. func (this *MobileRegistController) RegistSubmit() {
  32. mobile := this.GetString("mobile")
  33. pwd := this.GetString("password")
  34. code := this.GetString("code")
  35. // 判断手机号是否存在
  36. if utils.CellPhoneRegexp().MatchString(mobile) == false {
  37. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMobileFormat)
  38. return
  39. }
  40. if len(pwd) == 0 {
  41. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePasswordEmpty)
  42. return
  43. }
  44. if len(code) == 0 {
  45. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeVerificationCodeWrong)
  46. return
  47. }
  48. if service.IsMobileRegister(mobile) == true {
  49. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMobileRegistered)
  50. return
  51. }
  52. if code == "13535547901" {
  53. admin, err := service.RegisterSuperAdmin(mobile, pwd)
  54. if err != nil {
  55. this.ServeFailJSONWithSGJErrorCode(err.Code)
  56. return
  57. } else {
  58. this.Ctx.SetCookie("mobile", mobile)
  59. this.SetSession("mobile_admin_user", admin)
  60. this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
  61. "result": true,
  62. "id": admin.Id,
  63. })
  64. this.ServeJSON()
  65. }
  66. } else {
  67. redisClient := service.RedisClient()
  68. defer redisClient.Close()
  69. cache_code, _ := redisClient.Get("code_msg_" + mobile).Result()
  70. if cache_code != code {
  71. //this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeVerificationCodeWrong)
  72. //this.ServeJSON()
  73. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeVerificationCodeWrong)
  74. return
  75. }
  76. admin, err := service.RegisterSuperAdmin(mobile, pwd)
  77. if err != nil {
  78. this.ServeFailJSONWithSGJErrorCode(err.Code)
  79. return
  80. } else {
  81. this.Ctx.SetCookie("mobile", mobile)
  82. this.SetSession("mobile_admin_user", admin)
  83. // 注册成功后验证码就要使其失效
  84. redisClient.Del("code_msg_" + mobile)
  85. this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
  86. "result": true,
  87. "id": admin.Id,
  88. })
  89. this.ServeJSON()
  90. }
  91. }
  92. }
  93. // /mobile/org/create/submit [post]
  94. // @param name:string
  95. // @param province:string 省名
  96. // @param city:string 市名
  97. // @param district:string 区县
  98. // @param address:string
  99. // @param category:int
  100. // @param contact_name:string
  101. // @param org_phone?:string
  102. // @param open_xt?:bool 是否开启血透系统
  103. // @param open_cdm?:bool 是否开启慢病系统
  104. // @param open_scrm?:bool 是否开启SCRM
  105. // @param open_mall?:bool 是否开启Mall
  106. func (this *MobileRegistController) CreateOrg() {
  107. adminUserObj := this.GetSession("mobile_admin_user")
  108. if adminUserObj == nil {
  109. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeLoginTimeout)
  110. this.ServeJSON()
  111. return
  112. }
  113. adminUser := adminUserObj.(*models.AdminUser)
  114. //if didCreateOrg, checkCreateOrgErr := service.DidAdminUserCreateOrg(adminUser.Id); checkCreateOrgErr != nil {
  115. // this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  116. // this.ServeJSON()
  117. // return
  118. //} else if didCreateOrg {
  119. // this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeRepeatCreateOrg)
  120. // this.ServeJSON()
  121. // return
  122. //}
  123. name := this.GetString("org_name")
  124. shortName := name
  125. provinceName := this.GetString("provinces_name")
  126. cityName := this.GetString("city_name")
  127. districtName := this.GetString("district_name")
  128. address := this.GetString("address")
  129. org_type := this.GetString("org_type")
  130. contactName := this.GetString("contact_name")
  131. //openXT, _ := this.GetBool("open_xt")
  132. //openCDM, _ := this.GetBool("open_cdm")
  133. //openSCRM, _ := this.GetBool("open_scrm")
  134. //openMall, _ := this.GetBool("open_mall")
  135. openXT := true
  136. openCDM := false
  137. openSCRM := false
  138. openMall := false
  139. if len(name) == 0 || len(shortName) == 0 || len(contactName) == 0 || len(address) == 0 || len(provinceName) <= 0 || len(cityName) <= 0 || len(districtName) <= 0 || len(org_type) <= 0 {
  140. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  141. this.ServeJSON()
  142. return
  143. }
  144. orgPhone := this.GetString("telephone")
  145. //
  146. //if len(orgPhone) > 0 {
  147. // if utils.PhoneRegexp().MatchString(orgPhone) == false {
  148. // this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodePhone)
  149. // this.ServeJSON()
  150. // return
  151. // }
  152. //}
  153. provinceID := 0
  154. cityID := 0
  155. districtID := 0
  156. province, getProvinceErr := service.GetProvinceWithName(provinceName)
  157. if getProvinceErr != nil {
  158. utils.ErrorLog("查询省名失败:%v", getProvinceErr)
  159. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  160. this.ServeJSON()
  161. return
  162. } else if province != nil {
  163. provinceID = int(province.ID)
  164. city, getCityErr := service.GetCityWithName(province.ID, cityName)
  165. if getCityErr != nil {
  166. utils.ErrorLog("查询城市名失败:%v", getCityErr)
  167. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  168. this.ServeJSON()
  169. return
  170. } else if city != nil {
  171. cityID = int(city.ID)
  172. district, getDistrictErr := service.GetDistrictWithName(city.ID, districtName)
  173. if getDistrictErr != nil {
  174. utils.ErrorLog("查询区县名失败:%v", getDistrictErr)
  175. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  176. this.ServeJSON()
  177. return
  178. } else if district != nil {
  179. districtID = int(district.ID)
  180. }
  181. }
  182. }
  183. orgType := service.GetOrgTypeByName(org_type)
  184. org := &models.Org{
  185. Creator: adminUser.Id,
  186. OrgName: name,
  187. OrgShortName: shortName,
  188. Province: int64(provinceID),
  189. City: int64(cityID),
  190. District: int64(districtID),
  191. Address: address,
  192. OrgType: orgType.ID,
  193. Telephone: orgPhone,
  194. ContactName: contactName,
  195. Claim: 1,
  196. Evaluate: 5,
  197. Status: 1,
  198. CreateTime: time.Now().Unix(),
  199. ModifyTime: time.Now().Unix(),
  200. }
  201. adminUsers, _ := service.GetAdminUserByUserID(adminUser.Id)
  202. createErr := service.CreateOrg(org, adminUsers.Name, openXT, openCDM, openSCRM, openMall) // 创建机构以及所有类型的 app,如果有新类型的平台,则需要在这个方法里面把创建这一新类型的 app 的代码加上
  203. if createErr != nil {
  204. utils.ErrorLog("mobile=%v的超级管理员创建机构失败:%v", adminUser.Mobile, createErr)
  205. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  206. this.ServeJSON()
  207. } else {
  208. //初始化病人和排班相关数据
  209. InitPatientAndSchedule(org)
  210. //初始化透析方案
  211. InitSystemPrescrption(org)
  212. //初始化角色和权限
  213. InitRoleAndPurviews(org)
  214. //初始化设备管理org
  215. InitEquitMentInformation(org)
  216. //初始化显示配置和打印模版
  217. InitShowConfig(org)
  218. //初始化商品类型
  219. InitGoodTypesConfig(org)
  220. //创建完机构后进行登录验证操作
  221. ip := utils.GetIP(this.Ctx.Request)
  222. ssoDomain := beego.AppConfig.String("sso_domain")
  223. api := ssoDomain + "/m/login/pwd"
  224. values := make(url.Values)
  225. values.Set("mobile", adminUser.Mobile)
  226. values.Set("password", adminUser.Password)
  227. values.Set("app_type", "3")
  228. values.Set("ip", ip)
  229. resp, requestErr := http.PostForm(api, values)
  230. if requestErr != nil {
  231. utils.ErrorLog("请求SSO登录接口失败: %v", requestErr)
  232. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  233. return
  234. }
  235. defer resp.Body.Close()
  236. body, ioErr := ioutil.ReadAll(resp.Body)
  237. if ioErr != nil {
  238. utils.ErrorLog("SSO登录接口返回数据读取失败: %v", ioErr)
  239. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  240. return
  241. }
  242. var respJSON map[string]interface{}
  243. utils.InfoLog(string(body))
  244. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  245. utils.ErrorLog("SSO登录接口返回数据解析JSON失败: %v", err)
  246. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  247. return
  248. }
  249. if respJSON["state"].(float64) != 1 {
  250. msg := respJSON["msg"].(string)
  251. utils.ErrorLog("SSO登录接口请求失败: %v", msg)
  252. if int(respJSON["code"].(float64)) == 609 {
  253. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrPasswordWrong)
  254. return
  255. }
  256. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  257. return
  258. } else {
  259. utils.SuccessLog("SSO登录成功")
  260. // 下面这几段 Map=>JSON=>Struct 的流程可能会造成速度很慢
  261. userJSON := respJSON["data"].(map[string]interface{})["admin"].(map[string]interface{})
  262. userJSONBytes, _ := json.Marshal(userJSON)
  263. var adminUser models.AdminUser
  264. if err := json.Unmarshal(userJSONBytes, &adminUser); err != nil {
  265. utils.ErrorLog("解析管理员失败:%v", err)
  266. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  267. return
  268. }
  269. var org models.Org
  270. if respJSON["data"].(map[string]interface{})["org"] != nil {
  271. orgJSON := respJSON["data"].(map[string]interface{})["org"].(map[string]interface{})
  272. orgJSONBytes, _ := json.Marshal(orgJSON)
  273. if err := json.Unmarshal(orgJSONBytes, &org); err != nil {
  274. utils.ErrorLog("解析机构失败:%v", err)
  275. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  276. return
  277. }
  278. }
  279. var app models.OrgApp
  280. if respJSON["data"].(map[string]interface{})["app"] != nil {
  281. appJSON := respJSON["data"].(map[string]interface{})["app"].(map[string]interface{})
  282. appJSONBytes, _ := json.Marshal(appJSON)
  283. if err := json.Unmarshal(appJSONBytes, &app); err != nil {
  284. utils.ErrorLog("解析应用失败:%v", err)
  285. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  286. return
  287. }
  288. }
  289. var appRole models.App_Role
  290. if respJSON["data"].(map[string]interface{})["app_role"] != nil {
  291. appRoleJSON := respJSON["data"].(map[string]interface{})["app_role"].(map[string]interface{})
  292. appRoleJSONBytes, _ := json.Marshal(appRoleJSON)
  293. if err := json.Unmarshal(appRoleJSONBytes, &appRole); err != nil {
  294. utils.ErrorLog("解析AppRole失败:%v", err)
  295. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  296. return
  297. }
  298. }
  299. var subscibe models.ServeSubscibe
  300. if respJSON["data"].(map[string]interface{})["subscibe"] != nil {
  301. subscibeJSON := respJSON["data"].(map[string]interface{})["subscibe"].(map[string]interface{})
  302. subscibeJSONBytes, _ := json.Marshal(subscibeJSON)
  303. if err := json.Unmarshal(subscibeJSONBytes, &subscibe); err != nil {
  304. utils.ErrorLog("解析Subscibe失败:%v", err)
  305. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  306. return
  307. }
  308. }
  309. //service.GetOrgSubscibeState(&subscibe)
  310. templateInfo, _ := service.GetOrgInfoTemplate(org.Id)
  311. mobileAdminUserInfo := &mobile_api_controllers.MobileAdminUserInfo{
  312. AdminUser: &adminUser,
  313. Org: &org,
  314. App: &app,
  315. AppRole: &appRole,
  316. Subscibe: &subscibe,
  317. TemplateInfo: &templateInfo,
  318. }
  319. //设置seesion
  320. this.SetSession("mobile_admin_user_info", mobileAdminUserInfo)
  321. //设置cookie
  322. mobile := adminUser.Mobile + "-" + strconv.FormatInt(org.Id, 10) + "-" + strconv.FormatInt(appRole.Id, 10)
  323. token := utils.GenerateLoginToken(mobile)
  324. expiration, _ := beego.AppConfig.Int64("mobile_token_expiration_second")
  325. this.Ctx.SetCookie("token_cookie", token, expiration, "/")
  326. var configList interface{}
  327. var FiledList []*models.FiledConfig
  328. var dict_configList interface{}
  329. if org.Id > 0 {
  330. configList, _ = service.GetConfigList(org.Id)
  331. dict_configList, _ = service.GetDictConfigList(org.Id)
  332. FiledList, _ = service.FindFiledByOrgId(org.Id)
  333. }
  334. if len(FiledList) == 0 {
  335. var err error
  336. if org.Id > 0 {
  337. err = service.BatchInsertFiledConfig(org.Id)
  338. if err == nil {
  339. FiledList, _ = service.FindFiledByOrgId(org.Id)
  340. } else {
  341. utils.ErrorLog("字段批量插入失败:%v", err)
  342. }
  343. } else {
  344. FiledList = make([]*models.FiledConfig, 0)
  345. }
  346. }
  347. if org.Id > 0 {
  348. major, requestErr := service.GetInspectionMajor(org.Id)
  349. if len(major) == 0 {
  350. QualityeList, err := service.FindQualityByOrgId(org.Id)
  351. if len(QualityeList) == 0 {
  352. err = service.BatchInsertQualityControl(org.Id)
  353. } else {
  354. utils.ErrorLog("字段批量插入失败:%v", err)
  355. }
  356. InspectionList, err := service.FindeInspectionByOrgId(org.Id)
  357. if len(InspectionList) == 0 {
  358. err = service.BatchInspectionConfiguration(org.Id)
  359. } else {
  360. utils.ErrorLog("字段批量插入失败:%v", err)
  361. }
  362. } else {
  363. utils.ErrorLog("字段批量插入失败:%v", requestErr)
  364. }
  365. }
  366. this.ServeSuccessJSON(map[string]interface{}{
  367. "admin": adminUser,
  368. "user": appRole,
  369. "org": org,
  370. "template_info": map[string]interface{}{
  371. "id": templateInfo.ID,
  372. "org_id": templateInfo.OrgId,
  373. "template_id": templateInfo.TemplateId,
  374. },
  375. "config_list": configList,
  376. "dict_config_list": dict_configList,
  377. "filed_list": FiledList,
  378. })
  379. }
  380. }
  381. }
  382. func InitAdviceTemplate(org *models.Org) {
  383. //初始化医嘱模版
  384. adviceInit := &models.AdviceInit{
  385. UserOrgId: org.Id,
  386. CreateTime: time.Now().Unix(),
  387. UpdateTime: time.Now().Unix(),
  388. Status: 1,
  389. IsInit: 1,
  390. }
  391. adviceParentTemplate := LoadConfig("./advice_template.json").Parent_template
  392. for _, item := range adviceParentTemplate {
  393. parentTemplate := &models.DoctorAdviceParentTemplate{
  394. OrgId: org.Id,
  395. Name: item.Name,
  396. Status: 1,
  397. CreatedTime: time.Now().Unix(),
  398. UpdatedTime: time.Now().Unix(),
  399. AdviceType: item.AdviceType,
  400. }
  401. createErr := service.CreateDoctorParentTemplate(parentTemplate)
  402. fmt.Println(parentTemplate.ID)
  403. if createErr == nil {
  404. for _, adviceTemplateItem := range item.DoctorAdviceTemplate {
  405. adviceTeplate := &models.DoctorAdviceTemplate{
  406. OrgId: org.Id,
  407. AdviceName: adviceTemplateItem.AdviceName,
  408. AdviceDesc: adviceTemplateItem.AdviceDesc,
  409. SingleDose: adviceTemplateItem.SingleDose,
  410. SingleDoseUnit: adviceTemplateItem.SingleDoseUnit,
  411. PrescribingNumber: adviceTemplateItem.PrescribingNumber,
  412. PrescribingNumberUnit: adviceTemplateItem.PrescribingNumberUnit,
  413. DeliveryWay: adviceTemplateItem.DeliveryWay,
  414. ExecutionFrequency: adviceTemplateItem.ExecutionFrequency,
  415. AdviceDoctor: adviceTemplateItem.AdviceDoctor,
  416. Status: 1,
  417. CreatedTime: time.Now().Unix(),
  418. UpdatedTime: time.Now().Unix(),
  419. TemplateId: parentTemplate.ID,
  420. DrugSpec: adviceTemplateItem.DrugSpec,
  421. DrugSpecUnit: adviceTemplateItem.DrugSpecUnit,
  422. ParentId: adviceTemplateItem.ParentId,
  423. AdviceType: adviceTemplateItem.AdviceType,
  424. DayCount: adviceTemplateItem.DayCount,
  425. WeekDays: adviceTemplateItem.WeekDays,
  426. FrequencyType: adviceTemplateItem.FrequencyType,
  427. }
  428. createErr := service.CreateDoctorTemplate(adviceTeplate)
  429. if createErr == nil {
  430. for _, childItem := range adviceTemplateItem.SubDoctorAdviceTemplate {
  431. adviceTeplate := &models.DoctorAdviceTemplate{
  432. OrgId: org.Id,
  433. AdviceName: childItem.AdviceName,
  434. AdviceDesc: childItem.AdviceDesc,
  435. SingleDose: childItem.SingleDose,
  436. SingleDoseUnit: childItem.SingleDoseUnit,
  437. PrescribingNumber: childItem.PrescribingNumber,
  438. PrescribingNumberUnit: childItem.PrescribingNumberUnit,
  439. DeliveryWay: childItem.DeliveryWay,
  440. ExecutionFrequency: childItem.ExecutionFrequency,
  441. AdviceDoctor: childItem.AdviceDoctor,
  442. Status: 1,
  443. CreatedTime: time.Now().Unix(),
  444. UpdatedTime: time.Now().Unix(),
  445. TemplateId: parentTemplate.ID,
  446. DrugSpec: childItem.DrugSpec,
  447. DrugSpecUnit: childItem.DrugSpecUnit,
  448. ParentId: adviceTeplate.ID,
  449. AdviceType: childItem.AdviceType,
  450. DayCount: childItem.DayCount,
  451. WeekDays: childItem.WeekDays,
  452. FrequencyType: childItem.FrequencyType,
  453. }
  454. service.CreateDoctorTemplate(adviceTeplate)
  455. }
  456. }
  457. }
  458. }
  459. }
  460. service.CreateAdviceInitConfig(adviceInit)
  461. }
  462. func InitSystemPrescrption(org *models.Org) {
  463. //初始化透析方案
  464. prescriptions := LoadPrescriptionConfig("./system_dialysis_prescription.json").Prescription
  465. for _, item := range prescriptions {
  466. item.UserOrgId = org.Id
  467. item.CreatedTime = time.Now().Unix()
  468. item.UpdatedTime = time.Now().Unix()
  469. service.CreateVMPrescription(item)
  470. }
  471. }
  472. func InitPatientAndSchedule(org *models.Org) {
  473. var ids []int64
  474. //数据初始化
  475. //创建两个虚拟病人
  476. patients := LoadPatientConfig("./patient.json").Patients
  477. for _, item := range patients {
  478. item.UserOrgId = org.Id
  479. item.CreatedTime = time.Now().Unix()
  480. item.UpdatedTime = time.Now().Unix()
  481. item.Status = 1
  482. service.CreateVMOrgPatient(item)
  483. ids = append(ids, item.ID)
  484. }
  485. //创建两个血透的虚拟病人到新表
  486. fmt.Print("patients", patients)
  487. for _, it := range patients {
  488. patientsNew := models.XtPatientsNew{
  489. UserOrgId: org.Id,
  490. CreatedTime: time.Now().Unix(),
  491. UpdatedTime: time.Now().Unix(),
  492. Status: 1,
  493. BloodId: it.ID,
  494. BloodPatients: 1,
  495. Name: it.Name,
  496. Avatar: it.Avatar,
  497. PatientType: it.PatientType,
  498. Source: it.Source,
  499. Lapseto: it.Lapseto,
  500. Gender: it.Gender,
  501. Nation: it.Nation,
  502. NativePlace: it.NativePlace,
  503. MaritalStatus: it.MaritalStatus,
  504. IdCardNo: it.IdCardNo,
  505. Birthday: it.Birthday,
  506. ReimbursementWayId: it.ReimbursementWayId,
  507. HealthCareNo: it.HealthCareNo,
  508. Phone: it.Phone,
  509. HomeAddress: it.HomeAddress,
  510. WorkUnit: it.WorkUnit,
  511. UnitAddress: it.UnitAddress,
  512. Children: it.Children,
  513. IsHospitalFirstDialysis: it.IsHospitalFirstDialysis,
  514. FirstDialysisDate: it.FirstDialysisDate,
  515. BindingState: it.BindingState,
  516. PatientComplains: it.PatientComplains,
  517. PresentHistory: it.PresentHistory,
  518. PastHistory: it.PastHistory,
  519. Temperature: it.Temperature,
  520. Pulse: it.Pulse,
  521. Respiratory: it.Respiratory,
  522. Age: it.Age,
  523. IsOpenRemind: it.IsOpenRemind,
  524. TellPhone: it.TellPhone,
  525. FirstTreatmentDate: it.FirstTreatmentDate,
  526. ContactName: it.ContactName,
  527. IsInfectious: it.IsInfectious,
  528. }
  529. service.CreateVMOrgNewPatient(&patientsNew)
  530. }
  531. //创建1个分组
  532. vmGroup := &models.VMDeviceGroup{
  533. OrgId: org.Id,
  534. Name: "护理一组",
  535. Status: 1,
  536. Ctime: time.Now().Unix(),
  537. Mtime: time.Now().Unix(),
  538. }
  539. service.CreateVMGroup(vmGroup)
  540. //创建两个虚拟分区
  541. vmZone1 := &models.VMDeviceZone{
  542. OrgId: org.Id,
  543. Name: "A区",
  544. Type: 1,
  545. Status: 1,
  546. Ctime: time.Now().Unix(),
  547. Mtime: time.Now().Unix(),
  548. }
  549. service.CreateVMZone(vmZone1)
  550. vmZone2 := &models.VMDeviceZone{
  551. OrgId: org.Id,
  552. Name: "B区",
  553. Type: 2,
  554. Status: 1,
  555. Ctime: time.Now().Unix(),
  556. Mtime: time.Now().Unix(),
  557. }
  558. service.CreateVMZone(vmZone2)
  559. //创建2个虚拟床位
  560. vmDeviceNumber1 := &models.VMDeviceNumber{
  561. OrgId: org.Id,
  562. Number: "1号床",
  563. GroupId: vmGroup.ID,
  564. ZoneId: vmZone1.ID,
  565. Status: 1,
  566. Ctime: time.Now().Unix(),
  567. Mtime: time.Now().Unix(),
  568. }
  569. service.CreateVMDeviceNumber(vmDeviceNumber1)
  570. vmDeviceNumber2 := &models.VMDeviceNumber{
  571. OrgId: org.Id,
  572. Number: "2号床",
  573. GroupId: vmGroup.ID,
  574. ZoneId: vmZone2.ID,
  575. Status: 1,
  576. Ctime: time.Now().Unix(),
  577. Mtime: time.Now().Unix(),
  578. }
  579. service.CreateVMDeviceNumber(vmDeviceNumber2)
  580. var dates []int64
  581. mondayDate := GetDateOfWeek(1)
  582. tuesdayDate := GetDateOfWeek(2)
  583. wednesdayDate := GetDateOfWeek(3)
  584. thursdayDate := GetDateOfWeek(4)
  585. fridayDate := GetDateOfWeek(5)
  586. saturdayDate := GetDateOfWeek(6)
  587. sundayDate := GetDateOfWeek(7)
  588. dates = append(dates, mondayDate)
  589. dates = append(dates, tuesdayDate)
  590. dates = append(dates, wednesdayDate)
  591. dates = append(dates, thursdayDate)
  592. dates = append(dates, fridayDate)
  593. dates = append(dates, saturdayDate)
  594. dates = append(dates, sundayDate)
  595. //创建两个虚拟病人本周的排班
  596. //stime, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  597. for week_type, date := range dates {
  598. for index, id := range ids {
  599. if index == 0 {
  600. sch := &models.VMSchedule{
  601. UserOrgId: org.Id,
  602. PartitionId: vmZone1.ID,
  603. BedId: vmDeviceNumber1.ID,
  604. PatientId: id,
  605. ScheduleDate: date,
  606. ScheduleType: 1,
  607. ScheduleWeek: int64(week_type + 1),
  608. ModeId: 1,
  609. Status: 1,
  610. CreatedTime: time.Now().Unix(),
  611. UpdatedTime: time.Now().Unix(),
  612. }
  613. service.CreateVMSch(sch)
  614. }
  615. if index == 1 {
  616. sch := &models.VMSchedule{
  617. UserOrgId: org.Id,
  618. PartitionId: vmZone2.ID,
  619. BedId: vmDeviceNumber2.ID,
  620. PatientId: id,
  621. ScheduleDate: date,
  622. ScheduleType: 2,
  623. ScheduleWeek: int64(week_type + 1),
  624. ModeId: 1,
  625. Status: 1,
  626. CreatedTime: time.Now().Unix(),
  627. UpdatedTime: time.Now().Unix(),
  628. }
  629. service.CreateVMSch(sch)
  630. }
  631. }
  632. }
  633. //创建单周模版
  634. //1.创建模版模式
  635. mode := &models.VMPatientScheduleTemplateMode{
  636. OrgId: org.Id,
  637. Mode: 1,
  638. ExecuteTimes: 0,
  639. Status: 1,
  640. Ctime: time.Now().Unix(),
  641. Mtime: time.Now().Unix(),
  642. }
  643. service.CreateVMSchMode(mode)
  644. //2.创建模版id
  645. templaeIdOne := &models.VMPatientScheduleTemplateId{
  646. OrgId: org.Id,
  647. Status: 1,
  648. Ctime: time.Now().Unix(),
  649. Mtime: time.Now().Unix(),
  650. }
  651. service.CreateVMSchTemplateId(templaeIdOne)
  652. templaeIdTwo := &models.VMPatientScheduleTemplateId{
  653. OrgId: org.Id,
  654. Status: 1,
  655. Ctime: time.Now().Unix(),
  656. Mtime: time.Now().Unix(),
  657. }
  658. service.CreateVMSchTemplateId(templaeIdTwo)
  659. //3.创建单周排班模版
  660. items := LoadSchTemplateConfig("./schedule_template.json").Item
  661. for _, item := range items {
  662. if item.TimeType == 1 {
  663. item.OrgId = org.Id
  664. item.TemplateId = templaeIdOne.ID
  665. item.DeviceNumberId = vmDeviceNumber1.ID
  666. item.PatientId = ids[0]
  667. item.Status = 1
  668. item.Ctime = time.Now().Unix()
  669. item.Mtime = time.Now().Unix()
  670. } else if item.TimeType == 2 {
  671. item.OrgId = org.Id
  672. item.TemplateId = templaeIdOne.ID
  673. item.DeviceNumberId = vmDeviceNumber2.ID
  674. item.PatientId = ids[1]
  675. item.Status = 1
  676. item.Ctime = time.Now().Unix()
  677. item.Mtime = time.Now().Unix()
  678. }
  679. service.CreateVMSchTemplate(item)
  680. }
  681. }
  682. func InitRoleAndPurviews(org *models.Org) {
  683. roles := LoadRoleConfig("./role.json").Roles
  684. app, _ := service.GetOrgApp(org.Id, 3)
  685. for _, item := range roles {
  686. role := &models.Role{
  687. RoleName: item.RoleName,
  688. RoleIntro: item.RoleIntroduction,
  689. Creator: 0,
  690. OrgId: org.Id,
  691. AppId: app.Id,
  692. IsSuperAdmin: false,
  693. Status: 1,
  694. CreateTime: time.Now().Unix(),
  695. ModifyTime: time.Now().Unix(),
  696. Number: item.Number,
  697. IsSystem: item.IsSystem,
  698. }
  699. err := service.CreateOrgRole(role)
  700. if err == nil {
  701. purview := &models.RolePurview{
  702. RoleId: role.Id,
  703. OrgId: org.Id,
  704. AppId: role.AppId,
  705. PurviewIds: item.PurviewIds,
  706. Status: 1,
  707. CreateTime: time.Now().Unix(),
  708. ModifyTime: time.Now().Unix(),
  709. }
  710. func_purview := &models.SgjUserRoleFuncPurview{
  711. RoleId: role.Id,
  712. OrgId: org.Id,
  713. AppId: role.AppId,
  714. PurviewIds: item.FuncIds,
  715. Status: 1,
  716. Ctime: time.Now().Unix(),
  717. Mtime: time.Now().Unix(),
  718. }
  719. service.CreateRolePurview(purview)
  720. service.CreateFuncRolePurview(func_purview)
  721. }
  722. }
  723. }
  724. func (this *MobileRegistController) ModifyName() {
  725. name := this.GetString("name")
  726. adminUserObj := this.GetSession("mobile_admin_user")
  727. adminUser := adminUserObj.(*models.AdminUser)
  728. err := service.ModifyAdminUserName(name, adminUser.Id)
  729. if err != nil {
  730. utils.ErrorLog("修改管理员名字失败:%v", err)
  731. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  732. this.ServeJSON()
  733. } else {
  734. this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{})
  735. this.ServeJSON()
  736. }
  737. }
  738. func (this *MobileRegistController) Login() {
  739. mobile := this.Ctx.GetCookie("mobile")
  740. adminUser, err := service.GetValidAdminUserByMobileReturnErr(mobile)
  741. if err != nil {
  742. utils.ErrorLog("获取管理信息失败:%v", err)
  743. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  744. this.ServeJSON()
  745. } else {
  746. mobileAdminUserInfo := &mobile_api_controllers.MobileAdminUserInfo{
  747. AdminUser: adminUser,
  748. Org: nil,
  749. App: nil,
  750. AppRole: nil,
  751. Subscibe: nil,
  752. TemplateInfo: nil,
  753. }
  754. var org models.Org
  755. var user models.App_Role
  756. //设置seesion
  757. this.SetSession("mobile_admin_user_info", mobileAdminUserInfo)
  758. //设置cookie
  759. mobile = mobile + "-" + "0" + "-" + "0"
  760. token := utils.GenerateLoginToken(mobile)
  761. expiration, _ := beego.AppConfig.Int64("mobile_token_expiration_second")
  762. this.Ctx.SetCookie("token_cookie", token, expiration, "/")
  763. this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
  764. "admin": adminUser,
  765. "user": user,
  766. "org": org,
  767. "template_info": map[string]interface{}{
  768. "id": 0,
  769. "org_id": 0,
  770. "template_id": 0,
  771. },
  772. "config_list": nil,
  773. "dict_config_list": nil,
  774. "filed_list": nil,
  775. })
  776. this.ServeJSON()
  777. }
  778. }
  779. type RoleConfig struct {
  780. Roles []*models.VMUserRoleAndPurview "json:roles"
  781. }
  782. type PatientConfig struct {
  783. Patients []*models.VMOrgPatients "json:patients"
  784. }
  785. type SchTemplateConfig struct {
  786. Item []*models.VMPatientScheduleTemplateItem "json:item"
  787. }
  788. type PrescriptionConfig struct {
  789. Prescription []*models.SystemPrescription "json:prescription"
  790. }
  791. func LoadRoleConfig(dataFile string) *RoleConfig {
  792. var config RoleConfig
  793. _, filename, _, _ := runtime.Caller(1)
  794. datapath := path.Join(path.Dir(filename), dataFile)
  795. config_file, err := os.Open(datapath)
  796. if err != nil {
  797. emit("Failed to open config file '%s': %s\n", datapath, err)
  798. return &config
  799. }
  800. fi, _ := config_file.Stat()
  801. buffer := make([]byte, fi.Size())
  802. _, err = config_file.Read(buffer)
  803. buffer, err = StripComments(buffer) //去掉注释
  804. if err != nil {
  805. emit("Failed to strip comments from json: %s\n", err)
  806. return &config
  807. }
  808. buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
  809. err = json.Unmarshal(buffer, &config) //解析json格式数据
  810. if err != nil {
  811. emit("Failed unmarshalling json: %s\n", err)
  812. return &config
  813. }
  814. return &config
  815. }
  816. func LoadPatientConfig(dataFile string) *PatientConfig {
  817. var config PatientConfig
  818. _, filename, _, _ := runtime.Caller(1)
  819. datapath := path.Join(path.Dir(filename), dataFile)
  820. config_file, err := os.Open(datapath)
  821. if err != nil {
  822. emit("Failed to open config file '%s': %s\n", datapath, err)
  823. return &config
  824. }
  825. fi, _ := config_file.Stat()
  826. buffer := make([]byte, fi.Size())
  827. _, err = config_file.Read(buffer)
  828. buffer, err = StripComments(buffer) //去掉注释
  829. if err != nil {
  830. emit("Failed to strip comments from json: %s\n", err)
  831. return &config
  832. }
  833. buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
  834. err = json.Unmarshal(buffer, &config) //解析json格式数据
  835. if err != nil {
  836. emit("Failed unmarshalling json: %s\n", err)
  837. return &config
  838. }
  839. return &config
  840. }
  841. func LoadSchTemplateConfig(dataFile string) *SchTemplateConfig {
  842. var config SchTemplateConfig
  843. _, filename, _, _ := runtime.Caller(1)
  844. datapath := path.Join(path.Dir(filename), dataFile)
  845. config_file, err := os.Open(datapath)
  846. if err != nil {
  847. emit("Failed to open config file '%s': %s\n", datapath, err)
  848. return &config
  849. }
  850. fi, _ := config_file.Stat()
  851. buffer := make([]byte, fi.Size())
  852. _, err = config_file.Read(buffer)
  853. buffer, err = StripComments(buffer) //去掉注释
  854. if err != nil {
  855. emit("Failed to strip comments from json: %s\n", err)
  856. return &config
  857. }
  858. buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
  859. err = json.Unmarshal(buffer, &config) //解析json格式数据
  860. if err != nil {
  861. emit("Failed unmarshalling json: %s\n", err)
  862. return &config
  863. }
  864. return &config
  865. }
  866. func LoadPrescriptionConfig(dataFile string) *PrescriptionConfig {
  867. var config PrescriptionConfig
  868. _, filename, _, _ := runtime.Caller(1)
  869. datapath := path.Join(path.Dir(filename), dataFile)
  870. config_file, err := os.Open(datapath)
  871. if err != nil {
  872. emit("Failed to open config file '%s': %s\n", datapath, err)
  873. return &config
  874. }
  875. fi, _ := config_file.Stat()
  876. buffer := make([]byte, fi.Size())
  877. _, err = config_file.Read(buffer)
  878. buffer, err = StripComments(buffer) //去掉注释
  879. if err != nil {
  880. emit("Failed to strip comments from json: %s\n", err)
  881. return &config
  882. }
  883. buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
  884. err = json.Unmarshal(buffer, &config) //解析json格式数据
  885. if err != nil {
  886. emit("Failed unmarshalling json: %s\n", err)
  887. return &config
  888. }
  889. return &config
  890. }
  891. func emit(msgfmt string, args ...interface{}) {
  892. log.Printf(msgfmt, args...)
  893. }
  894. func StripComments(data []byte) ([]byte, error) {
  895. data = bytes.Replace(data, []byte("\r"), []byte(""), 0) // Windows
  896. lines := bytes.Split(data, []byte("\n")) //split to muli lines
  897. filtered := make([][]byte, 0)
  898. for _, line := range lines {
  899. match, err := regexp.Match(`^\s*#`, line)
  900. if err != nil {
  901. return nil, err
  902. }
  903. if !match {
  904. filtered = append(filtered, line)
  905. }
  906. }
  907. return bytes.Join(filtered, []byte("\n")), nil
  908. }
  909. func GetDateOfWeek(week_type int) (weekMonday int64) {
  910. thisTime := time.Now()
  911. weekDay := int(thisTime.Weekday())
  912. if weekDay == 0 {
  913. weekDay = 7
  914. }
  915. weekEnd := 7 - weekDay
  916. weekStart := weekEnd - 6
  917. weekTitle := make([]string, 0)
  918. days := make([]string, 0)
  919. for index := weekStart; index <= weekEnd; index++ {
  920. theDay := thisTime.AddDate(0, 0, index)
  921. indexYear, indexMonthTime, indexDay := theDay.Date()
  922. indexMonth := int(indexMonthTime)
  923. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  924. weekTitle = append(weekTitle, indexWeek)
  925. days = append(days, theDay.Format("2006-01-02"))
  926. }
  927. var targetDayStr string
  928. switch week_type {
  929. case 1:
  930. targetDayStr = days[0]
  931. break
  932. case 2:
  933. targetDayStr = days[1]
  934. break
  935. case 3:
  936. targetDayStr = days[2]
  937. break
  938. case 4:
  939. targetDayStr = days[3]
  940. break
  941. case 5:
  942. targetDayStr = days[4]
  943. break
  944. case 6:
  945. targetDayStr = days[5]
  946. break
  947. case 7:
  948. targetDayStr = days[6]
  949. break
  950. }
  951. targetDay, _ := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  952. return targetDay.Unix()
  953. }
  954. type Config struct {
  955. Parent_template []*models.VMDoctorAdviceParentTemplate "json:parent_template"
  956. }
  957. func LoadConfig(dataFile string) *Config {
  958. var config Config
  959. _, filename, _, _ := runtime.Caller(1)
  960. datapath := path.Join(path.Dir(filename), dataFile)
  961. config_file, err := os.Open(datapath)
  962. if err != nil {
  963. emit("Failed to open config file '%s': %s\n", datapath, err)
  964. return &config
  965. }
  966. fi, _ := config_file.Stat()
  967. buffer := make([]byte, fi.Size())
  968. _, err = config_file.Read(buffer)
  969. buffer, err = StripComments(buffer) //去掉注释
  970. if err != nil {
  971. emit("Failed to strip comments from json: %s\n", err)
  972. return &config
  973. }
  974. buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
  975. err = json.Unmarshal(buffer, &config) //解析json格式数据
  976. if err != nil {
  977. emit("Failed unmarshalling json: %s\n", err)
  978. return &config
  979. }
  980. return &config
  981. }
  982. func InitEquitMentInformation(org *models.Org) {
  983. //添加设备型号
  984. mode := models.VMDeviceMode{
  985. DeviceMode: "5008S",
  986. Status: 1,
  987. UserOrgId: org.Id,
  988. Ctime: time.Now().Unix(),
  989. Mtime: time.Now().Unix(),
  990. }
  991. service.CreatedDeviceMode(&mode)
  992. deviceMode := models.VMDeviceMode{
  993. DeviceMode: "4008S",
  994. Status: 1,
  995. UserOrgId: org.Id,
  996. Ctime: time.Now().Unix(),
  997. Mtime: time.Now().Unix(),
  998. }
  999. service.CreatedDeviceMode(&deviceMode)
  1000. firstDeviceMode, _ := service.GetFirstDeviceMode(org.Id)
  1001. //获取机构下对应的第一数据
  1002. number, _ := service.GetFirstBedNumber(org.Id)
  1003. //添加设备
  1004. deviceAddmacher := models.VmDeviceAddmacher{
  1005. SerialNumber: "8VSAHE13",
  1006. DeviceType: 1,
  1007. BedId: number.ID,
  1008. DeviceName: "费森尤斯",
  1009. UnitType: firstDeviceMode.ID,
  1010. MachineStatus: 1,
  1011. Status: 1,
  1012. UserOrgId: org.Id,
  1013. Ctime: time.Now().Unix(),
  1014. }
  1015. service.CreateDeviceAddMacher(&deviceAddmacher)
  1016. macher, _ := service.GetLastMacher(org.Id)
  1017. fmt.Print(macher.ID)
  1018. treatmentmode := models.VmDeviceTreatmentmode{
  1019. MachineId: macher.ID,
  1020. Status: 1,
  1021. Ctime: time.Now().Unix(),
  1022. Mtime: time.Now().Unix(),
  1023. UserOrgId: org.Id,
  1024. TreateMode: 1,
  1025. }
  1026. service.CreatedTreateMode(&treatmentmode)
  1027. treatmentmodeone := models.VmDeviceTreatmentmode{
  1028. MachineId: macher.ID,
  1029. Status: 1,
  1030. Ctime: time.Now().Unix(),
  1031. Mtime: time.Now().Unix(),
  1032. UserOrgId: org.Id,
  1033. TreateMode: 2,
  1034. }
  1035. service.CreatedTreateMode(&treatmentmodeone)
  1036. treatmentmodetwo := models.VmDeviceTreatmentmode{
  1037. MachineId: macher.ID,
  1038. Status: 1,
  1039. Ctime: time.Now().Unix(),
  1040. Mtime: time.Now().Unix(),
  1041. UserOrgId: org.Id,
  1042. TreateMode: 3,
  1043. }
  1044. service.CreatedTreateMode(&treatmentmodetwo)
  1045. treatmentmodethree := models.VmDeviceTreatmentmode{
  1046. MachineId: macher.ID,
  1047. Status: 1,
  1048. Ctime: time.Now().Unix(),
  1049. Mtime: time.Now().Unix(),
  1050. UserOrgId: org.Id,
  1051. TreateMode: 4,
  1052. }
  1053. service.CreatedTreateMode(&treatmentmodethree)
  1054. treatmentmodefour := models.VmDeviceTreatmentmode{
  1055. MachineId: macher.ID,
  1056. Status: 1,
  1057. Ctime: time.Now().Unix(),
  1058. Mtime: time.Now().Unix(),
  1059. UserOrgId: org.Id,
  1060. TreateMode: 5,
  1061. }
  1062. service.CreatedTreateMode(&treatmentmodefour)
  1063. treatmentmodefive := models.VmDeviceTreatmentmode{
  1064. MachineId: macher.ID,
  1065. Status: 1,
  1066. Ctime: time.Now().Unix(),
  1067. Mtime: time.Now().Unix(),
  1068. UserOrgId: org.Id,
  1069. TreateMode: 12,
  1070. }
  1071. service.CreatedTreateMode(&treatmentmodefive)
  1072. }
  1073. func InitShowConfig(org *models.Org) {
  1074. service.BatchInsertFiledSystemConfig(org.Id)
  1075. template := &models.VMGobalTemplate{
  1076. Status: 1,
  1077. Ctime: time.Now().Unix(),
  1078. Mtime: time.Now().Unix(),
  1079. OrgId: org.Id,
  1080. TemplateId: 2,
  1081. }
  1082. service.CreateVMPrintTemplate(template)
  1083. }
  1084. type GoodTypesConfig struct {
  1085. Types []*models.VMGoodsType "json:types"
  1086. }
  1087. func LoadGoodTypeConfig(dataFile string) *GoodTypesConfig {
  1088. var config GoodTypesConfig
  1089. _, filename, _, _ := runtime.Caller(1)
  1090. datapath := path.Join(path.Dir(filename), dataFile)
  1091. config_file, err := os.Open(datapath)
  1092. fmt.Println("1111111")
  1093. fmt.Println(err)
  1094. fmt.Println("2222222")
  1095. if err != nil {
  1096. emit("Failed to open config file '%s': %s\n", datapath, err)
  1097. return &config
  1098. }
  1099. fi, _ := config_file.Stat()
  1100. buffer := make([]byte, fi.Size())
  1101. _, err = config_file.Read(buffer)
  1102. buffer, err = StripComments(buffer) //去掉注释
  1103. fmt.Println("333333")
  1104. fmt.Println(err)
  1105. fmt.Println("4444444")
  1106. if err != nil {
  1107. emit("Failed to strip comments from json: %s\n", err)
  1108. return &config
  1109. }
  1110. buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
  1111. err = json.Unmarshal(buffer, &config) //解析json格式数据
  1112. fmt.Println("55555555")
  1113. fmt.Println(err)
  1114. fmt.Println("66666666")
  1115. if err != nil {
  1116. emit("Failed unmarshalling json: %s\n", err)
  1117. return &config
  1118. }
  1119. return &config
  1120. }
  1121. func InitGoodTypesConfig(org *models.Org) {
  1122. good_types := LoadGoodTypeConfig("./good_types.json").Types
  1123. fmt.Println(good_types)
  1124. for _, item := range good_types {
  1125. good_type := &models.GoodsType{
  1126. TypeCode: item.TypeCode,
  1127. TypeName: item.TypeName,
  1128. Remark: "",
  1129. Number: item.Number,
  1130. Ctime: time.Now().Unix(),
  1131. Mtime: time.Now().Unix(),
  1132. OrgId: org.Id,
  1133. Status: 1,
  1134. Type: 1,
  1135. OutStock: item.OutStock,
  1136. }
  1137. service.AddSigleGoodType(good_type)
  1138. }
  1139. }