初始代码
This commit is contained in:
22
yunzhupaas-message/yunzhupaas-message-controller/pom.xml
Normal file
22
yunzhupaas-message/yunzhupaas-message-controller/pom.xml
Normal file
@@ -0,0 +1,22 @@
|
||||
<?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-controller</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-message-biz</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,531 @@
|
||||
package com.yunzhupaas.message.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.entity.DictionaryDataEntity;
|
||||
import com.yunzhupaas.base.service.BillRuleService;
|
||||
import com.yunzhupaas.base.service.DictionaryDataService;
|
||||
import com.yunzhupaas.base.service.DictionaryTypeService;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.base.UserInfo;
|
||||
import com.yunzhupaas.base.vo.DownloadVO;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.message.entity.AccountConfigEntity;
|
||||
import com.yunzhupaas.message.model.accountconfig.*;
|
||||
import com.yunzhupaas.message.model.message.EmailModel;
|
||||
import com.yunzhupaas.message.service.AccountConfigService;
|
||||
import com.yunzhupaas.message.service.SendConfigTemplateService;
|
||||
import com.yunzhupaas.message.util.EmailUtil;
|
||||
import com.yunzhupaas.message.util.QyWebChatUtil;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.emnus.ModuleTypeEnum;
|
||||
import com.yunzhupaas.util.FileExport;
|
||||
import com.yunzhupaas.util.third.DingTalkUtil;
|
||||
import com.yunzhupaas.util.wxutil.HttpUtil;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.yunzhupaas.util.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* 账号配置功能
|
||||
*
|
||||
* @版本: V3.2.0
|
||||
* @版权: 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @作者: 云筑产品开发平台组
|
||||
* @日期: 2022-08-18
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Tag(name = "账号配置功能", description = "message")
|
||||
@RequestMapping("/api/message/AccountConfig")
|
||||
public class AccountConfigController extends SuperController<AccountConfigService, AccountConfigEntity> {
|
||||
|
||||
@Autowired
|
||||
private FileExport fileExport;
|
||||
|
||||
@Autowired
|
||||
private BillRuleService billRuleService;
|
||||
|
||||
@Autowired
|
||||
private ConfigValueUtil configValueUtil;
|
||||
|
||||
@Autowired
|
||||
private UserService userApi;
|
||||
|
||||
@Autowired
|
||||
private AccountConfigService accountConfigService;
|
||||
@Autowired
|
||||
private DictionaryDataService dictionaryDataApi;
|
||||
@Autowired
|
||||
private SendConfigTemplateService sendConfigTemplateService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @param accountConfigPagination 账号配置分页模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "列表")
|
||||
@SaCheckPermission("msgCenter.accountConfig")
|
||||
@GetMapping
|
||||
public ActionResult<PageListVO<AccountConfigListVO>> list(AccountConfigPagination accountConfigPagination) throws IOException {
|
||||
List<AccountConfigEntity> list = accountConfigService.getList(accountConfigPagination);
|
||||
List<DictionaryDataEntity> smsSendTypeList = dictionaryDataApi.getListByTypeDataCode("smsSendType");
|
||||
List<DictionaryDataEntity> webHookList = dictionaryDataApi.getListByTypeDataCode("msgWebHookSendType");
|
||||
//处理id字段转名称,若无需转或者为空可删除
|
||||
UserEntity userEntity;
|
||||
List<AccountConfigListVO> listVO = JsonUtil.getJsonToList(list, AccountConfigListVO.class);
|
||||
for (AccountConfigListVO accountConfigVO : listVO) {
|
||||
//渠道
|
||||
if (StringUtil.isNotEmpty(accountConfigVO.getChannel())) {
|
||||
smsSendTypeList.stream().filter(t -> accountConfigVO.getChannel().equals(t.getEnCode())).findFirst()
|
||||
.ifPresent(dataTypeEntity -> accountConfigVO.setChannel(dataTypeEntity.getFullName()));
|
||||
}
|
||||
//webhook类型
|
||||
if (accountConfigVO.getWebhookType() != null) {
|
||||
webHookList.stream().filter(t -> accountConfigVO.getWebhookType().equals(t.getEnCode())).findFirst()
|
||||
.ifPresent(dataTypeEntity -> accountConfigVO.setWebhookType(dataTypeEntity.getFullName()));
|
||||
}
|
||||
|
||||
if (StringUtil.isNotEmpty(accountConfigVO.getCreatorUserId())) {
|
||||
userEntity = userApi.getInfo(accountConfigVO.getCreatorUserId());
|
||||
if (userEntity != null) {
|
||||
accountConfigVO.setCreatorUser(userEntity.getRealName() + "/" + userEntity.getAccount());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PageListVO vo = new PageListVO();
|
||||
vo.setList(listVO);
|
||||
PaginationVO page = JsonUtil.getJsonToBean(accountConfigPagination, PaginationVO.class);
|
||||
vo.setPagination(page);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建
|
||||
*
|
||||
* @param accountConfigForm 新建账号配置模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "新建")
|
||||
@Parameters({
|
||||
@Parameter(name = "accountConfigForm", description = "新建账号配置模型")
|
||||
})
|
||||
@SaCheckPermission("msgCenter.accountConfig")
|
||||
@PostMapping
|
||||
@Transactional
|
||||
public ActionResult create(@RequestBody @Valid AccountConfigForm accountConfigForm) throws DataException {
|
||||
boolean b = accountConfigService.checkForm(accountConfigForm, 0,accountConfigForm.getType(),"");
|
||||
if (b) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
boolean c = accountConfigService.checkGzhId(accountConfigForm.getAppKey(),0, "7", "");
|
||||
if("7".equals(accountConfigForm.getType())) {
|
||||
if (c) {
|
||||
return ActionResult.fail(MsgCode.FA048.get());
|
||||
}
|
||||
}
|
||||
String mainId = RandomUtil.uuId();
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
AccountConfigEntity entity = JsonUtil.getJsonToBean(accountConfigForm, AccountConfigEntity.class);
|
||||
entity.setCreatorTime(DateUtil.getNowDate());
|
||||
entity.setCreatorUserId(userInfo.getUserId());
|
||||
entity.setId(mainId);
|
||||
accountConfigService.save(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "信息")
|
||||
@GetMapping("/{id}")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.accountConfig")
|
||||
public ActionResult<AccountConfigInfoVO> info(@PathVariable("id") String id) {
|
||||
AccountConfigEntity entity = accountConfigService.getInfo(id);
|
||||
AccountConfigInfoVO vo = JsonUtil.getJsonToBean(entity, AccountConfigInfoVO.class);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单信息(详情页)
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "表单信息(详情页)")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.accountConfig")
|
||||
@GetMapping("/detail/{id}")
|
||||
public ActionResult<AccountConfigInfoVO> detailInfo(@PathVariable("id") String id) {
|
||||
return info(id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @param id 主键
|
||||
* @param accountConfigForm 修改账号配置模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "更新")
|
||||
@PutMapping("/{id}")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "accountConfigForm", description = "修改账号配置模型", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.accountConfig")
|
||||
@Transactional
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid AccountConfigForm accountConfigForm) throws DataException {
|
||||
|
||||
boolean b = accountConfigService.checkForm(accountConfigForm, 0,accountConfigForm.getType(),accountConfigForm.getId());
|
||||
if (b) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
boolean c = accountConfigService.checkGzhId(accountConfigForm.getAppKey(),0, "7", id);
|
||||
if("7".equals(accountConfigForm.getType())) {
|
||||
if (c) {
|
||||
return ActionResult.fail(MsgCode.FA048.get());
|
||||
}
|
||||
}
|
||||
//判断配置是否被引用
|
||||
if(Objects.equals(0, accountConfigForm.getEnabledMark())){
|
||||
if(sendConfigTemplateService.isUsedAccount(accountConfigForm.getId())) {
|
||||
return ActionResult.fail(MsgCode.FA049.get());
|
||||
}
|
||||
}
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
AccountConfigEntity entity = accountConfigService.getInfo(id);
|
||||
if (entity != null) {
|
||||
AccountConfigEntity subentity = JsonUtil.getJsonToBean(accountConfigForm, AccountConfigEntity.class);
|
||||
subentity.setCreatorTime(entity.getCreatorTime());
|
||||
subentity.setCreatorUserId(entity.getCreatorUserId());
|
||||
subentity.setLastModifyTime(DateUtil.getNowDate());
|
||||
subentity.setLastModifyUserId(userInfo.getUserId());
|
||||
boolean b1 = accountConfigService.updateById(subentity);
|
||||
if (!b1) {
|
||||
return ActionResult.fail(MsgCode.VS405.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
} else {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "删除")
|
||||
@DeleteMapping("/{id}")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.accountConfig")
|
||||
@Transactional
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
AccountConfigEntity entity = accountConfigService.getInfo(id);
|
||||
if (entity != null) {
|
||||
//判断是否与消息发送配置关联
|
||||
//判断配置是否被引用
|
||||
if(sendConfigTemplateService.isUsedAccount(entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.FA050.get());
|
||||
}
|
||||
|
||||
accountConfigService.delete(entity);
|
||||
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 开启或禁用
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "开启或禁用")
|
||||
@PostMapping("/unable/{id}")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.accountConfig")
|
||||
@Transactional
|
||||
public ActionResult unable(@PathVariable("id") String id) {
|
||||
AccountConfigEntity entity = accountConfigService.getInfo(id);
|
||||
if (entity != null) {
|
||||
if("1".equals(String.valueOf(entity.getEnabledMark()))){
|
||||
entity.setEnabledMark(0);
|
||||
return ActionResult.success(MsgCode.WF027.get());
|
||||
}else {
|
||||
//判断是否被引用
|
||||
|
||||
entity.setEnabledMark(1);
|
||||
return ActionResult.success(MsgCode.WF026.get());
|
||||
}
|
||||
}else {
|
||||
return ActionResult.fail(MsgCode.FA007.get());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "复制")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.accountConfig")
|
||||
@PostMapping("/{id}/Actions/Copy")
|
||||
@Transactional
|
||||
public ActionResult copy(@PathVariable("id") String id) {
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
AccountConfigEntity entity = accountConfigService.getInfo(id);
|
||||
if (entity != null) {
|
||||
entity.setEnabledMark(0);
|
||||
String copyNum = UUID.randomUUID().toString().substring(0, 5);
|
||||
entity.setFullName(entity.getFullName()+".副本"+copyNum);
|
||||
entity.setEnCode(entity.getEnCode()+copyNum);
|
||||
entity.setCreatorTime(DateUtil.getNowDate());
|
||||
entity.setCreatorUserId(userInfo.getUserId());
|
||||
if("7".equals(entity.getType())){
|
||||
entity.setAppKey(entity.getAppKey()+"副本"+copyNum);
|
||||
}
|
||||
entity.setLastModifyTime(null);
|
||||
entity.setLastModifyUserId(null);
|
||||
entity.setId(RandomUtil.uuId());
|
||||
AccountConfigEntity copyEntity = JsonUtil.getJsonToBean(entity, AccountConfigEntity.class);
|
||||
if(copyEntity.getEnCode().length()>50 || copyEntity.getFullName().length()>50){
|
||||
return ActionResult.fail(MsgCode.PRI006.get());
|
||||
}
|
||||
accountConfigService.create(copyEntity);
|
||||
return ActionResult.success(MsgCode.SU007.get());
|
||||
}else {
|
||||
return ActionResult.fail(MsgCode.FA004.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出账号配置
|
||||
*
|
||||
* @param id 账号配置id
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "导出")
|
||||
@GetMapping("/{id}/Action/Export")
|
||||
public ActionResult export(@PathVariable String id) {
|
||||
AccountConfigEntity entity = accountConfigService.getInfo(id);
|
||||
//导出文件
|
||||
DownloadVO downloadVO = fileExport.exportFile(entity, configValueUtil.getTemporaryFilePath(), entity.getFullName(), ModuleTypeEnum.ACCOUNT_CONFIG.getTableName());
|
||||
return ActionResult.success(downloadVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入账号配置
|
||||
*
|
||||
* @param multipartFile 备份json文件
|
||||
* @return 执行结果标识
|
||||
*/
|
||||
@Operation(summary = "导入")
|
||||
@PostMapping(value = "/Action/Import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ActionResult importData(@RequestPart("file") MultipartFile multipartFile) throws DataException {
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
//判断是否为.json结尾
|
||||
if (FileUtil.existsSuffix(multipartFile, ModuleTypeEnum.ACCOUNT_CONFIG.getTableName())) {
|
||||
return ActionResult.fail(MsgCode.IMP002.get());
|
||||
}
|
||||
//获取文件内容
|
||||
String fileContent = FileUtil.getFileContent(multipartFile);
|
||||
AccountConfigEntity entity = JsonUtil.getJsonToBean(fileContent, AccountConfigEntity.class);
|
||||
entity.setCreatorUserId(userInfo.getUserId());
|
||||
entity.setCreatorTime(DateUtil.getNowDate());
|
||||
return accountConfigService.ImportData(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试发送邮件
|
||||
*
|
||||
* @param accountConfigForm 账号测试模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "测试发送邮箱")
|
||||
@Parameters({
|
||||
@Parameter(name = "accountConfigForm", description = "账号测试模型", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.accountConfig")
|
||||
@PostMapping("/testSendMail")
|
||||
@Transactional
|
||||
public ActionResult testSendMail(@RequestBody @Valid AccountConfigForm accountConfigForm) {
|
||||
List<String> toMails = accountConfigForm.getTestSendEmail();
|
||||
// 获取邮箱配置
|
||||
Map<String, String> objModel = new HashMap<>();
|
||||
objModel.put("emailSmtpHost",accountConfigForm.getSmtpServer());
|
||||
objModel.put("emailSmtpPort",accountConfigForm.getSmtpPort().toString());
|
||||
objModel.put("emailSenderName",accountConfigForm.getAddressorName());
|
||||
objModel.put("emailAccount",accountConfigForm.getSmtpUser());
|
||||
objModel.put("emailPassword",accountConfigForm.getSmtpPassword());
|
||||
objModel.put("emailSsl",accountConfigForm.getSslLink()== 1 ? "true" : "false");
|
||||
|
||||
|
||||
EmailModel emailModel = JsonUtil.getJsonToBean(objModel, EmailModel.class);
|
||||
StringBuilder toUserMail = new StringBuilder();
|
||||
String userEmailAll = "";
|
||||
String userEmail = "";
|
||||
String userName = "";
|
||||
|
||||
// 相关参数验证
|
||||
if (StringUtil.isEmpty(emailModel.getEmailSmtpHost())) {
|
||||
return ActionResult.fail(MsgCode.MSERR101.get());
|
||||
} else if (StringUtil.isEmpty(emailModel.getEmailSmtpPort())) {
|
||||
return ActionResult.fail(MsgCode.MSERR101.get());
|
||||
} else if (StringUtil.isEmpty(emailModel.getEmailAccount())) {
|
||||
return ActionResult.fail(MsgCode.MSERR102.get());
|
||||
} else if (StringUtil.isEmpty(emailModel.getEmailPassword())) {
|
||||
return ActionResult.fail(MsgCode.MSERR103.get());
|
||||
} else if (toMails == null || toMails.size() < 1) {
|
||||
return ActionResult.fail(MsgCode.MSERR104.get());
|
||||
} else {
|
||||
// 设置邮件标题
|
||||
emailModel.setEmailTitle(accountConfigForm.getTestEmailTitle());
|
||||
// 设置邮件内容
|
||||
String content = accountConfigForm.getTestEmailContent();
|
||||
emailModel.setEmailContent(content);
|
||||
|
||||
// 获取收件人的邮箱地址、创建消息用户实体
|
||||
for (String userId : toMails) {
|
||||
UserEntity userEntity = userApi.getInfo(userId);
|
||||
if (userEntity != null) {
|
||||
userEmail = StringUtil.isEmpty(userEntity.getEmail()) ? "" : userEntity.getEmail();
|
||||
userName = userEntity.getRealName();
|
||||
}
|
||||
if (StringUtil.isNotBlank(userEmail) && !"null".equals(userEmail)) {
|
||||
//校验用户邮箱格式
|
||||
if(!isEmail(userEmail)){
|
||||
return ActionResult.fail(MsgCode.MSERR105.get(userName));
|
||||
}
|
||||
toUserMail = toUserMail.append(",").append(userName).append("<").append(userEmail).append(">");
|
||||
} else {
|
||||
return ActionResult.fail(MsgCode.MSERR106.get(userName));
|
||||
}
|
||||
}
|
||||
// 处理接收人员的邮箱信息串并验证
|
||||
userEmailAll = toUserMail.toString();
|
||||
if (StringUtil.isNotEmpty(userEmailAll)) {
|
||||
userEmailAll = userEmailAll.substring(1);
|
||||
}
|
||||
if (StringUtil.isEmpty(userEmailAll)) {
|
||||
return ActionResult.fail(MsgCode.MSERR107.get());
|
||||
} else {
|
||||
// 设置接收人员
|
||||
emailModel.setEmailToUsers(userEmailAll);
|
||||
// 发送邮件
|
||||
JSONObject retJson = EmailUtil.sendMail(emailModel);
|
||||
if (!retJson.getBoolean("code")) {
|
||||
return ActionResult.fail(MsgCode.MSERR108.get(retJson.get("error")));
|
||||
}
|
||||
}
|
||||
}
|
||||
return ActionResult.success(MsgCode.MSERR111.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试企业微信配置的连接功能
|
||||
*
|
||||
* @param accountConfigForm 账号测试模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "测试企业微信配置的连接")
|
||||
@Parameters({
|
||||
@Parameter(name = "accountConfigForm", description = "账号测试模型", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.accountConfig")
|
||||
@PostMapping("/testQyWebChatConnect")
|
||||
public ActionResult testQyWebChatConnect(@RequestBody @Valid AccountConfigForm accountConfigForm) {
|
||||
JSONObject retMsg;
|
||||
// 测试发送消息、组织同步的连接
|
||||
//企业微信企业id
|
||||
String corpId = accountConfigForm.getEnterpriseId();
|
||||
//企业微信应用secret
|
||||
String agentSecret = accountConfigForm.getAppSecret();
|
||||
// String corpSecret = testAccountConfigForm.getQyhCorpSecret();
|
||||
// 测试发送消息的连接
|
||||
retMsg = QyWebChatUtil.getAccessToken(corpId, agentSecret);
|
||||
if (HttpUtil.isWxError(retMsg)) {
|
||||
return ActionResult.fail(MsgCode.MSERR110.get(retMsg.getString("errmsg")));
|
||||
}
|
||||
return ActionResult.success(MsgCode.MSERR109.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试钉钉配置的连接功能
|
||||
*
|
||||
* @param accountConfigForm 账号测试模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "测试钉钉配置的连接")
|
||||
@Parameters({
|
||||
@Parameter(name = "accountConfigForm", description = "账号测试模型", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.accountConfig")
|
||||
@PostMapping("/testDingTalkConnect")
|
||||
public ActionResult testDingTalkConnect(@RequestBody @Valid AccountConfigForm accountConfigForm) {
|
||||
JSONObject retMsg;
|
||||
// 测试钉钉配置的连接
|
||||
String appKey = accountConfigForm.getAppId();
|
||||
String appSecret = accountConfigForm.getAppSecret();
|
||||
///
|
||||
// String agentId = dingTalkModel.getDingAgentId();
|
||||
// 测试钉钉的连接
|
||||
retMsg = DingTalkUtil.getAccessToken(appKey, appSecret);
|
||||
if (!retMsg.getBoolean("code")) {
|
||||
return ActionResult.fail(MsgCode.MSERR110.get(retMsg.getString("error")));
|
||||
}
|
||||
return ActionResult.success(MsgCode.MSERR109.get());
|
||||
}
|
||||
|
||||
public boolean isEmail(String email){
|
||||
String EMAIL_REGEX = "^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$";
|
||||
Boolean b = email.matches(EMAIL_REGEX);
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
package com.yunzhupaas.message.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.message.entity.ImReplyEntity;
|
||||
import com.yunzhupaas.message.model.ImReplyListModel;
|
||||
import com.yunzhupaas.message.model.ImReplyListVo;
|
||||
import com.yunzhupaas.message.service.ImContentService;
|
||||
import com.yunzhupaas.message.service.ImReplyService;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.UploaderUtil;
|
||||
import com.yunzhupaas.util.UserProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 消息会话接口
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024-05-29
|
||||
*/
|
||||
@Tag(name = "消息会话接口", description = "imreply")
|
||||
@RestController
|
||||
@RequestMapping("/api/message/imreply")
|
||||
public class ImReplyController extends SuperController<ImReplyService, ImReplyEntity> {
|
||||
@Autowired
|
||||
private ImReplyService imReplyService;
|
||||
@Autowired
|
||||
private ImContentService imContentService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* 获取消息会话列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取消息会话列表")
|
||||
@GetMapping
|
||||
public ActionResult<ListVO<ImReplyListVo>> getList() {
|
||||
List<ImReplyListModel> imReplyList = imReplyService.getImReplyList();
|
||||
//过滤 发送者删除标记
|
||||
imReplyList = imReplyList.stream().filter(t ->{
|
||||
List<String> deleteId = StringUtil.isNotEmpty(t.getDeleteUserId())? Arrays.asList(t.getDeleteUserId().split(",")):new ArrayList<>();
|
||||
return !deleteId.contains(UserProvider.getUser().getUserId());
|
||||
}).collect(Collectors.toList());
|
||||
List<ImReplyListModel> imReplyLists = new ArrayList<>(imReplyList);
|
||||
for (ImReplyListModel vo : imReplyList) {
|
||||
UserEntity entity = userService.getInfo(vo.getId());
|
||||
if (entity == null || entity.getEnabledMark() == 0) {
|
||||
imReplyLists.remove(vo);
|
||||
continue;
|
||||
}
|
||||
//拼接账号和名称
|
||||
vo.setRealName(entity.getRealName());
|
||||
vo.setAccount(entity.getAccount());
|
||||
//头像路径拼接
|
||||
vo.setHeadIcon(UploaderUtil.uploaderImg(vo.getHeadIcon()));
|
||||
//获取未读消息
|
||||
vo.setUnreadMessage(imContentService.getUnreadCount(vo.getId(), UserProvider.getUser().getUserId()));
|
||||
if(vo.getSendDeleteMark()!=null && vo.getSendDeleteMark().equals(UserProvider.getUser().getUserId()) || vo.getDeleteMark()==1){
|
||||
vo.setLatestMessage("");
|
||||
vo.setMessageType("");
|
||||
}
|
||||
}
|
||||
//排序
|
||||
imReplyLists = imReplyLists.stream().sorted(Comparator.comparing(ImReplyListModel::getLatestDate).reversed()).collect(Collectors.toList());
|
||||
List<ImReplyListVo> imReplyListVoList = JsonUtil.getJsonToList(imReplyLists, ImReplyListVo.class);
|
||||
ListVO listVO = new ListVO();
|
||||
listVO.setList(imReplyListVoList);
|
||||
return ActionResult.success(listVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除聊天记录
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "删除聊天记录")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@DeleteMapping("/deleteChatRecord/{id}")
|
||||
public ActionResult deleteChatRecord(@PathVariable("id") String id){
|
||||
imContentService.deleteChatRecord(UserProvider.getUser().getUserId(),id);
|
||||
return ActionResult.success("");
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除会话列表
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "移除会话列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@DeleteMapping("/relocation/{id}")
|
||||
public ActionResult relocation(@PathVariable("id") String id){
|
||||
imReplyService.relocation(UserProvider.getUser().getUserId(),id);
|
||||
return ActionResult.success("");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,405 @@
|
||||
package com.yunzhupaas.message.controller;
|
||||
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.UserInfo;
|
||||
import com.yunzhupaas.base.entity.DictionaryDataEntity;
|
||||
import com.yunzhupaas.base.entity.SuperBaseEntity;
|
||||
import com.yunzhupaas.base.service.DictionaryDataService;
|
||||
import com.yunzhupaas.base.service.DictionaryTypeService;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.message.entity.MessageEntity;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.message.entity.MessageReceiveEntity;
|
||||
import com.yunzhupaas.message.model.NoticePagination;
|
||||
import com.yunzhupaas.message.service.MessageService;
|
||||
import com.yunzhupaas.message.model.message.*;
|
||||
import com.yunzhupaas.message.service.UserDeviceService;
|
||||
import com.yunzhupaas.message.util.unipush.UinPush;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.JsonUtilEx;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.UserProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 系统公告
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/09/27
|
||||
*/
|
||||
@Tag(name = "系统公告", description = "Message")
|
||||
@RestController
|
||||
@RequestMapping("/api/message")
|
||||
public class MessageController extends SuperController<MessageService, MessageEntity> {
|
||||
|
||||
@Autowired
|
||||
private MessageService messageService;
|
||||
@Autowired
|
||||
private UserService userApi;
|
||||
@Autowired
|
||||
private UinPush uinPush;
|
||||
@Autowired
|
||||
private UserDeviceService userDeviceService;
|
||||
@Autowired
|
||||
private DictionaryDataService dictionaryDataApi;
|
||||
@Autowired
|
||||
private DictionaryTypeService dictionaryTypeService;
|
||||
|
||||
/**
|
||||
* 列表(通知公告)
|
||||
*
|
||||
* @param pagination
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取系统公告列表(带分页)")
|
||||
@SaCheckPermission("system.notice")
|
||||
@PostMapping("/Notice/List")
|
||||
public ActionResult<PageListVO<MessageNoticeVO>> NoticeList(@RequestBody NoticePagination pagination) {
|
||||
messageService.updateEnabledMark();
|
||||
List<MessageEntity> list = messageService.getNoticeList(pagination);
|
||||
List<UserEntity> userList = userApi.getUserName(list.stream().map(MessageEntity::getCreatorUserId).collect(Collectors.toList()));
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
List<DictionaryDataEntity> noticeType = dictionaryDataApi.getListByTypeDataCode("NoticeType");
|
||||
List<MessageNoticeVO> voList = new ArrayList<>();
|
||||
// 判断是否过期
|
||||
list.forEach(t -> {
|
||||
MessageNoticeVO vo = JsonUtil.getJsonToBean(t, MessageNoticeVO.class);
|
||||
// 处理是否过期
|
||||
if (t.getExpirationTime() != null) {
|
||||
// 已发布的情况下
|
||||
if (t.getEnabledMark() == 1) {
|
||||
if (t.getExpirationTime().getTime() < System.currentTimeMillis()) {
|
||||
vo.setEnabledMark(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
DictionaryDataEntity dictionaryDataEntity = noticeType.stream().filter(notice -> notice.getEnCode().equals(t.getCategory())).findFirst().orElse(new DictionaryDataEntity());
|
||||
vo.setCategory(dictionaryDataEntity.getFullName());
|
||||
// 转换创建人、发布人
|
||||
UserEntity user = userList.stream().filter(ul -> ul.getId().equals(t.getCreatorUserId())).findFirst().orElse(null);
|
||||
vo.setCreatorUser(user != null ? user.getRealName() + "/" + user.getAccount() : "");
|
||||
if (t.getEnabledMark() != null && t.getEnabledMark() != 0) {
|
||||
UserEntity entity = userApi.getInfo(t.getLastModifyUserId());
|
||||
vo.setLastModifyUserId(entity != null ? entity.getRealName() + "/" + entity.getAccount() : "");
|
||||
vo.setReleaseTime(t.getLastModifyTime() != null ? t.getLastModifyTime().getTime() : null);
|
||||
vo.setReleaseUser(vo.getLastModifyUserId());
|
||||
}
|
||||
voList.add(vo);
|
||||
});
|
||||
return ActionResult.page(voList, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加系统公告
|
||||
*
|
||||
* @param noticeCrForm 实体对象
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "添加系统公告")
|
||||
@Parameters({
|
||||
@Parameter(name = "noticeCrForm", description = "新建系统公告模型", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.notice")
|
||||
@PostMapping("/Notice")
|
||||
public ActionResult create(@RequestBody @Valid NoticeCrForm noticeCrForm) {
|
||||
MessageEntity entity = JsonUtil.getJsonToBean(noticeCrForm, MessageEntity.class);
|
||||
if(entity != null && StringUtil.isNotEmpty(entity.getBodyText()) && (entity.getBodyText().contains("<") || entity.getBodyText().contains("&lt;"))){
|
||||
return ActionResult.fail(MsgCode.MSERR112.get());
|
||||
}
|
||||
messageService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改系统公告
|
||||
*
|
||||
* @param id 主键值
|
||||
* @param messageUpForm 实体对象
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "修改系统公告")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "messageUpForm", description = "修改系统公告模型", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.notice")
|
||||
@PutMapping("/Notice/{id}")
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid NoticeUpForm messageUpForm) {
|
||||
MessageEntity entity = JsonUtil.getJsonToBean(messageUpForm, MessageEntity.class);
|
||||
if(entity != null && StringUtil.isNotEmpty(entity.getBodyText()) && (entity.getBodyText().contains("<") || entity.getBodyText().contains("&lt;"))){
|
||||
return ActionResult.fail(MsgCode.MSERR112.get());
|
||||
}
|
||||
boolean flag = messageService.update(id, entity);
|
||||
if (flag == false) {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取/查看系统公告信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.notice")
|
||||
@GetMapping("/Notice/{id}")
|
||||
public ActionResult<NoticeInfoVO> Info(@PathVariable("id") String id) throws DataException {
|
||||
MessageEntity entity = messageService.getInfo(id);
|
||||
NoticeInfoVO vo = null;
|
||||
if (entity != null) {
|
||||
UserEntity info = userApi.getInfo(entity.getCreatorUserId());
|
||||
entity.setCreatorUserId(info != null ? info.getRealName() + "/" + info.getAccount() : "");
|
||||
vo = JsonUtilEx.getJsonToBeanEx(entity, NoticeInfoVO.class);
|
||||
vo.setReleaseUser(entity.getCreatorUserId());
|
||||
vo.setReleaseTime(entity.getLastModifyTime() != null ? entity.getLastModifyTime().getTime() : null);
|
||||
UserEntity userEntity = userApi.getInfo(entity.getLastModifyUserId());
|
||||
if (userEntity != null && StringUtil.isNotEmpty(userEntity.getId())) {
|
||||
String realName = userEntity.getRealName();
|
||||
String account = userEntity.getAccount();
|
||||
if (StringUtil.isNotEmpty(realName)) {
|
||||
vo.setReleaseUser(realName + "/" + account);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除系统公告")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.notice")
|
||||
@DeleteMapping("/Notice/{id}")
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
MessageEntity entity = messageService.getInfo(id);
|
||||
if (entity != null) {
|
||||
messageService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发布公告
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "发布系统公告")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.notice")
|
||||
@PutMapping("/Notice/{id}/Actions/Release")
|
||||
public ActionResult release(@PathVariable("id") String id) {
|
||||
MessageEntity entity = messageService.getInfo(id);
|
||||
if (entity != null) {
|
||||
List<String> userIds = null;
|
||||
if (StringUtil.isNotEmpty(entity.getToUserIds())) {
|
||||
userIds = Arrays.asList(entity.getToUserIds().split(","));
|
||||
} else {
|
||||
userIds = userApi.getListId();
|
||||
}
|
||||
List<String> userIdList = userApi.getUserIdList(userIds, null);
|
||||
if (messageService.sentNotice(userIdList, entity)) {
|
||||
/*if(userIdList != null && userIdList.size()>0) {
|
||||
for (String userId : userIdList) {
|
||||
List<String> cidList = userDeviceService.getCidList(userId);
|
||||
if(cidList != null && cidList.size()>0){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("type","1");
|
||||
jsonObject.put("id",entity.getId());
|
||||
jsonObject.put("title",entity.getTitle());
|
||||
String text = JSONObject.toJSONString(jsonObject);
|
||||
byte[] bytes = text.getBytes(StandardCharsets.UTF_8);
|
||||
text = Base64.getEncoder().encodeToString(bytes);
|
||||
uinPush.sendUniPush(cidList, entity.getTitle(), "你有一条公告消息", "1", text);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
return ActionResult.success(MsgCode.SU011.get());
|
||||
}
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA011.get());
|
||||
}
|
||||
//=======================================站内消息、消息中心=================================================
|
||||
|
||||
|
||||
/**
|
||||
* 获取消息中心列表
|
||||
*
|
||||
* @param pagination
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "列表(通知公告/系统消息/私信消息)")
|
||||
@GetMapping
|
||||
public ActionResult<PageListVO<MessageInfoVO>> messageList(PaginationMessage pagination) {
|
||||
List<MessageInfoVO> listVO = new ArrayList<>();
|
||||
List<MessageReceiveEntity> list = messageService.getMessageList3(pagination, pagination.getType(), null, pagination.getIsRead());
|
||||
List<UserEntity> userList = userApi.getUserName(list.stream().map(SuperBaseEntity.SuperCBaseEntity::getCreatorUserId).collect(Collectors.toList()));
|
||||
list.forEach(t -> {
|
||||
MessageInfoVO vo = JsonUtil.getJsonToBean(t, MessageInfoVO.class);
|
||||
UserEntity user = userList.stream().filter(ul -> ul.getId().equals(t.getCreatorUserId())).findFirst().orElse(null);
|
||||
if (user != null) {
|
||||
vo.setReleaseTime(t.getCreatorTime() != null ? t.getCreatorTime().getTime() : null);
|
||||
UserEntity entity = userApi.getInfo(t.getCreatorUserId());
|
||||
vo.setReleaseUser(entity != null ? entity.getRealName() + "/" + entity.getAccount() : "");
|
||||
vo.setCreatorUser(entity != null ? entity.getRealName() + "/" + entity.getAccount() : "");
|
||||
}
|
||||
listVO.add(vo);
|
||||
});
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(listVO, paginationVO);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 读取消息
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "读取消息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@GetMapping("/ReadInfo/{id}")
|
||||
public ActionResult<NoticeInfoVO> readInfo(@PathVariable("id") String id) throws DataException {
|
||||
MessageReceiveEntity receive = messageService.messageRead(id);
|
||||
if (receive != null) {
|
||||
UserEntity user = userApi.getInfo(receive.getCreatorUserId());
|
||||
receive.setCreatorUserId(user != null ? user.getRealName() + "/" + user.getAccount() : "");
|
||||
receive.setBodyText(receive.getBodyText());
|
||||
// if (entity.getType() == 2) {
|
||||
// entity.setBodyText(receive.getBodyText());
|
||||
// }
|
||||
}
|
||||
NoticeInfoVO vo = JsonUtil.getJsonToBean(receive, NoticeInfoVO.class);
|
||||
if (Objects.equals(receive.getType() , 1)) {
|
||||
try{
|
||||
MessageEntity jsonToBean = JsonUtil.getJsonToBean(receive.getBodyText(), MessageEntity.class);
|
||||
if (jsonToBean !=null) {
|
||||
vo.setCategory(jsonToBean.getCategory());
|
||||
vo.setCoverImage(jsonToBean.getCoverImage());
|
||||
vo.setExcerpt(jsonToBean.getExcerpt());
|
||||
vo.setExpirationTime(jsonToBean.getExpirationTime() != null ? jsonToBean.getExpirationTime().getTime() : null);
|
||||
vo.setFiles(jsonToBean.getFiles());
|
||||
vo.setBodyText(jsonToBean.getBodyText());
|
||||
if (jsonToBean.getId() != null) {
|
||||
MessageEntity info = messageService.getInfo(jsonToBean.getId());
|
||||
if (info != null) {
|
||||
vo.setCategory(info.getCategory());
|
||||
vo.setCoverImage(info.getCoverImage());
|
||||
vo.setExcerpt(info.getExcerpt());
|
||||
vo.setExpirationTime(info.getExpirationTime() != null ? info.getExpirationTime().getTime() : null);
|
||||
vo.setFiles(info.getFiles());
|
||||
vo.setBodyText(info.getBodyText());
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
vo.setBodyText(receive.getBodyText());
|
||||
}
|
||||
|
||||
}
|
||||
vo.setReleaseTime(receive.getCreatorTime() != null ? receive.getCreatorTime().getTime() : null);
|
||||
// UserEntity info = usersApi.getInfoById(receive.getCreatorUserId());
|
||||
vo.setReleaseUser(receive.getCreatorUserId());
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 全部已读
|
||||
*
|
||||
* @param pagination 分页模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "全部已读")
|
||||
@Parameters({
|
||||
@Parameter(name = "pagination", description = "分页模型", required = true)
|
||||
})
|
||||
@PostMapping("/Actions/ReadAll")
|
||||
public ActionResult allRead(@RequestBody PaginationMessage pagination) {
|
||||
List<MessageReceiveEntity> list = messageService.getMessageList3(pagination, pagination.getType(),null,pagination.getIsRead());
|
||||
if(list != null && list.size()>0) {
|
||||
List<String> idList = list.stream().map(SuperBaseEntity.SuperIBaseEntity::getId).collect(Collectors.toList());
|
||||
messageService.messageRead(idList);
|
||||
return ActionResult.success(MsgCode.SU005.get());
|
||||
}else {
|
||||
return ActionResult.fail(MsgCode.MSERR113.get());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* app端获取未读数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "app端获取未读数据")
|
||||
@GetMapping("/getUnReadMsgNum")
|
||||
public ActionResult getUnReadMsgNum() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
Integer unReadMsg = messageService.getUnreadCount(userInfo.getUserId(), 2);
|
||||
Integer unReadSchedule = messageService.getUnreadCount(userInfo.getUserId(),4);
|
||||
Integer unReadNotice = messageService.getUnreadCount(userInfo.getUserId(), 1);
|
||||
Integer unReadSystemMsg = messageService.getUnreadCount(userInfo.getUserId(), 3);
|
||||
Integer unReadNum = unReadMsg+unReadNotice+unReadSchedule+unReadSystemMsg;
|
||||
map.put("unReadMsg",unReadMsg.toString());
|
||||
map.put("unReadNotice",unReadNotice.toString());
|
||||
map.put("unReadSchedule",unReadSchedule.toString());
|
||||
map.put("unReadSystemMsg",unReadSystemMsg.toString());
|
||||
map.put("unReadNum",unReadNum.toString());
|
||||
return ActionResult.success(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录
|
||||
*
|
||||
* @param recordForm 已读模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除消息")
|
||||
@Parameters({
|
||||
@Parameter(name = "recordForm", description = "已读模型", required = true)
|
||||
})
|
||||
@DeleteMapping("/Record")
|
||||
public ActionResult deleteRecord(@RequestBody MessageRecordForm recordForm) {
|
||||
String[] id = recordForm.getIds().split(",");
|
||||
List<String> list = Arrays.asList(id);
|
||||
messageService.deleteRecord(list);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
package com.yunzhupaas.message.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.entity.DictionaryDataEntity;
|
||||
import com.yunzhupaas.base.service.DictionaryDataService;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.base.UserInfo;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.message.entity.MessageMonitorEntity;
|
||||
import com.yunzhupaas.message.model.messagemonitor.*;
|
||||
import com.yunzhupaas.message.service.MessageMonitorService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.yunzhupaas.util.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 消息监控
|
||||
*
|
||||
* @版本: V3.2.0
|
||||
* @版权: 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @作者: 云筑产品开发平台组
|
||||
* @日期: 2022-08-22
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Tag(name = "消息监控", description = "message")
|
||||
@RequestMapping("/api/message/MessageMonitor")
|
||||
public class MessageMonitorController extends SuperController<MessageMonitorService, MessageMonitorEntity> {
|
||||
|
||||
|
||||
@Autowired
|
||||
private MessageMonitorService messageMonitorService;
|
||||
@Autowired
|
||||
private DictionaryDataService dictionaryDataApi;
|
||||
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @param messageMonitorPagination 消息监控分页模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "列表")
|
||||
@SaCheckPermission("msgCenter.msgMonitor")
|
||||
@GetMapping
|
||||
public ActionResult<PageListVO<MessageMonitorListVO>> list(MessageMonitorPagination messageMonitorPagination) throws IOException {
|
||||
List<MessageMonitorEntity> list = messageMonitorService.getList(messageMonitorPagination);
|
||||
|
||||
List<DictionaryDataEntity> msgSendTypeList = dictionaryDataApi.getListByTypeDataCode("msgSendType");
|
||||
List<DictionaryDataEntity> msgSourceTypeList = dictionaryDataApi.getListByTypeDataCode("msgSourceType");
|
||||
|
||||
//处理id字段转名称,若无需转或者为空可删除
|
||||
List<MessageMonitorListVO> listVO = JsonUtil.getJsonToList(list, MessageMonitorListVO.class);
|
||||
for (MessageMonitorListVO messageMonitorVO : listVO) {
|
||||
//消息类型
|
||||
if (StringUtil.isNotEmpty(messageMonitorVO.getMessageType())) {
|
||||
msgSendTypeList.stream().filter(t -> messageMonitorVO.getMessageType().equals(t.getEnCode())).findFirst()
|
||||
.ifPresent(dataTypeEntity -> messageMonitorVO.setMessageType(dataTypeEntity.getFullName()));
|
||||
}
|
||||
//消息来源
|
||||
if (StringUtil.isNotEmpty(messageMonitorVO.getMessageSource())) {
|
||||
msgSourceTypeList.stream().filter(t -> messageMonitorVO.getMessageSource().equals(t.getEnCode())).findFirst()
|
||||
.ifPresent(dataTypeEntity -> messageMonitorVO.setMessageSource(dataTypeEntity.getFullName()));
|
||||
}
|
||||
//子表数据转换
|
||||
}
|
||||
|
||||
PageListVO vo = new PageListVO();
|
||||
vo.setList(listVO);
|
||||
PaginationVO page = JsonUtil.getJsonToBean(messageMonitorPagination, PaginationVO.class);
|
||||
vo.setPagination(page);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建
|
||||
*
|
||||
* @param messageMonitorForm 消息监控模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = ("创建"))
|
||||
@PostMapping
|
||||
@Parameters({
|
||||
@Parameter(name = "messageMonitorForm", description = "消息监控模型", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.msgMonitor")
|
||||
@Transactional
|
||||
public ActionResult create(@RequestBody @Valid MessageMonitorForm messageMonitorForm) throws DataException {
|
||||
String mainId = RandomUtil.uuId();
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
MessageMonitorEntity entity = JsonUtil.getJsonToBean(messageMonitorForm, MessageMonitorEntity.class);
|
||||
entity.setCreatorTime(DateUtil.getNowDate());
|
||||
entity.setCreatorUserId(userInfo.getUserId());
|
||||
entity.setId(mainId);
|
||||
messageMonitorService.save(entity);
|
||||
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param msgDelForm 消息删除模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = ("批量删除"))
|
||||
@DeleteMapping("/batchRemove")
|
||||
@Parameters({
|
||||
@Parameter(name = "msgDelForm", description = "消息删除模型", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.msgMonitor")
|
||||
@Transactional
|
||||
public ActionResult batchRemove(@RequestBody MsgDelForm msgDelForm) {
|
||||
boolean flag = messageMonitorService.delete(msgDelForm.getIds());
|
||||
if (flag == false) {
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 一键清空消息监控记录
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "一键清空消息监控记录")
|
||||
@SaCheckPermission("msgCenter.msgMonitor")
|
||||
@DeleteMapping("/empty")
|
||||
public ActionResult deleteHandelLog() {
|
||||
messageMonitorService.emptyMonitor();
|
||||
return ActionResult.success(MsgCode.SU005.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.msgMonitor")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<MessageMonitorInfoVO> info(@PathVariable("id") String id) {
|
||||
MessageMonitorEntity entity = messageMonitorService.getInfo(id);
|
||||
MessageMonitorInfoVO vo = JsonUtil.getJsonToBean(entity, MessageMonitorInfoVO.class);
|
||||
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单信息(详情页)
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "表单信息(详情页)")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.msgMonitor")
|
||||
@GetMapping("/detail/{id}")
|
||||
public ActionResult<MessageMonitorInfoVO> detailInfo(@PathVariable("id") String id) {
|
||||
MessageMonitorEntity entity = messageMonitorService.getInfo(id);
|
||||
|
||||
List<DictionaryDataEntity> msgSendTypeList = dictionaryDataApi.getListByTypeDataCode("msgSendType");
|
||||
List<DictionaryDataEntity> msgSourceTypeList = dictionaryDataApi.getListByTypeDataCode("msgSourceType");
|
||||
|
||||
MessageMonitorInfoVO vo = JsonUtil.getJsonToBean(entity, MessageMonitorInfoVO.class);
|
||||
if (StringUtil.isNotEmpty(vo.getMessageType())) {
|
||||
msgSendTypeList.stream().filter(t -> vo.getMessageType().equals(t.getEnCode())).findFirst()
|
||||
.ifPresent(dataTypeEntity -> vo.setMessageType(dataTypeEntity.getFullName()));
|
||||
}
|
||||
if (StringUtil.isNotEmpty(vo.getMessageSource())) {
|
||||
msgSourceTypeList.stream().filter(t -> vo.getMessageSource().equals(t.getEnCode())).findFirst()
|
||||
.ifPresent(dataTypeEntity -> vo.setMessageSource(dataTypeEntity.getFullName()));
|
||||
}
|
||||
if (!"webhook".equals(vo.getMessageType())) {
|
||||
vo.setReceiveUser(messageMonitorService.userSelectValues(vo.getReceiveUser()));
|
||||
}
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.msgMonitor")
|
||||
@Transactional
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
MessageMonitorEntity entity = messageMonitorService.getInfo(id);
|
||||
if (entity != null) {
|
||||
messageMonitorService.delete(entity);
|
||||
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,611 @@
|
||||
package com.yunzhupaas.message.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaMode;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.entity.DictionaryDataEntity;
|
||||
import com.yunzhupaas.base.service.BillRuleService;
|
||||
import com.yunzhupaas.base.service.DictionaryDataService;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.base.UserInfo;
|
||||
import com.yunzhupaas.base.vo.DownloadVO;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
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.model.messagetemplateconfig.MessageTemplateConfigForm;
|
||||
import com.yunzhupaas.message.model.messagetemplateconfig.MessageTemplateConfigInfoVO;
|
||||
import com.yunzhupaas.message.model.messagetemplateconfig.MessageTemplateConfigListVO;
|
||||
import com.yunzhupaas.message.model.messagetemplateconfig.MessageTemplateConfigPagination;
|
||||
import com.yunzhupaas.message.service.MessageTemplateConfigService;
|
||||
import com.yunzhupaas.message.service.SendConfigTemplateService;
|
||||
import com.yunzhupaas.message.service.SmsFieldService;
|
||||
import com.yunzhupaas.message.service.TemplateParamService;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.emnus.ModuleTypeEnum;
|
||||
import com.yunzhupaas.util.FileExport;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.yunzhupaas.util.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 消息模板(新)
|
||||
*
|
||||
* @版本: V3.2.0
|
||||
* @版权: 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @作者: 云筑产品开发平台组
|
||||
* @日期: 2022-08-18
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Tag(name = "消息模板(新)", description = "message")
|
||||
@RequestMapping("/api/message/MessageTemplateConfig")
|
||||
public class MessageTemplateConfigController extends SuperController<MessageTemplateConfigService, MessageTemplateConfigEntity> {
|
||||
|
||||
@Autowired
|
||||
private FileExport fileExport;
|
||||
|
||||
@Autowired
|
||||
private BillRuleService billRuleService;
|
||||
|
||||
@Autowired
|
||||
private ConfigValueUtil configValueUtil;
|
||||
|
||||
@Autowired
|
||||
private UserService userApi;
|
||||
|
||||
@Autowired
|
||||
private MessageTemplateConfigService messageTemplateConfigService;
|
||||
|
||||
@Autowired
|
||||
private TemplateParamService templateParamService;
|
||||
@Autowired
|
||||
private SmsFieldService smsFieldService;
|
||||
@Autowired
|
||||
private DictionaryDataService dictionaryDataApi;
|
||||
@Autowired
|
||||
private SendConfigTemplateService sendConfigTemplateService;
|
||||
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @param messageTemplateConfigPagination 消息模板分页模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "列表")
|
||||
@SaCheckPermission(value = {"msgCenter.msgTemplate", "msgCenter.accountConfig"}, mode = SaMode.OR)
|
||||
@GetMapping
|
||||
public ActionResult<PageListVO<MessageTemplateConfigListVO>> list(MessageTemplateConfigPagination messageTemplateConfigPagination) throws IOException {
|
||||
List<MessageTemplateConfigEntity> list = messageTemplateConfigService.getList(messageTemplateConfigPagination);
|
||||
List<DictionaryDataEntity> msgSendTypeList = dictionaryDataApi.getListByTypeDataCode("msgSendType");
|
||||
List<DictionaryDataEntity> msgSourceTypeList = dictionaryDataApi.getListByTypeDataCode("msgSourceType");
|
||||
//处理id字段转名称,若无需转或者为空可删除
|
||||
UserEntity userEntity = new UserEntity();
|
||||
List<MessageTemplateConfigListVO> listVO = JsonUtil.getJsonToList(list, MessageTemplateConfigListVO.class);
|
||||
for (MessageTemplateConfigListVO messageTemplateNewVO : listVO) {
|
||||
//消息类型
|
||||
if(StringUtil.isNotEmpty(messageTemplateNewVO.getMessageType())){
|
||||
msgSendTypeList.stream().filter(t -> messageTemplateNewVO.getMessageType().equals(t.getEnCode())).findFirst()
|
||||
.ifPresent(dataTypeEntity -> messageTemplateNewVO.setMessageType(dataTypeEntity.getFullName()));
|
||||
}
|
||||
//创建人员
|
||||
if(StringUtil.isNotBlank(messageTemplateNewVO.getCreatorUserId()) && !"null".equals(messageTemplateNewVO.getCreatorUserId())){
|
||||
userEntity = userApi.getInfo(messageTemplateNewVO.getCreatorUserId());
|
||||
if(userEntity != null){
|
||||
messageTemplateNewVO.setCreatorUser(userEntity.getRealName() +"/"+ userEntity.getAccount());
|
||||
}
|
||||
}
|
||||
//消息来源
|
||||
if(StringUtil.isNotEmpty(messageTemplateNewVO.getMessageSource())) {
|
||||
msgSourceTypeList.stream().filter(t -> messageTemplateNewVO.getMessageSource().equals(t.getEnCode())).findFirst()
|
||||
.ifPresent(dataTypeEntity -> messageTemplateNewVO.setMessageSource(dataTypeEntity.getFullName()));
|
||||
}
|
||||
}
|
||||
|
||||
PageListVO vo = new PageListVO();
|
||||
vo.setList(listVO);
|
||||
PaginationVO page = JsonUtil.getJsonToBean(messageTemplateConfigPagination, PaginationVO.class);
|
||||
vo.setPagination(page);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建
|
||||
*
|
||||
* @param messageTemplateConfigForm 消息模板页模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "创建")
|
||||
@Parameters({
|
||||
@Parameter(name = "messageTemplateConfigForm", description = "消息模板页模型", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.msgTemplate")
|
||||
@PostMapping
|
||||
@Transactional
|
||||
public ActionResult create(@RequestBody @Valid MessageTemplateConfigForm messageTemplateConfigForm) throws DataException {
|
||||
boolean b = messageTemplateConfigService.checkForm(messageTemplateConfigForm, 0,"");
|
||||
if (b) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
if(!"1".equals(messageTemplateConfigForm.getTemplateType())){
|
||||
if(messageTemplateConfigForm.getEnCode().contains("MBXT")){
|
||||
return ActionResult.fail(MsgCode.MSERR114.get());
|
||||
}
|
||||
}
|
||||
if (messageTemplateConfigForm.getSmsFieldList() != null && "7".equals(messageTemplateConfigForm.getMessageType())) {
|
||||
List<SmsFieldEntity> SmsFieldList = JsonUtil.getJsonToList(messageTemplateConfigForm.getSmsFieldList(), SmsFieldEntity.class);
|
||||
List<SmsFieldEntity> list = SmsFieldList.stream().filter(t->StringUtil.isNotEmpty(String.valueOf(t.getIsTitle())) &&!"null".equals(String.valueOf(t.getIsTitle())) && t.getIsTitle()==1).collect(Collectors.toList());
|
||||
if (list != null) {
|
||||
if(list.size() > 1) {
|
||||
return ActionResult.fail(MsgCode.MSERR115.get());
|
||||
}
|
||||
}else {
|
||||
return ActionResult.fail(MsgCode.MSERR116.get());
|
||||
}
|
||||
}
|
||||
String mainId = RandomUtil.uuId();
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
MessageTemplateConfigEntity entity = JsonUtil.getJsonToBean(messageTemplateConfigForm, MessageTemplateConfigEntity.class);
|
||||
entity.setCreatorTime(DateUtil.getNowDate());
|
||||
entity.setCreatorUserId(userInfo.getUserId());
|
||||
entity.setId(mainId);
|
||||
if("1".equals(entity.getMessageType()) && "2".equals(entity.getMessageSource())){
|
||||
entity.setContent(null);
|
||||
}
|
||||
messageTemplateConfigService.save(entity);
|
||||
if (messageTemplateConfigForm.getTemplateParamList() != null) {
|
||||
List<TemplateParamEntity> TemplateParamList = JsonUtil.getJsonToList(messageTemplateConfigForm.getTemplateParamList(), TemplateParamEntity.class);
|
||||
for (TemplateParamEntity entitys : TemplateParamList) {
|
||||
entitys.setId(RandomUtil.uuId());
|
||||
entitys.setTemplateId(entity.getId());
|
||||
templateParamService.save(entitys);
|
||||
}
|
||||
}
|
||||
if (messageTemplateConfigForm.getSmsFieldList() != null) {
|
||||
List<SmsFieldEntity> SmsFieldList = JsonUtil.getJsonToList(messageTemplateConfigForm.getSmsFieldList(), SmsFieldEntity.class);
|
||||
for (SmsFieldEntity entitys : SmsFieldList) {
|
||||
entitys.setId(RandomUtil.uuId());
|
||||
entitys.setTemplateId(entity.getId());
|
||||
smsFieldService.save(entitys);
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission(value = {"msgCenter.msgTemplate", "msgCenter.accountConfig"}, mode = SaMode.OR)
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<MessageTemplateConfigInfoVO> info(@PathVariable("id") String id) {
|
||||
MessageTemplateConfigEntity entity = messageTemplateConfigService.getInfo(id);
|
||||
MessageTemplateConfigInfoVO vo = JsonUtil.getJsonToBean(entity, MessageTemplateConfigInfoVO.class);
|
||||
//子表
|
||||
List<TemplateParamEntity> BaseTemplateParamList = messageTemplateConfigService.getTemplateParamList(id);
|
||||
// for (TemplateParamEntity basetemplateparamEntity : BaseTemplateParamList) {
|
||||
// }
|
||||
vo.setTemplateParamList(BaseTemplateParamList);
|
||||
List<SmsFieldEntity> BaseSmsFieldList = messageTemplateConfigService.getSmsFieldList(id);
|
||||
// for (SmsFieldEntity basesmsfieldEntity : BaseSmsFieldList) {
|
||||
// }
|
||||
vo.setSmsFieldList(BaseSmsFieldList);
|
||||
//副表
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单信息(详情页)
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "表单信息(详情页)")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.msgTemplate")
|
||||
@GetMapping("/detail/{id}")
|
||||
public ActionResult<MessageTemplateConfigInfoVO> detailInfo(@PathVariable("id") String id) {
|
||||
MessageTemplateConfigEntity entity = messageTemplateConfigService.getInfo(id);
|
||||
UserEntity userEntity = new UserEntity();
|
||||
MessageTemplateConfigInfoVO vo = JsonUtil.getJsonToBean(entity, MessageTemplateConfigInfoVO.class);
|
||||
|
||||
//子表数据转换
|
||||
List<TemplateParamEntity> BaseTemplateParamList = messageTemplateConfigService.getTemplateParamList(id);
|
||||
// for (TemplateParamEntity basetemplateparamEntity : BaseTemplateParamList) {
|
||||
// }
|
||||
vo.setTemplateParamList(BaseTemplateParamList);
|
||||
List<SmsFieldEntity> BaseSmsFieldList = messageTemplateConfigService.getSmsFieldList(id);
|
||||
// for (SmsFieldEntity basesmsfieldEntity : BaseSmsFieldList) {
|
||||
// }
|
||||
vo.setSmsFieldList(BaseSmsFieldList);
|
||||
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @param id 主键
|
||||
* @param messageTemplateConfigForm 消息模板页模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "更新")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "messageTemplateConfigForm", description = "消息模板页模型", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.msgTemplate")
|
||||
@PutMapping("/{id}")
|
||||
@Transactional
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid MessageTemplateConfigForm messageTemplateConfigForm) throws DataException {
|
||||
|
||||
boolean b = messageTemplateConfigService.checkForm(messageTemplateConfigForm, 0, messageTemplateConfigForm.getId());
|
||||
if (b) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
if(!"1".equals(messageTemplateConfigForm.getTemplateType())){
|
||||
if(messageTemplateConfigForm.getEnCode().contains("MBXT")){
|
||||
return ActionResult.fail(MsgCode.MSERR114.get());
|
||||
}
|
||||
}
|
||||
//判断配置是否被引用
|
||||
if("0".equals(String.valueOf(messageTemplateConfigForm.getEnabledMark()))){
|
||||
if(sendConfigTemplateService.isUsedTemplate(messageTemplateConfigForm.getId())) {
|
||||
return ActionResult.fail(MsgCode.FA049.get());
|
||||
}
|
||||
}
|
||||
if (messageTemplateConfigForm.getSmsFieldList() != null && "7".equals(messageTemplateConfigForm.getMessageType())) {
|
||||
List<SmsFieldEntity> SmsFieldList = JsonUtil.getJsonToList(messageTemplateConfigForm.getSmsFieldList(), SmsFieldEntity.class);
|
||||
List<SmsFieldEntity> list = SmsFieldList.stream().filter(t->StringUtil.isNotEmpty(String.valueOf(t.getIsTitle())) &&!"null".equals(String.valueOf(t.getIsTitle())) && t.getIsTitle()==1).collect(Collectors.toList());
|
||||
if (list != null) {
|
||||
if(list.size() > 1) {
|
||||
return ActionResult.fail(MsgCode.MSERR117.get());
|
||||
}
|
||||
}else {
|
||||
return ActionResult.fail(MsgCode.MSERR118.get());
|
||||
}
|
||||
}
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
MessageTemplateConfigEntity entity = messageTemplateConfigService.getInfo(id);
|
||||
if (entity != null) {
|
||||
MessageTemplateConfigEntity subentity = JsonUtil.getJsonToBean(messageTemplateConfigForm, MessageTemplateConfigEntity.class);
|
||||
subentity.setCreatorTime(entity.getCreatorTime());
|
||||
subentity.setCreatorUserId(entity.getCreatorUserId());
|
||||
subentity.setLastModifyTime(DateUtil.getNowDate());
|
||||
subentity.setLastModifyUserId(userInfo.getUserId());
|
||||
if("1".equals(subentity.getMessageType()) && "2".equals(subentity.getMessageSource())){
|
||||
subentity.setContent(null);
|
||||
}
|
||||
boolean b1 = messageTemplateConfigService.updateById(subentity);
|
||||
if (!b1) {
|
||||
return ActionResult.fail(MsgCode.VS405.get());
|
||||
}
|
||||
|
||||
//明细表数据更新
|
||||
List<TemplateParamEntity> addParamList = new ArrayList<>();
|
||||
List<TemplateParamEntity> updParamList = new ArrayList<>();
|
||||
List<TemplateParamEntity> delParamList = new ArrayList<>();
|
||||
if (messageTemplateConfigForm.getTemplateParamList() != null) {
|
||||
List<TemplateParamEntity> templateParamList = JsonUtil.getJsonToList(messageTemplateConfigForm.getTemplateParamList(), TemplateParamEntity.class);
|
||||
for (TemplateParamEntity entitys : templateParamList) {
|
||||
if (StringUtil.isNotBlank(entitys.getId()) && !"null".equals(entitys.getId())) {
|
||||
TemplateParamEntity paramEntity = templateParamService.getInfo(entitys.getId());
|
||||
if (paramEntity != null) {
|
||||
paramEntity.setId(entitys.getId());
|
||||
paramEntity.setTemplateId(entitys.getTemplateId());
|
||||
paramEntity.setField(entitys.getField());
|
||||
paramEntity.setFieldName(entitys.getFieldName());
|
||||
paramEntity.setCreatorUserId(entity.getCreatorUserId());
|
||||
paramEntity.setCreatorTime(entitys.getCreatorTime());
|
||||
paramEntity.setLastModifyUserId(userInfo.getUserId());
|
||||
paramEntity.setLastModifyTime(DateUtil.getNowDate());
|
||||
updParamList.add(paramEntity);
|
||||
}
|
||||
} else {
|
||||
entitys.setId(RandomUtil.uuId());
|
||||
entitys.setTemplateId(entity.getId());
|
||||
entitys.setCreatorUserId(userInfo.getUserId());
|
||||
entitys.setCreatorTime(DateUtil.getNowDate());
|
||||
addParamList.add(entitys);
|
||||
}
|
||||
}
|
||||
|
||||
//删除参数记录
|
||||
List<TemplateParamEntity> paramEntityList = templateParamService.getDetailListByParentId(entity.getId());
|
||||
if (paramEntityList != null) {
|
||||
for (TemplateParamEntity paramEntity : paramEntityList) {
|
||||
TemplateParamEntity paramEntity1 = templateParamList.stream().filter(t -> t.getId().equals(paramEntity.getId())).findFirst().orElse(null);
|
||||
if (paramEntity1 == null) {
|
||||
delParamList.add(paramEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (addParamList != null && addParamList.size() > 0) {
|
||||
templateParamService.saveBatch(addParamList);
|
||||
}
|
||||
if (updParamList != null && updParamList.size() > 0) {
|
||||
templateParamService.updateBatchById(updParamList);
|
||||
}
|
||||
if (delParamList != null && delParamList.size() > 0) {
|
||||
templateParamService.removeByIds(delParamList.stream().map(TemplateParamEntity::getId).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
//短信参数明细表数据更新
|
||||
List<SmsFieldEntity> addSmsList = new ArrayList<>();
|
||||
List<SmsFieldEntity> updSmsList = new ArrayList<>();
|
||||
List<SmsFieldEntity> delSmsList = new ArrayList<>();
|
||||
if (messageTemplateConfigForm.getSmsFieldList() != null) {
|
||||
List<SmsFieldEntity> smsFieldList = JsonUtil.getJsonToList(messageTemplateConfigForm.getSmsFieldList(), SmsFieldEntity.class);
|
||||
for (SmsFieldEntity entitys : smsFieldList) {
|
||||
if (StringUtil.isNotBlank(entitys.getId()) && !"null".equals(entitys.getId())) {
|
||||
SmsFieldEntity smsFieldEntity = smsFieldService.getInfo(entitys.getId());
|
||||
if (smsFieldEntity != null) {
|
||||
smsFieldEntity.setId(entitys.getId());
|
||||
smsFieldEntity.setTemplateId(entity.getId());
|
||||
smsFieldEntity.setFieldId(entitys.getFieldId());
|
||||
smsFieldEntity.setField(entitys.getField());
|
||||
smsFieldEntity.setSmsField(entitys.getSmsField());
|
||||
smsFieldEntity.setCreatorTime(entitys.getCreatorTime());
|
||||
smsFieldEntity.setCreatorUserId(entitys.getCreatorUserId());
|
||||
smsFieldEntity.setLastModifyTime(DateUtil.getNowDate());
|
||||
smsFieldEntity.setLastModifyUserId(userInfo.getUserId());
|
||||
smsFieldEntity.setIsTitle(entitys.getIsTitle());
|
||||
updSmsList.add(smsFieldEntity);
|
||||
}
|
||||
} else {
|
||||
entitys.setId(RandomUtil.uuId());
|
||||
entitys.setTemplateId(entity.getId());
|
||||
entitys.setCreatorTime(DateUtil.getNowDate());
|
||||
entitys.setCreatorUserId(userInfo.getUserId());
|
||||
addSmsList.add(entitys);
|
||||
}
|
||||
}
|
||||
//删除短信参数明细表
|
||||
List<SmsFieldEntity> smsFieldEntityList = smsFieldService.getDetailListByParentId(entity.getId());
|
||||
if (smsFieldEntityList != null && smsFieldEntityList.size() > 0) {
|
||||
for (SmsFieldEntity smsFieldEntity : smsFieldEntityList) {
|
||||
SmsFieldEntity smsFieldEntity1 = smsFieldList.stream().filter(t -> t.getId().equals(smsFieldEntity.getId())).findFirst().orElse(null);
|
||||
if (smsFieldEntity1 == null) {
|
||||
delSmsList.add(smsFieldEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (addSmsList != null && addSmsList.size() > 0) {
|
||||
smsFieldService.saveBatch(addSmsList);
|
||||
}
|
||||
if (updSmsList != null && updSmsList.size() > 0) {
|
||||
smsFieldService.updateBatchById(updSmsList);
|
||||
}
|
||||
if (delSmsList != null && delSmsList.size() > 0) {
|
||||
smsFieldService.removeByIds(delSmsList.stream().map(SmsFieldEntity::getId).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
} else {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "删除")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.msgTemplate")
|
||||
@DeleteMapping("/{id}")
|
||||
@Transactional
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
MessageTemplateConfigEntity entity = messageTemplateConfigService.getInfo(id);
|
||||
if (entity != null) {
|
||||
if(sendConfigTemplateService.isUsedTemplate(entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.FA050.get());
|
||||
}
|
||||
messageTemplateConfigService.delete(entity);
|
||||
QueryWrapper<TemplateParamEntity> queryWrapperTemplateParam = new QueryWrapper<>();
|
||||
queryWrapperTemplateParam.lambda().eq(TemplateParamEntity::getTemplateId, entity.getId());
|
||||
templateParamService.remove(queryWrapperTemplateParam);
|
||||
QueryWrapper<SmsFieldEntity> queryWrapperSmsField = new QueryWrapper<>();
|
||||
queryWrapperSmsField.lambda().eq(SmsFieldEntity::getTemplateId, entity.getId());
|
||||
smsFieldService.remove(queryWrapperSmsField);
|
||||
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启或禁用
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "开启或禁用")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.msgTemplate")
|
||||
@PostMapping("/unable/{id}")
|
||||
@Transactional
|
||||
public ActionResult unable(@PathVariable("id") String id) {
|
||||
MessageTemplateConfigEntity entity = messageTemplateConfigService.getInfo(id);
|
||||
if (entity != null) {
|
||||
if("1".equals(String.valueOf(entity.getEnabledMark()))){
|
||||
entity.setEnabledMark(0);
|
||||
return ActionResult.success(MsgCode.WF027.get());
|
||||
}else {
|
||||
//判断是否被引用
|
||||
|
||||
entity.setEnabledMark(1);
|
||||
return ActionResult.success(MsgCode.WF026.get());
|
||||
}
|
||||
}else {
|
||||
return ActionResult.fail(MsgCode.FA007.get());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "复制")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.msgTemplate")
|
||||
@PostMapping("/{id}/Actions/Copy")
|
||||
@Transactional
|
||||
public ActionResult copy(@PathVariable("id") String id) {
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
MessageTemplateConfigEntity entity = messageTemplateConfigService.getInfo(id);
|
||||
if (entity != null) {
|
||||
entity.setEnabledMark(0);
|
||||
String copyNum = UUID.randomUUID().toString().substring(0, 5);
|
||||
entity.setFullName(entity.getFullName()+".副本"+copyNum);
|
||||
entity.setEnCode(entity.getEnCode()+copyNum);
|
||||
entity.setCreatorTime(DateUtil.getNowDate());
|
||||
entity.setCreatorUserId(userInfo.getUserId());
|
||||
entity.setLastModifyTime(null);
|
||||
entity.setLastModifyUserId(null);
|
||||
entity.setTemplateType("0");
|
||||
entity.setId(RandomUtil.uuId());
|
||||
MessageTemplateConfigEntity copyEntity = JsonUtil.getJsonToBean(entity, MessageTemplateConfigEntity.class);
|
||||
if(copyEntity.getEnCode().length()>50 || copyEntity.getFullName().length()>50){
|
||||
return ActionResult.fail(MsgCode.PRI006.get());
|
||||
}
|
||||
messageTemplateConfigService.create(copyEntity);
|
||||
List<TemplateParamEntity> copyParamList = new ArrayList<>();
|
||||
List<TemplateParamEntity> baseParamList = templateParamService.getDetailListByParentId(id);
|
||||
if(baseParamList != null && baseParamList.size()>0){
|
||||
for(TemplateParamEntity entitys : baseParamList){
|
||||
entitys.setId(RandomUtil.uuId());
|
||||
entitys.setTemplateId(copyEntity.getId());
|
||||
entitys.setCreatorTime(DateUtil.getNowDate());
|
||||
entitys.setCreatorUserId(userInfo.getUserId());
|
||||
entitys.setLastModifyTime(null);
|
||||
entitys.setLastModifyUserId(null);
|
||||
copyParamList.add(entitys);
|
||||
}
|
||||
}
|
||||
if(copyParamList != null && copyParamList.size()>0) {
|
||||
templateParamService.saveBatch(copyParamList);
|
||||
}
|
||||
List<SmsFieldEntity> copySmsList = new ArrayList<>();
|
||||
List<SmsFieldEntity> baseSmsFieldList = smsFieldService.getDetailListByParentId(id);
|
||||
if(baseSmsFieldList != null && baseSmsFieldList.size()>0){
|
||||
for(SmsFieldEntity entitys : baseSmsFieldList){
|
||||
entitys.setId(RandomUtil.uuId());
|
||||
entitys.setTemplateId(copyEntity.getId());
|
||||
entitys.setCreatorTime(DateUtil.getNowDate());
|
||||
entitys.setCreatorUserId(userInfo.getUserId());
|
||||
entitys.setLastModifyTime(null);
|
||||
entitys.setLastModifyUserId(null);
|
||||
copySmsList.add(entitys);
|
||||
}
|
||||
}
|
||||
if(copySmsList != null && copySmsList.size()>0){
|
||||
smsFieldService.saveBatch(copySmsList);
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU007.get());
|
||||
}else {
|
||||
return ActionResult.fail(MsgCode.FA004.get());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出消息模板
|
||||
*
|
||||
* @param id 消息模板id
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "导出")
|
||||
@GetMapping("/{id}/Action/Export")
|
||||
public ActionResult export(@PathVariable String id) {
|
||||
MessageTemplateConfigEntity entity = messageTemplateConfigService.getInfo(id);
|
||||
MessageTemplateConfigInfoVO vo = JsonUtil.getJsonToBean(entity, MessageTemplateConfigInfoVO.class);
|
||||
//子表
|
||||
List<TemplateParamEntity> BaseTemplateParamList = messageTemplateConfigService.getTemplateParamList(id);
|
||||
vo.setTemplateParamList(BaseTemplateParamList);
|
||||
List<SmsFieldEntity> BaseSmsFieldList = messageTemplateConfigService.getSmsFieldList(id);
|
||||
vo.setSmsFieldList(BaseSmsFieldList);
|
||||
//导出文件
|
||||
DownloadVO downloadVO = fileExport.exportFile(vo, configValueUtil.getTemporaryFilePath(), entity.getFullName(), ModuleTypeEnum.MESSAGE_TEMPLATE.getTableName());
|
||||
return ActionResult.success(downloadVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入消息模板
|
||||
*
|
||||
* @param multipartFile 备份json文件
|
||||
* @return 执行结果标识
|
||||
*/
|
||||
@Operation(summary = "导入")
|
||||
@PostMapping(value = "/Action/Import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ActionResult importData(@RequestPart("file") MultipartFile multipartFile) throws DataException {
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
//判断是否为.json结尾
|
||||
if (FileUtil.existsSuffix(multipartFile, ModuleTypeEnum.MESSAGE_TEMPLATE.getTableName())) {
|
||||
return ActionResult.fail(MsgCode.IMP002.get());
|
||||
}
|
||||
//获取文件内容
|
||||
String fileContent = FileUtil.getFileContent(multipartFile);
|
||||
MessageTemplateConfigInfoVO infoVO = JsonUtil.getJsonToBean(fileContent, MessageTemplateConfigInfoVO.class);
|
||||
MessageTemplateConfigEntity entity = JsonUtil.getJsonToBean(infoVO, MessageTemplateConfigEntity.class);
|
||||
entity.setCreatorUserId(userInfo.getUserId());
|
||||
entity.setCreatorTime(DateUtil.getNowDate());
|
||||
//子表数据导入
|
||||
if (infoVO.getTemplateParamList() != null && infoVO.getTemplateParamList().size()>0) {
|
||||
List<TemplateParamEntity> templateParamList = JsonUtil.getJsonToList(infoVO.getTemplateParamList(), TemplateParamEntity.class);
|
||||
templateParamService.saveBatch(templateParamList);
|
||||
}
|
||||
if(infoVO.getSmsFieldList() != null && infoVO.getSmsFieldList().size()>0){
|
||||
List<SmsFieldEntity> smsFieldList = JsonUtil.getJsonToList(infoVO.getSmsFieldList(), SmsFieldEntity.class);
|
||||
smsFieldService.saveBatch(smsFieldList);
|
||||
}
|
||||
return messageTemplateConfigService.ImportData(entity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,779 @@
|
||||
package com.yunzhupaas.message.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.entity.DictionaryDataEntity;
|
||||
import com.yunzhupaas.base.entity.SysConfigEntity;
|
||||
import com.yunzhupaas.base.service.BillRuleService;
|
||||
import com.yunzhupaas.base.service.DictionaryDataService;
|
||||
import com.yunzhupaas.base.service.SysconfigService;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.base.UserInfo;
|
||||
import com.yunzhupaas.base.vo.DownloadVO;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.message.entity.*;
|
||||
import com.yunzhupaas.message.model.message.DingTalkModel;
|
||||
import com.yunzhupaas.message.model.messagetemplateconfig.TemplateParamModel;
|
||||
import com.yunzhupaas.message.model.sendmessageconfig.*;
|
||||
import com.yunzhupaas.message.service.*;
|
||||
import com.yunzhupaas.base.util.TestSendConfigUtil;
|
||||
import com.yunzhupaas.model.BaseSystemInfo;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.emnus.ModuleTypeEnum;
|
||||
import com.yunzhupaas.util.FileExport;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.yunzhupaas.util.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 消息发送配置
|
||||
*
|
||||
* @版本: V3.2.0
|
||||
* @版权: 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @作者: 云筑产品开发平台组
|
||||
* @日期: 2022-08-19
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Tag(name = "消息发送配置", description = "message")
|
||||
@RequestMapping("/api/message/SendMessageConfig")
|
||||
public class SendMessageConfigController extends SuperController<SendMessageConfigService, SendMessageConfigEntity> {
|
||||
@Autowired
|
||||
private FileExport fileExport;
|
||||
|
||||
@Autowired
|
||||
private BillRuleService billRuleService;
|
||||
|
||||
@Autowired
|
||||
private ConfigValueUtil configValueUtil;
|
||||
@Autowired
|
||||
private UserService userApi;
|
||||
|
||||
|
||||
|
||||
@Autowired
|
||||
private SysconfigService sysconfigService;
|
||||
@Autowired
|
||||
private SendMessageConfigService sendMessageConfigService;
|
||||
|
||||
@Autowired
|
||||
private SendConfigTemplateService sendConfigTemplateService;
|
||||
|
||||
@Autowired
|
||||
private AccountConfigService accountConfigService;
|
||||
|
||||
@Autowired
|
||||
private MessageTemplateConfigService messageTemplateConfigService;
|
||||
@Autowired
|
||||
private DictionaryDataService dictionaryDataApi;
|
||||
|
||||
@Autowired
|
||||
private TestSendConfigUtil testSendConfigUtil;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @param sendMessageConfigPagination 分页模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "消息发送配置列表")
|
||||
@SaCheckPermission("msgCenter.sendConfig")
|
||||
@GetMapping
|
||||
public ActionResult<PageListVO<SendMessageConfigListVO>> list(SendMessageConfigPagination sendMessageConfigPagination) throws IOException {
|
||||
List<SendMessageConfigEntity> list = sendMessageConfigService.getList(sendMessageConfigPagination, null);
|
||||
List<DictionaryDataEntity> msgSendTypeList = dictionaryDataApi.getListByTypeDataCode("msgSendType");
|
||||
List<DictionaryDataEntity> msgSourceTypeList = dictionaryDataApi.getListByTypeDataCode("msgSourceType");
|
||||
//处理id字段转名称,若无需转或者为空可删除
|
||||
UserEntity userEntity = new UserEntity();
|
||||
List<SendMessageConfigListVO> listVO = JsonUtil.getJsonToList(list, SendMessageConfigListVO.class);
|
||||
for (SendMessageConfigListVO sendMessageConfigVO : listVO) {
|
||||
List<Map<String,String>> mapList = new ArrayList<>();
|
||||
//子表数据转换
|
||||
List<SendConfigTemplateEntity> sendConfigTemplateList = sendConfigTemplateService.getDetailListByParentId(sendMessageConfigVO.getId());
|
||||
if (sendConfigTemplateList != null && sendConfigTemplateList.size()>0) {
|
||||
sendConfigTemplateList = sendConfigTemplateList.stream().sorted((a,b)->a.getMessageType().compareTo(b.getMessageType())).collect(Collectors.toList());
|
||||
List<String> typeList = sendConfigTemplateList.stream().map(t -> t.getMessageType()).distinct().collect(Collectors.toList());
|
||||
if (typeList != null && typeList.size()>0) {
|
||||
for(String type : typeList) {
|
||||
String messageType = "";
|
||||
Map<String,String> map = new HashMap<>();
|
||||
DictionaryDataEntity dataTypeEntity = msgSendTypeList.stream().filter(t -> t.getEnCode().equals(type)).findFirst().orElse(null);
|
||||
if (dataTypeEntity != null) {
|
||||
messageType = dataTypeEntity.getFullName();
|
||||
map.put("fullName",messageType);
|
||||
map.put("type",type);
|
||||
mapList.add(map);
|
||||
}
|
||||
}
|
||||
sendMessageConfigVO.setMessageType(mapList);
|
||||
}
|
||||
}
|
||||
if(StringUtil.isNotEmpty(sendMessageConfigVO.getCreatorUserId())){
|
||||
userEntity = userApi.getInfo(sendMessageConfigVO.getCreatorUserId());
|
||||
if(userEntity != null){
|
||||
sendMessageConfigVO.setCreatorUser(userEntity.getRealName() +"/"+ userEntity.getAccount());
|
||||
}
|
||||
}
|
||||
//消息来源
|
||||
if(StringUtil.isNotBlank(sendMessageConfigVO.getMessageSource())) {
|
||||
msgSourceTypeList.stream().filter(t -> sendMessageConfigVO.getMessageSource().equals(t.getEnCode())).findFirst()
|
||||
.ifPresent(dataTypeEntity -> sendMessageConfigVO.setMessageSource(dataTypeEntity.getFullName()));
|
||||
}
|
||||
}
|
||||
|
||||
PageListVO vo = new PageListVO();
|
||||
vo.setList(listVO);
|
||||
PaginationVO page = JsonUtil.getJsonToBean(sendMessageConfigPagination, PaginationVO.class);
|
||||
vo.setPagination(page);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取发送配置下拉框
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取发送配置下拉框")
|
||||
@GetMapping("/Selector")
|
||||
public ActionResult<PageListVO<SendMessageConfigListVO>> selector(SendMessageConfigPagination sendMessageConfigPagination) {
|
||||
List<SendMessageConfigEntity> list = sendMessageConfigService.getSelectorList(sendMessageConfigPagination);
|
||||
List<SendMessageConfigListVO> listVO = JsonUtil.getJsonToList(list, SendMessageConfigListVO.class);
|
||||
PageListVO vo = new PageListVO();
|
||||
vo.setList(listVO);
|
||||
PaginationVO page = JsonUtil.getJsonToBean(sendMessageConfigPagination, PaginationVO.class);
|
||||
vo.setPagination(page);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息发送配置弹窗列表
|
||||
*
|
||||
* @param sendMessageConfigPagination 分页模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "消息发送配置弹窗列表")
|
||||
@GetMapping("/getSendConfigList")
|
||||
public ActionResult<PageListVO<SendConfigListVO>> getSendConfigList(SendMessageConfigPagination sendMessageConfigPagination) throws IOException {
|
||||
if(StringUtil.isBlank(sendMessageConfigPagination.getEnabledMark())) {
|
||||
sendMessageConfigPagination.setEnabledMark("1");
|
||||
}
|
||||
if(StringUtil.isBlank(sendMessageConfigPagination.getTemplateType())){
|
||||
sendMessageConfigPagination.setTemplateType("0");
|
||||
}
|
||||
List<SendMessageConfigEntity> list = sendMessageConfigService.getList(sendMessageConfigPagination, null);
|
||||
//处理id字段转名称,若无需转或者为空可删除
|
||||
List<DictionaryDataEntity> msgSendTypeList = dictionaryDataApi.getListByTypeDataCode("msgSendType");
|
||||
List<SendConfigListVO> listVO = JsonUtil.getJsonToList(list, SendConfigListVO.class);
|
||||
for (SendConfigListVO sendConfigVO : listVO) {
|
||||
//子表数据转换
|
||||
List<SendConfigTemplateEntity> sendConfigTemplateList = sendConfigTemplateService.getDetailListByParentId(sendConfigVO.getId());
|
||||
sendConfigTemplateList = sendConfigTemplateList.stream().filter(t->"1".equals(String.valueOf(t.getEnabledMark()))).collect(Collectors.toList());
|
||||
List<SendConfigTemplateModel> modelList = JsonUtil.getJsonToList(sendConfigTemplateList, SendConfigTemplateModel.class);
|
||||
for(SendConfigTemplateModel model:modelList) {
|
||||
if (modelList != null && modelList.size() > 0) {
|
||||
List<TemplateParamModel> list1 = messageTemplateConfigService.getParamJson(model.getTemplateId());
|
||||
// if (list != null && list.size() > 0) {
|
||||
// model.setParamJson(JsonUtil.getObjectToString(list1));
|
||||
// }
|
||||
List<MsgTemplateJsonModel> jsonModels = new ArrayList<>();
|
||||
for(TemplateParamModel paramModel : list1){
|
||||
MsgTemplateJsonModel jsonModel = new MsgTemplateJsonModel();
|
||||
jsonModel.setField(paramModel.getField());
|
||||
jsonModel.setFieldName(paramModel.getFieldName());
|
||||
jsonModel.setMsgTemplateId(model.getId());
|
||||
jsonModels.add(jsonModel);
|
||||
}
|
||||
model.setParamJson(jsonModels);
|
||||
MessageTemplateConfigEntity msgTemEntity = messageTemplateConfigService.getInfo(model.getTemplateId());
|
||||
if (msgTemEntity != null) {
|
||||
model.setMsgTemplateName(msgTemEntity.getFullName());
|
||||
}
|
||||
if (StringUtil.isNotEmpty(model.getMessageType())) {
|
||||
msgSendTypeList.stream().filter(t -> model.getMessageType().equals(t.getEnCode())).findFirst()
|
||||
.ifPresent(dataTypeEntity -> model.setMessageType(dataTypeEntity.getFullName()));
|
||||
}
|
||||
}
|
||||
sendConfigVO.setTemplateJson(modelList);
|
||||
}
|
||||
}
|
||||
|
||||
PageListVO vo = new PageListVO();
|
||||
vo.setList(listVO);
|
||||
PaginationVO page = JsonUtil.getJsonToBean(sendMessageConfigPagination, PaginationVO.class);
|
||||
vo.setPagination(page);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建
|
||||
*
|
||||
* @param sendMessageConfigForm 发送消息配置模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "创建")
|
||||
@Parameters({
|
||||
@Parameter(name = "sendMessageConfigForm", description = "发送消息配置模型", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.sendConfig")
|
||||
@PostMapping
|
||||
@Transactional
|
||||
public ActionResult create(@RequestBody @Valid SendMessageConfigForm sendMessageConfigForm) throws DataException {
|
||||
boolean b = sendMessageConfigService.checkForm(sendMessageConfigForm, 0,"");
|
||||
if (b) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
if(!"1".equals(sendMessageConfigForm.getTemplateType())){
|
||||
if(sendMessageConfigForm.getEnCode().contains("PZXT")){
|
||||
return ActionResult.fail(MsgCode.MSERR114.get());
|
||||
}
|
||||
}
|
||||
String mainId = RandomUtil.uuId();
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
SendMessageConfigEntity entity = JsonUtil.getJsonToBean(sendMessageConfigForm, SendMessageConfigEntity.class);
|
||||
entity.setCreatorUserId(userInfo.getUserId());
|
||||
entity.setCreatorTime(DateUtil.getNowDate());
|
||||
entity.setId(mainId);
|
||||
|
||||
if (sendMessageConfigForm.getSendConfigTemplateList() != null) {
|
||||
List<SendConfigTemplateEntity> SendConfigTemplateList = JsonUtil.getJsonToList(sendMessageConfigForm.getSendConfigTemplateList(), SendConfigTemplateEntity.class);
|
||||
long dd = SendConfigTemplateList.stream().filter(t->t.getMessageType().equals("4")).count();
|
||||
long qy = SendConfigTemplateList.stream().filter(t->t.getMessageType().equals("5")).count();
|
||||
boolean isQy = true;
|
||||
boolean isDd = true;
|
||||
Map<String, String> objModel = getSysConfig();
|
||||
if(qy > 0){
|
||||
BaseSystemInfo baseSystemInfo = JsonUtil.getJsonToBean(objModel, BaseSystemInfo.class);
|
||||
// 企业号id
|
||||
String corpId = baseSystemInfo.getQyhCorpId();
|
||||
// 应用凭证
|
||||
String agentId = baseSystemInfo.getQyhAgentId();
|
||||
// 凭证密钥
|
||||
String agentSecret = baseSystemInfo.getQyhAgentSecret();
|
||||
// 同步密钥
|
||||
String corpSecret = baseSystemInfo.getQyhCorpSecret();
|
||||
if(StringUtil.isNotEmpty(corpId) && StringUtil.isNotEmpty(agentId) && StringUtil.isNotEmpty(corpSecret) && StringUtil.isNotEmpty(agentSecret)){
|
||||
isQy = true;
|
||||
}else {
|
||||
isQy = false;
|
||||
}
|
||||
}
|
||||
if(dd > 0){
|
||||
DingTalkModel dingTalkModel = JsonUtil.getJsonToBean(objModel, DingTalkModel.class);
|
||||
// 钉钉企业号Id
|
||||
String dingAgentId = dingTalkModel.getDingAgentId();
|
||||
// 应用凭证
|
||||
String dingSynAppKey = dingTalkModel.getDingSynAppKey();
|
||||
// 凭证密钥
|
||||
String dingSynAppSecret = dingTalkModel.getDingSynAppSecret();
|
||||
if(StringUtil.isNotEmpty(dingSynAppKey) && StringUtil.isNotEmpty(dingSynAppSecret) && StringUtil.isNotEmpty(dingAgentId)){
|
||||
isDd = true;
|
||||
}else {
|
||||
isDd = false;
|
||||
}
|
||||
}
|
||||
if(!isQy){
|
||||
return ActionResult.fail(MsgCode.MSERR120.get());
|
||||
}
|
||||
if(!isDd){
|
||||
return ActionResult.fail(MsgCode.MSERR119.get());
|
||||
}
|
||||
for (SendConfigTemplateEntity entitys : SendConfigTemplateList) {
|
||||
entitys.setId(RandomUtil.uuId());
|
||||
entitys.setSendConfigId(entity.getId());
|
||||
sendConfigTemplateService.save(entitys);
|
||||
}
|
||||
}
|
||||
sendMessageConfigService.save(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<SendMessageConfigInfoVO> info(@PathVariable("id") String id) {
|
||||
SendMessageConfigEntity entity = sendMessageConfigService.getInfo(id);
|
||||
SendMessageConfigInfoVO vo = JsonUtil.getJsonToBean(entity, SendMessageConfigInfoVO.class);
|
||||
List<DictionaryDataEntity> msgSourceTypeList = dictionaryDataApi.getListByTypeDataCode("msgSourceType");
|
||||
if (StringUtil.isNotEmpty(vo.getMessageSource())) {
|
||||
msgSourceTypeList.stream().filter(t -> vo.getMessageSource().equals(t.getEnCode())).findFirst()
|
||||
.ifPresent(dataTypeEntity -> vo.setMessageSourceName(dataTypeEntity.getFullName()));
|
||||
}
|
||||
//子表
|
||||
List<SendConfigTemplateEntity> sendConfigTemplateList = sendMessageConfigService.getSendConfigTemplateList(id);
|
||||
for (SendConfigTemplateEntity sendconfigtemplateEntity : sendConfigTemplateList) {
|
||||
AccountConfigEntity accountConfigEntity = accountConfigService.getInfo(sendconfigtemplateEntity.getAccountConfigId());
|
||||
if(accountConfigEntity != null){
|
||||
sendconfigtemplateEntity.setAccountCode(accountConfigEntity.getEnCode());
|
||||
sendconfigtemplateEntity.setAccountName(accountConfigEntity.getFullName());
|
||||
}
|
||||
MessageTemplateConfigEntity messageTemplateConfigEntity = messageTemplateConfigService.getInfo(sendconfigtemplateEntity.getTemplateId());
|
||||
if(messageTemplateConfigEntity != null){
|
||||
sendconfigtemplateEntity.setTemplateCode(messageTemplateConfigEntity.getEnCode());
|
||||
sendconfigtemplateEntity.setTemplateName(messageTemplateConfigEntity.getFullName());
|
||||
}
|
||||
}
|
||||
vo.setSendConfigTemplateList(sendConfigTemplateList);
|
||||
//副表
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据编码获取信息
|
||||
*
|
||||
* @param enCode 编码
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "根据编码获取信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "enCode", description = "编码", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.sendConfig")
|
||||
@GetMapping("/getInfoByEnCode/{enCode}")
|
||||
public ActionResult<SendMessageConfigInfoVO> getInfo(@PathVariable("enCode") String enCode) {
|
||||
SendMessageConfigEntity entity = sendMessageConfigService.getInfoByEnCode(enCode);
|
||||
SendMessageConfigInfoVO vo = JsonUtil.getJsonToBean(entity, SendMessageConfigInfoVO.class);
|
||||
//子表
|
||||
List<SendConfigTemplateEntity> sendConfigTemplateList = sendMessageConfigService.getSendConfigTemplateList(entity.getId());
|
||||
for (SendConfigTemplateEntity sendconfigtemplateEntity : sendConfigTemplateList) {
|
||||
AccountConfigEntity accountConfigEntity = accountConfigService.getInfo(sendconfigtemplateEntity.getAccountConfigId());
|
||||
if(accountConfigEntity != null){
|
||||
sendconfigtemplateEntity.setAccountCode(accountConfigEntity.getEnCode());
|
||||
sendconfigtemplateEntity.setAccountName(accountConfigEntity.getFullName());
|
||||
}
|
||||
MessageTemplateConfigEntity messageTemplateConfigEntity = messageTemplateConfigService.getInfo(sendconfigtemplateEntity.getTemplateId());
|
||||
if(messageTemplateConfigEntity != null){
|
||||
sendconfigtemplateEntity.setTemplateCode(messageTemplateConfigEntity.getEnCode());
|
||||
sendconfigtemplateEntity.setTemplateName(messageTemplateConfigEntity.getFullName());
|
||||
}
|
||||
}
|
||||
vo.setSendConfigTemplateList(sendConfigTemplateList);
|
||||
//副表
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单信息(详情页)
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "表单信息(详情页)")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.sendConfig")
|
||||
@GetMapping("/detail/{id}")
|
||||
public ActionResult<SendMessageConfigInfoVO> detailInfo(@PathVariable("id") String id) {
|
||||
SendMessageConfigEntity entity = sendMessageConfigService.getInfo(id);
|
||||
SendMessageConfigInfoVO vo = JsonUtil.getJsonToBean(entity, SendMessageConfigInfoVO.class);
|
||||
|
||||
//子表数据转换
|
||||
List<SendConfigTemplateEntity> sendConfigTemplateList = sendMessageConfigService.getSendConfigTemplateList(id);
|
||||
for(SendConfigTemplateEntity sendconfigtemplateEntity : sendConfigTemplateList){
|
||||
AccountConfigEntity accountConfigEntity = accountConfigService.getInfo(sendconfigtemplateEntity.getAccountConfigId());
|
||||
if(accountConfigEntity != null){
|
||||
sendconfigtemplateEntity.setAccountCode(accountConfigEntity.getEnCode());
|
||||
sendconfigtemplateEntity.setAccountName(accountConfigEntity.getFullName());
|
||||
}
|
||||
MessageTemplateConfigEntity messageTemplateConfigEntity = messageTemplateConfigService.getInfo(sendconfigtemplateEntity.getTemplateId());
|
||||
if(messageTemplateConfigEntity != null){
|
||||
sendconfigtemplateEntity.setTemplateCode(messageTemplateConfigEntity.getEnCode());
|
||||
sendconfigtemplateEntity.setTemplateName(messageTemplateConfigEntity.getFullName());
|
||||
}
|
||||
}
|
||||
vo.setSendConfigTemplateList(sendConfigTemplateList);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @param id 主键
|
||||
* @param sendMessageConfigForm 发送信息配置模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "更新")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "sendMessageConfigForm", description = "发送信息配置模型", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.sendConfig")
|
||||
@PutMapping("/{id}")
|
||||
@Transactional
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid SendMessageConfigForm sendMessageConfigForm) throws DataException {
|
||||
|
||||
boolean b = sendMessageConfigService.checkForm(sendMessageConfigForm, 0,sendMessageConfigForm.getId());
|
||||
if (b) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
if("0".equals(sendMessageConfigForm.getEnabledMark())){
|
||||
if(sendMessageConfigService.idUsed(id)){
|
||||
return ActionResult.fail(MsgCode.FA049.get());
|
||||
}
|
||||
}
|
||||
if(!"1".equals(sendMessageConfigForm.getTemplateType())){
|
||||
if(sendMessageConfigForm.getEnCode().contains("PZXT")){
|
||||
return ActionResult.fail(MsgCode.MSERR114.get());
|
||||
}
|
||||
}
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
SendMessageConfigEntity entity = sendMessageConfigService.getInfo(id);
|
||||
if (entity != null) {
|
||||
SendMessageConfigEntity subentity = JsonUtil.getJsonToBean(sendMessageConfigForm, SendMessageConfigEntity.class);
|
||||
subentity.setCreatorUserId(entity.getCreatorUserId());
|
||||
subentity.setCreatorTime(entity.getCreatorTime());
|
||||
subentity.setLastModifyUserId(userInfo.getUserId());
|
||||
subentity.setLastModifyTime(DateUtil.getNowDate());
|
||||
|
||||
//明细表数据更新
|
||||
List<SendConfigTemplateEntity> addTemplateList = new ArrayList<>();
|
||||
List<SendConfigTemplateEntity> updTemplateList = new ArrayList<>();
|
||||
List<SendConfigTemplateEntity> delTemplateList = new ArrayList<>();
|
||||
if (sendMessageConfigForm.getSendConfigTemplateList() != null) {
|
||||
List<SendConfigTemplateEntity> sendConfigTemplateEntityList = JsonUtil.getJsonToList(sendMessageConfigForm.getSendConfigTemplateList(), SendConfigTemplateEntity.class);
|
||||
long dd = sendConfigTemplateEntityList.stream().filter(t->t.getMessageType().equals("4")).count();
|
||||
long qy = sendConfigTemplateEntityList.stream().filter(t->t.getMessageType().equals("5")).count();
|
||||
boolean isQy = true;
|
||||
boolean isDd = true;
|
||||
Map<String, String> objModel = getSysConfig();
|
||||
if(qy > 0){
|
||||
BaseSystemInfo baseSystemInfo = JsonUtil.getJsonToBean(objModel, BaseSystemInfo.class);
|
||||
// 企业号id
|
||||
String corpId = baseSystemInfo.getQyhCorpId();
|
||||
// 应用凭证
|
||||
String agentId = baseSystemInfo.getQyhAgentId();
|
||||
// 凭证密钥
|
||||
String agentSecret = baseSystemInfo.getQyhAgentSecret();
|
||||
// 同步密钥
|
||||
String corpSecret = baseSystemInfo.getQyhCorpSecret();
|
||||
if(StringUtil.isNotEmpty(corpId) && StringUtil.isNotEmpty(agentId) && StringUtil.isNotEmpty(corpSecret) && StringUtil.isNotEmpty(agentSecret)){
|
||||
isQy = true;
|
||||
}else {
|
||||
isQy = false;
|
||||
}
|
||||
}
|
||||
if(dd > 0){
|
||||
DingTalkModel dingTalkModel = JsonUtil.getJsonToBean(objModel, DingTalkModel.class);
|
||||
// 钉钉企业号Id
|
||||
String dingAgentId = dingTalkModel.getDingAgentId();
|
||||
// 应用凭证
|
||||
String dingSynAppKey = dingTalkModel.getDingSynAppKey();
|
||||
// 凭证密钥
|
||||
String dingSynAppSecret = dingTalkModel.getDingSynAppSecret();
|
||||
if(StringUtil.isNotEmpty(dingSynAppKey) && StringUtil.isNotEmpty(dingSynAppSecret) && StringUtil.isNotEmpty(dingAgentId)){
|
||||
isDd = true;
|
||||
}else {
|
||||
isDd = false;
|
||||
}
|
||||
}
|
||||
if(!isQy){
|
||||
return ActionResult.fail(MsgCode.MSERR120.get());
|
||||
}
|
||||
if(!isDd){
|
||||
return ActionResult.fail(MsgCode.MSERR119.get());
|
||||
}
|
||||
for (SendConfigTemplateEntity entitys : sendConfigTemplateEntityList) {
|
||||
SendConfigTemplateEntity templateEntity = StringUtil.isNotEmpty(entitys.getId())?sendConfigTemplateService.getInfo(entitys.getId()):null;
|
||||
if(templateEntity != null){
|
||||
templateEntity.setSendConfigId(entity.getId());
|
||||
templateEntity.setId(entitys.getId());
|
||||
templateEntity.setEnabledMark(entitys.getEnabledMark());
|
||||
templateEntity.setCreatorTime(entitys.getCreatorTime());
|
||||
templateEntity.setCreatorUserId(entitys.getCreatorUserId());
|
||||
templateEntity.setDescription(entitys.getDescription());
|
||||
templateEntity.setAccountConfigId(entitys.getAccountConfigId());
|
||||
templateEntity.setSortCode(entitys.getSortCode());
|
||||
templateEntity.setLastModifyTime(DateUtil.getNowDate());
|
||||
templateEntity.setLastModifyUserId(userInfo.getUserId());
|
||||
templateEntity.setTemplateId(entitys.getTemplateId());
|
||||
updTemplateList.add(templateEntity);
|
||||
}else {
|
||||
entitys.setId(RandomUtil.uuId());
|
||||
entitys.setSendConfigId(entity.getId());
|
||||
entitys.setCreatorUserId(userInfo.getUserId());
|
||||
entitys.setCreatorTime(DateUtil.getNowDate());
|
||||
addTemplateList.add(entitys);
|
||||
}
|
||||
}
|
||||
//删除参数记录
|
||||
List<SendConfigTemplateEntity> paramEntityList = sendConfigTemplateService.getDetailListByParentId(entity.getId());
|
||||
if (paramEntityList != null) {
|
||||
for (SendConfigTemplateEntity templateEntity : paramEntityList) {
|
||||
SendConfigTemplateEntity templateEntity1 = sendConfigTemplateEntityList.stream().filter(t -> t.getId().equals(templateEntity.getId())).findFirst().orElse(null);
|
||||
if (templateEntity1 == null) {
|
||||
delTemplateList.add(templateEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (addTemplateList != null && addTemplateList.size() > 0) {
|
||||
sendConfigTemplateService.saveBatch(addTemplateList);
|
||||
}
|
||||
if (updTemplateList != null && updTemplateList.size() > 0) {
|
||||
sendConfigTemplateService.updateBatchById(updTemplateList);
|
||||
}
|
||||
if (delTemplateList != null && delTemplateList.size() > 0) {
|
||||
sendConfigTemplateService.removeByIds(delTemplateList.stream().map(SendConfigTemplateEntity::getId).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
boolean b1 = sendMessageConfigService.updateById(subentity);
|
||||
if (!b1) {
|
||||
return ActionResult.fail(MsgCode.VS405.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
} else {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.sendConfig")
|
||||
@DeleteMapping("/{id}")
|
||||
@Transactional
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
SendMessageConfigEntity entity = sendMessageConfigService.getInfo(id);
|
||||
if (entity != null) {
|
||||
if(sendMessageConfigService.idUsed(id)){
|
||||
return ActionResult.fail(MsgCode.FA050.get());
|
||||
}
|
||||
sendMessageConfigService.delete(entity);
|
||||
QueryWrapper<SendConfigTemplateEntity> queryWrapperSendConfigTemplate = new QueryWrapper<>();
|
||||
queryWrapperSendConfigTemplate.lambda().eq(SendConfigTemplateEntity::getSendConfigId, entity.getId());
|
||||
sendConfigTemplateService.remove(queryWrapperSendConfigTemplate);
|
||||
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取消息发送配置
|
||||
*
|
||||
* @param id 发送配置id
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取消息发送配置")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.sendConfig")
|
||||
@PostMapping("/getTestConfig/{id}")
|
||||
@Transactional
|
||||
public ActionResult getTestConfig(@PathVariable("id") String id){
|
||||
List<SendConfigTemplateEntity> configTemplateList = sendConfigTemplateService.getConfigTemplateListByConfigId(id);
|
||||
List<DictionaryDataEntity> msgSendTypeList = dictionaryDataApi.getListByTypeDataCode("msgSendType");
|
||||
if(configTemplateList != null && configTemplateList.size()>0){
|
||||
List<SendConfigTemplateModel> modelList = JsonUtil.getJsonToList(configTemplateList, SendConfigTemplateModel.class);
|
||||
for(SendConfigTemplateModel model:modelList){
|
||||
List<TemplateParamModel> list = messageTemplateConfigService.getParamJson(model.getTemplateId());
|
||||
if(list!=null && list.size()>0){
|
||||
model.setParamJson(list);
|
||||
}
|
||||
MessageTemplateConfigEntity msgTemEntity = messageTemplateConfigService.getInfo(model.getTemplateId());
|
||||
if(msgTemEntity != null){
|
||||
model.setMsgTemplateName(msgTemEntity.getFullName());
|
||||
}
|
||||
if(StringUtil.isNotEmpty(model.getMessageType())){
|
||||
msgSendTypeList.stream().filter(t -> model.getMessageType().equals(t.getEnCode())).findFirst()
|
||||
.ifPresent(dataTypeEntity -> model.setMessageType(dataTypeEntity.getFullName()));
|
||||
}
|
||||
}
|
||||
return ActionResult.success(modelList);
|
||||
}else {
|
||||
return ActionResult.fail(MsgCode.MSERR121.get());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试消息发送配置
|
||||
*
|
||||
* @param modelList 发送配置
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "测试消息发送配置")
|
||||
@Parameters({
|
||||
@Parameter(name = "modelList", description = "发送配置", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.sendConfig")
|
||||
@PostMapping("/testSendConfig")
|
||||
@Transactional
|
||||
public ActionResult testSendConfig(@RequestBody @Valid List<SendConfigTemplateModel> modelList) throws NoSuchAlgorithmException, InvalidKeyException {
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
List<SendConfigTestResultModel> resultList = new ArrayList<>();
|
||||
List<DictionaryDataEntity> msgSendTypeList = dictionaryDataApi.getListByTypeDataCode("msgSendType");
|
||||
if(modelList != null && modelList.size()>0){
|
||||
for(SendConfigTemplateModel model: modelList){
|
||||
SendConfigTestResultModel resultModel = new SendConfigTestResultModel();
|
||||
String result = testSendConfigUtil.sendMessage(model,userInfo);
|
||||
MessageTemplateConfigEntity msgTemEntity = messageTemplateConfigService.getInfo(model.getTemplateId());
|
||||
if(msgTemEntity != null) {
|
||||
msgSendTypeList.stream().filter(t -> msgTemEntity.getMessageType().equals(t.getEnCode())).findFirst()
|
||||
.ifPresent(dataTypeEntity -> resultModel.setMessageType("消息类型:" + dataTypeEntity.getFullName()));
|
||||
resultModel.setResult(result);
|
||||
if (result != null) {
|
||||
resultModel.setIsSuccess("0");
|
||||
} else {
|
||||
resultModel.setIsSuccess("1");
|
||||
}
|
||||
}
|
||||
resultList.add(resultModel);
|
||||
}
|
||||
}
|
||||
return ActionResult.success(resultList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "复制")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgCenter.sendConfig")
|
||||
@PostMapping("/{id}/Actions/Copy")
|
||||
@Transactional
|
||||
public ActionResult copy(@PathVariable("id") String id) {
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
SendMessageConfigEntity entity = sendMessageConfigService.getInfo(id);
|
||||
if (entity != null) {
|
||||
entity.setEnabledMark(0);
|
||||
String copyNum = UUID.randomUUID().toString().substring(0, 5);
|
||||
entity.setFullName(entity.getFullName()+".副本"+copyNum);
|
||||
entity.setEnCode(entity.getEnCode()+copyNum);
|
||||
entity.setCreatorTime(DateUtil.getNowDate());
|
||||
entity.setCreatorUserId(userInfo.getUserId());
|
||||
entity.setLastModifyTime(null);
|
||||
entity.setLastModifyUserId(null);
|
||||
entity.setTemplateType("0");
|
||||
entity.setId(RandomUtil.uuId());
|
||||
SendMessageConfigEntity copyEntity = JsonUtil.getJsonToBean(entity, SendMessageConfigEntity.class);
|
||||
if(copyEntity.getEnCode().length()>50 || copyEntity.getFullName().length()>50){
|
||||
return ActionResult.fail(MsgCode.PRI006.get());
|
||||
}
|
||||
sendMessageConfigService.create(copyEntity);
|
||||
List<SendConfigTemplateEntity> copyConfigTemplateList = new ArrayList<>();
|
||||
List<SendConfigTemplateEntity> configTemplateList = sendConfigTemplateService.getDetailListByParentId(id);
|
||||
if(configTemplateList != null && configTemplateList.size()>0){
|
||||
for(SendConfigTemplateEntity entitys : configTemplateList){
|
||||
entitys.setId(RandomUtil.uuId());
|
||||
entitys.setSendConfigId(copyEntity.getId());
|
||||
entitys.setCreatorTime(DateUtil.getNowDate());
|
||||
entitys.setCreatorUserId(userInfo.getUserId());
|
||||
entitys.setLastModifyTime(null);
|
||||
entitys.setLastModifyUserId(null);
|
||||
copyConfigTemplateList.add(entitys);
|
||||
}
|
||||
}
|
||||
if(copyConfigTemplateList != null && copyConfigTemplateList.size()>0) {
|
||||
sendConfigTemplateService.saveBatch(copyConfigTemplateList);
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU007.get());
|
||||
}else {
|
||||
return ActionResult.fail(MsgCode.FA004.get());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出消息发送配置
|
||||
*
|
||||
* @param id 账号配置id
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "导出")
|
||||
@GetMapping("/{id}/Action/Export")
|
||||
public ActionResult export(@PathVariable String id) {
|
||||
SendMessageConfigEntity entity = sendMessageConfigService.getInfo(id);
|
||||
SendMessageConfigInfoVO vo = JsonUtil.getJsonToBean(entity, SendMessageConfigInfoVO.class);
|
||||
|
||||
//子表数据
|
||||
List<SendConfigTemplateEntity> sendConfigTemplateList = sendMessageConfigService.getSendConfigTemplateList(id);
|
||||
vo.setSendConfigTemplateList(sendConfigTemplateList);
|
||||
//导出文件
|
||||
DownloadVO downloadVO = fileExport.exportFile(vo, configValueUtil.getTemporaryFilePath(), entity.getFullName(), ModuleTypeEnum.MESSAGE_SEND_CONFIG.getTableName());
|
||||
return ActionResult.success(downloadVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入账号配置
|
||||
*
|
||||
* @param multipartFile 备份json文件
|
||||
* @return 执行结果标识
|
||||
*/
|
||||
@Operation(summary = "导入")
|
||||
@PostMapping(value = "/Action/Import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ActionResult importData(@RequestPart("file") MultipartFile multipartFile) throws DataException {
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
//判断是否为.json结尾
|
||||
if (FileUtil.existsSuffix(multipartFile, ModuleTypeEnum.MESSAGE_SEND_CONFIG.getTableName())) {
|
||||
return ActionResult.fail(MsgCode.IMP002.get());
|
||||
}
|
||||
//获取文件内容
|
||||
String fileContent = FileUtil.getFileContent(multipartFile);
|
||||
SendMessageConfigInfoVO infoVO = JsonUtil.getJsonToBean(fileContent, SendMessageConfigInfoVO.class);
|
||||
SendMessageConfigEntity entity = JsonUtil.getJsonToBean(infoVO, SendMessageConfigEntity.class);
|
||||
entity.setCreatorUserId(userInfo.getUserId());
|
||||
entity.setCreatorTime(DateUtil.getNowDate());
|
||||
if (infoVO.getSendConfigTemplateList() != null) {
|
||||
List<SendConfigTemplateEntity> sendConfigTemplateList = JsonUtil.getJsonToList(infoVO.getSendConfigTemplateList(), SendConfigTemplateEntity.class);
|
||||
sendConfigTemplateService.saveBatch(sendConfigTemplateList);
|
||||
}
|
||||
return sendMessageConfigService.ImportData(entity);
|
||||
}
|
||||
|
||||
|
||||
public Map<String, String> getSysConfig() {
|
||||
Map<String, String> objModel = new HashMap<>();
|
||||
List<SysConfigEntity> configList = sysconfigService.getList("SysConfig");
|
||||
for (SysConfigEntity entity : configList) {
|
||||
objModel.put(entity.getFkey(), entity.getValue());
|
||||
}
|
||||
return objModel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
package com.yunzhupaas.message.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.consts.DeviceType;
|
||||
import com.yunzhupaas.database.util.TenantDataSourceUtil;
|
||||
import com.yunzhupaas.exception.LoginException;
|
||||
import com.yunzhupaas.message.entity.ShortLinkEntity;
|
||||
import com.yunzhupaas.message.service.ShortLinkService;
|
||||
import com.yunzhupaas.util.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Tag(name = "短链接跳转", description = "message")
|
||||
@RequestMapping("/api/message/ShortLink")
|
||||
public class ShortLinkController extends SuperController<ShortLinkService, ShortLinkEntity> {
|
||||
@Autowired
|
||||
private ShortLinkService shortLinkService;
|
||||
@Autowired
|
||||
private ConfigValueUtil configValueUtil;
|
||||
@Autowired
|
||||
protected AuthUtil authUtil;
|
||||
|
||||
|
||||
/**
|
||||
* 消息发送配置弹窗列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@NoDataSourceBind
|
||||
@Operation(summary = "根据短链接获取实际链接地址")
|
||||
@Parameters({
|
||||
@Parameter(name = "shortLink", description = "短链接", required = true),
|
||||
@Parameter(name = "tenant", description = "租户")
|
||||
})
|
||||
@GetMapping(value = {"/{shortLink}/{tenant}", "/{shortLink}"})
|
||||
public ActionResult getShortUrl(@PathVariable("shortLink") String shortLink, @PathVariable(value = "tenant", required = false) String tenant, HttpServletResponse response) throws LoginException, IOException {
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
if (StringUtil.isNotEmpty(tenant)) {
|
||||
//切换成租户库
|
||||
TenantDataSourceUtil.switchTenant(tenant);
|
||||
} else {
|
||||
return ActionResult.fail(MsgCode.LOG115.get());
|
||||
}
|
||||
}
|
||||
String link = new String();
|
||||
ShortLinkEntity entity = shortLinkService.getInfoByLink(shortLink);
|
||||
String frontDomain = configValueUtil.getFrontDomain();
|
||||
String appDomain = configValueUtil.getAppDomain();
|
||||
String realPcLink = entity.getRealPcLink();
|
||||
String realAppLink = entity.getRealAppLink();
|
||||
if (!realPcLink.contains("http")) {
|
||||
realPcLink = frontDomain + realPcLink;
|
||||
}
|
||||
if (!realAppLink.contains("http")) {
|
||||
realAppLink = appDomain + realAppLink;
|
||||
}
|
||||
DeviceType type = UserProvider.getDeviceForAgent();
|
||||
if (entity != null) {
|
||||
// String encode = "";
|
||||
String token = authUtil.loginTempUser(entity.getUserId(), tenant);
|
||||
if (StringUtil.isEmpty(token)) {
|
||||
return ActionResult.fail(MsgCode.AD104.get());
|
||||
}
|
||||
|
||||
if (entity.getIsUsed() == 1) {
|
||||
if (entity.getClickNum() < entity.getUnableNum() && entity.getUnableTime().after(DateUtil.getNowDate())) {
|
||||
if (DeviceType.PC.equals(type)) {
|
||||
link = realPcLink + "&token=" + token;
|
||||
entity.setClickNum(entity.getClickNum() + 1);
|
||||
shortLinkService.updateById(entity);
|
||||
} else {
|
||||
link = realAppLink + "&token=" + token;
|
||||
entity.setClickNum(entity.getClickNum() + 1);
|
||||
shortLinkService.updateById(entity);
|
||||
}
|
||||
} else {
|
||||
return ActionResult.fail(MsgCode.FA039.get());
|
||||
}
|
||||
} else {
|
||||
if (entity.getUnableTime().after(DateUtil.getNowDate())) {
|
||||
if (DeviceType.PC.equals(type)) {
|
||||
link = realPcLink + "&token=" + token;
|
||||
entity.setClickNum(entity.getClickNum() + 1);
|
||||
shortLinkService.updateById(entity);
|
||||
} else {
|
||||
link = realAppLink + "&token=" + token;
|
||||
entity.setClickNum(entity.getClickNum() + 1);
|
||||
shortLinkService.updateById(entity);
|
||||
}
|
||||
} else {
|
||||
return ActionResult.fail(MsgCode.FA039.get());
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
return ActionResult.fail(MsgCode.FA039.get());
|
||||
}
|
||||
response.sendRedirect(link);
|
||||
return ActionResult.success("");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,262 @@
|
||||
package com.yunzhupaas.message.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import com.yunzhupaas.base.entity.SysConfigEntity;
|
||||
import com.yunzhupaas.base.service.SysconfigService;
|
||||
import com.yunzhupaas.message.entity.AccountConfigEntity;
|
||||
import com.yunzhupaas.message.entity.WechatUserEntity;
|
||||
import com.yunzhupaas.message.service.AccountConfigService;
|
||||
import com.yunzhupaas.message.service.WechatUserService;
|
||||
import com.yunzhupaas.message.util.weixingzh.WXGZHWebChatUtil;
|
||||
import com.yunzhupaas.message.util.weixingzh.aes.WXBizMsgCrypt;
|
||||
import com.yunzhupaas.permission.entity.SocialsUserEntity;
|
||||
import com.yunzhupaas.permission.service.SocialsUserService;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.util.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 发送消息模型
|
||||
*/
|
||||
@Tag(name = "微信公众号事件接收", description = "WechatOpen")
|
||||
@Controller
|
||||
@RequestMapping("/api/message/WechatOpen")
|
||||
@Slf4j
|
||||
public class WxGZHFunctionController {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private SysconfigService sysconfigService;
|
||||
@Autowired
|
||||
private AccountConfigService accountConfigService;
|
||||
@Autowired
|
||||
private SocialsUserService socialsUserService;
|
||||
@Autowired
|
||||
private WechatUserService wechatUserService;
|
||||
|
||||
/**
|
||||
* 服务器基本配置链接微信公众号验证
|
||||
*
|
||||
* @param request 请求对象
|
||||
* @param response 响应对象
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "服务器基本配置链接微信公众号验证")
|
||||
@ResponseBody
|
||||
@Parameters({
|
||||
@Parameter(name = "enCode", description = "微信公众号账号配置编码", required = true)
|
||||
})
|
||||
@GetMapping("/token/{enCode}")
|
||||
public String token(@PathVariable("enCode") String enCode, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
//获取微信公众号账号配置
|
||||
AccountConfigEntity accountConfigEntity = accountConfigService.getInfoByEnCode(enCode,"7");
|
||||
if(ObjectUtil.isEmpty(accountConfigEntity)){
|
||||
log.info("未找到与编码相对应的微信公众号配置");
|
||||
return "";
|
||||
}
|
||||
//微信公众号服务器配置token
|
||||
String wxToken = accountConfigEntity.getAgentId();
|
||||
String signature = request.getParameter("signature");
|
||||
String echostr = XSSEscape.escape(request.getParameter("echostr"));
|
||||
String timestamp = request.getParameter("timestamp");
|
||||
String nonce = request.getParameter("nonce");
|
||||
|
||||
String sortStr = WXGZHWebChatUtil.sort(wxToken,timestamp,nonce);
|
||||
String mySinStr = WXGZHWebChatUtil.shal(sortStr);
|
||||
if(StringUtil.isNotBlank(signature) && mySinStr.equals(signature)){
|
||||
return echostr;
|
||||
}else {
|
||||
log.info("微信公众号链接失败");
|
||||
return echostr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 微信公众号事件请求
|
||||
*
|
||||
* @param request 请求对象
|
||||
* @param response 响应对象
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@Operation(summary = "微信公众号事件请求")
|
||||
@ResponseBody
|
||||
@PostMapping("/token/{enCode}")
|
||||
/**
|
||||
* 微信公众号事件请求
|
||||
*/
|
||||
public String tokenPost(@PathVariable("enCode") String enCode,HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
log.info("微信公众号请求事件");
|
||||
//获取微信公众号账号配置
|
||||
AccountConfigEntity accountConfigEntity = accountConfigService.getInfoByEnCode(enCode,"7");
|
||||
if(ObjectUtil.isEmpty(accountConfigEntity)){
|
||||
log.info("未找到与编码相对应的微信公众号配置");
|
||||
return "";
|
||||
}
|
||||
//微信公众号服务器配置token
|
||||
String wxToken = accountConfigEntity.getAgentId();
|
||||
//微信公众号服务器配置EncodingAesKey
|
||||
String encodingAesKey = accountConfigEntity.getBearer();
|
||||
//微信公众号AppId
|
||||
String wxAppId = accountConfigEntity.getAppId();
|
||||
|
||||
// 获取系统配置
|
||||
String msgSignature = request.getParameter("msg_signature");
|
||||
String encrypt_type = request.getParameter("encrypt_type");
|
||||
String signature = request.getParameter("signature");
|
||||
String echostr = XSSEscape.escape(request.getParameter("echostr"));
|
||||
String timestamp = request.getParameter("timestamp");
|
||||
String nonce = request.getParameter("nonce");
|
||||
|
||||
String sortStr = WXGZHWebChatUtil.sort(wxToken,timestamp,nonce);
|
||||
String mySinStr = WXGZHWebChatUtil.shal(sortStr);
|
||||
//验签
|
||||
if(StringUtil.isNotBlank(signature) && mySinStr.equals(signature)){
|
||||
//事件信息
|
||||
Map<String ,String> map = WXGZHWebChatUtil.parseXml(request);
|
||||
//事件信息
|
||||
String Event = map.get("Event");
|
||||
String openid = map.get("FromUserName");
|
||||
//公众号原始id
|
||||
String gzhId = map.get("ToUserName");
|
||||
if("aes".equals(encrypt_type)) {
|
||||
WXBizMsgCrypt pc = new WXBizMsgCrypt(wxToken, encodingAesKey, wxAppId);
|
||||
String encrypt = map.get("Encrypt");
|
||||
String format = "<xml><ToUserName><![CDATA[toUser]]></ToUserName><Encrypt><![CDATA[%1$s]]></Encrypt></xml>";
|
||||
String fromXML = String.format(format, encrypt);
|
||||
// 获取解密后消息明文
|
||||
String result = pc.decryptMsg(msgSignature, timestamp, nonce, fromXML);
|
||||
|
||||
Map<String, String> resultMap = new HashMap<>();
|
||||
resultMap = WXGZHWebChatUtil.xmlToMap(result);
|
||||
// 获取解密后事件信息
|
||||
Event = resultMap.get("Event");
|
||||
openid = resultMap.get("FromUserName");
|
||||
gzhId = resultMap.get("ToUserName");
|
||||
}
|
||||
|
||||
String appId = accountConfigEntity.getAppId();
|
||||
String appsecret = accountConfigEntity.getAppSecret();
|
||||
String token = WXGZHWebChatUtil.getAccessToken(appId,appsecret);
|
||||
if("subscribe".equals(Event)){
|
||||
//用户关注事件
|
||||
if(StringUtil.isNotBlank(token)){
|
||||
JSONObject rstObj = WXGZHWebChatUtil.getUsetInfo(token,openid);
|
||||
if(rstObj.containsKey("unionid")){
|
||||
String unionid = rstObj.getString("unionid");
|
||||
SocialsUserEntity socialsUserEntity = socialsUserService.getInfoBySocialId(unionid,"wechat_open");
|
||||
if(socialsUserEntity==null){
|
||||
log.info("微信公众号未绑定系统账号,请登录小程序绑定");
|
||||
return "";
|
||||
}else{
|
||||
WechatUserEntity wechatUserEntity = wechatUserService.getInfoByGzhId(socialsUserEntity.getUserId(),gzhId);
|
||||
if(wechatUserEntity==null){
|
||||
WechatUserEntity entity = new WechatUserEntity();
|
||||
entity.setId(RandomUtil.uuId());
|
||||
entity.setUserId(socialsUserEntity.getUserId());
|
||||
entity.setGzhId(gzhId);
|
||||
entity.setCloseMark(1);
|
||||
entity.setCreatorTime(DateUtil.getNowDate());
|
||||
entity.setOpenId(openid);
|
||||
wechatUserService.create(entity);
|
||||
return "";
|
||||
}else {
|
||||
if(wechatUserEntity.getCloseMark()==0){
|
||||
wechatUserEntity.setCloseMark(1);
|
||||
}
|
||||
wechatUserEntity.setOpenId(openid);
|
||||
wechatUserEntity.setLastModifyTime(DateUtil.getNowDate());
|
||||
wechatUserService.update(wechatUserEntity.getId(),wechatUserEntity);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}else{
|
||||
log.info("微信公众号未绑定系统账号,请登录小程序绑定");
|
||||
return "";
|
||||
}
|
||||
}else{
|
||||
log.error("微信公众号token错误,请查看配置");
|
||||
return "";
|
||||
}
|
||||
}else if("unsubscribe".equals(Event)){
|
||||
//用户取消关注事件
|
||||
if(StringUtil.isNotBlank(token)){
|
||||
JSONObject rstObj = WXGZHWebChatUtil.getUsetInfo(token,openid);
|
||||
if(rstObj.containsKey("unionid")){
|
||||
String unionid = rstObj.getString("unionid");
|
||||
SocialsUserEntity socialsUserEntity = socialsUserService.getInfoBySocialId(unionid,"wechat_open");
|
||||
if(socialsUserEntity==null){
|
||||
log.info("微信公众号未绑定系统账号,请登录小程序绑定");
|
||||
}else{
|
||||
WechatUserEntity wechatUserEntity = wechatUserService.getInfoByGzhId(socialsUserEntity.getUserId(),gzhId);
|
||||
if(wechatUserEntity==null){
|
||||
WechatUserEntity entity = new WechatUserEntity();
|
||||
entity.setId(RandomUtil.uuId());
|
||||
entity.setUserId(socialsUserEntity.getUserId());
|
||||
entity.setGzhId(gzhId);
|
||||
entity.setCloseMark(0);
|
||||
entity.setCreatorTime(DateUtil.getNowDate());
|
||||
entity.setOpenId(openid);
|
||||
wechatUserService.create(entity);
|
||||
return "";
|
||||
}else {
|
||||
if(wechatUserEntity.getCloseMark()==1){
|
||||
wechatUserEntity.setCloseMark(0);
|
||||
}
|
||||
wechatUserEntity.setOpenId(openid);
|
||||
wechatUserEntity.setLastModifyTime(DateUtil.getNowDate());
|
||||
wechatUserService.update(wechatUserEntity.getId(),wechatUserEntity);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}else{
|
||||
log.info("微信公众号未绑定系统账号,请登录小程序绑定");
|
||||
return "";
|
||||
}
|
||||
}else{
|
||||
log.error("微信公众号token错误,请查看配置");
|
||||
return "";
|
||||
}
|
||||
return "";
|
||||
}else {
|
||||
return "";
|
||||
}
|
||||
}else {
|
||||
log.info("微信公众号事件请求失败");
|
||||
return echostr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统配置
|
||||
*/
|
||||
private Map<String, String> getSystemConfig() {
|
||||
// 获取系统配置
|
||||
List<SysConfigEntity> configList = sysconfigService.getList("SysConfig");
|
||||
Map<String, String> objModel = new HashMap<>(16);
|
||||
for (SysConfigEntity entity : configList) {
|
||||
objModel.put(entity.getFkey(), entity.getValue());
|
||||
}
|
||||
return objModel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,477 @@
|
||||
package com.yunzhupaas.message.websocket;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.yunzhupaas.base.PageModel;
|
||||
import com.yunzhupaas.base.UserInfo;
|
||||
import com.yunzhupaas.base.service.SysconfigService;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.database.util.TenantDataSourceUtil;
|
||||
import com.yunzhupaas.message.entity.MessageReceiveEntity;
|
||||
import com.yunzhupaas.message.service.UserDeviceService;
|
||||
import com.yunzhupaas.message.util.*;
|
||||
import com.yunzhupaas.message.util.unipush.UinPush;
|
||||
import com.yunzhupaas.message.entity.ImContentEntity;
|
||||
import com.yunzhupaas.message.entity.MessageEntity;
|
||||
import com.yunzhupaas.message.model.message.PaginationMessage;
|
||||
import com.yunzhupaas.message.model.websocket.onconnettion.OnConnectionModel;
|
||||
import com.yunzhupaas.message.model.websocket.onconnettion.OnLineModel;
|
||||
import com.yunzhupaas.message.model.websocket.receivemessage.ReceiveMessageModel;
|
||||
import com.yunzhupaas.message.model.websocket.savafile.ImageMessageModel;
|
||||
import com.yunzhupaas.message.model.websocket.savafile.VoiceMessageModel;
|
||||
import com.yunzhupaas.message.model.websocket.savamessage.SavaMessageModel;
|
||||
import com.yunzhupaas.message.service.ImContentService;
|
||||
import com.yunzhupaas.message.service.MessageService;
|
||||
import com.yunzhupaas.message.model.ImUnreadNumModel;
|
||||
import com.yunzhupaas.model.BaseSystemInfo;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.util.*;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.context.SpringContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import jakarta.websocket.*;
|
||||
import jakarta.websocket.server.PathParam;
|
||||
import jakarta.websocket.server.ServerEndpoint;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 消息聊天
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024-09-26 上午9:18
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@ServerEndpoint(value = "/api/message/websocket/{token}")
|
||||
@Scope("prototype")
|
||||
public class WebSocket {
|
||||
|
||||
private ImContentService imContentService;
|
||||
private MessageService messageService;
|
||||
private ConfigValueUtil configValueUtil;
|
||||
private UserInfo userInfo;
|
||||
private UserService userApi;
|
||||
private SysconfigService sysConfigApi;
|
||||
private UinPush uinPush;
|
||||
private UserDeviceService userDeviceService;
|
||||
|
||||
|
||||
/**
|
||||
* 连接建立成功调用的方法
|
||||
*/
|
||||
@OnOpen
|
||||
public void onOpen(Session session, @PathParam("token") String token) {
|
||||
this.init();
|
||||
this.userInfo = UserProvider.getUser(token);
|
||||
if (this.userInfo.getUserId() == null) {
|
||||
try{
|
||||
OnlineUserProvider.closeFrontWs(null, session);
|
||||
session.close();
|
||||
}catch (Exception e){}
|
||||
log.info("WS建立链接, TOKEN无效:{}, {}", session.getId(), token);
|
||||
}else {
|
||||
log.info("WS建立链接:{}, {}", session.getId(), token);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接关闭调用的方法
|
||||
*/
|
||||
@OnClose
|
||||
public void onClose(Session session) {
|
||||
OnlineUserModel user = OnlineUserProvider.getOnlineUserList().stream().filter(t -> t.getConnectionId().equals(session.getId())).findFirst().orElse(null);
|
||||
if (user != null) {
|
||||
OnlineUserProvider.removeWebSocketByToken(user.getToken());
|
||||
log.info("WS连接断开: {}, {}, {}, {}", user.getTenantId(), user.getUserId(), session.getId(), user.getToken());
|
||||
}else{
|
||||
log.debug("WS连接断开, 无用户信息: {}", session.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 收到客户端消息后调用的方法
|
||||
*
|
||||
* @param message 客户端发送过来的消息
|
||||
*/
|
||||
@OnMessage
|
||||
public void onMessage(String message, Session session) {
|
||||
try{
|
||||
processMessage(message, session);
|
||||
}finally {
|
||||
//多租户切换后清除缓存
|
||||
UserProvider.clearLocalUser();
|
||||
TenantDataSourceUtil.clearLocalTenantInfo();
|
||||
}
|
||||
}
|
||||
|
||||
private void processMessage(String message, Session session){
|
||||
log.debug("WS消息内容: {}, {}", session.getId(), message);
|
||||
JSONObject receivedMessage = JSONObject.parseObject(message);
|
||||
String receivedMethod = receivedMessage.getString(MessageParameterEnum.PARAMETER_METHOD.getValue());
|
||||
String receivedToken = receivedMessage.getString(MessageParameterEnum.PARAMETER_TOKEN.getValue());
|
||||
//验证TOKEN
|
||||
this.userInfo = UserProvider.getUser(receivedMessage.getString(MessageParameterEnum.PARAMETER_TOKEN.getValue()));
|
||||
if (this.userInfo.getUserId() == null) {
|
||||
log.info("WSToken无效: {}, {}", session.getId(), message);
|
||||
OnlineUserProvider.closeFrontWs(null, session);
|
||||
return;
|
||||
}
|
||||
//判断是否为多租户
|
||||
if(!isMultiTenancy()){
|
||||
log.info("WS切库失败: {}, {}, {}, {}", userInfo.getTenantId(), userInfo.getUserId(), session.getId(), receivedToken);
|
||||
//切库失败
|
||||
OnlineUserProvider.closeFrontWs(null, session);
|
||||
}
|
||||
UserProvider.setLocalLoginUser(userInfo);
|
||||
switch (receivedMethod) {
|
||||
case ConnectionType.CONNECTION_ONCONNECTION:
|
||||
//建立连接
|
||||
log.info("WS开启连接: {}, {}, {}, {}", userInfo.getTenantId(), userInfo.getUserId(), session.getId(), receivedToken);
|
||||
if(OnlineUserProvider.getOnlineUserList().stream().anyMatch(t -> t.getWebSocket().getId().equals(session.getId()))){
|
||||
//WS已存在
|
||||
log.info("WS已存在: {}, {}, {}, {}", userInfo.getTenantId(), userInfo.getUserId(), session.getId(), receivedToken);
|
||||
return;
|
||||
}
|
||||
//Token已存在, 关闭之前的WebSocket, 继续执行后续代码添加新的WebSocket
|
||||
List<OnlineUserModel> tokenList = OnlineUserProvider.getOnlineUserList().stream().filter(t-> {
|
||||
if(receivedToken.equals(t.getToken())){
|
||||
OnlineUserProvider.closeFrontWs(t, t.getWebSocket());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}).collect(Collectors.toList());
|
||||
OnlineUserProvider.getOnlineUserList().removeAll(tokenList);
|
||||
|
||||
//app-true, PC-false
|
||||
Boolean isMobileDevice = receivedMessage.getBoolean(MessageParameterEnum.PARAMETER_MOBILEDEVICE.getValue());
|
||||
if (userInfo != null && userInfo.getUserId() != null) {
|
||||
OnlineUserModel model = new OnlineUserModel();
|
||||
model.setConnectionId(session.getId());
|
||||
model.setUserId(userInfo.getUserId());
|
||||
model.setTenantId(userInfo.getTenantId());
|
||||
model.setIsMobileDevice(isMobileDevice);
|
||||
model.setWebSocket(session);
|
||||
model.setToken(receivedToken);
|
||||
model.setSystemId(model.getIsMobileDevice() ? userInfo.getAppSystemId() : userInfo.getSystemId());
|
||||
BaseSystemInfo sysInfo = sysConfigApi.getSysInfo();
|
||||
//判断是否在线
|
||||
isOnLine(sysInfo, model);
|
||||
|
||||
List<OnlineUserModel> onlineUserList = OnlineUserProvider.getOnlineUserList().stream().filter(q -> !q.getUserId().equals(userInfo.getUserId()) && q.getTenantId().equals(userInfo.getTenantId())).collect(Collectors.toList());
|
||||
//反馈信息给登录者
|
||||
List<String> onlineUsers = onlineUserList.stream().map(t -> t.getUserId()).collect(Collectors.toList()).stream().distinct().collect(Collectors.toList());
|
||||
List<ImUnreadNumModel> unreadNums = imContentService.getUnreadList(userInfo.getUserId());
|
||||
int unreadNoticeCount = messageService.getUnreadCount(userInfo.getUserId(), 1);
|
||||
int unreadMessageCount = messageService.getUnreadCount(userInfo.getUserId(), 2);
|
||||
int unreadScheduleCount = messageService.getUnreadCount(userInfo.getUserId(),4);
|
||||
int unreadSystemMessageCount = messageService.getUnreadCount(userInfo.getUserId(), 3);
|
||||
MessageEntity noticeDefaultText = messageService.getInfoDefault(1);
|
||||
PaginationMessage pagination = new PaginationMessage();
|
||||
pagination.setCurrentPage(1);
|
||||
pagination.setPageSize(1);
|
||||
List<MessageReceiveEntity> list = messageService.getMessageList3(pagination, pagination.getType(),userInfo.getUserId(), null);
|
||||
MessageReceiveEntity messageDefaultText = new MessageReceiveEntity();
|
||||
if(list.size()>0){
|
||||
messageDefaultText = list.get(0);
|
||||
}
|
||||
String noticeText = noticeDefaultText.getTitle() != null ? noticeDefaultText.getTitle() : "";
|
||||
String messageText = messageDefaultText.getTitle() != null ? messageDefaultText.getTitle() : "";
|
||||
Long noticeTime = noticeDefaultText.getCreatorTime() != null ? noticeDefaultText.getCreatorTime().getTime() : 0;
|
||||
Long messageTime = messageDefaultText.getCreatorTime() != null ? messageDefaultText.getCreatorTime().getTime() : 0;
|
||||
//转model后上传到mq服务器上
|
||||
OnConnectionModel onConnectionModel = new OnConnectionModel();
|
||||
onConnectionModel.setMethod(MessageChannelType.CHANNEL_INITMESSAGE);
|
||||
onConnectionModel.setOnlineUsers(onlineUsers);
|
||||
onConnectionModel.setUnreadNums(JsonUtil.listToJsonField(unreadNums));
|
||||
onConnectionModel.setUnreadNoticeCount(unreadNoticeCount);
|
||||
// onConnectionModel.setNoticeDefaultText(noticeText);
|
||||
onConnectionModel.setUnreadMessageCount(unreadMessageCount);
|
||||
onConnectionModel.setUnreadSystemMessageCount(unreadSystemMessageCount);
|
||||
onConnectionModel.setUnreadScheduleCount(unreadScheduleCount);
|
||||
onConnectionModel.setMessageDefaultText(messageText);
|
||||
onConnectionModel.setMessageDefaultTime(messageTime);
|
||||
onConnectionModel.setUserId(userInfo.getUserId());
|
||||
int total = unreadNoticeCount+unreadMessageCount+unreadSystemMessageCount+unreadScheduleCount;
|
||||
onConnectionModel.setUnreadTotalCount(total);
|
||||
OnlineUserProvider.sendMessage(session, onConnectionModel);
|
||||
//通知所有在线用户,有用户在线
|
||||
for (OnlineUserModel item : onlineUserList) {
|
||||
if (!item.getUserId().equals(userInfo.getUserId())) {
|
||||
//创建模型
|
||||
OnLineModel remindUserModel = new OnLineModel(MessageChannelType.CHANNEL_ONLINE, userInfo.getUserId());
|
||||
OnlineUserProvider.sendMessage(item, remindUserModel);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case ConnectionType.CONNECTION_SENDMESSAGE:
|
||||
//发送消息
|
||||
String toUserId = receivedMessage.getString(MessageParameterEnum.PARAMETER_TOUSERID.getValue());
|
||||
//text/voice/image
|
||||
String messageType = receivedMessage.getString(MessageParameterEnum.PARAMETER_MESSAGETYPE.getValue());
|
||||
String messageContent = receivedMessage.getString(MessageParameterEnum.PARAMETER_MESSAGECONTENT.getValue());
|
||||
String tenantId = UserProvider.getUser(receivedMessage.getString(MessageParameterEnum.PARAMETER_TOKEN.getValue())).getTenantId();
|
||||
|
||||
String fileName = "";
|
||||
if (!SendMessageTypeEnum.MESSAGE_TEXT.getMessage().equals(messageType)) {
|
||||
JSONObject object = JSONObject.parseObject(messageContent);
|
||||
fileName = object.getString("name");
|
||||
}
|
||||
List<OnlineUserModel> user = OnlineUserProvider.getOnlineUserList().stream().filter(q -> String.valueOf(q.getUserId()).equals(String.valueOf(userInfo.getUserId())) && String.valueOf(q.getTenantId()).equals(tenantId)).collect(Collectors.toList());
|
||||
OnlineUserModel onlineUser = user.size() > 0 ? user.get(0) : null;
|
||||
List<OnlineUserModel> toUser = OnlineUserProvider.getOnlineUserList().stream().filter(q -> String.valueOf(q.getTenantId()).equals(String.valueOf(onlineUser.getTenantId())) && String.valueOf(q.getUserId()).equals(String.valueOf(toUserId))).collect(Collectors.toList());
|
||||
if (user.size() != 0) {
|
||||
//saveMessage
|
||||
if (SendMessageTypeEnum.MESSAGE_TEXT.getMessage().equals(messageType)) {
|
||||
messageContent = XSSEscape.escape(messageContent);
|
||||
imContentService.sendMessage(onlineUser.getUserId(), toUserId, messageContent, messageType);
|
||||
} else if (SendMessageTypeEnum.MESSAGE_IMAGE.getMessage().equals(messageType)) {
|
||||
JSONObject image = new JSONObject();
|
||||
image.put("path", UploaderUtil.uploaderImg("/api/file/Image/IM/", fileName));
|
||||
image.put("width", JSONObject.parseObject(messageContent).getString("width"));
|
||||
image.put("height", JSONObject.parseObject(messageContent).getString("height"));
|
||||
imContentService.sendMessage(onlineUser.getUserId(), toUserId, image.toJSONString(), messageType);
|
||||
} else if (SendMessageTypeEnum.MESSAGE_VOICE.getMessage().equals(messageType)) {
|
||||
JSONObject voice = new JSONObject();
|
||||
voice.put("path", UploaderUtil.uploaderImg("/api/file/Image/IM/", fileName));
|
||||
voice.put("length", JSONObject.parseObject(messageContent).getString("length"));
|
||||
imContentService.sendMessage(onlineUser.getUserId(), toUserId, voice.toJSONString(), messageType);
|
||||
}
|
||||
for (int i = 0; i < user.size(); i++) {
|
||||
OnlineUserModel model = user.get(i);
|
||||
//组装model
|
||||
SavaMessageModel savaMessageModel = new SavaMessageModel();
|
||||
savaMessageModel.setMethod(MessageChannelType.CHANNEL_SENDMESSAGE);
|
||||
savaMessageModel.setUserId(model.getUserId());
|
||||
savaMessageModel.setToUserId(toUserId);
|
||||
savaMessageModel.setDateTime(DateUtil.getNowDate().getTime());
|
||||
//头像
|
||||
savaMessageModel.setHeadIcon(UploaderUtil.uploaderImg(userInfo.getUserIcon()));
|
||||
//最新消息
|
||||
savaMessageModel.setLatestDate(DateUtil.getNowDate().getTime());
|
||||
//用户姓名
|
||||
savaMessageModel.setRealName(userInfo.getUserName());
|
||||
savaMessageModel.setAccount(userInfo.getUserAccount());
|
||||
//对方的名称账号头像
|
||||
Map<String, String> headers = ImmutableMap.of(Constants.AUTHORIZATION.toLowerCase(), receivedToken);
|
||||
UserEntity entity = userApi.getInfo(toUserId);
|
||||
savaMessageModel.setToAccount(entity.getAccount());
|
||||
savaMessageModel.setToRealName(entity.getRealName());
|
||||
savaMessageModel.setToHeadIcon(UploaderUtil.uploaderImg(entity.getHeadIcon()));
|
||||
|
||||
if (SendMessageTypeEnum.MESSAGE_TEXT.getMessage().equals(messageType)) {
|
||||
savaMessageModel.setMessageType(messageType);
|
||||
savaMessageModel.setToMessage(messageContent);
|
||||
} else if (SendMessageTypeEnum.MESSAGE_IMAGE.getMessage().equals(messageType)) {
|
||||
//构建图片模型
|
||||
ImageMessageModel messageModel = getImageModel(messageContent, UploaderUtil.uploaderImg("/api/file/Image/IM/", fileName));
|
||||
savaMessageModel.setToMessage(messageModel);
|
||||
savaMessageModel.setMessageType(messageType);
|
||||
} else if (SendMessageTypeEnum.MESSAGE_VOICE.getMessage().equals(messageType)) {
|
||||
//构建语音模型
|
||||
VoiceMessageModel messageModel = getVoiceMessageModel(messageContent, UploaderUtil.uploaderImg("/api/file/Image/IM/", fileName));
|
||||
savaMessageModel.setMessageType(messageType);
|
||||
savaMessageModel.setToMessage(messageModel);
|
||||
}
|
||||
/*List<String> cidList = userDeviceService.getCidList(toUserId);
|
||||
if(cidList != null && cidList.size()>0){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("type","3");
|
||||
jsonObject.put("name",userInfo.getUserName() + "/"+userInfo.getUserAccount());
|
||||
jsonObject.put("formUserId",userInfo.getUserId());
|
||||
jsonObject.put("headIcon",UploaderUtil.uploaderImg(userInfo.getUserIcon()));
|
||||
// jsonObject.put("title",userInfo.getUserName() + "/"+userInfo.getUserAccount());
|
||||
String text = JSONObject.toJSONString(jsonObject);
|
||||
byte[] bytes = text.getBytes(StandardCharsets.UTF_8);
|
||||
text = Base64.getEncoder().encodeToString(bytes);
|
||||
uinPush.sendUniPush(cidList, userInfo.getUserName(), "你有一条看聊天消息", "3", text);
|
||||
}*/
|
||||
OnlineUserProvider.sendMessage(model, savaMessageModel);
|
||||
}
|
||||
}
|
||||
|
||||
//接受消息
|
||||
ReceiveMessageModel receiveMessageModel = new ReceiveMessageModel();
|
||||
receiveMessageModel.setMethod(MessageChannelType.CHANNEL_RECEIVEMESSAGE);
|
||||
receiveMessageModel.setFormUserId(onlineUser.getUserId());
|
||||
receiveMessageModel.setDateTime(DateUtil.getNowDate().getTime());
|
||||
//头像
|
||||
receiveMessageModel.setHeadIcon(UploaderUtil.uploaderImg(userInfo.getUserIcon()));
|
||||
//最新消息
|
||||
receiveMessageModel.setLatestDate(DateUtil.getNowDate().getTime());
|
||||
//用户姓名
|
||||
receiveMessageModel.setRealName(userInfo.getUserName());
|
||||
receiveMessageModel.setAccount(userInfo.getUserAccount());
|
||||
receiveMessageModel.setUserId(toUserId);
|
||||
if (toUser.size() != 0) {
|
||||
for (int i = 0; i < toUser.size(); i++) {
|
||||
OnlineUserModel onlineToUser = toUser.get(i);
|
||||
if (SendMessageTypeEnum.MESSAGE_TEXT.getMessage().equals(messageType)) {
|
||||
receiveMessageModel.setMessageType(messageType);
|
||||
receiveMessageModel.setFormMessage(messageContent);
|
||||
} else if (SendMessageTypeEnum.MESSAGE_IMAGE.getMessage().equals(messageType)) {
|
||||
//构建图片模型
|
||||
ImageMessageModel messageModel = getImageModel(messageContent, UploaderUtil.uploaderImg("/api/file/Image/IM/", fileName));
|
||||
receiveMessageModel.setMessageType(messageType);
|
||||
receiveMessageModel.setFormMessage(messageModel);
|
||||
} else if (SendMessageTypeEnum.MESSAGE_VOICE.getMessage().equals(messageType)) {
|
||||
//构建语音模型
|
||||
VoiceMessageModel messageModel = getVoiceMessageModel(messageContent, UploaderUtil.uploaderImg("/api/file/Image/IM/", fileName));
|
||||
receiveMessageModel.setMessageType(messageType);
|
||||
receiveMessageModel.setFormMessage(messageModel);
|
||||
}
|
||||
OnlineUserProvider.sendMessage(onlineToUser, receiveMessageModel);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "UpdateReadMessage":
|
||||
//更新已读
|
||||
String formUserId = receivedMessage.getString("formUserId");
|
||||
onlineUser = OnlineUserProvider.getOnlineUserList().stream().filter(q -> String.valueOf(q.getConnectionId()).equals(String.valueOf(session.getId()))).findFirst().orElse(new OnlineUserModel());
|
||||
if (onlineUser != null) {
|
||||
imContentService.readMessage(formUserId, onlineUser.getUserId());
|
||||
}
|
||||
break;
|
||||
case "MessageList":
|
||||
//获取消息列表
|
||||
String sendUserId = receivedMessage.getString("toUserId");
|
||||
String receiveUserId = receivedMessage.getString("formUserId");
|
||||
PageModel pageModel = new PageModel();
|
||||
pageModel.setPage(receivedMessage.getInteger("currentPage"));
|
||||
pageModel.setRows(receivedMessage.getInteger("pageSize"));
|
||||
pageModel.setSord(receivedMessage.getString("sord"));
|
||||
pageModel.setKeyword(receivedMessage.getString("keyword"));
|
||||
List<ImContentEntity> data = imContentService.getMessageList(sendUserId, receiveUserId, pageModel).stream().sorted(Comparator.comparing(ImContentEntity::getSendTime)).collect(Collectors.toList());
|
||||
JSONObject object = new JSONObject();
|
||||
object.put("method", "messageList");
|
||||
object.put("list", JsonUtil.getListToJsonArray(data));
|
||||
JSONObject pagination = new JSONObject();
|
||||
pagination.put("total", pageModel.getRecords());
|
||||
pagination.put("currentPage", pageModel.getPage());
|
||||
pagination.put("pageSize", receivedMessage.getInteger("pageSize"));
|
||||
object.put("pagination", pagination);
|
||||
OnlineUserProvider.sendMessage(session, object);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否在线
|
||||
*
|
||||
* @param model
|
||||
*/
|
||||
private void isOnLine(BaseSystemInfo systemInfo, OnlineUserModel model) {
|
||||
// 不允许多人登录
|
||||
if ("1".equals(String.valueOf(systemInfo.getSingleLogin()))) {
|
||||
Long userAll = OnlineUserProvider.getOnlineUserList().stream().filter(t -> t.getUserId().equals(userInfo.getUserId()) && t.getTenantId().equals(userInfo.getTenantId())).count();
|
||||
Long userAllMobile = OnlineUserProvider.getOnlineUserList().stream().filter(t -> t.getUserId().equals(userInfo.getUserId()) && t.getTenantId().equals(userInfo.getTenantId()) && t.getIsMobileDevice().equals(true)).count();
|
||||
Long userAllWeb = OnlineUserProvider.getOnlineUserList().stream().filter(t -> t.getUserId().equals(userInfo.getUserId()) && t.getTenantId().equals(userInfo.getTenantId()) && t.getIsMobileDevice().equals(false)).count();
|
||||
//都不在线
|
||||
if (userAll == 0) {
|
||||
OnlineUserProvider.addModel(model);
|
||||
}
|
||||
//手机在线
|
||||
else if (userAllMobile != 0 && userAllWeb == 0) {
|
||||
if (!model.getIsMobileDevice()) {
|
||||
OnlineUserProvider.addModel(model);
|
||||
}
|
||||
}
|
||||
//电脑在线
|
||||
else {
|
||||
if (model.getIsMobileDevice()) {
|
||||
OnlineUserProvider.addModel(model);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//同时登录不限制
|
||||
OnlineUserProvider.addModel(model);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为多租户
|
||||
*
|
||||
*/
|
||||
private boolean isMultiTenancy() {
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
//多租户需要切库
|
||||
if (StringUtil.isNotEmpty(userInfo.getTenantId())) {
|
||||
TenantDataSourceUtil.switchTenant(userInfo.getTenantId());
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建图片消息模型
|
||||
*
|
||||
* @param messageContent
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
private ImageMessageModel getImageModel(String messageContent, String fileName) {
|
||||
String width = JSONObject.parseObject(messageContent).getString("width");
|
||||
String height = JSONObject.parseObject(messageContent).getString("height");
|
||||
return new ImageMessageModel(width, height, fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建语音模型
|
||||
*
|
||||
* @param messageContent
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
private VoiceMessageModel getVoiceMessageModel(String messageContent, String fileName) {
|
||||
String length = JSONObject.parseObject(messageContent).getString("length");
|
||||
return new VoiceMessageModel(length, fileName);
|
||||
}
|
||||
|
||||
@OnError
|
||||
public void onError(Session session, Throwable error) {
|
||||
// OnlineUserModel user = OnlineUserProvider.getOnlineUserList().stream().filter(t -> t.getConnectionId().equals(session.getId())).findFirst().isPresent() ? OnlineUserProvider.getOnlineUserList().stream().filter(t -> t.getConnectionId().equals(session.getId())).findFirst().get() : null;
|
||||
// if (user != null) {
|
||||
// log.error("调用onError,租户:" + user.getTenantId() + ",用户:" + user.getUserId());
|
||||
// }
|
||||
try {
|
||||
onClose(session);
|
||||
} catch (Exception e) {
|
||||
// log.error("发生error,调用onclose失败,session为:" + session);
|
||||
}
|
||||
if (error.getMessage() != null) {
|
||||
OnlineUserModel user = OnlineUserProvider.getOnlineUserList().stream().filter(t -> t.getConnectionId().equals(session.getId())).findFirst().isPresent() ? OnlineUserProvider.getOnlineUserList().stream().filter(t -> t.getConnectionId().equals(session.getId())).findFirst().get() : null;
|
||||
if(user != null){
|
||||
log.error("WS发生错误: {}, {}, {}, {}, {}", user.getTenantId(), user.getUserId(), session.getId(), error.getMessage(), user.getToken());
|
||||
}else{
|
||||
log.error("WS发生错误", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
private void init() {
|
||||
messageService = SpringContext.getBean(MessageService.class);
|
||||
imContentService = SpringContext.getBean(ImContentService.class);
|
||||
configValueUtil = SpringContext.getBean(ConfigValueUtil.class);
|
||||
userApi = SpringContext.getBean(UserService.class);
|
||||
sysConfigApi = SpringContext.getBean(SysconfigService.class);
|
||||
uinPush = SpringContext.getBean(UinPush.class);
|
||||
userDeviceService = SpringContext.getBean(UserDeviceService.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user