|
|
@@ -0,0 +1,131 @@
|
|
|
+package io.renren.modules.qmjz.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import io.renren.common.exception.RRException;
|
|
|
+import io.renren.common.utils.PageUtils;
|
|
|
+import io.renren.common.utils.Query;
|
|
|
+import io.renren.modules.qmjz.entity.ScoreStu;
|
|
|
+import io.renren.modules.qmjz.entity.TaskManage;
|
|
|
+import io.renren.modules.qmjz.entity.UserSignEntity;
|
|
|
+import io.renren.modules.qmjz.enums.ScoreType;
|
|
|
+import io.renren.modules.qmjz.enums.TaskType;
|
|
|
+import io.renren.modules.qmjz.mapper.ScoreStuMapper;
|
|
|
+import io.renren.modules.qmjz.mapper.TaskManageMapper;
|
|
|
+import io.renren.modules.qmjz.mapper.UserSignMapper;
|
|
|
+import io.renren.modules.qmjz.service.ScoreStuService;
|
|
|
+import io.renren.modules.qmjz.service.UserSignService;
|
|
|
+import io.renren.modules.qmjz.utils.DateForStr;
|
|
|
+import io.renren.modules.sys.entity.SysUserEntity;
|
|
|
+import io.renren.utils.R;
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+@Service("userSignService")
|
|
|
+public class UserSignServiceImpl extends ServiceImpl<UserSignMapper, UserSignEntity> implements UserSignService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ScoreStuMapper scoreStuMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TaskManageMapper taskManageMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ScoreStuService scoreStuService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageUtils queryPage(Map<String, Object> params) {
|
|
|
+ IPage<UserSignEntity> page = this.page(
|
|
|
+ new Query<UserSignEntity>().getPage(params),
|
|
|
+ new QueryWrapper<UserSignEntity>()
|
|
|
+ );
|
|
|
+
|
|
|
+ return new PageUtils(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public R dailySign(Map<String, Object> params) {
|
|
|
+ Long stuId = Long.parseLong(params.get("stuId").toString());
|
|
|
+ if (ObjectUtil.isEmpty(stuId)){
|
|
|
+ throw new RRException("用户不存在");
|
|
|
+ }
|
|
|
+ //判断当天是否已签到
|
|
|
+ if (curryDayIsSign(stuId)){
|
|
|
+ throw new RRException("今日已签到");
|
|
|
+ }
|
|
|
+ //插入签到表
|
|
|
+ UserSignEntity userSignEntity = new UserSignEntity();
|
|
|
+ userSignEntity.setStuId(stuId);
|
|
|
+ userSignEntity.setSignDate(DateForStr.getInfoDateStr(new Date()));
|
|
|
+ userSignEntity.setSignTime(LocalDateTime.now());
|
|
|
+ baseMapper.insert(userSignEntity);
|
|
|
+ TaskManage taskManage = taskManageMapper.selectOne(new LambdaQueryWrapper<TaskManage>()
|
|
|
+ .eq(TaskManage::getId, TaskType.DAILY_SIGN.getCode())
|
|
|
+ .eq(TaskManage::getTaskStatus,"1")
|
|
|
+ .last("limit 1")
|
|
|
+ );
|
|
|
+ if (ObjectUtil.isEmpty(taskManage)) {
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+ ScoreStu scoreStu=this.scoreStuService.queryDayTask(DateForStr.getInfoDateStr(),stuId,TaskType.DAILY_SIGN.getCode());
|
|
|
+ // 当日没有签到积分
|
|
|
+ if (ObjectUtil.isNull(scoreStu)) {
|
|
|
+ //插入一条积分记录
|
|
|
+ ScoreStu add = new ScoreStu();
|
|
|
+ add.setDay(DateForStr.getInfoDateStr(new Date()));
|
|
|
+ add.setStuId(stuId);
|
|
|
+ add.setScoreType(ScoreType.TASK_SCORE.getCode());
|
|
|
+ add.setTaskId(taskManage.getId());
|
|
|
+ add.setBusinessId(taskManage.getId());
|
|
|
+ add.setScoreEvent(TaskType.DAILY_SIGN.getInfo());
|
|
|
+ add.setScoreValue(taskManage.getTaskScore());
|
|
|
+ add.setCreateTime(new Date());
|
|
|
+ add.setSurplusScore(taskManage.getTaskScore() + this.scoreStuService.getTotalScore(stuId));
|
|
|
+ scoreStuMapper.insert(add);
|
|
|
+ }
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean curryDayIsSign(Long stuId) {
|
|
|
+ return baseMapper.selectOne(new QueryWrapper<UserSignEntity>()
|
|
|
+ .eq("stu_id", stuId)
|
|
|
+ .eq("sign_date", DateForStr.getInfoDateStr(new Date()))
|
|
|
+ .last("limit 1")) != null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<String> ApiQueryList(Long stuId) {
|
|
|
+ if (ObjectUtil.isEmpty(stuId)){
|
|
|
+ throw new RRException("用户不存在");
|
|
|
+ }
|
|
|
+ //获取当前年月
|
|
|
+ LocalDate currentDate = LocalDate.now();
|
|
|
+ String year = String.valueOf(currentDate.getYear());
|
|
|
+ String month = String.format("%02d", currentDate.getMonthValue());
|
|
|
+ String yearMonth = year + month;
|
|
|
+ List<UserSignEntity> userSignList = baseMapper.selectList(new LambdaQueryWrapper<UserSignEntity>()
|
|
|
+ .eq(UserSignEntity::getStuId, stuId)
|
|
|
+ .likeRight(UserSignEntity::getSignDate, yearMonth));
|
|
|
+ if (!ObjectUtil.isEmpty(userSignList)){
|
|
|
+ return userSignList.stream().map(UserSignEntity::getSignDate).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|