|
@@ -2,13 +2,24 @@ package com.platform.controller;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.platform.entity.Result;
|
|
|
+import com.platform.entity.SceneEntity;
|
|
|
+import com.platform.entity.SysUserEntity;
|
|
|
+import com.platform.entity.UserEntity;
|
|
|
import com.platform.enums.ResultCodeEnum;
|
|
|
+import com.platform.exception.CommonBaseException;
|
|
|
+import com.platform.service.SceneService;
|
|
|
+import com.platform.service.SysUserService;
|
|
|
+import com.platform.service.UserService;
|
|
|
+import com.platform.service.impl.FdkkService;
|
|
|
+import com.platform.service.impl.ZhiHouseService;
|
|
|
+import com.platform.utils.Base64Converter;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -18,47 +29,66 @@ import java.util.Map;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("token")
|
|
|
-public class TokenController {
|
|
|
+public class TokenController extends AbstractController{
|
|
|
|
|
|
protected Logger log = LoggerFactory.getLogger(this.getClass());
|
|
|
+ @Autowired
|
|
|
+ private SceneService sceneService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FdkkService fdkkService;
|
|
|
|
|
|
- @Value("${scenePath}")
|
|
|
- private String zhiHouseHost;
|
|
|
|
|
|
@Autowired
|
|
|
- private RestTemplate restTemplate;
|
|
|
+ private ZhiHouseService zhiHouseService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysUserService sysUserService;
|
|
|
|
|
|
@PostMapping("/renewToken")
|
|
|
@ResponseBody
|
|
|
public Result renewToken(@RequestBody Map<String,String> param) {
|
|
|
- if(ObjectUtils.isEmpty(param.get("userName")) || ObjectUtils.isEmpty(param.get("sceneNum"))){
|
|
|
- return Result.failure("参数有误!");
|
|
|
+ String sceneNum = param.get("sceneNum");
|
|
|
+ String userName = param.get("userName");
|
|
|
+ if(ObjectUtils.isEmpty(userName) || ObjectUtils.isEmpty(sceneNum)){
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101,"参数有误!");
|
|
|
}
|
|
|
+ // 判断场景为四维看看或者指房宝
|
|
|
+ SceneEntity scene = sceneService.queryByScene(sceneNum);
|
|
|
+ if(scene.getSceneUrl().contains("4dkankan.com")){
|
|
|
+ Long userId = getUser().getUserId();
|
|
|
+ SysUserEntity user = sysUserService.queryObject(userId);
|
|
|
+ if(ObjectUtils.isEmpty(user.getFdkkUser())){
|
|
|
+ throw new CommonBaseException(500, "请绑定四维看看账号!");
|
|
|
+ }
|
|
|
+ String password = Base64Converter.decode(Base64Converter.subText(user.getFdkkPassword()));
|
|
|
+ ResponseEntity<String> responseEntity = fdkkService.login(user.getFdkkUser(), password);
|
|
|
+ if(responseEntity.getStatusCode()!= HttpStatus.OK){
|
|
|
+ throw new CommonBaseException(500,"请求失败");
|
|
|
+ }
|
|
|
+ JSONObject result = JSONObject.parseObject(responseEntity.getBody());
|
|
|
+ if (result.getInteger("code") != 0) {
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101, "4d看看密码有误!");
|
|
|
+ }
|
|
|
+ return Result.success(result.getJSONObject("data").getString("token"));
|
|
|
+ }
|
|
|
+
|
|
|
// 判断token是否有效
|
|
|
- String url = zhiHouseHost + "api/platform/generateSceneEditToken";
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.add("token", param.get("token"));
|
|
|
- HttpEntity<Object> formEntity = new HttpEntity<>(param, headers);
|
|
|
- ResponseEntity<String> kankanResult = restTemplate.postForEntity(url,formEntity,String.class);
|
|
|
+ ResponseEntity<String> kankanResult = zhiHouseService.generateSceneEditToken(param.get("token"),userName,sceneNum);
|
|
|
return parseKanKanRsp(kankanResult.getBody());
|
|
|
}
|
|
|
|
|
|
private Result parseKanKanRsp(String result) {
|
|
|
- if(null == result){
|
|
|
- return Result.failure(ResultCodeEnum.D101.getCode() , "四维看看返回数据异常");
|
|
|
+ if (null == result) {
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101.getCode(), "返回数据异常");
|
|
|
}
|
|
|
//把信息封装为json
|
|
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
log.info("看看返回数据:{}", jsonObject.toJSONString());
|
|
|
int code = -10;
|
|
|
- if (jsonObject.containsKey("code")) {
|
|
|
- code = (int) jsonObject.get("code");
|
|
|
- if (code != 200) {
|
|
|
- return Result.failure(ResultCodeEnum.D101.getCode() , "调用四维看看失败");
|
|
|
- }
|
|
|
- return Result.success(jsonObject.get("message"));
|
|
|
- } else {
|
|
|
- return Result.failure(ResultCodeEnum.D101.getCode() , "调用四维看看失败");
|
|
|
+ if (!jsonObject.containsKey("code") || jsonObject.getInteger("code") != 200) {
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101.getCode(), "请求失败");
|
|
|
}
|
|
|
+ return Result.success(jsonObject.get("message"));
|
|
|
}
|
|
|
}
|