| | |
| | | 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.date.DateTime; |
| | | import cn.hutool.core.date.DateUnit; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.matrix.core.pojo.AjaxResult; |
| | | 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.ActivitySignRecord; |
| | | import com.matrix.system.shopXcx.api.vo.ActivitySignAwardSetVo; |
| | | import com.matrix.system.shopXcx.api.vo.ActivitySignRecordVo; |
| | | import com.matrix.system.shopXcx.api.vo.SignBasicInfoJsonVo; |
| | | import com.matrix.system.shopXcx.api.vo.SignBasicInfoVo; |
| | | import com.matrix.system.shopXcx.bean.ShopActivities; |
| | | import com.matrix.system.shopXcx.dao.ShopActivitiesDao; |
| | | 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 java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @RunWith(SpringRunner.class) |
| | |
| | | public class FenxiaoSoreInitTest { |
| | | |
| | | @Autowired |
| | | private BusParameterSettingsDao busParameterSettingsDao; |
| | | private ShopActivitiesDao shopActivitiesDao; |
| | | |
| | | @Autowired |
| | | private ActivitySignAwardSetDao activitySignAwardSetDao; |
| | | |
| | | @Autowired |
| | | private ActivitySignReceiveRecordDao activitySignReceiveRecordDao; |
| | | |
| | | @Autowired |
| | | private ActivitySignWriteoffDao activitySignWriteoffDao; |
| | | |
| | | @Autowired |
| | | private ActivitySignRecordDao activitySignRecordDao; |
| | | |
| | | public static void main(String[] args) { |
| | | System.out.println(getCurrentMonthDay(DateUtil.date())); |
| | | System.out.println(getMonthFullDay(DateUtil.year(DateUtil.date()),DateUtil.month(DateUtil.date())+1).toString()); |
| | | } |
| | | |
| | | /** |
| | | * 获取当月的 天数 |
| | | * */ |
| | | 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 actId = 74L; |
| | | Long userId = 30L; |
| | | Long companyId = 36L; |
| | | //获取签到活动的信息 |
| | | SignBasicInfoVo signBasicInfoVo = new SignBasicInfoVo(); |
| | | AjaxResult ajaxResult = new AjaxResult(); |
| | | |
| | | ShopActivities shopActivities = shopActivitiesDao.selectOneByCompanyIdAndActTypeAndActStatus(companyId,ShopActivities.ACTIVITIES_TYPE_SIGN,ShopActivities.ACTSTATUS_STATUS_ING); |
| | | |
| | | signBasicInfoVo.setActName(shopActivities.getActName()); |
| | | signBasicInfoVo.setActCode(shopActivities.getActCode()); |
| | | signBasicInfoVo.setId(shopActivities.getId()); |
| | | String actContent = shopActivities.getActContent(); |
| | | SignBasicInfoJsonVo signBasicInfoJsonVo = JSON.parseObject(actContent, SignBasicInfoJsonVo.class); |
| | | signBasicInfoVo.setSignBasicInfoJsonVo(signBasicInfoJsonVo); |
| | | |
| | | List<ActivitySignAwardSetVo> activitySignAwardSetVos = activitySignAwardSetDao |
| | | .selectListByActIDAndCompanyId(actId,companyId,ActivitySignAwardSet.AWARDSTATE_WORK); |
| | | signBasicInfoVo.setActivitySignAwardSetVos(activitySignAwardSetVos); |
| | | |
| | | //今日是否已经参与 |
| | | ActivitySignRecord activitySignRecord = activitySignRecordDao.selectOneByActIdAndUserIdLikesignTime(actId,userId,new Date()); |
| | | if(ObjectUtil.isNotEmpty(activitySignRecord)) { |
| | | signBasicInfoVo.setJoinState(SignBasicInfoVo.JOINSTATE_SIGN); |
| | | }else { |
| | | signBasicInfoVo.setJoinState(SignBasicInfoVo.JOINSTATE_NOTSIGN); |
| | | } |
| | | /** |
| | | * 默认获取当前月份 |
| | | * 获取当前月份的天数 |
| | | */ |
| | | List<ActivitySignRecordVo> activitySignRecordVos = new ArrayList<>(); |
| | | //获取当前月的第一天是星期几 |
| | | DateTime dateTime = DateUtil.beginOfMonth(DateUtil.date()); |
| | | int i = DateUtil.dayOfWeek(dateTime); |
| | | for(int j = 1;j<i;j++){ |
| | | ActivitySignRecordVo activitySignRecordVoNull = new ActivitySignRecordVo(); |
| | | activitySignRecordVos.add(activitySignRecordVoNull); |
| | | } |
| | | List<String> monthFullDays = getMonthFullDay(DateUtil.year(DateUtil.date()), DateUtil.month(DateUtil.date()) + 1); |
| | | for(String monthFullDay : monthFullDays){ |
| | | ActivitySignRecordVo activitySignRecordVo = new ActivitySignRecordVo(); |
| | | activitySignRecordVo.setSignTime(monthFullDay); |
| | | activitySignRecordVo.setActivityId(actId); |
| | | activitySignRecordVo.setCompanyId(companyId); |
| | | //对应日期是否已签到 |
| | | Date date = DateUtil.parse(monthFullDay); |
| | | ActivitySignRecord activitySignRecordDone = activitySignRecordDao.selectOneByActIdAndUserIdLikesignTime(actId,userId,date); |
| | | if(ObjectUtil.isNotEmpty(activitySignRecordDone)){ |
| | | activitySignRecordVo.setState(1); |
| | | }else{ |
| | | activitySignRecordVo.setState(2); |
| | | } |
| | | activitySignRecordVos.add(activitySignRecordVo); |
| | | } |
| | | signBasicInfoVo.setActivitySignRecords(activitySignRecordVos); |
| | | |
| | | //累计签到日期 |
| | | int cumulativeDay = getCumulativeDay(actId, userId, DateUtil.date(), 0); |
| | | signBasicInfoVo.setActAumulativeDay(cumulativeDay); |
| | | System.out.println(signBasicInfoVo); |
| | | } |
| | | /** |
| | | * 获取累计签到天数 |
| | | * @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; |
| | | // } |
| | | |
| | | } |