9fd81101 康伟

kangwei:门户:吨水电耗、吨水药费,公式修改

         试题:批量上传代码
1 个父辈 c6392105
...@@ -383,24 +383,16 @@ public class ReportItemvService { ...@@ -383,24 +383,16 @@ public class ReportItemvService {
383 startTime = dateVO.getLastMonthStartTime(); 383 startTime = dateVO.getLastMonthStartTime();
384 endTime = dateVO.getLastMonthEndTime(); 384 endTime = dateVO.getLastMonthEndTime();
385 385
386 String dfValueSql = "select sum(cost) cost from report_electric_cost t where t.month >='"+DateUtils.formatDate(startTime,"yyyy-MM")+"' and t.month<='"+DateUtils.formatDate(endTime,"yyyy-MM")+"' "; 386 String dfValue = getDSDFsql(departId, startTime, endTime);
387 dfValueSql += " and t.depart_id in ("+JSUtils.quoteEach(departId,",")+")"; 387 String dfTBValue = getDSDFsql( departId, DateUtils.getHbDate(startTime), DateUtils.getHbDate(endTime));
388 String dfValue = getJdbcTemplate().queryForObject(dfValueSql,String.class); 388 String dfHBValue = getDSDFsql(departId, DateUtils.getHbDate(startTime), DateUtils.getHbDate(endTime));
389 389
390 String dfTBValueSql = "select sum(cost) cost from report_electric_cost t where t.month >='"+DateUtils.formatDate(DateUtils.getTbDate(startTime),"yyyy-MM")+"' and t.month<='"+DateUtils.formatDate(DateUtils.getTbDate(endTime),"yyyy-MM")+"' ";
391 dfTBValueSql += " and t.depart_id in ("+JSUtils.quoteEach(departId,",")+")";
392 String dfTBValue = getJdbcTemplate().queryForObject(dfTBValueSql,String.class);
393 390
394 String dfHBValueSql = "select sum(cost) cost from report_electric_cost t where t.month >='"+DateUtils.formatDate(DateUtils.getHbDate(startTime),"yyyy-MM")+"' and t.month<='"+DateUtils.formatDate(DateUtils.getHbDate(endTime),"yyyy-MM")+"' ";
395 dfHBValueSql += " and t.depart_id in ("+JSUtils.quoteEach(departId,",")+")";
396 String dfHBValue = getJdbcTemplate().queryForObject(dfHBValueSql,String.class);
397 //出水量:+同比+环比
398 ReportItemVO csl_reportVO = ReportViewUtil.getSumValueByTBHB(ReportConstant.view2119,ReportConstant.field_CSL, departId, startTime, endTime);
399 391
400 //当月数据/环比、同比 392 //当月数据/环比、同比
401 FRportlCommandCenterVO nowMonthVO = new FRportlCommandCenterVO("月总电耗", "万kwh",JSUtils.divide(dlhjData.getValue(),10000), JSUtils.divide(dlhjData.getValueTb(),10000), JSUtils.divide(dlhjData.getValueHb(),10000)); 393 FRportlCommandCenterVO nowMonthVO = new FRportlCommandCenterVO("月总电耗", "万kwh",JSUtils.divide(dlhjData.getValue(),10000), JSUtils.divide(dlhjData.getValueTb(),10000), JSUtils.divide(dlhjData.getValueHb(),10000));
402 //日均数据:/环比/同比 394 //日均数据:/环比/同比
403 FRportlCommandCenterVO lastMonthVO = new FRportlCommandCenterVO("吨水电费","元/t",JSUtils.divide(dfValue,csl_reportVO.getValue()) ,JSUtils.divide(dfTBValue,csl_reportVO.getValueTb()) ,JSUtils.divide(dfHBValue,csl_reportVO.getValueHb())); 395 FRportlCommandCenterVO lastMonthVO = new FRportlCommandCenterVO("吨水电费","元/t",dfValue ,dfTBValue,dfHBValue);
404 //吨水消耗 396 //吨水消耗
405 FRportlCommandCenterVO lastYearVo = new FRportlCommandCenterVO("吨水电耗","kwh/t",dsdh_value ,dsdh_value_Tb,dsdh_value_Hb ); 397 FRportlCommandCenterVO lastYearVo = new FRportlCommandCenterVO("吨水电耗","kwh/t",dsdh_value ,dsdh_value_Tb,dsdh_value_Hb );
406 fRportlCommandCenterVOList.add( nowMonthVO) ; 398 fRportlCommandCenterVOList.add( nowMonthVO) ;
...@@ -409,6 +401,19 @@ public class ReportItemvService { ...@@ -409,6 +401,19 @@ public class ReportItemvService {
409 401
410 return fRportlCommandCenterVOList; 402 return fRportlCommandCenterVOList;
411 } 403 }
404 //吨水电耗
405 private String getDSDFsql(String departId,String startTime,String endTime){
406 String dfValueSql = null;
407 String buildView2119 = ReportViewUtil.buildView(ReportConstant.view2119,ReportConstant.field_CSL, departId, startTime, endTime);
408 dfValueSql = " select round(avg(t.cost / bbb.CSL),2) 'cost' from report_electric_cost t left join (";
409 dfValueSql +=" select aaa.depart_id , sum(aaa.CSL) 'CSL' from " +buildView2119+" aaa group by aaa.depart_id )bbb on t.depart_id = bbb.depart_id";
410 dfValueSql += " where t.month='"+DateUtils.formatDate(startTime,"yyyy-MM")+"' and t.cost > 0";
411 if(StringUtils.isNotEmpty(departId)){
412 dfValueSql += " and t.depart_id in ("+JSUtils.quoteEach(departId,",")+")";
413 }
414 String dfValue = getJdbcTemplate().queryForObject(dfValueSql,String.class);
415 return dfValue;
416 }
412 417
413 418
414 /*** 419 /***
...@@ -442,9 +447,9 @@ public class ReportItemvService { ...@@ -442,9 +447,9 @@ public class ReportItemvService {
442 String dataViewName3a24_valueHB = ReportViewUtil.buildView(ReportConstant.view4411,"yyh", departIds, monthHB,monthHB); 447 String dataViewName3a24_valueHB = ReportViewUtil.buildView(ReportConstant.view4411,"yyh", departIds, monthHB,monthHB);
443 String dataViewName3a24_valueTB = ReportViewUtil.buildView(ReportConstant.view4411,"yyh", departIds, monthTB,monthTB); 448 String dataViewName3a24_valueTB = ReportViewUtil.buildView(ReportConstant.view4411,"yyh", departIds, monthTB,monthTB);
444 String sql = "select "; 449 String sql = "select ";
445 sql += "(select ROUND(ifnull(avg(aaa.yyh),0) ,2) 'value' from " + dataViewName3a24_value+ "aaa) 'value',"; 450 sql += "(select ROUND(ifnull(avg(aaa.yyh),0) ,2) 'value' from " + dataViewName3a24_value+ "aaa where aaa.yyh > 0 ) 'value',";
446 sql += "(select ROUND(ifnull(avg(aaa.yyh),0) ,2) 'value' from " + dataViewName3a24_valueHB+ "aaa) 'valueHb',"; 451 sql += "(select ROUND(ifnull(avg(aaa.yyh),0) ,2) 'value' from " + dataViewName3a24_valueHB+ "aaa where aaa.yyh > 0 ) 'valueHb',";
447 sql += "(select ROUND(ifnull(avg(aaa.yyh),0) ,2) 'value' from " + dataViewName3a24_valueTB+ "aaa) 'valueTb' "; 452 sql += "(select ROUND(ifnull(avg(aaa.yyh),0) ,2) 'value' from " + dataViewName3a24_valueTB+ "aaa where aaa.yyh > 0 ) 'valueTb' ";
448 sql += " from dual"; 453 sql += " from dual";
449 JdbcTemplate masterDB = (JdbcTemplate)SpringContextUtils.getBean("master"); 454 JdbcTemplate masterDB = (JdbcTemplate)SpringContextUtils.getBean("master");
450 ReportItemVO dsyfReportVO = null; 455 ReportItemVO dsyfReportVO = null;
......
1 package com.skua.modules.edu.controller; 1 package com.skua.modules.edu.controller;
2 2
3 import java.util.ArrayList;
3 import java.util.Arrays; 4 import java.util.Arrays;
4 import java.util.List; 5 import java.util.List;
5 import java.util.Map; 6 import java.util.Map;
...@@ -56,19 +57,6 @@ public class QuestionController { ...@@ -56,19 +57,6 @@ public class QuestionController {
56 @Autowired 57 @Autowired
57 private IQuestionService questionService; 58 private IQuestionService questionService;
58 59
59 /**
60 * <pre>
61 * 分页列表查询
62 * </pre>
63 * @param question
64 * @param pageNo
65 * @param pageSize
66 * @param req
67 * @return
68 * @author 开发者姓名, 开发时间
69 * @Description: TODO(这里描述这个方法的需求变更情况)
70 */
71
72 @AutoLog(value = "在线考试-试题-分页列表查询") 60 @AutoLog(value = "在线考试-试题-分页列表查询")
73 @ApiOperation(value="在线考试-试题-分页列表查询", notes="在线考试-试题-分页列表查询") 61 @ApiOperation(value="在线考试-试题-分页列表查询", notes="在线考试-试题-分页列表查询")
74 @GetMapping(value = "/list") 62 @GetMapping(value = "/list")
...@@ -105,15 +93,6 @@ public class QuestionController { ...@@ -105,15 +93,6 @@ public class QuestionController {
105 return result; 93 return result;
106 } 94 }
107 95
108 /**
109 * <pre>
110 * 添加
111 * </pre>
112 * @param question
113 * @return
114 * @author 开发者姓名, 开发时间
115 * @Description: TODO(这里描述这个方法的需求变更情况)
116 */
117 @AutoLog(value = "在线考试-试题-添加") 96 @AutoLog(value = "在线考试-试题-添加")
118 @ApiOperation(value="在线考试-试题-添加", notes="在线考试-试题-添加") 97 @ApiOperation(value="在线考试-试题-添加", notes="在线考试-试题-添加")
119 @PostMapping(value = "/add") 98 @PostMapping(value = "/add")
...@@ -130,15 +109,7 @@ public class QuestionController { ...@@ -130,15 +109,7 @@ public class QuestionController {
130 } 109 }
131 return result; 110 return result;
132 } 111 }
133 /** 112
134 * <pre>
135 * 编辑
136 * </pre>
137 * @param question
138 * @return
139 * @author 开发者姓名, 开发时间
140 * @Description: TODO(这里描述这个方法的需求变更情况)
141 */
142 @AutoLog(value = "在线考试-试题-编辑") 113 @AutoLog(value = "在线考试-试题-编辑")
143 @ApiOperation(value="在线考试-试题-编辑", notes="在线考试-试题-编辑") 114 @ApiOperation(value="在线考试-试题-编辑", notes="在线考试-试题-编辑")
144 @PutMapping(value = "/edit") 115 @PutMapping(value = "/edit")
...@@ -155,18 +126,9 @@ public class QuestionController { ...@@ -155,18 +126,9 @@ public class QuestionController {
155 result.success("修改成功!"); 126 result.success("修改成功!");
156 } 127 }
157 } 128 }
158
159 return result; 129 return result;
160 } 130 }
161 /** 131
162 * <pre>
163 * 通过id删除
164 * </pre>
165 * @param id
166 * @return
167 * @author 开发者姓名, 开发时间
168 * @Description: TODO(这里描述这个方法的需求变更情况)
169 */
170 @AutoLog(value = "在线考试-试题-通过id删除") 132 @AutoLog(value = "在线考试-试题-通过id删除")
171 @ApiOperation(value="在线考试-试题-通过id删除", notes="在线考试-试题-通过id删除") 133 @ApiOperation(value="在线考试-试题-通过id删除", notes="在线考试-试题-通过id删除")
172 @DeleteMapping(value = "/delete") 134 @DeleteMapping(value = "/delete")
...@@ -186,15 +148,6 @@ public class QuestionController { ...@@ -186,15 +148,6 @@ public class QuestionController {
186 return Result.ok("删除成功!"); 148 return Result.ok("删除成功!");
187 } 149 }
188 150
189 /**
190 * <pre>
191 * 批量删除
192 * </pre>
193 * @param ids
194 * @return
195 * @author 开发者姓名, 开发时间
196 * @Description: TODO(这里描述这个方法的需求变更情况)
197 */
198 @AutoLog(value = "在线考试-试题-批量删除") 151 @AutoLog(value = "在线考试-试题-批量删除")
199 @ApiOperation(value="在线考试-试题-批量删除", notes="在线考试-试题-批量删除") 152 @ApiOperation(value="在线考试-试题-批量删除", notes="在线考试-试题-批量删除")
200 @DeleteMapping(value = "/deleteBatch") 153 @DeleteMapping(value = "/deleteBatch")
...@@ -297,39 +250,18 @@ public class QuestionController { ...@@ -297,39 +250,18 @@ public class QuestionController {
297 return result; 250 return result;
298 } 251 }
299 252
300 /** 253 @RequestMapping(value = "/exportXlsTemplate")
301 * <pre>
302 * 导出excel
303 * </pre>
304 * @param request
305 * @param response
306 * @return
307 * @author 开发者姓名, 开发时间
308 * @Description: TODO(这里描述这个方法的需求变更情况)
309 */
310
311 @RequestMapping(value = "/exportXls")
312 public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) { 254 public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
313 // Step.1 组装查询条件 255 // Step.1 组装查询条件
314 QueryWrapper<Question> queryWrapper = null;
315 try {
316 String paramsStr = request.getParameter("paramsStr");
317 if (ConvertUtils.isNotEmpty(paramsStr)) {
318 String deString = URLDecoder.decode(paramsStr, "UTF-8");
319 Question question = JSON.parseObject(deString, Question.class);
320 queryWrapper = QueryGenerator.initQueryWrapper(question, request.getParameterMap());
321 }
322 } catch (UnsupportedEncodingException e) {
323 e.printStackTrace();
324 }
325
326 //Step.2 AutoPoi 导出Excel 256 //Step.2 AutoPoi 导出Excel
327 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); 257 ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
328 List<Question> pageList = questionService.list(queryWrapper); 258 List<QuestionExcel> pageList = new ArrayList<>();
259 pageList.add( new QuestionExcel("单选", "车辆在较窄的山路上行驶时,如果靠山体的一方不让行,应怎样做?", "鸣喇叭催其让行", "保持正常车速行驶", "提前减速或停车避让", "向左占道,谨慎驶过", "A", ""));
260 pageList.add( new QuestionExcel("多选", "交通信号灯由( )组成。", "鸣喇叭催其让行", "红灯", "绿灯", "黄灯", "蓝", "ABC"));
329 //导出文件名称 261 //导出文件名称
330 mv.addObject(NormalExcelConstants.FILE_NAME, "在线考试-试题列表"); 262 mv.addObject(NormalExcelConstants.FILE_NAME, "选择题_批量导入模板");
331 mv.addObject(NormalExcelConstants.CLASS, Question.class); 263 mv.addObject(NormalExcelConstants.CLASS, QuestionExcel.class);
332 mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("在线考试-试题列表数据", "导出人:Jeecg", "导出信息")); 264 mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("选择题_批量导入模板", "导出人", ""));
333 mv.addObject(NormalExcelConstants.DATA_LIST, pageList); 265 mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
334 return mv; 266 return mv;
335 } 267 }
...@@ -356,7 +288,6 @@ public class QuestionController { ...@@ -356,7 +288,6 @@ public class QuestionController {
356 params.setNeedSave(true); 288 params.setNeedSave(true);
357 try { 289 try {
358 String dbId = request.getParameter("dbId"); 290 String dbId = request.getParameter("dbId");
359
360 List<QuestionExcel> listQuestions = ExcelImportUtil.importExcel(file.getInputStream(), QuestionExcel.class, params); 291 List<QuestionExcel> listQuestions = ExcelImportUtil.importExcel(file.getInputStream(), QuestionExcel.class, params);
361 questionService.batchImportExcel(listQuestions,dbId); 292 questionService.batchImportExcel(listQuestions,dbId);
362 return Result.ok("文件导入成功!数据行数:" + listQuestions.size()); 293 return Result.ok("文件导入成功!数据行数:" + listQuestions.size());
......
...@@ -42,7 +42,26 @@ public class QuestionOption implements Serializable { ...@@ -42,7 +42,26 @@ public class QuestionOption implements Serializable {
42 @ApiModelProperty(value = "选项标题") 42 @ApiModelProperty(value = "选项标题")
43 private String optionTitle; 43 private String optionTitle;
44 /**正确答案*/ 44 /**正确答案*/
45 @Excel(name = "正确答案", width = 15) 45 @Excel(name = "是否正确答案", width = 15)
46 @ApiModelProperty(value = "正确答案") 46 @ApiModelProperty(value = "是否正确答案")
47 private String correct; 47 private String correct;
48
49 public QuestionOption(){
50
51 }
52 public QuestionOption(String alias, String optionTitle) {
53 this.alias = alias;
54 this.optionTitle = optionTitle;
55 }
56 public QuestionOption(String alias, String optionTitle, String correct) {
57 this.alias = alias;
58 this.optionTitle = optionTitle;
59 this.correct = correct;
60 }
61 public QuestionOption(String questionId,String alias, String optionTitle, String correct) {
62 this.questionId = questionId;
63 this.alias = alias;
64 this.optionTitle = optionTitle;
65 this.correct = correct;
66 }
48 } 67 }
......
1 package com.skua.modules.edu.service;
2
3
4
5 import com.baomidou.mybatisplus.extension.service.IService;
6 import com.skua.modules.edu.entity.QuestionOption;
7
8 /**
9 * 在线考试-试题
10 */
11 public interface IQuestionOptionService extends IService<QuestionOption> {
12
13 }
...@@ -27,7 +27,7 @@ public interface IQuestionService extends IService<Question> { ...@@ -27,7 +27,7 @@ public interface IQuestionService extends IService<Question> {
27 * @param question 27 * @param question
28 * @return 28 * @return
29 */ 29 */
30 public int saveQuestion(Question question)throws Exception; 30 public int saveQuestion(Question question);
31 31
32 /*** 32 /***
33 * 修改试题 以及试题选项 33 * 修改试题 以及试题选项
......
1 package com.skua.modules.edu.service.impl;
2
3
4 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
5 import com.skua.modules.edu.entity.QuestionOption;
6 import com.skua.modules.edu.mapper.QuestionOptionMapper;
7 import com.skua.modules.edu.service.IQuestionOptionService;
8 import org.springframework.stereotype.Service;
9
10
11 /**
12 * 在线考试-试题选项
13 */
14 @Service
15 public class QuestionOptionServiceImpl extends ServiceImpl<QuestionOptionMapper, QuestionOption> implements IQuestionOptionService {
16
17 }
...@@ -5,16 +5,20 @@ import com.baomidou.mybatisplus.core.metadata.IPage; ...@@ -5,16 +5,20 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
5 import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 import com.google.gson.Gson; 6 import com.google.gson.Gson;
7 import com.skua.core.context.BaseContextHandler; 7 import com.skua.core.context.BaseContextHandler;
8 import com.skua.core.service.ISequenceService;
8 import com.skua.modules.edu.entity.Question; 9 import com.skua.modules.edu.entity.Question;
9 import com.skua.modules.edu.entity.QuestionDB; 10 import com.skua.modules.edu.entity.QuestionDB;
10 import com.skua.modules.edu.entity.QuestionOption; 11 import com.skua.modules.edu.entity.QuestionOption;
11 import com.skua.modules.edu.mapper.QuestionMapper; 12 import com.skua.modules.edu.mapper.QuestionMapper;
12 import com.skua.modules.edu.mapper.QuestionOptionMapper; 13 import com.skua.modules.edu.mapper.QuestionOptionMapper;
14 import com.skua.modules.edu.service.IQuestionOptionService;
13 import com.skua.modules.edu.service.IQuestionService; 15 import com.skua.modules.edu.service.IQuestionService;
14 import com.skua.modules.edu.vo.QuestionExcel; 16 import com.skua.modules.edu.vo.QuestionExcel;
15 import com.skua.modules.erp.entity.ApproveRecord; 17 import com.skua.modules.erp.entity.ApproveRecord;
16 import com.skua.modules.erp.mapper.ApproveRecordMapper; 18 import com.skua.modules.erp.mapper.ApproveRecordMapper;
19 import com.skua.tool.util.UniqIdUtils;
17 import org.apache.commons.lang3.StringUtils; 20 import org.apache.commons.lang3.StringUtils;
21 import org.springframework.beans.factory.annotation.Autowired;
18 import org.springframework.stereotype.Service; 22 import org.springframework.stereotype.Service;
19 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 23 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
20 import org.springframework.transaction.annotation.Transactional; 24 import org.springframework.transaction.annotation.Transactional;
...@@ -31,9 +35,15 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i ...@@ -31,9 +35,15 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
31 @Resource 35 @Resource
32 private QuestionOptionMapper optionMapper; 36 private QuestionOptionMapper optionMapper;
33 37
38 @Autowired
39 private IQuestionOptionService questionOptionService;
40
34 @Resource 41 @Resource
35 private ApproveRecordMapper recordMapper; 42 private ApproveRecordMapper recordMapper;
36 43
44 @Autowired
45 private ISequenceService sequenceService;
46
37 public IPage<Question> queryPageList(Page<Question> page, Question questionDB) { 47 public IPage<Question> queryPageList(Page<Question> page, Question questionDB) {
38 return this.baseMapper.queryPageList(page,questionDB); 48 return this.baseMapper.queryPageList(page,questionDB);
39 } 49 }
...@@ -48,16 +58,17 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i ...@@ -48,16 +58,17 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
48 * @return 58 * @return
49 */ 59 */
50 @Transactional 60 @Transactional
51 public int saveQuestion(Question question)throws Exception{ 61 public int saveQuestion(Question question){
52 62
53 int count = this.baseMapper.insert( question ); 63 int count = this.baseMapper.insert( question );
54
55 // 步骤2:批量插入试题选项集合 64 // 步骤2:批量插入试题选项集合
56 if(question.getOptionList() != null ){ 65 if(question.getOptionList() != null ){
57 for(QuestionOption option : question.getOptionList() ){ 66 for(QuestionOption option : question.getOptionList() ){
58 option.setQuestionId( question.getId() ) ; 67 option.setQuestionId( question.getId() ) ;
59 optionMapper.insert( option ); 68 // optionMapper.insert( option );
60 } 69 }
70 questionOptionService.saveBatch(question.getOptionList());
71
61 // 创建Gson实例 72 // 创建Gson实例
62 Gson gson = new Gson(); 73 Gson gson = new Gson();
63 // 将List转换为Json字符串 74 // 将List转换为Json字符串
...@@ -126,15 +137,53 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i ...@@ -126,15 +137,53 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
126 * @param listQuestions 137 * @param listQuestions
127 * @param dbId 138 * @param dbId
128 */ 139 */
140 @Transactional
129 public void batchImportExcel(List<QuestionExcel> listQuestions, String dbId){ 141 public void batchImportExcel(List<QuestionExcel> listQuestions, String dbId){
130 142 Question question = null;
131 143 List<QuestionOption> optionList = null;
144 // 创建Gson实例
145 Gson gson = new Gson();
146 if(listQuestions != null && !listQuestions.isEmpty()){
147 for(QuestionExcel questionExcel : listQuestions){
148 String questionId = UniqIdUtils.getInstance().getUniqID();
149 System.out.println("试题编号 = "+questionId);
150 question = new Question();
151 question.setQuestionDbId(dbId);
152 question.setId(questionId);
153 question.setQuestionAnswer(questionExcel.getAnswer());
154 question.setQuestionType(questionExcel.getQuestionType());//试题类型:1 单选、2多选、3判断
155 question.setQuestionTitle(questionExcel.getQuestionTitle());
156 question.setAnalyzes(questionExcel.getAnalyzes());//试题解析
157
158 optionList = new ArrayList<>();
159 if(StringUtils.isNotEmpty(questionExcel.getOptionA()))optionList.add( new QuestionOption(questionId,"A",questionExcel.getOptionA(),checkAnswer(questionExcel.getAnswer(),"A")) ) ;
160 if(StringUtils.isNotEmpty(questionExcel.getOptionB()))optionList.add( new QuestionOption(questionId,"B",questionExcel.getOptionB(),checkAnswer(questionExcel.getAnswer(),"B")) ) ;
161 if(StringUtils.isNotEmpty(questionExcel.getOptionC()))optionList.add( new QuestionOption(questionId,"C",questionExcel.getOptionC(),checkAnswer(questionExcel.getAnswer(),"C")) ) ;
162 if(StringUtils.isNotEmpty(questionExcel.getOptionD()))optionList.add( new QuestionOption(questionId,"D",questionExcel.getOptionD(),checkAnswer(questionExcel.getAnswer(),"D")) ) ;
163 if(StringUtils.isNotEmpty(questionExcel.getOptionE()))optionList.add( new QuestionOption(questionId,"E",questionExcel.getOptionE(),checkAnswer(questionExcel.getAnswer(),"E")) ) ;
164 if(StringUtils.isNotEmpty(questionExcel.getOptionF()))optionList.add( new QuestionOption(questionId,"F",questionExcel.getOptionF(),checkAnswer(questionExcel.getAnswer(),"F")) ) ;
165 if(StringUtils.isNotEmpty(questionExcel.getOptionG()))optionList.add( new QuestionOption(questionId,"G",questionExcel.getOptionG(),checkAnswer(questionExcel.getAnswer(),"G")) ) ;
166
167 // 将List转换为Json字符串
168 String questionData = gson.toJson( question.getOptionList() ) ;
169 question.setQuestionData( questionData ) ;
170 this.baseMapper.insert(question);
171 //批量新增
172 questionOptionService.saveBatch(optionList);
173 }
174 }
132 /* // 创建Gson实例 175 /* // 创建Gson实例
133 Gson gson = new Gson(); 176 Gson gson = new Gson();
134 // 将List转换为Json字符串 177 // 将List转换为Json字符串
135 String questionData = gson.toJson( question.getOptionList() ) ; 178 String questionData = gson.toJson( question.getOptionList() ) ;
136 question.setQuestionData( questionData ) ;*/ 179 question.setQuestionData( questionData ) ;*/
137 } 180 }
181 private String checkAnswer(String answer,String option){
182 if(answer.toUpperCase().contains(option)){
183 return "1";
184 }
185 return "0" ;
186 }
138 187
139 188
140 /*** 189 /***
......
...@@ -56,5 +56,17 @@ public class QuestionExcel { ...@@ -56,5 +56,17 @@ public class QuestionExcel {
56 @ApiModelProperty(value = "试题解析") 56 @ApiModelProperty(value = "试题解析")
57 private String analyzes; 57 private String analyzes;
58 58
59 public QuestionExcel(){
59 60
61 }
62 public QuestionExcel(String questionType, String questionTitle, String optionA, String optionB, String optionC, String optionD, String answer, String analyzes) {
63 this.questionType = questionType;
64 this.questionTitle = questionTitle;
65 this.optionA = optionA;
66 this.optionB = optionB;
67 this.optionC = optionC;
68 this.optionD = optionD;
69 this.answer = answer;
70 this.analyzes = analyzes;
71 }
60 } 72 }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!