diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/xkt/UserNoticeSettingController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/xkt/UserNoticeSettingController.java index 1527035e9..027b7fa99 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/xkt/UserNoticeSettingController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/xkt/UserNoticeSettingController.java @@ -1,19 +1,10 @@ package com.ruoyi.web.controller.xkt; -import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.XktBaseController; -import com.ruoyi.common.core.domain.R; -import com.ruoyi.common.core.page.TableDataInfo; -import com.ruoyi.common.enums.BusinessType; -import com.ruoyi.common.utils.poi.ExcelUtil; -import com.ruoyi.xkt.domain.UserNoticeSetting; import com.ruoyi.xkt.service.IUserNoticeSettingService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletResponse; -import java.util.List; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 用户通知接收设置Controller @@ -27,65 +18,4 @@ public class UserNoticeSettingController extends XktBaseController { @Autowired private IUserNoticeSettingService userNoticeSettingService; - /** - * 查询用户通知接收设置列表 - */ - // @PreAuthorize("@ss.hasPermi('system:setting:list')") - @GetMapping("/list") - public TableDataInfo list(UserNoticeSetting userNoticeSetting) { - startPage(); - List list = userNoticeSettingService.selectUserNoticeSettingList(userNoticeSetting); - return getDataTable(list); - } - - /** - * 导出用户通知接收设置列表 - */ - // @PreAuthorize("@ss.hasPermi('system:setting:export')") - @Log(title = "用户通知接收设置", businessType = BusinessType.EXPORT) - @PostMapping("/export") - public void export(HttpServletResponse response, UserNoticeSetting userNoticeSetting) { - List list = userNoticeSettingService.selectUserNoticeSettingList(userNoticeSetting); - ExcelUtil util = new ExcelUtil(UserNoticeSetting.class); - util.exportExcel(response, list, "用户通知接收设置数据"); - } - - /** - * 获取用户通知接收设置详细信息 - */ - // @PreAuthorize("@ss.hasPermi('system:setting:query')") - @GetMapping(value = "/{userNoticeSetId}") - public R getInfo(@PathVariable("userNoticeSetId") Long userNoticeSetId) { - return success(userNoticeSettingService.selectUserNoticeSettingByUserNoticeSetId(userNoticeSetId)); - } - - /** - * 新增用户通知接收设置 - */ - // @PreAuthorize("@ss.hasPermi('system:setting:add')") - @Log(title = "用户通知接收设置", businessType = BusinessType.INSERT) - @PostMapping - public R add(@RequestBody UserNoticeSetting userNoticeSetting) { - return success(userNoticeSettingService.insertUserNoticeSetting(userNoticeSetting)); - } - - /** - * 修改用户通知接收设置 - */ - // @PreAuthorize("@ss.hasPermi('system:setting:edit')") - @Log(title = "用户通知接收设置", businessType = BusinessType.UPDATE) - @PutMapping - public R edit(@RequestBody UserNoticeSetting userNoticeSetting) { - return success(userNoticeSettingService.updateUserNoticeSetting(userNoticeSetting)); - } - - /** - * 删除用户通知接收设置 - */ - // @PreAuthorize("@ss.hasPermi('system:setting:remove')") - @Log(title = "用户通知接收设置", businessType = BusinessType.DELETE) - @DeleteMapping("/{userNoticeSetIds}") - public R remove(@PathVariable Long[] userNoticeSetIds) { - return success(userNoticeSettingService.deleteUserNoticeSettingByUserNoticeSetIds(userNoticeSetIds)); - } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/xkt/vo/storeProd/StoreProdStatusVO.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/xkt/vo/storeProd/StoreProdStatusVO.java index 5a433de66..dac650a7c 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/xkt/vo/storeProd/StoreProdStatusVO.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/xkt/vo/storeProd/StoreProdStatusVO.java @@ -16,6 +16,9 @@ import java.util.List; @Data public class StoreProdStatusVO { + @NotNull(message = "档口ID不能为空!") + @ApiModelProperty(value = "档口ID", required = true) + private Long storeId; @NotNull(message = "档口商品ID不能为空!") @ApiModelProperty(value = "档口商品ID", required = true) private List storeProdIdList; diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheConstants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheConstants.java index d5dc601f4..72269677d 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheConstants.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheConstants.java @@ -253,5 +253,9 @@ public class CacheConstants { * 系统前20条热搜 */ public static final String SEARCH_HOT_KEY = "search_hot_key"; + /** + * 所有的推广 + */ + public static final String ADVERT_KEY = "advert:"; } diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/XktTask.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/XktTask.java index 8551291b9..d30caa059 100644 --- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/XktTask.java +++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/XktTask.java @@ -541,7 +541,7 @@ public class XktTask { } /** - * 通过定时任务(每天凌晨12:00:01秒)将store数据暂存到reidis中 + * 通过定时任务(每天凌晨12:00:01秒)将store数据暂存到redis中 */ public void saveStoreToRedis() { List storeList = this.storeMapper.selectList(new LambdaQueryWrapper() @@ -554,6 +554,19 @@ public class XktTask { }); } + /** + * 每天凌晨12:45:00秒 将advert的数据暂存到redis中 + */ + public void saveAdvertToRedis() { + List advertList = this.advertMapper.selectList(new LambdaQueryWrapper() + .eq(Advert::getDelFlag, Constants.UNDELETED)); + if (CollectionUtils.isEmpty(advertList)) { + return; + } + advertList.forEach(advert -> + redisCache.setCacheObject(CacheConstants.ADVERT_KEY + advert.getId(), advert, 1, TimeUnit.DAYS)); + } + /** * 凌晨00:00:30通过定时任务将symbol存放到redis中 */ @@ -576,6 +589,8 @@ public class XktTask { // 搜图服务同步 // sync2ImgSearchServer(storeProd.getId(), storeProdDTO.getFileList()); + // 新增档口商品动态、关注档口用户 通知公告 + } /** diff --git a/xkt/src/main/java/com/ruoyi/xkt/domain/UserNotice.java b/xkt/src/main/java/com/ruoyi/xkt/domain/UserNotice.java index 06752e829..ccf448f23 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/domain/UserNotice.java +++ b/xkt/src/main/java/com/ruoyi/xkt/domain/UserNotice.java @@ -3,8 +3,10 @@ package com.ruoyi.xkt.domain; import com.baomidou.mybatisplus.annotation.TableId; import com.fasterxml.jackson.annotation.JsonFormat; import com.ruoyi.common.core.domain.XktBaseEntity; +import lombok.Builder; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; import java.util.Date; @@ -16,6 +18,7 @@ import java.util.Date; */ @EqualsAndHashCode(callSuper = true) @Data +@Accessors(chain = true) public class UserNotice extends XktBaseEntity { private static final long serialVersionUID = 1L; @@ -36,6 +39,11 @@ public class UserNotice extends XktBaseEntity { */ private Long userId; + /** + * 目标公告类型 + */ + private Integer targetNoticeType; + /** * (0未读 1已读) */ diff --git a/xkt/src/main/java/com/ruoyi/xkt/domain/UserNoticeSetting.java b/xkt/src/main/java/com/ruoyi/xkt/domain/UserNoticeSetting.java index d9d8af832..3db7c4399 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/domain/UserNoticeSetting.java +++ b/xkt/src/main/java/com/ruoyi/xkt/domain/UserNoticeSetting.java @@ -5,8 +5,6 @@ import com.ruoyi.common.core.domain.XktBaseEntity; import lombok.Data; import lombok.EqualsAndHashCode; -import java.util.Date; - /** * 用户通知接收设置对象 user_notice_setting * @@ -43,25 +41,5 @@ public class UserNoticeSetting extends XktBaseEntity { * [电商卖家]是否允许接收收藏商品消息通知 0不接收 1接收 */ private Integer favoriteNotice; - /** - * [档口]是否允许接收广告消息通知 0不接收 1接收 - */ - private Integer advertNotice; - /** - * [档口]是否允许接收商品消息通知 0不接收 1接收 - */ - private Integer prodNotice; - /** - * [档口]是否允许接收短信通知 0不接收 1接收 - */ - private Integer smsNotice; - /** - * [档口]接收短信通知开始时间 yyyy-MM-dd HH:mm - */ - private Date smsNoticeStart; - /** - * [档口]接收短信通知结束时间 yyyy-MM-dd HH:mm - */ - private Date smsNoticeEnd; } diff --git a/xkt/src/main/java/com/ruoyi/xkt/dto/storeProduct/StoreProdStatusDTO.java b/xkt/src/main/java/com/ruoyi/xkt/dto/storeProduct/StoreProdStatusDTO.java index 9ade8b7c6..62ceb4fca 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/dto/storeProduct/StoreProdStatusDTO.java +++ b/xkt/src/main/java/com/ruoyi/xkt/dto/storeProduct/StoreProdStatusDTO.java @@ -15,6 +15,8 @@ import java.util.List; @Data public class StoreProdStatusDTO { + @ApiModelProperty(value = "档口ID") + private Long storeId; @ApiModelProperty("档口商品名称") private List storeProdIdList; @ApiModelProperty("档口商品状态") diff --git a/xkt/src/main/java/com/ruoyi/xkt/enums/NoticeReadType.java b/xkt/src/main/java/com/ruoyi/xkt/enums/NoticeReadType.java index 5b83d5e25..1e9936499 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/enums/NoticeReadType.java +++ b/xkt/src/main/java/com/ruoyi/xkt/enums/NoticeReadType.java @@ -6,7 +6,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; /** - * 推广营销展示类型 + * 通知公告阅读状态枚举 * * @author liujiang * @date 2025-04-02 23:42 @@ -32,6 +32,6 @@ public enum NoticeReadType { return e; } } - throw new ServiceException("营销推广展示类型不存在!", HttpStatus.ERROR); + throw new ServiceException("通知公告阅读类型不存在!", HttpStatus.ERROR); } } diff --git a/xkt/src/main/java/com/ruoyi/xkt/enums/NoticeReceiveType.java b/xkt/src/main/java/com/ruoyi/xkt/enums/NoticeReceiveType.java new file mode 100644 index 000000000..3d8b7d0b1 --- /dev/null +++ b/xkt/src/main/java/com/ruoyi/xkt/enums/NoticeReceiveType.java @@ -0,0 +1,37 @@ +package com.ruoyi.xkt.enums; + +import com.ruoyi.common.constant.HttpStatus; +import com.ruoyi.common.exception.ServiceException; +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 通知公告接收类型 + * + * @author liujiang + * @date 2025-04-02 23:42 + */ +@Getter +@AllArgsConstructor +public enum NoticeReceiveType { + + // 不接收 + UN_RECEIVE(0, "不接收"), + // 接收 + RECEIVE(1, "接收"), + + + ; + + private final Integer value; + private final String label; + + public static NoticeReceiveType of(Integer value) { + for (NoticeReceiveType e : NoticeReceiveType.values()) { + if (e.getValue().equals(value)) { + return e; + } + } + throw new ServiceException("通知公告接收类型不存在!", HttpStatus.ERROR); + } +} diff --git a/xkt/src/main/java/com/ruoyi/xkt/enums/NoticeType.java b/xkt/src/main/java/com/ruoyi/xkt/enums/NoticeType.java new file mode 100644 index 000000000..5cab024f2 --- /dev/null +++ b/xkt/src/main/java/com/ruoyi/xkt/enums/NoticeType.java @@ -0,0 +1,37 @@ +package com.ruoyi.xkt.enums; + +import com.ruoyi.common.constant.HttpStatus; +import com.ruoyi.common.exception.ServiceException; +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 通知公告类型 + * + * @author liujiang + * @date 2025-04-02 23:42 + */ +@Getter +@AllArgsConstructor +public enum NoticeType { + + // 通知 + NOTICE(1, "通知"), + // 公告 + ANNOUNCEMENT(2, "公告"), + + + ; + + private final Integer value; + private final String label; + + public static NoticeType of(Integer value) { + for (NoticeType e : NoticeType.values()) { + if (e.getValue().equals(value)) { + return e; + } + } + throw new ServiceException("通知公告类型不存在!", HttpStatus.ERROR); + } +} diff --git a/xkt/src/main/java/com/ruoyi/xkt/enums/UserNoticeType.java b/xkt/src/main/java/com/ruoyi/xkt/enums/UserNoticeType.java new file mode 100644 index 000000000..d75e56f6c --- /dev/null +++ b/xkt/src/main/java/com/ruoyi/xkt/enums/UserNoticeType.java @@ -0,0 +1,44 @@ +package com.ruoyi.xkt.enums; + +import com.ruoyi.common.constant.HttpStatus; +import com.ruoyi.common.exception.ServiceException; +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 通知公告类型 + * + * @author liujiang + * @date 2025-04-02 23:42 + */ +@Getter +@AllArgsConstructor +public enum UserNoticeType { + + // 系统消息 + SYSTEM_MSG(1, "系统消息"), + // 代发订单 + DELIVERY_ORDER(2, "代发订单"), + // 关注档口 + FOCUS_STORE(3, "关注档口"), + // 收藏商品 + FAVORITE_PRODUCT(4, "收藏商品"), + // 推广营销 + ADVERT(5, "推广营销"), + // 商品动态 + PRODUCT_DYNAMIC(6, "商品动态"), + + ; + + private final Integer value; + private final String label; + + public static UserNoticeType of(Integer value) { + for (UserNoticeType e : UserNoticeType.values()) { + if (e.getValue().equals(value)) { + return e; + } + } + throw new ServiceException("通知公告类型不存在!", HttpStatus.ERROR); + } +} diff --git a/xkt/src/main/java/com/ruoyi/xkt/mapper/UserNoticeSettingMapper.java b/xkt/src/main/java/com/ruoyi/xkt/mapper/UserNoticeSettingMapper.java index 4c98d9c3d..871aaafc1 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/mapper/UserNoticeSettingMapper.java +++ b/xkt/src/main/java/com/ruoyi/xkt/mapper/UserNoticeSettingMapper.java @@ -12,51 +12,5 @@ import java.util.List; * @date 2025-03-26 */ public interface UserNoticeSettingMapper extends BaseMapper { - /** - * 查询用户通知接收设置 - * - * @param id 用户通知接收设置主键 - * @return 用户通知接收设置 - */ - public UserNoticeSetting selectUserNoticeSettingByUserNoticeSetId(Long id); - /** - * 查询用户通知接收设置列表 - * - * @param userNoticeSetting 用户通知接收设置 - * @return 用户通知接收设置集合 - */ - public List selectUserNoticeSettingList(UserNoticeSetting userNoticeSetting); - - /** - * 新增用户通知接收设置 - * - * @param userNoticeSetting 用户通知接收设置 - * @return 结果 - */ - public int insertUserNoticeSetting(UserNoticeSetting userNoticeSetting); - - /** - * 修改用户通知接收设置 - * - * @param userNoticeSetting 用户通知接收设置 - * @return 结果 - */ - public int updateUserNoticeSetting(UserNoticeSetting userNoticeSetting); - - /** - * 删除用户通知接收设置 - * - * @param id 用户通知接收设置主键 - * @return 结果 - */ - public int deleteUserNoticeSettingByUserNoticeSetId(Long id); - - /** - * 批量删除用户通知接收设置 - * - * @param userNoticeSetIds 需要删除的数据主键集合 - * @return 结果 - */ - public int deleteUserNoticeSettingByUserNoticeSetIds(Long[] userNoticeSetIds); } diff --git a/xkt/src/main/java/com/ruoyi/xkt/service/INoticeService.java b/xkt/src/main/java/com/ruoyi/xkt/service/INoticeService.java index 6b75a8280..5620b7953 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/service/INoticeService.java +++ b/xkt/src/main/java/com/ruoyi/xkt/service/INoticeService.java @@ -49,4 +49,19 @@ public interface INoticeService { * @return Page */ Page page(NoticePageDTO pageDTO); + + /** + * 创建单个通知 + * + * @param userId 被通知的userId + * @param title 标题 + * @param noticeType NoticeType + * @param ownerType NoticeOwnerType + * @param storeId 档口ID + * @param targetNoticeType 目标通知类型 + * @param content 通知内容 + * @return 新增成功条数 + */ + Integer createSingleNotice(Long userId, String title, Integer noticeType, Integer ownerType, + Long storeId, Integer targetNoticeType, String content); } diff --git a/xkt/src/main/java/com/ruoyi/xkt/service/IUserNoticeSettingService.java b/xkt/src/main/java/com/ruoyi/xkt/service/IUserNoticeSettingService.java index f7e0f8b73..1086876c8 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/service/IUserNoticeSettingService.java +++ b/xkt/src/main/java/com/ruoyi/xkt/service/IUserNoticeSettingService.java @@ -1,9 +1,5 @@ package com.ruoyi.xkt.service; -import com.ruoyi.xkt.domain.UserNoticeSetting; - -import java.util.List; - /** * 用户通知接收设置Service接口 * @@ -11,51 +7,5 @@ import java.util.List; * @date 2025-03-26 */ public interface IUserNoticeSettingService { - /** - * 查询用户通知接收设置 - * - * @param userNoticeSetId 用户通知接收设置主键 - * @return 用户通知接收设置 - */ - public UserNoticeSetting selectUserNoticeSettingByUserNoticeSetId(Long userNoticeSetId); - /** - * 查询用户通知接收设置列表 - * - * @param userNoticeSetting 用户通知接收设置 - * @return 用户通知接收设置集合 - */ - public List selectUserNoticeSettingList(UserNoticeSetting userNoticeSetting); - - /** - * 新增用户通知接收设置 - * - * @param userNoticeSetting 用户通知接收设置 - * @return 结果 - */ - public int insertUserNoticeSetting(UserNoticeSetting userNoticeSetting); - - /** - * 修改用户通知接收设置 - * - * @param userNoticeSetting 用户通知接收设置 - * @return 结果 - */ - public int updateUserNoticeSetting(UserNoticeSetting userNoticeSetting); - - /** - * 批量删除用户通知接收设置 - * - * @param userNoticeSetIds 需要删除的用户通知接收设置主键集合 - * @return 结果 - */ - public int deleteUserNoticeSettingByUserNoticeSetIds(Long[] userNoticeSetIds); - - /** - * 删除用户通知接收设置信息 - * - * @param userNoticeSetId 用户通知接收设置主键 - * @return 结果 - */ - public int deleteUserNoticeSettingByUserNoticeSetId(Long userNoticeSetId); } diff --git a/xkt/src/main/java/com/ruoyi/xkt/service/impl/AdvertRoundServiceImpl.java b/xkt/src/main/java/com/ruoyi/xkt/service/impl/AdvertRoundServiceImpl.java index 06de8789d..7c1ec2f64 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/service/impl/AdvertRoundServiceImpl.java +++ b/xkt/src/main/java/com/ruoyi/xkt/service/impl/AdvertRoundServiceImpl.java @@ -12,12 +12,14 @@ import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.enums.AdType; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.xkt.domain.*; import com.ruoyi.xkt.dto.advertRound.*; import com.ruoyi.xkt.enums.*; import com.ruoyi.xkt.mapper.*; import com.ruoyi.xkt.service.IAdvertRoundService; import com.ruoyi.xkt.service.IAssetService; +import com.ruoyi.xkt.service.INoticeService; import lombok.RequiredArgsConstructor; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; @@ -61,6 +63,8 @@ public class AdvertRoundServiceImpl implements IAdvertRoundService { final StoreProductMapper storeProdMapper; final SysFileMapper fileMapper; final IAssetService assetService; + final INoticeService noticeService; + // 推广营销位锁 key:symbol + roundId 或者 symbol + roundId + position 。value都是new Object() public static Map advertLockMap = new ConcurrentHashMap<>(); @@ -330,7 +334,8 @@ public class AdvertRoundServiceImpl implements IAdvertRoundService { if (DateUtils.getTime().compareTo(this.getDeadline(createDTO.getSymbol())) > 0) { throw new ServiceException("竞价失败,已经有档口出价更高了噢!", HttpStatus.ERROR); } - if (ObjectUtils.isEmpty(redisCache.getCacheObject(CacheConstants.STORE_KEY + createDTO.getStoreId()))) { + Store store = redisCache.getCacheObject(CacheConstants.STORE_KEY + createDTO.getStoreId()); + if (ObjectUtils.isEmpty(store)) { throw new ServiceException("档口不存在!", HttpStatus.ERROR); } // 如果是位置枚举的推广位,则需要传position @@ -366,12 +371,20 @@ public class AdvertRoundServiceImpl implements IAdvertRoundService { if (createDTO.getPayPrice().compareTo(ObjectUtils.defaultIfNull(minPriceAdvert.getPayPrice(), BigDecimal.ZERO)) <= 0) { throw new ServiceException("已经有档口出价更高了噢,请重新出价!", HttpStatus.ERROR); } + Advert advert = redisCache.getCacheObject(CacheConstants.ADVERT_KEY + createDTO.getAdvertId()); + final String position = Objects.equals(minPriceAdvert.getShowType(), AdShowType.TIME_RANGE.getValue()) ? "" : minPriceAdvert.getPosition(); // storeId不为空,表明之前有其他的档口竞价 if (ObjectUtils.isNotEmpty(minPriceAdvert.getStoreId())) { // 将推广费退至原档口余额 assetService.refundAdvertFee(minPriceAdvert.getStoreId(), minPriceAdvert.getPayPrice()); // 记录竞价失败的档口推广营销 this.record(minPriceAdvert); + final String failTitle = ObjectUtils.isNotEmpty(advert) ? AdType.of(advert.getTypeId()).getLabel() : "" + position + "被抢占!"; + final String failContent = "您抢购的 " + (ObjectUtils.isNotEmpty(advert) ? AdType.of(advert.getTypeId()).getLabel() : "") + position + + " 被其它档口抢拍,订购金额已退回余额!您可在抢购结束前加价抢回噢!"; + // 新增竞价失败档口消息通知 + this.noticeService.createSingleNotice(SecurityUtils.getUserId(), failTitle, NoticeType.NOTICE.getValue(), NoticeOwnerType.SYSTEM.getValue(), + minPriceAdvert.getStoreId(), UserNoticeType.ADVERT.getValue(), failContent); } // 更新广告位数据 minPriceAdvert @@ -385,6 +398,13 @@ public class AdvertRoundServiceImpl implements IAdvertRoundService { .setPicAuditStatus(this.hasPic(minPriceAdvert.getDisplayType()) ? AdPicAuditStatus.UN_AUDIT.getValue() : null) .setProdIdStr(createDTO.getProdIdStr()); this.advertRoundMapper.updateById(minPriceAdvert); + final String successTitle = ObjectUtils.isNotEmpty(advert) ? AdType.of(advert.getTypeId()).getLabel() : "" + position + "订购成功!"; + final String successContent = ObjectUtils.isNotEmpty(store) ? store.getStoreName() : "" + " ,恭喜您!您成功订购 " + + (ObjectUtils.isNotEmpty(advert) ? AdType.of(advert.getTypeId()).getLabel() : "") + position + + "播放时间段为" + minPriceAdvert.getStartTime() + "至" + minPriceAdvert.getEndTime() + ",请确保推广设置正确噢!"; + // 新增订购成功的消息通知 + this.noticeService.createSingleNotice(SecurityUtils.getUserId(), successTitle, NoticeType.NOTICE.getValue(), NoticeOwnerType.SYSTEM.getValue(), + minPriceAdvert.getStoreId(), UserNoticeType.ADVERT.getValue(), successContent); // 扣除推广费 assetService.payAdvertFee(createDTO.getStoreId(), createDTO.getPayPrice(), createDTO.getTransactionPassword()); } @@ -392,7 +412,6 @@ public class AdvertRoundServiceImpl implements IAdvertRoundService { } - /** * 档口已订购推广列表 * @@ -555,7 +574,6 @@ public class AdvertRoundServiceImpl implements IAdvertRoundService { } - /** * @param picDTO 档口上传推广图 或 修改商品 * @return Integer @@ -850,6 +868,7 @@ public class AdvertRoundServiceImpl implements IAdvertRoundService { /** * 判断当前推广类型是否为 推广图 或者 图及商品类型 + * * @param displayType 推广类型 * @return true 是 false 不是 */ diff --git a/xkt/src/main/java/com/ruoyi/xkt/service/impl/NoticeServiceImpl.java b/xkt/src/main/java/com/ruoyi/xkt/service/impl/NoticeServiceImpl.java index 018f0ebf3..266a71932 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/service/impl/NoticeServiceImpl.java +++ b/xkt/src/main/java/com/ruoyi/xkt/service/impl/NoticeServiceImpl.java @@ -6,20 +6,19 @@ 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.mapper.NoticeMapper; -import com.ruoyi.xkt.mapper.UserFavoritesMapper; -import com.ruoyi.xkt.mapper.UserNoticeMapper; -import com.ruoyi.xkt.mapper.UserSubscriptionsMapper; +import com.ruoyi.xkt.enums.NoticeReceiveType; +import com.ruoyi.xkt.enums.UserNoticeType; +import com.ruoyi.xkt.mapper.*; import com.ruoyi.xkt.service.INoticeService; import lombok.RequiredArgsConstructor; import org.apache.commons.collections4.CollectionUtils; @@ -49,6 +48,7 @@ public class NoticeServiceImpl implements INoticeService { final UserFavoritesMapper userFavMapper; final UserNoticeMapper userNoticeMapper; final SysUserMapper userMapper; + final UserNoticeSettingMapper userNoticeSetMapper; /** * 新增公告 @@ -68,20 +68,19 @@ public class NoticeServiceImpl implements INoticeService { // 档口发的公告,则发送给关注档口用户 ? this.userSubMapper.selectUserFocusList(notice.getStoreId()) // 系统发的公告,则发送给所有用户 - : this.userMapper.selectList(new LambdaQueryWrapper().eq(SysUser::getDelFlag, Constants.UNDELETED)) - .stream().map(SysUser::getUserId).distinct().collect(Collectors.toList()); + : this.userNoticeSetMapper.selectList(new LambdaQueryWrapper() + .eq(UserNoticeSetting::getSysMsgNotice, NoticeReceiveType.RECEIVE.getValue()) + .eq(UserNoticeSetting::getDelFlag, Constants.UNDELETED)).stream() + .map(UserNoticeSetting::getUserId) + .collect(Collectors.toList()); if (CollectionUtils.isEmpty(userIdList)) { return 0; } // 往user_notice表插入数据 - List userNoticeList = userIdList.stream().map(userId -> { - UserNotice userNotice = new UserNotice(); - userNotice.setNoticeId(notice.getId()); - userNotice.setUserId(userId); - userNotice.setReadStatus(NoticeReadType.UN_READ.getValue()); - userNotice.setVoucherDate(voucherDate); - return userNotice; - }) + List userNoticeList = userIdList.stream().map(userId -> new UserNotice().setNoticeId(notice.getId()) + .setUserId(userId).setReadStatus(NoticeReadType.UN_READ.getValue()).setVoucherDate(voucherDate) + .setTargetNoticeType(Objects.equals(createDTO.getOwnerType(), NoticeOwnerType.STORE.getValue()) + ? UserNoticeType.FOCUS_STORE.getValue() : UserNoticeType.SYSTEM_MSG.getValue())) .collect(Collectors.toList()); this.userNoticeMapper.insert(userNoticeList); return count; @@ -187,5 +186,25 @@ public class NoticeServiceImpl implements INoticeService { } } + /** + * 创建单个通知 + * + * @param userId 被通知的userId + * @param title 标题 + * @param noticeType NoticeType + * @param ownerType NoticeOwnerType + * @param storeId 档口ID + * @param targetNoticeType 目标通知类型 + * @param content 通知内容 + * @return 新增成功条数 + */ + public Integer createSingleNotice(Long userId, String title, Integer noticeType, Integer ownerType, Long storeId, Integer targetNoticeType, String content) { + Notice notice = new Notice().setNoticeTitle(title).setNoticeType(noticeType).setOwnerType(ownerType) + .setStoreId(storeId).setUserId(userId).setPerpetuity(1).setNoticeContent(content); + this.noticeMapper.insert(notice); + return this.userNoticeMapper.insert(new UserNotice().setNoticeId(notice.getId()).setUserId(userId).setReadStatus(NoticeReadType.UN_READ.getValue()) + .setVoucherDate(java.sql.Date.valueOf(LocalDate.now())).setTargetNoticeType(targetNoticeType)); + } + } diff --git a/xkt/src/main/java/com/ruoyi/xkt/service/impl/StoreProductServiceImpl.java b/xkt/src/main/java/com/ruoyi/xkt/service/impl/StoreProductServiceImpl.java index 8df6761e1..9f0d56efd 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/service/impl/StoreProductServiceImpl.java +++ b/xkt/src/main/java/com/ruoyi/xkt/service/impl/StoreProductServiceImpl.java @@ -42,10 +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.enums.EProductStatus; -import com.ruoyi.xkt.enums.FileType; -import com.ruoyi.xkt.enums.ListingType; -import com.ruoyi.xkt.enums.ProductSizeStatus; +import com.ruoyi.xkt.enums.*; import com.ruoyi.xkt.mapper.*; import com.ruoyi.xkt.service.IPictureService; import com.ruoyi.xkt.service.IStoreProductService; @@ -59,6 +56,7 @@ import org.springframework.transaction.annotation.Transactional; import java.io.IOException; import java.math.BigDecimal; +import java.time.LocalDate; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; @@ -100,7 +98,9 @@ public class StoreProductServiceImpl implements IStoreProductService { final StoreProductStatisticsMapper storeProductStatisticsMapper; final StoreHomepageMapper storeHomepageMapper; final RedisCache redisCache; - + final NoticeMapper noticeMapper; + final UserNoticeSettingMapper userNoticeSetMapper; + final UserNoticeMapper userNoticeMapper; /** * 查询档口商品 @@ -234,6 +234,8 @@ public class StoreProductServiceImpl implements IStoreProductService { this.createESDoc(storeProd, storeProdDTO); // 搜图服务同步 sync2ImgSearchServer(storeProd.getId(), storeProdDTO.getFileList()); + // 新增档口商品动态、关注档口通知公告 + this.createNotice(storeProd, storeProdDTO.getStoreName()); } return count; } @@ -290,6 +292,8 @@ public class StoreProductServiceImpl implements IStoreProductService { this.updateESDoc(storeProd, storeProdDTO); // 搜图服务同步 sync2ImgSearchServer(storeProd.getId(), storeProdDTO.getFileList()); + // 更新档口商品动态、关注档口、收藏商品通知公告 + this.updateNotice(storeProd, storeProdDTO.getStoreName()); } return count; } @@ -451,9 +455,12 @@ public class StoreProductServiceImpl implements IStoreProductService { this.storeProdMapper.updateById(storeProdList); // 筛选商品状态为已下架,则删除ES文档 if (Objects.equals(prodStatusDTO.getProdStatus(), EProductStatus.OFF_SALE.getValue())) { + // 删除ES中商品 this.deleteESDoc(prodStatusDTO.getStoreProdIdList()); // 搜图服务同步 prodStatusDTO.getStoreProdIdList().forEach(spId -> sync2ImgSearchServer(spId, ListUtil.empty())); + // 新增消息通知 + this.offSaleOrReSaleProd(storeProdList, Boolean.TRUE, prodStatusDTO.getStoreId()); } // 已下架的商品重新上架 if (CollectionUtils.isNotEmpty(reSaleList)) { @@ -466,9 +473,12 @@ public class StoreProductServiceImpl implements IStoreProductService { Collectors.mapping(StoreProdMainPicDTO::getFileUrl, Collectors.toList()))); prodStatusDTO.getStoreProdIdList() .forEach(spId -> sync2ImgSearchServer(spId, picKeyGroupMap.get(spId), true)); + // 新增消息通知 + this.offSaleOrReSaleProd(storeProdList, Boolean.FALSE, prodStatusDTO.getStoreId()); } } + /** * 根据档口ID和商品货号模糊查询货号列表 * @@ -995,5 +1005,114 @@ public class StoreProductServiceImpl implements IStoreProductService { this.redisCache.setCacheObject(CacheConstants.USER_BROWSING_HISTORY + SecurityUtils.getUserId(), browsingList); } + /** + * 新增商品时,新增系统通知 + * + * @param storeProd 档口商品 + * @param storeName 档口名称 + */ + private void createNotice(StoreProduct storeProd, String storeName) { + // 新增档口 商品动态 通知公告 + Long userId = SecurityUtils.getUserId(); + // 新增一条档口消息通知 + Notice notice = new Notice().setNoticeTitle(storeName + "商品上新啦!").setNoticeType(NoticeType.NOTICE.getValue()) + .setNoticeContent(storeName + "上新了货号为: " + storeProd.getProdArtNum() + " 的商品!请及时关注!") + .setOwnerType(NoticeOwnerType.STORE.getValue()).setStoreId(storeProd.getStoreId()) + .setUserId(userId).setPerpetuity(1); + this.noticeMapper.insert(notice); + final Date voucherDate = java.sql.Date.valueOf(LocalDate.now()); + // 新增消息通知列表 + List userNoticeList = new ArrayList<>(); + // 新增档口商品动态 + userNoticeList.add(new UserNotice().setNoticeId(notice.getId()) + .setUserId(userId).setReadStatus(NoticeReadType.UN_READ.getValue()).setVoucherDate(voucherDate) + .setTargetNoticeType(UserNoticeType.PRODUCT_DYNAMIC.getValue())); + List focusList = this.userNoticeSetMapper.selectList(new LambdaQueryWrapper() + .isNotNull(UserNoticeSetting::getFocusNotice)); + if (CollectionUtils.isNotEmpty(focusList)) { + focusList.forEach(x -> userNoticeList.add(new UserNotice().setNoticeId(notice.getId()) + .setUserId(x.getUserId()).setReadStatus(NoticeReadType.UN_READ.getValue()).setVoucherDate(voucherDate) + .setTargetNoticeType(UserNoticeType.FOCUS_STORE.getValue()))); + } + if (CollectionUtils.isEmpty(userNoticeList)) { + return; + } + this.userNoticeMapper.insert(userNoticeList); + } + + /** + * 更新商品 新增消息通知 + * + * @param storeProd 档口商品 + * @param storeName 档口名称 + */ + private void updateNotice(StoreProduct storeProd, String storeName) { + // 新增档口 商品动态 通知公告 + Long userId = SecurityUtils.getUserId(); + // 新增一条档口消息通知 + Notice notice = new Notice().setNoticeTitle(storeName + "商品更新啦!").setNoticeType(NoticeType.NOTICE.getValue()) + .setNoticeContent(storeName + "更新了货号为: " + storeProd.getProdArtNum() + " 的商品!请及时关注!") + .setOwnerType(NoticeOwnerType.STORE.getValue()).setStoreId(storeProd.getStoreId()) + .setUserId(userId).setPerpetuity(1); + this.noticeMapper.insert(notice); + final Date voucherDate = java.sql.Date.valueOf(LocalDate.now()); + // 新增消息通知列表 + List userNoticeList = new ArrayList<>(); + userNoticeList.add(new UserNotice().setNoticeId(notice.getId()) + .setUserId(userId).setReadStatus(NoticeReadType.UN_READ.getValue()).setVoucherDate(voucherDate) + .setTargetNoticeType(UserNoticeType.PRODUCT_DYNAMIC.getValue())); + // 关注档口或者收藏商品的用户 + List targetList = this.userNoticeSetMapper.selectList(new LambdaQueryWrapper() + .isNotNull(UserNoticeSetting::getFocusNotice).or().isNotNull(UserNoticeSetting::getFavoriteNotice)); + 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()))); + } + if (CollectionUtils.isEmpty(userNoticeList)) { + return; + } + this.userNoticeMapper.insert(userNoticeList); + } + + /** + * 下架或重新上架商品时,新增消息列表 + * + * @param storeProdList 档口商品列表 + * @param offSale true 下架商品 false 重新上架商品 + * @param storeId 档口ID + */ + private void offSaleOrReSaleProd(List storeProdList, Boolean offSale, Long storeId) { + // 新增档口 商品动态 通知公告 + Long userId = SecurityUtils.getUserId(); + Store store = redisCache.getCacheObject(CacheConstants.STORE_KEY + storeId); + // 新增消息通知列表 + List userNoticeList = new ArrayList<>(); + final Date voucherDate = java.sql.Date.valueOf(LocalDate.now()); + storeProdList.forEach(storeProd -> { + // 新增一条档口消息通知 + Notice notice = new Notice().setNoticeType(NoticeType.NOTICE.getValue()).setUserId(userId).setPerpetuity(1) + .setOwnerType(NoticeOwnerType.STORE.getValue()).setStoreId(storeProd.getStoreId()) + .setNoticeTitle(ObjectUtils.isNotEmpty(store) ? store.getStoreName() : "" + "商品" + (offSale ? "下架" : "重新上架") + "啦!") + .setNoticeContent(ObjectUtils.isNotEmpty(store) ? store.getStoreName() : "" + (offSale ? "下架" : "重新上架") + + "了货号为: " + storeProd.getProdArtNum() + " 的商品!请及时关注!"); + this.noticeMapper.insert(notice); + // 关注档口或者收藏商品的用户 + List targetList = this.userNoticeSetMapper.selectList(new LambdaQueryWrapper() + .isNotNull(UserNoticeSetting::getFocusNotice).or().isNotNull(UserNoticeSetting::getFavoriteNotice)); + 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()))); + } + }); + if (CollectionUtils.isEmpty(userNoticeList)) { + return; + } + this.userNoticeMapper.insert(userNoticeList); + } + } diff --git a/xkt/src/main/java/com/ruoyi/xkt/service/impl/UserFavoritesServiceImpl.java b/xkt/src/main/java/com/ruoyi/xkt/service/impl/UserFavoritesServiceImpl.java index b6b67b77c..3175c46e0 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/service/impl/UserFavoritesServiceImpl.java +++ b/xkt/src/main/java/com/ruoyi/xkt/service/impl/UserFavoritesServiceImpl.java @@ -13,9 +13,9 @@ import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.xkt.domain.*; import com.ruoyi.xkt.dto.storeProductFile.StoreProdMainPicDTO; import com.ruoyi.xkt.dto.userFavorite.*; -import com.ruoyi.xkt.enums.FileType; -import com.ruoyi.xkt.enums.ProductSizeStatus; +import com.ruoyi.xkt.enums.*; import com.ruoyi.xkt.mapper.*; +import com.ruoyi.xkt.service.INoticeService; import com.ruoyi.xkt.service.IUserFavoritesService; import lombok.RequiredArgsConstructor; import org.apache.commons.collections4.CollectionUtils; @@ -48,6 +48,10 @@ public class UserFavoritesServiceImpl implements IUserFavoritesService { final StoreProductColorPriceMapper prodColorPriceMapper; final StoreProductColorMapper prodColorMapper; final ShoppingCartDetailMapper shopCartDetailMapper; + final StoreMapper storeMapper; + final INoticeService noticeService; + final StoreProductMapper storeProdMapper; + /** * 新增用户收藏商品 @@ -73,7 +77,26 @@ public class UserFavoritesServiceImpl implements IUserFavoritesService { .filter(x -> CollectionUtils.isNotEmpty(existStoreProdIdList) ? !existStoreProdIdList.contains(x.getStoreProdId()) : Boolean.TRUE) .map(x -> BeanUtil.toBean(x, UserFavorites.class).setUserId(loginUser.getUserId())) .collect(Collectors.toList()); - return this.userFavMapper.insert(list).size(); + int count = this.userFavMapper.insert(list).size(); + Map storeMap = this.storeMapper.selectList(new LambdaQueryWrapper() + .in(Store::getId, list.stream().map(UserFavorites::getStoreId).collect(Collectors.toList())) + .eq(Store::getDelFlag, Constants.UNDELETED)).stream() + .collect(Collectors.toMap(Store::getId, Function.identity())); + Map storeProdMap = this.storeProdMapper.selectList(new LambdaQueryWrapper() + .in(StoreProduct::getId, list.stream().map(UserFavorites::getStoreProdId).collect(Collectors.toList())) + .eq(StoreProduct::getDelFlag, Constants.UNDELETED)).stream() + .collect(Collectors.toMap(StoreProduct::getId, Function.identity())); + // 新增用户收藏商品通知 + list.forEach(userFav -> { + StoreProduct storeProd = storeProdMap.get(userFav.getStoreProdId()); + Store store = storeMap.get(userFav.getStoreId()); + // 新增用户收藏商品消息通知 + this.noticeService.createSingleNotice(SecurityUtils.getUserId(), "收藏商品成功!", NoticeType.NOTICE.getValue(), NoticeOwnerType.SYSTEM.getValue(), + userFav.getStoreId(), UserNoticeType.FAVORITE_PRODUCT.getValue(), + "恭喜您,收藏" + (ObjectUtils.isNotEmpty(store) ? store.getStoreName() : "") + " 家商品: " + + (ObjectUtils.isNotEmpty(storeProd) ? storeProd.getProdArtNum() : "") + "成功!"); + }); + return count; } /** @@ -206,7 +229,26 @@ public class UserFavoritesServiceImpl implements IUserFavoritesService { return 0; } favoriteList.forEach(x -> x.setDelFlag(Constants.DELETED)); - return this.userFavMapper.updateById(favoriteList).size(); + int count = this.userFavMapper.updateById(favoriteList).size(); + Map storeMap = this.storeMapper.selectList(new LambdaQueryWrapper() + .in(Store::getId, favoriteList.stream().map(UserFavorites::getStoreId).collect(Collectors.toList())) + .eq(Store::getDelFlag, Constants.UNDELETED)).stream() + .collect(Collectors.toMap(Store::getId, Function.identity())); + Map storeProdMap = this.storeProdMapper.selectList(new LambdaQueryWrapper() + .in(StoreProduct::getId, favoriteList.stream().map(UserFavorites::getStoreProdId).collect(Collectors.toList())) + .eq(StoreProduct::getDelFlag, Constants.UNDELETED)).stream() + .collect(Collectors.toMap(StoreProduct::getId, Function.identity())); + // 新增用户取消收藏商品通知 + favoriteList.forEach(userFav -> { + StoreProduct storeProd = storeProdMap.get(userFav.getStoreProdId()); + Store store = storeMap.get(userFav.getStoreId()); + // 新增用户取消收藏商品消息通知 + this.noticeService.createSingleNotice(SecurityUtils.getUserId(), "取消收藏商品!", NoticeType.NOTICE.getValue(), NoticeOwnerType.SYSTEM.getValue(), + userFav.getStoreId(), UserNoticeType.FAVORITE_PRODUCT.getValue(), + "您已取消收藏" + (ObjectUtils.isNotEmpty(store) ? store.getStoreName() : "") + " 家商品: " + + (ObjectUtils.isNotEmpty(storeProd) ? storeProd.getProdArtNum() : "") + "!"); + }); + return count; } diff --git a/xkt/src/main/java/com/ruoyi/xkt/service/impl/UserNoticeSettingServiceImpl.java b/xkt/src/main/java/com/ruoyi/xkt/service/impl/UserNoticeSettingServiceImpl.java index 719e7db08..7f5654afc 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/service/impl/UserNoticeSettingServiceImpl.java +++ b/xkt/src/main/java/com/ruoyi/xkt/service/impl/UserNoticeSettingServiceImpl.java @@ -1,14 +1,9 @@ package com.ruoyi.xkt.service.impl; -import com.ruoyi.common.utils.DateUtils; -import com.ruoyi.xkt.domain.UserNoticeSetting; import com.ruoyi.xkt.mapper.UserNoticeSettingMapper; import com.ruoyi.xkt.service.IUserNoticeSettingService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; /** * 用户通知接收设置Service业务层处理 @@ -18,76 +13,9 @@ import java.util.List; */ @Service public class UserNoticeSettingServiceImpl implements IUserNoticeSettingService { + @Autowired private UserNoticeSettingMapper userNoticeSettingMapper; - /** - * 查询用户通知接收设置 - * - * @param userNoticeSetId 用户通知接收设置主键 - * @return 用户通知接收设置 - */ - @Override - public UserNoticeSetting selectUserNoticeSettingByUserNoticeSetId(Long userNoticeSetId) { - return userNoticeSettingMapper.selectUserNoticeSettingByUserNoticeSetId(userNoticeSetId); - } - /** - * 查询用户通知接收设置列表 - * - * @param userNoticeSetting 用户通知接收设置 - * @return 用户通知接收设置 - */ - @Override - public List selectUserNoticeSettingList(UserNoticeSetting userNoticeSetting) { - return userNoticeSettingMapper.selectUserNoticeSettingList(userNoticeSetting); - } - - /** - * 新增用户通知接收设置 - * - * @param userNoticeSetting 用户通知接收设置 - * @return 结果 - */ - @Override - @Transactional - public int insertUserNoticeSetting(UserNoticeSetting userNoticeSetting) { - userNoticeSetting.setCreateTime(DateUtils.getNowDate()); - return userNoticeSettingMapper.insertUserNoticeSetting(userNoticeSetting); - } - - /** - * 修改用户通知接收设置 - * - * @param userNoticeSetting 用户通知接收设置 - * @return 结果 - */ - @Override - @Transactional - public int updateUserNoticeSetting(UserNoticeSetting userNoticeSetting) { - userNoticeSetting.setUpdateTime(DateUtils.getNowDate()); - return userNoticeSettingMapper.updateUserNoticeSetting(userNoticeSetting); - } - - /** - * 批量删除用户通知接收设置 - * - * @param userNoticeSetIds 需要删除的用户通知接收设置主键 - * @return 结果 - */ - @Override - public int deleteUserNoticeSettingByUserNoticeSetIds(Long[] userNoticeSetIds) { - return userNoticeSettingMapper.deleteUserNoticeSettingByUserNoticeSetIds(userNoticeSetIds); - } - - /** - * 删除用户通知接收设置信息 - * - * @param userNoticeSetId 用户通知接收设置主键 - * @return 结果 - */ - @Override - public int deleteUserNoticeSettingByUserNoticeSetId(Long userNoticeSetId) { - return userNoticeSettingMapper.deleteUserNoticeSettingByUserNoticeSetId(userNoticeSetId); - } } diff --git a/xkt/src/main/java/com/ruoyi/xkt/service/impl/UserSubscriptionsServiceImpl.java b/xkt/src/main/java/com/ruoyi/xkt/service/impl/UserSubscriptionsServiceImpl.java index b92f0c154..927085c3c 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/service/impl/UserSubscriptionsServiceImpl.java +++ b/xkt/src/main/java/com/ruoyi/xkt/service/impl/UserSubscriptionsServiceImpl.java @@ -9,6 +9,7 @@ import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.core.page.Page; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.xkt.domain.Store; import com.ruoyi.xkt.domain.StoreProduct; import com.ruoyi.xkt.domain.StoreSale; import com.ruoyi.xkt.domain.UserSubscriptions; @@ -16,9 +17,14 @@ import com.ruoyi.xkt.dto.userSubscriptions.UserSubscDTO; import com.ruoyi.xkt.dto.userSubscriptions.UserSubscDeleteDTO; import com.ruoyi.xkt.dto.userSubscriptions.UserSubscPageDTO; import com.ruoyi.xkt.dto.userSubscriptions.UserSubscPageResDTO; +import com.ruoyi.xkt.enums.NoticeOwnerType; +import com.ruoyi.xkt.enums.NoticeType; +import com.ruoyi.xkt.enums.UserNoticeType; +import com.ruoyi.xkt.mapper.StoreMapper; import com.ruoyi.xkt.mapper.StoreProductMapper; import com.ruoyi.xkt.mapper.StoreSaleMapper; import com.ruoyi.xkt.mapper.UserSubscriptionsMapper; +import com.ruoyi.xkt.service.INoticeService; import com.ruoyi.xkt.service.IUserSubscriptionsService; import lombok.RequiredArgsConstructor; import org.apache.commons.collections4.CollectionUtils; @@ -31,6 +37,7 @@ import java.util.Date; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -43,9 +50,11 @@ import java.util.stream.Collectors; @Service public class UserSubscriptionsServiceImpl implements IUserSubscriptionsService { - final UserSubscriptionsMapper userSubscMapper; + final UserSubscriptionsMapper userSubMapper; final StoreSaleMapper saleMapper; final StoreProductMapper storeProdMapper; + final INoticeService noticeService; + final StoreMapper storeMapper; /** @@ -60,7 +69,7 @@ public class UserSubscriptionsServiceImpl implements IUserSubscriptionsService { // 获取当前登录用户 LoginUser loginUser = SecurityUtils.getLoginUser(); // 判断是否已关注过 - UserSubscriptions exist = this.userSubscMapper.selectOne(new LambdaQueryWrapper() + UserSubscriptions exist = this.userSubMapper.selectOne(new LambdaQueryWrapper() .eq(UserSubscriptions::getUserId, loginUser.getUserId()).eq(UserSubscriptions::getStoreId, subscDTO.getStoreId()) .eq(UserSubscriptions::getDelFlag, Constants.UNDELETED)); if (ObjectUtils.isNotEmpty(exist)) { @@ -69,7 +78,14 @@ public class UserSubscriptionsServiceImpl implements IUserSubscriptionsService { UserSubscriptions userSubscriptions = new UserSubscriptions(); userSubscriptions.setUserId(loginUser.getUserId()); userSubscriptions.setStoreId(subscDTO.getStoreId()); - return this.userSubscMapper.insert(userSubscriptions); + int count = this.userSubMapper.insert(userSubscriptions); + Store store = Optional.ofNullable(this.storeMapper.selectOne(new LambdaQueryWrapper() + .eq(Store::getId, subscDTO.getStoreId()).eq(Store::getDelFlag, Constants.UNDELETED))) + .orElseThrow(() -> new ServiceException("档口不存在!", HttpStatus.ERROR)); + // 新增用户关注档口消息通知 + this.noticeService.createSingleNotice(SecurityUtils.getUserId(), "关注档口成功!", NoticeType.NOTICE.getValue(), NoticeOwnerType.SYSTEM.getValue(), + subscDTO.getStoreId(), UserNoticeType.FOCUS_STORE.getValue(), "恭喜您,关注档口: " + store.getStoreName() + "成功!"); + return count; } /** @@ -83,13 +99,23 @@ public class UserSubscriptionsServiceImpl implements IUserSubscriptionsService { public Integer delete(UserSubscDeleteDTO deleteDTO) { // 获取当前登录用户 LoginUser loginUser = SecurityUtils.getLoginUser(); - List list = Optional.ofNullable(this.userSubscMapper.selectList(new LambdaQueryWrapper() + List list = Optional.ofNullable(this.userSubMapper.selectList(new LambdaQueryWrapper() .eq(UserSubscriptions::getUserId, loginUser.getUserId()) .in(UserSubscriptions::getStoreId, deleteDTO.getStoreIdList()) .eq(UserSubscriptions::getDelFlag, Constants.UNDELETED))) .orElseThrow(() -> new ServiceException("用户关注档口不存在!", HttpStatus.ERROR)); list.forEach(x -> x.setDelFlag(Constants.DELETED)); - return this.userSubscMapper.updateById(list).size(); + int count = this.userSubMapper.updateById(list).size(); + Map storeMap = this.storeMapper.selectList(new LambdaQueryWrapper() + .in(Store::getId, deleteDTO.getStoreIdList()).eq(Store::getDelFlag, Constants.UNDELETED)).stream() + .collect(Collectors.toMap(Store::getId, Function.identity())); + list.forEach(x -> { + Store store = storeMap.get(x.getStoreId()); + // 用户取消关注档口消息通知 + this.noticeService.createSingleNotice(SecurityUtils.getUserId(), "取消关注档口!", NoticeType.NOTICE.getValue(), NoticeOwnerType.SYSTEM.getValue(), + store.getId(), UserNoticeType.FOCUS_STORE.getValue(), "您已取消关注档口: " + store.getStoreName() + " !"); + }); + return count; } /** @@ -104,7 +130,7 @@ public class UserSubscriptionsServiceImpl implements IUserSubscriptionsService { // 获取当前登录用户 LoginUser loginUser = SecurityUtils.getLoginUser(); PageHelper.startPage(pageDTO.getPageNum(), pageDTO.getPageSize()); - List list = this.userSubscMapper.selectUserSubscPage(loginUser.getUserId(), pageDTO.getStoreName()); + List list = this.userSubMapper.selectUserSubscPage(loginUser.getUserId(), pageDTO.getStoreName()); if (CollectionUtils.isEmpty(list)) { return Page.empty(pageDTO.getPageNum(), pageDTO.getPageSize()); } diff --git a/xkt/src/main/resources/mapper/UserNoticeSettingMapper.xml b/xkt/src/main/resources/mapper/UserNoticeSettingMapper.xml index ca3fbb072..d5d15e359 100644 --- a/xkt/src/main/resources/mapper/UserNoticeSettingMapper.xml +++ b/xkt/src/main/resources/mapper/UserNoticeSettingMapper.xml @@ -1,91 +1,7 @@ + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - - - - - - - - - - - - - - - select id, user_id, notice_type, allow, version, del_flag, create_by, create_time, update_by, update_time from user_notice_setting - - - - - - - - insert into user_notice_setting - - user_id, - notice_type, - allow, - version, - del_flag, - create_by, - create_time, - update_by, - update_time, - - - #{userId}, - #{noticeType}, - #{allow}, - #{version}, - #{delFlag}, - #{createBy}, - #{createTime}, - #{updateBy}, - #{updateTime}, - - - - - update user_notice_setting - - user_id = #{userId}, - notice_type = #{noticeType}, - allow = #{allow}, - version = #{version}, - del_flag = #{delFlag}, - create_by = #{createBy}, - create_time = #{createTime}, - update_by = #{updateBy}, - update_time = #{updateTime}, - - where id = #{id} - - - - delete from user_notice_setting where id = #{id} - - - - delete from user_notice_setting where id in - - #{id} - - \ No newline at end of file