|
|
|
@ -2,7 +2,6 @@ package com.zdxt.knowledge.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import com.alibaba.druid.sql.visitor.functions.If; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
@ -13,6 +12,7 @@ import com.zdxt.auth.feign.FileUploadApi; |
|
|
|
import com.zdxt.auth.feign.RoleApi; |
|
|
|
import com.zdxt.auth.feign.UserApi; |
|
|
|
import com.zdxt.auth.feign.ZdxtFileCommonApi; |
|
|
|
import com.zdxt.common.ZDResponse; |
|
|
|
import com.zdxt.common.util.Convert; |
|
|
|
import com.zdxt.common.util.DateUtils; |
|
|
|
import com.zdxt.common.util.StringUtils; |
|
|
|
@ -42,7 +42,8 @@ import java.util.stream.Collectors; |
|
|
|
public class SceneQuestionServiceImpl implements ISceneQuestionService { |
|
|
|
@Autowired |
|
|
|
private SceneQuestionMapper sceneQuestionMapper; |
|
|
|
@Autowired private ISceneRoleService iSceneRoleService; |
|
|
|
@Autowired |
|
|
|
private ISceneRoleService iSceneRoleService; |
|
|
|
@Autowired |
|
|
|
private UserApi userApi; |
|
|
|
@Autowired |
|
|
|
@ -99,12 +100,15 @@ public class SceneQuestionServiceImpl implements ISceneQuestionService { |
|
|
|
* @return 结果 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public int editSceneQuestion(MultipartFile[] files, SceneQuestion sceneQuestion) { |
|
|
|
public ZDResponse editSceneQuestion(MultipartFile[] files, SceneQuestion sceneQuestion) { |
|
|
|
int result; |
|
|
|
if (ObjectUtil.isEmpty(files) || files.length > 1) { |
|
|
|
return -1; |
|
|
|
if (!ObjectUtil.isEmpty(files) && files.length > 1) { |
|
|
|
return ZDResponse.error("只允许上传一个视频"); |
|
|
|
} |
|
|
|
String uploadFilePath = null; |
|
|
|
if (!ObjectUtil.isEmpty(files) && files.length == 1) { |
|
|
|
uploadFilePath = fileUploadApi.upload(files[0]); |
|
|
|
} |
|
|
|
String uploadFilePath = fileUploadApi.upload(files[0]); |
|
|
|
UserBean userBean = userApi.getCurrentUser(); |
|
|
|
SceneQuestion questionEntity = sceneQuestionMapper.selectSceneQuestionById(sceneQuestion.getGuid()); |
|
|
|
if (Objects.isNull(questionEntity)) { |
|
|
|
@ -123,8 +127,13 @@ public class SceneQuestionServiceImpl implements ISceneQuestionService { |
|
|
|
zdxtFileCommonApi.deleteZdxtFileByIds(sceneQuestion.getGuid()); |
|
|
|
} |
|
|
|
// 上传文件,并在附件表中添加记录
|
|
|
|
zdxtFileCommonApi.insertZdxtFile(files[0], sceneQuestion.getGuid() + "", uploadFilePath); |
|
|
|
return result; |
|
|
|
if (result > 0 && !ObjectUtil.isEmpty(files)) { |
|
|
|
zdxtFileCommonApi.insertZdxtFile(files[0], sceneQuestion.getGuid() + "", uploadFilePath); |
|
|
|
return ZDResponse.success(); |
|
|
|
} else if (result > 0) { |
|
|
|
return ZDResponse.success(); |
|
|
|
} |
|
|
|
return ZDResponse.error("失败"); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -208,23 +217,23 @@ public class SceneQuestionServiceImpl implements ISceneQuestionService { |
|
|
|
JSONObject json = JSON.parseObject(sceneRole.getContent()); |
|
|
|
JSONObject dataJson = json.getJSONObject("drawflow").getJSONObject("Home").getJSONObject("data"); |
|
|
|
Map<String, Object> root = new HashMap<>(); |
|
|
|
Map<String, Map<String,String>> answerList = new HashMap<>(); |
|
|
|
Map<String, Map<String, String>> answerList = new HashMap<>(); |
|
|
|
List<Map<String, Object>> paramsList = new ArrayList<>(); |
|
|
|
for (int i=1; i<=dataJson.size(); i++) { |
|
|
|
JSONObject data = dataJson.getJSONObject(i+""); |
|
|
|
for (int i = 1; i <= dataJson.size(); i++) { |
|
|
|
JSONObject data = dataJson.getJSONObject(i + ""); |
|
|
|
Map<String, Object> params = new HashMap<>(); |
|
|
|
params.put("questionId", data.get("name")); |
|
|
|
params.put("nodeId", data.get("id")); |
|
|
|
|
|
|
|
JSONObject dataTmp = data.getJSONObject("data"); |
|
|
|
if (Objects.nonNull(dataTmp) && dataTmp.size()!=0) { |
|
|
|
if (Objects.nonNull(dataTmp) && dataTmp.size() != 0) { |
|
|
|
String channel = dataTmp.getString("channel"); |
|
|
|
if (StringUtils.isNotEmpty(channel)) { |
|
|
|
params.put("channel", channel); |
|
|
|
if(data.getJSONObject("inputs").size()!=0){ |
|
|
|
if (data.getJSONObject("inputs").size() != 0) { |
|
|
|
JSONArray ints = data.getJSONObject("inputs").getJSONObject("input_1").getJSONArray("connections"); |
|
|
|
if(Objects.nonNull(ints) && ints.size()!=0){ |
|
|
|
for (int j=0; j<ints.size(); j++) { |
|
|
|
if (Objects.nonNull(ints) && ints.size() != 0) { |
|
|
|
for (int j = 0; j < ints.size(); j++) { |
|
|
|
JSONObject it = ints.getJSONObject(j); |
|
|
|
params.put("ints", it.getString("node")); |
|
|
|
} |
|
|
|
@ -238,12 +247,12 @@ public class SceneQuestionServiceImpl implements ISceneQuestionService { |
|
|
|
params.put("correct", correct); |
|
|
|
} |
|
|
|
JSONArray option = dataTmp.getJSONArray("option"); |
|
|
|
if(Objects.nonNull(option) && option.size()!=0){ |
|
|
|
Map<String ,String> map = new HashMap<>(); |
|
|
|
for (int j=0; j<option.size(); j++) { |
|
|
|
if (Objects.nonNull(option) && option.size() != 0) { |
|
|
|
Map<String, String> map = new HashMap<>(); |
|
|
|
for (int j = 0; j < option.size(); j++) { |
|
|
|
JSONObject ot = option.getJSONObject(j); |
|
|
|
map.put(ot.getString("identify"),ot.getString("content")); |
|
|
|
answerList.put(data.getString("id"),map); |
|
|
|
map.put(ot.getString("identify"), ot.getString("content")); |
|
|
|
answerList.put(data.getString("id"), map); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
@ -252,7 +261,7 @@ public class SceneQuestionServiceImpl implements ISceneQuestionService { |
|
|
|
|
|
|
|
Set<Integer> outList = new HashSet(); |
|
|
|
JSONArray outs = data.getJSONObject("outputs").getJSONObject("output_1").getJSONArray("connections"); |
|
|
|
for (int j=0; j<outs.size(); j++) { |
|
|
|
for (int j = 0; j < outs.size(); j++) { |
|
|
|
JSONObject ot = outs.getJSONObject(j); |
|
|
|
outList.add(ot.getInteger("node")); |
|
|
|
} |
|
|
|
@ -265,7 +274,7 @@ public class SceneQuestionServiceImpl implements ISceneQuestionService { |
|
|
|
SceneQuestion sq = this.selectSceneQuestionById(params.get("questionId").toString()); |
|
|
|
if (null != sq) { |
|
|
|
params.put("videoUrl", sq.getUploadPath()); |
|
|
|
} else if(Objects.nonNull(dataTmp) && !StringUtils.isEmpty(dataTmp.getString("channel"))){ |
|
|
|
} else if (Objects.nonNull(dataTmp) && !StringUtils.isEmpty(dataTmp.getString("channel"))) { |
|
|
|
paramsList.add(params); |
|
|
|
continue; |
|
|
|
} else { |
|
|
|
@ -280,14 +289,14 @@ public class SceneQuestionServiceImpl implements ISceneQuestionService { |
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(paramsList) && !answerList.isEmpty()) { |
|
|
|
paramsList.stream() |
|
|
|
.filter(item->Objects.nonNull(item.get("ints"))) |
|
|
|
.filter(item->Objects.nonNull(item.get("channel"))) |
|
|
|
.peek(item->{ |
|
|
|
.filter(item -> Objects.nonNull(item.get("ints"))) |
|
|
|
.filter(item -> Objects.nonNull(item.get("channel"))) |
|
|
|
.peek(item -> { |
|
|
|
Map<String, String> stringStringMap = answerList.get((String) item.get("ints")); |
|
|
|
if(Objects.nonNull(stringStringMap) && !stringStringMap.isEmpty()){ |
|
|
|
if (Objects.nonNull(stringStringMap) && !stringStringMap.isEmpty()) { |
|
|
|
String channel = (String) item.get("channel"); |
|
|
|
String newChannel = stringStringMap.get(channel); |
|
|
|
item.put("channel",StringUtils.isEmpty(newChannel) ? channel : channel+":"+newChannel); |
|
|
|
item.put("channel", StringUtils.isEmpty(newChannel) ? channel : channel + ":" + newChannel); |
|
|
|
} |
|
|
|
}) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
|