package service import ( "IC/models" "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: 0, }, }, } // 将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 //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(result []models.GPReportListResultData, key string) (results []models.InspectResultFive) { for _, item := range result { 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 // 解析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 }