123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694 |
- package controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "encoding/json"
- "fmt"
- "github.com/astaxie/beego"
- "io/ioutil"
- "math/rand"
- "os"
- "strconv"
- "strings"
- "time"
- )
-
- type CoordinateController struct {
- BaseAPIController
- }
-
- type ResultReg struct {
- ResultCode string `json:"resultCode"`
- ResultDesc string `json:"resultDesc"`
- InfoSeq string `json:"infoSeq"`
- }
-
- type ResultSettle struct {
- ResultCode string `json:"resultCode"`
- ResultDesc string `json:"resultDesc"`
- }
-
- type ResultCancelSettle struct {
- ResultCode string `json:"resultCode"`
- ResultDesc string `json:"resultDesc"`
- }
-
- type Settle struct {
- PatientId string `json:"resultCode"`
- DocId string `json:"docId"`
- InfoSeq string `json:"infoSeq"`
- }
-
- type Refund struct {
- PatientId string `json:"resultCode"`
- DocId string `json:"docId"`
- InfoSeq string `json:"infoSeq"`
- }
-
- type RefundDetail struct {
- Msg string `json:"msg"`
- Result []struct {
- ResultMsg string `json:"resultMsg"`
- Code string `json:"code"`
- Records int `json:"records"`
- TotalPage int `json:"totalPage"`
- List []struct {
- Zae01 int64 `json:"ZAE01"`
- } `json:"list"`
- RecordsTotal int `json:"recordsTotal"`
- Pagenumber int `json:"pagenumber"`
- Result string `json:"result"`
- Total int `json:"total"`
- RecordsFtered int `json:"recordsFtered"`
- Page int `json:"page"`
- } `json:"result"`
- Code string `json:"code"`
- }
-
- func CoordinateRcegistRouters() {
- beego.Router("/coordinate/check", &CoordinateController{}, "get:SavePatientMessageInfo")
- //坐标挂号
- beego.Router("/coordinate/register", &CoordinateController{}, "get:Register")
- //坐标记账
- beego.Router("/coordinate/opKeepAccounts", &CoordinateController{}, "get:OpKeepAccounts")
- //坐标撤销记账
- beego.Router("/coordinate/opCancelKeepAccounts", &CoordinateController{}, "get:OpCancelKeepAccounts")
- //坐标结算回调
- beego.Router("/coordinate/settle", &CoordinateController{}, "post:Settle")
- //坐标退费回调
- beego.Router("/coordinate/refund", &CoordinateController{}, "post:Refund")
-
- }
-
- func (c *CoordinateController) Settle() {
- //参数1 patient_id
- //参数2 就诊号
- //参数3 单据id
- fmt.Println(c.Ctx.Request.Body)
-
- body, _ := ioutil.ReadAll(c.Ctx.Request.Body)
- fmt.Println(string(body))
-
- var respJSON map[string]interface{}
- if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
- utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
- return
- }
- patien_id := respJSON["patientid"].(string)
- infoSeq := respJSON["infoseq"].(string)
- docId := respJSON["docid"].(string)
- fmt.Println(patien_id)
- fmt.Println(infoSeq)
- fmt.Println(docId)
-
- order, _ := service.GetHisOrderFour(patien_id, infoSeq, "")
- order.SetlId = docId
- if order.ID == 0 {
- json := make(map[string]interface{})
- json["msg"] = "结算记录不存在,请检查参数是否正确"
- json["code"] = "-1"
- c.Data["json"] = json
- c.ServeJSON()
- return
- }
- order.OrderStatus = 2
- service.UpDateOrder(order)
- service.UpdataOrderStatusTwo(order.Number, order.UserOrgId)
- json := make(map[string]interface{})
- json["msg"] = "结算成功"
- json["code"] = "0"
- c.Data["json"] = json
- c.ServeJSON()
- return
- }
- func (c *CoordinateController) Refund() {
- //参数1 patient_id
- //参数2 就诊号
- //参数3 单据id
- body, _ := ioutil.ReadAll(c.Ctx.Request.Body)
- var respJSON map[string]interface{}
- if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
- utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
- return
- }
- patien_id := respJSON["patientid"].(string)
- infoSeq := respJSON["infoseq"].(string)
- docId := respJSON["docid"].(string)
- order, _ := service.GetHisOrderFour(patien_id, infoSeq, docId)
- if order.ID == 0 {
- json := make(map[string]interface{})
- json["msg"] = "结算记录不存在,请检查参数是否正确"
- json["code"] = "-1"
- c.Data["json"] = json
- c.ServeJSON()
- return
- }
- service.UpdataOrderStatus(order.ID, order.Number, order.UserOrgId)
- json := make(map[string]interface{})
- json["msg"] = "退费成功"
- json["code"] = "0"
- c.Data["json"] = json
- c.ServeJSON()
- return
- }
-
- func (c *CoordinateController) SavePatientMessageInfo() {
- result, request_log := service.SavePatientMessageInfo()
- fmt.Println(result)
- fmt.Println(request_log)
-
- }
-
- func (c *CoordinateController) Register() {
- patient_id, _ := c.GetInt64("patient_id")
- diagnosis_time := c.GetString("diagnosis_time")
- record_date := c.GetString("record_date")
- admin_user_id, _ := c.GetInt64("admin_user_id")
- org_id, _ := c.GetInt64("org_id")
- patient, _ := service.GetPatientByID(org_id, patient_id)
- org, _ := service.GetOrgById(org_id)
-
- 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
- }
- if len(patient.ZbPatientId) == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnNoEmpty)
- return
- }
-
- recordDateTime := theTime.Unix()
- patientPrescription, _ := service.FindPatientPrescriptionInfoTwo(org_id, patient.ID, recordDateTime, 2)
- if patientPrescription.ID == 0 {
- patientPrescription, _ = service.FindLastPatientPrescriptionInfo(org_id, patient.ID, recordDateTime)
- }
- doctor_info, _ := service.GetAdminUserInfoByID(org_id, patientPrescription.DoctorId)
- admin_user_info, _ := service.GetAdminUserInfoByID(org_id, admin_user_id)
- reg := models.Reg{
- DeptId: "0112",
- PatientId: patient.ZbPatientId,
- PatientName: patient.Name,
- DoctorId: doctor_info.DoctorNumber,
- RegDate: strings.Split(diagnosis_time, " ")[0],
- RegFee: "0",
- TreatFee: "0",
- OperatorId: admin_user_info.UserName,
- IdCardNo: patient.IdCardNo,
- }
-
- result, request_log := service.SaveReg(reg)
- fmt.Println(result)
- fmt.Println(request_log)
- saveLog(result, request_log, "登记", "登记", org.OrgName)
- var res ResultReg
- if err := json.Unmarshal([]byte(result), &res); err != nil {
- utils.ErrorLog("解析失败:%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- if res.ResultCode == "0" {
- timestamp := time.Now().Unix()
- tempTime := time.Unix(timestamp, 0)
- timeFormat := tempTime.Format("20060102150405")
- chrgBchno := rand.Intn(100000) + 10000
- ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(patient.ID, 10)
- his := models.VMHisPatient{
- Name: patient.Name,
- Gender: patient.Gender,
- Birthday: patient.Birthday,
- MedicalTreatmentType: 0,
- IdType: 1,
- IdCardNo: patient.IdCardNo,
- BalanceAccountsType: 1,
- MedicalInsuranceNumber: "",
- RegisterType: 0,
- RegisterCost: 0,
- TreatmentCost: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- PsnNo: patient.ZbPatientId,
- PsnCertType: "",
- Certno: patient.IdCardNo,
- PsnName: patient.Name,
- Gend: "",
- Naty: "",
- Brdy: "",
- Age: 0,
- Iinfo: "",
- Idetinfo: "",
- PatientId: patient.ID,
- RecordDate: theTime.Unix(),
- UserOrgId: org_id,
- AdminUserId: admin_user_id,
- IsReturn: 1,
- Doctor: patientPrescription.DoctorId,
- Departments: patientPrescription.Departments,
- IptOtpNo: ipt_otp_no,
- Number: res.InfoSeq,
- PhoneNumber: patient.Phone,
- }
- service.UpdateHisPatientStatus(&his)
- service.UpdateHisPrescriptionHisID(his.ID, patient.ID, recordDateTime, org_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "his_info": his,
- })
- } else {
-
- c.ServeSuccessJSON(map[string]interface{}{
- "failed_code": -10,
- "msg": res.ResultDesc,
- })
-
- }
- }
-
- //func (c *CoordinateController) GetWaitPayDetail() {
- // result, request_log := service.GetWaitPayDetail()
- // fmt.Println(result)
- // fmt.Println(request_log)
- //
- //}
-
- func (c *CoordinateController) OpKeepAccounts() {
- id, _ := c.GetInt64("id")
- record_time := c.GetString("record_time")
- his_patient_id, _ := c.GetInt64("his_patient_id")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
- fapiao_code := c.GetString("fapiao_code")
- fapiao_number := c.GetString("fapiao_number")
- diagnosis_id := c.GetString("diagnosis")
- sick_type, _ := c.GetInt64("sick_type")
- reg_type, _ := c.GetInt64("p_type")
- org_id, _ := c.GetInt64("org_id")
- org, _ := service.GetOrgById(org_id)
-
- his, _ := service.GetHisPatientByIdThree(his_patient_id)
-
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- //adminUser := c.GetAdminUserInfo()
- var prescriptions []*models.HisPrescription
- var start_time int64
- var end_time int64
-
- //ids_str := c.GetString("ids")
- //ids_arr := strings.Split(ids_str, ",")
-
- if settle_accounts_type == 1 { //日结
- //fmt.Println(reg_type)
- prescriptions, _ = service.GetUnSettleHisPrescriptionFive(org_id, id, recordDateTime, 2)
-
- } else { //月结
-
- start_time_str := c.GetString("start_time")
- end_time_str := c.GetString("end_time")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordStartTime := theStartTime.Unix()
- start_time = recordStartTime
- theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordEndTime := theEndTime.Unix()
- end_time = recordEndTime
- prescriptions, _ = service.GetUnSettleMonthHisPrescription(org_id, id, recordStartTime, recordEndTime)
- }
-
- timestamp := time.Now().Unix()
- tempTime := time.Unix(timestamp, 0)
- timeFormat := tempTime.Format("20060102150405")
- chrgBchno := rand.Intn(100000) + 10000
- chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
- strconv.FormatInt(his.PatientId, 10)
-
- var ids []int64
-
- for _, item := range prescriptions {
- ids = append(ids, item.ID)
- }
- var total float64
-
- for _, item := range prescriptions {
- fmt.Println(item)
- if item.Type == 1 { //药品
- for _, subItem := range item.HisDoctorAdviceInfo {
- total = total + (subItem.Price * subItem.PrescribingNumber)
- }
- }
- if item.Type == 2 { //项目
- for _, subItem := range item.HisPrescriptionProject {
- cnt, _ := strconv.ParseFloat(subItem.Count, 64)
- total = total + (subItem.Price * cnt)
- }
- }
-
- for _, subItem := range item.HisAdditionalCharge {
- total = total + (subItem.Price * float64(subItem.Count))
- }
- }
-
- tm := time.Unix(time.Now().Unix(), 0)
-
- var customs []*models.NewCustomTwo
- for _, item := range prescriptions {
- if item.Type == 1 { //药品
- for _, subItem := range item.HisDoctorAdviceInfo {
- cus := &models.NewCustomTwo{
- AdviceId: subItem.ID,
- ProjectId: 0,
- DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
- Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
- FeedetlSn: subItem.FeedetlSn,
- Price: fmt.Sprintf("%.2f", subItem.Price),
- MedListCodg: subItem.Drug.MedicalInsuranceNumber,
- Type: 1,
- }
- customs = append(customs, cus)
- }
- }
- if item.Type == 2 { //项目
- for _, subItem := range item.HisPrescriptionProject {
- if subItem.Type == 2 {
- cnt, _ := strconv.ParseFloat(subItem.Count, 64)
- cus := &models.NewCustomTwo{
- AdviceId: 0,
- ProjectId: subItem.ID,
- DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
- Cut: fmt.Sprintf("%.4f", cnt),
- FeedetlSn: subItem.FeedetlSn,
- Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
- MedListCodg: subItem.HisProject.MedicalCode,
- Type: 2,
- }
- customs = append(customs, cus)
-
- } else {
- cnt, _ := strconv.ParseFloat(subItem.Count, 64)
- cus := &models.NewCustomTwo{
- AdviceId: 0,
- ProjectId: subItem.ID,
- DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
- Cut: fmt.Sprintf("%.4f", cnt),
- FeedetlSn: subItem.FeedetlSn,
- Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
- MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
- Type: 3,
- }
- customs = append(customs, cus)
-
- }
-
- }
- }
- for _, item := range item.HisAdditionalCharge {
- cus := &models.NewCustomTwo{
- ItemId: item.ID,
- AdviceId: 0,
- ProjectId: 0,
- DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
- Cut: fmt.Sprintf("%.4f", float64(item.Count)),
- FeedetlSn: item.FeedetlSn,
- Price: fmt.Sprintf("%.4f", float64(item.Price)),
- MedListCodg: item.XtHisAddtionConfig.Code,
- Type: 3,
- }
- customs = append(customs, cus)
- }
- }
- result, request_log := service.OpKeepAccounts(his.Number, customs)
- saveLog(result, request_log, "记账", "记账", org.OrgName)
-
- var res ResultSettle
- if err := json.Unmarshal([]byte(result), &res); err != nil {
- utils.ErrorLog("解析失败:%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- if res.ResultCode == "0" {
-
- //totals, _ := strconv.ParseFloat(total, 64)
- order := &models.HisOrder{
- PsnNo: his.PsnNo,
- UserOrgId: org_id,
- HisPatientId: his.ID,
- PatientId: id,
- SettleAccountsDate: recordDateTime,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- Status: 1,
- OrderStatus: 1,
- MdtrtId: his.Number,
- Number: chrg_bchno,
- SetlId: "",
- MedfeeSumamt: total,
- MedType: strconv.Itoa(int(reg_type)),
- SettleEndTime: end_time,
- SettleStartTime: start_time,
- SettleType: settle_accounts_type,
- FaPiaoCode: fapiao_code,
- FaPiaoNumber: fapiao_number,
- Diagnosis: diagnosis_id,
- PType: 2,
- SetlTime: tm.Format("2006-01-02 15:04:05"),
- }
- err = service.CreateOrder(order)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
- return
- }
-
- for _, item := range customs {
- var advice_id int64 = 0
- var project_id int64 = 0
- var item_id int64 = 0
-
- var types int64 = 0
-
- if item.Type == 1 {
- advice_id = item.AdviceId
- project_id = 0
- item_id = 0
- } else if item.Type == 2 {
- advice_id = 0
- item_id = 0
-
- project_id = item.ProjectId
- } else if item.Type == 3 {
- advice_id = 0
- item_id = item.ItemId
- project_id = 0
- }
- detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
- cut, _ := strconv.ParseFloat(item.Cut, 32)
- pric, _ := strconv.ParseFloat(item.Price, 32)
- info := &models.HisOrderInfo{
- OrderNumber: order.Number,
- UploadDate: time.Now().Unix(),
- AdviceId: advice_id,
- DetItemFeeSumamt: detItemFeeSumamt,
- Cnt: cut,
- Pric: pric,
- PatientId: id,
- Status: 1,
- Mtime: time.Now().Unix(),
- Ctime: time.Now().Unix(),
- UserOrgId: org_id,
- HisPatientId: his.ID,
- OrderId: order.ID,
- ProjectId: project_id,
- Type: types,
- ItemId: item_id,
- }
- service.CreateOrderInfo(info)
- }
- his.Diagnosis = diagnosis_id
- his.SickType = sick_type
- his.RegisterType = reg_type
- his.MedicalTreatmentType = reg_type
- service.UpdataHisPateint(&his)
- err = service.UpDatePrescriptionNumber(org_id, ids, chrg_bchno)
- err = service.UpDateHisPrescriptionInfoNumber(org_id, id, chrg_bchno, recordDateTime, his_patient_id)
- err = service.UpdataOrderStatusThree(chrg_bchno, org_id)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "记账成功",
- })
- }
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "failed_code": -10,
- "msg": res.ResultDesc,
- })
- }
-
- }
-
- func (c *CoordinateController) OpCancelKeepAccounts() {
- order_id, _ := c.GetInt64("order_id")
- admin_user_id, _ := c.GetInt64("admin_user_id")
- org_id, _ := c.GetInt64("org_id")
- org, _ := service.GetOrgById(org_id)
-
- order, _ := service.GetHisOrderByID(order_id)
- if order.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
- return
- }
-
- role, _ := service.GetAdminUserInfoByID(org_id, admin_user_id)
- result, request_log := service.OpCancelKeepAccounts(order.SetlId, role.UserName, role.DoctorNumber)
- saveLog(result, request_log, "撤销记账", "撤销记账", org.OrgName)
- var res RefundDetail
- if err := json.Unmarshal([]byte(result), &res); err != nil {
- utils.ErrorLog("解析失败:%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- fmt.Println(result)
- fmt.Println(request_log)
- fmt.Println(res)
- flag := 0
- isSuccess := false
- for _, item := range res.Result {
- if item.Code == "200" {
- flag = flag + 1
- }
- }
- if len(res.Result) == flag {
- isSuccess = true
- }
- var errMsg string
- for _, item := range res.Result {
- errMsg = errMsg + "\n" + item.ResultMsg
- }
-
- if isSuccess {
- err := service.UpdataOrderStatus(order_id, order.Number, org_id)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "撤销记账成功",
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "failed_code": -10,
- "msg": errMsg,
- })
-
- }
- }
-
- //func saveLog(result string, request string, infno string, desc string) {
- //
- // org_id, _ := beego.AppConfig.Int64("org_id")
- // miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
- // dir := miConfig.OrgName + "日志"
- // 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 := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
- // file_name := file + ".txt"
- // file_path := miConfig.OrgName + "日志" + "/" + 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(miConfig.OrgName + "日志" + "/" + file_name)
- // defer f.Close()
- // if err != nil {
- // } else {
- // _, err = f.Write([]byte("记录日志"))
- // }
- // }
- //
- //}
-
- type Charset string
-
- const (
- UTF8 = Charset("UTF-8")
- GB18030 = Charset("GB18030")
- )
-
- func saveLog(result string, request string, infno string, desc string, org_name string) {
-
- //org_id, _ := beego.AppConfig.Int64("org_id")
- //miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
- dir := org_name + "日志"
- 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 := org_name + "_" + year + month + day + "_log"
- file_name := file + ".txt"
- file_path := org_name + "日志" + "/" + 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(org_name + "日志" + "/" + file_name)
- defer f.Close()
- if err != nil {
- } else {
- _, err = f.Write([]byte("记录日志"))
- }
- }
-
- }
|