pasture_service.go 35 KB

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