coordinate_controller.go 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  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 int64 `json:"vaa01"`
  41. Vaa07 int64 `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. for index, item := range prescriptions {
  209. var presDetails []*models.PresDetail
  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 = ""
  220. } else {
  221. presInfo.Cbm07 = ""
  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.StartTime, 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.Vaf18 = fmt.Sprintf("%.2f", subItem.SingleDose)
  241. infoItem.Vaf20 = fmt.Sprintf("%.2f", subItem.SingleDose)
  242. infoItem.Vaf21 = fmt.Sprintf("%.2f", subItem.PrescribingNumber)
  243. infoItem.Vaf35 = "0"
  244. infoItem.Vaf32 = "0"
  245. infoItem.Bck01b = departmwnt.Number
  246. infoItem.Bck01d = departmwnt.Number
  247. infoItem.Vaf58 = "0"
  248. infoItem.Vaf61 = "1"
  249. infoItems = append(infoItems, &infoItem)
  250. }
  251. for _, subItem := range item.HisPrescriptionProject {
  252. //ef, _ := service.GetExecutionFrequencyByName(subItem.ExecutionFrequency, subItem.UserOrgId)
  253. if subItem.Type == 2 {
  254. fmt.Println(subItem.HisProject.CostClassify)
  255. if subItem.HisProject.CostClassify == 100 {
  256. var infoItem models.Item
  257. infoItem.Rownr = "0"
  258. infoItem.Vaf11 = "2"
  259. infoItem.Vaf36 = time.Unix(subItem.Ctime, 0).Format("2006-01-02 15:04:05")
  260. infoItem.Bbx01 = subItem.HisProject.MedicalCode
  261. infoItem.Bda01 = "Z"
  262. infoItem.Bby01 = ""
  263. infoItem.Vaf14 = subItem.HisProject.ProjectName
  264. infoItem.Vaf15 = subItem.HisProject.ProjectName
  265. infoItem.Bdi01 = "160"
  266. infoItem.Vaf17 = "1"
  267. infoItem.Vaf20 = subItem.SingleDose
  268. infoItem.Vaf21 = subItem.Count
  269. infoItem.Vaf35 = "0"
  270. infoItem.Vaf18 = ""
  271. infoItem.Vaf32 = "1"
  272. infoItem.Bck01b = departmwnt.Number
  273. infoItem.Bck01d = departmwnt.Number
  274. infoItem.Vaf58 = "0"
  275. infoItem.Vaf61 = "1"
  276. infoItems = append(infoItems, &infoItem)
  277. } else {
  278. var infoItem models.Item
  279. infoItem.Rownr = "0"
  280. infoItem.Vaf11 = "1"
  281. infoItem.Vaf36 = time.Unix(subItem.Ctime, 0).Format("2006-01-02 15:04:05")
  282. infoItem.Bbx01 = subItem.HisProject.MedicalCode
  283. if subItem.HisProject.CostClassify == 2 {
  284. infoItem.Bda01 = "T"
  285. } else if subItem.HisProject.CostClassify == 3 {
  286. infoItem.Bda01 = "L"
  287. } else {
  288. infoItem.Bda01 = "T"
  289. }
  290. infoItem.Bby01 = ""
  291. infoItem.Vaf14 = subItem.HisProject.ProjectName
  292. infoItem.Bdi01 = "160"
  293. infoItem.Vaf17 = subItem.Day
  294. infoItem.Vaf20 = subItem.SingleDose
  295. infoItem.Vaf21 = subItem.Count
  296. infoItem.Vaf35 = "0"
  297. infoItem.Vaf18 = fmt.Sprintf("%.2f", subItem.SingleDose)
  298. infoItem.Vaf32 = "0"
  299. infoItem.Bck01b = departmwnt.Number
  300. infoItem.Bck01d = departmwnt.Number
  301. infoItem.Vaf58 = "0"
  302. infoItem.Vaf61 = "1"
  303. infoItems = append(infoItems, &infoItem)
  304. }
  305. } else {
  306. var infoItem models.Item
  307. infoItem.Rownr = "0"
  308. infoItem.Vaf11 = "1"
  309. infoItem.Vaf36 = time.Unix(subItem.Ctime, 0).Format("2006-01-02 15:04:05")
  310. infoItem.Bbx01 = subItem.GoodInfo.MedicalInsuranceNumber
  311. infoItem.Bda01 = "M"
  312. infoItem.Bby01 = ""
  313. infoItem.Vaf14 = subItem.GoodInfo.GoodName + " " + subItem.GoodInfo.SpecificationName
  314. infoItem.Bdi01 = "160"
  315. infoItem.Vaf17 = subItem.Day
  316. infoItem.Vaf20 = subItem.SingleDose
  317. infoItem.Vaf21 = subItem.Count
  318. infoItem.Vaf35 = "0"
  319. infoItem.Vaf32 = "0"
  320. infoItem.Bck01b = departmwnt.Number
  321. infoItem.Bck01d = departmwnt.Number
  322. infoItem.Vaf58 = "0"
  323. infoItem.Vaf61 = "1"
  324. infoItems = append(infoItems, &infoItem)
  325. }
  326. }
  327. presDetail.Item = infoItems
  328. presDetails = append(presDetails, &presDetail)
  329. presInfo.PresDetail = presDetails
  330. presInfos = append(presInfos, &presInfo)
  331. }
  332. info.PresInfo = presInfos
  333. var result2 string
  334. var request2 string
  335. if res.Result[0].Type == "1" {
  336. result2, request2 = service.UploadPrescriptionForCoordinate(info)
  337. } else {
  338. result2, request2 = service.UploadPrescriptionForCoordinateHospital(info)
  339. }
  340. saveLog(result2, request2, "上传明细", "上传明细", org.OrgName)
  341. var res2 ResultUpload
  342. if err := json.Unmarshal([]byte(result2), &res2); err != nil {
  343. utils.ErrorLog("解析失败:%v", err)
  344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  345. return
  346. }
  347. if res2.Code == "10000" && len(res2.Result) > 0 && res2.Result[0].Code != "500" && len(res2.Result[0].List) > 0 {
  348. timestamp := time.Now().Unix()
  349. tempTime := time.Unix(timestamp, 0)
  350. timeFormat := tempTime.Format("20060102150405")
  351. chrgBchno := rand.Intn(100000) + 10000
  352. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(patient.ID, 10)
  353. his := models.VMHisPatient{
  354. Name: patient.Name,
  355. Gender: patient.Gender,
  356. Birthday: patient.Birthday,
  357. MedicalTreatmentType: 0,
  358. IdType: 1,
  359. IdCardNo: patient.IdCardNo,
  360. BalanceAccountsType: 1,
  361. MedicalInsuranceNumber: "",
  362. RegisterType: 0,
  363. RegisterCost: 0,
  364. TreatmentCost: 0,
  365. Status: 1,
  366. Ctime: time.Now().Unix(),
  367. Mtime: time.Now().Unix(),
  368. PsnNo: strconv.FormatInt(int64(res.Result[0].Vaa01), 10),
  369. PsnCertType: "",
  370. Certno: patient.IdCardNo,
  371. PsnName: patient.Name,
  372. Gend: "",
  373. Naty: "",
  374. Brdy: "",
  375. Age: 0,
  376. Iinfo: "",
  377. Idetinfo: "",
  378. PatientId: patient.ID,
  379. RecordDate: theTime.Unix(),
  380. UserOrgId: org_id,
  381. AdminUserId: admin_user_id,
  382. IsReturn: 1,
  383. Doctor: patientPrescription.DoctorId,
  384. Departments: patientPrescription.Departments,
  385. IptOtpNo: ipt_otp_no,
  386. Number: strconv.FormatInt(int64(res.Result[0].Vaa07), 10),
  387. PhoneNumber: patient.Phone,
  388. }
  389. service.UpdateHisPatientStatusTwo(&his)
  390. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, recordDateTime, org_id)
  391. tm := time.Unix(time.Now().Unix(), 0)
  392. order := &models.HisOrder{
  393. PsnNo: his.PsnNo,
  394. UserOrgId: org_id,
  395. HisPatientId: his.ID,
  396. PatientId: patient_id,
  397. SettleAccountsDate: recordDateTime,
  398. Ctime: time.Now().Unix(),
  399. Mtime: time.Now().Unix(),
  400. Status: 1,
  401. OrderStatus: 1,
  402. MdtrtId: his.Number,
  403. Number: ipt_otp_no,
  404. SetlId: "",
  405. MedfeeSumamt: total,
  406. MedType: strconv.Itoa(int(reg_type)),
  407. SettleEndTime: 0,
  408. SettleStartTime: 0,
  409. SettleType: settle_accounts_type,
  410. Diagnosis: diagnosis_id,
  411. PType: 2,
  412. SetlTime: tm.Format("2006-01-02 15:04:05"),
  413. }
  414. err = service.CreateOrder(order)
  415. if err != nil {
  416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderExceptionT)
  417. return
  418. }
  419. for _, item := range customs {
  420. var advice_id int64 = 0
  421. var project_id int64 = 0
  422. var item_id int64 = 0
  423. var types int64 = 0
  424. if item.Type == 1 {
  425. advice_id = item.AdviceId
  426. project_id = 0
  427. item_id = 0
  428. } else if item.Type == 2 {
  429. advice_id = 0
  430. item_id = 0
  431. project_id = item.ProjectId
  432. } else if item.Type == 3 {
  433. advice_id = 0
  434. item_id = item.ItemId
  435. project_id = 0
  436. }
  437. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  438. cut, _ := strconv.ParseFloat(item.Cut, 32)
  439. pric, _ := strconv.ParseFloat(item.Price, 32)
  440. info := &models.HisOrderInfo{
  441. OrderNumber: order.Number,
  442. UploadDate: time.Now().Unix(),
  443. AdviceId: advice_id,
  444. DetItemFeeSumamt: detItemFeeSumamt,
  445. Cnt: cut,
  446. Pric: pric,
  447. PatientId: patient_id,
  448. Status: 1,
  449. Mtime: time.Now().Unix(),
  450. Ctime: time.Now().Unix(),
  451. UserOrgId: org_id,
  452. HisPatientId: his.ID,
  453. OrderId: order.ID,
  454. ProjectId: project_id,
  455. Type: types,
  456. ItemId: item_id,
  457. }
  458. service.CreateOrderInfo(info)
  459. }
  460. his.Diagnosis = diagnosis_id
  461. his.SickType = sick_type
  462. his.RegisterType = reg_type
  463. his.MedicalTreatmentType = reg_type
  464. service.UpdataHisPateintTwoTen(&his)
  465. err = service.UpDatePrescriptionNumber(org_id, ids, order.Number)
  466. err = service.UpDateHisPrescriptionInfoNumberTen(org_id, patient_id, order.Number, recordDateTime, his.ID)
  467. err = service.UpdataOrderStatusThreeTen(strconv.FormatInt(int64(chrgBchno), 10), org_id)
  468. c.ServeSuccessJSON(map[string]interface{}{
  469. "msg": "医嘱保存成功",
  470. })
  471. } else {
  472. c.ServeSuccessJSON(map[string]interface{}{
  473. "failed_code": -10,
  474. "msg": res2.Msg + "----" + res2.Result[0].ResultMsg,
  475. })
  476. }
  477. } else {
  478. c.ServeSuccessJSON(map[string]interface{}{
  479. "failed_code": -10,
  480. "msg": res.Msg,
  481. })
  482. }
  483. }
  484. type Charset string
  485. const (
  486. UTF8 = Charset("UTF-8")
  487. GB18030 = Charset("GB18030")
  488. )
  489. func saveLog(result string, request string, infno string, desc string, org_name string) {
  490. //org_id, _ := beego.AppConfig.Int64("org_id")
  491. //miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  492. dir := org_name + "日志"
  493. utils.Mkdir(dir)
  494. month := time.Unix(1557042972, 0).Format("1")
  495. year := time.Now().Format("2006")
  496. month = time.Now().Format("01")
  497. day := time.Now().Format("02")
  498. hour := time.Now().Format("15")
  499. min := time.Now().Format("04")
  500. sec := time.Now().Format("05")
  501. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  502. file := org_name + "_" + year + month + day + "_log"
  503. file_name := file + ".txt"
  504. file_path := org_name + "日志" + "/" + file_name
  505. exist, _ := utils.PathExists(file_path)
  506. if exist { //存在
  507. fmt.Println("存在")
  508. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  509. if err != nil {
  510. fmt.Println("read fail")
  511. }
  512. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  513. n, _ := f.Seek(0, 2)
  514. _, err = f.WriteAt([]byte(content), n)
  515. } else { //不存在
  516. fmt.Println("文件不存在,创建文件")
  517. f, err := os.Create(org_name + "日志" + "/" + file_name)
  518. defer f.Close()
  519. if err != nil {
  520. } else {
  521. _, err = f.Write([]byte("记录日志"))
  522. }
  523. }
  524. }