| | |
| | | package com.yeshi.fanli.service.impl.user.integral;
|
| | |
|
| | | import java.text.ParseException;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.core.task.TaskExecutor;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import org.yeshi.utils.DateUtil;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.integral.IntegralTaskClassMapper;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
|
| | | import com.yeshi.fanli.entity.bus.user.UserRank;
|
| | | import com.yeshi.fanli.entity.integral.IntegralTask;
|
| | | import com.yeshi.fanli.entity.integral.IntegralTaskClass;
|
| | | import com.yeshi.fanli.entity.integral.IntegralTaskClass.UniqueKeyEnum;
|
| | | import com.yeshi.fanli.entity.integral.IntegralTaskRank;
|
| | | import com.yeshi.fanli.entity.integral.IntegralTaskRecord;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
|
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralTaskClassService;
|
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralTaskRankService;
|
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralTaskRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralTaskService;
|
| | | import com.yeshi.fanli.vo.integral.DailySignVO;
|
| | | import com.yeshi.fanli.vo.integral.IntegralTaskClassVO;
|
| | | import com.yeshi.fanli.vo.integral.SignDateVO;
|
| | |
|
| | | @Service
|
| | | public class IntegralTaskClassServiceImpl implements IntegralTaskClassService {
|
| | |
|
| | | @Resource(name = "taskExecutor")
|
| | | private TaskExecutor executor;
|
| | | |
| | | @Resource
|
| | | private IntegralTaskClassMapper integralTaskClassMapper;
|
| | |
|
| | | @Resource
|
| | | private IntegralTaskService integralTaskService;
|
| | |
|
| | | @Resource
|
| | | private IntegralTaskRankService integralTaskRankService;
|
| | |
|
| | | @Resource
|
| | | private IntegralTaskRecordService integralTaskRecordService;
|
| | |
|
| | | @Resource
|
| | | private UserInfoExtraService userInfoExtraService;
|
| | |
|
| | | |
| | | @Override
|
| | | public IntegralTaskClass selectByPrimaryKey(Long id) {
|
| | | return integralTaskClassMapper.selectByPrimaryKey(id);
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public List<IntegralTaskClassVO> getIntegralTaskClassVO(Long uid, long start, int count) {
|
| | | return integralTaskClassMapper.getIntegralTaskClassVO(start, count);
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public Long countTaskClass() {
|
| | | return integralTaskClassMapper.countTaskClass();
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public IntegralTaskClass getByUniqueKey(String uniqueKey) {
|
| | | return integralTaskClassMapper.getByUniqueKey(uniqueKey);
|
| | | }
|
| | | |
| | | /**
|
| | | * 签到
|
| | | * @param uid
|
| | | * @return
|
| | | */
|
| | | @Transactional
|
| | | public Integer finishedDailySign(long uid) throws Exception{
|
| | | IntegralTaskClass taskClass = getByUniqueKey(UniqueKeyEnum.dailySign.name());
|
| | | if (taskClass == null || taskClass.getState() == null || taskClass.getState() != 1)
|
| | | throw new Exception("抛出异常:任务分类不存在");
|
| | |
|
| | | Long cid = taskClass.getId();
|
| | | // 今日已签到完成
|
| | | if (integralTaskRecordService.isToDaySign(uid, cid))
|
| | | return 2;
|
| | |
|
| | | // 任务
|
| | | Integer num = integralTaskRecordService.getNowdaySignNum(uid, cid);
|
| | | String uniqueKey = UniqueKeyEnum.dailySign.name() + num;
|
| | | IntegralTask integralTask = integralTaskService.getByCidAndUniqueKey(cid, uniqueKey);
|
| | | if (integralTask == null)
|
| | | throw new Exception("抛出异常:任务不存在");
|
| | |
|
| | | UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
|
| | | if (userInfoExtra == null)
|
| | | throw new Exception("抛出异常:额外信息不存在");
|
| | |
|
| | | UserRank userRank = userInfoExtra.getUserRank();
|
| | | if (userRank == null)
|
| | | throw new Exception("抛出异常:等级信息不存在");
|
| | |
|
| | | Integer goldCoin = integralTask.getGoldCoin();
|
| | | Integer baseDoubleNum = integralTask.getDoubleNum();
|
| | | if (baseDoubleNum != null && baseDoubleNum > 0)
|
| | | goldCoin = goldCoin * baseDoubleNum;
|
| | | |
| | | // 根据等级计算是否增加或加倍
|
| | | Long taskId = integralTask.getId();
|
| | | IntegralTaskRank traskRank = integralTaskRankService.getByTsakIdAndRankId(taskId, userRank.getId());
|
| | | if (traskRank != null) {
|
| | | Integer addCoin = traskRank.getAddCoin();
|
| | | if (addCoin != null && addCoin > 0)
|
| | | goldCoin += addCoin;
|
| | |
|
| | | Integer doubleNum = traskRank.getDoubleNum();
|
| | | if (doubleNum != null && doubleNum > 0) {
|
| | | goldCoin = goldCoin * doubleNum;
|
| | | }
|
| | | }
|
| | | // 加入记录
|
| | | integralTaskRecordService.finishedTask(uid, cid, taskId, goldCoin);
|
| | | |
| | | return 1;
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public DailySignVO getDailySignList(Long uid, Long rankId) throws ParseException{
|
| | | SimpleDateFormat format = new SimpleDateFormat("MM.dd");
|
| | | List<SignDateVO> listSign = new ArrayList<SignDateVO>();
|
| | | IntegralTaskClass taskClass = integralTaskClassMapper.getByUniqueKey(UniqueKeyEnum.dailySign.name());
|
| | | if (taskClass == null || taskClass.getState() == null || taskClass.getState() != 1)
|
| | | return null;
|
| | | |
| | | DailySignVO dailySignVO = new DailySignVO();
|
| | | |
| | | Long cid = taskClass.getId();
|
| | | List<IntegralTaskRecord> listRecord7Days = integralTaskRecordService.getSign7DaysRecord(uid, cid);
|
| | | if (listRecord7Days != null && listRecord7Days.size() > 0) {
|
| | | for (int i = listRecord7Days.size() - 1; i >= 0; i--) {
|
| | | IntegralTaskRecord taskRecord = listRecord7Days.get(i);
|
| | | SignDateVO signDateVO = new SignDateVO();
|
| | | signDateVO.setLightUp(true);
|
| | | signDateVO.setGoldCoin("+" + taskRecord.getGoldCoin());
|
| | | if(i == 0) {
|
| | | signDateVO.setDate("今日");
|
| | | dailySignVO.setGoldCoin(taskRecord.getGoldCoin());
|
| | | } else {
|
| | | String before = format.format(taskRecord.getCreateTime());
|
| | | if (before.startsWith("0")) |
| | | before = before.substring(1, before.length());
|
| | | signDateVO.setDate(before);
|
| | | }
|
| | | listSign.add(signDateVO);
|
| | | |
| | | if (listSign.size() >= 7) {
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | List<IntegralTaskRecord> listRecord = integralTaskRecordService.getSignDaysRecord(uid, cid);
|
| | | if(listRecord == null) {
|
| | | dailySignVO.setDays(0);
|
| | | } else {
|
| | | dailySignVO.setDays(listRecord.size());
|
| | | }
|
| | | |
| | | if (listSign.size() < 7) {
|
| | | List<IntegralTask> listTask = integralTaskService.listByCid(cid);
|
| | | if (listTask == null || listTask.size() == 0) {
|
| | | return null;
|
| | | }
|
| | | |
| | | Date date = new Date();
|
| | | int j = 1;
|
| | | for (int i = listSign.size(); i < listTask.size(); i ++) {
|
| | | String after = format.format(DateUtil.plusDayDate(j, date));
|
| | | if (after.startsWith("0")) |
| | | after = after.substring(1, after.length());
|
| | | |
| | | IntegralTask task = listTask.get(i);
|
| | | Integer goldCoin = task.getGoldCoin();
|
| | | Integer baseDoubleNum = task.getDoubleNum();
|
| | | if (baseDoubleNum != null && baseDoubleNum > 0)
|
| | | goldCoin = goldCoin * baseDoubleNum;
|
| | | |
| | | IntegralTaskRank traskRank = integralTaskRankService.getByTsakIdAndRankId(task.getId(), rankId);
|
| | | if (traskRank != null) {
|
| | | Integer addCoin = traskRank.getAddCoin();
|
| | | if (addCoin != null && addCoin > 0)
|
| | | goldCoin += addCoin;
|
| | |
|
| | | Integer doubleNum = traskRank.getDoubleNum();
|
| | | if (doubleNum != null && doubleNum > 0) {
|
| | | goldCoin = goldCoin * doubleNum;
|
| | | }
|
| | | }
|
| | | |
| | | SignDateVO signDateVO = new SignDateVO();
|
| | | signDateVO.setDate(after);
|
| | | signDateVO.setGoldCoin("+" + goldCoin);
|
| | | listSign.add(signDateVO);
|
| | | j++;
|
| | | }
|
| | | } |
| | | |
| | | if (listSign.size() > 7) {
|
| | | listSign = listSign.subList(listSign.size() - 7, listSign.size() - 1);
|
| | | }
|
| | | |
| | | dailySignVO.setListDate(listSign);
|
| | | return dailySignVO;
|
| | | }
|
| | | |
| | | |
| | |
|
| | | }
|
| | | package com.yeshi.fanli.service.impl.user.integral; |
| | | |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.core.task.TaskExecutor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.yeshi.utils.DateUtil; |
| | | |
| | | import com.yeshi.fanli.dao.mybatis.integral.IntegralTaskClassMapper; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfoExtra; |
| | | import com.yeshi.fanli.entity.bus.user.UserRank; |
| | | import com.yeshi.fanli.entity.integral.IntegralTask; |
| | | import com.yeshi.fanli.entity.integral.IntegralTaskClass; |
| | | import com.yeshi.fanli.entity.integral.IntegralTaskClass.UniqueKeyEnum; |
| | | import com.yeshi.fanli.entity.integral.IntegralTaskRank; |
| | | import com.yeshi.fanli.entity.integral.IntegralTaskRecord; |
| | | import com.yeshi.fanli.service.inter.user.UserInfoExtraService; |
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralTaskClassService; |
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralTaskRankService; |
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralTaskRecordService; |
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralTaskService; |
| | | import com.yeshi.fanli.vo.integral.DailySignVO; |
| | | import com.yeshi.fanli.vo.integral.IntegralTaskClassVO; |
| | | import com.yeshi.fanli.vo.integral.SignDateVO; |
| | | |
| | | @Service |
| | | public class IntegralTaskClassServiceImpl implements IntegralTaskClassService { |
| | | |
| | | @Resource(name = "taskExecutor") |
| | | private TaskExecutor executor; |
| | | |
| | | @Resource |
| | | private IntegralTaskClassMapper integralTaskClassMapper; |
| | | |
| | | @Resource |
| | | private IntegralTaskService integralTaskService; |
| | | |
| | | @Resource |
| | | private IntegralTaskRankService integralTaskRankService; |
| | | |
| | | @Resource |
| | | private IntegralTaskRecordService integralTaskRecordService; |
| | | |
| | | @Resource |
| | | private UserInfoExtraService userInfoExtraService; |
| | | |
| | | |
| | | @Override |
| | | public IntegralTaskClass selectByPrimaryKey(Long id) { |
| | | return integralTaskClassMapper.selectByPrimaryKey(id); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<IntegralTaskClassVO> getIntegralTaskClassVO(Long uid, long start, int count) { |
| | | return integralTaskClassMapper.getIntegralTaskClassVO(start, count); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Long countTaskClass() { |
| | | return integralTaskClassMapper.countTaskClass(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public IntegralTaskClass getByUniqueKey(String uniqueKey) { |
| | | return integralTaskClassMapper.getByUniqueKey(uniqueKey); |
| | | } |
| | | |
| | | /** |
| | | * 签到 |
| | | * @param uid |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor=Exception.class) |
| | | public Integer finishedDailySign(long uid) throws Exception{ |
| | | IntegralTaskClass taskClass = getByUniqueKey(UniqueKeyEnum.dailySign.name()); |
| | | if (taskClass == null || taskClass.getState() == null || taskClass.getState() != 1) |
| | | throw new Exception("抛出异常:任务分类不存在"); |
| | | |
| | | Long cid = taskClass.getId(); |
| | | // 今日已签到完成 |
| | | if (integralTaskRecordService.isToDaySign(uid, cid)) |
| | | return 2; |
| | | |
| | | // 任务 |
| | | Integer num = integralTaskRecordService.getNowdaySignNum(uid, cid); |
| | | String uniqueKey = UniqueKeyEnum.dailySign.name() + num; |
| | | IntegralTask integralTask = integralTaskService.getByCidAndUniqueKey(cid, uniqueKey); |
| | | if (integralTask == null) |
| | | throw new Exception("抛出异常:任务不存在"); |
| | | |
| | | UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid); |
| | | if (userInfoExtra == null) |
| | | throw new Exception("抛出异常:额外信息不存在"); |
| | | |
| | | UserRank userRank = userInfoExtra.getUserRank(); |
| | | if (userRank == null) |
| | | throw new Exception("抛出异常:等级信息不存在"); |
| | | |
| | | Integer goldCoin = integralTask.getGoldCoin(); |
| | | Integer baseDoubleNum = integralTask.getDoubleNum(); |
| | | if (baseDoubleNum != null && baseDoubleNum > 0) |
| | | goldCoin = goldCoin * baseDoubleNum; |
| | | |
| | | // 根据等级计算是否增加或加倍 |
| | | Long taskId = integralTask.getId(); |
| | | IntegralTaskRank traskRank = integralTaskRankService.getByTsakIdAndRankId(taskId, userRank.getId()); |
| | | if (traskRank != null) { |
| | | Integer addCoin = traskRank.getAddCoin(); |
| | | if (addCoin != null && addCoin > 0) |
| | | goldCoin += addCoin; |
| | | |
| | | Integer doubleNum = traskRank.getDoubleNum(); |
| | | if (doubleNum != null && doubleNum > 0) { |
| | | goldCoin = goldCoin * doubleNum; |
| | | } |
| | | } |
| | | // 加入记录 |
| | | integralTaskRecordService.finishedTask(uid, cid, taskId, goldCoin); |
| | | |
| | | return 1; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public DailySignVO getDailySignList(Long uid, Long rankId) throws ParseException{ |
| | | SimpleDateFormat format = new SimpleDateFormat("MM.dd"); |
| | | List<SignDateVO> listSign = new ArrayList<SignDateVO>(); |
| | | IntegralTaskClass taskClass = integralTaskClassMapper.getByUniqueKey(UniqueKeyEnum.dailySign.name()); |
| | | if (taskClass == null || taskClass.getState() == null || taskClass.getState() != 1) |
| | | return null; |
| | | |
| | | DailySignVO dailySignVO = new DailySignVO(); |
| | | |
| | | Long cid = taskClass.getId(); |
| | | List<IntegralTaskRecord> listRecord7Days = integralTaskRecordService.getSign7DaysRecord(uid, cid); |
| | | if (listRecord7Days != null && listRecord7Days.size() > 0) { |
| | | for (int i = listRecord7Days.size() - 1; i >= 0; i--) { |
| | | IntegralTaskRecord taskRecord = listRecord7Days.get(i); |
| | | SignDateVO signDateVO = new SignDateVO(); |
| | | signDateVO.setLightUp(true); |
| | | signDateVO.setGoldCoin("+" + taskRecord.getGoldCoin()); |
| | | if(i == 0) { |
| | | signDateVO.setDate("今日"); |
| | | dailySignVO.setGoldCoin(taskRecord.getGoldCoin()); |
| | | } else { |
| | | String before = format.format(taskRecord.getCreateTime()); |
| | | if (before.startsWith("0")) |
| | | before = before.substring(1, before.length()); |
| | | signDateVO.setDate(before); |
| | | } |
| | | listSign.add(signDateVO); |
| | | |
| | | if (listSign.size() >= 7) { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | List<IntegralTaskRecord> listRecord = integralTaskRecordService.getSignDaysRecord(uid, cid); |
| | | if(listRecord == null) { |
| | | dailySignVO.setDays(0); |
| | | } else { |
| | | dailySignVO.setDays(listRecord.size()); |
| | | } |
| | | |
| | | if (listSign.size() < 7) { |
| | | List<IntegralTask> listTask = integralTaskService.listByCid(cid); |
| | | if (listTask == null || listTask.size() == 0) { |
| | | return null; |
| | | } |
| | | |
| | | Date date = new Date(); |
| | | int j = 1; |
| | | for (int i = listSign.size(); i < listTask.size(); i ++) { |
| | | String after = format.format(DateUtil.plusDayDate(j, date)); |
| | | if (after.startsWith("0")) |
| | | after = after.substring(1, after.length()); |
| | | |
| | | IntegralTask task = listTask.get(i); |
| | | Integer goldCoin = task.getGoldCoin(); |
| | | Integer baseDoubleNum = task.getDoubleNum(); |
| | | if (baseDoubleNum != null && baseDoubleNum > 0) |
| | | goldCoin = goldCoin * baseDoubleNum; |
| | | |
| | | IntegralTaskRank traskRank = integralTaskRankService.getByTsakIdAndRankId(task.getId(), rankId); |
| | | if (traskRank != null) { |
| | | Integer addCoin = traskRank.getAddCoin(); |
| | | if (addCoin != null && addCoin > 0) |
| | | goldCoin += addCoin; |
| | | |
| | | Integer doubleNum = traskRank.getDoubleNum(); |
| | | if (doubleNum != null && doubleNum > 0) { |
| | | goldCoin = goldCoin * doubleNum; |
| | | } |
| | | } |
| | | |
| | | SignDateVO signDateVO = new SignDateVO(); |
| | | signDateVO.setDate(after); |
| | | signDateVO.setGoldCoin("+" + goldCoin); |
| | | listSign.add(signDateVO); |
| | | j++; |
| | | } |
| | | } |
| | | |
| | | if (listSign.size() > 7) { |
| | | listSign = listSign.subList(listSign.size() - 7, listSign.size() - 1); |
| | | } |
| | | |
| | | dailySignVO.setListDate(listSign); |
| | | return dailySignVO; |
| | | } |
| | | |
| | | |
| | | |
| | | } |