api
/**
* 查询推荐好友的缘分值
*
* @param userId 好友的id
* @param toUserId 我的id
* @return
*/
Double queryScore(Long userId, Long toUserId);
===========================================================
api impl
@Override
public Double queryScore(Long userId, Long toUserId) {
Query query = Query.query(Criteria.where("toUserId").is(toUserId)
.and("userId").is(userId));
RecommendUser recommendUser = this.mongoTemplate.findOne(query, RecommendUser.class);
if (null != recommendUser) {
return recommendUser.getScore();
}
return null;
}
============================================================
controller
import com.tanhua.server.service.TanHuaService;
import com.tanhua.server.vo.TodayBest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RequestMapping("tanhua")
@RestController
public class TanHuaController {
@Autowired
private TanHuaService tanHuaService;
/**
* 查询个人主页的个人信息
*
* @param userId
* @return
*/
@GetMapping("{id}/personalInfo")
public ResponseEntity<TodayBest> queryUserInfo(@PathVariable("id") Long userId) {
try {
TodayBest todayBest = this.tanHuaService.queryUserInfo(userId);
return ResponseEntity.ok(todayBest);
} catch (Exception e) {
e.printStackTrace();
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
============================================================
service
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.tanhua.common.pojo.User;
import com.tanhua.common.pojo.UserInfo;
import com.tanhua.common.utils.UserThreadLocal;
import com.tanhua.server.vo.TodayBest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class TanHuaService {
@Autowired
private UserInfoService userInfoService;
@Autowired
private RecommendUserService recommendUserService;
public TodayBest queryUserInfo(Long userId) {
UserInfo userInfo = this.userInfoService.queryUserInfoByUserId(userId);
if(ObjectUtil.isEmpty(userInfo)){
return null;
}
TodayBest todayBest = new TodayBest();
todayBest.setId(userId);
todayBest.setAge(userInfo.getAge());
todayBest.setGender(userInfo.getSex().name().toLowerCase());
todayBest.setNickname(userInfo.getNickName());
todayBest.setTags(Convert.toStrArray(StrUtil.split(userInfo.getTags(),',')));
todayBest.setAvatar(userInfo.getLogo());
//缘分值
User user = UserThreadLocal.get();
todayBest.setFateValue(this.recommendUserService.queryScore(userId, user.getId()).longValue());
return todayBest;
}
}
======================================================
/**
* 查询推荐好友的缘分值 RecommendUserService
*
* @param userId
* @param toUserId
* @return
*/
public Double queryScore(Long userId, Long toUserId){
Double score = this.recommendUserApi.queryScore(userId, toUserId);
if(ObjectUtil.isNotEmpty(score)){
return score;
}
//默认值
return 98d;
}
如若转载,请注明出处:https://www.52mingliang.com/4850.html