时间返回格式修改

hehai
shijie 4 years ago
parent ce2b17a796
commit bb9c251e90
  1. 4
      src/main/java/com/msdw/tms/entity/vo/QuestionsDetailVO.java
  2. 52
      src/main/java/com/msdw/tms/entity/vo/QuestionsVO.java
  3. 41
      src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java
  4. 45
      src/test/java/com/msdw/tms/TmsApplicationTests.java

@ -102,7 +102,7 @@ public class QuestionsDetailVO implements Serializable {
/** /**
* 创建时间 * 创建时间
*/ */
private Date createTime; private String createTime;
/** /**
* 修改人 * 修改人
*/ */
@ -110,7 +110,7 @@ public class QuestionsDetailVO implements Serializable {
/** /**
* 修改时间用于排序创建时修改时间等于创建时间 * 修改时间用于排序创建时修改时间等于创建时间
*/ */
private Date modifyTime; private String modifyTime;
/** /**
* 试题科目 * 试题科目
*/ */

@ -0,0 +1,52 @@
package com.msdw.tms.entity.vo;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
/**
* 试题列表展示信息
*
* @author gongsj
* @email gongsj@gmail.com
* @date 2020-08-19 09:28:06
*/
@Data
@ToString
public class QuestionsVO implements Serializable {
/**
* 自增主键
*/
private Integer id;
/**
* 题型号用于区分是什么题型
*/
private Integer questionTypeNo;
/**
* 题型名称
*/
private String questionType;
/**
* 题干信息
*/
private String questionStem;
/**
* 正确答案
*/
private String answer;
/**
* 答案解析
*/
private String answerAnalysis;
/**
* 修改时间用于排序创建时修改时间等于创建时间
*/
private String modifyTime;
/**
* 试题科目
*/
private String subjects;
}

@ -20,6 +20,7 @@ import com.msdw.tms.entity.response.CommonCode;
import com.msdw.tms.entity.vo.EvaluationRulesVO; import com.msdw.tms.entity.vo.EvaluationRulesVO;
import com.msdw.tms.entity.vo.EvaluationVO; import com.msdw.tms.entity.vo.EvaluationVO;
import com.msdw.tms.entity.vo.QuestionsDetailVO; import com.msdw.tms.entity.vo.QuestionsDetailVO;
import com.msdw.tms.entity.vo.QuestionsVO;
import com.msdw.tms.service.AliyunOssService; import com.msdw.tms.service.AliyunOssService;
import com.msdw.tms.service.EvaluationRulesService; import com.msdw.tms.service.EvaluationRulesService;
import com.msdw.tms.service.QuestionsService; import com.msdw.tms.service.QuestionsService;
@ -33,6 +34,10 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -89,14 +94,30 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
queryWrapper queryWrapper
); );
// PageUtils questionsPage = new PageUtils(questionsEntityIPage); PageUtils questionsPage = new PageUtils(questionsEntityIPage);
// List<QuestionsEntity> list = (List<QuestionsEntity>) questionsPage.getList(); List<QuestionsEntity> list = (List<QuestionsEntity>) questionsPage.getList();
//
// list.stream().map(item -> {
//
// })
return new PageUtils(questionsEntityIPage); List<QuestionsVO> collect = list.stream().map(item -> {
QuestionsVO questionsVO = new QuestionsVO();
BeanUtils.copyProperties(item, questionsVO);
//处理时间格式
questionsVO.setModifyTime(handleTime(item.getModifyTime()));
return questionsVO;
}).collect(Collectors.toList());
questionsPage.setList(collect);
return questionsPage;
}
//处理时间格式
private String handleTime(Date date) {
Instant instant = date.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
return localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); // 当前日期和时间
} }
@Override @Override
@ -106,6 +127,12 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
//查询试题信息 //查询试题信息
QuestionsEntity questionsEntity = this.getById(id); QuestionsEntity questionsEntity = this.getById(id);
BeanUtils.copyProperties(questionsEntity, questionsDetailVO); BeanUtils.copyProperties(questionsEntity, questionsDetailVO);
//处理时间
//处理时间格式
questionsDetailVO.setCreateTime(handleTime(questionsEntity.getCreateTime()));
questionsDetailVO.setModifyTime(handleTime(questionsEntity.getModifyTime()));
//处理每个选项是否为被设置为答案 //处理每个选项是否为被设置为答案
String answer = questionsEntity.getAnswer(); String answer = questionsEntity.getAnswer();

@ -3,11 +3,56 @@ package com.msdw.tms;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
@SpringBootTest @SpringBootTest
class TmsApplicationTests { class TmsApplicationTests {
@Test @Test
void contextLoads() { void contextLoads() {
// QuestionsVO questionsVO = new QuestionsVO();
//
// QuestionsEntity questionsEntity = new QuestionsEntity();
//
// questionsEntity.setId(1);
// questionsEntity.setQuestionType("单选题");
// questionsEntity.setQuestionStem("adfasdfasdfasd");
// questionsEntity.setQuestionTypeNo(1);
// questionsEntity.setIsEnable(1);
// questionsEntity.setIsDel(1);
// questionsEntity.setCreateUser("eqweq");
// questionsEntity.setModifyUser("sadsa");
// questionsEntity.setCreateTime(new Date());
// questionsEntity.setModifyTime(new Date());
// questionsEntity.setAnswer("asdasdasdsd");
// questionsEntity.setAnswerAnalysis("qeqwewqeqweeqweqwe");
// questionsEntity.setOptionA("dasdsada");
// questionsEntity.setOptionB("asdasd");
// questionsEntity.setOptionC("dasdsada");
// questionsEntity.setOptionD("dasdsada");
// questionsEntity.setOptionE("dasdsada");
// questionsEntity.setOptionF("dasdsada");
// questionsEntity.setSubjects("sadasd");
//
// BeanUtils.copyProperties(questionsEntity, questionsVO);
//
// System.out.println(questionsVO.toString());
Date date = new Date();
Instant instant = date.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
System.out.println("Date = " + date);
System.out.println("LocalDateTime = " + localDateTime);
String DateNow = localDateTime.format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss")); // 当前日期和时间
// String DateNow = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss")); // 当前日期和时间
System.out.println(DateNow);
} }
} }

Loading…
Cancel
Save