1.提交【管理后台】-营销管理-积分管理相关接口
2.修改websocket代码,增加用户端、拍卖师端类型区分
| | |
| | | */ |
| | | public class WebSocketUsers |
| | | { |
| | | /** |
| | | * WebSocketUsers 日志控制器 |
| | | */ |
| | | private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketUsers.class); |
| | | |
| | | /** |
| | | * 用户集 |
| | | */ |
| | | private static Map<String, Session> USERS = new ConcurrentHashMap<String, Session>(); |
| | | private static Map<String, Session> USERS = new ConcurrentHashMap<>(); |
| | | private static Map<String, Integer> USER_TYPES = new ConcurrentHashMap<>(); |
| | | |
| | | /** |
| | | * 存储用户 |
| | | * |
| | | * @param key 唯一键 |
| | | * @param session 用户信息 |
| | | */ |
| | | public static void put(String key, Session session) |
| | | public static void put(String key, Session session, Integer clientType) |
| | | { |
| | | USERS.put(key, session); |
| | | USER_TYPES.put(key, clientType); |
| | | } |
| | | |
| | | /** |
| | | * 移除用户 |
| | | * |
| | | * @param session 用户信息 |
| | | * |
| | | * @return 移除结果 |
| | | */ |
| | | public static boolean remove(Session session) |
| | | { |
| | | String key = null; |
| | |
| | | return remove(key); |
| | | } |
| | | |
| | | /** |
| | | * 移出用户 |
| | | * |
| | | * @param key 键 |
| | | */ |
| | | public static boolean remove(String key) |
| | | { |
| | | LOGGER.info("\n 正在移出用户 - {}", key); |
| | | Session remove = USERS.remove(key); |
| | | USER_TYPES.remove(key); |
| | | if (remove != null) |
| | | { |
| | | boolean containsValue = USERS.containsValue(remove); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取在线用户列表 |
| | | * |
| | | * @return 返回用户集合 |
| | | */ |
| | | public static Map<String, Session> getUsers() |
| | | { |
| | | return USERS; |
| | | } |
| | | |
| | | /** |
| | | * 群发消息文本消息 |
| | | * |
| | | * @param message 消息内容 |
| | | */ |
| | | public static Integer getUserType(String key) { |
| | | return USER_TYPES.get(key); |
| | | } |
| | | |
| | | public static void sendMessageToUsersByText(String message) |
| | | { |
| | | Collection<Session> values = USERS.values(); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 发送文本消息 |
| | | * |
| | | * @param session 自己的用户名 |
| | | * @param message 消息内容 |
| | | */ |
| | | public static void sendMessageToUserByText(Session session, String message) |
| | | { |
| | | if (session != null) |
| | |
| | | LOGGER.info("\n[你已离线]"); |
| | | } |
| | | } |
| | | |
| | | public static void sendMessageToUsersByType(Integer clientType, String message) { |
| | | for (Map.Entry<String, Session> entry : USERS.entrySet()) { |
| | | String key = entry.getKey(); |
| | | Session session = entry.getValue(); |
| | | if (clientType.equals(USER_TYPES.get(key))) { |
| | | sendMessageToUserByText(session, message); |
| | | } |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ruoyi.system.api.util; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.Collection; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import javax.websocket.Session; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | /** |
| | | * websocket 客户端用户集 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class WebSocketUsers_Bak { |
| | | |
| | | /** |
| | | * WebSocketUsers 日志控制器 |
| | | */ |
| | | private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketUsers_Bak.class); |
| | | |
| | | /** |
| | | * 用户集 |
| | | */ |
| | | private static Map<String, Session> USERS = new ConcurrentHashMap<String, Session>(); |
| | | |
| | | /** |
| | | * 存储用户 |
| | | * |
| | | * @param key 唯一键 |
| | | * @param session 用户信息 |
| | | */ |
| | | public static void put(String key, Session session) { |
| | | USERS.put(key, session); |
| | | } |
| | | |
| | | /** |
| | | * 移除用户 |
| | | * |
| | | * @param session 用户信息 |
| | | * @return 移除结果 |
| | | */ |
| | | public static boolean remove(Session session) { |
| | | String key = null; |
| | | boolean flag = USERS.containsValue(session); |
| | | if (flag) { |
| | | Set<Map.Entry<String, Session>> entries = USERS.entrySet(); |
| | | for (Map.Entry<String, Session> entry : entries) { |
| | | Session value = entry.getValue(); |
| | | if (value.equals(session)) { |
| | | key = entry.getKey(); |
| | | break; |
| | | } |
| | | } |
| | | } else { |
| | | return true; |
| | | } |
| | | return remove(key); |
| | | } |
| | | |
| | | /** |
| | | * 移出用户 |
| | | * |
| | | * @param key 键 |
| | | */ |
| | | public static boolean remove(String key) { |
| | | LOGGER.info("\n 正在移出用户 - {}", key); |
| | | Session remove = USERS.remove(key); |
| | | if (remove != null) { |
| | | boolean containsValue = USERS.containsValue(remove); |
| | | LOGGER.info("\n 移出结果 - {}", containsValue ? "失败" : "成功"); |
| | | return containsValue; |
| | | } else { |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取在线用户列表 |
| | | * |
| | | * @return 返回用户集合 |
| | | */ |
| | | public static Map<String, Session> getUsers() { |
| | | return USERS; |
| | | } |
| | | |
| | | /** |
| | | * 群发消息文本消息 |
| | | * |
| | | * @param message 消息内容 |
| | | */ |
| | | public static void sendMessageToUsersByText(String message) { |
| | | Collection<Session> values = USERS.values(); |
| | | for (Session value : values) { |
| | | sendMessageToUserByText(value, message); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 发送文本消息 |
| | | * |
| | | * @param session 自己的用户名 |
| | | * @param message 消息内容 |
| | | */ |
| | | public static void sendMessageToUserByText(Session session, String message) { |
| | | if (session != null) { |
| | | try { |
| | | session.getBasicRemote().sendText(message); |
| | | } catch (IOException e) { |
| | | LOGGER.error("\n[发送消息异常]", e); |
| | | } |
| | | } else { |
| | | LOGGER.info("\n[你已离线]"); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ruoyi.common.core.enums; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Getter; |
| | | |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum ClientTypeEnum { |
| | | MEMBER(1, "会员小程序"), |
| | | AUCTIONEER(2, "拍卖师小程序"); |
| | | |
| | | private final Integer code; |
| | | private final String desc; |
| | | |
| | | public static ClientTypeEnum getEnumByCode(Integer code) { |
| | | for (ClientTypeEnum e : ClientTypeEnum.values()) { |
| | | if (e.code.equals(code)) { |
| | | return e; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.common.security.utils; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
| | | import com.ruoyi.common.core.constant.SecurityConstants; |
| | | import com.ruoyi.common.core.constant.TokenConstants; |
| | | import com.ruoyi.common.core.context.SecurityContextHolder; |
| | | import com.ruoyi.common.core.utils.ServletUtils; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.system.api.model.LoginUser; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
| | | |
| | | /** |
| | | * 权限获取工具类 |
| | |
| | | { |
| | | // 从header获取token标识 |
| | | String token = request.getHeader(TokenConstants.AUTHENTICATION); |
| | | if (StringUtils.isBlank(token)) { |
| | | // 如果Authorization为空,那么尝试读取Sec-Websocket-Protocol的内容 |
| | | token = request.getHeader("Sec-Websocket-Protocol"); |
| | | } |
| | | return replaceTokenPrefix(token); |
| | | } |
| | | |
| | |
| | | </exclusion> |
| | | </exclusions> |
| | | </dependency> |
| | | |
| | | <!-- 分布式事务 --> |
| | | <dependency> |
| | | <groupId>com.ruoyi</groupId> |
| | | <artifactId>ruoyi-common-seata</artifactId> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
| | |
| | | import com.ruoyi.common.core.enums.AuctionStartStatusEnum; |
| | | import com.ruoyi.common.core.enums.BidStatusEnum; |
| | | import com.ruoyi.common.core.enums.BondStatusEnum; |
| | | import com.ruoyi.common.core.enums.ClientTypeEnum; |
| | | import com.ruoyi.common.core.enums.ListingStatusEnum; |
| | | import com.ruoyi.common.core.enums.OrderFromEnum; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | |
| | | map.put("target_id", id); |
| | | map.put("message_type", "end"); |
| | | String msg = objectMapper.writeValueAsString(map); |
| | | WebSocketUsers.sendMessageToUsersByText(msg); |
| | | WebSocketUsers.sendMessageToUsersByType(1, msg); |
| | | log.info("===================>发送websocket通知,消息体{}", msg); |
| | | } |
| | | } |
| | |
| | | map.put("target_id", id); |
| | | map.put("message_type", "start"); |
| | | String msg = objectMapper.writeValueAsString(map); |
| | | WebSocketUsers.sendMessageToUsersByText(msg); |
| | | WebSocketUsers.sendMessageToUsersByType(ClientTypeEnum.MEMBER.getCode(), msg); |
| | | log.info("===================>发送websocket通知,消息体{}", msg); |
| | | } |
| | | } |
| | |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.google.common.collect.Lists; |
| | | import com.ruoyi.system.api.constants.NotificationTypeConstant; |
| | | import com.ruoyi.system.api.domain.*; |
| | | import com.ruoyi.system.api.domain.dto.AuctionSalesroomDTO; |
| | | import com.ruoyi.system.api.domain.dto.AuctionSalesroomGoodsInfoDTO; |
| | | import com.ruoyi.system.api.domain.vo.AuctionBidRecordVO; |
| | | import com.ruoyi.system.api.domain.vo.AuctionSalesroomGoodsInfoVO; |
| | | import com.ruoyi.system.api.domain.vo.AuctionSalesroomVO; |
| | | import com.ruoyi.system.api.domain.vo.ForepartAuctionSalesroomGoodsVO; |
| | | import com.ruoyi.auction.domain.AuctionBidRecord; |
| | | import com.ruoyi.auction.domain.AuctionBrowseRecord; |
| | | import com.ruoyi.auction.domain.AuctionSalesroomGoods; |
| | | import com.ruoyi.auction.mapper.AuctionBidRecordMapper; |
| | | import com.ruoyi.auction.mapper.AuctionSalesroomGoodsMapper; |
| | |
| | | import com.ruoyi.common.core.enums.AuctionOrderTypeEnum; |
| | | import com.ruoyi.common.core.enums.AuctionStartStatusEnum; |
| | | import com.ruoyi.common.core.enums.BidStatusEnum; |
| | | import com.ruoyi.common.core.enums.ClientTypeEnum; |
| | | import com.ruoyi.common.core.enums.OrderFromEnum; |
| | | import com.ruoyi.system.api.constants.NotificationTypeConstant; |
| | | import com.ruoyi.system.api.domain.AuctionSalesroom; |
| | | import com.ruoyi.system.api.domain.CustomConfig; |
| | | import com.ruoyi.system.api.domain.GoodsBrand; |
| | | import com.ruoyi.system.api.domain.GoodsCategory; |
| | | import com.ruoyi.system.api.domain.GoodsFlavorType; |
| | | import com.ruoyi.system.api.domain.GoodsSeries; |
| | | import com.ruoyi.system.api.domain.GoodsSku; |
| | | import com.ruoyi.system.api.domain.Member; |
| | | import com.ruoyi.system.api.domain.MemberAddress; |
| | | import com.ruoyi.system.api.domain.dto.AuctionSalesroomDTO; |
| | | import com.ruoyi.system.api.domain.dto.AuctionSalesroomGoodsInfoDTO; |
| | | import com.ruoyi.system.api.domain.dto.GoodsStockUpdDTO; |
| | | import com.ruoyi.system.api.domain.dto.OrderAuctionBondDTO; |
| | | import com.ruoyi.system.api.domain.dto.OrderDTO; |
| | | import com.ruoyi.system.api.domain.vo.AuctionBidRecordVO; |
| | | import com.ruoyi.system.api.domain.vo.AuctionSalesroomGoodsInfoVO; |
| | | import com.ruoyi.system.api.domain.vo.AuctionSalesroomVO; |
| | | import com.ruoyi.system.api.domain.vo.ForepartAuctionSalesroomGoodsVO; |
| | | import com.ruoyi.system.api.feignClient.GoodsSkuClient; |
| | | import com.ruoyi.system.api.feignClient.MemberClient; |
| | | import com.ruoyi.system.api.feignClient.OrderClient; |
| | | import com.ruoyi.system.api.feignClient.SysUserClient; |
| | | import com.ruoyi.system.api.util.WebSocketUsers; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.ruoyi.system.api.feignClient.SysUserClient; |
| | | import com.ruoyi.system.api.util.WebSocketUsers; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | |
| | |
| | | msg = objectMapper.writeValueAsString(map); |
| | | } catch (JsonProcessingException e) { |
| | | } |
| | | WebSocketUsers.sendMessageToUsersByText(msg); |
| | | WebSocketUsers.sendMessageToUsersByType(ClientTypeEnum.AUCTIONEER.getCode(), msg); |
| | | |
| | | } |
| | | |
| | |
| | | msg = objectMapper.writeValueAsString(map); |
| | | } catch (JsonProcessingException e) { |
| | | } |
| | | WebSocketUsers.sendMessageToUsersByText(msg); |
| | | WebSocketUsers.sendMessageToUsersByType(ClientTypeEnum.AUCTIONEER.getCode(), msg); |
| | | } |
| | | |
| | | |
| | |
| | | } catch (JsonProcessingException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | WebSocketUsers.sendMessageToUsersByText(msg); |
| | | WebSocketUsers.sendMessageToUsersByType(ClientTypeEnum.AUCTIONEER.getCode(), msg); |
| | | } |
| | | |
| | | |
| | |
| | | } catch (JsonProcessingException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | WebSocketUsers.sendMessageToUsersByText(msg); |
| | | WebSocketUsers.sendMessageToUsersByType(ClientTypeEnum.AUCTIONEER.getCode(), msg); |
| | | |
| | | } |
| | | |
| | |
| | | server: |
| | | port: 9300 |
| | | # Spring |
| | | spring: |
| | | spring: |
| | | application: |
| | | # 应用名称 |
| | | name: ruoyi-file |
| | | profiles: |
| | | # 环境配置 |
| | | active: dev |
| | | servlet: |
| | | multipart: |
| | | max-file-size: 100MB |
| | | max-request-size: 200MB |
| | | location: /data/tmp |
| | | --- |
| | | spring: |
| | | config: |
| | |
| | | </exclusion> |
| | | </exclusions> |
| | | </dependency> |
| | | |
| | | <!-- 分布式事务 --> |
| | | <dependency> |
| | | <groupId>com.ruoyi</groupId> |
| | | <artifactId>ruoyi-common-seata</artifactId> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
| | |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.google.common.collect.Lists; |
| | | import com.ruoyi.common.core.constant.SecurityConstants; |
| | | import com.ruoyi.common.core.enums.ClientTypeEnum; |
| | | import com.ruoyi.common.core.enums.GroupStatusEnum; |
| | | import com.ruoyi.common.core.enums.ListingStatusEnum; |
| | | import com.ruoyi.common.core.enums.OrderStatusEnum; |
| | |
| | | map.put("target_id", groupPurchaseId); |
| | | map.put("message_type", "start"); |
| | | String msg = objectMapper.writeValueAsString(map); |
| | | WebSocketUsers.sendMessageToUsersByText(msg); |
| | | WebSocketUsers.sendMessageToUsersByType(ClientTypeEnum.MEMBER.getCode(), msg); |
| | | log.info("===================>发送websocket通知,消息体{}", msg); |
| | | } |
| | | } |
| | |
| | | map.put("target_id", groupPurchaseId); |
| | | map.put("message_type", "end"); |
| | | String msg = objectMapper.writeValueAsString(map); |
| | | WebSocketUsers.sendMessageToUsersByText(msg); |
| | | WebSocketUsers.sendMessageToUsersByType(ClientTypeEnum.MEMBER.getCode(), msg); |
| | | log.info("===================>发送websocket通知,消息体{}", msg); |
| | | } |
| | | } |
| | |
| | | import com.google.common.collect.Lists; |
| | | import com.ruoyi.common.core.constant.CacheConstants; |
| | | import com.ruoyi.common.core.constant.SecurityConstants; |
| | | import com.ruoyi.common.core.enums.ClientTypeEnum; |
| | | import com.ruoyi.common.core.enums.ListingStatusEnum; |
| | | import com.ruoyi.common.core.enums.StartStatusEnum; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | |
| | | map.put("target_id", seckillId); |
| | | map.put("message_type", "start"); |
| | | String msg = objectMapper.writeValueAsString(map); |
| | | WebSocketUsers.sendMessageToUsersByText(msg); |
| | | WebSocketUsers.sendMessageToUsersByType(ClientTypeEnum.MEMBER.getCode(), msg); |
| | | log.info("===================>发送websocket通知,消息体{}", msg); |
| | | } |
| | | |
| | |
| | | map.put("target_id", seckillId); |
| | | map.put("message_type", "end"); |
| | | String msg = objectMapper.writeValueAsString(map); |
| | | WebSocketUsers.sendMessageToUsersByText(msg); |
| | | WebSocketUsers.sendMessageToUsersByType(ClientTypeEnum.MEMBER.getCode(), msg); |
| | | log.info("===================>发送websocket通知,消息体{}", msg); |
| | | } |
| | | |
| | |
| | | </exclusions> |
| | | </dependency> |
| | | |
| | | <!-- 分布式事务 --> |
| | | <dependency> |
| | | <groupId>com.ruoyi</groupId> |
| | | <artifactId>ruoyi-common-seata</artifactId> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
New file |
| | |
| | | package com.ruoyi.member.controller.management; |
| | | |
| | | |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.page.PageDTO; |
| | | import com.ruoyi.member.controller.management.dto.MgtMemberPointsQuery; |
| | | import com.ruoyi.member.controller.management.vo.MgtMemberPointsVO; |
| | | import com.ruoyi.member.service.IMemberPointsService; |
| | | 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.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | /** |
| | | * <p> |
| | | * 会员积分表 前端控制器 |
| | | * </p> |
| | | * |
| | | * @author mitao |
| | | * @since 2024-05-23 |
| | | */ |
| | | @RestController |
| | | @RequiredArgsConstructor |
| | | @RequestMapping("/mgt/member-points") |
| | | @Api(value = "管理后台-会员积分管理相关接口", tags = "管理后台-会员积分管理相关接口") |
| | | public class MemberPointsController { |
| | | |
| | | private final IMemberPointsService iMemberPointsService; |
| | | |
| | | /** |
| | | * 获取会员积分列表的分页数据 |
| | | * |
| | | * @param query 会员积分明细查询对象 |
| | | * @return PageDTO<MgtMemberPointsVO> |
| | | */ |
| | | @ApiOperation(value = "获取会员积分列表的分页数据", notes = "会员积分列表的分页数据") |
| | | @PostMapping("/page") |
| | | public R<PageDTO<MgtMemberPointsVO>> getMemberPointsPage( |
| | | @Validated @RequestBody MgtMemberPointsQuery query) { |
| | | return R.ok(iMemberPointsService.getMemberPointsPage(query)); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.member.controller.management.dto; |
| | | |
| | | import com.ruoyi.common.core.enums.PointStatusEnum; |
| | | import com.ruoyi.common.core.web.page.BasePage; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | |
| | | |
| | | private static final long serialVersionUID = -5584030212572003337L; |
| | | |
| | | @ApiModelProperty(value = "积分id") |
| | | @ApiModelProperty(value = "会员id", notes = "会员管理-查看详情必传,积分管理不传") |
| | | private Long id; |
| | | |
| | | @ApiModelProperty(value = "会员姓名") |
| | | private String nickname; |
| | | |
| | | @ApiModelProperty(value = "联系电话") |
| | | private String phone; |
| | | |
| | | @ApiModelProperty(value = "变动类型 增加 减少") |
| | | private PointStatusEnum pointsStatus; |
| | | } |
| | |
| | | |
| | | @ApiModelProperty(value = "时间") |
| | | private LocalDateTime createTime; |
| | | |
| | | @ApiModelProperty(value = "会员id") |
| | | private Long memberId; |
| | | |
| | | @ApiModelProperty(value = "会员姓名") |
| | | private String nickname; |
| | | |
| | | @ApiModelProperty(value = "联系电话") |
| | | private String phone; |
| | | } |
| | |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.ruoyi.common.core.utils.page.PageDTO; |
| | | import com.ruoyi.member.controller.management.dto.MgtMemberPointsQuery; |
| | | import com.ruoyi.member.controller.management.vo.MgtMemberPointsVO; |
| | | import com.ruoyi.system.api.domain.MemberPoints; |
| | | import com.ruoyi.system.api.domain.dto.MemberDTO; |
| | | |
| | |
| | | |
| | | PageDTO<MemberPoints> getMemberPoints(MemberDTO memberDTO); |
| | | |
| | | /** |
| | | * 获取会员积分列表的分页数据 |
| | | * |
| | | * @param query 会员积分明细查询对象 |
| | | * @return PageDTO<MgtMemberPointsVO> |
| | | */ |
| | | PageDTO<MgtMemberPointsVO> getMemberPointsPage(MgtMemberPointsQuery query); |
| | | } |
| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.constant.SecurityConstants; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.utils.page.PageDTO; |
| | | import com.ruoyi.system.api.domain.MemberPoints; |
| | | import com.ruoyi.system.api.domain.dto.MemberDTO; |
| | | import com.ruoyi.member.controller.management.dto.MgtMemberPointsQuery; |
| | | import com.ruoyi.member.controller.management.vo.MgtMemberPointsVO; |
| | | import com.ruoyi.member.mapper.MemberPointsMapper; |
| | | import com.ruoyi.member.service.IMemberPointsService; |
| | | import com.ruoyi.system.api.domain.Member; |
| | | import com.ruoyi.system.api.domain.MemberPoints; |
| | | import com.ruoyi.system.api.domain.dto.MemberDTO; |
| | | import com.ruoyi.system.api.feignClient.MemberClient; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | /** |
| | |
| | | * @since 2024-05-23 |
| | | */ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, MemberPoints> implements IMemberPointsService { |
| | | |
| | | private final MemberClient memberClient; |
| | | |
| | | @Override |
| | | public PageDTO<MemberPoints> getMemberPoints(MemberDTO memberDTO) { |
| | |
| | | Page<MemberPoints> page1 = this.page(page, wrapper); |
| | | return PageDTO.of(page1); |
| | | } |
| | | |
| | | /** |
| | | * 获取会员积分列表的分页数据 |
| | | * |
| | | * @param query 会员积分明细查询对象 |
| | | * @return PageDTO<MgtMemberPointsVO> |
| | | */ |
| | | @Override |
| | | public PageDTO<MgtMemberPointsVO> getMemberPointsPage(MgtMemberPointsQuery query) { |
| | | Set<Long> memberIdSet = null; |
| | | MemberDTO memberDTO = getMemberQueryParam(query); |
| | | if (StringUtils.isNotNull(memberDTO)) { |
| | | memberIdSet = getMemberIdSet(memberDTO); |
| | | } |
| | | // 分页查询积分 |
| | | Page<MemberPoints> page = this.lambdaQuery() |
| | | .eq(StringUtils.isNotNull(query.getPointsStatus()), MemberPoints::getPointsStatus, |
| | | query.getPointsStatus()) |
| | | .in(StringUtils.isNotEmpty(memberIdSet), MemberPoints::getMemberId, memberIdSet) |
| | | .page(new Page<>(query.getPageCurr(), query.getPageSize())); |
| | | if (StringUtils.isEmpty(page.getRecords())) { |
| | | return PageDTO.empty(page); |
| | | } |
| | | // 封装VO |
| | | PageDTO<MgtMemberPointsVO> pageVO = PageDTO.of(page, |
| | | MgtMemberPointsVO.class); |
| | | List<MgtMemberPointsVO> list = pageVO.getList(); |
| | | Set<Long> memIdSet = list.stream().map(MgtMemberPointsVO::getMemberId) |
| | | .collect(Collectors.toSet()); |
| | | List<Member> memberList = memberClient.getMemberListByIds(memIdSet, SecurityConstants.INNER) |
| | | .getData(); |
| | | Map<Long, Member> memberMap = memberList.stream() |
| | | .collect(Collectors.toMap(Member::getId, Function.identity())); |
| | | if (StringUtils.isNotEmpty(memberList)) { |
| | | for (MgtMemberPointsVO mgtMemberPointsVO : list) { |
| | | Member member = memberMap.get(mgtMemberPointsVO.getMemberId()); |
| | | if (StringUtils.isNotNull(member)) { |
| | | mgtMemberPointsVO.setNickname(member.getNickname()); |
| | | mgtMemberPointsVO.setPhone(member.getPhone()); |
| | | } |
| | | } |
| | | } |
| | | return pageVO; |
| | | } |
| | | |
| | | private Set<Long> getMemberIdSet(MemberDTO memberDTO) { |
| | | Set<Long> memberIdSet = null; |
| | | if (StringUtils.isNotNull(memberDTO)) { |
| | | List<Member> data = memberClient.getMemberListByCondition(memberDTO, |
| | | SecurityConstants.INNER).getData(); |
| | | memberIdSet = data.stream().map(Member::getId).collect(Collectors.toSet()); |
| | | } |
| | | return memberIdSet; |
| | | } |
| | | |
| | | private static MemberDTO getMemberQueryParam(MgtMemberPointsQuery query) { |
| | | MemberDTO memberDTO = null; |
| | | if (StringUtils.isNotBlank(query.getNickname()) || StringUtils.isNotBlank( |
| | | query.getPhone())) { |
| | | memberDTO = new MemberDTO(); |
| | | memberDTO.setNickname(query.getNickname()); |
| | | memberDTO.setPhone(query.getPhone()); |
| | | } |
| | | return memberDTO; |
| | | } |
| | | } |
| | |
| | | <scope>compile</scope> |
| | | </dependency> |
| | | |
| | | |
| | | <!-- 分布式事务 --> |
| | | <dependency> |
| | | <groupId>com.ruoyi</groupId> |
| | | <artifactId>ruoyi-common-seata</artifactId> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
| | |
| | | <version>1.2.47</version> |
| | | </dependency> |
| | | |
| | | <!--EasyExcel--> |
| | | <dependency> |
| | | <groupId>cn.afterturn</groupId> |
| | | <artifactId>easypoi-spring-boot-starter</artifactId> |
| | | <version>4.0.0</version> |
| | | <exclusions> |
| | | <exclusion> |
| | | <artifactId>guava</artifactId> |
| | | <groupId>com.google.guava</groupId> |
| | | </exclusion> |
| | | </exclusions> |
| | | <groupId>com.alibaba</groupId> |
| | | <artifactId>easyexcel</artifactId> |
| | | <version>3.3.4</version> |
| | | </dependency> |
| | | |
| | | <!-- 分布式事务 --> |
| | | <dependency> |
| | | <groupId>com.ruoyi</groupId> |
| | | <artifactId>ruoyi-common-seata</artifactId> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
| | |
| | | package com.ruoyi.promotion.controller.management; |
| | | |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.ExcelWriter; |
| | | import com.alibaba.excel.util.DateUtils; |
| | | import com.alibaba.excel.write.metadata.WriteSheet; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.page.PageDTO; |
| | | import com.ruoyi.promotion.controller.management.dto.MgtCouponDTO; |
| | |
| | | import com.ruoyi.system.api.validate.ModifyGroup; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | |
| | | @Validated @RequestBody MgtCouponReceiveQuery query) { |
| | | return R.ok(couponService.getReceiveDetail(query)); |
| | | } |
| | | |
| | | /** |
| | | * 导出优惠券领取详情 |
| | | * |
| | | * @param query 管理后台-优惠券领取详情查询对象 |
| | | */ |
| | | @ApiOperation("领取详情-导出") |
| | | @PostMapping("/receive-detail/export") |
| | | public void exportReceiveDetail(@RequestBody MgtCouponReceiveQuery query) { |
| | | List<CouponReceiveDetailVO> couponReceiveDetailVOList = couponService.getCouponReceiveDetailList( |
| | | query); |
| | | String fileName = |
| | | "优惠券领取明细" + DateUtils.format(new Date(), "yyyyMMddHHmmss") + ".xlsx"; |
| | | |
| | | try (ExcelWriter excelWriter = EasyExcel.write(fileName, CouponReceiveDetailVO.class) |
| | | .build()) { |
| | | WriteSheet writeSheet = EasyExcel.writerSheet("优惠券领取详情").build(); |
| | | excelWriter.write(couponReceiveDetailVOList, writeSheet); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | private Long id; |
| | | |
| | | @ApiModelProperty(value = "会员姓名") |
| | | private String realName; |
| | | private String nickname; |
| | | |
| | | @ApiModelProperty(value = "联系电话") |
| | | private String phone; |
| | |
| | | package com.ruoyi.promotion.controller.management.vo; |
| | | |
| | | import com.alibaba.excel.annotation.ExcelIgnore; |
| | | import com.alibaba.excel.annotation.ExcelProperty; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.ruoyi.common.core.enums.CouponUseEnum; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import java.io.Serializable; |
| | | import java.time.LocalDateTime; |
| | | import lombok.Data; |
| | | |
| | |
| | | */ |
| | | @Data |
| | | @ApiModel(value = "管理后台-优惠券领取详情视图对象", description = "管理后台-优惠券领取详情视图对象") |
| | | public class CouponReceiveDetailVO { |
| | | public class CouponReceiveDetailVO implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 7898162954825380293L; |
| | | |
| | | @ApiModelProperty(value = "优惠券id") |
| | | @ExcelIgnore |
| | | private Long couponId; |
| | | |
| | | @ApiModelProperty(value = "优惠券id") |
| | | @ExcelIgnore |
| | | private Long memberId; |
| | | |
| | | @ApiModelProperty(value = "会员姓名") |
| | | private String realName; |
| | | @ExcelProperty("会员姓名") |
| | | private String nickname; |
| | | |
| | | @ApiModelProperty(value = "联系电话") |
| | | @ExcelProperty("联系电话") |
| | | private String phone; |
| | | |
| | | @ApiModelProperty(value = "订单编号") |
| | | @ApiModelProperty(value = "使用订单") |
| | | @ExcelProperty("使用订单") |
| | | private String orderNo; |
| | | |
| | | @ApiModelProperty(value = "使用时间") |
| | | @ExcelProperty("使用时间") |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private LocalDateTime createTime; |
| | | |
| | | @ApiModelProperty(value = "优惠券状态 0:未使用, 1:已使用") |
| | | @ApiModelProperty(value = "使用状态 0:未使用, 1:已使用") |
| | | @ExcelProperty("使用状态") |
| | | private CouponUseEnum couponStatus; |
| | | |
| | | } |
| | |
| | | import com.ruoyi.promotion.controller.management.vo.CouponReceiveDetailVO; |
| | | import com.ruoyi.promotion.controller.management.vo.MgtCouponVO; |
| | | import com.ruoyi.promotion.domain.Coupon; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @return PageDTO<CouponReceiveDetailVO> |
| | | */ |
| | | PageDTO<CouponReceiveDetailVO> getReceiveDetail(MgtCouponReceiveQuery query); |
| | | |
| | | /** |
| | | * 查询领取详情列表 |
| | | * |
| | | * @param query 管理后台-优惠券领取详情查询对象 |
| | | * @return List<CouponReceiveDetailVO> |
| | | */ |
| | | List<CouponReceiveDetailVO> getCouponReceiveDetailList(MgtCouponReceiveQuery query); |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public PageDTO<CouponReceiveDetailVO> getReceiveDetail(MgtCouponReceiveQuery query) { |
| | | MemberDTO memberDTO = null; |
| | | Set<Long> memberIdSet = null; |
| | | if (StringUtils.isNotBlank(query.getRealName()) || StringUtils.isNotBlank( |
| | | query.getPhone())) { |
| | | memberDTO = new MemberDTO(); |
| | | memberDTO.setRealName(query.getRealName()); |
| | | memberDTO.setPhone(query.getPhone()); |
| | | } |
| | | if (StringUtils.isNotNull(memberDTO)) { |
| | | List<Member> data = memberClient.getMemberListByCondition(memberDTO, |
| | | SecurityConstants.INNER).getData(); |
| | | memberIdSet = data.stream().map(Member::getId).collect(Collectors.toSet()); |
| | | } |
| | | MemberDTO memberDTO = getMemberQueryParam(query); |
| | | Set<Long> memberIdSet = getMemberIdSet(memberDTO); |
| | | Page<CouponMember> page = couponMemberService.lambdaQuery() |
| | | .eq(StringUtils.isNotNull(query.getCouponStatus()), |
| | | CouponMember::getCouponStatus, query.getCouponStatus()) |
| | |
| | | } |
| | | PageDTO<CouponReceiveDetailVO> couponReceiveDetailVOPageDTO = PageDTO.of(page, |
| | | CouponReceiveDetailVO.class); |
| | | // 远程调用会员服务,获取会员信息 |
| | | List<Long> memberIdList = page.getRecords().stream().map(CouponMember::getMemberId) |
| | | .collect(Collectors.toList()); |
| | | if (StringUtils.isNotEmpty(memberIdList)) { |
| | | List<Member> memberList = memberClient.getMemberListByIds(memberIdList, |
| | | SecurityConstants.INNER).getData(); |
| | | Map<Long, Member> memberMap = memberList.stream() |
| | | .collect(Collectors.toMap(Member::getId, Function.identity())); |
| | | couponReceiveDetailVOPageDTO.getList().forEach(item -> { |
| | | Member member = memberMap.get(item.getMemberId()); |
| | | item.setRealName(member.getRealName()); |
| | | item.setPhone(member.getPhone()); |
| | | }); |
| | | } |
| | | List<CouponReceiveDetailVO> couponReceiveDetailVOList = couponReceiveDetailVOPageDTO.getList(); |
| | | handleCouponReceiveDetailVO(couponReceiveDetailVOList); |
| | | return couponReceiveDetailVOPageDTO; |
| | | } |
| | | |
| | | private void handleCouponReceiveDetailVO( |
| | | List<CouponReceiveDetailVO> couponReceiveDetailVOList) { |
| | | // 远程调用订单服务,获取订单信息 |
| | | List<CouponReceiveDetailVO> usedCouponList = couponReceiveDetailVOPageDTO.getList().stream() |
| | | List<CouponReceiveDetailVO> usedCouponList = couponReceiveDetailVOList.stream() |
| | | .filter(item -> item.getCouponStatus().equals( |
| | | CouponUseEnum.USED)).collect(Collectors.toList()); |
| | | Set<Long> couponIdSet = usedCouponList.stream().map(CouponReceiveDetailVO::getCouponId) |
| | |
| | | Function.identity())); |
| | | |
| | | } |
| | | Set<Long> memberSet = couponReceiveDetailVOPageDTO.getList().stream() |
| | | // 远程调用会员服务,获取会员信息 |
| | | Set<Long> memberSet = couponReceiveDetailVOList.stream() |
| | | .map(CouponReceiveDetailVO::getMemberId).collect( |
| | | Collectors.toSet()); |
| | | if (StringUtils.isNotEmpty(memberSet)) { |
| | |
| | | Collectors.toMap(Member::getId, Function.identity())); |
| | | } |
| | | // 封装VO |
| | | for (CouponReceiveDetailVO couponReceiveDetailVO : couponReceiveDetailVOPageDTO.getList()) { |
| | | for (CouponReceiveDetailVO couponReceiveDetailVO : couponReceiveDetailVOList) { |
| | | if (StringUtils.isNotEmpty(memberMap)) { |
| | | Member member = memberMap.get(couponReceiveDetailVO.getMemberId()); |
| | | if (StringUtils.isNotNull(member)) { |
| | | couponReceiveDetailVO.setRealName(member.getRealName()); |
| | | couponReceiveDetailVO.setNickname(member.getNickname()); |
| | | couponReceiveDetailVO.setPhone(member.getPhone()); |
| | | } |
| | | } else if (StringUtils.isNotEmpty(orderMap)) { |
| | |
| | | break; |
| | | } |
| | | } |
| | | return couponReceiveDetailVOPageDTO; |
| | | } |
| | | |
| | | private Set<Long> getMemberIdSet(MemberDTO memberDTO) { |
| | | Set<Long> memberIdSet = null; |
| | | if (StringUtils.isNotNull(memberDTO)) { |
| | | List<Member> data = memberClient.getMemberListByCondition(memberDTO, |
| | | SecurityConstants.INNER).getData(); |
| | | memberIdSet = data.stream().map(Member::getId).collect(Collectors.toSet()); |
| | | } |
| | | return memberIdSet; |
| | | } |
| | | |
| | | private static MemberDTO getMemberQueryParam(MgtCouponReceiveQuery query) { |
| | | MemberDTO memberDTO = null; |
| | | if (StringUtils.isNotBlank(query.getNickname()) || StringUtils.isNotBlank( |
| | | query.getPhone())) { |
| | | memberDTO = new MemberDTO(); |
| | | memberDTO.setNickname(query.getNickname()); |
| | | memberDTO.setPhone(query.getPhone()); |
| | | } |
| | | return memberDTO; |
| | | } |
| | | |
| | | /** |
| | | * 查询领取详情列表 |
| | | * |
| | | * @param query 管理后台-优惠券领取详情查询对象 |
| | | * @return List<CouponReceiveDetailVO> |
| | | */ |
| | | @Override |
| | | public List<CouponReceiveDetailVO> getCouponReceiveDetailList(MgtCouponReceiveQuery query) { |
| | | MemberDTO memberDTO = getMemberQueryParam(query); |
| | | Set<Long> memberIdSet = getMemberIdSet(memberDTO); |
| | | List<CouponMember> couponMemberList = couponMemberService.lambdaQuery() |
| | | .eq(StringUtils.isNotNull(query.getCouponStatus()), |
| | | CouponMember::getCouponStatus, query.getCouponStatus()) |
| | | .in(StringUtils.isNotEmpty(memberIdSet), CouponMember::getMemberId, memberIdSet) |
| | | .eq(CouponMember::getCouponId, query.getId()) |
| | | .list(); |
| | | if (StringUtils.isEmpty(couponMemberList)) { |
| | | throw new ServiceException("没有符合条件的数据导出"); |
| | | } |
| | | List<CouponReceiveDetailVO> couponReceiveDetailVOList = BeanUtils.copyList(couponMemberList, |
| | | CouponReceiveDetailVO.class); |
| | | handleCouponReceiveDetailVO(couponReceiveDetailVOList); |
| | | return couponReceiveDetailVOList; |
| | | } |
| | | } |
| | |
| | | <artifactId>fastjson</artifactId> |
| | | <version>1.2.47</version> |
| | | </dependency> |
| | | |
| | | <!-- 分布式事务 --> |
| | | <dependency> |
| | | <groupId>com.ruoyi</groupId> |
| | | <artifactId>ruoyi-common-seata</artifactId> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.system.api.domain.CustomConfig; |
| | | import com.ruoyi.system.domain.dto.PointsConfigDTO; |
| | | import com.ruoyi.system.service.ICustomConfigService; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import javax.annotation.Resource; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | CustomConfig one = iCustomConfigService.getOne(wrapper); |
| | | return R.ok(one); |
| | | } |
| | | |
| | | /** |
| | | * 保存积分设置 |
| | | * |
| | | * @param dto 积分配置数据传输对象 |
| | | */ |
| | | @ApiOperation(value = "保存积分设置") |
| | | @PostMapping("/save-points") |
| | | public R<?> savePointsSettings(@Validated @RequestBody PointsConfigDTO dto) { |
| | | iCustomConfigService.savePointsSettings(dto); |
| | | return R.ok(); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ruoyi.system.domain.dto; |
| | | |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import java.io.Serializable; |
| | | import java.math.BigDecimal; |
| | | import javax.validation.constraints.NotNull; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * @author mitao |
| | | * @date 2024/6/11 |
| | | */ |
| | | @Data |
| | | @ApiModel(value = "积分配置数据传输对象", description = "积分配置数据传输对象") |
| | | public class PointsConfigDTO implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 8009805126467325247L; |
| | | |
| | | @ApiModelProperty(value = "消费金额") |
| | | @NotNull(message = "消费金额不能为空") |
| | | private BigDecimal consumeAmount; |
| | | |
| | | @ApiModelProperty(value = "积分") |
| | | @NotNull(message = "积分不能为空") |
| | | private Integer points; |
| | | } |
| | |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.ruoyi.system.api.domain.CustomConfig; |
| | | import com.ruoyi.system.domain.dto.PointsConfigDTO; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | */ |
| | | public interface ICustomConfigService extends IService<CustomConfig> { |
| | | |
| | | void savePointsSettings(PointsConfigDTO dto); |
| | | } |
| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.google.common.collect.Lists; |
| | | import com.ruoyi.system.api.constants.ConfigEnum; |
| | | import com.ruoyi.system.api.domain.CustomConfig; |
| | | import com.ruoyi.system.domain.dto.PointsConfigDTO; |
| | | import com.ruoyi.system.mapper.CustomConfigMapper; |
| | | import com.ruoyi.system.service.ICustomConfigService; |
| | | import java.util.Optional; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class CustomConfigServiceImpl extends ServiceImpl<CustomConfigMapper, CustomConfig> implements ICustomConfigService { |
| | | |
| | | @Override |
| | | @Transactional(propagation = Propagation.REQUIRES_NEW) |
| | | public void savePointsSettings(PointsConfigDTO dto) { |
| | | Optional<CustomConfig> customConfigOptional = getCustomConfigByKey( |
| | | ConfigEnum.MEMBER_POINTS_MONEY.getKey()); |
| | | CustomConfig moneyConfig = customConfigOptional.orElseGet(() -> { |
| | | CustomConfig config = new CustomConfig(); |
| | | config.setConfigKey(ConfigEnum.MEMBER_POINTS_MONEY.getKey()); |
| | | config.setConfigType(ConfigEnum.MEMBER_POINTS_MONEY.getKeyType()); |
| | | config.setConfigName(ConfigEnum.MEMBER_POINTS_MONEY.getKeyName()); |
| | | return config; |
| | | }); |
| | | moneyConfig.setConfigValue(dto.getConsumeAmount().toString()); |
| | | Optional<CustomConfig> customConfigByKey = getCustomConfigByKey( |
| | | ConfigEnum.MEMBER_POINTS_POINTS.getKey()); |
| | | CustomConfig pointsConfig = customConfigByKey.orElseGet(() -> { |
| | | CustomConfig config = new CustomConfig(); |
| | | config.setConfigKey(ConfigEnum.MEMBER_POINTS_POINTS.getKey()); |
| | | config.setConfigType(ConfigEnum.MEMBER_POINTS_POINTS.getKeyType()); |
| | | config.setConfigName(ConfigEnum.MEMBER_POINTS_POINTS.getKeyName()); |
| | | return config; |
| | | }); |
| | | pointsConfig.setConfigValue(dto.getPoints().toString()); |
| | | this.saveOrUpdateBatch(Lists.newArrayList(moneyConfig, pointsConfig)); |
| | | } |
| | | |
| | | private Optional<CustomConfig> getCustomConfigByKey(String key) { |
| | | return this.lambdaQuery() |
| | | .eq(CustomConfig::getConfigType, key) |
| | | .eq(CustomConfig::getDelFlag, 0).oneOpt(); |
| | | } |
| | | } |
| | |
| | | import javax.websocket.OnMessage; |
| | | import javax.websocket.OnOpen; |
| | | import javax.websocket.Session; |
| | | import javax.websocket.server.PathParam; |
| | | import javax.websocket.server.ServerEndpoint; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | /** |
| | | * websocket 消息处理 |
| | | * |
| | | * @author ruoyi |
| | | * @作者 ruoyi |
| | | */ |
| | | @Component |
| | | @ServerEndpoint("/websocket/message") |
| | | @ServerEndpoint("/websocket/message/{clientType}") |
| | | public class WebSocketServer { |
| | | |
| | | /** |
| | | * WebSocketServer 日志控制器 |
| | | */ |
| | | private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketServer.class); |
| | | |
| | | /** |
| | | * 默认最多允许同时在线人数100 |
| | | */ |
| | | public static int socketMaxOnlineCount = 100; |
| | | |
| | | public static int socketMaxOnlineCount = 1000; |
| | | private static Semaphore socketSemaphore = new Semaphore(socketMaxOnlineCount); |
| | | |
| | | /** |
| | | * 连接建立成功调用的方法 |
| | | */ |
| | | @OnOpen |
| | | public void onOpen(Session session) throws Exception { |
| | | public void onOpen(Session session, @PathParam("clientType") Integer clientType) |
| | | throws Exception { |
| | | boolean semaphoreFlag = false; |
| | | // 尝试获取信号量 |
| | | semaphoreFlag = SemaphoreUtils.tryAcquire(socketSemaphore); |
| | | if (!semaphoreFlag) { |
| | | // 未获取到信号量 |
| | | LOGGER.error("\n 当前在线人数超过限制数- {}", socketMaxOnlineCount); |
| | | WebSocketUsers.sendMessageToUserByText(session, |
| | | "当前在线人数超过限制数:" + socketMaxOnlineCount); |
| | | session.close(); |
| | | } else { |
| | | // 添加用户 |
| | | WebSocketUsers.put(session.getId(), session); |
| | | WebSocketUsers.put(session.getId(), session, clientType); |
| | | LOGGER.info("\n 建立连接 - {}", session); |
| | | LOGGER.info("\n 当前人数 - {}", WebSocketUsers.getUsers().size()); |
| | | WebSocketUsers.sendMessageToUserByText(session, "连接成功"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 连接关闭时处理 |
| | | */ |
| | | @OnClose |
| | | public void onClose(Session session) { |
| | | LOGGER.info("\n 关闭连接 - {}", session); |
| | | // 移除用户 |
| | | WebSocketUsers.remove(session.getId()); |
| | | // 获取到信号量则需释放 |
| | | SemaphoreUtils.release(socketSemaphore); |
| | | } |
| | | |
| | | /** |
| | | * 抛出异常时处理 |
| | | */ |
| | | @OnError |
| | | public void onError(Session session, Throwable exception) throws Exception { |
| | | if (session.isOpen()) { |
| | | // 关闭连接 |
| | | session.close(); |
| | | } |
| | | String sessionId = session.getId(); |
| | | LOGGER.info("\n 连接异常 - {}", sessionId); |
| | | LOGGER.info("\n 异常信息 - {}", exception); |
| | | // 移出用户 |
| | | WebSocketUsers.remove(sessionId); |
| | | // 获取到信号量则需释放 |
| | | SemaphoreUtils.release(socketSemaphore); |
| | | } |
| | | |
| | | /** |
| | | * 服务器接收到客户端消息时调用的方法 |
| | | */ |
| | | @OnMessage |
| | | public void onMessage(String message, Session session) { |
| | | String msg = message.replace("你", "我").replace("吗", ""); |
| | | String msg = message.replace("你", "我").replace("吗", "").replace("PING", "PONG") |
| | | .replace("ping", "pong"); |
| | | WebSocketUsers.sendMessageToUserByText(session, msg); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ruoyi.system.websocket; |
| | | |
| | | import com.ruoyi.system.api.util.WebSocketUsers_Bak; |
| | | import java.util.concurrent.Semaphore; |
| | | import javax.websocket.OnClose; |
| | | import javax.websocket.OnError; |
| | | import javax.websocket.OnMessage; |
| | | import javax.websocket.OnOpen; |
| | | import javax.websocket.Session; |
| | | import javax.websocket.server.ServerEndpoint; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * websocket 消息处理 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Component |
| | | @ServerEndpoint("/websocket/message") |
| | | public class WebSocketServer_Bak { |
| | | |
| | | /** |
| | | * WebSocketServer 日志控制器 |
| | | */ |
| | | private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketServer_Bak.class); |
| | | |
| | | /** |
| | | * 默认最多允许同时在线人数100 |
| | | */ |
| | | public static int socketMaxOnlineCount = 100; |
| | | |
| | | private static Semaphore socketSemaphore = new Semaphore(socketMaxOnlineCount); |
| | | |
| | | /** |
| | | * 连接建立成功调用的方法 |
| | | */ |
| | | @OnOpen |
| | | public void onOpen(Session session) throws Exception { |
| | | boolean semaphoreFlag = false; |
| | | // 尝试获取信号量 |
| | | semaphoreFlag = SemaphoreUtils.tryAcquire(socketSemaphore); |
| | | if (!semaphoreFlag) { |
| | | // 未获取到信号量 |
| | | LOGGER.error("\n 当前在线人数超过限制数- {}", socketMaxOnlineCount); |
| | | WebSocketUsers_Bak.sendMessageToUserByText(session, |
| | | "当前在线人数超过限制数:" + socketMaxOnlineCount); |
| | | session.close(); |
| | | } else { |
| | | // 添加用户 |
| | | WebSocketUsers_Bak.put(session.getId(), session); |
| | | LOGGER.info("\n 建立连接 - {}", session); |
| | | LOGGER.info("\n 当前人数 - {}", WebSocketUsers_Bak.getUsers().size()); |
| | | WebSocketUsers_Bak.sendMessageToUserByText(session, "连接成功"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 连接关闭时处理 |
| | | */ |
| | | @OnClose |
| | | public void onClose(Session session) { |
| | | LOGGER.info("\n 关闭连接 - {}", session); |
| | | // 移除用户 |
| | | WebSocketUsers_Bak.remove(session.getId()); |
| | | // 获取到信号量则需释放 |
| | | SemaphoreUtils.release(socketSemaphore); |
| | | } |
| | | |
| | | /** |
| | | * 抛出异常时处理 |
| | | */ |
| | | @OnError |
| | | public void onError(Session session, Throwable exception) throws Exception { |
| | | if (session.isOpen()) { |
| | | // 关闭连接 |
| | | session.close(); |
| | | } |
| | | String sessionId = session.getId(); |
| | | LOGGER.info("\n 连接异常 - {}", sessionId); |
| | | LOGGER.info("\n 异常信息 - {}", exception); |
| | | // 移出用户 |
| | | WebSocketUsers_Bak.remove(sessionId); |
| | | // 获取到信号量则需释放 |
| | | SemaphoreUtils.release(socketSemaphore); |
| | | } |
| | | |
| | | /** |
| | | * 服务器接收到客户端消息时调用的方法 |
| | | */ |
| | | @OnMessage |
| | | public void onMessage(String message, Session session) { |
| | | String msg = message.replace("你", "我").replace("吗", ""); |
| | | WebSocketUsers_Bak.sendMessageToUserByText(session, msg); |
| | | } |
| | | } |