package com.doumee.service.business.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.doumee.core.constants.Constants;
|
import com.doumee.core.model.PageData;
|
import com.doumee.core.model.PageWrap;
|
import com.doumee.dao.business.NoticeMapper;
|
import com.doumee.dao.business.model.Notice;
|
import com.doumee.service.business.NoticeService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.List;
|
import java.util.Objects;
|
|
/**
|
* 消息通知信息Service实现
|
* @author rk
|
* @date 2026/04/20
|
*/
|
@Service
|
public class NoticeServiceImpl implements NoticeService {
|
|
@Autowired
|
private NoticeMapper noticeMapper;
|
|
@Override
|
public Integer create(Notice notice) {
|
noticeMapper.insert(notice);
|
return notice.getId();
|
}
|
|
@Override
|
public void deleteById(Integer id) {
|
noticeMapper.deleteById(id);
|
}
|
|
@Override
|
public void delete(Notice notice) {
|
QueryWrapper<Notice> deleteWrapper = new QueryWrapper<>(notice);
|
noticeMapper.delete(deleteWrapper);
|
}
|
|
@Override
|
public void deleteByIdInBatch(List<Integer> ids) {
|
if (ids == null || ids.isEmpty()) {
|
return;
|
}
|
noticeMapper.deleteBatchIds(ids);
|
}
|
|
@Override
|
public void updateById(Notice notice) {
|
noticeMapper.updateById(notice);
|
}
|
|
@Override
|
public void updateByIdInBatch(List<Notice> notices) {
|
if (notices == null || notices.isEmpty()) {
|
return;
|
}
|
for (Notice notice : notices) {
|
this.updateById(notice);
|
}
|
}
|
|
@Override
|
public Notice findById(Integer id) {
|
return noticeMapper.selectById(id);
|
}
|
|
@Override
|
public Notice findOne(Notice notice) {
|
QueryWrapper<Notice> wrapper = new QueryWrapper<>(notice);
|
return noticeMapper.selectOne(wrapper);
|
}
|
|
@Override
|
public List<Notice> findList(Notice notice) {
|
QueryWrapper<Notice> wrapper = new QueryWrapper<>(notice);
|
return noticeMapper.selectList(wrapper);
|
}
|
|
@Override
|
public PageData<Notice> findPage(PageWrap<Notice> pageWrap) {
|
IPage<Notice> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
|
QueryWrapper<Notice> queryWrapper = new QueryWrapper<>();
|
if (pageWrap.getModel() != null) {
|
Notice model = pageWrap.getModel();
|
queryWrapper.lambda().eq(Notice::getIsdeleted,Constants.ZERO);
|
queryWrapper.lambda().eq(Objects.nonNull(model.getUserId()),Notice::getUserId,model.getUserId());
|
queryWrapper.lambda().eq(Objects.nonNull(model.getUserType()),Notice::getUserType,model.getUserType());
|
}
|
queryWrapper.lambda().orderByAsc(Notice::getStatus).orderByDesc(Notice::getCreateDate);
|
return PageData.from(noticeMapper.selectPage(page, queryWrapper));
|
}
|
|
@Override
|
public long count(Notice notice) {
|
QueryWrapper<Notice> wrapper = new QueryWrapper<>(notice);
|
return noticeMapper.selectCount(wrapper);
|
}
|
|
@Override
|
public void readNotice(Integer id, Integer userId) {
|
Notice notice = noticeMapper.selectById(id);
|
if (notice != null && notice.getUserId().equals(userId)) {
|
notice.setStatus(Constants.ONE);
|
notice.setEditDate(new java.util.Date());
|
noticeMapper.updateById(notice);
|
}
|
}
|
|
@Override
|
public void readAllNotice(Integer userType, Integer userId) {
|
noticeMapper.update(new UpdateWrapper<Notice>().lambda()
|
.set(Notice::getStatus, Constants.ONE)
|
.set(Notice::getEditDate, new java.util.Date())
|
.eq(Notice::getUserType, userType)
|
.eq(Notice::getUserId, userId)
|
.eq(Notice::getStatus, Constants.ZERO)
|
.eq(Notice::getIsdeleted, Constants.ZERO));
|
}
|
|
}
|