Переглянути джерело

[疲劳度检查实现][新增]

release_toaliyun_real
Stormeye.Wu 7 роки тому
джерело
коміт
0a96b1a07f
7 змінених файлів з 145 додано та 5 видалено
  1. +3
    -3
      mallinkService/src/main/java/com/iformall/common/ErrorCode.java
  2. +14
    -0
      mallinkService/src/main/java/com/iformall/mapper/WxCouponActionLogMapper.java
  3. +19
    -0
      mallinkService/src/main/java/com/iformall/service/PushLimitService.java
  4. +55
    -2
      mallinkService/src/main/java/com/iformall/service/impl/PushLimitServiceImpl.java
  5. +33
    -0
      mallinkService/src/main/java/com/iformall/utils/DateUtils.java
  6. +2
    -0
      mallinkService/src/main/java/com/iformall/utils/Utility.java
  7. +19
    -0
      mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml

+ 3
- 3
mallinkService/src/main/java/com/iformall/common/ErrorCode.java Переглянути файл

@@ -86,12 +86,12 @@ public enum ErrorCode{

COUPON_TYPE_IS_NOT_ACTIVE(2025, "此券不能用于主动领取"),
COUPON_TYPE_IS_NOT_PASSIVE(2026, "此券不能用于定向投放"),
COUPON_CHANNEL_IS_EXISTED(2027, "此券已投放过"),

COUPON_SEND_IS_EXISTED(2028, "此券已经添加到该渠道"),

COUPON_SEND_IS_INVALID(2029, "此发券渠道不存在"),
COUPON_SEND_UP_TO_1DAYLIMIT(2030, "此用户一天内发券到达限制"),
COUPON_SEND_UP_TO_COUPONLIMIT(2031, "此用户发此券到达限制"),
COUPON_SEND_NOT_INRANG(2032, "发券不在允许的时间段"),
/**
* 车流 2040
*/


+ 14
- 0
mallinkService/src/main/java/com/iformall/mapper/WxCouponActionLogMapper.java Переглянути файл

@@ -29,4 +29,18 @@ public interface WxCouponActionLogMapper extends CommonMapper<WxCouponActionLog,

int getCountByChannelId(@Param("tenantId")String tenantId,@Param("channelType") int channelType,@Param("channelId")Long channelId);

/**
* 每人每天最多可接收多少张券
* @param params
* @return
*/
int getCountByUser(Map<String,Object> params);

/**
* 每人多少天不会重复收到一张券
* @param params
* @return
*/
int getCountByUserAndCoupon(Map<String,Object> params);

}

+ 19
- 0
mallinkService/src/main/java/com/iformall/service/PushLimitService.java Переглянути файл

@@ -2,6 +2,8 @@ package com.iformall.service;

import com.github.pagehelper.PageInfo;
import com.iformall.domain.po.PushLimit;
import com.iformall.domain.po.WxCUser;
import com.iformall.domain.po.WxCoupon;

public interface PushLimitService {

@@ -44,4 +46,21 @@ public interface PushLimitService {
* @param id
*/
void deleteById(Long id);

/**
* 发短信检查
* @param tenantId
* @param phone
* @return
*/
boolean checkMsg(String tenantId, String phone);

/**
* 主动发券检查
* @param user
* @param coupon
* @return
*/
boolean checkCoupon(WxCUser user, WxCoupon coupon);

}

+ 55
- 2
mallinkService/src/main/java/com/iformall/service/impl/PushLimitServiceImpl.java Переглянути файл

@@ -2,25 +2,36 @@ package com.iformall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iformall.common.ErrorCode;
import com.iformall.common.IdWorker;
import com.iformall.domain.po.PushLimit;
import com.iformall.domain.po.WxCUser;
import com.iformall.domain.po.WxCoupon;
import com.iformall.exception.MallinkException;
import com.iformall.mapper.PushLimitMapper;
import com.iformall.mapper.WxCouponActionLogMapper;
import com.iformall.service.PushLimitService;
import com.iformall.utils.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PushLimitServiceImpl implements PushLimitService {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
@Autowired
PushLimitMapper pushLimitMapper;

@Autowired
WxCouponActionLogMapper wxCouponActionLogMapper;


@Override
public PageInfo<PushLimit> listAsPage(PushLimit record, Integer pageIndex, Integer pageSize) {
@@ -65,4 +76,46 @@ public class PushLimitServiceImpl implements PushLimitService {
public void deleteById(Long id) {
pushLimitMapper.deleteByPrimaryKey(id);
}

@Override
public boolean checkMsg(String tenantId, String phone) {
Date curDate = new Date();
// 1. get tenant limit
PushLimit pushLimit = getPushLimit(tenantId);
// 2. check time
boolean isInDate = DateUtils.isInDate(curDate, pushLimit.getTimeStart(), pushLimit.getTimeEnd());
if (!isInDate) {
throw new MallinkException(ErrorCode.COUPON_SEND_NOT_INRANG);
}
// TODO 3. check phone had up to limit
return true;
}

@Override
public boolean checkCoupon(WxCUser user, WxCoupon coupon) {
Date curDate = new Date();
// 1. get tenant limit
PushLimit pushLimit = getPushLimit(user.getTenantId());
// 2. check time 是否在给定的时间段内
boolean isInDate = DateUtils.isInDate(curDate, pushLimit.getTimeStart(), pushLimit.getTimeEnd());
if (!isInDate) {
throw new MallinkException(ErrorCode.COUPON_SEND_NOT_INRANG);
}
// 3. check 每人每天多少张券
Map params = new HashMap<String, Object>();
params.put("tenantId", user.getTenantId());
params.put("c_user_id", user.getId());
int countForUser = wxCouponActionLogMapper.getCountByUser(params);
if (countForUser >= pushLimit.getCouponAmount()) {
throw new MallinkException(ErrorCode.COUPON_SEND_UP_TO_COUPONLIMIT);
}
// 4. check 每人多少天内不会重复收到一张券
params.put("dayNum", pushLimit.getCouponDay());
int countForUserCoupon = wxCouponActionLogMapper.getCountByUserAndCoupon(params);
if (countForUserCoupon >= pushLimit.getCouponDay()) {
throw new MallinkException(ErrorCode.COUPON_SEND_UP_TO_COUPONLIMIT);
}

return true;
}
}

+ 33
- 0
mallinkService/src/main/java/com/iformall/utils/DateUtils.java Переглянути файл

@@ -890,4 +890,37 @@ public class DateUtils {
}
}

/**
* 判断时间是否在时间段内
* @param date
* @param timeStart
* @param timeEnd
* @return
*/
public static boolean isInDate(Date date, String timeStart, String timeEnd) {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
String strDate = sdf.format(date);

// 截取当前时间时分
int strDateH = Integer.parseInt(strDate.substring(0, 2));
int strDateM = Integer.parseInt(strDate.substring(3, 5));
int strDateT = strDateH * 60 + strDateM;

// 截取开始时间时分
int strDateBeginH = Integer.parseInt(timeStart.substring(0, 2));
int strDateBeginM = Integer.parseInt(timeStart.substring(3, 5));
int strDateBeginT = strDateBeginH * 60 + strDateBeginM;
// 截取结束时间时分
int strDateEndH = Integer.parseInt(timeEnd.substring(0, 2));
int strDateEndM = Integer.parseInt(timeEnd.substring(3, 5));
int strDateEndT = strDateEndH * 60 + strDateEndM;


if (strDateT >= strDateBeginT && strDateT <= strDateEndT) {
return true;
} else {
return false;
}
}

}

+ 2
- 0
mallinkService/src/main/java/com/iformall/utils/Utility.java Переглянути файл

@@ -601,4 +601,6 @@ public final class Utility {
}
return sb.toString();
}


}

+ 19
- 0
mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml Переглянути файл

@@ -154,4 +154,23 @@
and channel_id &lt;= #{channelId}
</select>

<select id="getCountByUser" resultType="java.lang.Integer" parameterType="hashmap">
select COUNT(a.*)
FROM wx_coupon_action_log a, wx_coupon_order o
WHERE a.coupon_order_id = o.id
AND a.tenant_id = #{tenantId}
AND o.c_user_id = #{cUserId}
AND a.create_time between date_sub(now(),interval 1 day) and now()
</select>

<select id="getCountByUserAndCoupon" resultType="java.lang.Integer" parameterType="hashmap">
select COUNT(a.*)
FROM wx_coupon_action_log a, wx_coupon_order o
WHERE a.coupon_order_id = o.id
AND a.tenant_id = #{tenantId}
AND o.c_user_id = #{cUserId}
AND a.coupon_id = #{couponId}
AND a.create_time between date_sub(now(),interval #{dayNum} day) and now()
</select>

</mapper>

Завантаження…
Відмінити
Зберегти