|
@@ -1,12 +1,97 @@
|
|
|
package fcb.project.manager.core.controller;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import fcb.project.manager.base.entity.TmApiHouseInfo;
|
|
|
+import fcb.project.manager.base.entity.TmApiHouseRecommend;
|
|
|
+import fcb.project.manager.base.service.impl.TmApiHouseInfoServiceImpl;
|
|
|
+import fcb.project.manager.base.service.impl.TmApiHouseRecommendServiceImpl;
|
|
|
+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.ApiOperation;
|
|
|
+import lombok.extern.log4j.Log4j2;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.time.Duration;
|
|
|
+import java.time.Instant;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
/**
|
|
|
* 2 * @Author: Abner
|
|
|
* 3 * @Date: 2021/1/11 10:10
|
|
|
* 4
|
|
|
*/
|
|
|
-
|
|
|
+@Log4j2
|
|
|
+@RestController
|
|
|
+@RequestMapping("api/query")
|
|
|
public class ApiQueryHouseController {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private TmApiHouseInfoServiceImpl tmApiHouseInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TmApiHouseRecommendServiceImpl tmApiHouseRecommendService;
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "H5页面请求房源信息")
|
|
|
+ @ResponseBody
|
|
|
+ @GetMapping(value = "/getHouseInfo")
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ //TODO:这里要添加写入和读取缓存
|
|
|
+ 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) {
|
|
|
+
|
|
|
+ if (!StringUtils.isNoneBlank(sceneCode , roomId)) {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<TmApiHouseInfo> getRecommends(TmApiHouseInfo houseInfo) {
|
|
|
+ List<TmApiHouseInfo> houseInfoList = new ArrayList<>();
|
|
|
+ if (null != houseInfo) {
|
|
|
+ List<TmApiHouseRecommend> houseRecommendList = tmApiHouseRecommendService.getRecommendList(houseInfo.getSceneNum() , houseInfo.getCommunicateRoomId());
|
|
|
+ if (!CollectionUtils.isEmpty(houseRecommendList)) {
|
|
|
+ for (TmApiHouseRecommend recommend : houseRecommendList) {
|
|
|
+ TmApiHouseInfo tmHouseInfo = tmApiHouseInfoService.getHouseBySceneAndRoomId(recommend.getSceneNum() , recommend.getCommunicateRoomId());
|
|
|
+ if (null != tmHouseInfo) {
|
|
|
+ houseInfoList.add(tmHouseInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return houseInfoList;
|
|
|
+ }
|
|
|
|
|
|
}
|