Commit 86794995 by aye

代码提交

parent b0c4f68b
...@@ -2,6 +2,7 @@ package com.jty.wsxt.application.service; ...@@ -2,6 +2,7 @@ package com.jty.wsxt.application.service;
import com.jty.wsxt.domain.model.paper.Paper; import com.jty.wsxt.domain.model.paper.Paper;
import com.jty.wsxt.interfaces.dto.PaperDto; import com.jty.wsxt.interfaces.dto.PaperDto;
import com.jty.wsxt.interfaces.dto.PaperSearchDto;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
/** /**
...@@ -13,11 +14,11 @@ import org.springframework.data.domain.Page; ...@@ -13,11 +14,11 @@ import org.springframework.data.domain.Page;
public interface PaperService { public interface PaperService {
/** /**
* 新增试卷 * 新增试卷
* @param paperDto paperDto * @param paperSearchDto paperDto
*/ */
void addPaper(PaperDto paperDto); void addPaper(PaperSearchDto paperSearchDto);
Page<Paper> findPagePaper(PaperDto paperDto); Page<Paper> findPagePaper(PaperSearchDto paperSearchDto);
/** /**
* 删除试卷 * 删除试卷
......
...@@ -6,6 +6,7 @@ import com.jty.wsxt.domain.model.paper.Paper; ...@@ -6,6 +6,7 @@ import com.jty.wsxt.domain.model.paper.Paper;
import com.jty.wsxt.infrastructure.support.BusinessException; import com.jty.wsxt.infrastructure.support.BusinessException;
import com.jty.wsxt.infrastructure.support.ResultCode; import com.jty.wsxt.infrastructure.support.ResultCode;
import com.jty.wsxt.interfaces.dto.PaperDto; import com.jty.wsxt.interfaces.dto.PaperDto;
import com.jty.wsxt.interfaces.dto.PaperSearchDto;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.Example; import org.springframework.data.domain.Example;
...@@ -23,32 +24,29 @@ import com.alibaba.fastjson.JSON; ...@@ -23,32 +24,29 @@ import com.alibaba.fastjson.JSON;
@Service @Service
public class PaperServiceImpl implements PaperService { public class PaperServiceImpl implements PaperService {
@Override @Override
public void addPaper(PaperDto paperDto) { public void addPaper(PaperSearchDto paperSearchDto) {
Paper paper = new Paper(); Paper paper = new Paper();
BeanUtils.copyProperties(paperDto,paper,"answer","firstFeedback","secondFeedback"); BeanUtils.copyProperties(paperSearchDto,paper,"answer","firstFeedback","secondFeedback");
paper.setAnswer(JSON.toJSONString(paperDto.getAnswer())); paper.setAnswer(JSON.toJSONString(paperSearchDto.getAnswer()));
paper.save(); paper.save();
} }
@Override @Override
public Page<Paper> findPagePaper(PaperDto paperDto) { public Page<Paper> findPagePaper(PaperSearchDto paperSearchDto) {
Paper paper = new Paper(); Paper paper = new Paper();
if(paperDto.getCreatorId() != null){ if(paperSearchDto.getModuleId() != null){
paper.setCreatorId(paperDto.getCreatorId()); paper.setModuleId(paperSearchDto.getModuleId());
} }
if(paperDto.getModuleId() != null){ if(paperSearchDto.getSubjectId() != null){
paper.setModuleId(paperDto.getModuleId()); paper.setSubjectId(paperSearchDto.getSubjectId());
} }
if(paperDto.getSubjectId() != null){ if(paperSearchDto.getTypeId() != null){
paper.setSubjectId(paperDto.getSubjectId()); paper.setTypeId(paperSearchDto.getTypeId());
}
if(paperDto.getTypeId() != null){
paper.setTypeId(paperDto.getTypeId());
} }
ExampleMatcher matcher = ExampleMatcher.matching().withMatcher("name",ExampleMatcher.GenericPropertyMatchers.contains()); ExampleMatcher matcher = ExampleMatcher.matching().withMatcher("name",ExampleMatcher.GenericPropertyMatchers.contains());
Example<Paper> example = Example.of(paper,matcher); Example<Paper> example = Example.of(paper,matcher);
return DomainRegistry.paperRepository().findAll(example,paperDto.getPageable()); return DomainRegistry.paperRepository().findAll(example,paperSearchDto.getPageable());
} }
@Override @Override
......
package com.jty.wsxt.domain.model.paper; package com.jty.wsxt.domain.model.paper;
import com.alibaba.fastjson.JSON;
import com.jty.wsxt.domain.DomainRegistry; import com.jty.wsxt.domain.DomainRegistry;
import com.jty.wsxt.domain.model.module.Module; import com.jty.wsxt.domain.model.module.Module;
import com.jty.wsxt.domain.shared.IdentifiedEntityObject; import com.jty.wsxt.domain.shared.IdentifiedEntityObject;
import com.jty.wsxt.infrastructure.support.BusinessException;
import com.jty.wsxt.infrastructure.support.ResultCode;
import com.jty.wsxt.interfaces.dto.PaperDto;
import lombok.Data; import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import javax.persistence.Entity; import javax.persistence.Entity;
import java.time.LocalDateTime;
/** /**
* Paper * Paper
...@@ -23,18 +29,24 @@ public class Paper extends IdentifiedEntityObject<Module> { ...@@ -23,18 +29,24 @@ public class Paper extends IdentifiedEntityObject<Module> {
private Integer creatorId; private Integer creatorId;
private String creatorName;
private Integer subjectId; private Integer subjectId;
private Integer typeId; private Integer typeId;
private Integer specialistId; private Integer specialistId;
private String specialistName;
private String answer; private String answer;
private String firstFeedback; private String firstFeedback;
private String secondFeedback; private String secondFeedback;
private LocalDateTime feedbackTime;
@Override @Override
public boolean sameIdentityAs(Module other) { public boolean sameIdentityAs(Module other) {
return false; return false;
...@@ -47,4 +59,24 @@ public class Paper extends IdentifiedEntityObject<Module> { ...@@ -47,4 +59,24 @@ public class Paper extends IdentifiedEntityObject<Module> {
public void delete(){ public void delete(){
DomainRegistry.paperRepository().delete(this); DomainRegistry.paperRepository().delete(this);
} }
public PaperDto cashToPaperDto(){
PaperDto paperDto = new PaperDto();
paperDto.setCreatorName(this.creatorName);
paperDto.setModuleName(DomainRegistry.moduleRepository().findById(this.moduleId).orElseThrow(()-> new BusinessException(ResultCode.DATA_IS_WRONG)).getName());
paperDto.setTypeName(DomainRegistry.typeRepository().findById(this.typeId).orElseThrow(()-> new BusinessException(ResultCode.DATA_IS_WRONG)).getName());
paperDto.setSpecialistName(this.specialistName);
paperDto.setName(this.name);
if (StringUtils.isNotEmpty(this.answer)) {
paperDto.setAnswer(JSON.parseArray(this.answer, String.class));
}
if (StringUtils.isNotEmpty(this.firstFeedback)) {
paperDto.setFirstFeedback(JSON.parseArray(this.firstFeedback, String.class));
}
if (StringUtils.isNotEmpty(this.secondFeedback)) {
paperDto.setSecondFeedback(JSON.parseArray(this.secondFeedback, String.class));
}
paperDto.setFeedbackTime(this.feedbackTime);
return paperDto;
}
} }
...@@ -2,13 +2,21 @@ package com.jty.wsxt.interfaces.controller; ...@@ -2,13 +2,21 @@ package com.jty.wsxt.interfaces.controller;
import com.jty.wsxt.application.ApplicationRegistry; import com.jty.wsxt.application.ApplicationRegistry;
import com.jty.wsxt.application.feign.UserFeign; import com.jty.wsxt.application.feign.UserFeign;
import com.jty.wsxt.domain.model.paper.Paper;
import com.jty.wsxt.infrastructure.support.Result;
import com.jty.wsxt.interfaces.dto.PaperDto; import com.jty.wsxt.interfaces.dto.PaperDto;
import com.jty.wsxt.interfaces.dto.PaperSearchDto;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
/** /**
* PaperController * PaperController
* *
...@@ -26,13 +34,20 @@ public class PaperController { ...@@ -26,13 +34,20 @@ public class PaperController {
} }
@PostMapping @PostMapping
public void addPaper(@RequestBody PaperDto paperDto){ public Result addPaper(@RequestBody PaperSearchDto paperSearchDto){
paperDto.setCreatorId(userFeign.getLoginId()); paperSearchDto.setCreatorId(userFeign.getLoginId());
ApplicationRegistry.paperService().addPaper(paperDto); paperSearchDto.setCreatorName(userFeign.getLoginName());
ApplicationRegistry.paperService().addPaper(paperSearchDto);
return Result.success();
} }
@GetMapping("/papers") @GetMapping("/papers")
public void getPapers(PaperDto paperDto){ public Result getPapers(PaperSearchDto paperSearchDto){
Page<Paper> paperPage = ApplicationRegistry.paperService().findPagePaper(paperSearchDto);
List<PaperDto> paperDtos = new ArrayList<>();
if(paperPage.getTotalElements() != 0){
paperPage.getContent().forEach(paper -> paperDtos.add(paper.cashToPaperDto()));
}
return Result.success(new PageImpl<>(paperDtos,paperPage.getPageable(),paperPage.getTotalElements()));
} }
} }
package com.jty.wsxt.interfaces.dto; package com.jty.wsxt.interfaces.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
import java.time.LocalDateTime;
/** /**
* PaperDto * PaperDto
* *
* @author Manjiajie * @author Manjiajie
* @since 2019-6-21 15:16:27 * @since 2019-6-21 16:46:36
*/ */
@Data @Data
public class PaperDto extends SuperDto { public class PaperDto extends PaperSearchDto {
private Integer moduleId;
private Integer creatorId;
private Integer subjectId;
private Integer typeId; private String moduleName;
private Integer specialistId; private String creatorName;
private String[] answer; private String typeName;
private String[] firstFeedback; private String specialistName;
private String[] secondFeedback; @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
private LocalDateTime feedbackTime;
} }
package com.jty.wsxt.interfaces.dto;
import lombok.Data;
import java.util.List;
/**
* PaperDto
*
* @author Manjiajie
* @since 2019-6-21 15:16:27
*/
@Data
public class PaperSearchDto extends SuperDto {
private Integer moduleId;
private Integer creatorId;
private String creatorName;
private Integer subjectId;
private Integer typeId;
private Integer specialistId;
private String specialistName;
private List<String> answer;
private List<String> firstFeedback;
private List<String> secondFeedback;
}
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