123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590 |
- package controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "fmt"
- "github.com/astaxie/beego"
- "os"
- "strings"
- "time"
- )
-
- const (
- key = "4a6617a4409c48dc836152e80e18febd"
- )
-
- type HisPrintApiController struct {
- BaseAuthAPIController
- }
-
- func HisPrintApiRegistRouters() {
- beego.Router("/api/his/prescription/print", &HisPrintApiController{}, "get:GetBatchHisPrescriptionData")
- beego.Router("/api/his/prescription/list", &HisPrintApiController{}, "get:GetUnChargePrescriptionList")
- beego.Router("/api/his/prescription/summary", &HisPrintApiController{}, "get:GetUnChargePrescriptionSummary")
- beego.Router("/api/his/label/create", &HisPrintApiController{}, "get:CreateLablePrint")
- beego.Router("/api/his/label/get", &HisPrintApiController{}, "get:GetLablePrint")
- //beego.Router("/api/his/label/send", &HisPrintApiController{}, "get:SendApplyCode")
- }
-
- //func (c *HisPrintApiController) SendApplyCode() {
- // list, _ := service.GetAllLisDataFor10191(c.GetAdminUserInfo().CurrentOrgId)
- // if len(list) > 0 {
- // //插入中间库中
- // for _, item := range list {
- // if len(item.ApplyCode) == 0 {
- // var apply models.JYApply
- // apply.BedCode = ""
- // apply.PatientName = item.Patient.Name
- // idCard := item.Patient.IdCardNo // 身份证号码示例
- // age, err := GetAge(idCard)
- // if err != nil {
- // age = int(item.Patient.Age)
- // fmt.Println("计算年龄时出错:", err)
- // }
- //
- // apply.Age = strconv.FormatInt(int64(age), 10)
- // apply.AgeUnit = "岁"
- // if item.Patient.Gender == 1 {
- // apply.Sex = "男"
- // } else if item.Patient.Gender == 2 {
- // apply.Sex = "女"
- // } else {
- // apply.Sex = "不详"
- // }
- // apply.RegisterCode = ""
- // apply.Diagnosis = ""
- // apply.Ward = ""
- // role, _ := service.GetAdminUserRole(2398, c.GetAdminUserInfo().CurrentOrgId)
- // apply.SendDoctor = role.UserName
- // apply.PatientType = 1
- // apply.PatientPhone = item.Patient.Phone
- // //applys = append(applys, apply)
- // var jYApplyDetails []models.CustomerApplyDetail
- //
- // if len(item.ItemIds) > 0 {
- // team_ids := strings.Split(item.ItemIds, ",")
- // for index, subItem := range team_ids {
- // //判断一些需要拆分的组套 血透体检(定量):需要拆分出传染病检查(定性),丙型肝炎抗体测试,血透体检(定量)
- // if subItem == "267" {
- // //血透体检(定量)
- // var jYApplyDetail models.CustomerApplyDetail
- // id, _ := strconv.ParseInt(subItem, 10, 64)
- // jYApplyDetail.CustomerChargeItemCode = strconv.FormatInt(id, 10)
- // jYApplyDetail.RowIndex = int64(index + 1)
- // jYApplyDetail.Barcode = ""
- // jYApplyDetail.CustomerBarcode = strconv.FormatInt(item.ID, 10)
- // jYApplyDetail.Comment = ""
- // jYApplyDetail.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
- // jYApplyDetails = append(jYApplyDetails, jYApplyDetail)
- //
- // //丙型肝炎抗体测定
- // var jYApplyDetail2 models.CustomerApplyDetail
- // id2, _ := strconv.ParseInt("26701", 10, 64)
- // jYApplyDetail2.CustomerChargeItemCode = strconv.FormatInt(id2, 10)
- // jYApplyDetail2.RowIndex = int64(index + 1)
- // jYApplyDetail2.Barcode = ""
- // jYApplyDetail2.CustomerBarcode = strconv.FormatInt(item.ID, 10)
- // jYApplyDetail2.Comment = ""
- // jYApplyDetail2.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
- // jYApplyDetails = append(jYApplyDetails, jYApplyDetail2)
- //
- // //传染病检查(定性)
- // var jYApplyDetail3 models.CustomerApplyDetail
- // id3, _ := strconv.ParseInt("26700", 10, 64)
- // jYApplyDetail3.CustomerChargeItemCode = strconv.FormatInt(id3, 10)
- // jYApplyDetail3.RowIndex = int64(index + 1)
- // jYApplyDetail3.Barcode = ""
- // jYApplyDetail3.CustomerBarcode = strconv.FormatInt(item.ID, 10)
- // jYApplyDetail3.Comment = ""
- // jYApplyDetail3.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
- // jYApplyDetails = append(jYApplyDetails, jYApplyDetail3)
- //
- // }
- //
- // //判断一些需要拆分的组套 血透体检(定性):需要拆分出传染病检查(定性),丙型肝炎抗体测试,血透体检(定性)
- // if subItem == "424" {
- // //血透体检(定性)
- // var jYApplyDetail models.CustomerApplyDetail
- // id, _ := strconv.ParseInt(subItem, 10, 64)
- // jYApplyDetail.CustomerChargeItemCode = strconv.FormatInt(id, 10)
- // jYApplyDetail.RowIndex = int64(index + 1)
- // jYApplyDetail.Barcode = ""
- // jYApplyDetail.CustomerBarcode = strconv.FormatInt(item.ID, 10)
- // jYApplyDetail.Comment = ""
- // jYApplyDetail.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
- // jYApplyDetails = append(jYApplyDetails, jYApplyDetail)
- //
- // //丙型肝炎抗体测定
- // var jYApplyDetail2 models.CustomerApplyDetail
- // id2, _ := strconv.ParseInt("42401", 10, 64)
- // jYApplyDetail2.CustomerChargeItemCode = strconv.FormatInt(id2, 10)
- // jYApplyDetail2.RowIndex = int64(index + 1)
- // jYApplyDetail2.Barcode = ""
- // jYApplyDetail2.CustomerBarcode = strconv.FormatInt(item.ID, 10)
- // jYApplyDetail2.Comment = ""
- // jYApplyDetail2.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
- // jYApplyDetails = append(jYApplyDetails, jYApplyDetail2)
- //
- // //传染病检查(定性)
- // var jYApplyDetail3 models.CustomerApplyDetail
- // id3, _ := strconv.ParseInt("42400", 10, 64)
- // jYApplyDetail3.CustomerChargeItemCode = strconv.FormatInt(id3, 10)
- // jYApplyDetail3.RowIndex = int64(index + 1)
- // jYApplyDetail3.Barcode = ""
- // jYApplyDetail3.CustomerBarcode = strconv.FormatInt(item.ID, 10)
- // jYApplyDetail3.Comment = ""
- // jYApplyDetail3.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
- // jYApplyDetails = append(jYApplyDetails, jYApplyDetail3)
- //
- // }
- // var jYApplyDetail models.CustomerApplyDetail
- // id, _ := strconv.ParseInt(subItem, 10, 64)
- // jYApplyDetail.CustomerChargeItemCode = strconv.FormatInt(id, 10)
- // jYApplyDetail.RowIndex = int64(index + 1)
- // jYApplyDetail.Barcode = ""
- // jYApplyDetail.CustomerBarcode = strconv.FormatInt(item.ID, 10)
- // jYApplyDetail.Comment = ""
- // jYApplyDetail.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
- // jYApplyDetails = append(jYApplyDetails, jYApplyDetail)
- // }
- // }
- //
- // if len(item.ProjectIds) > 0 {
- // team_ids := strings.Split(item.ProjectIds, ",")
- // for index, subItem := range team_ids {
- // var jYApplyDetail models.CustomerApplyDetail
- // id, _ := strconv.ParseInt(subItem, 10, 64)
- // jYApplyDetail.CustomerChargeItemCode = strconv.FormatInt(id, 10)
- // jYApplyDetail.RowIndex = int64(index)
- // jYApplyDetail.Barcode = ""
- // jYApplyDetail.CustomerBarcode = strconv.FormatInt(item.ID, 10)
- // jYApplyDetail.Comment = ""
- // jYApplyDetail.TakeSampleTime = time.Unix(item.Ctime, 0).Format("2006-01-02 15:04:05")
- // jYApplyDetails = append(jYApplyDetails, jYApplyDetail)
- // }
- // }
- // result := PostInspectApply(key, apply, jYApplyDetails)
- // if result.Res == 0 {
- // item.ApplyCode = result.JYApplyResult.ApplyCode
- // jsonData, err := json.Marshal(apply)
- // if err != nil {
- // fmt.Println("转换为JSON时发生错误:", err)
- // }
- // jsonStr := string(jsonData)
- // jsonData2, err2 := json.Marshal(jYApplyDetails)
- // if err2 != nil {
- // fmt.Println("转换为JSON时发生错误:", err2)
- // }
- // jsonStr2 := string(jsonData2)
- //
- // jsonData3, err3 := json.Marshal(result)
- // if err3 != nil {
- // fmt.Println("转换为JSON时发生错误:", err3)
- // }
- // jsonStr3 := string(jsonData3)
- // saveSuccessLog(jsonStr3, jsonStr+"\r\n"+jsonStr2, "申清单成功日志", "申清单")
- // err1 := service.CreateLabelPrint(&item)
- // if err1 == nil {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "发送成功",
- // })
- // }
- // return
- // } else {
- // jsonData, err := json.Marshal(apply)
- // if err != nil {
- // fmt.Println("转换为JSON时发生错误:", err)
- //
- // }
- // jsonStr := string(jsonData)
- //
- // jsonData2, err2 := json.Marshal(jYApplyDetails)
- // if err2 != nil {
- // fmt.Println("转换为JSON时发生错误:", err2)
- //
- // }
- // jsonStr2 := string(jsonData2)
- //
- // jsonData3, err3 := json.Marshal(result)
- // if err3 != nil {
- // fmt.Println("转换为JSON时发生错误:", err3)
- //
- // }
- // jsonStr3 := string(jsonData3)
- //
- // SaveErrorLog(jsonStr3, jsonStr+"\r\n"+jsonStr2, "申清单错误日志", "申清单")
- //
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- // return
- // }
- // }
- // }
- //
- // }
- //}
-
- func (c *HisPrintApiController) GetLablePrint() {
- patient_id, _ := c.GetInt64("patient_id")
- ids := c.GetString("ids")
- record_date := c.GetString("record_date")
- labels, _ := service.GetLabelPrint(ids, c.GetAdminUserInfo().CurrentOrgId, record_date, patient_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "labels": labels,
- })
- return
- }
-
- func (c *HisPrintApiController) CreateLablePrint() {
- patient_id, _ := c.GetInt64("patient_id")
- isCombinationPrint, _ := c.GetBool("is_combination_print")
- team_ids := c.GetString("team_ids")
- ids := c.GetString("ids")
- record_date := c.GetString("record_date")
- doctor_id, _ := c.GetInt64("doctor_id")
- project_ids := c.GetString("project_ids")
- is_team, _ := c.GetInt64("is_team")
-
- var hlpsi models.HisLabelPrintStatusInfo
- hlpsi.Status = 1
- hlpsi.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
- hlpsi.PatientId = patient_id
- hlpsi.RecordDate = record_date
- hlpsi.Mtime = time.Now().Unix()
- hlpsi.Ctime = time.Now().Unix()
- hlpsi.ItemIds = team_ids
- hlpsi.ProjectIds = project_ids
- hlpsi.Ids = ids
- hlpsi.DoctorId = doctor_id
- hlpsi.IsTeam = is_team
- hlpsi.IsPrint = 1
- if isCombinationPrint == true {
- hlpsi.IsCombinationPrint = 1
- } else {
- hlpsi.IsCombinationPrint = 0
- }
- service.CreateLabelPrint(&hlpsi)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功",
- "hlpsi": hlpsi,
- })
- return
- }
-
- func (c *HisPrintApiController) GetUnChargePrescriptionList() {
- patient_id, _ := c.GetInt64("patient_id")
- recordDateTime, _ := c.GetInt64("record_date")
- admin_user_id, _ := c.GetInt64("admin_user_id")
- p_type, _ := c.GetInt64("p_type", 0)
- admin := c.GetAdminUserInfo()
- xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
- record, _ := service.GetLastInHospitalRecord(patient_id, c.GetAdminUserInfo().CurrentOrgId)
- var prescriptions []*models.HisPrescription
- prescriptions, _ = service.GetUnChargeHisPrescriptionTen(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
- admin_info, _ := service.GetAdminUserRole(admin_user_id, c.GetAdminUserInfo().CurrentOrgId)
- //获取所有科室信息
- c.ServeSuccessJSON(map[string]interface{}{
- "xt_info": xt_patient_info,
- "prescription": prescriptions,
- "record": record,
- "admin_info": admin_info,
- })
- return
- }
- func (c *HisPrintApiController) GetUnChargePrescriptionSummary() {
- patient_id, _ := c.GetInt64("patient_id")
- record_date, _ := c.GetInt64("record_date")
- admin_user_id, _ := c.GetInt64("admin_user_id")
- p_type, _ := c.GetInt64("p_type", 0)
- //timeLayout := "2006-01-02"
- //loc, _ := time.LoadLocation("Local")
- //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- //if err != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- //}
- //recordDateTime := theTime.Unix()
- admin := c.GetAdminUserInfo()
- xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
- record, _ := service.GetLastInHospitalRecord(patient_id, c.GetAdminUserInfo().CurrentOrgId)
- var prescriptions []*models.HisPrescription
- prescriptions, _ = service.GetUnChargeHisPrescriptionTen(admin.CurrentOrgId, patient_id, record_date, p_type)
- //doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
- service.GetAdminUserRole(admin_user_id, c.GetAdminUserInfo().CurrentOrgId)
- //获取所有科室信息
- c.ServeSuccessJSON(map[string]interface{}{
- "xt_info": xt_patient_info,
- "prescription": prescriptions,
- "record": record,
- "admin_info": admin_user_id,
- })
- return
- }
- func (c *HisPrintApiController) GetBatchHisPrescriptionData() {
- record_date := c.GetString("record_date")
- patient_ids := c.GetString("patient_ids")
- print_type, _ := c.GetInt64("type")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- adminInfo := c.GetAdminUserInfo()
- ids := strings.Split(patient_ids, ",")
- switch print_type {
- case 1:
- patients, _ := service.GetBatchDrugHisPrescription(ids, recordDateTime, adminInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "patients": patients,
- })
- break
- case 2:
- //var newPatients []*models.PrintPatient
-
- patients, _ := service.GetBatchProjectHisPrescription(ids, recordDateTime, adminInfo.CurrentOrgId)
- //for _, item := range patients {
- // for _, subItem := range item.HisPrintPrescription {
- // for _, subItemTwo := range subItem.HisPrescriptionProject {
- // if subItemTwo.HisProject.CostClassify != 3 {
- //
- // }
- // }
- // }
- //}
- c.ServeSuccessJSON(map[string]interface{}{
- "patients": patients,
- })
- break
- case 3:
- var newPatients []*models.PrintPatient
- var newPatientsTwo []*models.PrintPatient
-
- patients, _ := service.GetBatchInspectionProjectHisPrescription(ids, recordDateTime, adminInfo.CurrentOrgId)
- for _, item := range patients {
- var newPatient *models.PrintPatient
- newPatient = item
- for index, subItem := range item.HisPrintPrescription {
- if index > 0 {
- item.HisPrintPrescription[0].HisPrescriptionProject = append(item.HisPrintPrescription[0].HisPrescriptionProject, subItem.HisPrescriptionProject...)
- }
- }
- newPatients = append(newPatients, newPatient)
- }
-
- for _, item := range patients {
- var newPatient *models.PrintPatient
- newPatient = item
- if len(item.HisPrintPrescription) > 0 {
- newPatient.NewHisPrintPrescription = append(newPatient.NewHisPrintPrescription, item.HisPrintPrescription[0])
- newPatientsTwo = append(newPatientsTwo, newPatient)
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "patients": newPatientsTwo,
- })
- break
- }
- }
-
- func GetAge(idCard string) (int, error) {
- birthDate, err := getBirthDateFromIDCard(idCard)
- if err != nil {
- return 0, err
- }
-
- age := calculateAge(birthDate)
- return age, nil
- }
-
- func getBirthDateFromIDCard(idCard string) (time.Time, error) {
- birthDateStr := idCard[6:14] // 身份证号码中生日部分的字符
- birthDate, err := time.Parse("20060102", birthDateStr)
- if err != nil {
- return time.Time{}, err
- }
-
- return birthDate, nil
- }
-
- func calculateAge(birthDate time.Time) int {
- now := time.Now()
- age := now.Year() - birthDate.Year()
-
- // 如果当前月份小于出生月份,或者当前月份等于出生月份但当前日期小于出生日期,则年龄减一
- if now.Month() < birthDate.Month() || (now.Month() == birthDate.Month() && now.Day() < birthDate.Day()) {
- age--
- }
-
- return age
- }
-
- // 送检单
- //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
- //}
-
- func SaveErrorLog(result string, request string, infno string, desc string) {
- //org_id, _ := beego.AppConfig.Int64("org_id")
- //miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
- dir := "faild"
- utils.Mkdir(dir)
- month := time.Unix(1557042972, 0).Format("1")
- year := time.Now().Format("2006")
- month = time.Now().Format("01")
- day := time.Now().Format("02")
- hour := time.Now().Format("15")
- min := time.Now().Format("04")
- sec := time.Now().Format("05")
-
- result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
-
- file := "failed" + "_" + year + month + day + "_log"
- file_name := file + ".txt"
- file_path := "faild" + "/" + file_name
- exist, _ := utils.PathExists(file_path)
- if exist { //存在
- fmt.Println("存在")
- f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
- if err != nil {
- fmt.Println("read fail")
- }
- content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
- n, _ := f.Seek(0, 2)
- _, err = f.WriteAt([]byte(content), n)
-
- } else { //不存在
- fmt.Println("文件不存在,创建文件")
- f, err := os.Create("faild" + "/" + file_name)
- defer f.Close()
- if err != nil {
- } else {
- _, err = f.Write([]byte("记录日志"))
- }
- }
-
- }
- func saveSuccessLog(result string, request string, infno string, desc string) {
-
- //org_id, _ := beego.AppConfig.Int64("org_id")
- //miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
- //dir := "同步成功日志"
- //utils.Mkdir(dir)
- month := time.Unix(1557042972, 0).Format("1")
- year := time.Now().Format("2006")
- month = time.Now().Format("01")
- day := time.Now().Format("02")
- hour := time.Now().Format("15")
- min := time.Now().Format("04")
- sec := time.Now().Format("05")
-
- result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
-
- file := "success" + "_" + year + month + day + "_log"
- file_name := file + ".txt"
- file_path := file_name
- exist, _ := utils.PathExists(file_path)
- if exist { //存在
- fmt.Println("存在")
- f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
- if err != nil {
- fmt.Println("read fail")
- }
- content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
- n, _ := f.Seek(0, 2)
- _, err = f.WriteAt([]byte(content), n)
-
- } else { //不存在
- fmt.Println("文件不存在,创建文件")
- f, err := os.Create(file_name)
- defer f.Close()
- if err != nil {
- } else {
- _, err = f.Write([]byte("记录日志"))
- }
- }
-
- }
|