Authored by caoyan

Merge branch 'test6.8.9' of http://git.yoho.cn/ufo/yohoufo-fore into test6.8.9

... ... @@ -35,4 +35,6 @@ public interface SellerOrderGoodsViewMapper {
@Param("limit")Integer limit);
int selectEntryCntByUidStatusGBSku(SellerOrderGoods condition);
List<SellerOrderGoods> selectCanSellByStorageId(@Param("storageId")int storageId);
}
... ...
... ... @@ -123,4 +123,11 @@
) t
</select>
<select id="selectCanSellByStorageId" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List" />
FROM seller_order_goods
WHERE storage_id = #{storageId,jdbcType=INTEGER} and status = 1
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -136,7 +136,32 @@ public class ActionStatusHold {
static {
sellerCanCancelBuyerOrderStatus = Arrays.asList(OrderStatus.HAS_PAYED.getCode());
}
/**
* 未完成的订单状态,商家退驻时需要
* @return
*/
public static List<Integer> unfinishedOrderStatusCode = Arrays.asList(
OrderStatus.WAITING_PAY.getCode(),
OrderStatus.HAS_PAYED.getCode(),
OrderStatus.SELLER_SEND_OUT.getCode(),
OrderStatus.PLATFORM_RECEIVE.getCode(),
OrderStatus.PLATFORM_CHECKING.getCode(),
OrderStatus.MINI_FAULT_WAITING.getCode(),
OrderStatus.MINI_FAULT_ACCEPT.getCode(),
OrderStatus.JUDGE_PASS.getCode()
);
}
public static List<Integer> getUnfinishedOrderStatusCode(){
return SellerASH.unfinishedOrderStatusCode;
}
public static List<Integer> getSellerShowExpressStatusList(){
return SellerASH.View_Express_Status;
}
... ...
package com.yohoufo.order.event;
import com.yohoufo.common.alarm.Event;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Builder;
/**
* Created by craig.qin on 2019/3/20.
* 价格变动(调价、新的上架)发消息
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SellerOrderPriceChangeEvent extends Event{
private int sellerUid;
private Integer skup;
}
... ...
package com.yohoufo.order.service.handler;
import com.google.common.eventbus.Subscribe;
import com.yoho.core.redis.cluster.annotation.Redis;
import com.yoho.core.redis.cluster.operations.nosync.YHRedisTemplate;
import com.yoho.core.redis.cluster.operations.nosync.YHSetOperations;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohoufo.common.alarm.IEventHandler;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.SellerOrderGoodsViewMapper;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.event.SellerOrderPriceChangeEvent;
import com.yohoufo.order.service.proxy.InBoxFacade;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
* Created by craig
*/
@Component
public class SellerOrderPriceChangeHandler implements IEventHandler<SellerOrderPriceChangeEvent> {
final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
@Autowired
private SellerOrderGoodsViewMapper sellerOrderGoodsViewMapper;
@Autowired
private InBoxFacade inBoxFacade;
@Redis("gwNoSyncRedis")
YHSetOperations yhSetOperations;
@Redis("gwNoSyncRedis")
YHRedisTemplate yhRedisTemplate;
private final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
@Override
@Subscribe
public void handle(SellerOrderPriceChangeEvent event) {
logger.info("Subscribe SellerOrderPriceChangeEvent msg, event {}", event);
SellerOrderGoods sog = sellerOrderGoodsMapper.selectByPrimaryKey(event.getSkup());
if(sog==null){
logger.warn("Subscribe SellerOrderPriceChangeEvent msg return SellerOrderGoods is null, event {}", event);
return ;
}
if(SkupStatus.CAN_SELL.getCode()!=sog.getStatus()){
logger.warn("Subscribe SellerOrderPriceChangeEvent msg return SellerOrderGoods status is not can sell , event {} ,sog {}", event,sog);
return ;
}
int changedSellerUid = sog.getUid();
BigDecimal changedPrice = sog.getGoodsPrice();
//根据storageId获取所有在售的卖家的订单
List<SellerOrderGoods> list= sellerOrderGoodsViewMapper.selectCanSellByStorageId(sog.getStorageId());
//把自己过滤掉,只保留价格高于当前价格
list = list.stream().filter(r->r.getGoodsPrice().compareTo(changedPrice)>0&&changedSellerUid!=r.getUid().intValue()).collect(Collectors.toList());
//从redis过滤uid+storgeid+date
Date currentTime = new Date();
String dateString = formatter.format(currentTime);//2019-03-20
//发送,并记录到redis
RedisKeyBuilder redisKey = getRedisKeyBuilder(dateString);
Set<String> members = yhSetOperations.members(redisKey);
if(CollectionUtils.isNotEmpty(members)){
list = list.stream().filter(r->!members.contains(getValueForSet(r))).collect(Collectors.toList());
}
Set<Integer> noticeSellerUidList = new HashSet<>();
Set<String> redisSetValue = new HashSet<>();
for(SellerOrderGoods r:list){
noticeSellerUidList.add(r.getUid());
redisSetValue.add(getValueForSet(r));
}
logger.info("Subscribe SellerOrderPriceChangeEvent begin send msg, event {},noticeSellerUidList {} ,redisSetValue {}", event,noticeSellerUidList,redisSetValue);
//发消息
inBoxFacade.noticeSellerWhenOtherChangePriceLower(sog,noticeSellerUidList);
// 记录到redis
if(redisSetValue.size()>0){
yhSetOperations.add(redisKey,redisSetValue.toArray(new String[redisSetValue.size()]));
yhRedisTemplate.longExpire(redisKey, 24, TimeUnit.HOURS); //24小时失效
}
}
public String getValueForSet(SellerOrderGoods r){
return r.getUid()+"-"+r.getStorageId();
}
public static RedisKeyBuilder getRedisKeyBuilder(String dateString){
return RedisKeyBuilder.newInstance().appendFixed("ufo:order:price:change:").appendVar(dateString);
}
}
... ...
... ... @@ -678,7 +678,7 @@ public class PaymentServiceImpl implements IPaymentService {
logger.info("transferMon uid {} 支付宝账号uid无值使用账号{}", targetUid, account.getAlipayAccount());
transfer.setAlipayAccount(account.getAlipayAccount());
}
transfer.setUpdateTime(now);
tradeBillsMapper.insert(record);
String alipayAccount = transfer.getAlipayAccount();
... ... @@ -689,7 +689,8 @@ public class PaymentServiceImpl implements IPaymentService {
logger.info("transferMon开始调用阿里接口参数buyerOrderCode={}, alipayAccount={}, transferAmount={}", buyerOrderCode, alipayAccount, transferAmount);
if(exceedMillion()) {
transfer.setTransferType(2);
transfer.setInterfaceType(2);
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
Map<String, String> mapResult = transferWhenExceedMillion(transfer.getId(), record, buyerOrderCode, account, transferAmount, now);
String resultStr = JSON.toJSONString(mapResult);
jsonObject = JSON.parseObject(resultStr);
... ... @@ -701,7 +702,8 @@ public class PaymentServiceImpl implements IPaymentService {
}
}
transfer.setTransferType(1);
transfer.setInterfaceType(1);
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
jsonObject = alipayService.transferMoney(Long.toString(buyerOrderCode), account.getAlipayId(), account.getAlipayAccount(), transferAmount);
if (jsonObject == null) {
logger.warn("transferMonErr 转账失败 , orderCode is {}", buyerOrderCode);
... ... @@ -720,7 +722,8 @@ public class PaymentServiceImpl implements IPaymentService {
transfer.setAlipayTradeId(orderId);
transfer.setStatus(1);
} else if(exceedMillion(jsonObject)) {
transfer.setTransferType(2);
transfer.setInterfaceType(2);
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
Map<String, String> mapResult = transferWhenExceedMillion(transfer.getId(), record, buyerOrderCode, account, transferAmount, now);
String resultStr = JSON.toJSONString(mapResult);
jsonObject = JSON.parseObject(resultStr);
... ... @@ -754,7 +757,6 @@ public class PaymentServiceImpl implements IPaymentService {
return;
}
logger.info("transferMon最后更新状态 status= {}", transfer.getStatus());
transfer.setUpdateTime(now);
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
// 100:成功;201:没有支付宝账号;202:金额不合法;299:转账失败
record.setTradeStatus(transfer.getStatus() == 1 ? 100 : 299);
... ... @@ -812,11 +814,13 @@ public class PaymentServiceImpl implements IPaymentService {
// 转账
JSONObject jsonObject = null;
boolean exceedMillionAndSuccess = false;
transfer.setUpdateTime(now);
try {
logger.info("transAllEarnest开始调用阿里接口参数buyerOrderCode={}, alipayAccount={}, transferAmount={}", orderCode, account, amount);
if(exceedMillion()) {
transfer.setTransferType(2);
transfer.setInterfaceType(2);
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
Map<String, String> mapResult = transferWhenExceedMillion(transfer.getId(), record, orderCode, aliPayAccount, amount, now);
String resultStr = JSON.toJSONString(mapResult);
jsonObject = JSON.parseObject(resultStr);
... ... @@ -828,7 +832,8 @@ public class PaymentServiceImpl implements IPaymentService {
}
}
transfer.setTransferType(1);
transfer.setInterfaceType(1);
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
jsonObject = alipayService.transferMoney(Long.toString(orderCode), aliPayAccount.getAlipayId(), aliPayAccount.getAlipayAccount(), amount);
if (jsonObject == null) {
logger.warn("transAllEarnestErr 转账失败 , orderCode is {}", orderCode);
... ... @@ -848,7 +853,8 @@ public class PaymentServiceImpl implements IPaymentService {
transfer.setStatus(1);
return true;
} else if(exceedMillion(jsonObject)) {
transfer.setTransferType(2);
transfer.setInterfaceType(2);
ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
Map<String, String> mapResult = transferWhenExceedMillion(transfer.getId(), record, orderCode, aliPayAccount, amount, now);
String resultStr = JSON.toJSONString(mapResult);
jsonObject = JSON.parseObject(resultStr);
... ... @@ -1075,7 +1081,7 @@ public class PaymentServiceImpl implements IPaymentService {
}
}
JSONObject jsonObject = null;
Integer transferType = null;
Integer interfaceType = null;
try {
OrdersPayTransfer transfer = ordersPayTransferMapper.selectByBuyerOrderCode(orderCode);
if (transfer == null) {
... ... @@ -1084,16 +1090,16 @@ public class PaymentServiceImpl implements IPaymentService {
if (transfer == null || transfer.getStatus() == 1) {
throw new ServiceException(400, "转账记录已成功转账,流水id=" + tradeBillsId);
}
transferType = transfer.getInterfaceType();
if (transferType == null || transferType < 1 || transferType > 2) {
throw new ServiceException(400, "转账记录接口类型有误,流水id=" + tradeBillsId);
}
interfaceType = transfer.getInterfaceType();
if (transferType == 2) {
logger.info("manualDeal orderCode={}, tradeBillId={}, 转账接口类型为 {}", orderCode, tradeBillsId, interfaceType);
if (interfaceType != null && interfaceType == 2) {
logger.info("manualDeal orderCode={}, tradeBillId={}, 转账接口类型为 超过100万的接口", orderCode, tradeBillsId);
transferWhenExceedMillion(transfer.getId(), preSuccess, orderCode, account, amount, now);
return;
}
logger.info("manualDeal orderCode={}, tradeBillId={}, 转账接口类型为 小于100万的接口", orderCode, tradeBillsId);
jsonObject = alipayService.transferMoney(Long.toString(orderCode), account.getAlipayId(), account.getAlipayAccount(), amount);
if (jsonObject == null) {
logger.warn("manualDeal 转账失败 , req is {}", req);
... ... @@ -1127,7 +1133,7 @@ public class PaymentServiceImpl implements IPaymentService {
throw new ServiceException(500, "转账失败:返回code="+code+",order_id="+orderId);
}
} catch (Exception e) {
if (transferType != null && transferType == 2) {
if (interfaceType != null && interfaceType == 2) {
return;
}
logger.warn("manualDealErr 转账失败 , orderCode is {}, msg is {}", orderCode, e.getMessage());
... ...
... ... @@ -814,7 +814,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
*/
public int getUnfinishedOrderBySellerUid(Integer uid){
log.info("in seller order getUnfinishedOrderBySellerUid count uid {} ", uid);
List<Integer> statusList = OrderStatus.getUnfinishedOrderStatusCode();
List<Integer> statusList = ActionStatusHold.getUnfinishedOrderStatusCode();
Integer total = buyerOrderMapper.selectCntBySellerUidStatus(uid, statusList);
log.info("in seller order getUnfinishedOrderBySellerUid count uid {}, total {} ", uid, total);
return total;
... ...
... ... @@ -21,6 +21,7 @@ import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
... ... @@ -945,6 +946,36 @@ public class InBoxFacade {
}
}
/**
* 更低的出价提醒
* @param sog
*/
public void noticeSellerWhenOtherChangePriceLower(SellerOrderGoods sog,Set<Integer> noticeSellerUidList){
String prdName = sog.getProductName();
String sizeName = sog.getSizeName();
try {
executorService.execute(() -> {
// 发站内信
logger.info("record noticeSellerWhenOtherChangePriceLower for seller,noticeSellerUidList {}, sog {}", noticeSellerUidList, sog);
Product product = productMapper.selectByPrimaryKey(sog.getProductId());
String productCode = product.getProductCode();
String params = buildParams(prdName, sizeName,productCode,sog.getGoodsPrice().toPlainString());
noticeSellerUidList.stream().forEach(
sellerUid ->{
InboxReqVO req = buildInboxReqVO(sellerUid, params, InboxBusinessTypeEnum.NOTICE_SELLER_WHEN_OTHER_LOWER_PRICE);
InBoxResponse resp = inBoxSDK.addInbox(req);
logger.info("record seller sham send out inbox msg,sellerUid {}, prdName {},sizeName {} resp {}",
sellerUid, prdName, sizeName, resp);
}
);
});
} catch (Exception e) {
logger.warn("InBoxFacade noticeSellerWhenOtherChangePriceLower error inbox msg, noticeSellerUidList {}, sog {} ", noticeSellerUidList, sog, e);
}
}
/*********************************************************************
* 其他---短信
********************************************************************/
... ...
... ... @@ -6,7 +6,7 @@
<parent>
<groupId>com.yoho</groupId>
<artifactId>parent</artifactId>
<version>1.5.1-SNAPSHOT</version>
<version>1.5.4-SNAPSHOT</version>
</parent>
<groupId>com.yohoufo.fore</groupId>
... ...