|
@@ -10,23 +10,22 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.ruoyi.common.datascope.annotation.DataScope;
|
|
|
-import com.ruoyi.common.datascope.context.DataScopeContextHolder;
|
|
|
-import com.usky.common.core.bean.ApiResult;
|
|
|
import com.usky.common.core.bean.CommonPage;
|
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
|
-import com.usky.system.RemoteUserService;
|
|
|
import com.usky.system.domain.*;
|
|
|
import com.usky.system.mapper.MceReceiveMapper;
|
|
|
+import com.usky.system.mapper.MceSettingMapper;
|
|
|
import com.usky.system.mapper.SysUserMapper;
|
|
|
import com.usky.system.service.*;
|
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -56,35 +55,37 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
|
|
|
|
|
|
@Autowired
|
|
|
private SysUserMapper userMapper;
|
|
|
+ @Autowired
|
|
|
+ private MceSettingMapper mceSettingMapper;
|
|
|
|
|
|
@Override
|
|
|
public CommonPage<Object> mceList(String infoTitle, String infoType, String startTime, String endTime, Integer id, Integer current, Integer size) {
|
|
|
List<Object> list = new ArrayList<>();
|
|
|
LambdaQueryWrapper<MceContent> lambdaQuery1 = Wrappers.lambdaQuery();
|
|
|
lambdaQuery1.select(MceContent::getId, MceContent::getInfoTitle, MceContent::getInfoContent)
|
|
|
- .like(StringUtils.isNotBlank(infoTitle),MceContent::getInfoTitle,infoTitle)
|
|
|
- .eq(id != null,MceContent::getId,id);
|
|
|
+ .like(StringUtils.isNotBlank(infoTitle), MceContent::getInfoTitle, infoTitle)
|
|
|
+ .eq(id != null, MceContent::getId, id);
|
|
|
List<MceContent> list1 = mceContentService.list(lambdaQuery1);
|
|
|
IPage<MceReceive> page = new Page<>(current, size);
|
|
|
List<Integer> contentIds = new ArrayList<>();
|
|
|
- if (CollectionUtils.isNotEmpty(list1)){
|
|
|
- for(int i=0;i<list1.size();i++){
|
|
|
+ if (CollectionUtils.isNotEmpty(list1)) {
|
|
|
+ for (int i = 0; i < list1.size(); i++) {
|
|
|
contentIds.add(list1.get(i).getId());
|
|
|
}
|
|
|
Long userId = SecurityUtils.getUserId();
|
|
|
LambdaQueryWrapper<MceReceive> lambdaQuery = Wrappers.lambdaQuery();
|
|
|
lambdaQuery.select(MceReceive::getId, MceReceive::getInfoType,
|
|
|
- MceReceive::getContentId, MceReceive::getReadFlag, MceReceive::getCreateTime,
|
|
|
- MceReceive::getReceiverId,MceReceive::getModuleId)
|
|
|
- .between(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime),MceReceive::getCreateTime,
|
|
|
- startTime,endTime)
|
|
|
- .eq(StringUtils.isNotBlank(infoType),MceReceive::getInfoType, infoType)
|
|
|
+ MceReceive::getContentId, MceReceive::getReadFlag, MceReceive::getCreateTime,
|
|
|
+ MceReceive::getReceiverId, MceReceive::getModuleId)
|
|
|
+ .between(StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime), MceReceive::getCreateTime,
|
|
|
+ startTime, endTime)
|
|
|
+ .eq(StringUtils.isNotBlank(infoType), MceReceive::getInfoType, infoType)
|
|
|
.eq(MceReceive::getReceiverId, SecurityUtils.getUserId())
|
|
|
- .in(CollectionUtils.isNotEmpty(contentIds),MceReceive::getContentId,contentIds)
|
|
|
+ .in(CollectionUtils.isNotEmpty(contentIds), MceReceive::getContentId, contentIds)
|
|
|
.orderByDesc(MceReceive::getId);
|
|
|
// .inSql(StringUtils.isNotBlank(infoTitle),MceReceive::getContentId,"SELECT id FROM mce_content WHERE " +
|
|
|
// "info_title like '%" + infoTitle + "%' AND tenant_id = "+SecurityUtils.getTenantId()+"");
|
|
|
- page = this.page(page,lambdaQuery);
|
|
|
+ page = this.page(page, lambdaQuery);
|
|
|
if (CollectionUtils.isNotEmpty(page.getRecords())) {
|
|
|
for (int i = 0; i < page.getRecords().size(); i++) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
@@ -96,7 +97,7 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
|
|
|
if (CollectionUtils.isNotEmpty(list1)) {
|
|
|
for (int j = 0; j < list1.size(); j++) {
|
|
|
if (page.getRecords().get(i).getContentId().equals(list1.get(j).getId())) {
|
|
|
- map.put("contentId",list1.get(j).getId());
|
|
|
+ map.put("contentId", list1.get(j).getId());
|
|
|
map.put("infoTitle", list1.get(j).getInfoTitle());
|
|
|
map.put("infoContent", list1.get(j).getInfoContent());
|
|
|
}
|
|
@@ -106,7 +107,7 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return new CommonPage<>(list,page.getTotal(),page.getCurrent(),page.getSize());
|
|
|
+ return new CommonPage<>(list, page.getTotal(), page.getCurrent(), page.getSize());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -114,16 +115,16 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
|
|
|
public CommonPage<Object> mceManageList(String infoTitle, String infoType, String startTime, String endTime, Integer current, Integer size) {
|
|
|
List<Object> list = new ArrayList<>();
|
|
|
IPage<MceContent> page = new Page<>(current, size);
|
|
|
- //查询消息内容
|
|
|
+ // 查询消息内容
|
|
|
LambdaQueryWrapper<MceContent> lambdaQuery1 = Wrappers.lambdaQuery();
|
|
|
- lambdaQuery1.select(MceContent::getId, MceContent::getInfoTitle, MceContent::getInfoContent, MceContent::getCreateTime,MceContent::getInfoType)
|
|
|
- .like(StringUtils.isNotBlank(infoTitle),MceContent::getInfoTitle,infoTitle)
|
|
|
- .between(StringUtils.isNotBlank(startTime)&&StringUtils.isNotBlank(endTime),MceContent::getCreateTime, startTime,endTime)
|
|
|
- .eq(StringUtils.isNotBlank(infoType),MceContent::getInfoType, infoType)
|
|
|
+ lambdaQuery1.select(MceContent::getId, MceContent::getInfoTitle, MceContent::getInfoContent, MceContent::getCreateTime, MceContent::getInfoType)
|
|
|
+ .like(StringUtils.isNotBlank(infoTitle), MceContent::getInfoTitle, infoTitle)
|
|
|
+ .between(StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime), MceContent::getCreateTime, startTime, endTime)
|
|
|
+ .eq(StringUtils.isNotBlank(infoType), MceContent::getInfoType, infoType)
|
|
|
// .apply(DataScopeContextHolder.getDataScopeSql())
|
|
|
- .eq(MceContent::getTenantId,SecurityUtils.getTenantId())
|
|
|
+ .eq(MceContent::getTenantId, SecurityUtils.getTenantId())
|
|
|
.orderByDesc(MceContent::getId);
|
|
|
- page = mceContentService.page(page,lambdaQuery1);
|
|
|
+ page = mceContentService.page(page, lambdaQuery1);
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(page.getRecords())) {
|
|
|
List<Integer> contentIds = new ArrayList<>();
|
|
@@ -131,11 +132,11 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
|
|
|
contentIds.add(page.getRecords().get(i).getId());
|
|
|
}
|
|
|
QueryWrapper<MceReceive> queryWrapper = Wrappers.query();
|
|
|
- queryWrapper.select("content_id AS contentId","COUNT(read_flag=0 or null) as notReadCount","COUNT" +
|
|
|
- "(read_flag=1 or null) as readCount","issuer_name AS issuerName")
|
|
|
- .in("content_id",contentIds)
|
|
|
- .groupBy("content_id","issuer_name");
|
|
|
- List<Map<String,Object>> readStatisticList = this.listMaps(queryWrapper);
|
|
|
+ queryWrapper.select("content_id AS contentId", "COUNT(read_flag=0 or null) as notReadCount", "COUNT" +
|
|
|
+ "(read_flag=1 or null) as readCount", "issuer_name AS issuerName")
|
|
|
+ .in("content_id", contentIds)
|
|
|
+ .groupBy("content_id", "issuer_name");
|
|
|
+ List<Map<String, Object>> readStatisticList = this.listMaps(queryWrapper);
|
|
|
for (int i = 0; i < page.getRecords().size(); i++) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("id", page.getRecords().get(i).getId());
|
|
@@ -144,7 +145,7 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
|
|
|
map.put("infoType", page.getRecords().get(i).getInfoType());
|
|
|
map.put("createTime", page.getRecords().get(i).getCreateTime());
|
|
|
for (int j = 0; j < readStatisticList.size(); j++) {
|
|
|
- if (page.getRecords().get(i).getId().equals(readStatisticList.get(j).get("contentId"))){
|
|
|
+ if (page.getRecords().get(i).getId().equals(readStatisticList.get(j).get("contentId"))) {
|
|
|
map.put("notReadCount", readStatisticList.get(j).get("notReadCount"));
|
|
|
map.put("readCount", readStatisticList.get(j).get("readCount"));
|
|
|
map.put("userName", readStatisticList.get(j).get("issuerName"));
|
|
@@ -154,15 +155,15 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return new CommonPage<>(list,page.getTotal(),page.getCurrent(),page.getSize());
|
|
|
+ return new CommonPage<>(list, page.getTotal(), page.getCurrent(), page.getSize());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public CommonPage<MceReceive> mceManageById(Integer id, Integer current, Integer size) {
|
|
|
IPage<MceReceive> page = new Page<>(current, size);
|
|
|
LambdaQueryWrapper<MceReceive> lambdaQuery = Wrappers.lambdaQuery();
|
|
|
- lambdaQuery.eq(MceReceive::getContentId,id);
|
|
|
- page = this.page(page,lambdaQuery);
|
|
|
+ lambdaQuery.eq(MceReceive::getContentId, id);
|
|
|
+ page = this.page(page, lambdaQuery);
|
|
|
// if (CollectionUtils.isNotEmpty(page.getRecords())) {
|
|
|
// List<Integer> userIds = new ArrayList<>();
|
|
|
// for (int i = 0; i < page.getRecords().size(); i++) {
|
|
@@ -185,7 +186,7 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
- return new CommonPage<>(page.getRecords(),page.getTotal(),page.getCurrent(),page.getSize());
|
|
|
+ return new CommonPage<>(page.getRecords(), page.getTotal(), page.getCurrent(), page.getSize());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -194,15 +195,15 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
|
|
|
LocalDateTime oneYearAgo = currentDate.minusYears(1);
|
|
|
LocalDateTime zeroTime = oneYearAgo.withHour(0).withMinute(0).withSecond(0);
|
|
|
QueryWrapper<MceReceive> queryWrapper = Wrappers.query();
|
|
|
- queryWrapper.select("COUNT(read_flag=0 or null) as notReadCount","COUNT(read_flag=1 or null) as readCount"
|
|
|
- ,"info_type AS infoType")
|
|
|
- .eq("receiver_id",SecurityUtils.getUserId())
|
|
|
- .between("create_time",zeroTime,currentDate)
|
|
|
+ queryWrapper.select("COUNT(read_flag=0 or null) as notReadCount", "COUNT(read_flag=1 or null) as readCount"
|
|
|
+ , "info_type AS infoType")
|
|
|
+ .eq("receiver_id", SecurityUtils.getUserId())
|
|
|
+ .between("create_time", zeroTime, currentDate)
|
|
|
.groupBy("info_type");
|
|
|
- List<Map<String,Object>> readStatisticList = this.listMaps(queryWrapper);
|
|
|
+ List<Map<String, Object>> readStatisticList = this.listMaps(queryWrapper);
|
|
|
LambdaQueryWrapper<MceReceive> lambdaQuery = Wrappers.lambdaQuery();
|
|
|
- lambdaQuery.eq(MceReceive::getReceiverId,SecurityUtils.getUserId())
|
|
|
- .eq(MceReceive::getReadFlag,0);
|
|
|
+ lambdaQuery.eq(MceReceive::getReceiverId, SecurityUtils.getUserId())
|
|
|
+ .eq(MceReceive::getReadFlag, 0);
|
|
|
Integer notReadCount = this.count(lambdaQuery);
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("notReadCount", notReadCount);
|
|
@@ -211,19 +212,19 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void updateMceReceive(MceReceive mceReceive){
|
|
|
+ public void updateMceReceive(MceReceive mceReceive) {
|
|
|
LambdaUpdateWrapper<MceReceive> updateWrapper = new UpdateWrapper<MceReceive>().lambda();
|
|
|
- if (Objects.nonNull(mceReceive.getId())&&!mceReceive.getId().equals(0)){
|
|
|
- updateWrapper.eq(MceReceive::getId,mceReceive.getId())
|
|
|
- .set(MceReceive::getReadFlag,1)
|
|
|
- .set(MceReceive::getUpdateBy,SecurityUtils.getUsername())
|
|
|
- .set(MceReceive::getUpdateTime,LocalDateTime.now());
|
|
|
- }else {
|
|
|
- updateWrapper.eq(MceReceive::getReceiverId,SecurityUtils.getUserId())
|
|
|
- .eq(MceReceive::getReadFlag,0)
|
|
|
- .set(MceReceive::getReadFlag,1)
|
|
|
- .set(MceReceive::getUpdateBy,SecurityUtils.getUsername())
|
|
|
- .set(MceReceive::getUpdateTime,LocalDateTime.now());
|
|
|
+ if (Objects.nonNull(mceReceive.getId()) && !mceReceive.getId().equals(0)) {
|
|
|
+ updateWrapper.eq(MceReceive::getId, mceReceive.getId())
|
|
|
+ .set(MceReceive::getReadFlag, 1)
|
|
|
+ .set(MceReceive::getUpdateBy, SecurityUtils.getUsername())
|
|
|
+ .set(MceReceive::getUpdateTime, LocalDateTime.now());
|
|
|
+ } else {
|
|
|
+ updateWrapper.eq(MceReceive::getReceiverId, SecurityUtils.getUserId())
|
|
|
+ .eq(MceReceive::getReadFlag, 0)
|
|
|
+ .set(MceReceive::getReadFlag, 1)
|
|
|
+ .set(MceReceive::getUpdateBy, SecurityUtils.getUsername())
|
|
|
+ .set(MceReceive::getUpdateTime, LocalDateTime.now());
|
|
|
}
|
|
|
this.update(updateWrapper);
|
|
|
}
|
|
@@ -238,6 +239,241 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Async
|
|
|
+ public void addMceReceive(MceRequestVO mceRequestVO) {
|
|
|
+ // 如果 infoTypeName 为空,则从字典数据中获取
|
|
|
+ if (mceRequestVO.getInfoTypeName() == null) {
|
|
|
+ String infoTypeName = sysDictDataService.selectDictLabel("message_type", mceRequestVO.getInfoType());
|
|
|
+ mceRequestVO.setInfoTypeName(infoTypeName);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取当前租户的所有用户
|
|
|
+ List<SysUser> userList = userMapper.tenantIdUserList(SecurityUtils.getTenantId());
|
|
|
+ if (CollectionUtils.isEmpty(userList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取用户昵称与真实姓名的映射
|
|
|
+ Map<String, String> userNameNickNameMap = userList.stream()
|
|
|
+ .collect(Collectors.toMap(SysUser::getUserName, SysUser::getNickName));
|
|
|
+
|
|
|
+ LocalDateTime currentTime = LocalDateTime.now();
|
|
|
+ List<Long> userIdList = new ArrayList<>();
|
|
|
+ MceContent contentEntity = new MceContent();
|
|
|
+ Integer generatedContentId = 0;
|
|
|
+
|
|
|
+ // 遍历用户列表,处理消息内容
|
|
|
+ for (SysUser user : userList) {
|
|
|
+ userIdList.add(user.getUserId());
|
|
|
+ if (mceRequestVO.getUserName().equals(user.getUserName())) {
|
|
|
+ contentEntity.setInfoTitle(mceRequestVO.getInfoTitle());
|
|
|
+ contentEntity.setInfoContent(mceRequestVO.getInfoContent());
|
|
|
+ contentEntity.setInfoType(mceRequestVO.getInfoType());
|
|
|
+ contentEntity.setCreateBy(user.getUserName());
|
|
|
+ contentEntity.setCreateTime(currentTime);
|
|
|
+ contentEntity.setDeptId(user.getDeptId().intValue());
|
|
|
+ contentEntity.setTenantId(user.getTenantId());
|
|
|
+ mceContentService.save(contentEntity);
|
|
|
+ generatedContentId = contentEntity.getId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 筛选符合用户ID条件的用户
|
|
|
+ List<Long> targetUserIds = mceRequestVO.getUserIds();
|
|
|
+ userIdList.retainAll(targetUserIds);
|
|
|
+
|
|
|
+ // 查询符合条件的 MceMbuser 列表
|
|
|
+ List<MceMbuser> mbUserList = mceMbuserService.list(Wrappers.lambdaQuery(MceMbuser.class).in(MceMbuser::getUserId, userIdList));
|
|
|
+
|
|
|
+ // 遍历用户列表,处理消息接收记录
|
|
|
+ for (Long userId : userIdList) {
|
|
|
+ if (CollectionUtils.isEmpty(mbUserList)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ Optional<MceMbuser> mbUserOptional = mbUserList.stream()
|
|
|
+ .filter(mbUser -> mbUser.getUserId().equals(userId))
|
|
|
+ .findFirst();
|
|
|
+
|
|
|
+
|
|
|
+ for (SysUser user : userList) {
|
|
|
+ if (user.getUserId().equals(userId)) {
|
|
|
+ // 创建消息接收记录
|
|
|
+ List<MceSetting> setting = mceSettingService.list(Wrappers.lambdaQuery(MceSetting.class).eq(MceSetting::getCreateBy, user.getUserName()));
|
|
|
+ Integer receiveId = 0;
|
|
|
+ if (CollectionUtils.isNotEmpty(setting)){
|
|
|
+ MceReceive mceReceive = createMceReceive(user, generatedContentId, mceRequestVO, userNameNickNameMap);
|
|
|
+ this.save(mceReceive);
|
|
|
+ receiveId = mceReceive.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (mbUserOptional.isPresent()) {
|
|
|
+ MceMbuser mbUser = mbUserOptional.get();
|
|
|
+ // 处理消息发送设置
|
|
|
+ handleMessageSettings(mbUser, mceRequestVO, receiveId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建消息接收记录
|
|
|
+ private MceReceive createMceReceive(SysUser user, Integer generatedContentId, MceRequestVO mceRequestVO, Map<String, String> userNameNickNameMap) {
|
|
|
+ MceReceive mceReceive = new MceReceive();
|
|
|
+ mceReceive.setReceiverId(user.getUserId().intValue());
|
|
|
+ mceReceive.setContentId(generatedContentId);
|
|
|
+ mceReceive.setReadFlag(0);
|
|
|
+ mceReceive.setInfoType(mceRequestVO.getInfoType());
|
|
|
+ mceReceive.setModuleId(mceRequestVO.getId());
|
|
|
+
|
|
|
+ String userName = mceRequestVO.getUserName();
|
|
|
+ String nickName = userNameNickNameMap.get(userName);
|
|
|
+ mceReceive.setIssuerName(nickName);
|
|
|
+
|
|
|
+ mceReceive.setReceiverName(user.getUserName());
|
|
|
+ mceReceive.setCreateBy(mceRequestVO.getUserName());
|
|
|
+ mceReceive.setCreateTime(LocalDateTime.now());
|
|
|
+ mceReceive.setTenantId(user.getTenantId());
|
|
|
+ mceReceive.setDeptId(Math.toIntExact(user.getDeptId()));
|
|
|
+ return mceReceive;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理消息发送设置
|
|
|
+ private void handleMessageSettings(MceMbuser mbUser, MceRequestVO mceRequestVO, Integer mceReceiveId) {
|
|
|
+ List<MceSetting> settingList = mceSettingService.list(Wrappers.lambdaQuery(MceSetting.class).eq(MceSetting::getCreateBy, mceRequestVO.getUserName()));
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(settingList)) {
|
|
|
+ MceSetting setting = settingList.get(0);
|
|
|
+ JSONObject appMode = JSONObject.parseObject(setting.getAppMode());
|
|
|
+ JSONObject wcMode = JSONObject.parseObject(setting.getWcMode());
|
|
|
+
|
|
|
+ String infoType = mceRequestVO.getInfoType();
|
|
|
+
|
|
|
+ // 处理应用消息发送
|
|
|
+ if (appMode.getBoolean(infoType)) {
|
|
|
+ if (mbUser.getCids() != null) {
|
|
|
+ try {
|
|
|
+ mceContentService.sendAppNew(mceRequestVO, mbUser.getCids(), 0, 0);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("为用户ID: {} 发送应用消息失败,错误信息: {}", mbUser.getUserId(), e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理微信消息发送
|
|
|
+ if (wcMode.getBoolean(infoType)) {
|
|
|
+ if (mbUser.getOpenid() != null) {
|
|
|
+ try {
|
|
|
+ mceContentService.sendAppNew(mceRequestVO, mbUser.getOpenid(), mceReceiveId, 1);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("为用户ID: {} 发送微信消息失败,错误信息: {}", mbUser.getUserId(), e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ @Async
|
|
|
+ @Override
|
|
|
+ public void addMceReceive(MceRequestVO mceRequestVO) {
|
|
|
+ if (mceRequestVO.getInfoTypeName() == null) {
|
|
|
+ String infoTypeName = sysDictDataService.selectDictLabel("message_type", mceRequestVO.getInfoType());
|
|
|
+ mceRequestVO.setInfoTypeName(infoTypeName);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<SysUser> userList = userMapper.tenantIdUserList(SecurityUtils.getTenantId());
|
|
|
+ // 获取用户昵称与真实姓名Map
|
|
|
+ Map<String, String> userNameNickNameMap = userList.stream().collect(Collectors.toMap(SysUser::getUserName, SysUser::getNickName));
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(userList)) {
|
|
|
+ LocalDateTime currentTime = LocalDateTime.now();
|
|
|
+ List<Integer> userIdList = new ArrayList<>();
|
|
|
+ MceContent contentEntity = new MceContent();
|
|
|
+ Integer generatedContentId = 0;
|
|
|
+ for (SysUser user : userList) {
|
|
|
+ userIdList.add(user.getUserId().intValue());
|
|
|
+ if (mceRequestVO.getUserName().equals(user.getUserName())) {
|
|
|
+ contentEntity.setInfoTitle(mceRequestVO.getInfoTitle());
|
|
|
+ contentEntity.setInfoContent(mceRequestVO.getInfoContent());
|
|
|
+ contentEntity.setInfoType(mceRequestVO.getInfoType());
|
|
|
+ contentEntity.setCreateBy(user.getUserName());
|
|
|
+ contentEntity.setCreateTime(currentTime);
|
|
|
+ contentEntity.setDeptId(user.getDeptId().intValue());
|
|
|
+ contentEntity.setTenantId(user.getTenantId());
|
|
|
+ mceContentService.save(contentEntity);
|
|
|
+ generatedContentId = contentEntity.getId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> userIds1;
|
|
|
+ userIds1 = mceRequestVO.getUserIds();
|
|
|
+ userList.retainAll(userIds1);
|
|
|
+
|
|
|
+ LambdaQueryWrapper<MceMbuser> lambdaQuery3 = Wrappers.lambdaQuery();
|
|
|
+ lambdaQuery3.in(MceMbuser::getUserId, userList);
|
|
|
+ List<MceMbuser> list3 = mceMbuserService.list(lambdaQuery3);
|
|
|
+
|
|
|
+ for (int i = 0; i < userList.size(); i++) {
|
|
|
+ if (CollectionUtils.isNotEmpty(list3)) {
|
|
|
+ for (int j = 0; j < list3.size(); j++) {
|
|
|
+ if (userList.get(i).getUserId().equals(list3.get(j).getUserId())) {
|
|
|
+ MceReceive mceReceive1 = new MceReceive();
|
|
|
+ mceReceive1.setReceiverId(userList.get(i).getUserId().intValue());
|
|
|
+ mceReceive1.setContentId(generatedContentId);
|
|
|
+ mceReceive1.setReadFlag(0);
|
|
|
+ mceReceive1.setInfoType(mceRequestVO.getInfoType());
|
|
|
+ mceReceive1.setModuleId(mceRequestVO.getId());
|
|
|
+
|
|
|
+ String userName = mceRequestVO.getUserName();
|
|
|
+ String nickName = userNameNickNameMap.get(userName);
|
|
|
+ mceReceive1.setIssuerName(nickName);
|
|
|
+
|
|
|
+ mceReceive1.setReceiverName(userList.get(i).getUserName());
|
|
|
+ mceReceive1.setCreateBy(mceRequestVO.getUserName());
|
|
|
+ mceReceive1.setCreateTime(LocalDateTime.now());
|
|
|
+ mceReceive1.setTenantId(userList.get(i).getTenantId());
|
|
|
+ mceReceive1.setDeptId(Math.toIntExact(userList.get(i).getDeptId()));
|
|
|
+ this.save(mceReceive1);
|
|
|
+ Integer mceReceiveId = mceReceive1.getId();
|
|
|
+
|
|
|
+ LambdaQueryWrapper<MceSetting> lambdaQuery = Wrappers.lambdaQuery();
|
|
|
+ lambdaQuery.eq(MceSetting::getCreateBy, userList.get(i).getUserName());
|
|
|
+ List<MceSetting> list1 = mceSettingService.list(lambdaQuery);
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(list1)) {
|
|
|
+ JSONObject appMode = JSONObject.parseObject(list1.get(0).getAppMode());
|
|
|
+ JSONObject wcMode = JSONObject.parseObject(list1.get(0).getWcMode());
|
|
|
+
|
|
|
+ if (appMode.get(mceRequestVO.getInfoType()).equals(true)) {
|
|
|
+ if (userList.get(i).getUserId().equals(list3.get(j).getUserId()) && StringUtils.isNotBlank(list3.get(j).getCids())) {
|
|
|
+ try {
|
|
|
+ mceContentService.sendAppNew(mceRequestVO, list3.get(j).getCids(), 0, 0);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("为用户ID: {} 发送应用消息失败,错误信息: {}", list3.get(j).getUserId(), e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (wcMode.get(mceRequestVO.getInfoType()).equals(true)) {
|
|
|
+ if (userList.get(i).getUserId().equals(list3.get(j).getUserId()) && StringUtils.isNotBlank(list3.get(j).getOpenid())) {
|
|
|
+ try {
|
|
|
+ mceContentService.sendAppNew(mceRequestVO, list3.get(j).getOpenid(), mceReceiveId, 1);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("为用户ID: {} 发送微信消息失败,错误信息: {}", list3.get(j).getUserId(), e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ */
|
|
|
+
|
|
|
+ @Async
|
|
|
@Override
|
|
|
public void add(String mceReceive) {
|
|
|
JSONObject mceReceiveVO = JSONObject.parseObject(mceReceive);
|
|
@@ -247,6 +483,8 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
|
|
|
}
|
|
|
|
|
|
List<SysUser> list = userMapper.tenantIdUserList(SecurityUtils.getTenantId());
|
|
|
+ // 获取用户昵称与真实姓名Map
|
|
|
+ Map<String, String> userNameNickNameMap = list.stream().collect(Collectors.toMap(SysUser::getUserName, SysUser::getNickName));
|
|
|
MceContent mceContent = new MceContent();
|
|
|
Integer contentId = 0;
|
|
|
|
|
@@ -288,7 +526,9 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
|
|
|
mceReceive1.setInfoType(mceReceiveVO.get("infoType").toString());
|
|
|
mceReceive1.setModuleId((int) mceReceiveVO.get("id"));
|
|
|
if (mceReceiveVO.containsKey("userName")) {
|
|
|
- mceReceive1.setIssuerName(mceReceiveVO.get("userName").toString());
|
|
|
+ String userName = mceReceiveVO.get("userName").toString();
|
|
|
+ String nickName = userNameNickNameMap.get(userName);
|
|
|
+ mceReceive1.setIssuerName(nickName);
|
|
|
}
|
|
|
mceReceive1.setReceiverName(list.get(i).getUserName());
|
|
|
mceReceive1.setCreateBy(mceReceiveVO.get("userName").toString());
|
|
@@ -336,7 +576,7 @@ public class MceReceiveServiceImpl extends AbstractCrudService<MceReceiveMapper,
|
|
|
@Override
|
|
|
public boolean removeById(Integer id) {
|
|
|
LambdaQueryWrapper<MceReceive> lambdaQuery = Wrappers.lambdaQuery();
|
|
|
- lambdaQuery.eq(MceReceive::getContentId,id);
|
|
|
+ lambdaQuery.eq(MceReceive::getContentId, id);
|
|
|
this.remove(lambdaQuery);
|
|
|
return mceContentService.removeById(id);
|
|
|
}
|