coordinate_controller.go 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. package coordinate
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "gdyb/controllers"
  6. "gdyb/enums"
  7. "gdyb/models"
  8. "gdyb/service"
  9. "gdyb/utils"
  10. "github.com/astaxie/beego"
  11. "math/rand"
  12. "os"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. type ResultUpload struct {
  18. Code string `json:"code"`
  19. Msg string `json:"msg"`
  20. Result []struct {
  21. List []interface{} `json:"list"`
  22. Page int64 `json:"page"`
  23. Pagenumber int64 `json:"pagenumber"`
  24. Records int64 `json:"records"`
  25. RecordsFiltered int64 `json:"recordsFiltered"`
  26. RecordsTotal int64 `json:"recordsTotal"`
  27. Result string `json:"result"`
  28. ResultMsg string `json:"resultMsg"`
  29. Total int64 `json:"total"`
  30. TotalPage int64 `json:"totalPage"`
  31. Userdata string `json:"userdata"`
  32. Code string `json:"code"`
  33. } `json:"result"`
  34. }
  35. type ResultQuery struct {
  36. Msg string `json:"msg"`
  37. Result []struct {
  38. Type string `json:"type"`
  39. Name string `json:"name"`
  40. Vaa01 int `json:"vaa01"`
  41. Vaa07 int `json:"vaa07"`
  42. Visittime string `json:"visittime"`
  43. } `json:"result"`
  44. Code string `json:"code"`
  45. }
  46. type CoordinateController struct {
  47. controllers.BaseAuthAPIController
  48. }
  49. type ResultReg struct {
  50. ResultCode string `json:"resultCode"`
  51. ResultDesc string `json:"resultDesc"`
  52. InfoSeq string `json:"infoSeq"`
  53. }
  54. func CoordinateRegistRouters() {
  55. beego.Router("/coordinate/settleAccount", &CoordinateController{}, "get:SettleAccount")
  56. }
  57. func (c *CoordinateController) SettleAccount() {
  58. patient_id, _ := c.GetInt64("patient_id")
  59. record_date := c.GetString("record_date")
  60. admin_user_id, _ := c.GetInt64("admin_user_id")
  61. diagnosis_id := c.GetString("diagnosis")
  62. sick_type, _ := c.GetInt64("sick_type")
  63. reg_type, _ := c.GetInt64("p_type")
  64. org_id, _ := c.GetInt64("org_id")
  65. org_id = 10340
  66. org, _ := service.GetOrgById(org_id)
  67. patient, _ := service.GetPatientByID(org.Id, patient_id)
  68. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  69. result, request := service.GetHisPatientForCoordinate(patient.IdCardNo)
  70. saveLog(result, request, "查询", "查询", org.OrgName)
  71. var res ResultQuery
  72. if err := json.Unmarshal([]byte(result), &res); err != nil {
  73. utils.ErrorLog("解析失败:%v", err)
  74. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  75. return
  76. }
  77. if res.Code == "10000" {
  78. if len(res.Result) == 0 {
  79. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientNoRegException)
  80. return
  81. }
  82. timeLayout := "2006-01-02"
  83. loc, _ := time.LoadLocation("Local")
  84. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  85. if err != nil {
  86. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  87. return
  88. }
  89. org_id := org.Id
  90. recordDateTime := theTime.Unix()
  91. patientPrescription, _ := service.FindPatientPrescriptionInfoTwo(org_id, patient.ID, recordDateTime, 2)
  92. if patientPrescription.ID == 0 {
  93. patientPrescription, _ = service.FindLastPatientPrescriptionInfoTwoTen(org_id, patient.ID, recordDateTime)
  94. }
  95. departmwnt, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  96. doctor_info, _ := service.GetAdminUserInfoByID(org_id, patientPrescription.DoctorId)
  97. //admin_user_info, _ := service.GetAdminUserInfoByID(org_id, admin_user_id)
  98. var prescriptions []*models.HisPrescription
  99. if settle_accounts_type == 1 { //日结
  100. prescriptions, _ = service.GetUnSettleHisPrescriptionFiveTen(org_id, patient_id, recordDateTime, 2)
  101. } else { //月结
  102. start_time_str := c.GetString("start_time")
  103. end_time_str := c.GetString("end_time")
  104. timeLayout := "2006-01-02"
  105. loc, _ := time.LoadLocation("Local")
  106. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  107. if err != nil {
  108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  109. return
  110. }
  111. recordStartTime := theStartTime.Unix()
  112. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  113. if err != nil {
  114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  115. return
  116. }
  117. recordEndTime := theEndTime.Unix()
  118. prescriptions, _ = service.GetUnSettleMonthHisPrescription(org_id, patient_id, recordStartTime, recordEndTime)
  119. }
  120. var total float64
  121. for _, item := range prescriptions {
  122. fmt.Println(item)
  123. if item.Type == 1 { //药品
  124. for _, subItem := range item.HisDoctorAdviceInfo {
  125. total = total + (subItem.Price * subItem.PrescribingNumber)
  126. }
  127. }
  128. if item.Type == 2 { //项目
  129. for _, subItem := range item.HisPrescriptionProject {
  130. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  131. total = total + (subItem.Price * cnt)
  132. }
  133. }
  134. }
  135. var ids []int64
  136. for _, item := range prescriptions {
  137. ids = append(ids, item.ID)
  138. }
  139. var customs []*models.NewCustomTwo
  140. for _, item := range prescriptions {
  141. if item.Type == 1 { //药品
  142. for _, subItem := range item.HisDoctorAdviceInfo {
  143. cus := &models.NewCustomTwo{
  144. AdviceId: subItem.ID,
  145. ProjectId: 0,
  146. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  147. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  148. FeedetlSn: subItem.FeedetlSn,
  149. Price: fmt.Sprintf("%.2f", subItem.Price),
  150. MedListCodg: subItem.BaseDrugLib.MedicalInsuranceNumber,
  151. Type: 1,
  152. }
  153. customs = append(customs, cus)
  154. }
  155. }
  156. if item.Type == 2 { //项目
  157. for _, subItem := range item.HisPrescriptionProject {
  158. if subItem.Type == 2 {
  159. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  160. cus := &models.NewCustomTwo{
  161. AdviceId: 0,
  162. ProjectId: subItem.ID,
  163. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  164. Cut: fmt.Sprintf("%.4f", cnt),
  165. FeedetlSn: subItem.FeedetlSn,
  166. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  167. MedListCodg: subItem.HisProject.MedicalCode,
  168. Type: 2,
  169. }
  170. customs = append(customs, cus)
  171. } else {
  172. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  173. cus := &models.NewCustomTwo{
  174. AdviceId: 0,
  175. ProjectId: subItem.ID,
  176. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  177. Cut: fmt.Sprintf("%.4f", cnt),
  178. FeedetlSn: subItem.FeedetlSn,
  179. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  180. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  181. Type: 3,
  182. }
  183. customs = append(customs, cus)
  184. }
  185. }
  186. }
  187. }
  188. var info models.UploadInfo
  189. info.Vaa01 = res.Result[0].Vaa01
  190. info.Fasong = "1"
  191. info.Vaa07 = res.Result[0].Vaa07
  192. info.Bck01c = departmwnt.Number
  193. info.Bce02a = doctor_info.DoctorNumber
  194. diagnosis_ids := strings.Split(patientPrescription.Diagnosis, ",")
  195. var config []*models.HisXtDiagnoseConfig
  196. for _, item := range diagnosis_ids {
  197. id, _ := strconv.ParseInt(item, 10, 64)
  198. diagnosisConfig, _ := service.FindDiagnoseById(id)
  199. config = append(config, &diagnosisConfig)
  200. }
  201. for index, item := range config {
  202. var diag models.Diag
  203. diag.Vao06 = strconv.FormatInt(int64(index+1), 10)
  204. diag.Bak02 = item.CountryCode
  205. info.Diag = append(info.Diag, &diag)
  206. }
  207. var presInfos []*models.PresInfo
  208. var presDetails []*models.PresDetail
  209. for index, item := range prescriptions {
  210. var presDetail models.PresDetail
  211. var presInfo models.PresInfo
  212. presInfo.Cbmid = strconv.FormatInt(item.ID, 10)
  213. if item.Type == 1 {
  214. presInfo.Cbm06 = "0"
  215. } else {
  216. presInfo.Cbm06 = "5"
  217. }
  218. if item.Type == 1 {
  219. presInfo.Cbm07 = item.MedType
  220. } else {
  221. presInfo.Cbm07 = item.MedType
  222. }
  223. presDetail.Vaf59 = strconv.FormatInt(int64(index+1), 10)
  224. var infoItems []*models.Item
  225. for index, subItem := range item.HisDoctorAdviceInfo {
  226. ef, _ := service.GetExecutionFrequencyByName(subItem.ExecutionFrequency, subItem.UserOrgId)
  227. var infoItem models.Item
  228. infoItem.Rownr = strconv.FormatInt(int64(index+1), 10)
  229. infoItem.Vaf11 = "2"
  230. infoItem.Vaf36 = time.Unix(subItem.ExecutionTime, 0).Format("2006-01-02 15:04:05")
  231. infoItem.Bbx01 = subItem.BaseDrugLib.MedicalInsuranceNumber
  232. infoItem.Bda01 = "1"
  233. infoItem.Bby01 = ""
  234. if subItem.BaseDrugLib.MinUnit != subItem.BaseDrugLib.DoseUnit {
  235. infoItem.Vaf22 = subItem.BaseDrugLib.DrugName + " " + subItem.BaseDrugLib.Dose + subItem.BaseDrugLib.DoseUnit + "*" + strconv.FormatInt(subItem.BaseDrugLib.MinNumber, 10) + subItem.BaseDrugLib.MinUnit + "/" + subItem.BaseDrugLib.MaxUnit
  236. }
  237. infoItem.Vaf14 = subItem.BaseDrugLib.DrugName
  238. infoItem.Bdi01 = ef.Code
  239. infoItem.Vaf17 = strconv.FormatInt(subItem.Day, 10)
  240. infoItem.Vaf20 = fmt.Sprintf("%.2f", subItem.SingleDose)
  241. infoItem.Vaf21 = fmt.Sprintf("%.2f", subItem.PrescribingNumber)
  242. infoItem.Vaf35 = "0"
  243. infoItem.Vaf32 = "0"
  244. infoItem.Bck01b = departmwnt.Number
  245. infoItem.Bck01d = departmwnt.Number
  246. infoItem.Vaf58 = "0"
  247. infoItem.Vaf61 = "1"
  248. infoItems = append(infoItems, &infoItem)
  249. }
  250. for _, subItem := range item.HisPrescriptionProject {
  251. //ef, _ := service.GetExecutionFrequencyByName(subItem.ExecutionFrequency, subItem.UserOrgId)
  252. if subItem.Type == 2 {
  253. if subItem.HisProject.CostClassify == 10 {
  254. var infoItem models.Item
  255. infoItem.Rownr = "0"
  256. infoItem.Vaf11 = "2"
  257. infoItem.Vaf36 = time.Unix(subItem.ExecutionTime, 0).Format("2006-01-02 15:04:05")
  258. infoItem.Bbx01 = subItem.HisProject.MedicalCode
  259. infoItem.Bda01 = "Z"
  260. infoItem.Bby01 = ""
  261. infoItem.Vaf14 = subItem.HisProject.ProjectName
  262. infoItem.Vaf15 = subItem.HisProject.ProjectName
  263. infoItem.Bdi01 = "160"
  264. infoItem.Vaf17 = subItem.Day
  265. infoItem.Vaf20 = subItem.SingleDose
  266. infoItem.Vaf21 = subItem.Count
  267. infoItem.Vaf35 = "0"
  268. infoItem.Vaf18 = 0
  269. infoItem.Vaf32 = "1"
  270. infoItem.Bck01b = departmwnt.Number
  271. infoItem.Bck01d = departmwnt.Number
  272. infoItem.Vaf58 = "0"
  273. infoItem.Vaf61 = "1"
  274. infoItems = append(infoItems, &infoItem)
  275. } else {
  276. var infoItem models.Item
  277. infoItem.Rownr = "0"
  278. infoItem.Vaf11 = "1"
  279. infoItem.Vaf36 = time.Unix(subItem.ExecutionTime, 0).Format("2006-01-02 15:04:05")
  280. infoItem.Bbx01 = subItem.HisProject.MedicalCode
  281. if subItem.HisProject.CostClassify == 2 {
  282. infoItem.Bda01 = "T"
  283. } else if subItem.HisProject.CostClassify == 3 {
  284. infoItem.Bda01 = "L"
  285. } else {
  286. infoItem.Bda01 = "T"
  287. }
  288. infoItem.Bby01 = ""
  289. infoItem.Vaf14 = subItem.HisProject.ProjectName
  290. infoItem.Bdi01 = "160"
  291. infoItem.Vaf17 = subItem.Day
  292. infoItem.Vaf20 = subItem.SingleDose
  293. infoItem.Vaf21 = subItem.Count
  294. infoItem.Vaf35 = "0"
  295. infoItem.Vaf18 = 0
  296. infoItem.Vaf32 = "0"
  297. infoItem.Bck01b = departmwnt.Number
  298. infoItem.Bck01d = departmwnt.Number
  299. infoItem.Vaf58 = "0"
  300. infoItem.Vaf61 = "1"
  301. infoItems = append(infoItems, &infoItem)
  302. }
  303. } else {
  304. var infoItem models.Item
  305. infoItem.Rownr = "0"
  306. infoItem.Vaf11 = "1"
  307. infoItem.Vaf36 = time.Unix(subItem.ExecutionTime, 0).Format("2006-01-02 15:04:05")
  308. infoItem.Bbx01 = subItem.GoodInfo.MedicalInsuranceNumber
  309. infoItem.Bda01 = "M"
  310. infoItem.Bby01 = ""
  311. infoItem.Vaf14 = subItem.GoodInfo.GoodName + " " + subItem.GoodInfo.SpecificationName
  312. infoItem.Bdi01 = "160"
  313. infoItem.Vaf17 = subItem.Day
  314. infoItem.Vaf20 = subItem.SingleDose
  315. infoItem.Vaf21 = subItem.Count
  316. infoItem.Vaf35 = "0"
  317. infoItem.Vaf32 = "0"
  318. infoItem.Bck01b = departmwnt.Number
  319. infoItem.Bck01d = departmwnt.Number
  320. infoItem.Vaf58 = "0"
  321. infoItem.Vaf61 = "1"
  322. infoItems = append(infoItems, &infoItem)
  323. }
  324. }
  325. presDetail.Item = infoItems
  326. presDetails = append(presDetails, &presDetail)
  327. presInfo.PresDetail = presDetails
  328. presInfos = append(presInfos, &presInfo)
  329. }
  330. info.PresInfo = presInfos
  331. var result2 string
  332. var request2 string
  333. if res.Result[0].Type == "1" {
  334. result2, request2 = service.UploadPrescriptionForCoordinate(info)
  335. } else {
  336. result2, request2 = service.UploadPrescriptionForCoordinateHospital(info)
  337. }
  338. saveLog(result2, request2, "上传明细", "上传明细", org.OrgName)
  339. var res2 ResultUpload
  340. if err := json.Unmarshal([]byte(result2), &res2); err != nil {
  341. utils.ErrorLog("解析失败:%v", err)
  342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  343. return
  344. }
  345. if res2.Code == "10000" && len(res2.Result) > 0 && res2.Result[0].Code != "500" && len(res2.Result[0].List) > 0 {
  346. timestamp := time.Now().Unix()
  347. tempTime := time.Unix(timestamp, 0)
  348. timeFormat := tempTime.Format("20060102150405")
  349. chrgBchno := rand.Intn(100000) + 10000
  350. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(patient.ID, 10)
  351. his := models.VMHisPatient{
  352. Name: patient.Name,
  353. Gender: patient.Gender,
  354. Birthday: patient.Birthday,
  355. MedicalTreatmentType: 0,
  356. IdType: 1,
  357. IdCardNo: patient.IdCardNo,
  358. BalanceAccountsType: 1,
  359. MedicalInsuranceNumber: "",
  360. RegisterType: 0,
  361. RegisterCost: 0,
  362. TreatmentCost: 0,
  363. Status: 1,
  364. Ctime: time.Now().Unix(),
  365. Mtime: time.Now().Unix(),
  366. PsnNo: strconv.FormatInt(int64(res.Result[0].Vaa01), 10),
  367. PsnCertType: "",
  368. Certno: patient.IdCardNo,
  369. PsnName: patient.Name,
  370. Gend: "",
  371. Naty: "",
  372. Brdy: "",
  373. Age: 0,
  374. Iinfo: "",
  375. Idetinfo: "",
  376. PatientId: patient.ID,
  377. RecordDate: theTime.Unix(),
  378. UserOrgId: org_id,
  379. AdminUserId: admin_user_id,
  380. IsReturn: 1,
  381. Doctor: patientPrescription.DoctorId,
  382. Departments: patientPrescription.Departments,
  383. IptOtpNo: ipt_otp_no,
  384. Number: strconv.FormatInt(int64(res.Result[0].Vaa07), 10),
  385. PhoneNumber: patient.Phone,
  386. }
  387. service.UpdateHisPatientStatusTwo(&his)
  388. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, recordDateTime, org_id)
  389. tm := time.Unix(time.Now().Unix(), 0)
  390. order := &models.HisOrder{
  391. PsnNo: his.PsnNo,
  392. UserOrgId: org_id,
  393. HisPatientId: his.ID,
  394. PatientId: patient_id,
  395. SettleAccountsDate: recordDateTime,
  396. Ctime: time.Now().Unix(),
  397. Mtime: time.Now().Unix(),
  398. Status: 1,
  399. OrderStatus: 1,
  400. MdtrtId: his.Number,
  401. Number: ipt_otp_no,
  402. SetlId: "",
  403. MedfeeSumamt: total,
  404. MedType: strconv.Itoa(int(reg_type)),
  405. SettleEndTime: 0,
  406. SettleStartTime: 0,
  407. SettleType: settle_accounts_type,
  408. Diagnosis: diagnosis_id,
  409. PType: 2,
  410. SetlTime: tm.Format("2006-01-02 15:04:05"),
  411. }
  412. err = service.CreateOrder(order)
  413. if err != nil {
  414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  415. return
  416. }
  417. for _, item := range customs {
  418. var advice_id int64 = 0
  419. var project_id int64 = 0
  420. var item_id int64 = 0
  421. var types int64 = 0
  422. if item.Type == 1 {
  423. advice_id = item.AdviceId
  424. project_id = 0
  425. item_id = 0
  426. } else if item.Type == 2 {
  427. advice_id = 0
  428. item_id = 0
  429. project_id = item.ProjectId
  430. } else if item.Type == 3 {
  431. advice_id = 0
  432. item_id = item.ItemId
  433. project_id = 0
  434. }
  435. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  436. cut, _ := strconv.ParseFloat(item.Cut, 32)
  437. pric, _ := strconv.ParseFloat(item.Price, 32)
  438. info := &models.HisOrderInfo{
  439. OrderNumber: order.Number,
  440. UploadDate: time.Now().Unix(),
  441. AdviceId: advice_id,
  442. DetItemFeeSumamt: detItemFeeSumamt,
  443. Cnt: cut,
  444. Pric: pric,
  445. PatientId: patient_id,
  446. Status: 1,
  447. Mtime: time.Now().Unix(),
  448. Ctime: time.Now().Unix(),
  449. UserOrgId: org_id,
  450. HisPatientId: his.ID,
  451. OrderId: order.ID,
  452. ProjectId: project_id,
  453. Type: types,
  454. ItemId: item_id,
  455. }
  456. service.CreateOrderInfo(info)
  457. }
  458. his.Diagnosis = diagnosis_id
  459. his.SickType = sick_type
  460. his.RegisterType = reg_type
  461. his.MedicalTreatmentType = reg_type
  462. service.UpdataHisPateintTwoTen(&his)
  463. err = service.UpDatePrescriptionNumber(org_id, ids, order.Number)
  464. err = service.UpDateHisPrescriptionInfoNumberTen(org_id, patient_id, order.Number, recordDateTime, his.ID)
  465. err = service.UpdataOrderStatusThreeTen(strconv.FormatInt(int64(chrgBchno), 10), org_id)
  466. c.ServeSuccessJSON(map[string]interface{}{
  467. "msg": "医嘱保存成功",
  468. })
  469. } else {
  470. c.ServeSuccessJSON(map[string]interface{}{
  471. "failed_code": -10,
  472. "msg": res2.Msg + "----" + res2.Result[0].ResultMsg,
  473. })
  474. }
  475. } else {
  476. c.ServeSuccessJSON(map[string]interface{}{
  477. "failed_code": -10,
  478. "msg": res.Msg,
  479. })
  480. }
  481. }
  482. type Charset string
  483. const (
  484. UTF8 = Charset("UTF-8")
  485. GB18030 = Charset("GB18030")
  486. )
  487. func saveLog(result string, request string, infno string, desc string, org_name string) {
  488. //org_id, _ := beego.AppConfig.Int64("org_id")
  489. //miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  490. dir := org_name + "日志"
  491. utils.Mkdir(dir)
  492. month := time.Unix(1557042972, 0).Format("1")
  493. year := time.Now().Format("2006")
  494. month = time.Now().Format("01")
  495. day := time.Now().Format("02")
  496. hour := time.Now().Format("15")
  497. min := time.Now().Format("04")
  498. sec := time.Now().Format("05")
  499. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  500. file := org_name + "_" + year + month + day + "_log"
  501. file_name := file + ".txt"
  502. file_path := org_name + "日志" + "/" + file_name
  503. exist, _ := utils.PathExists(file_path)
  504. if exist { //存在
  505. fmt.Println("存在")
  506. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  507. if err != nil {
  508. fmt.Println("read fail")
  509. }
  510. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  511. n, _ := f.Seek(0, 2)
  512. _, err = f.WriteAt([]byte(content), n)
  513. } else { //不存在
  514. fmt.Println("文件不存在,创建文件")
  515. f, err := os.Create(org_name + "日志" + "/" + file_name)
  516. defer f.Close()
  517. if err != nil {
  518. } else {
  519. _, err = f.Write([]byte("记录日志"))
  520. }
  521. }
  522. }