Commit 830bd15e authored by 吴卿华's avatar 吴卿华

导入修改

parent aa08a383
package com.zehong.web.controller.system; package com.zehong.web.controller.system;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.zehong.common.exception.CustomException; import com.zehong.common.exception.CustomException;
import com.zehong.common.utils.StringUtils; import com.zehong.common.utils.StringUtils;
import com.zehong.system.domain.Answer;
import com.zehong.system.domain.TBankSubject; import com.zehong.system.domain.TBankSubject;
import com.zehong.system.domain.TDeviceInfo;
import com.zehong.system.service.ITBankSubjectService; import com.zehong.system.service.ITBankSubjectService;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
...@@ -39,8 +30,6 @@ import com.zehong.common.utils.poi.ExcelUtil; ...@@ -39,8 +30,6 @@ import com.zehong.common.utils.poi.ExcelUtil;
import com.zehong.common.core.page.TableDataInfo; import com.zehong.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.xml.crypto.Data;
/** /**
* 题目Controller * 题目Controller
* *
...@@ -149,7 +138,7 @@ public class TBankSubjectController extends BaseController ...@@ -149,7 +138,7 @@ public class TBankSubjectController extends BaseController
int lastRowNum = sheet.getLastRowNum(); int lastRowNum = sheet.getLastRowNum();
// 通过循环,逐行取出表中每行数据 // 通过循环,逐行取出表中每行数据
for(int i=0;i<=lastRowNum;i++){//跳过第一行和第二行 for(int i=0;i<=lastRowNum;i++){//跳过第一行和第二行
if(i<=2){ if(i<=1){
continue; continue;
} }
// 获取行 // 获取行
...@@ -167,26 +156,28 @@ public class TBankSubjectController extends BaseController ...@@ -167,26 +156,28 @@ public class TBankSubjectController extends BaseController
/**选项*/ /**选项*/
for (int s=1;s<=8;s++){ for (int s=1;s<=8;s++){
JSONObject jsonObject=new JSONObject(); JSONObject jsonObject=new JSONObject();
jsonObject.put("value",row.getCell(s).toString()); if (!StringUtils.isEmpty(row.getCell(s).toString())) {
jsonObject.put("value", row.getCell(s).toString());
jsonArray.add(jsonObject); jsonArray.add(jsonObject);
} }
}
/**答案*/ /**答案*/
if ("A".equals(row.getCell(9).toString())){ if ("A".equals(row.getCell(9).toString())){
excelEntity.setAnswer(0);
}else if ("B".equals(row.getCell(9).toString())){
excelEntity.setAnswer(1); excelEntity.setAnswer(1);
}else if ("b".equals(row.getCell(9).toString())){
excelEntity.setAnswer(2);
}else if ("C".equals(row.getCell(9).toString())){ }else if ("C".equals(row.getCell(9).toString())){
excelEntity.setAnswer(3); excelEntity.setAnswer(2);
}else if ("D".equals(row.getCell(9).toString())){ }else if ("D".equals(row.getCell(9).toString())){
excelEntity.setAnswer(4); excelEntity.setAnswer(3);
}else if ("E".equals(row.getCell(9).toString())){ }else if ("E".equals(row.getCell(9).toString())){
excelEntity.setAnswer(5); excelEntity.setAnswer(4);
}else if ("F".equals(row.getCell(9).toString())){ }else if ("F".equals(row.getCell(9).toString())){
excelEntity.setAnswer(6); excelEntity.setAnswer(5);
}else if ("G".equals(row.getCell(9).toString())){ }else if ("G".equals(row.getCell(9).toString())){
excelEntity.setAnswer(7); excelEntity.setAnswer(6);
}else if ("H".equals(row.getCell(9).toString())){ }else if ("H".equals(row.getCell(9).toString())){
excelEntity.setAnswer(8); excelEntity.setAnswer(7);
} }
excelEntity.setTopicOption(String.valueOf(jsonArray)); excelEntity.setTopicOption(String.valueOf(jsonArray));
excelEntity.setDatetime(new Date()); excelEntity.setDatetime(new Date());
...@@ -213,8 +204,10 @@ public class TBankSubjectController extends BaseController ...@@ -213,8 +204,10 @@ public class TBankSubjectController extends BaseController
{ {
successMsg.insert(0, "数据已全部导入成功!共 " + successNum + " 条"); successMsg.insert(0, "数据已全部导入成功!共 " + successNum + " 条");
} }
if (list.size()!=0){
/**数据添加方法*/ /**数据添加方法*/
tBankSubjectService.insertBank(list); tBankSubjectService.insertBank(list);
}
// String message = tBankSubjectService.importDevice(file, updateSupport); // String message = tBankSubjectService.importDevice(file, updateSupport);
return AjaxResult.success(successMsg.toString()); return AjaxResult.success(successMsg.toString());
} }
......
...@@ -174,6 +174,9 @@ export default { ...@@ -174,6 +174,9 @@ export default {
// 上传的地址 // 上传的地址
url: process.env.VUE_APP_BASE_API + "/system/subject/import" url: process.env.VUE_APP_BASE_API + "/system/subject/import"
}, },
queryParams: {
bankId:0
},
}; };
}, },
// watch: { // watch: {
...@@ -198,9 +201,9 @@ export default { ...@@ -198,9 +201,9 @@ export default {
// 文件下载处理 // 文件下载处理
handleDownload(row) { handleDownload(row) {
const a = document.createElement('a') const a = document.createElement('a')
a.setAttribute('download', '考试宝') a.setAttribute('download', '试题导入模板')
a.setAttribute('target', '_blank') a.setAttribute('target', '_blank')
a.setAttribute('href', 'http://36.138.181.113:8091/dangerManage/profile/upload/2022/kaoshi/kaoshibao.xlsx') a.setAttribute('href', 'http://36.138.181.113:8091/dangerManage/profile/upload/2022/kaoshi/shitimoban.xlsx')
a.click() a.click()
}, },
...@@ -219,7 +222,7 @@ export default { ...@@ -219,7 +222,7 @@ export default {
this.upload.isUploading = false; this.upload.isUploading = false;
this.$refs.upload.clearFiles(); this.$refs.upload.clearFiles();
this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true }); this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
this.getList(); this.getQuestion({ bankId: this.bankId });
}, },
/** 下载模板操作 */ /** 下载模板操作 */
importTemplate() { importTemplate() {
...@@ -243,9 +246,7 @@ export default { ...@@ -243,9 +246,7 @@ export default {
this.$parent.$parent.componentsNumChange(3); this.$parent.$parent.componentsNumChange(3);
}, },
getQuestion(bankId) { getQuestion(bankId) {
console.log(bankId);
return listSubject(bankId).then((res) => { return listSubject(bankId).then((res) => {
console.log("题库res", res);
this.questionList = res.rows.map((item) => { this.questionList = res.rows.map((item) => {
return { return {
......
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