|  |  |  | 
|---|
|  |  |  | package com.matrix; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.matrix.system.common.bean.BusParameterSettings; | 
|---|
|  |  |  | import com.matrix.system.common.dao.BusParameterSettingsDao; | 
|---|
|  |  |  | import com.matrix.system.fenxiao.constant.FenxiaoSettingConstant; | 
|---|
|  |  |  | import com.matrix.system.score.constant.ScoreSettingConstant; | 
|---|
|  |  |  | import cn.hutool.core.collection.CollUtil; | 
|---|
|  |  |  | import cn.hutool.core.date.DateTime; | 
|---|
|  |  |  | import cn.hutool.core.date.DateUnit; | 
|---|
|  |  |  | import cn.hutool.core.date.DateUtil; | 
|---|
|  |  |  | import cn.hutool.core.util.ObjectUtil; | 
|---|
|  |  |  | import cn.hutool.core.util.RandomUtil; | 
|---|
|  |  |  | import cn.hutool.core.util.StrUtil; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.matrix.core.pojo.AjaxResult; | 
|---|
|  |  |  | import com.matrix.core.tools.StringUtils; | 
|---|
|  |  |  | import com.matrix.system.activity.dao.ActivitySignAwardSetDao; | 
|---|
|  |  |  | import com.matrix.system.activity.dao.ActivitySignReceiveRecordDao; | 
|---|
|  |  |  | import com.matrix.system.activity.dao.ActivitySignRecordDao; | 
|---|
|  |  |  | import com.matrix.system.activity.dao.ActivitySignWriteoffDao; | 
|---|
|  |  |  | import com.matrix.system.activity.entity.ActivitySignAwardSet; | 
|---|
|  |  |  | import com.matrix.system.activity.entity.ActivitySignReceiveRecord; | 
|---|
|  |  |  | import com.matrix.system.activity.entity.ActivitySignRecord; | 
|---|
|  |  |  | import com.matrix.system.activity.entity.ActivitySignWriteoff; | 
|---|
|  |  |  | import com.matrix.system.common.constance.AppConstance; | 
|---|
|  |  |  | import com.matrix.system.hive.bean.SysVipInfo; | 
|---|
|  |  |  | import com.matrix.system.hive.dao.SysVipInfoDao; | 
|---|
|  |  |  | import com.matrix.system.score.entity.ScoreVipDetail; | 
|---|
|  |  |  | import com.matrix.system.score.service.ScoreVipDetailService; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.dto.SeeAwardTextDto; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.service.WxShopLogisticsQueryService; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.tools.WxShopCouponUtil; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.vo.ActivitySignAwardSetVo; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.vo.LuckyDrawBasicInfoJsonVo; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.vo.LuckyDrawSuccessVo; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.vo.SeeAwardTextVo; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.bean.*; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.dao.*; | 
|---|
|  |  |  | import org.junit.Test; | 
|---|
|  |  |  | import org.junit.runner.RunWith; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.boot.test.context.SpringBootTest; | 
|---|
|  |  |  | import org.springframework.test.context.junit4.SpringRunner; | 
|---|
|  |  |  | import org.springframework.validation.annotation.Validated; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestBody; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RunWith(SpringRunner.class) | 
|---|
|  |  |  | @SpringBootTest(classes = {ZqErpApplication.class},webEnvironment =SpringBootTest.WebEnvironment.RANDOM_PORT) | 
|---|
|  |  |  | public class FenxiaoSoreInitTest { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ShopActivitiesDao shopActivitiesDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ActivitySignAwardSetDao activitySignAwardSetDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ActivitySignReceiveRecordDao activitySignReceiveRecordDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ActivitySignWriteoffDao activitySignWriteoffDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ActivitySignRecordDao activitySignRecordDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | ShopDeliveryInfoDao shopDeliveryInfoDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ShopLogisticsInfoDao shopLogisticsInfoDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WxShopLogisticsQueryService wxShopLogisticsQueryService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ScoreVipDetailService scoreVipDetailService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ShopCouponDao shopCouponDao; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WxShopCouponUtil wxShopCouponUtil; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ShopCouponRecordDao shopCouponRecordDao; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | SysVipInfoDao sysVipInfoDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取奖品并索引+1 已领取+1 | 
|---|
|  |  |  | public synchronized ActivitySignAwardSet updateShopActivityAndAwardSet(Long actId){ | 
|---|
|  |  |  | //通过活动ID获取对应的活动 | 
|---|
|  |  |  | ShopActivities shopActivities = shopActivitiesDao.selectById(actId); | 
|---|
|  |  |  | String actContent = shopActivities.getActContent(); | 
|---|
|  |  |  | LuckyDrawBasicInfoJsonVo luckyDrawBasicInfoJsonVo = JSON.parseObject(actContent, LuckyDrawBasicInfoJsonVo.class); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //中奖索引 | 
|---|
|  |  |  | Integer awrdLineIndex = luckyDrawBasicInfoJsonVo.getAwrdLineIndex(); | 
|---|
|  |  |  | //中奖序列 | 
|---|
|  |  |  | String awardLine = luckyDrawBasicInfoJsonVo.getAwardLine(); | 
|---|
|  |  |  | ActivitySignAwardSet activitySignAwardSet = null; | 
|---|
|  |  |  | if(awardLine.length() > 0) { | 
|---|
|  |  |  | String substring = awardLine.substring(1, awardLine.length() - 1); | 
|---|
|  |  |  | List<String> awardList = StrUtil.splitTrim(substring, ","); | 
|---|
|  |  |  | if(awrdLineIndex < awardList.size()){ | 
|---|
|  |  |  | //中奖 | 
|---|
|  |  |  | Long awardId = Long.parseLong(awardList.get(awrdLineIndex + 1)); | 
|---|
|  |  |  | ActivitySignAwardSet activitySignAwardSetGet = activitySignAwardSetDao.selectById(awardId); | 
|---|
|  |  |  | //奖项库存数量 | 
|---|
|  |  |  | int awardInventoryCnt = activitySignAwardSetGet.getAwardInventoryCnt(); | 
|---|
|  |  |  | //已派发数量 | 
|---|
|  |  |  | int awardDistributeCnt = activitySignAwardSetGet.getAwardDistributeCnt(); | 
|---|
|  |  |  | if(awardDistributeCnt < awardInventoryCnt){ | 
|---|
|  |  |  | activitySignAwardSet = activitySignAwardSetGet; | 
|---|
|  |  |  | activitySignAwardSetGet.setAwardDistributeCnt(awardDistributeCnt +1); | 
|---|
|  |  |  | activitySignAwardSetDao.updateById(activitySignAwardSetGet); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //将基本信息转换成JSON字符串存储到活动主表的act_content字段 | 
|---|
|  |  |  | luckyDrawBasicInfoJsonVo.setAwrdLineIndex(awrdLineIndex + 1); | 
|---|
|  |  |  | String json= JSON.toJSONString(luckyDrawBasicInfoJsonVo); | 
|---|
|  |  |  | shopActivities.setActContent(json); | 
|---|
|  |  |  | shopActivitiesDao.updateByModel(shopActivities); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return activitySignAwardSet; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Test | 
|---|
|  |  |  | public void getLuckDraw(){ | 
|---|
|  |  |  | long actId = 85L; | 
|---|
|  |  |  | Long userId = 85L; | 
|---|
|  |  |  | Long companyId = 36L; | 
|---|
|  |  |  | SysVipInfo user = sysVipInfoDao.selectById(userId); | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 活动是否存在 | 
|---|
|  |  |  | * 活动是否已经开始 | 
|---|
|  |  |  | * 免费抽奖还是积分抽奖 | 
|---|
|  |  |  | *      积分抽奖一次一次换 | 
|---|
|  |  |  | *      减少积分 | 
|---|
|  |  |  | *  是否中奖 | 
|---|
|  |  |  | *      中奖规则 | 
|---|
|  |  |  | *  奖品处理 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | //活动是否存在 | 
|---|
|  |  |  | ShopActivities shopActivities = shopActivitiesDao.selectById(actId); | 
|---|
|  |  |  | if (ObjectUtil.isEmpty(shopActivities)) { | 
|---|
|  |  |  | // return AjaxResult.buildFailInstance("活动不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //活动是否已经开始 | 
|---|
|  |  |  | Integer actStatus = shopActivities.getActStatus(); | 
|---|
|  |  |  | if(ShopActivities.ACTSTATUS_STATUS_ING != actStatus) { | 
|---|
|  |  |  | //return AjaxResult.buildFailInstance("活动未开始"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //获取今日抽奖总次数 | 
|---|
|  |  |  | String actContent = shopActivities.getActContent(); | 
|---|
|  |  |  | LuckyDrawBasicInfoJsonVo luckyDrawBasicInfoJsonVo = JSON.parseObject(actContent, LuckyDrawBasicInfoJsonVo.class); | 
|---|
|  |  |  | List<ActivitySignRecord> activityRecords = activitySignRecordDao.selectListByActIdAndUserIdLikesignTime(actId,userId, DateUtil.date()); | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(activityRecords)){ | 
|---|
|  |  |  | Integer wmkcjjh = luckyDrawBasicInfoJsonVo.getWmkcjjh(); | 
|---|
|  |  |  | Integer jfdhcs = luckyDrawBasicInfoJsonVo.getJfdhcs(); | 
|---|
|  |  |  | if(activityRecords.size() >= (wmkcjjh+jfdhcs)){ | 
|---|
|  |  |  | //return AjaxResult.buildFailInstance("明天再来抽奖吧"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //生成抽奖记录 | 
|---|
|  |  |  | ActivitySignRecord activitySignRecordAdd = new ActivitySignRecord(); | 
|---|
|  |  |  | activitySignRecordAdd.setCompanyId(companyId); | 
|---|
|  |  |  | activitySignRecordAdd.setCreateBy(user.getVipName()); | 
|---|
|  |  |  | activitySignRecordAdd.setCreateTime(DateUtil.date()); | 
|---|
|  |  |  | activitySignRecordAdd.setUpdateBy(user.getVipName()); | 
|---|
|  |  |  | activitySignRecordAdd.setUpdateTime(DateUtil.date()); | 
|---|
|  |  |  | activitySignRecordAdd.setActivityId(actId); | 
|---|
|  |  |  | activitySignRecordAdd.setSignTime(DateUtil.date()); | 
|---|
|  |  |  | activitySignRecordAdd.setUserId(userId); | 
|---|
|  |  |  | activitySignRecordDao.insert(activitySignRecordAdd); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 获取中奖概率 | 
|---|
|  |  |  | 中奖了获取奖品ID | 
|---|
|  |  |  | 没有中奖则获取谢谢参与的奖品ID | 
|---|
|  |  |  | 每个人最多中奖次数 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<LuckyDrawSuccessVo> luckyDrawSuccessVos = new ArrayList<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取谢谢参与奖 | 
|---|
|  |  |  | QueryWrapper<ActivitySignAwardSet> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | queryWrapper.eq("award_rule",ActivitySignAwardSet.AWARDRULE_NORMAL); | 
|---|
|  |  |  | queryWrapper.eq("company_id",companyId); | 
|---|
|  |  |  | queryWrapper.eq("activity_id",actId); | 
|---|
|  |  |  | ActivitySignAwardSet activitySignAwardSetNormal = activitySignAwardSetDao.selectOne(queryWrapper); | 
|---|
|  |  |  | //每个人最多中奖次数 | 
|---|
|  |  |  | Integer zzjcs = luckyDrawBasicInfoJsonVo.getZzjcs(); | 
|---|
|  |  |  | QueryWrapper<ActivitySignReceiveRecord> queryWrapperActivitySignReceiveRecord = new QueryWrapper<>(); | 
|---|
|  |  |  | queryWrapperActivitySignReceiveRecord.eq("company_id", companyId); | 
|---|
|  |  |  | queryWrapperActivitySignReceiveRecord.eq("activity_id", actId); | 
|---|
|  |  |  | queryWrapperActivitySignReceiveRecord.eq("user_id", userId); | 
|---|
|  |  |  | queryWrapperActivitySignReceiveRecord.ne("award_id", activitySignAwardSetNormal.getId()); | 
|---|
|  |  |  | List<ActivitySignReceiveRecord> activitySignReceiveRecordDone = activitySignReceiveRecordDao.selectList(queryWrapperActivitySignReceiveRecord); | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(activitySignReceiveRecordDone)){ | 
|---|
|  |  |  | if(activitySignReceiveRecordDone.size() >= zzjcs){ | 
|---|
|  |  |  | //生成领取记录 | 
|---|
|  |  |  | ActivitySignReceiveRecord activitySignReceiveRecord = new ActivitySignReceiveRecord(); | 
|---|
|  |  |  | activitySignReceiveRecord.setUserId(userId); | 
|---|
|  |  |  | activitySignReceiveRecord.setReceiveTime(DateUtil.date()); | 
|---|
|  |  |  | activitySignReceiveRecord.setAwardId(activitySignAwardSetNormal.getId()); | 
|---|
|  |  |  | activitySignReceiveRecord.setState(ActivitySignReceiveRecord.STATE_DONE); | 
|---|
|  |  |  | activitySignReceiveRecord.setActivityId(actId); | 
|---|
|  |  |  | activitySignReceiveRecord.setCompanyId(companyId); | 
|---|
|  |  |  | activitySignReceiveRecord.setCreateBy(user.getVipName()); | 
|---|
|  |  |  | activitySignReceiveRecord.setCreateTime(new Date()); | 
|---|
|  |  |  | activitySignReceiveRecord.setUpdateBy(user.getVipName()); | 
|---|
|  |  |  | activitySignReceiveRecord.setUpdateTime(new Date()); | 
|---|
|  |  |  | activitySignReceiveRecordDao.insert(activitySignReceiveRecord); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LuckyDrawSuccessVo luckyDrawSuccessVo = new LuckyDrawSuccessVo(); | 
|---|
|  |  |  | luckyDrawSuccessVo.setType(1); | 
|---|
|  |  |  | luckyDrawSuccessVo.setAwardName(activitySignAwardSetNormal.getAwardName()); | 
|---|
|  |  |  | luckyDrawSuccessVo.setAwardImg(activitySignAwardSetNormal.getIntroduceImg()); | 
|---|
|  |  |  | luckyDrawSuccessVos.add(luckyDrawSuccessVo); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AjaxResult ajaxResult = AjaxResult.buildSuccessInstance(""); | 
|---|
|  |  |  | ajaxResult.setData(luckyDrawSuccessVos); | 
|---|
|  |  |  | //return ajaxResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //总中奖率 | 
|---|
|  |  |  | int zzjl = luckyDrawBasicInfoJsonVo.getZzjl(); | 
|---|
|  |  |  | int randomInt = RandomUtil.randomInt(1, 100); | 
|---|
|  |  |  | //不中奖的分界线 | 
|---|
|  |  |  | int failureScope = 0; | 
|---|
|  |  |  | if(failureScope >= randomInt){ | 
|---|
|  |  |  | //生成领取记录 | 
|---|
|  |  |  | ActivitySignReceiveRecord activitySignReceiveRecord = new ActivitySignReceiveRecord(); | 
|---|
|  |  |  | activitySignReceiveRecord.setUserId(userId); | 
|---|
|  |  |  | activitySignReceiveRecord.setReceiveTime(DateUtil.date()); | 
|---|
|  |  |  | activitySignReceiveRecord.setAwardId(activitySignAwardSetNormal.getId()); | 
|---|
|  |  |  | activitySignReceiveRecord.setState(ActivitySignReceiveRecord.STATE_DONE); | 
|---|
|  |  |  | activitySignReceiveRecord.setActivityId(actId); | 
|---|
|  |  |  | activitySignReceiveRecord.setCompanyId(companyId); | 
|---|
|  |  |  | activitySignReceiveRecord.setCreateBy(user.getVipName()); | 
|---|
|  |  |  | activitySignReceiveRecord.setCreateTime(new Date()); | 
|---|
|  |  |  | activitySignReceiveRecord.setUpdateBy(user.getVipName()); | 
|---|
|  |  |  | activitySignReceiveRecord.setUpdateTime(new Date()); | 
|---|
|  |  |  | activitySignReceiveRecordDao.insert(activitySignReceiveRecord); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LuckyDrawSuccessVo luckyDrawSuccessVo = new LuckyDrawSuccessVo(); | 
|---|
|  |  |  | luckyDrawSuccessVo.setType(1); | 
|---|
|  |  |  | luckyDrawSuccessVo.setAwardName(activitySignAwardSetNormal.getAwardName()); | 
|---|
|  |  |  | luckyDrawSuccessVo.setAwardImg(activitySignAwardSetNormal.getIntroduceImg()); | 
|---|
|  |  |  | luckyDrawSuccessVos.add(luckyDrawSuccessVo); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AjaxResult ajaxResult = AjaxResult.buildSuccessInstance(""); | 
|---|
|  |  |  | ajaxResult.setData(luckyDrawSuccessVos); | 
|---|
|  |  |  | //return ajaxResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //中奖 | 
|---|
|  |  |  | if(failureScope < randomInt){ | 
|---|
|  |  |  | //获取奖品 | 
|---|
|  |  |  | ActivitySignAwardSet activitySignAwardSetCumulativeDay = updateShopActivityAndAwardSet(actId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(activitySignAwardSetCumulativeDay)){ | 
|---|
|  |  |  | LuckyDrawSuccessVo luckyDrawSuccessVo = new LuckyDrawSuccessVo(); | 
|---|
|  |  |  | luckyDrawSuccessVo.setType(2); | 
|---|
|  |  |  | luckyDrawSuccessVo.setAwardType(activitySignAwardSetCumulativeDay.getAwardType()); | 
|---|
|  |  |  | luckyDrawSuccessVo.setAwardName(activitySignAwardSetCumulativeDay.getAwardName()); | 
|---|
|  |  |  | luckyDrawSuccessVo.setAwardImg(activitySignAwardSetCumulativeDay.getIntroduceImg()); | 
|---|
|  |  |  | luckyDrawSuccessVo.setAwardState(activitySignAwardSetCumulativeDay.getAwardState()); | 
|---|
|  |  |  | //新增奖品领取记录 | 
|---|
|  |  |  | ActivitySignReceiveRecord activitySignReceiveRecord = new ActivitySignReceiveRecord(); | 
|---|
|  |  |  | activitySignReceiveRecord.setUserId(userId); | 
|---|
|  |  |  | activitySignReceiveRecord.setReceiveTime(DateUtil.date()); | 
|---|
|  |  |  | activitySignReceiveRecord.setAwardId(activitySignAwardSetCumulativeDay.getId()); | 
|---|
|  |  |  | activitySignReceiveRecord.setActivityId(actId); | 
|---|
|  |  |  | activitySignReceiveRecord.setCompanyId(companyId); | 
|---|
|  |  |  | activitySignReceiveRecord.setState(ActivitySignReceiveRecord.STATE_DONE); | 
|---|
|  |  |  | activitySignReceiveRecord.setCreateBy(user.getVipName()); | 
|---|
|  |  |  | activitySignReceiveRecord.setCreateTime(new Date()); | 
|---|
|  |  |  | activitySignReceiveRecord.setUpdateBy(user.getVipName()); | 
|---|
|  |  |  | activitySignReceiveRecord.setUpdateTime(new Date()); | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 奖项类型(1:自定义产品2:积分3:优惠券4:店铺商品) | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * todo:4:店铺商品 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | //1:自定义产品 | 
|---|
|  |  |  | if(ActivitySignAwardSet.AWARDTYPE_CUSTOMIZE == activitySignAwardSetCumulativeDay.getAwardType()) { | 
|---|
|  |  |  | activitySignReceiveRecord.setState(ActivitySignReceiveRecord.STATE_ING); | 
|---|
|  |  |  | String randomString = StringUtils.getRandomString(8); | 
|---|
|  |  |  | activitySignReceiveRecord.setWriteOffCode(randomString); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取对应奖品的领取方式(兑奖方式(1:线下兑换2:物流配送3:客服兑换) | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | luckyDrawSuccessVo.setWriteOffCode(randomString); | 
|---|
|  |  |  | luckyDrawSuccessVo.setAwardWay(activitySignAwardSetCumulativeDay.getAwardWay()); | 
|---|
|  |  |  | //2:物流配送 | 
|---|
|  |  |  | luckyDrawSuccessVo.setOperationTip(activitySignAwardSetCumulativeDay.getOperationTip()); | 
|---|
|  |  |  | //1:线下兑换 | 
|---|
|  |  |  | if(ActivitySignAwardSet.AWARDWAY_ONE == activitySignAwardSetCumulativeDay.getAwardWay()) { | 
|---|
|  |  |  | luckyDrawSuccessVo.setIntroduceTip(activitySignAwardSetCumulativeDay.getIntroduceTip()); | 
|---|
|  |  |  | luckyDrawSuccessVo.setPrizeAddress(activitySignAwardSetCumulativeDay.getPrizeAddress()); | 
|---|
|  |  |  | luckyDrawSuccessVo.setPrizeStartTime(activitySignAwardSetCumulativeDay.getPrizeStartTime()); | 
|---|
|  |  |  | luckyDrawSuccessVo.setPrizeEndTime(activitySignAwardSetCumulativeDay.getPrizeEndTime()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //3:客服兑换 | 
|---|
|  |  |  | if(ActivitySignAwardSet.AWARDWAY_THREE == activitySignAwardSetCumulativeDay.getAwardWay()) { | 
|---|
|  |  |  | luckyDrawSuccessVo.setWechatImg(activitySignAwardSetCumulativeDay.getWechatImg()); | 
|---|
|  |  |  | luckyDrawSuccessVo.setPrizeStartTime(activitySignAwardSetCumulativeDay.getPrizeStartTime()); | 
|---|
|  |  |  | luckyDrawSuccessVo.setPrizeEndTime(activitySignAwardSetCumulativeDay.getPrizeEndTime()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //2:积分 | 
|---|
|  |  |  | if(ActivitySignAwardSet.AWARDTYPE_SCORE == activitySignAwardSetCumulativeDay.getAwardType()) { | 
|---|
|  |  |  | luckyDrawSuccessVo.setScoreCnt(activitySignAwardSetCumulativeDay.getScoreCnt()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //3:优惠券 | 
|---|
|  |  |  | if(ActivitySignAwardSet.AWARDTYPE_COUPON == activitySignAwardSetCumulativeDay.getAwardType()) { | 
|---|
|  |  |  | luckyDrawSuccessVo.setCouponName(activitySignAwardSetCumulativeDay.getCouponName()); | 
|---|
|  |  |  | //获取优惠券 | 
|---|
|  |  |  | int couponId = Integer.parseInt(activitySignAwardSetCumulativeDay.getCouponId()); | 
|---|
|  |  |  | ShopCoupon shopCoupon = shopCouponDao.selectById(couponId); | 
|---|
|  |  |  | // 如果没有找到该优惠券 | 
|---|
|  |  |  | if (shopCoupon == null) { | 
|---|
|  |  |  | // return new AjaxResult(AjaxResult.STATUS_FAIL, "没有找到该优惠券!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 如果优惠券有数量限制并且已经领完 | 
|---|
|  |  |  | if (shopCoupon.getMaxQuantity() >= 0 && (shopCoupon.getMaxQuantity() <= shopCoupon.getQuantityReceive())) { | 
|---|
|  |  |  | //return new AjaxResult(AjaxResult.STATUS_FAIL, "优惠券已领完!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | boolean newPeople = wxShopCouponUtil.verifyIsNewPeople(userId); | 
|---|
|  |  |  | // 如果改券是新人专属且当前用户不是新人 | 
|---|
|  |  |  | if (AppConstance.COUPON_GET_LIMT_NEW.equals(shopCoupon.getGetLimit()) && !newPeople) { | 
|---|
|  |  |  | // return new AjaxResult(AjaxResult.STATUS_FAIL, "该优惠券为新人专享优惠券!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ShopCouponRecord insertRecord = new ShopCouponRecord(); | 
|---|
|  |  |  | insertRecord.setCreateBy(AppConstance.SYSTEM_USER); | 
|---|
|  |  |  | insertRecord.setUpdateBy(AppConstance.SYSTEM_USER); | 
|---|
|  |  |  | insertRecord.setCId(couponId); | 
|---|
|  |  |  | insertRecord.setUserId(userId); | 
|---|
|  |  |  | insertRecord.setIsUsing(2); | 
|---|
|  |  |  | int i = shopCouponRecordDao.insert(insertRecord); | 
|---|
|  |  |  | // 如果插入领取记录表失败 | 
|---|
|  |  |  | if (i < 0) { | 
|---|
|  |  |  | //return new AjaxResult(AjaxResult.STATUS_FAIL, "优惠券领取失败!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | shopCoupon.setQuantityReceive(shopCoupon.getQuantityReceive() + 1); | 
|---|
|  |  |  | shopCouponDao.updateByModel(shopCoupon); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | activitySignReceiveRecordDao.insert(activitySignReceiveRecord); | 
|---|
|  |  |  | //累计奖励积分,对应用户积分加减 | 
|---|
|  |  |  | if(ActivitySignAwardSet.AWARDTYPE_SCORE == activitySignAwardSetCumulativeDay.getAwardType()) { | 
|---|
|  |  |  | int awardType = activitySignAwardSetCumulativeDay.getAwardType(); | 
|---|
|  |  |  | if(ActivitySignAwardSet.AWARDTYPE_SCORE == awardType){ | 
|---|
|  |  |  | int scoreCnt = activitySignAwardSetCumulativeDay.getScoreCnt(); | 
|---|
|  |  |  | if(scoreCnt > 0){ | 
|---|
|  |  |  | scoreVipDetailService.addScore(userId,null,null,scoreCnt, | 
|---|
|  |  |  | activitySignReceiveRecord.getId(), ScoreVipDetail.SCORE_VIP_TYPE_JOIN_ACTIVE,"签到积分"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //生成核销记录 | 
|---|
|  |  |  | if(ActivitySignAwardSet.AWARDTYPE_CUSTOMIZE == activitySignAwardSetCumulativeDay.getAwardType()) { | 
|---|
|  |  |  | ActivitySignWriteoff activitySignWriteoff = new ActivitySignWriteoff(); | 
|---|
|  |  |  | //线下兑换和客服兑换 | 
|---|
|  |  |  | if(ActivitySignAwardSet.AWARDWAY_ONE == activitySignAwardSetCumulativeDay.getAwardWay() | 
|---|
|  |  |  | || ActivitySignAwardSet.AWARDWAY_THREE == activitySignAwardSetCumulativeDay.getAwardWay()) { | 
|---|
|  |  |  | activitySignWriteoff.setWriteoffCode(activitySignReceiveRecord.getWriteOffCode()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | activitySignWriteoff.setActId(actId); | 
|---|
|  |  |  | activitySignWriteoff.setAwardId(activitySignAwardSetCumulativeDay.getId()); | 
|---|
|  |  |  | activitySignWriteoff.setWinTime(DateUtil.date()); | 
|---|
|  |  |  | if(ActivitySignAwardSet.AWARDWAY_TWO == activitySignAwardSetCumulativeDay.getAwardWay()) { | 
|---|
|  |  |  | activitySignWriteoff.setState(ActivitySignWriteoff.STATE_TWO); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | activitySignWriteoff.setState(ActivitySignWriteoff.STATE_ONE); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | activitySignWriteoff.setUserId(userId); | 
|---|
|  |  |  | activitySignWriteoff.setCompanyId(companyId); | 
|---|
|  |  |  | activitySignWriteoff.setReceiveId(activitySignReceiveRecord.getId()); | 
|---|
|  |  |  | activitySignWriteoff.setCreateBy(user.getVipName()); | 
|---|
|  |  |  | activitySignWriteoff.setCreateTime(new Date()); | 
|---|
|  |  |  | activitySignWriteoff.setUpdateBy(user.getVipName()); | 
|---|
|  |  |  | activitySignWriteoff.setUpdateTime(new Date()); | 
|---|
|  |  |  | activitySignWriteoffDao.insert(activitySignWriteoff); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | luckyDrawSuccessVos.add(luckyDrawSuccessVo); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | //生成领取记录 | 
|---|
|  |  |  | ActivitySignReceiveRecord activitySignReceiveRecord = new ActivitySignReceiveRecord(); | 
|---|
|  |  |  | activitySignReceiveRecord.setUserId(userId); | 
|---|
|  |  |  | activitySignReceiveRecord.setReceiveTime(DateUtil.date()); | 
|---|
|  |  |  | activitySignReceiveRecord.setAwardId(activitySignAwardSetNormal.getId()); | 
|---|
|  |  |  | activitySignReceiveRecord.setState(ActivitySignReceiveRecord.STATE_DONE); | 
|---|
|  |  |  | activitySignReceiveRecord.setActivityId(actId); | 
|---|
|  |  |  | activitySignReceiveRecord.setCompanyId(companyId); | 
|---|
|  |  |  | activitySignReceiveRecord.setCreateBy(user.getVipName()); | 
|---|
|  |  |  | activitySignReceiveRecord.setCreateTime(new Date()); | 
|---|
|  |  |  | activitySignReceiveRecord.setUpdateBy(user.getVipName()); | 
|---|
|  |  |  | activitySignReceiveRecord.setUpdateTime(new Date()); | 
|---|
|  |  |  | activitySignReceiveRecordDao.insert(activitySignReceiveRecord); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LuckyDrawSuccessVo luckyDrawSuccessVo = new LuckyDrawSuccessVo(); | 
|---|
|  |  |  | luckyDrawSuccessVo.setType(1); | 
|---|
|  |  |  | luckyDrawSuccessVo.setAwardName(activitySignAwardSetNormal.getAwardName()); | 
|---|
|  |  |  | luckyDrawSuccessVo.setAwardImg(activitySignAwardSetNormal.getIntroduceImg()); | 
|---|
|  |  |  | luckyDrawSuccessVos.add(luckyDrawSuccessVo); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AjaxResult ajaxResult = AjaxResult.buildSuccessInstance(""); | 
|---|
|  |  |  | ajaxResult.setData(luckyDrawSuccessVos); | 
|---|
|  |  |  | //return ajaxResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | AjaxResult ajaxResult = AjaxResult.buildSuccessInstance(""); | 
|---|
|  |  |  | ajaxResult.setData(luckyDrawSuccessVos); | 
|---|
|  |  |  | //return ajaxResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Test | 
|---|
|  |  |  | public void awardInsert() { | 
|---|
|  |  |  | //获取奖品的抽奖顺序 | 
|---|
|  |  |  | List<ActivitySignAwardSetVo> activitySignAwardSetVos = new ArrayList<>(); | 
|---|
|  |  |  | ActivitySignAwardSetVo activitySignAwardSetVo1 = new ActivitySignAwardSetVo(); | 
|---|
|  |  |  | activitySignAwardSetVo1.setAwardInventoryCnt(10); | 
|---|
|  |  |  | activitySignAwardSetVo1.setId(1L); | 
|---|
|  |  |  | activitySignAwardSetVos.add(activitySignAwardSetVo1); | 
|---|
|  |  |  | ActivitySignAwardSetVo activitySignAwardSetVo2 = new ActivitySignAwardSetVo(); | 
|---|
|  |  |  | activitySignAwardSetVo2.setAwardInventoryCnt(10); | 
|---|
|  |  |  | activitySignAwardSetVo2.setId(2L); | 
|---|
|  |  |  | activitySignAwardSetVos.add(activitySignAwardSetVo2); | 
|---|
|  |  |  | ActivitySignAwardSetVo activitySignAwardSetVo3 = new ActivitySignAwardSetVo(); | 
|---|
|  |  |  | activitySignAwardSetVo3.setAwardInventoryCnt(2); | 
|---|
|  |  |  | activitySignAwardSetVo3.setId(3L); | 
|---|
|  |  |  | activitySignAwardSetVos.add(activitySignAwardSetVo3); | 
|---|
|  |  |  | ActivitySignAwardSetVo activitySignAwardSetVo4 = new ActivitySignAwardSetVo(); | 
|---|
|  |  |  | activitySignAwardSetVo4.setAwardInventoryCnt(1); | 
|---|
|  |  |  | activitySignAwardSetVo4.setId(4L); | 
|---|
|  |  |  | activitySignAwardSetVos.add(activitySignAwardSetVo4); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //插入所有奖品后的集合 | 
|---|
|  |  |  | LinkedList awardIdFinalList = new LinkedList<>(); | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(activitySignAwardSetVos)){ | 
|---|
|  |  |  | //总数 | 
|---|
|  |  |  | int maxCount = 0; | 
|---|
|  |  |  | HashMap<Long, ActivitySignAwardSetVo> integerStringHashMap = new HashMap<>(); | 
|---|
|  |  |  | for(ActivitySignAwardSetVo activitySignAwardSetVo : activitySignAwardSetVos){ | 
|---|
|  |  |  | //总共派发数量 | 
|---|
|  |  |  | int awardInventoryCnt = activitySignAwardSetVo.getAwardInventoryCnt(); | 
|---|
|  |  |  | integerStringHashMap.put(activitySignAwardSetVo.getId(),activitySignAwardSetVo); | 
|---|
|  |  |  | maxCount = maxCount + awardInventoryCnt; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | HashMap<Long, ActivitySignAwardSetVo> sortHashMap = sortHashMap(integerStringHashMap,2); | 
|---|
|  |  |  | HashMap<Long, ActivitySignAwardSetVo> sortHashMapAec = sortHashMap(integerStringHashMap,1); | 
|---|
|  |  |  | //获取奖品最多的ID | 
|---|
|  |  |  | Long maxAwardIds = sortHashMap.keySet().stream().findFirst().get(); | 
|---|
|  |  |  | Long minAwardIds = sortHashMapAec.keySet().stream().findFirst().get(); | 
|---|
|  |  |  | //获取最大长度的奖品集合 | 
|---|
|  |  |  | List awardIdList = new LinkedList<Long>(); | 
|---|
|  |  |  | for(int i = 0; i< maxCount ; i++){ | 
|---|
|  |  |  | awardIdList.add(maxAwardIds); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Iterator<Map.Entry<Long, ActivitySignAwardSetVo>> entries = sortHashMap.entrySet().iterator(); | 
|---|
|  |  |  | //插入奖品 | 
|---|
|  |  |  | while (entries.hasNext()) { | 
|---|
|  |  |  | Map.Entry<Long, ActivitySignAwardSetVo> entry = entries.next(); | 
|---|
|  |  |  | ActivitySignAwardSetVo activitySignAwardSetVo = entry.getValue(); | 
|---|
|  |  |  | int awardInventoryCnt = activitySignAwardSetVo.getAwardInventoryCnt(); | 
|---|
|  |  |  | Long awardIdNew = entry.getKey(); | 
|---|
|  |  |  | if(awardIdNew != maxAwardIds){ | 
|---|
|  |  |  | //分段之后的List | 
|---|
|  |  |  | List splitLists = getSplitList(awardInventoryCnt, awardIdList); | 
|---|
|  |  |  | for(int j = 0; j<awardInventoryCnt; j++){ | 
|---|
|  |  |  | List splitList = (List) splitLists.get(j); | 
|---|
|  |  |  | //中间插入对应的奖品ID,如果和maxAwardIds相同,则索引+1 | 
|---|
|  |  |  | List<Long> listInsert = getListInsert(maxAwardIds, awardIdNew, splitList); | 
|---|
|  |  |  | if(minAwardIds == awardIdNew){ | 
|---|
|  |  |  | awardIdFinalList.addAll(listInsert); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String awrdList = awardIdFinalList.toString(); | 
|---|
|  |  |  | String substring = awrdList.substring(1, awrdList.length() - 1); | 
|---|
|  |  |  | List<String> strings = Arrays.asList(substring); | 
|---|
|  |  |  | System.out.println(strings); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //中间插入对应的奖品ID,如果和maxAwardIds相同,则索引+1 | 
|---|
|  |  |  | public static List<Long> getListInsert(Long awardOld,Long awardNew,List splitList){ | 
|---|
|  |  |  | //中间位置索引 | 
|---|
|  |  |  | LinkedList<Integer> indexs = new LinkedList<>(); | 
|---|
|  |  |  | int groupFlag = splitList.size() % 2 == 0 ? (splitList.size() / 2) : (splitList.size() / 2 + 1); | 
|---|
|  |  |  | for(int j = groupFlag-1; j < splitList.size();j++){ | 
|---|
|  |  |  | if(splitList.get(j) == awardOld){ | 
|---|
|  |  |  | indexs.add(j); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(indexs)){ | 
|---|
|  |  |  | splitList.set(indexs.get(0),awardNew); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | splitList.add(groupFlag,awardNew); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return splitList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //等份平分数组,最后剩余的添加到倒数第二个集合中 | 
|---|
|  |  |  | public static List<List<Long>> getSplitList(int splitNum, List<Long> list) { | 
|---|
|  |  |  | LinkedList<List<Long>> splitList = new LinkedList<>(); | 
|---|
|  |  |  | // groupFlag >= 1 | 
|---|
|  |  |  | int groupFlag = list.size() % splitNum == 0 ? (list.size() / splitNum) : (list.size() / splitNum); | 
|---|
|  |  |  | if(groupFlag * splitNum < list.size()){ | 
|---|
|  |  |  | for (int j = 1; j <= splitNum +1; j++) { | 
|---|
|  |  |  | if ((j * groupFlag) <= list.size() ) { | 
|---|
|  |  |  | splitList.add(list.subList(j * groupFlag - groupFlag, j * groupFlag)); | 
|---|
|  |  |  | } else if ((j * groupFlag) > list.size()) { | 
|---|
|  |  |  | splitList.add(list.subList(j * groupFlag - groupFlag, list.size())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else if(groupFlag * splitNum > list.size()){ | 
|---|
|  |  |  | for (int j = 1; j < splitNum; j++) { | 
|---|
|  |  |  | if ((j * groupFlag) <= list.size() ) { | 
|---|
|  |  |  | splitList.add(list.subList(j * groupFlag - groupFlag, j * groupFlag)); | 
|---|
|  |  |  | } else if ((j * groupFlag) > list.size()) { | 
|---|
|  |  |  | splitList.add(list.subList(j * groupFlag - groupFlag, list.size())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | for (int j = 1; j <= splitNum; j++) { | 
|---|
|  |  |  | if ((j * groupFlag) <= list.size() ) { | 
|---|
|  |  |  | splitList.add(list.subList(j * groupFlag - groupFlag, j * groupFlag)); | 
|---|
|  |  |  | } else if ((j * groupFlag) > list.size()) { | 
|---|
|  |  |  | splitList.add(list.subList(j * groupFlag - groupFlag, list.size())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return splitList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //对于奖品排序 1:升序进行排,2是倒序就是o2-o1 | 
|---|
|  |  |  | public static HashMap<Long, ActivitySignAwardSetVo> sortHashMap(HashMap<Long, ActivitySignAwardSetVo> map,int type) { | 
|---|
|  |  |  | // 首先拿到 map 的键值对集合 | 
|---|
|  |  |  | Set<Map.Entry<Long, ActivitySignAwardSetVo>> entrySet = map.entrySet(); | 
|---|
|  |  |  | // 将 set 集合转为 List 集合,为什么,为了使用工具类的排序方法 | 
|---|
|  |  |  | List<Map.Entry<Long, ActivitySignAwardSetVo>> list = new ArrayList<Map.Entry<Long, ActivitySignAwardSetVo>>(entrySet); | 
|---|
|  |  |  | // 使用 Collections 集合工具类对 list 进行排序,排序规则使用匿名内部类来实现 | 
|---|
|  |  |  | Collections.sort(list, new Comparator<Map.Entry<Long, ActivitySignAwardSetVo>>() { | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public int compare(Map.Entry<Long, ActivitySignAwardSetVo> o1, Map.Entry<Long, ActivitySignAwardSetVo> o2) { | 
|---|
|  |  |  | if(type == 2){ | 
|---|
|  |  |  | //按照要求根据 升序进行排,如果是倒序就是o2-o1 | 
|---|
|  |  |  | return o2.getValue().getAwardInventoryCnt() - o1.getValue().getAwardInventoryCnt(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return o1.getValue().getAwardInventoryCnt() - o2.getValue().getAwardInventoryCnt(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | //创建一个新的有序的 HashMap 子类的集合 | 
|---|
|  |  |  | LinkedHashMap<Long, ActivitySignAwardSetVo> linkedHashMap = new LinkedHashMap<Long, ActivitySignAwardSetVo>(); | 
|---|
|  |  |  | //将 List 中的数据存储在 LinkedHashMap 中 | 
|---|
|  |  |  | for (Map.Entry<Long, ActivitySignAwardSetVo> entry : list) { | 
|---|
|  |  |  | linkedHashMap.put(entry.getKey(), entry.getValue()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //返回结果 | 
|---|
|  |  |  | return linkedHashMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private BusParameterSettingsDao busParameterSettingsDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取当月的 天数 | 
|---|
|  |  |  | * */ | 
|---|
|  |  |  | public static int getCurrentMonthDay(Date date) { | 
|---|
|  |  |  | Date beginOfMonth = DateUtil.beginOfMonth(date); | 
|---|
|  |  |  | Date endOfMonth = DateUtil.endOfMonth(date); | 
|---|
|  |  |  | long betweenDay = DateUtil.between(beginOfMonth, endOfMonth, DateUnit.DAY); | 
|---|
|  |  |  | return Integer.parseInt(String.valueOf(betweenDay))+1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | *  java 获取 获取某年某月 所有日期(yyyy-mm-dd格式字符串) | 
|---|
|  |  |  | * @param year | 
|---|
|  |  |  | * @param month | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static List<String> getMonthFullDay(int year , int month){ | 
|---|
|  |  |  | SimpleDateFormat dateFormatYYYYMMDD = new SimpleDateFormat("yyyy-MM-dd"); | 
|---|
|  |  |  | List<String> fullDayList = new ArrayList<>(32); | 
|---|
|  |  |  | // 获得当前日期对象 | 
|---|
|  |  |  | Calendar cal = Calendar.getInstance(); | 
|---|
|  |  |  | cal.clear();// 清除信息 | 
|---|
|  |  |  | cal.set(Calendar.YEAR, year); | 
|---|
|  |  |  | // 1月从0开始 | 
|---|
|  |  |  | cal.set(Calendar.MONTH, month-1 ); | 
|---|
|  |  |  | // 当月1号 | 
|---|
|  |  |  | cal.set(Calendar.DAY_OF_MONTH,1); | 
|---|
|  |  |  | int count = cal.getActualMaximum(Calendar.DAY_OF_MONTH); | 
|---|
|  |  |  | for (int j = 1; j <= count ; j++) { | 
|---|
|  |  |  | fullDayList.add(dateFormatYYYYMMDD.format(cal.getTime())); | 
|---|
|  |  |  | cal.add(Calendar.DAY_OF_MONTH,1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return fullDayList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //    @Test | 
|---|
|  |  |  | //    public void getinterger() { | 
|---|
|  |  |  | //      Long userId = 30L; | 
|---|
|  |  |  | //      Long companyId = 36L; | 
|---|
|  |  |  | //      int size = activitySignReceiveRecordDao.getSignAwardReceiveCount(userId,companyId); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | //    /** | 
|---|
|  |  |  | //     * 获取累计签到天数 | 
|---|
|  |  |  | //     * @param actId | 
|---|
|  |  |  | //     * @param userId | 
|---|
|  |  |  | //     * @param date | 
|---|
|  |  |  | //     * @return | 
|---|
|  |  |  | //     */ | 
|---|
|  |  |  | //    public int getCumulativeDay(long actId, long userId,Date date, int i) { | 
|---|
|  |  |  | //        ActivitySignRecord activitySignRecordOld = activitySignRecordDao.selectOneByActIdAndUserIdLikesignTime(actId,userId,date); | 
|---|
|  |  |  | //        if(ObjectUtil.isEmpty(activitySignRecordOld)) { | 
|---|
|  |  |  | //            return i; | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        i++; | 
|---|
|  |  |  | //        DateTime offsetDay = DateUtil.offsetDay(date, -i); | 
|---|
|  |  |  | //        return getCumulativeDay(actId,userId,offsetDay,i); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | @Test | 
|---|
|  |  |  | public void clickSign() { | 
|---|
|  |  |  | long awardId = 10; | 
|---|
|  |  |  | Long userId = 30L; | 
|---|
|  |  |  | Long companyId = 36L; | 
|---|
|  |  |  | SeeAwardTextDto seeAwardTextDto = new SeeAwardTextDto(); | 
|---|
|  |  |  | seeAwardTextDto.setAwardId(awardId); | 
|---|
|  |  |  | seeAwardTextDto.setCompanyId(companyId); | 
|---|
|  |  |  | seeAwardTextDto.setUserId(userId); | 
|---|
|  |  |  | logisticsInsure(seeAwardTextDto); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | public AjaxResult logisticsInsure(@RequestBody @Validated SeeAwardTextDto seeAwardTextDto) { | 
|---|
|  |  |  | SeeAwardTextVo seeAwardTextVO = activitySignReceiveRecordDao.selectSeeAwardTextVOById(seeAwardTextDto); | 
|---|
|  |  |  | if(ObjectUtil.isEmpty(seeAwardTextVO)){ | 
|---|
|  |  |  | return AjaxResult.buildFailInstance("奖品信息无法查看"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | long receiveId = seeAwardTextVO.getId(); | 
|---|
|  |  |  | //获取核销记录的ID | 
|---|
|  |  |  | ActivitySignWriteoff activitySignWriteoff = activitySignWriteoffDao.selectActivitySignWriteoffByUserIDAndReceiveId(seeAwardTextDto.getUserId(),receiveId); | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(activitySignWriteoff)){ | 
|---|
|  |  |  | Integer logisticsId = activitySignWriteoff.getLogisticsId(); | 
|---|
|  |  |  | ShopDeliveryInfo shopDeliveryInfo = shopDeliveryInfoDao.selectById(logisticsId); | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(shopDeliveryInfo)){ | 
|---|
|  |  |  | //查看物流信息 | 
|---|
|  |  |  | wxShopLogisticsQueryService.selectLogisticsInfo(shopDeliveryInfo); | 
|---|
|  |  |  | List<ShopLogisticsInfo> shopLogisticsInfos = shopLogisticsInfoDao.selectByDelieryId(shopDeliveryInfo.getId()); | 
|---|
|  |  |  | seeAwardTextVO.setShopLogisticsInfos(shopLogisticsInfos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | AjaxResult result=AjaxResult.buildSuccessInstance(seeAwardTextVO); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取累计签到天数 | 
|---|
|  |  |  | * @param actId | 
|---|
|  |  |  | * @param userId | 
|---|
|  |  |  | * @param date | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public int getCumulativeDay(long actId, long userId,Date date, int i) { | 
|---|
|  |  |  | ActivitySignRecord activitySignRecordOld = activitySignRecordDao.selectOneByActIdAndUserIdLikesignTime(actId,userId,date); | 
|---|
|  |  |  | if(ObjectUtil.isEmpty(activitySignRecordOld)) { | 
|---|
|  |  |  | return i; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | i++; | 
|---|
|  |  |  | DateTime offsetDay = DateUtil.offsetDay(date, -i); | 
|---|
|  |  |  | return getCumulativeDay(actId,userId,offsetDay,i); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | public void InitByCompanyId() { | 
|---|
|  |  |  | //对应的公司ID | 
|---|
|  |  |  | long companyId = 35L; | 
|---|
|  |  |  | initBusParameterSetting(companyId); | 
|---|
|  |  |  | initBusParameterFenxiaoSetting(companyId); | 
|---|
|  |  |  | //      long companyId = 36L; | 
|---|
|  |  |  | //      initBusParameterSetting(companyId); | 
|---|
|  |  |  | //      //initBusParameterFenxiaoSetting(companyId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 初始化默认积分规则设置 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void initBusParameterSetting(long companyId) { | 
|---|
|  |  |  | List<BusParameterSettings> ruleSettings=new ArrayList<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.VALID_PERIOD_POINTS, companyId)); | 
|---|
|  |  |  | ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.CREDIT_POINTS_CASH, companyId)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.CASH_CONSUMPTION, companyId)); | 
|---|
|  |  |  | ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.PRINCIPAL_BALANCE_CONSUMPTION, companyId)); | 
|---|
|  |  |  | ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.BONUS_BALANCE_CONSUMPTION, companyId)); | 
|---|
|  |  |  | ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.PRINCIPAL_CONSUMPTION, companyId)); | 
|---|
|  |  |  | ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.GIVE_CONSUMPTION, companyId)); | 
|---|
|  |  |  | ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.REFERRALS_CONSUMPTION, companyId)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.CASH_CONSUMPTION_SHOP, companyId)); | 
|---|
|  |  |  | ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.RESERVATION_SERVICE_SHOP, companyId)); | 
|---|
|  |  |  | ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.EVALUATUIN_ORDER_SHOP, companyId)); | 
|---|
|  |  |  | ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.SIGN_SHOP, companyId)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | busParameterSettingsDao.batchInsert(ruleSettings); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 初始化默认分销规则设置 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void initBusParameterFenxiaoSetting(long companyId) { | 
|---|
|  |  |  | List<BusParameterSettings> ruleSettings=new ArrayList<>(); | 
|---|
|  |  |  | ruleSettings.add(addScoreRuleSetting(FenxiaoSettingConstant.FX_SWITCH, companyId)); | 
|---|
|  |  |  | ruleSettings.add(addScoreRuleSetting(FenxiaoSettingConstant.FX_MODEL, companyId)); | 
|---|
|  |  |  | ruleSettings.add(addScoreRuleSetting(FenxiaoSettingConstant.FX_APPLY_WAY, companyId)); | 
|---|
|  |  |  | ruleSettings.add(addScoreRuleSetting(FenxiaoSettingConstant.FX_AUDIT_METHOD, companyId)); | 
|---|
|  |  |  | ruleSettings.add(addScoreRuleSetting(FenxiaoSettingConstant.FX_APPLY_CONDITION, companyId)); | 
|---|
|  |  |  | ruleSettings.add(addScoreRuleSetting(FenxiaoSettingConstant.FX_TG_PLAN, companyId)); | 
|---|
|  |  |  | ruleSettings.add(addScoreRuleSetting(FenxiaoSettingConstant.FX_TG_POSTER, companyId)); | 
|---|
|  |  |  | ruleSettings.add(addScoreRuleSetting(FenxiaoSettingConstant.FX_ZGFY, companyId)); | 
|---|
|  |  |  | busParameterSettingsDao.batchInsert(ruleSettings); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private BusParameterSettings addScoreRuleSetting(String code,long companyId) { | 
|---|
|  |  |  | BusParameterSettings busParameterSetting = new BusParameterSettings(); | 
|---|
|  |  |  | busParameterSetting.setParamCode(code); | 
|---|
|  |  |  | busParameterSetting.setCompanyId(companyId); | 
|---|
|  |  |  | return busParameterSetting; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //    /** | 
|---|
|  |  |  | //     * 初始化默认积分规则设置 | 
|---|
|  |  |  | //     */ | 
|---|
|  |  |  | //    public void initBusParameterSetting(long companyId) { | 
|---|
|  |  |  | //        List<BusParameterSettings> ruleSettings=new ArrayList<>(); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.VALID_PERIOD_POINTS, companyId)); | 
|---|
|  |  |  | //        ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.CREDIT_POINTS_CASH, companyId)); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.CASH_CONSUMPTION, companyId)); | 
|---|
|  |  |  | //        ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.PRINCIPAL_BALANCE_CONSUMPTION, companyId)); | 
|---|
|  |  |  | //        ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.BONUS_BALANCE_CONSUMPTION, companyId)); | 
|---|
|  |  |  | //        ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.PRINCIPAL_CONSUMPTION, companyId)); | 
|---|
|  |  |  | //        ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.GIVE_CONSUMPTION, companyId)); | 
|---|
|  |  |  | //        ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.REFERRALS_CONSUMPTION, companyId)); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.CASH_CONSUMPTION_SHOP, companyId)); | 
|---|
|  |  |  | //        ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.RESERVATION_SERVICE_SHOP, companyId)); | 
|---|
|  |  |  | //        ruleSettings.add(addScoreRuleSetting(ScoreSettingConstant.EVALUATUIN_ORDER_SHOP, companyId)); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        busParameterSettingsDao.batchInsert(ruleSettings); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //    /** | 
|---|
|  |  |  | //     * 初始化默认分销规则设置 | 
|---|
|  |  |  | //     */ | 
|---|
|  |  |  | //    public void initBusParameterFenxiaoSetting(long companyId) { | 
|---|
|  |  |  | //        List<BusParameterSettings> ruleSettings=new ArrayList<>(); | 
|---|
|  |  |  | //        ruleSettings.add(addScoreRuleSetting(FenxiaoSettingConstant.FX_SWITCH, companyId)); | 
|---|
|  |  |  | //        ruleSettings.add(addScoreRuleSetting(FenxiaoSettingConstant.FX_MODEL, companyId)); | 
|---|
|  |  |  | //        ruleSettings.add(addScoreRuleSetting(FenxiaoSettingConstant.FX_APPLY_WAY, companyId)); | 
|---|
|  |  |  | //        ruleSettings.add(addScoreRuleSetting(FenxiaoSettingConstant.FX_AUDIT_METHOD, companyId)); | 
|---|
|  |  |  | //        ruleSettings.add(addScoreRuleSetting(FenxiaoSettingConstant.FX_APPLY_CONDITION, companyId)); | 
|---|
|  |  |  | //        ruleSettings.add(addScoreRuleSetting(FenxiaoSettingConstant.FX_TG_PLAN, companyId)); | 
|---|
|  |  |  | //        ruleSettings.add(addScoreRuleSetting(FenxiaoSettingConstant.FX_TG_POSTER, companyId)); | 
|---|
|  |  |  | //        ruleSettings.add(addScoreRuleSetting(FenxiaoSettingConstant.FX_ZGFY, companyId)); | 
|---|
|  |  |  | //        busParameterSettingsDao.batchInsert(ruleSettings); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //    private BusParameterSettings addScoreRuleSetting(String code,long companyId) { | 
|---|
|  |  |  | //        BusParameterSettings busParameterSetting = new BusParameterSettings(); | 
|---|
|  |  |  | //        busParameterSetting.setParamCode(code); | 
|---|
|  |  |  | //        busParameterSetting.setCompanyId(companyId); | 
|---|
|  |  |  | //        return busParameterSetting; | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|