初始代码

This commit is contained in:
wangmingwei
2026-04-21 16:49:46 +08:00
parent aae9dc4036
commit f0453ff3a3
2396 changed files with 256575 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>yunzhupaas-message</artifactId>
<groupId>com.yunzhupaas</groupId>
<version>5.2.0-RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>yunzhupaas-message-biz</artifactId>
<dependencies>
<dependency>
<groupId>com.yunzhupaas</groupId>
<artifactId>yunzhupaas-provider</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>com.yunzhupaas</groupId>
<artifactId>yunzhupaas-permission-biz</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.yunzhupaas</groupId>
<artifactId>yunzhupaas-system-biz</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,27 @@
package com.yunzhupaas.message.config;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnNotWarDeployment;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class WebsocketConfig {
/**
* 支持websocket
* 如果不使用内置tomcat则无需配置
*
* @return
*/
@Bean
@ConditionalOnNotWarDeployment
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
}

View File

@@ -0,0 +1,20 @@
package com.yunzhupaas.message.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunzhupaas.message.entity.AccountConfigEntity;
/**
*
* 账号配置功能
* 版本: V3.2.0
* 版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* 作者: 云筑产品开发平台组
* 日期: 2022-08-18
*/
public interface AccountConfigMapper extends SuperMapper<AccountConfigEntity> {
}

View File

@@ -0,0 +1,30 @@
package com.yunzhupaas.message.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunzhupaas.message.entity.ImContentEntity;
import com.yunzhupaas.message.model.ImUnreadNumModel;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* 聊天内容
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
public interface ImContentMapper extends SuperMapper<ImContentEntity> {
List<ImUnreadNumModel> getUnreadList(@Param("receiveUserId") String receiveUserId);
List<ImUnreadNumModel> getUnreadLists(@Param("receiveUserId") String receiveUserId);
int readMessage(@Param("map") Map<String, String> map);
}

View File

@@ -0,0 +1,27 @@
package com.yunzhupaas.message.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunzhupaas.message.entity.ImReplyEntity;
import com.yunzhupaas.message.model.ImReplyListModel;
import java.util.List;
/**
* 聊天会话
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司http://www.szlecheng.cn
* @date 2024-05-28
*/
public interface ImReplyMapper extends SuperMapper<ImReplyEntity> {
/**
* 聊天会话列表
* @return
*/
List<ImReplyListModel> getImReplyList();
}

View File

@@ -0,0 +1,28 @@
package com.yunzhupaas.message.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunzhupaas.message.entity.MessageEntity;
import com.yunzhupaas.message.entity.MessageReceiveEntity;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* 消息实例
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司http://www.szlecheng.cn
* @date 2023/09/27
*/
public interface MessageMapper extends SuperMapper<MessageEntity> {
List<MessageReceiveEntity> getMessageList(@Param("map") Map<String, Object> map);
int getUnreadCount(@Param("userId") String userId,@Param("type") Integer type);
List<MessageEntity> getInfoDefault(@Param("type") int type);
}

View File

@@ -0,0 +1,20 @@
package com.yunzhupaas.message.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunzhupaas.message.entity.MessageMonitorEntity;
/**
*
* 消息监控
* 版本: V3.2.0
* 版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* 作者: 云筑产品开发平台组
* 日期: 2022-08-22
*/
public interface MessageMonitorMapper extends SuperMapper<MessageMonitorEntity> {
}

View File

@@ -0,0 +1,19 @@
package com.yunzhupaas.message.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunzhupaas.message.entity.MessageTemplateConfigEntity;
/**
*
* 消息模板(新)
* 版本: V3.2.0
* 版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* 作者: 云筑产品开发平台组
* 日期: 2022-08-18
*/
public interface MessageTemplateConfigMapper extends SuperMapper<MessageTemplateConfigEntity> {
}

View File

@@ -0,0 +1,19 @@
package com.yunzhupaas.message.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunzhupaas.message.entity.MessageReceiveEntity;
/**
* 消息接收
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
public interface MessagereceiveMapper extends SuperMapper<MessageReceiveEntity> {
}

View File

@@ -0,0 +1,20 @@
package com.yunzhupaas.message.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunzhupaas.message.entity.SendConfigTemplateEntity;
/**
*
* 消息发送配置
* 版本: V3.2.0
* 版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* 作者: 云筑产品开发平台组
* 日期: 2022-08-19
*/
public interface SendConfigTemplateMapper extends SuperMapper<SendConfigTemplateEntity> {
}

View File

@@ -0,0 +1,20 @@
package com.yunzhupaas.message.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunzhupaas.message.entity.SendMessageConfigEntity;
/**
*
* 消息发送配置
* 版本: V3.2.0
* 版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* 作者: 云筑产品开发平台组
* 日期: 2022-08-19
*/
public interface SendMessageConfigMapper extends SuperMapper<SendMessageConfigEntity> {
}

View File

@@ -0,0 +1,20 @@
package com.yunzhupaas.message.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunzhupaas.message.entity.ShortLinkEntity;
/**
*
* 消息模板(新)
* 版本: V3.2.0
* 版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* 作者: 云筑产品开发平台组
* 日期: 2022-08-18
*/
public interface ShortLInkMapper extends SuperMapper<ShortLinkEntity> {
}

View File

@@ -0,0 +1,20 @@
package com.yunzhupaas.message.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunzhupaas.message.entity.SmsFieldEntity;
/**
*
* 消息模板(新)
* 版本: V3.2.0
* 版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* 作者: 云筑产品开发平台组
* 日期: 2022-08-18
*/
public interface SmsFieldMapper extends SuperMapper<SmsFieldEntity> {
}

View File

@@ -0,0 +1,18 @@
package com.yunzhupaas.message.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunzhupaas.message.entity.SynThirdInfoEntity;
/**
* 第三方工具对象同步表
*
* @版本: V3.1.0
* @版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* @作者: 云筑产品开发平台组
* @日期: 2021/4/23 17:25
*/
public interface SynThirdInfoMapper extends SuperMapper<SynThirdInfoEntity> {
}

View File

@@ -0,0 +1,20 @@
package com.yunzhupaas.message.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunzhupaas.message.entity.TemplateParamEntity;
/**
*
* 消息模板(新)
* 版本: V3.2.0
* 版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* 作者: 云筑产品开发平台组
* 日期: 2022-08-18
*/
public interface TemplateParamMapper extends SuperMapper<TemplateParamEntity> {
}

View File

@@ -0,0 +1,20 @@
package com.yunzhupaas.message.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunzhupaas.message.entity.UserDeviceEntity;
/**
*
* 消息模板(新)
* 版本: V3.2.0
* 版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* 作者: 云筑产品开发平台组
* 日期: 2022-08-18
*/
public interface UserDeviceMapper extends SuperMapper<UserDeviceEntity> {
}

View File

@@ -0,0 +1,20 @@
package com.yunzhupaas.message.mapper;
import com.yunzhupaas.base.mapper.SuperMapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yunzhupaas.message.entity.WechatUserEntity;
/**
*
* 消息模板(新)
* 版本: V3.2.0
* 版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* 作者: 云筑产品开发平台组
* 日期: 2022-08-18
*/
public interface WechatUserMapper extends SuperMapper<WechatUserEntity> {
}

View File

@@ -0,0 +1,75 @@
package com.yunzhupaas.message.service;
import com.yunzhupaas.base.service.SuperService;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yunzhupaas.base.PageModel;
import com.yunzhupaas.message.entity.ImContentEntity;
import com.yunzhupaas.message.model.ImUnreadNumModel;
import java.util.List;
/**
* 聊天内容
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
public interface ImContentService extends SuperService<ImContentEntity> {
/**
* 获取消息列表
*
* @param sendUserId 发送者
* @param receiveUserId 接收者
* @param pageModel
* @return
*/
List<ImContentEntity> getMessageList(String sendUserId, String receiveUserId, PageModel pageModel);
/**
* 获取未读消息
*
* @param receiveUserId 接收者
* @return
*/
List<ImUnreadNumModel> getUnreadList(String receiveUserId);
/**
* 获取未读消息
*
* @param receiveUserId 接收者
* @return
*/
int getUnreadCount(String sendUserId, String receiveUserId);
/**
* 发送消息
*
* @param sendUserId 发送者
* @param receiveUserId 接收者
* @param message 消息内容
* @param messageType 消息类型
* @return
*/
void sendMessage(String sendUserId, String receiveUserId, String message, String messageType);
/**
* 已读消息
*
* @param sendUserId 发送者
* @param receiveUserId 接收者
* @return
*/
void readMessage(String sendUserId, String receiveUserId);
/**
* 删除聊天记录
*
* @return
*/
boolean deleteChatRecord(String sendUserId, String receiveUserId);
}

View File

@@ -0,0 +1,50 @@
package com.yunzhupaas.message.service;
import com.yunzhupaas.base.service.SuperService;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yunzhupaas.message.entity.ImReplyEntity;
import com.yunzhupaas.message.model.ImReplyListModel;
import java.util.List;
/**
* 聊天会话
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司http://www.szlecheng.cn
* @date 2024-05-29
*/
public interface ImReplyService extends SuperService<ImReplyEntity> {
/**
* 获取消息会话列表
*
* @return
*/
List<ImReplyEntity> getList();
/**
* 保存聊天会话
*
* @param entity
* @return
*/
boolean savaImReply(ImReplyEntity entity);
/**
* 获取聊天会话列表
*
* @return
*/
List<ImReplyListModel> getImReplyList();
/**
* 移除聊天会话列表
*
* @return
*/
boolean relocation(String sendUserId,String receiveUserId);
}

View File

@@ -0,0 +1,33 @@
package com.yunzhupaas.message.service;
import com.yunzhupaas.base.service.SuperService;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yunzhupaas.message.entity.UserDeviceEntity;
import java.util.List;
/**
*
* 消息模板(新)
* 版本: V3.2.0
* 版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* 作者: 云筑产品开发平台组
* 日期: 2022-08-18
*/
public interface UserDeviceService extends SuperService<UserDeviceEntity> {
UserDeviceEntity getInfoByUserId(String userId);
List<String> getCidList(String userId);
UserDeviceEntity getInfoByClientId(String clientId);
void create(UserDeviceEntity entity);
boolean update(String id, UserDeviceEntity entity);
void delete(UserDeviceEntity entity);
}

View File

@@ -0,0 +1,409 @@
package com.yunzhupaas.message.service.impl;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.base.ActionResult;
import com.yunzhupaas.constant.MsgCode;
import com.yunzhupaas.database.model.superQuery.ConditionJsonModel;
import com.yunzhupaas.database.model.superQuery.SuperQueryConditionModel;
import com.yunzhupaas.entity.*;
import com.yunzhupaas.exception.DataException;
import com.yunzhupaas.message.entity.AccountConfigEntity;
import com.yunzhupaas.message.mapper.AccountConfigMapper;
import com.yunzhupaas.message.model.accountconfig.*;
import com.yunzhupaas.message.service.AccountConfigService;
import cn.hutool.core.util.ObjectUtil;
import com.yunzhupaas.permission.service.AuthorizeService;
import java.lang.reflect.Field;
import com.baomidou.mybatisplus.annotation.TableField;
import com.yunzhupaas.util.visiual.YunzhupaasKeyConsts;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yunzhupaas.util.*;
import java.util.*;
/**
* 账号配置功能
* 版本: V3.2.0
* 版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* 作者: 云筑产品开发平台组
* 日期: 2022-08-18
*/
@Service
public class AccountConfigServiceImpl extends SuperServiceImpl<AccountConfigMapper, AccountConfigEntity>
implements AccountConfigService {
@Autowired
private AuthorizeService authorizeService;
@Override
public List<AccountConfigEntity> getList(AccountConfigPagination accountConfigPagination) {
return getTypeList(accountConfigPagination, accountConfigPagination.getDataType());
}
@Override
public List<AccountConfigEntity> getTypeList(AccountConfigPagination accountConfigPagination, String dataType) {
String userId = UserProvider.getUser().getUserId();
int total = 0;
int accountConfigNum = 0;
QueryWrapper<AccountConfigEntity> accountConfigQueryWrapper = new QueryWrapper<>();
// 关键字
if (StringUtil.isNotBlank(accountConfigPagination.getKeyword())
&& !"null".equals(accountConfigPagination.getKeyword())) {
accountConfigNum++;
accountConfigQueryWrapper.lambda()
.and(t -> t.like(AccountConfigEntity::getEnCode, accountConfigPagination.getKeyword())
.or().like(AccountConfigEntity::getFullName, accountConfigPagination.getKeyword()).or()
.like(AccountConfigEntity::getAddressorName, accountConfigPagination.getKeyword())
.or().like(AccountConfigEntity::getSmtpUser, accountConfigPagination.getKeyword()).or()
.like(AccountConfigEntity::getSmsSignature, accountConfigPagination.getKeyword()));
}
// webhook类型
if (ObjectUtil.isNotEmpty(accountConfigPagination.getWebhookType())) {
accountConfigNum++;
accountConfigQueryWrapper.lambda().eq(AccountConfigEntity::getWebhookType,
accountConfigPagination.getWebhookType());
}
// 渠道
if (ObjectUtil.isNotEmpty(accountConfigPagination.getChannel())) {
accountConfigNum++;
accountConfigQueryWrapper.lambda().eq(AccountConfigEntity::getChannel,
accountConfigPagination.getChannel());
}
// 状态
if (ObjectUtil.isNotEmpty(accountConfigPagination.getEnabledMark())) {
accountConfigNum++;
int enabledMark = Integer.parseInt(accountConfigPagination.getEnabledMark());
accountConfigQueryWrapper.lambda().eq(AccountConfigEntity::getEnabledMark, enabledMark);
}
// 配置类型
if (ObjectUtil.isNotEmpty(accountConfigPagination.getType())) {
accountConfigNum++;
accountConfigQueryWrapper.lambda().eq(AccountConfigEntity::getType, accountConfigPagination.getType());
}
// 排序
if (StringUtil.isEmpty(accountConfigPagination.getSidx())) {
accountConfigQueryWrapper.lambda().orderByAsc(AccountConfigEntity::getSortCode)
.orderByDesc(AccountConfigEntity::getCreatorTime)
.orderByDesc(AccountConfigEntity::getLastModifyTime);
} else {
try {
String sidx = accountConfigPagination.getSidx();
AccountConfigEntity accountConfigEntity = new AccountConfigEntity();
Field declaredField = accountConfigEntity.getClass().getDeclaredField(sidx);
declaredField.setAccessible(true);
String value = declaredField.getAnnotation(TableField.class).value();
accountConfigQueryWrapper = "asc".equals(accountConfigPagination.getSort().toLowerCase())
? accountConfigQueryWrapper.orderByAsc(value)
: accountConfigQueryWrapper.orderByDesc(value);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
}
if (!"1".equals(dataType)) {
if (total > 0 || total == 0) {
Page<AccountConfigEntity> page = new Page<>(accountConfigPagination.getCurrentPage(),
accountConfigPagination.getPageSize());
IPage<AccountConfigEntity> userIPage = this.page(page, accountConfigQueryWrapper);
return accountConfigPagination.setData(userIPage.getRecords(), userIPage.getTotal());
} else {
List<AccountConfigEntity> list = new ArrayList();
return accountConfigPagination.setData(list, list.size());
}
} else {
return this.list(accountConfigQueryWrapper);
}
}
@Override
public AccountConfigEntity getInfo(String id) {
QueryWrapper<AccountConfigEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(AccountConfigEntity::getId, id);
return this.getOne(queryWrapper);
}
@Override
public void create(AccountConfigEntity entity) {
this.save(entity);
}
@Override
public boolean update(String id, AccountConfigEntity entity) {
entity.setId(id);
return this.updateById(entity);
}
@Override
public void delete(AccountConfigEntity entity) {
if (entity != null) {
this.removeById(entity.getId());
}
}
// 子表方法
// 列表子表数据方法
// 验证表单唯一字段
@Override
public boolean checkForm(AccountConfigForm form, int i, String type, String id) {
int total = 0;
if (ObjectUtil.isNotEmpty(form.getEnCode())) {
QueryWrapper<AccountConfigEntity> codeWrapper = new QueryWrapper<>();
codeWrapper.lambda().eq(AccountConfigEntity::getEnCode, form.getEnCode());
codeWrapper.lambda().eq(AccountConfigEntity::getType, type);
if (StringUtil.isNotBlank(id) && !"null".equals(id)) {
codeWrapper.lambda().ne(AccountConfigEntity::getId, id);
}
total += (int) this.count(codeWrapper);
}
int c = 0;
if (total > i + c) {
return true;
}
return false;
}
@Override
public boolean checkGzhId(String gzhId, int i, String type, String id) {
int total = 0;
if (StringUtil.isNotEmpty(gzhId) && !"null".equals(gzhId)) {
QueryWrapper<AccountConfigEntity> codeWrapper = new QueryWrapper<>();
codeWrapper.lambda().eq(AccountConfigEntity::getAppKey, gzhId);
codeWrapper.lambda().eq(AccountConfigEntity::getType, type);
if (StringUtil.isNotBlank(id) && !"null".equals(id)) {
codeWrapper.lambda().ne(AccountConfigEntity::getId, id);
}
total += (int) this.count(codeWrapper);
}
int c = 0;
if (total > i + c) {
return true;
}
return false;
}
@Override
public AccountConfigEntity getInfoByType(String appKey, String type) {
QueryWrapper<AccountConfigEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(AccountConfigEntity::getType, type);
queryWrapper.lambda().eq(AccountConfigEntity::getAppKey, appKey);
return this.getOne(queryWrapper);
}
@Override
public AccountConfigEntity getInfoByEnCode(String enCode, String type) {
QueryWrapper<AccountConfigEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(AccountConfigEntity::getType, type);
queryWrapper.lambda().eq(AccountConfigEntity::getEnCode, enCode);
return this.getOne(queryWrapper);
}
@Override
public List<AccountConfigEntity> getListByType(String type) {
QueryWrapper<AccountConfigEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(AccountConfigEntity::getType, type);
queryWrapper.lambda().eq(AccountConfigEntity::getEnabledMark, 1);
return this.list(queryWrapper);
}
@Override
public boolean isExistByFullName(String fullName, String id) {
QueryWrapper<AccountConfigEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(AccountConfigEntity::getFullName, fullName);
if (!StringUtil.isEmpty(id)) {
queryWrapper.lambda().ne(AccountConfigEntity::getId, id);
}
return this.count(queryWrapper) > 0 ? true : false;
}
@Override
public boolean isExistByEnCode(String enCode, String id, String type) {
QueryWrapper<AccountConfigEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(AccountConfigEntity::getEnCode, enCode);
queryWrapper.lambda().eq(AccountConfigEntity::getType, type);
if (!StringUtil.isEmpty(id)) {
queryWrapper.lambda().ne(AccountConfigEntity::getId, id);
}
return this.count(queryWrapper) > 0 ? true : false;
}
@Override
public ActionResult ImportData(AccountConfigEntity entity) throws DataException {
if (entity != null) {
// if (isExistByFullName(entity.getFullName(), entity.getId())) {
// return ActionResult.fail(MsgCode.EXIST001.get());
// }
if (isExistByEnCode(entity.getEnCode(), entity.getId(), entity.getType())) {
return ActionResult.fail(MsgCode.EXIST002.get());
}
try {
this.save(entity);
} catch (Exception e) {
throw new DataException(MsgCode.IMP003.get());
}
return ActionResult.success(MsgCode.IMP001.get());
}
return ActionResult.fail(MsgCode.IMP006.get());
}
/**
* 高级查询
*
* @param conditionModel
* @param entity
* @param num
* @return
*/
public Integer getCondition(SuperQueryConditionModel conditionModel, Object entity, int num) {
QueryWrapper<?> queryWrapper = conditionModel.getObj();
List<ConditionJsonModel> queryConditionModels = conditionModel.getConditionList();
String op = conditionModel.getMatchLogic();
String tableName = conditionModel.getTableName();
List<ConditionJsonModel> useCondition = new ArrayList<>();
for (ConditionJsonModel queryConditionModel : queryConditionModels) {
if (queryConditionModel.getTableName().equalsIgnoreCase(tableName)) {
if (queryConditionModel.getField().contains("yunzhupaas")) {
String child = queryConditionModel.getField();
String s1 = child.substring(child.lastIndexOf("yunzhupaas_")).replace("yunzhupaas_", "");
queryConditionModel.setField(s1);
}
if (queryConditionModel.getField().toLowerCase().startsWith(YunzhupaasKeyConsts.CHILD_TABLE_PREFIX)) {
String child = queryConditionModel.getField();
String s1 = child.substring(child.indexOf("-") + 1);
queryConditionModel.setField(s1);
}
useCondition.add(queryConditionModel);
}
}
if (queryConditionModels.size() < 1 || useCondition.size() < 1) {
return num;
}
if (useCondition.size() > 0) {
num += 1;
}
// 处理控件 转换为有效值
for (ConditionJsonModel queryConditionModel : useCondition) {
String yunzhupaasKey = queryConditionModel.getYunzhupaasKey();
String fieldValue = queryConditionModel.getFieldValue();
if (yunzhupaasKey.equals(YunzhupaasKeyConsts.DATE)) {
Long o1 = Long.valueOf(fieldValue);
String startTime = DateUtil.daFormat(o1);
queryConditionModel.setFieldValue(startTime);
} else if (yunzhupaasKey.equals(YunzhupaasKeyConsts.CREATETIME)
|| yunzhupaasKey.equals(YunzhupaasKeyConsts.MODIFYTIME)) {
Long o1 = Long.valueOf(fieldValue);
String startTime = DateUtil.daFormatHHMMSS(o1);
queryConditionModel.setFieldValue(startTime);
} else if (yunzhupaasKey.equals(YunzhupaasKeyConsts.CURRORGANIZE)) {
List<String> orgList = JsonUtil.getJsonToList(fieldValue, String.class);
queryConditionModel.setFieldValue(orgList.get(orgList.size() - 1));
}
}
// 反射获取数据库实际字段
Class<?> aClass = entity.getClass();
queryWrapper.and(tw -> {
for (ConditionJsonModel conditionJsonModel : useCondition) {
String conditionField = conditionJsonModel.getField();
Field declaredField = null;
try {
declaredField = aClass.getDeclaredField(conditionField);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
declaredField.setAccessible(true);
String field = declaredField.getAnnotation(TableField.class).value();
String fieldValue = conditionJsonModel.getFieldValue();
String symbol = conditionJsonModel.getSymbol();
if ("AND".equalsIgnoreCase(op)) {
if (symbol.equals("==")) {
tw.eq(field, fieldValue);
} else if (symbol.equals(">=")) {
tw.ge(field, fieldValue);
} else if (symbol.equals("<=")) {
tw.le(field, fieldValue);
tw.and(
qw -> qw.ne(field, ""));
} else if (symbol.equals(">")) {
tw.gt(field, fieldValue);
} else if (symbol.equals("<")) {
tw.lt(field, fieldValue);
tw.and(
qw -> qw.ne(field, ""));
} else if (symbol.equals("<>")) {
tw.ne(field, fieldValue);
if (StringUtil.isNotEmpty(fieldValue)) {
tw.or(
qw -> qw.isNull(field));
}
} else if (symbol.equals("like")) {
if (StringUtil.isNotEmpty(fieldValue)) {
tw.like(field, fieldValue);
} else {
tw.isNull(field);
}
} else if (symbol.equals("notLike")) {
if (StringUtil.isNotEmpty(fieldValue)) {
tw.notLike(field, fieldValue);
tw.or(
qw -> qw.isNull(field));
} else {
tw.isNotNull(field);
}
}
} else {
if (symbol.equals("==")) {
tw.or(
qw -> qw.eq(field, fieldValue));
} else if (symbol.equals(">=")) {
tw.or(
qw -> qw.ge(field, fieldValue));
} else if (symbol.equals("<=")) {
tw.or(
qw -> qw.le(field, fieldValue));
} else if (symbol.equals(">")) {
tw.or(
qw -> qw.gt(field, fieldValue));
} else if (symbol.equals("<")) {
tw.or(
qw -> qw.lt(field, fieldValue));
} else if (symbol.equals("<>")) {
tw.or(
qw -> qw.ne(field, fieldValue));
if (StringUtil.isNotEmpty(fieldValue)) {
tw.or(
qw -> qw.isNull(field));
}
} else if (symbol.equals("like")) {
if (StringUtil.isNotEmpty(fieldValue)) {
tw.or(
qw -> qw.like(field, fieldValue));
} else {
tw.or(
qw -> qw.isNull(field));
}
} else if (symbol.equals("notLike")) {
if (StringUtil.isNotEmpty(fieldValue)) {
tw.or(
qw -> qw.notLike(field, fieldValue));
tw.or(
qw -> qw.isNull(field));
} else {
tw.or(
qw -> qw.isNotNull(field));
}
}
}
}
});
return num;
}
}

View File

@@ -0,0 +1,168 @@
package com.yunzhupaas.message.service.impl;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunzhupaas.base.PageModel;
import com.yunzhupaas.message.entity.ImContentEntity;
import com.yunzhupaas.message.entity.ImReplyEntity;
import com.yunzhupaas.message.mapper.ImContentMapper;
import com.yunzhupaas.message.model.ImReplySavaModel;
import com.yunzhupaas.message.service.ImContentService;
import com.yunzhupaas.message.model.ImUnreadNumModel;
import com.yunzhupaas.message.service.ImReplyService;
import com.yunzhupaas.permission.service.UserService;
import com.yunzhupaas.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
/**
* 聊天内容
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
@Service
public class ImContentServiceImpl extends SuperServiceImpl<ImContentMapper, ImContentEntity> implements ImContentService {
@Autowired
private ImReplyService imReplyService;
@Override
public List<ImContentEntity> getMessageList(String sendUserId, String receiveUserId, PageModel pageModel) {
QueryWrapper<ImContentEntity> queryWrapper = new QueryWrapper<>();
//发件人、收件人
if (!StringUtil.isEmpty(sendUserId) && !StringUtil.isEmpty(receiveUserId)) {
queryWrapper.lambda().and(wrapper -> {
wrapper.eq(ImContentEntity::getSendUserId, sendUserId);
wrapper.eq(ImContentEntity::getReceiveUserId, receiveUserId);
wrapper.or().eq(ImContentEntity::getSendUserId, receiveUserId);
wrapper.eq(ImContentEntity::getReceiveUserId, sendUserId);
});
queryWrapper.lambda().and(wrapper -> {
wrapper.isNull(ImContentEntity::getDeleteUserId);
wrapper.or(). ne(ImContentEntity::getDeleteUserId,receiveUserId);
// wrapper.ne(ImContentEntity::getDeleteMark, 1);
});
}
//关键字查询
if (pageModel != null && pageModel.getKeyword() != null) {
queryWrapper.lambda().like(ImContentEntity::getContent, pageModel.getKeyword());
//排序
pageModel.setSidx("f_send_time");
}
if (StringUtil.isEmpty(pageModel.getSidx())) {
queryWrapper.lambda().orderByDesc(ImContentEntity::getSendTime);
} else {
queryWrapper = "asc".equals(pageModel.getSord().toLowerCase()) ? queryWrapper.orderByAsc(pageModel.getSidx()) : queryWrapper.orderByDesc(pageModel.getSidx());
}
Page<ImContentEntity> page = new Page<>(pageModel.getPage(), pageModel.getRows());
IPage<ImContentEntity> iPage = this.page(page, queryWrapper);
return pageModel.setData(iPage.getRecords(), page.getTotal());
}
@Override
public List<ImUnreadNumModel> getUnreadList(String receiveUserId) {
List<ImUnreadNumModel> list = this.baseMapper.getUnreadList(receiveUserId);
List<ImUnreadNumModel> list1 = this.baseMapper.getUnreadLists(receiveUserId);
for (ImUnreadNumModel item : list) {
Optional<ImUnreadNumModel> first = list1.stream().filter(q -> q.getSendUserId().equals(item.getSendUserId())).findFirst();
if(first.isPresent()){
ImUnreadNumModel defaultItem = first.get();
item.setDefaultMessage(defaultItem.getDefaultMessage());
item.setDefaultMessageType(defaultItem.getDefaultMessageType());
item.setDefaultMessageTime(defaultItem.getDefaultMessageTime());
}
}
return list;
}
@Override
public int getUnreadCount(String sendUserId, String receiveUserId) {
QueryWrapper<ImContentEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(ImContentEntity::getSendUserId, sendUserId).eq(ImContentEntity::getReceiveUserId, receiveUserId).eq(ImContentEntity::getEnabledMark, 0);
return (int) this.count(queryWrapper);
}
@Override
@DSTransactional
public void sendMessage(String sendUserId, String receiveUserId, String message, String messageType) {
ImContentEntity entity = new ImContentEntity();
entity.setId(RandomUtil.uuId());
entity.setSendUserId(sendUserId);
entity.setSendTime(new Date());
entity.setReceiveUserId(receiveUserId);
entity.setEnabledMark(0);
entity.setContent(message);
entity.setContentType(messageType);
this.save(entity);
//写入到会话表中
ImReplySavaModel imReplySavaModel = new ImReplySavaModel(sendUserId, receiveUserId, entity.getSendTime());
ImReplyEntity imReplyEntity = JsonUtil.getJsonToBean(imReplySavaModel, ImReplyEntity.class);
imReplyService.savaImReply(imReplyEntity);
}
@Override
public void readMessage(String sendUserId, String receiveUserId) {
QueryWrapper<ImContentEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(ImContentEntity::getSendUserId, sendUserId);
queryWrapper.lambda().eq(ImContentEntity::getReceiveUserId, receiveUserId);
queryWrapper.lambda().eq(ImContentEntity::getEnabledMark, 0);
List<ImContentEntity> list = this.list(queryWrapper);
for (ImContentEntity entity : list) {
entity.setEnabledMark(1);
entity.setReceiveTime(new Date());
this.updateById(entity);
}
}
// @Override
// public ImContentEntity getList(String userId, String receiveUserId) {
// QueryWrapper<ImContentEntity> queryWrapper = new QueryWrapper<>();
// queryWrapper.lambda().eq(ImContentEntity::getSendUserId, userId)
// .and(t -> t.eq(ImContentEntity::getReceiveUserId, receiveUserId)).orderByDesc(ImContentEntity::getReceiveTime);
// List<ImContentEntity> list = this.list(queryWrapper);
// return list.size() > 0 ? list.get(0) : null;
// }
@Override
public boolean deleteChatRecord(String sendUserId, String receiveUserId) {
QueryWrapper<ImContentEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().and(t-> {
t.eq(ImContentEntity::getSendUserId, receiveUserId)
.eq(ImContentEntity::getReceiveUserId, sendUserId).or();
t.eq(ImContentEntity::getReceiveUserId, receiveUserId)
.eq(ImContentEntity::getSendUserId, sendUserId);
});
List<ImContentEntity> list = this.list(queryWrapper);
for (ImContentEntity entity : list) {
if(entity.getDeleteUserId()!=null){
if(!entity.getDeleteUserId().equals(sendUserId)) {
entity.setDeleteMark(1);
this.updateById(entity);
}
}
entity.setDeleteUserId(sendUserId);
this.updateById(entity);
}
QueryWrapper<ImContentEntity> wrapper = new QueryWrapper<>();
wrapper.lambda().eq(ImContentEntity::getDeleteMark,1);
this.remove(wrapper);
return false;
}
}

View File

@@ -0,0 +1,154 @@
package com.yunzhupaas.message.service.impl;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunzhupaas.message.entity.ImContentEntity;
import com.yunzhupaas.message.entity.ImReplyEntity;
import com.yunzhupaas.message.mapper.ImReplyMapper;
import com.yunzhupaas.message.model.ImReplyListModel;
import com.yunzhupaas.message.service.ImReplyService;
import com.yunzhupaas.permission.entity.UserEntity;
import com.yunzhupaas.permission.service.UserService;
import com.yunzhupaas.util.UserProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司http://www.szlecheng.cn
* @date 2024-05-29
*/
@Service
public class ImReplyServiceImpl extends SuperServiceImpl<ImReplyMapper, ImReplyEntity> implements ImReplyService {
@Autowired
private UserService userService;
@Override
public List<ImReplyEntity> getList() {
QueryWrapper<ImReplyEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(ImReplyEntity::getUserId, UserProvider.getUser().getUserId()).or()
.eq(ImReplyEntity::getReceiveUserId, UserProvider.getUser().getUserId())
.orderByDesc(ImReplyEntity::getUserId);
return this.list();
}
@Override
public boolean savaImReply(ImReplyEntity entity) {
QueryWrapper<ImReplyEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(ImReplyEntity::getUserId, entity.getUserId()).eq(ImReplyEntity::getReceiveUserId, entity.getReceiveUserId());
//判断数据是否存在
ImReplyEntity imReplyEntity = this.getOne(queryWrapper);
if (imReplyEntity != null) {
entity.setId(imReplyEntity.getId());
this.updateById(entity);
return true;
}
this.save(entity);
return true;
}
@Override
public List<ImReplyListModel> getImReplyList() {
List<ImReplyListModel> imReplyList = this.baseMapper.getImReplyList();
List<ImReplyListModel> imReplyLists = new ArrayList<>(imReplyList);
// 过滤掉用户id和接收id相同的
imReplyLists = imReplyList.stream().filter(t ->{
if(t.getImreplySendDeleteMark() == null){
return true;
}
return false;
}).collect(Collectors.toList());
// // 过滤掉用户id和接收id相同的
// List<ImReplyListModel> imReplyListModels = new ArrayList<>(imReplyList);
// for (int i = 0; i < imReplyList.size(); i++) {
// ImReplyListModel imReplyListModel = imReplyList.get(i);
// // 不和自己比
// imReplyListModels.remove(imReplyList.get(i));
// List<ImReplyListModel> irs = new ArrayList<>(imReplyListModels);
// ImReplyListModel model = irs.stream().filter(t -> t.getUserId().equals(imReplyListModel.getUserId()) && t.getId().equals(imReplyListModel.getId())).findFirst().orElse(null);
// if (model != null) {
// imReplyLists.remove(model);
// }
// }
//我发给别人
List<ImReplyListModel> collect = imReplyLists.stream().filter(t -> t.getUserId().equals(UserProvider.getUser().getUserId())).collect(Collectors.toList());
//头像替换成对方的
for (ImReplyListModel imReplyListModel : collect) {
UserEntity entity = userService.getInfo(imReplyListModel.getId());
imReplyListModel.setHeadIcon(entity != null ? entity.getHeadIcon() : "");
// imReplyListModel.setSendDeleteMark(imReplyListModel.getSendDeleteMark());
// imReplyListModel.setImreplySendDeleteMark(imReplyListModel.getImreplySendDeleteMark());
// imReplyListModel.setDeleteMark(imReplyListModel.getDeleteMark());
}
//别人发给我
List<ImReplyListModel> list = imReplyLists.stream().filter(t -> t.getId().equals(UserProvider.getUser().getUserId())).collect(Collectors.toList());
for (ImReplyListModel model : list) {
//移除掉互发的
List<ImReplyListModel> collect1 = collect.stream().filter(t -> t.getId().equals(model.getUserId())).collect(Collectors.toList());
if (collect1.size() > 0) {
//判断我发给别人的时间和接收的时间大小
//接收的大于发送的
if (model.getLatestDate().getTime() > collect1.get(0).getLatestDate().getTime()) {
collect.remove(collect1.get(0));
} else { //发送的大于接收的则跳过
continue;
}
}
ImReplyListModel imReplyListModel = new ImReplyListModel();
UserEntity entity = userService.getInfo(model.getUserId());
if(entity != null) {
imReplyListModel.setHeadIcon(entity.getHeadIcon());
imReplyListModel.setUserId(UserProvider.getUser().getUserId());
imReplyListModel.setId(entity.getId());
imReplyListModel.setLatestDate(model.getLatestDate());
imReplyListModel.setLatestMessage(model.getLatestMessage());
imReplyListModel.setMessageType(model.getMessageType());
if (model.getImreplySendDeleteMark() != null && !model.getImreplySendDeleteMark().equals(UserProvider.getUser().getUserId())) {
imReplyListModel.setSendDeleteMark(model.getSendDeleteMark());
imReplyListModel.setImreplySendDeleteMark(model.getImreplySendDeleteMark());
imReplyListModel.setDeleteMark(model.getDeleteMark());
}
imReplyListModel.setDeleteUserId(model.getDeleteUserId());
collect.add(imReplyListModel);
}
}
return collect;
}
@Override
public boolean relocation(String sendUserId, String receiveUserId) {
QueryWrapper<ImReplyEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().and(t-> {
t.eq(ImReplyEntity::getUserId, receiveUserId)
.eq(ImReplyEntity::getReceiveUserId, sendUserId).or();
t.eq(ImReplyEntity::getReceiveUserId, receiveUserId)
.eq(ImReplyEntity::getUserId, sendUserId);
});
List<ImReplyEntity> list = this.list(queryWrapper);
for (ImReplyEntity entity : list) {
if(entity.getDeleteUserId()!=null){
if(!entity.getDeleteUserId().equals(sendUserId)) {
entity.setDeleteMark(1);
this.updateById(entity);
}
}
entity.setDeleteUserId(sendUserId);
this.updateById(entity);
}
QueryWrapper<ImReplyEntity> wrapper = new QueryWrapper<>();
wrapper.lambda().eq(ImReplyEntity::getDeleteMark,1);
this.remove(wrapper);
return false;
}
}

View File

@@ -0,0 +1,199 @@
package com.yunzhupaas.message.service.impl;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.yunzhupaas.message.entity.MessageMonitorEntity;
import com.yunzhupaas.message.mapper.MessageMonitorMapper;
import com.yunzhupaas.message.model.messagemonitor.*;
import com.yunzhupaas.message.service.MessageMonitorService;
import com.yunzhupaas.permission.entity.UserEntity;
import com.yunzhupaas.permission.service.UserService;
import cn.hutool.core.util.ObjectUtil;
import com.yunzhupaas.permission.service.AuthorizeService;
import java.lang.reflect.Field;
import com.baomidou.mybatisplus.annotation.TableField;
import com.yunzhupaas.util.DateUtil;
import com.yunzhupaas.util.JsonUtil;
import com.yunzhupaas.util.StringUtil;
import com.yunzhupaas.util.UserProvider;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.*;
/**
* 消息监控
* 版本: V3.2.0
* 版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* 作者: 云筑产品开发平台组
* 日期: 2022-08-22
*/
@Service
public class MessageMonitorServiceImpl extends SuperServiceImpl<MessageMonitorMapper, MessageMonitorEntity> implements MessageMonitorService {
@Autowired
private UserService userService;
@Override
public List<MessageMonitorEntity> getList(MessageMonitorPagination messageMonitorPagination) {
return getTypeList(messageMonitorPagination, messageMonitorPagination.getDataType());
}
@Override
public List<MessageMonitorEntity> getTypeList(MessageMonitorPagination messageMonitorPagination, String dataType) {
String userId = UserProvider.getUser().getUserId();
int total = 0;
int messageMonitorNum = 0;
QueryWrapper<MessageMonitorEntity> messageMonitorQueryWrapper = new QueryWrapper<>();
//关键字
if (ObjectUtil.isNotEmpty(messageMonitorPagination.getKeyword())) {
messageMonitorNum++;
messageMonitorQueryWrapper.lambda().and(t -> t.like(MessageMonitorEntity::getTitle, messageMonitorPagination.getKeyword()));
}
//消息类型
if (ObjectUtil.isNotEmpty(messageMonitorPagination.getMessageType())) {
messageMonitorNum++;
messageMonitorQueryWrapper.lambda().eq(MessageMonitorEntity::getMessageType, messageMonitorPagination.getMessageType());
}
//发送时间
if (ObjectUtil.isNotEmpty(messageMonitorPagination.getStartTime()) && ObjectUtil.isNotEmpty(messageMonitorPagination.getEndTime())) {
messageMonitorNum++;
messageMonitorQueryWrapper.lambda().ge(MessageMonitorEntity::getSendTime, new Date(messageMonitorPagination.getStartTime()))
.le(MessageMonitorEntity::getSendTime, new Date(messageMonitorPagination.getEndTime()));
}
//消息来源
if (ObjectUtil.isNotEmpty(messageMonitorPagination.getMessageSource())) {
messageMonitorNum++;
messageMonitorQueryWrapper.lambda().eq(MessageMonitorEntity::getMessageSource, messageMonitorPagination.getMessageSource());
}
//排序
if (StringUtil.isEmpty(messageMonitorPagination.getSidx())) {
messageMonitorQueryWrapper.lambda().orderByDesc(MessageMonitorEntity::getSendTime);
} else {
try {
String sidx = messageMonitorPagination.getSidx();
MessageMonitorEntity messageMonitorEntity = new MessageMonitorEntity();
Field declaredField = messageMonitorEntity.getClass().getDeclaredField(sidx);
declaredField.setAccessible(true);
String value = declaredField.getAnnotation(TableField.class).value();
messageMonitorQueryWrapper = "asc".equals(messageMonitorPagination.getSort().toLowerCase()) ? messageMonitorQueryWrapper.orderByAsc(value) : messageMonitorQueryWrapper.orderByDesc(value);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
}
if (!"1".equals(dataType)) {
if (total > 0 || total == 0) {
Page<MessageMonitorEntity> page = new Page<>(messageMonitorPagination.getCurrentPage(), messageMonitorPagination.getPageSize());
IPage<MessageMonitorEntity> userIPage = this.page(page, messageMonitorQueryWrapper);
return messageMonitorPagination.setData(userIPage.getRecords(), userIPage.getTotal());
} else {
List<MessageMonitorEntity> list = new ArrayList();
return messageMonitorPagination.setData(list, list.size());
}
} else {
return this.list(messageMonitorQueryWrapper);
}
}
@Override
public MessageMonitorEntity getInfo(String id) {
QueryWrapper<MessageMonitorEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(MessageMonitorEntity::getId, id);
return this.getOne(queryWrapper);
}
@Override
public void create(MessageMonitorEntity entity) {
this.save(entity);
}
@Override
public boolean update(String id, MessageMonitorEntity entity) {
entity.setId(id);
return this.updateById(entity);
}
@Override
public void delete(MessageMonitorEntity entity) {
if (entity != null) {
this.removeById(entity.getId());
}
}
//子表方法
//列表子表数据方法
//验证表单唯一字段
@Override
public boolean checkForm(MessageMonitorForm form, int i) {
int total = 0;
if (total > 0) {
return true;
}
return false;
}
@Override
public void emptyMonitor(){
QueryWrapper<MessageMonitorEntity> queryWrapper = new QueryWrapper<>();
this.remove(queryWrapper);
}
@Override
@DSTransactional
public boolean delete(String[] ids) {
if (ids.length > 0) {
QueryWrapper<MessageMonitorEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().in(MessageMonitorEntity::getId, ids);
return this.remove(queryWrapper);
}
return false;
}
/**
* 用户id转名称(多选)
*
* @param ids
* @return
*/
@Override
public String userSelectValues(String ids) {
if (StringUtil.isEmpty(ids)) {
return ids;
}
if (ids.contains("[")){
List<String> nameList = new ArrayList<>();
List<String> jsonToList = JsonUtil.getJsonToList(ids, String.class);
for (String userId : jsonToList){
UserEntity info = userService.getInfo(userId);
nameList.add(Objects.nonNull(info) ? info.getRealName()+ "/" + info.getAccount() : userId);
}
return String.join(";", nameList);
}else {
List<String> userInfoList = new ArrayList<>();
String[] idList = ids.split(",");
if (idList.length > 0) {
for (String id : idList) {
UserEntity userEntity = userService.getInfo(id);
if (ObjectUtil.isNotEmpty(userEntity)) {
String info = userEntity.getRealName() + "/" + userEntity.getAccount();
userInfoList.add(info);
}
}
}
return String.join("-", userInfoList);
}
}
}

View File

@@ -0,0 +1,806 @@
package com.yunzhupaas.message.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.Method;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunzhupaas.base.Pagination;
import com.yunzhupaas.base.UserInfo;
import com.yunzhupaas.base.entity.DictionaryDataEntity;
import com.yunzhupaas.base.entity.DictionaryTypeEntity;
import com.yunzhupaas.base.entity.MessageTemplateEntity;
import com.yunzhupaas.base.service.DictionaryDataService;
import com.yunzhupaas.base.service.DictionaryTypeService;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.base.util.SentMessageUtil;
import com.yunzhupaas.config.ConfigValueUtil;
import com.yunzhupaas.flowable.model.trigger.TriggerModel;
import com.yunzhupaas.message.entity.*;
import com.yunzhupaas.message.mapper.MessageMapper;
import com.yunzhupaas.message.model.NoticePagination;
import com.yunzhupaas.message.model.SentMessageForm;
import com.yunzhupaas.message.model.message.NoticeVO;
import com.yunzhupaas.message.model.message.PaginationMessage;
import com.yunzhupaas.message.service.*;
import com.yunzhupaas.message.util.OnlineUserProvider;
import com.yunzhupaas.message.util.PushMessageUtil;
import com.yunzhupaas.permission.entity.UserEntity;
import com.yunzhupaas.permission.service.UserService;
import com.yunzhupaas.util.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringSubstitutor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
/**
* 消息实例
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
@Service
@Slf4j
public class MessageServiceImpl extends SuperServiceImpl<MessageMapper, MessageEntity> implements MessageService {
@Autowired
private MessagereceiveService messagereceiveService;
@Autowired
private MessageMonitorService messageMonitorService;
@Autowired
private RedisUtil redisUtil;
@Autowired
private SentMessageUtil sentMessageUtil;
@Autowired
private SendMessageConfigService sendMessageConfigService;
@Autowired
private SendConfigTemplateService sendConfigTemplateService;
@Autowired
private MessageTemplateConfigService messageTemplateConfigService;
@Autowired
private UserService userService;
@Autowired
private DictionaryTypeService dictionaryTypeService;
@Autowired
private DictionaryDataService dictionaryDataService;
@Autowired
private ConfigValueUtil configValueUtil;
@Override
public List<MessageEntity> getNoticeList(NoticePagination pagination) {
// 定义变量判断是否需要使用修改时间倒序
QueryWrapper<MessageEntity> queryWrapper = new QueryWrapper<>();
//关键词(消息标题)
if (!StringUtils.isEmpty(pagination.getKeyword())) {
queryWrapper.lambda().like(MessageEntity::getTitle, pagination.getKeyword());
}
// 类型
if (CollectionUtil.isNotEmpty(pagination.getType())) {
queryWrapper.lambda().in(MessageEntity::getCategory, pagination.getType());
}
// 状态
if (CollectionUtil.isNotEmpty(pagination.getEnabledMark())) {
queryWrapper.lambda().in(MessageEntity::getEnabledMark, pagination.getEnabledMark());
} else {
queryWrapper.lambda().and(t -> t.ne(MessageEntity::getEnabledMark, 3)
.or().isNull(MessageEntity::getEnabledMark));
queryWrapper.lambda().ne(MessageEntity::getEnabledMark, -1);
}
// 发布人
if (CollectionUtil.isNotEmpty(pagination.getReleaseUser())) {
queryWrapper.lambda().in(MessageEntity::getLastModifyUserId, pagination.getReleaseUser());
}
// 发布时间
if (CollectionUtil.isNotEmpty(pagination.getReleaseTime())) {
queryWrapper.lambda().between(MessageEntity::getLastModifyTime, new Date(pagination.getReleaseTime().get(0)), new Date(pagination.getReleaseTime().get(1)));
}
// 失效时间
if (CollectionUtil.isNotEmpty(pagination.getExpirationTime())) {
queryWrapper.lambda().between(MessageEntity::getExpirationTime, new Date(pagination.getExpirationTime().get(0)), new Date(pagination.getExpirationTime().get(1)));
}
// 创建人
if (CollectionUtil.isNotEmpty(pagination.getCreatorUser())) {
queryWrapper.lambda().in(MessageEntity::getCreatorUserId, pagination.getCreatorUser());
}
// 创建时间
if (CollectionUtil.isNotEmpty(pagination.getCreatorTime())) {
queryWrapper.lambda().between(MessageEntity::getCreatorTime, new Date(pagination.getCreatorTime().get(0)), new Date(pagination.getCreatorTime().get(1)));
}
//默认排序
queryWrapper.lambda().orderByAsc(MessageEntity::getEnabledMark).orderByDesc(MessageEntity::getLastModifyTime).orderByDesc(MessageEntity::getCreatorTime);
queryWrapper.lambda().select(MessageEntity::getId, MessageEntity::getCreatorUserId, MessageEntity::getEnabledMark,
MessageEntity::getLastModifyTime, MessageEntity::getTitle, MessageEntity::getCreatorTime,
MessageEntity::getLastModifyUserId, MessageEntity::getExpirationTime, MessageEntity::getCategory);
Page<MessageEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
IPage<MessageEntity> userIPage = this.page(page, queryWrapper);
return pagination.setData(userIPage.getRecords(), page.getTotal());
}
@Override
public List<MessageEntity> getNoticeList() {
QueryWrapper<MessageEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(MessageEntity::getEnabledMark, 1);
queryWrapper.lambda().orderByAsc(MessageEntity::getSortCode);
return this.baseMapper.selectList(queryWrapper);
}
@Override
public List<MessageEntity> getDashboardNoticeList(List<String> typeList) {
List<MessageEntity> list = new ArrayList<>(16);
// 判断哪些消息是自己接收的
QueryWrapper<MessageReceiveEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(MessageReceiveEntity::getUserId, UserProvider.getUser().getUserId());
queryWrapper.lambda().eq(MessageReceiveEntity::getType, 1);
List<MessageReceiveEntity> receiveEntities = messagereceiveService.list(queryWrapper);
for (int i = 0; i < receiveEntities.size(); i++) {
// 得到message
MessageReceiveEntity messageReceiveEntity = receiveEntities.get(i);
try{
MessageEntity entity = JsonUtil.getJsonToBean(messageReceiveEntity.getBodyText(), MessageEntity.class);
if (entity != null) {
if (StringUtil.isNotEmpty(entity.getId())) {
MessageEntity messageEntity = this.getInfo(entity.getId());
if (messageEntity != null) {
if ((typeList != null && typeList.size() > 0 && typeList.contains(messageEntity.getCategory()) || typeList == null || typeList.size() == 0)) {
if (Objects.equals(messageEntity.getEnabledMark(), 1)
&& (entity.getExpirationTime() == null || entity.getExpirationTime().getTime() > System.currentTimeMillis())) {
messageEntity.setId(messageReceiveEntity.getId());
list.add(messageEntity);
}
}
}
}else{
entity.setId(messageReceiveEntity.getId());
list.add(entity);
}
}
}catch (Exception e){
MessageEntity messageEntity = JsonUtil.getJsonToBean(messageReceiveEntity, MessageEntity.class);
list.add(messageEntity);
}
if (list.size() > 49) {
break;
}
}
list = list.stream().sorted(Comparator.comparing(MessageEntity::getLastModifyTime).reversed()).collect(Collectors.toList());
return list;
}
@Override
public List<MessageReceiveEntity> getMessageList3(Pagination pagination, Integer type, String user, Integer isRead) {
PaginationMessage paginationMessage = BeanUtil.copyProperties(pagination, PaginationMessage.class);
List<MessageReceiveEntity> messageColumnList = getMessageColumnList(paginationMessage,
MessageReceiveEntity::getId,
MessageReceiveEntity::getUserId,
MessageReceiveEntity::getType,
MessageReceiveEntity::getTitle,
MessageReceiveEntity::getFlowType,
MessageReceiveEntity::getIsRead,
MessageReceiveEntity::getSortCode,
MessageReceiveEntity::getCreatorTime,
MessageReceiveEntity::getCreatorUserId);
return pagination.setData(messageColumnList, paginationMessage.getTotal());
}
@Override
public List<MessageReceiveEntity> getMessageColumnList(PaginationMessage pagination, SFunction<MessageReceiveEntity, ?>... columns) {
QueryWrapper<MessageReceiveEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().select(MessageReceiveEntity::getId);
if (StringUtil.isNotEmpty(pagination.getUserId())) {
queryWrapper.lambda().eq(MessageReceiveEntity::getUserId, pagination.getUserId());
} else {
queryWrapper.lambda().eq(MessageReceiveEntity::getUserId, UserProvider.getLoginUserId());
}
if (pagination.getType() != null) {
queryWrapper.lambda().eq(MessageReceiveEntity::getType, pagination.getType());
}
if (pagination.getIsRead() != null) {
queryWrapper.lambda().eq(MessageReceiveEntity::getIsRead, pagination.getIsRead());
}
if (StringUtil.isNotEmpty(pagination.getKeyword())) {
queryWrapper.lambda().like(MessageReceiveEntity::getTitle, pagination.getKeyword());
}
queryWrapper.lambda().orderByDesc(MessageReceiveEntity::getCreatorTime);
Page<MessageReceiveEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
IPage<MessageReceiveEntity> userIPage = messagereceiveService.page(page, queryWrapper);
List<String> ids = userIPage.getRecords().stream().map(MessageReceiveEntity::getId).collect(Collectors.toList());
List<MessageReceiveEntity> list = new ArrayList<>();
if (CollectionUtil.isNotEmpty(ids)) {
QueryWrapper<MessageReceiveEntity> wrapper = new QueryWrapper<>();
if (columns != null && columns.length > 0) {
wrapper.lambda().select(columns);
}
wrapper.lambda().in(MessageReceiveEntity::getId, ids);
wrapper.lambda().orderByDesc(MessageReceiveEntity::getCreatorTime);
list = messagereceiveService.list(wrapper);
}
return pagination.setData(list, page.getTotal());
}
@Override
public List<MessageReceiveEntity> getMessageList(Pagination pagination) {
return this.getMessageList3(pagination, null, null, null);
}
@Override
public MessageEntity getInfo(String id) {
QueryWrapper<MessageEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(MessageEntity::getId, id);
return this.getOne(queryWrapper);
}
@Override
public MessageEntity getInfoDefault(int type) {
QueryWrapper<MessageEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(MessageEntity::getEnabledMark, 1);
if (type == 1) {
queryWrapper.lambda().orderByDesc(MessageEntity::getCreatorTime);
} else {
queryWrapper.lambda().orderByDesc(MessageEntity::getLastModifyTime);
}
// 只查询id
queryWrapper.lambda().select(MessageEntity::getId, MessageEntity::getTitle, MessageEntity::getCreatorTime);
List<MessageEntity> list = this.page(new Page<>(1, 1, false), queryWrapper).getRecords();
MessageEntity entity = new MessageEntity();
if (list.size() > 0) {
entity = list.get(0);
}
return entity;
}
@Override
@DSTransactional
public void delete(MessageEntity entity) {
entity.setEnabledMark(-1);
entity.setLastModifyTime(new Date());
entity.setLastModifyUserId(UserProvider.getUser().getUserId());
updateById(entity);
}
@Override
public void create(MessageEntity entity) {
entity.setId(RandomUtil.uuId());
entity.setBodyText(XSSEscape.escapeImgOnlyBase64(entity.getBodyText()));
entity.setEnabledMark(0);
entity.setCreatorUserId(UserProvider.getUser().getUserId());
this.save(entity);
}
@Override
public boolean update(String id, MessageEntity entity) {
entity.setId(id);
entity.setBodyText(XSSEscape.escapeImgOnlyBase64(entity.getBodyText()));
entity.setCreatorUserId(UserProvider.getUser().getUserId());
entity.setLastModifyUserId(null);
entity.setLastModifyTime(null);
return this.updateById(entity);
}
@Override
public MessageReceiveEntity messageRead(String messageId) {
String userId = UserProvider.getUser().getUserId();
QueryWrapper<MessageReceiveEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(MessageReceiveEntity::getUserId, userId).eq(MessageReceiveEntity::getId, messageId);
MessageReceiveEntity entity = messagereceiveService.getOne(queryWrapper);
if (entity != null) {
entity.setIsRead(1);
messagereceiveService.updateById(entity);
}
return entity;
}
@Override
@DSTransactional
public void messageRead(List<String> idList) {
String userId = UserProvider.getUser().getUserId();
QueryWrapper<MessageReceiveEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().select(MessageReceiveEntity::getId)
.eq(MessageReceiveEntity::getUserId, userId).eq(MessageReceiveEntity::getIsRead, 0);
// queryWrapper.lambda().in(MessageReceiveEntity::getMessageId,idList);
List<MessageReceiveEntity> entitys = messagereceiveService.list(queryWrapper);
if (entitys.size() > 0) {
for (MessageReceiveEntity entity : entitys) {
entity.setIsRead(1);
messagereceiveService.updateById(entity);
}
}
}
@Override
@DSTransactional
public void deleteRecord(List<String> messageIds) {
// 删除已读表
QueryWrapper<MessageReceiveEntity> queryWrapper = new QueryWrapper<>();
if (messageIds.size() > 0) {
queryWrapper.lambda().in(MessageReceiveEntity::getId, messageIds);
}
// 通过id删除无需判断接收人
queryWrapper.lambda().eq(MessageReceiveEntity::getUserId, UserProvider.getLoginUserId());
messagereceiveService.remove(queryWrapper);
}
@Override
public int getUnreadCount(String userId, Integer type) {
int result = this.baseMapper.getUnreadCount(userId, type);
return result;
}
@Override
public boolean sentNotice(List<String> toUserIds, MessageEntity entity) {
// 存到redis中的key对象
UserInfo userInfo = UserProvider.getUser();
List<String> idList = new ArrayList<>();
// 修改发送状态
entity.setEnabledMark(1);
entity.setLastModifyTime(new Date());
entity.setLastModifyUserId(userInfo.getUserId());
this.updateById(entity);
// 存到redis生成Redis的key
Callable executeInsert = () -> {
executeInsert(toUserIds, idList);
return true;
};
Future<Boolean> submit = ThreadPoolExecutorUtil.getExecutor().submit(executeInsert);
try {
if (submit.get()) {
// 执行发送公告操作
Runnable runnable = () -> executeBatch(idList, entity, userInfo);
ThreadPoolExecutorUtil.getExecutor().submit(runnable);
}
return true;
} catch (Exception e) {
// 还原公告状态
entity.setEnabledMark(0);
entity.setLastModifyTime(null);
entity.setLastModifyUserId(null);
this.updateById(entity);
}
return false;
}
/**
* 数据存到redis中
*
* @param toUserIds 接受者id
*/
private void executeInsert(List<String> toUserIds, List<String> idList) throws Exception {
List<String> key = new ArrayList<>();
try {
int frequency = 10000;
int count = toUserIds.size() / frequency + 1;
if (toUserIds.size() < 1) return;
for (int i = 0; i < count; i++) {
// 生成redis的key
String cacheKey = RandomUtil.uuId() + toUserIds.get(i);
// 存到redis
int endSize = Math.min(((i + 1) * frequency), toUserIds.size());
redisUtil.insert(cacheKey, toUserIds.subList(i * frequency, endSize));
key.add(cacheKey);
}
} catch (Exception e) {
key.forEach(k -> redisUtil.remove(k));
key.clear();
throw new Exception();
}
idList.addAll(key);
}
/**
* 执行发送操作
*
* @param idList 存到redis中的key
* @param entity
* @param userInfo
*/
private void executeBatch(List<String> idList, MessageEntity entity, UserInfo userInfo) {
if (idList.size() == 0 || "3".equals(String.valueOf(entity.getRemindCategory()))) {
return;
}
SentMessageForm sentMessageForm = new SentMessageForm();
List<String> toUserId = new ArrayList<>();
for (String cacheKey : idList) {
List<String> cacheValue = (List) redisUtil.get(cacheKey, 0, -1);
toUserId.addAll(cacheValue);
}
sentMessageForm.setToUserIds(toUserId);
sentMessageForm.setTitle(entity.getTitle());
sentMessageForm.setContent(entity.getBodyText());
sentMessageForm.setContentMsg(Collections.EMPTY_MAP);
sentMessageForm.setUserInfo(userInfo);
sentMessageForm.setType(1);
sentMessageForm.setId(entity.getId());
// 站内信
if ("1".equals(String.valueOf(entity.getRemindCategory()))) {
message(sentMessageForm);
} else if ("2".equals(String.valueOf(entity.getRemindCategory()))) {
SendMessageConfigEntity sendMessageConfigEntity = sendMessageConfigService.getInfo(entity.getSendConfigId());
if (sendMessageConfigEntity != null) {
List<SendConfigTemplateEntity> configTemplateEntityList = sendConfigTemplateService.getDetailListByParentId(sendMessageConfigEntity.getId());
for (SendConfigTemplateEntity sendConfigTemplateEntity : configTemplateEntityList) {
Map<String, String> map = new HashMap<>();
map.put("Title", entity.getTitle());
map.put("Content", entity.getBodyText());
map.put("Remark", entity.getExcerpt());
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("@title", entity.getTitle());
paramMap.put("@Content", entity.getBodyText());
paramMap.put("@Remark", entity.getExcerpt());
switch (sendConfigTemplateEntity.getMessageType()) {
case "1":
MessageTemplateConfigEntity configEntity = messageTemplateConfigService.getInfo(sendConfigTemplateEntity.getTemplateId());
if (configEntity != null) {
sentMessageForm.setTitle(configEntity.getTitle());
}
message(sentMessageForm);
break;
case "2":
// 邮件
sentMessageUtil.SendMail(toUserId, userInfo, "2", sendConfigTemplateEntity, new HashMap<>(), map);
break;
case "3":
// 发送短信
sentMessageUtil.sendSms(toUserId, userInfo, sendConfigTemplateEntity, paramMap, new HashMap<>());
break;
case "4":
// 钉钉
JSONObject jsonObject1 = sentMessageUtil.SendDingTalk(toUserId, userInfo, "4", sendConfigTemplateEntity, new HashMap<>(), map);
if (!(Boolean) jsonObject1.get("code")) {
log.error("发送企业微信消息失败,错误:" + jsonObject1.get("error"));
}
break;
case "5":
// 企业微信
JSONObject jsonObject = sentMessageUtil.SendQyWebChat(toUserId, userInfo, "5", sendConfigTemplateEntity, new HashMap<>(), map);
if (!(Boolean) jsonObject.get("code")) {
log.error("发送企业微信消息失败,错误:" + jsonObject.get("error"));
}
break;
case "6":
// webhook
sentMessageUtil.SendWebHook(null, userInfo, sendConfigTemplateEntity, new HashMap<>(), map);
break;
case "7":
// 微信公众号
sentMessageUtil.SendWXGzhChat(toUserId, userInfo, "7", sendConfigTemplateEntity, new HashMap<>(), paramMap);
break;
default:
break;
}
}
}
}
}
@Override
public void sentMessage(List<String> toUserIds, String title) {
this.sentMessage(toUserIds, title, null);
}
@Override
@DSTransactional
public void sentMessage(List<String> toUserIds, String title, String bodyText) {
UserInfo userInfo = UserProvider.getUser();
MessageReceiveEntity messageReceiveEntity = new MessageReceiveEntity();
messageReceiveEntity.setTitle(title);
messageReceiveEntity.setType(2);
messageReceiveEntity.setFlowType(1);
messageReceiveEntity.setIsRead(0);
Map<String, MessageReceiveEntity> map = new HashMap<>();
for (String item : toUserIds) {
MessageReceiveEntity messageReceiveEntitys = new MessageReceiveEntity();
BeanUtils.copyProperties(messageReceiveEntity, messageReceiveEntitys);
messageReceiveEntitys.setId(RandomUtil.uuId());
messageReceiveEntitys.setUserId(item);
messageReceiveEntitys.setBodyText(bodyText);
messagereceiveService.save(messageReceiveEntitys);
map.put(messageReceiveEntitys.getUserId(), messageReceiveEntitys);
}
//消息推送 - PC端
PushMessageUtil.pushMessage(map, userInfo, 2);
}
@Override
@DSTransactional
public void sentMessage(List<String> toUserIds, String title, String bodyText, Map<String, String> contentMsg, UserInfo userInfo) {
MessageReceiveEntity messageReceiveEntity = new MessageReceiveEntity();
messageReceiveEntity.setTitle(title);
messageReceiveEntity.setType(2);
messageReceiveEntity.setFlowType(1);
messageReceiveEntity.setIsRead(0);
Map<String, MessageReceiveEntity> map = new HashMap<>();
for (String item : toUserIds) {
MessageReceiveEntity messageReceiveEntitys = new MessageReceiveEntity();
BeanUtils.copyProperties(messageReceiveEntity, messageReceiveEntitys);
messageReceiveEntitys.setId(RandomUtil.uuId());
messageReceiveEntitys.setUserId(item);
String msg = contentMsg.get(item) != null ? contentMsg.get(item) : "{}" ;
messageReceiveEntitys.setBodyText(msg);
messageReceiveEntitys.setCreatorUserId(userInfo.getUserId());
messageReceiveEntitys.setCreatorTime(new Date());
messagereceiveService.save(messageReceiveEntitys);
map.put(messageReceiveEntitys.getUserId(), messageReceiveEntitys);
}
//消息推送 - PC端
PushMessageUtil.pushMessage(map, userInfo, 2);
}
@Override
@DSTransactional
public void sentMessage(List<String> toUserIds, String title, String bodyText, UserInfo userInfo, Integer source, Integer type) {
sentMessage(toUserIds, title, bodyText, userInfo, source, type, false);
}
@Override
@DSTransactional
public void sentMessage(List<String> toUserIds, String title, String bodyText, UserInfo userInfo, Integer source, Integer type, boolean testMessage) {
MessageReceiveEntity messageReceiveEntity = new MessageReceiveEntity();
messageReceiveEntity.setTitle(title);
messageReceiveEntity.setType(source);
messageReceiveEntity.setFlowType(1);
messageReceiveEntity.setBodyText(bodyText);
messageReceiveEntity.setIsRead(0);
Map<String, MessageReceiveEntity> map = new HashMap<>();
for (String item : toUserIds) {
MessageReceiveEntity messageReceiveEntitys = new MessageReceiveEntity();
BeanUtils.copyProperties(messageReceiveEntity, messageReceiveEntitys);
messageReceiveEntitys.setId(RandomUtil.uuId());
messageReceiveEntitys.setUserId(item);
messagereceiveService.save(messageReceiveEntitys);
map.put(messageReceiveEntitys.getUserId(), messageReceiveEntitys);
}
//消息监控写入
MessageMonitorEntity monitorEntity = new MessageMonitorEntity();
monitorEntity.setId(RandomUtil.uuId());
monitorEntity.setTitle(title);
monitorEntity.setMessageType(String.valueOf(type));
monitorEntity.setMessageSource(String.valueOf(source));
monitorEntity.setReceiveUser(JsonUtil.getObjectToString(toUserIds));
monitorEntity.setSendTime(DateUtil.getNowDate());
monitorEntity.setCreatorTime(DateUtil.getNowDate());
monitorEntity.setCreatorUserId(userInfo.getUserId());
messageMonitorService.create(monitorEntity);
PushMessageUtil.pushMessage(map, userInfo, source);
}
@Override
public void sentFlowMessage(List<String> toUserIds, MessageTemplateEntity entity, String content) {
if (entity != null) {
// 消息标题
String title = entity.getTitle();
this.sentMessage(toUserIds, title, content);
}
}
@Override
public void logoutWebsocketByToken(String token, String userId) {
if (StringUtil.isNotEmpty(token)) {
OnlineUserProvider.removeWebSocketByToken(token.split(","));
} else {
OnlineUserProvider.removeWebSocketByUser(userId);
}
}
@Override
public List<String> sentScheduleMessage(SentMessageForm sentMessageForm, String type) {
List<String> errList = new ArrayList<>();
UserInfo userInfo = sentMessageForm.getUserInfo();
String templateId = sentMessageForm.getTemplateId();
String title = sentMessageForm.getTitle();
List<String> toUserIds = sentMessageForm.getToUserIds();
//获取发送配置详情
SendMessageConfigEntity configEntity = sendMessageConfigService.getInfoByEnCode(templateId);
if (configEntity != null) {
templateId = configEntity.getId();
} else {
configEntity = sendMessageConfigService.getInfo(templateId);
}
List<SendConfigTemplateEntity> list = sendConfigTemplateService.getDetailListByParentId(templateId);
if (configEntity != null) {
for (SendConfigTemplateEntity sendConfigTemplateEntity : list) {
Map<String, Object> objectMap = new HashMap<>(sentMessageForm.getParameterMap());
Map<String, Object> parameterMap = new HashMap<>();
for (String key : objectMap.keySet()) {
if (key.contains(sendConfigTemplateEntity.getId())) {
parameterMap.put(key.substring(sendConfigTemplateEntity.getId().length()), objectMap.get(key));
}
}
parameterMap.putAll(objectMap);
Map<String, String> contentMsg = new HashMap<>();
for (String key : parameterMap.keySet()) {
contentMsg.put(key, String.valueOf(parameterMap.get(key)));
}
String sendType = sendConfigTemplateEntity.getMessageType();
switch (sendType) {
case "1":
MessageTemplateConfigEntity templateConfigEntity = messageTemplateConfigService.getInfo(sendConfigTemplateEntity.getTemplateId());
String messageTitle = StringUtil.isNotEmpty(templateConfigEntity.getTitle()) ? templateConfigEntity.getTitle() : "" ;
String content = StringUtil.isNotEmpty(templateConfigEntity.getContent()) ? templateConfigEntity.getContent() : "" ;
StringSubstitutor strSubstitutor = new StringSubstitutor(parameterMap, "{", "}");
messageTitle = strSubstitutor.replace(messageTitle);
content = strSubstitutor.replace(content);
sentMessageForm.setTitle(messageTitle);
sentMessageForm.setContent(content);
// 站内消息
message(sentMessageForm);
// 通知触发
String url = configValueUtil.getApiDomain() + "/api/workflow/trigger/MsgExecute";
TriggerModel model = new TriggerModel();
model.setUserInfo(userInfo);
model.setId(templateConfigEntity.getId());
HttpRequest request = HttpRequest.of(url).method(Method.POST).body(JsonUtil.getObjectToString(model));
request.header(Constants.AUTHORIZATION, userInfo.getToken());
request.execute().body();
break;
case "2":
// 邮件
List<String> mailErrs = sentMessageUtil.SendMail(toUserIds, userInfo, sendType, sendConfigTemplateEntity, new HashMap<>(), contentMsg);
errList.addAll(mailErrs.stream().distinct().collect(Collectors.toList()));
break;
case "3":
// 发送短信
List<String> smsErrs = sentMessageUtil.sendSms(toUserIds, userInfo, sendConfigTemplateEntity, parameterMap, new HashMap<>());
errList.addAll(smsErrs.stream().distinct().collect(Collectors.toList()));
break;
case "4":
// 钉钉
JSONObject jsonObject1 = sentMessageUtil.SendDingTalk(toUserIds, userInfo, sendType, sendConfigTemplateEntity, new HashMap<>(), contentMsg);
if (!(Boolean) jsonObject1.get("code")) {
log.error("发送企业微信消息失败,错误:" + jsonObject1.get("error"));
errList.add("发送钉钉消息失败,错误:" + jsonObject1.get("error"));
}
break;
case "5":
// 企业微信
JSONObject jsonObject = sentMessageUtil.SendQyWebChat(toUserIds, userInfo, sendType, sendConfigTemplateEntity, new HashMap<>(), contentMsg);
if (!(Boolean) jsonObject.get("code")) {
log.error("发送企业微信消息失败,错误:" + jsonObject.get("error"));
errList.add("发送企业微信消息失败,错误:" + jsonObject.get("error"));
}
break;
case "6":
// webhook
sentMessageUtil.SendWebHook(sendType, userInfo, sendConfigTemplateEntity, new HashMap<>(), contentMsg);
break;
case "7":
// 微信公众号
JSONObject jsonObject2 = sentMessageUtil.SendWXGzhChat(toUserIds, userInfo, sendType, sendConfigTemplateEntity, new HashMap<>(), parameterMap);
if (!(Boolean) jsonObject2.get("code")) {
errList.add("发送微信公众号消息失败,错误:" + jsonObject2.get("error"));
}
break;
default:
break;
}
}
}
return errList;
}
@Override
public Boolean updateEnabledMark() {
QueryWrapper<MessageEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().and(t -> t.eq(MessageEntity::getEnabledMark, 1).lt(MessageEntity::getExpirationTime, new Date()));
List<MessageEntity> list = this.list(queryWrapper);
list.forEach(t -> {
t.setEnabledMark(2);
this.updateById(t);
});
return true;
}
private void message(SentMessageForm sentMessageForm) {
List<String> toUserIds = sentMessageForm.getToUserIds();
Integer type = sentMessageForm.getType();
String title = sentMessageForm.getTitle();
String content = sentMessageForm.getContent();
String bodyText = Objects.equals(type, 3) ? content : JsonUtil.getObjectToString(sentMessageForm.getContentMsg());
UserInfo userInfo = sentMessageForm.getUserInfo();
MessageReceiveEntity messageReceiveEntity = new MessageReceiveEntity();
messageReceiveEntity.setIsRead(0);
messageReceiveEntity.setId(RandomUtil.uuId());
messageReceiveEntity.setType(sentMessageForm.getType());
if (type != null) {
messageReceiveEntity.setId(sentMessageForm.getId());
messageReceiveEntity.setType(type);
messageReceiveEntity.setCreatorUserId(userInfo.getUserId());
messageReceiveEntity.setCreatorTime(DateUtil.getNowDate());
}
//消息监控写入
MessageMonitorEntity monitorEntity = new MessageMonitorEntity();
MessageEntity messageEntity = this.getInfo(sentMessageForm.getId());
if (!"1".equals(String.valueOf(messageReceiveEntity.getType()))) {
monitorEntity.setMessageSource(sentMessageForm.getType() + "");
messageReceiveEntity.setFlowType(sentMessageForm.getFlowType());
monitorEntity.setTitle(title);
} else {
monitorEntity.setMessageSource("1");
title = title.replaceAll("\\{@Title}", messageEntity.getTitle())
.replaceAll("\\{@CreatorUserName}", userInfo.getUserName())
.replaceAll("\\{@SendTime}", DateUtil.getNow().substring(11))
.replaceAll("\\{@Content}", messageEntity.getBodyText())
.replaceAll("\\{@Remark}", StringUtil.isNotEmpty(messageEntity.getExcerpt()) ? messageEntity.getExcerpt() : "");
monitorEntity.setTitle(title);
MessageEntity messageEntity2 = new MessageEntity();
messageEntity2.setId(messageEntity.getId());
bodyText = JsonUtil.getObjectToString(messageEntity2);
}
Map<String, MessageReceiveEntity> map = new HashMap<>();
for (String item : toUserIds) {
MessageReceiveEntity messageReceiveEntitys = new MessageReceiveEntity();
BeanUtils.copyProperties(messageReceiveEntity, messageReceiveEntitys);
messageReceiveEntitys.setId(RandomUtil.uuId());
messageReceiveEntitys.setUserId(item);
messageReceiveEntitys.setTitle(title);
// if(ObjectUtil.isNotEmpty(messageEntity)) {
// messageReceiveEntitys.setTitle(title.replaceAll("\\{@Title}", messageEntity.getTitle())
// .replaceAll("\\{@CreatorUserName}", userInfo.getUserName())
// .replaceAll("\\{@Content}", messageEntity.getBodyText())
// .replaceAll("\\{@Remark}", StringUtil.isNotEmpty(messageEntity.getExcerpt()) ? messageEntity.getExcerpt() : ""));
// }
messageReceiveEntitys.setBodyText(bodyText);
messagereceiveService.save(messageReceiveEntitys);
map.put(messageReceiveEntitys.getUserId(), messageReceiveEntitys);
}
monitorEntity.setId(RandomUtil.uuId());
monitorEntity.setMessageType("1");
monitorEntity.setReceiveUser(JsonUtil.getObjectToString(toUserIds));
monitorEntity.setSendTime(DateUtil.getNowDate());
monitorEntity.setCreatorTime(DateUtil.getNowDate());
monitorEntity.setCreatorUserId(userInfo.getUserId());
monitorEntity.setContent(content);
messageMonitorService.create(monitorEntity);
//消息推送 - PC端
PushMessageUtil.pushMessage(map, userInfo, type != null ? type : 2);
}
public List<NoticeVO> getNoticeList(List<String> list) {
List<MessageEntity> dashboardNoticeList = this.getDashboardNoticeList(list);
List<UserEntity> userList = userService.getUserName(dashboardNoticeList.stream().map(MessageEntity::getCreatorUserId).collect(Collectors.toList()));
DictionaryTypeEntity dictionaryTypeEntity = dictionaryTypeService.getInfoByEnCode("NoticeType");
List<DictionaryDataEntity> noticeType = dictionaryDataService.getDicList(dictionaryTypeEntity.getId());
dashboardNoticeList.forEach(t -> {
// 转换创建人、发布人
UserEntity user = userList.stream().filter(ul -> ul.getId().equals(t.getCreatorUserId())).findFirst().orElse(null);
t.setCreatorUserId(user != null ? user.getRealName() + "/" + user.getAccount() : "");
if (t.getEnabledMark() != null && t.getEnabledMark() != 0) {
UserEntity entity = userService.getInfo(t.getLastModifyUserId());
t.setLastModifyUserId(entity != null ? entity.getRealName() + "/" + entity.getAccount() : "");
}
DictionaryDataEntity dictionaryDataEntity = noticeType.stream().filter(notice -> notice.getEnCode().equals(t.getCategory())).findFirst().orElse(new DictionaryDataEntity());
t.setCategory(dictionaryDataEntity.getFullName());
});
List<NoticeVO> jsonToList = new ArrayList<>();
dashboardNoticeList.forEach(t -> {
NoticeVO vo = JsonUtil.getJsonToBean(t, NoticeVO.class);
vo.setReleaseTime(t.getLastModifyTime() != null ? t.getLastModifyTime().getTime() : null);
vo.setReleaseUser(t.getLastModifyUserId());
vo.setCreatorUser(t.getCreatorUserId());
jsonToList.add(vo);
});
return jsonToList;
}
}

View File

@@ -0,0 +1,494 @@
package com.yunzhupaas.message.service.impl;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.base.ActionResult;
import com.yunzhupaas.constant.MsgCode;
import com.yunzhupaas.database.model.superQuery.ConditionJsonModel;
import com.yunzhupaas.database.model.superQuery.SuperQueryConditionModel;
import com.yunzhupaas.exception.DataException;
import com.yunzhupaas.message.entity.MessageTemplateConfigEntity;
import com.yunzhupaas.message.entity.SmsFieldEntity;
import com.yunzhupaas.message.entity.TemplateParamEntity;
import com.yunzhupaas.message.mapper.MessageTemplateConfigMapper;
import com.yunzhupaas.message.model.messagetemplateconfig.MessageTemplateConfigForm;
import com.yunzhupaas.message.model.messagetemplateconfig.MessageTemplateConfigPagination;
import com.yunzhupaas.message.model.messagetemplateconfig.TemplateParamModel;
import com.yunzhupaas.message.service.MessageTemplateConfigService;
import com.yunzhupaas.message.service.SmsFieldService;
import com.yunzhupaas.message.service.TemplateParamService;
import cn.hutool.core.util.ObjectUtil;
import com.yunzhupaas.permission.service.AuthorizeService;
import java.lang.reflect.Field;
import com.baomidou.mybatisplus.annotation.TableField;
import com.yunzhupaas.util.DateUtil;
import com.yunzhupaas.util.JsonUtil;
import com.yunzhupaas.util.StringUtil;
import com.yunzhupaas.util.UserProvider;
import com.yunzhupaas.util.visiual.YunzhupaasKeyConsts;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* 消息模板(新)
* 版本: V3.2.0
* 版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* 作者: 云筑产品开发平台组
* 日期: 2022-08-18
*/
@Service
public class MessageTemplateConfigServiceImpl
extends SuperServiceImpl<MessageTemplateConfigMapper, MessageTemplateConfigEntity>
implements MessageTemplateConfigService {
@Autowired
private TemplateParamService templateParamService;
@Autowired
private SmsFieldService smsFieldService;
@Override
public List<MessageTemplateConfigEntity> getList(MessageTemplateConfigPagination MessageTemplateConfigPagination) {
return getTypeList(MessageTemplateConfigPagination, MessageTemplateConfigPagination.getDataType());
}
@Override
public List<MessageTemplateConfigEntity> getTypeList(
MessageTemplateConfigPagination MessageTemplateConfigPagination, String dataType) {
String userId = UserProvider.getUser().getUserId();
int total = 0;
int messageTemplateNewNum = 0;
QueryWrapper<MessageTemplateConfigEntity> messageTemplateNewQueryWrapper = new QueryWrapper<>();
int templateParamNum = 0;
QueryWrapper<TemplateParamEntity> templateParamQueryWrapper = new QueryWrapper<>();
int smsFieldNum = 0;
QueryWrapper<SmsFieldEntity> smsFieldQueryWrapper = new QueryWrapper<>();
// 关键字
if (ObjectUtil.isNotEmpty(MessageTemplateConfigPagination.getKeyword())) {
messageTemplateNewNum++;
messageTemplateNewQueryWrapper.lambda().and(t -> t
.like(MessageTemplateConfigEntity::getEnCode, MessageTemplateConfigPagination.getKeyword()).or()
.like(MessageTemplateConfigEntity::getFullName, MessageTemplateConfigPagination.getKeyword()));
}
// 模板类型
if (ObjectUtil.isNotEmpty(MessageTemplateConfigPagination.getTemplateType())) {
messageTemplateNewNum++;
messageTemplateNewQueryWrapper.lambda().eq(MessageTemplateConfigEntity::getTemplateType,
MessageTemplateConfigPagination.getTemplateType());
}
// 消息类型
if (ObjectUtil.isNotEmpty(MessageTemplateConfigPagination.getMessageType())) {
messageTemplateNewNum++;
messageTemplateNewQueryWrapper.lambda().eq(MessageTemplateConfigEntity::getMessageType,
MessageTemplateConfigPagination.getMessageType());
}
// 消息来源
if (ObjectUtil.isNotEmpty(MessageTemplateConfigPagination.getMessageSource())) {
messageTemplateNewNum++;
messageTemplateNewQueryWrapper.lambda().eq(MessageTemplateConfigEntity::getMessageSource,
MessageTemplateConfigPagination.getMessageSource());
}
// 状态
if (ObjectUtil.isNotEmpty(MessageTemplateConfigPagination.getEnabledMark())) {
messageTemplateNewNum++;
int enabledMark = Integer.parseInt(MessageTemplateConfigPagination.getEnabledMark());
messageTemplateNewQueryWrapper.lambda().eq(MessageTemplateConfigEntity::getEnabledMark, enabledMark);
}
// 排序
if (StringUtil.isEmpty(MessageTemplateConfigPagination.getSidx())) {
messageTemplateNewQueryWrapper.lambda().orderByAsc(MessageTemplateConfigEntity::getSortCode)
.orderByDesc(MessageTemplateConfigEntity::getCreatorTime)
.orderByDesc(MessageTemplateConfigEntity::getLastModifyTime);
} else {
try {
String sidx = MessageTemplateConfigPagination.getSidx();
MessageTemplateConfigEntity MessageTemplateConfigEntity = new MessageTemplateConfigEntity();
Field declaredField = MessageTemplateConfigEntity.getClass().getDeclaredField(sidx);
declaredField.setAccessible(true);
String value = declaredField.getAnnotation(TableField.class).value();
messageTemplateNewQueryWrapper = "asc".equals(MessageTemplateConfigPagination.getSort().toLowerCase())
? messageTemplateNewQueryWrapper.orderByAsc(value)
: messageTemplateNewQueryWrapper.orderByDesc(value);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
}
if (!"1".equals(dataType)) {
if (total > 0 || total == 0) {
Page<MessageTemplateConfigEntity> page = new Page<>(MessageTemplateConfigPagination.getCurrentPage(),
MessageTemplateConfigPagination.getPageSize());
IPage<MessageTemplateConfigEntity> userIPage = this.page(page, messageTemplateNewQueryWrapper);
return MessageTemplateConfigPagination.setData(userIPage.getRecords(), userIPage.getTotal());
} else {
List<MessageTemplateConfigEntity> list = new ArrayList();
return MessageTemplateConfigPagination.setData(list, list.size());
}
} else {
return this.list(messageTemplateNewQueryWrapper);
}
}
@Override
public MessageTemplateConfigEntity getInfo(String id) {
QueryWrapper<MessageTemplateConfigEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(MessageTemplateConfigEntity::getId, id);
return this.getOne(queryWrapper);
}
@Override
public MessageTemplateConfigEntity getInfoByEnCode(String enCode, String messageType) {
QueryWrapper<MessageTemplateConfigEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(MessageTemplateConfigEntity::getEnCode, enCode);
queryWrapper.lambda().eq(MessageTemplateConfigEntity::getMessageType, messageType);
return this.getOne(queryWrapper);
}
@Override
public void create(MessageTemplateConfigEntity entity) {
this.save(entity);
}
@Override
public boolean update(String id, MessageTemplateConfigEntity entity) {
entity.setId(id);
return this.updateById(entity);
}
@Override
public void delete(MessageTemplateConfigEntity entity) {
if (entity != null) {
this.removeById(entity.getId());
}
}
// 子表方法
@Override
public List<TemplateParamEntity> getTemplateParamList(String id,
MessageTemplateConfigPagination MessageTemplateConfigPagination) {
QueryWrapper<TemplateParamEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(TemplateParamEntity::getTemplateId, id);
return templateParamService.list(templateParamService.getChild(MessageTemplateConfigPagination, queryWrapper));
}
@Override
public List<TemplateParamEntity> getTemplateParamList(String id) {
QueryWrapper<TemplateParamEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(TemplateParamEntity::getTemplateId, id);
return templateParamService.list(queryWrapper);
}
@Override
public List<SmsFieldEntity> getSmsFieldList(String id,
MessageTemplateConfigPagination MessageTemplateConfigPagination) {
QueryWrapper<SmsFieldEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SmsFieldEntity::getTemplateId, id);
return smsFieldService.list(smsFieldService.getChild(MessageTemplateConfigPagination, queryWrapper));
}
@Override
public List<SmsFieldEntity> getSmsFieldList(String id) {
QueryWrapper<SmsFieldEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SmsFieldEntity::getTemplateId, id);
return smsFieldService.list(queryWrapper);
}
// 验证表单唯一字段
@Override
public boolean checkForm(MessageTemplateConfigForm form, int i, String id) {
int total = 0;
if (ObjectUtil.isNotEmpty(form.getEnCode())) {
QueryWrapper<MessageTemplateConfigEntity> codeWrapper = new QueryWrapper<>();
codeWrapper.lambda().eq(MessageTemplateConfigEntity::getEnCode, form.getEnCode());
if (StringUtil.isNotBlank(id) && !"null".equals(id)) {
codeWrapper.lambda().ne(MessageTemplateConfigEntity::getId, id);
}
if ((int) this.count(codeWrapper) > i) {
total++;
}
}
if (form.getTemplateParamList() != null) {
}
if (form.getSmsFieldList() != null) {
}
if (total > 0) {
return true;
}
return false;
}
@Override
public boolean isExistByFullName(String fullName, String id) {
QueryWrapper<MessageTemplateConfigEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(MessageTemplateConfigEntity::getFullName, fullName);
if (!StringUtil.isEmpty(id)) {
queryWrapper.lambda().ne(MessageTemplateConfigEntity::getId, id);
}
return this.count(queryWrapper) > 0 ? true : false;
}
@Override
public boolean isExistByEnCode(String enCode, String id) {
QueryWrapper<MessageTemplateConfigEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(MessageTemplateConfigEntity::getEnCode, enCode);
if (!StringUtil.isEmpty(id)) {
queryWrapper.lambda().ne(MessageTemplateConfigEntity::getId, id);
}
return this.count(queryWrapper) > 0 ? true : false;
}
@Override
public ActionResult ImportData(MessageTemplateConfigEntity entity) throws DataException {
if (entity != null) {
// if (isExistByFullName(entity.getFullName(), null)) {
// return ActionResult.fail(MsgCode.EXIST001.get());
// }
if (isExistByEnCode(entity.getEnCode(), entity.getId())) {
return ActionResult.fail(MsgCode.EXIST002.get());
}
try {
this.save(entity);
} catch (Exception e) {
throw new DataException(MsgCode.IMP003.get());
}
return ActionResult.success(MsgCode.IMP001.get());
}
return ActionResult.fail(MsgCode.IMP006.get());
}
@Override
public List<TemplateParamModel> getParamJson(String id) {
MessageTemplateConfigEntity entity = getInfo(id);
List<TemplateParamModel> paramModelList = new ArrayList<>();
List<String> smsField = new ArrayList<>();
List<String> paramList = new ArrayList<>();
if (entity != null) {
if ("3".equals(entity.getMessageType()) || "7".equals(entity.getMessageType())) {
List<SmsFieldEntity> smsFieldList = smsFieldService.getDetailListByParentId(id);
for (SmsFieldEntity entity1 : smsFieldList) {
if (!"@flowLink".equals(entity1.getField())) {
smsField.add(entity1.getField());
}
}
List<TemplateParamEntity> paramFieldList = templateParamService.getDetailListByParentId(id);
for (TemplateParamEntity entity1 : paramFieldList) {
if (smsField.contains(entity1.getField())) {
TemplateParamModel paramModel = new TemplateParamModel();
paramModel.setTemplateId(entity.getId());
paramModel.setTemplateCode(entity.getEnCode());
paramModel.setTemplateType(entity.getTemplateType());
paramModel.setField(entity1.getField());
paramModel.setFieldName(entity1.getFieldName());
paramModel.setId(entity1.getId());
paramModel.setTemplateName(entity.getFullName());
paramModelList.add(paramModel);
}
}
} else {
String content = StringUtil.isNotEmpty(entity.getContent()) ? entity.getContent() : "";
String title = StringUtil.isNotEmpty(entity.getTitle()) ? entity.getTitle() : "";
Set<String> list = new HashSet<>();
list.addAll(regexContent(content));
list.addAll(regexContent(title));
List<TemplateParamEntity> paramFieldList = templateParamService.getDetailListByParentId(id);
for (TemplateParamEntity entity1 : paramFieldList) {
TemplateParamModel paramModel = new TemplateParamModel();
paramModel.setTemplateId(entity.getId());
paramModel.setTemplateCode(entity.getEnCode());
paramModel.setTemplateType(entity.getTemplateType());
paramModel.setField(entity1.getField());
paramModel.setFieldName(entity1.getFieldName());
paramModel.setId(entity1.getId());
paramModel.setTemplateName(entity.getFullName());
if (list.contains(entity1.getField())) {
if (!"@FlowLink".equals(entity1.getField())
&& !"@CreatorUserName".equals(entity1.getField())
&& !"@SendTime".equals(entity1.getField())
&& !"@Mandator".equals(entity1.getField())
&& !"@Mandatary".equals(entity1.getField())) {
paramModelList.add(paramModel);
}
}
}
}
}
// 将参数模板转为json格式数据
// String data = JsonUtil.getObjectToString(paramModelList);
return paramModelList;
}
// 获取消息内容参数
public List<String> regexContent(String content) {
List<String> list = new ArrayList<>();
String pattern = "[{]([^}]+)[}]";
Pattern patternList = Pattern.compile(pattern);
Matcher m = patternList.matcher(content);
while (m.find()) {
String group = m.group().replaceAll("\\{", "").replaceAll("}", "");
list.add(group);
}
return list;
}
/**
* 高级查询
*
* @param conditionModel
* @param entity
* @param num
* @return
*/
public Integer getCondition(SuperQueryConditionModel conditionModel, Object entity, int num) {
QueryWrapper<?> queryWrapper = conditionModel.getObj();
List<ConditionJsonModel> queryConditionModels = conditionModel.getConditionList();
String op = conditionModel.getMatchLogic();
String tableName = conditionModel.getTableName();
List<ConditionJsonModel> useCondition = new ArrayList<>();
for (ConditionJsonModel queryConditionModel : queryConditionModels) {
if (queryConditionModel.getTableName().equalsIgnoreCase(tableName)) {
if (queryConditionModel.getField().contains("yunzhupaas")) {
String child = queryConditionModel.getField();
String s1 = child.substring(child.lastIndexOf("yunzhupaas_")).replace("yunzhupaas_", "");
queryConditionModel.setField(s1);
}
if (queryConditionModel.getField().toLowerCase().startsWith(YunzhupaasKeyConsts.CHILD_TABLE_PREFIX)) {
String child = queryConditionModel.getField();
String s1 = child.substring(child.indexOf("-") + 1);
queryConditionModel.setField(s1);
}
useCondition.add(queryConditionModel);
}
}
if (queryConditionModels.size() < 1 || useCondition.size() < 1) {
return num;
}
if (useCondition.size() > 0) {
num += 1;
}
// 处理控件 转换为有效值
for (ConditionJsonModel queryConditionModel : useCondition) {
String yunzhupaasKey = queryConditionModel.getYunzhupaasKey();
String fieldValue = queryConditionModel.getFieldValue();
if (yunzhupaasKey.equals(YunzhupaasKeyConsts.DATE)) {
Long o1 = Long.valueOf(fieldValue);
String startTime = DateUtil.daFormat(o1);
queryConditionModel.setFieldValue(startTime);
} else if (yunzhupaasKey.equals(YunzhupaasKeyConsts.CREATETIME)
|| yunzhupaasKey.equals(YunzhupaasKeyConsts.MODIFYTIME)) {
Long o1 = Long.valueOf(fieldValue);
String startTime = DateUtil.daFormatHHMMSS(o1);
queryConditionModel.setFieldValue(startTime);
} else if (yunzhupaasKey.equals(YunzhupaasKeyConsts.CURRORGANIZE)) {
List<String> orgList = JsonUtil.getJsonToList(fieldValue, String.class);
queryConditionModel.setFieldValue(orgList.get(orgList.size() - 1));
}
}
// 反射获取数据库实际字段
Class<?> aClass = entity.getClass();
queryWrapper.and(tw -> {
for (ConditionJsonModel conditionJsonModel : useCondition) {
String conditionField = conditionJsonModel.getField();
Field declaredField = null;
try {
declaredField = aClass.getDeclaredField(conditionField);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
declaredField.setAccessible(true);
String field = declaredField.getAnnotation(TableField.class).value();
String fieldValue = conditionJsonModel.getFieldValue();
String symbol = conditionJsonModel.getSymbol();
if ("AND".equalsIgnoreCase(op)) {
if (symbol.equals("==")) {
tw.eq(field, fieldValue);
} else if (symbol.equals(">=")) {
tw.ge(field, fieldValue);
} else if (symbol.equals("<=")) {
tw.le(field, fieldValue);
tw.and(
qw -> qw.ne(field, ""));
} else if (symbol.equals(">")) {
tw.gt(field, fieldValue);
} else if (symbol.equals("<")) {
tw.lt(field, fieldValue);
tw.and(
qw -> qw.ne(field, ""));
} else if (symbol.equals("<>")) {
tw.ne(field, fieldValue);
if (StringUtil.isNotEmpty(fieldValue)) {
tw.or(
qw -> qw.isNull(field));
}
} else if (symbol.equals("like")) {
if (StringUtil.isNotEmpty(fieldValue)) {
tw.like(field, fieldValue);
} else {
tw.isNull(field);
}
} else if (symbol.equals("notLike")) {
if (StringUtil.isNotEmpty(fieldValue)) {
tw.notLike(field, fieldValue);
tw.or(
qw -> qw.isNull(field));
} else {
tw.isNotNull(field);
}
}
} else {
if (symbol.equals("==")) {
tw.or(
qw -> qw.eq(field, fieldValue));
} else if (symbol.equals(">=")) {
tw.or(
qw -> qw.ge(field, fieldValue));
} else if (symbol.equals("<=")) {
tw.or(
qw -> qw.le(field, fieldValue));
} else if (symbol.equals(">")) {
tw.or(
qw -> qw.gt(field, fieldValue));
} else if (symbol.equals("<")) {
tw.or(
qw -> qw.lt(field, fieldValue));
} else if (symbol.equals("<>")) {
tw.or(
qw -> qw.ne(field, fieldValue));
if (StringUtil.isNotEmpty(fieldValue)) {
tw.or(
qw -> qw.isNull(field));
}
} else if (symbol.equals("like")) {
if (StringUtil.isNotEmpty(fieldValue)) {
tw.or(
qw -> qw.like(field, fieldValue));
} else {
tw.or(
qw -> qw.isNull(field));
}
} else if (symbol.equals("notLike")) {
if (StringUtil.isNotEmpty(fieldValue)) {
tw.or(
qw -> qw.notLike(field, fieldValue));
tw.or(
qw -> qw.isNull(field));
} else {
tw.or(
qw -> qw.isNotNull(field));
}
}
}
}
});
return num;
}
}

View File

@@ -0,0 +1,23 @@
package com.yunzhupaas.message.service.impl;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunzhupaas.message.entity.MessageReceiveEntity;
import com.yunzhupaas.message.mapper.MessagereceiveMapper;
import com.yunzhupaas.message.service.MessagereceiveService;
import org.springframework.stereotype.Service;
/**
* 消息接收 服务实现类
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2023/09/27
*/
@Service
public class MessagereceiveServiceImpl extends SuperServiceImpl<MessagereceiveMapper, MessageReceiveEntity> implements MessagereceiveService {
}

View File

@@ -0,0 +1,82 @@
package com.yunzhupaas.message.service.impl;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.message.entity.SendConfigTemplateEntity;
import com.yunzhupaas.message.mapper.SendConfigTemplateMapper;
import com.yunzhupaas.message.model.sendmessageconfig.SendMessageConfigPagination;
import com.yunzhupaas.message.service.SendConfigTemplateService;
import com.yunzhupaas.permission.service.AuthorizeService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yunzhupaas.util.*;
import java.util.List;
/**
* 消息发送配置
* 版本: V3.2.0
* 版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* 作者: 云筑产品开发平台组
* 日期: 2022-08-19
*/
@Service
public class SendConfigTemplateServiceImpl extends SuperServiceImpl<SendConfigTemplateMapper, SendConfigTemplateEntity> implements SendConfigTemplateService {
@Override
public QueryWrapper<SendConfigTemplateEntity> getChild(SendMessageConfigPagination pagination, QueryWrapper<SendConfigTemplateEntity> sendConfigTemplateQueryWrapper) {
// boolean pcPermission = false;
// boolean appPermission = false;
// boolean isPc = ServletUtil.getHeader("yunzhupaas-origin").equals("pc");
// if (isPc) {
// }
return sendConfigTemplateQueryWrapper;
}
@Override
public SendConfigTemplateEntity getInfo(String id) {
QueryWrapper<SendConfigTemplateEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SendConfigTemplateEntity::getId, id);
return this.getOne(queryWrapper);
}
@Override
public List<SendConfigTemplateEntity> getDetailListByParentId(String id) {
QueryWrapper<SendConfigTemplateEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SendConfigTemplateEntity::getSendConfigId, id);
return this.list(queryWrapper);
}
@Override
public List<SendConfigTemplateEntity> getConfigTemplateListByConfigId(String id) {
QueryWrapper<SendConfigTemplateEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SendConfigTemplateEntity::getSendConfigId, id);
queryWrapper.lambda().eq(SendConfigTemplateEntity::getEnabledMark, 1);
return this.list(queryWrapper);
}
@Override
public boolean isUsedAccount(String accountId) {
QueryWrapper<SendConfigTemplateEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SendConfigTemplateEntity::getAccountConfigId, accountId);
if (this.list(queryWrapper) != null && this.list(queryWrapper).size() > 0) {
return true;
} else {
return false;
}
}
@Override
public boolean isUsedTemplate(String templateId) {
QueryWrapper<SendConfigTemplateEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SendConfigTemplateEntity::getTemplateId, templateId);
if (this.list(queryWrapper) != null && this.list(queryWrapper).size() > 0) {
return true;
} else {
return false;
}
}
}

View File

@@ -0,0 +1,332 @@
package com.yunzhupaas.message.service.impl;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.base.ActionResult;
import com.yunzhupaas.base.UserInfo;
import com.yunzhupaas.constant.MsgCode;
import com.yunzhupaas.exception.DataException;
import com.yunzhupaas.message.entity.SendConfigTemplateEntity;
import com.yunzhupaas.message.entity.SendMessageConfigEntity;
import com.yunzhupaas.message.mapper.SendMessageConfigMapper;
import com.yunzhupaas.message.model.sendmessageconfig.*;
import com.yunzhupaas.message.service.SendConfigTemplateService;
import com.yunzhupaas.message.service.SendMessageConfigService;
import com.yunzhupaas.util.RandomUtil;
import cn.hutool.core.util.ObjectUtil;
import java.lang.reflect.Field;
import com.baomidou.mybatisplus.annotation.TableField;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yunzhupaas.util.*;
import java.util.*;
/**
* 消息发送配置
* 版本: V3.2.0
* 版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* 作者: 云筑产品开发平台组
* 日期: 2022-08-19
*/
@Service
public class SendMessageConfigServiceImpl extends SuperServiceImpl<SendMessageConfigMapper, SendMessageConfigEntity> implements SendMessageConfigService {
@Autowired
private SendConfigTemplateService sendConfigTemplateService;
@Override
public List<SendMessageConfigEntity> getList(SendMessageConfigPagination sendMessageConfigPagination, String dataType) {
String userId = UserProvider.getUser().getUserId();
int total = 0;
int sendMessageConfigNum = 0;
QueryWrapper<SendMessageConfigEntity> sendMessageConfigQueryWrapper = new QueryWrapper<>();
int sendConfigTemplateNum = 0;
QueryWrapper<SendConfigTemplateEntity> sendConfigTemplateQueryWrapper = new QueryWrapper<>();
//关键字
if (ObjectUtil.isNotEmpty(sendMessageConfigPagination.getKeyword())) {
sendMessageConfigNum++;
sendMessageConfigQueryWrapper.lambda().and(t -> t.like(SendMessageConfigEntity::getEnCode, sendMessageConfigPagination.getKeyword()).
or().like(SendMessageConfigEntity::getFullName, sendMessageConfigPagination.getKeyword()));
}
//模板类型
if (ObjectUtil.isNotEmpty(sendMessageConfigPagination.getTemplateType())) {
sendMessageConfigNum++;
sendMessageConfigQueryWrapper.lambda().eq(SendMessageConfigEntity::getTemplateType, sendMessageConfigPagination.getTemplateType());
}
//状态
if (ObjectUtil.isNotEmpty(sendMessageConfigPagination.getEnabledMark())) {
sendMessageConfigNum++;
int enabledMark = Integer.parseInt(sendMessageConfigPagination.getEnabledMark());
sendMessageConfigQueryWrapper.lambda().eq(SendMessageConfigEntity::getEnabledMark, enabledMark);
}
//消息来源
if (ObjectUtil.isNotEmpty(sendMessageConfigPagination.getMessageSource())) {
sendMessageConfigNum++;
sendMessageConfigQueryWrapper.lambda().eq(SendMessageConfigEntity::getMessageSource, sendMessageConfigPagination.getMessageSource());
}
//排序
if (StringUtil.isEmpty(sendMessageConfigPagination.getSidx())) {
sendMessageConfigQueryWrapper.lambda().orderByAsc(SendMessageConfigEntity::getSortCode).orderByDesc(SendMessageConfigEntity::getCreatorTime).orderByDesc(SendMessageConfigEntity::getLastModifyTime);;
} else {
try {
String sidx = sendMessageConfigPagination.getSidx();
SendMessageConfigEntity sendMessageConfigEntity = new SendMessageConfigEntity();
Field declaredField = sendMessageConfigEntity.getClass().getDeclaredField(sidx);
declaredField.setAccessible(true);
String value = declaredField.getAnnotation(TableField.class).value();
sendMessageConfigQueryWrapper = "asc".equals(sendMessageConfigPagination.getSort().toLowerCase()) ? sendMessageConfigQueryWrapper.orderByAsc(value) : sendMessageConfigQueryWrapper.orderByDesc(value);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
}
if (!"1".equals(dataType)) {
if (total > 0 || total == 0) {
Page<SendMessageConfigEntity> page = new Page<>(sendMessageConfigPagination.getCurrentPage(), sendMessageConfigPagination.getPageSize());
IPage<SendMessageConfigEntity> userIPage = this.page(page, sendMessageConfigQueryWrapper);
return sendMessageConfigPagination.setData(userIPage.getRecords(), userIPage.getTotal());
} else {
List<SendMessageConfigEntity> list = new ArrayList();
return sendMessageConfigPagination.setData(list, list.size());
}
} else {
return this.list(sendMessageConfigQueryWrapper);
}
}
@Override
public List<SendMessageConfigEntity> getSelectorList(SendMessageConfigPagination sendMessageConfigPagination) {
QueryWrapper<SendMessageConfigEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SendMessageConfigEntity::getMessageSource, 5).eq(SendMessageConfigEntity::getEnabledMark, 1);
queryWrapper.lambda().eq(SendMessageConfigEntity::getTemplateType, 0);
Page<SendMessageConfigEntity> page = new Page<>(sendMessageConfigPagination.getCurrentPage(), sendMessageConfigPagination.getPageSize());
IPage<SendMessageConfigEntity> userIPage = this.page(page, queryWrapper);
return sendMessageConfigPagination.setData(userIPage.getRecords(), userIPage.getTotal());
}
@Override
public SendMessageConfigEntity getInfo(String id) {
QueryWrapper<SendMessageConfigEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SendMessageConfigEntity::getId, id);
return this.getOne(queryWrapper);
}
@Override
public SendMessageConfigEntity getInfoByEnCode(String enCode){
QueryWrapper<SendMessageConfigEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SendMessageConfigEntity::getEnCode, enCode);
return this.getOne(queryWrapper);
}
@Override
public SendMessageConfigEntity getSysConfig(String enCode,String type){
QueryWrapper<SendMessageConfigEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SendMessageConfigEntity::getTemplateType, type);
queryWrapper.lambda().eq(SendMessageConfigEntity::getEnCode,enCode);
return this.getOne(queryWrapper);
}
@Override
public void create(SendMessageConfigEntity entity) {
this.save(entity);
}
@Override
public boolean update(String id, SendMessageConfigEntity entity) {
entity.setId(id);
return this.updateById(entity);
}
@Override
public void delete(SendMessageConfigEntity entity) {
if (entity != null) {
this.removeById(entity.getId());
}
}
//子表方法
@Override
public List<SendConfigTemplateEntity> getSendConfigTemplateList(String id, SendMessageConfigPagination sendMessageConfigPagination) {
QueryWrapper<SendConfigTemplateEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SendConfigTemplateEntity::getSendConfigId, id);
return sendConfigTemplateService.list(sendConfigTemplateService.getChild(sendMessageConfigPagination, queryWrapper));
}
@Override
public List<SendConfigTemplateEntity> getSendConfigTemplateList(String id) {
QueryWrapper<SendConfigTemplateEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SendConfigTemplateEntity::getSendConfigId, id);
queryWrapper.lambda().orderByDesc(SendConfigTemplateEntity::getSortCode);
return sendConfigTemplateService.list(queryWrapper);
}
//列表子表数据方法
//验证表单唯一字段
@Override
public boolean checkForm(SendMessageConfigForm form, int i,String id) {
int total = 0;
if (ObjectUtil.isNotEmpty(form.getEnCode())) {
QueryWrapper<SendMessageConfigEntity> enCodeWrapper = new QueryWrapper<>();
enCodeWrapper.lambda().eq(SendMessageConfigEntity::getEnCode, form.getEnCode());
if(StringUtil.isNotBlank(id) && !"null".equals(id)) {
enCodeWrapper.lambda().ne(SendMessageConfigEntity::getId, id);
}
if ((int) this.count(enCodeWrapper) > i) {
total++;
}
}
if (form.getSendConfigTemplateList() != null) {
}
if (total > 0) {
return true;
}
return false;
}
@Override
public boolean isExistByFullName(String fullName, String id) {
QueryWrapper<SendMessageConfigEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SendMessageConfigEntity::getFullName, fullName);
if (!StringUtil.isEmpty(id)) {
queryWrapper.lambda().ne(SendMessageConfigEntity::getId, id);
}
return this.count(queryWrapper) > 0 ? true : false;
}
@Override
public boolean isExistByEnCode(String enCode, String id) {
QueryWrapper<SendMessageConfigEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SendMessageConfigEntity::getEnCode, enCode);
if (!StringUtil.isEmpty(id)) {
queryWrapper.lambda().ne(SendMessageConfigEntity::getId, id);
}
return this.count(queryWrapper) > 0 ? true : false;
}
@Override
public ActionResult ImportData(SendMessageConfigEntity entity) throws DataException {
if (entity != null) {
// if (isExistByFullName(entity.getFullName(), null)) {
// return ActionResult.fail(MsgCode.EXIST001.get());
// }
if (isExistByEnCode(entity.getEnCode(), entity.getId())) {
return ActionResult.fail(MsgCode.EXIST002.get());
}
try {
this.save(entity);
} catch (Exception e) {
throw new DataException(MsgCode.IMP003.get());
}
return ActionResult.success(MsgCode.IMP001.get());
}
return ActionResult.fail(MsgCode.IMP006.get());
}
@Override
public List<SendMessageConfigEntity> getList(List<String> idList){
QueryWrapper<SendMessageConfigEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().in(SendMessageConfigEntity::getId,idList);
return this.list(queryWrapper);
}
public List<String> getIdList(String usedId){
List<String> idList = new ArrayList<>();
QueryWrapper<SendMessageConfigEntity> queryWrapper = new QueryWrapper<>();
if(this.list(queryWrapper) != null && this.list(queryWrapper).size()>0){
idList = this.list(queryWrapper).stream().distinct().map(t->t.getId()).collect(Collectors.toList());
}
return idList;
}
@Override
public void updateUsed(String id,List<String> sendConfigIdList){
UserInfo userInfo = UserProvider.getUser();
List<String> oldSendConfigList = this.getIdList(id);
if(oldSendConfigList != null && oldSendConfigList.size()>0){
List<String> subSendConfigIdList = this.subList(oldSendConfigList,sendConfigIdList);
this.removeUsed(id,subSendConfigIdList);
}
if(sendConfigIdList != null && sendConfigIdList.size()>0) {
List<SendMessageConfigEntity> sendConfigList = this.getList(sendConfigIdList);
if (sendConfigIdList != null && sendConfigIdList.size() > 0) {
// for (SendMessageConfigEntity entity : sendConfigList) {
// SendConfigRecordEntity recordEntity = new SendConfigRecordEntity();
// recordEntity = sendConfigRecordService.getRecord(entity.getId(),id);
// if(recordEntity != null){
// recordEntity.setLastModifyTime(DateUtil.getNowDate());
// recordEntity.setLastModifyUserId(userInfo.getUserId());
// sendConfigRecordService.update(recordEntity.getId(),recordEntity);
// }else {
// recordEntity = new SendConfigRecordEntity();
// recordEntity.setId(RandomUtil.uuId());
// recordEntity.setSendConfigId(entity.getId());
// recordEntity.setMessageSource(entity.getMessageSource());
// recordEntity.setUsedId(id);
// recordEntity.setCreatorTime(DateUtil.getNowDate());
// recordEntity.setCreatorUserId(userInfo.getUserId());
// sendConfigRecordService.create(recordEntity);
// }
// }
this.updateBatchById(sendConfigList);
}
}
}
@Override
public void removeUsed(String id,List<String> sendConfigIdList){
if(sendConfigIdList != null && sendConfigIdList.size()>0){
List<SendMessageConfigEntity> subConfigList = this.getList(sendConfigIdList);
// if(subConfigList != null && subConfigList.size()>0){
// for(SendMessageConfigEntity subEntity : subConfigList) {
// SendConfigRecordEntity recordEntity = sendConfigRecordService.getRecord(subEntity.getId(),id);
// if(recordEntity != null){
// sendConfigRecordService.delete(recordEntity);
// }
// }
// }
this.updateBatchById(subConfigList);
}
}
@Override
public List<String> subList(List<String> list1, List<String> list2) {
//空间换时间 降低时间复杂度
Map<String, String> tempMap = new HashMap<>();
for(String str:list2){
tempMap.put(str,str);
}
//LinkedList 频繁添加删除 也可以ArrayList容量初始化为List1.size(),防止数据量过大时频繁扩容以及数组复制
List<String> resList = new LinkedList<>();
for(String str:list1){
if(!tempMap.containsKey(str)){
resList.add(str);
}
}
return resList;
}
@Override
public boolean idUsed(String id){
boolean flag = false;
SendMessageConfigEntity entity = this.getInfo(id);
// TODO 删除逻辑重新设置
return flag;
}
}

View File

@@ -0,0 +1,129 @@
package com.yunzhupaas.message.service.impl;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.message.entity.ShortLinkEntity;
import com.yunzhupaas.message.mapper.ShortLInkMapper;
import com.yunzhupaas.message.service.ShortLinkService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunzhupaas.permission.service.AuthorizeService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yunzhupaas.util.*;
import java.security.MessageDigest;
import java.util.*;
/**
* 消息模板(新)
* 版本: V3.2.0
* 版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* 作者: 云筑产品开发平台组
* 日期: 2022-08-18
*/
@Service
public class ShortLinkServiceImpl extends SuperServiceImpl<ShortLInkMapper, ShortLinkEntity> implements ShortLinkService {
@Override
public ShortLinkEntity getInfoByLink(String link){
QueryWrapper<ShortLinkEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(ShortLinkEntity::getShortLink,link);
return this.getOne(queryWrapper);
}
@Override
public String shortLink (String link){
String shortUrl = null;
if(StringUtil.isNotBlank(link)) {
String[] aResult = shortUrl(link);//将产生4组6位字符串
// 打印出结果
Random random = new Random();
int j = random.nextInt(4);//产成4以内随机数
shortUrl = aResult[j];
if(StringUtil.isNotBlank(shortUrl)) {
QueryWrapper<ShortLinkEntity> queryWrapper = new QueryWrapper<>();
if (StringUtil.isNotEmpty(shortUrl)) {
queryWrapper.lambda().eq(ShortLinkEntity::getShortLink, shortUrl);
}
if (this.list(queryWrapper) != null && this.list(queryWrapper).size() > 0) {
shortUrl = shortUrl + j;
}
}
}
return shortUrl;
}
public static String[] shortUrl(String url) {
// 可以自定义生成 MD5 加密字符传前的混合 KEY
String key = "test";
// 要使用生成 URL 的字符
String[] chars = new String[] { "a", "b", "c", "d", "e", "f", "g", "h",
"i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
"u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5",
"6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H",
"I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
"U", "V", "W", "X", "Y", "Z"
};
// 对传入网址进行 MD5 加密
String hex = md5ByHex(key + url);
String[] resUrl = new String[4];
for (int i = 0; i < 4; i++) {
// 把加密字符按照 8 位一组 16 进制与 0x3FFFFFFF 进行位与运算
String sTempSubString = hex.substring(i * 8, i * 8 + 8);
// 这里需要使用 long 型来转换,因为 Inteper .parseInt() 只能处理 31 位 , 首位为符号位 , 如果不用long ,则会越界
long lHexLong = 0x3FFFFFFF & Long.parseLong(sTempSubString, 16);
String outChars = "";
for (int j = 0; j < 6; j++) {
// 把得到的值与 0x0000003D 进行位与运算,取得字符数组 chars 索引
long index = 0x0000003D & lHexLong;
// 把取得的字符相加
outChars += chars[(int) index];
// 每次循环按位右移 5 位
lHexLong = lHexLong >> 5;
}
// 把字符串存入对应索引的输出数组
resUrl[i] = outChars;
}
return resUrl;
}
/**
* MD5加密(32位大写)
* @param src
* @return
*/
public static String md5ByHex(String src) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] b = src.getBytes();
md.reset();
md.update(b);
byte[] hash = md.digest();
String hs = "";
String stmp = "";
for (int i = 0; i < hash.length; i++) {
stmp = Integer.toHexString(hash[i] & 0xFF);
if (stmp.length() == 1)
hs = hs + "0" + stmp;
else {
hs = hs + stmp;
}
}
return hs.toUpperCase();
} catch (Exception e) {
return "";
}
}
}

View File

@@ -0,0 +1,89 @@
package com.yunzhupaas.message.service.impl;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.message.entity.SmsFieldEntity;
import com.yunzhupaas.message.mapper.SmsFieldMapper;
import com.yunzhupaas.message.model.messagetemplateconfig.MessageTemplateConfigPagination;
import com.yunzhupaas.message.service.SmsFieldService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunzhupaas.permission.service.AuthorizeService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yunzhupaas.util.*;
import java.util.*;
/**
* 消息模板(新)
* 版本: V3.2.0
* 版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* 作者: 云筑产品开发平台组
* 日期: 2022-08-18
*/
@Service
public class SmsFieldServiceImpl extends SuperServiceImpl<SmsFieldMapper, SmsFieldEntity> implements SmsFieldService {
@Override
public QueryWrapper<SmsFieldEntity> getChild(MessageTemplateConfigPagination pagination, QueryWrapper<SmsFieldEntity> smsFieldQueryWrapper) {
// boolean pcPermission = false;
// boolean appPermission = false;
// boolean isPc = ServletUtil.getHeader("yunzhupaas-origin").equals("pc");
// if (isPc) {
// }
return smsFieldQueryWrapper;
}
@Override
public SmsFieldEntity getInfo(String id) {
QueryWrapper<SmsFieldEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SmsFieldEntity::getId, id);
return this.getOne(queryWrapper);
}
@Override
public List<SmsFieldEntity> getDetailListByParentId(String id) {
QueryWrapper<SmsFieldEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SmsFieldEntity::getTemplateId, id);
return this.list(queryWrapper);
}
@Override
public List<SmsFieldEntity> getParamList(String id,List<String> params) {
QueryWrapper<SmsFieldEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SmsFieldEntity::getTemplateId, id);
queryWrapper.lambda().in(SmsFieldEntity::getField,params);
return this.list(queryWrapper);
}
@Override
public Map<String,Object> getParamMap(String templateId,Map<String,Object> map) {
Map<String,Object> paramMap = new HashMap<>();
List<SmsFieldEntity> list = this.getDetailListByParentId(templateId);
if (list != null && list.size() > 0) {
for (SmsFieldEntity entity : list) {
if (map.containsKey(entity.getField())) {
for (String key : map.keySet()) {
if (key.equals(entity.getField())) {
paramMap.put(entity.getSmsField(), map.get(key));
if(StringUtil.isNotEmpty(String.valueOf(entity.getIsTitle())) &&!"null".equals(String.valueOf(entity.getIsTitle())) && entity.getIsTitle()==1){
paramMap.put("title",map.get(key));
}
}
}
if(entity.getField().equals("@FlowLink")){
paramMap.put(entity.getSmsField(),"@FlowLink");
}
}
}
}
return paramMap;
}
}

View File

@@ -0,0 +1,303 @@
package com.yunzhupaas.message.service.impl;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dingtalk.api.response.OapiV2DepartmentGetResponse;
import com.yunzhupaas.message.entity.SynThirdInfoEntity;
import com.yunzhupaas.message.mapper.SynThirdInfoMapper;
import com.yunzhupaas.message.model.message.DingTalkDeptModel;
import com.yunzhupaas.message.service.SynThirdDingTalkService;
import com.yunzhupaas.message.service.SynThirdInfoService;
import com.yunzhupaas.base.util.SynDingTalkUtil;
import com.yunzhupaas.message.util.SynThirdConsts;
import com.yunzhupaas.message.util.SynThirdTotal;
import com.yunzhupaas.permission.service.OrganizeService;
import com.yunzhupaas.permission.service.UserService;
import com.yunzhupaas.util.JsonUtil;
import com.yunzhupaas.util.RandomUtil;
import com.yunzhupaas.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
/**
* 第三方工具的公司-部门-用户同步表模型
*
* @版本: V3.1.0
* @版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* @作者: 云筑产品开发平台组
* @日期: 2021/4/23 17:33
*/
@Service
public class SynThirdInfoServiceImpl extends SuperServiceImpl<SynThirdInfoMapper, SynThirdInfoEntity> implements SynThirdInfoService {
@Autowired
private OrganizeService organizeApi;
@Autowired
private UserService userApi;
@Autowired
SynThirdDingTalkService synThirdDingTalkService;
@Override
public List<SynThirdInfoEntity> getList(String thirdType, String dataType) {
QueryWrapper<SynThirdInfoEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().and(t->t.eq(SynThirdInfoEntity::getThirdType, Integer.valueOf(thirdType)));
queryWrapper.lambda().and(t->t.eq(SynThirdInfoEntity::getDataType, Integer.valueOf(dataType)));
queryWrapper.lambda().orderByAsc(SynThirdInfoEntity::getCreatorTime);
return this.list(queryWrapper);
}
@Override
public SynThirdInfoEntity getInfo(String id) {
QueryWrapper<SynThirdInfoEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SynThirdInfoEntity::getId,id);
return this.getOne(queryWrapper);
}
@Override
public void create(SynThirdInfoEntity entity) {
this.save(entity);
}
@Override
public boolean update(String id, SynThirdInfoEntity entity) {
entity.setId(id);
return this.updateById(entity);
}
@Override
public void delete(SynThirdInfoEntity entity) {
if(entity!=null){
this.removeById(entity.getId());
}
}
@Override
public SynThirdInfoEntity getInfoBySysObjId(String thirdType,String dataType,String id) {
QueryWrapper<SynThirdInfoEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().and(t->t.eq(SynThirdInfoEntity::getThirdType,thirdType));
queryWrapper.lambda().and(t->t.eq(SynThirdInfoEntity::getDataType,dataType));
queryWrapper.lambda().and(t->t.eq(SynThirdInfoEntity::getSysObjId,id));
return this.getOne(queryWrapper);
}
@Override
public SynThirdTotal getSynTotal(String thirdType, String dataType) {
String synType = dataType.equals(SynThirdConsts.DATA_TYPE_ORG) ? "组织" : "用户";
Integer recordTotal = 0;
Long synSuccessCount = 0L;
Long synFailCount = 0L;
Long unSynCount = 0L;
Date synDate = null;
// 获取列表数据
List<SynThirdInfoEntity> synList = getList(thirdType, dataType).stream().filter(t->t.getLastModifyTime() != null).collect(Collectors.toList());
if(synList!=null && synList.size()>0){
synSuccessCount = synList.stream().filter(t -> t.getEnabledMark().equals(SynThirdConsts.SYN_STATE_OK)).count();
synFailCount = synList.stream().filter(t -> t.getEnabledMark().equals(SynThirdConsts.SYN_STATE_FAIL)).count();
unSynCount = synList.stream().filter(t -> t.getEnabledMark().equals(SynThirdConsts.SYN_STATE_NO)).count();
synDate = synList.stream().max(Comparator.comparing(u -> u.getLastModifyTime())).isPresent() ? synList.stream().max(Comparator.comparing(u -> u.getLastModifyTime())).get().getLastModifyTime() : null;
}
// 获取本系统的组织、用户表的记录数
if(dataType.equals(SynThirdConsts.DATA_TYPE_ORG)){
// 获取组织(公司和部门)的记录数
recordTotal = organizeApi.getList(false).size();
}else{
// 获取用户的记录数
recordTotal = userApi.getList(false).size();
}
// 写入同步统计模型对象
SynThirdTotal synThirdTotal = new SynThirdTotal();
synThirdTotal.setSynType(synType);
synThirdTotal.setRecordTotal(recordTotal);
synThirdTotal.setSynSuccessCount(synSuccessCount);
synThirdTotal.setSynFailCount(synFailCount);
synThirdTotal.setUnSynCount(unSynCount);
synThirdTotal.setSynDate(synDate);
return synThirdTotal;
}
@Override
public List<SynThirdInfoEntity> syncThirdInfoByType(String thirdToSysType, String dataTypeOrg, String SysToThirdType) {
HashMap<String,String> typeMap = new HashMap<>();
typeMap.put(SysToThirdType,thirdToSysType);
typeMap.put(thirdToSysType,SysToThirdType);
List<SynThirdInfoEntity> synThirdInfoList = this.getList(thirdToSysType, dataTypeOrg);
List<SynThirdInfoEntity> synThirdInfoDingList = this.getList( typeMap.get(thirdToSysType), dataTypeOrg);
List<String> collectSource = synThirdInfoList.stream().filter(t -> StringUtil.isBlank(t.getThirdObjId()) || StringUtil.isBlank(t.getSysObjId())).map(t->t.getId()).collect(Collectors.toList());
List<String> collectTarget = synThirdInfoDingList.stream().filter(t -> StringUtil.isBlank(t.getThirdObjId()) || StringUtil.isBlank(t.getSysObjId())).map(t->t.getId()).collect(Collectors.toList());
List<String> deleteList = new ArrayList<>();
deleteList.addAll(collectSource);
deleteList.addAll(collectTarget);
// List<String> fails = this.selectAllFail();
// deleteList.addAll(fails);
if(!deleteList.isEmpty()){
this.getBaseMapper().deleteBatchIds(deleteList);
}
synThirdInfoList = this.getList(thirdToSysType, dataTypeOrg);
synThirdInfoDingList = this.getList( typeMap.get(thirdToSysType), dataTypeOrg);
// 记录已经存在的组合
HashMap<String,Boolean> existingMap = new HashMap<>();
synThirdInfoList.forEach(k->{
String tag = k.getThirdType() + "-" + k.getDataType() + "-" +k.getSysObjId() +"-"+k.getThirdObjId();
existingMap.put(tag,true);
});
synThirdInfoDingList.forEach(k->{
String tag = k.getThirdType() + "-" + k.getDataType() + "-" +k.getSysObjId() +"-"+k.getThirdObjId();
existingMap.put(tag,true);
});
HashMap<String, SynThirdInfoEntity> mapSource = new HashMap<>();
HashMap<String, SynThirdInfoEntity> mapTarget = new HashMap<>();
String tag = "";
for(SynThirdInfoEntity entity :synThirdInfoList){
// if(collectSource.size()>0 && !collectSource.contains(entity.getId())){
tag =entity.getSysObjId() +"-" + entity.getThirdObjId();
mapSource.put(tag,entity);
// }
}
for(SynThirdInfoEntity entity :synThirdInfoDingList){
// if(collectTarget.size()>0 && !collectTarget.contains(entity.getId())){
tag =entity.getSysObjId() +"-" + entity.getThirdObjId();
mapTarget.put(tag,entity);
// }
}
// 同步记录
List<SynThirdInfoEntity> synThirdInfoAddList = new ArrayList<>();
SynThirdInfoEntity addEntity = null;
if(mapSource.size()==0 && mapTarget.size()==0){
return new ArrayList<>();
}else if (mapSource.size()>0 && mapTarget.size()==0){
for(String key : mapSource.keySet()){
SynThirdInfoEntity synThirdInfoEntity = mapSource.get(key);
addEntity = JsonUtil.getJsonToBean(synThirdInfoEntity,SynThirdInfoEntity.class);
addEntity.setId(RandomUtil.uuId());
addEntity.setThirdType(Integer.valueOf(typeMap.get(thirdToSysType)));
synThirdInfoAddList.add(addEntity);
}
}else if (mapSource.size()==0 && mapTarget.size()>0){
for(String key : mapTarget.keySet()){
SynThirdInfoEntity synThirdInfoEntity = mapTarget.get(key);
addEntity = JsonUtil.getJsonToBean(synThirdInfoEntity,SynThirdInfoEntity.class);
addEntity.setId(RandomUtil.uuId());
addEntity.setThirdType(Integer.valueOf(thirdToSysType));
synThirdInfoAddList.add(addEntity);
}
}else{
for(String key : mapSource.keySet()){
if(!mapTarget.containsKey(key)){
SynThirdInfoEntity synThirdInfoEntity = mapSource.get(key);
addEntity = JsonUtil.getJsonToBean(synThirdInfoEntity,SynThirdInfoEntity.class);
addEntity.setId(RandomUtil.uuId());
addEntity.setThirdType(Integer.valueOf(typeMap.get(thirdToSysType)));
synThirdInfoAddList.add(addEntity);
}
}
for(String key : mapTarget.keySet()){
if(!mapSource.containsKey(key)){
SynThirdInfoEntity synThirdInfoEntity = mapTarget.get(key);
addEntity = JsonUtil.getJsonToBean(synThirdInfoEntity,SynThirdInfoEntity.class);
addEntity.setId(RandomUtil.uuId());
addEntity.setThirdType(Integer.valueOf(thirdToSysType));
synThirdInfoAddList.add(addEntity);
}
}
}
ArrayList<SynThirdInfoEntity> addList = new ArrayList<>();
if(synThirdInfoAddList.size() > 0 ){
// 过滤
synThirdInfoAddList.forEach(k->{
String addTag = k.getThirdType() + "-" + k.getDataType() + "-" +k.getSysObjId() +"-"+k.getThirdObjId();
if (existingMap.get(addTag)==null) {
addList.add(k);
}
});
this.saveBatch(addList);
}
// 查找对应的数据
synThirdInfoList = this.getList(thirdToSysType, dataTypeOrg);
return synThirdInfoList;
}
private List<String> selectAllFail() {
QueryWrapper<SynThirdInfoEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().and(t->t.eq(SynThirdInfoEntity::getEnabledMark,"2"));
List<SynThirdInfoEntity> lists = this.getBaseMapper().selectList(queryWrapper);
return lists.stream().map(t->t.getId()).collect(Collectors.toList());
}
@Override
public void initBaseDept(Long dingRootDeptId, String access_token, String thirdType) {
final String sysByThird = this.getSysByThird("1");
// 判断是否在中间表存在
JSONObject retMsg = new JSONObject();
if(StringUtil.isBlank(sysByThird)){
if("22".equals(thirdType)){
retMsg = SynDingTalkUtil.getDepartmentInfo(SynThirdConsts.DING_ROOT_DEPT_ID, access_token);
OapiV2DepartmentGetResponse.DeptGetResponse departmentInfo = (OapiV2DepartmentGetResponse.DeptGetResponse) retMsg.get("departmentInfo");
DingTalkDeptModel model = JsonUtil.getJsonToBean(departmentInfo, DingTalkDeptModel.class);
retMsg = synThirdDingTalkService.createDepartmentDingToSys(true, model, access_token);
}
// if("11".equals(thirdType)){
// retMsg = SynDingTalkUtil.getDepartmentInfo(SynThirdConsts.QY_ROOT_DEPT_ID, access_token);
// OapiV2DepartmentGetResponse.DeptGetResponse departmentInfo = (OapiV2DepartmentGetResponse.DeptGetResponse) retMsg.get("departmentInfo");
// DingTalkDeptModel model = JsonUtil.getJsonToBean(departmentInfo, DingTalkDeptModel.class);
// retMsg = synThirdDingTalkService.createDepartmentDingToSys(true, model, access_token);
// }
}
}
@Override
public boolean getBySysObjId(String id) {
QueryWrapper<SynThirdInfoEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SynThirdInfoEntity::getEnabledMark,"1");
queryWrapper.lambda().eq(SynThirdInfoEntity::getSysObjId,id);
List<SynThirdInfoEntity> list = this.getBaseMapper().selectList(queryWrapper);
if(list!=null && list.size() > 0){
return true;
}else{
return false;
}
}
@Override
public String getSysByThird(String valueOf) {
QueryWrapper<SynThirdInfoEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().isNotNull(SynThirdInfoEntity::getSysObjId);
queryWrapper.lambda().eq(SynThirdInfoEntity::getThirdObjId,valueOf);
List<SynThirdInfoEntity> list = this.getBaseMapper().selectList(queryWrapper);
if(list!=null && !list.isEmpty()){
return list.get(0).getSysObjId();
}
return null;
}
@Override
public SynThirdInfoEntity getInfoByThirdObjId(String thirdType,String dataType,String thirdObjId) {
QueryWrapper<SynThirdInfoEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().and(t->t.eq(SynThirdInfoEntity::getThirdType,thirdType));
queryWrapper.lambda().and(t->t.eq(SynThirdInfoEntity::getDataType,dataType));
queryWrapper.lambda().and(t->t.eq(SynThirdInfoEntity::getThirdObjId,thirdObjId));
return this.getOne(queryWrapper);
}
}

View File

@@ -0,0 +1,66 @@
package com.yunzhupaas.message.service.impl;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.message.entity.TemplateParamEntity;
import com.yunzhupaas.message.mapper.TemplateParamMapper;
import com.yunzhupaas.message.model.messagetemplateconfig.MessageTemplateConfigPagination;
import com.yunzhupaas.message.service.TemplateParamService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunzhupaas.permission.service.AuthorizeService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yunzhupaas.util.*;
import java.util.*;
/**
* 消息模板(新)
* 版本: V3.2.0
* 版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* 作者: 云筑产品开发平台组
* 日期: 2022-08-18
*/
@Service
public class TemplateParamServiceImpl extends SuperServiceImpl<TemplateParamMapper, TemplateParamEntity> implements TemplateParamService {
@Override
public QueryWrapper<TemplateParamEntity> getChild(MessageTemplateConfigPagination pagination, QueryWrapper<TemplateParamEntity> templateParamQueryWrapper) {
// boolean pcPermission = false;
// boolean appPermission = false;
// boolean isPc = ServletUtil.getHeader("yunzhupaas-origin").equals("pc");
// if (isPc) {
// }
return templateParamQueryWrapper;
}
@Override
public TemplateParamEntity getInfo(String id) {
QueryWrapper<TemplateParamEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(TemplateParamEntity::getId, id);
return this.getOne(queryWrapper);
}
@Override
public List<TemplateParamEntity> getDetailListByParentId(String id) {
QueryWrapper<TemplateParamEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(TemplateParamEntity::getTemplateId, id);
return this.list(queryWrapper);
}
@Override
public List<TemplateParamEntity> getParamList(String id,List<String> params) {
QueryWrapper<TemplateParamEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(TemplateParamEntity::getTemplateId, id);
queryWrapper.lambda().in(TemplateParamEntity::getField,params);
return this.list(queryWrapper);
}
}

View File

@@ -0,0 +1,76 @@
package com.yunzhupaas.message.service.impl;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunzhupaas.message.entity.UserDeviceEntity;
import com.yunzhupaas.message.mapper.UserDeviceMapper;
import com.yunzhupaas.message.service.UserDeviceService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yunzhupaas.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* 消息模板(新)
* 版本: V3.2.0
* 版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* 作者: 云筑产品开发平台组
* 日期: 2022-08-18
*/
@Service
public class UserDeviceServiceImpl extends SuperServiceImpl<UserDeviceMapper, UserDeviceEntity> implements UserDeviceService {
@Override
public UserDeviceEntity getInfoByUserId(String userId){
QueryWrapper<UserDeviceEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(UserDeviceEntity::getUserId,userId);
return this.getOne(queryWrapper);
}
@Override
public List<String> getCidList(String userId){
List<String> cidList = new ArrayList<>();
QueryWrapper<UserDeviceEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(UserDeviceEntity::getUserId,userId);
if(this.list(queryWrapper) != null && this.list(queryWrapper).size()>0) {
cidList = this.list(queryWrapper).stream().map(t -> t.getClientId()).distinct().collect(Collectors.toList());
}
return cidList;
}
@Override
public UserDeviceEntity getInfoByClientId(String clientId){
QueryWrapper<UserDeviceEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(UserDeviceEntity::getClientId,clientId);
return this.getOne(queryWrapper);
}
@Override
public void create(UserDeviceEntity entity) {
this.save(entity);
}
@Override
public boolean update(String id, UserDeviceEntity entity) {
entity.setId(id);
return this.updateById(entity);
}
@Override
public void delete(UserDeviceEntity entity) {
if (entity != null) {
this.removeById(entity.getId());
}
}
}

View File

@@ -0,0 +1,62 @@
package com.yunzhupaas.message.service.impl;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.message.entity.WechatUserEntity;
import com.yunzhupaas.message.mapper.WechatUserMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunzhupaas.message.service.WechatUserService;
import com.yunzhupaas.permission.service.AuthorizeService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yunzhupaas.util.*;
import java.security.MessageDigest;
import java.util.*;
/**
* 消息模板(新)
* 版本: V3.2.0
* 版权: 深圳市乐程软件有限公司http://www.szlecheng.cn
* 作者: 云筑产品开发平台组
* 日期: 2022-08-18
*/
@Service
public class WechatUserServiceImpl extends SuperServiceImpl<WechatUserMapper, WechatUserEntity> implements WechatUserService {
@Override
public WechatUserEntity getInfoByGzhId(String userId,String gzhId){
QueryWrapper<WechatUserEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(WechatUserEntity::getUserId,userId);
queryWrapper.lambda().eq(WechatUserEntity::getGzhId,gzhId);
queryWrapper.lambda().eq(WechatUserEntity::getCloseMark,1);
return this.getOne(queryWrapper);
}
@Override
public void create(WechatUserEntity entity) {
this.save(entity);
}
@Override
public boolean update(String id, WechatUserEntity entity) {
entity.setId(id);
return this.updateById(entity);
}
@Override
public void delete(WechatUserEntity entity) {
if (entity != null) {
this.removeById(entity.getId());
}
}
}

View File

@@ -0,0 +1,48 @@
package com.yunzhupaas.message.util;
import com.alibaba.fastjson.JSONObject;
import com.yunzhupaas.base.UserInfo;
import com.yunzhupaas.message.entity.MessageReceiveEntity;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.Objects;
/**
* 消息推送工具类
*
* @author 云筑产品开发平台组
* @version V3.1.0
* @copyright 深圳市乐程软件有限公司http://www.szlecheng.cn
* @date 2024-07-07
*/
@Component
public class PushMessageUtil {
/**
* 工作流消息发送
*
*
* @param userInfo
*/
public static void pushMessage(Map<String, MessageReceiveEntity> map, UserInfo userInfo, int messageType){
for (String userId : map.keySet()) {
for (OnlineUserModel item : OnlineUserProvider.getOnlineUserList()) {
if (userId.equals(item.getUserId()) && Objects.equals(userInfo.getTenantId(), item.getTenantId())) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("method", "messagePush");
jsonObject.put("unreadNoticeCount", 1);
jsonObject.put("messageType", messageType);
jsonObject.put("userId", userInfo.getUserId());
jsonObject.put("toUserId", userId);
jsonObject.put("title", map.get(userId).getTitle());
jsonObject.put("id",map.get(userId).getId());
jsonObject.put("messageDefaultTime", map.get(userId).getLastModifyTime() != null ? map.get(userId).getLastModifyTime().getTime() : null);
OnlineUserProvider.sendMessage(item, jsonObject);
}
}
}
}
}