pasture_service.go 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  1. package backend
  2. import (
  3. "bytes"
  4. "context"
  5. "errors"
  6. "fmt"
  7. "io"
  8. "kpt-tmr-group/model"
  9. "kpt-tmr-group/pkg/logger/zaplog"
  10. "kpt-tmr-group/pkg/tool"
  11. "kpt-tmr-group/pkg/xerr"
  12. operationPb "kpt-tmr-group/proto/go/backend/operation"
  13. "net/http"
  14. "strconv"
  15. "sync"
  16. "go.uber.org/zap"
  17. "github.com/xuri/excelize/v2"
  18. "gorm.io/gorm"
  19. )
  20. // CreateGroupPasture 创建集团牧场
  21. func (s *StoreEntry) CreateGroupPasture(ctx context.Context, req *operationPb.AddPastureRequest) error {
  22. // 账号同步牧场端
  23. groupPasture := model.NewGroupPasture(req)
  24. if err := s.DB.Create(groupPasture).Error; err != nil {
  25. return xerr.WithStack(err)
  26. }
  27. if err := s.PastureAccountDistribution(ctx, groupPasture); err != nil {
  28. s.DB.Model(new(model.GroupPasture)).Where("id = ?", groupPasture.Id).Update("is_delete", operationPb.IsShow_NO)
  29. return xerr.WithStack(err)
  30. } else {
  31. s.DB.Model(new(model.GroupPasture)).Where("id = ?", groupPasture.Id).Update("is_distribution", operationPb.IsShow_OK)
  32. }
  33. return nil
  34. }
  35. // PastureAccountDistribution 账号同步牧场端
  36. func (s *StoreEntry) PastureAccountDistribution(ctx context.Context, groupPasture *model.GroupPasture) error {
  37. if groupPasture.Domain == "" {
  38. return nil
  39. }
  40. body := &model.AccountDistribution{
  41. Account: groupPasture.Account,
  42. UserName: groupPasture.ManagerUser,
  43. Password: groupPasture.Password,
  44. Phone: groupPasture.ManagerPhone,
  45. PastureId: int32(groupPasture.Id),
  46. PastureName: groupPasture.Name,
  47. Address: groupPasture.Address,
  48. }
  49. res := &model.PastureCommonResponse{}
  50. if err := s.PastureHttpClient(ctx, model.PastureAccountDistributionURl, groupPasture.Id, body, res); err != nil {
  51. zaplog.Error("AccountDistribution", zap.Any("url", model.PastureAccountDistributionURl), zap.Any("err", err), zap.Any("body", body), zap.Any("res", res))
  52. return xerr.WithStack(err)
  53. }
  54. if res.Code != http.StatusOK {
  55. if err := s.DB.Model(new(model.GroupPasture)).Where("id = ?", groupPasture.Id).Update("is_distribution", operationPb.IsShow_OK).Error; err != nil {
  56. zaplog.Error("AccountDistribution-Update", zap.Any("url", model.PastureAccountDistributionURl), zap.Any("err", err), zap.Any("body", body), zap.Any("res", res))
  57. return xerr.Customf("%s", res.Msg)
  58. }
  59. }
  60. return nil
  61. }
  62. func (s *StoreEntry) FindGroupPastureListByIds(ctx context.Context, pastureIds []int32) ([]*model.GroupPasture, error) {
  63. groupPastureList := make([]*model.GroupPasture, 0)
  64. if err := s.DB.Model(new(model.GroupPasture)).Where("is_delete = ? ", operationPb.IsShow_OK).
  65. Where("id IN ?", pastureIds).
  66. Find(&groupPastureList).Error; err != nil {
  67. return nil, xerr.WithStack(err)
  68. }
  69. return groupPastureList, nil
  70. }
  71. func (s *StoreEntry) GetGroupPastureListById(ctx context.Context, pastureId int64) (*model.GroupPasture, error) {
  72. groupPasture := &model.GroupPasture{
  73. Id: int64(pastureId),
  74. }
  75. if err := s.DB.Model(new(model.GroupPasture)).Where("is_delete = ? ", operationPb.IsShow_OK).
  76. First(&groupPasture).Error; err != nil {
  77. return nil, xerr.WithStack(err)
  78. }
  79. return groupPasture, nil
  80. }
  81. // EditGroupPasture 创建集团牧场
  82. func (s *StoreEntry) EditGroupPasture(ctx context.Context, req *operationPb.AddPastureRequest) error {
  83. groupPasture := &model.GroupPasture{Id: int64(req.Id)}
  84. if err := s.DB.First(groupPasture).Error; err != nil {
  85. if errors.Is(err, gorm.ErrRecordNotFound) {
  86. return xerr.Custom("该数据不存在!")
  87. }
  88. return xerr.WithStack(err)
  89. }
  90. updateData := &model.GroupPasture{
  91. Name: req.Name,
  92. Account: req.Account,
  93. ManagerUser: req.ManagerUser,
  94. ManagerPhone: req.ManagerPhone,
  95. Address: req.Address,
  96. Domain: req.Domain,
  97. }
  98. if err := s.DB.Model(new(model.GroupPasture)).Omit("is_show", "password").
  99. Where("id = ?", req.Id).
  100. Updates(updateData).Error; err != nil {
  101. return xerr.WithStack(err)
  102. }
  103. return nil
  104. }
  105. // SearchGroupPastureList 查询牧场列表
  106. func (s *StoreEntry) SearchGroupPastureList(ctx context.Context, req *operationPb.SearchPastureRequest) (*operationPb.SearchPastureResponse, error) {
  107. groupPasture := make([]*model.GroupPasture, 0)
  108. var count int64 = 0
  109. pref := s.DB.Model(new(model.GroupPasture)).Where("is_delete = ? ", operationPb.IsShow_OK)
  110. if req.Name != "" {
  111. pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
  112. }
  113. if req.ManagerPhone != "" {
  114. pref.Where("manager_phone like ?", fmt.Sprintf("%s%s%s", "%", req.ManagerPhone, "%"))
  115. }
  116. if req.ManagerUser != "" {
  117. pref.Where("manager_user like ?", fmt.Sprintf("%s%s%s", "%", req.ManagerUser, "%"))
  118. }
  119. if req.StartTime > 0 && req.EndTime > 0 && req.EndTime >= req.StartTime {
  120. pref.Where("created_at BETWEEN ? AND ? ", req.StartTime, req.EndTime)
  121. }
  122. if err := pref.Order("id desc").Count(&count).Limit(int(req.Pagination.PageSize)).Offset(int(req.Pagination.PageOffset)).
  123. Find(&groupPasture).Error; err != nil {
  124. return nil, xerr.WithStack(err)
  125. }
  126. return &operationPb.SearchPastureResponse{
  127. Code: http.StatusOK,
  128. Msg: "ok",
  129. Data: &operationPb.SearchPastureData{
  130. Page: req.Pagination.Page,
  131. Total: int32(count),
  132. PageSize: req.Pagination.PageSize,
  133. List: model.GroupPastureSlice(groupPasture).ToPB(),
  134. },
  135. }, nil
  136. }
  137. func (s *StoreEntry) GroupPastureList(ctx context.Context) ([]*model.GroupPasture, error) {
  138. groupPastureList := make([]*model.GroupPasture, 0)
  139. if err := s.DB.Model(new(model.GroupPasture)).Where("is_delete = ? ", operationPb.IsShow_OK).Find(&groupPastureList).Error; err != nil {
  140. return nil, xerr.WithStack(err)
  141. }
  142. return groupPastureList, nil
  143. }
  144. func (s *StoreEntry) DeleteGroupPasture(ctx context.Context, pastureId int64) error {
  145. groupPasture := &model.GroupPasture{
  146. Id: pastureId,
  147. }
  148. if err := s.DB.First(groupPasture).Error; err != nil {
  149. if errors.Is(err, gorm.ErrRecordNotFound) {
  150. return xerr.Custom("该数据不存在")
  151. }
  152. return xerr.WithStack(err)
  153. }
  154. if err := s.DB.Model(groupPasture).Update("is_delete", operationPb.IsShow_NO).Error; err != nil {
  155. return xerr.WithStack(err)
  156. }
  157. return nil
  158. }
  159. func (s *StoreEntry) ResetPasswordGroupPasture(ctx context.Context, pastureId int64) error {
  160. groupPasture := &model.GroupPasture{
  161. Id: pastureId,
  162. }
  163. if err := s.DB.Where("is_delete = ?", operationPb.IsShow_OK).First(groupPasture).Error; err != nil {
  164. if errors.Is(err, gorm.ErrRecordNotFound) {
  165. return xerr.Custom("该数据不存在")
  166. }
  167. return xerr.WithStack(err)
  168. }
  169. if err := s.DB.Model(groupPasture).Update("password", tool.Md5String(model.InitManagerPassword)).Error; err != nil {
  170. return xerr.WithStack(err)
  171. }
  172. return nil
  173. }
  174. func (s *StoreEntry) IsShowGroupPasture(ctx context.Context, req *operationPb.IsShowGroupPasture) error {
  175. groupPasture := &model.GroupPasture{
  176. Id: int64(req.PastureId),
  177. }
  178. if err := s.DB.First(groupPasture).Error; err != nil {
  179. if errors.Is(err, gorm.ErrRecordNotFound) {
  180. return xerr.Custom("该数据不存在")
  181. }
  182. return xerr.WithStack(err)
  183. }
  184. if err := s.DB.Model(groupPasture).Where("is_delete = ?", operationPb.IsShow_OK).Update("is_show", req.IsShow).Error; err != nil {
  185. return xerr.WithStack(err)
  186. }
  187. return nil
  188. }
  189. // AddCattleCategory 添加畜牧分类
  190. func (s *StoreEntry) AddCattleCategory(ctx context.Context, req *operationPb.AddCattleCategoryRequest) error {
  191. cattleCategory := model.NewCattleCategory(req)
  192. if err := s.DB.Create(cattleCategory).Error; err != nil {
  193. return xerr.WithStack(err)
  194. } else {
  195. body := &model.CategoryRequest{
  196. ParentId: int32(req.ParentId),
  197. ParentName: req.ParentName,
  198. Name: req.Name,
  199. Id: int32(req.Id),
  200. Number: req.Number,
  201. IsShow: int32(req.IsShow),
  202. GroupId: int32(cattleCategory.Id),
  203. }
  204. if err = s.CategoryDistribution(ctx, model.CattleCategoryDistributionURl, body); err != nil {
  205. zaplog.Error("AddCattleCategory", zap.Any("CategoryDistribution", err))
  206. }
  207. }
  208. return nil
  209. }
  210. // EditCattleCategory 编辑畜牧分类
  211. func (s *StoreEntry) EditCattleCategory(ctx context.Context, req *operationPb.AddCattleCategoryRequest) error {
  212. cattleCategory := &model.CattleCategory{Id: int64(req.Id)}
  213. if err := s.DB.First(cattleCategory).Error; err != nil {
  214. if errors.Is(err, gorm.ErrRecordNotFound) {
  215. return xerr.Custom("该数据不存在")
  216. }
  217. return xerr.WithStack(err)
  218. }
  219. updateData := &model.CattleCategory{
  220. ParentName: req.ParentName,
  221. Name: req.Name,
  222. Number: req.Number,
  223. ParentId: req.ParentId,
  224. }
  225. if err := s.DB.Model(new(model.CattleCategory)).Omit("is_show", "is_delete").
  226. Where("id = ?", req.Id).
  227. Updates(updateData).Error; err != nil {
  228. return xerr.WithStack(err)
  229. } else {
  230. body := &model.CategoryRequest{
  231. ParentId: int32(req.ParentId),
  232. ParentName: req.ParentName,
  233. Name: req.Name,
  234. Id: int32(req.Id),
  235. Number: req.Number,
  236. IsShow: int32(req.IsShow),
  237. GroupId: int32(req.Id),
  238. }
  239. if err = s.CategoryDistribution(ctx, model.CattleCategoryDistributionURl, body); err != nil {
  240. zaplog.Error("EditCattleCategory", zap.Any("CategoryDistribution", err))
  241. }
  242. }
  243. return nil
  244. }
  245. // IsShowCattleCategory 是否启用
  246. func (s *StoreEntry) IsShowCattleCategory(ctx context.Context, req *operationPb.IsShowCattleCategory) error {
  247. cattleCategory := &model.CattleCategory{Id: int64(req.CattleCategoryId)}
  248. if err := s.DB.First(cattleCategory).Error; err != nil {
  249. if errors.Is(err, gorm.ErrRecordNotFound) {
  250. return xerr.Custom("该数据不存在")
  251. }
  252. return xerr.WithStack(err)
  253. }
  254. if err := s.DB.Model(new(model.CattleCategory)).Where("id = ?", req.CattleCategoryId).Update("is_show", req.IsShow).Error; err != nil {
  255. return xerr.WithStack(err)
  256. } else {
  257. body := &model.CategoryRequest{
  258. ParentId: int32(cattleCategory.ParentId),
  259. ParentName: cattleCategory.ParentName,
  260. Name: cattleCategory.Name,
  261. Id: req.CattleCategoryId,
  262. Number: cattleCategory.Number,
  263. IsShow: int32(req.IsShow),
  264. GroupId: int32(cattleCategory.Id),
  265. }
  266. if err = s.CategoryDistribution(ctx, model.CattleCategoryDistributionURl, body); err != nil {
  267. zaplog.Error("IsShowCattleCategory", zap.Any("CategoryDistribution", err), zap.Any("body", body))
  268. }
  269. }
  270. return nil
  271. }
  272. // DeleteCattleCategory 是否删除
  273. func (s *StoreEntry) DeleteCattleCategory(ctx context.Context, cattleCategoryId int64) error {
  274. cattleCategory := &model.CattleCategory{Id: cattleCategoryId}
  275. if err := s.DB.First(cattleCategory).Error; err != nil {
  276. if errors.Is(err, gorm.ErrRecordNotFound) {
  277. return xerr.Custom("该数据不存在")
  278. }
  279. return xerr.WithStack(err)
  280. }
  281. if err := s.DB.Model(new(model.CattleCategory)).Where("id = ?", cattleCategoryId).Update("is_delete", operationPb.IsShow_NO).Error; err != nil {
  282. return xerr.WithStack(err)
  283. } else {
  284. body := &model.CategoryDeleteRequest{
  285. GroupId: int32(cattleCategory.Id),
  286. IsDelete: int32(operationPb.IsShow_OK),
  287. }
  288. if err = s.CategoryDelete(ctx, model.CattleCategoryDeleteURl, body); err != nil {
  289. zaplog.Error("DeleteCattleCategory", zap.Any("CategoryDelete", err), zap.Any("body", body))
  290. }
  291. }
  292. return nil
  293. }
  294. // SearchCattleCategoryList 牧畜分类类别列表
  295. func (s *StoreEntry) SearchCattleCategoryList(ctx context.Context, req *operationPb.SearchCattleCategoryRequest) (*operationPb.SearchCattleCategoryResponse, error) {
  296. cattleCategory := make([]*model.CattleCategory, 0)
  297. var count int64 = 0
  298. pref := s.DB.Model(new(model.CattleCategory)).Where("is_delete = ?", operationPb.IsShow_OK)
  299. if req.Name != "" {
  300. pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
  301. }
  302. if req.ParentId > 0 {
  303. pref.Where("parent_id = ?", req.ParentId)
  304. }
  305. if req.IsShow > 0 {
  306. pref.Where("is_show = ?", req.IsShow)
  307. }
  308. if err := pref.Order("id desc").Count(&count).Limit(int(req.Pagination.PageSize)).Offset(int(req.Pagination.PageOffset)).
  309. Find(&cattleCategory).Debug().Error; err != nil {
  310. return nil, xerr.WithStack(err)
  311. }
  312. return &operationPb.SearchCattleCategoryResponse{
  313. Code: http.StatusOK,
  314. Msg: "ok",
  315. Data: &operationPb.SearchCattleCategoryData{
  316. Page: req.Pagination.Page,
  317. PageSize: req.Pagination.PageSize,
  318. Total: int32(count),
  319. List: model.CattleCategorySlice(cattleCategory).ToPB(),
  320. },
  321. }, nil
  322. }
  323. // AddForageCategory 添加饲料分类
  324. func (s *StoreEntry) AddForageCategory(ctx context.Context, req *operationPb.AddForageCategoryRequest) error {
  325. forageCategory := model.NewForageCategory(req)
  326. if err := s.DB.Create(forageCategory).Error; err != nil {
  327. return xerr.WithStack(err)
  328. } else {
  329. body := &model.CategoryRequest{
  330. ParentId: int32(req.ParentId),
  331. ParentName: req.ParentName,
  332. Name: req.Name,
  333. Id: int32(req.Id),
  334. Number: req.Number,
  335. IsShow: int32(req.IsShow),
  336. GroupId: int32(forageCategory.Id),
  337. }
  338. if err = s.CategoryDistribution(ctx, model.ForageCategoryDistributionURl, body); err != nil {
  339. zaplog.Error("AddForageCategory", zap.Any("CategoryDistribution", err), zap.Any("body", body))
  340. }
  341. }
  342. return nil
  343. }
  344. // EditForageCategory 编辑饲料分类
  345. func (s *StoreEntry) EditForageCategory(ctx context.Context, req *operationPb.AddForageCategoryRequest) error {
  346. forageCategory := &model.ForageCategory{Id: int64(req.Id)}
  347. if err := s.DB.First(forageCategory).Error; err != nil {
  348. if errors.Is(err, gorm.ErrRecordNotFound) {
  349. return xerr.Custom("该数据不存在")
  350. }
  351. return xerr.WithStack(err)
  352. }
  353. updateData := &model.ForageCategory{
  354. ParentName: req.ParentName,
  355. Name: req.Name,
  356. Number: req.Number,
  357. ParentId: req.ParentId,
  358. }
  359. if err := s.DB.Model(new(model.ForageCategory)).Omit("is_show", "is_delete").
  360. Where("id = ?", req.Id).
  361. Updates(updateData).Error; err != nil {
  362. return xerr.WithStack(err)
  363. } else {
  364. body := &model.CategoryRequest{
  365. ParentId: int32(req.ParentId),
  366. ParentName: req.ParentName,
  367. Name: req.Name,
  368. Id: int32(req.Id),
  369. Number: req.Number,
  370. IsShow: int32(req.IsShow),
  371. GroupId: int32(req.Id),
  372. }
  373. if err = s.CategoryDistribution(ctx, model.ForageCategoryDistributionURl, body); err != nil {
  374. zaplog.Error("EditForageCategory", zap.Any("CategoryDistribution", err), zap.Any("body", body))
  375. }
  376. }
  377. return nil
  378. }
  379. // IsShowForageCategory 是否启用
  380. func (s *StoreEntry) IsShowForageCategory(ctx context.Context, req *operationPb.IsShowForageCategory) error {
  381. forageCategory := &model.ForageCategory{Id: int64(req.ForageCategoryId)}
  382. if err := s.DB.First(forageCategory).Error; err != nil {
  383. if errors.Is(err, gorm.ErrRecordNotFound) {
  384. return xerr.Custom("该数据不存在")
  385. }
  386. return xerr.WithStack(err)
  387. }
  388. if err := s.DB.Model(new(model.ForageCategory)).Where("id = ?", req.ForageCategoryId).Update("is_show", req.IsShow).Error; err != nil {
  389. return xerr.WithStack(err)
  390. } else {
  391. body := &model.CategoryRequest{
  392. ParentId: int32(forageCategory.ParentId),
  393. ParentName: forageCategory.ParentName,
  394. Name: forageCategory.Name,
  395. Id: req.ForageCategoryId,
  396. Number: forageCategory.Number,
  397. IsShow: int32(req.IsShow),
  398. GroupId: int32(forageCategory.Id),
  399. }
  400. if err = s.CategoryDistribution(ctx, model.ForageCategoryDistributionURl, body); err != nil {
  401. zaplog.Error("IsShowForageCategory", zap.Any("CategoryDistribution", err), zap.Any("body", body))
  402. }
  403. }
  404. return nil
  405. }
  406. // DeleteForageCategory 是否删除
  407. func (s *StoreEntry) DeleteForageCategory(ctx context.Context, forageCategoryId int64) error {
  408. forageCategory := &model.ForageCategory{Id: forageCategoryId}
  409. if err := s.DB.First(forageCategory).Error; err != nil {
  410. if errors.Is(err, gorm.ErrRecordNotFound) {
  411. return xerr.Custom("该数据不存在")
  412. }
  413. return xerr.WithStack(err)
  414. }
  415. if err := s.DB.Model(new(model.ForageCategory)).Where("id = ?", forageCategoryId).Update("is_delete", operationPb.IsShow_NO).Error; err != nil {
  416. return xerr.WithStack(err)
  417. } else {
  418. body := &model.CategoryDeleteRequest{
  419. GroupId: int32(forageCategory.Id),
  420. IsDelete: int32(operationPb.IsShow_OK),
  421. }
  422. if err = s.CategoryDelete(ctx, model.CattleCategoryDeleteURl, body); err != nil {
  423. zaplog.Error("DeleteForageCategory", zap.Any("CategoryDelete", err), zap.Any("body", body))
  424. }
  425. }
  426. return nil
  427. }
  428. // SearchForageCategoryList 饲料分类类别列表
  429. func (s *StoreEntry) SearchForageCategoryList(ctx context.Context, req *operationPb.SearchForageCategoryRequest) (*operationPb.SearchForageCategoryResponse, error) {
  430. forageCategory := make([]*model.ForageCategory, 0)
  431. var count int64 = 0
  432. pref := s.DB.Model(new(model.ForageCategory)).Where("is_delete = ?", operationPb.IsShow_OK)
  433. if req.Name != "" {
  434. pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
  435. }
  436. if req.ParentId > 0 {
  437. pref.Where("parent_id = ?", req.ParentId)
  438. }
  439. if req.Number != "" {
  440. pref.Where("number like ?", fmt.Sprintf("%s%s%s", "%", req.Number, "%"))
  441. }
  442. if req.IsShow > 0 {
  443. pref.Where("is_show = ?", req.IsShow)
  444. }
  445. if err := pref.Order("id desc").Count(&count).Limit(int(req.Pagination.PageSize)).Offset(int(req.Pagination.PageOffset)).
  446. Find(&forageCategory).Debug().Error; err != nil {
  447. return nil, xerr.WithStack(err)
  448. }
  449. return &operationPb.SearchForageCategoryResponse{
  450. Code: http.StatusOK,
  451. Msg: "ok",
  452. Data: &operationPb.SearchForageCategoryData{
  453. Page: req.Pagination.Page,
  454. PageSize: req.Pagination.PageSize,
  455. Total: int32(count),
  456. List: model.ForageCategorySlice(forageCategory).ToPB(),
  457. },
  458. }, nil
  459. }
  460. // CategoryDistribution 饲料分类和畜牧分类下发
  461. func (s *StoreEntry) CategoryDistribution(ctx context.Context, url string, req *model.CategoryRequest) error {
  462. groupList, err := s.GroupPastureList(ctx)
  463. if err != nil {
  464. return xerr.WithStack(err)
  465. }
  466. wg := sync.WaitGroup{}
  467. wg.Add(len(groupList))
  468. for _, v := range groupList {
  469. go func(data *model.GroupPasture) {
  470. res := &model.PastureCommonResponse{}
  471. req.PastureId = int32(data.Id)
  472. if err = s.PastureHttpClient(ctx, url, int64(data.Id), req, res); err != nil {
  473. zaplog.Error("CategoryDistribution",
  474. zap.Any("url", url),
  475. zap.Any("err", err),
  476. zap.Any("body", req),
  477. zap.Any("res", res),
  478. )
  479. }
  480. if res.Code != http.StatusOK {
  481. zaplog.Error("CategoryDistribution-http",
  482. zap.Any("url", url),
  483. zap.Any("body", req),
  484. zap.Any("res", res),
  485. )
  486. }
  487. wg.Done()
  488. }(v)
  489. }
  490. wg.Wait()
  491. return nil
  492. }
  493. // CategoryDelete 饲料分类和畜牧分类删除
  494. func (s *StoreEntry) CategoryDelete(ctx context.Context, url string, req *model.CategoryDeleteRequest) error {
  495. groupList, err := s.GroupPastureList(ctx)
  496. if err != nil {
  497. return xerr.WithStack(err)
  498. }
  499. wg := sync.WaitGroup{}
  500. wg.Add(len(groupList))
  501. for _, v := range groupList {
  502. go func(data *model.GroupPasture) {
  503. res := &model.PastureCommonResponse{}
  504. req.PastureId = int32(data.Id)
  505. if err = s.PastureHttpClient(ctx, url, int64(data.Id), req, res); err != nil {
  506. zaplog.Error("CategoryDistribution",
  507. zap.Any("url", url),
  508. zap.Any("err", err),
  509. zap.Any("body", req),
  510. zap.Any("res", res),
  511. )
  512. }
  513. if res.Code != http.StatusOK {
  514. zaplog.Error("CategoryDistribution-http",
  515. zap.Any("url", url),
  516. zap.Any("body", req),
  517. zap.Any("res", res),
  518. )
  519. }
  520. wg.Done()
  521. }(v)
  522. }
  523. wg.Wait()
  524. return nil
  525. }
  526. // CreateForage 创建饲料
  527. func (s *StoreEntry) CreateForage(ctx context.Context, req *operationPb.AddForageRequest) error {
  528. forage := model.NewForage(req)
  529. if err := s.DB.Create(forage).Error; err != nil {
  530. return xerr.WithStack(err)
  531. }
  532. return nil
  533. }
  534. // EditForage 编辑饲料
  535. func (s *StoreEntry) EditForage(ctx context.Context, req *operationPb.AddForageRequest) error {
  536. forage := model.Forage{Id: int64(req.Id)}
  537. if err := s.DB.Where("is_delete = ?", operationPb.IsShow_OK).First(&forage).Error; err != nil {
  538. if errors.Is(err, gorm.ErrRecordNotFound) {
  539. return xerr.Custom("该数据不存在")
  540. }
  541. return xerr.WithStack(err)
  542. }
  543. updateData := &model.Forage{
  544. Name: req.Name,
  545. CategoryId: int64(req.CategoryId),
  546. CategoryName: req.CategoryName,
  547. MaterialType: req.MaterialType,
  548. UniqueEncode: req.UniqueEncode,
  549. ForageSourceId: req.ForageSourceId,
  550. PlanTypeId: req.PlanTypeId,
  551. SmallMaterialScale: req.SmallMaterialScale,
  552. AllowError: int64(req.AllowError),
  553. PackageWeight: int64(req.PackageWeight),
  554. Price: int64(req.Price),
  555. JumpWeight: int64(req.JumpWeight),
  556. JumpDelay: req.JumpDelay,
  557. ConfirmStart: req.ConfirmStart,
  558. RelayLocations: int64(req.RelayLocations),
  559. Jmp: req.Jmp,
  560. Backup1: req.Backup1,
  561. Backup2: req.Backup2,
  562. Backup3: req.Backup3,
  563. }
  564. if err := s.DB.Model(new(model.Forage)).Omit("is_show", "is_delete").Where("id = ?", req.Id).
  565. Updates(updateData).Error; err != nil {
  566. return xerr.WithStack(err)
  567. }
  568. return nil
  569. }
  570. func (s *StoreEntry) SearchForageList(ctx context.Context, req *operationPb.SearchForageListRequest) (*operationPb.SearchForageListResponse, error) {
  571. forage := make([]*model.Forage, 0)
  572. var count int64 = 0
  573. pref := s.DB.Model(new(model.Forage)).Where("is_delete = ?", operationPb.IsShow_OK)
  574. if req.Name != "" {
  575. pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
  576. }
  577. if req.CategoryId > 0 {
  578. pref.Where("category_id = ?", req.CategoryId)
  579. }
  580. if req.ForageSourceId > 0 {
  581. pref.Where("forage_source_id = ?", req.ForageSourceId)
  582. }
  583. if req.IsShow > 0 {
  584. pref.Where("is_show = ?", req.IsShow)
  585. }
  586. if req.AllowError > 0 {
  587. pref.Where("allow_error = ?", req.AllowError)
  588. }
  589. if req.JumpWeight > 0 {
  590. pref.Where("jump_weight = ?", req.JumpWeight)
  591. }
  592. if req.JumpDelay > 0 {
  593. pref.Where("jump_delay = ?", req.JumpDelay)
  594. }
  595. if err := pref.Order("sort").Count(&count).Limit(int(req.Pagination.PageSize)).Offset(int(req.Pagination.PageOffset)).
  596. Find(&forage).Error; err != nil {
  597. return nil, xerr.WithStack(err)
  598. }
  599. return &operationPb.SearchForageListResponse{
  600. Code: http.StatusOK,
  601. Msg: "ok",
  602. Data: &operationPb.SearchForageList{
  603. Page: req.Pagination.Page,
  604. PageSize: req.Pagination.PageSize,
  605. Total: int32(count),
  606. List: model.ForageSlice(forage).ToPB(),
  607. },
  608. }, nil
  609. }
  610. func (s *StoreEntry) ForageListSort(ctx context.Context, req *operationPb.ForageListSortRequest) error {
  611. for _, v := range req.List {
  612. if err := s.DB.Model(new(model.Forage)).Select("sort").Where("id = ?", v.Id).Updates(map[string]interface{}{
  613. "sort": v.Sort,
  614. }).Error; err != nil {
  615. zaplog.Error("ForageListSort", zap.Any("err", err), zap.Any("id", v.Id), zap.Any("sort", v.Sort))
  616. }
  617. }
  618. return nil
  619. }
  620. func (s *StoreEntry) ForageEnumList(ctx context.Context) *operationPb.ForageEnumListResponse {
  621. res := &operationPb.ForageEnumListResponse{
  622. Code: http.StatusOK,
  623. Msg: "ok",
  624. Data: &operationPb.ForageEnumList{
  625. JumpDelaType: make([]*operationPb.JumpDelaTypeEnum, 0),
  626. ForageSource: make([]*operationPb.ForageSourceEnum, 0),
  627. ForagePlanType: make([]*operationPb.ForagePlanTypeEnum, 0),
  628. CattleParentCategory: make([]*operationPb.CattleParentCategoryEnum, 0),
  629. ForageParentCategory: make([]*operationPb.ForageParentCategoryEnum, 0),
  630. IsShow: make([]*operationPb.IsShowEnum, 0),
  631. FormulaType: make([]*operationPb.FormulaTypeEnum, 0),
  632. FormulaList: make([]*operationPb.FormulaOptionEnum, 0),
  633. ConfirmStart: make([]*operationPb.IsShowEnum, 0),
  634. FormulationEvaluation: make([]*operationPb.FormulaOptionEnum, 0),
  635. UseMaterialsType: make([]*operationPb.FormulaOptionEnum, 0),
  636. UseMaterialsList: make([]*operationPb.FormulaOptionEnum, 0),
  637. PriceMaterialsType: make([]*operationPb.FormulaOptionEnum, 0),
  638. },
  639. }
  640. // 跳转延迟
  641. res.Data.JumpDelaType = append(res.Data.JumpDelaType, &operationPb.JumpDelaTypeEnum{
  642. Value: operationPb.JumpDelaType_INVALID,
  643. Label: "禁用",
  644. }, &operationPb.JumpDelaTypeEnum{
  645. Value: operationPb.JumpDelaType_THREE,
  646. Label: "3秒",
  647. }, &operationPb.JumpDelaTypeEnum{
  648. Value: operationPb.JumpDelaType_SIX,
  649. Label: "6秒",
  650. })
  651. // 饲料来源
  652. res.Data.ForageSource = append(res.Data.ForageSource, &operationPb.ForageSourceEnum{
  653. Value: operationPb.ForageSource_SYSTEM_BUILT_IN,
  654. Label: "系统内置",
  655. }, &operationPb.ForageSourceEnum{
  656. Value: operationPb.ForageSource_USER_DEFINED,
  657. Label: "用户自定义",
  658. })
  659. // 计划类型
  660. res.Data.ForagePlanType = append(res.Data.ForagePlanType,
  661. &operationPb.ForagePlanTypeEnum{
  662. Value: operationPb.ForagePlanType_INVALID,
  663. Label: "无",
  664. },
  665. &operationPb.ForagePlanTypeEnum{
  666. Value: operationPb.ForagePlanType_FORKLIFT,
  667. Label: "铲车",
  668. }, &operationPb.ForagePlanTypeEnum{
  669. Value: operationPb.ForagePlanType_CONCENTRATE,
  670. Label: "精料",
  671. })
  672. // 畜牧类别
  673. res.Data.CattleParentCategory = append(res.Data.CattleParentCategory, &operationPb.CattleParentCategoryEnum{
  674. Value: operationPb.CattleCategoryParent_LACTATION_CAW,
  675. Label: "泌乳牛",
  676. }, &operationPb.CattleParentCategoryEnum{
  677. Value: operationPb.CattleCategoryParent_FATTEN_CAW,
  678. Label: "育肥牛",
  679. }, &operationPb.CattleParentCategoryEnum{
  680. Value: operationPb.CattleCategoryParent_RESERVE_CAW,
  681. Label: "后备牛",
  682. }, &operationPb.CattleParentCategoryEnum{
  683. Value: operationPb.CattleCategoryParent_DRY_CAW,
  684. Label: "干奶牛",
  685. }, &operationPb.CattleParentCategoryEnum{
  686. Value: operationPb.CattleCategoryParent_PERINATAL_CAW,
  687. Label: "围产牛",
  688. }, &operationPb.CattleParentCategoryEnum{
  689. Value: operationPb.CattleCategoryParent_OTHER_CAW,
  690. Label: "其他",
  691. })
  692. // 饲料类别
  693. res.Data.ForageParentCategory = append(res.Data.ForageParentCategory, &operationPb.ForageParentCategoryEnum{
  694. Value: operationPb.ForageCategoryParent_ROUGHAGE,
  695. Label: "粗料",
  696. }, &operationPb.ForageParentCategoryEnum{
  697. Value: operationPb.ForageCategoryParent_CONCENTRATE,
  698. Label: "精料",
  699. }, &operationPb.ForageParentCategoryEnum{
  700. Value: operationPb.ForageCategoryParent_HALF_ROUGHAGE_HALF_CONCENTRATE,
  701. Label: "粗料精料参半",
  702. }, &operationPb.ForageParentCategoryEnum{
  703. Value: operationPb.ForageCategoryParent_OTHER,
  704. Label: "其他",
  705. })
  706. res.Data.IsShow = append(res.Data.IsShow, &operationPb.IsShowEnum{
  707. Value: operationPb.IsShow_OK,
  708. Label: "是",
  709. }, &operationPb.IsShowEnum{
  710. Value: operationPb.IsShow_NO,
  711. Label: "否",
  712. })
  713. res.Data.FormulationEvaluation = append(res.Data.FormulationEvaluation, &operationPb.FormulaOptionEnum{
  714. Value: 0,
  715. Label: "按配方查询",
  716. }, &operationPb.FormulaOptionEnum{
  717. Value: 1,
  718. Label: "按栏舍查询",
  719. })
  720. res.Data.FormulaType = append(res.Data.FormulaType, &operationPb.FormulaTypeEnum{
  721. Value: operationPb.FormulaType_FEED_FORMULA,
  722. Label: "饲喂配方",
  723. }, &operationPb.FormulaTypeEnum{
  724. Value: operationPb.FormulaType_PREMIXED_FORMULA,
  725. Label: "预混配方",
  726. }, &operationPb.FormulaTypeEnum{
  727. Value: operationPb.FormulaType_SUPPLEMENTARY_FORMULA,
  728. Label: "补料配方",
  729. })
  730. res.Data.ConfirmStart = append(res.Data.ConfirmStart, &operationPb.IsShowEnum{
  731. Value: operationPb.IsShow_OK,
  732. Label: "启用",
  733. }, &operationPb.IsShowEnum{
  734. Value: operationPb.IsShow_NO,
  735. Label: "禁用",
  736. })
  737. res.Data.UseMaterialsList = append(res.Data.UseMaterialsList, &operationPb.FormulaOptionEnum{
  738. Value: 1,
  739. Label: "理论",
  740. }, &operationPb.FormulaOptionEnum{
  741. Value: 2,
  742. Label: "实际",
  743. })
  744. res.Data.PriceMaterialsType = append(res.Data.PriceMaterialsType, &operationPb.FormulaOptionEnum{
  745. Value: 1,
  746. Label: "畜牧类别",
  747. }, &operationPb.FormulaOptionEnum{
  748. Value: 2,
  749. Label: "栏舍名称",
  750. }, &operationPb.FormulaOptionEnum{
  751. Value: 3,
  752. Label: "日期",
  753. }, &operationPb.FormulaOptionEnum{
  754. Value: 4,
  755. Label: "TMR设备号",
  756. })
  757. res.Data.UseMaterialsType = append(res.Data.PriceMaterialsType, &operationPb.FormulaOptionEnum{
  758. Value: 5,
  759. Label: "TMR班次",
  760. }, &operationPb.FormulaOptionEnum{
  761. Value: 6,
  762. Label: "车次",
  763. })
  764. res.Data.JumpType = append(res.Data.JumpType, &operationPb.FormulaOptionEnum{
  765. Value: 0,
  766. Label: "手动跳转",
  767. }, &operationPb.FormulaOptionEnum{
  768. Value: 1,
  769. Label: "自动跳转",
  770. })
  771. res.Data.StatisticsType = append(res.Data.StatisticsType, &operationPb.FormulaOptionEnum{
  772. Value: 7,
  773. Label: "无分类",
  774. }, &operationPb.FormulaOptionEnum{
  775. Value: 0,
  776. Label: "驾驶员",
  777. }, &operationPb.FormulaOptionEnum{
  778. Value: 1,
  779. Label: "配方名称",
  780. }, &operationPb.FormulaOptionEnum{
  781. Value: 2,
  782. Label: "栏舍名称",
  783. }, &operationPb.FormulaOptionEnum{
  784. Value: 3,
  785. Label: "牧畜类别",
  786. }, &operationPb.FormulaOptionEnum{
  787. Value: 4,
  788. Label: "车次",
  789. }, &operationPb.FormulaOptionEnum{
  790. Value: 5,
  791. Label: "TMR名称",
  792. }, &operationPb.FormulaOptionEnum{
  793. Value: 6,
  794. Label: "饲料",
  795. })
  796. res.Data.FormulaList = append(res.Data.FormulaList, &operationPb.FormulaOptionEnum{
  797. Value: 0,
  798. Label: "所有",
  799. })
  800. formulaList := make([]*model.FeedFormula, 0)
  801. if err := s.DB.Where("is_delete = ?", operationPb.IsShow_OK).Find(&formulaList).Error; err != nil {
  802. zaplog.Error("OptionFormula", zap.Any("Err", err))
  803. return res
  804. }
  805. for _, v := range formulaList {
  806. res.Data.FormulaList = append(res.Data.FormulaList, &operationPb.FormulaOptionEnum{
  807. Value: int32(v.Id),
  808. Label: v.Name,
  809. })
  810. }
  811. return res
  812. }
  813. func (s *StoreEntry) DeleteForageList(ctx context.Context, ids []int64) error {
  814. if len(ids) == 0 {
  815. return xerr.Custom("参数错误")
  816. }
  817. if err := s.DB.Model(new(model.Forage)).Where("id IN ?", ids).Update("is_delete", operationPb.IsShow_NO).Error; err != nil {
  818. return xerr.WithStack(err)
  819. }
  820. return nil
  821. }
  822. func (s *StoreEntry) IsShowForage(ctx context.Context, req *operationPb.IsShowForage) error {
  823. forage := &model.Forage{Id: int64(req.ForageId)}
  824. if err := s.DB.First(forage).Error; err != nil {
  825. if errors.Is(err, gorm.ErrRecordNotFound) {
  826. return xerr.Custom("该数据不存在")
  827. }
  828. return xerr.WithStack(err)
  829. }
  830. if err := s.DB.Model(new(model.Forage)).Where("id = ?", req.ForageId).Update("is_show", req.IsShow).Error; err != nil {
  831. return xerr.WithStack(err)
  832. }
  833. return nil
  834. }
  835. // ExcelImportForage 导入excel
  836. func (s *StoreEntry) ExcelImportForage(ctx context.Context, req io.Reader) error {
  837. xlsx, err := excelize.OpenReader(req)
  838. if err != nil {
  839. return xerr.WithStack(err)
  840. }
  841. defer xlsx.Close()
  842. rows, err := xlsx.GetRows(xlsx.GetSheetName(xlsx.GetActiveSheetIndex()))
  843. if err != nil {
  844. return xerr.WithStack(err)
  845. }
  846. if len(rows) > 10000 {
  847. rows = rows[:10000]
  848. }
  849. forageList := make([]*model.Forage, 0)
  850. for i, row := range rows {
  851. if i == 0 {
  852. continue
  853. }
  854. var (
  855. forageSourceId int32
  856. categoryId, price, jumpWeight, relayLocations int
  857. allowError, packageWeight int
  858. name, uniqueEncode, backup1, backup2, backup3 string
  859. )
  860. for k, v := range row {
  861. if k == 0 {
  862. name = v
  863. }
  864. if k == 2 {
  865. uniqueEncode = v
  866. }
  867. if k == 3 {
  868. forageSourceId = operationPb.ForageSource_Kind_value[v]
  869. }
  870. if k == 5 {
  871. allowError, _ = strconv.Atoi(v)
  872. }
  873. if k == 6 {
  874. packageWeight, _ = strconv.Atoi(v)
  875. }
  876. if k == 7 {
  877. price, _ = strconv.Atoi(v)
  878. }
  879. if k == 8 {
  880. jumpWeight, _ = strconv.Atoi(v)
  881. }
  882. if k == 11 {
  883. relayLocations, _ = strconv.Atoi(v)
  884. }
  885. if k == 13 {
  886. backup1 = v
  887. }
  888. if k == 14 {
  889. backup2 = v
  890. }
  891. if k == 15 {
  892. backup3 = v
  893. }
  894. }
  895. forageItem := &model.Forage{
  896. Name: name,
  897. CategoryId: int64(categoryId),
  898. MaterialType: 0,
  899. UniqueEncode: uniqueEncode,
  900. ForageSourceId: operationPb.ForageSource_Kind(forageSourceId),
  901. PlanTypeId: 0,
  902. SmallMaterialScale: "",
  903. AllowError: int64(allowError),
  904. PackageWeight: int64(packageWeight),
  905. Price: int64(price),
  906. JumpWeight: int64(jumpWeight),
  907. JumpDelay: 0,
  908. ConfirmStart: 0,
  909. RelayLocations: int64(relayLocations),
  910. Jmp: 0,
  911. Backup1: backup1,
  912. Backup2: backup2,
  913. Backup3: backup3,
  914. IsShow: operationPb.IsShow_OK,
  915. IsDelete: operationPb.IsShow_OK,
  916. DataSource: operationPb.DataSource_EXCEL_IMPORT,
  917. }
  918. forageList = append(forageList, forageItem)
  919. }
  920. if len(forageList) > 0 {
  921. if err = s.DB.Create(forageList).Error; err != nil {
  922. return xerr.WithStack(err)
  923. }
  924. }
  925. return nil
  926. }
  927. // ExcelExportForage 流式导出excel
  928. func (s *StoreEntry) ExcelExportForage(ctx context.Context, req *operationPb.SearchForageListRequest) (*bytes.Buffer, error) {
  929. res, err := s.SearchForageList(ctx, req)
  930. if err != nil {
  931. return nil, xerr.WithStack(err)
  932. }
  933. if len(res.Data.List) <= 0 {
  934. return nil, xerr.Custom("数据为空")
  935. }
  936. file := excelize.NewFile()
  937. defer file.Close()
  938. streamWriter, err := file.NewStreamWriter(model.DefaultSheetName)
  939. if err != nil {
  940. return nil, xerr.WithStack(err)
  941. }
  942. titles := []interface{}{"饲料名称", "饲料分类", "唯一编码", "饲料来源", "计划类型", "允许误差(kg)", "包装单位重量(kg)",
  943. "单价", "跳转重量域(kg)", "跳转延迟", "确认开始", "继电器位置", "无上域", "备用字段01", "备用字段02", "备用字段03"}
  944. if err = streamWriter.SetRow("A1", titles); err != nil {
  945. return nil, xerr.WithStack(err)
  946. }
  947. for i, item := range res.Data.List {
  948. cell, err := excelize.CoordinatesToCellName(1, i+2)
  949. if err != nil {
  950. zaplog.Error("excelize.CoordinatesToCellName", zap.Any("Err", err))
  951. continue
  952. }
  953. row := make([]interface{}, 0)
  954. row = append(row, item.Name, item.CategoryName, item.UniqueEncode, item.ForageSourceId, item.PlanTypeId,
  955. item.AllowError, item.PackageWeight, float64(item.Price/100.00), item.JumpWeight, item.JumpDelay,
  956. item.ConfirmStart, item.RelayLocations, item.Jmp, item.Backup1, item.Backup2, item.Backup3)
  957. if err = streamWriter.SetRow(cell, row); err != nil {
  958. return nil, xerr.WithStack(err)
  959. }
  960. }
  961. if err = streamWriter.Flush(); err != nil {
  962. return nil, xerr.WithStack(err)
  963. }
  964. return file.WriteToBuffer()
  965. }
  966. // ExcelTemplateForage 导出模板
  967. func (s *StoreEntry) ExcelTemplateForage(ctx context.Context) (*bytes.Buffer, error) {
  968. file := excelize.NewFile()
  969. defer file.Close()
  970. streamWriter, err := file.NewStreamWriter("Sheet1")
  971. if err != nil {
  972. return nil, xerr.WithStack(err)
  973. }
  974. titles := []interface{}{"饲料名称", "饲料分类", "唯一编码", "饲料来源", "计划类型", "允许误差(kg)", "包装单位重量(kg)",
  975. "单价", "跳转重量域(kg)", "跳转延迟", "确认开始", "继电器位置", "无上域", "备用字段01", "备用字段02", "备用字段03"}
  976. if err = streamWriter.SetRow("A1", titles); err != nil {
  977. return nil, xerr.WithStack(err)
  978. }
  979. if err = streamWriter.Flush(); err != nil {
  980. return nil, xerr.WithStack(err)
  981. }
  982. return file.WriteToBuffer()
  983. }
  984. func (s *StoreEntry) SmallMaterial(ctx context.Context, req *operationPb.SmallMaterialRequest) (*model.PastureCommonResponse, error) {
  985. body := &model.PastureCommonRequest{
  986. Name: req.ApiName,
  987. ReturnType: "Map",
  988. ParamMaps: &model.FormulaEstimateParams{
  989. PastureId: fmt.Sprintf("%d", req.PastureId),
  990. ImforName: req.InfoName,
  991. },
  992. }
  993. response := &model.PastureCommonResponse{Data: &model.PastureCommonData{}}
  994. if err := s.PastureHttpClient(ctx, model.UrlDataByName, int64(req.PastureId), body, response); err != nil {
  995. return nil, xerr.WithStack(err)
  996. }
  997. return response, nil
  998. }