coordinate_controller.go 37KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "io/ioutil"
  11. "math/rand"
  12. "os"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. type CoordinateController struct {
  18. BaseAPIController
  19. }
  20. type ResultReg struct {
  21. ResultCode string `json:"resultCode"`
  22. ResultDesc string `json:"resultDesc"`
  23. InfoSeq string `json:"infoSeq"`
  24. }
  25. type ResultSettle struct {
  26. ResultCode string `json:"resultCode"`
  27. ResultDesc string `json:"resultDesc"`
  28. }
  29. type ResultCancelSettle struct {
  30. ResultCode string `json:"resultCode"`
  31. ResultDesc string `json:"resultDesc"`
  32. }
  33. type Settle struct {
  34. PatientId string `json:"resultCode"`
  35. DocId string `json:"docId"`
  36. InfoSeq string `json:"infoSeq"`
  37. }
  38. type Refund struct {
  39. PatientId string `json:"resultCode"`
  40. DocId string `json:"docId"`
  41. InfoSeq string `json:"infoSeq"`
  42. }
  43. type RefundDetail struct {
  44. Msg string `json:"msg"`
  45. Result []struct {
  46. ResultMsg string `json:"resultMsg"`
  47. Code string `json:"code"`
  48. Records int `json:"records"`
  49. TotalPage int `json:"totalPage"`
  50. List []struct {
  51. Zae01 int64 `json:"ZAE01"`
  52. } `json:"list"`
  53. RecordsTotal int `json:"recordsTotal"`
  54. Pagenumber int `json:"pagenumber"`
  55. Result string `json:"result"`
  56. Total int `json:"total"`
  57. RecordsFtered int `json:"recordsFtered"`
  58. Page int `json:"page"`
  59. } `json:"result"`
  60. Code string `json:"code"`
  61. }
  62. type ResultQuery struct {
  63. Msg string `json:"msg"`
  64. Result []struct {
  65. Type string `json:"type"`
  66. Name string `json:"name"`
  67. Vaa01 int `json:"vaa01"`
  68. Vaa07 int `json:"vaa07"`
  69. Visittime string `json:"visittime"`
  70. } `json:"result"`
  71. Code string `json:"code"`
  72. }
  73. type ResultUpload struct {
  74. Code string `json:"code"`
  75. Msg string `json:"msg"`
  76. Result []struct {
  77. List []interface{} `json:"list"`
  78. Page int64 `json:"page"`
  79. Pagenumber int64 `json:"pagenumber"`
  80. Records int64 `json:"records"`
  81. RecordsFiltered int64 `json:"recordsFiltered"`
  82. RecordsTotal int64 `json:"recordsTotal"`
  83. Result string `json:"result"`
  84. ResultMsg string `json:"resultMsg"`
  85. Total int64 `json:"total"`
  86. TotalPage int64 `json:"totalPage"`
  87. Userdata string `json:"userdata"`
  88. } `json:"result"`
  89. }
  90. func CoordinateRcegistRouters() {
  91. beego.Router("/coordinate/check", &CoordinateController{}, "get:SavePatientMessageInfo")
  92. //坐标挂号
  93. beego.Router("/coordinate/register", &CoordinateController{}, "get:Register")
  94. //坐标记账
  95. beego.Router("/coordinate/opKeepAccounts", &CoordinateController{}, "get:OpKeepAccounts")
  96. //坐标撤销记账
  97. beego.Router("/coordinate/opCancelKeepAccounts", &CoordinateController{}, "get:OpCancelKeepAccounts")
  98. //坐标结算回调
  99. beego.Router("/coordinate/settle", &CoordinateController{}, "post:Settle")
  100. //坐标退费回调
  101. beego.Router("/coordinate/refund", &CoordinateController{}, "post:Refund")
  102. //坐标患者查询~上传医嘱~结算功能
  103. beego.Router("/coordinate/settleAccount", &CoordinateController{}, "get:SettleAccount")
  104. }
  105. func (c *CoordinateController) SettleAccount() {
  106. patient_id, _ := c.GetInt64("patient_id")
  107. record_date := c.GetString("record_date")
  108. admin_user_id, _ := c.GetInt64("admin_user_id")
  109. diagnosis_id := c.GetString("diagnosis")
  110. sick_type, _ := c.GetInt64("sick_type")
  111. reg_type, _ := c.GetInt64("p_type")
  112. org_id, _ := c.GetInt64("org_id")
  113. org_id = 3877
  114. org, _ := service.GetOrgById(org_id)
  115. patient, _ := service.GetPatientByID(org.Id, patient_id)
  116. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  117. result, request := service.GetHisPatientForCoordinate(patient.IdCardNo)
  118. saveLog(result, request, "查询", "查询", org.OrgName)
  119. var res ResultQuery
  120. if err := json.Unmarshal([]byte(result), &res); err != nil {
  121. utils.ErrorLog("解析失败:%v", err)
  122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  123. return
  124. }
  125. if res.Code == "10000" {
  126. if len(res.Result) == 0 {
  127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientNoRegException)
  128. return
  129. }
  130. timeLayout := "2006-01-02"
  131. loc, _ := time.LoadLocation("Local")
  132. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  133. if err != nil {
  134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  135. return
  136. }
  137. org_id := org.Id
  138. recordDateTime := theTime.Unix()
  139. patientPrescription, _ := service.FindPatientPrescriptionInfoTwo(org_id, patient.ID, recordDateTime, 2)
  140. if patientPrescription.ID == 0 {
  141. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(org_id, patient.ID, recordDateTime)
  142. }
  143. departmwnt, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  144. doctor_info, _ := service.GetAdminUserInfoByID(org_id, patientPrescription.DoctorId)
  145. //admin_user_info, _ := service.GetAdminUserInfoByID(org_id, admin_user_id)
  146. var prescriptions []*models.HisPrescription
  147. if settle_accounts_type == 1 { //日结
  148. prescriptions, _ = service.GetUnSettleHisPrescriptionFive(org_id, patient_id, recordDateTime, 2)
  149. } else { //月结
  150. start_time_str := c.GetString("start_time")
  151. end_time_str := c.GetString("end_time")
  152. timeLayout := "2006-01-02"
  153. loc, _ := time.LoadLocation("Local")
  154. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  155. if err != nil {
  156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  157. return
  158. }
  159. recordStartTime := theStartTime.Unix()
  160. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  161. if err != nil {
  162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  163. return
  164. }
  165. recordEndTime := theEndTime.Unix()
  166. prescriptions, _ = service.GetUnSettleMonthHisPrescription(org_id, patient_id, recordStartTime, recordEndTime)
  167. }
  168. var total float64
  169. for _, item := range prescriptions {
  170. fmt.Println(item)
  171. if item.Type == 1 { //药品
  172. for _, subItem := range item.HisDoctorAdviceInfo {
  173. total = total + (subItem.Price * subItem.PrescribingNumber)
  174. }
  175. }
  176. if item.Type == 2 { //项目
  177. for _, subItem := range item.HisPrescriptionProject {
  178. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  179. total = total + (subItem.Price * cnt)
  180. }
  181. }
  182. }
  183. var ids []int64
  184. for _, item := range prescriptions {
  185. ids = append(ids, item.ID)
  186. }
  187. var customs []*models.NewCustomTwo
  188. for _, item := range prescriptions {
  189. if item.Type == 1 { //药品
  190. for _, subItem := range item.HisDoctorAdviceInfo {
  191. cus := &models.NewCustomTwo{
  192. AdviceId: subItem.ID,
  193. ProjectId: 0,
  194. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  195. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  196. FeedetlSn: subItem.FeedetlSn,
  197. Price: fmt.Sprintf("%.2f", subItem.Price),
  198. MedListCodg: subItem.Drug.MedicalInsuranceNumber,
  199. Type: 1,
  200. }
  201. customs = append(customs, cus)
  202. }
  203. }
  204. if item.Type == 2 { //项目
  205. for _, subItem := range item.HisPrescriptionProject {
  206. if subItem.Type == 2 {
  207. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  208. cus := &models.NewCustomTwo{
  209. AdviceId: 0,
  210. ProjectId: subItem.ID,
  211. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  212. Cut: fmt.Sprintf("%.4f", cnt),
  213. FeedetlSn: subItem.FeedetlSn,
  214. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  215. MedListCodg: subItem.HisProject.MedicalCode,
  216. Type: 2,
  217. }
  218. customs = append(customs, cus)
  219. } else {
  220. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  221. cus := &models.NewCustomTwo{
  222. AdviceId: 0,
  223. ProjectId: subItem.ID,
  224. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  225. Cut: fmt.Sprintf("%.4f", cnt),
  226. FeedetlSn: subItem.FeedetlSn,
  227. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  228. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  229. Type: 3,
  230. }
  231. customs = append(customs, cus)
  232. }
  233. }
  234. }
  235. }
  236. var info models.UploadInfo
  237. info.Vaa01 = res.Result[0].Vaa01
  238. info.Fasong = "1"
  239. info.Vaa07 = res.Result[0].Vaa07
  240. info.Bck01c = departmwnt.Number
  241. info.Bce02a = doctor_info.DoctorNumber
  242. diagnosis_ids := strings.Split(patientPrescription.Diagnosis, ",")
  243. var config []*models.HisXtDiagnoseConfig
  244. for _, item := range diagnosis_ids {
  245. id, _ := strconv.ParseInt(item, 10, 64)
  246. diagnosisConfig, _ := service.FindDiagnoseById(id)
  247. config = append(config, diagnosisConfig)
  248. }
  249. for index, item := range config {
  250. var diag models.Diag
  251. diag.Vao06 = strconv.FormatInt(int64(index+1), 10)
  252. diag.Bak02 = item.CountryCode
  253. info.Diag = append(info.Diag, &diag)
  254. }
  255. var presInfos []*models.PresInfo
  256. var presDetails []*models.PresDetail
  257. for index, item := range prescriptions {
  258. var presDetail models.PresDetail
  259. var presInfo models.PresInfo
  260. presInfo.Cbmid = strconv.FormatInt(item.ID, 10)
  261. if item.Type == 1 {
  262. presInfo.Cbm06 = "0"
  263. } else {
  264. presInfo.Cbm06 = "5"
  265. }
  266. if item.Type == 1 {
  267. presInfo.Cbm07 = item.MedType
  268. } else {
  269. presInfo.Cbm07 = item.MedType
  270. }
  271. presDetail.Vaf59 = strconv.FormatInt(int64(index+1), 10)
  272. var infoItems []*models.Item
  273. for _, subItem := range item.HisDoctorAdviceInfo {
  274. ef, _ := service.GetExecutionFrequencyByName(subItem.ExecutionFrequency, subItem.UserOrgId)
  275. var infoItem models.Item
  276. infoItem.Rownr = "0"
  277. infoItem.Vaf11 = "1"
  278. infoItem.Vaf36 = time.Unix(subItem.ExecutionTime, 0).Format("2006-01-02 15:04:05")
  279. infoItem.Bbx01 = subItem.Drug.MedicalInsuranceNumber
  280. infoItem.Bda01 = "1"
  281. infoItem.Bby01 = ""
  282. if subItem.Drug.MinUnit != subItem.Drug.DoseUnit {
  283. infoItem.Vaf22 = subItem.Drug.DrugName + " " + subItem.Drug.Dose + subItem.Drug.DoseUnit + "*" + strconv.FormatInt(subItem.Drug.MinNumber, 10) + subItem.Drug.MinUnit + "/" + subItem.Drug.MaxUnit
  284. }
  285. infoItem.Vaf14 = subItem.Drug.DrugName
  286. infoItem.Bdi01 = ef.Code
  287. infoItem.Vaf17 = strconv.FormatInt(subItem.Day, 10)
  288. infoItem.Vaf20 = fmt.Sprintf("%.2f", subItem.SingleDose)
  289. infoItem.Vaf21 = fmt.Sprintf("%.2f", subItem.PrescribingNumber)
  290. infoItem.Vaf35 = "0"
  291. infoItem.Vaf32 = "0"
  292. infoItem.Bck01b = departmwnt.Number
  293. infoItem.Bck01d = departmwnt.Number
  294. infoItem.Vaf58 = "0"
  295. infoItem.Vaf61 = "1"
  296. infoItems = append(infoItems, &infoItem)
  297. }
  298. for _, subItem := range item.HisPrescriptionProject {
  299. ef, _ := service.GetExecutionFrequencyByName(subItem.ExecutionFrequency, subItem.UserOrgId)
  300. if subItem.Type == 2 {
  301. var infoItem models.Item
  302. infoItem.Rownr = "0"
  303. infoItem.Vaf11 = "1"
  304. infoItem.Vaf36 = time.Unix(subItem.ExecutionTime, 0).Format("2006-01-02 15:04:05")
  305. infoItem.Bbx01 = subItem.HisProject.MedicalCode
  306. if subItem.HisProject.CostClassify == 2 {
  307. infoItem.Bda01 = "T"
  308. } else if subItem.HisProject.CostClassify == 3 {
  309. infoItem.Bda01 = "L"
  310. } else {
  311. infoItem.Bda01 = "T"
  312. }
  313. infoItem.Bby01 = ""
  314. infoItem.Vaf22 = subItem.HisProject.ProjectName
  315. infoItem.Bdi01 = ef.Code
  316. infoItem.Vaf17 = subItem.Day
  317. infoItem.Vaf20 = fmt.Sprintf("%.2f", subItem.SingleDose)
  318. infoItem.Vaf21 = fmt.Sprintf("%.2f", subItem.Count)
  319. infoItem.Vaf35 = "0"
  320. infoItem.Vaf18 = 0
  321. infoItem.Vaf32 = "0"
  322. infoItem.Bck01b = departmwnt.Number
  323. infoItem.Bck01d = departmwnt.Number
  324. infoItem.Vaf58 = "0"
  325. infoItem.Vaf61 = "1"
  326. infoItems = append(infoItems, &infoItem)
  327. } else {
  328. var infoItem models.Item
  329. infoItem.Rownr = "0"
  330. infoItem.Vaf11 = "1"
  331. infoItem.Vaf36 = time.Unix(subItem.ExecutionTime, 0).Format("2006-01-02 15:04:05")
  332. infoItem.Bbx01 = subItem.GoodInfo.MedicalInsuranceNumber
  333. infoItem.Bda01 = "M"
  334. infoItem.Bby01 = ""
  335. infoItem.Vaf22 = subItem.GoodInfo.GoodName + " " + subItem.GoodInfo.SpecificationName
  336. infoItem.Bdi01 = ef.Code
  337. infoItem.Vaf17 = subItem.Day
  338. infoItem.Vaf20 = fmt.Sprintf("%.2f", subItem.SingleDose)
  339. infoItem.Vaf21 = fmt.Sprintf("%.2f", subItem.Count)
  340. infoItem.Vaf35 = "0"
  341. infoItem.Vaf32 = "0"
  342. infoItem.Bck01b = departmwnt.Number
  343. infoItem.Bck01d = departmwnt.Number
  344. infoItem.Vaf58 = "0"
  345. infoItem.Vaf61 = "1"
  346. infoItems = append(infoItems, &infoItem)
  347. }
  348. }
  349. presDetail.Item = infoItems
  350. presDetails = append(presDetails, &presDetail)
  351. presInfo.PresDetail = presDetails
  352. presInfos = append(presInfos, &presInfo)
  353. }
  354. info.PresInfo = presInfos
  355. result2, request2 := service.UploadPrescriptionForCoordinate(info)
  356. saveLog(result2, request2, "上传明细", "上传明细", org.OrgName)
  357. var res2 ResultUpload
  358. if err := json.Unmarshal([]byte(result2), &res2); err != nil {
  359. utils.ErrorLog("解析失败:%v", err)
  360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  361. return
  362. }
  363. if res2.Code == "10000" {
  364. timestamp := time.Now().Unix()
  365. tempTime := time.Unix(timestamp, 0)
  366. timeFormat := tempTime.Format("20060102150405")
  367. chrgBchno := rand.Intn(100000) + 10000
  368. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(patient.ID, 10)
  369. his := models.VMHisPatient{
  370. Name: patient.Name,
  371. Gender: patient.Gender,
  372. Birthday: patient.Birthday,
  373. MedicalTreatmentType: 0,
  374. IdType: 1,
  375. IdCardNo: patient.IdCardNo,
  376. BalanceAccountsType: 1,
  377. MedicalInsuranceNumber: "",
  378. RegisterType: 0,
  379. RegisterCost: 0,
  380. TreatmentCost: 0,
  381. Status: 1,
  382. Ctime: time.Now().Unix(),
  383. Mtime: time.Now().Unix(),
  384. PsnNo: strconv.FormatInt(int64(res.Result[0].Vaa01), 10),
  385. PsnCertType: "",
  386. Certno: patient.IdCardNo,
  387. PsnName: patient.Name,
  388. Gend: "",
  389. Naty: "",
  390. Brdy: "",
  391. Age: 0,
  392. Iinfo: "",
  393. Idetinfo: "",
  394. PatientId: patient.ID,
  395. RecordDate: theTime.Unix(),
  396. UserOrgId: org_id,
  397. AdminUserId: admin_user_id,
  398. IsReturn: 1,
  399. Doctor: patientPrescription.DoctorId,
  400. Departments: patientPrescription.Departments,
  401. IptOtpNo: ipt_otp_no,
  402. Number: strconv.FormatInt(int64(res.Result[0].Vaa07), 10),
  403. PhoneNumber: patient.Phone,
  404. }
  405. service.UpdateHisPatientStatus(&his)
  406. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, recordDateTime, org_id)
  407. tm := time.Unix(time.Now().Unix(), 0)
  408. order := &models.HisOrder{
  409. PsnNo: his.PsnNo,
  410. UserOrgId: org_id,
  411. HisPatientId: his.ID,
  412. PatientId: patient_id,
  413. SettleAccountsDate: recordDateTime,
  414. Ctime: time.Now().Unix(),
  415. Mtime: time.Now().Unix(),
  416. Status: 1,
  417. OrderStatus: 1,
  418. MdtrtId: his.Number,
  419. Number: ipt_otp_no,
  420. SetlId: "",
  421. MedfeeSumamt: total,
  422. MedType: strconv.Itoa(int(reg_type)),
  423. SettleEndTime: 0,
  424. SettleStartTime: 0,
  425. SettleType: settle_accounts_type,
  426. Diagnosis: diagnosis_id,
  427. PType: 2,
  428. SetlTime: tm.Format("2006-01-02 15:04:05"),
  429. }
  430. err = service.CreateOrder(order)
  431. if err != nil {
  432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  433. return
  434. }
  435. for _, item := range customs {
  436. var advice_id int64 = 0
  437. var project_id int64 = 0
  438. var item_id int64 = 0
  439. var types int64 = 0
  440. if item.Type == 1 {
  441. advice_id = item.AdviceId
  442. project_id = 0
  443. item_id = 0
  444. } else if item.Type == 2 {
  445. advice_id = 0
  446. item_id = 0
  447. project_id = item.ProjectId
  448. } else if item.Type == 3 {
  449. advice_id = 0
  450. item_id = item.ItemId
  451. project_id = 0
  452. }
  453. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  454. cut, _ := strconv.ParseFloat(item.Cut, 32)
  455. pric, _ := strconv.ParseFloat(item.Price, 32)
  456. info := &models.HisOrderInfo{
  457. OrderNumber: order.Number,
  458. UploadDate: time.Now().Unix(),
  459. AdviceId: advice_id,
  460. DetItemFeeSumamt: detItemFeeSumamt,
  461. Cnt: cut,
  462. Pric: pric,
  463. PatientId: patient_id,
  464. Status: 1,
  465. Mtime: time.Now().Unix(),
  466. Ctime: time.Now().Unix(),
  467. UserOrgId: org_id,
  468. HisPatientId: his.ID,
  469. OrderId: order.ID,
  470. ProjectId: project_id,
  471. Type: types,
  472. ItemId: item_id,
  473. }
  474. service.CreateOrderInfo(info)
  475. }
  476. his.Diagnosis = diagnosis_id
  477. his.SickType = sick_type
  478. his.RegisterType = reg_type
  479. his.MedicalTreatmentType = reg_type
  480. service.UpdataHisPateintTwo(&his)
  481. err = service.UpDatePrescriptionNumber(org_id, ids, strconv.FormatInt(int64(chrgBchno), 10))
  482. err = service.UpDateHisPrescriptionInfoNumber(org_id, patient_id, strconv.FormatInt(int64(chrgBchno), 10), recordDateTime, his.ID)
  483. err = service.UpdataOrderStatusThree(strconv.FormatInt(int64(chrgBchno), 10), org_id)
  484. c.ServeSuccessJSON(map[string]interface{}{
  485. "msg": "医嘱保存成功",
  486. })
  487. } else {
  488. c.ServeSuccessJSON(map[string]interface{}{
  489. "failed_code": -10,
  490. "msg": res.Msg,
  491. })
  492. }
  493. } else {
  494. c.ServeSuccessJSON(map[string]interface{}{
  495. "failed_code": -10,
  496. "msg": res.Msg,
  497. })
  498. }
  499. }
  500. func (c *CoordinateController) Settle() {
  501. //参数1 patient_id
  502. //参数2 就诊号
  503. //参数3 单据id
  504. fmt.Println(c.Ctx.Request.Body)
  505. body, _ := ioutil.ReadAll(c.Ctx.Request.Body)
  506. fmt.Println(string(body))
  507. var respJSON map[string]interface{}
  508. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  509. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  510. return
  511. }
  512. patien_id := respJSON["vaa01"].(float64)
  513. infoSeq := respJSON["vaa07"].(float64)
  514. //strconv.For(patien_id, 10)
  515. vaa001 := fmt.Sprintf("%f", patien_id)
  516. vaa007 := fmt.Sprintf("%f", infoSeq)
  517. setl_id := respJSON["setl_id"].(string)
  518. order, _ := service.GetHisOrderFour(vaa001, vaa007, "")
  519. order.SetlId = setl_id
  520. if order.ID == 0 {
  521. json := make(map[string]interface{})
  522. json["msg"] = "结算记录不存在,请检查参数是否正确"
  523. json["code"] = "-1"
  524. c.Data["json"] = json
  525. c.ServeJSON()
  526. return
  527. }
  528. order.OrderStatus = 2
  529. service.UpDateOrder(order)
  530. service.UpdataOrderStatusTwo(order.Number, order.UserOrgId)
  531. json := make(map[string]interface{})
  532. json["msg"] = "结算成功"
  533. json["code"] = "0"
  534. c.Data["json"] = json
  535. c.ServeJSON()
  536. return
  537. }
  538. func (c *CoordinateController) Refund() {
  539. //参数1 patient_id
  540. //参数2 就诊号
  541. //参数3 单据id
  542. body, _ := ioutil.ReadAll(c.Ctx.Request.Body)
  543. var respJSON map[string]interface{}
  544. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  545. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  546. return
  547. }
  548. patien_id := respJSON["vaa01"].(float64)
  549. infoSeq := respJSON["vaa07"].(float64)
  550. //strconv.For(patien_id, 10)
  551. vaa001 := fmt.Sprintf("%f", patien_id)
  552. vaa007 := fmt.Sprintf("%f", infoSeq)
  553. docId := respJSON["setl_id"].(string)
  554. order, _ := service.GetHisOrderFour(vaa001, vaa007, docId)
  555. if order.ID == 0 {
  556. json := make(map[string]interface{})
  557. json["msg"] = "结算记录不存在,请检查参数是否正确"
  558. json["code"] = "-1"
  559. c.Data["json"] = json
  560. c.ServeJSON()
  561. return
  562. }
  563. service.UpdataOrderStatus(order.ID, order.Number, order.UserOrgId)
  564. json := make(map[string]interface{})
  565. json["msg"] = "退费成功"
  566. json["code"] = "0"
  567. c.Data["json"] = json
  568. c.ServeJSON()
  569. return
  570. }
  571. func (c *CoordinateController) SavePatientMessageInfo() {
  572. result, request_log := service.SavePatientMessageInfo()
  573. fmt.Println(result)
  574. fmt.Println(request_log)
  575. }
  576. func (c *CoordinateController) Register() {
  577. patient_id, _ := c.GetInt64("patient_id")
  578. diagnosis_time := c.GetString("diagnosis_time")
  579. record_date := c.GetString("record_date")
  580. admin_user_id, _ := c.GetInt64("admin_user_id")
  581. org_id, _ := c.GetInt64("org_id")
  582. patient, _ := service.GetPatientByID(org_id, patient_id)
  583. org, _ := service.GetOrgById(org_id)
  584. timeLayout := "2006-01-02"
  585. loc, _ := time.LoadLocation("Local")
  586. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  587. if err != nil {
  588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  589. return
  590. }
  591. if len(patient.ZbPatientId) == 0 {
  592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnNoEmpty)
  593. return
  594. }
  595. recordDateTime := theTime.Unix()
  596. patientPrescription, _ := service.FindPatientPrescriptionInfoTwo(org_id, patient.ID, recordDateTime, 2)
  597. if patientPrescription.ID == 0 {
  598. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(org_id, patient.ID, recordDateTime)
  599. }
  600. doctor_info, _ := service.GetAdminUserInfoByID(org_id, patientPrescription.DoctorId)
  601. admin_user_info, _ := service.GetAdminUserInfoByID(org_id, admin_user_id)
  602. reg := models.Reg{
  603. DeptId: "0112",
  604. PatientId: patient.ZbPatientId,
  605. PatientName: patient.Name,
  606. DoctorId: doctor_info.DoctorNumber,
  607. RegDate: strings.Split(diagnosis_time, " ")[0],
  608. RegFee: "0",
  609. TreatFee: "0",
  610. OperatorId: admin_user_info.UserName,
  611. IdCardNo: patient.IdCardNo,
  612. }
  613. result, request_log := service.SaveReg(reg)
  614. fmt.Println(result)
  615. fmt.Println(request_log)
  616. saveLog(result, request_log, "登记", "登记", org.OrgName)
  617. var res ResultReg
  618. if err := json.Unmarshal([]byte(result), &res); err != nil {
  619. utils.ErrorLog("解析失败:%v", err)
  620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  621. return
  622. }
  623. if res.ResultCode == "0" {
  624. timestamp := time.Now().Unix()
  625. tempTime := time.Unix(timestamp, 0)
  626. timeFormat := tempTime.Format("20060102150405")
  627. chrgBchno := rand.Intn(100000) + 10000
  628. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(patient.ID, 10)
  629. his := models.VMHisPatient{
  630. Name: patient.Name,
  631. Gender: patient.Gender,
  632. Birthday: patient.Birthday,
  633. MedicalTreatmentType: 0,
  634. IdType: 1,
  635. IdCardNo: patient.IdCardNo,
  636. BalanceAccountsType: 1,
  637. MedicalInsuranceNumber: "",
  638. RegisterType: 0,
  639. RegisterCost: 0,
  640. TreatmentCost: 0,
  641. Status: 1,
  642. Ctime: time.Now().Unix(),
  643. Mtime: time.Now().Unix(),
  644. PsnNo: patient.ZbPatientId,
  645. PsnCertType: "",
  646. Certno: patient.IdCardNo,
  647. PsnName: patient.Name,
  648. Gend: "",
  649. Naty: "",
  650. Brdy: "",
  651. Age: 0,
  652. Iinfo: "",
  653. Idetinfo: "",
  654. PatientId: patient.ID,
  655. RecordDate: theTime.Unix(),
  656. UserOrgId: org_id,
  657. AdminUserId: admin_user_id,
  658. IsReturn: 1,
  659. Doctor: patientPrescription.DoctorId,
  660. Departments: patientPrescription.Departments,
  661. IptOtpNo: ipt_otp_no,
  662. Number: res.InfoSeq,
  663. PhoneNumber: patient.Phone,
  664. }
  665. service.UpdateHisPatientStatus(&his)
  666. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, recordDateTime, org_id)
  667. c.ServeSuccessJSON(map[string]interface{}{
  668. "his_info": his,
  669. })
  670. } else {
  671. c.ServeSuccessJSON(map[string]interface{}{
  672. "failed_code": -10,
  673. "msg": res.ResultDesc,
  674. })
  675. }
  676. }
  677. //func (c *CoordinateController) GetWaitPayDetail() {
  678. // result, request_log := service.GetWaitPayDetail()
  679. // fmt.Println(result)
  680. // fmt.Println(request_log)
  681. //
  682. //}
  683. func (c *CoordinateController) OpKeepAccounts() {
  684. id, _ := c.GetInt64("id")
  685. record_time := c.GetString("record_time")
  686. his_patient_id, _ := c.GetInt64("his_patient_id")
  687. timeLayout := "2006-01-02"
  688. loc, _ := time.LoadLocation("Local")
  689. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  690. fapiao_code := c.GetString("fapiao_code")
  691. fapiao_number := c.GetString("fapiao_number")
  692. diagnosis_id := c.GetString("diagnosis")
  693. sick_type, _ := c.GetInt64("sick_type")
  694. reg_type, _ := c.GetInt64("p_type")
  695. org_id, _ := c.GetInt64("org_id")
  696. org, _ := service.GetOrgById(org_id)
  697. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  698. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  699. if err != nil {
  700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  701. return
  702. }
  703. recordDateTime := theTime.Unix()
  704. //adminUser := c.GetAdminUserInfo()
  705. var prescriptions []*models.HisPrescription
  706. var start_time int64
  707. var end_time int64
  708. //ids_str := c.GetString("ids")
  709. //ids_arr := strings.Split(ids_str, ",")
  710. if settle_accounts_type == 1 { //日结
  711. //fmt.Println(reg_type)
  712. prescriptions, _ = service.GetUnSettleHisPrescriptionFive(org_id, id, recordDateTime, 2)
  713. } else { //月结
  714. start_time_str := c.GetString("start_time")
  715. end_time_str := c.GetString("end_time")
  716. timeLayout := "2006-01-02"
  717. loc, _ := time.LoadLocation("Local")
  718. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  719. if err != nil {
  720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  721. return
  722. }
  723. recordStartTime := theStartTime.Unix()
  724. start_time = recordStartTime
  725. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  726. if err != nil {
  727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  728. return
  729. }
  730. recordEndTime := theEndTime.Unix()
  731. end_time = recordEndTime
  732. prescriptions, _ = service.GetUnSettleMonthHisPrescription(org_id, id, recordStartTime, recordEndTime)
  733. }
  734. timestamp := time.Now().Unix()
  735. tempTime := time.Unix(timestamp, 0)
  736. timeFormat := tempTime.Format("20060102150405")
  737. chrgBchno := rand.Intn(100000) + 10000
  738. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  739. strconv.FormatInt(his.PatientId, 10)
  740. var ids []int64
  741. for _, item := range prescriptions {
  742. ids = append(ids, item.ID)
  743. }
  744. var total float64
  745. for _, item := range prescriptions {
  746. fmt.Println(item)
  747. if item.Type == 1 { //药品
  748. for _, subItem := range item.HisDoctorAdviceInfo {
  749. total = total + (subItem.Price * subItem.PrescribingNumber)
  750. }
  751. }
  752. if item.Type == 2 { //项目
  753. for _, subItem := range item.HisPrescriptionProject {
  754. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  755. total = total + (subItem.Price * cnt)
  756. }
  757. }
  758. for _, subItem := range item.HisAdditionalCharge {
  759. total = total + (subItem.Price * float64(subItem.Count))
  760. }
  761. }
  762. tm := time.Unix(time.Now().Unix(), 0)
  763. var customs []*models.NewCustomTwo
  764. for _, item := range prescriptions {
  765. if item.Type == 1 { //药品
  766. for _, subItem := range item.HisDoctorAdviceInfo {
  767. cus := &models.NewCustomTwo{
  768. AdviceId: subItem.ID,
  769. ProjectId: 0,
  770. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  771. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  772. FeedetlSn: subItem.FeedetlSn,
  773. Price: fmt.Sprintf("%.2f", subItem.Price),
  774. MedListCodg: subItem.Drug.MedicalInsuranceNumber,
  775. Type: 1,
  776. }
  777. customs = append(customs, cus)
  778. }
  779. }
  780. if item.Type == 2 { //项目
  781. for _, subItem := range item.HisPrescriptionProject {
  782. if subItem.Type == 2 {
  783. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  784. cus := &models.NewCustomTwo{
  785. AdviceId: 0,
  786. ProjectId: subItem.ID,
  787. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  788. Cut: fmt.Sprintf("%.4f", cnt),
  789. FeedetlSn: subItem.FeedetlSn,
  790. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  791. MedListCodg: subItem.HisProject.MedicalCode,
  792. Type: 2,
  793. }
  794. customs = append(customs, cus)
  795. } else {
  796. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  797. cus := &models.NewCustomTwo{
  798. AdviceId: 0,
  799. ProjectId: subItem.ID,
  800. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  801. Cut: fmt.Sprintf("%.4f", cnt),
  802. FeedetlSn: subItem.FeedetlSn,
  803. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  804. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  805. Type: 3,
  806. }
  807. customs = append(customs, cus)
  808. }
  809. }
  810. }
  811. for _, item := range item.HisAdditionalCharge {
  812. cus := &models.NewCustomTwo{
  813. ItemId: item.ID,
  814. AdviceId: 0,
  815. ProjectId: 0,
  816. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  817. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  818. FeedetlSn: item.FeedetlSn,
  819. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  820. MedListCodg: item.XtHisAddtionConfig.Code,
  821. Type: 3,
  822. }
  823. customs = append(customs, cus)
  824. }
  825. }
  826. result, request_log := service.OpKeepAccounts(his.Number, customs)
  827. saveLog(result, request_log, "记账", "记账", org.OrgName)
  828. var res ResultSettle
  829. if err := json.Unmarshal([]byte(result), &res); err != nil {
  830. utils.ErrorLog("解析失败:%v", err)
  831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  832. return
  833. }
  834. if res.ResultCode == "0" {
  835. //totals, _ := strconv.ParseFloat(total, 64)
  836. order := &models.HisOrder{
  837. PsnNo: his.PsnNo,
  838. UserOrgId: org_id,
  839. HisPatientId: his.ID,
  840. PatientId: id,
  841. SettleAccountsDate: recordDateTime,
  842. Ctime: time.Now().Unix(),
  843. Mtime: time.Now().Unix(),
  844. Status: 1,
  845. OrderStatus: 1,
  846. MdtrtId: his.Number,
  847. Number: chrg_bchno,
  848. SetlId: "",
  849. MedfeeSumamt: total,
  850. MedType: strconv.Itoa(int(reg_type)),
  851. SettleEndTime: end_time,
  852. SettleStartTime: start_time,
  853. SettleType: settle_accounts_type,
  854. FaPiaoCode: fapiao_code,
  855. FaPiaoNumber: fapiao_number,
  856. Diagnosis: diagnosis_id,
  857. PType: 2,
  858. SetlTime: tm.Format("2006-01-02 15:04:05"),
  859. }
  860. err = service.CreateOrder(order)
  861. if err != nil {
  862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  863. return
  864. }
  865. for _, item := range customs {
  866. var advice_id int64 = 0
  867. var project_id int64 = 0
  868. var item_id int64 = 0
  869. var types int64 = 0
  870. if item.Type == 1 {
  871. advice_id = item.AdviceId
  872. project_id = 0
  873. item_id = 0
  874. } else if item.Type == 2 {
  875. advice_id = 0
  876. item_id = 0
  877. project_id = item.ProjectId
  878. } else if item.Type == 3 {
  879. advice_id = 0
  880. item_id = item.ItemId
  881. project_id = 0
  882. }
  883. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  884. cut, _ := strconv.ParseFloat(item.Cut, 32)
  885. pric, _ := strconv.ParseFloat(item.Price, 32)
  886. info := &models.HisOrderInfo{
  887. OrderNumber: order.Number,
  888. UploadDate: time.Now().Unix(),
  889. AdviceId: advice_id,
  890. DetItemFeeSumamt: detItemFeeSumamt,
  891. Cnt: cut,
  892. Pric: pric,
  893. PatientId: id,
  894. Status: 1,
  895. Mtime: time.Now().Unix(),
  896. Ctime: time.Now().Unix(),
  897. UserOrgId: org_id,
  898. HisPatientId: his.ID,
  899. OrderId: order.ID,
  900. ProjectId: project_id,
  901. Type: types,
  902. ItemId: item_id,
  903. }
  904. service.CreateOrderInfo(info)
  905. }
  906. his.Diagnosis = diagnosis_id
  907. his.SickType = sick_type
  908. his.RegisterType = reg_type
  909. his.MedicalTreatmentType = reg_type
  910. service.UpdataHisPateint(&his)
  911. err = service.UpDatePrescriptionNumber(org_id, ids, chrg_bchno)
  912. err = service.UpDateHisPrescriptionInfoNumber(org_id, id, chrg_bchno, recordDateTime, his_patient_id)
  913. err = service.UpdataOrderStatusThree(chrg_bchno, org_id)
  914. if err == nil {
  915. c.ServeSuccessJSON(map[string]interface{}{
  916. "msg": "记账成功",
  917. })
  918. }
  919. } else {
  920. c.ServeSuccessJSON(map[string]interface{}{
  921. "failed_code": -10,
  922. "msg": res.ResultDesc,
  923. })
  924. }
  925. }
  926. func (c *CoordinateController) OpCancelKeepAccounts() {
  927. order_id, _ := c.GetInt64("order_id")
  928. admin_user_id, _ := c.GetInt64("admin_user_id")
  929. org_id, _ := c.GetInt64("org_id")
  930. org, _ := service.GetOrgById(org_id)
  931. order, _ := service.GetHisOrderByID(order_id)
  932. if order.ID == 0 {
  933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  934. return
  935. }
  936. role, _ := service.GetAdminUserInfoByID(org_id, admin_user_id)
  937. result, request_log := service.OpCancelKeepAccounts(order.SetlId, role.UserName, role.DoctorNumber)
  938. saveLog(result, request_log, "撤销记账", "撤销记账", org.OrgName)
  939. var res RefundDetail
  940. if err := json.Unmarshal([]byte(result), &res); err != nil {
  941. utils.ErrorLog("解析失败:%v", err)
  942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  943. return
  944. }
  945. fmt.Println(result)
  946. fmt.Println(request_log)
  947. fmt.Println(res)
  948. flag := 0
  949. isSuccess := false
  950. for _, item := range res.Result {
  951. if item.Code == "200" {
  952. flag = flag + 1
  953. }
  954. }
  955. if len(res.Result) == flag {
  956. isSuccess = true
  957. }
  958. var errMsg string
  959. for _, item := range res.Result {
  960. errMsg = errMsg + "\n" + item.ResultMsg
  961. }
  962. if isSuccess {
  963. err := service.UpdataOrderStatus(order_id, order.Number, org_id)
  964. if err == nil {
  965. c.ServeSuccessJSON(map[string]interface{}{
  966. "msg": "撤销记账成功",
  967. })
  968. } else {
  969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  970. return
  971. }
  972. } else {
  973. c.ServeSuccessJSON(map[string]interface{}{
  974. "failed_code": -10,
  975. "msg": errMsg,
  976. })
  977. }
  978. }
  979. //func saveLog(result string, request string, infno string, desc string) {
  980. //
  981. // org_id, _ := beego.AppConfig.Int64("org_id")
  982. // miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  983. // dir := miConfig.OrgName + "日志"
  984. // utils.Mkdir(dir)
  985. // month := time.Unix(1557042972, 0).Format("1")
  986. // year := time.Now().Format("2006")
  987. // month = time.Now().Format("01")
  988. // day := time.Now().Format("02")
  989. // hour := time.Now().Format("15")
  990. // min := time.Now().Format("04")
  991. // sec := time.Now().Format("05")
  992. //
  993. // result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  994. //
  995. // file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  996. // file_name := file + ".txt"
  997. // file_path := miConfig.OrgName + "日志" + "/" + file_name
  998. // exist, _ := utils.PathExists(file_path)
  999. // if exist { //存在
  1000. // fmt.Println("存在")
  1001. // f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  1002. // if err != nil {
  1003. // fmt.Println("read fail")
  1004. // }
  1005. // content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  1006. // n, _ := f.Seek(0, 2)
  1007. // _, err = f.WriteAt([]byte(content), n)
  1008. //
  1009. // } else { //不存在
  1010. // fmt.Println("文件不存在,创建文件")
  1011. // f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  1012. // defer f.Close()
  1013. // if err != nil {
  1014. // } else {
  1015. // _, err = f.Write([]byte("记录日志"))
  1016. // }
  1017. // }
  1018. //
  1019. //}
  1020. type Charset string
  1021. const (
  1022. UTF8 = Charset("UTF-8")
  1023. GB18030 = Charset("GB18030")
  1024. )
  1025. func saveLog(result string, request string, infno string, desc string, org_name string) {
  1026. //org_id, _ := beego.AppConfig.Int64("org_id")
  1027. //miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  1028. dir := org_name + "日志"
  1029. utils.Mkdir(dir)
  1030. month := time.Unix(1557042972, 0).Format("1")
  1031. year := time.Now().Format("2006")
  1032. month = time.Now().Format("01")
  1033. day := time.Now().Format("02")
  1034. hour := time.Now().Format("15")
  1035. min := time.Now().Format("04")
  1036. sec := time.Now().Format("05")
  1037. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  1038. file := org_name + "_" + year + month + day + "_log"
  1039. file_name := file + ".txt"
  1040. file_path := org_name + "日志" + "/" + file_name
  1041. exist, _ := utils.PathExists(file_path)
  1042. if exist { //存在
  1043. fmt.Println("存在")
  1044. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  1045. if err != nil {
  1046. fmt.Println("read fail")
  1047. }
  1048. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  1049. n, _ := f.Seek(0, 2)
  1050. _, err = f.WriteAt([]byte(content), n)
  1051. } else { //不存在
  1052. fmt.Println("文件不存在,创建文件")
  1053. f, err := os.Create(org_name + "日志" + "/" + file_name)
  1054. defer f.Close()
  1055. if err != nil {
  1056. } else {
  1057. _, err = f.Write([]byte("记录日志"))
  1058. }
  1059. }
  1060. }