|
|
@@ -3,19 +3,14 @@ package com.qnfhq.modules.c2c.service.impl;
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
-import cn.hutool.json.JSONArray;
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.Query;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.qnfhq.common.constant.Constant;
|
|
|
import com.qnfhq.common.exception.ErrorCode;
|
|
|
import com.qnfhq.common.page.PageData;
|
|
|
import com.qnfhq.common.redis.RedisUtils;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.qnfhq.common.service.impl.CrudServiceImpl;
|
|
|
+import com.qnfhq.common.service.impl.BaseServiceImpl;
|
|
|
import com.qnfhq.common.utils.MessageUtils;
|
|
|
import com.qnfhq.common.utils.Result;
|
|
|
import com.qnfhq.modules.c2c.dao.C2cAdDao;
|
|
|
@@ -32,15 +27,12 @@ import com.qnfhq.modules.user.service.AppAssetService;
|
|
|
import com.qnfhq.utils.OrderUtils;
|
|
|
import jakarta.annotation.Resource;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
-
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
* c2c商家广告
|
|
|
@@ -50,7 +42,7 @@ import java.util.concurrent.TimeUnit;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
-public class C2cAdServiceImpl extends ServiceImpl<C2cAdDao, C2cAdEntity> implements C2cAdService {
|
|
|
+public class C2cAdServiceImpl extends BaseServiceImpl<C2cAdDao, C2cAdEntity> implements C2cAdService {
|
|
|
|
|
|
@Resource
|
|
|
private C2cMerchantService c2cMerchantService;
|
|
|
@@ -141,7 +133,7 @@ public class C2cAdServiceImpl extends ServiceImpl<C2cAdDao, C2cAdEntity> impleme
|
|
|
// c2cAd.setFinishNum(merchant.getFinishNum());
|
|
|
//成单率
|
|
|
// c2cAd.setFinishRate(merchant.getFinishRate());
|
|
|
- if(!save(c2cAd)) {
|
|
|
+ if(!updateById(c2cAd)) {
|
|
|
throw new Exception(MessageUtils.message("c2c.order.save.fail"));//保存广告失败
|
|
|
}
|
|
|
if (direction.intValue() == DirectionEnum.SELL.getCode().intValue()) {
|
|
|
@@ -194,15 +186,15 @@ public class C2cAdServiceImpl extends ServiceImpl<C2cAdDao, C2cAdEntity> impleme
|
|
|
String adHKey = getAdHKey(c2cAdId);
|
|
|
redisUtils.delete(adHKey);
|
|
|
|
|
|
- //2 按价格排序,用于浏览广告
|
|
|
- String zsetKey = getViewAdKey(direction, legalCoin, symbol);
|
|
|
- redisUtils.removeZset(zsetKey, c2cAdId.toString());
|
|
|
-
|
|
|
- //3 按支付方式、按最小数量排序,用于快捷交易 c2c_ad_payId_buy_cnyusdt
|
|
|
- String[] paywayAr = payway.split(",");
|
|
|
- for (String paywayId : paywayAr) {
|
|
|
- redisUtils.removeZset(getQuickAdKey(zsetKey, paywayId), c2cAdId.toString());
|
|
|
- }
|
|
|
+// //2 按价格排序,用于浏览广告
|
|
|
+// String zsetKey = getViewAdKey(direction, legalCoin, symbol);
|
|
|
+// redisUtils.removeZset(zsetKey, c2cAdId.toString());
|
|
|
+//
|
|
|
+// //3 按支付方式、按最小数量排序,用于快捷交易 c2c_ad_payId_buy_cnyusdt
|
|
|
+// String[] paywayAr = payway.split(",");
|
|
|
+// for (String paywayId : paywayAr) {
|
|
|
+// redisUtils.removeZset(getQuickAdKey(zsetKey, paywayId), c2cAdId.toString());
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -235,26 +227,26 @@ public class C2cAdServiceImpl extends ServiceImpl<C2cAdDao, C2cAdEntity> impleme
|
|
|
redisUtils.hMSet(adHKey, adMap, randomHour*3600L);
|
|
|
|
|
|
//2 按价格排序,用于浏览广告
|
|
|
- String zsetKey = getViewAdKey(c2cAd.getDirection(), c2cAd.getLegalCoin(), c2cAd.getSymbol());
|
|
|
- redisUtils.addZSet(zsetKey, c2cAd.getId().toString(), c2cAd.getPrice().doubleValue(), c2cAd.getDirection());
|
|
|
+// String zsetKey = getViewAdKey(c2cAd.getDirection(), c2cAd.getLegalCoin(), c2cAd.getSymbol());
|
|
|
+// redisUtils.addZSet(zsetKey, c2cAd.getId().toString(), c2cAd.getPrice().doubleValue(), c2cAd.getDirection());
|
|
|
|
|
|
//3 按支付方式、按最小数量排序,用于快捷交易
|
|
|
- String[] paywayAr = payway.split(",");
|
|
|
- for (String paywayId : paywayAr) {
|
|
|
- redisUtils.addZSet(getQuickAdKey(zsetKey, paywayId), c2cAd.getId().toString(), c2cAd.getMinAmount().doubleValue(), c2cAd.getDirection());
|
|
|
- }
|
|
|
+// String[] paywayAr = payway.split(",");
|
|
|
+// for (String paywayId : paywayAr) {
|
|
|
+// redisUtils.addZSet(getQuickAdKey(zsetKey, paywayId), c2cAd.getId().toString(), c2cAd.getMinAmount().doubleValue(), c2cAd.getDirection());
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
|
|
|
-// @Override
|
|
|
-// public PageData<C2cAdEntity> page(Map<String, Object> params) {
|
|
|
-// IPage<C2cAdEntity> page = baseDao.selectPage(
|
|
|
-// getPage(params, "id", false),
|
|
|
-// getWrapper(params)
|
|
|
-// );
|
|
|
-//
|
|
|
-// return getPageData(page, C2cAdEntity.class);
|
|
|
-// }
|
|
|
+ @Override
|
|
|
+ public PageData<C2cAdEntity> page(Map<String, Object> params) {
|
|
|
+ IPage<C2cAdEntity> page = baseDao.selectPage(
|
|
|
+ getPage(params, "id", false),
|
|
|
+ getWrapper(params)
|
|
|
+ );
|
|
|
+
|
|
|
+ return getPageData(page, C2cAdEntity.class);
|
|
|
+ }
|
|
|
|
|
|
private QueryWrapper<C2cAdEntity> getWrapper(Map<String, Object> params){
|
|
|
|
|
|
@@ -273,17 +265,17 @@ public class C2cAdServiceImpl extends ServiceImpl<C2cAdDao, C2cAdEntity> impleme
|
|
|
|
|
|
/**
|
|
|
* 快捷交易查询
|
|
|
+ * 优先匹配“新手友好”商家
|
|
|
* @param tranDTO
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public Result queryTranAd(C2cAdTranDTO tranDTO) {
|
|
|
Result result = new Result();
|
|
|
- long loginId = StpUtil.getLoginIdAsLong();
|
|
|
String tranSymbol = tranDTO.getSymbol().toLowerCase();
|
|
|
String tranLegalCoin = tranDTO.getLegalCoin().toUpperCase();
|
|
|
Integer tranDirection = tranDTO.getDirection();
|
|
|
- //所有支付方式
|
|
|
+ //支付方式
|
|
|
List<C2cPayWayEntity> paywayList = c2cPayWayService.selectListByLegalCoin(tranLegalCoin);
|
|
|
if(CollectionUtils.isEmpty(paywayList)) {
|
|
|
return result.error(MessageUtils.message("c2c.ad.current.payway.empty"));//当前法币未设置支付方式
|
|
|
@@ -293,37 +285,48 @@ public class C2cAdServiceImpl extends ServiceImpl<C2cAdDao, C2cAdEntity> impleme
|
|
|
if(Objects.isNull(tLegalCoin)) {
|
|
|
return result.error(MessageUtils.message("c2c.ad.legalCoin.notset"));//当前法币未设置
|
|
|
}
|
|
|
+ //买入法币金额,卖出是数币
|
|
|
BigDecimal maxAmount = BigDecimal.ZERO;
|
|
|
if (tranDTO.getDirection().intValue() == DirectionEnum.BUY.getCode().intValue()) {
|
|
|
- maxAmount = tranDTO.getAmount();//法币cny的金额
|
|
|
+ maxAmount = tranDTO.getAmount();
|
|
|
} else {
|
|
|
- //卖出是usdt币的数量
|
|
|
maxAmount = tranDTO.getAmount().multiply(tLegalCoin.getExchangeRate());
|
|
|
}
|
|
|
|
|
|
|
|
|
- boolean flag = true;
|
|
|
- //1从redis取数
|
|
|
+ Integer direction = 0;
|
|
|
+ if (tranDTO.getDirection().intValue() == DirectionEnum.BUY.getCode().intValue()) {
|
|
|
+ direction = DirectionEnum.SELL.getCode();
|
|
|
+ } else {
|
|
|
+ direction = DirectionEnum.BUY.getCode();
|
|
|
+ }
|
|
|
+ //先查新手友好的商行
|
|
|
+ List<C2cAdEntity> queryAdList = selectC2cAdTranList(tranSymbol,direction,tranLegalCoin,maxAmount,1);
|
|
|
+ setPaywayList(paywayList, queryAdList,tranDirection);
|
|
|
+
|
|
|
+ int total = 0;
|
|
|
for(C2cPayWayEntity payway : paywayList) {
|
|
|
- String zsetKey = getViewAdKey(tranDirection, tranLegalCoin, tranSymbol);
|
|
|
- String zQuickKey = getQuickAdKey(zsetKey,payway.getId().toString());
|
|
|
-
|
|
|
- ArrayList<Object> adidList = null;
|
|
|
- //配置 最小买入金额
|
|
|
- adidList = redisUtils.getRangeByScore(zQuickKey, 10.0, maxAmount.doubleValue());
|
|
|
- if (adidList != null) {
|
|
|
- List<C2cAdEntity> adList = new ArrayList<>();
|
|
|
- for (Object adId : adidList) {
|
|
|
- Long adIdLong = Long.valueOf((String)adId);
|
|
|
- C2cAdEntity ad = selectAdFromRedis(adIdLong);
|
|
|
- if(ad == null) {
|
|
|
- ad = getById(adIdLong);
|
|
|
- if(ad==null) {
|
|
|
- redisUtils.removeZset(zQuickKey, adIdLong.toString());
|
|
|
- }
|
|
|
- delSetAdCache(ad);
|
|
|
- }
|
|
|
- if (ad!=null && ad.getMaxAmount().compareTo(maxAmount) != -1) {
|
|
|
+ if(payway.getAdList()!=null) {
|
|
|
+ total += payway.getAdList().size();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(total<3) {
|
|
|
+ //查其他的商行
|
|
|
+ queryAdList = selectC2cAdTranList(tranSymbol,direction,tranLegalCoin,maxAmount,0);
|
|
|
+ setPaywayList(paywayList, queryAdList,tranDirection);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result.ok(paywayList);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<C2cPayWayEntity> setPaywayList(List<C2cPayWayEntity> paywayList,List<C2cAdEntity> queryAdList,Integer direction) {
|
|
|
+ if (!CollectionUtils.isEmpty(queryAdList)) {
|
|
|
+ for(C2cPayWayEntity payway : paywayList) {
|
|
|
+ List<C2cAdEntity> adList = payway.getAdList()==null ? new ArrayList<>() : payway.getAdList();
|
|
|
+ for(C2cAdEntity ad : queryAdList) {
|
|
|
+ String[] payIds = ad.getPayway().split(",");
|
|
|
+ if(Arrays.asList(payIds).contains(payway.getId().toString())) {
|
|
|
adList.add(ad);
|
|
|
if (adList.size() > 2) {
|
|
|
break;
|
|
|
@@ -331,47 +334,17 @@ public class C2cAdServiceImpl extends ServiceImpl<C2cAdDao, C2cAdEntity> impleme
|
|
|
}
|
|
|
}
|
|
|
if(adList.size()>0) {
|
|
|
- flag = false;
|
|
|
- sortAdList(adList,tranDTO.getDirection());
|
|
|
+ sortAdList(adList,direction);
|
|
|
payway.setAdList(adList);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if(flag) {
|
|
|
- //2从数据库查询
|
|
|
- Integer direction = 0;
|
|
|
- if (tranDTO.getDirection().intValue() == DirectionEnum.BUY.getCode().intValue()) {
|
|
|
- direction = DirectionEnum.SELL.getCode();
|
|
|
- } else {
|
|
|
- direction = DirectionEnum.BUY.getCode();
|
|
|
- }
|
|
|
- List<C2cAdEntity> queryAdList = selectC2cAdTranList(tranSymbol,direction,tranLegalCoin,maxAmount);
|
|
|
- if (!CollectionUtils.isEmpty(queryAdList)) {
|
|
|
- for(C2cPayWayEntity payway : paywayList) {
|
|
|
- List<C2cAdEntity> adList = new ArrayList<>();
|
|
|
- for(C2cAdEntity ad : queryAdList) {
|
|
|
- String[] payIds = ad.getPayway().split(",");
|
|
|
- if(Arrays.asList(payIds).contains(payway.getId().toString())
|
|
|
- && ad.getUserId().longValue()!=loginId) {
|
|
|
- adList.add(ad);
|
|
|
- if (adList.size() > 2) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if(adList.size()>0) {
|
|
|
- sortAdList(adList,tranDTO.getDirection());
|
|
|
- payway.setAdList(adList);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return result.ok(paywayList);
|
|
|
+ return paywayList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询快捷交易广告
|
|
|
+ *
|
|
|
* @param symbol
|
|
|
* @param direction
|
|
|
* @param legalCoin
|
|
|
@@ -379,15 +352,15 @@ public class C2cAdServiceImpl extends ServiceImpl<C2cAdDao, C2cAdEntity> impleme
|
|
|
* @return
|
|
|
*/
|
|
|
private List<C2cAdEntity> selectC2cAdTranList(String symbol,Integer direction,
|
|
|
- String legalCoin,BigDecimal tranAmount) {
|
|
|
- return list(new LambdaQueryWrapper<C2cAdEntity>()
|
|
|
- .eq(C2cAdEntity::getDirection,direction)
|
|
|
- .eq(C2cAdEntity::getLegalCoin,legalCoin)
|
|
|
- .eq(C2cAdEntity::getSymbol,symbol)
|
|
|
+ String legalCoin,BigDecimal tranAmount,Integer tag) {
|
|
|
+ return baseDao.selectList(new LambdaQueryWrapper<C2cAdEntity>()
|
|
|
+ .ne(C2cAdEntity::getUserId, StpUtil.getLoginIdAsLong())
|
|
|
+ .eq(Objects.nonNull(direction),C2cAdEntity::getDirection, direction)
|
|
|
+ .eq(StrUtil.isNotBlank(legalCoin),C2cAdEntity::getLegalCoin, legalCoin)
|
|
|
+ .eq(StrUtil.isNotBlank(symbol),C2cAdEntity::getSymbol, symbol)
|
|
|
.eq(C2cAdEntity::getStatus,AdStatusEnum.PASS.getCode())
|
|
|
- .ge(C2cAdEntity::getMaxAmount,tranAmount)
|
|
|
- .le(C2cAdEntity::getMinAmount,tranAmount)
|
|
|
- .last(" limit 50")
|
|
|
+ .eq(Objects.nonNull(tag),C2cAdEntity::getTag,tag)
|
|
|
+ .last(" limit 100")
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -405,7 +378,7 @@ public class C2cAdServiceImpl extends ServiceImpl<C2cAdDao, C2cAdEntity> impleme
|
|
|
if(viewDTO.getId()!=null) {
|
|
|
C2cAdEntity ad = selectAdFromRedis(viewDTO.getId());
|
|
|
if(ad == null) {
|
|
|
- ad = getById(viewDTO.getId());
|
|
|
+ ad = selectById(viewDTO.getId());
|
|
|
}
|
|
|
if(ad!=null) {
|
|
|
resList.add(ad);
|
|
|
@@ -418,6 +391,8 @@ public class C2cAdServiceImpl extends ServiceImpl<C2cAdDao, C2cAdEntity> impleme
|
|
|
BigDecimal amount = viewDTO.getAmount();
|
|
|
//设置支付方式
|
|
|
String payway = viewDTO.getPayway();
|
|
|
+ //标签
|
|
|
+ Integer tag = viewDTO.getTag();
|
|
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
//买入\卖出广告
|
|
|
@@ -431,37 +406,12 @@ public class C2cAdServiceImpl extends ServiceImpl<C2cAdDao, C2cAdEntity> impleme
|
|
|
direction = DirectionEnum.BUY.getCode();
|
|
|
params.put("direction", DirectionEnum.BUY.getCode());
|
|
|
}
|
|
|
- Integer pageNum = Convert.toInt(viewDTO.getPageNum(), 1);
|
|
|
- Integer pageSize = Convert.toInt(viewDTO.getPageSize(), 10);
|
|
|
- params.put(Constant.PAGE,pageNum.toString());
|
|
|
- params.put(Constant.LIMIT,pageSize.toString());
|
|
|
+ params.put(Constant.PAGE,viewDTO.getPageNum());
|
|
|
+ params.put(Constant.LIMIT,viewDTO.getPageSize());
|
|
|
String inputSymbol = viewDTO.getSymbol().toLowerCase();
|
|
|
String inputLegalCoin = viewDTO.getLegalCoin().toUpperCase();
|
|
|
|
|
|
- //1从redis查询
|
|
|
- if(amount == null && StrUtil.isEmpty(payway)) {
|
|
|
- long start = (pageNum - 1) * pageSize;
|
|
|
- long end = pageNum * pageSize-1;
|
|
|
- String zsetKey = getViewAdKey(direction, inputLegalCoin, inputSymbol);
|
|
|
- ArrayList<Object> adList = redisUtils.getRange(zsetKey, type, start, end);
|
|
|
- if (adList != null) {
|
|
|
- for(Object adId : adList) {
|
|
|
- Long adIdLong = Long.valueOf((String)adId);
|
|
|
- C2cAdEntity ad = selectAdFromRedis(adIdLong);
|
|
|
- if(ad == null) {
|
|
|
- ad = getById(adIdLong);
|
|
|
- delSetAdCache(ad);
|
|
|
- }
|
|
|
- if(ad!=null && ad.getUserId().longValue()!=StpUtil.getLoginIdAsLong()) {
|
|
|
- resList.add(ad);
|
|
|
- }
|
|
|
- }
|
|
|
- PageData<C2cAdEntity> data = new PageData<C2cAdEntity>(resList,resList.size());
|
|
|
- return result.ok(data);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //2 查数据库
|
|
|
+ // 查数据库
|
|
|
List paywayList = new ArrayList();
|
|
|
if (StrUtil.isNotEmpty(payway)) {
|
|
|
paywayList = Arrays.stream(payway.split(",")).toList();
|
|
|
@@ -472,6 +422,7 @@ public class C2cAdServiceImpl extends ServiceImpl<C2cAdDao, C2cAdEntity> impleme
|
|
|
.eq(StrUtil.isNotBlank(inputLegalCoin),C2cAdEntity::getLegalCoin, inputLegalCoin)
|
|
|
.eq(StrUtil.isNotBlank(inputSymbol),C2cAdEntity::getSymbol, inputSymbol)
|
|
|
.eq(C2cAdEntity::getStatus,AdStatusEnum.PASS.getCode())
|
|
|
+ .eq(Objects.nonNull(tag) && tag != -1,C2cAdEntity::getTag,tag)
|
|
|
.le(Objects.nonNull(amount),C2cAdEntity::getMinAmount,amount)
|
|
|
.ge(Objects.nonNull(amount),C2cAdEntity::getMaxAmount,amount);
|
|
|
if(paywayList.size()>0) {
|
|
|
@@ -479,15 +430,13 @@ public class C2cAdServiceImpl extends ServiceImpl<C2cAdDao, C2cAdEntity> impleme
|
|
|
wrapper.and(qw -> createQw(qw, finalPaywayList));
|
|
|
}
|
|
|
|
|
|
- //todo 分页
|
|
|
- return null;
|
|
|
-// IPage<C2cAdEntity> page2 =new Page<>();
|
|
|
-// IPage<C2cAdEntity> page = baseDao.selectPage(
|
|
|
-// getPage(params, "price", "asc".equals(type) ? true : false),
|
|
|
-// wrapper
|
|
|
-// );
|
|
|
-// PageData<C2cAdEntity> data = getPageData(page, C2cAdEntity.class);
|
|
|
-// return result.ok(data);
|
|
|
+ IPage<C2cAdEntity> page = baseDao.selectPage(
|
|
|
+ getPage(params, "price", "asc".equals(type) ? true : false),
|
|
|
+ wrapper
|
|
|
+ );
|
|
|
+ PageData<C2cAdEntity> data = getPageData(page, C2cAdEntity.class);
|
|
|
+ return result.ok(data);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void createQw(LambdaQueryWrapper<C2cAdEntity> qw, List<String> paywayList) {
|