Преглед изворни кода

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

csx пре 3 година
родитељ
комит
b0406762af
3 измењених фајлова са 182 додато и 38 уклоњено
  1. 98 27
      controllers/js/jsyb_controller.go
  2. 78 5
      controllers/sg/his_api_controller.go
  3. 6 6
      main.go

+ 98 - 27
controllers/js/jsyb_controller.go Прегледај датотеку

@@ -4,11 +4,15 @@ import (
4 4
 	"encoding/json"
5 5
 	"fmt"
6 6
 	"gdyb/controllers"
7
+	"gdyb/enums"
7 8
 	"gdyb/models"
8 9
 	"gdyb/service"
9 10
 	"gdyb/utils"
10 11
 	"github.com/astaxie/beego"
12
+	"github.com/axgle/mahonia"
11 13
 	"io/ioutil"
14
+	"syscall"
15
+	"unsafe"
12 16
 )
13 17
 
14 18
 type JSybController struct {
@@ -26,7 +30,7 @@ func JSybRegistRouters() {
26 30
 	beego.Router("/jsyb/2207", &JSybController{}, "get:PostEight")
27 31
 	beego.Router("/jsyb/2208", &JSybController{}, "get:PostNine")
28 32
 	beego.Router("/jsyb/5203", &JSybController{}, "get:PostTen")
29
-	//beego.Router("/jsyb/readcard", &JSybController{}, "get:ReadCard")
33
+	beego.Router("/jsyb/readcard", &JSybController{}, "get:ReadCard")
30 34
 
31 35
 }
32 36
 
@@ -462,29 +466,96 @@ func (c *JSybController) PostTen() {
462 466
 	})
463 467
 }
464 468
 
465
-//var initFlag int64 = 0
466
-
467
-//func (c *JSybController) ReadCard() {
468
-//	if initFlag == 0 {
469
-//		c.TestGetBasBaseInit()
470
-//	}
471
-//}
472
-//
473
-//func (c *JSybController) TestGetBasBaseInit() {
474
-//	DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
475
-//	Iinit := DllDef.MustFindProc("Init")
476
-//	miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
477
-//
478
-//	ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_api/prd/api/card/initDll"), StrPtr(miConfig.InsuplcAdmdvs))
479
-//	if ret != 0 {
480
-//		fmt.Println("SSCard的报错原因:", err)
481
-//		fmt.Println("SSCard的运算结果为:", ret)
482
-//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
483
-//		return
484
-//	}
485
-//
486
-//	result := int(ret)
487
-//	fmt.Println("SSCard的运算结果为1:", result)
488
-//	initFlag = 1
489
-//	return
490
-//}
469
+var initFlag int64 = 0
470
+
471
+func (c *JSybController) ReadCard() {
472
+	fixmedins_code := c.GetString("fixmedins_code")
473
+	secret_key := c.GetString("secret_key")
474
+	ak := c.GetString("ak")
475
+
476
+	if initFlag == 0 {
477
+		c.TestGetBasBaseInit(fixmedins_code, secret_key, ak)
478
+	}
479
+	basStr := c.GetBasBaseInfo()
480
+	fmt.Println(basStr)
481
+
482
+}
483
+
484
+func (c *JSybController) TestGetBasBaseInit(code string, secret_key string, ak string) {
485
+	DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
486
+	Iinit := DllDef.MustFindProc("Init")
487
+	//miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
488
+	str := make([]byte, 1024)
489
+
490
+	inputData := make(map[string]interface{})
491
+
492
+	inputData["IP"] = "10.72.3.87"
493
+	inputData["PORT"] = "8086"
494
+	inputData["TIMEOUT"] = "180"
495
+	inputData["LOG_PATH"] = "C:\\log\\"
496
+	inputData["EC_URL"] = "http://10.72.42.210:10081/localcfc/api/hsecfc/localQrCodeQuery"
497
+	inputData["CARD_PASSTYPE"] = "1"
498
+	inputData["API_NAME"] = "hssServives"
499
+	inputData["API_VERSION"] = "1.0.0"
500
+	inputData["ACCESS_KEY"] = ak
501
+	inputData["SECRETKEY"] = secret_key
502
+	inputData["ORG_ID"] = code
503
+	inputData["EXT"] = ""
504
+	bytesData, _ := json.Marshal(inputData)
505
+	ret, _, err := Iinit.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&str[0])))
506
+	if ret != 0 {
507
+		fmt.Println("SSCard的报错原因:", err)
508
+		fmt.Println("SSCard的运算结果为:", ret)
509
+		fmt.Println("SSCard的返回结果为:", string(str))
510
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
511
+		return
512
+	}
513
+
514
+	result := int(ret)
515
+	fmt.Println("SSCard的运算结果为1:", result)
516
+	initFlag = 1
517
+	return
518
+}
519
+func (c *JSybController) GetBasBaseInfo() string {
520
+	DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
521
+	readCard := DllDef.MustFindProc("ReadCardBas")
522
+	if readCard == nil {
523
+		fmt.Println("readcard is nil")
524
+		readCard = DllDef.MustFindProc("ReadCardBas")
525
+	}
526
+	str := make([]byte, 2048)
527
+	str1 := make([]byte, 8192)
528
+	ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), uintptr(1024), (uintptr)(unsafe.Pointer(&str1[0])), uintptr(1024))
529
+	fmt.Println(string(str1))
530
+	fmt.Println(string(str))
531
+	fmt.Println(":", ConvertToString(string(str1), "gbk", "utf-8"))
532
+	fmt.Println(":", ConvertToString(string(str), "gbk", "utf-8"))
533
+	if ret2 != 0 {
534
+		return ""
535
+	}
536
+	return string(str)
537
+}
538
+
539
+func IntPtr(n int) uintptr {
540
+	return uintptr(n)
541
+}
542
+
543
+func StrPtr(s string) uintptr {
544
+	return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
545
+}
546
+
547
+type Charset string
548
+
549
+const (
550
+	UTF8    = Charset("UTF-8")
551
+	GB18030 = Charset("GB18030")
552
+)
553
+
554
+func ConvertToString(src string, srcCode string, tagCode string) string {
555
+	srcCoder := mahonia.NewDecoder(srcCode)
556
+	srcResult := srcCoder.ConvertString(src)
557
+	tagCoder := mahonia.NewDecoder(tagCode)
558
+	_, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
559
+	result := string(cdata)
560
+	return result
561
+}

+ 78 - 5
controllers/sg/his_api_controller.go Прегледај датотеку

@@ -339,6 +339,82 @@ func (c *HisApiController) ReadCard() {
339 339
 				return
340 340
 			}
341 341
 
342
+		} else if miConfig.MdtrtareaAdmvs == "320921" {
343
+			var res ResultTwo
344
+			api := "http://192.168.124.4:9532/" + "hbyb/1101?cert_no=" + "" +
345
+				"&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
346
+				"&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(id_card_type, 10) + "&card_sn=" + "" + "&certificates=" + strconv.FormatInt(certificates, 10)
347
+			resp, requestErr := http.Get(api)
348
+			if requestErr != nil {
349
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
350
+				return
351
+			}
352
+
353
+			body, ioErr := ioutil.ReadAll(resp.Body)
354
+			if ioErr != nil {
355
+				utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
356
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
357
+				return
358
+			}
359
+			var respJSON map[string]interface{}
360
+			if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
361
+				utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
362
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
363
+				return
364
+			}
365
+
366
+			respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
367
+			result, _ := json.Marshal(respJSON)
368
+			fmt.Println("log")
369
+			fmt.Println(string(result))
370
+
371
+			if err := json.Unmarshal([]byte(result), &res); err != nil {
372
+				utils.ErrorLog("解析失败:%v", err)
373
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
374
+				return
375
+			}
376
+
377
+			if res.Infcode == 0 {
378
+				patient, err := service.GetPatientByIDCard(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
379
+				if err == gorm.ErrRecordNotFound {
380
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
381
+					return
382
+				} else if err != nil {
383
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
384
+					return
385
+
386
+				} else {
387
+
388
+					Iinfos, _ := json.Marshal(res.Output.Iinfo)
389
+					Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
390
+					infoStr := string(Iinfos)
391
+					idetinfoStr := string(Idetinfos)
392
+					psn := &models.HisPsn{
393
+						PsnNo:       res.Output.Baseinfo.PsnNo,
394
+						Age:         res.Output.Baseinfo.Age,
395
+						PatientId:   patient.ID,
396
+						Certno:      res.Output.Baseinfo.Certno,
397
+						Brdy:        res.Output.Baseinfo.Brdy,
398
+						Gend:        res.Output.Baseinfo.Gend,
399
+						Naty:        res.Output.Baseinfo.Naty,
400
+						PsnCertType: res.Output.Baseinfo.PsnCertType,
401
+						PsnName:     res.Output.Baseinfo.PsnName,
402
+						Idetinfo:    idetinfoStr,
403
+						Insuinfo:    infoStr,
404
+						UserOrgId:   c.GetAdminUserInfo().CurrentOrgId,
405
+					}
406
+					service.CreateHisPsn(psn)
407
+
408
+					c.ServeSuccessJSON(map[string]interface{}{
409
+						"patient": patient,
410
+						"number":  res.Output.Baseinfo.Certno,
411
+					})
412
+				}
413
+			} else {
414
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
415
+				return
416
+			}
417
+
342 418
 		} else {
343 419
 			if initFlag == 0 {
344 420
 				c.TestGetBasBaseInit()
@@ -1871,7 +1947,7 @@ func (c *HisApiController) GetHisPatientInfo() {
1871 1947
 //
1872 1948
 //	str := make([]byte, 256)
1873 1949
 //	str1 := make([]byte, 256)
1874
-//	r, _, _ := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
1950
+	r, _, _ := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
1875 1951
 //
1876 1952
 //	fmt.Println(string(str))
1877 1953
 //	fmt.Println(r)
@@ -2925,10 +3001,7 @@ func (c *HisApiController) GetRegisterInfo() {
2925 3001
 
2926 3002
 		} else if miConfig.MdtrtareaAdmvs == "320921" {
2927 3003
 			var res ResultTwo
2928
-			api := "http://192.168.3.111:9532/" + "jsyb/1101?cert_no=" + "" +
2929
-				"&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
2930
-				"&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(id_card_type, 10) + "&card_sn=" + "" + "&certificates=" + strconv.FormatInt(certificates, 10) + "&url=" + miConfig.Url + "&ak=" + miConfig.ChannelNumber
2931
-			fmt.Println(api)
3004
+			api := "http://192.168.3.111:9532/" + "jsyb/readcard?" +"fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&ak=" + miConfig.ChannelNumber
2932 3005
 			resp, requestErr := http.Get(api)
2933 3006
 			if requestErr != nil {
2934 3007
 				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)

+ 6 - 6
main.go Прегледај датотеку

@@ -5,7 +5,7 @@ import (
5 5
 	"fmt"
6 6
 	"gdyb/models"
7 7
 	_ "gdyb/routers"
8
-	//"gdyb/service"
8
+	"gdyb/service"
9 9
 	"github.com/astaxie/beego"
10 10
 	"github.com/qiniu/api.v7/auth/qbox"
11 11
 	"github.com/qiniu/api.v7/storage"
@@ -15,11 +15,11 @@ import (
15 15
 )
16 16
 
17 17
 func init() {
18
-	//service.ConnectDB()
19
-	//org_id, _ := beego.AppConfig.Int64("org_id")
20
-	//miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
21
-	//CreateLog(miConfig)
22
-	//UploadLog(miConfig)
18
+	service.ConnectDB()
19
+	org_id, _ := beego.AppConfig.Int64("org_id")
20
+	miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
21
+	CreateLog(miConfig)
22
+	UploadLog(miConfig)
23 23
 
24 24
 }
25 25
 func main() {