Quellcode durchsuchen

fix 后台订单列表查询优化

zoujiajian vor 2 Jahren
Ursprung
Commit
4ef3588d7c

+ 3 - 0
netflix-dao/src/main/java/com/cyksj/mapper/GroupsRelationMapper.java

@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateTime;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.cyksj.model.entity.GroupsRelation;
+import com.cyksj.model.manage.views.GroupsRelationBackView;
 import com.cyksj.model.manage.views.GroupsRelationView;
 import com.cyksj.model.views.GroupsRelationUserView;
 import com.cyksj.model.views.UserRecommendGoodsFrontView;
@@ -61,4 +62,6 @@ public interface GroupsRelationMapper extends BaseMapper<GroupsRelation> {
 	Integer selectNumWaitingGroups(Long skuId);
 
 	Integer selectLimitAvailableNum(@Param("skuId") Long skuId, @Param("maxNum") Integer maxNum);
+
+	GroupsRelationBackView getGroupRelationAccountView(Long relationId);
 }

+ 13 - 13
netflix-dao/src/main/java/com/cyksj/model/manage/views/OrderDonBackView.java

@@ -23,9 +23,9 @@ import java.util.List;
  */
 @Getter
 @Setter
-@SearchBean(tables = "order_don o left join goods_don g on g.id = o.goods_id " +
-		"left join user u on o.user_id = u.id " +
-		"left join order_don_transport odt on odt.order_id = o.id ",
+@SearchBean(tables = "order_don o left join goods_don g on g.id = o.goods_id" +
+		" left join order_don_transport odt on odt.order_id = o.id" +
+		" left join goods_don_sku sku on sku.id = o.sku_id",
 		where = ":condition:"
 )
 public class OrderDonBackView {
@@ -83,33 +83,33 @@ public class OrderDonBackView {
 	@DbField("o.goods_id")
 	private Long goodsId;
 
-	@DbIgnore
+	@DbField("sku.spec_val")
 	private String specVal;
 
+	@DbField("sku.is_benefits")
+	private Boolean isBenefits;
+
 	@DbField("o.user_id")
 	private Long userId;
 
-	@DbField("u.nickname")
+	@DbIgnore
 	private String nickname;
 
-	@DbField("case when u.login_phone != '' then 'phone' when u.email != '' then 'email' when u.open_id != '' then 'wechat' else 'wechat' end")
+	@DbIgnore
 	private String register;
 
 	/**
 	 * 登录注册手机号
 	 */
-	@DbField("u.login_phone")
+	@DbIgnore
 	private String loginPhone;
 
 	/**
 	 * 登录注册邮箱
 	 */
-	@DbField("u.email")
+	@DbIgnore
 	private String email;
 
-	@DbField("u.is_google")
-	private Boolean isGoogle;
-
 	@DbField("o.money")
 	private BigDecimal money;
 
@@ -143,10 +143,10 @@ public class OrderDonBackView {
 	@DbField("o.tv_type")
 	private Integer tvType;
 
-	@DbIgnore
+	@DbField("sku.months")
 	private Integer months;
 
-	@DbIgnore
+	@DbField("sku.days")
 	private Integer days;
 
 	@DbField("o.num")

+ 7 - 0
netflix-dao/src/main/resources/mapper/GroupRelationMapper.xml

@@ -302,4 +302,11 @@
                 and gt.available_parking_num != 0) t
         where t.s1 >= s2
     </select>
+
+    <select id="getGroupRelationAccountView" resultType="com.cyksj.model.manage.views.GroupsRelationBackView">
+        select s.account, a.account as tripsAccount
+        from (select groups_id, account from groups_relation where id = #{relationId} limit 1) s
+                 inner join groups_trips gt on gt.id = s.groups_id
+                 left join account a on a.id = gt.account_id
+    </select>
 </mapper>

+ 58 - 27
netflix-web/src/main/java/com/cyksj/web/controller/manage/CmsOrderController.java

@@ -4,6 +4,7 @@ import cn.dev33.satoken.annotation.SaCheckPermission;
 import cn.dev33.satoken.stp.StpUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateTime;
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.excel.EasyExcel;
 import com.alibaba.excel.support.ExcelTypeEnum;
@@ -18,10 +19,7 @@ import com.cyksj.dto.Result;
 import com.cyksj.enums.BusinessType;
 import com.cyksj.enums.GatewayApiCode;
 import com.cyksj.enums.GatewayResponse;
-import com.cyksj.mapper.GoodsDonSkuMapper;
-import com.cyksj.mapper.GroupsRelationMapper;
-import com.cyksj.mapper.OrderCommentMapper;
-import com.cyksj.mapper.RealGoodsInterestUserMapper;
+import com.cyksj.mapper.*;
 import com.cyksj.mapper.channel.ChannelPopularizeMapper;
 import com.cyksj.mapper.channel.UserPayEquipmentAvailableBenefitsMapper;
 import com.cyksj.mapper.channel.UserPayEquipmentReceiveBenefitsRecordMapper;
@@ -105,10 +103,12 @@ public class CmsOrderController {
 
 	private final CmsUserMapper cmsUserMapper;
 
+	private final UserMapper userMapper;
+
 
 	@GetMapping("/get")
 	@SaCheckPermission("order:view")
-	public Result<SearchResult<OrderDonBackView>> get(Long channelId, String account, String showId, Long acId) {
+	public Result<SearchResult<OrderDonBackView>> get(Long channelId, String account, String showId, Long acId, String nickname, String register, Boolean isGoogle) {
 		MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
 		if (channelId != null) {
 			List<Long> popularizeIds = channelPopularizeMapper.getPopularizeIdByChannelId(channelId);
@@ -130,6 +130,28 @@ public class CmsOrderController {
 		if (acId != null) {
 			conditionSql += String.format(" o.user_id in (select user_id from corp_user where ac_id = %s)", acId);
 		}
+		if (!ObjectUtil.isAllEmpty(nickname, register, isGoogle)) {
+			if (StrUtil.isNotEmpty(conditionSql)) {
+				conditionSql += " and ";
+			}
+			conditionSql += " exists (select u.id from user u where u.id = o.user_id";
+			if (StrUtil.isNotEmpty(nickname)) {
+				conditionSql += String.format(" and u.nickname like '%s%%'", nickname);
+			}
+			if (StrUtil.isNotEmpty(register)) {
+				if ("phone".equals(register)) {
+					conditionSql += " and u.login_phone != ''";
+				} else if ("email".equals(register)) {
+					conditionSql += " and u.email != ''";
+				} else if ("wechat".equals(register)) {
+					conditionSql += " and u.unionid != ''";
+				}
+			}
+			if (isGoogle != null && isGoogle) {
+				conditionSql += String.format(" and u.is_google is %s", isGoogle);
+			}
+			conditionSql += " limit 1)";
+		}
 		if (StrUtil.isNotBlank(conditionSql)) {
 			builder.put("condition", conditionSql);
 		}
@@ -139,6 +161,7 @@ public class CmsOrderController {
 				Optional.ofNullable(channelPopularizeMapper.selectChannelByPid(data.getPopularizeId()))
 						.ifPresent(channelName -> data.setChannel(channelName));
 			}
+
 			if (data.getGoodsDonType() != null && Constant.realGoodsType.contains(data.getGoodsDonType())) {
 				RealGoodsOrderHandle realGoodsOrderHandle = realGoodsOrderHandleMapper.selectOne(Wrappers.lambdaQuery(RealGoodsOrderHandle.class).eq(RealGoodsOrderHandle::getOrderId, data.getId()).last("limit 1"));
 				if (realGoodsOrderHandle != null) {
@@ -146,32 +169,31 @@ public class CmsOrderController {
 					data.setAfterServiceName(realGoodsOrderHandle.getAfterServiceName());
 				}
 			}
+
 			if (data.getCouponUserId() != 0) {
 				data.setCouponName(couponMapper.getCouponNameByCouponUserId(data.getCouponUserId()));
 				data.setCouponMoney(data.getCouponMoney() == null ? BigDecimal.ZERO : data.getCouponMoney());
 			}
-			Optional.ofNullable(relationMapper.selectById(data.getRelationId()))
-					.ifPresent(relation -> {
-						data.setAccount(relation.getAccount());
-						AccountView accountView = beanSearcher.searchFirst(AccountView.class, MapUtils.builder().field(AccountView::getGroupsId, relation.getGroupsId()).onlySelect(AccountView::getAccount).build());
-						Optional.ofNullable(accountView).ifPresent(view -> data.setGtAccount(view.getAccount()));
-					});
-			Optional.ofNullable(skuMapper.selectById(data.getSkuId()))
-					.ifPresent(sku -> {
-						data.setSpecVal(sku.getSpecVal());
-						data.setMonths(sku.getMonths());
-						data.setDays(sku.getDays());
-						if (sku.getIsBenefits() && !Constant.noOrderAllStatus.contains(data.getStatus())) {
-							//是否实物权益已发放
-							Integer count = receiveBenefitsRecordMapper.selectCount(Wrappers.lambdaQuery(UserPayEquipmentReceiveBenefitsRecord.class)
-									.eq(UserPayEquipmentReceiveBenefitsRecord::getRealOrderId, data.getId()));
-							if (count == 0) {
-								count = availableBenefitsMapper.selectCount(Wrappers.lambdaQuery(UserPayEquipmentAvailableBenefits.class)
-										.eq(UserPayEquipmentAvailableBenefits::getRealOrderId, data.getId()));
-							}
-							data.setIsHasBenefits(count == 0 ? true : false);
-						}
-					});
+
+			if (data.getRelationId() != 0) {
+				Optional.ofNullable(relationMapper.getGroupRelationAccountView(data.getRelationId()))
+						.ifPresent(e -> {
+							data.setGtAccount(e.getTripsAccount());
+							data.setAccount(e.getAccount());
+						});
+			}
+
+			if (data.getIsBenefits() != null && data.getIsBenefits() && !Constant.noOrderAllStatus.contains(data.getStatus())) {
+				//是否实物权益已发放
+				Integer count = receiveBenefitsRecordMapper.selectCount(Wrappers.lambdaQuery(UserPayEquipmentReceiveBenefitsRecord.class)
+						.eq(UserPayEquipmentReceiveBenefitsRecord::getRealOrderId, data.getId()));
+				if (count == 0) {
+					count = availableBenefitsMapper.selectCount(Wrappers.lambdaQuery(UserPayEquipmentAvailableBenefits.class)
+							.eq(UserPayEquipmentAvailableBenefits::getRealOrderId, data.getId()));
+				}
+				data.setIsHasBenefits(count == 0 ? true : false);
+			}
+
 			if (data.getYhsId() != 0) {
 				Optional.ofNullable(yhShopMapper.selectById(data.getYhsId()))
 						.ifPresent(e -> {
@@ -179,6 +201,15 @@ public class CmsOrderController {
 							data.setCustomId(e.getCustomId());
 						});
 			}
+
+			User user = userMapper.selectById(data.getUserId());
+			if (user != null) {
+				data.setNickname(user.getNickname());
+				data.setLoginPhone(user.getLoginPhone());
+				data.setEmail(user.getEmail());
+				data.setRegister(StrUtil.isNotEmpty(user.getUnionid()) ? "wechat" : StrUtil.isNotEmpty(user.getLoginPhone()) ? "phone" : "email");
+
+			}
 		});
 		return GatewayResponse.SUCCESS.newBuilder().toResult(search);
 	}