|
@@ -2,14 +2,21 @@ package fcb.project.manager.core.controller;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import fcb.project.manager.base.constant.CommonConstant;
|
|
|
import fcb.project.manager.base.entity.TmApiHouseInfo;
|
|
|
import fcb.project.manager.base.entity.TmApiHouseRecommend;
|
|
|
+import fcb.project.manager.base.entity.TmFcbHouseInfo;
|
|
|
+import fcb.project.manager.base.entity.TmHouse;
|
|
|
import fcb.project.manager.base.service.impl.TmApiHouseInfoServiceImpl;
|
|
|
import fcb.project.manager.base.service.impl.TmApiHouseRecommendServiceImpl;
|
|
|
+import fcb.project.manager.base.service.impl.TmHouseServiceImpl;
|
|
|
+import fcb.project.manager.base.utils.RedisServiceUtils;
|
|
|
import fdage.back.sdk.base.entity.Result;
|
|
|
import fdage.back.sdk.base.enums.ResultCodeEnum;
|
|
|
import fdage.back.sdk.base.exception.CommonBaseException;
|
|
|
import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -34,7 +41,7 @@ import java.util.Map;
|
|
|
@Api(tags = "api房源数据查询接口")
|
|
|
@Log4j2
|
|
|
@RestController
|
|
|
-@RequestMapping("api/query")
|
|
|
+@RequestMapping("fcb/project/api/query")
|
|
|
public class ApiQueryHouseController {
|
|
|
|
|
|
@Autowired
|
|
@@ -43,41 +50,60 @@ public class ApiQueryHouseController {
|
|
|
@Autowired
|
|
|
private TmApiHouseRecommendServiceImpl tmApiHouseRecommendService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisServiceUtils redisServiceUtils;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TmHouseServiceImpl tmHouseService;
|
|
|
+
|
|
|
|
|
|
@ApiOperation(value = "H5页面请求房源信息")
|
|
|
- @ResponseBody
|
|
|
@GetMapping(value = "/getHouseInfo")
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- //TODO:这里要添加写入和读取TmEstateServiceImpl缓存
|
|
|
- public Result getHouseInfo(@RequestParam(value = "scene_code") String sceneCode,
|
|
|
- @RequestParam(value = "user_id") String userId,
|
|
|
- @RequestParam(value = "room_id") String roomId,
|
|
|
- @RequestParam(value = "terminal_type") String terminalType) {
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "sceneNum", value = "场景码", paramType = "query", required = true, dataType = "String"),
|
|
|
+ @ApiImplicitParam(name = "projectId", value = "楼盘ID", paramType = "query", required = true, dataType = "String"),
|
|
|
+ @ApiImplicitParam(name = "houseId", value = "房源ID", paramType = "query", required = true, dataType = "String"),
|
|
|
+ })
|
|
|
+ public Result getHouseInfo(@RequestParam(value = "sceneNum") String sceneNum,
|
|
|
+ @RequestParam(value = "projectId") String projectId,
|
|
|
+ @RequestParam(value = "houseId") String houseId) {
|
|
|
|
|
|
- if (!StringUtils.isNoneBlank(sceneCode , roomId)) {
|
|
|
+ if (!StringUtils.isNoneBlank(sceneNum , projectId , houseId)) {
|
|
|
throw new CommonBaseException(ResultCodeEnum.D3001);
|
|
|
}
|
|
|
|
|
|
- log.info("上送的场景码为:{},终端类型为:{}", sceneCode, terminalType);
|
|
|
- Instant stepOneStart = Instant.now();
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
- TmApiHouseInfo tmHouseInfo = tmApiHouseInfoService.getHouseBySceneAndRoomId(sceneCode , roomId);
|
|
|
- if (null == tmHouseInfo) {
|
|
|
- //todo:补充异常返回信息
|
|
|
- throw new CommonBaseException(ResultCodeEnum.D101);
|
|
|
+ String redisKey = this.getClass().getName() + CommonConstant.REDIS_KEY_SEPERATER +
|
|
|
+ projectId + CommonConstant.REDIS_KEY_SEPERATER + houseId + CommonConstant.REDIS_KEY_SEPERATER +
|
|
|
+ sceneNum;
|
|
|
+ TmFcbHouseInfo fcbHouseInfo = null;
|
|
|
+ if(redisServiceUtils.hasKey(redisKey)){
|
|
|
+ String fcbHouseInfoStr = (String) redisServiceUtils.get(redisKey);
|
|
|
+ if(StringUtils.isNotBlank(fcbHouseInfoStr)){
|
|
|
+ fcbHouseInfo = JSON.parseObject(fcbHouseInfoStr , TmFcbHouseInfo.class);
|
|
|
+ return Result.success(fcbHouseInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //缓中没有,则去库中获取 todo:考虑下,到底值是去库中获取还是直接取房车宝获取
|
|
|
+ TmHouse tmHouse = tmHouseService.getBySceneNumAndHouseId(sceneNum , projectId , houseId);
|
|
|
+ if(null == tmHouse){
|
|
|
+ return Result.failure("房源不存在");
|
|
|
}
|
|
|
- Instant stepOneEnd = Instant.now();
|
|
|
- long stepOneDuration = Duration.between(stepOneStart , stepOneEnd).toMillis();
|
|
|
- log.info("======={}=============1、捞取房源数据耗时:{}===================" , "获取房源阶段" , stepOneDuration);
|
|
|
- //覆盖推荐房源字段
|
|
|
- Instant stepTwoStart = Instant.now();
|
|
|
- List<TmApiHouseInfo> recList = getRecommends(tmHouseInfo);
|
|
|
- tmHouseInfo.setRecommendHouses(JSON.toJSONString(recList));
|
|
|
- Instant stepTwoEnd = Instant.now();
|
|
|
- long stepTwoDuration = Duration.between(stepTwoStart , stepTwoEnd).toMillis();
|
|
|
- log.info("========{}============2、生成推荐房源数据耗时:{}===================" ,"获取房源阶段" , stepTwoDuration);
|
|
|
- result.put("houseInfo", tmHouseInfo);
|
|
|
- return Result.success("请求结束", result);
|
|
|
+ if(StringUtils.isBlank(tmHouse.getHouseInfo())){
|
|
|
+ //TODO:去房车宝接口获取
|
|
|
+
|
|
|
+ }else{
|
|
|
+ //缓存一天
|
|
|
+ redisServiceUtils.set(redisKey , tmHouse.getHouseInfo() , 86400);
|
|
|
+ fcbHouseInfo = JSON.parseObject(tmHouse.getHouseInfo() , TmFcbHouseInfo.class);
|
|
|
+ }
|
|
|
+ return Result.success(fcbHouseInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "测试获取fcbhouseInfo的json")
|
|
|
+ @GetMapping(value = "/justTest")
|
|
|
+ public void justTest(@RequestBody TmFcbHouseInfo tmFcbHouseInfo){
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private List<TmApiHouseInfo> getRecommends(TmApiHouseInfo houseInfo) {
|