Quellcode durchsuchen

用户系统消息

zoujiajian vor 2 Jahren
Ursprung
Commit
e0209d576d

+ 4 - 0
netflix-common/src/main/java/com/cyksj/common/constant/Constant.java

@@ -250,4 +250,8 @@ public interface Constant {
 	 * 获客链接 值班客服更新定时任务id
 	 */
 	Integer CORP_LINK_JOB_ID = 192;
+
+	String ACCOUNT_PWD_UPDATE_SYS_MSG_NOTIFY = "您购买的%s,密码已修改";
+
+	String ACCOUNT_SET_SYS_MSG_NOTIFY = "您购买的%s,账号已配置";
 }

+ 21 - 0
netflix-dao/src/main/java/com/cyksj/mapper/UserSysMsgNotifyMapper.java

@@ -0,0 +1,21 @@
+package com.cyksj.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.GroupsRelation;
+import com.cyksj.model.entity.UserSysMsgNotify;
+import com.cyksj.model.manage.views.GroupsRelationView;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: UserSysMsgNotifyMapper
+ * 创建者: JavaZou
+ * 创建时间:2024/2/4 16:02
+ */
+public interface UserSysMsgNotifyMapper extends BaseMapper<UserSysMsgNotify> {
+	void recordUserAccountUpdateSysMsg(@Param("goodsId") Long goodsId, @Param("skuId") Long skuId, @Param("list") List<GroupsRelationView> relations, @Param("account") String account, @Param("msg") String msg);
+
+	void recordUserAccountSetSysMsg(@Param("goodsId") Long goodsId, @Param("skuId") Long skuId, @Param("collect") List<GroupsRelation> collect, @Param("account") String account, @Param("msg") String msg);
+}

+ 30 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/UserSysMsgNotify.java

@@ -0,0 +1,30 @@
+package com.cyksj.model.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: UserSysMsgNotify
+ * 创建者: JavaZou
+ * 创建时间:2024/2/4 16:01
+ */
+@Getter
+@Setter
+public class UserSysMsgNotify extends BaseEntity{
+	private Long goodsId;
+
+	private Long skuId;
+
+	private Long userId;
+
+	private Long relationId;
+
+	private String account;
+
+	private String msg;
+
+	private Boolean isView;
+
+	private Boolean deleted;
+}

+ 23 - 0
netflix-dao/src/main/resources/mapper/UserSysMsgNotifyMapper.xml

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.cyksj.mapper.UserSysMsgNotifyMapper">
+
+    <insert id="recordUserAccountUpdateSysMsg">
+        insert into
+        user_sys_msg_notify(`goods_id`,`sku_id`,`user_id`,`relation_id`,`account`,`msg`,`created_time`,`update_time`)
+        values
+        <foreach collection="userSet" item="item" separator=",">
+            (#{goodsId},#{skuId},#{item.userId},#{item.id},#{account},#{msg},now(),now())
+        </foreach>
+    </insert>
+
+    <insert id="recordUserAccountSetSysMsg">
+        insert into
+        user_sys_msg_notify(`goods_id`,`sku_id`,`user_id`,`relation_id`,`account`,`msg`,`created_time`,`update_time`)
+        values
+        <foreach collection="userSet" item="item" separator=",">
+            (#{goodsId},#{skuId},#{item.userId},#{item.id},#{account},#{msg},now(),now())
+        </foreach>
+    </insert>
+</mapper>

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/mange/CmsGroupService.java

@@ -20,5 +20,5 @@ public interface CmsGroupService extends IService<GroupsTrips> {
 
 	Integer getAvailableRelation(Long goodsId, Long skuId);
 
-    void sendChangeAccountMsg(Long groupsId, Long goodsId);
+    void sendChangeAccountMsg(Long groupsId, Long goodsId, String account);
 }

+ 16 - 3
netflix-service/src/main/java/com/cyksj/service/mange/group/CmsGroupServiceImpl.java

@@ -1,5 +1,6 @@
 package com.cyksj.service.mange.group;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateField;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
@@ -16,12 +17,14 @@ import com.cyksj.mapper.manage.GroupsTripsAccountReplaceRecordMapper;
 import com.cyksj.mapper.manage.cms.CmsUserMapper;
 import com.cyksj.model.entity.*;
 import com.cyksj.model.manage.views.AccountView;
+import com.cyksj.model.manage.views.GroupsRelationView;
 import com.cyksj.model.request.ReplaceTripsAccountReq;
 import com.cyksj.model.views.GroupsAccountView;
 import com.cyksj.redis.RedisService;
 import com.cyksj.service.mange.AccountCommonService;
 import com.cyksj.service.mange.CmsGroupService;
 import com.cyksj.service.sms.SmsService;
+import com.cyksj.service.user.UserSysMsgNotifyService;
 import com.ejlchina.searcher.BeanSearcher;
 import com.ejlchina.searcher.param.Operator;
 import com.ejlchina.searcher.util.MapBuilder;
@@ -74,6 +77,8 @@ public class CmsGroupServiceImpl extends ServiceImpl<GroupsMapper,GroupsTrips> i
 
     private final GroupsRelationAlertMapper alertMapper;
 
+    private final UserSysMsgNotifyService userSysMsgNotifyService;
+
     private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
 
 
@@ -273,6 +278,9 @@ public class CmsGroupServiceImpl extends ServiceImpl<GroupsMapper,GroupsTrips> i
         }
        updateById(groupsTrips);
 
+        GoodsDon goodsDon = goodsDonMapper.selectById(account.getGoodsId());
+        userSysMsgNotifyService.recordUserAccountSetSysMsg(account.getGoodsId(), groupsTrips.getSkuId(), groupsRelations, account.getAccount(), goodsDon.getTitle());
+
         Integer alertCount = alertMapper.selectCount(Wrappers.lambdaQuery(GroupsRelationAlert.class)
                 .eq(GroupsRelationAlert::getSkuId, sku.getId())
                 .last("limit 1"));
@@ -364,7 +372,7 @@ public class CmsGroupServiceImpl extends ServiceImpl<GroupsMapper,GroupsTrips> i
 
         replaceRecordMapper.insert(replaceRecord);
 
-        TASK_EXECUTOR.execute(() -> sendChangeAccountMsg(groupsId, goodsId));;
+        TASK_EXECUTOR.execute(() -> sendChangeAccountMsg(groupsId, goodsId, account));;
     }
 
     @Override
@@ -419,12 +427,17 @@ public class CmsGroupServiceImpl extends ServiceImpl<GroupsMapper,GroupsTrips> i
     }
 
     @Override
-    public void sendChangeAccountMsg(Long groupsId, Long goodsId) {
+    public void sendChangeAccountMsg(Long groupsId, Long goodsId, String account) {
         GoodsDon goodsDon = goodsDonMapper.selectById(goodsId);
         String title = goodsDon != null ? goodsDon.getTitle() : "车票";
         DateTime now = DateTime.now();
         Boolean isPrd = envCommonService.isPrdEnv();
-        List<GroupsRelation> groupsRelations = beanSearcher.searchAll(GroupsRelation.class, MapUtils.builder().field(GroupsRelation::getGroupsId, groupsId).build());
+        List<GroupsRelationView> groupsRelations = beanSearcher.searchAll(GroupsRelationView.class, MapUtils.builder().field(GroupsRelationView::getGroupsId, groupsId).build());
+        if (CollUtil.isEmpty(groupsRelations)) {
+            return;
+        }
+        Long skuId = groupsMapper.selectById(groupsId).getSkuId();
+        userSysMsgNotifyService.recordUserAccountUpdateSysMsg(goodsId, skuId, groupsRelations, account, goodsDon.getTitle());
         groupsRelations.forEach(relation -> {
             if (relation.getExpiryTime() == null) {
                 return;

+ 11 - 3
netflix-service/src/main/java/com/cyksj/service/template/impl/TemplateCommonServiceImpl.java

@@ -1,5 +1,6 @@
 package com.cyksj.service.template.impl;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.StrUtil;
@@ -23,9 +24,9 @@ import com.cyksj.model.manage.views.GroupsRelationView;
 import com.cyksj.model.views.WxAppTemplateView;
 import com.cyksj.service.sms.SmsService;
 import com.cyksj.service.template.TemplateCommonService;
+import com.cyksj.service.user.UserSysMsgNotifyService;
 import com.cyksj.service.wechat.WeChatService;
 import com.ejlchina.searcher.BeanSearcher;
-import com.ejlchina.searcher.param.Operator;
 import com.ejlchina.searcher.util.MapBuilder;
 import com.ejlchina.searcher.util.MapUtils;
 import lombok.RequiredArgsConstructor;
@@ -65,6 +66,8 @@ public class TemplateCommonServiceImpl implements TemplateCommonService {
 
 	private final SmsService smsService;
 
+	private final UserSysMsgNotifyService userSysMsgNotifyService;
+
 	public void newOderSendMsgByType(OrderDon order, GoodsDon goodsDon, User user, String toPeople, Boolean isCustomer) throws Exception {
 		if (!EnvCommonService.active.equals(envCommonService.getEnv())) {
 			String openId = toPeople;
@@ -211,14 +214,19 @@ public class TemplateCommonServiceImpl implements TemplateCommonService {
 	public void sendAccountTemplateMsg(Account account) throws Exception {
 		if (!EnvCommonService.active.equals(envCommonService.getEnv())) {
 			List<GroupsRelationView> relations = beanSearcher.searchList(GroupsRelationView.class, MapUtils.builder()
-					.field(GroupsRelationView::getAccountId, account.getId()).op(Operator.Equal)
-					.field(GroupsRelationView::getStatus, "validity").op(Operator.Equal)
+					.field(GroupsRelationView::getAccountId, account.getId())
+					.field(GroupsRelationView::getStatus, "validity")
 					.build());
+			if (CollUtil.isEmpty(relations)) {
+				return;
+			}
 			Boolean isPrdEnv = envCommonService.isPrdEnv();
 			GoodsDon goodsDon = goodsDonMapper.selectById(account.getGoodsId());
 			String title = goodsDon != null ? goodsDon.getTitle() : "车票";
 			DateTime now = DateTime.now();
 			log.info("开始发送账号修改密码模板消息,大小:{}", relations.size());
+			Long skuId = relations.get(0).getSkuId();
+			userSysMsgNotifyService.recordUserAccountUpdateSysMsg(account.getGoodsId(), skuId, relations, account.getAccount(), goodsDon.getTitle());
 			for (GroupsRelationView relation : relations) {
 				if (relation.getExpiryTime() == null) {
 					return;

+ 20 - 0
netflix-service/src/main/java/com/cyksj/service/user/UserSysMsgNotifyService.java

@@ -0,0 +1,20 @@
+package com.cyksj.service.user;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.cyksj.model.entity.GroupsRelation;
+import com.cyksj.model.entity.UserSysMsgNotify;
+import com.cyksj.model.manage.views.GroupsRelationView;
+
+import java.util.List;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: UserSysMsgNotifyService
+ * 创建者: JavaZou
+ * 创建时间:2024/2/4 16:03
+ */
+public interface UserSysMsgNotifyService extends IService<UserSysMsgNotify> {
+	void recordUserAccountUpdateSysMsg(Long goodsId, Long skuId, List<GroupsRelationView> relations, String account, String title);
+
+	void recordUserAccountSetSysMsg(Long goodsId, Long skuId, List<GroupsRelation> groupsRelations, String account, String title);
+}

+ 59 - 0
netflix-service/src/main/java/com/cyksj/service/user/impl/UserSysMsgNotifyServiceImpl.java

@@ -0,0 +1,59 @@
+package com.cyksj.service.user.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.cyksj.common.constant.Constant;
+import com.cyksj.mapper.UserSysMsgNotifyMapper;
+import com.cyksj.model.entity.GroupsRelation;
+import com.cyksj.model.entity.UserSysMsgNotify;
+import com.cyksj.model.manage.views.GroupsRelationView;
+import com.cyksj.service.user.UserSysMsgNotifyService;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: UserSysMsgNotifyServiceImpl
+ * 创建者: JavaZou
+ * 创建时间:2024/2/4 16:03
+ */
+@Service
+@RequiredArgsConstructor
+@Slf4j
+public class UserSysMsgNotifyServiceImpl extends ServiceImpl<UserSysMsgNotifyMapper, UserSysMsgNotify> implements UserSysMsgNotifyService {
+	private final UserSysMsgNotifyMapper userSysMsgNotifyMapper;
+
+
+	@Override
+	public void recordUserAccountUpdateSysMsg(Long goodsId, Long skuId, List<GroupsRelationView> relations, String account, String title) {
+		String sysMsg = String.format(Constant.ACCOUNT_PWD_UPDATE_SYS_MSG_NOTIFY, title);
+		Set<Long> userSet = new HashSet<>();
+		List<GroupsRelationView> collect = relations.stream().filter(e -> {
+			if (userSet.contains(e.getUserId())) {
+				return false;
+			}
+			userSet.add(e.getUserId());
+			return true;
+		}).collect(Collectors.toList());
+		userSysMsgNotifyMapper.recordUserAccountUpdateSysMsg(goodsId, skuId, collect, account, sysMsg);
+	}
+
+	@Override
+	public void recordUserAccountSetSysMsg(Long goodsId, Long skuId, List<GroupsRelation> relations, String account, String title) {
+		String sysMsg = String.format(Constant.ACCOUNT_SET_SYS_MSG_NOTIFY, title);
+		Set<Long> userSet = new HashSet<>();
+		List<GroupsRelation> collect = relations.stream().filter(e -> {
+			if (userSet.contains(e.getUserId())) {
+				return false;
+			}
+			userSet.add(e.getUserId());
+			return true;
+		}).collect(Collectors.toList());
+		userSysMsgNotifyMapper.recordUserAccountSetSysMsg(goodsId, skuId, collect, account, sysMsg);
+	}
+}

+ 2 - 1
netflix-web/src/main/java/com/cyksj/web/controller/manage/account/CmsAccountController.java

@@ -1006,7 +1006,8 @@ public class CmsAccountController {
 					GroupsTrips groupsTrips = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class)
 							.eq(GroupsTrips::getAccountId, accountId).last("limit 1"));
 					if (groupsTrips != null) {
-						cmsGroupService.sendChangeAccountMsg(groupsTrips.getId(), goodsId);
+						Account byId = accountService.getById(accountId);
+						cmsGroupService.sendChangeAccountMsg(groupsTrips.getId(), goodsId, byId.getAccount());
 					}
 				});
 			});

+ 81 - 0
netflix-web/src/main/java/com/cyksj/web/controller/sys/UserSysMsgController.java

@@ -0,0 +1,81 @@
+package com.cyksj.web.controller.sys;
+
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.cyksj.dto.Result;
+import com.cyksj.enums.GatewayResponse;
+import com.cyksj.mapper.UserSysMsgNotifyMapper;
+import com.cyksj.model.entity.UserSysMsgNotify;
+import com.cyksj.service.user.UserBindRelationService;
+import com.cyksj.web.util.StpUserUtil;
+import com.ejlchina.searcher.BeanSearcher;
+import com.ejlchina.searcher.SearchResult;
+import com.ejlchina.searcher.param.Operator;
+import com.ejlchina.searcher.util.MapUtils;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: UserSysMsgController
+ * 创建者: JavaZou
+ * 创建时间:2024/2/4 16:58
+ */
+@RequestMapping("/sys/msg")
+@RestController
+@RequiredArgsConstructor
+public class UserSysMsgController {
+
+	private final BeanSearcher beanSearcher;
+
+	private final UserBindRelationService userBindRelationService;
+
+	private final UserSysMsgNotifyMapper userSysMsgNotifyMapper;
+
+	private final HttpServletRequest request;
+
+
+	/**
+	 * 用户系统消息
+	 */
+	@GetMapping("/get")
+	public Result<SearchResult<UserSysMsgNotify>> getSysMsg() {
+		long userId = StpUserUtil.getLoginIdAsLong();
+		List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
+		SearchResult<UserSysMsgNotify> search = beanSearcher.search(UserSysMsgNotify.class, MapUtils.flatBuilder(request.getParameterMap()).field(UserSysMsgNotify::getUserId, userIdList).op(Operator.InList).field(UserSysMsgNotify::getDeleted, 1).orderBy(UserSysMsgNotify::getIsView).orderBy(UserSysMsgNotify::getCreatedTime).desc().onlySelect(UserSysMsgNotify::getId, UserSysMsgNotify::getAccount, UserSysMsgNotify::getRelationId, UserSysMsgNotify::getMsg, UserSysMsgNotify::getIsView).build());
+		return GatewayResponse.SUCCESS.newBuilder().toResult(search);
+	}
+
+	/**
+	 * 查看消息
+	 */
+	@GetMapping("/view/detail/{id}")
+	public Result viewMsgDetail(@PathVariable Long id) {
+		long userId = StpUserUtil.getLoginIdAsLong();
+		List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
+		Optional.ofNullable(userSysMsgNotifyMapper.selectOne(Wrappers.lambdaQuery(UserSysMsgNotify.class).eq(UserSysMsgNotify::getId, id).in(UserSysMsgNotify::getUserId, userIdList).eq(UserSysMsgNotify::getDeleted, 1))).ifPresent(e -> {
+			if (!e.getIsView()) {
+				e.setIsView(false);
+				userSysMsgNotifyMapper.updateById(e);
+			}
+		});
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
+
+	/**
+	 * 删除消息
+	 */
+	@DeleteMapping("/del/{id}")
+	public Result delMsg(@PathVariable Long id) {
+		long userId = StpUserUtil.getLoginIdAsLong();
+		List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
+		Optional.ofNullable(userSysMsgNotifyMapper.selectOne(Wrappers.lambdaQuery(UserSysMsgNotify.class).eq(UserSysMsgNotify::getId, id).in(UserSysMsgNotify::getUserId, userIdList).eq(UserSysMsgNotify::getDeleted, 1))).ifPresent(e -> {
+			e.setDeleted(false);
+			userSysMsgNotifyMapper.updateById(e);
+		});
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
+}