his_print_api_controller.go 20KB

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