master:用户消息功能完善;

pull/1121/head
liujiang 2025-06-06 23:58:57 +08:00
parent 29cd8a5241
commit 9be91d4537
23 changed files with 538 additions and 33 deletions

View File

@ -43,7 +43,6 @@ public class NoticeController extends BaseController {
}
@ApiOperation(value = "公告详情(档口公告、系统公告)", httpMethod = "PUT", response = R.class)
@Log(title = "公告详情", businessType = BusinessType.UPDATE)
@GetMapping("/{noticeId}")
public R<NoticeResVO> getInfo(@PathVariable Long noticeId) {
return R.ok(BeanUtil.toBean(noticeService.getInfo(noticeId), NoticeResVO.class));
@ -56,7 +55,7 @@ public class NoticeController extends BaseController {
return R.ok(noticeService.delete(BeanUtil.toBean(deleteVO, NoticeDeleteDTO.class)));
}
@ApiOperation(value = "查询公告列表 ", httpMethod = "POST", response = R.class)
@ApiOperation(value = "档口公告列表、系统公告列表 ", httpMethod = "POST", response = R.class)
@PostMapping("/page")
public R<Page<NoticeResDTO>> page(@Validated @RequestBody NoticePageVO pageVO) {
return R.ok(noticeService.page(BeanUtil.toBean(pageVO, NoticePageDTO.class)));

View File

@ -1,8 +1,24 @@
package com.ruoyi.web.controller.xkt;
import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.core.controller.XktBaseController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.Page;
import com.ruoyi.web.controller.xkt.vo.userNotice.UserNoticeAppListResVO;
import com.ruoyi.web.controller.xkt.vo.userNotice.UserNoticeAppTypePageVO;
import com.ruoyi.web.controller.xkt.vo.userNotice.UserNoticePageVO;
import com.ruoyi.xkt.dto.userNotice.UserNoticeAppResDTO;
import com.ruoyi.xkt.dto.userNotice.UserNoticeAppTypePageDTO;
import com.ruoyi.xkt.dto.userNotice.UserNoticePageDTO;
import com.ruoyi.xkt.dto.userNotice.UserNoticeResDTO;
import com.ruoyi.xkt.service.IUserNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* Controller
@ -10,8 +26,30 @@ import org.springframework.web.bind.annotation.RestController;
* @author ruoyi
* @date 2025-03-26
*/
@Api(tags = "用户所有通知")
@RestController
@RequiredArgsConstructor
@RequestMapping("/rest/v1/user-notices")
public class UserNoticeController extends XktBaseController {
final IUserNoticeService userNoticeService;
@ApiOperation(value = "PC - 电商卖家消息列表", httpMethod = "POST", response = R.class)
@PostMapping("/pc/page")
public R<Page<UserNoticeResDTO>> pcPage(@Validated @RequestBody UserNoticePageVO pageVO) {
return R.ok(userNoticeService.pcPage(BeanUtil.toBean(pageVO, UserNoticePageDTO.class)));
}
@ApiOperation(value = "APP - 电商卖家消息列表", httpMethod = "GET", response = R.class)
@GetMapping("/app/list")
public R<List<UserNoticeAppListResVO>> appList() {
return R.ok(BeanUtil.copyToList(userNoticeService.appList(), UserNoticeAppListResVO.class));
}
@ApiOperation(value = "APP - 获取某一个类型消息列表", httpMethod = "POST", response = R.class)
@PostMapping("/app/type/page")
public R<Page<UserNoticeAppResDTO>> appTypePage(@Validated @RequestBody UserNoticeAppTypePageVO pageVO) {
return R.ok(userNoticeService.appTypePage(BeanUtil.toBean(pageVO, UserNoticeAppTypePageDTO.class)));
}
}

View File

@ -6,17 +6,22 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
/**
* @author liujiang
* @version v1.0
* @date 2025/3/27 15:12
*/
@EqualsAndHashCode(callSuper = true)
@ApiModel("公告分页查询入参")
@ApiModel("档口消息、系统消息分页查询入参")
@Data
public class NoticePageVO extends BasePageVO {
@ApiModelProperty(value = "公告标题")
private String noticeTitle;
@NotNull(message = "ownerType不能为空")
@ApiModelProperty(value = "谁发的公告 1 档口 2 系统")
private Integer ownerType;
}

View File

@ -0,0 +1,33 @@
package com.ruoyi.web.controller.xkt.vo.userNotice;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* @author liujiang
* @version v1.0
* @date 2025/3/27 15:12
*/
@ApiModel("用户消息APP返回数据")
@Data
@Accessors(chain = true)
public class UserNoticeAppListResVO {
@ApiModelProperty(value = "用户通知类型")
private Integer targetNoticeType;
@ApiModelProperty(value = "用户通知类型名称")
private String targetNoticeTypeName;
@ApiModelProperty(value = "公告内容")
private String noticeContent;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "是否已读 0未读 1已读")
private Integer readStatus;
@ApiModelProperty(value = "公告状态 0不提醒 1提醒")
private Integer remindStatus;
}

View File

@ -0,0 +1,25 @@
package com.ruoyi.web.controller.xkt.vo.userNotice;
import com.ruoyi.web.controller.xkt.vo.BasePageVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
/**
* @author liujiang
* @version v1.0
* @date 2025/3/27 15:12
*/
@EqualsAndHashCode(callSuper = true)
@ApiModel("用户消息分页查询入参")
@Data
public class UserNoticeAppTypePageVO extends BasePageVO {
@NotNull(message = "消息接收类型不能为空")
@ApiModelProperty(value = "消息接收类型")
private Integer targetNoticeType;
}

View File

@ -0,0 +1,22 @@
package com.ruoyi.web.controller.xkt.vo.userNotice;
import com.ruoyi.web.controller.xkt.vo.BasePageVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author liujiang
* @version v1.0
* @date 2025/3/27 15:12
*/
@EqualsAndHashCode(callSuper = true)
@ApiModel("用户消息分页查询入参")
@Data
public class UserNoticePageVO extends BasePageVO {
@ApiModelProperty(value = "公告标题")
private String noticeTitle;
}

View File

@ -6,6 +6,8 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
/**
* @author liujiang
* @version v1.0
@ -18,5 +20,7 @@ public class NoticePageDTO extends BasePageDTO {
@ApiModelProperty(value = "公告标题")
private String noticeTitle;
@ApiModelProperty(value = "谁发的公告 1 档口 2 系统")
private Integer ownerType;
}

View File

@ -1,5 +1,6 @@
package com.ruoyi.xkt.dto.notice;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ -13,7 +14,7 @@ import java.util.Date;
* @version v1.0
* @date 2025/3/27 15:12
*/
@ApiModel("新增公告")
@ApiModel("消息返回数据")
@Data
@Accessors(chain = true)
public class NoticeResDTO {
@ -35,5 +36,7 @@ public class NoticeResDTO {
private Date effectEnd;
@ApiModelProperty(value = "是否永久生效 1不是 2是")
private Integer perpetuity;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
}

View File

@ -0,0 +1,23 @@
package com.ruoyi.xkt.dto.userNotice;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* @author liujiang
* @version v1.0
* @date 2025/3/27 15:12
*/
@ApiModel("用户关注档口或者收藏商品用户ID列表")
@Data
@Accessors(chain = true)
public class UserFocusAndFavUserIdDTO {
@ApiModelProperty(value = "用户接收消息类型")
private Integer targetNoticeType;
@ApiModelProperty(value = "用户ID")
private Long userId;
}

View File

@ -0,0 +1,33 @@
package com.ruoyi.xkt.dto.userNotice;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* @author liujiang
* @version v1.0
* @date 2025/3/27 15:12
*/
@ApiModel("用户消息APP返回数据")
@Data
@Accessors(chain = true)
public class UserNoticeAppListResDTO {
@ApiModelProperty(value = "用户通知类型")
private Integer targetNoticeType;
@ApiModelProperty(value = "用户通知类型名称")
private String targetNoticeTypeName;
@ApiModelProperty(value = "公告内容")
private String noticeContent;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "是否已读 0未读 1已读")
private Integer readStatus;
@ApiModelProperty(value = "公告状态 0不提醒 1提醒")
private Integer remindStatus;
}

View File

@ -0,0 +1,27 @@
package com.ruoyi.xkt.dto.userNotice;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* @author liujiang
* @version v1.0
* @date 2025/3/27 15:12
*/
@ApiModel("用户消息APP返回数据")
@Data
@Accessors(chain = true)
public class UserNoticeAppResDTO {
@ApiModelProperty(value = "公告标题")
private String noticeTitle;
@ApiModelProperty(value = "公告内容")
private String noticeContent;
@ApiModelProperty(value = "创建时间")
private Date createTime;
}

View File

@ -0,0 +1,24 @@
package com.ruoyi.xkt.dto.userNotice;
import com.ruoyi.xkt.dto.BasePageDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
/**
* @author liujiang
* @version v1.0
* @date 2025/3/27 15:12
*/
@EqualsAndHashCode(callSuper = true)
@ApiModel("用户消息分页查询入参")
@Data
public class UserNoticeAppTypePageDTO extends BasePageDTO {
@ApiModelProperty(value = "消息接收类型")
private Integer targetNoticeType;
}

View File

@ -0,0 +1,22 @@
package com.ruoyi.xkt.dto.userNotice;
import com.ruoyi.xkt.dto.BasePageDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author liujiang
* @version v1.0
* @date 2025/3/27 15:12
*/
@EqualsAndHashCode(callSuper = true)
@ApiModel("用户消息分页查询入参")
@Data
public class UserNoticePageDTO extends BasePageDTO {
@ApiModelProperty(value = "公告标题")
private String noticeTitle;
}

View File

@ -0,0 +1,41 @@
package com.ruoyi.xkt.dto.userNotice;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* @author liujiang
* @version v1.0
* @date 2025/3/27 15:12
*/
@ApiModel("用户消息返回数据")
@Data
@Accessors(chain = true)
public class UserNoticeResDTO {
@ApiModelProperty(value = "用户消息ID")
private Long userNoticeId;
@ApiModelProperty(value = "公告ID")
private Long noticeId;
@ApiModelProperty(value = "用户通知类型")
private Integer targetNoticeType;
@ApiModelProperty(value = "用户通知类型名称")
private String targetNoticeTypeName;
@ApiModelProperty(value = "公告标题")
private String noticeTitle;
@ApiModelProperty(value = "公告内容")
private String noticeContent;
@ApiModelProperty(value = "档口id")
private Long storeId;
@ApiModelProperty(value = "生效开始时间")
private Date effectStart;
@ApiModelProperty(value = "生效结束时间")
private Date effectEnd;
@ApiModelProperty(value = "是否永久生效 1不是 2是")
private Integer perpetuity;
}

View File

@ -6,7 +6,7 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
/**
*
*
*
* @author liujiang
* @date 2025-04-02 23:42
@ -39,6 +39,6 @@ public enum UserNoticeType {
return e;
}
}
throw new ServiceException("通知公告类型不存在!", HttpStatus.ERROR);
throw new ServiceException("用户接收通知公告类型不存在!", HttpStatus.ERROR);
}
}

View File

@ -2,6 +2,12 @@ package com.ruoyi.xkt.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.xkt.domain.UserNotice;
import com.ruoyi.xkt.dto.userNotice.UserNoticeAppListResDTO;
import com.ruoyi.xkt.dto.userNotice.UserNoticeAppResDTO;
import com.ruoyi.xkt.dto.userNotice.UserNoticeResDTO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* Mapper
@ -11,4 +17,28 @@ import com.ruoyi.xkt.domain.UserNotice;
*/
public interface UserNoticeMapper extends BaseMapper<UserNotice> {
/**
*
*
* @param userId ID
* @param noticeTitle
* @return
*/
List<UserNoticeResDTO> selectUserNoticeList(@Param("userId") Long userId, @Param("noticeTitle") String noticeTitle);
/**
* APP
*
* @param userId ID
* @return
*/
List<UserNoticeAppListResDTO> appList(Long userId);
/**
* APP
* @param userId ID
* @param targetNoticeType
* @return
*/
List<UserNoticeAppResDTO> selectAppTypePage(@Param("userId") Long userId, @Param("targetNoticeType") Integer targetNoticeType);
}

View File

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.xkt.domain.UserSubscriptions;
import com.ruoyi.xkt.dto.dailyStoreTag.DailyStoreTagDTO;
import com.ruoyi.xkt.dto.userIndex.UserOverallResDTO;
import com.ruoyi.xkt.dto.userNotice.UserFocusAndFavUserIdDTO;
import com.ruoyi.xkt.dto.userSubscriptions.UserSubscPageResDTO;
import org.apache.ibatis.annotations.Param;
@ -47,4 +48,12 @@ public interface UserSubscriptionsMapper extends BaseMapper<UserSubscriptions> {
* @return List<Long>
*/
List<Long> selectUserFocusList(Long storeId);
/**
* ID
* @param storeId ID
* @param storeProdId ID
* @return List<Long>
*/
List<UserFocusAndFavUserIdDTO> selectFocusAndFavUserIdList(@Param("storeId") Long storeId, @Param("storeProdId") Long storeProdId);
}

View File

@ -1,6 +1,7 @@
package com.ruoyi.xkt.service;
import com.ruoyi.xkt.domain.UserNotice;
import com.ruoyi.common.core.page.Page;
import com.ruoyi.xkt.dto.userNotice.*;
import java.util.List;
@ -12,4 +13,26 @@ import java.util.List;
*/
public interface IUserNoticeService {
/**
*
*
* @param pageDTO
* @return Page<UserNoticeResDTO>
*/
Page<UserNoticeResDTO> pcPage(UserNoticePageDTO pageDTO);
/**
* APP
*
* @return List<UserNoticeAppResDTO>
*/
List<UserNoticeAppListResDTO> appList();
/**
* APP
*
* @param pageDTO
* @return List<UserNoticeAppResDTO>
*/
Page<UserNoticeAppResDTO> appTypePage(UserNoticeAppTypePageDTO pageDTO);
}

View File

@ -6,17 +6,16 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.Page;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.xkt.domain.Notice;
import com.ruoyi.xkt.domain.UserNotice;
import com.ruoyi.xkt.domain.UserNoticeSetting;
import com.ruoyi.xkt.dto.notice.*;
import com.ruoyi.xkt.enums.NoticeOwnerType;
import com.ruoyi.xkt.enums.NoticeReadType;
import com.ruoyi.xkt.enums.NoticeReceiveType;
import com.ruoyi.xkt.enums.UserNoticeType;
import com.ruoyi.xkt.mapper.*;
import com.ruoyi.xkt.service.INoticeService;
@ -68,11 +67,8 @@ public class NoticeServiceImpl implements INoticeService {
// 档口发的公告,则发送给关注档口用户
? this.userSubMapper.selectUserFocusList(notice.getStoreId())
// 系统发的公告,则发送给所有用户
: this.userNoticeSetMapper.selectList(new LambdaQueryWrapper<UserNoticeSetting>()
.eq(UserNoticeSetting::getSysMsgNotice, NoticeReceiveType.RECEIVE.getValue())
.eq(UserNoticeSetting::getDelFlag, Constants.UNDELETED)).stream()
.map(UserNoticeSetting::getUserId)
.collect(Collectors.toList());
: this.userMapper.selectList(new LambdaQueryWrapper<SysUser>().eq(SysUser::getDelFlag, Constants.UNDELETED))
.stream().map(SysUser::getUserId).collect(Collectors.toList());
if (CollectionUtils.isEmpty(userIdList)) {
return 0;
}
@ -158,7 +154,7 @@ public class NoticeServiceImpl implements INoticeService {
@Transactional(readOnly = true)
public Page<NoticeResDTO> page(NoticePageDTO pageDTO) {
LambdaQueryWrapper<Notice> queryWrapper = new LambdaQueryWrapper<Notice>().eq(Notice::getDelFlag, Constants.UNDELETED)
.orderByDesc(Notice::getCreateTime);
.eq(Notice::getOwnerType, pageDTO.getOwnerType()).orderByDesc(Notice::getCreateTime);
if (StringUtils.isNotBlank(pageDTO.getNoticeTitle())) {
queryWrapper.like(Notice::getNoticeTitle, pageDTO.getNoticeTitle());
}

View File

@ -42,6 +42,7 @@ import com.ruoyi.xkt.dto.storeProductFile.StoreProdFileDTO;
import com.ruoyi.xkt.dto.storeProductFile.StoreProdFileResDTO;
import com.ruoyi.xkt.dto.storeProductFile.StoreProdMainPicDTO;
import com.ruoyi.xkt.dto.userBrowsingHistory.UserBrowsingHisDTO;
import com.ruoyi.xkt.dto.userNotice.UserFocusAndFavUserIdDTO;
import com.ruoyi.xkt.enums.*;
import com.ruoyi.xkt.mapper.*;
import com.ruoyi.xkt.service.IPictureService;
@ -101,6 +102,7 @@ public class StoreProductServiceImpl implements IStoreProductService {
final NoticeMapper noticeMapper;
final UserNoticeSettingMapper userNoticeSetMapper;
final UserNoticeMapper userNoticeMapper;
final UserSubscriptionsMapper userSubMapper;
/**
*
@ -1027,10 +1029,10 @@ public class StoreProductServiceImpl implements IStoreProductService {
userNoticeList.add(new UserNotice().setNoticeId(notice.getId())
.setUserId(userId).setReadStatus(NoticeReadType.UN_READ.getValue()).setVoucherDate(voucherDate)
.setTargetNoticeType(UserNoticeType.PRODUCT_DYNAMIC.getValue()));
List<UserNoticeSetting> focusList = this.userNoticeSetMapper.selectList(new LambdaQueryWrapper<UserNoticeSetting>()
.isNotNull(UserNoticeSetting::getFocusNotice));
if (CollectionUtils.isNotEmpty(focusList)) {
focusList.forEach(x -> userNoticeList.add(new UserNotice().setNoticeId(notice.getId())
List<UserSubscriptions> userSubList = this.userSubMapper.selectList(new LambdaQueryWrapper<UserSubscriptions>()
.eq(UserSubscriptions::getStoreId, storeProd.getStoreId()));
if (CollectionUtils.isNotEmpty(userSubList)) {
userSubList.forEach(x -> userNoticeList.add(new UserNotice().setNoticeId(notice.getId())
.setUserId(x.getUserId()).setReadStatus(NoticeReadType.UN_READ.getValue()).setVoucherDate(voucherDate)
.setTargetNoticeType(UserNoticeType.FOCUS_STORE.getValue())));
}
@ -1061,14 +1063,12 @@ public class StoreProductServiceImpl implements IStoreProductService {
userNoticeList.add(new UserNotice().setNoticeId(notice.getId())
.setUserId(userId).setReadStatus(NoticeReadType.UN_READ.getValue()).setVoucherDate(voucherDate)
.setTargetNoticeType(UserNoticeType.PRODUCT_DYNAMIC.getValue()));
// 关注档口或者收藏商品的用户
List<UserNoticeSetting> targetList = this.userNoticeSetMapper.selectList(new LambdaQueryWrapper<UserNoticeSetting>()
.isNotNull(UserNoticeSetting::getFocusNotice).or().isNotNull(UserNoticeSetting::getFavoriteNotice));
// 关注档口 或 收藏商品用户
List<UserFocusAndFavUserIdDTO> targetList = this.userSubMapper.selectFocusAndFavUserIdList(storeProd.getStoreId(), storeProd.getId());
if (CollectionUtils.isNotEmpty(targetList)) {
targetList.forEach(x -> userNoticeList.add(new UserNotice().setNoticeId(notice.getId())
.setUserId(x.getUserId()).setReadStatus(NoticeReadType.UN_READ.getValue()).setVoucherDate(voucherDate)
.setTargetNoticeType(Objects.equals(x.getFocusNotice(), NoticeReceiveType.RECEIVE.getValue())
? UserNoticeType.FOCUS_STORE.getValue() : UserNoticeType.FAVORITE_PRODUCT.getValue())));
targetList.forEach(target -> userNoticeList.add(new UserNotice().setNoticeId(notice.getId())
.setUserId(target.getUserId()).setReadStatus(NoticeReadType.UN_READ.getValue()).setVoucherDate(voucherDate)
.setTargetNoticeType(target.getTargetNoticeType())));
}
if (CollectionUtils.isEmpty(userNoticeList)) {
return;
@ -1098,14 +1098,12 @@ public class StoreProductServiceImpl implements IStoreProductService {
.setNoticeContent(ObjectUtils.isNotEmpty(store) ? store.getStoreName() : "" + (offSale ? "下架" : "重新上架")
+ "了货号为: " + storeProd.getProdArtNum() + " 的商品!请及时关注!");
this.noticeMapper.insert(notice);
// 关注档口或者收藏商品的用户
List<UserNoticeSetting> targetList = this.userNoticeSetMapper.selectList(new LambdaQueryWrapper<UserNoticeSetting>()
.isNotNull(UserNoticeSetting::getFocusNotice).or().isNotNull(UserNoticeSetting::getFavoriteNotice));
// 关注档口 或 收藏商品用户
List<UserFocusAndFavUserIdDTO> targetList = this.userSubMapper.selectFocusAndFavUserIdList(storeProd.getStoreId(), storeProd.getId());
if (CollectionUtils.isNotEmpty(targetList)) {
targetList.forEach(x -> userNoticeList.add(new UserNotice().setNoticeId(notice.getId())
.setUserId(x.getUserId()).setReadStatus(NoticeReadType.UN_READ.getValue()).setVoucherDate(voucherDate)
.setTargetNoticeType(Objects.equals(x.getFocusNotice(), NoticeReceiveType.RECEIVE.getValue())
? UserNoticeType.FOCUS_STORE.getValue() : UserNoticeType.FAVORITE_PRODUCT.getValue())));
.setTargetNoticeType(x.getTargetNoticeType())));
}
});
if (CollectionUtils.isEmpty(userNoticeList)) {

View File

@ -1,7 +1,23 @@
package com.ruoyi.xkt.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.page.Page;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.xkt.dto.userNotice.*;
import com.ruoyi.xkt.enums.UserNoticeType;
import com.ruoyi.xkt.mapper.UserNoticeMapper;
import com.ruoyi.xkt.service.IUserNoticeService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* Service
@ -10,6 +26,59 @@ import org.springframework.stereotype.Service;
* @date 2025-03-26
*/
@Service
@RequiredArgsConstructor
public class UserNoticeServiceImpl implements IUserNoticeService {
final UserNoticeMapper userNoticeMapper;
/**
*
*
* @param pageDTO
* @return Page<UserNoticeResDTO>
*/
@Override
@Transactional(readOnly = true)
public Page<UserNoticeResDTO> pcPage(UserNoticePageDTO pageDTO) {
PageHelper.startPage(pageDTO.getPageNum(), pageDTO.getPageSize());
List<UserNoticeResDTO> list = this.userNoticeMapper.selectUserNoticeList(SecurityUtils.getUserId(), pageDTO.getNoticeTitle());
list.forEach(x -> x.setTargetNoticeTypeName(UserNoticeType.of(x.getTargetNoticeType()).getLabel()));
return Page.convert(new PageInfo<>(list));
}
/**
* APP
*
* @return List<UserNoticeAppResDTO>
*/
@Override
@Transactional(readOnly = true)
public List<UserNoticeAppListResDTO> appList() {
List<UserNoticeAppListResDTO> appList = this.userNoticeMapper.appList(SecurityUtils.getUserId());
if (CollectionUtils.isEmpty(appList)) {
return Collections.emptyList();
}
return appList.stream().collect(Collectors.groupingBy(UserNoticeAppListResDTO::getTargetNoticeType,
Collectors.maxBy(Comparator.comparing(UserNoticeAppListResDTO::getCreateTime))))
.values().stream()
.filter(Optional::isPresent)
.map(Optional::get)
.map(x -> x.setTargetNoticeTypeName(UserNoticeType.of(x.getTargetNoticeType()).getLabel()))
.collect(Collectors.toList());
}
/**
* APP
*
* @param pageDTO
* @return List<UserNoticeAppResDTO>
*/
@Override
@Transactional(readOnly = true)
public Page<UserNoticeAppResDTO> appTypePage(UserNoticeAppTypePageDTO pageDTO) {
PageHelper.startPage(pageDTO.getPageNum(), pageDTO.getPageSize());
List<UserNoticeAppResDTO> list = this.userNoticeMapper.selectAppTypePage(SecurityUtils.getUserId(), pageDTO.getTargetNoticeType());
return Page.convert(new PageInfo<>(list));
}
}

View File

@ -4,4 +4,71 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.xkt.mapper.UserNoticeMapper">
<select id="selectUserNoticeList" resultType="com.ruoyi.xkt.dto.userNotice.UserNoticeResDTO">
SELECT
un.id AS userNoticeId,
n.id AS noticeId,
un.target_notice_type,
n.notice_title,
n.notice_content,
n.store_id,
n.effect_start,
n.effect_end,
n.perpetuity
FROM
user_notice un
LEFT JOIN notice n ON un.notice_id = n.id
WHERE
un.del_flag = 0
<if test="noticeTitle != null and noticeTitle != ''">
AND n.notice_title LIKE concat('%', #{noticeTitle}, '%')
</if>
AND un.user_id = #{userId}
ORDER BY
un.create_time DESC,
un.target_notice_type
</select>
<select id="appList" resultType="com.ruoyi.xkt.dto.userNotice.UserNoticeAppListResDTO">
SELECT
un.target_notice_type,
n.notice_content,
un.create_time,
un.read_status,
CASE
un.target_notice_type
WHEN 1 THEN
uns.sys_msg_notice
WHEN 2 THEN
uns.order_notice
WHEN 3 THEN
uns.focus_notice
WHEN 4 THEN
uns.favorite_notice
END AS remindStatus
FROM
user_notice un
LEFT JOIN user_notice_setting uns ON un.user_id = uns.user_id
LEFT JOIN notice n ON un.notice_id = n.id
WHERE
un.del_flag = 0
AND un.user_id = #{userId}
</select>
<select id="selectAppTypePage" resultType="com.ruoyi.xkt.dto.userNotice.UserNoticeAppResDTO">
SELECT
n.notice_title,
n.notice_content,
un.create_time
FROM
user_notice un
LEFT JOIN notice n ON un.notice_id = n.id
WHERE
un.del_flag = 0
AND un.target_notice_type = #{targetNoticeType}
AND un.user_id = #{userId}
ORDER BY
un.create_time DESC
</select>
</mapper>

View File

@ -68,5 +68,19 @@
AND uns.focus_notice = 1
</select>
<select id="selectFocusAndFavUserIdList" resultType="com.ruoyi.xkt.dto.userNotice.UserFocusAndFavUserIdDTO">
SELECT us.user_id, 3 AS targetNoticeType
FROM user_subscriptions us
WHERE us.del_flag = 0
AND us.store_id = ?
UNION
SELECT uf.user_id , 4 AS targetNoticeType
FROM user_favorites uf
WHERE uf.del_flag = 0
AND uf.store_prod_id = ?
</select>
</mapper>