|
@@ -39,7 +39,8 @@ import cn.com.qmth.am.service.QuestionService;
|
|
@Service
|
|
@Service
|
|
public class QuestionServiceImpl extends ServiceImpl<QuestionDao, QuestionEntity> implements QuestionService {
|
|
public class QuestionServiceImpl extends ServiceImpl<QuestionDao, QuestionEntity> implements QuestionService {
|
|
|
|
|
|
- private static final String[] EXCEL_HEADER = new String[] { "考试ID", "科目代码","科目名称", "大题号", "小题号", "满分", "试题内容", "试题答案","作答坐标" };
|
|
|
|
|
|
+ private static final String[] EXCEL_HEADER = new String[] { "考试ID", "科目代码", "科目名称", "大题号", "小题号", "满分", "试题内容",
|
|
|
|
+ "试题答案", "作答坐标" };
|
|
@Autowired
|
|
@Autowired
|
|
private SysProperty sysProperty;
|
|
private SysProperty sysProperty;
|
|
@Autowired
|
|
@Autowired
|
|
@@ -186,7 +187,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionDao, QuestionEntity
|
|
msg.append(" 科目代码不能超过100个字符");
|
|
msg.append(" 科目代码不能超过100个字符");
|
|
}
|
|
}
|
|
imp.setSubjectCode(subjectCode);
|
|
imp.setSubjectCode(subjectCode);
|
|
-
|
|
|
|
|
|
+
|
|
String subjectName = trimAndNullIfBlank(line.get(EXCEL_HEADER[2]));
|
|
String subjectName = trimAndNullIfBlank(line.get(EXCEL_HEADER[2]));
|
|
if (StringUtils.isBlank(subjectName)) {
|
|
if (StringUtils.isBlank(subjectName)) {
|
|
msg.append(" 科目名称不能为空");
|
|
msg.append(" 科目名称不能为空");
|
|
@@ -217,7 +218,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionDao, QuestionEntity
|
|
msg.append(" 小题号不能为空");
|
|
msg.append(" 小题号不能为空");
|
|
} else if (subNum.length() > 10) {
|
|
} else if (subNum.length() > 10) {
|
|
msg.append(" 小题号不能超过10个字符");
|
|
msg.append(" 小题号不能超过10个字符");
|
|
- }
|
|
|
|
|
|
+ }
|
|
imp.setSubNumber(subNum);
|
|
imp.setSubNumber(subNum);
|
|
|
|
|
|
String fullScore = trimAndNullIfBlank(line.get(EXCEL_HEADER[5]));
|
|
String fullScore = trimAndNullIfBlank(line.get(EXCEL_HEADER[5]));
|
|
@@ -249,17 +250,16 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionDao, QuestionEntity
|
|
}
|
|
}
|
|
imp.setAnswer(answer);
|
|
imp.setAnswer(answer);
|
|
|
|
|
|
-
|
|
|
|
String imageSlice = trimAndNullIfBlank(line.get(EXCEL_HEADER[8]));
|
|
String imageSlice = trimAndNullIfBlank(line.get(EXCEL_HEADER[8]));
|
|
if (StringUtils.isBlank(imageSlice)) {
|
|
if (StringUtils.isBlank(imageSlice)) {
|
|
msg.append(" 作答坐标不能为空");
|
|
msg.append(" 作答坐标不能为空");
|
|
} else if (imageSlice.length() > 1000) {
|
|
} else if (imageSlice.length() > 1000) {
|
|
msg.append(" 作答坐标不能超过1000个字符");
|
|
msg.append(" 作答坐标不能超过1000个字符");
|
|
} else {
|
|
} else {
|
|
- List<ImageSlice> val=getImageSlice(imageSlice);
|
|
|
|
- if(val==null) {
|
|
|
|
|
|
+ List<ImageSlice> val = getImageSlice(imageSlice);
|
|
|
|
+ if (val == null) {
|
|
msg.append(" 作答坐标格式有误");
|
|
msg.append(" 作答坐标格式有误");
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
imp.setImageSlice(val);
|
|
imp.setImageSlice(val);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -276,7 +276,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionDao, QuestionEntity
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
- saveQuestionBatch(ret,ss);
|
|
|
|
|
|
+ saveQuestionBatch(ret, ss);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
failRecords.add("系统错误:" + e.getMessage());
|
|
failRecords.add("系统错误:" + e.getMessage());
|
|
}
|
|
}
|
|
@@ -287,25 +287,25 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionDao, QuestionEntity
|
|
if (StringUtils.isBlank(s)) {
|
|
if (StringUtils.isBlank(s)) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
- s=s.trim();
|
|
|
|
|
|
+ s = s.trim();
|
|
if (StringUtils.isBlank(s)) {
|
|
if (StringUtils.isBlank(s)) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
- List<ImageSlice> list=new ArrayList<>();
|
|
|
|
- String[] items=s.split(",");
|
|
|
|
- for(int i=0;i<items.length;i++) {
|
|
|
|
- String item=items[i];
|
|
|
|
- item=item.trim();
|
|
|
|
- String[] config=item.split(":");
|
|
|
|
- if(config.length!=5) {
|
|
|
|
|
|
+ List<ImageSlice> list = new ArrayList<>();
|
|
|
|
+ String[] items = s.split(",");
|
|
|
|
+ for (int i = 0; i < items.length; i++) {
|
|
|
|
+ String item = items[i];
|
|
|
|
+ item = item.trim();
|
|
|
|
+ String[] config = item.split(":");
|
|
|
|
+ if (config.length != 5) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
- int iVal=Integer.valueOf(config[0]);
|
|
|
|
- int x=Integer.valueOf(config[1]);
|
|
|
|
- int y=Integer.valueOf(config[2]);
|
|
|
|
- int w=Integer.valueOf(config[3]);
|
|
|
|
- int h=Integer.valueOf(config[4]);
|
|
|
|
|
|
+ int iVal = Integer.valueOf(config[0]);
|
|
|
|
+ int x = Integer.valueOf(config[1]);
|
|
|
|
+ int y = Integer.valueOf(config[2]);
|
|
|
|
+ int w = Integer.valueOf(config[3]);
|
|
|
|
+ int h = Integer.valueOf(config[4]);
|
|
ImageSlice ret = new ImageSlice();
|
|
ImageSlice ret = new ImageSlice();
|
|
ret.setH(h);
|
|
ret.setH(h);
|
|
ret.setI(iVal);
|
|
ret.setI(iVal);
|
|
@@ -313,12 +313,12 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionDao, QuestionEntity
|
|
ret.setX(x);
|
|
ret.setX(x);
|
|
ret.setY(y);
|
|
ret.setY(y);
|
|
if (ret.getH() == null || ret.getI() == null || ret.getW() == null || ret.getX() == null
|
|
if (ret.getH() == null || ret.getI() == null || ret.getW() == null || ret.getX() == null
|
|
- || ret.getY() == null||ret.getI()<0) {
|
|
|
|
|
|
+ || ret.getY() == null || ret.getI() < 0) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
list.add(ret);
|
|
list.add(ret);
|
|
}
|
|
}
|
|
- if(list.size()==0) {
|
|
|
|
|
|
+ if (list.size() == 0) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
list.sort(new Comparator<ImageSlice>() {
|
|
list.sort(new Comparator<ImageSlice>() {
|
|
@@ -341,38 +341,39 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionDao, QuestionEntity
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void saveQuestionBatch(ImportResult ret,List<QuestionEntity> ss) {
|
|
|
|
|
|
+ private void saveQuestionBatch(ImportResult ret, List<QuestionEntity> ss) {
|
|
if (CollectionUtils.isEmpty(ss)) {
|
|
if (CollectionUtils.isEmpty(ss)) {
|
|
ret.setCountInfo("新增数量:0,更新数量:0");
|
|
ret.setCountInfo("新增数量:0,更新数量:0");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
List<QuestionEntity> all = this.list();
|
|
List<QuestionEntity> all = this.list();
|
|
- Map<String,QuestionEntity> old = new HashMap<>();
|
|
|
|
- Map<String,QuestionEntity> addMap = new HashMap<>();
|
|
|
|
|
|
+ Map<String, QuestionEntity> old = new HashMap<>();
|
|
|
|
+ Map<String, QuestionEntity> addMap = new HashMap<>();
|
|
if (CollectionUtils.isNotEmpty(all)) {
|
|
if (CollectionUtils.isNotEmpty(all)) {
|
|
for (QuestionEntity s : all) {
|
|
for (QuestionEntity s : all) {
|
|
- String key = s.getExamId() + "-" + s.getSubjectCode() + "-" + s.getMainNumber()+"-"+s.getSubNumber();
|
|
|
|
- old.put(key,s);
|
|
|
|
|
|
+ String key = s.getExamId() + "-" + s.getSubjectCode() + "-" + s.getMainNumber() + "-"
|
|
|
|
+ + s.getSubNumber();
|
|
|
|
+ old.put(key, s);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
List<QuestionEntity> adds = new ArrayList<>();
|
|
List<QuestionEntity> adds = new ArrayList<>();
|
|
List<QuestionEntity> updates = new ArrayList<>();
|
|
List<QuestionEntity> updates = new ArrayList<>();
|
|
for (QuestionEntity s : ss) {
|
|
for (QuestionEntity s : ss) {
|
|
- String key = s.getExamId() + "-" + s.getSubjectCode() + "-" + s.getMainNumber()+"-"+s.getSubNumber();
|
|
|
|
- if (old.get(key)==null) {
|
|
|
|
- QuestionEntity add=addMap.get(key);
|
|
|
|
- if(add!=null) {
|
|
|
|
|
|
+ String key = s.getExamId() + "-" + s.getSubjectCode() + "-" + s.getMainNumber() + "-" + s.getSubNumber();
|
|
|
|
+ if (old.get(key) == null) {
|
|
|
|
+ QuestionEntity add = addMap.get(key);
|
|
|
|
+ if (add != null) {
|
|
add.setSubjectName(s.getSubjectName());
|
|
add.setSubjectName(s.getSubjectName());
|
|
add.setFullScore(s.getFullScore());
|
|
add.setFullScore(s.getFullScore());
|
|
add.setImageSlice(s.getImageSlice());
|
|
add.setImageSlice(s.getImageSlice());
|
|
add.setContent(s.getContent());
|
|
add.setContent(s.getContent());
|
|
add.setAnswer(s.getAnswer());
|
|
add.setAnswer(s.getAnswer());
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
addMap.put(key, s);
|
|
addMap.put(key, s);
|
|
adds.add(s);
|
|
adds.add(s);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- QuestionEntity up=old.get(key);
|
|
|
|
|
|
+ QuestionEntity up = old.get(key);
|
|
up.setSubjectName(s.getSubjectName());
|
|
up.setSubjectName(s.getSubjectName());
|
|
up.setFullScore(s.getFullScore());
|
|
up.setFullScore(s.getFullScore());
|
|
up.setImageSlice(s.getImageSlice());
|
|
up.setImageSlice(s.getImageSlice());
|
|
@@ -387,7 +388,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionDao, QuestionEntity
|
|
if (CollectionUtils.isNotEmpty(updates)) {
|
|
if (CollectionUtils.isNotEmpty(updates)) {
|
|
updateBatchById(updates);
|
|
updateBatchById(updates);
|
|
}
|
|
}
|
|
- ret.setCountInfo("新增数量:"+adds.size()+",更新数量:"+updates.size());
|
|
|
|
|
|
+ ret.setCountInfo("新增数量:" + adds.size() + ",更新数量:" + updates.size());
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -395,6 +396,8 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionDao, QuestionEntity
|
|
QueryWrapper<QuestionEntity> wrapper = new QueryWrapper<>();
|
|
QueryWrapper<QuestionEntity> wrapper = new QueryWrapper<>();
|
|
LambdaQueryWrapper<QuestionEntity> lw = wrapper.lambda();
|
|
LambdaQueryWrapper<QuestionEntity> lw = wrapper.lambda();
|
|
lw.eq(QuestionEntity::getExamId, examId);
|
|
lw.eq(QuestionEntity::getExamId, examId);
|
|
|
|
+ lw.orderByAsc(QuestionEntity::getSubjectCode).orderByAsc(QuestionEntity::getMainNumber)
|
|
|
|
+ .orderByAsc(QuestionEntity::getSubNumber);
|
|
return this.list(wrapper);
|
|
return this.list(wrapper);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -403,7 +406,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionDao, QuestionEntity
|
|
public void removeBy(Long examId, String subjectCode) {
|
|
public void removeBy(Long examId, String subjectCode) {
|
|
QueryWrapper<QuestionEntity> wrapper = new QueryWrapper<>();
|
|
QueryWrapper<QuestionEntity> wrapper = new QueryWrapper<>();
|
|
LambdaQueryWrapper<QuestionEntity> lw = wrapper.lambda();
|
|
LambdaQueryWrapper<QuestionEntity> lw = wrapper.lambda();
|
|
- if(subjectCode!=null) {
|
|
|
|
|
|
+ if (subjectCode != null) {
|
|
lw.eq(QuestionEntity::getSubjectCode, subjectCode);
|
|
lw.eq(QuestionEntity::getSubjectCode, subjectCode);
|
|
}
|
|
}
|
|
lw.eq(QuestionEntity::getExamId, examId);
|
|
lw.eq(QuestionEntity::getExamId, examId);
|