|
@@ -4,11 +4,24 @@ import (
|
4
|
4
|
"XT_New/enums"
|
5
|
5
|
"XT_New/models"
|
6
|
6
|
"XT_New/service"
|
|
7
|
+ "XT_New/utils"
|
|
8
|
+ "bytes"
|
|
9
|
+ "encoding/json"
|
|
10
|
+ "encoding/xml"
|
|
11
|
+ "fmt"
|
7
|
12
|
"github.com/astaxie/beego"
|
|
13
|
+ "io/ioutil"
|
|
14
|
+ "net/http"
|
|
15
|
+ "os"
|
|
16
|
+ "strconv"
|
8
|
17
|
"strings"
|
9
|
18
|
"time"
|
10
|
19
|
)
|
11
|
20
|
|
|
21
|
+const (
|
|
22
|
+ key = "4a6617a4409c48dc836152e80e18febd"
|
|
23
|
+)
|
|
24
|
+
|
12
|
25
|
type HisPrintApiController struct {
|
13
|
26
|
BaseAuthAPIController
|
14
|
27
|
}
|
|
@@ -19,34 +32,205 @@ func HisPrintApiRegistRouters() {
|
19
|
32
|
beego.Router("/api/his/prescription/summary", &HisPrintApiController{}, "get:GetUnChargePrescriptionSummary")
|
20
|
33
|
beego.Router("/api/his/label/create", &HisPrintApiController{}, "get:CreateLablePrint")
|
21
|
34
|
beego.Router("/api/his/label/get", &HisPrintApiController{}, "get:GetLablePrint")
|
|
35
|
+ beego.Router("/api/his/label/send", &HisPrintApiController{}, "get:SendApplyCode")
|
|
36
|
+}
|
22
|
37
|
|
23
|
|
- //beego.Router("/api/his/checkprescription/print", &HisPrintApiController{}, "get:GetBatchCheckHisPrescriptionData")
|
|
38
|
+func (c *HisPrintApiController) SendApplyCode() {
|
|
39
|
+ list, _ := service.GetAllLisDataFor10191(c.GetAdminUserInfo().CurrentOrgId)
|
|
40
|
+ if len(list) > 0 {
|
|
41
|
+ //插入中间库中
|
|
42
|
+ for _, item := range list {
|
|
43
|
+ if len(item.ApplyCode) == 0 {
|
|
44
|
+ var apply models.JYApply
|
|
45
|
+ apply.BedCode = ""
|
|
46
|
+ apply.PatientName = item.Patient.Name
|
|
47
|
+ idCard := item.Patient.IdCardNo // 身份证号码示例
|
|
48
|
+ age, err := GetAge(idCard)
|
|
49
|
+ if err != nil {
|
|
50
|
+ age = int(item.Patient.Age)
|
|
51
|
+ fmt.Println("计算年龄时出错:", err)
|
|
52
|
+ }
|
24
|
53
|
|
25
|
|
-}
|
|
54
|
+ apply.Age = strconv.FormatInt(int64(age), 10)
|
|
55
|
+ apply.AgeUnit = "岁"
|
|
56
|
+ if item.Patient.Gender == 1 {
|
|
57
|
+ apply.Sex = "男"
|
|
58
|
+ } else if item.Patient.Gender == 2 {
|
|
59
|
+ apply.Sex = "女"
|
|
60
|
+ } else {
|
|
61
|
+ apply.Sex = "不详"
|
|
62
|
+ }
|
|
63
|
+ apply.RegisterCode = ""
|
|
64
|
+ apply.Diagnosis = ""
|
|
65
|
+ apply.Ward = ""
|
|
66
|
+ role, _ := service.GetAdminUserRole(2398, c.GetAdminUserInfo().CurrentOrgId)
|
|
67
|
+ apply.SendDoctor = role.UserName
|
|
68
|
+ apply.PatientType = 1
|
|
69
|
+ apply.PatientPhone = item.Patient.Phone
|
|
70
|
+ //applys = append(applys, apply)
|
|
71
|
+ var jYApplyDetails []models.CustomerApplyDetail
|
|
72
|
+
|
|
73
|
+ if len(item.ItemIds) > 0 {
|
|
74
|
+ team_ids := strings.Split(item.ItemIds, ",")
|
|
75
|
+ for index, subItem := range team_ids {
|
|
76
|
+ //判断一些需要拆分的组套 血透体检(定量):需要拆分出传染病检查(定性),丙型肝炎抗体测试,血透体检(定量)
|
|
77
|
+ if subItem == "267" {
|
|
78
|
+ //血透体检(定量)
|
|
79
|
+ var jYApplyDetail models.CustomerApplyDetail
|
|
80
|
+ id, _ := strconv.ParseInt(subItem, 10, 64)
|
|
81
|
+ jYApplyDetail.CustomerChargeItemCode = strconv.FormatInt(id, 10)
|
|
82
|
+ jYApplyDetail.RowIndex = int64(index + 1)
|
|
83
|
+ jYApplyDetail.Barcode = ""
|
|
84
|
+ jYApplyDetail.CustomerBarcode = strconv.FormatInt(item.ID, 10)
|
|
85
|
+ jYApplyDetail.Comment = ""
|
|
86
|
+ jYApplyDetail.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
|
|
87
|
+ jYApplyDetails = append(jYApplyDetails, jYApplyDetail)
|
|
88
|
+
|
|
89
|
+ //丙型肝炎抗体测定
|
|
90
|
+ var jYApplyDetail2 models.CustomerApplyDetail
|
|
91
|
+ id2, _ := strconv.ParseInt("26701", 10, 64)
|
|
92
|
+ jYApplyDetail2.CustomerChargeItemCode = strconv.FormatInt(id2, 10)
|
|
93
|
+ jYApplyDetail2.RowIndex = int64(index + 1)
|
|
94
|
+ jYApplyDetail2.Barcode = ""
|
|
95
|
+ jYApplyDetail2.CustomerBarcode = strconv.FormatInt(item.ID, 10)
|
|
96
|
+ jYApplyDetail2.Comment = ""
|
|
97
|
+ jYApplyDetail2.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
|
|
98
|
+ jYApplyDetails = append(jYApplyDetails, jYApplyDetail2)
|
|
99
|
+
|
|
100
|
+ //传染病检查(定性)
|
|
101
|
+ var jYApplyDetail3 models.CustomerApplyDetail
|
|
102
|
+ id3, _ := strconv.ParseInt("26700", 10, 64)
|
|
103
|
+ jYApplyDetail3.CustomerChargeItemCode = strconv.FormatInt(id3, 10)
|
|
104
|
+ jYApplyDetail3.RowIndex = int64(index + 1)
|
|
105
|
+ jYApplyDetail3.Barcode = ""
|
|
106
|
+ jYApplyDetail3.CustomerBarcode = strconv.FormatInt(item.ID, 10)
|
|
107
|
+ jYApplyDetail3.Comment = ""
|
|
108
|
+ jYApplyDetail3.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
|
|
109
|
+ jYApplyDetails = append(jYApplyDetails, jYApplyDetail3)
|
|
110
|
+
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ //判断一些需要拆分的组套 血透体检(定性):需要拆分出传染病检查(定性),丙型肝炎抗体测试,血透体检(定性)
|
|
114
|
+ if subItem == "424" {
|
|
115
|
+ //血透体检(定性)
|
|
116
|
+ var jYApplyDetail models.CustomerApplyDetail
|
|
117
|
+ id, _ := strconv.ParseInt(subItem, 10, 64)
|
|
118
|
+ jYApplyDetail.CustomerChargeItemCode = strconv.FormatInt(id, 10)
|
|
119
|
+ jYApplyDetail.RowIndex = int64(index + 1)
|
|
120
|
+ jYApplyDetail.Barcode = ""
|
|
121
|
+ jYApplyDetail.CustomerBarcode = strconv.FormatInt(item.ID, 10)
|
|
122
|
+ jYApplyDetail.Comment = ""
|
|
123
|
+ jYApplyDetail.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
|
|
124
|
+ jYApplyDetails = append(jYApplyDetails, jYApplyDetail)
|
|
125
|
+
|
|
126
|
+ //丙型肝炎抗体测定
|
|
127
|
+ var jYApplyDetail2 models.CustomerApplyDetail
|
|
128
|
+ id2, _ := strconv.ParseInt("42401", 10, 64)
|
|
129
|
+ jYApplyDetail2.CustomerChargeItemCode = strconv.FormatInt(id2, 10)
|
|
130
|
+ jYApplyDetail2.RowIndex = int64(index + 1)
|
|
131
|
+ jYApplyDetail2.Barcode = ""
|
|
132
|
+ jYApplyDetail2.CustomerBarcode = strconv.FormatInt(item.ID, 10)
|
|
133
|
+ jYApplyDetail2.Comment = ""
|
|
134
|
+ jYApplyDetail2.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
|
|
135
|
+ jYApplyDetails = append(jYApplyDetails, jYApplyDetail2)
|
|
136
|
+
|
|
137
|
+ //传染病检查(定性)
|
|
138
|
+ var jYApplyDetail3 models.CustomerApplyDetail
|
|
139
|
+ id3, _ := strconv.ParseInt("42400", 10, 64)
|
|
140
|
+ jYApplyDetail3.CustomerChargeItemCode = strconv.FormatInt(id3, 10)
|
|
141
|
+ jYApplyDetail3.RowIndex = int64(index + 1)
|
|
142
|
+ jYApplyDetail3.Barcode = ""
|
|
143
|
+ jYApplyDetail3.CustomerBarcode = strconv.FormatInt(item.ID, 10)
|
|
144
|
+ jYApplyDetail3.Comment = ""
|
|
145
|
+ jYApplyDetail3.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
|
|
146
|
+ jYApplyDetails = append(jYApplyDetails, jYApplyDetail3)
|
|
147
|
+
|
|
148
|
+ }
|
|
149
|
+ var jYApplyDetail models.CustomerApplyDetail
|
|
150
|
+ id, _ := strconv.ParseInt(subItem, 10, 64)
|
|
151
|
+ jYApplyDetail.CustomerChargeItemCode = strconv.FormatInt(id, 10)
|
|
152
|
+ jYApplyDetail.RowIndex = int64(index + 1)
|
|
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
|
+
|
|
161
|
+ if len(item.ProjectIds) > 0 {
|
|
162
|
+ team_ids := strings.Split(item.ProjectIds, ",")
|
|
163
|
+ for index, subItem := range team_ids {
|
|
164
|
+ var jYApplyDetail models.CustomerApplyDetail
|
|
165
|
+ id, _ := strconv.ParseInt(subItem, 10, 64)
|
|
166
|
+ jYApplyDetail.CustomerChargeItemCode = strconv.FormatInt(id, 10)
|
|
167
|
+ jYApplyDetail.RowIndex = int64(index)
|
|
168
|
+ jYApplyDetail.Barcode = ""
|
|
169
|
+ jYApplyDetail.CustomerBarcode = strconv.FormatInt(item.ID, 10)
|
|
170
|
+ jYApplyDetail.Comment = ""
|
|
171
|
+ jYApplyDetail.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
|
|
172
|
+ jYApplyDetails = append(jYApplyDetails, jYApplyDetail)
|
|
173
|
+ }
|
|
174
|
+ }
|
|
175
|
+ result := PostInspectApply(key, apply, jYApplyDetails)
|
|
176
|
+ if result.Res == 0 {
|
|
177
|
+ item.ApplyCode = result.JYApplyResult.ApplyCode
|
|
178
|
+ jsonData, err := json.Marshal(apply)
|
|
179
|
+ if err != nil {
|
|
180
|
+ fmt.Println("转换为JSON时发生错误:", err)
|
|
181
|
+ }
|
|
182
|
+ jsonStr := string(jsonData)
|
|
183
|
+ jsonData2, err2 := json.Marshal(jYApplyDetails)
|
|
184
|
+ if err2 != nil {
|
|
185
|
+ fmt.Println("转换为JSON时发生错误:", err2)
|
|
186
|
+ }
|
|
187
|
+ jsonStr2 := string(jsonData2)
|
|
188
|
+
|
|
189
|
+ jsonData3, err3 := json.Marshal(result)
|
|
190
|
+ if err3 != nil {
|
|
191
|
+ fmt.Println("转换为JSON时发生错误:", err3)
|
|
192
|
+ }
|
|
193
|
+ jsonStr3 := string(jsonData3)
|
|
194
|
+ saveSuccessLog(jsonStr3, jsonStr+"\r\n"+jsonStr2, "申清单成功日志", "申清单")
|
|
195
|
+ err1 := service.CreateLabelPrint(&item)
|
|
196
|
+ if err1 == nil {
|
|
197
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
198
|
+ "msg": "发送成功",
|
|
199
|
+ })
|
|
200
|
+ }
|
|
201
|
+ return
|
|
202
|
+ } else {
|
|
203
|
+ jsonData, err := json.Marshal(apply)
|
|
204
|
+ if err != nil {
|
|
205
|
+ fmt.Println("转换为JSON时发生错误:", err)
|
|
206
|
+
|
|
207
|
+ }
|
|
208
|
+ jsonStr := string(jsonData)
|
|
209
|
+
|
|
210
|
+ jsonData2, err2 := json.Marshal(jYApplyDetails)
|
|
211
|
+ if err2 != nil {
|
|
212
|
+ fmt.Println("转换为JSON时发生错误:", err2)
|
|
213
|
+
|
|
214
|
+ }
|
|
215
|
+ jsonStr2 := string(jsonData2)
|
|
216
|
+
|
|
217
|
+ jsonData3, err3 := json.Marshal(result)
|
|
218
|
+ if err3 != nil {
|
|
219
|
+ fmt.Println("转换为JSON时发生错误:", err3)
|
|
220
|
+
|
|
221
|
+ }
|
|
222
|
+ jsonStr3 := string(jsonData3)
|
26
|
223
|
|
27
|
|
-//func (c *HisPrintApiController) GetBatchCheckHisPrescriptionData() {
|
28
|
|
-// record_date := c.GetString("record_date")
|
29
|
|
-// patient_ids := c.GetString("patient_ids")
|
30
|
|
-// timeLayout := "2006-01-02"
|
31
|
|
-// loc, _ := time.LoadLocation("Local")
|
32
|
|
-// theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
|
33
|
|
-// if err != nil {
|
34
|
|
-// c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
35
|
|
-// return
|
36
|
|
-// }
|
37
|
|
-// recordDateTime := theTime.Unix()
|
38
|
|
-// adminInfo := c.GetAdminUserInfo()
|
39
|
|
-// ids := strings.Split(patient_ids, ",")
|
40
|
|
-//
|
41
|
|
-// //var newPatients []*models.PrintPatient
|
42
|
|
-//
|
43
|
|
-// patients, _ := service.GetBatchInspectionProjectHisPrescriptionTwo(ids, recordDateTime, adminInfo.CurrentOrgId)
|
44
|
|
-//
|
45
|
|
-// c.ServeSuccessJSON(map[string]interface{}{
|
46
|
|
-// "patients": patients,
|
47
|
|
-// })
|
48
|
|
-// break
|
49
|
|
-//}
|
|
224
|
+ SaveErrorLog(jsonStr3, jsonStr+"\r\n"+jsonStr2, "申清单错误日志", "申清单")
|
|
225
|
+
|
|
226
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
|
|
227
|
+ return
|
|
228
|
+ }
|
|
229
|
+ }
|
|
230
|
+ }
|
|
231
|
+
|
|
232
|
+ }
|
|
233
|
+}
|
50
|
234
|
|
51
|
235
|
func (c *HisPrintApiController) GetLablePrint() {
|
52
|
236
|
patient_id, _ := c.GetInt64("patient_id")
|
|
@@ -213,3 +397,199 @@ func (c *HisPrintApiController) GetBatchHisPrescriptionData() {
|
213
|
397
|
break
|
214
|
398
|
}
|
215
|
399
|
}
|
|
400
|
+
|
|
401
|
+func GetAge(idCard string) (int, error) {
|
|
402
|
+ birthDate, err := getBirthDateFromIDCard(idCard)
|
|
403
|
+ if err != nil {
|
|
404
|
+ return 0, err
|
|
405
|
+ }
|
|
406
|
+
|
|
407
|
+ age := calculateAge(birthDate)
|
|
408
|
+ return age, nil
|
|
409
|
+}
|
|
410
|
+
|
|
411
|
+func getBirthDateFromIDCard(idCard string) (time.Time, error) {
|
|
412
|
+ birthDateStr := idCard[6:14] // 身份证号码中生日部分的字符
|
|
413
|
+ birthDate, err := time.Parse("20060102", birthDateStr)
|
|
414
|
+ if err != nil {
|
|
415
|
+ return time.Time{}, err
|
|
416
|
+ }
|
|
417
|
+
|
|
418
|
+ return birthDate, nil
|
|
419
|
+}
|
|
420
|
+
|
|
421
|
+func calculateAge(birthDate time.Time) int {
|
|
422
|
+ now := time.Now()
|
|
423
|
+ age := now.Year() - birthDate.Year()
|
|
424
|
+
|
|
425
|
+ // 如果当前月份小于出生月份,或者当前月份等于出生月份但当前日期小于出生日期,则年龄减一
|
|
426
|
+ if now.Month() < birthDate.Month() || (now.Month() == birthDate.Month() && now.Day() < birthDate.Day()) {
|
|
427
|
+ age--
|
|
428
|
+ }
|
|
429
|
+
|
|
430
|
+ return age
|
|
431
|
+}
|
|
432
|
+
|
|
433
|
+// 送检单
|
|
434
|
+func PostInspectApply(key string, apply models.JYApply, list []models.CustomerApplyDetail) models.InspectApplyData {
|
|
435
|
+ // 构建SOAP请求数据
|
|
436
|
+ requestData := &models.JYApplyEnvelope{
|
|
437
|
+ Soap: "http://schemas.xmlsoap.org/soap/envelope/",
|
|
438
|
+ Xsi: "http://www.w3.org/2001/XMLSchema-instance",
|
|
439
|
+ Xsd: "http://www.w3.org/2001/XMLSchema",
|
|
440
|
+ Body: models.JYApplyBody{
|
|
441
|
+ InspectApplyReq: models.InspectApplyReq{
|
|
442
|
+ XMLName: xml.Name{Local: "InspectApplyByInstituteItemCode", Space: "http://tempuri.org/"},
|
|
443
|
+ ApiKey: key,
|
|
444
|
+ Apply: apply,
|
|
445
|
+ ApplyDetailList: struct {
|
|
446
|
+ CustomerApplyDetail []models.CustomerApplyDetail `xml:"CustomerApplyDetail"`
|
|
447
|
+ }{
|
|
448
|
+ CustomerApplyDetail: list,
|
|
449
|
+ },
|
|
450
|
+ ApplyAdditional: nil,
|
|
451
|
+ },
|
|
452
|
+ },
|
|
453
|
+ }
|
|
454
|
+
|
|
455
|
+ // 将SOAP请求数据转换为XML格式
|
|
456
|
+ requestBody, err := xml.Marshal(requestData)
|
|
457
|
+ if err != nil {
|
|
458
|
+ fmt.Println("XML Marshal error:", err)
|
|
459
|
+ }
|
|
460
|
+ fmt.Println(string(requestBody))
|
|
461
|
+
|
|
462
|
+ // 创建POST请求
|
|
463
|
+ url := "http://gpis.cnhiqc.com:9799/InstituteLISService.asmx"
|
|
464
|
+ req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
|
|
465
|
+ if err != nil {
|
|
466
|
+ fmt.Println("Request creation error:", err)
|
|
467
|
+ }
|
|
468
|
+
|
|
469
|
+ // 设置请求头
|
|
470
|
+ req.Header.Set("Content-Type", "text/xml; charset=utf-8")
|
|
471
|
+ req.Header.Set("Content-Length", "length")
|
|
472
|
+ req.Header.Set("SOAPAction", "http://tempuri.org/InspectApplyByInstituteItemCode")
|
|
473
|
+
|
|
474
|
+ // 发送请求
|
|
475
|
+ client := &http.Client{}
|
|
476
|
+ resp, err := client.Do(req)
|
|
477
|
+ if err != nil {
|
|
478
|
+ fmt.Println("Request error:", err)
|
|
479
|
+ }
|
|
480
|
+ defer resp.Body.Close()
|
|
481
|
+
|
|
482
|
+ // 读取响应数据
|
|
483
|
+ responseBody, err := ioutil.ReadAll(resp.Body)
|
|
484
|
+ if err != nil {
|
|
485
|
+ fmt.Println("Response read error:", err)
|
|
486
|
+
|
|
487
|
+ }
|
|
488
|
+ fmt.Println(string(responseBody))
|
|
489
|
+
|
|
490
|
+ // 解析XML数据
|
|
491
|
+ var envelope_four models.EnvelopeFour
|
|
492
|
+ err2 := xml.Unmarshal(responseBody, &envelope_four)
|
|
493
|
+ if err2 != nil {
|
|
494
|
+ fmt.Println("XML Unmarshal error:", err2)
|
|
495
|
+
|
|
496
|
+ }
|
|
497
|
+
|
|
498
|
+ // 获取GetReportListResult的JSON字符串
|
|
499
|
+ jsonStr := envelope_four.Body.InspectApplyByInstituteItemCodeResponse.InspectApply
|
|
500
|
+
|
|
501
|
+ // 解析JSON字符串到结构体
|
|
502
|
+ var reportData models.InspectApplyData
|
|
503
|
+ err = json.Unmarshal([]byte(jsonStr), &reportData)
|
|
504
|
+
|
|
505
|
+ if err != nil {
|
|
506
|
+ fmt.Println("JSON Unmarshal error:", err)
|
|
507
|
+ }
|
|
508
|
+ if reportData.Res != 0 {
|
|
509
|
+ fmt.Println("Data:", reportData)
|
|
510
|
+ //return reportData.JYApplyResult
|
|
511
|
+ }
|
|
512
|
+ return reportData
|
|
513
|
+}
|
|
514
|
+
|
|
515
|
+func SaveErrorLog(result string, request string, infno string, desc string) {
|
|
516
|
+ //org_id, _ := beego.AppConfig.Int64("org_id")
|
|
517
|
+ //miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
|
|
518
|
+ dir := "faild"
|
|
519
|
+ utils.Mkdir(dir)
|
|
520
|
+ month := time.Unix(1557042972, 0).Format("1")
|
|
521
|
+ year := time.Now().Format("2006")
|
|
522
|
+ month = time.Now().Format("01")
|
|
523
|
+ day := time.Now().Format("02")
|
|
524
|
+ hour := time.Now().Format("15")
|
|
525
|
+ min := time.Now().Format("04")
|
|
526
|
+ sec := time.Now().Format("05")
|
|
527
|
+
|
|
528
|
+ result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
|
|
529
|
+
|
|
530
|
+ file := "failed" + "_" + year + month + day + "_log"
|
|
531
|
+ file_name := file + ".txt"
|
|
532
|
+ file_path := "faild" + "/" + file_name
|
|
533
|
+ exist, _ := utils.PathExists(file_path)
|
|
534
|
+ if exist { //存在
|
|
535
|
+ fmt.Println("存在")
|
|
536
|
+ f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
|
|
537
|
+ if err != nil {
|
|
538
|
+ fmt.Println("read fail")
|
|
539
|
+ }
|
|
540
|
+ content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
|
|
541
|
+ n, _ := f.Seek(0, 2)
|
|
542
|
+ _, err = f.WriteAt([]byte(content), n)
|
|
543
|
+
|
|
544
|
+ } else { //不存在
|
|
545
|
+ fmt.Println("文件不存在,创建文件")
|
|
546
|
+ f, err := os.Create("faild" + "/" + file_name)
|
|
547
|
+ defer f.Close()
|
|
548
|
+ if err != nil {
|
|
549
|
+ } else {
|
|
550
|
+ _, err = f.Write([]byte("记录日志"))
|
|
551
|
+ }
|
|
552
|
+ }
|
|
553
|
+
|
|
554
|
+}
|
|
555
|
+func saveSuccessLog(result string, request string, infno string, desc string) {
|
|
556
|
+
|
|
557
|
+ //org_id, _ := beego.AppConfig.Int64("org_id")
|
|
558
|
+ //miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
|
|
559
|
+ //dir := "同步成功日志"
|
|
560
|
+ //utils.Mkdir(dir)
|
|
561
|
+ month := time.Unix(1557042972, 0).Format("1")
|
|
562
|
+ year := time.Now().Format("2006")
|
|
563
|
+ month = time.Now().Format("01")
|
|
564
|
+ day := time.Now().Format("02")
|
|
565
|
+ hour := time.Now().Format("15")
|
|
566
|
+ min := time.Now().Format("04")
|
|
567
|
+ sec := time.Now().Format("05")
|
|
568
|
+
|
|
569
|
+ result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
|
|
570
|
+
|
|
571
|
+ file := "success" + "_" + year + month + day + "_log"
|
|
572
|
+ file_name := file + ".txt"
|
|
573
|
+ file_path := file_name
|
|
574
|
+ exist, _ := utils.PathExists(file_path)
|
|
575
|
+ if exist { //存在
|
|
576
|
+ fmt.Println("存在")
|
|
577
|
+ f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
|
|
578
|
+ if err != nil {
|
|
579
|
+ fmt.Println("read fail")
|
|
580
|
+ }
|
|
581
|
+ content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
|
|
582
|
+ n, _ := f.Seek(0, 2)
|
|
583
|
+ _, err = f.WriteAt([]byte(content), n)
|
|
584
|
+
|
|
585
|
+ } else { //不存在
|
|
586
|
+ fmt.Println("文件不存在,创建文件")
|
|
587
|
+ f, err := os.Create(file_name)
|
|
588
|
+ defer f.Close()
|
|
589
|
+ if err != nil {
|
|
590
|
+ } else {
|
|
591
|
+ _, err = f.Write([]byte("记录日志"))
|
|
592
|
+ }
|
|
593
|
+ }
|
|
594
|
+
|
|
595
|
+}
|