...
|
...
|
@@ -4,10 +4,12 @@ import com.alibaba.fastjson.JSONException; |
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.core.config.ConfigReader;
|
|
|
import com.yoho.core.rabbitmq.YhProducer;
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yoho.service.model.union.bo.*;
|
|
|
import com.yoho.service.model.union.request.UnionShareOrderReqBO;
|
|
|
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;
|
...
|
...
|
@@ -49,6 +51,9 @@ import java.util.concurrent.atomic.AtomicInteger; |
|
|
@Service
|
|
|
public class UnionShareServiceImpl implements IUnionShareService,IBusinessExportService {
|
|
|
private Logger logger = LoggerFactory.getLogger(UnionShareServiceImpl.class);
|
|
|
private Logger mqLog = LoggerFactory.getLogger("cps_mq");
|
|
|
private Logger settlementLog = LoggerFactory.getLogger("cps_settlement");
|
|
|
// private Logger mqLog = LoggerFactory.getLogger("cps_mq");
|
|
|
|
|
|
@Autowired
|
|
|
private UnionShareOrdersMapper unionShareOrdersMapper;
|
...
|
...
|
@@ -332,16 +337,24 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<UnionShareSettlement> querySettlementRecord(UnionShareOrderReqBO unionShareOrderReqBO) {
|
|
|
public PageResponseBO<UnionShareSettlement> querySettlementRecord(UnionShareOrderReqBO unionShareOrderReqBO) {
|
|
|
//先从缓存获取
|
|
|
String key = "settlementRecord";
|
|
|
UnionShareSettlementListBO cacheResult = getFromRedis(ShareOrdersKeyEnum.SETTLEMENT_LIST, unionShareOrderReqBO.getUid(),
|
|
|
UnionShareSettlementListBO.class, key, String.valueOf(unionShareOrderReqBO.getPage()), String.valueOf(unionShareOrderReqBO.getSize()));
|
|
|
PageResponseBO<UnionShareSettlement> cacheResult = getFromRedis(ShareOrdersKeyEnum.SETTLEMENT_LIST, unionShareOrderReqBO.getUid(),
|
|
|
PageResponseBO.class, key, String.valueOf(unionShareOrderReqBO.getPage()), String.valueOf(unionShareOrderReqBO.getSize()));
|
|
|
if (cacheResult != null) {
|
|
|
logger.debug("UnionShareServiceImpl :: querySettlementRecord get redis cache ,uid is {},cacheResult is {}",unionShareOrderReqBO.getUid(),cacheResult);
|
|
|
return cacheResult.getList();
|
|
|
return cacheResult;
|
|
|
}
|
|
|
//数据库获取
|
|
|
//获取总数
|
|
|
PageResponseBO<UnionShareSettlement> response = new PageResponseBO<>();
|
|
|
Integer count = unionShareSettlementMapper.selectSettlementRecordCount(unionShareOrderReqBO.getUid());
|
|
|
if (count <= 0){
|
|
|
logger.info("UnionShareServiceImpl :: querySettlementRecord count is 0");
|
|
|
return response;
|
|
|
}
|
|
|
//分页
|
|
|
List<UnionShareSettlement> unionShareSettlementList = unionShareSettlementMapper.selectSettlementRecordByUid(unionShareOrderReqBO.getUid(),
|
|
|
(unionShareOrderReqBO.getPage()-1)*unionShareOrderReqBO.getSize(), unionShareOrderReqBO.getSize());
|
|
|
if (CollectionUtils.isNotEmpty(unionShareSettlementList)){
|
...
|
...
|
@@ -351,34 +364,56 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
unionShareSettlement.setSettlementTimeStr(DateUtils.int2DateStr(unionShareSettlement.getSettlementTime(), DateUtils.POINT_FOMARTPATTER));
|
|
|
}
|
|
|
}
|
|
|
response.setSize(unionShareOrderReqBO.getSize());
|
|
|
response.setPage(unionShareOrderReqBO.getPage());
|
|
|
response.setTotal(count);
|
|
|
if (count % unionShareOrderReqBO.getSize() == 0) {
|
|
|
response.setTotalPage(count/unionShareOrderReqBO.getSize());
|
|
|
} else {
|
|
|
response.setTotalPage(count/unionShareOrderReqBO.getSize()+1);
|
|
|
}
|
|
|
response.setList(unionShareSettlementList);
|
|
|
//设置缓存
|
|
|
UnionShareSettlementListBO unionShareSettlementListBO = new UnionShareSettlementListBO();
|
|
|
unionShareSettlementListBO.setList(unionShareSettlementList);
|
|
|
addToRedis(ShareOrdersKeyEnum.SETTLEMENT_LIST,unionShareOrderReqBO.getUid(),unionShareSettlementListBO,key, String.valueOf(unionShareOrderReqBO.getPage()), String.valueOf(unionShareOrderReqBO.getSize()));
|
|
|
return unionShareSettlementList;
|
|
|
addToRedis(ShareOrdersKeyEnum.SETTLEMENT_LIST,unionShareOrderReqBO.getUid(),response,key, String.valueOf(unionShareOrderReqBO.getPage()), String.valueOf(unionShareOrderReqBO.getSize()));
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<UnionShareOrders> queryOrderList(UnionShareOrderReqBO unionShareOrderReqBO) {
|
|
|
public PageResponseBO<UnionShareOrders> queryOrderList(UnionShareOrderReqBO unionShareOrderReqBO) {
|
|
|
//先从缓存获取
|
|
|
UnionShareOrdersListBO cacheResult = getFromRedis(ShareOrdersKeyEnum.ORDER_LIST, unionShareOrderReqBO.getUid(),UnionShareOrdersListBO.class, unionShareOrderReqBO.getTab1().toString(),
|
|
|
PageResponseBO<UnionShareOrders> cacheResult = getFromRedis(ShareOrdersKeyEnum.ORDER_LIST, unionShareOrderReqBO.getUid(),PageResponseBO.class, unionShareOrderReqBO.getTab1().toString(),
|
|
|
unionShareOrderReqBO.getTab2().toString(), String.valueOf(unionShareOrderReqBO.getPage()), String.valueOf(unionShareOrderReqBO.getSize()));
|
|
|
if (cacheResult != null) {
|
|
|
logger.debug("UnionShareServiceImpl :: queryOrderList get redis cache ,uid is {},cacheResult is {}",unionShareOrderReqBO.getUid(),cacheResult);
|
|
|
return cacheResult.getList();
|
|
|
return cacheResult;
|
|
|
}
|
|
|
//数据库获取
|
|
|
//获取总数
|
|
|
PageResponseBO<UnionShareOrders> response = new PageResponseBO<>();
|
|
|
Integer count = unionShareOrdersMapper.selectOrderListCount(unionShareOrderReqBO);
|
|
|
if (count <= 0){
|
|
|
logger.info("UnionShareServiceImpl :: queryOrderList count is 0");
|
|
|
return response;
|
|
|
}
|
|
|
//分页
|
|
|
//tab1表示1、全部订单;2、有效订单;3、无效订单 tab2表示1、已付款;2、待结算;3、结算中
|
|
|
unionShareOrderReqBO.setStart((unionShareOrderReqBO.getPage()-1)*unionShareOrderReqBO.getSize());
|
|
|
List<UnionShareOrders> unionShareOrdersList = unionShareOrdersMapper.selectOrderList(unionShareOrderReqBO);
|
|
|
//处理订单列表数据
|
|
|
dealShareOrderList(unionShareOrdersList);
|
|
|
response.setSize(unionShareOrderReqBO.getSize());
|
|
|
response.setPage(unionShareOrderReqBO.getPage());
|
|
|
response.setTotal(count);
|
|
|
if (count % unionShareOrderReqBO.getSize() == 0) {
|
|
|
response.setTotalPage(count/unionShareOrderReqBO.getSize());
|
|
|
} else {
|
|
|
response.setTotalPage(count/unionShareOrderReqBO.getSize()+1);
|
|
|
}
|
|
|
response.setList(unionShareOrdersList);
|
|
|
//设置缓存
|
|
|
UnionShareOrdersListBO unionShareOrdersListBO = new UnionShareOrdersListBO();
|
|
|
unionShareOrdersListBO.setList(unionShareOrdersList);
|
|
|
addToRedis(ShareOrdersKeyEnum.ORDER_LIST,unionShareOrderReqBO.getUid(),unionShareOrdersListBO,unionShareOrderReqBO.getTab1().toString(), unionShareOrderReqBO.getTab2().toString(),
|
|
|
addToRedis(ShareOrdersKeyEnum.ORDER_LIST,unionShareOrderReqBO.getUid(),response,unionShareOrderReqBO.getTab1().toString(), unionShareOrderReqBO.getTab2().toString(),
|
|
|
String.valueOf(unionShareOrderReqBO.getPage()), String.valueOf(unionShareOrderReqBO.getSize()));
|
|
|
return unionShareOrdersList;
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -519,34 +554,34 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
*/
|
|
|
@Override
|
|
|
public BigDecimal addSettlement(Integer uid) {
|
|
|
logger.info("addSettlement enter,uid is {}",uid);
|
|
|
settlementLog.info("addSettlement enter,uid is {}",uid);
|
|
|
if (uid == null ) {
|
|
|
return null;
|
|
|
throw new ServiceException(ServiceError.USER_ID_ERROR);
|
|
|
}
|
|
|
//查询该用户是否为特邀用户
|
|
|
int count = unionShareUserMapper.selectCountByUid(uid);
|
|
|
if (count == 0) {
|
|
|
//不是特邀用户
|
|
|
logger.info("addSettlement end,can not find unionType,uid is {}",uid);
|
|
|
return null;
|
|
|
settlementLog.info("addSettlement end,can not find unionType,uid is {}",uid);
|
|
|
throw new ServiceException(ServiceError.USER_ID_ERROR);
|
|
|
}
|
|
|
//查询是否有处理中的提现
|
|
|
if (hasSettlement(uid)) {
|
|
|
//有处理中的提现单,不可提现
|
|
|
logger.info("addSettlement end,hasSettlement,uid is {}",uid);
|
|
|
return null;
|
|
|
settlementLog.info("addSettlement end,hasSettlement,uid is {}",uid);
|
|
|
throw new ServiceException(ServiceError.UNION_HASSETTLEMENT_ERROR);
|
|
|
}
|
|
|
|
|
|
//查询当前是否有可提现的订单
|
|
|
int orderCount = unionShareOrdersMapper.selectCountByCondition(uid,ShareOrdersStatusEnum.CAN_SETTLE.getCode());
|
|
|
if (orderCount == 0 ) {
|
|
|
//没有可以提现的订单
|
|
|
logger.info("addSettlement end,has not remaining settlement,uid is {}",uid);
|
|
|
return null;
|
|
|
settlementLog.info("addSettlement end,has not remaining settlement,uid is {}",uid);
|
|
|
throw new ServiceException(ServiceError.UNION_HASNOT_REMAINING_SETTLEMENT);
|
|
|
}
|
|
|
//todo 生成取现单,绑定订单,考虑是否异步操作
|
|
|
// 生成取现单,绑定订单
|
|
|
BigDecimal amount = relateSettlementAndOrder(uid);
|
|
|
logger.info("addSettlement end,remaining settlement is {},uid is {}",amount,uid);
|
|
|
settlementLog.info("addSettlement end,remaining settlement is {},uid is {}",amount,uid);
|
|
|
return amount;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -635,22 +670,22 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
* */
|
|
|
public BigDecimal relateSettlementAndOrder(int uid) {
|
|
|
|
|
|
logger.info("relateSettlementAndOrder enter,uid is {}",uid);
|
|
|
settlementLog.info("relateSettlementAndOrder enter,uid is {}",uid);
|
|
|
|
|
|
//生成提现编号
|
|
|
String settlementCode = createSettlementCode();
|
|
|
logger.info("relateSettlementAndOrder,uid is {},settlementCode is {}",uid,settlementCode);
|
|
|
settlementLog.info("relateSettlementAndOrder,uid is {},settlementCode is {}",uid,settlementCode);
|
|
|
|
|
|
//更新订单状态,由可结算变为打款中
|
|
|
int updateTime = DateUtil.getCurrentTimeSecond();
|
|
|
int count=unionShareOrdersMapper.updateStatusByUid(uid,settlementCode, ShareOrdersStatusEnum.CAN_SETTLE.getCode(), ShareOrdersStatusEnum.SETTLE.getCode(), updateTime);
|
|
|
if (count == 0) {
|
|
|
logger.info("relateSettlementAndOrder end,uid is {},settlementCode is {},There are no available orders.",uid,settlementCode);
|
|
|
return null;
|
|
|
settlementLog.info("relateSettlementAndOrder end,uid is {},settlementCode is {},There are no available orders.",uid,settlementCode);
|
|
|
throw new ServiceException(ServiceError.UNION_SETTLEMENT_UNAVAILABLE_ORDER_ERROR);
|
|
|
}
|
|
|
//计算提现金额
|
|
|
BigDecimal totalAmount=unionShareOrdersMapper.selectAmountBySettleCode(uid, settlementCode);
|
|
|
logger.info("relateSettlementAndOrder,uid is {},settlementCode is {},totalAmount is {}",uid,settlementCode,totalAmount);
|
|
|
settlementLog.info("relateSettlementAndOrder,uid is {},settlementCode is {},totalAmount is {}",uid,settlementCode,totalAmount);
|
|
|
|
|
|
//生成提现单
|
|
|
UnionShareSettlement insertReq = new UnionShareSettlement();
|
...
|
...
|
@@ -662,8 +697,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
insertReq.setStatus((byte)1);//是否打款成功:1-处理中,2-已打款
|
|
|
int num=unionShareSettlementMapper.insertSelective(insertReq);
|
|
|
if (num < 1) {
|
|
|
//插入失败
|
|
|
logger.warn("relateSettlementAndOrder end,uid is {},settlementCode is {},totalAmount is {},insert nothing.",uid,settlementCode,totalAmount);
|
|
|
//插入失败 todo 日志记录
|
|
|
settlementLog.warn("relateSettlementAndOrder end,uid is {},settlementCode is {},totalAmount is {},insert nothing.",uid,settlementCode,totalAmount);
|
|
|
}
|
|
|
|
|
|
Set<String> orderCodes = new HashSet<>();
|
...
|
...
|
@@ -679,20 +714,21 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
}
|
|
|
if (orderCodes.size() == 0) {
|
|
|
//不该查不到订单
|
|
|
logger.warn("relateSettlementAndOrder end,uid is {},settlementCode is {},totalAmount is {},can not find orders.",uid,settlementCode,totalAmount);
|
|
|
return null;
|
|
|
settlementLog.warn("relateSettlementAndOrder end,uid is {},settlementCode is {},totalAmount is {},can not find orders.",uid,settlementCode,totalAmount);
|
|
|
throw new ServiceException(ServiceError.UNION_SETTLEMENT_CANNOT_FIND_ORDER_ERROR);
|
|
|
}
|
|
|
|
|
|
|
|
|
//清缓存
|
|
|
clearShareOrderRedis(uid);
|
|
|
|
|
|
//todo 发送取现mq给erp SETTLEMENT_TOPIC
|
|
|
// 发送取现mq给erp SETTLEMENT_TOPIC
|
|
|
ShareSettlementBo bo = new ShareSettlementBo();
|
|
|
BeanUtils.copyProperties(insertReq,bo);
|
|
|
bo.setOrderCodes(orderCodes);
|
|
|
logger.info("relateSettlementAndOrder,send mq {} to erp,uid is {},settlementCode is {},bo is {}", SETTLEMENT_TOPIC, uid, settlementCode, bo);
|
|
|
mqLog.info("relateSettlementAndOrder,send mq {} to erp,uid is {},settlementCode is {},bo is {}", SETTLEMENT_TOPIC, uid, settlementCode, bo);
|
|
|
yhProducer.send(SETTLEMENT_TOPIC, bo);
|
|
|
settlementLog.info("relateSettlementAndOrder,send mq {} to erp success,uid is {},settlementCode is {},bo is {}", SETTLEMENT_TOPIC, uid, settlementCode, bo);
|
|
|
return totalAmount;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -708,10 +744,17 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
|
|
|
//是否打款成功:1-处理中,2-已打款
|
|
|
if (bo.getStatus() == null || bo.getStatus().intValue() != 2) {
|
|
|
logger.info("updateSettlementStatus end,status error changed,bo is {}",bo);
|
|
|
return;
|
|
|
}
|
|
|
UnionShareSettlement unionShareSettlement = unionShareSettlementMapper.selectByCode(bo.getSettlementCode());
|
|
|
if (unionShareSettlement == null) {
|
|
|
logger.info("updateSettlementStatus end,settlementCode doesn't exist,bo is {}",bo);
|
|
|
return;
|
|
|
}
|
|
|
if (unionShareSettlement.getStatus().intValue()==2) {
|
|
|
//已更新,多余mq略过
|
|
|
logger.info("updateSettlementStatus end,status is already changed,bo is {}",bo);
|
|
|
return;
|
|
|
}
|
|
|
//更新结算状态
|
...
|
...
|
|