|
|
@@ -1,8 +1,13 @@
|
|
|
package com.xjrsoft.module.oa.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
|
+import com.github.yulichang.toolkit.MPJWrappers;
|
|
|
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
+import com.xjrsoft.common.enums.EnabledMark;
|
|
|
+import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
|
import com.xjrsoft.module.authority.entity.DataAuthConfig;
|
|
|
import com.xjrsoft.module.oa.dto.*;
|
|
|
import com.xjrsoft.module.oa.entity.News;
|
|
|
@@ -14,9 +19,15 @@ import com.xjrsoft.module.oa.mapper.NewsMapper;
|
|
|
import com.xjrsoft.module.oa.mapper.NewsRelationConfigMapper;
|
|
|
import com.xjrsoft.module.oa.mapper.NewsRelationMapper;
|
|
|
import com.xjrsoft.module.oa.service.INewsService;
|
|
|
+import com.xjrsoft.module.oa.vo.NewsAppendixVo;
|
|
|
+import com.xjrsoft.module.oa.vo.NewsRelationVo;
|
|
|
+import com.xjrsoft.module.organization.dto.WeChatSendMessageDto;
|
|
|
+import com.xjrsoft.module.organization.entity.User;
|
|
|
import com.xjrsoft.module.organization.entity.UserDeptRelation;
|
|
|
import com.xjrsoft.module.organization.entity.UserRoleRelation;
|
|
|
import com.xjrsoft.module.organization.mapper.UserDeptRelationMapper;
|
|
|
+import com.xjrsoft.module.organization.mapper.UserMapper;
|
|
|
+import com.xjrsoft.module.organization.service.WeChatService;
|
|
|
import com.xjrsoft.module.student.entity.BaseStudentContact;
|
|
|
import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
|
|
|
import com.xjrsoft.module.student.entity.BaseStudentUser;
|
|
|
@@ -53,11 +64,16 @@ public class NewsServiceImpl extends MPJBaseServiceImpl<NewsMapper, News> implem
|
|
|
|
|
|
private final BaseStudentSchoolRollMapper baseStudentSchoolRollMapper;
|
|
|
|
|
|
+ private final com.xjrsoft.module.organization.service.WeChatService weChatService;
|
|
|
+
|
|
|
+ private final UserMapper userMapper;
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public boolean add(AddNewsDto addNewsDto) {
|
|
|
+ public Long add(AddNewsDto addNewsDto) {
|
|
|
|
|
|
News news = BeanUtil.toBean(addNewsDto, News.class);
|
|
|
+ news.setEnabledMark(EnabledMark.ENABLED.getCode());
|
|
|
newsMapper.insert(news);
|
|
|
if (addNewsDto.getAppendixList() != null) {
|
|
|
for (AddNewsAppendixDto appendixDto : addNewsDto.getAppendixList()) {
|
|
|
@@ -85,7 +101,9 @@ public class NewsServiceImpl extends MPJBaseServiceImpl<NewsMapper, News> implem
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return true;
|
|
|
+ SendMessage(news.getId());
|
|
|
+
|
|
|
+ return news.getId();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -242,4 +260,69 @@ public class NewsServiceImpl extends MPJBaseServiceImpl<NewsMapper, News> implem
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ private boolean SendMessage(Long id) {
|
|
|
+ News news = newsMapper.selectById(id);
|
|
|
+ if (news.getSendRange() == 1) {
|
|
|
+ List<User> userList = userMapper.selectList(Wrappers.<User>query().lambda().isNotNull(User::getOpenId));
|
|
|
+ if(userList.size()>0) {
|
|
|
+ for (User user : userList) {
|
|
|
+ WeChatSendMessageDto weChatSendMessageDto = new WeChatSendMessageDto();
|
|
|
+ weChatSendMessageDto.setUserId(user.getOpenId());
|
|
|
+ weChatSendMessageDto.setTemplateId("sHsmz7LRj7HLd7GSTS3r2uKMhE2f1iDAW15RqSK_6KM");
|
|
|
+ weChatSendMessageDto.setUrl("");
|
|
|
+ weChatSendMessageDto.setMsgId(id.toString());
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+
|
|
|
+ JSONObject data1 = new JSONObject();
|
|
|
+ data1.put("value", news.getFullHead());
|
|
|
+ data.put("thing2", data1);
|
|
|
+
|
|
|
+ JSONObject data2 = new JSONObject();
|
|
|
+ data2.put("value", news.getAuthorName());
|
|
|
+ data.put("phrase5", data2);
|
|
|
+
|
|
|
+ JSONObject data3 = new JSONObject();
|
|
|
+ data3.put("value", news.getReleaseTime());
|
|
|
+ data.put("time3", data3);
|
|
|
+ weChatSendMessageDto.setContent(data);
|
|
|
+ weChatService.sendMessage(weChatSendMessageDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ List<NewsRelationVo> newsRelationVoList = newsRelationMapper.selectJoinList(NewsRelationVo.class,
|
|
|
+ new MPJLambdaWrapper<NewsRelation>().distinct()
|
|
|
+ .eq(NewsRelation::getNewsId, id)
|
|
|
+ .select(NewsRelation.class, x -> VoToColumnUtil.fieldsToColumns(NewsRelationVo.class).contains(x.getProperty()))
|
|
|
+ .innerJoin(User.class, onWrapper -> onWrapper.eq(NewsRelation::getUserId, User::getId).isNotNull(User::getOpenId))
|
|
|
+ .selectAs(User::getOpenId, NewsRelationVo::getUserName)
|
|
|
+ );
|
|
|
+ if (newsRelationVoList.size() > 0) {
|
|
|
+ for (NewsRelationVo newsRelationVo : newsRelationVoList) {
|
|
|
+ WeChatSendMessageDto weChatSendMessageDto = new WeChatSendMessageDto();
|
|
|
+ weChatSendMessageDto.setUserId(newsRelationVo.getUserName());
|
|
|
+ weChatSendMessageDto.setTemplateId("sHsmz7LRj7HLd7GSTS3r2uKMhE2f1iDAW15RqSK_6KM");
|
|
|
+ weChatSendMessageDto.setUrl("");
|
|
|
+ weChatSendMessageDto.setMsgId(id.toString());
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+
|
|
|
+ JSONObject data1 = new JSONObject();
|
|
|
+ data1.put("value", news.getFullHead());
|
|
|
+ data.put("thing2", data1);
|
|
|
+
|
|
|
+ JSONObject data2 = new JSONObject();
|
|
|
+ data2.put("value", news.getAuthorName());
|
|
|
+ data.put("phrase5", data2);
|
|
|
+
|
|
|
+ JSONObject data3 = new JSONObject();
|
|
|
+ data3.put("value", news.getReleaseTime());
|
|
|
+ data.put("time3", data3);
|
|
|
+ weChatSendMessageDto.setContent(data);
|
|
|
+ weChatService.sendMessage(weChatSendMessageDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|