|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
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;
|
|
|
}
|
|
|
} |
...
|
...
|
|