|
@@ -0,0 +1,129 @@
|
|
|
+package fcb.project.manager.core.controller;
|
|
|
+
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import fcb.project.manager.base.entity.ContextTokenBean;
|
|
|
+import fcb.project.manager.base.utils.DateUtil;
|
|
|
+import fdage.back.sdk.utils.HttpClientUtil;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.log4j.Log4j2;
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.time.Duration;
|
|
|
+import java.time.Instant;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Api(tags = "二手房小区相关接口")
|
|
|
+@RestController
|
|
|
+@Log4j2
|
|
|
+@RequestMapping("/fcb/project/redirctweb")
|
|
|
+public class TmRedirectWebController extends BaseController{
|
|
|
+
|
|
|
+ @Value("${fcb.agentsaas}")
|
|
|
+ private String fcbagentsaas;
|
|
|
+
|
|
|
+ @PostMapping("/{name}")
|
|
|
+ @ApiOperation(value = "二手房小区接口转发")
|
|
|
+ public Object addNewHouse(@PathVariable String name, @RequestBody JSONObject object){
|
|
|
+ Instant stepTwoStart = Instant.now();
|
|
|
+ String str = "";
|
|
|
+ try {
|
|
|
+ ContextTokenBean tokenMap = getContextUserInfo();
|
|
|
+ log.info("二手房接口转发 : " + name);
|
|
|
+
|
|
|
+ String timestamp = String.valueOf(new Date().getTime());
|
|
|
+ String apiNumber = name;
|
|
|
+ String nonce = DateUtil.randonNum(5);
|
|
|
+ String secret = "fcb2021";
|
|
|
+
|
|
|
+ if(object.containsKey("companyName")){
|
|
|
+ if(StringUtils.isNotEmpty(tokenMap.getDepartmentName())){
|
|
|
+ object.put("companyName",tokenMap.getDepartmentName());
|
|
|
+ }else{
|
|
|
+ object.put("companyName","");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(object.containsKey("operatorCompanyId")){
|
|
|
+ if(StringUtils.isNotEmpty(tokenMap.getDepartmentId())){
|
|
|
+ object.put("operatorCompanyId",tokenMap.getDepartmentId());
|
|
|
+ }else{
|
|
|
+ object.put("operatorCompanyId","");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(object.containsKey("operatorCompanyName")){
|
|
|
+ if(StringUtils.isNotEmpty(tokenMap.getDepartmentName())){
|
|
|
+ object.put("operatorCompanyName",tokenMap.getDepartmentName());
|
|
|
+ }else{
|
|
|
+ object.put("operatorCompanyName","");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String params = object.toJSONString();
|
|
|
+ String[] strary = new String[]{secret,timestamp,nonce,params,apiNumber};
|
|
|
+ Arrays.sort(strary);
|
|
|
+
|
|
|
+ String strs = "";
|
|
|
+ for(int i=0;i<strary.length;i++){
|
|
|
+ strs += strary[i];
|
|
|
+ }
|
|
|
+
|
|
|
+ String signature = DigestUtils.shaHex(strs);
|
|
|
+ log.info("url : " + fcbagentsaas);
|
|
|
+
|
|
|
+ Map mm = new HashMap();
|
|
|
+ mm.put("apiNumber", apiNumber);
|
|
|
+ mm.put("nonce", nonce);
|
|
|
+ mm.put("secret", secret);
|
|
|
+ mm.put("params", params);
|
|
|
+ mm.put("timestamp", timestamp);
|
|
|
+ mm.put("signature", signature);
|
|
|
+
|
|
|
+ String param = JSON.toJSONString(mm);
|
|
|
+ log.info("====================参数:{}===================" , param);
|
|
|
+
|
|
|
+ str = HttpClientUtil.doPostJson(fcbagentsaas, param);
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(str)){
|
|
|
+ JSONObject responsemsg = JSONObject.parseObject(str);
|
|
|
+
|
|
|
+
|
|
|
+ return responsemsg;
|
|
|
+ }else{
|
|
|
+ JSONObject responsemsg = new JSONObject();
|
|
|
+ responsemsg.put("resultType",99);
|
|
|
+ responsemsg.put("resultMsg","接口请求失败,未获取到数据");
|
|
|
+ responsemsg.put("resultData",str);
|
|
|
+ return responsemsg;
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+
|
|
|
+ e.printStackTrace();
|
|
|
+ JSONObject responsemsg = new JSONObject();
|
|
|
+ responsemsg.put("resultType",99);
|
|
|
+ responsemsg.put("resultMsg","系统繁忙");
|
|
|
+ responsemsg.put("resultData",str);
|
|
|
+ return responsemsg;
|
|
|
+
|
|
|
+ }finally {
|
|
|
+
|
|
|
+ Instant stepTwoEnd = Instant.now();
|
|
|
+ long stepTwoDuration = Duration.between(stepTwoStart , stepTwoEnd).toMillis();
|
|
|
+
|
|
|
+ log.info("====================二手房接口转发完成:{}===================" , stepTwoDuration);
|
|
|
+ log.info("二手房接口转发完成 : " + str);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|