Authored by csgyoho

Merge branch 'dev_180508_联盟红人推广' of http://git.yoho.cn/yoho30/yohobuy-union into dev_180508_联盟红人推广

# Conflicts:
#	server/src/main/java/com/yoho/unions/server/restapi/UnionShareRest.java
#	server/src/main/java/com/yoho/unions/server/service/IUnionShareService.java
#	server/src/main/java/com/yoho/unions/server/service/impl/UnionShareServiceImpl.java
... ... @@ -10,7 +10,8 @@ public enum ShareOrdersKeyEnum {
ORDER_LIST("unions:share:orderList:","type:{}:status:{}:page:{}:limit:{}",3600,"订单列表"),
ORDER_INFO("unions:share:orderInfo:","orderCode:{}",3600,"订单详情"),
USER_SETTLEMENT("unions:share:userSettlement:","type:{}",3600,"用户提现未提现总计"),
SETTLEMENT_LIST("unions:share:settlementList:","page:{}:limit:{}",3600,"提现列表");
SETTLEMENT_LIST("unions:share:settlementList:","page:{}:limit:{}",3600,"提现列表"),
UNION_TYPE("unions:share:unionType:","",3600,"用户登录时获取对应的渠道号");
private String preKey;
private String periodHashKey;
... ...
package com.yoho.unions.convert;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* @author xieyong
*
*/
@Component
public class BeanConvert implements Convert{
private final Logger log = LoggerFactory.getLogger(getClass());
//拷贝不支持对象里面嵌套对象拷贝
/* (non-Javadoc)
* @see com.yoho.product.convert.Convert#convertFrom(java.lang.Object, java.lang.Object, java.lang.Class)
*/
@SuppressWarnings("unchecked")
@Override
public final <T> T convertFrom(Object source, Object target, Class<T> clazz) {
if (source == null){
return null;
}
Preconditions.checkNotNull(target, "target can't be null");
BeanCopier copier = BeanCopier.create(source.getClass(), target.getClass(), false);
copier.copy(source, target, null);
return (T) target;
}
/**
* 将多个对象拷贝到一个目的对象, 不需要实例化目的对象
*
* @param targetClazz 目的对象的CLASS
* @param sources 源对象
* @param <T> 目的对象类型
*
* @return 目的对象实例, 拷贝之后的结果
* @author create by DengXinFei 2016-1-23
*/
public static <T>T copyBeans(Class<T> targetClazz, Object... sources){
if(null == sources || sources.length == 0){
return null;
}
T targetObj = null;
try{
targetObj = targetClazz.newInstance();
for(Object sourceObj: sources){
BeanCopier copier = BeanCopier.create(sourceObj.getClass(), targetClazz, false);
copier.copy(sourceObj, targetObj, null);
}
}catch(Exception e){
e.printStackTrace();
return null;
}
return targetObj;
}
/* (non-Javadoc)
* @see com.yoho.product.convert.Convert#convertFromList(java.util.List, java.lang.Class)
*/
@SuppressWarnings("unchecked")
@Override
public final <T> List<T> convertFromList(List<? extends Object> sourceList,Class<T> clazz) {
if(CollectionUtils.isEmpty(sourceList))
{
return new ArrayList<T>(0);
}
BeanCopier copier = BeanCopier.create(sourceList.get(0).getClass(), clazz, false);
List<T> list=Lists.newArrayList();
//这里反射性能可能不佳,要测试
try
{
Object target=null;
for (Object t : sourceList) {
target=clazz.newInstance();
copier.copy(t, target, null);
list.add((T)target);
}
}
catch (Exception e) {
log.error("other exception" ,e);
throw new RuntimeException("other exception",e);
}
return list;
}
}
... ...
package com.yoho.unions.convert;
import java.util.List;
/**
* 用做两个对象之间的拷贝
* @author xieyong
*
*/
public interface Convert
{
/**
* 在拷贝时,属性名字和类型保持一样,不然就拷贝不进去,会存在属性丢失,如果dao模型整改,这个可以替换掉<br>
* 将源对象拷贝到目标对象,并返回目标对象
* @param source 源对象
* @param target 目标对象
* @param clazz 返回的类型
* @return
*/
<T> T convertFrom(Object source, Object target, Class<T> clazz);
/**
* 在拷贝时,属性名字和类型保持一样,不然就拷贝不进去,会存在属性丢失,如果dao模型整改,这个可以替换掉<br>
* 将源对象拷贝到目标对象,并返回目标对象list
* @param source
* @param obj
* @param clazz
* @return
*/
<T> List<T> convertFromList(List<? extends Object> source, Class<T> clazz);
}
... ...
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;
... ... @@ -47,4 +48,8 @@ public interface UnionShareOrdersMapper {
int updateStatusByUid(@Param("promoteUid")int promoteUid,@Param("settlementCode")String settlementCode,@Param("oldStatus")String oldStatus,@Param("newStatus")String newStatus,@Param("updateTime")int updateTime);
int updateByPrimaryKey(UnionShareOrders record);
UnionShareOrders selectRecentlyOrderLimitTen(@Param("uid") int uid);
List<UnionShareOrders> selectOrderList(@Param("params") UnionShareOrderReqBO unionShareOrderReqBO);
}
\ No newline at end of file
... ...
package com.yoho.unions.dal;
import com.yoho.unions.dal.model.UnionShareOrdersProduct;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface UnionShareOrdersProductMapper {
int deleteByPrimaryKey(Integer id);
... ... @@ -14,4 +17,6 @@ public interface UnionShareOrdersProductMapper {
int updateByPrimaryKeySelective(UnionShareOrdersProduct record);
int updateByPrimaryKey(UnionShareOrdersProduct record);
List<UnionShareOrdersProduct> selectOrdersProductByOrderCode(@Param("orderCode") String orderCode);
}
\ No newline at end of file
... ...
... ... @@ -4,6 +4,7 @@ import com.yoho.unions.dal.model.UnionShareSettlement;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.List;
public interface UnionShareSettlementMapper {
int deleteByPrimaryKey(Integer id);
... ... @@ -23,4 +24,6 @@ public interface UnionShareSettlementMapper {
int updateByPrimaryKeySelective(UnionShareSettlement record);
int updateByPrimaryKey(UnionShareSettlement record);
List<UnionShareSettlement> selectSettlementRecordByUid(@Param("uid") int uid, @Param("start") Integer start, @Param("size") Integer size);
}
\ No newline at end of file
... ...
... ... @@ -9,6 +9,8 @@ public class UnionShareUser {
private Integer updateTime;
private String note;
public Integer getId() {
return id;
}
... ... @@ -40,4 +42,12 @@ public class UnionShareUser {
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
}
\ No newline at end of file
... ...
... ... @@ -276,4 +276,49 @@
update_time = #{updateTime,jdbcType=INTEGER}
where promote_uid = #{promoteUid,jdbcType=INTEGER} and status = #{oldStatus,jdbcType=VARCHAR}
</update>
<select id="selectRecentlyOrderLimitTen" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from union_share_orders
where promote_uid = #{uid,jdbcType=INTEGER}
order by order_time desc
limit 0,10
</select>
<select id="selectOrderList" resultMap="BaseResultMap" parameterType="com.yoho.service.model.union.request.UnionShareOrderReqBO">
select
<include refid="Base_Column_List" />
from union_share_orders
where promote_uid = #{uid,jdbcType=INTEGER}
<if test="tab1 != null and tab1 == 1 and tab2 == null">
AND status != 100
</if>
<if test="tab1 != null and tab1 == 1 and tab2 == 1">
AND status = 10
</if>
<if test="tab1 != null and tab1 == 1 and tab2 == 2">
AND status = 20
</if>
<if test="tab1 != null and tab1 == 1 and tab2 == 3">
AND status IN (30,40)
</if>
<if test="tab1 != null and tab1 == 2 and tab2 == null">
AND status IN (10,20,30,40)
</if>
<if test="tab1 != null and tab1 == 2 and tab2 == 1">
AND status = 10
</if>
<if test="tab1 != null and tab1 == 2 and tab2 == 2">
AND status = 20
</if>
<if test="tab1 != null and tab1 == 2 and tab2 == 3">
AND status IN (30,40)
</if>
<if test="tab1 != null and tab1 == 3">
AND status IN (91,92,93)
</if>
order by order_time desc
limit 0,10
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -114,4 +114,10 @@
num = #{num,jdbcType=TINYINT}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectOrdersProductByOrderCode" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from union_share_orders_product
where order_code = #{orderCode,jdbcType=INTEGER}
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -132,4 +132,12 @@
update_time = #{updateTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectSettlementRecordByUid" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from union_share_settlement
where promote_uid = #{uid,jdbcType=INTEGER}
order by settlement_time desc
limit #{start,jdbcType=INTEGER}, #{size,jdbcType=INTEGER}
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -5,7 +5,7 @@
<parent>
<groupId>com.yoho</groupId>
<artifactId>parent</artifactId>
<version>1.3.8-SNAPSHOT</version>
<version>1.3.9-SNAPSHOT</version>
</parent>
<groupId>com.yoho.dsf</groupId>
<artifactId>yoho-unions</artifactId>
... ...
... ... @@ -31,9 +31,13 @@ public class UnionSettleUpdateConsumer implements YhConsumer {
}
List<Object> list = JsonUtil.jsonToObject(o.toString(), List.class);
list.forEach(l->{
ShareSettlementBo bo = JsonUtil.jsonToObject(l.toString(), ShareSettlementBo.class);
//TODO 提现结算单状态变更
unionShareService.updateSettlementStatus(bo);
try {
ShareSettlementBo bo = JsonUtil.jsonToObject(l.toString(), ShareSettlementBo.class);
//TODO 提现结算单状态变更
unionShareService.updateSettlementStatus(bo);
} catch (Exception e) {
logger.warn("UnionSettleUpdateConsumer,handleMessage fail! obj is {}, e {}",l,e.getMessage());
}
});
} catch (Exception e) {
... ...
... ... @@ -32,9 +32,13 @@ public class UnionShareOrderConsumer implements YhConsumer {
List<Object> list = JsonUtil.jsonToObject(o.toString(), List.class);
list.forEach(l->{
ShareOrderBo bo = JsonUtil.jsonToObject(l.toString(), ShareOrderBo.class);
//TODO 订单插入或更新
unionShareService.saveOrUpdateOrder(bo);
try {
ShareOrderBo bo = JsonUtil.jsonToObject(l.toString(), ShareOrderBo.class);
//TODO 订单插入或更新
unionShareService.saveOrUpdateOrder(bo);
} catch (Exception e) {
logger.warn("UnionShareOrderConsumer,handleMessage fail! bo is {}, e {}",l,e.getMessage());
}
});
} catch (Exception e) {
logger.warn("UnionShareOrderConsumer,handleMessage fail! obj is {}, e {}",o,e.getMessage());
... ...
package com.yoho.unions.server.restapi;
import com.yoho.core.common.utils.JsonUtil;
import com.yoho.service.model.union.bo.ShareOrderBo;
import com.yoho.service.model.union.bo.ShareUserSettlementInfoBo;
import com.yoho.service.model.union.request.UnionShareOrderReqBO;
import com.yoho.service.model.union.request.UnionShareOrderSearchReqBO;
import com.yoho.service.model.union.response.PageUnionShareOrderRspBO;
import com.yoho.service.model.union.response.UnionResponse;
import com.yoho.unions.common.ApiResponse;
import com.yoho.unions.dal.model.UnionShareOrders;
import com.yoho.unions.dal.model.UnionShareSettlement;
import com.yoho.unions.dal.model.UnionShareUser;
import com.yoho.unions.server.service.IUnionShareService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -14,7 +17,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.math.BigDecimal;
... ... @@ -51,17 +53,120 @@ public class UnionShareRest {
@RequestMapping("/queryUnionShareOrders")
@ResponseBody
public ApiResponse queryUnionShareOrders(UnionShareOrderSearchReqBO reqBO){
public ApiResponse queryUnionShareOrders(UnionShareOrderSearchReqBO reqBO) {
log.info("enter queryUnionShareOrders. param UnionShareOrderReqBO={}", reqBO);
if(reqBO==null){
if (reqBO == null) {
return new ApiResponse.ApiResponseBuilder().code(500).message("缺少参数").build();
}
try{
try {
PageUnionShareOrderRspBO unionOrderRspBO = unionShareService.queryUnionShareOrders(reqBO);
return new ApiResponse.ApiResponseBuilder().code(200).message("查询共享联盟订单").data(unionOrderRspBO).build();
}catch (Exception e){
log.warn("queryUnionShareOrders error exception is {}",e);
} catch (Exception e) {
log.warn("queryUnionShareOrders error exception is {}", e);
return new ApiResponse.ApiResponseBuilder().code(500).message("失败").build();
}
}
/**
* 用户登录时获取对应的渠道号
* Created by qing.zhao on 2018/5/15
* @param uid
* @return
*/
@RequestMapping("/queryUnionTypeByUid")
@ResponseBody
public UnionResponse queryUnionTypeByUid(int uid){
log.info("UnionShareRest :: queryUnionTypeByUid uid is{}", uid);
try {
UnionShareUser unionShareUser = unionShareService.queryUnionTypeByUid(uid);
return new UnionResponse(200, "queryUnionTypeByUid success",unionShareUser);
}catch (Exception e){
log.error("UnionShareRest :: queryUnionTypeByUid error", e);
return new UnionResponse(500,"queryUnionTypeByUid error!");
}
}
/**
* 用户前台获取个人推广近期订单(10个)
* Created by qing.zhao on 2018/5/15
* @param uid
* @return
*/
@RequestMapping("/queryRecentlyOrderLimitTen")
@ResponseBody
public UnionResponse queryRecentlyOrderLimitTen(int uid){
log.info("UnionShareRest :: queryRecentlyOrderLimitTen uid is{}", uid);
try {
UnionShareOrders unionShareOrders = unionShareService.queryRecentlyOrderLimitTen(uid);
return new UnionResponse(200, "queryRecentlyOrderLimitTen success",unionShareOrders);
}catch (Exception e){
log.error("UnionShareRest :: queryRecentlyOrderLimitTen error", e);
return new UnionResponse(500,"queryRecentlyOrderLimitTen error!");
}
}
/**
* 订单明细
* Created by qing.zhao on 2018/5/15
* @param orderCode
* @return
*/
@RequestMapping("/queryOderDetail")
@ResponseBody
public UnionResponse queryOderDetail(String orderCode){
log.info("UnionShareRest :: queryOderDetail orderCode is{}", orderCode);
try {
ShareOrderBo shareOrderBo = unionShareService.queryOrderDetail(orderCode);
return new UnionResponse(200, "queryOderDetail success",shareOrderBo);
}catch (Exception e){
log.error("UnionShareRest :: queryOderDetail error", e);
return new UnionResponse(500,"queryOderDetail error!");
}
}
/**
* 提现记录列表
* Created by qing.zhao on 2018/5/15
* @param unionShareOrderReqBO
* @return
*/
@RequestMapping("/querySettlementRecord")
@ResponseBody
public UnionResponse querySettlementRecord(UnionShareOrderReqBO unionShareOrderReqBO){
log.info("UnionShareRest :: querySettlementRecord unionShareOrderReqBO is{}", unionShareOrderReqBO);
if (null == unionShareOrderReqBO || null == unionShareOrderReqBO.getUid()){
return new UnionResponse(400, "querySettlementRecord params is null");
}
try {
List<UnionShareSettlement> unionShareSettlement = unionShareService.querySettlementRecord(unionShareOrderReqBO.getUid(),
unionShareOrderReqBO.getPage()*unionShareOrderReqBO.getSize(), unionShareOrderReqBO.getSize());
return new UnionResponse(200, "querySettlementRecord success",unionShareSettlement);
}catch (Exception e){
log.error("UnionShareRest :: querySettlementRecord error", e);
return new UnionResponse(500,"querySettlementRecord error!");
}
}
/**
* 订单列表
* //tab1表示1、全部订单;2、有效订单;3、无效订单 tab2表示1、已付款;2、待结算;3、结算中
* Created by qing.zhao on 2018/5/15
* @param unionShareOrderReqBO csg
* @return
*/
@RequestMapping("/queryOrderList")
@ResponseBody
public UnionResponse queryOrderList(UnionShareOrderReqBO unionShareOrderReqBO){
log.info("UnionShareRest :: queryOrderList unionShareOrderReqBO is{}", unionShareOrderReqBO);
if (null == unionShareOrderReqBO || null == unionShareOrderReqBO.getUid()){
return new UnionResponse(400, "queryOrderList params is null");
}
try {
List<UnionShareOrders> unionShareOrdersList = unionShareService.queryOrderList(unionShareOrderReqBO);
return new UnionResponse(200, "queryOrderList success",unionShareOrdersList);
}catch (Exception e){
log.error("UnionShareRest :: queryOrderList error", e);
return new UnionResponse(500,"queryOrderList error!");
}
}
}
... ...
... ... @@ -3,10 +3,15 @@ package com.yoho.unions.server.service;
import com.yoho.service.model.union.bo.ShareOrderBo;
import com.yoho.service.model.union.bo.ShareSettlementBo;
import com.yoho.service.model.union.bo.ShareUserSettlementInfoBo;
import com.yoho.service.model.union.request.UnionShareOrderReqBO;
import com.yoho.service.model.union.request.UnionShareOrderSearchReqBO;
import com.yoho.service.model.union.response.PageUnionShareOrderRspBO;
import com.yoho.unions.dal.model.UnionShareOrders;
import com.yoho.unions.dal.model.UnionShareSettlement;
import com.yoho.unions.dal.model.UnionShareUser;
import java.math.BigDecimal;
import java.util.List;
/**
* 联盟红人推广返利
... ... @@ -34,4 +39,39 @@ public interface IUnionShareService {
* 获取用户可提现金额、已提现金额、是否可以提现
* */
ShareUserSettlementInfoBo getUserSettleMentInfo(Integer uid);
/**
* 用户登录时获取对应的渠道号
* @param uid
* @return
*/
UnionShareUser queryUnionTypeByUid(int uid);
/**
* 用户前台获取个人推广近期订单(10个)
* @param uid
* @return
*/
UnionShareOrders queryRecentlyOrderLimitTen(int uid);
/**
* 订单明细
* @param orderCode
* @return
*/
ShareOrderBo queryOrderDetail(String orderCode);
/**
* 提现记录列表
* @param uid
* @return
*/
List<UnionShareSettlement> querySettlementRecord(int uid, Integer start, Integer size);
/**
* 订单列表
* @param unionShareOrderReqBO
* @return
*/
List<UnionShareOrders> queryOrderList(UnionShareOrderReqBO unionShareOrderReqBO);
}
... ...
... ... @@ -5,11 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.yoho.core.config.ConfigReader;
import com.yoho.core.rabbitmq.YhProducer;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.union.bo.ShareOrderBo;
import com.yoho.service.model.union.bo.ShareSettlementBo;
import com.yoho.service.model.union.bo.ShareUserSettlementInfoBo;
import com.yoho.service.model.union.bo.UnionShareOrderSearchBo;
import com.yoho.service.model.union.request.UnionOrderReqBO;
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.PageUnionShareOrderRspBO;
... ... @@ -22,6 +18,8 @@ import com.yoho.unions.common.redis.RedisValueCache;
import com.yoho.unions.common.service.IBusinessExportService;
import com.yoho.unions.common.utils.DateUtil;
import com.yoho.unions.common.utils.RandomUtil;
import com.yoho.unions.convert.BeanConvert;
import com.yoho.unions.convert.Convert;
import com.yoho.unions.dal.*;
import com.yoho.unions.dal.model.*;
import com.yoho.unions.server.service.IUnionShareService;
... ... @@ -30,6 +28,7 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
... ... @@ -39,6 +38,7 @@ import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
/**
* 联盟红人推广返利
* Created by mingdan.ge on 2018/5/10.
... ... @@ -69,6 +69,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
private AtomicInteger atomicInt = new AtomicInteger(0);
private Convert convert = new BeanConvert();
private String SETTLEMENT_TOPIC = "front.union.shareSettleAdd";
private String NEW_USER_REBATES_RATIO_KEY = "union.newUserRebatesRatio";
private String OLD_USER_REBATES_RATIO_KEY = "union.oldUserRebatesRatio";
... ... @@ -94,7 +96,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
result.setCanSettlement(canSettlement);
result.setHistorySettlementAmount(historySettlementAmount);
result.setSettlementAmount(settlementAmount);
logger.info("getUserSettleMentInfo enter,uid is {},result is {}",uid,result);
logger.info("getUserSettleMentInfo end,uid is {},result is {}",uid,result);
return result;
}
... ... @@ -205,6 +207,68 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
return userOrderDatailBOMap;
}
/**
* 用户登录时获取对应的渠道号
* @param uid
* @return
*/
@Override
public UnionShareUser queryUnionTypeByUid(int uid) {
//先从缓存获取
String key = "unionType";
UnionShareUser cacheResult = getFromRedis(ShareOrdersKeyEnum.UNION_TYPE, uid, UnionShareUser.class, key);
if (cacheResult != null) {
logger.info("UnionShareServiceImpl :: queryUnionTypeByUid get redis cache ,uid is {},cacheResult is {}",uid,cacheResult);
return cacheResult;
}
//获取数据库
UnionShareUser unionShareUser = unionShareUserMapper.selectByUid(uid);
//设置返回文案
unionShareUser.setNote("邀请新客购买返点" + configReader.getDouble(NEW_USER_REBATES_RATIO_KEY, 0.1) + ",老客" + configReader.getDouble(OLD_USER_REBATES_RATIO_KEY, 0.03));
//设置缓存
addToRedis(ShareOrdersKeyEnum.UNION_TYPE, uid, unionShareUser, key);
return unionShareUser;
}
/**
* 用户前台获取个人推广近期订单(10个)
* @param uid
* @return
*/
@Override
public UnionShareOrders queryRecentlyOrderLimitTen(int uid) {
UnionShareOrders unionShareOrders = unionShareOrdersMapper.selectRecentlyOrderLimitTen(uid);
return unionShareOrders;
}
@Override
public ShareOrderBo queryOrderDetail(String orderCode) {
UnionShareOrders unionShareOrders = unionShareOrdersMapper.selectByCode(orderCode);
if (null == unionShareOrders){
return null;
}
List<UnionShareOrdersProduct> unionShareOrdersProductlist = unionShareOrdersProductMapper.selectOrdersProductByOrderCode(orderCode);
List<ShareOrdersProductBo> shareOrdersProductBoList = convert.convertFromList(unionShareOrdersProductlist, ShareOrdersProductBo.class);
ShareOrderBo shareOrderBo = new ShareOrderBo();
shareOrderBo = convert.convertFrom(unionShareOrders,shareOrderBo,ShareOrderBo.class);
shareOrderBo.setIsNew(unionShareOrders.getIsNew().toString());
shareOrderBo.setProductList(shareOrdersProductBoList);
return shareOrderBo;
}
@Override
public List<UnionShareSettlement> querySettlementRecord(int uid, Integer start, Integer size) {
List<UnionShareSettlement> unionShareSettlement = unionShareSettlementMapper.selectSettlementRecordByUid(uid, start, size);
return unionShareSettlement;
}
@Override
public List<UnionShareOrders> queryOrderList(UnionShareOrderReqBO unionShareOrderReqBO) {
//tab1表示1、全部订单;2、有效订单;3、无效订单 tab2表示1、已付款;2、待结算;3、结算中
List<UnionShareOrders> unionShareOrdersList = unionShareOrdersMapper.selectOrderList(unionShareOrderReqBO);
return unionShareOrdersList;
}
/**
* 订单插入或更新
*/
@Override
... ... @@ -227,18 +291,22 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
//判断是否可以进行状态变更
if (!checkOrderStatusChangePass(unionShareOrders.getStatus(), bo.getStatus())) {
//订单状态不可变更
logger.info("saveOrUpdateOrder end,status can not be change,oldStatus is {} ,req is {}",unionShareOrders.getStatus(),bo);
return;
}
int result = unionShareOrdersMapper.updateStatusById(unionShareOrders.getId(), unionShareOrders.getStatus(), bo.getStatus(), DateUtil.getCurrentTimeSecond());
if (result == 0) {
logger.info("saveOrUpdateOrder enter,update nothing,req is {}",bo);
//没有更新到数据,应该有并发更新事件,查询新的再试一下
UnionShareOrders unionShareOrdersNew = unionShareOrdersMapper.selectByCode(bo.getOrderCode());
if (unionShareOrdersNew == null) {
logger.info("saveOrUpdateOrder end,can not find the orderCode,req is {}",bo);
//查不到数据,不该出现的情况,目前没有硬删数据的途径
return;
}
if (!checkOrderStatusChangePass(unionShareOrdersNew.getStatus(), bo.getStatus())) {
//订单状态不可变更
logger.info("saveOrUpdateOrder end,Second try,status can not be change,oldStatus is {} ,req is {}",unionShareOrdersNew.getStatus(),bo);
return;
}
unionShareOrdersMapper.updateStatusById(unionShareOrdersNew.getId(), unionShareOrdersNew.getStatus(), bo.getStatus(), DateUtil.getCurrentTimeSecond());
... ... @@ -254,13 +322,15 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
logger.info("insertOrder,req is {}",bo);
//检查参数
if (!checkParam(bo)) {
//缺少参数 todo logger
//缺少参数
logger.warn("insertOrder end,param is invaild,req is {}",bo);
return;
}
//检查状态
if (!canInsertStatus(bo.getStatus())) {
//该状态数据不可插入 todo logger
//该状态数据不可插入
logger.warn("insertOrder end,status can not be change,req is {}",bo);
return;
}
//新增订单信息
... ... @@ -286,10 +356,14 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
unionShareOrdersMapper.insertSelective(insertReq);
//新增订单商品信息
bo.getProductList().forEach(p->{
UnionShareOrdersProduct insertPro = new UnionShareOrdersProduct();
BeanUtils.copyProperties(p, insertPro);
insertPro.setOrderCode(bo.getOrderCode());
unionShareOrdersProductMapper.insertSelective(insertPro);
try {
UnionShareOrdersProduct insertPro = new UnionShareOrdersProduct();
BeanUtils.copyProperties(p, insertPro);
insertPro.setOrderCode(bo.getOrderCode());
unionShareOrdersProductMapper.insertSelective(insertPro);
} catch (BeansException e) {
logger.info("insertOrder product error,orderCode is {},product is {}",bo.getOrderCode(), p);
}
});
logger.info("insertOrder end,req is {}",bo);
}
... ... @@ -340,11 +414,13 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
int count = unionShareUserMapper.selectCountByUid(uid);
if (count == 0) {
//不是特邀用户
logger.info("addSettlement end,can not find unionType,uid is {}",uid);
return null;
}
//查询是否有处理中的提现
if (hasSettlement(uid)) {
//有处理中的提现单,不可提现
logger.info("addSettlement end,hasSettlement,uid is {}",uid);
return null;
}
... ... @@ -352,10 +428,12 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
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;
}
//todo 生成取现单,绑定订单,考虑是否异步操作
BigDecimal amount = relateSettlementAndOrder(uid);
logger.info("addSettlement end,remaining settlement is {},uid is {}",amount,uid);
return amount;
}
... ... @@ -407,7 +485,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
return cacheResult;
}
int count = unionShareSettlementMapper.selectCountByUid(uid,(byte) 1);//是否打款成功:1-处理中,2-已打款
logger.info("hasSettlement ,uid is {},result is {},count is {}",uid,count);
logger.info("hasSettlement ,uid is {},count is {}",uid,count);
if (count > 0) {
addToRedis(ShareOrdersKeyEnum.USER_SETTLEMENT,uid,true,type);
return true;
... ... @@ -444,17 +522,22 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
* */
public BigDecimal relateSettlementAndOrder(int uid) {
logger.info("relateSettlementAndOrder enter,uid is {}",uid);
//生成提现编号
String settlementCode = createSettlementCode();
logger.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;
}
//计算提现金额
BigDecimal totalAmount=unionShareOrdersMapper.selectAmountBySettleCode(uid, settlementCode);
logger.info("relateSettlementAndOrder,uid is {},settlementCode is {},totalAmount is {}",uid,settlementCode,totalAmount);
//生成提现单
UnionShareSettlement insertReq = new UnionShareSettlement();
... ... @@ -466,7 +549,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
insertReq.setStatus((byte)1);//是否打款成功:1-处理中,2-已打款
int num=unionShareSettlementMapper.insertSelective(insertReq);
if (num < 1) {
//todo 插入失败
//插入失败
logger.warn("relateSettlementAndOrder end,uid is {},settlementCode is {},totalAmount is {},insert nothing.",uid,settlementCode,totalAmount);
}
Set<String> orderCodes = new HashSet<>();
... ... @@ -481,6 +565,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
orderCodes.addAll(periodOrders);
}
if (orderCodes.size() == 0) {
//不该查不到订单
logger.warn("relateSettlementAndOrder end,uid is {},settlementCode is {},totalAmount is {},can not find orders.",uid,settlementCode,totalAmount);
return null;
}
... ... @@ -492,6 +578,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
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);
yhProducer.send(SETTLEMENT_TOPIC, bo);
return totalAmount;
}
... ... @@ -584,6 +671,6 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
}
ordersDOMap=this.unionShareOrdersMapper.selectAllListByUids(bo.getBeginTime(), bo.getEndTime(), uids, bo.getOrderCode());
}
return ordersDOMap.isEmpty()?null:queryUnionShareOrderRsp(ordersDOMap);
return ordersDOMap.isEmpty()?null:queryUnionShareOrderRsp(ordersDOMap);
}
}
... ...