package cn.lili.modules.lmk.service.impl;
|
|
|
import cn.lili.base.Result;
|
import cn.lili.common.enums.ActivityCoverTypeEnum;
|
import cn.lili.modules.lmk.domain.entity.Activity;
|
import cn.lili.modules.lmk.domain.entity.MySubscribe;
|
import cn.lili.modules.lmk.domain.entity.News;
|
import cn.lili.modules.lmk.domain.form.ActivityForm;
|
import cn.lili.modules.lmk.domain.form.NewsForm;
|
import cn.lili.modules.lmk.domain.query.NewsQuery;
|
import cn.lili.modules.lmk.domain.vo.ActivityVO;
|
import cn.lili.modules.lmk.domain.vo.NewsVO;
|
import cn.lili.modules.lmk.mapper.NewsMapper;
|
import cn.lili.modules.lmk.service.NewsService;
|
import cn.lili.utils.PageUtil;
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import lombok.RequiredArgsConstructor;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.Assert;
|
|
import java.util.*;
|
import java.util.function.Function;
|
|
/**
|
* lmk-shop-java
|
* 新闻服务实现类
|
*
|
* @author : zxl
|
* @date : 2025-06-20 14:55
|
**/
|
@Service
|
@RequiredArgsConstructor
|
public class NewsServiceImpl extends ServiceImpl<NewsMapper, News> implements NewsService {
|
|
private final NewsMapper newsMapper;
|
@Override
|
public Result add(NewsForm form) {
|
News entity = NewsForm.getEntityByForm(form, null);
|
baseMapper.insert(entity);
|
return Result.ok("添加成功");
|
}
|
|
@Override
|
public Result update(NewsForm form) {
|
News entity = baseMapper.selectById(form.getId());
|
|
Assert.notNull(entity, "记录不存在");
|
BeanUtils.copyProperties(form, entity);
|
|
baseMapper.updateById(entity);
|
|
|
return Result.ok("修改成功");
|
}
|
|
@Override
|
public Result remove(List<String> ids) {
|
baseMapper.deleteBatchIds(ids);
|
return Result.ok("删除成功");
|
}
|
|
@Override
|
public Result removeById(String id) {
|
//判断是否发布发布则提示先下架,再删除
|
News entity = baseMapper.selectById(id);
|
if(entity.getPublish()){
|
throw new RuntimeException("该新闻已发布");
|
}
|
|
baseMapper.deleteById(id);
|
return Result.ok("删除成功");
|
}
|
|
@Override
|
public Result page(NewsQuery query) {
|
IPage<NewsVO> page = PageUtil.getPage(query, NewsVO.class);
|
|
baseMapper.getPage(page, query);
|
|
return Result.ok().data(page.getRecords()).total(page.getTotal());
|
}
|
|
@Override
|
public Result detail(String id) {
|
NewsVO vo = baseMapper.getById(id);
|
Assert.notNull(vo, "记录不存在");
|
return Result.ok().data(vo);
|
}
|
|
@Override
|
public Result publish(String id) {
|
News entity = baseMapper.selectById(id);
|
if (!entity.getPublish()) {
|
entity.setPublishDate(new Date());
|
}else {
|
entity.setPublishDate(null);
|
}
|
entity.setPublish(!entity.getPublish());
|
baseMapper.updateById(entity);
|
return Result.ok("成功");
|
}
|
|
|
}
|