|
|
@@ -18,9 +18,11 @@ package org.springblade.ldt.notice.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
import org.springblade.common.enums.ReceiverType;
|
|
|
import org.springblade.common.enums.SenderType;
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
+import org.springblade.core.secure.BladeUser;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.ldt.mall.entity.Mall;
|
|
|
import org.springblade.ldt.mall.service.IMallService;
|
|
|
@@ -36,6 +38,7 @@ import org.springblade.ldt.user.service.ILoginUserService;
|
|
|
import org.springblade.ldt.user.service.IMemberService;
|
|
|
import org.springblade.modules.system.service.IUserService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
@@ -50,6 +53,7 @@ import java.util.stream.Collectors;
|
|
|
* @since 2021-11-03
|
|
|
*/
|
|
|
@Service
|
|
|
+@AllArgsConstructor
|
|
|
public class NoticeManagementServiceImpl extends BaseServiceImpl<NoticeManagementMapper, NoticeManagement> implements INoticeManagementService {
|
|
|
|
|
|
@Override
|
|
|
@@ -64,34 +68,50 @@ public class NoticeManagementServiceImpl extends BaseServiceImpl<NoticeManagemen
|
|
|
private ILoginUserService loginUserService;
|
|
|
|
|
|
@Override
|
|
|
- public R saveNotice(NoticeManagement notice) {
|
|
|
- Map<Long, String> receiver = new HashMap<>();
|
|
|
- if (notice.getReceiverType().equals(ReceiverType.MALL)) {//平台可发
|
|
|
- List<Mall> malls = mallService.list();
|
|
|
- receiver.putAll(malls.stream().collect(Collectors.toMap(Mall::getId, Mall::getMallName)));
|
|
|
+ @Transactional
|
|
|
+ public R saveNotice(NoticeManagementVO notice, BladeUser bladeUser) {
|
|
|
+ Mall mall = null;
|
|
|
+ if (notice.getSenderType().equals(SenderType.MALL)) {
|
|
|
+ mall = mallService.getOne(Wrappers.<Mall>lambdaQuery().eq(Mall::getTenantId, bladeUser.getTenantId()));
|
|
|
}
|
|
|
- if (notice.getReceiverType().equals(ReceiverType.SHOP)) {//平台,商场可发
|
|
|
- List<Shop> shops = shopService.list(Wrappers.<Shop>lambdaQuery()
|
|
|
- .eq(notice.getSenderType().equals(SenderType.MALL), Shop::getMallId, notice.getSenderId()));
|
|
|
- receiver.putAll(shops.stream().collect(Collectors.toMap(Shop::getId, Shop::getName)));
|
|
|
- }
|
|
|
- if (notice.getReceiverType().equals(ReceiverType.MEMBER)) {//商场可发
|
|
|
- List<Member> members = memberService.list();
|
|
|
- receiver.putAll(members.stream().collect(Collectors.toMap(Member::getId, Member::getNickName)));
|
|
|
- }
|
|
|
- if (notice.getReceiverType().equals(ReceiverType.CONSUMER)) {//平台可发
|
|
|
- List<LoginUser> loginUsers = loginUserService.list();
|
|
|
- receiver.putAll(loginUsers.stream().collect(Collectors.toMap(LoginUser::getId, LoginUser::getNickName)));
|
|
|
+ Map<ReceiverType, Map<Long, String>> receiver = new HashMap<>();
|
|
|
+ for (ReceiverType receiverType : notice.getReceiverTypes()) {
|
|
|
+ if (receiverType.equals(ReceiverType.MALL)) {//平台可发
|
|
|
+ List<Mall> malls = mallService.list();
|
|
|
+ receiver.put(ReceiverType.MALL, malls.stream().collect(Collectors.toMap(Mall::getId, Mall::getMallName)));
|
|
|
+ }
|
|
|
+ if (receiverType.equals(ReceiverType.SHOP)) {//平台,商场可发
|
|
|
+ List<Shop> shops = shopService.list(Wrappers.<Shop>lambdaQuery()
|
|
|
+ .eq(notice.getSenderType().equals(SenderType.MALL) && mall != null, Shop::getMallId, mall.getId()));
|
|
|
+ receiver.put(ReceiverType.SHOP, shops.stream().collect(Collectors.toMap(Shop::getId, Shop::getName)));
|
|
|
+ }
|
|
|
+ if (receiverType.equals(ReceiverType.MEMBER)) {//商场可发
|
|
|
+ List<Member> members = memberService.list(Wrappers.<Member>lambdaQuery().eq(mall != null, Member::getMallId, mall.getId()));
|
|
|
+ receiver.put(ReceiverType.MEMBER, members.stream().collect(Collectors.toMap(Member::getId, Member::getNickName)));
|
|
|
+ }
|
|
|
+ if (receiverType.equals(ReceiverType.CONSUMER)) {//平台可发
|
|
|
+ List<LoginUser> loginUsers = loginUserService.list();
|
|
|
+ receiver.put(ReceiverType.CONSUMER, loginUsers.stream().collect(Collectors.toMap(LoginUser::getId, LoginUser::getNickName)));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
List<NoticeManagement> notices = new ArrayList<>();
|
|
|
- for (Map.Entry<Long, String> item : receiver.entrySet()) {
|
|
|
- notice.setReceiver(item.getValue());
|
|
|
- notice.setReceiverId(item.getKey());
|
|
|
- notice.setIsRead(false);
|
|
|
- notices.add(notice);
|
|
|
+ for (Map.Entry<ReceiverType, Map<Long, String>> data : receiver.entrySet()) {
|
|
|
+ for (Map.Entry<Long, String> item : data.getValue().entrySet()) {
|
|
|
+ notice.setReceiver(item.getValue());
|
|
|
+ notice.setReceiverId(item.getKey());
|
|
|
+ notice.setReceiverType(data.getKey());
|
|
|
+ notice.setIsRead(false);
|
|
|
+ if (notice.getSenderType().equals(SenderType.MALL)) {
|
|
|
+ notice.setSenderId(mall.getId());
|
|
|
+ notice.setSender(mall.getMallName());
|
|
|
+ } else {
|
|
|
+ notice.setSenderId(bladeUser.getUserId());
|
|
|
+ notice.setSender("[平台]");
|
|
|
+ }
|
|
|
+ notices.add(notice);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
return R.data(saveBatch(notices));
|
|
|
}
|
|
|
|