列表返回值格式修改

hehai
shijie 4 years ago
parent 39eb350537
commit c3988b9618
  1. 46
      src/main/java/com/msdw/tms/common/utils/poi/ExcelExportUtil.java
  2. 2
      src/main/java/com/msdw/tms/common/utils/poi/ExcelImportUtil.java
  3. 6
      src/main/java/com/msdw/tms/controller/QuestionsController.java
  4. 50
      src/main/java/com/msdw/tms/entity/vo/QuestionsListVO.java
  5. 2
      src/main/java/com/msdw/tms/service/QuestionsService.java
  6. 18
      src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java
  7. 5
      src/test/java/com/msdw/tms/TmsApplicationTests.java
  8. 2
      src/test/java/com/msdw/tms/service/QuestionsServiceTest.java

@ -74,52 +74,6 @@ public class ExcelExportUtil<T> {
workbook.write(response.getOutputStream());
}
/**
* 基于注解导出
* 参数
* response
* objs数据
* fileName生成的文件名
*/
// public void export(HttpServletResponse response, List<T> objs, String fileName) throws Exception {
//
// //1.根据模板创建工作簿
// Workbook workbook = new XSSFWorkbook(); //2007版本
//
// fileName = URLEncoder.encode(fileName, "UTF-8");
//
// Sheet sheet = workbook.createSheet(fileName);
//
// //3.提取公共的样式
// // CellStyle[] styles = getTemplateStyles(sheet.getRow(styleIndex));
// //4.根据数据创建每一行和每一个单元格的数据2
// AtomicInteger datasAi = new AtomicInteger(rowIndex); //数字
// for (T t : objs) {
// //datasAi.getAndIncrement() :获取数字,并++ i++
// Row row = sheet.createRow(datasAi.getAndIncrement());
// for (int i = 0; i < styles.length; i++) {
// Cell cell = row.createCell(i);
// cell.setCellStyle(styles[i]);
// for (Field field : fields) {
// if (field.isAnnotationPresent(ExcelAttribute.class)) {
// field.setAccessible(true);
// ExcelAttribute ea = field.getAnnotation(ExcelAttribute.class);
// if (i == ea.sort()) {
// if (field.get(t) != null) {
// cell.setCellValue(field.get(t).toString());
// }
// }
// }
// }
// }
// }
//
// response.setContentType("application/octet-stream");
// response.setHeader("content-disposition", "attachment;filename=" + new String(fileName.getBytes("ISO8859-1")));
// response.setHeader("filename", fileName);
// workbook.write(response.getOutputStream());
// }
CellStyle[] getTemplateStyles(Row row) {
CellStyle[] styles = new CellStyle[row.getLastCellNum()];
for (int i = 0; i < row.getLastCellNum(); i++) {

@ -29,7 +29,7 @@ public class ExcelImportUtil<T> {
* 基于注解读取excel
*/
public List<T> readExcel(InputStream is, int rowIndex, int cellIndex) {
List<T> list = new ArrayList<T>();
List<T> list = new ArrayList<>();
T entity = null;
try {
XSSFWorkbook workbook = new XSSFWorkbook(is);

@ -88,10 +88,10 @@ public class QuestionsController implements QuestionsControllerApi {
* 是否禁用试题
*/
@Override
@PutMapping("/isnable")
//@RequiresPermissions("qms:questions:isnable")
@PutMapping("/isenable")
//@RequiresPermissions("qms:questions:isenable")
public R isNable(Integer id) {
boolean b = questionsService.isnable(id);
boolean b = questionsService.isEnable(id);
return b ? R.ok() : R.error();
}

@ -0,0 +1,50 @@
package com.msdw.tms.entity.vo;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
/**
* 试题列表展示信息
*
* @author gongsj
*/
@Data
@ToString
public class QuestionsListVO implements Serializable {
/**
* 主键
*/
private Integer id;
/**
* 题型号用于区分是什么题型
*/
private Integer questionTypeNo;
/**
* 题型名称
*/
private String questionType;
/**
* 题干信息
*/
private String questionStem;
/**
* 正确答案
*/
private String answer;
/**
* 答案解析
*/
private String answerAnalysis;
/**
* 是否禁用1启用0禁用默认是1启用
*/
private Integer isEnable;
/**
* 修改时间用于排序创建时修改时间等于创建时间
*/
private String modifyTime;
}

@ -34,7 +34,7 @@ public interface QuestionsService extends IService<QuestionsEntity> {
boolean updateQuestionById(QuestionsUpdateRequest questions);
boolean isnable(Integer id);
boolean isEnable(Integer id);
boolean deleteByIds(List<Integer> asList);

@ -18,10 +18,7 @@ import com.msdw.tms.entity.request.QuestionsImportRequest;
import com.msdw.tms.entity.request.QuestionsQueryRequest;
import com.msdw.tms.entity.request.QuestionsUpdateRequest;
import com.msdw.tms.entity.response.CommonCode;
import com.msdw.tms.entity.vo.EvaluationRulesVO;
import com.msdw.tms.entity.vo.EvaluationVO;
import com.msdw.tms.entity.vo.QuestionsDetailVO;
import com.msdw.tms.entity.vo.QuestionsVO;
import com.msdw.tms.entity.vo.*;
import com.msdw.tms.service.AliyunOssService;
import com.msdw.tms.service.EvaluationRulesService;
import com.msdw.tms.service.QuestionsService;
@ -94,15 +91,14 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
List<QuestionsEntity> records = questionsIPage.getRecords();
List<QuestionsVO> questions = records.stream().map(question -> {
QuestionsVO questionsVO = new QuestionsVO();
BeanUtils.copyProperties(question, questionsVO);
List<QuestionsListVO> questions = records.stream().map(question -> {
QuestionsListVO questionsListVO = new QuestionsListVO();
BeanUtils.copyProperties(question, questionsListVO);
//处理时间格式
questionsVO.setCreateTime(handleTime(question.getCreateTime()));
questionsVO.setModifyTime(handleTime(question.getModifyTime()));
questionsListVO.setModifyTime(handleTime(question.getModifyTime()));
return questionsVO;
return questionsListVO;
}).collect(Collectors.toList());
PageUtils questionsPage = new PageUtils(questionsIPage);
@ -246,7 +242,7 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
@Override
@Transactional
public boolean isnable(Integer id) {
public boolean isEnable(Integer id) {
QuestionsEntity questionsEntity = new QuestionsEntity();
questionsEntity.setId(id);
QuestionsEntity byId = this.getById(id);

@ -82,8 +82,9 @@ class TmsApplicationTests {
return instance;
}
public <T> T TestG(T t){
return t;
public <T, K> K t2(T t, K k) {
k = (K) "haha";
return k;
}
}

@ -70,7 +70,7 @@ class QuestionsServiceTest {
@Transactional
void isnable() {
Integer id = 1;
System.out.println(questionsService.isnable(id));
System.out.println(questionsService.isEnable(id));
}
@Test

Loading…
Cancel
Save