albertshaw лет назад: 8
Родитель
Сommit
66c23f98f9

+ 1 - 1
src/main/java/com/goafanti/evaluation/bo/Step1.java

@@ -32,7 +32,7 @@ public class Step1 {
 	private String	currencyType;
 
 	@NotNull
-	@Pattern(regexp = "\\d{4}-\\d{2}-\\d{2}")
+	@Pattern(regexp = "\\d{4}-\\d{2}-01")
 	private String	benchmarkDate;
 
 	public String getName() {

+ 64 - 2
src/main/java/com/goafanti/evaluation/controller/EvaluationController.java

@@ -1,5 +1,8 @@
 package com.goafanti.evaluation.controller;
 
+import java.math.BigDecimal;
+import java.math.MathContext;
+import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -21,7 +24,9 @@ import com.alibaba.fastjson.JSONObject;
 import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.BaseApiController;
+import com.goafanti.common.model.IndustryCategory;
 import com.goafanti.common.model.ValueEvaluation;
+import com.goafanti.common.service.IndustryCategoryService;
 import com.goafanti.common.utils.LoggerUtils;
 import com.goafanti.core.shiro.token.TokenManager;
 import com.goafanti.evaluation.bo.Step1;
@@ -35,10 +40,13 @@ import com.goafanti.evaluation.service.ValueEvaluationService;
 @RequestMapping(value = "/api/user/evaluate")
 public class EvaluationController extends BaseApiController {
 
-	private static final Logger	logger	= LoggerFactory.getLogger(EvaluationController.class);
+	private static final Logger			logger				= LoggerFactory.getLogger(EvaluationController.class);
+	private static final MathContext	DEFAULT_PRECISION	= new MathContext(3, RoundingMode.HALF_UP);
 
 	@Autowired
-	ValueEvaluationService		valueEvaluationService;
+	ValueEvaluationService				valueEvaluationService;
+	@Autowired
+	private IndustryCategoryService		industryCategoryService;
 
 	@RequestMapping(value = "/create", method = RequestMethod.GET)
 	public Result create() {
@@ -139,6 +147,24 @@ public class EvaluationController extends BaseApiController {
 		return res;
 	}
 
+	@RequestMapping(value = "/step5/{id}", method = RequestMethod.GET)
+	public Result step5Info(@PathVariable String id) {
+		Assert.isTrue(StringUtils.isNumeric(id), ErrorConstants.EVALUATE_ID);
+		Result res = new Result();
+		ValueEvaluation ve = valueEvaluationService.getEvaluation(Long.valueOf(id));
+		try {
+			JSONObject jo = JSON.parseObject(ve.getLog());
+			Step4 step4 = ((JSON) jo.get("3")).toJavaObject(Step4.class);
+			if (step4.getHasIncome().equals(2)) {
+				Step1 step1 = ((JSON) jo.get("0")).toJavaObject(Step1.class);
+				res.data(getPredicateIncome(step4.getIncomes(), getIndustryCategoryValue(step1)));
+			}
+		} catch (Exception e) {
+			res.error(buildError(ErrorConstants.EVALUATE_PARAM));
+		}
+		return res;
+	}
+
 	private void updateSteps(Object step, Integer nextStep, String key, Result res, String id) {
 		ValueEvaluation ve = valueEvaluationService.getEvaluation(Long.valueOf(id));
 		Assert.notNull(ve, ErrorConstants.EVALUATE_ID);
@@ -158,4 +184,40 @@ public class EvaluationController extends BaseApiController {
 		}
 		return false;
 	}
+
+	private BigDecimal getIndustryCategoryValue(Step1 step1) {
+		List<IndustryCategory> cates = industryCategoryService.list(step1.getIndustry());
+		String[] subs = step1.getSubIndustry().split(",");
+		Integer[] subIds = new Integer[subs.length];
+		for (int i = 0; i < subs.length; i++) {
+			subIds[i] = Integer.valueOf(subs[i]);
+		}
+		BigDecimal average = BigDecimal.ZERO;
+		for (IndustryCategory ic : cates) {
+			for (int i = 0; i < subIds.length; i++) {
+				if (ic.getId().equals(subIds[i])) {
+					average = average.add(ic.getValue());
+				}
+			}
+		}
+		return average.divide(new BigDecimal(3), 2, RoundingMode.HALF_UP);
+	}
+
+	private Long[] getPredicateIncome(List<YearIncome> incomes, BigDecimal growth) {
+		BigDecimal useGrowth = growth.divide(new BigDecimal(100), 2, RoundingMode.CEILING);
+		BigDecimal base = new BigDecimal(incomes.get(0).getIncome());
+		if (!incomes.get(1).getIncome().equals(0)) {
+			useGrowth = base.divide(new BigDecimal(incomes.get(1).getIncome()), 2, RoundingMode.CEILING)
+					.subtract(BigDecimal.ONE);
+		}
+		Long[] res = new Long[3];
+		BigDecimal one = base.multiply(useGrowth.add(BigDecimal.ONE));
+		useGrowth = useGrowth.multiply(new BigDecimal(0.9, DEFAULT_PRECISION));
+		BigDecimal two = one.multiply(useGrowth.add(BigDecimal.ONE));
+		useGrowth = useGrowth.multiply(new BigDecimal(0.8, DEFAULT_PRECISION));
+		res[2] = two.multiply(useGrowth.add(BigDecimal.ONE)).longValue();
+		res[0] = one.longValue();
+		res[1] = two.longValue();
+		return res;
+	}
 }

+ 1 - 0
src/main/webapp/WEB-INF/views/common.html

@@ -6,6 +6,7 @@
     <meta charset="UTF-8">
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
+    <meta name="renderer" content="webkit">
     <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
     <title th:replace="${title}"></title>
     <th:block th:replace="${link}" />