| package com.doumee.service.system.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.ResponseStatus; | 
| import com.doumee.core.exception.BusinessException; | 
| import com.doumee.core.model.LoginUserInfo; | 
| import com.doumee.core.model.PageData; | 
| import com.doumee.core.model.PageWrap; | 
| import com.doumee.core.utils.Constants; | 
| import com.doumee.core.utils.Utils; | 
| import com.doumee.dao.system.dto.NoticesDTO; | 
| import com.doumee.dao.system.join.NoticesJoinMapper; | 
| import com.doumee.dao.system.model.Notices; | 
| import com.doumee.service.system.NoticesService; | 
| import com.github.xiaoymin.knife4j.core.util.CollectionUtils; | 
| import com.github.yulichang.wrapper.MPJLambdaWrapper; | 
| import org.apache.commons.lang3.StringUtils; | 
| import org.apache.shiro.SecurityUtils; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Service; | 
|   | 
| import java.util.List; | 
| import java.util.Objects; | 
|   | 
| /** | 
|  * 系统消息信息表Service实现 | 
|  * @author 江蹄蹄 | 
|  * @date 2024/01/16 10:03 | 
|  */ | 
| @Service | 
| public class NoticesServiceImpl implements NoticesService { | 
|   | 
|     @Autowired | 
|     private NoticesJoinMapper noticesMapper; | 
|   | 
|     @Override | 
|     public Integer create(Notices notices) { | 
|         noticesMapper.insert(notices); | 
|         return notices.getId(); | 
|     } | 
|   | 
|     @Override | 
|     public void deleteById(Integer id) { | 
|         noticesMapper.deleteById(id); | 
|     } | 
|   | 
|     @Override | 
|     public void delete(Notices notices) { | 
|         UpdateWrapper<Notices> deleteWrapper = new UpdateWrapper<>(notices); | 
|         noticesMapper.delete(deleteWrapper); | 
|     } | 
|   | 
|     @Override | 
|     public void deleteByIdInBatch(List<Integer> ids) { | 
|         if (CollectionUtils.isEmpty(ids)) { | 
|             return; | 
|         } | 
|         noticesMapper.deleteBatchIds(ids); | 
|     } | 
|   | 
|     @Override | 
|     public void updateById(Notices notices) { | 
|         noticesMapper.updateById(notices); | 
|     } | 
|   | 
|     @Override | 
|     public void updateByIdInBatch(List<Notices> noticess) { | 
|         if (CollectionUtils.isEmpty(noticess)) { | 
|             return; | 
|         } | 
|         for (Notices notices: noticess) { | 
|             this.updateById(notices); | 
|         } | 
|     } | 
|   | 
|     @Override | 
|     public Notices findById(Integer id) { | 
|         return noticesMapper.selectById(id); | 
|     } | 
|   | 
|     @Override | 
|     public Notices findOne(Notices notices) { | 
|         QueryWrapper<Notices> wrapper = new QueryWrapper<>(notices); | 
|         return noticesMapper.selectOne(wrapper); | 
|     } | 
|   | 
|     @Override | 
|     public List<Notices> findList(Notices notices) { | 
|         QueryWrapper<Notices> wrapper = new QueryWrapper<>(notices); | 
|         return noticesMapper.selectList(wrapper); | 
|     } | 
|    | 
|     @Override | 
|     public PageData<Notices> findPage(PageWrap<Notices> pageWrap) { | 
|         IPage<Notices> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
|         MPJLambdaWrapper<Notices> queryWrapper = new MPJLambdaWrapper<>(); | 
|         Utils.MP.blankToNull(pageWrap.getModel()); | 
|         queryWrapper.selectAll(Notices.class); | 
|         if (pageWrap.getModel().getIsdeleted() != null) { | 
|             queryWrapper.eq(Notices::getIsdeleted, pageWrap.getModel().getIsdeleted()); | 
|         } | 
|         if (pageWrap.getModel().getObjType() != null) { | 
|             queryWrapper.eq(Notices::getObjType, pageWrap.getModel().getObjType()); | 
|         } | 
|         if (pageWrap.getModel().getType() != null) { | 
|             queryWrapper.eq(Notices::getType, pageWrap.getModel().getType()); | 
|         } | 
|         if (pageWrap.getModel().getCompanyId() != null) { | 
|             queryWrapper.eq(Notices::getCompanyId, pageWrap.getModel().getCompanyId()); | 
|         } | 
|         if (pageWrap.getModel().getPalt() != null) { | 
|             queryWrapper.eq(Notices::getPalt, pageWrap.getModel().getPalt()); | 
|         } | 
|         if (pageWrap.getModel().getStatus() != null) { | 
|             queryWrapper.eq(Notices::getStatus, pageWrap.getModel().getStatus()); | 
|         } | 
|         if (pageWrap.getModel().getReaded() != null) { | 
|             queryWrapper.eq(Notices::getReaded, pageWrap.getModel().getReaded()); | 
|         } | 
|   | 
|         if(CollectionUtils.isNotEmpty(pageWrap.getSorts())){ | 
|             for(PageWrap.SortData sortData: pageWrap.getSorts()) { | 
|                 if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { | 
|                     queryWrapper.orderByDesc(sortData.getProperty()); | 
|                 } else { | 
|                     queryWrapper.orderByAsc(sortData.getProperty()); | 
|                 } | 
|             } | 
|         }else{ | 
|             queryWrapper.orderByDesc(Notices::getCreateDate); | 
|         } | 
|         PageData<Notices> pageData = PageData.from(noticesMapper.selectJoinPage(page,Notices.class, queryWrapper)); | 
|   | 
|         return pageData; | 
|     } | 
|   | 
|     @Override | 
|     public long count(Notices notices) { | 
|         QueryWrapper<Notices> wrapper = new QueryWrapper<>(notices); | 
|         return noticesMapper.selectCount(wrapper); | 
|     } | 
|   | 
|     @Override | 
|     public PageData<Notices> taskCanterPage(PageWrap<NoticesDTO> pageWrap) { | 
|         IPage<Notices> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
|         MPJLambdaWrapper<Notices> queryWrapper = new MPJLambdaWrapper<>(); | 
|         Utils.MP.blankToNull(pageWrap.getModel()); | 
|         queryWrapper.selectAll(Notices.class); | 
|         NoticesDTO noticesDTO = pageWrap.getModel(); | 
|         if(Objects.isNull(noticesDTO) | 
|             || Objects.isNull(noticesDTO.getMemberId()) | 
|             || Objects.isNull(noticesDTO.getQueryType())){ | 
|                 queryWrapper.eq("1","2"); | 
|         } | 
|         if(noticesDTO.getQueryType().equals(Constants.ZERO)){ | 
|             queryWrapper.eq(Notices::getStatus,Constants.ZERO); | 
|             queryWrapper.eq(Notices::getSendacopy,Constants.ZERO); | 
|             queryWrapper.eq(Notices::getUserId, noticesDTO.getMemberId()); | 
|         } else if(noticesDTO.getQueryType().equals(Constants.ONE)){ | 
|             queryWrapper.eq(Notices::getStatus,Constants.ONE); | 
|             queryWrapper.eq(Notices::getSendacopy,Constants.ZERO); | 
|         } else if(noticesDTO.getQueryType().equals(Constants.TWO)){ | 
|             queryWrapper.eq(Notices::getParam3, noticesDTO.getMemberId()); | 
|         } else if (noticesDTO.getQueryType().equals(Constants.THREE)) { | 
|             queryWrapper.eq(Notices::getUserId, noticesDTO.getMemberId()); | 
|             queryWrapper.eq(Notices::getSendacopy,Constants.ONE); | 
|             if(Objects.nonNull(noticesDTO.getNoRead())&&Constants.equalsInteger(noticesDTO.getNoRead(),Constants.ONE)){ | 
|                 queryWrapper.eq(Notices::getReaded,Constants.ONE); | 
|             } | 
|         }else{ | 
|             queryWrapper.eq("1","2"); | 
|         } | 
|         queryWrapper.ge(noticesDTO.getStartDate() != null, Notices::getCreateDate, Utils.Date.getStart(noticesDTO.getStartDate() )); | 
|         queryWrapper.le(noticesDTO.getEndDate() != null,  Notices::getCreateDate, Utils.Date.getEnd(noticesDTO.getEndDate() )); | 
|         queryWrapper.eq(Objects.nonNull(noticesDTO.getType()),Notices::getType,noticesDTO.getType()); | 
|         queryWrapper.eq(StringUtils.isNotBlank(noticesDTO.getTitle()),Notices::getTitle,noticesDTO.getTitle()); | 
|         queryWrapper.orderByDesc(Notices::getCreateDate); | 
|         PageData<Notices> pageData = PageData.from(noticesMapper.selectJoinPage(page,Notices.class, queryWrapper)); | 
|         return pageData; | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 标记已读 | 
|      * @param noticesId | 
|      */ | 
|     @Override | 
|     public void signReadById(Integer noticesId){ | 
|         if(Objects.isNull(noticesId)){ | 
|             throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|         } | 
|         Notices notices = noticesMapper.selectById(noticesId); | 
|         if(Objects.isNull(notices)){ | 
|             throw new BusinessException(ResponseStatus.DATA_EMPTY); | 
|         } | 
|         if(Constants.equalsInteger(notices.getSendacopy(),Constants.ONE)){ | 
|             if(Constants.equalsInteger(Constants.ZERO,notices.getReaded())){ | 
|                 noticesMapper.update(null,new UpdateWrapper<Notices>().lambda() | 
|                         .set(Notices::getReaded,Constants.ONE).eq(Notices::getId,notices)); | 
|             } | 
|         }else{ | 
|             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非抄送数据,无法进行标记"); | 
|         } | 
|     } | 
|   | 
|     /** | 
|      * 批量标记已读 | 
|      * @param memberId | 
|      */ | 
|     @Override | 
|     public void signRead(Integer memberId) { | 
|         noticesMapper.update(null, new UpdateWrapper<Notices>().lambda() | 
|                 .set(Notices::getReaded, Constants.ONE) | 
|                 .eq(Notices::getSendacopy,Constants.ONE) | 
|                 .eq(Notices::getReaded,Constants.ZERO) | 
|                 .eq(Notices::getUserId, memberId)); | 
|     } | 
|   | 
| } |