Commit 3616e775 by 霍志良

feat:im-灵犀2.0-回答问题接口

parent 5d070de9
...@@ -119,4 +119,9 @@ interface ImRetrofitApi { ...@@ -119,4 +119,9 @@ interface ImRetrofitApi {
@GET("consult/user/order/affirmComplete") @GET("consult/user/order/affirmComplete")
@Headers(YDL_DOMAIN + YDL_DOMAIN_JAVA) @Headers(YDL_DOMAIN + YDL_DOMAIN_JAVA)
fun affirmComplete( @Query("id") orderId: String): Observable<BaseAPIResponse<Any>> fun affirmComplete( @Query("id") orderId: String): Observable<BaseAPIResponse<Any>>
//回答问题接口
@POST("chat/sendCustomizeMessage")
@Headers(YDL_DOMAIN + YDL_DOMAIN_JAVA)
fun lingxiAnswerQuestion(@Body body: RequestBody): Observable<BaseAPIResponse<Any>>
} }
\ No newline at end of file
...@@ -11,46 +11,45 @@ import java.util.ArrayList; ...@@ -11,46 +11,45 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class CustomAttachLingxiWhichQuestion extends CustomAttachment { public class CustomAttachLingxiWhichQuestion extends CustomAttachment {
private final String XQUESTIONPAPERID = "xquestionPaperId";//试卷id private final String QUESTIONPAPERID = "questionPaperId";//试卷id
private final String XQUESTIONPAPERNAME = "xquestionPaperName";//试卷名称 private final String TYPE = "type";//选项类型:radio单选,check多选
private final String QUESTIONID = "questionId";//问题id private final String OPTIONS = "options";//选项
private final String QUESTIONTITLE = "questionTitle";//问题题目 private final String EXAMID="examId";//考试ID
private final String SELECTTYPE = "selectType";//选项类型:1单选,2多选 private final String ID="id";//id
private final String SELECTVALS = "selectVals";//选项 private final String NAME="name";//name
public String xquestionPaperId;
public String xquestionPaperName;
public String questionId;
public String questionTitle;
public String selectType;
public List<QuestionItemBean> selectVals;
public String questionPaperId;
public String type;
public List<QuestionItemBean> options;
public String examId;
public String id;
public String name;
public CustomAttachLingxiWhichQuestion() { public CustomAttachLingxiWhichQuestion() {
super(CustomAttachmentType.TYPE_LINGXI_WHICH_QUESTION); super(CustomAttachmentType.TYPE_LINGXI_WHICH_QUESTION);
} }
@Override @Override
protected void parseData(JSONObject data) { protected void parseData(JSONObject data) {
this.xquestionPaperId = data.getString(XQUESTIONPAPERID); this.questionPaperId = data.getString(QUESTIONPAPERID);
this.xquestionPaperName = data.getString(XQUESTIONPAPERNAME); this.type = data.getString(TYPE);
this.questionId = data.getString(QUESTIONID); this.examId = data.getString(EXAMID);
this.questionTitle = data.getString(QUESTIONTITLE); this.id = data.getString(ID);
this.selectType = data.getString(SELECTTYPE); this.name = data.getString(NAME);
LogUtil.e("aaaaa"+data.getString(SELECTVALS)); this.options=(ArrayList<QuestionItemBean>)JSON.parseArray(data.getString(OPTIONS), QuestionItemBean.class);
this.selectVals=(ArrayList<QuestionItemBean>)JSON.parseArray(data.getString(SELECTVALS), QuestionItemBean.class);
} }
@Override @Override
protected JSONObject packData() { protected JSONObject packData() {
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
data.put(XQUESTIONPAPERID, xquestionPaperId); data.put(QUESTIONPAPERID, questionPaperId);
data.put(XQUESTIONPAPERNAME, xquestionPaperName); data.put(TYPE,type);
data.put(QUESTIONID, questionId); data.put(OPTIONS, options);
data.put(QUESTIONTITLE, questionTitle); data.put(EXAMID, examId);
data.put(SELECTTYPE, selectType); data.put(ID, id);
data.put(SELECTVALS, selectVals); data.put(NAME, name);
return data; return data;
} }
......
...@@ -2,27 +2,28 @@ package com.yidianling.im.session.viewholder; ...@@ -2,27 +2,28 @@ package com.yidianling.im.session.viewholder;
import android.widget.TextView; import android.widget.TextView;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.google.gson.Gson;
import com.netease.nimlib.sdk.NIMClient; import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.RequestCallback; import com.netease.nimlib.sdk.RequestCallback;
import com.netease.nimlib.sdk.msg.MsgService; import com.netease.nimlib.sdk.msg.MsgService;
import com.netease.nimlib.sdk.msg.attachment.MsgAttachment; import com.netease.nimlib.sdk.msg.attachment.MsgAttachment;
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum; import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum;
import com.netease.nimlib.sdk.msg.model.IMMessage; import com.netease.nimlib.sdk.msg.model.IMMessage;
import com.ydl.ydlcommon.data.http.RxUtils;
import com.yidianling.common.tools.LogUtil; import com.yidianling.common.tools.LogUtil;
import com.yidianling.common.tools.ToastUtil;
import com.yidianling.im.R; import com.yidianling.im.R;
import com.yidianling.im.event.MultipleSelectedEvent; import com.yidianling.im.event.MultipleSelectedEvent;
import com.yidianling.im.http.ImRetrofitApi;
import com.yidianling.im.router.ImIn;
import com.yidianling.im.session.extension.CustomAttachLingxiWhichQuestion; import com.yidianling.im.session.extension.CustomAttachLingxiWhichQuestion;
import com.yidianling.im.session.extension.CustomAttachmentConfirmOrder;
import com.yidianling.im.session.extension.CustomAttachmentOrderStatus;
import com.yidianling.im.session.viewholder.adapter.AdapterLingxiMultipleChoice; import com.yidianling.im.session.viewholder.adapter.AdapterLingxiMultipleChoice;
import com.yidianling.im.session.viewholder.adapter.AdapterLingxiWhichQuestion; import com.yidianling.im.session.viewholder.adapter.AdapterLingxiWhichQuestion;
import com.yidianling.im.session.viewholder.bean.LingxiWhichQuestionBean; import com.yidianling.im.session.viewholder.bean.AnswerBean;
import com.yidianling.im.session.viewholder.bean.AnswersItem;
import com.yidianling.im.session.viewholder.bean.LingxiAnswerBean;
import com.yidianling.im.session.viewholder.bean.QuestionItemBean; import com.yidianling.im.session.viewholder.bean.QuestionItemBean;
import com.yidianling.nimbase.common.ui.recyclerview.adapter.BaseMultiItemFetchLoadAdapter; import com.yidianling.nimbase.common.ui.recyclerview.adapter.BaseMultiItemFetchLoadAdapter;
import com.yidianling.uikit.business.session.viewholder.MsgViewHolderBase; import com.yidianling.uikit.business.session.viewholder.MsgViewHolderBase;
...@@ -35,6 +36,11 @@ import java.util.List; ...@@ -35,6 +36,11 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import de.greenrobot.event.EventBus; import de.greenrobot.event.EventBus;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.RequestBody;
public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implements AdapterLingxiWhichQuestion.OnQuestionlItemClickListener, AdapterLingxiMultipleChoice.OnMultiplelItemClickListener { public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implements AdapterLingxiWhichQuestion.OnQuestionlItemClickListener, AdapterLingxiMultipleChoice.OnMultiplelItemClickListener {
private RecyclerView recycleviewWhichQuestion; private RecyclerView recycleviewWhichQuestion;
...@@ -51,6 +57,12 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -51,6 +57,12 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
private StringBuffer stringBuffer=new StringBuffer("已选:"); private StringBuffer stringBuffer=new StringBuffer("已选:");
ArrayList<String> selectedStr=new ArrayList<String>(); ArrayList<String> selectedStr=new ArrayList<String>();
private Boolean isClickable=true; private Boolean isClickable=true;
//回答试卷接口
private String examId;
private String questionPaperId;
private String questionId;
private ArrayList<AnswersItem> answersItems=new ArrayList<>();
public MsgViewHolderLingxiWhichQuestion(BaseMultiItemFetchLoadAdapter adapter) { public MsgViewHolderLingxiWhichQuestion(BaseMultiItemFetchLoadAdapter adapter) {
super(adapter); super(adapter);
} }
...@@ -58,17 +70,22 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -58,17 +70,22 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
@Override @Override
protected int getContentResId() { protected int getContentResId() {
customAttachLingxiWhichQuestion = ((CustomAttachLingxiWhichQuestion) message.getAttachment()); customAttachLingxiWhichQuestion = ((CustomAttachLingxiWhichQuestion) message.getAttachment());
switch (Integer.parseInt(customAttachLingxiWhichQuestion.selectType)){ if (customAttachLingxiWhichQuestion.type!=null){
case 1://您想要咨询下列哪类的问题?(单选) switch (customAttachLingxiWhichQuestion.type){
case "radio"://您想要咨询下列哪类的问题?(单选)
return R.layout.im_nim_lingxi_which_question; return R.layout.im_nim_lingxi_which_question;
// return R.layout.im_nim_lingxi_multiple_choice; // return R.layout.im_nim_lingxi_multiple_choice;
case 2://请问是发生了什么事情导致的呢?(多选) case "check"://请问是发生了什么事情导致的呢?(多选)
return R.layout.im_nim_lingxi_multiple_choice; return R.layout.im_nim_lingxi_multiple_choice;
case 3://您是先生还是女生 case "3"://您是先生还是女生
return R.layout.im_nim_lingxi_men_female; return R.layout.im_nim_lingxi_men_female;
default: default:
return R.layout.im_nim_lingxi_which_question; return R.layout.im_nim_lingxi_which_question;
} }
}else{
return R.layout.im_nim_lingxi_which_question;
}
} }
@Override @Override
...@@ -83,21 +100,26 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -83,21 +100,26 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
@Override @Override
protected void bindContentView() { protected void bindContentView() {
customAttachLingxiWhichQuestion = ((CustomAttachLingxiWhichQuestion) message.getAttachment()); customAttachLingxiWhichQuestion = ((CustomAttachLingxiWhichQuestion) message.getAttachment());
examId=customAttachLingxiWhichQuestion.examId;
questionPaperId=customAttachLingxiWhichQuestion.questionPaperId;
questionId=customAttachLingxiWhichQuestion.id;
//您想要咨询下列哪类的问题?(单选) //您想要咨询下列哪类的问题?(单选)
if (customAttachLingxiWhichQuestion.selectVals!=null){ if (customAttachLingxiWhichQuestion.options!=null){
questionList= (ArrayList<QuestionItemBean>) customAttachLingxiWhichQuestion.selectVals; questionList= (ArrayList<QuestionItemBean>) customAttachLingxiWhichQuestion.options;
} }
adapterLingxiWhichQuestion = new AdapterLingxiWhichQuestion(); adapterLingxiWhichQuestion = new AdapterLingxiWhichQuestion();
which_question_title.setText(customAttachLingxiWhichQuestion.xquestionPaperName); which_question_title.setText(customAttachLingxiWhichQuestion.name);
for (int i=0;i<questionList.size();i++){ for (int i=0;i<questionList.size();i++){
questionList.get(i).setSelected(false); questionList.get(i).setSelected(false);
if (questionList.get(i).getValue().length()>5){ if (questionList.get(i).getName().length()>5){
isSingleChoice=true; isSingleChoice=true;
break; break;
} }
} }
switch (Integer.parseInt(customAttachLingxiWhichQuestion.selectType)){ if (customAttachLingxiWhichQuestion.type!=null){
case 1://您想要咨询下列哪类的问题?(单选) switch (customAttachLingxiWhichQuestion.type){
case "radio"://您想要咨询下列哪类的问题?(单选)
if (questionList!=null&&questionList.size()!=0){ if (questionList!=null&&questionList.size()!=0){
adapterLingxiWhichQuestion.setTagData(questionList,isSingleChoice); adapterLingxiWhichQuestion.setTagData(questionList,isSingleChoice);
adapterLingxiWhichQuestion.setItemListener(this); adapterLingxiWhichQuestion.setItemListener(this);
...@@ -109,7 +131,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -109,7 +131,7 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
recycleviewWhichQuestion.setAdapter(adapterLingxiWhichQuestion); recycleviewWhichQuestion.setAdapter(adapterLingxiWhichQuestion);
} }
break; break;
case 2://请问是发生了什么事情导致的呢?(多选) case "check"://请问是发生了什么事情导致的呢?(多选)
// //请问是发生了什么事情导致的呢?(多选) // //请问是发生了什么事情导致的呢?(多选)
adapterLingxiMultipleChoice = new AdapterLingxiMultipleChoice(); adapterLingxiMultipleChoice = new AdapterLingxiMultipleChoice();
adapterLingxiMultipleChoice.setTagData(questionList); adapterLingxiMultipleChoice.setTagData(questionList);
...@@ -121,11 +143,13 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -121,11 +143,13 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
recycleviewMultipleChoice.setLayoutManager(multipleChoiceManager); recycleviewMultipleChoice.setLayoutManager(multipleChoiceManager);
recycleviewMultipleChoice.setAdapter(adapterLingxiMultipleChoice); recycleviewMultipleChoice.setAdapter(adapterLingxiMultipleChoice);
break; break;
case 3://您是先生还是女生 case "3"://您是先生还是女生
break; break;
default: default:
break; break;
} }
}
try { try {
Map<String, Object> map = message.getLocalExtension(); Map<String, Object> map = message.getLocalExtension();
if (map != null) { if (map != null) {
...@@ -162,11 +186,32 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -162,11 +186,32 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
} }
adapterLingxiWhichQuestion.setTagData(questionList,isSingleChoice); adapterLingxiWhichQuestion.setTagData(questionList,isSingleChoice);
isClickable=false; isClickable=false;
answersItems.add(new AnswersItem(questionList.get(position).getId(),
questionList.get(position).getName(),"其他",questionList.get(position).getRelates()));
//请求接口发送所选题目 //请求接口发送所选题目
answerLingxiQuestion(examId,questionPaperId, ImIn.INSTANCE.getUserInfo().getUid().toString(),questionId,answersItems);
//更新本地消息
updateLocalMsg(position); updateLocalMsg(position);
} }
} }
/*
* 用户回答问题接口
* */
private void answerLingxiQuestion(String examID , String questionPaperId, String uid, String questionId, ArrayList<AnswersItem> answersItems) {
String str = new Gson().toJson(new LingxiAnswerBean(new AnswerBean(examID,questionPaperId,uid,questionId,answersItems),message.getFromAccount(),"56",uid));
RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str);
Disposable subscribe = ImRetrofitApi.Companion.getImRetrofitApi().lingxiAnswerQuestion(body)
.compose(RxUtils.INSTANCE.resultJavaData())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(it -> {
LogUtil.e("answerQuestion"+it.toString());
}, throwable ->
LogUtil.e(throwable.getMessage())
);
}
@Override @Override
public void onMultipleItemClick(@NotNull QuestionItemBean string, int position) { public void onMultipleItemClick(@NotNull QuestionItemBean string, int position) {
//多选发送消息 //多选发送消息
...@@ -174,12 +219,12 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -174,12 +219,12 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
if (questionList.get(i).isSelected()){ if (questionList.get(i).isSelected()){
if (i==position){ if (i==position){
questionList.get(i).setSelected(false); questionList.get(i).setSelected(false);
selectedStr.remove(questionList.get(i).getValue()); selectedStr.remove(questionList.get(i).getName());
} }
}else{ }else{
if (i==position){ if (i==position){
questionList.get(i).setSelected(true); questionList.get(i).setSelected(true);
selectedStr.add(questionList.get(i).getValue()); selectedStr.add(questionList.get(i).getName());
} }
} }
} }
...@@ -210,10 +255,6 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -210,10 +255,6 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
for (IMMessage msg : param) { for (IMMessage msg : param) {
MsgAttachment attachment = msg.getAttachment(); MsgAttachment attachment = msg.getAttachment();
if (attachment instanceof CustomAttachLingxiWhichQuestion) { if (attachment instanceof CustomAttachLingxiWhichQuestion) {
CustomAttachLingxiWhichQuestion customattachlingxiwhichquestion = (CustomAttachLingxiWhichQuestion) attachment;
// if (customattachlingxiwhichquestion) {
//已经筛选过答案
//修改历史消息状态为已失效
Map map1 = msg.getLocalExtension(); Map map1 = msg.getLocalExtension();
if (map1 == null) { if (map1 == null) {
map1 = new HashMap(); map1 = new HashMap();
...@@ -224,7 +265,6 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen ...@@ -224,7 +265,6 @@ public class MsgViewHolderLingxiWhichQuestion extends MsgViewHolderBase implemen
//通知ui刷新 //通知ui刷新
getMsgAdapter().updateItemAtLocalExtension(msg); getMsgAdapter().updateItemAtLocalExtension(msg);
} }
// }
} }
} }
} }
......
...@@ -41,7 +41,7 @@ class AdapterLingxiMultipleChoice : RecyclerView.Adapter<AdapterLingxiMultipleCh ...@@ -41,7 +41,7 @@ class AdapterLingxiMultipleChoice : RecyclerView.Adapter<AdapterLingxiMultipleCh
} }
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.tvWhichQuestion.text=tagList[position].value holder.tvWhichQuestion.text=tagList[position].name
holder.tvWhichQuestion.setOnClickListener { holder.tvWhichQuestion.setOnClickListener {
onItemClickListener?.onMultipleItemClick( onItemClickListener?.onMultipleItemClick(
tagList[position], position tagList[position], position
......
...@@ -45,7 +45,7 @@ class AdapterLingxiWhichQuestion : RecyclerView.Adapter<AdapterLingxiWhichQuesti ...@@ -45,7 +45,7 @@ class AdapterLingxiWhichQuestion : RecyclerView.Adapter<AdapterLingxiWhichQuesti
} }
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.tvWhichQuestion.text = tagList[position].value holder.tvWhichQuestion.text = tagList[position].name
if (tagList[position].isSelected!!){ if (tagList[position].isSelected!!){
holder.tvWhichQuestion.background=ContextCompat.getDrawable(holder.itemView.context,R.drawable.im_background_18dp_1da1f2) holder.tvWhichQuestion.background=ContextCompat.getDrawable(holder.itemView.context,R.drawable.im_background_18dp_1da1f2)
holder.tvWhichQuestion.setTextColor(ContextCompat.getColor(holder.itemView.context,R.color.white)) holder.tvWhichQuestion.setTextColor(ContextCompat.getColor(holder.itemView.context,R.color.white))
......
package com.yidianling.im.session.viewholder.bean package com.yidianling.im.session.viewholder.bean
import com.google.gson.annotations.SerializedName
data class LingxiWhichQuestionBean( data class LingxiWhichQuestionBean(
var isSelected: Boolean, var isSelected: Boolean,
var xquestionPaperId: String?,//试卷ID var id: String?,//ID
var xquestionPaperName: String?,//试卷名称 var questionPaperId: String?,//试卷ID
var questionId:String?,//问题ID var name:String?,//问题题目
var questionTitle:String?,//问题题目 var type:String?,//试卷type radio单选,check 多选
var selectType:String?,//试卷type 1单选 2多选 var options:ArrayList<QuestionItemBean>?//选项
var selectVals:ArrayList<QuestionItemBean>?//选项
) )
data class QuestionItemBean( data class QuestionItemBean(
var id:String?, var id:String?,
var value:String?, var name:String?,
var isSelected: Boolean?=false var relates:ArrayList<Relates>?,
var isSelected: Boolean=false
)
//回答问题bean
data class LingxiAnswerBean(
var data:AnswerBean,
var fromUid:String,
var type:String,
var toUid:String
)
data class AnswerBean(
var examId:String,
var questionPaperId:String,
var uid:String,
var questionId:String,
var answers:ArrayList<AnswersItem>
)
data class AnswersItem(
var optionId:String,
var name: String,
var other:String,
var relates:ArrayList<Relates>
)
data class Relates(
var id: String?,
var category:String?,
var name: String?,
var score:String?
) )
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment