Commit 92afa3a05c3aba9422275ccfe7a27c5fff9dfc1a

Authored by shixianjie
1 parent 7eb90a5ec1
Exists in master

作业反馈

app/src/main/java/com/hjx/parent/HomeworkFeedbackActivity.java
1 1 package com.hjx.parent;
2 2  
  3 +import android.annotation.SuppressLint;
3 4 import android.os.Bundle;
4 5 import android.view.View;
5 6 import android.widget.ImageView;
6 7 import android.widget.RadioButton;
  8 +import android.widget.Toast;
7 9  
8 10 import androidx.annotation.NonNull;
9 11 import androidx.annotation.Nullable;
... ... @@ -12,20 +14,30 @@ import com.bumptech.glide.Glide;
12 14 import com.chad.library.adapter.base.BaseQuickAdapter;
13 15 import com.chad.library.adapter.base.BaseViewHolder;
14 16 import com.google.android.flexbox.FlexboxLayoutManager;
  17 +import com.google.gson.Gson;
15 18 import com.hjx.parent.databinding.ActivityHomeworkFeedbackBinding;
16 19 import com.hjx.parent.rx.BaseRxActivity;
17 20 import com.prws.common.bean.Student;
  21 +import com.prws.common.bean.homework.Correction;
  22 +import com.prws.common.bean.homework.CorrectionPoint;
18 23 import com.prws.common.bean.homework.HomeWork;
19 24 import com.prws.common.bean.homework.HomeworkList;
  25 +import com.prws.common.bean.homework.KeyValue;
  26 +import com.prws.common.net.NetWorks;
20 27  
21 28 import java.text.DecimalFormat;
22 29 import java.util.ArrayList;
  30 +import java.util.HashMap;
  31 +import java.util.HashSet;
23 32 import java.util.List;
  33 +import java.util.Map;
  34 +import java.util.Set;
24 35  
25 36 public class HomeworkFeedbackActivity extends BaseRxActivity<ActivityHomeworkFeedbackBinding> {
26 37 private Student student;
27 38 private HomeworkList mData;
28 39 private ArrayList<HomeWork> mList;
  40 + private List<Correction> corrections = new ArrayList<>();
29 41  
30 42 @SuppressWarnings("unchecked")
31 43 @Override
... ... @@ -41,7 +53,9 @@ public class HomeworkFeedbackActivity extends BaseRxActivity&lt;ActivityHomeworkFee
41 53 List<HomeWork> errorList = new ArrayList<>();
42 54 int correctNo = 0;
43 55 for (HomeWork homeWork: mList) {
44   - homeWork.homeworkId = mData.getId();
  56 + homeWork.state = 1;
  57 + homeWork.index = mList.indexOf(homeWork);
  58 + corrections.add(new Correction(homeWork.brief, homeWork.check ? 1 : 0));
45 59 if (!homeWork.check) correctNo ++;
46 60 else errorList.add(homeWork);
47 61 }
... ... @@ -51,8 +65,99 @@ public class HomeworkFeedbackActivity extends BaseRxActivity&lt;ActivityHomeworkFee
51 65 binding.rvCorrect.setAdapter(new NumberAdapter(mList));
52 66 binding.rvError.setVisibility(errorList.isEmpty() ? View.GONE : View.VISIBLE);
53 67 binding.rvError.setAdapter(new EvalAdapter(errorList));
  68 +
  69 + binding.btnPublish.setOnClickListener(v -> submit());
  70 + }
  71 +
  72 + @SuppressLint("CheckResult")
  73 + private void submit() {
  74 + Map<String, Object> body = new HashMap<>();
  75 + body.put("homeworkId", mData.getId());
  76 + body.put("comment", binding.etComment.getText().toString());
  77 + body.put("stuId", student.stuId);
  78 + body.put("points", countPoint());
  79 + body.put("correctionList", corrections);
  80 + NetWorks.service_url.uploadHomeworkFeedback(NetWorks.getHeader(), body)
  81 + .compose(transformSingle())
  82 + .subscribe((response, th) -> {
  83 + if (th != null) th.printStackTrace();
  84 + if (response != null && response.getSuccess()) {
  85 + // TODO
  86 + Toast.makeText(this, "反馈成功", Toast.LENGTH_SHORT).show();
  87 + }
  88 + });
54 89 }
55 90  
  91 + @SuppressLint("CheckResult")
  92 + private List<CorrectionPoint> countPoint() {
  93 + Set<KeyValue> set = new HashSet<>();
  94 + Map<String, Integer> totalTimes = new HashMap<>();
  95 + Map<String, Integer> correctTimes = new HashMap<>();
  96 + Map<String, Integer> underTimes = new HashMap<>();
  97 + Map<String, Integer> baseTimes = new HashMap<>();
  98 + Map<String, Integer> normalTimes = new HashMap<>();
  99 + Gson gson = new Gson();
  100 + for (HomeWork homeWork: mList) {
  101 + homeWork.formatPoints(gson);
  102 +
  103 + set.addAll(homeWork.pointsObj);
  104 + for (KeyValue keyValue: homeWork.pointsObj) {
  105 + String key = keyValue.Key;
  106 + if (totalTimes.containsKey(key)) {
  107 + totalTimes.put(key, totalTimes.get(key) + 1);
  108 + } else {
  109 + totalTimes.put(key, 1);
  110 + }
  111 + if (!homeWork.check) {
  112 + if (correctTimes.containsKey(key)) {
  113 + correctTimes.put(key, correctTimes.get(key) + 1);
  114 + } else {
  115 + correctTimes.put(key, 1);
  116 + }
  117 + } else if (homeWork.state == 1) {
  118 + if (underTimes.containsKey(key)) {
  119 + underTimes.put(key, underTimes.get(key) + 1);
  120 + } else {
  121 + underTimes.put(key, 1);
  122 + }
  123 + } else if (homeWork.state == 2) {
  124 + if (baseTimes.containsKey(key)) {
  125 + baseTimes.put(key, baseTimes.get(key) + 1);
  126 + } else {
  127 + baseTimes.put(key, 1);
  128 + }
  129 + } else if (homeWork.state == 3) {
  130 + if (normalTimes.containsKey(key)) {
  131 + normalTimes.put(key, normalTimes.get(key) + 1);
  132 + } else {
  133 + normalTimes.put(key, 1);
  134 + }
  135 + }
  136 + }
  137 + }
  138 + List<CorrectionPoint> points = new ArrayList<>();
  139 + for (KeyValue obj: set) {
  140 + CorrectionPoint point = new CorrectionPoint();
  141 + point.pointId = obj.Key;
  142 + point.pointName = obj.Value;
  143 + point.totalCount = ifNull(totalTimes.get(obj.Key), 1);
  144 + point.correctCount = ifNull(correctTimes.get(obj.Key), 0);
  145 + point.understandCount = ifNull(underTimes.get(obj.Key), 0);
  146 + point.basicCount = ifNull(baseTimes.get(obj.Key), 0);
  147 + point.normalCount = ifNull(normalTimes.get(obj.Key), 0);
  148 +
  149 + points.add(point);
  150 + }
  151 +
  152 + return points;
  153 + }
  154 +
  155 + private int ifNull(Integer src, int defaultVal) {
  156 + if (src == null) return defaultVal;
  157 + else return src;
  158 + }
  159 +
  160 +
56 161 @Override
57 162 protected ActivityHomeworkFeedbackBinding getViewBinding() {
58 163 return ActivityHomeworkFeedbackBinding.inflate(getLayoutInflater());
... ...
libs/common/src/main/java/com/prws/common/bean/homework/Correction.java
... ... @@ -0,0 +1,16 @@
  1 +package com.prws.common.bean.homework;
  2 +
  3 +public class Correction {
  4 +
  5 + public String brief;
  6 +
  7 + public int correction; // 0 对, 1 错
  8 +
  9 + public Correction() {
  10 + }
  11 +
  12 + public Correction(String brief, int correction) {
  13 + this.brief = brief;
  14 + this.correction = correction;
  15 + }
  16 +}
... ...
libs/common/src/main/java/com/prws/common/bean/homework/CorrectionPoint.java
... ... @@ -0,0 +1,38 @@
  1 +package com.prws.common.bean.homework;
  2 +
  3 +public class CorrectionPoint {
  4 + /**
  5 + * 知识点id
  6 + */
  7 + public String pointId;
  8 +
  9 + /**
  10 + * 知识点名称
  11 + */
  12 + public String pointName;
  13 +
  14 + /**
  15 + * 知识点出现次数
  16 + */
  17 + public Integer totalCount;
  18 +
  19 + /**
  20 + * 知识点正确次数
  21 + */
  22 + public Integer correctCount;
  23 +
  24 + /**
  25 + * 知识点听懂次数
  26 + */
  27 + public Integer understandCount;
  28 +
  29 + /**
  30 + * 知识点基本听懂次数
  31 + */
  32 + public Integer basicCount;
  33 +
  34 + /**
  35 + * 知识点一般听懂次数
  36 + */
  37 + public Integer normalCount;
  38 +}
... ...
libs/common/src/main/java/com/prws/common/bean/homework/HomeWork.java
1 1 package com.prws.common.bean.homework;
2 2  
  3 +import com.google.gson.Gson;
3 4 import com.google.gson.annotations.SerializedName;
  5 +import com.google.gson.reflect.TypeToken;
4 6  
5 7 import java.io.Serializable;
  8 +import java.util.ArrayList;
  9 +import java.util.List;
6 10  
7 11 public class HomeWork implements Serializable {
8 12  
... ... @@ -16,8 +20,22 @@ public class HomeWork implements Serializable {
16 20 public String answer;
17 21 public String points;
18 22  
19   - public boolean check = false;
  23 + public boolean check = false; //选中为错题
20 24 public transient int index = 0;
21 25 public transient int state = 1;
22 26  
  27 + public transient List<KeyValue> pointsObj;
  28 + public void formatPoints(Gson gson) {
  29 + if (points == null) {
  30 + pointsObj = new ArrayList<>();
  31 + return;
  32 + }
  33 + try {
  34 + pointsObj = gson.fromJson(points, new TypeToken<List<KeyValue>>(){}.getType());
  35 + } catch (Exception e) {
  36 + e.printStackTrace();
  37 + pointsObj = new ArrayList<>();
  38 + }
  39 + }
  40 +
23 41 }
... ...
libs/common/src/main/java/com/prws/common/bean/homework/KeyValue.java
... ... @@ -0,0 +1,22 @@
  1 +package com.prws.common.bean.homework;
  2 +
  3 +import java.util.Objects;
  4 +
  5 +public class KeyValue {
  6 + public String Key;
  7 + public String Value;
  8 +
  9 + @Override
  10 + public boolean equals(Object o) {
  11 + if (this == o) return true;
  12 + if (o == null || getClass() != o.getClass()) return false;
  13 + KeyValue keyValue = (KeyValue) o;
  14 + return Objects.equals(Key.toUpperCase(), keyValue.Key.toUpperCase());
  15 + }
  16 +
  17 + @Override
  18 + public int hashCode() {
  19 + return Objects.hash(Key.toUpperCase());
  20 + }
  21 +
  22 +}
... ...
libs/common/src/main/java/com/prws/common/net/NetWorks.java
... ... @@ -202,6 +202,9 @@ public class NetWorks extends RetrofitUtils {
202 202 @GET("api/v1/homework/listHomeworkById")
203 203 Single<ResponseResult<List<HomeWork>>> getHomeworkDetail(@Header("Authorization") String token, @Query("homeworkId") String homeworkId);
204 204  
  205 + @POST("api/v1/homework/uploadHomeworkFeedback")
  206 + Single<ResponseResult> uploadHomeworkFeedback(@Header("Authorization") String token, @Body Map<String, Object> map);
  207 +
205 208 }
206 209  
207 210 public static String getUserId() {
... ...