|
@@ -24,66 +24,71 @@ public class ScaleCalculate {
|
|
|
double sum = 0;
|
|
|
Map<String, Object> data = (Map<String, Object>) jsonObject.get("data");
|
|
|
String scaleName = data.get("scaleName").toString();
|
|
|
- List<Map<String, Object>> groupList = (List<Map<String, Object>>) data.get("group");
|
|
|
- for (Map<String, Object> group : groupList) {
|
|
|
- double groupSum = 0;
|
|
|
- groupResults = new HashMap<>();
|
|
|
- String groupName = group.get("groupName").toString();
|
|
|
- List<Map<String, Object>> rowsList = (List<Map<String, Object>>) group.get("rows");
|
|
|
- for (Map<String, Object> rows : rowsList) {
|
|
|
- List<Map<String, Object>> rowList = (List<Map<String, Object>>) rows.get("row");
|
|
|
- //多条选第一条
|
|
|
- Map<String, Object> firstRow = rowList.get(0);
|
|
|
- int coefficent = Integer.valueOf(firstRow.get("coefficent").toString());
|
|
|
- int constant = Integer.valueOf(firstRow.get("constant").toString());
|
|
|
- List<Map<String, Object>> detailsList = (List<Map<String, Object>>) firstRow.get("details");
|
|
|
- for (Map<String, Object> details : detailsList) {
|
|
|
- if (Integer.valueOf(details.get("select").toString()) == 1) {
|
|
|
- Double score = Double.valueOf(details.get("score").toString());
|
|
|
- //分值*系数+常数
|
|
|
- score = score * coefficent + constant;
|
|
|
- groupSum += score;
|
|
|
- sum += score;
|
|
|
+ int scaleType = Integer.valueOf(data.get("scaleType").toString());
|
|
|
+ if (scaleType == 1) {
|
|
|
+ List<Map<String, Object>> groupList = (List<Map<String, Object>>) data.get("group");
|
|
|
+ for (Map<String, Object> group : groupList) {
|
|
|
+ double groupSum = 0;
|
|
|
+ groupResults = new HashMap<>();
|
|
|
+ String groupName = group.get("groupName").toString();
|
|
|
+ List<Map<String, Object>> rowsList = (List<Map<String, Object>>) group.get("rows");
|
|
|
+ for (Map<String, Object> rows : rowsList) {
|
|
|
+ List<Map<String, Object>> rowList = (List<Map<String, Object>>) rows.get("row");
|
|
|
+ //多条选第一条
|
|
|
+ Map<String, Object> firstRow = rowList.get(0);
|
|
|
+ int coefficient = Integer.valueOf(firstRow.get("coefficient").toString());
|
|
|
+ int constant = Integer.valueOf(firstRow.get("constant").toString());
|
|
|
+ List<Map<String, Object>> detailsList = (List<Map<String, Object>>) firstRow.get("details");
|
|
|
+ for (Map<String, Object> details : detailsList) {
|
|
|
+ if (Integer.valueOf(details.get("select").toString()) == 1) {
|
|
|
+ Double score = Double.valueOf(details.get("score").toString());
|
|
|
+ //分值*系数+常数
|
|
|
+ score = score * coefficient + constant;
|
|
|
+ groupSum += score;
|
|
|
+ sum += score;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- }
|
|
|
- // String text = scaleResultText(groupSum);
|
|
|
- JSONObject groupCalculate = new JSONObject();
|
|
|
- JSONObject groupResult = new JSONObject();
|
|
|
- groupResult.put("text", "");
|
|
|
- groupResult.put("value", groupSum);
|
|
|
+ }
|
|
|
+ // String text = scaleResultText(groupSum);
|
|
|
+ JSONObject groupCalculate = new JSONObject();
|
|
|
+ JSONObject groupResult = new JSONObject();
|
|
|
+ groupResult.put("text", "");
|
|
|
+ groupResult.put("value", groupSum);
|
|
|
|
|
|
- groupCalculate.put("result", groupResult);
|
|
|
- groupCalculate.put("isShow", 1);
|
|
|
+ groupCalculate.put("result", groupResult);
|
|
|
+ groupCalculate.put("isShow", 1);
|
|
|
|
|
|
- groupResults.put("groupName", groupName);
|
|
|
- groupResults.put("groupCalculate", groupCalculate);
|
|
|
+ groupResults.put("groupName", groupName);
|
|
|
+ groupResults.put("groupCalculate", groupCalculate);
|
|
|
|
|
|
- groupLists.add(groupResults);
|
|
|
- }
|
|
|
- String text = null;
|
|
|
- Map<String, Object> calculate = (Map<String, Object>) data.get("calculate");
|
|
|
- List<Map<String, Object>> rangeList = (List<Map<String, Object>>) calculate.get("range");
|
|
|
- for (Map<String, Object> range : rangeList) {
|
|
|
- Double max = Double.valueOf(range.get("max").toString());
|
|
|
- Double min = Double.valueOf(range.get("min").toString());
|
|
|
- if (sum >= min && sum <= max) {
|
|
|
- text = range.get("text").toString();
|
|
|
- break;
|
|
|
+ groupLists.add(groupResults);
|
|
|
+ }
|
|
|
+ String text = null;
|
|
|
+ Map<String, Object> calculate = (Map<String, Object>) data.get("calculate");
|
|
|
+ List<Map<String, Object>> rangeList = (List<Map<String, Object>>) calculate.get("range");
|
|
|
+ for (Map<String, Object> range : rangeList) {
|
|
|
+ Double max = Double.valueOf(range.get("max").toString());
|
|
|
+ Double min = Double.valueOf(range.get("min").toString());
|
|
|
+ if (sum >= min && sum <= max) {
|
|
|
+ text = range.get("text").toString();
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- scaleCalcResult.put("scaleName", scaleName);
|
|
|
- scaleCalcResult.put("group", groupLists);
|
|
|
+ scaleCalcResult.put("scaleName", scaleName);
|
|
|
+ scaleCalcResult.put("group", groupLists);
|
|
|
|
|
|
- JSONObject calcalculate = new JSONObject();
|
|
|
- JSONObject result = new JSONObject();
|
|
|
- result.put("text", text);
|
|
|
- //TODO 根据数字类型给出结果
|
|
|
- result.put("value", sum);
|
|
|
- calcalculate.put("result", result);
|
|
|
- scaleCalcResult.put("calcalculate", calcalculate);
|
|
|
+ JSONObject calcalculate = new JSONObject();
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ result.put("text", text);
|
|
|
+ //TODO 根据数字类型给出结果
|
|
|
+ result.put("value", sum);
|
|
|
+ calcalculate.put("result", result);
|
|
|
+ scaleCalcResult.put("calcalculate", calcalculate);
|
|
|
+ }else {
|
|
|
+ scaleCalcResult.put("errMsg","量表类型错误。");
|
|
|
+ }
|
|
|
return scaleCalcResult;
|
|
|
}
|
|
|
|