Просмотр исходного кода

Merge branch 'test' of jishutao/jitao-server into prod

anderx лет назад: 3
Родитель
Сommit
9edb609e94

+ 82 - 0
src/main/java/com/goafanti/common/utils/HttpUtils.java

@@ -0,0 +1,82 @@
+package com.goafanti.common.utils;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.ParseException;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.util.EntityUtils;
+
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.Map;
+
+public class HttpUtils {
+
+
+
+	 public static JSONObject httpGet(String url) {
+			JSONObject jsonResult = null;
+			try {
+			HttpClient client = HttpClientBuilder.create().build();//获取DefaultHttpClient请求
+			HttpGet request = new HttpGet(url);
+			HttpResponse response = client.execute(request);
+			if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
+			String strResult = EntityUtils.toString(response.getEntity(),"UTF-8");//此处设定编码格式
+			jsonResult = JSON.parseObject(strResult);
+			} else {
+			LoggerUtils.error(HttpUtils.class,"HttpStatus异常");
+			}
+			} catch (IOException e) {
+			e.printStackTrace();
+			}
+			return jsonResult;
+		}
+
+		 /**
+		  *
+		  * @param url 地址
+		  * @param map 参数
+		  * @return
+		  */
+		public static JSONObject httpPost(String url,Map<String, Object>map){
+			HttpClient httpClient = HttpClientBuilder.create().build();
+			HttpPost httpPost = new HttpPost(url);
+			httpPost.addHeader("Content-type", "application/json");
+			httpPost.setHeader("Accept", "application/json");
+			httpPost.setEntity(new StringEntity(JSON.toJSONString(map), Charset.forName("UTF-8")));
+			HttpResponse response = null;
+			try {
+				response = httpClient.execute(httpPost);
+			if (null == response || response.getStatusLine() == null) {
+				throw new Exception("Post Request For Url[{}] is not ok. Response is null");
+			} else if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
+				throw new Exception("Post Request For Url[{}] is not ok. Response Status Code is {"+response.getStatusLine().getStatusCode()+"}");
+			}
+			} catch (ClientProtocolException e) {
+				e.printStackTrace();
+			} catch (IOException e) {
+				e.printStackTrace();
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+			String resultString=null;
+			try {
+				resultString = EntityUtils.toString(response.getEntity());
+			} catch (ParseException | IOException e) {
+				e.printStackTrace();
+			}
+			JSONObject jsonObj = JSONObject.parseObject(resultString);
+			return jsonObj;
+			}
+
+
+
+
+}

+ 34 - 38
src/main/java/com/goafanti/evaluation/controller/UserEvaluationApiController.java

@@ -1,28 +1,5 @@
 package com.goafanti.evaluation.controller;
 
-import java.math.BigDecimal;
-import java.math.MathContext;
-import java.math.RoundingMode;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import javax.validation.Valid;
-
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.util.Assert;
-import org.springframework.validation.BindingResult;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
-
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.goafanti.common.bo.Result;
@@ -33,25 +10,40 @@ import com.goafanti.common.model.IndustryCategory;
 import com.goafanti.common.model.ValueEvaluation;
 import com.goafanti.common.service.DistrictGlossoryService;
 import com.goafanti.common.service.IndustryCategoryService;
+import com.goafanti.common.utils.HttpUtils;
 import com.goafanti.common.utils.LoggerUtils;
 import com.goafanti.core.shiro.token.TokenManager;
-import com.goafanti.evaluation.bo.ForecastIncome;
-import com.goafanti.evaluation.bo.Step1;
-import com.goafanti.evaluation.bo.Step2;
-import com.goafanti.evaluation.bo.Step3;
-import com.goafanti.evaluation.bo.Step4;
-import com.goafanti.evaluation.bo.Step5;
-import com.goafanti.evaluation.bo.Step6;
-import com.goafanti.evaluation.bo.Step7;
-import com.goafanti.evaluation.bo.YearIncome;
+import com.goafanti.evaluation.bo.*;
 import com.goafanti.evaluation.enums.ProfitRate;
 import com.goafanti.evaluation.service.ValueEvaluationService;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.Assert;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.validation.Valid;
+import java.math.BigDecimal;
+import java.math.MathContext;
+import java.math.RoundingMode;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 @RestController
 @RequestMapping(value = "/api/user/evaluate")
 public class UserEvaluationApiController extends BaseApiController {
 
-	private static final String			GOVERNMENT_LOAN_ROR	= "government_loan_ror"; //政府贷款利率
+//	private static final String			GOVERNMENT_LOAN_ROR	= "government_loan_ror"; //政府贷款利率
+	private static final String			GOVERNMENT_LOAN_ROR	= "4.6"; //政府贷款利率
 	private static final Logger			logger				= LoggerFactory.getLogger(UserEvaluationApiController.class);
 	private static final MathContext	DEFAULT_PRECISION	= new MathContext(4, RoundingMode.HALF_UP); //默认精度
 
@@ -227,7 +219,7 @@ public class UserEvaluationApiController extends BaseApiController {
 	}
 
 	/**
-	 * 
+	 *
 	 * @param id
 	 * @return
 	 */
@@ -347,9 +339,9 @@ public class UserEvaluationApiController extends BaseApiController {
 
 		BigDecimal profitRate = calcProfitRate(profitScores, step1.getIndustry(), result);
 
-		/*BigDecimal governmentLoanRoR = new BigDecimal(sysDictService.getValue(GOVERNMENT_LOAN_ROR),
-				MathContext.DECIMAL32);*/
-		BigDecimal governmentLoanRoR = new BigDecimal(0);
+		BigDecimal governmentLoanRoR = new BigDecimal(GOVERNMENT_LOAN_ROR,
+				MathContext.DECIMAL32);
+//		BigDecimal governmentLoanRoR = new BigDecimal(0);
 		BigDecimal taxRate = new BigDecimal(step6.getTaxRate());
 
 		BigDecimal discountRate = calcDiscountRate(discountRates, taxRate, governmentLoanRoR);
@@ -403,6 +395,8 @@ public class UserEvaluationApiController extends BaseApiController {
 		return discountRate;
 	}
 
+
+
 	private Map<String, Integer> getDiscountRates(Step7 step7) {
 		Map<String, Integer> profitScores = new HashMap<>();
 		profitScores.put("capital", getDiscountScore(step7.getCapital()));// 资金风险
@@ -580,7 +574,7 @@ public class UserEvaluationApiController extends BaseApiController {
 		return industryCategoryService.list(pid).stream()
 				.collect(Collectors.toMap(IndustryCategory::getId, (it) -> it));
 	}
-	
+
 	private Map<Integer, DistrictGlossory> getProvinces() {
 		return districtGlossoryService.list(0).stream().collect(Collectors.toMap(DistrictGlossory::getId, (it) -> it));
 	}
@@ -629,4 +623,6 @@ public class UserEvaluationApiController extends BaseApiController {
 		res[1] = two.longValue();
 		return res;
 	}
+
+
 }