package com.cyksj.web.controller.group; import com.cyksj.common.constant.Constant; import com.cyksj.dto.Result; import com.cyksj.enums.GatewayResponse; import com.cyksj.mapper.GoodsDonSkuMapper; import com.cyksj.model.manage.views.GroupsRelationView; import com.cyksj.model.views.GroupsView; import com.ejlchina.searcher.BeanSearcher; import com.ejlchina.searcher.SearchResult; import com.ejlchina.searcher.util.MapUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import java.util.List; /** * @author chan * @date 2022/9/26 6:31 PM */ @Slf4j @RequestMapping("/applets/group") @RestController @RequiredArgsConstructor public class GroupController { private final HttpServletRequest request; private final BeanSearcher beanSearcher; private final GoodsDonSkuMapper goodsDonSkuMapper; @GetMapping("/get") public Result> get() { SearchResult search = beanSearcher.search(GroupsView.class, MapUtils.flatBuilder(request.getParameterMap()) .orderBy(GroupsView::getOrderBy).asc() .orderBy(GroupsView::getId).desc().build() ); search.getDataList().forEach((groupsView) -> { if (Constant.CHAT_GPT_SKU_IDS.contains(groupsView.getSkuId())) { List relationViewList = beanSearcher.searchAll(GroupsRelationView.class, MapUtils.builder() .field(GroupsRelationView::getGroupsId, groupsView.getId()) .orderBy(GroupsRelationView::getUpdate_time).desc() .build()); List all = null; //GPT 月付 暗改成20个 展示10个 if (groupsView.getSkuId().equals(Constant.CHAT_GPT_SKU_IDS.get(0))) { all = relationViewList.subList(0, 5); List after = relationViewList.subList(relationViewList.size() - 5, 20); all.addAll(after); } //GPT 4人月付暗改成6个 展示4个 if (groupsView.getSkuId().equals(Constant.CHAT_GPT_SKU_IDS.get(1))) { all = relationViewList.subList(0, 2); List after = relationViewList.subList(relationViewList.size() - 2, 6); all.addAll(after); } groupsView.setRelations(all); } else if (Constant.MIDJOURNEY_SKU_IDS.contains(groupsView.getSkuId()) && groupsView.getNum() == 15) { List relationViewList = beanSearcher.searchAll(GroupsRelationView.class, MapUtils.builder() .field(GroupsRelationView::getGroupsId, groupsView.getId()) .orderBy(GroupsRelationView::getUpdate_time).desc() .build()); List all = null; //MIDJOURNEY 月付5个 暗改15个 展示5个 if (groupsView.getSkuId().equals(Constant.MIDJOURNEY_SKU_IDS.get(0))) { all = relationViewList.subList(0, 5); List after = relationViewList.subList(relationViewList.size() - 1, 15); all.addAll(after); } //MIDJOURNEY 标准会员月付10个 暗改15个 展示10个 if (groupsView.getSkuId().equals(Constant.MIDJOURNEY_SKU_IDS.get(1)) || groupsView.getSkuId().equals(Constant.MIDJOURNEY_SKU_IDS.get(2))) { all = relationViewList.subList(0, 5); List after = relationViewList.subList(relationViewList.size() - 5, 15); all.addAll(after); } groupsView.setRelations(all); } else { groupsView.setRelations(beanSearcher.searchAll(GroupsRelationView.class, MapUtils.builder().field(GroupsRelationView::getGroupsId, groupsView.getId()).build())); } }); return GatewayResponse.SUCCESS.newBuilder().toResult(search); } }