Browse Source

Merge branch 'master' of http://git.shengws.com/csx/gdyb

csx 3 years ago
parent
commit
259606666e
6 changed files with 279 additions and 122 deletions
  1. 1 1
      conf/app.conf
  2. 25 6
      controllers/sg/gdyb_controller.go
  3. 77 62
      controllers/sg/his_api_controller.go
  4. 75 0
      main.go
  5. 69 53
      service/gdyb_service.go
  6. 32 0
      utils/log.go

+ 1 - 1
conf/app.conf View File

@@ -44,7 +44,7 @@ appsecret="61ee2e6268497d5aa9de0b0187c39aea"
44 44
 
45 45
 
46 46
 [prod]
47
-org_id = 10138
47
+org_id = 10028
48 48
 mobile_token_expiration_second = 86400
49 49
 httpdomain = https://api.xt.kuyicloud.com
50 50
 sso_domain = https://sso.kuyicloud.com

+ 25 - 6
controllers/sg/gdyb_controller.go View File

@@ -80,7 +80,7 @@ func (c *GdybController) PostOne() {
80 80
 	card_sn := c.GetString("card_sn")
81 81
 	certificates := c.GetString("certificates")
82 82
 
83
-	result := service.Gdyb1101(certNo, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs, secret_key, id_card_type, card_sn, certificates)
83
+	result, inputLog := service.Gdyb1101(certNo, org_name, doctor, fixmedins_code, insuplc_admdvs, mdtrtarea_admvs, secret_key, id_card_type, card_sn, certificates)
84 84
 	var dat map[string]interface{}
85 85
 	if err := json.Unmarshal([]byte(result), &dat); err == nil {
86 86
 
@@ -88,8 +88,16 @@ func (c *GdybController) PostOne() {
88 88
 
89 89
 	}
90 90
 
91
+	var dat2 map[string]interface{}
92
+	if err := json.Unmarshal([]byte(inputLog), &dat2); err == nil {
93
+
94
+	} else {
95
+
96
+	}
97
+
91 98
 	c.ServeSuccessJSON(map[string]interface{}{
92 99
 		"pre": dat,
100
+		"log": dat2,
93 101
 	})
94 102
 }
95 103
 
@@ -113,7 +121,7 @@ func (c *GdybController) PostTwo() {
113 121
 
114 122
 	id_card_type, _ := c.GetInt64("id_card_type")
115 123
 
116
-	result := service.Gdyb2201(psnNo, insutype, certNo, org_name, doctor, ipt_otp_no, dept, fixmedins_code, dept_code, doctor_id, insuplc_admdvs, mdtrtarea_admvs, secret_key, id_card_type)
124
+	result, _ := service.Gdyb2201(psnNo, insutype, certNo, org_name, doctor, ipt_otp_no, dept, fixmedins_code, dept_code, doctor_id, insuplc_admdvs, mdtrtarea_admvs, secret_key, id_card_type)
117 125
 
118 126
 	var dat map[string]interface{}
119 127
 	if err := json.Unmarshal([]byte(result), &dat); err == nil {
@@ -136,7 +144,8 @@ func (c *GdybController) PostThree() {
136 144
 	mdtrtarea_admvs := c.GetString("mdtrtarea_admvs")
137 145
 	secret_key := c.GetString("secret_key")
138 146
 	fixmedins_code := c.GetString("fixmedins_code")
139
-	result := service.Gdyb2202(psnNo, mdtrtId, iptOtpNo, org_name, doctor, insuplc_admdvs, mdtrtarea_admvs, secret_key, fixmedins_code)
147
+	result, requestLog := service.Gdyb2202(psnNo, mdtrtId, iptOtpNo, org_name, doctor, insuplc_admdvs, mdtrtarea_admvs, secret_key, fixmedins_code)
148
+	saveLog(result, requestLog)
140 149
 	var dat map[string]interface{}
141 150
 	if err := json.Unmarshal([]byte(result), &dat); err == nil {
142 151
 	} else {
@@ -235,7 +244,7 @@ func (c *GdybController) PostFive() {
235 244
 	fmt.Println(respJSON["mdtrtarea_admvs"].(string))
236 245
 	fmt.Println(respJSON["secret_key"].(string))
237 246
 
238
-	result := service.Gdyb2204(respJSON["psn_no"].(string), respJSON["mdtrt_id"].(string), hp, respJSON["chrg_bchno"].(string), respJSON["org_name"].(string),
247
+	result, requestLog := service.Gdyb2204(respJSON["psn_no"].(string), respJSON["mdtrt_id"].(string), hp, respJSON["chrg_bchno"].(string), respJSON["org_name"].(string),
239 248
 		respJSON["doctor"].(string), respJSON["dept"].(string), respJSON["fixmedins_code"].(string), respJSON["dept_code"].(string), respJSON["doctor_id"].(string), respJSON["insuplc_admdvs"].(string), respJSON["mdtrtarea_admvs"].(string), respJSON["secret_key"].(string), respJSON["balance_accounts_type"].(string))
240 249
 
241 250
 	var dat map[string]interface{}
@@ -244,8 +253,17 @@ func (c *GdybController) PostFive() {
244 253
 	} else {
245 254
 		fmt.Println(err)
246 255
 	}
256
+
257
+	var dat2 map[string]interface{}
258
+	if err := json.Unmarshal([]byte(requestLog), &dat2); err == nil {
259
+		fmt.Println(dat2)
260
+	} else {
261
+		fmt.Println(err)
262
+	}
263
+
247 264
 	c.ServeSuccessJSON(map[string]interface{}{
248
-		"pre": dat,
265
+		"pre":         dat,
266
+		"request_log": requestLog,
249 267
 	})
250 268
 }
251 269
 
@@ -262,7 +280,8 @@ func (c *GdybController) PostSix() {
262 280
 	secret_key := c.GetString("secret_key")
263 281
 	fixmedins_code := c.GetString("fixmedins_code")
264 282
 
265
-	result := service.Gdyb2205(psnNo, mdtrtId, chrgBchno, org_name, doctor, insuplc_admdvs, mdtrtarea_admvs, secret_key, fixmedins_code)
283
+	result, requestlog := service.Gdyb2205(psnNo, mdtrtId, chrgBchno, org_name, doctor, insuplc_admdvs, mdtrtarea_admvs, secret_key, fixmedins_code)
284
+	fmt.Println(requestlog)
266 285
 	var dat map[string]interface{}
267 286
 	if err := json.Unmarshal([]byte(result), &dat); err == nil {
268 287
 		fmt.Println(dat)

+ 77 - 62
controllers/sg/his_api_controller.go View File

@@ -1759,32 +1759,10 @@ func (c *HisApiController) GetRegisterInfo() {
1759 1759
 
1760 1760
 	if config.IsOpen == 1 {
1761 1761
 		//service.Gdyb1201("", miConfig.OrgName, "1122", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 1, "")
1762
-
1763
-		api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&id_card_type=" + strconv.FormatInt(id_card_type, 10) + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&certificates=" + strconv.FormatInt(certificates, 10)
1764
-		resp, requestErr := http.Get(api)
1765
-		if requestErr != nil {
1766
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1767
-			return
1768
-		}
1769
-		defer resp.Body.Close()
1770
-		body, ioErr := ioutil.ReadAll(resp.Body)
1771
-		if ioErr != nil {
1772
-			utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
1773
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1774
-			return
1775
-		}
1776
-		var respJSON map[string]interface{}
1777
-
1778
-		if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
1779
-			utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
1780
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1781
-			return
1782
-		}
1783
-
1784
-		userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
1785
-		userJSONBytes, _ := json.Marshal(userJSON)
1762
+		result, requestLog := service.Gdyb1101(patient.IdCardNo, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, "", strconv.FormatInt(certificates, 10))
1763
+		saveLog(result, requestLog)
1786 1764
 		var res ResultTwo
1787
-		if err := json.Unmarshal(userJSONBytes, &res); err != nil {
1765
+		if err := json.Unmarshal([]byte(result), &res); err != nil {
1788 1766
 			utils.ErrorLog("解析失败:%v", err)
1789 1767
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1790 1768
 			return
@@ -1884,37 +1862,12 @@ func (c *HisApiController) GetRegisterInfo() {
1884 1862
 
1885 1863
 			//insutype = "390"
1886 1864
 
1887
-			//if count == 1 {
1888
-			//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
1889
-			//	return
1890
-			//}
1891
-			api := "http://127.0.0.1:9532/" + "gdyb/two?cert_no=" + IdCardNo + "&insutype=" +
1892
-				insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
1893
-				"&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
1894
-				"&dept=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&dept_code=" + department.Number + "&doctor_id=" + doctor_id + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10)
1895
-			resp, requestErr := http.Get(api)
1896
-			if requestErr != nil {
1897
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1898
-				return
1899
-			}
1900
-			defer resp.Body.Close()
1901
-			body, ioErr := ioutil.ReadAll(resp.Body)
1902
-			if ioErr != nil {
1903
-				utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
1904
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1905
-				return
1906
-			}
1907
-			var respJSON map[string]interface{}
1908
-			if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
1909
-				utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
1910
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1911
-				return
1912
-			}
1865
+			result, requestLog := service.Gdyb2201(res.Output.Baseinfo.PsnNo, insutype, IdCardNo, miConfig.OrgName, roles.UserName, ipt_otp_no, department.Name, miConfig.Code, department.Number, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type)
1866
+
1867
+			saveLog(result, requestLog)
1913 1868
 
1914
-			respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
1915
-			userJSONBytes, _ := json.Marshal(respJSON)
1916 1869
 			var res ResultThree
1917
-			if err := json.Unmarshal(userJSONBytes, &res); err != nil {
1870
+			if err := json.Unmarshal([]byte(result), &res); err != nil {
1918 1871
 				utils.ErrorLog("解析失败:%v", err)
1919 1872
 				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1920 1873
 				return
@@ -1937,8 +1890,6 @@ func (c *HisApiController) GetRegisterInfo() {
1937 1890
 					"msg":         res.ErrMsg,
1938 1891
 				})
1939 1892
 				return
1940
-				//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
1941
-				//return
1942 1893
 			}
1943 1894
 
1944 1895
 			his.Number = res.Output.Data.MdtrtID
@@ -2085,13 +2036,17 @@ func (c *HisApiController) GetUploadInfo() {
2085 2036
 
2086 2037
 	if tempOrder.ID == 0 {
2087 2038
 		var result string
2039
+		var requestLog string
2040
+
2088 2041
 		if miConfig.InsuplcAdmdvs == "440781" { //
2089
-			result = service.Gdyb2203A(his.PsnNo, his.Number, doctor_info.UserName, department.Name, miConfig.OrgName, strconv.FormatInt(reg_type, 10), doctor_info.AdminUserId, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sickConfig.ContentCode, sickConfig.ClassName, roles.UserName, config)
2042
+			result, requestLog = service.Gdyb2203A(his.PsnNo, his.Number, doctor_info.UserName, department.Name, miConfig.OrgName, strconv.FormatInt(reg_type, 10), doctor_info.AdminUserId, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sickConfig.ContentCode, sickConfig.ClassName, roles.UserName, config)
2090 2043
 		} else {
2091
-			result = service.Gdyb2203(his.PsnNo, his.Number, doctor_info.UserName, department.Name, miConfig.OrgName, strconv.FormatInt(reg_type, 10), doctor_info.AdminUserId, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sickConfig.ContentCode, sickConfig.ClassName, roles.UserName, config)
2044
+			result, requestLog = service.Gdyb2203(his.PsnNo, his.Number, doctor_info.UserName, department.Name, miConfig.OrgName, strconv.FormatInt(reg_type, 10), doctor_info.AdminUserId, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sickConfig.ContentCode, sickConfig.ClassName, roles.UserName, config)
2092 2045
 
2093 2046
 		}
2094 2047
 
2048
+		saveLog(result, requestLog)
2049
+
2095 2050
 		var respJSON2 map[string]interface{}
2096 2051
 		if err := json.Unmarshal([]byte(string(result)), &respJSON2); err != nil {
2097 2052
 			utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
@@ -2223,6 +2178,12 @@ func (c *HisApiController) GetUploadInfo() {
2223 2178
 
2224 2179
 				respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
2225 2180
 				userJSONBytes, _ := json.Marshal(respJSON)
2181
+
2182
+				request_respJSON := respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
2183
+				requestJSONBytes, _ := json.Marshal(request_respJSON)
2184
+
2185
+				saveLog(string(userJSONBytes), string(requestJSONBytes))
2186
+
2226 2187
 				var res ResultFour
2227 2188
 				if err := json.Unmarshal(userJSONBytes, &res); err != nil {
2228 2189
 					utils.ErrorLog("解析失败:%v", err)
@@ -2412,6 +2373,8 @@ func (c *HisApiController) GetUploadInfo() {
2412 2373
 							fmt.Println(err)
2413 2374
 						}
2414 2375
 
2376
+						saveLog(result, src_resquest)
2377
+
2415 2378
 						userJSONBytes, _ := json.Marshal(dat)
2416 2379
 
2417 2380
 						var res ResultSeven
@@ -2606,6 +2569,8 @@ func (c *HisApiController) GetUploadInfo() {
2606 2569
 				fmt.Println(err)
2607 2570
 			}
2608 2571
 
2572
+			saveLog(result, src_resquest)
2573
+
2609 2574
 			userJSONBytes, _ := json.Marshal(dat)
2610 2575
 
2611 2576
 			var res ResultSeven
@@ -3289,13 +3254,16 @@ func (c *HisApiController) GetPreUploadInfo() {
3289 3254
 	strconv.FormatInt(his.PatientId, 10)
3290 3255
 
3291 3256
 	var result string
3257
+	var requestLog string
3292 3258
 	if miConfig.InsuplcAdmdvs == "440781" { //
3293
-		result = service.Gdyb2203A(his.PsnNo, his.Number, doctor_info.UserName, department.Name, miConfig.OrgName, strconv.FormatInt(reg_type, 10), doctor_info.AdminUserId, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sickConfig.ContentCode, sickConfig.ClassName, roles.UserName, config)
3259
+		result, requestLog = service.Gdyb2203A(his.PsnNo, his.Number, doctor_info.UserName, department.Name, miConfig.OrgName, strconv.FormatInt(reg_type, 10), doctor_info.AdminUserId, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sickConfig.ContentCode, sickConfig.ClassName, roles.UserName, config)
3294 3260
 	} else {
3295
-		result = service.Gdyb2203(his.PsnNo, his.Number, doctor_info.UserName, department.Name, miConfig.OrgName, strconv.FormatInt(reg_type, 10), doctor_info.AdminUserId, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sickConfig.CountryCode, sickConfig.ClassName, roles.UserName, config)
3261
+		result, requestLog = service.Gdyb2203(his.PsnNo, his.Number, doctor_info.UserName, department.Name, miConfig.OrgName, strconv.FormatInt(reg_type, 10), doctor_info.AdminUserId, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sickConfig.CountryCode, sickConfig.ClassName, roles.UserName, config)
3296 3262
 
3297 3263
 	}
3298 3264
 
3265
+	saveLog(result, requestLog)
3266
+
3299 3267
 	var respJSON2 map[string]interface{}
3300 3268
 	if err := json.Unmarshal([]byte(string(result)), &respJSON2); err != nil {
3301 3269
 		utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
@@ -3416,6 +3384,12 @@ func (c *HisApiController) GetPreUploadInfo() {
3416 3384
 
3417 3385
 			respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
3418 3386
 			userJSONBytes, _ := json.Marshal(respJSON)
3387
+
3388
+			request_respJSON := respJSON["data"].(map[string]interface{})["request_log"].(map[string]interface{})
3389
+			requestJSONBytes, _ := json.Marshal(request_respJSON)
3390
+
3391
+			saveLog(string(userJSONBytes), string(requestJSONBytes))
3392
+
3419 3393
 			var res ResultFour
3420 3394
 			if err := json.Unmarshal(userJSONBytes, &res); err != nil {
3421 3395
 				utils.ErrorLog("解析失败:%v", err)
@@ -3586,7 +3560,7 @@ func (c *HisApiController) GetPreUploadInfo() {
3586 3560
 
3587 3561
 					}
3588 3562
 
3589
-					result := service.Gdyb2206(his.PsnNo, his.Number, chrg_bchno, cert_no, insutype, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, strconv.FormatInt(reg_type, 10), his.IdCardType, 0, 0, 0, 0, his.IdType)
3563
+					result, request_log := service.Gdyb2206(his.PsnNo, his.Number, chrg_bchno, cert_no, insutype, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, strconv.FormatInt(reg_type, 10), his.IdCardType, 0, 0, 0, 0, his.IdType)
3590 3564
 					var dat map[string]interface{}
3591 3565
 					if err := json.Unmarshal([]byte(result), &dat); err == nil {
3592 3566
 						fmt.Println(dat)
@@ -3594,6 +3568,8 @@ func (c *HisApiController) GetPreUploadInfo() {
3594 3568
 						fmt.Println(err)
3595 3569
 					}
3596 3570
 
3571
+					saveLog(result, request_log)
3572
+
3597 3573
 					userJSONBytes, _ := json.Marshal(dat)
3598 3574
 
3599 3575
 					var res ResultSeven
@@ -3963,6 +3939,7 @@ func (c *HisApiController) Refund() {
3963 3939
 		} else {
3964 3940
 			fmt.Println(err)
3965 3941
 		}
3942
+		saveLog(result, src_resquest)
3966 3943
 
3967 3944
 		userJSONBytes, _ := json.Marshal(dat)
3968 3945
 
@@ -3973,7 +3950,7 @@ func (c *HisApiController) Refund() {
3973 3950
 			return
3974 3951
 		}
3975 3952
 		if res.Infcode == 0 {
3976
-			result := service.Gdyb2205(order.PsnNo, order.MdtrtId, order.Number, miConfig.OrgName, roles.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
3953
+			result, src_request := service.Gdyb2205(order.PsnNo, order.MdtrtId, order.Number, miConfig.OrgName, roles.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
3977 3954
 			var dat map[string]interface{}
3978 3955
 			if err := json.Unmarshal([]byte(result), &dat); err == nil {
3979 3956
 				fmt.Println(dat)
@@ -3981,6 +3958,8 @@ func (c *HisApiController) Refund() {
3981 3958
 				fmt.Println(err)
3982 3959
 			}
3983 3960
 
3961
+			saveLog(result, src_request)
3962
+
3984 3963
 			userJSONBytes, _ := json.Marshal(dat)
3985 3964
 
3986 3965
 			var res2 ResultSix
@@ -6102,3 +6081,39 @@ func RemoveRepeatedCode(arr []string) (newArr []string) {
6102 6081
 	}
6103 6082
 	return
6104 6083
 }
6084
+
6085
+func saveLog(result string, request string) {
6086
+
6087
+	org_id, _ := beego.AppConfig.Int64("org_id")
6088
+	miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
6089
+	dir := miConfig.OrgName + "日志"
6090
+	utils.Mkdir(dir)
6091
+	month := time.Unix(1557042972, 0).Format("1")
6092
+	year := time.Now().Format("2006")
6093
+	month = time.Now().Format("01")
6094
+	day := time.Now().Format("02")
6095
+	file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
6096
+	file_name := file + ".txt"
6097
+	file_path := miConfig.OrgName + "日志" + "/" + file_name
6098
+	exist, _ := utils.PathExists(file_path)
6099
+	if exist { //存在
6100
+		fmt.Println("存在")
6101
+		f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
6102
+		if err != nil {
6103
+			fmt.Println("read fail")
6104
+		}
6105
+		content := "\r" + request + "\r" + result
6106
+		n, _ := f.Seek(0, 2)
6107
+		_, err = f.WriteAt([]byte(content), n)
6108
+
6109
+	} else { //不存在
6110
+		fmt.Println("文件不存在,创建文件")
6111
+		f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
6112
+		defer f.Close()
6113
+		if err != nil {
6114
+		} else {
6115
+			_, err = f.Write([]byte("记录日志"))
6116
+		}
6117
+	}
6118
+
6119
+}

+ 75 - 0
main.go View File

@@ -1,9 +1,17 @@
1 1
 package main
2 2
 
3 3
 import (
4
+	"context"
5
+	"fmt"
4 6
 	_ "gdyb/routers"
5 7
 	"gdyb/service"
8
+	"gdyb/utils"
6 9
 	"github.com/astaxie/beego"
10
+	"github.com/qiniu/api.v7/auth/qbox"
11
+	"github.com/qiniu/api.v7/storage"
12
+	"os"
13
+	"strconv"
14
+	"time"
7 15
 )
8 16
 
9 17
 func init() {
@@ -12,7 +20,74 @@ func init() {
12 20
 }
13 21
 
14 22
 func main() {
23
+	org_id, _ := beego.AppConfig.Int64("org_id")
24
+	miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
25
+	dir := miConfig.OrgName + "日志"
26
+	utils.Mkdir(dir)
27
+	month := time.Unix(1557042972, 0).Format("1")
28
+	year := time.Now().Format("2006")
29
+	month = time.Now().Format("01")
30
+	day := time.Now().Format("02")
31
+	file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
32
+	file_name := file + ".txt"
33
+	file_path := miConfig.OrgName + "日志" + "/" + file_name
34
+	exist, _ := utils.PathExists(file_path)
35
+	if exist { //存在
36
+		fmt.Println("存在")
37
+		f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
38
+		if err != nil {
39
+			fmt.Println("read fail")
40
+		}
41
+		content := "\r\r\r"
42
+		n, _ := f.Seek(0, 2)
43
+		_, err = f.WriteAt([]byte(content), n)
15 44
 
45
+	} else { //不存在
46
+		fmt.Println("文件不存在,创建文件")
47
+		f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
48
+		defer f.Close()
49
+		if err != nil {
50
+		} else {
51
+			_, err = f.Write([]byte("记录日志"))
52
+		}
53
+	}
54
+	//upload_qiniu(file_path,miConfig.OrgName+"_"+year+month+day)
16 55
 	beego.Run()
56
+}
57
+
58
+func upload_qiniu(filePath string, temp_key string) {
59
+	key := temp_key
60
+	//上传凭证,关于凭证这块大家可以去看看官方文档
61
+	putPolicy := storage.PutPolicy{
62
+		Scope: beego.AppConfig.String("qiniu_bucket"),
63
+	}
64
+	mac := qbox.NewMac(beego.AppConfig.String("qiniu_accesskey"), beego.AppConfig.String("qiniu_secretkey"))
65
+	upToken := putPolicy.UploadToken(mac)
66
+	cfg := storage.Config{}
67
+	//空间对应机房
68
+	//其中关于Zone对象和机房的关系如下:
69
+	//    机房    Zone对象
70
+	//    华东    storage.ZoneHuadong
71
+	//    华北    storage.ZoneHuabei
72
+	//    华南    storage.ZoneHuanan
73
+	//    北美    storage.ZoneBeimei
74
+	//七牛云存储空间设置首页有存储区域
75
+	cfg.Zone = &storage.ZoneHuadong
76
+	//不启用HTTPS域名
77
+	cfg.UseHTTPS = false
78
+	//不使用CND加速
79
+	cfg.UseCdnDomains = false
80
+	//构建上传表单对象
81
+	formUploader := storage.NewFormUploader(&cfg)
82
+	ret := storage.PutRet{}
83
+	// 可选
84
+	putExtra := storage.PutExtra{
85
+		Params: map[string]string{},
86
+	}
87
+	err := formUploader.PutFile(context.Background(), &ret, upToken, key, filePath, &putExtra)
88
+	if err != nil {
89
+		fmt.Println(err)
90
+		return
91
+	}
17 92
 
18 93
 }

+ 69 - 53
service/gdyb_service.go View File

@@ -21,7 +21,7 @@ import (
21 21
 	"time"
22 22
 	"unsafe"
23 23
 
24
-	ole "github.com/go-ole/go-ole"
24
+	"github.com/go-ole/go-ole"
25 25
 	"github.com/go-ole/go-ole/oleutil"
26 26
 )
27 27
 
@@ -141,7 +141,7 @@ func Gdyb1201(certNo string, org_name string, doctor string, fixmedins_code stri
141 141
 }
142 142
 
143 143
 // 人员基本信息
144
-func Gdyb1101(certNo string, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, id_card_type int64, card_sn string, certificates string) string {
144
+func Gdyb1101(certNo string, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, id_card_type int64, card_sn string, certificates string) (string, string) {
145 145
 	//生成签名
146 146
 	nonce := GetRandomString(32)
147 147
 	timestamp := time.Now().Unix()
@@ -178,11 +178,13 @@ func Gdyb1101(certNo string, org_name string, doctor string, fixmedins_code stri
178 178
 	input["data"] = inputData
179 179
 	inputMessage["input"] = input //交易输入
180 180
 
181
+	var inputLog string
181 182
 	bytesData, err := json.Marshal(inputMessage)
183
+	inputLog = string(bytesData)
182 184
 	fmt.Println(string(bytesData))
183 185
 	if err != nil {
184 186
 		fmt.Println(err.Error())
185
-		return err.Error()
187
+		return err.Error(), ""
186 188
 	}
187 189
 	reader := bytes.NewReader(bytesData)
188 190
 	gdyb_url := beego.AppConfig.String("gdyb_url")
@@ -202,7 +204,7 @@ func Gdyb1101(certNo string, org_name string, doctor string, fixmedins_code stri
202 204
 	request, err := http.NewRequest("POST", url, reader)
203 205
 	if err != nil {
204 206
 		fmt.Println(err.Error())
205
-		return err.Error()
207
+		return err.Error(), ""
206 208
 	}
207 209
 
208 210
 	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
@@ -215,16 +217,16 @@ func Gdyb1101(certNo string, org_name string, doctor string, fixmedins_code stri
215 217
 	resp, err := client.Do(request)
216 218
 	if err != nil {
217 219
 		fmt.Println(err.Error())
218
-		return err.Error()
220
+		return err.Error(), ""
219 221
 	}
220 222
 	respBytes, err := ioutil.ReadAll(resp.Body)
221 223
 	if err != nil {
222 224
 		fmt.Println(err.Error())
223
-		return err.Error()
225
+		return err.Error(), ""
224 226
 	}
225 227
 	fmt.Println(string(respBytes))
226 228
 	str := string(respBytes)
227
-	return str
229
+	return str, inputLog
228 230
 }
229 231
 
230 232
 func Gdyb1101A(certNo string, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string) string {
@@ -290,7 +292,7 @@ func Gdyb1101A(certNo string, org_name string, doctor string, fixmedins_code str
290 292
 }
291 293
 
292 294
 // 门诊挂号
293
-func Gdyb2201(psnNo string, insutype string, certNo string, org_name string, doctor string, ipt_otp_no string, dept string, fixmedins_code string, dept_code string, doctor_id string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, id_card_type int64) string {
295
+func Gdyb2201(psnNo string, insutype string, certNo string, org_name string, doctor string, ipt_otp_no string, dept string, fixmedins_code string, dept_code string, doctor_id string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, id_card_type int64) (string, string) {
294 296
 	// 生成签名
295 297
 	nonce := GetRandomString(32)
296 298
 	timestamp := time.Now().Unix()
@@ -325,11 +327,13 @@ func Gdyb2201(psnNo string, insutype string, certNo string, org_name string, doc
325 327
 	input["data"] = inputData
326 328
 	inputMessage["input"] = input //交易输入
327 329
 
330
+	var requestLog string
328 331
 	bytesData, err := json.Marshal(inputMessage)
332
+	requestLog = string(bytesData)
329 333
 	fmt.Println(string(bytesData))
330 334
 	if err != nil {
331 335
 		fmt.Println(err.Error())
332
-		return err.Error()
336
+		return err.Error(), ""
333 337
 	}
334 338
 	reader := bytes.NewReader(bytesData)
335 339
 	//url := "http://igb.hsa.gdgov.cn/ebus/gdyb_api/prd/hsa/hgs/2201"
@@ -342,7 +346,7 @@ func Gdyb2201(psnNo string, insutype string, certNo string, org_name string, doc
342 346
 	request, err := http.NewRequest("POST", url, reader)
343 347
 	if err != nil {
344 348
 		fmt.Println(err.Error())
345
-		return err.Error()
349
+		return err.Error(), ""
346 350
 	}
347 351
 
348 352
 	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
@@ -355,20 +359,20 @@ func Gdyb2201(psnNo string, insutype string, certNo string, org_name string, doc
355 359
 	resp, err := client.Do(request)
356 360
 	if err != nil {
357 361
 		fmt.Println(err.Error())
358
-		return err.Error()
362
+		return err.Error(), ""
359 363
 	}
360 364
 	respBytes, err := ioutil.ReadAll(resp.Body)
361 365
 	if err != nil {
362 366
 		fmt.Println(err.Error())
363
-		return err.Error()
367
+		return err.Error(), ""
364 368
 	}
365 369
 	str := string(respBytes)
366 370
 	fmt.Println(str)
367
-	return str
371
+	return str, requestLog
368 372
 }
369 373
 
370 374
 // 门诊挂号撤销
371
-func Gdyb2202(psnNo string, mdtrtId string, ipt_otp_no string, org_name string, doctor string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, fixmedins_code string) string {
375
+func Gdyb2202(psnNo string, mdtrtId string, ipt_otp_no string, org_name string, doctor string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, fixmedins_code string) (string, string) {
372 376
 	// 生成签名
373 377
 	nonce := GetRandomString(32)
374 378
 	timestamp := time.Now().Unix()
@@ -386,11 +390,14 @@ func Gdyb2202(psnNo string, mdtrtId string, ipt_otp_no string, org_name string,
386 390
 	input["data"] = inputData
387 391
 	inputMessage["input"] = input //交易输入
388 392
 
393
+	var requestLog string
394
+
389 395
 	bytesData, err := json.Marshal(inputMessage)
390 396
 	fmt.Println(string(bytesData))
397
+	requestLog = string(bytesData)
391 398
 	if err != nil {
392 399
 		fmt.Println(err.Error())
393
-		return err.Error()
400
+		return err.Error(), ""
394 401
 	}
395 402
 	reader := bytes.NewReader(bytesData)
396 403
 
@@ -404,7 +411,7 @@ func Gdyb2202(psnNo string, mdtrtId string, ipt_otp_no string, org_name string,
404 411
 	request, err := http.NewRequest("POST", url, reader)
405 412
 	if err != nil {
406 413
 		fmt.Println(err.Error())
407
-		return err.Error()
414
+		return err.Error(), ""
408 415
 	}
409 416
 
410 417
 	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
@@ -419,20 +426,20 @@ func Gdyb2202(psnNo string, mdtrtId string, ipt_otp_no string, org_name string,
419 426
 	resp, err := client.Do(request)
420 427
 	if err != nil {
421 428
 		fmt.Println(err.Error())
422
-		return err.Error()
429
+		return err.Error(), ""
423 430
 	}
424 431
 	respBytes, err := ioutil.ReadAll(resp.Body)
425 432
 	if err != nil {
426 433
 		fmt.Println(err.Error())
427
-		return err.Error()
434
+		return err.Error(), ""
428 435
 	}
429 436
 	str := string(respBytes)
430 437
 	fmt.Println(str)
431
-	return str
438
+	return str, requestLog
432 439
 }
433 440
 
434 441
 // 门诊就诊信息上传
435
-func Gdyb2203(psnNo string, mdtrtId string, doctor string, department string, org_name string, med_type string, doctor_id int64, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, sick_code string, sick_name string, dept string, config []*models.HisXtDiagnoseConfig) string {
442
+func Gdyb2203(psnNo string, mdtrtId string, doctor string, department string, org_name string, med_type string, doctor_id int64, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, sick_code string, sick_name string, dept string, config []*models.HisXtDiagnoseConfig) (string, string) {
436 443
 	// 生成签名
437 444
 	nonce := GetRandomString(32)
438 445
 	timestamp := time.Now().Unix()
@@ -475,12 +482,13 @@ func Gdyb2203(psnNo string, mdtrtId string, doctor string, department string, or
475 482
 	input["diseinfo"] = diseinfo
476 483
 	input["mdtrtinfo"] = inputData
477 484
 	inputMessage["input"] = input //交易输入
478
-
485
+	var requestLog string
479 486
 	bytesData, err := json.Marshal(inputMessage)
480 487
 	fmt.Println(string(bytesData))
488
+	requestLog = string(bytesData)
481 489
 	if err != nil {
482 490
 		fmt.Println(err.Error())
483
-		return err.Error()
491
+		return err.Error(), ""
484 492
 	}
485 493
 	reader := bytes.NewReader(bytesData)
486 494
 
@@ -495,7 +503,7 @@ func Gdyb2203(psnNo string, mdtrtId string, doctor string, department string, or
495 503
 	request, err := http.NewRequest("POST", url, reader)
496 504
 	if err != nil {
497 505
 		fmt.Println(err.Error())
498
-		return err.Error()
506
+		return err.Error(), ""
499 507
 	}
500 508
 
501 509
 	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
@@ -508,20 +516,20 @@ func Gdyb2203(psnNo string, mdtrtId string, doctor string, department string, or
508 516
 	resp, err := client.Do(request)
509 517
 	if err != nil {
510 518
 		fmt.Println(err.Error())
511
-		return err.Error()
519
+		return err.Error(), ""
512 520
 	}
513 521
 	respBytes, err := ioutil.ReadAll(resp.Body)
514 522
 	if err != nil {
515 523
 		fmt.Println(err.Error())
516
-		return err.Error()
524
+		return err.Error(), ""
517 525
 	}
518 526
 	str := string(respBytes)
519 527
 	fmt.Println(str)
520
-	return str
528
+	return str, requestLog
521 529
 }
522 530
 
523 531
 // 门诊就诊信息上传
524
-func Gdyb2203A(psnNo string, mdtrtId string, doctor string, department string, org_name string, med_type string, doctor_id int64, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, sick_code string, sick_name string, dept string, config []*models.HisXtDiagnoseConfig) string {
532
+func Gdyb2203A(psnNo string, mdtrtId string, doctor string, department string, org_name string, med_type string, doctor_id int64, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, sick_code string, sick_name string, dept string, config []*models.HisXtDiagnoseConfig) (string, string) {
525 533
 	// 生成签名
526 534
 	nonce := GetRandomString(32)
527 535
 	timestamp := time.Now().Unix()
@@ -567,12 +575,13 @@ func Gdyb2203A(psnNo string, mdtrtId string, doctor string, department string, o
567 575
 	input["diseinfo"] = diseinfo
568 576
 	input["mdtrtinfo"] = inputData
569 577
 	inputMessage["input"] = input //交易输入
570
-
578
+	var requestLog string
571 579
 	bytesData, err := json.Marshal(inputMessage)
572 580
 	fmt.Println(string(bytesData))
581
+	requestLog = string(bytesData)
573 582
 	if err != nil {
574 583
 		fmt.Println(err.Error())
575
-		return err.Error()
584
+		return err.Error(), ""
576 585
 	}
577 586
 	reader := bytes.NewReader(bytesData)
578 587
 
@@ -587,7 +596,7 @@ func Gdyb2203A(psnNo string, mdtrtId string, doctor string, department string, o
587 596
 	request, err := http.NewRequest("POST", url, reader)
588 597
 	if err != nil {
589 598
 		fmt.Println(err.Error())
590
-		return err.Error()
599
+		return err.Error(), ""
591 600
 	}
592 601
 
593 602
 	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
@@ -600,16 +609,16 @@ func Gdyb2203A(psnNo string, mdtrtId string, doctor string, department string, o
600 609
 	resp, err := client.Do(request)
601 610
 	if err != nil {
602 611
 		fmt.Println(err.Error())
603
-		return err.Error()
612
+		return err.Error(), ""
604 613
 	}
605 614
 	respBytes, err := ioutil.ReadAll(resp.Body)
606 615
 	if err != nil {
607 616
 		fmt.Println(err.Error())
608
-		return err.Error()
617
+		return err.Error(), ""
609 618
 	}
610 619
 	str := string(respBytes)
611 620
 	fmt.Println(str)
612
-	return str
621
+	return str, requestLog
613 622
 }
614 623
 
615 624
 type Custom struct {
@@ -669,7 +678,7 @@ type Result struct {
669 678
 }
670 679
 
671 680
 //  门诊费用明细信息上传
672
-func Gdyb2204(psnNo string, mdtrtId string, hisPrescription []*models.HisPrescription, chrg_bchno string, org_name string, doctor string, dept string, fixmedins_code string, dept_code string, doctor_id string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, balance_accounts_type string) string {
681
+func Gdyb2204(psnNo string, mdtrtId string, hisPrescription []*models.HisPrescription, chrg_bchno string, org_name string, doctor string, dept string, fixmedins_code string, dept_code string, doctor_id string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, balance_accounts_type string) (string, string) {
673 682
 	// 生成签名
674 683
 	nonce := GetRandomString(32)
675 684
 	timestamp := time.Now().Unix()
@@ -815,15 +824,15 @@ func Gdyb2204(psnNo string, mdtrtId string, hisPrescription []*models.HisPrescri
815 824
 	}
816 825
 	input["feedetail"] = feedetail
817 826
 	inputMessage["input"] = input //交易输入
818
-
827
+	var requestLog string
819 828
 	bytesData, err := json.Marshal(inputMessage)
820 829
 	fmt.Println("----------")
821 830
 	fmt.Println(string(bytesData))
822 831
 	fmt.Println("----------")
823
-
832
+	requestLog = string(bytesData)
824 833
 	if err != nil {
825 834
 		fmt.Println(err.Error())
826
-		return ""
835
+		return "", ""
827 836
 	}
828 837
 	reader := bytes.NewReader(bytesData)
829 838
 
@@ -840,7 +849,7 @@ func Gdyb2204(psnNo string, mdtrtId string, hisPrescription []*models.HisPrescri
840 849
 	request, err := http.NewRequest("POST", url, reader)
841 850
 	if err != nil {
842 851
 		fmt.Println(err.Error())
843
-		return ""
852
+		return "", ""
844 853
 	}
845 854
 
846 855
 	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
@@ -853,21 +862,21 @@ func Gdyb2204(psnNo string, mdtrtId string, hisPrescription []*models.HisPrescri
853 862
 	resp, err := client.Do(request)
854 863
 	if err != nil {
855 864
 		fmt.Println(err.Error())
856
-		return ""
865
+		return "", ""
857 866
 	}
858 867
 	respBytes, err := ioutil.ReadAll(resp.Body)
859 868
 	if err != nil {
860 869
 		fmt.Println(err.Error())
861
-		return ""
870
+		return "", ""
862 871
 	}
863
-	return string(respBytes)
872
+	return string(respBytes), requestLog
864 873
 	//var result RequestResult
865 874
 	//json.Unmarshal(respBytes, &result)
866 875
 	//return &result
867 876
 }
868 877
 
869 878
 //  门诊费用明细信息撤销
870
-func Gdyb2205(psnNo string, mdtrtId string, chrgBchno string, org_name string, doctor string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, fixmedins_code string) string {
879
+func Gdyb2205(psnNo string, mdtrtId string, chrgBchno string, org_name string, doctor string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, fixmedins_code string) (string, string) {
871 880
 	// 生成签名
872 881
 	nonce := GetRandomString(32)
873 882
 	timestamp := time.Now().Unix()
@@ -888,9 +897,12 @@ func Gdyb2205(psnNo string, mdtrtId string, chrgBchno string, org_name string, d
888 897
 
889 898
 	bytesData, err := json.Marshal(inputMessage)
890 899
 	fmt.Println(string(bytesData))
900
+
901
+	var requestLog string
902
+	requestLog = string(bytesData)
891 903
 	if err != nil {
892 904
 		fmt.Println(err.Error())
893
-		return err.Error()
905
+		return err.Error(), ""
894 906
 	}
895 907
 	reader := bytes.NewReader(bytesData)
896 908
 	gdyb_url := beego.AppConfig.String("gdyb_url")
@@ -909,7 +921,7 @@ func Gdyb2205(psnNo string, mdtrtId string, chrgBchno string, org_name string, d
909 921
 	fmt.Println(request)
910 922
 	if err != nil {
911 923
 		fmt.Println(err.Error())
912
-		return err.Error()
924
+		return err.Error(), ""
913 925
 	}
914 926
 
915 927
 	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
@@ -922,21 +934,21 @@ func Gdyb2205(psnNo string, mdtrtId string, chrgBchno string, org_name string, d
922 934
 	resp, err := client.Do(request)
923 935
 	if err != nil {
924 936
 		fmt.Println(err.Error())
925
-		return err.Error()
937
+		return err.Error(), ""
926 938
 	}
927 939
 	respBytes, err := ioutil.ReadAll(resp.Body)
928 940
 	if err != nil {
929 941
 		fmt.Println(err.Error())
930
-		return err.Error()
942
+		return err.Error(), ""
931 943
 	}
932 944
 	str := string(respBytes)
933 945
 	fmt.Println(str)
934
-	return str
946
+	return str, requestLog
935 947
 }
936 948
 
937 949
 //  门诊预结算
938 950
 //func Gdyb2206(psnNo string, mdtrtId string, chrgBchno string, certNo string, insutype string, total string, org_name string, doctor string, secret_key string) string {
939
-func Gdyb2206(psnNo string, mdtrtId string, chrgBchno string, certNo string, insutype string, total string, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, med_type string, id_card_type int64, fulamt_ownpay_amt float64, overlmt_selfpay float64, preselfpay_amt float64, inscp_scp_amt float64, certificates int64) string {
951
+func Gdyb2206(psnNo string, mdtrtId string, chrgBchno string, certNo string, insutype string, total string, org_name string, doctor string, fixmedins_code string, insuplc_admdvs string, mdtrtarea_admvs string, secret_key string, med_type string, id_card_type int64, fulamt_ownpay_amt float64, overlmt_selfpay float64, preselfpay_amt float64, inscp_scp_amt float64, certificates int64) (string, string) {
940 952
 
941 953
 	// 生成签名
942 954
 	nonce := GetRandomString(32)
@@ -973,11 +985,15 @@ func Gdyb2206(psnNo string, mdtrtId string, chrgBchno string, certNo string, ins
973 985
 	input["data"] = inputData
974 986
 	inputMessage["input"] = input //交易输入
975 987
 
988
+	var requestLog string
989
+
976 990
 	bytesData, err := json.Marshal(inputMessage)
991
+
992
+	requestLog = string(bytesData)
977 993
 	fmt.Println(string(bytesData))
978 994
 	if err != nil {
979 995
 		fmt.Println(err.Error())
980
-		return err.Error()
996
+		return err.Error(), ""
981 997
 	}
982 998
 	reader := bytes.NewReader(bytesData)
983 999
 
@@ -994,7 +1010,7 @@ func Gdyb2206(psnNo string, mdtrtId string, chrgBchno string, certNo string, ins
994 1010
 	request, err := http.NewRequest("POST", url, reader)
995 1011
 	if err != nil {
996 1012
 		fmt.Println(err.Error())
997
-		return err.Error()
1013
+		return err.Error(), ""
998 1014
 	}
999 1015
 
1000 1016
 	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
@@ -1007,16 +1023,16 @@ func Gdyb2206(psnNo string, mdtrtId string, chrgBchno string, certNo string, ins
1007 1023
 	resp, err := client.Do(request)
1008 1024
 	if err != nil {
1009 1025
 		fmt.Println(err.Error())
1010
-		return err.Error()
1026
+		return err.Error(), ""
1011 1027
 	}
1012 1028
 	respBytes, err := ioutil.ReadAll(resp.Body)
1013 1029
 	if err != nil {
1014 1030
 		fmt.Println(err.Error())
1015
-		return err.Error()
1031
+		return err.Error(), ""
1016 1032
 	}
1017 1033
 	str := string(respBytes)
1018 1034
 	fmt.Println(str)
1019
-	return str
1035
+	return str, requestLog
1020 1036
 }
1021 1037
 
1022 1038
 //  门诊结算

+ 32 - 0
utils/log.go View File

@@ -2,6 +2,7 @@ package utils
2 2
 
3 3
 import (
4 4
 	"fmt"
5
+	"os"
5 6
 	"time"
6 7
 )
7 8
 
@@ -64,3 +65,34 @@ func magenta(s string) string {
64 65
 func formatLog(prefix string) string {
65 66
 	return time.Now().Format("[2006/01/02 15:04:05]") + " " + prefix + " "
66 67
 }
68
+
69
+func Mkdir(dir string) {
70
+	// 创建文件夹
71
+	exist, err := PathExists(dir)
72
+	if err != nil {
73
+		fmt.Println(err.Error())
74
+	} else {
75
+		if exist {
76
+			fmt.Println(dir + "文件夹已存在!")
77
+		} else {
78
+			// 文件夹名称,权限
79
+			err := os.Mkdir(dir, os.ModePerm)
80
+			if err != nil {
81
+				fmt.Println(dir+"文件夹创建失败:", err.Error())
82
+			} else {
83
+				fmt.Println(dir + "文件夹创建成功!")
84
+			}
85
+		}
86
+	}
87
+}
88
+
89
+func PathExists(path string) (bool, error) {
90
+	_, err := os.Stat(path)
91
+	if err == nil {
92
+		return true, nil
93
+	}
94
+	if os.IsNotExist(err) {
95
+		return false, nil
96
+	}
97
+	return false, err
98
+}