|  |  | 
 |  |  | package com.doumee.service.business.impl; | 
 |  |  |  | 
 |  |  | import com.dingtalk.api.request.OapiMaterialNewsListRequest; | 
 |  |  | import com.doumee.biz.system.SystemDictDataBiz; | 
 |  |  | 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.DateUtil; | 
 |  |  | import com.doumee.core.utils.Utils; | 
 |  |  | import com.doumee.dao.business.ActionsMapper; | 
 |  |  | import com.doumee.dao.business.MultifileMapper; | 
 |  |  | import com.doumee.dao.business.NewsMapper; | 
 |  |  | import com.doumee.dao.business.model.Actions; | 
 |  |  | import com.doumee.dao.business.model.BjParam; | 
 |  |  | import com.doumee.dao.business.model.Multifile; | 
 |  |  | import com.doumee.dao.business.model.News; | 
 |  |  | import com.doumee.dao.system.model.SystemUser; | 
 |  |  | import com.doumee.dao.web.response.DailyUpdatesResponse; | 
 |  |  | import com.doumee.service.business.NewsService; | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
 |  |  | 
 |  |  | import org.springframework.transaction.annotation.Transactional; | 
 |  |  | import org.springframework.util.CollectionUtils; | 
 |  |  |  | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.Date; | 
 |  |  | import java.util.List; | 
 |  |  | import javax.swing.*; | 
 |  |  | import java.util.*; | 
 |  |  | import java.util.stream.Collectors; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * 资讯和定制服务信息表Service实现 | 
 |  |  | 
 |  |  |     private MultifileMapper multifileMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private SystemDictDataBiz systemDictDataBiz; | 
 |  |  |     @Autowired | 
 |  |  |     private ActionsMapper actionsMapper; | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     @Transactional | 
 |  |  | 
 |  |  |         param.setCreateDate(new Date()); | 
 |  |  |         param.setEditDate(param.getCreateDate()); | 
 |  |  |         param.setPublishUserid(param.getCreator()); | 
 |  |  |         param.setLookNum(Constants.ZERO); | 
 |  |  |         param.setDonwloadNum(Constants.ZERO); | 
 |  |  |         param.setFileType(Constants.formatIntegerNum(param.getFileType())); | 
 |  |  |         newsMapper.insert(param); | 
 |  |  |         if(param.getFileList()!=null && param.getFileList().size()>0){ | 
 |  |  | 
 |  |  |         if (pageWrap.getModel().getType() != null) { | 
 |  |  |             queryWrapper.eq(News::getType, pageWrap.getModel().getType()); | 
 |  |  |         } | 
 |  |  |         queryWrapper.orderByDesc(News::getCreateDate); | 
 |  |  |  | 
 |  |  |         PageData<News> pageData =  PageData.from(newsMapper.selectJoinPage(page, News.class,queryWrapper)); | 
 |  |  |         if(pageData!=null && pageData.getRecords()!=null && pageData.getRecords().size()>0){ | 
 |  |  | 
 |  |  |         QueryWrapper<News> wrapper = new QueryWrapper<>(news); | 
 |  |  |         return newsMapper.selectCount(wrapper); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 查询定制服务列表 | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     @Override | 
 |  |  |     public List<News> getCustomizedNewsList(Integer type,Integer num,Integer fileType){ | 
 |  |  |         List<News> list = newsMapper.selectList(new QueryWrapper<News>().lambda() | 
 |  |  |                 .eq(News::getIsdeleted,Constants.ZERO) | 
 |  |  |                 .eq(News::getType,type) | 
 |  |  |                 .eq(News::getStatus,Constants.ZERO) | 
 |  |  |                 .eq(Objects.nonNull(fileType),News::getFileType,fileType) | 
 |  |  |                 .last(Objects.nonNull(num),"limit " + num) | 
 |  |  |                 .orderByAsc(News::getSortnum) | 
 |  |  |         ); | 
 |  |  |         if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(list)){ | 
 |  |  |             List<Long> idList =  list.stream().map(i->i.getId()).collect(Collectors.toList()); | 
 |  |  |             List<Multifile> files = dealMultifileList(idList); | 
 |  |  |             for(News model : list){ | 
 |  |  |                 setFilelistById(model,files); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return list; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public News getCustomizedNewsDetail(Long id){ | 
 |  |  |         News news =  newsMapper.selectById(id); | 
 |  |  |         if(Objects.isNull(news)){ | 
 |  |  |             throw new BusinessException(ResponseStatus.DATA_EMPTY); | 
 |  |  |         } | 
 |  |  |         List<Long> idList =  new ArrayList<>(); | 
 |  |  |         idList.add(id); | 
 |  |  |         List<Multifile> files = dealMultifileList(idList); | 
 |  |  |         setFilelistById(news,files); | 
 |  |  |         //增加浏览量 | 
 |  |  |         newsMapper.update(new UpdateWrapper<News>().lambda() | 
 |  |  |                 .setSql( " LOOK_NUM = ( LOOK_NUM + 1 ) ").eq(News::getId,id)); | 
 |  |  |         return news; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 每日上新 | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     @Override | 
 |  |  |     public DailyUpdatesResponse getDailyUpdatesResponse(Integer fileType){ | 
 |  |  |         DailyUpdatesResponse dailyUpdatesResponse = new DailyUpdatesResponse(); | 
 |  |  |         dailyUpdatesResponse.setDailyUpdateNum( | 
 |  |  |                 newsMapper.selectCount(new QueryWrapper<News>().lambda() | 
 |  |  |                 .eq(News::getIsdeleted,Constants.ZERO) | 
 |  |  |                 .like(News::getCreateDate, DateUtil.getDateLong(new Date())) | 
 |  |  |                 .eq(News::getType,Constants.ONE) | 
 |  |  |         )); | 
 |  |  |         dailyUpdatesResponse.setShareNum( | 
 |  |  |                 actionsMapper.selectCount(new QueryWrapper<Actions>()) | 
 |  |  |         ); | 
 |  |  |         dailyUpdatesResponse.setNewsList( | 
 |  |  |                 this.getCustomizedNewsList(Constants.ZERO,Constants.THREE,fileType) | 
 |  |  |         ); | 
 |  |  |         return dailyUpdatesResponse; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Transactional(rollbackFor = {Exception.class,BusinessException.class}) | 
 |  |  |     @Override | 
 |  |  |     public void saveShareRecord(Long id,Long userId){ | 
 |  |  |         News news = newsMapper.selectById(id); | 
 |  |  |         if(Objects.isNull(news)){ | 
 |  |  |             throw new BusinessException(ResponseStatus.DATA_EMPTY); | 
 |  |  |         } | 
 |  |  |         Actions actions = new Actions(); | 
 |  |  |         actions.setCreateDate(new Date()); | 
 |  |  |         actions.setIsDeleted(Constants.ZERO); | 
 |  |  |         actions.setType(Constants.ZERO); | 
 |  |  |         actions.setObjId(id); | 
 |  |  |         actions.setObjType(Constants.ZERO); | 
 |  |  |         actions.setMemberId(userId); | 
 |  |  |         actions.setTitle(news.getTitle()); | 
 |  |  |         actions.setContent(news.getContent()); | 
 |  |  |         actions.setSubTitle(news.getSubTitle()); | 
 |  |  |         actionsMapper.insert(actions); | 
 |  |  |         //增加分享量 | 
 |  |  |         newsMapper.update(new UpdateWrapper<News>().lambda() | 
 |  |  |                 .setSql( " DONWLOAD_NUM = ( DONWLOAD_NUM + 1 ) ").eq(News::getId,id)); | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  | } |