|
@@ -0,0 +1,62 @@
|
|
|
+package com.flyer.foster.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.flyer.exception.BusinessException;
|
|
|
+import com.flyer.foster.dto.app.AppScoreAddDTO;
|
|
|
+import com.flyer.foster.dto.app.AppScoreRespDTO;
|
|
|
+import com.flyer.foster.entity.AppUser;
|
|
|
+import com.flyer.foster.entity.Score;
|
|
|
+import com.flyer.foster.mapper.IScoreMapper;
|
|
|
+import com.flyer.foster.pojo.StpAppUtil;
|
|
|
+import com.flyer.foster.service.IAppUserService;
|
|
|
+import com.flyer.foster.service.IScoreService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+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;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 小程序用户积分 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author flyer
|
|
|
+ * @since 2024-05-18
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ScoreServiceImpl extends ServiceImpl<IScoreMapper, Score> implements IScoreService {
|
|
|
+ @Autowired
|
|
|
+ private IAppUserService iAppUserService;
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public boolean addScore(AppScoreAddDTO addDTO) {
|
|
|
+ int tenantId = StpAppUtil.getLoginIdAsInt();
|
|
|
+ // 根据用户id查询积分数据是否存在
|
|
|
+ Score entity = new Score();
|
|
|
+ AppScoreRespDTO score = baseMapper.isExist(addDTO);
|
|
|
+ if (score == null) {
|
|
|
+ entity.setAction(addDTO.getAction());
|
|
|
+ entity.setAppUserId(addDTO.getAppUserId());
|
|
|
+ entity.setScore(addDTO.getScore());
|
|
|
+ entity.setTenantId(tenantId);
|
|
|
+ entity.setCreatedBy("kelei");
|
|
|
+ entity.setCreatedTime(LocalDateTime.now());
|
|
|
+ entity.setUpdatedBy("kelei");
|
|
|
+ entity.setUpdatedTime(LocalDateTime.now());
|
|
|
+ // 插入用户积分
|
|
|
+ this.save(entity);
|
|
|
+ // 修改用户总积分
|
|
|
+ AppUser appUser = iAppUserService.getById(entity.getAppUserId());
|
|
|
+ // 原始积分
|
|
|
+ Integer totalScore = appUser.getTotalScore();
|
|
|
+ totalScore += addDTO.getScore();
|
|
|
+ appUser.setTotalScore(totalScore);
|
|
|
+ iAppUserService.saveOrUpdate(appUser);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|