@ -4,12 +4,8 @@ import cn.hutool.core.util.IdUtil;
import com.sztzjy.resource_center.annotation.AnonymousAccess ;
import com.sztzjy.resource_center.config.security.JwtUser ;
import com.sztzjy.resource_center.config.security.TokenProvider ;
import com.sztzjy.resource_center.entity.SysOneCatalog ;
import com.sztzjy.resource_center.entity.SysThreeCatalog ;
import com.sztzjy.resource_center.entity.SysTwoCatalog ;
import com.sztzjy.resource_center.mapper.SysOneCatalogMapper ;
import com.sztzjy.resource_center.mapper.SysThreeCatalogMapper ;
import com.sztzjy.resource_center.mapper.SysTwoCatalogMapper ;
import com.sztzjy.resource_center.entity.* ;
import com.sztzjy.resource_center.mapper.* ;
import com.sztzjy.resource_center.util.ResultEntity ;
import io.swagger.annotations.Api ;
import io.swagger.annotations.ApiOperation ;
@ -25,6 +21,7 @@ import java.util.Date;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
import java.util.stream.Collectors ;
/ * *
* @Author xcj
@ -42,6 +39,11 @@ public class CourseTagManageController {
private SysThreeCatalogMapper sysThreeCatalogMapper ;
@Resource
private AuthenticationManagerBuilder authenticationManagerBuilder ;
@Autowired
private SysTopicAndCourseMapper sysTopicAndCourseMapper ;
@Autowired
private SysResourceAndCourseMapper sysResourceAndCourseMapper ;
@AnonymousAccess
@ApiOperation ( "添加二级目录" )
@ -89,10 +91,35 @@ public class CourseTagManageController {
SysTwoCatalog sysTwoCatalog = sysTwoCatalogMapper . selectByPrimaryKey ( id ) ;
sysTwoCatalog . setTwoName ( name ) ;
sysTwoCatalogMapper . updateByPrimaryKey ( sysTwoCatalog ) ;
SysResourceAndCourseExample example = new SysResourceAndCourseExample ( ) ;
example . createCriteria ( ) . andTwoIdEqualTo ( id ) ;
List < SysResourceAndCourse > sysResourceAndCourses = sysResourceAndCourseMapper . selectByExample ( example ) ;
List < String > ids = sysResourceAndCourses . stream ( ) . map ( SysResourceAndCourse : : getId ) . collect ( Collectors . toList ( ) ) ;
sysResourceAndCourseMapper . batchUpdateTwoName ( ids , name ) ;
SysTopicAndCourseExample example1 = new SysTopicAndCourseExample ( ) ;
example1 . createCriteria ( ) . andTwoIdEqualTo ( id ) ;
List < SysTopicAndCourse > sysTopicAndCourses = sysTopicAndCourseMapper . selectByExample ( example1 ) ;
List < String > collect = sysTopicAndCourses . stream ( ) . map ( SysTopicAndCourse : : getId ) . collect ( Collectors . toList ( ) ) ;
sysTopicAndCourseMapper . batchUpdateTwoName ( collect , name ) ;
} else {
SysThreeCatalog sysThreeCatalog = sysThreeCatalogMapper . selectByPrimaryKey ( id ) ;
sysThreeCatalog . setThreeName ( name ) ;
sysThreeCatalogMapper . updateByPrimaryKey ( sysThreeCatalog ) ;
SysResourceAndCourseExample example = new SysResourceAndCourseExample ( ) ;
example . createCriteria ( ) . andThreeIdEqualTo ( id ) ;
List < SysResourceAndCourse > sysResourceAndCourses = sysResourceAndCourseMapper . selectByExample ( example ) ;
List < String > ids = sysResourceAndCourses . stream ( ) . map ( SysResourceAndCourse : : getId ) . collect ( Collectors . toList ( ) ) ;
sysResourceAndCourseMapper . batchUpdateThreeName ( ids , name ) ;
SysTopicAndCourseExample example1 = new SysTopicAndCourseExample ( ) ;
example1 . createCriteria ( ) . andThreeIdEqualTo ( id ) ;
List < SysTopicAndCourse > sysTopicAndCourses = sysTopicAndCourseMapper . selectByExample ( example1 ) ;
List < String > collect = sysTopicAndCourses . stream ( ) . map ( SysTopicAndCourse : : getId ) . collect ( Collectors . toList ( ) ) ;
sysTopicAndCourseMapper . batchUpdateThreeName ( collect , name ) ;
}
return new ResultEntity < > ( HttpStatus . OK , "修改成功" ) ;
}
@ -103,10 +130,34 @@ public class CourseTagManageController {
@PostMapping ( "deleteTwoAndThreeCatalog" )
public ResultEntity < String > deleteTwoAndThreeCatalog ( @ApiParam ( "二级目录传2/三级传3" ) @RequestParam int type ,
@RequestParam String id ) {
if ( type = = 2 ) {
sysTwoCatalogMapper . deleteByPrimaryKey ( id ) ;
} else {
sysThreeCatalogMapper . deleteByPrimaryKey ( id ) ;
try {
if ( type = = 2 ) {
sysTwoCatalogMapper . deleteByPrimaryKey ( id ) ;
//删除资源
SysResourceAndCourseExample example1 = new SysResourceAndCourseExample ( ) ;
example1 . createCriteria ( ) . andTwoIdEqualTo ( id ) ;
sysResourceAndCourseMapper . deleteByExample ( example1 ) ;
//删除题目
SysTopicAndCourseExample example = new SysTopicAndCourseExample ( ) ;
example . createCriteria ( ) . andTwoIdEqualTo ( id ) ;
sysTopicAndCourseMapper . deleteByExample ( example ) ;
} else {
sysThreeCatalogMapper . deleteByPrimaryKey ( id ) ;
//删除资源
SysResourceAndCourseExample example1 = new SysResourceAndCourseExample ( ) ;
example1 . createCriteria ( ) . andThreeIdEqualTo ( id ) ;
sysResourceAndCourseMapper . deleteByExample ( example1 ) ;
//删除题目
SysTopicAndCourseExample example = new SysTopicAndCourseExample ( ) ;
example . createCriteria ( ) . andThreeIdEqualTo ( id ) ;
sysTopicAndCourseMapper . deleteByExample ( example ) ;
sysThreeCatalogMapper . deleteByPrimaryKey ( id ) ;
}
} catch ( Exception e ) {
e . printStackTrace ( ) ;
return new ResultEntity < > ( HttpStatus . INTERNAL_SERVER_ERROR , "删除失败,请联系管理员" ) ;
}
return new ResultEntity < > ( HttpStatus . OK , "删除成功" ) ;
}
@ -153,7 +204,7 @@ public class CourseTagManageController {
@AnonymousAccess
@ApiOperation ( "二级目录重新排序" )
@PostMapping ( "setTwoCatalogueRank" )
public ResultEntity setTwoCatalogueRank ( @ApiParam ( "一级ID( 可为空) , 二级ID和sort必传" ) @RequestBody List < SysTwoCatalog > sysTwoCatalogs ) {
public ResultEntity setTwoCatalogueRank ( @ApiParam ( "一级ID( 可为空) , 二级ID和sort必传" ) @RequestBody List < SysTwoCatalog > sysTwoCatalogs ) {
for ( SysTwoCatalog sysTwoCatalog : sysTwoCatalogs ) {
if ( StringUtils . isBlank ( sysTwoCatalog . getTwoId ( ) )
| | sysTwoCatalog . getSort ( ) = = null ) {
@ -168,7 +219,7 @@ public class CourseTagManageController {
@AnonymousAccess
@ApiOperation ( "三级目录重新排序" )
@PostMapping ( "setThreeCatalogueRank" )
public ResultEntity setThreeCatalogueRank ( @ApiParam ( "需要一级( 可为空) 二级( 可为空) , 三级ID和sort必传" ) @RequestBody List < SysThreeCatalog > sysThreeCatalogs ) {
public ResultEntity setThreeCatalogueRank ( @ApiParam ( "需要一级( 可为空) 二级( 可为空) , 三级ID和sort必传" ) @RequestBody List < SysThreeCatalog > sysThreeCatalogs ) {
for ( SysThreeCatalog sysThreeCatalog : sysThreeCatalogs ) {
if ( StringUtils . isBlank ( sysThreeCatalog . getThreeId ( ) ) | | sysThreeCatalog . getSort ( ) = = null ) {
return new ResultEntity < > ( HttpStatus . BAD_REQUEST , "更新失败,缺少必须的数据!" ) ;