123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412 |
- package service
-
- import (
- "IC/models"
- "IC/utils"
- "bytes"
- "encoding/json"
- "encoding/xml"
- "fmt"
- "io/ioutil"
- "net/http"
- )
-
- // 获取可下载标本列表
- func GetGPReportListData(start_date string, end_date string, key string) (result []models.GPReportListResultData) {
- // 构建SOAP请求数据
- requestData := &models.ReportListEnvelope{
- Soap: "http://schemas.xmlsoap.org/soap/envelope/",
- Xsi: "http://www.w3.org/2001/XMLSchema-instance",
- Xsd: "http://www.w3.org/2001/XMLSchema",
- Body: models.ReportListBody{
- GetReportReq: models.GetReportReq{
- XMLName: xml.Name{Local: "GetAllSampleList", Space: "http://tempuri.org/"},
- Key: key,
- BeginDateTime: start_date,
- EndDateTime: end_date,
- DateType: 1,
- PrintState: 2,
- },
- },
- }
-
- // 将SOAP请求数据转换为XML格式
- requestBody, err := xml.Marshal(requestData)
- if err != nil {
- fmt.Println("XML Marshal error:", err)
- return result
- }
-
- // 创建POST请求
- url := "http://gpis.cnhiqc.com:9799/InstituteLISService.asmx"
- req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
- if err != nil {
- fmt.Println("Request creation error:", err)
- return result
- }
-
- // 设置请求头
- req.Header.Set("Content-Type", "text/xml; charset=utf-8")
- req.Header.Set("Content-Length", "length")
- req.Header.Set("SOAPAction", "http://tempuri.org/GetAllSampleList")
-
- // 发送请求
- client := &http.Client{}
- resp, err := client.Do(req)
- if err != nil {
- fmt.Println("Request error:", err)
- return result
- }
- defer resp.Body.Close()
-
- // 读取响应数据
- responseBody, err := ioutil.ReadAll(resp.Body)
- //fmt.Println(string(responseBody))
- if err != nil {
- fmt.Println("Response read error:", err)
- return result
- }
-
- // 解析XML数据
- var envelope_two models.EnvelopeTwo
- err2 := xml.Unmarshal(responseBody, &envelope_two)
- if err2 != nil {
- fmt.Println("XML Unmarshal error:", err2)
- return result
- }
-
- // 获取GetReportListResult的JSON字符串
- jsonStr := envelope_two.Body.GetAllSampleListResponse.GetAllSampleListResult
- utils.InfoLog("jsonStr:%v", jsonStr)
- //fmt.Println(jsonStr)
- // 解析JSON字符串到结构体
- var reportData models.ReportData
- err = json.Unmarshal([]byte(jsonStr), &reportData)
- if err != nil {
- fmt.Println("JSON Unmarshal error:", err)
- return result
- }
- if reportData.Res == 0 {
- //fmt.Println( . ."Data:", reportData.GPReportListResultData)
- return reportData.GPReportListResultData
- }
- return result
- }
-
- // 根据院所自身条码获取标本检测结果或诊断结果,遍历结果
- //func GetGPResultData(result []models.GPReportListResultData, key string) (results []models.InspectResult) {
- // for _, item := range result {
- //
- // // 构建SOAP请求数据
- // requestData := &models.ReportResultEnvelope{
- // Soap: "http://schemas.xmlsoap.org/soap/envelope/",
- // Xsi: "http://www.w3.org/2001/XMLSchema-instance",
- // Xsd: "http://www.w3.org/2001/XMLSchema",
- // Body: models.ReportResultBody{
- // GetReportResultReq: models.GetReportResultReq{
- // XMLName: xml.Name{Local: "GetJSONReportItemListByCustomerBarocde", Space: "http://tempuri.org/"},
- // Key: key,
- // CustomerBarCode: item.CustomerBarcode,
- // },
- // },
- // }
- //
- // // 将SOAP请求数据转换为XML格式
- // requestBody, err := xml.Marshal(requestData)
- // if err != nil {
- // fmt.Println("XML Marshal error:", err)
- //
- // }
- //
- // // 创建POST请求
- // url := "http://gpis.cnhiqc.com:9799/InstituteLISService.asmx"
- // req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
- // if err != nil {
- // fmt.Println("Request creation error:", err)
- // }
- // // 设置请求头
- // req.Header.Set("Content-Type", "text/xml; charset=utf-8")
- // req.Header.Set("Content-Length", "length")
- // req.Header.Set("SOAPAction", "http://tempuri.org/GetJSONReportItemListByCustomerBarocde")
- // // 发送请求
- // client := &http.Client{}
- // resp, err := client.Do(req)
- // if err != nil {
- // fmt.Println("Request error:", err)
- //
- // }
- // defer resp.Body.Close()
- // // 读取响应数据
- // responseBody, err := ioutil.ReadAll(resp.Body)
- // if err != nil {
- // fmt.Println("Response read error:", err)
- // }
- //
- // // 解析XML数据
- // var envelope_three models.EnvelopeThree
- // err2 := xml.Unmarshal(responseBody, &envelope_three)
- // if err2 != nil {
- // fmt.Println("XML Unmarshal error:", err2)
- // }
- // // 获取GetReportListResult的JSON字符串
- // jsonStr := envelope_three.Body.GetJSONReportItemListByCustomerBarocdeResponse.GetJSONReportItemListByCustomerBarocdeResult
- // // 解析JSON字符串到结构体
- // fmt.Println(jsonStr)
- // var reportData models.ReportResultData
- // err = json.Unmarshal([]byte(jsonStr), &reportData)
- // if err != nil {
- // fmt.Println("JSON Unmarshal error:", err)
- // }
- // if reportData.Res == 0 {
- // fmt.Println("Data:", reportData.InspectResult)
- // reportData.InspectResult.ListResult = item
- // results = append(results, reportData.InspectResult)
- // }
- // }
- // return results
- //}
-
- // 根据高品条码获取标本检测结果或诊断结果,遍历结果
- func GetGPResultDataTwo(item models.GPReportListResultData, key string) (results []models.InspectResultFive) {
- if len(item.CustomerBarcode) > 0 {
- fmt.Println("~~~~~~-------")
- // 构建SOAP请求数据
- requestData := &models.ReportResultEnvelope{
- Soap: "http://schemas.xmlsoap.org/soap/envelope/",
- Xsi: "http://www.w3.org/2001/XMLSchema-instance",
- Xsd: "http://www.w3.org/2001/XMLSchema",
- Body: models.ReportResultBody{
- GetReportResultReq: models.GetReportResultReq{
- XMLName: xml.Name{Local: "GetJSONReportItemListByCustomerBarocde", Space: "http://tempuri.org/"},
- Key: key,
- CustomerBarCode: item.CustomerBarcode,
- },
- },
- }
-
- // 将SOAP请求数据转换为XML格式
- requestBody, err := xml.Marshal(requestData)
- if err != nil {
- fmt.Println("XML Marshal error:", err)
-
- }
-
- // 创建POST请求
- url := "http://gpis.cnhiqc.com:9799/InstituteLISService.asmx"
- req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
- if err != nil {
- fmt.Println("Request creation error:", err)
- }
- // 设置请求头
- req.Header.Set("Content-Type", "text/xml; charset=utf-8")
- req.Header.Set("Content-Length", "length")
- req.Header.Set("SOAPAction", "http://tempuri.org/GetJSONReportItemListByCustomerBarocde")
- // 发送请求
- client := &http.Client{}
- resp, err := client.Do(req)
- if err != nil {
- fmt.Println("Request error:", err)
-
- }
- defer resp.Body.Close()
- // 读取响应数据
- responseBody, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- fmt.Println("Response read error:", err)
- }
-
- // 解析XML数据
- var envelope_three models.EnvelopeThree
- err2 := xml.Unmarshal(responseBody, &envelope_three)
- if err2 != nil {
- fmt.Println("XML Unmarshal error:", err2)
- }
- // 获取GetReportListResult的JSON字符串
- jsonStr := envelope_three.Body.GetJSONReportItemListByCustomerBarocdeResponse.GetJSONReportItemListByCustomerBarocdeResult
- // 解析JSON字符串到结构体
- //fmt.Println(jsonStr)
- var reportData models.ReportResultData
- err = json.Unmarshal([]byte(jsonStr), &reportData)
- if err != nil {
- fmt.Println("JSON Unmarshal error:", err)
- }
- if reportData.Res == 0 {
- //reportData.ListResult = item
- for _, subItem := range reportData.InspectResult {
- subItem.ListResult = item
- var resultTwo models.InspectResultFive
- resultTwo.ListResult = subItem.ListResult
- resultTwo.Result = subItem.Result
- resultTwo.Barcode = subItem.Barcode
- resultTwo.Flag = subItem.Flag
- resultTwo.Unit = subItem.Unit
- resultTwo.ChargeItemName = subItem.ChargeItemName
- resultTwo.InspectionName = subItem.InspectionName
- resultTwo.InspectionCode = subItem.InspectionCode
- resultTwo.Reference = subItem.Reference
- results = append(results, resultTwo)
- }
- }
- } else {
- if len(item.Barcode) > 0 {
-
- //fmt.Println("11122222")
- // 构建SOAP请求数据
- requestData := &models.GPReportResultEnvelope{
- Soap: "http://schemas.xmlsoap.org/soap/envelope/",
- Xsi: "http://www.w3.org/2001/XMLSchema-instance",
- Xsd: "http://www.w3.org/2001/XMLSchema",
- Body: models.GPReportResultBody{
- GetReportResultReq: models.GetGPReportResultReq{
- XMLName: xml.Name{Local: "GetJSONReportItemListByGPBarocde", Space: "http://tempuri.org/"},
- Key: key,
- GPBarCode: item.Barcode,
- },
- },
- }
-
- // 将SOAP请求数据转换为XML格式
- requestBody, err := xml.Marshal(requestData)
- if err != nil {
- fmt.Println("XML Marshal error:", err)
-
- }
-
- // 创建POST请求
- url := "http://gpis.cnhiqc.com:9799/InstituteLISService.asmx"
- req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
- if err != nil {
- fmt.Println("Request creation error:", err)
- }
- // 设置请求头
- req.Header.Set("Content-Type", "text/xml; charset=utf-8")
- req.Header.Set("Content-Length", "length")
- req.Header.Set("SOAPAction", "http://tempuri.org/GetJSONReportItemListByGPBarocde")
- // 发送请求
- client := &http.Client{}
- resp, err := client.Do(req)
- if err != nil {
- fmt.Println("Request error:", err)
-
- }
- defer resp.Body.Close()
- // 读取响应数据
- responseBody, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- fmt.Println("Response read error:", err)
- }
-
- // 解析XML数据
- var envelope_five models.EnvelopeFive
- err2 := xml.Unmarshal(responseBody, &envelope_five)
- if err2 != nil {
- fmt.Println("XML Unmarshal error:", err2)
- }
-
- // 获取GetReportListResult的JSON字符串
- jsonStr := envelope_five.Body.GetJSONReportItemListByGPBarocdeResponse.GetJSONReportItemListByGPBarocdeResult
- utils.InfoLog("jsonStr:%v", jsonStr)
- // 解析JSON字符串到结构体
- var reportData models.ReportResultDataFive
- err = json.Unmarshal([]byte(jsonStr), &reportData)
- if err != nil {
- fmt.Println("JSON Unmarshal error:", err)
- }
- //fmt.Println(reportData)
-
- if reportData.Res == 0 {
- //reportData.ListResult = item
- for _, subItem := range reportData.InspectResult {
- subItem.ListResult = item
- results = append(results, subItem)
- }
- }
-
- }
- }
- return results
-
- }
-
- // 送检单
- func PostInspectApply(key string, apply models.JYApply, list []models.CustomerApplyDetail) models.InspectApplyData {
- // 构建SOAP请求数据
- requestData := &models.JYApplyEnvelope{
- Soap: "http://schemas.xmlsoap.org/soap/envelope/",
- Xsi: "http://www.w3.org/2001/XMLSchema-instance",
- Xsd: "http://www.w3.org/2001/XMLSchema",
- Body: models.JYApplyBody{
- InspectApplyReq: models.InspectApplyReq{
- XMLName: xml.Name{Local: "InspectApplyByInstituteItemCode", Space: "http://tempuri.org/"},
- ApiKey: key,
- Apply: apply,
- ApplyDetailList: struct {
- CustomerApplyDetail []models.CustomerApplyDetail `xml:"CustomerApplyDetail"`
- }{
- CustomerApplyDetail: list,
- },
- ApplyAdditional: nil,
- },
- },
- }
-
- // 将SOAP请求数据转换为XML格式
- requestBody, err := xml.Marshal(requestData)
- if err != nil {
- fmt.Println("XML Marshal error:", err)
- }
- fmt.Println(string(requestBody))
-
- // 创建POST请求
- url := "http://gpis.cnhiqc.com:9799/InstituteLISService.asmx"
- req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
- if err != nil {
- fmt.Println("Request creation error:", err)
- }
-
- // 设置请求头
- req.Header.Set("Content-Type", "text/xml; charset=utf-8")
- req.Header.Set("Content-Length", "length")
- req.Header.Set("SOAPAction", "http://tempuri.org/InspectApplyByInstituteItemCode")
-
- // 发送请求
- client := &http.Client{}
- resp, err := client.Do(req)
- if err != nil {
- fmt.Println("Request error:", err)
- }
- defer resp.Body.Close()
-
- // 读取响应数据
- responseBody, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- fmt.Println("Response read error:", err)
-
- }
- fmt.Println(string(responseBody))
-
- // 解析XML数据
- var envelope_four models.EnvelopeFour
- err2 := xml.Unmarshal(responseBody, &envelope_four)
- if err2 != nil {
- fmt.Println("XML Unmarshal error:", err2)
-
- }
-
- // 获取GetReportListResult的JSON字符串
- jsonStr := envelope_four.Body.InspectApplyByInstituteItemCodeResponse.InspectApply
-
- // 解析JSON字符串到结构体
- var reportData models.InspectApplyData
- err = json.Unmarshal([]byte(jsonStr), &reportData)
-
- if err != nil {
- fmt.Println("JSON Unmarshal error:", err)
- }
- if reportData.Res != 0 {
- fmt.Println("Data:", reportData)
- //return reportData.JYApplyResult
- }
- return reportData
- }
|