|
|
@@ -28,6 +28,7 @@ import com.zhongzheng.modules.alioss.service.OssService;
|
|
|
import com.zhongzheng.modules.bank.domain.*;
|
|
|
import com.zhongzheng.modules.bank.mapper.QuestionMapper;
|
|
|
import com.zhongzheng.modules.bank.service.*;
|
|
|
+import com.zhongzheng.modules.bank.vo.QuestionAnswerVo;
|
|
|
import com.zhongzheng.modules.base.domain.*;
|
|
|
import com.zhongzheng.modules.base.service.*;
|
|
|
import com.zhongzheng.modules.course.bo.*;
|
|
|
@@ -376,6 +377,8 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
|
|
// goods.setSpecTemplateId(relation.getSpecTemplateId());
|
|
|
// }
|
|
|
// }
|
|
|
+ List<Question> questionAnswer = baseMapper.getQuestionAnswer(goods.getGoodsId());
|
|
|
+ goods.setIsQuestionAnswer(CollectionUtils.isNotEmpty(questionAnswer)?1:0);
|
|
|
//多规格下的价格区间
|
|
|
if (ObjectUtils.isNotNull(goods.getSpecTemplateId())) {
|
|
|
List<GoodsSpecAttributeRelation> specAttributeRelations = goodsSpecAttributeRelationService
|
|
|
@@ -5888,6 +5891,92 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<QuestionAnswerVo> getQuestionAnswer(Long goodsId) {
|
|
|
+ Goods goods = getById(goodsId);
|
|
|
+ if (ObjectUtils.isNull(goods)){
|
|
|
+ throw new CustomException("获取商品信息失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取题库
|
|
|
+ List<Question> questions = baseMapper.getQuestionAnswer(goodsId);
|
|
|
+ if (CollectionUtils.isEmpty(questions)){
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ List<QuestionAnswerVo> answerVos = questions.stream().map(item -> {
|
|
|
+ QuestionAnswerVo vo = new QuestionAnswerVo();
|
|
|
+ vo.setQuestionName(htmlToTextSimple(item.getContent()));
|
|
|
+ switch (item.getType()) {
|
|
|
+ case 1: //单选
|
|
|
+ vo.setAnswer(answerTransition(item.getAnswerQuestion()));
|
|
|
+ break;
|
|
|
+ case 2: //多选
|
|
|
+ vo.setAnswer(answerTransition(item.getAnswerQuestion()));
|
|
|
+ break;
|
|
|
+ case 3: //判断
|
|
|
+ vo.setAnswer(item.getAnswerQuestion().equals("1") ? "正确" : "错误");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return answerVos;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String htmlToTextSimple(String html) {
|
|
|
+ if (html == null) return "";
|
|
|
+
|
|
|
+ // 去除常见HTML标签
|
|
|
+ String text = html
|
|
|
+ .replaceAll("<p>", "")
|
|
|
+ .replaceAll("</p>", "")
|
|
|
+ .replaceAll("<div>", "")
|
|
|
+ .replaceAll("</div>", "")
|
|
|
+ .replaceAll("<br>", "\n")
|
|
|
+ .replaceAll("<br/>", "\n")
|
|
|
+ .replaceAll("<br />", "\n");
|
|
|
+
|
|
|
+ // 去除HTML实体
|
|
|
+ text = text
|
|
|
+ .replaceAll(" ", " ")
|
|
|
+ .replaceAll("&", "&")
|
|
|
+ .replaceAll("<", "<")
|
|
|
+ .replaceAll(">", ">")
|
|
|
+ .replaceAll(""", "\"");
|
|
|
+
|
|
|
+ return text.trim();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String answerTransition(String answer){
|
|
|
+ List<String> list = Arrays.asList(answer.split(","));
|
|
|
+ String collect = list.stream().map(x -> {
|
|
|
+ String mm = "";
|
|
|
+ switch (x) {
|
|
|
+ case "1":
|
|
|
+ mm = "A";
|
|
|
+ break;
|
|
|
+ case "2":
|
|
|
+ mm = "B";
|
|
|
+ break;
|
|
|
+ case "3":
|
|
|
+ mm = "C";
|
|
|
+ break;
|
|
|
+ case "4":
|
|
|
+ mm = "D";
|
|
|
+ break;
|
|
|
+ case "5":
|
|
|
+ mm = "E";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ mm = "";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return mm;
|
|
|
+ }).collect(Collectors.joining(","));
|
|
|
+ return collect;
|
|
|
+ }
|
|
|
|
|
|
private void updateHandoutsId(Long goodsId, Long tenantId, Long handoutsId) {
|
|
|
baseMapper.updateHandoutsId(goodsId, tenantId, handoutsId);
|