|
|
@ -7,8 +7,10 @@ import com.teaching.backend.common.ResultUtils; |
|
|
|
import com.teaching.backend.mapper.cms.CmsEssayMapper; |
|
|
|
import com.teaching.backend.mapper.cms.CmsEssayMapper; |
|
|
|
import com.teaching.backend.model.entity.cms.CmsEssay; |
|
|
|
import com.teaching.backend.model.entity.cms.CmsEssay; |
|
|
|
import com.teaching.backend.service.cms.ICmsEssayService; |
|
|
|
import com.teaching.backend.service.cms.ICmsEssayService; |
|
|
|
|
|
|
|
import com.teaching.backend.service.impl.umsAdmin.UmsUserServiceImpl; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
@ -23,6 +25,9 @@ import java.util.List; |
|
|
|
@Service |
|
|
|
@Service |
|
|
|
public class CmsEssayServiceImpl extends ServiceImpl<CmsEssayMapper, CmsEssay> implements ICmsEssayService { |
|
|
|
public class CmsEssayServiceImpl extends ServiceImpl<CmsEssayMapper, CmsEssay> implements ICmsEssayService { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
|
|
private UmsUserServiceImpl userService; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public BaseResponse<String> addEssay(CmsEssay cmsEssay) { |
|
|
|
public BaseResponse<String> addEssay(CmsEssay cmsEssay) { |
|
|
|
//设置文章发布时间
|
|
|
|
//设置文章发布时间
|
|
|
@ -30,9 +35,11 @@ public class CmsEssayServiceImpl extends ServiceImpl<CmsEssayMapper, CmsEssay> i |
|
|
|
//设置发布人姓名
|
|
|
|
//设置发布人姓名
|
|
|
|
// String nickName = userService.getById(cmsEssay.getUserId()).getNickName();
|
|
|
|
// String nickName = userService.getById(cmsEssay.getUserId()).getNickName();
|
|
|
|
// cmsEssay.setUsername(nickName);
|
|
|
|
// cmsEssay.setUsername(nickName);
|
|
|
|
|
|
|
|
//将浏览次数设置为0
|
|
|
|
|
|
|
|
cmsEssay.setReadingNumber(0); |
|
|
|
//如果数据库里没有文章,文章id设为2
|
|
|
|
//如果数据库里没有文章,文章id设为2
|
|
|
|
Long count = query().count(); |
|
|
|
Long count = query().count(); |
|
|
|
if (count == 0){ |
|
|
|
if (count == 0) { |
|
|
|
cmsEssay.setId(2); |
|
|
|
cmsEssay.setId(2); |
|
|
|
} |
|
|
|
} |
|
|
|
save(cmsEssay); |
|
|
|
save(cmsEssay); |
|
|
@ -42,7 +49,7 @@ public class CmsEssayServiceImpl extends ServiceImpl<CmsEssayMapper, CmsEssay> i |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public BaseResponse<String> deleteEssay(List<Integer> ids) { |
|
|
|
public BaseResponse<String> deleteEssay(List<Integer> ids) { |
|
|
|
//如果要删除的文章中包含id为1的文章(就是包含关于我们)就删除失败
|
|
|
|
//如果要删除的文章中包含id为1的文章(就是包含关于我们)就删除失败
|
|
|
|
if (ids.contains(1)){ |
|
|
|
if (ids.contains(1)) { |
|
|
|
return ResultUtils.success("删除失败,不能删除关于我们!"); |
|
|
|
return ResultUtils.success("删除失败,不能删除关于我们!"); |
|
|
|
} |
|
|
|
} |
|
|
|
removeByIds(ids); |
|
|
|
removeByIds(ids); |
|
|
@ -54,10 +61,10 @@ public class CmsEssayServiceImpl extends ServiceImpl<CmsEssayMapper, CmsEssay> i |
|
|
|
//获取要修改的文章id
|
|
|
|
//获取要修改的文章id
|
|
|
|
Integer id = cmsEssay.getId(); |
|
|
|
Integer id = cmsEssay.getId(); |
|
|
|
//判断文章id是否为1
|
|
|
|
//判断文章id是否为1
|
|
|
|
if (id == 1){ |
|
|
|
if (id == 1) { |
|
|
|
Long count = query().eq("id", id).count(); |
|
|
|
Long count = query().eq("id", id).count(); |
|
|
|
//如果数据库里没id为的文章就先新增
|
|
|
|
//如果数据库里没id为的文章就先新增
|
|
|
|
if (count == 0){ |
|
|
|
if (count == 0) { |
|
|
|
save(cmsEssay); |
|
|
|
save(cmsEssay); |
|
|
|
return ResultUtils.success("添加成功!"); |
|
|
|
return ResultUtils.success("添加成功!"); |
|
|
|
} |
|
|
|
} |
|
|
@ -83,4 +90,10 @@ public class CmsEssayServiceImpl extends ServiceImpl<CmsEssayMapper, CmsEssay> i |
|
|
|
public BaseResponse<CmsEssay> queryEssayById(Integer essayId) { |
|
|
|
public BaseResponse<CmsEssay> queryEssayById(Integer essayId) { |
|
|
|
return ResultUtils.success(getById(essayId)); |
|
|
|
return ResultUtils.success(getById(essayId)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public BaseResponse<String> views(Integer id) { |
|
|
|
|
|
|
|
boolean update = update().setSql("reading_number = reading_number + 1 where id = " + id).update(); |
|
|
|
|
|
|
|
return update ? ResultUtils.success("浏览次数加1") : ResultUtils.success("error!!!"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |