GroupController.java 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package com.cyksj.web.controller.group;
  2. import com.cyksj.common.constant.Constant;
  3. import com.cyksj.dto.Result;
  4. import com.cyksj.enums.GatewayResponse;
  5. import com.cyksj.mapper.GoodsDonSkuMapper;
  6. import com.cyksj.model.manage.views.GroupsRelationView;
  7. import com.cyksj.model.views.GroupsView;
  8. import com.ejlchina.searcher.BeanSearcher;
  9. import com.ejlchina.searcher.SearchResult;
  10. import com.ejlchina.searcher.util.MapUtils;
  11. import lombok.RequiredArgsConstructor;
  12. import lombok.extern.slf4j.Slf4j;
  13. import org.springframework.web.bind.annotation.GetMapping;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RestController;
  16. import javax.servlet.http.HttpServletRequest;
  17. import java.util.List;
  18. /**
  19. * @author chan
  20. * @date 2022/9/26 6:31 PM
  21. */
  22. @Slf4j
  23. @RequestMapping("/applets/group")
  24. @RestController
  25. @RequiredArgsConstructor
  26. public class GroupController {
  27. private final HttpServletRequest request;
  28. private final BeanSearcher beanSearcher;
  29. private final GoodsDonSkuMapper goodsDonSkuMapper;
  30. @GetMapping("/get")
  31. public Result<SearchResult<GroupsView>> get() {
  32. SearchResult<GroupsView> search = beanSearcher.search(GroupsView.class, MapUtils.flatBuilder(request.getParameterMap())
  33. .orderBy(GroupsView::getOrderBy).asc()
  34. .orderBy(GroupsView::getId).desc().build()
  35. );
  36. search.getDataList().forEach((groupsView) -> {
  37. if (Constant.CHAT_GPT_SKU_IDS.contains(groupsView.getSkuId())) {
  38. List<GroupsRelationView> relationViewList = beanSearcher.searchAll(GroupsRelationView.class, MapUtils.builder()
  39. .field(GroupsRelationView::getGroupsId, groupsView.getId())
  40. .orderBy(GroupsRelationView::getUpdate_time).desc()
  41. .build());
  42. List<GroupsRelationView> all = null;
  43. //GPT 月付 暗改成20个 展示10个
  44. if (groupsView.getSkuId().equals(Constant.CHAT_GPT_SKU_IDS.get(0))) {
  45. all = relationViewList.subList(0, 5);
  46. List<GroupsRelationView> after = relationViewList.subList(relationViewList.size() - 5, 20);
  47. all.addAll(after);
  48. }
  49. //GPT 4人月付暗改成6个 展示4个
  50. if (groupsView.getSkuId().equals(Constant.CHAT_GPT_SKU_IDS.get(1))) {
  51. all = relationViewList.subList(0, 2);
  52. List<GroupsRelationView> after = relationViewList.subList(relationViewList.size() - 2, 6);
  53. all.addAll(after);
  54. }
  55. groupsView.setRelations(all);
  56. } else if (Constant.MIDJOURNEY_SKU_IDS.contains(groupsView.getSkuId()) && groupsView.getNum() == 15) {
  57. List<GroupsRelationView> relationViewList = beanSearcher.searchAll(GroupsRelationView.class, MapUtils.builder()
  58. .field(GroupsRelationView::getGroupsId, groupsView.getId())
  59. .orderBy(GroupsRelationView::getUpdate_time).desc()
  60. .build());
  61. List<GroupsRelationView> all = null;
  62. //MIDJOURNEY 月付5个 暗改15个 展示5个
  63. if (groupsView.getSkuId().equals(Constant.MIDJOURNEY_SKU_IDS.get(0))) {
  64. all = relationViewList.subList(0, 5);
  65. List<GroupsRelationView> after = relationViewList.subList(relationViewList.size() - 1, 15);
  66. all.addAll(after);
  67. }
  68. //MIDJOURNEY 标准会员月付10个 暗改15个 展示10个
  69. if (groupsView.getSkuId().equals(Constant.MIDJOURNEY_SKU_IDS.get(1)) || groupsView.getSkuId().equals(Constant.MIDJOURNEY_SKU_IDS.get(2))) {
  70. all = relationViewList.subList(0, 5);
  71. List<GroupsRelationView> after = relationViewList.subList(relationViewList.size() - 5, 15);
  72. all.addAll(after);
  73. }
  74. groupsView.setRelations(all);
  75. } else {
  76. groupsView.setRelations(beanSearcher.searchAll(GroupsRelationView.class, MapUtils.builder().field(GroupsRelationView::getGroupsId, groupsView.getId()).build()));
  77. }
  78. });
  79. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  80. }
  81. }