瀏覽代碼

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

csx 3 年之前
父節點
當前提交
70e7ecf457
共有 2 個文件被更改,包括 147 次插入145 次删除
  1. 1 1
      conf/app.conf
  2. 146 144
      controllers/sg/his_api_controller.go

+ 1 - 1
conf/app.conf 查看文件

@@ -6,7 +6,7 @@ runmode = dev
6 6
 copyrequestbody = true
7 7
 sessionon = true
8 8
 sessiongcmaxlifetime = 64800
9
-
9
+###
10 10
 tokencookiemaxlifetime = 7200
11 11
 enablexsrf = false
12 12
 xsrfkey = 61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o

+ 146 - 144
controllers/sg/his_api_controller.go 查看文件

@@ -11,6 +11,8 @@ import (
11 11
 	"gdyb/service"
12 12
 	"gdyb/utils"
13 13
 	"github.com/astaxie/beego"
14
+	"github.com/jinzhu/gorm"
15
+
14 16
 	//"github.com/jinzhu/gorm"
15 17
 	"github.com/shopspring/decimal"
16 18
 	"io"
@@ -47,7 +49,7 @@ func HisManagerApiRegistRouters() {
47 49
 	beego.Router("/api/org/info", &HisApiController{}, "get:GetOrgInfo")
48 50
 	//beego.Router("/api/testcard", &HisApiController{}, "get:TestGetBasBaseInfo")
49 51
 
50
-	//beego.Router("/api/readcard", &HisApiController{}, "get:ReadCard")
52
+	beego.Router("/api/readcard", &HisApiController{}, "get:ReadCard")
51 53
 
52 54
 	//beego.Router("/api/testpay", &HisApiController{}, "get:TestPay")
53 55
 
@@ -177,131 +179,131 @@ func (c *HisApiController) CheckCardPWD() {
177 179
 
178 180
 }
179 181
 
180
-//func (c *HisApiController) ReadCard() {
181
-//	id_card_type, _ := c.GetInt64("id_card_type")
182
-//	admin_user_id, _ := c.GetInt64("admin_user_id")
183
-//	certificates, _ := c.GetInt64("certificates")
184
-//
185
-//	roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
186
-//	miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
187
-//	if initFlag == 0 {
188
-//		c.TestGetBasBaseInit()
189
-//	}
190
-//	switch id_card_type {
191
-//	case 1:
192
-//		basStr := c.GetBasBaseInfo()
193
-//		if len(basStr) == 0 {
194
-//			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
195
-//			return
196
-//		}
197
-//		fmt.Println(basStr)
198
-//		bas := strings.Split(basStr, "|")
199
-//		basNumber := bas[2]
200
-//		fmt.Println(basNumber)
201
-//		card_sn := bas[3]
202
-//		fmt.Println(card_sn)
203
-//		result := service.Gdyb1101B(basNumber, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, card_sn, certificates)
204
-//		var dat map[string]interface{}
205
-//		if err := json.Unmarshal([]byte(result), &dat); err == nil {
206
-//			fmt.Println(dat)
207
-//		} else {
208
-//			fmt.Println(err)
209
-//		}
210
-//
211
-//		userJSONBytes, _ := json.Marshal(dat)
212
-//		var res ResultTwo
213
-//		if err := json.Unmarshal(userJSONBytes, &res); err != nil {
214
-//			utils.ErrorLog("解析失败:%v", err)
215
-//			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
216
-//			return
217
-//		}
218
-//
219
-//		if res.Infcode == 0 {
220
-//			patient, err := service.GetPatientByNumber(basNumber, c.GetAdminUserInfo().CurrentOrgId)
221
-//			if err == gorm.ErrRecordNotFound {
222
-//				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
223
-//				return
224
-//			} else if err != nil {
225
-//				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
226
-//				return
227
-//
228
-//			} else {
229
-//				c.ServeSuccessJSON(map[string]interface{}{
230
-//					"patient": patient,
231
-//					"number":  basNumber,
232
-//				})
233
-//			}
234
-//		} else {
235
-//			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
236
-//			return
237
-//		}
238
-//		break
239
-//	case 2:
240
-//		SFZStr := c.GetSFZBaseInfo()
241
-//		id_card_str := strings.Split(SFZStr, "^")
242
-//		id_card_number := id_card_str[0]
243
-//		card_sn := ""
244
-//		result := service.Gdyb1101B(id_card_number, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, card_sn, certificates)
245
-//		var dat map[string]interface{}
246
-//		if err := json.Unmarshal([]byte(result), &dat); err == nil {
247
-//			fmt.Println(dat)
248
-//		} else {
249
-//			fmt.Println(err)
250
-//		}
251
-//
252
-//		userJSONBytes, _ := json.Marshal(dat)
253
-//		var res ResultTwo
254
-//		if err := json.Unmarshal(userJSONBytes, &res); err != nil {
255
-//			utils.ErrorLog("解析失败:%v", err)
256
-//			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
257
-//			return
258
-//		}
259
-//
260
-//		if res.Infcode == 0 {
261
-//			patient, err := service.GetPatientByNumber(id_card_number, c.GetAdminUserInfo().CurrentOrgId)
262
-//			if err == gorm.ErrRecordNotFound {
263
-//				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
264
-//				return
265
-//			} else if err != nil {
266
-//				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
267
-//				return
268
-//
269
-//			} else {
270
-//				c.ServeSuccessJSON(map[string]interface{}{
271
-//					"patient": patient,
272
-//					"number":  id_card_number,
273
-//				})
274
-//			}
275
-//		} else {
276
-//			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
277
-//			return
278
-//		}
279
-//
280
-//		break
281
-//	case 3:
282
-//		break
283
-//	}
284
-//
285
-//}
182
+func (c *HisApiController) ReadCard() {
183
+	id_card_type, _ := c.GetInt64("id_card_type")
184
+	admin_user_id, _ := c.GetInt64("admin_user_id")
185
+	certificates, _ := c.GetInt64("certificates")
186
+
187
+	roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
188
+	miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
189
+	if initFlag == 0 {
190
+		c.TestGetBasBaseInit()
191
+	}
192
+	switch id_card_type {
193
+	case 1:
194
+		basStr := c.GetBasBaseInfo()
195
+		if len(basStr) == 0 {
196
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
197
+			return
198
+		}
199
+		fmt.Println(basStr)
200
+		bas := strings.Split(basStr, "|")
201
+		basNumber := bas[2]
202
+		fmt.Println(basNumber)
203
+		card_sn := bas[3]
204
+		fmt.Println(card_sn)
205
+		result := service.Gdyb1101B(basNumber, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, card_sn, certificates)
206
+		var dat map[string]interface{}
207
+		if err := json.Unmarshal([]byte(result), &dat); err == nil {
208
+			fmt.Println(dat)
209
+		} else {
210
+			fmt.Println(err)
211
+		}
212
+
213
+		userJSONBytes, _ := json.Marshal(dat)
214
+		var res ResultTwo
215
+		if err := json.Unmarshal(userJSONBytes, &res); err != nil {
216
+			utils.ErrorLog("解析失败:%v", err)
217
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
218
+			return
219
+		}
220
+
221
+		if res.Infcode == 0 {
222
+			patient, err := service.GetPatientByNumber(basNumber, c.GetAdminUserInfo().CurrentOrgId)
223
+			if err == gorm.ErrRecordNotFound {
224
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
225
+				return
226
+			} else if err != nil {
227
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
228
+				return
229
+
230
+			} else {
231
+				c.ServeSuccessJSON(map[string]interface{}{
232
+					"patient": patient,
233
+					"number":  basNumber,
234
+				})
235
+			}
236
+		} else {
237
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
238
+			return
239
+		}
240
+		break
241
+	case 2:
242
+		SFZStr := c.GetSFZBaseInfo()
243
+		id_card_str := strings.Split(SFZStr, "^")
244
+		id_card_number := id_card_str[0]
245
+		card_sn := ""
246
+		result := service.Gdyb1101B(id_card_number, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, card_sn, certificates)
247
+		var dat map[string]interface{}
248
+		if err := json.Unmarshal([]byte(result), &dat); err == nil {
249
+			fmt.Println(dat)
250
+		} else {
251
+			fmt.Println(err)
252
+		}
253
+
254
+		userJSONBytes, _ := json.Marshal(dat)
255
+		var res ResultTwo
256
+		if err := json.Unmarshal(userJSONBytes, &res); err != nil {
257
+			utils.ErrorLog("解析失败:%v", err)
258
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
259
+			return
260
+		}
261
+
262
+		if res.Infcode == 0 {
263
+			patient, err := service.GetPatientByNumber(id_card_number, c.GetAdminUserInfo().CurrentOrgId)
264
+			if err == gorm.ErrRecordNotFound {
265
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
266
+				return
267
+			} else if err != nil {
268
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
269
+				return
270
+
271
+			} else {
272
+				c.ServeSuccessJSON(map[string]interface{}{
273
+					"patient": patient,
274
+					"number":  id_card_number,
275
+				})
276
+			}
277
+		} else {
278
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
279
+			return
280
+		}
281
+
282
+		break
283
+	case 3:
284
+		break
285
+	}
286
+
287
+}
286 288
 
287 289
 var initFlag int64 = 0
288 290
 
289
-//func (c *HisApiController) TestGetBasBaseInit() {
290
-//	DllDef := syscall.MustLoadDLL("SSCard.dll")
291
-//	Iinit := DllDef.MustFindProc("Init")
292
-//	ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
293
-//	if ret != 0 {
294
-//		fmt.Println("SSCard的报错原因:", err)
295
-//		fmt.Println("SSCard的运算结果为:", ret)
296
-//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
297
-//		return
298
-//	}
299
-//
300
-//	result := int(ret)
301
-//	fmt.Println("SSCard的运算结果为1:", result)
302
-//	initFlag = 1
303
-//	return
304
-//}
291
+func (c *HisApiController) TestGetBasBaseInit() {
292
+	DllDef := syscall.MustLoadDLL("SSCard.dll")
293
+	Iinit := DllDef.MustFindProc("Init")
294
+	ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
295
+	if ret != 0 {
296
+		fmt.Println("SSCard的报错原因:", err)
297
+		fmt.Println("SSCard的运算结果为:", ret)
298
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
299
+		return
300
+	}
301
+
302
+	result := int(ret)
303
+	fmt.Println("SSCard的运算结果为1:", result)
304
+	initFlag = 1
305
+	return
306
+}
305 307
 
306 308
 //func (c *HisApiController) GetSFZBaseInfo() string {
307 309
 //	DllDef := syscall.MustLoadDLL("SSCard.dll")
@@ -319,27 +321,27 @@ var initFlag int64 = 0
319 321
 //	return string(str)
320 322
 //}
321 323
 
322
-//func (c *HisApiController) GetBasBaseInfo() string {
323
-//	DllDef := syscall.MustLoadDLL("SSCard.dll")
324
-//	readCard := DllDef.MustFindProc("ReadCardBas")
325
-//	if readCard == nil {
326
-//		fmt.Println("readcard is nil")
327
-//		readCard = DllDef.MustFindProc("ReadCardBas")
328
-//	}
329
-//
330
-//	str := make([]byte, 1024)
331
-//	str1 := make([]byte, 1024)
332
-//	ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), uintptr(1024), (uintptr)(unsafe.Pointer(&str1[0])), uintptr(1024))
333
-//
334
-//	fmt.Println(string(str1))
335
-//	fmt.Println(string(str))
336
-//
337
-//	if ret2 != 0 {
338
-//		return ""
339
-//	}
340
-//	return string(str)
341
-//
342
-//}
324
+func (c *HisApiController) GetBasBaseInfo() string {
325
+	DllDef := syscall.MustLoadDLL("SSCard.dll")
326
+	readCard := DllDef.MustFindProc("ReadCardBas")
327
+	if readCard == nil {
328
+		fmt.Println("readcard is nil")
329
+		readCard = DllDef.MustFindProc("ReadCardBas")
330
+	}
331
+
332
+	str := make([]byte, 1024)
333
+	str1 := make([]byte, 1024)
334
+	ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), uintptr(1024), (uintptr)(unsafe.Pointer(&str1[0])), uintptr(1024))
335
+
336
+	fmt.Println(string(str1))
337
+	fmt.Println(string(str))
338
+
339
+	if ret2 != 0 {
340
+		return ""
341
+	}
342
+	return string(str)
343
+
344
+}
343 345
 
344 346
 func prttostr(vcode uintptr) string {
345 347
 	var vbyte []byte