Authored by michaelcao

Merge branch 'brandDraw' of git.yoho.cn:yoho30/yohobuy-activity into brandDraw

... ... @@ -11,3 +11,5 @@ controller/.settings/
*.iml
controller/target/
*.iml
*.class
other/
... ...
package com.yoho.activity.common.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Mapping {
public String name() default "";
}
\ No newline at end of file
... ...
package com.yoho.activity.common.bo;
import com.yoho.queue.dal.model.BaseModel;
public class ActNewBrandBo extends BaseModel {
/**
*
*/
private static final long serialVersionUID = 1704484697194941946L;
private Integer id;
private String boxImage;
private String brandInfo;
private String showDate;
private String boxNum;
private Byte prize;
private Byte prizeType;
private String prizeInfo;
private String prizeRemark;
public Byte getPrizeType() {
return prizeType;
}
public void setPrizeType(Byte prizeType) {
this.prizeType = prizeType;
}
public String getPrizeInfo() {
return prizeInfo;
}
public void setPrizeInfo(String prizeInfo) {
this.prizeInfo = prizeInfo;
}
public String getPrizeRemark() {
return prizeRemark;
}
public void setPrizeRemark(String prizeRemark) {
this.prizeRemark = prizeRemark;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getBoxImage() {
return boxImage;
}
public void setBoxImage(String boxImage) {
this.boxImage = boxImage == null ? null : boxImage.trim();
}
public String getBrandInfo() {
return brandInfo;
}
public void setBrandInfo(String brandInfo) {
this.brandInfo = brandInfo == null ? null : brandInfo.trim();
}
public String getShowDate() {
return showDate;
}
public void setShowDate(String showDate) {
this.showDate = showDate == null ? null : showDate.trim();
}
public String getBoxNum() {
return boxNum;
}
public void setBoxNum(String boxNum) {
this.boxNum = boxNum == null ? null : boxNum.trim();
}
public Byte getPrize() {
return prize;
}
public void setPrize(Byte prize) {
this.prize = prize;
}
}
\ No newline at end of file
... ...
package com.yoho.activity.common.bo;
import com.yoho.queue.dal.model.BaseModel;
public class ActNewBrandResultBo extends BaseModel {
/**
*
*/
private static final long serialVersionUID = 337788940402609195L;
private Integer id;
private Integer uid;
private Integer boxId;
private Integer createTime;
private String drawDate;
private Byte prizeType;
private String prizeInfo;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getUid() {
return uid;
}
public void setUid(Integer uid) {
this.uid = uid;
}
public Integer getBoxId() {
return boxId;
}
public void setBoxId(Integer boxId) {
this.boxId = boxId;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public String getDrawDate() {
return drawDate;
}
public void setDrawDate(String drawDate) {
this.drawDate = drawDate == null ? null : drawDate.trim();
}
public Byte getPrizeType() {
return prizeType;
}
public void setPrizeType(Byte prizeType) {
this.prizeType = prizeType;
}
public String getPrizeInfo() {
return prizeInfo;
}
public void setPrizeInfo(String prizeInfo) {
this.prizeInfo = prizeInfo == null ? null : prizeInfo.trim();
}
}
\ No newline at end of file
... ...
package com.yoho.activity.common.utils;
import com.yoho.activity.common.annotation.Mapping;
import org.springframework.beans.BeanUtils;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.util.*;
/**
* @author lijian
* 对象copy工具类
*/
public class BeanTool {
@SuppressWarnings("serial")
private final static List<Class<?>> PrimitiveClasses = new ArrayList<Class<?>>() {
{
add(Long.class);
add(Double.class);
add(Integer.class);
add(String.class);
add(Boolean.class);
add(Date.class);
add(java.sql.Date.class);
}
};
private final static boolean _IsPrimitive(Class<?> cls) {
return cls.isPrimitive() || PrimitiveClasses.contains(cls);
}
/**
* copy不同的pojo数据对象
*
* @param fromObj
* @param toObjClazz
* @return
*/
@SuppressWarnings("unchecked")
public static <T> T copyObject(Object fromObj, Class<T> toObjClazz) {
try {
if(fromObj==null){
return null;
}
Class<?> fromObjClazz = fromObj.getClass();
// 普通类型直接返回
if (_IsPrimitive(toObjClazz))
return (T) fromObj;
T toObj = toObjClazz.newInstance();
Field[] fields = toObjClazz.getDeclaredFields();
for (Field toF : fields) {
try {
int mod = toF.getModifiers();
// 静态成员及常量成员不copy
if (Modifier.isFinal(mod) || Modifier.isStatic(mod))
continue;
String toFieldName = toF.getName();
String fromFieldName;
Mapping mapping = toF.getAnnotation(Mapping.class);
if (mapping == null || mapping.name() == null
|| mapping.name().trim().equals(""))
fromFieldName = toFieldName;
else
fromFieldName = mapping.name();
toF.setAccessible(true);
Field fromF = fromObjClazz.getDeclaredField(fromFieldName);
fromF.setAccessible(true);
// System.out.println("aaaaa"+fromF.get(fromObj));
toF.set(toObj, fromF.get(fromObj));
// System.out.println(toF.get(toObj));
} catch (Exception e) {
if (e instanceof IllegalArgumentException)
e.printStackTrace();
}
}
return toObj;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* copy list对象
*
* @param fromObjList
* @param toObjClazz
* @return
*/
public static <T> List<T> copyList(List<?> fromObjList, Class<T> toObjClazz) {
if(fromObjList==null){
return null;
}
List<T> toObjList = new ArrayList<T>(fromObjList.size());
for (int i = 0; i < fromObjList.size(); i++) {
toObjList.add(copyObject(fromObjList.get(i), toObjClazz));
}
return toObjList;
}
/**
* copy map 对象
*
* @param fromObjMap
* @param toObjClazz
* @return
*/
public static <T> Map<String, T> copyMap(Map<String, ?> fromObjMap,
Class<T> toObjClazz) {
Map<String, T> toObjMap = new HashMap<String, T>(fromObjMap.size());
Iterator<String> iter = fromObjMap.keySet().iterator();
while (iter.hasNext()) {
String key = iter.next();
Object fromObj = fromObjMap.get(key);
// if(List.class.isAssignableFrom(fromObj.getClass())){
// toObjMap.put(key, copyList((List<?>)fromObj, toObjClazz));
// }
toObjMap.put(key, copyObject(fromObj, toObjClazz));
}
return toObjMap;
}
public static <T> List<T> copyListMap(List<Map<String, ?>> mapList,
Class<T> toObjClass) {
List<T> toObjList = new ArrayList<T>(mapList.size());
for (Map<String, ?> map : mapList) {
toObjList.add(copyMapToBean(map, toObjClass));
}
return toObjList;
}
public static <T> T copyMapToBean(Map<String, ?> map, Class<T> toObjClass) {
try {
Set<String> set = map.keySet();
T objT = toObjClass.newInstance();
for (String key : set) {
try {
Object value = map.get(key);
Field toF = toObjClass.getDeclaredField(key);
toF.setAccessible(true);
toF.set(objT, value);
} catch (Exception e) {
// 吃掉这个异常
}
}
return objT;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 复制集合
*
* @param <E>
* @param source
* @param destinationClass
* @return
* @throws InstantiationException
* @throws InvocationTargetException
* @throws IllegalAccessException
*/
public static <E> List<E> copyToList(List<?> source, Class<E> destinationClass) throws IllegalAccessException, InvocationTargetException, InstantiationException {
if (source.size() == 0) return Collections.emptyList();
List<E> res = new ArrayList<E>(source.size());
for (Object o : source) {
E e = destinationClass.newInstance();
BeanUtils.copyProperties(o, e);
res.add(e);
}
return res;
}
}
\ No newline at end of file
... ...
... ... @@ -7,9 +7,12 @@ import java.util.Date;
import java.util.TimeZone;
public final class DateUtils {
private final static String DEFAULT_FOMARTPATTER="yyyy-MM-dd HH:mm:ss";
public final static String DEFAULT_FOMARTPATTER="yyyy-MM-dd HH:mm:ss";
public final static String DAY_FOMARTPATTER="yyyy-MM-dd";
/**
* 将数据库中的UNIX_Time(该时间是距离1970年的秒数,在转换过程中先要换算成毫秒)转换成UTC时间
* @param time
... ...
package com.yoho.activity.common.vo;
import java.util.List;
/**
* Created by lijian
*/
public class FavoriteAddReq {
/**
* sknId列表
*/
private List<Integer> sknIds;
}
... ...
/**
*
*/
package com.yoho.activity.controller;
import com.alibaba.fastjson.JSON;
import com.yoho.activity.common.ApiResponse;
import com.yoho.activity.common.bo.ActNewBrandBo;
import com.yoho.activity.service.IBrandActivityService;
import com.yoho.error.exception.ServiceException;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.List;
/**
* 描述:品牌抽奖
*
* @author lijian
* 2016-8-23 11:35:42
*/
@Controller
@RequestMapping("/brandDraw")
public class BrandDrawController {
static Logger log = LoggerFactory.getLogger(BrandDrawController.class);
@Resource
IBrandActivityService brandActivityService;
/**
* @return
* @throws ServiceException
*/
@RequestMapping("/getBrandActList")
@ResponseBody
public ApiResponse getBrandActList() throws ServiceException {
List<ActNewBrandBo> actNewBrandBoList = brandActivityService.getBrandActList();
log.info("getBrandActList res={}", JSON.toJSONString(actNewBrandBoList));
if (CollectionUtils.isEmpty(actNewBrandBoList)) {
log.warn("getBrandActList error!!!! , res={}", JSON.toJSONString(actNewBrandBoList));
new ApiResponse(500, "对不起,活动未开始或已失效");
}
ApiResponse apiResponse = new ApiResponse(200, "活动列表");
apiResponse.setData(actNewBrandBoList);
return apiResponse;
}
/**
* @return
* @throws ServiceException
*/
@RequestMapping("/getBrandActInfoById")
@ResponseBody
public ApiResponse getBrandActInfoById(@RequestParam(value="id") Integer id) throws ServiceException {
log.info("getBrandActInfoById req is={}", id);
ActNewBrandBo actNewBrandBo = brandActivityService.getBrandActInfoById(id);
if (actNewBrandBo == null || actNewBrandBo.getId() == null) {
log.warn("getBrandActInfoById error!!!! , res={}", JSON.toJSONString(actNewBrandBo));
new ApiResponse(500, "对不起,活动未开始或已失效");
}
ApiResponse apiResponse = new ApiResponse(200, "活动详情");
apiResponse.setData(actNewBrandBo);
return apiResponse;
}
/**
* @return
* @throws ServiceException
*/
@RequestMapping("/addBrandActPrize")
@ResponseBody
public ApiResponse addBrandActPrize(@RequestParam(value="uid")int uid,@RequestParam(value="boxId")int boxId) throws ServiceException {
log.info("getBrandActInfoById req uid is={},boxid is {}", uid, boxId);
ApiResponse apiResponse = brandActivityService.addBrandActPrize(uid, boxId);
log.info("getBrandActInfoById res {}", apiResponse);
return apiResponse;
}
/**
* @return
* @throws ServiceException
*/
@RequestMapping("/getBrandPrizeListByUid")
@ResponseBody
public ApiResponse getBrandPrizeListByUid(@RequestParam(value="uid") int uid) throws ServiceException {
log.info("getBrandPrizeListByUid req uid is={},boxid is {}", uid);
ApiResponse apiResponse = brandActivityService.getBrandPrizeListByUid(uid);
log.info("getBrandPrizeListByUid res {}", apiResponse);
return apiResponse;
}
}
... ...
/**
*
*/
package com.yoho.activity.controller;
import com.yoho.activity.common.ApiResponse;
import com.yoho.error.exception.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* 描述:商品收藏
*
* @author lijian
* 2016-8-23 11:35:42
*/
@Controller
@RequestMapping("/favorite")
public class FavoriteController {
static Logger log = LoggerFactory.getLogger(FavoriteController.class);
/**
* 添加收藏
*
* @param
* @return
* @throws ServiceException
*/
@RequestMapping("/addFavorite")
@ResponseBody
public ApiResponse addFavorite() throws ServiceException {
return new ApiResponse();
}
}
... ...
... ... @@ -2,6 +2,8 @@ package com.yoho.activity.dal;
import com.yoho.activity.dal.model.ActNewBrand;
import java.util.List;
public interface ActNewBrandMapper {
int deleteByPrimaryKey(Integer id);
... ... @@ -11,6 +13,8 @@ public interface ActNewBrandMapper {
ActNewBrand selectByPrimaryKey(Integer id);
List<ActNewBrand> selectListByTime(String day);
int updateByPrimaryKeySelective(ActNewBrand record);
int updateByPrimaryKey(ActNewBrand record);
... ...
package com.yoho.activity.dal;
import com.yoho.activity.dal.model.ActNewBrandResult;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ActNewBrandResultMapper {
int deleteByPrimaryKey(Integer id);
... ... @@ -11,6 +14,10 @@ public interface ActNewBrandResultMapper {
ActNewBrandResult selectByPrimaryKey(Integer id);
ActNewBrandResult selectByUidAndBoxId(@Param("uid") int uid,@Param("boxId")int boxId);
List<ActNewBrandResult> selectListByUid(int uid);
int updateByPrimaryKeySelective(ActNewBrandResult record);
int updateByPrimaryKey(ActNewBrandResult record);
... ...
... ... @@ -20,6 +20,36 @@ public class ActNewBrand extends BaseModel {
private Byte prize;
private Byte prizeType;
private String prizeInfo;
private String prizeRemark;
public Byte getPrizeType() {
return prizeType;
}
public void setPrizeType(Byte prizeType) {
this.prizeType = prizeType;
}
public String getPrizeInfo() {
return prizeInfo;
}
public void setPrizeInfo(String prizeInfo) {
this.prizeInfo = prizeInfo;
}
public String getPrizeRemark() {
return prizeRemark;
}
public void setPrizeRemark(String prizeRemark) {
this.prizeRemark = prizeRemark;
}
public Integer getId() {
return id;
}
... ...
... ... @@ -22,6 +22,16 @@ public class ActNewBrandResult extends BaseModel {
private String prizeInfo;
private String prizeRemark;
public String getPrizeRemark() {
return prizeRemark;
}
public void setPrizeRemark(String prizeRemark) {
this.prizeRemark = prizeRemark;
}
public Integer getId() {
return id;
}
... ...
... ... @@ -8,9 +8,13 @@
<result column="show_date" property="showDate" jdbcType="VARCHAR" />
<result column="box_num" property="boxNum" jdbcType="VARCHAR" />
<result column="prize" property="prize" jdbcType="TINYINT" />
<result column="prize_type" property="prizeType" jdbcType="TINYINT" />
<result column="prize_info" property="prizeInfo" jdbcType="VARCHAR" />
<result column="prize_remark" property="prizeRemark" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List">
id, box_image, brand_info, show_date, box_num, prize
id, box_image, brand_info, show_date, box_num, prize,prize_type,prize_info,prize_remark
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap"
parameterType="java.lang.Integer">
... ... @@ -19,10 +23,16 @@
from act_new_brand
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from act_new_brand
where id = #{id,jdbcType=INTEGER}
</delete>
<select id="selectListByTime" resultMap="BaseResultMap"
parameterType="java.lang.String">
select
<include refid="Base_Column_List" />
from act_new_brand
where show_date = #{day}
</select>
<insert id="insert" parameterType="com.yoho.activity.dal.model.ActNewBrand">
insert into act_new_brand (id, box_image, brand_info,
show_date, box_num, prize
... ...
... ... @@ -9,9 +9,10 @@
<result column="draw_date" property="drawDate" jdbcType="VARCHAR" />
<result column="prize_type" property="prizeType" jdbcType="TINYINT" />
<result column="prize_info" property="prizeInfo" jdbcType="VARCHAR" />
<result column="prize_remark" property="prizeRemark" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List">
id, uid, box_id, create_time, draw_date, prize_type, prize_info
id, uid, box_id, create_time, draw_date, prize_type, prize_info,prize_remark
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap"
parameterType="java.lang.Integer">
... ... @@ -20,18 +21,32 @@
from act_new_brand_result
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from act_new_brand_result
where id = #{id,jdbcType=INTEGER}
</delete>
<select id="selectByUidAndBoxId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from act_new_brand_result
where uid = #{uid}
and box_id=#{boxId}
limit 1
</select>
<select id="selectListByUid" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from act_new_brand_result
where uid = #{uid}
</select>
<insert id="insert" parameterType="com.yoho.activity.dal.model.ActNewBrandResult">
insert into act_new_brand_result (id, uid, box_id,
create_time, draw_date, prize_type,
prize_info)
prize_info,prize_remark)
values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER},
#{boxId,jdbcType=INTEGER},
#{createTime,jdbcType=INTEGER}, #{drawDate,jdbcType=VARCHAR}, #{prizeType,jdbcType=TINYINT},
#{prizeInfo,jdbcType=VARCHAR})
#{prizeInfo,jdbcType=VARCHAR},#{prizeRemark,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.yoho.activity.dal.model.ActNewBrandResult">
insert into act_new_brand_result
... ...
/**
*
*/
package com.yoho.activity.service;
import com.yoho.activity.common.ApiResponse;
import com.yoho.activity.common.bo.ActNewBrandBo;
import com.yoho.error.exception.ServiceException;
import java.util.List;
/**
* 描述:品牌抽奖活动
*
* @author lijian
* 2016年8月28日
*/
public interface IBrandActivityService {
public List<ActNewBrandBo> getBrandActList() throws ServiceException;
public ActNewBrandBo getBrandActInfoById(Integer id) throws ServiceException;
public ApiResponse addBrandActPrize(int uid, int boxId) throws ServiceException;
public ApiResponse getBrandPrizeListByUid(int uid) throws ServiceException;
}
... ...
... ... @@ -18,30 +18,33 @@ public interface ICouponActivityService {
/**
* 发送短信
*
* @param mobile
* @param password
* @param activity
* @throws ServiceException
*/
public void sendNoticeSms(String mobile, String password, CouponActivity activity) throws ServiceException;
/**
* 根据id活动优惠券活动信息
*
* @param activityCode
* @return
* @throws ServiceException
*/
public CouponActivityResponseBO getCouponActivityByCode(String activityCode) throws ServiceException;
/**
* 发送短信
*
* @param area
* @param mobile
* @return
* @throws Exception
*/
public ApiResponse sendSms(String area, String mobile) throws ServiceException;
/**
* 验证验证码
* 该方法会执行后续一系列动作
... ... @@ -50,6 +53,7 @@ public interface ICouponActivityService {
* 3、如果未领取,则判断该手机号码是否注册过有货账号,如果没有,则调用注册接口,注册。
* 4、调用接口发送优惠券
* 5、如果用户是新用户,则发送短信提醒用户。
*
* @param code
* @param area
* @param mobile
... ... @@ -58,10 +62,11 @@ public interface ICouponActivityService {
* @throws ServiceException
*/
public ApiResponse validCodeAndSendCode(String code, String area, String mobile, String client_id, String activityCode) throws ServiceException;
/**
* 验证验证码
*
* @param regCode
* @param area
* @param mobile
... ... @@ -69,9 +74,10 @@ public interface ICouponActivityService {
* @throws ServiceException
*/
public ApiResponse validRegCode(String regCode, String area, String mobile) throws ServiceException;
/**
* 使用手机号注册
*
* @param area
* @param mobile
* @param client_type
... ... @@ -79,4 +85,7 @@ public interface ICouponActivityService {
* @throws ServiceException
*/
public ApiResponse register(String area, String mobile, String client_type) throws ServiceException;
public String sendCoupon(String couponId, String uid) throws ServiceException;
}
... ...
/**
*
*/
package com.yoho.activity.service;
/**
* 描述:活动收藏接口
*
* @author lijian
* 2016-8-23 13:44:46
*/
public interface IFavoriteActivityService {
}
... ...
/**
*
*/
package com.yoho.activity.service.impl;
import com.alibaba.fastjson.JSON;
import com.yoho.activity.common.ApiResponse;
import com.yoho.activity.common.bo.ActNewBrandBo;
import com.yoho.activity.common.utils.BeanTool;
import com.yoho.activity.common.utils.DateUtils;
import com.yoho.activity.dal.ActNewBrandMapper;
import com.yoho.activity.dal.ActNewBrandResultMapper;
import com.yoho.activity.dal.model.ActNewBrand;
import com.yoho.activity.dal.model.ActNewBrandResult;
import com.yoho.activity.service.IBrandActivityService;
import com.yoho.activity.service.ICouponActivityService;
import com.yoho.error.exception.ServiceException;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* 描述:品牌抽奖活动
*
* @author lijian
* 2016年8月28日
*/
@Service
public class BrandActivityServiceImpl implements IBrandActivityService {
static Logger logger = LoggerFactory.getLogger(BrandActivityServiceImpl.class);
@Resource
ActNewBrandMapper actNewBrandMapper;
@Resource
ActNewBrandResultMapper actNewBrandResultMapper;
@Resource
ICouponActivityService iCouponActivityService;
/**
* 根据当前时间查询品牌活动奖项列表
*
* @return
* @throws ServiceException
*/
@Override
public List<ActNewBrandBo> getBrandActList() throws ServiceException {
//获取当前时间
String dt = DateUtils.getToday(DateUtils.DAY_FOMARTPATTER);
List<ActNewBrand> actNewBrandList = actNewBrandMapper.selectListByTime(dt);
logger.info("getBrandActList db res={}", JSON.toJSONString(actNewBrandList));
List<ActNewBrandBo> actNewBrandBoList = BeanTool.copyList(actNewBrandList, ActNewBrandBo.class);
return actNewBrandBoList;
}
@Override
public ActNewBrandBo getBrandActInfoById(Integer id) throws ServiceException {
ActNewBrand actNewBrand = actNewBrandMapper.selectByPrimaryKey(id);
ActNewBrandBo actNewBrandBo = BeanTool.copyObject(actNewBrand, ActNewBrandBo.class);
return actNewBrandBo;
}
@Override
public ApiResponse addBrandActPrize(int uid, int boxId) throws ServiceException {
// 检查参数
ApiResponse apiRespons = null;
if (uid < 1 || boxId < 1) {
logger.warn("addBrandActPrize error uid={}, boxid={}", uid, boxId);
return new ApiResponse(403, "参数异常");
}
ActNewBrandResult actNewBrandResult = actNewBrandResultMapper.selectByUidAndBoxId(uid, boxId);
if (actNewBrandResult != null && actNewBrandResult.getId().intValue() > 0) {
logger.warn("addBrandActPrize error uid={}, boxid={}", uid, boxId);
apiRespons = new ApiResponse(403, "对不起,您已领取");
apiRespons.setData(actNewBrandResult);
return apiRespons;
}
ActNewBrand actNewBrand = actNewBrandMapper.selectByPrimaryKey(boxId);
ActNewBrandResult brandResult = new ActNewBrandResult();
brandResult.setPrizeInfo(actNewBrand.getPrizeInfo());
brandResult.setPrizeType(actNewBrand.getPrizeType());
brandResult.setUid(uid);
brandResult.setBoxId(boxId);
brandResult.setCreateTime(DateUtils.getCurrentTimeSecond());
brandResult.setDrawDate(DateUtils.getToday(DateUtils.DAY_FOMARTPATTER));
brandResult.setPrizeRemark(actNewBrand.getPrizeRemark());
int res = 0;
//活动没有批量
if (actNewBrand.getPrizeInfo() != null) {
String[] ids = StringUtils.split(actNewBrand.getPrizeInfo(), ',');
if (ids.length > 0) {
for (String id : ids) {
String str = iCouponActivityService.sendCoupon(id, String.valueOf(uid));
if (str != null) {
res++;
}
}
}
if (res == ids.length) {
res = actNewBrandResultMapper.insert(brandResult);
}
}
if (res > 0) {
apiRespons = new ApiResponse(200, "领取成功");
} else {
logger.warn("addBrandActPrize error uid={}, boxid={} db {}", uid, boxId, brandResult);
apiRespons = new ApiResponse(403, "对不起,领取失败");
}
return apiRespons;
}
@Override
public ApiResponse getBrandPrizeListByUid(int uid) throws ServiceException {
ApiResponse apiRespons = null;
if (uid < 1) {
logger.warn("addBrandActPrize error uid={}", uid);
return new ApiResponse(403, "参数异常");
}
List<ActNewBrandResult> results = actNewBrandResultMapper.selectListByUid(uid);
apiRespons = new ApiResponse(200, "用户抽奖记录");
apiRespons.setData(results);
return apiRespons;
}
}
... ...
... ... @@ -3,19 +3,6 @@
*/
package com.yoho.activity.service.impl;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.yoho.activity.common.ApiResponse;
import com.yoho.activity.common.constatns.Constant;
... ... @@ -32,12 +19,25 @@ import com.yoho.coupon.dal.ICouponActivityDAO;
import com.yoho.coupon.dal.model.CouponActivity;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.activity.coupon.response.CouponActivityResponseBO;
import com.yoho.service.model.promotion.CouponForm;
import com.yoho.service.model.promotion.request.ParamsConfigReq;
import com.yoho.service.model.promotion.response.EventConfigRsp;
import com.yoho.service.model.request.ProfileRequestBO;
import com.yoho.service.model.request.RegisterReqBO;
import com.yoho.service.model.response.ProfileInfoRsp;
import com.yoho.service.model.response.RegisterRspBO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* 描述:
... ... @@ -72,7 +72,11 @@ public class ICouponActivityServiceImpl implements ICouponActivityService {
@Resource
SendSMSHelper sendSMSHelper;
@Resource
ServiceCaller serviceCaller;
@Override
public CouponActivityResponseBO getCouponActivityByCode(String activityCode) throws ServiceException {
log.debug("getCouponActivityByCode with activityCode={}", activityCode);
... ... @@ -340,4 +344,26 @@ public class ICouponActivityServiceImpl implements ICouponActivityService {
return bo;
}
/**
* 发送优惠券
*
* @param couponId
* @param uid
*/
@Autowired
public String sendCoupon(String couponId, String uid) throws ServiceException{
log.info("start with sendCoupon. couponId is {}, uid is {}", couponId, uid);
CouponForm form = new CouponForm();
form.setCouponId(couponId);
form.setUid(uid);
String couponCode = "";
try {
couponCode = serviceCaller.call("promotion.sendCoupon", form, String.class);
} catch (Exception e) {
log.error("sendCoupon failed, ex: {}", e.getMessage());
}
log.info("end with sendCoupon. couponCode is {}", couponCode);
return couponCode;
}
}
... ...
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
<classpath>
<dir name="E:/work_yoho/yohobuy-activity/target/classes">
</dir>
</classpath>
</application>
... ...