@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper ;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper ;
import com.zh.project0512.annotation.AdminCheckAuthorityAnnotation ;
import com.zh.project0512.annotation.AdminCheckAuthorityAnnotation ;
import com.zh.project0512.annotation.AdminTokenValid ;
import com.zh.project0512.annotation.AdminTokenValid ;
import com.zh.project0512.model.Brand ;
import com.zh.project0512.model.TopicActivity ;
import com.zh.project0512.model.TopicActivity ;
import com.zh.project0512.service.ITopicActivityService ;
import com.zh.project0512.service.ITopicActivityService ;
import com.zh.project0512.utils.MybatisPlusUtil ;
import com.zh.project0512.utils.MybatisPlusUtil ;
@ -15,7 +16,9 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema ;
import io.swagger.v3.oas.annotations.media.Schema ;
import io.swagger.v3.oas.annotations.tags.Tag ;
import io.swagger.v3.oas.annotations.tags.Tag ;
import lombok.Data ;
import lombok.Data ;
import net.sf.jsqlparser.statement.select.Top ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.validation.annotation.Validated ;
import org.springframework.validation.annotation.Validated ;
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 ;
@ -65,14 +68,24 @@ public class TopicActivityController {
@Operation ( summary = "新增动态" )
@Operation ( summary = "新增动态" )
@PostMapping ( "/add" )
@PostMapping ( "/add" )
@Transactional
@AdminTokenValid
@AdminTokenValid
@AdminCheckAuthorityAnnotation ( jurisdictionId = "4" )
@AdminCheckAuthorityAnnotation ( jurisdictionId = "4" )
public Result add ( @Validated @RequestBody AddTopicParam param ) {
public Result add ( @Validated @RequestBody AddTopicParam param ) {
TopicActivity topicActivity = new TopicActivity ( ) . setTitle ( param . getTitle ( ) ) . setSubtitle ( param . getSubtitle ( ) )
TopicActivity topicActivity = new TopicActivity ( )
. setType ( param . getType ( ) ) . setContent ( param . getContent ( ) ) . setDuration ( param . getDuration ( ) ) . setCover ( param . getCover ( ) ) . setCreatAt ( LocalDateTime . now ( ) ) ;
. setTitle ( param . getTitle ( ) )
. setSubtitle ( param . getSubtitle ( ) )
. setType ( param . getType ( ) )
. setContent ( param . getContent ( ) )
. setDuration ( param . getDuration ( ) )
. setCover ( param . getCover ( ) )
. setSortWeight ( 1 )
. setCreatAt ( LocalDateTime . now ( ) )
. setUpdateAt ( LocalDateTime . now ( ) ) ;
if ( param . getShowAtIndex ( ) ! = null & & param . getShowAtIndex ( ) = = 1 ) {
if ( param . getShowAtIndex ( ) ! = null & & param . getShowAtIndex ( ) = = 1 ) {
topicActivity . setShowAtIndex ( 1 ) ;
topicActivity . setShowAtIndex ( 1 ) ;
}
}
topicActivityService . updSortWeightPlus ( ) ;
topicActivityService . save ( topicActivity ) ;
topicActivityService . save ( topicActivity ) ;
return Result . success ( "添加完成" ) ;
return Result . success ( "添加完成" ) ;
}
}
@ -120,11 +133,11 @@ public class TopicActivityController {
UpdateWrapper < TopicActivity > qw = new UpdateWrapper < > ( ) ;
UpdateWrapper < TopicActivity > qw = new UpdateWrapper < > ( ) ;
qw . eq ( "id" , param . getId ( ) )
qw . eq ( "id" , param . getId ( ) )
. set ( param . getTitle ( ) ! = null , "title" , param . getTitle ( ) )
. set ( param . getTitle ( ) ! = null , "title" , param . getTitle ( ) )
. set ( param . getSubtitle ( ) ! = null , " title", param . getSubtitle ( ) )
. set ( param . getSubtitle ( ) ! = null , " sub title", param . getSubtitle ( ) )
. set ( param . getType ( ) ! = null , "t itl e", param . getType ( ) )
. set ( param . getType ( ) ! = null , "t yp e", param . getType ( ) )
. set ( param . getCover ( ) ! = null , " title ", param . getCover ( ) )
. set ( param . getCover ( ) ! = null , " cover ", param . getCover ( ) )
. set ( param . getDuration ( ) ! = null , " title ", param . getDuration ( ) )
. set ( param . getDuration ( ) ! = null , " duration ", param . getDuration ( ) )
. set ( param . getContent ( ) ! = null , " title ", param . getContent ( ) )
. set ( param . getContent ( ) ! = null , " content ", param . getContent ( ) )
. set ( "updateAt" , LocalDateTime . now ( ) ) ;
. set ( "updateAt" , LocalDateTime . now ( ) ) ;
return MybatisPlusUtil . sqlResult ( topicActivityService . update ( qw ) , "修改" ) ;
return MybatisPlusUtil . sqlResult ( topicActivityService . update ( qw ) , "修改" ) ;
}
}
@ -145,6 +158,7 @@ public class TopicActivityController {
public Result list ( @Validated @RequestBody ListTopicParam param ) {
public Result list ( @Validated @RequestBody ListTopicParam param ) {
QueryWrapper < TopicActivity > qw = new QueryWrapper < > ( ) ;
QueryWrapper < TopicActivity > qw = new QueryWrapper < > ( ) ;
qw . like ( param . getKeyword ( ) ! = null , "title" , param . getKeyword ( ) ) ;
qw . like ( param . getKeyword ( ) ! = null , "title" , param . getKeyword ( ) ) ;
qw . orderByAsc ( "sortWeight" ) ;
qw . orderByDesc ( "updateAt" , "creatAt" ) ;
qw . orderByDesc ( "updateAt" , "creatAt" ) ;
if ( param . getShowAtIndex ( ) ! = null & & param . getShowAtIndex ( ) = = true ) {
if ( param . getShowAtIndex ( ) ! = null & & param . getShowAtIndex ( ) = = true ) {
qw . eq ( "showAtIndex" , 1 ) ;
qw . eq ( "showAtIndex" , 1 ) ;
@ -191,4 +205,30 @@ public class TopicActivityController {
return MybatisPlusUtil . sqlResult ( topicActivityService . update ( updateWrapper ) , "编辑" ) ;
return MybatisPlusUtil . sqlResult ( topicActivityService . update ( updateWrapper ) , "编辑" ) ;
}
}
@Data
static class UpdTAParam {
@NotNull ( message = "id不能为空" )
@Min ( value = 1 , message = "id最小值为1" )
@Schema ( title = "动态id" )
private Integer id ;
@NotNull ( message = "排序权重不能为空" )
@Min ( value = 1 , message = "排序权重最小值为1" )
@Schema ( title = "排序权重:数字越小排序靠前" )
private Integer sortWeight ;
}
@Operation ( summary = "修改品牌排序" )
@PostMapping ( "/updSort" )
@AdminTokenValid
public Result updSort ( @Validated @RequestBody UpdTAParam param ) {
TopicActivity topicActivity = topicActivityService . getById ( param . getId ( ) ) ;
int origin = topicActivity . getSortWeight ( ) ;
int current = param . getSortWeight ( ) ;
if ( origin = = current ) {
return Result . fail ( HttpStatusEnum . CUSTOM_EXCEPTION , "权重无变化" ) ;
}
topicActivityService . updSort ( origin , current , origin > current ) ;
return Result . success ( "修改完成" ) ;
}
}
}