|
|
@@ -5,20 +5,21 @@ import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.cyksj.common.constant.PointsRecordConst;
|
|
|
import com.cyksj.common.constant.TaskTypeEnum;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.mapper.manage.distribute.UserDistributeSharedMapper;
|
|
|
+import com.cyksj.mapper.market.sign.UserPointsRecordMapper;
|
|
|
+import com.cyksj.mapper.market.task.TaskFollowPlatVerifyMapper;
|
|
|
import com.cyksj.mapper.market.task.TaskMapper;
|
|
|
import com.cyksj.mapper.market.task.TaskTypeMapper;
|
|
|
import com.cyksj.mapper.market.task.TaskUserCompleteRecordMapper;
|
|
|
-import com.cyksj.model.entity.Task;
|
|
|
-import com.cyksj.model.entity.TaskType;
|
|
|
-import com.cyksj.model.entity.TaskUserCompleteRecord;
|
|
|
-import com.cyksj.model.entity.UserDistributeShared;
|
|
|
+import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.service.market.task.TaskService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -33,7 +34,7 @@ import java.util.List;
|
|
|
@Slf4j
|
|
|
public class TaskServiceImpl implements TaskService {
|
|
|
|
|
|
- public static List<String> times = List.of("添加企业微信", "绑定手机号");
|
|
|
+ public static List<String> times = List.of("添加企业微信", "绑定手机号", "关注引导");
|
|
|
|
|
|
private final TaskTypeMapper taskTypeMapper;
|
|
|
|
|
|
@@ -43,6 +44,10 @@ public class TaskServiceImpl implements TaskService {
|
|
|
|
|
|
private final UserDistributeSharedMapper userDistributeSharedMapper;
|
|
|
|
|
|
+ private final TaskFollowPlatVerifyMapper taskFollowPlatVerifyMapper;
|
|
|
+
|
|
|
+ private final UserPointsRecordMapper userPointsRecordMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public void saveTask(Task task) {
|
|
|
checkTask(task);
|
|
|
@@ -90,6 +95,70 @@ public class TaskServiceImpl implements TaskService {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Throwable.class)
|
|
|
+ public void batchVerifyFollow(List<TaskFollowPlatVerify> taskFollowPlatVerifyList) {
|
|
|
+ TaskFollowPlatVerify.Status success = TaskFollowPlatVerify.Status.success;
|
|
|
+ TaskFollowPlatVerify.Status fail = TaskFollowPlatVerify.Status.fail;
|
|
|
+ TaskFollowPlatVerify.Status verifying = TaskFollowPlatVerify.Status.verifying;
|
|
|
+ taskFollowPlatVerifyList.forEach(taskVerify -> {
|
|
|
+ if (taskVerify.getId() != null) {
|
|
|
+ TaskFollowPlatVerify dbPlatVerify = taskFollowPlatVerifyMapper.selectById(taskVerify.getId());
|
|
|
+ TaskFollowPlatVerify.Status verifyStatus = taskVerify.getStatus();
|
|
|
+ TaskFollowPlatVerify.Status dbStatus = dbPlatVerify.getStatus();
|
|
|
+ Boolean isFlag = false;
|
|
|
+ if (dbPlatVerify != null && dbStatus != success) {
|
|
|
+ if (dbStatus == fail && verifyStatus == success) {
|
|
|
+ dbPlatVerify.setStatus(success);
|
|
|
+ dbPlatVerify.setErrorReason("");
|
|
|
+ isFlag = true;
|
|
|
+ } else if (dbStatus == verifying) {
|
|
|
+ if (verifyStatus == fail) {
|
|
|
+ dbPlatVerify.setStatus(fail);
|
|
|
+ dbPlatVerify.setErrorReason(taskVerify.getErrorReason());
|
|
|
+ isFlag = true;
|
|
|
+ } else if (verifyStatus == success) {
|
|
|
+ dbPlatVerify.setStatus(success);
|
|
|
+ isFlag = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (isFlag) {
|
|
|
+ dbPlatVerify.setVerifyTime(DateTime.now());
|
|
|
+ taskFollowPlatVerifyMapper.updateById(dbPlatVerify);
|
|
|
+ TaskUserCompleteRecord record = taskUserCompleteRecordMapper.selectOne(Wrappers.lambdaQuery(TaskUserCompleteRecord.class)
|
|
|
+ .eq(TaskUserCompleteRecord::getUserId, taskVerify.getUserId())
|
|
|
+ .eq(TaskUserCompleteRecord::getTaskId, taskVerify.getTaskId())
|
|
|
+ .last("limit 1"));
|
|
|
+ if (record == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (verifyStatus == success) {
|
|
|
+ record.setStatus(TaskUserCompleteRecord.Status.received);
|
|
|
+ this.pointsRecord(record.getUserId(), record.getPoints(), PointsRecordConst.TASK, false);
|
|
|
+ } else if (verifyStatus == fail) {
|
|
|
+ record.setStatus(TaskUserCompleteRecord.Status.fail);
|
|
|
+ }
|
|
|
+ taskUserCompleteRecordMapper.updateById(record);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void pointsRecord(Long userId, Integer points, String remark, Boolean isLottery) {
|
|
|
+ UserPointsRecord userPointsRecord = new UserPointsRecord();
|
|
|
+ userPointsRecord.setUserId(userId);
|
|
|
+ userPointsRecord.setPoints(points);
|
|
|
+ userPointsRecord.setRemark(remark);
|
|
|
+ userPointsRecordMapper.insert(userPointsRecord);
|
|
|
+
|
|
|
+ if (!isLottery) {
|
|
|
+ //发放爱心
|
|
|
+ userPointsRecordMapper.updateUserPoints(userId, points);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void checkTask(Task task) {
|
|
|
Long typeId = task.getTypeId();
|
|
|
TaskType taskType = taskTypeMapper.selectById(typeId);
|
|
|
@@ -109,9 +178,11 @@ public class TaskServiceImpl implements TaskService {
|
|
|
if (task.getId() != null) {
|
|
|
wrapper.ne(Task::getId, task.getId());
|
|
|
}
|
|
|
- Task selectOne = taskMapper.selectOne(wrapper);
|
|
|
- if (selectOne != null) {
|
|
|
- throw BusinessRuntimeException.getInstance("已新增对应的任务");
|
|
|
+ if (!"关注引导".equals(taskType.getName())) {
|
|
|
+ Task selectOne = taskMapper.selectOne(wrapper);
|
|
|
+ if (selectOne != null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("已新增对应的任务");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -130,7 +201,7 @@ public class TaskServiceImpl implements TaskService {
|
|
|
wrapper.between(TaskUserCompleteRecord::getCreatedTime, beginTime, endTime);
|
|
|
TaskUserCompleteRecord record = taskUserCompleteRecordMapper.selectOne(wrapper);
|
|
|
if (record == null) {
|
|
|
- saveCompleteTask(task.getId(), userId,task.getPoints());
|
|
|
+ saveCompleteTask(task.getId(), userId, task.getPoints());
|
|
|
}
|
|
|
} else if (TaskTypeEnum.share.getDesc().equals(type.getName())) {
|
|
|
//邀请人数是否达标
|