153 lines
5.3 KiB
Java
153 lines
5.3 KiB
Java
package com.example.caseData.service;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.example.caseData.config.AppConfig;
|
|
import com.example.caseData.dao.*;
|
|
import com.example.caseData.extend.app.Reward.Reward;
|
|
import com.example.caseData.middlewares.LogRequestInterceptor;
|
|
import com.example.caseData.model.*;
|
|
import com.example.caseData.request.RewardPointRequest.rewardPoint;
|
|
import jakarta.annotation.Resource;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
|
|
@Slf4j
|
|
@Service
|
|
public class RewardPointService {
|
|
|
|
@Resource
|
|
private Reward reward;
|
|
|
|
@Resource
|
|
private UserDao userDao;
|
|
|
|
@Resource
|
|
private AppConfig appConfig;
|
|
|
|
@Resource
|
|
private CaseClinicalArticleAuthorDao caseClinicalArticleAuthorDao;
|
|
|
|
@Resource
|
|
private CaseClinicalVideoAuthorDao caseClinicalVideoAuthorDao;
|
|
|
|
@Resource
|
|
private CaseClinicalDoctorDao caseClinicalDoctorDao;
|
|
|
|
@Resource
|
|
private CaseExchangeDao caseExchangeDao;
|
|
|
|
@Resource
|
|
private RecordRewardPointDao recordRewardPointDao;
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(LogRequestInterceptor.class);
|
|
|
|
/**
|
|
* 打赏积分
|
|
*/
|
|
@Transactional
|
|
public boolean RewardPoint(String userId, rewardPoint r){
|
|
// 获取当前登录用户数据
|
|
UserModel user = userDao.selectById(Long.valueOf(userId));
|
|
if (user == null) {
|
|
return false;
|
|
}
|
|
|
|
// 获取对应作者
|
|
List<String> authorList = new ArrayList<>();
|
|
|
|
// 文章
|
|
if (r.getType() == 1){
|
|
// 获取文章作者数据
|
|
LambdaQueryWrapper<CaseClinicalArticleAuthorModel> authorQueryWrapper = new LambdaQueryWrapper<>();
|
|
authorQueryWrapper.eq(CaseClinicalArticleAuthorModel::getArticleId, r.getId());
|
|
List<CaseClinicalArticleAuthorModel> caseClinicalArticleAuthors = caseClinicalArticleAuthorDao.selectList(authorQueryWrapper);
|
|
for (CaseClinicalArticleAuthorModel author : caseClinicalArticleAuthors) {
|
|
// 查询医生
|
|
CaseClinicalDoctorModel caseClinicalDoctor = caseClinicalDoctorDao.selectById(author.getDoctorId());
|
|
if (caseClinicalDoctor == null) {
|
|
authorList.add(appConfig.getPlatformPointAccount());
|
|
}else{
|
|
if (caseClinicalDoctor.getDoctorIden() == null){
|
|
authorList.add(appConfig.getPlatformPointAccount());
|
|
}else{
|
|
authorList.add(caseClinicalDoctor.getDoctorIden());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 视频
|
|
if (r.getType() == 2){
|
|
// 获取文章作者数据
|
|
LambdaQueryWrapper<CaseClinicalVideoAuthorModel> authorQueryWrapper = new LambdaQueryWrapper<>();
|
|
authorQueryWrapper.eq(CaseClinicalVideoAuthorModel::getVideoId, r.getId());
|
|
List<CaseClinicalVideoAuthorModel> caseClinicalVideoAuthors = caseClinicalVideoAuthorDao.selectList(authorQueryWrapper);
|
|
for (CaseClinicalVideoAuthorModel author : caseClinicalVideoAuthors) {
|
|
// 查询医生
|
|
CaseClinicalDoctorModel caseClinicalDoctor = caseClinicalDoctorDao.selectById(author.getDoctorId());
|
|
if (caseClinicalDoctor == null) {
|
|
authorList.add(appConfig.getPlatformPointAccount());
|
|
}else {
|
|
if (caseClinicalDoctor.getDoctorIden() == null || caseClinicalDoctor.getDoctorIden().isEmpty()){
|
|
authorList.add(appConfig.getPlatformPointAccount());
|
|
}else{
|
|
authorList.add(caseClinicalDoctor.getDoctorIden());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 病例交流
|
|
if (r.getType() == 3){
|
|
// 获取病例交流数据
|
|
CaseExchangeModel exchange = caseExchangeDao.selectById(r.getId());
|
|
if (exchange == null) {
|
|
return false;
|
|
}
|
|
|
|
if (exchange.getExchangeStatus() != 1){
|
|
return false;
|
|
}
|
|
|
|
// 获取病例交流用户数据
|
|
UserModel exchangeUser = userDao.selectById(exchange.getUserId());
|
|
if (exchangeUser == null) {
|
|
return false;
|
|
}
|
|
|
|
authorList.add(exchangeUser.getUserIden());
|
|
}
|
|
|
|
if (authorList.isEmpty()) {
|
|
return false;
|
|
}
|
|
|
|
// String authors = String.join(",", authorList);
|
|
// System.out.println(authors);
|
|
// reward.RewardPoint(user.getUserIden(),r.getPoint(),authors);
|
|
//
|
|
// // 添加打赏记录
|
|
// RecordRewardPointModel data = new RecordRewardPointModel();
|
|
// data.setUserId(Long.valueOf(userId));
|
|
// data.setAuthorIden(authors);
|
|
// data.setSourceId(r.getId());
|
|
// data.setPoint(r.getPoint());
|
|
// data.setSourceType(r.getType());
|
|
// int res = recordRewardPointDao.insert(data);
|
|
// if (res <= 0){
|
|
// logger.info("添加打赏记录失败: {}",r);
|
|
// }
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
}
|