feed_service.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. package backend
  2. import (
  3. "bytes"
  4. "context"
  5. "encoding/json"
  6. "errors"
  7. "fmt"
  8. "io"
  9. "kpt-tmr-group/model"
  10. "kpt-tmr-group/pkg/logger/zaplog"
  11. "kpt-tmr-group/pkg/xerr"
  12. operationPb "kpt-tmr-group/proto/go/backend/operation"
  13. "net/http"
  14. "strconv"
  15. "sync"
  16. "time"
  17. "go.uber.org/multierr"
  18. "github.com/xuri/excelize/v2"
  19. "go.uber.org/zap"
  20. "gorm.io/gorm"
  21. )
  22. const EncodeNumberPrefix = "encode_number"
  23. var PastureDataLogType = map[string]int32{
  24. "FeedFormula_Distribute": 1,
  25. "FeedFormula_IsModify": 2,
  26. "FeedFormula_Cancel_Distribute": 3,
  27. }
  28. // CreateFeedFormula 添加数据
  29. func (s *StoreEntry) CreateFeedFormula(ctx context.Context, req *operationPb.AddFeedFormulaRequest) error {
  30. forage := model.NewFeedFormula(req)
  31. if err := s.DB.Create(forage).Error; err != nil {
  32. return xerr.WithStack(err)
  33. }
  34. return nil
  35. }
  36. // EditFeedFormula 编辑数据
  37. func (s *StoreEntry) EditFeedFormula(ctx context.Context, req *operationPb.AddFeedFormulaRequest) error {
  38. forage := model.FeedFormula{Id: int64(req.Id)}
  39. if err := s.DB.Where("is_delete = ?", operationPb.IsShow_OK).First(&forage).Error; err != nil {
  40. if errors.Is(err, gorm.ErrRecordNotFound) {
  41. return xerr.Custom("该数据不存在")
  42. }
  43. return xerr.WithStack(err)
  44. }
  45. updateData := &model.FeedFormula{
  46. Name: req.Name,
  47. Colour: req.Colour,
  48. CattleCategoryId: req.CattleCategoryId,
  49. CattleCategoryName: req.CattleCategoryName,
  50. FormulaTypeId: req.FormulaTypeId,
  51. FormulaTypeName: req.FormulaTypeName,
  52. DataSourceId: req.DataSourceId,
  53. DataSourceName: req.DataSourceName,
  54. Remarks: req.Remarks,
  55. IsShow: req.IsShow,
  56. }
  57. if err := s.DB.Model(new(model.FeedFormula)).
  58. Omit("is_show", "is_delete", "encode_number", "formula_type_id", "formula_type_name", "data_source", "version", "is_modify").
  59. Where("id = ?", req.Id).
  60. Updates(updateData).Error; err != nil {
  61. return xerr.WithStack(err)
  62. }
  63. return nil
  64. }
  65. // SearchFeedFormulaList 查询数据列表
  66. func (s *StoreEntry) SearchFeedFormulaList(ctx context.Context, req *operationPb.SearchFeedFormulaRequest) (*operationPb.SearchFeedFormulaListResponse, error) {
  67. feedFormula := make([]*model.FeedFormula, 0)
  68. var count int64 = 0
  69. pref := s.DB.Model(new(model.FeedFormula)).Where("is_delete = ?", operationPb.IsShow_OK)
  70. if req.Name != "" {
  71. pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
  72. }
  73. if req.CattleCategoryId > 0 {
  74. pref.Where("cattle_category_id = ?", req.CattleCategoryId)
  75. }
  76. if req.FormulaTypeId > 0 {
  77. pref.Where("formula_type_id = ?", req.FormulaTypeId)
  78. }
  79. if req.IsShow > 0 {
  80. pref.Where("is_show = ?", req.IsShow)
  81. }
  82. if req.DataSource > 0 {
  83. pref.Where("data_source = ?", req.DataSource)
  84. }
  85. if req.Remarks != "" {
  86. pref.Where("remarks = ?", req.Remarks)
  87. }
  88. if err := pref.Order("id desc").Count(&count).Limit(int(req.Pagination.PageSize)).Offset(int(req.Pagination.PageOffset)).
  89. Find(&feedFormula).Error; err != nil {
  90. return nil, xerr.WithStack(err)
  91. }
  92. return &operationPb.SearchFeedFormulaListResponse{
  93. Code: http.StatusOK,
  94. Msg: "ok",
  95. Data: &operationPb.SearchFeedFormulaListData{
  96. Page: req.Pagination.Page,
  97. PageSize: req.Pagination.PageSize,
  98. Total: int32(count),
  99. List: model.FeedFormulaSlice(feedFormula).ToPB(),
  100. },
  101. }, nil
  102. }
  103. // IsShowFeedFormula 是否启用和是否可修改
  104. func (s *StoreEntry) IsShowFeedFormula(ctx context.Context, req *operationPb.IsShowModifyFeedFormula) error {
  105. feedFormula := &model.FeedFormula{Id: int64(req.FeedFormulaId)}
  106. if err := s.DB.First(feedFormula).Error; err != nil {
  107. if errors.Is(err, gorm.ErrRecordNotFound) {
  108. return xerr.Custom("该数据不存在")
  109. }
  110. return xerr.WithStack(err)
  111. }
  112. if req.EditType == 1 {
  113. if err := s.DB.Model(new(model.FeedFormula)).Where("id = ?", req.FeedFormulaId).Update("is_show", req.IsShow).Error; err != nil {
  114. return xerr.WithStack(err)
  115. }
  116. }
  117. if req.EditType == 2 {
  118. if err := s.DB.Model(new(model.FeedFormula)).Where("id = ?", req.FeedFormulaId).Update("is_modify", req.IsShow).Error; err != nil {
  119. return xerr.WithStack(err)
  120. } else {
  121. s.PastureFeedFormulaIsModify(ctx, req.FeedFormulaId, req.IsShow)
  122. }
  123. }
  124. return nil
  125. }
  126. // DeleteFeedFormula 是否删除
  127. func (s *StoreEntry) DeleteFeedFormula(ctx context.Context, feedFormulaId int64) error {
  128. feedFormula := &model.FeedFormula{Id: feedFormulaId}
  129. if err := s.DB.First(feedFormula).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(new(model.FeedFormula)).Where("id = ?", feedFormula.Id).Update("is_delete", operationPb.IsShow_NO).Error; err != nil {
  136. return xerr.WithStack(err)
  137. }
  138. return nil
  139. }
  140. // ExcelImportFeedFormula 导入excel
  141. func (s *StoreEntry) ExcelImportFeedFormula(ctx context.Context, req io.Reader) error {
  142. xlsx, err := excelize.OpenReader(req)
  143. if err != nil {
  144. return xerr.WithStack(err)
  145. }
  146. defer xlsx.Close()
  147. rows, err := xlsx.GetRows(xlsx.GetSheetName(xlsx.GetActiveSheetIndex()))
  148. if err != nil {
  149. return xerr.WithStack(err)
  150. }
  151. if len(rows) > 10000 {
  152. rows = rows[:10000]
  153. }
  154. feedFormulaList := make([]*model.FeedFormula, 0)
  155. for i, row := range rows {
  156. if i == 0 {
  157. continue
  158. }
  159. var (
  160. name, encodeNumber, cattleCategoryName, formulaTypeName, dataSourceName, remarks, isShowStr string
  161. isShow operationPb.IsShow_Kind
  162. )
  163. for k, v := range row {
  164. if k == 0 {
  165. name = v
  166. }
  167. if k == 1 {
  168. encodeNumber = v
  169. }
  170. if k == 2 {
  171. cattleCategoryName = v
  172. }
  173. if k == 3 {
  174. formulaTypeName = v
  175. }
  176. if k == 4 {
  177. dataSourceName = v
  178. }
  179. if k == 5 {
  180. remarks = v
  181. }
  182. if k == 6 {
  183. isShowStr = v
  184. }
  185. }
  186. if isShowStr == "是" {
  187. isShow = operationPb.IsShow_OK
  188. } else {
  189. isShow = operationPb.IsShow_NO
  190. }
  191. feedFormulaItem := &model.FeedFormula{
  192. Name: name,
  193. EncodeNumber: encodeNumber,
  194. CattleCategoryName: cattleCategoryName,
  195. FormulaTypeName: formulaTypeName,
  196. Remarks: remarks,
  197. IsShow: isShow,
  198. IsDelete: operationPb.IsShow_OK,
  199. DataSourceId: operationPb.DataSource_EXCEL_IMPORT,
  200. DataSourceName: dataSourceName,
  201. }
  202. feedFormulaList = append(feedFormulaList, feedFormulaItem)
  203. }
  204. if len(feedFormulaList) > 0 {
  205. if err = s.DB.Create(feedFormulaList).Error; err != nil {
  206. return xerr.WithStack(err)
  207. }
  208. }
  209. return nil
  210. }
  211. // ExcelExportFeedFormula 流式导出excel
  212. func (s *StoreEntry) ExcelExportFeedFormula(ctx context.Context, req *operationPb.SearchFeedFormulaRequest) (*bytes.Buffer, error) {
  213. res, err := s.SearchFeedFormulaList(ctx, req)
  214. if err != nil {
  215. return nil, xerr.WithStack(err)
  216. }
  217. if len(res.Data.List) <= 0 {
  218. return nil, xerr.Custom("数据为空")
  219. }
  220. file := excelize.NewFile()
  221. defer file.Close()
  222. streamWriter, err := file.NewStreamWriter("Sheet1")
  223. if err != nil {
  224. return nil, xerr.WithStack(err)
  225. }
  226. titles := []interface{}{"配方名称", "配方编码", "畜牧类别", "配方类别", "来源", "备注", "是否启用",
  227. "饲料组", "饲料名称", "重量(kg)", "搅拌延迟(min)", "是否锁定牛头数比例", "顺序"}
  228. if err = streamWriter.SetRow("A1", titles); err != nil {
  229. return nil, xerr.WithStack(err)
  230. }
  231. for i, item := range res.Data.List {
  232. cell, err := excelize.CoordinatesToCellName(1, i+2)
  233. if err != nil {
  234. zaplog.Error("excelize.CoordinatesToCellName", zap.Any("Err", err))
  235. continue
  236. }
  237. row := make([]interface{}, 0)
  238. row = append(row, item.Name, item.EncodeNumber, item.CattleCategoryName, item.FormulaTypeName, item.DataSourceName,
  239. item.Remarks, item.IsShow)
  240. if err = streamWriter.SetRow(cell, row); err != nil {
  241. return nil, xerr.WithStack(err)
  242. }
  243. }
  244. if err = streamWriter.Flush(); err != nil {
  245. return nil, xerr.WithStack(err)
  246. }
  247. return file.WriteToBuffer()
  248. }
  249. // ExcelTemplateFeedFormula 导出模板
  250. func (s *StoreEntry) ExcelTemplateFeedFormula(ctx context.Context) (*bytes.Buffer, error) {
  251. file := excelize.NewFile()
  252. defer file.Close()
  253. streamWriter, err := file.NewStreamWriter("Sheet1")
  254. if err != nil {
  255. return nil, xerr.WithStack(err)
  256. }
  257. titles := []interface{}{"配方名称", "配方编码", "畜牧类别", "配方类别", "来源", "备注", "是否启用",
  258. "饲料组", "饲料名称", "重量(kg)", "搅拌延迟(min)", "是否锁定牛头数比例", "顺序"}
  259. if err = streamWriter.SetRow("A1", titles); err != nil {
  260. return nil, xerr.WithStack(err)
  261. }
  262. if err = streamWriter.Flush(); err != nil {
  263. return nil, xerr.WithStack(err)
  264. }
  265. return file.WriteToBuffer()
  266. }
  267. // EncodeNumber 配方编码
  268. func (s *StoreEntry) EncodeNumber(ctx context.Context) string {
  269. currTime := time.Now().Format(model.LayoutDate)
  270. prefix := fmt.Sprintf("%s_%s", EncodeNumberPrefix, currTime)
  271. data := &model.UniqueData{}
  272. if err := s.DB.Order("id desc").Where("prefix = ?", prefix).First(data).Error; err != nil {
  273. if !errors.Is(err, gorm.ErrRecordNotFound) {
  274. return ""
  275. }
  276. ud, _ := strconv.Atoi(currTime)
  277. result := ud*100 + 1
  278. newData := &model.UniqueData{
  279. Prefix: prefix,
  280. Data: int64(result),
  281. }
  282. if err = s.DB.Create(newData).Error; err != nil {
  283. zaplog.Error("EncodeNumber Create", zap.Any("data", newData), zap.Any("Err", err))
  284. return ""
  285. }
  286. return fmt.Sprintf("%d", newData.Data)
  287. }
  288. data.Data += 1
  289. if err := s.DB.Model(new(model.UniqueData)).Where("prefix = ?", prefix).Update("data", data.Data).Error; err != nil {
  290. return ""
  291. } else {
  292. return fmt.Sprintf("%d", data.Data)
  293. }
  294. }
  295. // DistributeFeedFormula 配方下发牧场
  296. func (s *StoreEntry) DistributeFeedFormula(ctx context.Context, req *operationPb.DistributeFeedFormulaRequest) error {
  297. distributeData, err := s.checkoutDistributeData(ctx, req)
  298. if err != nil {
  299. return xerr.WithStack(err)
  300. }
  301. wg := sync.WaitGroup{}
  302. wg.Add(len(distributeData.PastureList))
  303. var muError error
  304. for _, pasture := range distributeData.PastureList {
  305. go func(p *model.GroupPasture) {
  306. defer wg.Done()
  307. // 过滤已下发的
  308. body := make([]*model.FeedFormula, 0)
  309. for _, v := range distributeData.FeedFormulaList {
  310. if ok := s.checkoutDistributeLog(ctx, p.Id, v.Id); !ok {
  311. body = append(body, v)
  312. }
  313. }
  314. if len(body) <= 0 {
  315. return
  316. }
  317. request := &model.DistributeFeedFormulaRequest{
  318. PastureId: p.Id,
  319. Body: body,
  320. }
  321. response := &model.PastureResponse{}
  322. defer func() {
  323. if response.Code == http.StatusOK {
  324. s.DB.Create(model.NewFeedFormulaDistributeLogList(distributeData.FeedFormulaList, p.Id, p.Name, operationPb.IsShow_OK))
  325. } else {
  326. muError = multierr.Append(muError, xerr.Custom(response.Msg))
  327. }
  328. }()
  329. if _, err = s.PastureHttpClient(ctx, model.FeedFormulaDistributeUrl, p.Id, request, response); err != nil {
  330. muError = multierr.Append(muError, err)
  331. zaplog.Error("DistributeFeedFormula", zap.Any("pasture", p), zap.Any("body", distributeData.FeedFormulaList), zap.Any("err", err), zap.Any("response", response))
  332. b, _ := json.Marshal(request)
  333. res, _ := json.Marshal(response)
  334. pastureDataLog := model.NewPastureDataLog(p.Id, PastureDataLogType["FeedFormula_Distribute"], model.FeedFormulaDistributeUrl, string(b), string(res))
  335. s.DB.Create(pastureDataLog)
  336. }
  337. }(pasture)
  338. }
  339. wg.Wait()
  340. return muError
  341. }
  342. // CancelDistributeFeedFormula 取消配方下发牧场
  343. func (s *StoreEntry) CancelDistributeFeedFormula(ctx context.Context, req *operationPb.DistributeFeedFormulaRequest) error {
  344. distributeData, err := s.checkoutDistributeData(ctx, req)
  345. if err != nil {
  346. return xerr.WithStack(err)
  347. }
  348. wg := sync.WaitGroup{}
  349. wg.Add(len(distributeData.PastureList))
  350. var muError error
  351. for _, pasture := range distributeData.PastureList {
  352. go func(p *model.GroupPasture) {
  353. defer wg.Done()
  354. pastureDataId := make([]int64, 0)
  355. for _, v := range distributeData.FeedFormulaList {
  356. if v.PastureId == p.Id {
  357. pastureDataId = append(pastureDataId, v.PastureDataId)
  358. }
  359. }
  360. if len(pastureDataId) <= 0 {
  361. return
  362. }
  363. request := &model.CancelDistributeFeedFormulaRequest{
  364. PastureId: p.Id,
  365. PastureDataId: pastureDataId,
  366. }
  367. response := &model.PastureResponse{}
  368. if _, err = s.PastureHttpClient(ctx, model.FeedFormulaCancelDistributeUrl, p.Id, request, response); err != nil {
  369. zaplog.Error("DistributeFeedFormula", zap.Any("pasture", p), zap.Any("body", distributeData.FeedFormulaList), zap.Any("err", err), zap.Any("response", response))
  370. b, _ := json.Marshal(request)
  371. res, _ := json.Marshal(response)
  372. pastureDataLog := model.NewPastureDataLog(p.Id, PastureDataLogType["FeedFormula_Cancel_Distribute"], model.FeedFormulaCancelDistributeUrl, string(b), string(res))
  373. s.DB.Create(pastureDataLog)
  374. }
  375. }(pasture)
  376. }
  377. wg.Wait()
  378. return muError
  379. }
  380. // EditRecodeFeedFormula 配方修改记录
  381. func (s *StoreEntry) EditRecodeFeedFormula(ctx context.Context, req *operationPb.EditRecodeFeedFormulaRequest) (*operationPb.EditRecodeFeedFormulaResponse, error) {
  382. return nil, nil
  383. }
  384. // FeedFormulaUsage 配方使用概况
  385. func (s *StoreEntry) FeedFormulaUsage(ctx context.Context, req *operationPb.FeedFormulaUsageRequest) (*operationPb.FeedFormulaUsageResponse, error) {
  386. feedFormulaDistributeLogList := make([]*model.FeedFormulaDistributeLog, 0)
  387. if err := s.DB.Model(new(model.FeedFormulaDistributeLog)).
  388. Where("feed_formula_id = ?", req.FeedFormulaId).
  389. Where("is_show = ?", operationPb.IsShow_OK).Group("pasture_id").
  390. Find(&feedFormulaDistributeLogList).Error; err != nil {
  391. return nil, xerr.WithStack(err)
  392. }
  393. res := &operationPb.FeedFormulaUsageResponse{
  394. Code: http.StatusOK,
  395. Msg: "ok",
  396. Data: make([]*operationPb.FeedFormulaUsageList, 0),
  397. }
  398. wg := sync.WaitGroup{}
  399. wg.Add(len(feedFormulaDistributeLogList))
  400. for _, list := range feedFormulaDistributeLogList {
  401. go func(l *model.FeedFormulaDistributeLog) {
  402. defer wg.Done()
  403. groupDetail, err := s.PastureDetailById(ctx, l.PastureId)
  404. if err != nil {
  405. zaplog.Error("FeedFormulaUsage", zap.Any("PastureDetailById", err))
  406. return
  407. }
  408. req.PastureId = int32(groupDetail.PastureId)
  409. response := &operationPb.PastureFeedFormulaUsageResponse{}
  410. if _, err = s.PastureHttpClient(ctx, model.FeedUsageURl, groupDetail.Id, req, response); err != nil {
  411. zaplog.Error("FeedFormulaUsage", zap.Any("PastureDetailById", err))
  412. return
  413. }
  414. if response.Code == http.StatusOK {
  415. data := &operationPb.FeedFormulaUsageList{
  416. PastureId: int32(groupDetail.Id),
  417. PastureName: groupDetail.Name,
  418. MixedFodderAccurateRatio: response.Data.MixedFodderAccurateRatio,
  419. MixedFodderCorrectRatio: response.Data.MixedFodderCorrectRatio,
  420. SprinkleFodderAccurateRatio: response.Data.SprinkleFodderAccurateRatio,
  421. SprinkleFodderCorrectRatio: response.Data.SprinkleFodderCorrectRatio,
  422. AddFeedTime: response.Data.AddFeedTime,
  423. SprinkleTime: response.Data.SprinkleTime,
  424. StirTime: response.Data.StirTime,
  425. LastEditTime: response.Data.LastEditTime,
  426. }
  427. res.Data = append(res.Data, data)
  428. } else {
  429. zaplog.Error("FeedFormulaUsage-http", zap.Any("response", response))
  430. return
  431. }
  432. }(list)
  433. }
  434. wg.Wait()
  435. return res, nil
  436. }
  437. func (s *StoreEntry) PastureFeedFormulaIsModify(ctx context.Context, feedFormulaId int32, isModify operationPb.IsShow_Kind) {
  438. feedFormulaDistributeLogList := make([]*model.FeedFormulaDistributeLog, 0)
  439. if err := s.DB.Where("is_show = ?", operationPb.IsShow_OK).
  440. Where("feed_formula_id = ?", feedFormulaId).
  441. Group("pasture_id").Find(&feedFormulaDistributeLogList).Error; err != nil {
  442. zaplog.Error("PastureFeedFormulaIsModify", zap.Any("err", err), zap.Any("feed_formula_id", feedFormulaId))
  443. return
  444. }
  445. for _, v := range feedFormulaDistributeLogList {
  446. response := &model.PastureResponse{}
  447. request := &model.FeedFormulaIsModifyRequest{
  448. PastureId: v.PastureId,
  449. FeedFormulaId: v.FeedFormulaId,
  450. IsModify: int32(isModify),
  451. }
  452. if _, err := s.PastureHttpClient(ctx, model.FeedFormulaIsModifyUrl, v.Id, request, response); err != nil {
  453. zaplog.Error("PastureFeedFormulaIsModify", zap.Any("request", request), zap.Any("err", err), zap.Any("response", response))
  454. b, _ := json.Marshal(request)
  455. res, _ := json.Marshal(response)
  456. pastureDataLog := model.NewPastureDataLog(v.PastureId, PastureDataLogType["FeedFormula_IsModify"], model.FeedFormulaIsModifyUrl, string(b), string(res))
  457. s.DB.Create(pastureDataLog)
  458. }
  459. }
  460. }
  461. func (s *StoreEntry) checkoutDistributeData(ctx context.Context, req *operationPb.DistributeFeedFormulaRequest) (*model.DistributeData, error) {
  462. result := &model.DistributeData{
  463. PastureList: make([]*model.GroupPasture, 0),
  464. FeedFormulaList: make([]*model.FeedFormula, 0),
  465. }
  466. if err := s.DB.Where("id IN ?", req.PastureIds).Where("is_delete = ?", operationPb.IsShow_OK).Find(&result.PastureList).Error; err != nil {
  467. return result, xerr.WithStack(err)
  468. }
  469. if err := s.DB.Where("id IN ?", req.FeedFormulaIds).Find(&result.FeedFormulaList).Error; err != nil {
  470. return result, xerr.WithStack(err)
  471. }
  472. if len(result.PastureList) <= 0 || len(result.FeedFormulaList) <= 0 {
  473. return result, xerr.Customf("数据错误")
  474. }
  475. return result, nil
  476. }
  477. func (s *StoreEntry) checkoutDistributeLog(ctx context.Context, pastureId, feedFormulaId int64) bool {
  478. res := &model.FeedFormulaDistributeLog{}
  479. if err := s.DB.Model(new(model.FeedFormulaDistributeLog)).Where("feed_formula_id = ?", feedFormulaId).
  480. Where("pasture_id = ?", pastureId).Where("is_show = ?", operationPb.IsShow_OK).First(res).Error; err != nil {
  481. return false
  482. }
  483. if res.IsShow == operationPb.IsShow_OK {
  484. return true
  485. }
  486. return false
  487. }