Commit f25ca85d authored by YangZhaoJun1's avatar YangZhaoJun1

解决bug,解决springBoot返回null值时前台获取不到对象的问题

parent 4b98f49b
......@@ -90,11 +90,12 @@ public class BChapterController extends PaginationController<BChapter> {
@ApiOperation(value="删除章节", notes="根据ID删除一条记录")
@ApiImplicitParam(name = "id", value = "businessId", required = true, dataType = "varchar")
@ApiImplicitParams({@ApiImplicitParam(name = "id", value = "businessId", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "lessonOrSl", value = "区分课程开课 0开课,1课程", required = true, dataType = "varchar")})
@PreAuthorize("hasAnyRole('ROLE_1001','ROLE_1002')")
@PostMapping(value = "/remove")
public Result remove(String id) {
PersistModel data = bChapterService.removeBChapter(id,getToken());
public Result remove(String id, String lessonOrSl) {
PersistModel data = bChapterService.removeBChapter(id,lessonOrSl);
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
......
......@@ -70,7 +70,7 @@ public interface BChapterService{
* @param scoreInfoDTOS
* @return
*/
void markScore(List<ScoreInfoDTO> scoreInfoDTOS,String token);
void markScore(List<ScoreInfoDTO> scoreInfoDTOS,String lessonOrSl);
/**
* 根据学生id和课程id获取该学生的课程章节分数列表
......
......@@ -129,20 +129,23 @@ public class BChapterServiceImpl implements BChapterService {
@Override
@Transactional(propagation = Propagation.REQUIRED,readOnly = false)
public PersistModel removeBChapter(String id,String token) {
public PersistModel removeBChapter(String id,String lessonOrSl) {
BChapter bChapter = bChapterRepository.selectByPrimaryKey(id);
if(bChapter==null)
throw new ServiceException(ResultServiceEnums.CHAPTER_NOT_EXISTS);
List<BChapter> childList = bChapterRepository.queryBChaptersByPid(id);
boolean hasChild =childList!=null&&childList.size()>0;
boolean isChapter = bChapter.getChapterLevel()== ChapterLevelEnum.CHAPTER.getCode();
if(isChapter&&hasChild)
if(isChapter&&hasChild) {
throw new ServiceException(ResultServiceEnums.CHAPTER_HAS_CHILD);
String state = bSlRepository.queryStateById(bChapter.getSlId());
}
String state;
if(lessonOrSl.equals("0")){
state = bSlRepository.queryStateById(bChapter.getSlId());
if(state.equals(AuditStatusEnum.PUBLISHED.getCode())){
throw new ServiceException(ResultServiceEnums.CHAPTER_IS_USED);
}
}
bChapterRepository.deleteStudentChapter(id);
int line = bChapterRepository.deleteByPrimaryKey(id);
return new PersistModel(line);
......@@ -222,6 +225,7 @@ public class BChapterServiceImpl implements BChapterService {
sl_chapter.setPid(lessonList.get(i).getPid());
map.put(lessonList.get(i).getBusinessId(),sl_chapter.getBusinessId());
}else{
sl_chapter.setPid("0");
sl_chapter.setLPid(lessonList.get(i).getPid());
}
//set老的章节ID后面比对用
......@@ -267,10 +271,10 @@ public class BChapterServiceImpl implements BChapterService {
BFile bFile = bFileRepository.queryBVideoByChapterId(leBChapter.getBusinessId());
BFile newVideo = new BFile();
newVideo.setChapterId(slChapter.getBusinessId());
newVideo.setVideoName(bFile.getVideoName());
UserUtil.setCurrentPersistOperation(newVideo);
//将节的ID替换成新的
if(bFile !=null){
newVideo.setVideoName(bFile.getVideoName());
if(bFile.getVideoUrl()!=null&&!bFile.getVideoUrl().equals("")){
String newUrl = bFile.getVideoUrl().replace(bLessonId,slId);
String path = newUrl.replace(leBChapter.getBusinessId(),slChapter.getBusinessId());
......
......@@ -114,6 +114,7 @@ public class BSlController extends PaginationController<BSl> {
@ApiImplicitParam(name = "teacherName", value = "教师姓名", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "lessonName", value = "课程名称", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "termName", value = "学期名称", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "termCode", value = "学期编号", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "auditStatus", value = "审核状态 0:待发布,1审核中,2已发布,3已驳回", required = false, dataType = "varchar")})
@GetMapping(value = "/queryBSlsByPagination")
public GridModel queryBSlsByPagination(BSl param) {
......@@ -285,15 +286,15 @@ public class BSlController extends PaginationController<BSl> {
@ApiOperation(value="根据 学号/工号 分页获取 历史学习课程/历史授课", notes="传学号代表查学生历史学习,传教师工号代表查教师历史授课,不能同时传")
@ApiImplicitParams({@ApiImplicitParam(name = "lessonName", value = "课程名称关键字", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "term", value = "学期名称关键字", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "termCode", value = "学期编号", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "studentCode", value = "学生学号", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "teacherCode", value = "教师工号", required = false, dataType = "varchar")})
@GetMapping(value = "/historySlByCode")
public GridModel historySlByCode(String lessonName,String term,String studentCode,String teacherCode) {
public GridModel historySlByCode(String lessonName,String termCode,String studentCode,String teacherCode) {
if((studentCode!=null&&!studentCode.equals(""))&&(teacherCode!=null&&!studentCode.equals(""))){
throw new ServiceException(ResultServiceEnums.PARAMER_ERROR);
}
bSlService.historySlByCodeByPagination(getPaginationUtility(),lessonName,term,studentCode,teacherCode);
bSlService.historySlByCodeByPagination(getPaginationUtility(),lessonName,termCode,studentCode,teacherCode);
GridModel gridModel = getGridModelResponse();
return gridModel;
}
......
......@@ -136,37 +136,27 @@ public interface BSlRepository extends BaseMapper<BSl> {
* @param id
* @return
*/
@Select("<script>SELECT\n" +
"\tt1.business_id as businessId,\n" +
"\tt1.`code` AS slCode,\n" +
"\tt1.sl_notes as slNotes,\n" +
"\tt1.sl_cover_url as coverUrl,\n" +
"\tt6.lesson_name as lessonName,\n" +
"\tt5.head_pic as teaPic,\n" +
"\tt5.`name` AS teaName,\n" +
"\tt5.t_num as teaSlNum,\n" +
"\tt5.`code` AS teaCode,\n" +
"\t(select count(*) from b_chapter bc where bc.sl_id=t1.business_id and bc.is_test like CONCAT('%','1','%' )) AS isTest,\n"+
"\t(select count(*) from b_chapter bc where bc.sl_id=t1.business_id and bc.is_test like CONCAT('%','2','%' )) AS video\n"+
@Select("<script>SELECT t1.business_id as businessId,t1.credits AS credits,t1.class_hour AS classHour,\n" +
"t1.audit_status AS auditStatus,t8.`name` AS directionName,t9.`name` AS termName,\n" +
"t1.`code` AS slCode,t1.sl_notes as slNotes,t1.sl_cover_url as coverUrl,\n" +
"t6.lesson_name as lessonName,t5.head_pic as teaPic,t5.`name` AS teaName,\n" +
"t5.t_num as teaSlNum,t5.`code` AS teaCode,\n" +
"(select count(*) from b_chapter bc where bc.sl_id=t1.business_id and bc.is_test like CONCAT('%','1','%' )) AS experiment,\n" +
"(select count(*) from b_chapter bc where bc.sl_id=t1.business_id and bc.is_test like CONCAT('%','2','%' )) AS video,\n" +
"(select count(*) from b_chapter bc where bc.sl_id=t1.business_id and bc.is_test like CONCAT('%','3','%' )) AS ppt,\n" +
"(select count(*) from b_chapter bc where bc.sl_id=t1.business_id and bc.is_test like CONCAT('%','4','%' )) AS pdf\n" +
"FROM\n" +
"\tb_sl t1\n" +
"LEFT JOIN b_lesson t6\n" +
"ON t1.lesson_code = t6.`code`\n" +
"LEFT JOIN (\n" +
"\tSELECT\n" +
"\t\tcount(t3.business_id) AS t_num,\n" +
"\t\tt4.`name`,\n" +
"\t\tt2.`code`,\n" +
"\t\tt4.head_pic\n" +
"\tFROM\n" +
"\t\tb_teacher t2\n" +
"\tLEFT JOIN b_sl t3 ON t2.`code` = t3.teacher_code\n" +
"\tLEFT JOIN s_user t4 ON t4.login_name = t2.`code`\n" +
"\tGROUP BY\n" +
"\t\tt3.teacher_code\n" +
") t5 ON t5.`code` = t1.teacher_code\n" +
"b_sl t1\n" +
"LEFT JOIN b_lesson_direction t7 ON t1.business_id = t7.sl_id\n" +
"LEFT JOIN b_direction t8 ON t7.direction_id = t8.business_id\n" +
"LEFT JOIN b_term t9 ON t1.term_code = t9.`code`\n" +
"LEFT JOIN b_lesson t6 ON t1.lesson_code = t6.`code`\n" +
"LEFT JOIN (SELECT count(t3.business_id) AS t_num,t4.`name`,t2.`code`,t4.head_pic FROM b_teacher t2\n" +
"LEFT JOIN b_sl t3 ON t2.`code` = t3.teacher_code\n" +
"LEFT JOIN s_user t4 ON t4.login_name = t2.`code`\n" +
"GROUP BY t3.teacher_code) t5 ON t5.`code` = t1.teacher_code\n" +
"WHERE\n" +
"\tt1.business_id = #{id}</script>")
"t1.business_id = #{id}</script>")
SlDetailDTO selectSlDetailDTOById(@Param("id") String id);
/**
......@@ -224,12 +214,12 @@ public interface BSlRepository extends BaseMapper<BSl> {
@Select("<script>select *, bl.lesson_name as lessonName from b_sl sl left join b_r_sl_student stu on sl.code = stu.sl_code " +
"left join b_term bt on sl.term_code = bt.code " +
"left join b_lesson bl on sl.lesson_code = bl.code " +
"where sl.del_flag != '1' and sl.flag = '1' " +
"where sl.del_flag != '1' and sl.flag = '1' and sl.audit_status = '4' " +
"<if test=\"lessonName!=null and lessonName != ''\">" +
" AND bl.lesson_name LIKE CONCAT('%',#{lessonName},'%') " +
"</if>" +
"<if test=\"term!=null and term != ''\">" +
" AND bt.name LIKE CONCAT('%',#{term},'%') " +
"<if test=\"termCode!=null and termCode != ''\">" +
" AND sl.term_code LIKE CONCAT('%',#{termCode},'%') " +
"</if>" +
"<if test=\"studentCode!=null and studentCode != ''\">" +
" AND stu.student_code = #{studentCode} " +
......@@ -240,7 +230,7 @@ public interface BSlRepository extends BaseMapper<BSl> {
"</script>")
@ResultMap(value = "BaseResultMap" )
List<BSl> historySlByCodeByPagination(@Param("lessonName") String lessonName,
@Param("term") String term,
@Param("termCode") String termCode,
@Param("studentCode")String studentCode,
@Param("teacherCode")String teacherCode);
......@@ -248,6 +238,6 @@ public interface BSlRepository extends BaseMapper<BSl> {
int updateAuditStatus(@Param("slId") String slId, @Param("code") String code);
@Select("select audit_status from b_sl where business_id = #{slId}")
String queryStateById(String slId);
String queryStateById(@Param("slId") String slId);
}
......@@ -18,8 +18,13 @@ public class SlDetailDTO {
private String teaName;
private String teaSlNum;
private String teaCode;
private String isTest;
@Transient
private String experiment;
private String video;
private String ppt;
private String pdf;
private String credits;
private String classHour;
private String directionName;
private String termName;
private String auditStatus;
}
......@@ -118,7 +118,7 @@ public interface BSlService{
int queryBslTeacher(String teacherCode, String businessId);
List<BSl> historySlByCodeByPagination(PageUtil pageUtil, String lessonName, String term, String studentCode, String teacherCode);
List<BSl> historySlByCodeByPagination(PageUtil pageUtil, String lessonName, String termCode, String studentCode, String teacherCode);
int auditBsl(String slId, String status, String opinion);
}
......@@ -334,8 +334,8 @@ public class BSlServiceImpl implements BSlService {
}
@Override
public List<BSl> historySlByCodeByPagination(PageUtil pageUtil, String lessonName, String term, String studentCode, String teacherCode) {
return bSlRepository.historySlByCodeByPagination(lessonName,term,studentCode,teacherCode);
public List<BSl> historySlByCodeByPagination(PageUtil pageUtil, String lessonName, String termCode, String studentCode, String teacherCode) {
return bSlRepository.historySlByCodeByPagination(lessonName,termCode,studentCode,teacherCode);
}
@Transactional(propagation = Propagation.REQUIRED,readOnly = false)
......
package org.rcisoft.config;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
/**
* Created by YangZhaojun on 2018/1/3.
* 自定义ObjectMapper
* springBoot返回json数据时会将数据库为null的字段过滤,前台看不见返回值,这个类是null值转化为空字符串操作,便于前台判断
*/
public class NullSerializer extends ObjectMapper {
private static final long serialVersionUID = -2785650514571869859L;
public NullSerializer(){
super();
// null值处理为空字符串
this.getSerializerProvider().setNullValueSerializer(new JsonSerializer<Object>() {
@Override
public void serialize(Object value, JsonGenerator jg, SerializerProvider sp)
throws IOException, JsonProcessingException {
jg.writeString("");
}
});
}
}
package org.rcisoft.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
/**
* Created by YangZhaojun on 2018/1/3.
* 将自定义ObjectMapper加入到SpringBoot中
*/
@Configuration
public class NullSerializerConfig {
@Bean
public MappingJackson2HttpMessageConverter mappingJacksonHttpMessageConverter() {
final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
NullSerializer mapper = new NullSerializer();
converter.setObjectMapper(mapper);
return converter;
}
}
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