his_print_api_controller.go 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "fmt"
  8. "github.com/astaxie/beego"
  9. "os"
  10. "strings"
  11. "time"
  12. )
  13. const (
  14. key = "4a6617a4409c48dc836152e80e18febd"
  15. )
  16. type HisPrintApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func HisPrintApiRegistRouters() {
  20. beego.Router("/api/his/prescription/print", &HisPrintApiController{}, "get:GetBatchHisPrescriptionData")
  21. beego.Router("/api/his/prescription/list", &HisPrintApiController{}, "get:GetUnChargePrescriptionList")
  22. beego.Router("/api/his/prescription/summary", &HisPrintApiController{}, "get:GetUnChargePrescriptionSummary")
  23. beego.Router("/api/his/label/create", &HisPrintApiController{}, "get:CreateLablePrint")
  24. beego.Router("/api/his/label/get", &HisPrintApiController{}, "get:GetLablePrint")
  25. //beego.Router("/api/his/label/send", &HisPrintApiController{}, "get:SendApplyCode")
  26. }
  27. //func (c *HisPrintApiController) SendApplyCode() {
  28. // list, _ := service.GetAllLisDataFor10191(c.GetAdminUserInfo().CurrentOrgId)
  29. // if len(list) > 0 {
  30. // //插入中间库中
  31. // for _, item := range list {
  32. // if len(item.ApplyCode) == 0 {
  33. // var apply models.JYApply
  34. // apply.BedCode = ""
  35. // apply.PatientName = item.Patient.Name
  36. // idCard := item.Patient.IdCardNo // 身份证号码示例
  37. // age, err := GetAge(idCard)
  38. // if err != nil {
  39. // age = int(item.Patient.Age)
  40. // fmt.Println("计算年龄时出错:", err)
  41. // }
  42. //
  43. // apply.Age = strconv.FormatInt(int64(age), 10)
  44. // apply.AgeUnit = "岁"
  45. // if item.Patient.Gender == 1 {
  46. // apply.Sex = "男"
  47. // } else if item.Patient.Gender == 2 {
  48. // apply.Sex = "女"
  49. // } else {
  50. // apply.Sex = "不详"
  51. // }
  52. // apply.RegisterCode = ""
  53. // apply.Diagnosis = ""
  54. // apply.Ward = ""
  55. // role, _ := service.GetAdminUserRole(2398, c.GetAdminUserInfo().CurrentOrgId)
  56. // apply.SendDoctor = role.UserName
  57. // apply.PatientType = 1
  58. // apply.PatientPhone = item.Patient.Phone
  59. // //applys = append(applys, apply)
  60. // var jYApplyDetails []models.CustomerApplyDetail
  61. //
  62. // if len(item.ItemIds) > 0 {
  63. // team_ids := strings.Split(item.ItemIds, ",")
  64. // for index, subItem := range team_ids {
  65. // //判断一些需要拆分的组套 血透体检(定量):需要拆分出传染病检查(定性),丙型肝炎抗体测试,血透体检(定量)
  66. // if subItem == "267" {
  67. // //血透体检(定量)
  68. // var jYApplyDetail models.CustomerApplyDetail
  69. // id, _ := strconv.ParseInt(subItem, 10, 64)
  70. // jYApplyDetail.CustomerChargeItemCode = strconv.FormatInt(id, 10)
  71. // jYApplyDetail.RowIndex = int64(index + 1)
  72. // jYApplyDetail.Barcode = ""
  73. // jYApplyDetail.CustomerBarcode = strconv.FormatInt(item.ID, 10)
  74. // jYApplyDetail.Comment = ""
  75. // jYApplyDetail.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
  76. // jYApplyDetails = append(jYApplyDetails, jYApplyDetail)
  77. //
  78. // //丙型肝炎抗体测定
  79. // var jYApplyDetail2 models.CustomerApplyDetail
  80. // id2, _ := strconv.ParseInt("26701", 10, 64)
  81. // jYApplyDetail2.CustomerChargeItemCode = strconv.FormatInt(id2, 10)
  82. // jYApplyDetail2.RowIndex = int64(index + 1)
  83. // jYApplyDetail2.Barcode = ""
  84. // jYApplyDetail2.CustomerBarcode = strconv.FormatInt(item.ID, 10)
  85. // jYApplyDetail2.Comment = ""
  86. // jYApplyDetail2.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
  87. // jYApplyDetails = append(jYApplyDetails, jYApplyDetail2)
  88. //
  89. // //传染病检查(定性)
  90. // var jYApplyDetail3 models.CustomerApplyDetail
  91. // id3, _ := strconv.ParseInt("26700", 10, 64)
  92. // jYApplyDetail3.CustomerChargeItemCode = strconv.FormatInt(id3, 10)
  93. // jYApplyDetail3.RowIndex = int64(index + 1)
  94. // jYApplyDetail3.Barcode = ""
  95. // jYApplyDetail3.CustomerBarcode = strconv.FormatInt(item.ID, 10)
  96. // jYApplyDetail3.Comment = ""
  97. // jYApplyDetail3.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
  98. // jYApplyDetails = append(jYApplyDetails, jYApplyDetail3)
  99. //
  100. // }
  101. //
  102. // //判断一些需要拆分的组套 血透体检(定性):需要拆分出传染病检查(定性),丙型肝炎抗体测试,血透体检(定性)
  103. // if subItem == "424" {
  104. // //血透体检(定性)
  105. // var jYApplyDetail models.CustomerApplyDetail
  106. // id, _ := strconv.ParseInt(subItem, 10, 64)
  107. // jYApplyDetail.CustomerChargeItemCode = strconv.FormatInt(id, 10)
  108. // jYApplyDetail.RowIndex = int64(index + 1)
  109. // jYApplyDetail.Barcode = ""
  110. // jYApplyDetail.CustomerBarcode = strconv.FormatInt(item.ID, 10)
  111. // jYApplyDetail.Comment = ""
  112. // jYApplyDetail.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
  113. // jYApplyDetails = append(jYApplyDetails, jYApplyDetail)
  114. //
  115. // //丙型肝炎抗体测定
  116. // var jYApplyDetail2 models.CustomerApplyDetail
  117. // id2, _ := strconv.ParseInt("42401", 10, 64)
  118. // jYApplyDetail2.CustomerChargeItemCode = strconv.FormatInt(id2, 10)
  119. // jYApplyDetail2.RowIndex = int64(index + 1)
  120. // jYApplyDetail2.Barcode = ""
  121. // jYApplyDetail2.CustomerBarcode = strconv.FormatInt(item.ID, 10)
  122. // jYApplyDetail2.Comment = ""
  123. // jYApplyDetail2.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
  124. // jYApplyDetails = append(jYApplyDetails, jYApplyDetail2)
  125. //
  126. // //传染病检查(定性)
  127. // var jYApplyDetail3 models.CustomerApplyDetail
  128. // id3, _ := strconv.ParseInt("42400", 10, 64)
  129. // jYApplyDetail3.CustomerChargeItemCode = strconv.FormatInt(id3, 10)
  130. // jYApplyDetail3.RowIndex = int64(index + 1)
  131. // jYApplyDetail3.Barcode = ""
  132. // jYApplyDetail3.CustomerBarcode = strconv.FormatInt(item.ID, 10)
  133. // jYApplyDetail3.Comment = ""
  134. // jYApplyDetail3.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
  135. // jYApplyDetails = append(jYApplyDetails, jYApplyDetail3)
  136. //
  137. // }
  138. // var jYApplyDetail models.CustomerApplyDetail
  139. // id, _ := strconv.ParseInt(subItem, 10, 64)
  140. // jYApplyDetail.CustomerChargeItemCode = strconv.FormatInt(id, 10)
  141. // jYApplyDetail.RowIndex = int64(index + 1)
  142. // jYApplyDetail.Barcode = ""
  143. // jYApplyDetail.CustomerBarcode = strconv.FormatInt(item.ID, 10)
  144. // jYApplyDetail.Comment = ""
  145. // jYApplyDetail.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
  146. // jYApplyDetails = append(jYApplyDetails, jYApplyDetail)
  147. // }
  148. // }
  149. //
  150. // if len(item.ProjectIds) > 0 {
  151. // team_ids := strings.Split(item.ProjectIds, ",")
  152. // for index, subItem := range team_ids {
  153. // var jYApplyDetail models.CustomerApplyDetail
  154. // id, _ := strconv.ParseInt(subItem, 10, 64)
  155. // jYApplyDetail.CustomerChargeItemCode = strconv.FormatInt(id, 10)
  156. // jYApplyDetail.RowIndex = int64(index)
  157. // jYApplyDetail.Barcode = ""
  158. // jYApplyDetail.CustomerBarcode = strconv.FormatInt(item.ID, 10)
  159. // jYApplyDetail.Comment = ""
  160. // jYApplyDetail.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
  161. // jYApplyDetails = append(jYApplyDetails, jYApplyDetail)
  162. // }
  163. // }
  164. // result := PostInspectApply(key, apply, jYApplyDetails)
  165. // if result.Res == 0 {
  166. // item.ApplyCode = result.JYApplyResult.ApplyCode
  167. // jsonData, err := json.Marshal(apply)
  168. // if err != nil {
  169. // fmt.Println("转换为JSON时发生错误:", err)
  170. // }
  171. // jsonStr := string(jsonData)
  172. // jsonData2, err2 := json.Marshal(jYApplyDetails)
  173. // if err2 != nil {
  174. // fmt.Println("转换为JSON时发生错误:", err2)
  175. // }
  176. // jsonStr2 := string(jsonData2)
  177. //
  178. // jsonData3, err3 := json.Marshal(result)
  179. // if err3 != nil {
  180. // fmt.Println("转换为JSON时发生错误:", err3)
  181. // }
  182. // jsonStr3 := string(jsonData3)
  183. // saveSuccessLog(jsonStr3, jsonStr+"\r\n"+jsonStr2, "申清单成功日志", "申清单")
  184. // err1 := service.CreateLabelPrint(&item)
  185. // if err1 == nil {
  186. // c.ServeSuccessJSON(map[string]interface{}{
  187. // "msg": "发送成功",
  188. // })
  189. // }
  190. // return
  191. // } else {
  192. // jsonData, err := json.Marshal(apply)
  193. // if err != nil {
  194. // fmt.Println("转换为JSON时发生错误:", err)
  195. //
  196. // }
  197. // jsonStr := string(jsonData)
  198. //
  199. // jsonData2, err2 := json.Marshal(jYApplyDetails)
  200. // if err2 != nil {
  201. // fmt.Println("转换为JSON时发生错误:", err2)
  202. //
  203. // }
  204. // jsonStr2 := string(jsonData2)
  205. //
  206. // jsonData3, err3 := json.Marshal(result)
  207. // if err3 != nil {
  208. // fmt.Println("转换为JSON时发生错误:", err3)
  209. //
  210. // }
  211. // jsonStr3 := string(jsonData3)
  212. //
  213. // SaveErrorLog(jsonStr3, jsonStr+"\r\n"+jsonStr2, "申清单错误日志", "申清单")
  214. //
  215. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  216. // return
  217. // }
  218. // }
  219. // }
  220. //
  221. // }
  222. //}
  223. func (c *HisPrintApiController) GetLablePrint() {
  224. patient_id, _ := c.GetInt64("patient_id")
  225. ids := c.GetString("ids")
  226. record_date := c.GetString("record_date")
  227. labels, _ := service.GetLabelPrint(ids, c.GetAdminUserInfo().CurrentOrgId, record_date, patient_id)
  228. c.ServeSuccessJSON(map[string]interface{}{
  229. "labels": labels,
  230. })
  231. return
  232. }
  233. func (c *HisPrintApiController) CreateLablePrint() {
  234. patient_id, _ := c.GetInt64("patient_id")
  235. isCombinationPrint, _ := c.GetBool("is_combination_print")
  236. team_ids := c.GetString("team_ids")
  237. ids := c.GetString("ids")
  238. record_date := c.GetString("record_date")
  239. doctor_id, _ := c.GetInt64("doctor_id")
  240. project_ids := c.GetString("project_ids")
  241. is_team, _ := c.GetInt64("is_team")
  242. var hlpsi models.HisLabelPrintStatusInfo
  243. hlpsi.Status = 1
  244. hlpsi.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
  245. hlpsi.PatientId = patient_id
  246. hlpsi.RecordDate = record_date
  247. hlpsi.Mtime = time.Now().Unix()
  248. hlpsi.Ctime = time.Now().Unix()
  249. hlpsi.ItemIds = team_ids
  250. hlpsi.ProjectIds = project_ids
  251. hlpsi.Ids = ids
  252. hlpsi.DoctorId = doctor_id
  253. hlpsi.IsTeam = is_team
  254. hlpsi.IsPrint = 1
  255. if isCombinationPrint == true {
  256. hlpsi.IsCombinationPrint = 1
  257. } else {
  258. hlpsi.IsCombinationPrint = 0
  259. }
  260. service.CreateLabelPrint(&hlpsi)
  261. c.ServeSuccessJSON(map[string]interface{}{
  262. "msg": "保存成功",
  263. "hlpsi": hlpsi,
  264. })
  265. return
  266. }
  267. func (c *HisPrintApiController) GetUnChargePrescriptionList() {
  268. patient_id, _ := c.GetInt64("patient_id")
  269. recordDateTime, _ := c.GetInt64("record_date")
  270. admin_user_id, _ := c.GetInt64("admin_user_id")
  271. p_type, _ := c.GetInt64("p_type", 0)
  272. admin := c.GetAdminUserInfo()
  273. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  274. record, _ := service.GetLastInHospitalRecord(patient_id, c.GetAdminUserInfo().CurrentOrgId)
  275. var prescriptions []*models.HisPrescription
  276. prescriptions, _ = service.GetUnChargeHisPrescriptionTen(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  277. admin_info, _ := service.GetAdminUserRole(admin_user_id, c.GetAdminUserInfo().CurrentOrgId)
  278. //获取所有科室信息
  279. c.ServeSuccessJSON(map[string]interface{}{
  280. "xt_info": xt_patient_info,
  281. "prescription": prescriptions,
  282. "record": record,
  283. "admin_info": admin_info,
  284. })
  285. return
  286. }
  287. func (c *HisPrintApiController) GetUnChargePrescriptionSummary() {
  288. patient_id, _ := c.GetInt64("patient_id")
  289. record_date, _ := c.GetInt64("record_date")
  290. admin_user_id, _ := c.GetInt64("admin_user_id")
  291. p_type, _ := c.GetInt64("p_type", 0)
  292. //timeLayout := "2006-01-02"
  293. //loc, _ := time.LoadLocation("Local")
  294. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  295. //if err != nil {
  296. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  297. // return
  298. //}
  299. //recordDateTime := theTime.Unix()
  300. admin := c.GetAdminUserInfo()
  301. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  302. record, _ := service.GetLastInHospitalRecord(patient_id, c.GetAdminUserInfo().CurrentOrgId)
  303. var prescriptions []*models.HisPrescription
  304. prescriptions, _ = service.GetUnChargeHisPrescriptionTen(admin.CurrentOrgId, patient_id, record_date, p_type)
  305. //doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  306. service.GetAdminUserRole(admin_user_id, c.GetAdminUserInfo().CurrentOrgId)
  307. //获取所有科室信息
  308. c.ServeSuccessJSON(map[string]interface{}{
  309. "xt_info": xt_patient_info,
  310. "prescription": prescriptions,
  311. "record": record,
  312. "admin_info": admin_user_id,
  313. })
  314. return
  315. }
  316. func (c *HisPrintApiController) GetBatchHisPrescriptionData() {
  317. record_date := c.GetString("record_date")
  318. patient_ids := c.GetString("patient_ids")
  319. print_type, _ := c.GetInt64("type")
  320. timeLayout := "2006-01-02"
  321. loc, _ := time.LoadLocation("Local")
  322. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  323. if err != nil {
  324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  325. return
  326. }
  327. recordDateTime := theTime.Unix()
  328. adminInfo := c.GetAdminUserInfo()
  329. ids := strings.Split(patient_ids, ",")
  330. switch print_type {
  331. case 1:
  332. patients, _ := service.GetBatchDrugHisPrescription(ids, recordDateTime, adminInfo.CurrentOrgId)
  333. c.ServeSuccessJSON(map[string]interface{}{
  334. "patients": patients,
  335. })
  336. break
  337. case 2:
  338. //var newPatients []*models.PrintPatient
  339. patients, _ := service.GetBatchProjectHisPrescription(ids, recordDateTime, adminInfo.CurrentOrgId)
  340. //for _, item := range patients {
  341. // for _, subItem := range item.HisPrintPrescription {
  342. // for _, subItemTwo := range subItem.HisPrescriptionProject {
  343. // if subItemTwo.HisProject.CostClassify != 3 {
  344. //
  345. // }
  346. // }
  347. // }
  348. //}
  349. c.ServeSuccessJSON(map[string]interface{}{
  350. "patients": patients,
  351. })
  352. break
  353. case 3:
  354. var newPatients []*models.PrintPatient
  355. var newPatientsTwo []*models.PrintPatient
  356. patients, _ := service.GetBatchInspectionProjectHisPrescription(ids, recordDateTime, adminInfo.CurrentOrgId)
  357. for _, item := range patients {
  358. var newPatient *models.PrintPatient
  359. newPatient = item
  360. for index, subItem := range item.HisPrintPrescription {
  361. if index > 0 {
  362. item.HisPrintPrescription[0].HisPrescriptionProject = append(item.HisPrintPrescription[0].HisPrescriptionProject, subItem.HisPrescriptionProject...)
  363. }
  364. }
  365. newPatients = append(newPatients, newPatient)
  366. }
  367. for _, item := range patients {
  368. var newPatient *models.PrintPatient
  369. newPatient = item
  370. if len(item.HisPrintPrescription) > 0 {
  371. newPatient.NewHisPrintPrescription = append(newPatient.NewHisPrintPrescription, item.HisPrintPrescription[0])
  372. newPatientsTwo = append(newPatientsTwo, newPatient)
  373. }
  374. }
  375. c.ServeSuccessJSON(map[string]interface{}{
  376. "patients": newPatientsTwo,
  377. })
  378. break
  379. }
  380. }
  381. func GetAge(idCard string) (int, error) {
  382. birthDate, err := getBirthDateFromIDCard(idCard)
  383. if err != nil {
  384. return 0, err
  385. }
  386. age := calculateAge(birthDate)
  387. return age, nil
  388. }
  389. func getBirthDateFromIDCard(idCard string) (time.Time, error) {
  390. birthDateStr := idCard[6:14] // 身份证号码中生日部分的字符
  391. birthDate, err := time.Parse("20060102", birthDateStr)
  392. if err != nil {
  393. return time.Time{}, err
  394. }
  395. return birthDate, nil
  396. }
  397. func calculateAge(birthDate time.Time) int {
  398. now := time.Now()
  399. age := now.Year() - birthDate.Year()
  400. // 如果当前月份小于出生月份,或者当前月份等于出生月份但当前日期小于出生日期,则年龄减一
  401. if now.Month() < birthDate.Month() || (now.Month() == birthDate.Month() && now.Day() < birthDate.Day()) {
  402. age--
  403. }
  404. return age
  405. }
  406. // 送检单
  407. //func PostInspectApply(key string, apply models.JYApply, list []models.CustomerApplyDetail) models.InspectApplyData {
  408. // // 构建SOAP请求数据
  409. // requestData := &models.JYApplyEnvelope{
  410. // Soap: "http://schemas.xmlsoap.org/soap/envelope/",
  411. // Xsi: "http://www.w3.org/2001/XMLSchema-instance",
  412. // Xsd: "http://www.w3.org/2001/XMLSchema",
  413. // Body: models.JYApplyBody{
  414. // InspectApplyReq: models.InspectApplyReq{
  415. // XMLName: xml.Name{Local: "InspectApplyByInstituteItemCode", Space: "http://tempuri.org/"},
  416. // ApiKey: key,
  417. // Apply: apply,
  418. // ApplyDetailList: struct {
  419. // CustomerApplyDetail []models.CustomerApplyDetail `xml:"CustomerApplyDetail"`
  420. // }{
  421. // CustomerApplyDetail: list,
  422. // },
  423. // ApplyAdditional: nil,
  424. // },
  425. // },
  426. // }
  427. //
  428. // // 将SOAP请求数据转换为XML格式
  429. // requestBody, err := xml.Marshal(requestData)
  430. // if err != nil {
  431. // fmt.Println("XML Marshal error:", err)
  432. // }
  433. // fmt.Println(string(requestBody))
  434. //
  435. // // 创建POST请求
  436. // url := "http://gpis.cnhiqc.com:9799/InstituteLISService.asmx"
  437. // req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
  438. // if err != nil {
  439. // fmt.Println("Request creation error:", err)
  440. // }
  441. //
  442. // // 设置请求头
  443. // req.Header.Set("Content-Type", "text/xml; charset=utf-8")
  444. // req.Header.Set("Content-Length", "length")
  445. // req.Header.Set("SOAPAction", "http://tempuri.org/InspectApplyByInstituteItemCode")
  446. //
  447. // // 发送请求
  448. // client := &http.Client{}
  449. // resp, err := client.Do(req)
  450. // if err != nil {
  451. // fmt.Println("Request error:", err)
  452. // }
  453. // defer resp.Body.Close()
  454. //
  455. // // 读取响应数据
  456. // responseBody, err := ioutil.ReadAll(resp.Body)
  457. // if err != nil {
  458. // fmt.Println("Response read error:", err)
  459. //
  460. // }
  461. // fmt.Println(string(responseBody))
  462. //
  463. // // 解析XML数据
  464. // var envelope_four models.EnvelopeFour
  465. // err2 := xml.Unmarshal(responseBody, &envelope_four)
  466. // if err2 != nil {
  467. // fmt.Println("XML Unmarshal error:", err2)
  468. //
  469. // }
  470. //
  471. // // 获取GetReportListResult的JSON字符串
  472. // jsonStr := envelope_four.Body.InspectApplyByInstituteItemCodeResponse.InspectApply
  473. //
  474. // // 解析JSON字符串到结构体
  475. // var reportData models.InspectApplyData
  476. // err = json.Unmarshal([]byte(jsonStr), &reportData)
  477. //
  478. // if err != nil {
  479. // fmt.Println("JSON Unmarshal error:", err)
  480. // }
  481. // if reportData.Res != 0 {
  482. // fmt.Println("Data:", reportData)
  483. // //return reportData.JYApplyResult
  484. // }
  485. // return reportData
  486. //}
  487. func SaveErrorLog(result string, request string, infno string, desc string) {
  488. //org_id, _ := beego.AppConfig.Int64("org_id")
  489. //miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  490. dir := "faild"
  491. utils.Mkdir(dir)
  492. month := time.Unix(1557042972, 0).Format("1")
  493. year := time.Now().Format("2006")
  494. month = time.Now().Format("01")
  495. day := time.Now().Format("02")
  496. hour := time.Now().Format("15")
  497. min := time.Now().Format("04")
  498. sec := time.Now().Format("05")
  499. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  500. file := "failed" + "_" + year + month + day + "_log"
  501. file_name := file + ".txt"
  502. file_path := "faild" + "/" + file_name
  503. exist, _ := utils.PathExists(file_path)
  504. if exist { //存在
  505. fmt.Println("存在")
  506. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  507. if err != nil {
  508. fmt.Println("read fail")
  509. }
  510. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  511. n, _ := f.Seek(0, 2)
  512. _, err = f.WriteAt([]byte(content), n)
  513. } else { //不存在
  514. fmt.Println("文件不存在,创建文件")
  515. f, err := os.Create("faild" + "/" + file_name)
  516. defer f.Close()
  517. if err != nil {
  518. } else {
  519. _, err = f.Write([]byte("记录日志"))
  520. }
  521. }
  522. }
  523. func saveSuccessLog(result string, request string, infno string, desc string) {
  524. //org_id, _ := beego.AppConfig.Int64("org_id")
  525. //miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  526. //dir := "同步成功日志"
  527. //utils.Mkdir(dir)
  528. month := time.Unix(1557042972, 0).Format("1")
  529. year := time.Now().Format("2006")
  530. month = time.Now().Format("01")
  531. day := time.Now().Format("02")
  532. hour := time.Now().Format("15")
  533. min := time.Now().Format("04")
  534. sec := time.Now().Format("05")
  535. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  536. file := "success" + "_" + year + month + day + "_log"
  537. file_name := file + ".txt"
  538. file_path := file_name
  539. exist, _ := utils.PathExists(file_path)
  540. if exist { //存在
  541. fmt.Println("存在")
  542. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  543. if err != nil {
  544. fmt.Println("read fail")
  545. }
  546. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  547. n, _ := f.Seek(0, 2)
  548. _, err = f.WriteAt([]byte(content), n)
  549. } else { //不存在
  550. fmt.Println("文件不存在,创建文件")
  551. f, err := os.Create(file_name)
  552. defer f.Close()
  553. if err != nil {
  554. } else {
  555. _, err = f.Write([]byte("记录日志"))
  556. }
  557. }
  558. }