Commit f451ce8d by 刘鹏

feat: 请求题库、答题完成

parent 130b6b88
......@@ -314,27 +314,27 @@ public class YDLMessageFragment extends TFragment implements ModuleProxy {
if (ChatStatusCacheHelper.getStatusCache("collectEvent")) {
String time = Calendar.getInstance().get(Calendar.YEAR) + "-" + Calendar.getInstance().get(Calendar.MONTH) + Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
if (!TextUtils.equals(time, SharedPreferencesEditor.getString("skip_time_" + ImIn.INSTANCE.getUserInfo().getUid()))) {
// collectInfoPopupWindow = new CollectInfoPopupWindow(getActivity(), new CollectInfoPopupWindow.OnSendMsgListener() {
// @Override
// public void sendMsg(@NotNull String content, @NotNull List<QuestionsInfoBean> result) {
// if (TextUtils.isEmpty(content)) {//点击跳过后当天不再显示此弹窗
// SharedPreferencesEditor.putString("skip_time_" + ImIn.INSTANCE.getUserInfo().getUid()
// , time);
// } else {
// IMMessage textMessage = MessageBuilder.createTextMessage(sessionId, sessionType, content);
// if (sendMessage(textMessage)) {
// openOrCloseCommonQuestionLayout(false);
// }
//// submitUserCollect(result);
// }
// }
//
// @Override
// public void finishPage() {
// getActivity().finish();
// }
// });
// if (!TextUtils.equals(time, SharedPreferencesEditor.getString("skip_time_" + ImIn.INSTANCE.getUserInfo().getUid()))) {
collectInfoPopupWindow = new CollectInfoPopupWindow(getActivity(), new CollectInfoPopupWindow.OnSendMsgListener() {
@Override
public void sendMsg(@NotNull String content, @NotNull List<? extends QuestionsInfoBean> result) {
if (TextUtils.isEmpty(content)) {//点击跳过后当天不再显示此弹窗
SharedPreferencesEditor.putString("skip_time_" + ImIn.INSTANCE.getUserInfo().getUid()
, time);
} else {
IMMessage textMessage = MessageBuilder.createTextMessage(sessionId, sessionType, content);
if (sendMessage(textMessage)) {
openOrCloseCommonQuestionLayout(false);
}
// submitUserCollect(result);
}
}
@Override
public void finishPage() {
getActivity().finish();
}
});
getUserInfoCollect();
if (!getActivity().isFinishing()) {
try {
......@@ -344,7 +344,7 @@ public class YDLMessageFragment extends TFragment implements ModuleProxy {
}
collectInfoPopupWindow.show(top_expert_info_cl);
}
}
// }
ChatStatusCacheHelper.clearDataByKey("collectEvent");
}
}
......@@ -1408,22 +1408,22 @@ public class YDLMessageFragment extends TFragment implements ModuleProxy {
@SuppressLint("CheckResult")
private void getUserInfoCollect() {
ServiceImpl.Companion.getInstance().userCollectList()
ServiceImpl.Companion.getInstance().preExamQuestionPaper()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(resp -> {
if (resp.data != null && resp.data.size() > 0) {
if (resp.data != null ) {
ServiceImpl.Companion.getInstance().getNewUserMes(new NewUserMesBean(""))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(hasCollectedInResp -> {
if (hasCollectedInResp.data != null && hasCollectedInResp.data.size() > 0) {
// collectInfoPopupWindow.setData(resp.data, hasCollectedInResp.data);
collectInfoPopupWindow.setData(resp.data);
} else {
// collectInfoPopupWindow.setData(resp.data, null);
collectInfoPopupWindow.setData(resp.data);
}
}, throwable -> {
// collectInfoPopupWindow.setData(resp.data, null);
collectInfoPopupWindow.setData(resp.data);
});
} else {
collectInfoPopupWindow.dismiss();
......
......@@ -56,7 +56,6 @@ class CollectInfoPopupWindow(var mContext: Activity, var listener: OnSendMsgList
isOutsideTouchable = false
}
@RequiresApi(Build.VERSION_CODES.N)
fun setData(questionInfo: QuestionsInfoBean) {
collectUserInformationView.setData(questionInfo)
}
......
......@@ -3,7 +3,6 @@ package com.yidianling.uikit.business.session.view
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.os.Build
import android.os.Handler
import android.text.Editable
import android.text.TextUtils
......@@ -14,19 +13,21 @@ import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import android.widget.LinearLayout
import androidx.annotation.RequiresApi
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.fastjson.JSON
import com.ydl.ydlcommon.utils.Utils
import com.ydl.ydlcommon.view.dialog.CommonDialog
import com.yidianling.im.R
import com.yidianling.im.router.ImIn
import com.yidianling.listener.SoftKeyBoardListener
import com.yidianling.uikit.business.session.view.question.QuestionAdapter
import com.yidianling.uikit.business.session.view.question.QuestionMultiItem
import com.yidianling.uikit.business.session.view.question.QuestionOneCheckListener
import com.yidianling.uikit.custom.http.response.question.OptionsBean
import com.yidianling.uikit.custom.http.response.question.QuestionsBean
import com.yidianling.uikit.custom.http.response.question.QuestionsInfoBean
import com.yidianling.uikit.custom.http.ServiceImpl.Companion.instance
import com.yidianling.uikit.custom.http.response.question.*
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.im_view_question_infomation.view.*
import java.util.*
import kotlin.collections.ArrayList
......@@ -52,6 +53,7 @@ class QuestionInformationView(
private var mData = ArrayList<QuestionMultiItem>();
private var mQuestionBean: QuestionsInfoBean? = null
private var problemContent = ""
private var answerQuestionId = ""
init {
val params = LayoutParams(
......@@ -76,19 +78,31 @@ class QuestionInformationView(
mQuestionAdapter = QuestionAdapter(mData)
recycle.adapter = mQuestionAdapter
mQuestionAdapter.setOneCheckListener(object : QuestionOneCheckListener {
override fun itemClick(bean: OptionsBean?, question: QuestionsBean) {
override fun itemClick(list: List<OptionsBean>?, question: QuestionsBean) {
var anwserStr = ""
list?.forEach {
if (anwserStr.isNotEmpty()) {
anwserStr = anwserStr + "、" + it?.name
} else {
anwserStr += it?.name
}
}
//发送回答问题信息
val questionMultiItem = QuestionMultiItem()
questionMultiItem.type2Text = bean?.name
questionMultiItem.type2Text = anwserStr
questionMultiItem.viewType = 2
mData.add(questionMultiItem)
mQuestionAdapter.notifyDataSetChanged()
//回答问题
list?.let { anserOneChek(question, it, "") }
recycle.scrollToPosition(mData.size - 1)
val questionMultiItem2 = QuestionMultiItem()
// 使用问题questionId 去questionChains取到选项配置
val options = mQuestionBean!!.questionPaper.questionChains[question.id]?.options
//从配置里找到下一题id
val nextQuestionId = options?.get(bean?.id)
val nextQuestionId = options?.get(list?.get(0)?.id)
//使用下一题nextQuestionId 取到题
val questionsBean = mQuestionBean!!.questionPaper.questions[nextQuestionId]
......@@ -130,7 +144,7 @@ class QuestionInformationView(
}
override fun moreDefineItemClick(list: List<OptionsBean?>?, question: QuestionsBean) {
override fun moreDefineItemClick(list: List<OptionsBean>?, question: QuestionsBean) {
//多选确定
var anwserStr = ""
list?.forEach {
......@@ -140,13 +154,18 @@ class QuestionInformationView(
anwserStr += it?.name
}
}
//创建回答消息
val bean = list?.get(0)
val questionMultiItem = QuestionMultiItem()
questionMultiItem.type2Text = anwserStr
questionMultiItem.viewType = 2
mData.add(questionMultiItem)
mQuestionAdapter.notifyDataSetChanged()
//回答问题
list?.let { anserOneChek(question, it, "") }
//寻找下一题
recycle.scrollToPosition(mData.size - 1)
val questionMultiItem2 = QuestionMultiItem()
// 使用问题questionId 去questionChains取到选项配置
......@@ -247,17 +266,92 @@ class QuestionInformationView(
}
/**
* 回答单选问题
* @param question 问题
* @param list 选中回答的选项list
* @param otherInput 其他输入的内容
* */
@SuppressLint("CheckResult")
private fun anserOneChek(
question: QuestionsBean,
list: List<OptionsBean>,
otherInput: String
) {
val answerQuestionRequestBean = AnswerQuestionRequestBean()
answerQuestionRequestBean.examId = answerQuestionId
answerQuestionRequestBean.questionId = question.id
answerQuestionRequestBean.questionPaperId = question.questionPaperId
answerQuestionRequestBean.uid = ImIn.getUserInfo()?.uid
var answersBeanList = ArrayList<AnswersBean>()
for (optionsBean in list) {
var answersBean = AnswersBean()
answersBean.name = optionsBean.name
answersBean.optionId = optionsBean.id
answersBean.relates = optionsBean.relates
if ("其他" == optionsBean.name && otherInput.isNotEmpty()) {
answersBean.other = otherInput
}
answersBeanList.add(answersBean)
}
answerQuestionRequestBean.answers = answersBeanList
instance.answerQuestion(answerQuestionId, JSON.toJSONString(answerQuestionRequestBean))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe()
}
@SuppressLint("ClickableViewAccessibility")
@RequiresApi(Build.VERSION_CODES.N)
fun setData(questionInfo: QuestionsInfoBean) {
mQuestionBean = questionInfo
//设置数据,清空list数据
mData.clear()
//取到问候语
getFirstQuestion(questionInfo)
//取出第二条消息
setSecondQuestion()
//设置view事件
addVIewListener()
createExams()
}
@SuppressLint("CheckResult")
private fun createExams() {
val createExamsRequestBean =
CreateExamsRequestBean()
createExamsRequestBean.name = mQuestionBean?.questionPaper?.name
createExamsRequestBean.questionPaperId = mQuestionBean?.questionPaper?.id
createExamsRequestBean.type = "first_entry_lingxi"
createExamsRequestBean.uid = ImIn.getUserInfo()?.uid
instance.createEexams(JSON.toJSONString(createExamsRequestBean))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ resp ->
answerQuestionId = resp.data
}, { throwable ->
})
}
/***取到问候语*/
private fun getFirstQuestion(questionInfo: QuestionsInfoBean) {
val questionMultiItem = QuestionMultiItem()
questionMultiItem.type1Text = questionInfo.questions[0].question
questionMultiItem.viewType = 1
mData.add(questionMultiItem)
mQuestionAdapter.notifyDataSetChanged()
}
/***问候语之后第一道题*/
private fun setSecondQuestion() {
val questionMultiItem2 = QuestionMultiItem()
mQuestionBean!!.questionPaper.questionChains.forEach { (k, v) ->
if (v.head) {
......@@ -271,9 +365,15 @@ class QuestionInformationView(
questionMultiItem2.type4CanClick = true
}
mData.add(questionMultiItem2)
mQuestionAdapter.notifyDataSetChanged()
return@forEach
}
}
}
/**添加view事件*/
private fun addVIewListener() {
tv_send.setOnClickListener {
et_input_problem.setText("")
hideInputMethod(et_input_problem)
......@@ -315,16 +415,16 @@ class QuestionInformationView(
if (char.contains("\n")) {
val s = char.toString().replace("\n", "")
if (TextUtils.isEmpty(s)) {
tv_send.visibility = View.GONE
tv_send.visibility = GONE
et_input_problem.setText("")
} else {
tv_send.visibility = View.VISIBLE
tv_send.visibility = VISIBLE
}
} else {
tv_send.visibility = View.VISIBLE
tv_send.visibility = VISIBLE
}
} else {
tv_send.visibility = View.GONE
tv_send.visibility = GONE
}
}
......@@ -357,7 +457,6 @@ class QuestionInformationView(
}
}
}
}
......
......@@ -215,7 +215,9 @@ public class QuestionAdapter extends BaseMultiItemQuickAdapter<QuestionMultiItem
}
oneCheckAdapter.getData().get(position).check = true;
oneCheckAdapter.notifyDataSetChanged();
mOneCheckListener.itemClick(data.get(position), item.questionsBean);
List<OptionsBean> list = new ArrayList();
list.add(data.get(position));
mOneCheckListener.itemClick(list, item.questionsBean);
}
}
});
......@@ -225,7 +227,7 @@ public class QuestionAdapter extends BaseMultiItemQuickAdapter<QuestionMultiItem
List<OptionsBean> data = moreCheckAdapter.getData();
List<OptionsBean> checkList = new ArrayList();
for (OptionsBean datum : data) {
if (datum.check && !("其他".equals(datum.name))) {
if (datum.check) {
checkList.add(datum);
}
}
......
......@@ -7,12 +7,12 @@ interface QuestionOneCheckListener {
/**
* 单选点击获取item信息
*/
fun itemClick(bean: OptionsBean?, question: QuestionsBean)
fun itemClick(bean: List<OptionsBean>?, question: QuestionsBean)
/**
* 多选确定按钮点击
*/
fun moreDefineItemClick(list: List<OptionsBean?>?, question: QuestionsBean)
fun moreDefineItemClick(list: List<OptionsBean>?, question: QuestionsBean)
/**
* 展示其他
......
......@@ -4,6 +4,7 @@ import com.ydl.ydlcommon.base.config.YDL_DOMAIN
import com.ydl.ydlcommon.base.config.YDL_DOMAIN_JAVA
import com.ydl.ydlcommon.data.http.BaseAPIResponse
import com.yidianling.uikit.custom.http.response.*
import com.yidianling.uikit.custom.http.response.question.QuestionsInfoBean
import io.reactivex.Observable
import okhttp3.RequestBody
import retrofit2.http.*
......@@ -67,7 +68,10 @@ interface ServiceApi {
//关注
@GET("consult/expert-page/toggle-follow")
@Headers(YDL_DOMAIN + YDL_DOMAIN_JAVA)
fun focus(@Query("doctorId") doctorId: String, @Query("status") status: String): Observable<BaseAPIResponse<Any>>
fun focus(
@Query("doctorId") doctorId: String,
@Query("status") status: String
): Observable<BaseAPIResponse<Any>>
//服务列表
@GET("consult/expert-page/nproducts")
......@@ -84,6 +88,30 @@ interface ServiceApi {
@GET("chat/get-source-doctor")
@Headers(YDL_DOMAIN + YDL_DOMAIN_JAVA)
//注意:这个接口返回的还有很多字段,但是暂时不需要,就先取这两个字段
fun getSourceDoctor(@Query("scene") scene: Int,@Query("userUid") userUid: String,@Query("assistantUid") assistantUid: String): Observable<BaseAPIResponse<SourceDoctorInfoBean>>
fun getSourceDoctor(
@Query("scene") scene: Int,
@Query("userUid") userUid: String,
@Query("assistantUid") assistantUid: String
): Observable<BaseAPIResponse<SourceDoctorInfoBean>>
//新版前置信息收集 客户端灵犀信息收集卡题库
@GET("cms/exam/api/v1/exams/lingxi/pre-exam-question-paper")
@Headers(YDL_DOMAIN + YDL_DOMAIN_JAVA)
//注意:这个接口返回的还有很多字段,但是暂时不需要,就先取这两个字段
fun preExamQuestionPaper(): Observable<BaseAPIResponse<QuestionsInfoBean>>
//创建答题信息
@POST("cms/exam/api/v1/exams")
@Headers(YDL_DOMAIN + YDL_DOMAIN_JAVA)
fun createEexams(@Body body: RequestBody): Observable<BaseAPIResponse<String>>
//答题
@POST("cms/exam/api/v1/exams/{id}/lingxi/answer-question")
@Headers(YDL_DOMAIN + YDL_DOMAIN_JAVA)
fun answerQuestion(
@Path("id") id: String,
@Body body: RequestBody
): Observable<BaseAPIResponse<String>>
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON
import com.ydl.ydlcommon.data.http.BaseAPIResponse
import com.ydl.ydlnet.YDLHttpUtils
import com.yidianling.uikit.custom.http.response.*
import com.yidianling.uikit.custom.http.response.question.QuestionsInfoBean
import io.reactivex.Observable
import okhttp3.MediaType
import okhttp3.RequestBody
......@@ -65,6 +66,13 @@ class ServiceImpl private constructor() {
}
/**
* 信息采集的问题新版
*/
fun preExamQuestionPaper(): Observable<BaseAPIResponse<QuestionsInfoBean>> {
return YDLHttpUtils.obtainApi(ServiceApi::class.java).preExamQuestionPaper()
}
/**
* 获取新用户收集的信息
*/
fun getNewUserMes(bean: NewUserMesBean): Observable<BaseAPIResponse<List<UserQuestInfoBean>>> {
......@@ -117,10 +125,36 @@ class ServiceImpl private constructor() {
/**
* 获取代运营关联的专家的信息
* 客户端灵犀信息收集卡题库
*/
fun getSourceDoctor(userUid: String, assistantUid: String): Observable<BaseAPIResponse<SourceDoctorInfoBean>> {
return YDLHttpUtils.obtainApi(ServiceApi::class.java).getSourceDoctor(1, userUid, assistantUid)
fun getSourceDoctor(
userUid: String,
assistantUid: String
): Observable<BaseAPIResponse<SourceDoctorInfoBean>> {
return YDLHttpUtils.obtainApi(ServiceApi::class.java)
.getSourceDoctor(1, userUid, assistantUid)
}
/**
* 创建答题信息
*/
fun createEexams(params: String): Observable<BaseAPIResponse<String>> {
val body = RequestBody.create(
MediaType.parse("application/json; charset=utf-8"),
params
) as RequestBody
return YDLHttpUtils.obtainApi(ServiceApi::class.java).createEexams(body)
}
/**
* 创建答题信息
*/
fun answerQuestion(id: String, params: String): Observable<BaseAPIResponse<String>> {
val body = RequestBody.create(
MediaType.parse("application/json; charset=utf-8"),
params
) as RequestBody
return YDLHttpUtils.obtainApi(ServiceApi::class.java).answerQuestion(id, body)
}
}
\ No newline at end of file
package com.yidianling.uikit.custom.http.response.question;
import com.yidianling.uikit.custom.http.response.question.RelatesBean;
import java.util.List;
/**
* 回答问题bean
*
* @author liupeng
*/
public class AnswerQuestionRequestBean {
/**
* questionPaperId : 601128023407726592
* type : adviser_pre_diagnosis
* name : 灵犀用户首次问诊信息收集卡
* dataId : 13131313
* uid : 1313
*/
public String examId;
public String questionPaperId;
public String uid;
public String questionId;
public List<AnswersBean> answers;
}
package com.yidianling.uikit.custom.http.response.question;
import java.util.List;
/**
* @author liupeng
*/
public class AnswersBean {
public String optionId;
public String name;
public String other;
public List<RelatesBean> relates;
}
package com.yidianling.uikit.custom.http.response.question;
public class CreateExamsRequestBean {
/**
* questionPaperId : 601128023407726592
* type : adviser_pre_diagnosis
* name : 灵犀用户首次问诊信息收集卡
* dataId : 13131313
* uid : 1313
*/
public String questionPaperId;
public String type;
public String name;
public String uid;
}
......@@ -14,13 +14,4 @@ public class OptionsBean {
public List<RelatesBean> relates;
public boolean check;
public static class RelatesBean {
/**
* category : 症状
* name : 幻觉
*/
public String category;
public String name;
}
}
package com.yidianling.uikit.custom.http.response.question;
import java.io.Serializable;
import java.util.List;
public class QuestionsBean {
public class QuestionsBean implements Serializable {
/**
* id : 601128318581870592
......
package com.yidianling.uikit.custom.http.response.question;
/**
* @author liupeng
*/
public class RelatesBean {
/**
* category : 症状
* name : 幻觉
*/
public String id;
public String category;
public String name;
public String score;
}
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