pasture_service.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. package backend
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "kpt-tmr-group/model"
  7. "kpt-tmr-group/pkg/xerr"
  8. operationPb "kpt-tmr-group/proto/go/backend/operation"
  9. "net/http"
  10. "github.com/gin-gonic/gin"
  11. "gorm.io/gorm"
  12. )
  13. var (
  14. CattleParentCategoryMap = map[operationPb.CattleCategoryParent_Kind]string{
  15. operationPb.CattleCategoryParent_LACTATION_CAW: "泌乳牛",
  16. operationPb.CattleCategoryParent_FATTEN_CAW: "育肥牛",
  17. operationPb.CattleCategoryParent_RESERVE_CAW: "后备牛",
  18. operationPb.CattleCategoryParent_DRY_CAW: "干奶牛",
  19. operationPb.CattleCategoryParent_PERINATAL_CAW: "围产牛",
  20. operationPb.CattleCategoryParent_OTHER_CAW: "其他",
  21. }
  22. ForageParentCategoryMap = map[operationPb.ForageCategoryParent_Kind]string{
  23. operationPb.ForageCategoryParent_ROUGHAGE: "粗料",
  24. operationPb.ForageCategoryParent_CONCENTRATE: "精料",
  25. operationPb.ForageCategoryParent_HALF_ROUGHAGE_HALF_CONCENTRATE: "粗料精料各半",
  26. operationPb.ForageCategoryParent_OTHER: "其他",
  27. }
  28. ForageSourceMap = map[operationPb.ForageSource_Kind]string{
  29. operationPb.ForageSource_SYSTEM_BUILT_IN: "系统内置",
  30. operationPb.ForageSource_USER_DEFINED: "用户自定义",
  31. }
  32. ForagePlanTypeMap = map[operationPb.ForagePlanType_Kind]string{
  33. operationPb.ForagePlanType_INVALID: "无",
  34. operationPb.ForagePlanType_FORKLIFT: "铲车",
  35. operationPb.ForagePlanType_CONCENTRATE: "精料",
  36. }
  37. JumpDelaTypeMap = map[operationPb.JumpDelaType_Kind]string{
  38. operationPb.JumpDelaType_INVALID: "禁用",
  39. operationPb.JumpDelaType_THREE: "3秒",
  40. operationPb.JumpDelaType_SIX: "6秒",
  41. operationPb.JumpDelaType_NINE: "9秒",
  42. }
  43. IsShowMap = map[operationPb.IsShow_Kind]string{
  44. operationPb.IsShow_OK: "是",
  45. operationPb.IsShow_NO: "否",
  46. }
  47. )
  48. // CreateGroupPasture 创建集团牧场
  49. func (s *StoreEntry) CreateGroupPasture(ctx context.Context, req *operationPb.AddPastureRequest) error {
  50. pastureList := model.NewGroupPasture(req)
  51. if err := s.DB.Create(pastureList).Error; err != nil {
  52. return xerr.WithStack(err)
  53. }
  54. return nil
  55. }
  56. // EditGroupPasture 创建集团牧场
  57. func (s *StoreEntry) EditGroupPasture(ctx context.Context, req *operationPb.AddPastureRequest) error {
  58. groupPasture := &model.GroupPasture{Id: int64(req.Id)}
  59. if err := s.DB.First(groupPasture).Error; err != nil {
  60. if errors.Is(err, gorm.ErrRecordNotFound) {
  61. return xerr.Custom("该数据不存在!")
  62. }
  63. return xerr.WithStack(err)
  64. }
  65. updateData := &model.GroupPasture{
  66. Name: req.Name,
  67. Account: req.Account,
  68. ManagerUser: req.ManagerUser,
  69. ManagerPhone: req.ManagerPhone,
  70. Address: req.Address,
  71. }
  72. if err := s.DB.Model(new(model.GroupPasture)).Omit("is_show", "password").
  73. Where("id = ?", req.Id).
  74. Updates(updateData).Error; err != nil {
  75. return xerr.WithStack(err)
  76. }
  77. return nil
  78. }
  79. // SearchGroupPastureList 查询牧场列表
  80. func (s *StoreEntry) SearchGroupPastureList(ctx context.Context, req *operationPb.SearchPastureRequest) (*operationPb.SearchPastureResponse, error) {
  81. groupPasture := make([]*model.GroupPasture, 0)
  82. var count int64 = 0
  83. pref := s.DB.Model(new(model.GroupPasture)).Where("is_delete = ? ", operationPb.IsShow_OK)
  84. if req.Name != "" {
  85. pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
  86. }
  87. if req.ManagerPhone != "" {
  88. pref.Where("manager_phone like ?", fmt.Sprintf("%s%s%s", "%", req.ManagerPhone, "%"))
  89. }
  90. if req.ManagerUser != "" {
  91. pref.Where("manager_user like ?", fmt.Sprintf("%s%s%s", "%", req.ManagerUser, "%"))
  92. }
  93. if req.StartTime > 0 && req.EndTime > 0 && req.EndTime >= req.StartTime {
  94. pref.Where("created_at BETWEEN ? AND ? ", req.StartTime, req.EndTime)
  95. }
  96. if err := pref.Order("id desc").Count(&count).Limit(int(req.Pagination.PageSize)).Offset(int(req.Pagination.PageOffset)).
  97. Find(&groupPasture).Debug().Error; err != nil {
  98. return nil, xerr.WithStack(err)
  99. }
  100. return &operationPb.SearchPastureResponse{
  101. Code: http.StatusOK,
  102. Msg: "ok",
  103. Data: &operationPb.SearchPastureData{
  104. Page: req.Pagination.Page,
  105. Total: int32(count),
  106. List: model.GroupPastureSlice(groupPasture).ToPB(),
  107. },
  108. }, nil
  109. }
  110. func (s *StoreEntry) DeleteGroupPasture(ctx context.Context, pastureId int64) error {
  111. groupPasture := &model.GroupPasture{
  112. Id: pastureId,
  113. }
  114. if err := s.DB.First(groupPasture).Error; err != nil {
  115. if errors.Is(err, gorm.ErrRecordNotFound) {
  116. return xerr.Custom("该数据不存在")
  117. }
  118. return xerr.WithStack(err)
  119. }
  120. if err := s.DB.Model(groupPasture).Update("is_delete", operationPb.IsShow_NO).Error; err != nil {
  121. return xerr.WithStack(err)
  122. }
  123. return nil
  124. }
  125. func (s *StoreEntry) ResetPasswordGroupPasture(ctx context.Context, req *operationPb.RestPasswordGroupPasture) error {
  126. groupPasture := &model.GroupPasture{
  127. Id: int64(req.PastureId),
  128. }
  129. if err := s.DB.First(groupPasture).Error; err != nil {
  130. if errors.Is(err, gorm.ErrRecordNotFound) {
  131. return xerr.Custom("该数据不存在")
  132. }
  133. return xerr.WithStack(err)
  134. }
  135. if err := s.DB.Model(groupPasture).Update("password", req.Password).Error; err != nil {
  136. return xerr.WithStack(err)
  137. }
  138. return nil
  139. }
  140. func (s *StoreEntry) IsShowGroupPasture(ctx context.Context, req *operationPb.IsShowGroupPasture) error {
  141. groupPasture := &model.GroupPasture{
  142. Id: int64(req.PastureId),
  143. }
  144. if err := s.DB.First(groupPasture).Error; err != nil {
  145. if errors.Is(err, gorm.ErrRecordNotFound) {
  146. return xerr.Custom("该数据不存在")
  147. }
  148. return xerr.WithStack(err)
  149. }
  150. if err := s.DB.Model(groupPasture).Update("is_show", req.IsShow).Error; err != nil {
  151. return xerr.WithStack(err)
  152. }
  153. return nil
  154. }
  155. // ParentCattleCategoryList 畜牧类别父类列表
  156. func (s *StoreEntry) ParentCattleCategoryList(ctx context.Context) map[operationPb.CattleCategoryParent_Kind]string {
  157. return CattleParentCategoryMap
  158. }
  159. // AddCattleCategory 添加畜牧分类
  160. func (s *StoreEntry) AddCattleCategory(ctx context.Context, req *operationPb.AddCattleCategoryRequest) error {
  161. cattleCategory := model.NewCattleCategory(req)
  162. if err := s.DB.Create(cattleCategory).Error; err != nil {
  163. return xerr.WithStack(err)
  164. }
  165. return nil
  166. }
  167. // EditCattleCategory 编辑畜牧分类
  168. func (s *StoreEntry) EditCattleCategory(ctx context.Context, req *operationPb.AddCattleCategoryRequest) error {
  169. cattleCategory := &model.CattleCategory{Id: int64(req.Id)}
  170. if err := s.DB.First(cattleCategory).Error; err != nil {
  171. if errors.Is(err, gorm.ErrRecordNotFound) {
  172. return xerr.Custom("该数据不存在")
  173. }
  174. return xerr.WithStack(err)
  175. }
  176. updateData := &model.CattleCategory{
  177. ParentName: req.ParentName,
  178. Name: req.Name,
  179. Number: req.Number,
  180. ParentId: req.ParentId,
  181. }
  182. if err := s.DB.Model(new(model.CattleCategory)).Omit("is_show", "is_delete").
  183. Where("id = ?", req.Id).
  184. Updates(updateData).Error; err != nil {
  185. return xerr.WithStack(err)
  186. }
  187. return nil
  188. }
  189. // IsShowCattleCategory 是否启用
  190. func (s *StoreEntry) IsShowCattleCategory(ctx context.Context, req *operationPb.IsShowCattleCategory) error {
  191. cattleCategory := &model.CattleCategory{Id: int64(req.CattleCategoryId)}
  192. if err := s.DB.First(cattleCategory).Error; err != nil {
  193. if errors.Is(err, gorm.ErrRecordNotFound) {
  194. return xerr.Custom("该数据不存在")
  195. }
  196. return xerr.WithStack(err)
  197. }
  198. if err := s.DB.Model(new(model.CattleCategory)).Where("id = ?", req.CattleCategoryId).Update("is_show", req.IsShow).Error; err != nil {
  199. return xerr.WithStack(err)
  200. }
  201. return nil
  202. }
  203. // DeleteCattleCategory 是否删除
  204. func (s *StoreEntry) DeleteCattleCategory(ctx context.Context, cattleCategoryId int64) error {
  205. cattleCategory := &model.CattleCategory{Id: cattleCategoryId}
  206. if err := s.DB.First(cattleCategory).Error; err != nil {
  207. if errors.Is(err, gorm.ErrRecordNotFound) {
  208. return xerr.Custom("该数据不存在")
  209. }
  210. return xerr.WithStack(err)
  211. }
  212. if err := s.DB.Model(new(model.CattleCategory)).Where("id = ?", cattleCategoryId).Update("is_delete", operationPb.IsShow_NO).Error; err != nil {
  213. return xerr.WithStack(err)
  214. }
  215. return nil
  216. }
  217. // SearchCattleCategoryList 牧畜分类类别列表
  218. func (s *StoreEntry) SearchCattleCategoryList(ctx context.Context, req *operationPb.SearchCattleCategoryRequest) (*operationPb.SearchCattleCategoryResponse, error) {
  219. cattleCategory := make([]*model.CattleCategory, 0)
  220. var count int64 = 0
  221. pref := s.DB.Model(new(model.CattleCategory)).Where("is_delete = ?", operationPb.IsShow_OK)
  222. if req.Name != "" {
  223. pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
  224. }
  225. if req.ParentName != "" {
  226. pref.Where("parent_name like ?", fmt.Sprintf("%s%s%s", "%", req.ParentName, "%"))
  227. }
  228. if req.IsShow > 0 {
  229. pref.Where("is_show = ?", req.IsShow)
  230. }
  231. if err := pref.Order("id desc").Count(&count).Limit(int(req.Pagination.PageSize)).Offset(int(req.Pagination.PageOffset)).
  232. Find(&cattleCategory).Debug().Error; err != nil {
  233. return nil, xerr.WithStack(err)
  234. }
  235. return &operationPb.SearchCattleCategoryResponse{
  236. Code: http.StatusOK,
  237. Msg: "ok",
  238. Data: &operationPb.SearchCattleCategoryData{
  239. Page: req.Pagination.Page,
  240. Total: int32(count),
  241. List: model.CattleCategorySlice(cattleCategory).ToPB(),
  242. },
  243. }, nil
  244. }
  245. // ParentForageCategoryList 饲料类别父类列表
  246. func (s *StoreEntry) ParentForageCategoryList(ctx context.Context) map[operationPb.ForageCategoryParent_Kind]string {
  247. return ForageParentCategoryMap
  248. }
  249. // AddForageCategory 添加饲料分类
  250. func (s *StoreEntry) AddForageCategory(ctx context.Context, req *operationPb.AddForageCategoryRequest) error {
  251. forageCategory := model.NewForageCategory(req)
  252. if err := s.DB.Create(forageCategory).Error; err != nil {
  253. return xerr.WithStack(err)
  254. }
  255. return nil
  256. }
  257. // EditForageCategory 编辑饲料分类
  258. func (s *StoreEntry) EditForageCategory(ctx context.Context, req *operationPb.AddForageCategoryRequest) error {
  259. forageCategory := &model.ForageCategory{Id: int64(req.Id)}
  260. if err := s.DB.First(forageCategory).Error; err != nil {
  261. if errors.Is(err, gorm.ErrRecordNotFound) {
  262. return xerr.Custom("该数据不存在")
  263. }
  264. return xerr.WithStack(err)
  265. }
  266. updateData := &model.ForageCategory{
  267. ParentName: req.ParentName,
  268. Name: req.Name,
  269. Number: req.Number,
  270. ParentId: req.ParentId,
  271. }
  272. if err := s.DB.Model(new(model.ForageCategory)).Omit("is_show", "is_delete").
  273. Where("id = ?", req.Id).
  274. Updates(updateData).Error; err != nil {
  275. return xerr.WithStack(err)
  276. }
  277. return nil
  278. }
  279. // IsShowForageCategory 是否启用
  280. func (s *StoreEntry) IsShowForageCategory(ctx context.Context, req *operationPb.IsShowForageCategory) error {
  281. forageCategory := &model.ForageCategory{Id: int64(req.ForageCategoryId)}
  282. if err := s.DB.First(forageCategory).Error; err != nil {
  283. if errors.Is(err, gorm.ErrRecordNotFound) {
  284. return xerr.Custom("该数据不存在")
  285. }
  286. return xerr.WithStack(err)
  287. }
  288. if err := s.DB.Model(new(model.ForageCategory)).Where("id = ?", req.ForageCategoryId).Update("is_show", req.IsShow).Error; err != nil {
  289. return xerr.WithStack(err)
  290. }
  291. return nil
  292. }
  293. // DeleteForageCategory 是否删除
  294. func (s *StoreEntry) DeleteForageCategory(ctx context.Context, forageCategoryId int64) error {
  295. forageCategory := &model.ForageCategory{Id: forageCategoryId}
  296. if err := s.DB.First(forageCategory).Error; err != nil {
  297. if errors.Is(err, gorm.ErrRecordNotFound) {
  298. return xerr.Custom("该数据不存在")
  299. }
  300. return xerr.WithStack(err)
  301. }
  302. if err := s.DB.Model(new(model.ForageCategory)).Where("id = ?", forageCategoryId).Update("is_delete", operationPb.IsShow_NO).Error; err != nil {
  303. return xerr.WithStack(err)
  304. }
  305. return nil
  306. }
  307. // SearchForageCategoryList 饲料分类类别列表
  308. func (s *StoreEntry) SearchForageCategoryList(ctx context.Context, req *operationPb.SearchForageCategoryRequest) (*operationPb.SearchForageCategoryResponse, error) {
  309. forageCategory := make([]*model.ForageCategory, 0)
  310. var count int64 = 0
  311. pref := s.DB.Model(new(model.ForageCategory)).Where("is_delete = ?", operationPb.IsShow_OK)
  312. if req.Name != "" {
  313. pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
  314. }
  315. if req.ParentName != "" {
  316. pref.Where("parent_name like ?", fmt.Sprintf("%s%s%s", "%", req.ParentName, "%"))
  317. }
  318. if req.IsShow > 0 {
  319. pref.Where("is_show = ?", req.IsShow)
  320. }
  321. if err := pref.Order("id desc").Count(&count).Limit(int(req.Pagination.PageSize)).Offset(int(req.Pagination.PageOffset)).
  322. Find(&forageCategory).Debug().Error; err != nil {
  323. return nil, xerr.WithStack(err)
  324. }
  325. return &operationPb.SearchForageCategoryResponse{
  326. Code: http.StatusOK,
  327. Msg: "ok",
  328. Data: &operationPb.SearchForageCategoryData{
  329. Page: req.Pagination.Page,
  330. Total: int32(count),
  331. List: model.ForageCategorySlice(forageCategory).ToPB(),
  332. },
  333. }, nil
  334. }
  335. // CreateForage 创建饲料
  336. func (s *StoreEntry) CreateForage(ctx context.Context, req *operationPb.AddForageRequest) error {
  337. forage := model.NewForage(req)
  338. if err := s.DB.Create(forage).Error; err != nil {
  339. return xerr.WithStack(err)
  340. }
  341. return nil
  342. }
  343. // EditForage 编辑饲料
  344. func (s *StoreEntry) EditForage(ctx context.Context, req *operationPb.AddForageRequest) error {
  345. forage := model.Forage{Id: int64(req.Id)}
  346. if err := s.DB.Where("is_delete = ?", operationPb.IsShow_OK).First(forage).Error; err != nil {
  347. if errors.Is(err, gorm.ErrRecordNotFound) {
  348. return xerr.Custom("该数据不存在")
  349. }
  350. return xerr.WithStack(err)
  351. }
  352. updateData := &model.Forage{
  353. Name: req.Name,
  354. CategoryId: int64(req.CategoryId),
  355. UniqueEncode: req.UniqueEncode,
  356. ForageSourceId: req.ForageSourceId,
  357. PlanTypeId: req.PlanTypeId,
  358. SmallMaterialScale: req.SmallMaterialScale,
  359. AllowError: int64(req.AllowError),
  360. PackageWeight: int64(req.PackageWeight),
  361. Price: int64(req.Price),
  362. JumpWeight: int64(req.JumpWeight),
  363. JumpDelay: req.JumpDelay,
  364. ConfirmStart: req.ConfirmStart,
  365. RelayLocations: int64(req.RelayLocations),
  366. Jmp: req.Jmp,
  367. Backup1: req.Backup1,
  368. Backup2: req.Backup2,
  369. Backup3: req.Backup3,
  370. }
  371. if err := s.DB.Model(new(model.Forage)).Omit("is_show", "is_delete").Where("id = ?", req.Id).
  372. Updates(updateData).Error; err != nil {
  373. return xerr.WithStack(err)
  374. }
  375. return nil
  376. }
  377. func (s *StoreEntry) SearchForageList(ctx context.Context, req *operationPb.SearchForageListRequest) (*operationPb.SearchForageListResponse, error) {
  378. forage := make([]*model.Forage, 0)
  379. var count int64 = 0
  380. pref := s.DB.Model(new(model.Forage)).Where("is_delete = ?", operationPb.IsShow_OK)
  381. if req.Name != "" {
  382. pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
  383. }
  384. if req.CategoryId != "" {
  385. pref.Where("category_id = ?", req.CategoryId)
  386. }
  387. if req.ForageSourceId > 0 {
  388. pref.Where("forage_source_id = ?", req.ForageSourceId)
  389. }
  390. if req.IsShow > 0 {
  391. pref.Where("is_show = ?", req.IsShow)
  392. }
  393. if req.AllowError > 0 {
  394. pref.Where("allow_error = ?", req.AllowError)
  395. }
  396. if req.AllowError > 0 {
  397. pref.Where("allow_error = ?", req.AllowError)
  398. }
  399. if req.JumpWeight > 0 {
  400. pref.Where("jump_weight = ?", req.JumpWeight)
  401. }
  402. if req.JumpDelay > 0 {
  403. pref.Where("jump_delay = ?", req.JumpDelay)
  404. }
  405. if err := pref.Order("id desc").Count(&count).Limit(int(req.Pagination.PageSize)).Offset(int(req.Pagination.PageOffset)).
  406. Find(&forage).Error; err != nil {
  407. return nil, xerr.WithStack(err)
  408. }
  409. return &operationPb.SearchForageListResponse{
  410. Page: req.Pagination.Page,
  411. Total: int32(count),
  412. List: model.ForageSlice(forage).ToPB(),
  413. }, nil
  414. }
  415. func (s *StoreEntry) ForageEnumList(ctx context.Context) *operationPb.ForageEnumList {
  416. res := &operationPb.ForageEnumList{
  417. JumpDelaType: make([]*operationPb.JumpDelaTypeEnum, 0),
  418. ForageSource: make([]*operationPb.ForageSourceEnum, 0),
  419. ForagePlanType: make([]*operationPb.ForagePlanTypeEnum, 0),
  420. CattleParentCategory: make([]*operationPb.CattleParentCategoryEnum, 0),
  421. ForageParentCategory: make([]*operationPb.ForageParentCategoryEnum, 0),
  422. IsShow: make([]*operationPb.IsShowEnum, 0),
  423. }
  424. // operationPb.JumpDelaType_INVALID: "禁用",
  425. // operationPb.JumpDelaType_THREE: "3秒",
  426. // operationPb.JumpDelaType_SIX: "6秒",
  427. // operationPb.JumpDelaType_NINE: "9秒",
  428. res.JumpDelaType = append(res.JumpDelaType, &operationPb.JumpDelaTypeEnum{
  429. Value: operationPb.JumpDelaType_INVALID,
  430. Label: "禁用",
  431. }, &operationPb.JumpDelaTypeEnum{
  432. Value: operationPb.JumpDelaType_THREE,
  433. Label: "3秒",
  434. }, &operationPb.JumpDelaTypeEnum{
  435. Value: operationPb.JumpDelaType_SIX,
  436. Label: "6秒",
  437. })
  438. return res
  439. }
  440. func (s *StoreEntry) DeleteForageList(ctx context.Context, ids []int64) error {
  441. if len(ids) == 0 {
  442. return xerr.Custom("参数错误")
  443. }
  444. if err := s.DB.Where("id IN ?", ids).Update("is_delete", operationPb.IsShow_NO).Error; err != nil {
  445. return xerr.WithStack(err)
  446. }
  447. return nil
  448. }
  449. func (s *StoreEntry) IsShowForage(ctx context.Context, req *operationPb.IsShowForage) error {
  450. forage := &model.Forage{Id: int64(req.ForageId)}
  451. if err := s.DB.First(forage).Error; err != nil {
  452. if errors.Is(err, gorm.ErrRecordNotFound) {
  453. return xerr.Custom("该数据不存在")
  454. }
  455. return xerr.WithStack(err)
  456. }
  457. if err := s.DB.Model(new(model.Forage)).Where("id = ?", req.ForageId).Update("is_show", req.IsShow).Error; err != nil {
  458. return xerr.WithStack(err)
  459. }
  460. return nil
  461. }
  462. func (s *StoreEntry) ImportForage(ctx context.Context) error {
  463. return nil
  464. }
  465. func (s *StoreEntry) ExportForage(ctx *gin.Context, req *operationPb.SearchForageListRequest) error {
  466. res, err := s.SearchForageList(context.Background(), req)
  467. if err != nil {
  468. return xerr.WithStack(err)
  469. }
  470. if len(res.List) <= 0 {
  471. return nil
  472. }
  473. titleList := []string{
  474. "a",
  475. "b",
  476. "c",
  477. }
  478. data := make([]interface{}, 0)
  479. for _, v := range res.List {
  480. data = append(data, v)
  481. }
  482. return s.ExcelClient.ExportExcelByStruct(titleList, data, "demo", "sheet1", ctx)
  483. }