Authored by csgyoho

CPS订单管理,后台查询优化,减少不必要的循环和查数据库

... ... @@ -2,12 +2,10 @@ package com.yoho.unions.dal;
import com.yoho.service.model.union.request.UnionShareOrderReqBO;
import com.yoho.unions.dal.model.UnionShareOrders;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
public interface UnionShareOrdersMapper {
int deleteByPrimaryKey(Integer id);
... ... @@ -22,14 +20,11 @@ public interface UnionShareOrdersMapper {
int selectCountBySearchCodition(@Param("beginTime") int beginTime, @Param("endTime") int endTime, @Param("uid") Integer uid, @Param("orderCode")String orderCode);
@MapKey("orderCode")
Map<String,UnionShareOrders> selectListBySearchCodition(@Param("beginTime") int beginTime, @Param("endTime") int endTime, @Param("uid") Integer uid, @Param("orderCode") String orderCode, @Param("startIndex") int startIndex, @Param("pageSize") int pageSize);
List<UnionShareOrders> selectListBySearchCodition(@Param("beginTime") int beginTime, @Param("endTime") int endTime, @Param("uid") Integer uid, @Param("orderCode") String orderCode, @Param("startIndex") int startIndex, @Param("pageSize") int pageSize);
@MapKey("orderCode")
Map<String,UnionShareOrders> selectListByIds(List<String> ids);
List<UnionShareOrders> selectListByIds(List<String> ids);
@MapKey("orderCode")
Map<String,UnionShareOrders> selectAllListByUids(@Param("beginTime") int beginTime,@Param("endTime") int endTime,@Param("uid") Integer uid,@Param("orderCode") String orderCode);
List<UnionShareOrders> selectAllListByUids(@Param("beginTime") int beginTime,@Param("endTime") int endTime,@Param("uid") Integer uid,@Param("orderCode") String orderCode);
int selectCountByCondition(@Param("promoteUid")int promoteUid, @Param("status")String status);
... ...
... ... @@ -2,9 +2,10 @@ package com.yoho.unions.dal;
import com.yoho.unions.dal.model.UnionShareUser;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
import java.util.Set;
public interface UnionShareUserMapper {
int deleteByPrimaryKey(Integer id);
... ... @@ -26,5 +27,5 @@ public interface UnionShareUserMapper {
Integer selectUidByUnionType(Long unionType);
@MapKey("uid")
Map<Integer,UnionShareUser> selectByUids(List<Integer> uids);
Map<Integer,UnionShareUser> selectByUids(@Param("uids") Set<Integer> uids);
}
\ No newline at end of file
... ...
... ... @@ -36,12 +36,12 @@
values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{unionType,jdbcType=VARCHAR},
#{updateTime,jdbcType=INTEGER})
</insert>
<select id="selectByUids" parameterType="Integer" resultMap="BaseResultMap">
<select id="selectByUids" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from union_share_user
where uid in
<foreach collection="list" open="(" close=")" item="uid" separator=",">
<foreach collection="uids" open="(" close=")" item="uid" separator=",">
#{uid}
</foreach>
</select>
... ...
... ... @@ -12,7 +12,6 @@ import com.yoho.service.model.union.request.UnionShareOrderSearchReqBO;
import com.yoho.service.model.union.response.PageResponseBO;
import com.yoho.service.model.union.response.PageUnionShareOrderRspBO;
import com.yoho.service.model.union.response.UnionShareOrderRspBO;
import com.yoho.unions.common.enums.OrderStatusEnum;
import com.yoho.unions.common.enums.ShareOrdersKeyEnum;
import com.yoho.unions.common.enums.ShareOrdersStatusEnum;
import com.yoho.unions.common.redis.RedisHashCache;
... ... @@ -127,8 +126,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
if (count < 1) {
return null;
}
Map<String,UnionShareOrders> ordersDOMap=this.unionShareOrdersMapper.selectListBySearchCodition(bo.getBeginTime(), bo.getEndTime(), uid,bo.getOrderCode(), reqBO.getStart(), reqBO.getSize());
List<UnionShareOrderRspBO> unionOrderRspBOList = queryUnionShareOrderRsp(ordersDOMap);
List<UnionShareOrders> ordersDOList=this.unionShareOrdersMapper.selectListBySearchCodition(bo.getBeginTime(), bo.getEndTime(), uid,bo.getOrderCode(), reqBO.getStart(), reqBO.getSize());
List<UnionShareOrderRspBO> unionOrderRspBOList = queryUnionShareOrderRspBO(ordersDOList);
PageUnionShareOrderRspBO pageUnionOrderRspBO = new PageUnionShareOrderRspBO();
pageUnionOrderRspBO.setList(unionOrderRspBOList);
pageUnionOrderRspBO.setTotal(count);
... ... @@ -138,13 +137,11 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
}
private Integer queryUid(UnionShareOrderSearchBo bo){
Integer uid=null;
Long unionType=mktMarketingUrlDAO.selectUnionTypeByNameAndUnionType(bo.getUnionName(),bo.getUnionType());
Long unionType=null==bo.getUnionName()?bo.getUnionType():mktMarketingUrlDAO.selectUnionTypeByNameAndUnionType(bo.getUnionName(),bo.getUnionType());
if(null==unionType){
return null;
}
uid=this.unionShareUserMapper.selectUidByUnionType(unionType);
return uid;
return this.unionShareUserMapper.selectUidByUnionType(unionType);
}
private UnionShareOrderSearchBo initUnionShareOrderSearchBo(UnionShareOrderSearchReqBO reqBO){
UnionShareOrderSearchBo bo=new UnionShareOrderSearchBo();
... ... @@ -157,17 +154,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
return bo;
}
private List<UnionShareOrderRspBO> queryUnionShareOrderRsp(Map<String,UnionShareOrders> ordersDOMap){
List<UnionShareOrderRspBO> unionOrderRspBOList = new ArrayList<>(ordersDOMap.size());
Map<String, ShareUserOrderDatailBO> userOrderDatailBOMap = initUserShareOrderDatails(ordersDOMap);
for (UnionShareOrders orders : ordersDOMap.values()) {
UnionShareOrderRspBO bo=initShareUnionOrderRspBO(orders,userOrderDatailBOMap);
unionOrderRspBOList.add(bo);
}
return unionOrderRspBOList;
}
private UnionShareOrderRspBO initShareUnionOrderRspBO(UnionShareOrders orders,Map<String, ShareUserOrderDatailBO> userOrderDatailBOMap){
private UnionShareOrderRspBO initShareUnionOrderRspBO(String unionType,MktMarketingUrl mktMarketingUrl,UnionShareOrders orders){
UnionShareOrderRspBO orderRspBO=new UnionShareOrderRspBO();
orderRspBO.setOrderAmount(orders.getLastOrderAmount());
orderRspBO.setOrderStatus(ShareOrdersStatusEnum.getDescByCode(orders.getStatus()));
... ... @@ -176,48 +163,38 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
orderRspBO.setOrderCode(orders.getOrderCode());
orderRspBO.setId(orders.getId());
orderRspBO.setOrderTime(DateUtil.long2DateStr(Long.valueOf(orders.getCreateTime()) * Long.valueOf(1000), "yyyy-MM-dd HH:mm:ss"));
ShareUserOrderDatailBO userOrderDatailBO = userOrderDatailBOMap.get(orders.getOrderCode());
orderRspBO.setUnionId(userOrderDatailBO.getUnionType());
orderRspBO.setUnionType(userOrderDatailBO.getUnionName());
orderRspBO.setChannelType(userOrderDatailBO.getChannelType());
orderRspBO.setUnionId(unionType);
if(null!=mktMarketingUrl){
orderRspBO.setUnionType(mktMarketingUrl.getName());
orderRspBO.setChannelType(mktMarketingUrl.getChannelType());
}
return orderRspBO;
}
private List<Integer> getUids(Map<String,UnionShareOrders> ordersDOMap){
List<Integer> uids=new ArrayList<>(ordersDOMap.size());
for(UnionShareOrders order:ordersDOMap.values()){
private Set<Integer> getUids(List<UnionShareOrders> ordersDOList){
Set<Integer> uids=new HashSet<>(ordersDOList.size());
for(UnionShareOrders order:ordersDOList){
uids.add(order.getPromoteUid());
}
return uids;
}
private Map<String, ShareUserOrderDatailBO> initUserShareOrderDatails( Map<String,UnionShareOrders> ordersDOMap){
Map<String, ShareUserOrderDatailBO> userOrderDatailBOMap = new HashMap<>(ordersDOMap.size());
Map<Integer,UnionShareUser> userMap=unionShareUserMapper.selectByUids(getUids(ordersDOMap));
Map<Long,MktMarketingUrl> mktMarketMap=listMktMarketingUrls(ordersDOMap,userMap);
for (UnionShareOrders userOrders : ordersDOMap.values()) {
private List<UnionShareOrderRspBO> queryUnionShareOrderRspBO(List<UnionShareOrders> ordersDOList){
List<UnionShareOrderRspBO> unionOrderRspBOList = new ArrayList<>(ordersDOList.size());
Map<Integer,UnionShareUser> userMap=unionShareUserMapper.selectByUids(getUids(ordersDOList));
Map<Long,MktMarketingUrl> mktMarketMap=listMktMarketingUrls(ordersDOList,userMap);
for (UnionShareOrders userOrders : ordersDOList) {
String unionType=userMap.get(userOrders.getPromoteUid()).getUnionType();
ShareUserOrderDatailBO userOrderDatailBO = new ShareUserOrderDatailBO();
userOrderDatailBO.setUnionType(unionType);
MktMarketingUrl mktMarketingUrl = redisValueCache.get("yh:union:uniontype:" + unionType, MktMarketingUrl.class);
if (mktMarketingUrl == null && isLong(unionType)) {
mktMarketingUrl = mktMarketMap.get(Long.valueOf(unionType));
if(null!=mktMarketingUrl){
redisValueCache.set("yh:union:uniontype:" + unionType, mktMarketingUrl, 1, TimeUnit.HOURS);
}
}
if (mktMarketingUrl != null) {
userOrderDatailBO.setUnionName(mktMarketingUrl.getName());
userOrderDatailBO.setChannelType(mktMarketingUrl.getChannelType());
}
userOrderDatailBO.setOrderCode(userOrders.getOrderCode());
userOrderDatailBOMap.put(userOrderDatailBO.getOrderCode(),userOrderDatailBO);
MktMarketingUrl mktMarketingUrl = isLong(unionType)?mktMarketMap.get(Long.valueOf(unionType)):null;
UnionShareOrderRspBO bo=initShareUnionOrderRspBO(unionType,mktMarketingUrl,userOrders);
unionOrderRspBOList.add(bo);
}
return userOrderDatailBOMap;
return unionOrderRspBOList;
}
private Map<Long,MktMarketingUrl> listMktMarketingUrls(Map<String,UnionShareOrders> ordersDOMap, Map<Integer,UnionShareUser> userMap){
private Map<Long,MktMarketingUrl> listMktMarketingUrls(List<UnionShareOrders> ordersDOList, Map<Integer,UnionShareUser> userMap){
List<String> unionTypes=new ArrayList<>();
for (UnionShareOrders userOrders : ordersDOMap.values()) {
for (UnionShareOrders userOrders : ordersDOList) {
String unionType=userMap.get(userOrders.getPromoteUid()).getUnionType();
if(StringUtils.isNotBlank(unionType)){
unionTypes.add(unionType);
... ... @@ -815,9 +792,9 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
}
private List<UnionShareOrderRspBO> queryUnionShareOrderRspBOForExport(UnionShareOrderSearchReqBO reqBO){
UnionShareOrderSearchBo bo=initUnionShareOrderSearchBo(reqBO);
Map<String,UnionShareOrders> ordersDOMap=null;
List<UnionShareOrders> ordersDOList=null;
if(bo.getIdList()!=null&&!bo.getIdList().isEmpty()){
ordersDOMap= this.unionShareOrdersMapper.selectListByIds(bo.getIdList());
ordersDOList= this.unionShareOrdersMapper.selectListByIds(bo.getIdList());
}else{
Integer uid=null;
if(bo.getUnionType()!=null || bo.getUnionName()!=null){
... ... @@ -826,8 +803,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
return null;
}
}
ordersDOMap=this.unionShareOrdersMapper.selectAllListByUids(bo.getBeginTime(), bo.getEndTime(), uid, bo.getOrderCode());
ordersDOList=this.unionShareOrdersMapper.selectAllListByUids(bo.getBeginTime(), bo.getEndTime(), uid, bo.getOrderCode());
}
return ordersDOMap.isEmpty()?null:queryUnionShareOrderRsp(ordersDOMap);
return ordersDOList.isEmpty()?null: queryUnionShareOrderRspBO(ordersDOList);
}
}
... ...