prescription.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. package backend
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "kpt-pasture/model"
  7. "net/http"
  8. "strconv"
  9. "strings"
  10. "golang.org/x/text/language"
  11. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  12. "gitee.com/xuyiping_admin/pkg/xerr"
  13. "gorm.io/gorm"
  14. )
  15. func (s *StoreEntry) CreateOrUpdateSameTime(ctx context.Context, req *pasturePb.SearchSameTimeList) error {
  16. userModel, err := s.GetUserModel(ctx)
  17. if err != nil {
  18. return xerr.WithStack(err)
  19. }
  20. semeTime := model.NewSameTime(userModel.AppPasture.Id, userModel.SystemUser, req)
  21. if req.Id > 0 {
  22. if err = s.DB.Model(new(model.SameTime)).
  23. Where("id = ?", req.Id).
  24. Where("pasture_id = ?", userModel.AppPasture.Id).
  25. Updates(map[string]interface{}{
  26. "name": semeTime.Name,
  27. "week_type": semeTime.WeekType,
  28. "cow_type": semeTime.CowType,
  29. "postpartum_days_start": semeTime.PostpartumDaysStart,
  30. "postpartum_days_end": semeTime.PostpartumDaysEnd,
  31. "collate_nodes": semeTime.CollateNodes,
  32. "is_show": semeTime.IsShow,
  33. "remarks": semeTime.Remarks,
  34. }).Error; err != nil {
  35. return xerr.WithStack(err)
  36. }
  37. } else {
  38. if err = s.DB.Create(&semeTime).Error; err != nil {
  39. return xerr.WithStack(err)
  40. }
  41. }
  42. return nil
  43. }
  44. func (s *StoreEntry) SearchSameTimeList(ctx context.Context, req *pasturePb.SearchNameRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SameTimeResponse, error) {
  45. userModel, err := s.GetUserModel(ctx)
  46. if err != nil {
  47. return nil, xerr.WithStack(err)
  48. }
  49. semeTimeList := make([]*model.SameTime, 0)
  50. var count int64 = 0
  51. pastureId := userModel.AppPasture.Id
  52. pref := s.DB.Model(new(model.SameTime)).
  53. Where("pasture_id = ?", pastureId)
  54. if req.Name != "" {
  55. pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
  56. }
  57. if err = pref.Order("is_show asc,id desc").
  58. Count(&count).
  59. Limit(int(pagination.PageSize)).
  60. Offset(int(pagination.PageOffset)).
  61. Find(&semeTimeList).Error; err != nil {
  62. return nil, xerr.WithStack(err)
  63. }
  64. weekMap := s.WeekMap()
  65. sameTimeCowTypeMap := s.SameTimeCowTypeMap()
  66. systemUser, _ := s.SystemUserList(ctx, pastureId)
  67. return &pasturePb.SameTimeResponse{
  68. Code: http.StatusOK,
  69. Msg: "ok",
  70. Data: &pasturePb.SearchSameTimeData{
  71. List: model.SameTimeSlice(semeTimeList).ToPB(weekMap, sameTimeCowTypeMap, systemUser),
  72. Total: int32(count),
  73. PageSize: pagination.PageSize,
  74. Page: pagination.Page,
  75. },
  76. }, nil
  77. }
  78. func (s *StoreEntry) SameTimeIsShow(ctx context.Context, id int64) error {
  79. userModel, err := s.GetUserModel(ctx)
  80. if err != nil {
  81. return xerr.WithStack(err)
  82. }
  83. sameTime := &model.SameTime{}
  84. if err = s.DB.Model(new(model.SameTime)).
  85. Where("id = ?", id).
  86. Where("pasture_id = ?", userModel.AppPasture.Id).
  87. First(sameTime).Error; err != nil {
  88. if errors.Is(err, gorm.ErrRecordNotFound) {
  89. return xerr.Custom("该同期数据不存在")
  90. }
  91. return xerr.WithStack(err)
  92. }
  93. isShow := pasturePb.IsShow_No
  94. if sameTime.IsShow == pasturePb.IsShow_No {
  95. isShow = pasturePb.IsShow_Ok
  96. }
  97. if err = s.DB.Model(sameTime).Update("is_show", isShow).Error; err != nil {
  98. return xerr.WithStack(err)
  99. }
  100. return nil
  101. }
  102. func (s *StoreEntry) SearchDiseaseList(ctx context.Context, req *pasturePb.SearchDiseaseRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchDiseaseResponse, error) {
  103. userModel, err := s.GetUserModel(ctx)
  104. if err != nil {
  105. return nil, xerr.WithStack(err)
  106. }
  107. diseaseList := make([]*model.Disease, 0)
  108. var count int64 = 0
  109. pastureId := userModel.AppPasture.Id
  110. pref := s.DB.Model(new(model.Disease)).
  111. Where("pasture_id = ?", pastureId)
  112. if req.Name != "" {
  113. pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
  114. }
  115. if req.DiseaseTypeId > 0 {
  116. pref.Where("disease_type = ?", req.DiseaseTypeId)
  117. }
  118. if err = pref.Order("id desc").
  119. Count(&count).
  120. Limit(int(pagination.PageSize)).
  121. Offset(int(pagination.PageOffset)).
  122. Find(&diseaseList).Error; err != nil {
  123. return nil, xerr.WithStack(err)
  124. }
  125. systemUserList, _ := s.SystemUserList(ctx, pastureId)
  126. diseaseTypeList, _ := s.DiseaseTypeList(pastureId)
  127. return &pasturePb.SearchDiseaseResponse{
  128. Code: http.StatusOK,
  129. Msg: "ok",
  130. Data: &pasturePb.SearchDiseaseData{
  131. List: model.DiseaseSlice(diseaseList).ToPB(userModel.Language, systemUserList, diseaseTypeList),
  132. Total: int32(count),
  133. PageSize: pagination.PageSize,
  134. Page: pagination.Page,
  135. },
  136. }, nil
  137. }
  138. func (s *StoreEntry) CreateOrUpdateDisease(ctx context.Context, req *pasturePb.SearchDiseaseList) error {
  139. userModel, err := s.GetUserModel(ctx)
  140. if err != nil {
  141. return xerr.WithStack(err)
  142. }
  143. if req.Id > 0 {
  144. barn := &model.Disease{Id: int64(req.Id)}
  145. if err = s.DB.Model(new(model.Disease)).First(barn).Error; err != nil {
  146. if !errors.Is(err, gorm.ErrRecordNotFound) {
  147. return xerr.WithStack(err)
  148. }
  149. }
  150. }
  151. diseaseTypeList, _ := s.DiseaseTypeList(userModel.AppPasture.Id)
  152. if req.DiseaseTypeId > 0 {
  153. for _, v := range diseaseTypeList {
  154. if int32(v.Id) == req.DiseaseTypeId {
  155. req.DiseaseTypeName = v.Zh
  156. if userModel.Language == language.English.String() {
  157. req.DiseaseTypeName = v.En
  158. }
  159. }
  160. }
  161. }
  162. if err = s.DB.Model(new(model.Disease)).Where(map[string]interface{}{
  163. "id": req.Id,
  164. "pasture_id": userModel.AppPasture.Id,
  165. }).Assign(map[string]interface{}{
  166. "disease_type": req.DiseaseTypeId,
  167. "disease_type_name": req.DiseaseTypeName,
  168. "name": req.Name,
  169. "symptoms": strings.Join(req.Symptoms, "|"),
  170. "remarks": req.Remarks,
  171. "is_show": pasturePb.IsShow_Ok,
  172. "operation_id": userModel.SystemUser.Id,
  173. }).FirstOrCreate(&model.Disease{}).Error; err != nil {
  174. return xerr.WithStack(err)
  175. }
  176. return nil
  177. }
  178. func (s *StoreEntry) SearchDiseaseTypeList(ctx context.Context, req *pasturePb.SearchNameRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchBaseConfigResponse, error) {
  179. userModel, err := s.GetUserModel(ctx)
  180. if err != nil {
  181. return nil, xerr.WithStack(err)
  182. }
  183. diseaseTypeList := make([]*model.ConfigDiseaseType, 0)
  184. var count int64 = 0
  185. pref := s.DB.Model(new(model.ConfigDiseaseType)).Where("pasture_id = ?", userModel.AppPasture.Id)
  186. if req.Name != "" {
  187. pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
  188. }
  189. if err = pref.Order("id desc").Count(&count).Limit(int(pagination.PageSize)).Offset(int(pagination.PageOffset)).
  190. Find(&diseaseTypeList).Error; err != nil {
  191. return nil, xerr.WithStack(err)
  192. }
  193. return &pasturePb.SearchBaseConfigResponse{
  194. Code: http.StatusOK,
  195. Msg: "ok",
  196. Data: &pasturePb.SearchBaseConfigData{
  197. List: model.ConfigDiseaseTypeSlice(diseaseTypeList).ToPB(userModel.Language),
  198. Total: int32(count),
  199. PageSize: pagination.PageSize,
  200. Page: pagination.Page,
  201. },
  202. }, nil
  203. }
  204. func (s *StoreEntry) CreateOrUpdateDiseaseType(ctx context.Context, req *pasturePb.SearchBaseConfigList) error {
  205. userModel, err := s.GetUserModel(ctx)
  206. if err != nil {
  207. return xerr.WithStack(err)
  208. }
  209. if req.Id > 0 {
  210. barn := &model.ConfigDiseaseType{Id: int64(req.Id)}
  211. if err = s.DB.Model(new(model.ConfigDiseaseType)).
  212. Where("pasture_id = ?", userModel.AppPasture.Id).
  213. First(barn).Error; err != nil {
  214. if !errors.Is(err, gorm.ErrRecordNotFound) {
  215. return xerr.WithStack(err)
  216. }
  217. }
  218. }
  219. if err = s.DB.Model(&model.ConfigDiseaseType{}).Where(map[string]interface{}{
  220. "id": req.Id,
  221. "pasture_id": userModel.AppPasture.Id,
  222. }).Assign(map[string]interface{}{
  223. "name": req.Name,
  224. "remarks": req.Remarks,
  225. "is_show": pasturePb.IsShow_Ok,
  226. }).FirstOrCreate(&model.ConfigDiseaseType{}).Error; err != nil {
  227. return xerr.WithStack(err)
  228. }
  229. return nil
  230. }
  231. func (s *StoreEntry) SearchPrescriptionList(ctx context.Context, req *pasturePb.SearchPrescriptionRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchPrescriptionResponse, error) {
  232. userModel, err := s.GetUserModel(ctx)
  233. if err != nil {
  234. return nil, xerr.WithStack(err)
  235. }
  236. prescriptionList := make([]*model.Prescription, 0)
  237. var count int64 = 0
  238. pref := s.DB.Model(new(model.Prescription)).
  239. Where("pasture_id = ?", userModel.AppPasture.Id).
  240. Where("is_show = ?", pasturePb.IsShow_Ok)
  241. if req.Name != "" {
  242. pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
  243. }
  244. if err = pref.Order("id desc").Count(&count).Limit(int(pagination.PageSize)).Offset(int(pagination.PageOffset)).
  245. Find(&prescriptionList).Error; err != nil {
  246. return nil, xerr.WithStack(err)
  247. }
  248. prescriptionIds := make([]int32, 0)
  249. for _, prescription := range prescriptionList {
  250. prescriptionIds = append(prescriptionIds, prescription.Id)
  251. }
  252. prescriptionDrugs := make([]*model.PrescriptionDrugs, 0)
  253. if len(prescriptionIds) > 0 {
  254. if err = s.DB.Model(new(model.PrescriptionDrugs)).
  255. Where("pasture_id = ?", userModel.AppPasture.Id).
  256. Where("prescription_id in (?)", prescriptionIds).
  257. Where("is_show = ? ", pasturePb.IsShow_Ok).
  258. Find(&prescriptionDrugs).Error; err != nil {
  259. return nil, xerr.WithStack(err)
  260. }
  261. }
  262. diseaseMaps, _ := s.DiseaseMaps(ctx)
  263. return &pasturePb.SearchPrescriptionResponse{
  264. Code: http.StatusOK,
  265. Msg: "ok",
  266. Data: &pasturePb.SearchPrescriptionData{
  267. List: model.PrescriptionSlice(prescriptionList).ToPB(prescriptionDrugs, diseaseMaps),
  268. Total: int32(count),
  269. PageSize: pagination.PageSize,
  270. Page: pagination.Page,
  271. },
  272. }, nil
  273. }
  274. func (s *StoreEntry) CreateOrUpdatePrescription(ctx context.Context, req *pasturePb.PrescriptionRequest) error {
  275. userModel, err := s.GetUserModel(ctx)
  276. if err != nil {
  277. return xerr.WithStack(err)
  278. }
  279. var maxUseDays, maxMeatExpiredDays, maxMilkExpiredDays int32 = 0, 0, 0
  280. for _, v := range req.DrugsList {
  281. if v.DrugsId <= 0 {
  282. return xerr.Customf("错误处方药品的数据")
  283. }
  284. if v.UseDays <= 0 {
  285. return xerr.Customf("错误处方药品使用天数")
  286. }
  287. if v.UseDays > maxUseDays {
  288. maxUseDays = v.UseDays
  289. }
  290. drugs, err := s.GetDrugsById(ctx, userModel.AppPasture.Id, int64(v.DrugsId))
  291. if err != nil {
  292. return xerr.WithStack(err)
  293. }
  294. if drugs.MeatExpiredDays > maxMeatExpiredDays {
  295. maxMeatExpiredDays = drugs.MeatExpiredDays
  296. }
  297. if drugs.MilkExpiredDays > maxMilkExpiredDays {
  298. maxMilkExpiredDays = drugs.MilkExpiredDays
  299. }
  300. }
  301. applicableDisease := ""
  302. if len(req.ApplicableDiseaseIds) > 0 {
  303. applicableDiseaseIds := make([]string, 0)
  304. for _, v := range req.ApplicableDiseaseIds {
  305. applicableDiseaseIds = append(applicableDiseaseIds, strconv.Itoa(int(v)))
  306. }
  307. applicableDisease = strings.Join(applicableDiseaseIds, ",")
  308. }
  309. newPrescription := model.NewPrescription(userModel.AppPasture.Id, req, applicableDisease, maxUseDays, maxMeatExpiredDays, maxMilkExpiredDays, userModel.SystemUser)
  310. if req.Id > 0 {
  311. prescription := &model.Prescription{Id: req.Id}
  312. if err = s.DB.Model(&model.Prescription{}).First(prescription).Error; err != nil {
  313. if !errors.Is(err, gorm.ErrRecordNotFound) {
  314. return xerr.WithStack(err)
  315. }
  316. }
  317. if err = s.DB.Transaction(func(tx *gorm.DB) error {
  318. if err = tx.Model(&model.Prescription{}).Where(map[string]interface{}{
  319. "id": req.Id,
  320. }).Updates(map[string]interface{}{
  321. "name": newPrescription.Name,
  322. "applicable_disease": newPrescription.ApplicableDisease,
  323. "use_days": newPrescription.UseDays,
  324. "meat_expired_days": newPrescription.MeatExpiredDays,
  325. "milk_expired_days": newPrescription.MilkExpiredDays,
  326. "remarks": newPrescription.Remarks,
  327. }).Error; err != nil {
  328. return xerr.WithStack(err)
  329. }
  330. if err = tx.Model(new(model.PrescriptionDrugs)).Where("prescription_id", req.Id).
  331. Update("is_show", pasturePb.IsShow_No).Error; err != nil {
  332. return xerr.WithStack(err)
  333. }
  334. // 创建处方药品
  335. newPrescriptionDrugs := model.NewPrescriptionDrugs(userModel.AppPasture.Id, req.Id, req.DrugsList)
  336. if err = tx.Create(&newPrescriptionDrugs).Error; err != nil {
  337. return xerr.WithStack(err)
  338. }
  339. return nil
  340. }); err != nil {
  341. return xerr.WithStack(err)
  342. }
  343. return nil
  344. }
  345. // 创建处方
  346. if err = s.DB.Transaction(func(tx *gorm.DB) error {
  347. // 创建处方
  348. if err = tx.Create(&newPrescription).Error; err != nil {
  349. return xerr.WithStack(err)
  350. }
  351. // 创建处方药品
  352. newPrescriptionDrugs := model.NewPrescriptionDrugs(userModel.AppPasture.Id, newPrescription.Id, req.DrugsList)
  353. if err = tx.Create(&newPrescriptionDrugs).Error; err != nil {
  354. return xerr.WithStack(err)
  355. }
  356. return nil
  357. }); err != nil {
  358. return xerr.WithStack(err)
  359. }
  360. return nil
  361. }
  362. func (s *StoreEntry) PrescriptionDetail(ctx context.Context, id int64) (*pasturePb.PrescriptionDetailResponse, error) {
  363. userModel, err := s.GetUserModel(ctx)
  364. if err != nil {
  365. return nil, xerr.WithStack(err)
  366. }
  367. prescriptionData, err := s.GetPrescriptionById(ctx, userModel.AppPasture.Id, int32(id))
  368. if err != nil {
  369. return nil, xerr.WithStack(err)
  370. }
  371. prescriptionDrugsList, err := s.PrescriptionDrugsByPrescriptionId(ctx, userModel.AppPasture.Id, int32(id))
  372. if err != nil {
  373. return nil, xerr.WithStack(err)
  374. }
  375. return &pasturePb.PrescriptionDetailResponse{
  376. Code: http.StatusOK,
  377. Msg: "ok",
  378. Data: &pasturePb.PrescriptionRequest{
  379. Id: prescriptionData.Id,
  380. Name: prescriptionData.Name,
  381. ApplicableDiseaseIds: make([]int32, 0),
  382. IsShow: prescriptionData.IsShow,
  383. Remarks: prescriptionData.Remarks,
  384. DrugsList: model.PrescriptionDrugsSlice(prescriptionDrugsList).ToPB(),
  385. },
  386. }, nil
  387. }
  388. func (s *StoreEntry) ImmunizationSetList(ctx context.Context, req *pasturePb.ImmunizationRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchImmunizationResponse, error) {
  389. userModel, err := s.GetUserModel(ctx)
  390. if err != nil {
  391. return nil, xerr.WithStack(err)
  392. }
  393. immunizationList := make([]*model.ImmunizationPlan, 0)
  394. var count int64 = 0
  395. pref := s.DB.Model(new(model.ImmunizationPlan)).
  396. Where("pasture_id = ?", userModel.AppPasture.Id)
  397. if req.Name != "" {
  398. pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
  399. }
  400. if err = pref.Order("is_show asc,id desc").
  401. Count(&count).
  402. Limit(int(pagination.PageSize)).
  403. Offset(int(pagination.PageOffset)).
  404. Find(&immunizationList).Error; err != nil {
  405. return nil, xerr.WithStack(err)
  406. }
  407. CowTypeOptions := s.ImmunizationCowTypeEnumList("")
  408. conditionsOptions := s.ImmunizationConditionsEnumList("")
  409. return &pasturePb.SearchImmunizationResponse{
  410. Code: http.StatusOK,
  411. Msg: "ok",
  412. Data: &pasturePb.SearchImmunizationData{
  413. List: model.ImmunizationPlanSlice(immunizationList).ToPB(CowTypeOptions, conditionsOptions),
  414. Total: int32(count),
  415. PageSize: pagination.PageSize,
  416. Page: pagination.Page,
  417. },
  418. }, nil
  419. }
  420. func (s *StoreEntry) CreatedOrUpdateImmunization(ctx context.Context, req *pasturePb.ImmunizationRequest) error {
  421. var (
  422. immunization *model.ImmunizationPlan
  423. err error
  424. systemUser *model.SystemUser
  425. )
  426. userModel, err := s.GetUserModel(ctx)
  427. if err != nil {
  428. return xerr.WithStack(err)
  429. }
  430. if req.Conditions == pasturePb.ImmunizationConditions_Other_Vaccine_After && req.ImmunizationPlanId <= 0 {
  431. return xerr.Custom("请选择具体的免疫计划")
  432. }
  433. if req.ImmunizationPlanId > 0 {
  434. otherImmunization, err := s.GetImmunizationById(ctx, userModel.AppPasture.Id, int64(req.ImmunizationPlanId))
  435. if err != nil {
  436. return xerr.WithStack(err)
  437. }
  438. req.ImmunizationPlanName = otherImmunization.Name
  439. }
  440. if req.Id > 0 {
  441. immunization, err = s.GetImmunizationById(ctx, userModel.AppPasture.Id, int64(req.Id))
  442. if err != nil {
  443. return xerr.WithStack(err)
  444. }
  445. systemUser, _ = s.GetSystemUserById(ctx, immunization.OperationId)
  446. } else {
  447. systemUser, _ = s.GetCurrentSystemUser(ctx)
  448. }
  449. immunization = model.NewImmunizationPlan(userModel.AppPasture.Id, systemUser, req)
  450. if err = s.DB.Model(&model.ImmunizationPlan{}).Where(map[string]interface{}{
  451. "id": req.Id,
  452. "pasture_id": userModel.AppPasture.Id,
  453. }).Assign(map[string]interface{}{
  454. "name": immunization.Name,
  455. "cow_type": immunization.CowType,
  456. "conditions": immunization.Conditions,
  457. "value": immunization.Value,
  458. "immunization_plan_id": immunization.ImmunizationPlanId,
  459. "immunization_plan_name": immunization.ImmunizationPlanName,
  460. "is_show": immunization.IsShow,
  461. "operation_id": immunization.OperationId,
  462. "operation_name": immunization.OperationName,
  463. }).FirstOrCreate(&model.ImmunizationPlan{}).Error; err != nil {
  464. return xerr.WithStack(err)
  465. }
  466. return nil
  467. }
  468. func (s *StoreEntry) ImmunizationIsShow(ctx context.Context, id int64) error {
  469. userModel, err := s.GetUserModel(ctx)
  470. if err != nil {
  471. return xerr.WithStack(err)
  472. }
  473. immunizationPlan := &model.ImmunizationPlan{
  474. Id: id,
  475. }
  476. if err = s.DB.Model(new(model.ImmunizationPlan)).
  477. Where("id = ?", id).
  478. Where("pasture_id = ?", userModel.AppPasture.Id).
  479. First(immunizationPlan).Error; err != nil {
  480. if errors.Is(err, gorm.ErrRecordNotFound) {
  481. return xerr.Custom("该免疫计划不存在")
  482. }
  483. return xerr.WithStack(err)
  484. }
  485. isShow := pasturePb.IsShow_No
  486. if immunizationPlan.IsShow == pasturePb.IsShow_No {
  487. isShow = pasturePb.IsShow_Ok
  488. }
  489. if err = s.DB.Model(immunizationPlan).Update("is_show", isShow).Error; err != nil {
  490. return xerr.WithStack(err)
  491. }
  492. return nil
  493. }