Commit 8c6408cc authored by YangZhaoJun1's avatar YangZhaoJun1

解决Bug

parent b6f0a937
...@@ -47,7 +47,8 @@ public interface BChapterRepository extends BaseMapper<BChapter> { ...@@ -47,7 +47,8 @@ public interface BChapterRepository extends BaseMapper<BChapter> {
" bf.video_url AS videoUrl,\n" + " bf.video_url AS videoUrl,\n" +
" bf.file_url AS fileUrl,\n" + " bf.file_url AS fileUrl,\n" +
" bf.ppt_url AS pptUrl,\n" + " bf.ppt_url AS pptUrl,\n" +
" bf.pdf_url AS pdfUrl,\n" + " bf.pdf_url AS pdfUrl," +
" bf.video_name AS fileName,\n" +
" pc.business_id AS paperUrl," + " pc.business_id AS paperUrl," +
" (SELECT count(*) FROM b_r_student_chapter brs WHERE brs.chapter_id = bc.business_id AND brs.score = - 1) AS studentNum \n" + " (SELECT count(*) FROM b_r_student_chapter brs WHERE brs.chapter_id = bc.business_id AND brs.score = - 1) AS studentNum \n" +
" FROM\n" + " FROM\n" +
......
...@@ -136,6 +136,9 @@ public class BChapter extends IdEntity<BChapter> { ...@@ -136,6 +136,9 @@ public class BChapter extends IdEntity<BChapter> {
@Transient @Transient
private String paperUrl; private String paperUrl;
@Transient
private String fileName;
public BChapter(String businessId) { public BChapter(String businessId) {
this.businessId = businessId; this.businessId = businessId;
......
...@@ -156,55 +156,40 @@ public class BFileController extends PaginationController<BFile> { ...@@ -156,55 +156,40 @@ public class BFileController extends PaginationController<BFile> {
*/ */
@ApiOperation(value="下载文件", notes="下载文件") @ApiOperation(value="下载文件", notes="下载文件")
@ApiImplicitParam(name = "chapterId", value = "章节ID", required = true, dataType = "varchar") @ApiImplicitParam(name = "chapterId", value = "章节ID", required = true, dataType = "varchar")
@PostMapping(value = "/downloadFileWithoutAuth") @GetMapping(value = "/downloadFileWithoutAuth")
public Result downloadFileWithoutAuth(String chapterId, HttpServletResponse response){ public Result downloadFileWithoutAuth(String chapterId, HttpServletResponse response) throws IOException {
BFile bFile = bFileService.queryFileUrlByChapterId(chapterId); BFile bFile = bFileService.queryFileUrlByChapterId(chapterId);
BufferedInputStream bis = null; BufferedInputStream bis = null;
BufferedOutputStream bos = null; BufferedOutputStream bos = null;
if(bFile.getFileUrl()!=""&&bFile.getFileUrl()!=null){ if(bFile.getFileUrl()!=""&&bFile.getFileUrl()!=null){
try { File file=new File(global.getBASE_UPLOAD_SERVER_LOCATION()+File.separator+bFile.getFileUrl());
File file=new File(global.getBASE_UPLOAD_SERVER_LOCATION()+bFile.getFileUrl()); if(!file.isFile()){
bis = new BufferedInputStream(new FileInputStream(file)); throw new ServiceException(ResultServiceEnums.DOWNLOAD_ERROR);
bos = new BufferedOutputStream(response.getOutputStream());
String fileName = "";
if(bFile.getVideoName()!=null&&!bFile.getVideoName().equals("")&&bFile.getVideoName().endsWith(".zip")){
fileName = bFile.getVideoName();
}else{
fileName = file.getName();
}
response.reset();
response.setContentType("application/octet-stream;charset=utf-8");
response.setHeader("Content-Disposition", "attachment;filename="+ new String((fileName).getBytes(), "iso-8859-1"));
response.setHeader("Access-Control-Allow-Origin", "*");
IOUtils.copy(bis, bos);
}catch (Exception e){
e.printStackTrace();
}finally {
if (bis != null)
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
if (bos != null)
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
} }
return Result.builder(new PersistModel(1), bis = new BufferedInputStream(new FileInputStream(file));
MessageConstant.MESSAGE_ALERT_SUCCESS, bos = new BufferedOutputStream(response.getOutputStream());
MessageConstant.MESSAGE_ALERT_ERROR,
""); String fileName = "";
}else{ if(bFile.getVideoName()!=null&&!bFile.getVideoName().equals("")&&bFile.getVideoName().endsWith(".zip")){
return Result.builder(new PersistModel(0), fileName = bFile.getVideoName();
MessageConstant.MESSAGE_ALERT_SUCCESS, }else{
MessageConstant.MESSAGE_ALERT_ERROR, fileName = file.getName();
""); }
response.reset();
response.setContentType("application/octet-stream;charset=utf-8");
response.setHeader("Content-Disposition", "attachment;filename="+ new String((fileName).getBytes(), "iso-8859-1"));
response.setHeader("Access-Control-Allow-Origin", "*");
IOUtils.copy(bis, bos);
bis.close();
bos.close();
}else {
throw new ServiceException(ResultServiceEnums.DOWNLOAD_ERROR);
} }
return Result.builder(new PersistModel(1),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
"");
} }
} }
......
...@@ -197,7 +197,7 @@ public class BSlServiceImpl implements BSlService { ...@@ -197,7 +197,7 @@ public class BSlServiceImpl implements BSlService {
lessonCode.add(value[1]); lessonCode.add(value[1]);
continue; continue;
} }
if ((bTermRepository.selectOne(new BTerm(value[3]))) == null) { if ((bTermRepository.selectOne(new BTerm(value[3],null))) == null) {
if (!termCode.contains(value[3])) if (!termCode.contains(value[3]))
termCode.add(value[3]); termCode.add(value[3]);
continue; continue;
......
...@@ -80,7 +80,7 @@ public class BSlApplyServiceImpl implements BSlApplyService { ...@@ -80,7 +80,7 @@ public class BSlApplyServiceImpl implements BSlApplyService {
@Transactional(propagation = Propagation.REQUIRED,readOnly = false) @Transactional(propagation = Propagation.REQUIRED,readOnly = false)
public PersistModel persist(BSlApply model, String token){ public PersistModel persist(BSlApply model, String token){
int line = 0; int line = 0;
if(model.getTermCode()!=null&&bTermRepository.selectOne(new BTerm(model.getTermCode()))==null) if(model.getTermCode()!=null&&bTermRepository.selectOne(new BTerm(model.getTermCode(),null))==null)
throw new ServiceException(ResultServiceEnums.TERM_NOT_EXISTS); throw new ServiceException(ResultServiceEnums.TERM_NOT_EXISTS);
if(model.getTeacherCode()!=null&&bTeacherRepository.selectOne(new BTeacher(model.getTeacherCode()))==null) if(model.getTeacherCode()!=null&&bTeacherRepository.selectOne(new BTeacher(model.getTeacherCode()))==null)
throw new ServiceException(ResultServiceEnums.TEACHER_NOT_EXISTS); throw new ServiceException(ResultServiceEnums.TEACHER_NOT_EXISTS);
......
...@@ -144,15 +144,15 @@ public class BTermController extends PaginationController<BTerm> { ...@@ -144,15 +144,15 @@ public class BTermController extends PaginationController<BTerm> {
@ApiOperation(value="更改当前学期", notes="更改当前学期") @ApiOperation(value="更改当前学期", notes="更改当前学期")
@ApiImplicitParam(name = "id", value = "businessId", required = true, dataType = "varchar") @ApiImplicitParam(name = "code", value = "code", required = true, dataType = "varchar")
@PreAuthorize("hasRole('ROLE_1001')") @PreAuthorize("hasRole('ROLE_1001')")
@PostMapping(value = "/changeCurrent") @PostMapping(value = "/changeCurrent")
public Result changeCurrent(@RequestParam("id") String id){ public Result changeCurrent(@RequestParam("code") String code){
PersistModel data=bTermService.changeCurrent(id); PersistModel data=bTermService.changeCurrent(code);
return Result.builder(data, return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR, MessageConstant.MESSAGE_ALERT_ERROR,
id); code);
} }
@ApiOperation(value="获取校历", notes="获取校历") @ApiOperation(value="获取校历", notes="获取校历")
......
...@@ -46,8 +46,8 @@ public interface BTermRepository extends BaseMapper<BTerm> { ...@@ -46,8 +46,8 @@ public interface BTermRepository extends BaseMapper<BTerm> {
@Update("<script>update b_term set current = '0'</script>") @Update("<script>update b_term set current = '0'</script>")
int changeAllTermNotCurrent(); int changeAllTermNotCurrent();
@Update("<script>update b_term set current = '1' where business_id = #{id}</script>") @Update("<script>update b_term set current = '1' where code = #{code} and del_flag = 0 and flag = 1</script>")
int changeCurrent(String id); int changeCurrent(String code);
@Select("select max_sl_code from b_term where code = #{termCode}") @Select("select max_sl_code from b_term where code = #{termCode}")
int queryMaxSlCodeByTermCode(String termCode); int queryMaxSlCodeByTermCode(String termCode);
...@@ -69,5 +69,13 @@ public interface BTermRepository extends BaseMapper<BTerm> { ...@@ -69,5 +69,13 @@ public interface BTermRepository extends BaseMapper<BTerm> {
@Select("select * from b_term where code = #{termCode}") @Select("select * from b_term where code = #{termCode}")
@ResultMap(value = "BaseResultMap" ) @ResultMap(value = "BaseResultMap" )
BTerm queryCurrentTerm(String termCode); BTerm queryCurrentTerm(String termCode);
@Select("select * from b_term " +
"WHERE (#{startDate} BETWEEN start_date AND end_date) " +
"OR (#{endDate} BETWEEN start_date AND end_date) " +
"OR (start_date BETWEEN #{startDate} AND #{endDate}) " +
"OR (end_date BETWEEN #{startDate} AND #{endDate})")
@ResultMap(value = "BaseResultMap" )
List<BTerm> queryBTermsByStartDateOrEndDate(BTerm model);
} }
...@@ -24,8 +24,9 @@ public class BTerm extends IdEntity<BTerm> { ...@@ -24,8 +24,9 @@ public class BTerm extends IdEntity<BTerm> {
private static final long serialVersionUID = 6619306545135522432L; private static final long serialVersionUID = 6619306545135522432L;
public BTerm(String code) { public BTerm(String code, String name) {
this.code = code; this.code = code;
this.name = name;
} }
......
...@@ -58,7 +58,7 @@ public interface BTermService{ ...@@ -58,7 +58,7 @@ public interface BTermService{
List<SelectModel> queryBTermList(); List<SelectModel> queryBTermList();
PersistModel changeCurrent(String id); PersistModel changeCurrent(String code);
Map<String,Object> getSchoolWeek(String termCode); Map<String,Object> getSchoolWeek(String termCode);
} }
...@@ -56,13 +56,22 @@ public class BTermServiceImpl implements BTermService { ...@@ -56,13 +56,22 @@ public class BTermServiceImpl implements BTermService {
@Override @Override
@Transactional(propagation = Propagation.REQUIRED,readOnly = false) @Transactional(propagation = Propagation.REQUIRED,readOnly = false)
public PersistModel persist(BTerm model, String token){ public PersistModel persist(BTerm model, String token){
//验证时间区间是否重叠
List<BTerm> bTerms = bTermRepository.queryBTermsByStartDateOrEndDate(model);
if(bTerms.size()>0){
throw new ServiceException(ResultServiceEnums.CAN_NOT_OVERLAP);
}
//验证名称是否重复
if(bTermRepository.selectOne(new BTerm(null,model.getName()))!=null)
throw new ServiceException(ResultServiceEnums.NAME_IS_EXISTS);
int line = 0; int line = 0;
model.setWeek(String.valueOf(Week.buildList(model.getStartDate(),model.getEndDate()).size() + 1)); model.setWeek(String.valueOf(Week.buildList(model.getStartDate(),model.getEndDate()).size() + 1));
if(model.getBusinessId()!=null) { if(model.getBusinessId()!=null) {
UserUtil.setCurrentMergeOperation(model); UserUtil.setCurrentMergeOperation(model);
line = bTermRepository.updateByPrimaryKeySelective(model); line = bTermRepository.updateByPrimaryKeySelective(model);
}else { }else {
if(bTermRepository.selectOne(new BTerm(model.getCode()))!=null) //验证编号是否重复
if(bTermRepository.selectOne(new BTerm(model.getCode(),null))!=null)
throw new ServiceException(ResultServiceEnums.TERM_EXISTS); throw new ServiceException(ResultServiceEnums.TERM_EXISTS);
Map<String,Object> map = Week.buildWeek(model.getStartDate(),model.getEndDate()); Map<String,Object> map = Week.buildWeek(model.getStartDate(),model.getEndDate());
model.setWeek(String.valueOf(((List<Week>) map.get("weeks")).size())); model.setWeek(String.valueOf(((List<Week>) map.get("weeks")).size()));
...@@ -133,11 +142,11 @@ public class BTermServiceImpl implements BTermService { ...@@ -133,11 +142,11 @@ public class BTermServiceImpl implements BTermService {
} }
@Override @Override
public PersistModel changeCurrent(String id) { public PersistModel changeCurrent(String code) {
//先把学期全部置为否 //先把学期全部置为否
bTermRepository.changeAllTermNotCurrent(); bTermRepository.changeAllTermNotCurrent();
//把所选的学期置为是 //把所选的学期置为是
int result = bTermRepository.changeCurrent(id); int result = bTermRepository.changeCurrent(code);
return new PersistModel(result); return new PersistModel(result);
} }
......
...@@ -15,6 +15,7 @@ import org.springframework.http.converter.HttpMessageConverter; ...@@ -15,6 +15,7 @@ import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.security.access.AccessDeniedException; import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.DisabledException;
import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.AuthenticationException;
import org.springframework.web.method.HandlerMethod; import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerExceptionResolver; import org.springframework.web.servlet.HandlerExceptionResolver;
...@@ -80,7 +81,7 @@ public class MvcConfig extends WebMvcConfigurerAdapter { ...@@ -80,7 +81,7 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
if (handler instanceof HandlerMethod) { if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler; HandlerMethod handlerMethod = (HandlerMethod) handler;
if(e instanceof SystemException){ if(e instanceof SystemException){
/*sys*/ /*license*/
try { try {
throw e; throw e;
} catch (Exception e1) { } catch (Exception e1) {
...@@ -88,14 +89,16 @@ public class MvcConfig extends WebMvcConfigurerAdapter { ...@@ -88,14 +89,16 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
log.error(e1.getMessage()); log.error(e1.getMessage());
} }
} }
if (e instanceof ServiceException) {//业务失败的异常,如“账号或密码错误” if (e instanceof ServiceException) {//业务失败的异常,如“账号或密码错误”
result.setCode(ResultCode.FAIL).setMessage(e.getMessage()); result.setCode(ResultCode.FAIL).setMessage(e.getMessage());
} else if (e instanceof AuthenticationException) { } else if (e instanceof AuthenticationException) {
if (e instanceof BadCredentialsException) if (e instanceof BadCredentialsException) {
//密码错误 //密码错误
result.setCode(ResultCode.UNAUTHORIZED).setMessage(e.getMessage()); result.setCode(ResultCode.UNAUTHORIZED).setMessage(e.getMessage());
} else if (e instanceof DisabledException){
//用户已停用
result.setCode(ResultCode.UNAUTHORIZED).setMessage("用户已停用");
}
else else
result.setCode(ResultCode.UNAUTHORIZED).setMessage(e.getMessage()); result.setCode(ResultCode.UNAUTHORIZED).setMessage(e.getMessage());
} else if (e instanceof AccessDeniedException) { } else if (e instanceof AccessDeniedException) {
......
...@@ -20,6 +20,9 @@ public class JwtUser implements UserDetails{ ...@@ -20,6 +20,9 @@ public class JwtUser implements UserDetails{
private final String username; private final String username;
private final String password; private final String password;
private boolean enable = true;
/** 权限类.*/ /** 权限类.*/
private final Collection<? extends GrantedAuthority> authorities; private final Collection<? extends GrantedAuthority> authorities;
...@@ -68,6 +71,6 @@ public class JwtUser implements UserDetails{ ...@@ -68,6 +71,6 @@ public class JwtUser implements UserDetails{
} }
@JsonIgnore @JsonIgnore
public boolean isEnabled() { public boolean isEnabled() {
return true; return enable;
} }
} }
...@@ -187,6 +187,8 @@ public enum ResultServiceEnums { ...@@ -187,6 +187,8 @@ public enum ResultServiceEnums {
NAME_IS_EXISTS(99,"名称重复"), NAME_IS_EXISTS(99,"名称重复"),
DATA_HAS_USED(100,"当前数据被使用,不可删除"), DATA_HAS_USED(100,"当前数据被使用,不可删除"),
CAN_NOT_OVERLAP(101,"时间区间不可重叠"),
; ;
private Integer code; private Integer code;
......
package org.rcisoft.core.service.impl; package org.rcisoft.core.service.impl;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.rcisoft.core.constant.FlagStatus;
import org.rcisoft.core.model.JwtUser;
import org.rcisoft.core.util.JwtUserFactory; import org.rcisoft.core.util.JwtUserFactory;
import org.rcisoft.sys.role.dao.SysRoleRepository; import org.rcisoft.sys.role.dao.SysRoleRepository;
import org.rcisoft.sys.role.entity.SysRole; import org.rcisoft.sys.role.entity.SysRole;
...@@ -41,6 +43,10 @@ public class JwtUserDetailServiceImpl implements UserDetailsService { ...@@ -41,6 +43,10 @@ public class JwtUserDetailServiceImpl implements UserDetailsService {
if (CollectionUtils.isEmpty(roles)) if (CollectionUtils.isEmpty(roles))
roles = Collections.emptyList(); roles = Collections.emptyList();
sysUser.setRoleList(roles); sysUser.setRoleList(roles);
return JwtUserFactory.create(sysUser); JwtUser user = JwtUserFactory.create(sysUser);
/*停用*/
if(FlagStatus.ABNORMAL.getStatus().equals(sysUser.getFlag()))
user.setEnable(false);
return user;
} }
} }
...@@ -19,7 +19,7 @@ import java.util.List; ...@@ -19,7 +19,7 @@ import java.util.List;
public interface SysUserMapper extends BaseMapper<SysUser> { public interface SysUserMapper extends BaseMapper<SysUser> {
@Select("<script>select * from s_user where login_name = #{username} and del_flag = 0 and flag = 1</script>") @Select("<script>select * from s_user where login_name = #{username} and del_flag = 0 </script>")
@ResultMap(value = "BaseResultMap") @ResultMap(value = "BaseResultMap")
List<SysUser> queryUserByName(String username); List<SysUser> queryUserByName(String username);
...@@ -42,7 +42,7 @@ public interface SysUserMapper extends BaseMapper<SysUser> { ...@@ -42,7 +42,7 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
"(#{businessId},#{userId},#{roleId})") "(#{businessId},#{userId},#{roleId})")
int insertUserRole(UserRole userRole); int insertUserRole(UserRole userRole);
@Select("SELECT u.business_id from s_user u left join ${tab} s on u.login_name = s.code where s.business_id = #{id} and u.del_flag = 0 and u.flag = 1") @Select("SELECT u.business_id from s_user u left join ${tab} s on u.login_name = s.code where s.business_id = #{id} and u.del_flag = 0")
String selectUserIdByStuOrTeaId(@Param("id") String id, @Param("tab") String table); String selectUserIdByStuOrTeaId(@Param("id") String id, @Param("tab") String table);
@Update("update s_user set del_flag = 1 where login_name = #{code}") @Update("update s_user set del_flag = 1 where login_name = #{code}")
...@@ -74,7 +74,7 @@ public interface SysUserMapper extends BaseMapper<SysUser> { ...@@ -74,7 +74,7 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
@Update("<script>update s_user set password = #{password} where 1=1 " + @Update("<script>update s_user set password = #{password} where 1=1 " +
"and login_name = #{loginName} " + "and login_name = #{loginName} " +
"and del_flag = 0 and flag = 1</script>") "and del_flag = 0</script>")
int resetPassword(@Param("loginName") String loginNam,@Param("password") String password); int resetPassword(@Param("loginName") String loginNam,@Param("password") String password);
@Select("<script>select business_id from s_user where login_name = #{studentCode} and del_flag = 0 and flag = 1</script>") @Select("<script>select business_id from s_user where login_name = #{studentCode} and del_flag = 0 and flag = 1</script>")
......
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