Authored by mingdan.ge

cps5期

... ... @@ -201,6 +201,13 @@ public class DateUtil {
}
}
public static int getLastDayInt(int lastDay) {
Calendar time = Calendar.getInstance();
time.add(Calendar.DAY_OF_YEAR,1-lastDay);
time.set(time.get(Calendar.YEAR),time.get(Calendar.MONTH),time.get(Calendar.HOUR_OF_DAY),0,0,0);
return (int) (time.getTime().getTime()/1000);
}
/**
* 日期格式转换
* @param date
... ...
... ... @@ -15,6 +15,7 @@ public interface UnionShareOrdersActivityMapper {
UnionShareOrdersActivity selectByPrimaryKey(Integer id);
List<UnionShareOrdersActivity> selectByDate(@Param("time") Integer time);
List<UnionShareOrdersActivity> selectWaitListByDate(@Param("time") Integer time);
List<UnionShareOrdersActivity> selectLastDaysIngActivity(@Param("startTime") Integer startTime,@Param("endTime") Integer endTime);
int updateByPrimaryKeySelective(UnionShareOrdersActivity record);
... ...
... ... @@ -5,10 +5,13 @@ import com.yoho.service.model.union.request.UnionShareOrderReqBO;
import com.yoho.service.model.union.request.UnionShareOrderSearchReqBO;
import com.yoho.unions.dal.model.UnionShareOrders;
import com.yoho.unions.dal.model.UnionShareOrdersMonth;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Set;
public interface UnionShareOrdersMapper {
int deleteByPrimaryKey(Integer id);
... ... @@ -32,9 +35,9 @@ public interface UnionShareOrdersMapper {
List<UnionShareOrdersUidBo> selectUidList(@Param("beginTime") int beginTime, @Param("endTime") int endTime);
List<UnionShareOrders> selectListByOrderUidForActivity(@Param("beginTime") int beginTime,@Param("endTime") int endTime,@Param("orderUid") Integer orderUid,@Param("promoteUid") Integer promoteUid);
UnionShareOrders selectActivityOrderByUid(@Param("activityId") int activityId,@Param("orderUid") Integer orderUid,@Param("promoteUid") Integer promoteUid);
int selectCountByCondition(@Param("promoteUid")int promoteUid, @Param("status")String status);
UnionShareOrders selectActivityOrderByUid(@Param("activityId") Integer activityId, @Param("orderUid") Integer orderUid, @Param("promoteUid") Integer promoteUid);
BigDecimal selectAmountByStatus(@Param("promoteUid")int promoteUid, @Param("statusList")List<String> statusList);
... ... @@ -66,4 +69,8 @@ public interface UnionShareOrdersMapper {
Integer selectOrderListCount(@Param("params") UnionShareOrderReqBO unionShareOrderReqBO);
List<UnionShareOrders> selectListForStatistics(@Param("uid") int uid, @Param("beginTime") int beginTime, @Param("endTime") int endTime);
@MapKey("uid")
Map<Integer, List<UnionShareOrders>> selectNewPromoteUidsOrder(@Param("promoteUids") Set<Integer> promoteUids, @Param("endTime") int endTime);
}
\ No newline at end of file
... ...
... ... @@ -20,6 +20,8 @@ public interface UnionShareUserApplyMapper {
int selectCountByUid(UnionShareUserApply record);
List<UnionShareUserApply> selectByIds(@Param("ids")Set<Integer> ids);
Set<Integer> selectUidListByTime(@Param("beginTime") int beginTime,@Param("endTime") int endTime);
int updateByPrimaryKeySelective(UnionShareUserApply record);
int updateStatus(@Param("ids")Set<Integer> ids,@Param("oldState")Integer oldState,@Param("newState")Integer newState,@Param("time")Integer time);
... ...
... ... @@ -40,6 +40,9 @@ public class UnionShareOrders extends BaseBO {
private BigDecimal extraAmount;
private BigDecimal orderAmount;
private Integer specialStatus;//1-正常点击订单,2-锁粉订单
private Integer paymentType;//支付类型:1-在线支付 2-货到付款
public Integer getId() {
return id;
}
... ... @@ -200,6 +203,22 @@ public class UnionShareOrders extends BaseBO {
this.orderUid = orderUid;
}
public Integer getSpecialStatus() {
return specialStatus;
}
public void setSpecialStatus(Integer specialStatus) {
this.specialStatus = specialStatus;
}
public Integer getPaymentType() {
return paymentType;
}
public void setPaymentType(Integer paymentType) {
this.paymentType = paymentType;
}
@Override
public String toString() {
return "UnionShareOrders{" +
... ... @@ -223,6 +242,8 @@ public class UnionShareOrders extends BaseBO {
", activityName=" + activityName +
", extraAmount=" + extraAmount +
", orderAmount=" + orderAmount +
", specialStatus=" + specialStatus +
", paymentType=" + paymentType +
'}';
}
}
\ No newline at end of file
... ...
... ... @@ -39,6 +39,12 @@
from union_share_orders_activity
where status=1 and type=3 and progress=0 and end_time &lt; #{time,jdbcType=INTEGER}
</select>
<select id="selectLastDaysIngActivity" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from union_share_orders_activity
where status=1 and type=4 and start_time &lt; #{endTime,jdbcType=INTEGER} and end_time > #{startTime,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from union_share_orders_activity
where id = #{id,jdbcType=INTEGER}
... ...
... ... @@ -19,10 +19,12 @@
<result column="activity_name" property="activityName" jdbcType="VARCHAR" />
<result column="extra_amount" property="extraAmount" jdbcType="DECIMAL" />
<result column="order_amount" property="orderAmount" jdbcType="DECIMAL" />
<result column="special_status" property="specialStatus" jdbcType="TINYINT" />
<result column="payment_type" property="paymentType" jdbcType="TINYINT" />
</resultMap>
<sql id="Base_Column_List" >
id, order_code,settlement_code, promote_uid,order_uid, status, last_order_amount, order_time, is_new, amount, create_time,
update_time,extra_activity_id,activity_id,activity_name,extra_amount,order_amount
update_time,extra_activity_id,activity_id,activity_name,extra_amount,order_amount,special_status,payment_type
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
... ... @@ -103,13 +105,13 @@
last_order_amount, order_time, is_new,
amount, create_time, update_time,
extra_activity_id, activity_id,activity_name, extra_amount,
order_amount)
order_amount,special_status,payment_type)
values (#{id,jdbcType=INTEGER}, #{orderCode,jdbcType=VARCHAR}, #{promoteUid,jdbcType=INTEGER},
#{orderUid,jdbcType=INTEGER}, #{settlementCode,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR},
#{lastOrderAmount,jdbcType=DECIMAL}, #{orderTime,jdbcType=INTEGER}, #{isNew,jdbcType=TINYINT},
#{amount,jdbcType=DECIMAL}, #{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER},
#{extraActivityId,jdbcType=INTEGER}, #{activityId,jdbcType=INTEGER},#{activityName,jdbcType=VARCHAR}, #{extraAmount,jdbcType=DECIMAL},
#{orderAmount,jdbcType=DECIMAL})
#{orderAmount,jdbcType=DECIMAL}), #{specialStatus,jdbcType=TINYINT}, #{paymentType,jdbcType=TINYINT}
</insert>
<insert id="insertSelective" useGeneratedKeys="true" keyProperty="id" parameterType="com.yoho.unions.dal.model.UnionShareOrders" >
insert into union_share_orders
... ... @@ -165,6 +167,12 @@
<if test="orderAmount != null" >
order_amount,
</if>
<if test="specialStatus != null" >
special_status,
</if>
<if test="paymentType != null" >
payment_type,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
... ... @@ -218,6 +226,12 @@
<if test="orderAmount != null" >
#{orderAmount,jdbcType=DECIMAL},
</if>
<if test="specialStatus != null" >
#{specialStatus,jdbcType=TINYINT},
</if>
<if test="paymentType != null" >
#{paymentType,jdbcType=TINYINT},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.unions.dal.model.UnionShareOrders" >
... ... @@ -271,6 +285,12 @@
<if test="orderAmount != null" >
order_amount = #{orderAmount,jdbcType=DECIMAL},
</if>
<if test="specialStatus != null" >
special_status = #{specialStatus,jdbcType=TINYINT},
</if>
<if test="paymentType != null" >
payment_type = #{paymentType,jdbcType=TINYINT},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
... ... @@ -300,7 +320,9 @@
activity_id = #{activityId,jdbcType=INTEGER},
activity_name = #{activityName,jdbcType=VARCHAR},
extra_amount = #{extraAmount,jdbcType=DECIMAL},
order_amount = #{orderAmount,jdbcType=DECIMAL}
order_amount = #{orderAmount,jdbcType=DECIMAL},
special_status = #{specialStatus,jdbcType=TINYINT},
payment_type = #{paymentType,jdbcType=TINYINT}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectCountBySearchCodition" resultType="java.lang.Integer" parameterType="com.yoho.service.model.union.request.UnionShareOrderSearchReqBO">
... ... @@ -372,7 +394,10 @@
select
<include refid="Base_Column_List" />
from union_share_orders
where order_uid = #{orderUid} and promote_uid = #{promoteUid} and activity_id = #{activityId} and status in (10,20,30,40)
where promote_uid = #{promoteUid} and activity_id = #{activityId} and status in (10,20,30,40)
<if test="orderUid!=null">
and order_uid = #{orderUid}
</if>
limit 1
</select>
<select id="selectListBySearchCodition" resultMap="BaseResultMap" parameterType="com.yoho.service.model.union.request.UnionShareOrderSearchReqBO">
... ...
... ... @@ -49,6 +49,11 @@
#{id}
</foreach>
</select>
<select id="selectUidListByTime" resultType="java.lang.Integer" >
select uid
from union_share_user_apply
where status=2 and del_flag=1 and check_time > #{beginTime} and check_time &lt; #{endTime}
</select>
<select id="selectByCondition"
resultType="com.yoho.service.model.union.response.UnionShareUserApplyListBo"
parameterType="com.yoho.service.model.union.request.UnionShareUserApplyListReqBo">
... ...
... ... @@ -49,6 +49,10 @@ public interface IUnionShareService {
List<UnionShareOrdersActivity> queryWaitActivity();
List<UnionShareOrdersActivity> queryLastDaysIngActivity(int beginTime,int endTime);
void dealWithCpsNewUserActivity(UnionShareOrdersActivity activity, int beginTime, int endTime,int orderEndTime);
void dealWithWaitActivity(UnionShareOrdersActivity activity);
PageUnionShareOrderRspBO queryUnionShareOrders(UnionShareOrderSearchReqBO reqBO);
... ...
... ... @@ -1500,6 +1500,29 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
return true;
}
//处理cps新人额外返活动某时间段数据
@Override
@Database(ForceMaster = true)
public void dealWithCpsNewUserActivity(UnionShareOrdersActivity activity,int beginTime,int endTime,int orderEndTime) {
logger.info("dealWithCpsNewUserActivity,activity is {},beginTime is {},endTime is {},orderEndTime is {}.",activity,beginTime,endTime,orderEndTime);
//查询可以参与活动的uid
Set<Integer> uids=unionShareUserApplyMapper.selectUidListByTime(activity.getStartTime(), activity.getEndTime());
logger.info("dealWithCpsNewUserActivity,activity is {},beginTime is {},endTime is {},orderEndTime is {},selectUidListByTime, uids is {}",activity,beginTime,endTime,orderEndTime,uids);
if (CollectionUtils.isEmpty(uids)) {
return;
}
//查询uid名下分享订单
Map<Integer, List<UnionShareOrders>> uidOrders=unionShareOrdersMapper.selectNewPromoteUidsOrder(uids, orderEndTime);
uids.forEach(u->{
joinNewCpsActivity(u,uidOrders.get(u), activity.getId());
});
//发放完成
logger.info("dealWithCpsNewUserActivity over,activity is {},begin to change status to 2.",activity);
unionShareOrdersActivityMapper.updateStatusById(activity.getId(), 1, 2, DateUtil.getCurrentTimeSecond());
return ;
}
//处理已结束等待发放奖励的活动
@Override
... ... @@ -1527,7 +1550,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
return ;
}
//查询已结束等待发放奖励的活动
//查询已结束等待发放奖励的普通额外返活动
@Override
public List<UnionShareOrdersActivity> queryWaitActivity() {
logger.info("queryWaitActivity.");
... ... @@ -1535,6 +1558,18 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
return activities;
}
//查询过去startDays天到过去endDays内有进行中状态的的新人额外返活动(startDays>endDays)
@Override
public List<UnionShareOrdersActivity> queryLastDaysIngActivity(int beginTime,int endTime) {
logger.info("queryLastDaysActivity.beginTime is {},endTime is {}.",beginTime,endTime);
if (beginTime <= endTime) {
return null;
}
List<UnionShareOrdersActivity> activities=unionShareOrdersActivityMapper.selectLastDaysIngActivity(beginTime,endTime);
return activities;
}
//查询进行中的活动
private List<UnionShareOrdersActivity> queryActivity() {
logger.info("queryActivity.");
... ... @@ -1563,8 +1598,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
List<UnionShareOrders> orders = unionShareOrdersMapper.selectListByOrderUidForActivity(beginTime, endTime, orderUid,promoteUid);
return orders;
}
//查询分享人和下单人关联订单参与的满单返活动单
private UnionShareOrders queryOrderActivity(int orderUid,int promoteUid,int activityId) {
//查询分享人分享订单参与的满单返活动单
private UnionShareOrders queryOrderActivity(Integer orderUid,int promoteUid,int activityId) {
logger.info("queryOrderActivity,orderUid is {},promoteUid is {},activityId is {}",orderUid,promoteUid,activityId);
UnionShareOrders activityOrder = unionShareOrdersMapper.selectActivityOrderByUid(activityId, orderUid,promoteUid);
return activityOrder;
... ... @@ -1683,62 +1718,106 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
for (UnionShareOrdersActivityItem item : items) {
if (orders.size() >= item.getOrderMinNum() && orders.size() <= item.getOrderMaxNum()) {
//满足此项标准
StringBuilder ordersStr = new StringBuilder();
List<Integer> orderIds = new ArrayList<>();
String status=ShareOrdersStatusEnum.CAN_SETTLE.getCode();
for(UnionShareOrders order:orders){
if(ShareOrdersStatusEnum.getLevelByCode(order.getStatus())<ShareOrdersStatusEnum.CAN_SETTLE.getLevel()){
status = order.getStatus();
}
ordersStr.append(order.getOrderCode()).append(',');
orderIds.add(order.getId());
}
//更新订单额外返数据
int now = DateUtil.getCurrentTimeSecond();
logger.info("joinExtraActivity,orderUid is {},promoteUid is {},activityId is {},updateByIdsForExtraActivity,orderIds is {} .",orderUid,promoteUid,activityId,orderIds);
unionShareOrdersMapper.updateByIdsForExtraActivity(orderIds, activityId,now);
//插入额外返利单
UnionShareOrders insertExtraOrder = new UnionShareOrders();
insertExtraOrder.setExtraAmount(item.getAmount());
insertExtraOrder.setAmount(item.getAmount());
insertExtraOrder.setExtraActivityId(activityId);
insertExtraOrder.setActivityId(activityId);
insertExtraOrder.setActivityName(activity.getActivityName());
insertExtraOrder.setPromoteUid(promoteUid);
insertExtraOrder.setOrderUid(orderUid);
insertExtraOrder.setStatus(status);
insertExtraOrder.setOrderTime(now);
insertExtraOrder.setCreateTime(now);
insertExtraOrder.setUpdateTime(now);
logger.info("joinExtraActivity,orderUid is {},promoteUid is {},activityId is {},insertExtraOrder is {} .",orderUid,promoteUid,activityId,insertExtraOrder);
unionShareOrdersMapper.insertSelective(insertExtraOrder);
//记录满单返活动参与日志
UnionShareOrdersActivityLogs logs = new UnionShareOrdersActivityLogs();
logs.setOrders(ordersStr.substring(0,ordersStr.length()-1));
logs.setOrderId(insertExtraOrder.getId());
logs.setActivityId(activityId);
logs.setActivityName(activity.getActivityName());
logs.setActivityType(activity.getType());
logs.setActivityItemId(item.getId());
logs.setAmount(item.getAmount());
logs.setCreateTime(now);
logs.setUpdateTime(now);
logs.setPromoteUid(promoteUid);
logs.setOrderUid(orderUid);
logger.info("joinExtraActivity,orderUid is {},promoteUid is {},activityId is {},logs is {} .",orderUid,promoteUid,activityId,logs);
unionShareOrdersActivityLogsMapper.insertSelective(logs);
//更新用户月统计数据
updateMonthData(logs.getPromoteUid(),new HashSet<String>(){{add(DateUtil.getDateStrBySecond(now,"yyyyMM"));}});
insertJoinDataForActivity(orders, orderUid, promoteUid, activity, item);
return true;
}
}
return false;
}
//参加新cps用户分享满单额外返活动
boolean joinNewCpsActivity(int promoteUid ,List<UnionShareOrders> orders,int activityId){
if (CollectionUtils.isEmpty(orders)) {
return false;
}
//查询是否已参加过此活动
if (hasJoinActivity(null, promoteUid, activityId)) {
//存在有效的参与数据,直接返回
logger.info("joinNewCpsActivity end,hasJoinActivity,promoteUid is {},activityId is {}.",promoteUid,activityId);
return true;
}
UnionShareOrdersActivity activity = queryActivity(activityId);
if (null == activity || activity.getType() != 4) {
logger.info("joinNewCpsActivity end,activity error,promoteUid is {},activityId is {},activity is {}.",promoteUid,activityId,activity);
return false;
}
//查询满x单返活动条目(正常状态)
List<UnionShareOrdersActivityItem> items = queryActivityItemList(activityId);
for (UnionShareOrdersActivityItem item : items) {
if (orders.size() >= item.getOrderMinNum() && orders.size() <= item.getOrderMaxNum()) {
//满足此项标准
insertJoinDataForActivity(orders, null, promoteUid, activity, item);
return true;
}
}
return false;
}
//向数据库插入参与某种额外返、新cps额外返活动的数据
boolean insertJoinDataForActivity(List<UnionShareOrders> orders, Integer orderUid , int promoteUid , UnionShareOrdersActivity activity, UnionShareOrdersActivityItem item) {
//满足此项标准
if (orderUid != null && activity.getType() != 3) {
//活动类型:1-订单返利比例升级,2-订单返利翻x倍,3-额外返,4-cps新人额外返
//当类型为3时需要传orderUid,当类型为4时不需要传orderUid
return false;
}
StringBuilder ordersStr = new StringBuilder();
List<Integer> orderIds = new ArrayList<>();
String status=ShareOrdersStatusEnum.CAN_SETTLE.getCode();
for(UnionShareOrders order:orders){
if(ShareOrdersStatusEnum.getLevelByCode(order.getStatus())<ShareOrdersStatusEnum.CAN_SETTLE.getLevel()){
status = order.getStatus();
}
ordersStr.append(order.getOrderCode()).append(',');
orderIds.add(order.getId());
}
//更新订单额外返数据
int now = DateUtil.getCurrentTimeSecond();
if (orderUid != null) {
logger.info("insertJoinDataForActivity,orderUid is {},promoteUid is {},activityId is {},updateByIdsForExtraActivity,orderIds is {} .",orderUid,promoteUid,activity.getId(),orderIds);
unionShareOrdersMapper.updateByIdsForExtraActivity(orderIds, activity.getId(),now);
}
//插入额外返利单
UnionShareOrders insertExtraOrder = new UnionShareOrders();
insertExtraOrder.setExtraAmount(item.getAmount());
insertExtraOrder.setAmount(item.getAmount());
insertExtraOrder.setExtraActivityId(activity.getId());
insertExtraOrder.setActivityId(activity.getId());
insertExtraOrder.setActivityName(activity.getActivityName());
insertExtraOrder.setPromoteUid(promoteUid);
insertExtraOrder.setOrderUid(orderUid);
insertExtraOrder.setStatus(status);
insertExtraOrder.setOrderTime(now);
insertExtraOrder.setCreateTime(now);
insertExtraOrder.setUpdateTime(now);
logger.info("insertJoinDataForActivity,orderUid is {},promoteUid is {},activityId is {},insertExtraOrder is {} .",orderUid,promoteUid,activity.getId(),insertExtraOrder);
unionShareOrdersMapper.insertSelective(insertExtraOrder);
//记录满单返活动参与日志
UnionShareOrdersActivityLogs logs = new UnionShareOrdersActivityLogs();
logs.setOrders(ordersStr.substring(0,ordersStr.length()-1));
logs.setOrderId(insertExtraOrder.getId());
logs.setActivityId(activity.getId());
logs.setActivityName(activity.getActivityName());
logs.setActivityType(activity.getType());
logs.setActivityItemId(item.getId());
logs.setAmount(item.getAmount());
logs.setCreateTime(now);
logs.setUpdateTime(now);
logs.setPromoteUid(promoteUid);
logs.setOrderUid(orderUid);
logger.info("insertJoinDataForActivity,orderUid is {},promoteUid is {},activityId is {},logs is {} .",orderUid,promoteUid,activity.getId(),logs);
unionShareOrdersActivityLogsMapper.insertSelective(logs);
//更新用户月统计数据
updateMonthData(logs.getPromoteUid(),new HashSet<String>(){{add(DateUtil.getDateStrBySecond(now,"yyyyMM"));}});
return true;
}
//是否已参加过此活动
private boolean hasJoinActivity(int orderUid ,int promoteUid ,int activityId) {
private boolean hasJoinActivity(Integer orderUid ,int promoteUid ,int activityId) {
UnionShareOrders unionShareOrders=queryOrderActivity(orderUid, promoteUid, activityId);
if (unionShareOrders == null) {
return false;
... ...
package com.yoho.unions.server.task;
import com.yoho.unions.common.utils.DateUtil;
import com.yoho.unions.dal.model.UnionShareOrdersActivity;
import com.yoho.unions.server.service.IUnionShareService;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* cps新用户7天满单额外返活动奖励定时发放
* Created by mingdan.ge on 2018/9/5.
*/
@Component
public class CpsNewUserActivityTask {
private Logger logger = LoggerFactory.getLogger(CpsNewUserActivityTask.class);
@Autowired
IUnionShareService unionShareService;
// 每天08:30执行
@Scheduled(cron = "0 40 8 * * ?")
public void run() {
logger.info("start giving out new user rewards");
//查询6天前一天为进行中状态的新用户满x单返活动
int endTime= DateUtil.getLastDayInt(6);
int beginTime=DateUtil.getLastDayInt(7);
List<UnionShareOrdersActivity> activities = unionShareService.queryLastDaysIngActivity(beginTime,endTime);
if (CollectionUtils.isEmpty(activities)) {
return;
}
int orderEndTime = DateUtil.getLastDayInt(1);
//其实一天只允许有一个活动
activities.forEach(a->{
unionShareService.dealWithCpsNewUserActivity(a,beginTime,endTime,orderEndTime);
});
}
}
... ...