From 2c022df7f87c387169fb3ed35a7aaca09b1323f6 Mon Sep 17 00:00:00 2001 From: chen-xin-zhi <3588068430@qq.com> Date: Mon, 17 Mar 2025 18:47:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0https?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../heritage/constant/FileConstant.java | 4 +- .../controller/good/GoodController.java | 24 +++ .../order/AdvanceOrderController.java | 29 +++ .../controller/order/OrderController.java | 35 +++- .../controller/wx/WeChatPayController.java | 11 ++ .../dto/order/OrderStatusUpdateRequest.java | 29 +++ .../model/dto/user/UserAddRequest.java | 7 +- .../model/dto/user/UserQueryRequest.java | 5 - .../model/dto/user/UserUpdateRequest.java | 7 +- .../cultural/heritage/model/entity/User.java | 4 - .../heritage/model/vo/user/UserVO.java | 7 +- .../service/user/impl/UserServiceImpl.java | 7 +- .../service/wx/impl/WeChatServiceImpl.java | 4 +- .../cultural/heritage/test/GoodHandler.java | 178 +++++++++--------- .../com/cultural/heritage/test/TestRedis.java | 72 ++++--- src/main/resources/application.yml | 4 +- 16 files changed, 261 insertions(+), 166 deletions(-) create mode 100644 src/main/java/com/cultural/heritage/model/dto/order/OrderStatusUpdateRequest.java diff --git a/src/main/java/com/cultural/heritage/constant/FileConstant.java b/src/main/java/com/cultural/heritage/constant/FileConstant.java index 835dc4a..dc5b1ef 100644 --- a/src/main/java/com/cultural/heritage/constant/FileConstant.java +++ b/src/main/java/com/cultural/heritage/constant/FileConstant.java @@ -8,9 +8,9 @@ public interface FileConstant { // String SERVER_HOST = "http://123.249.108.160:8888/api/file/downloadFile?objectKey="; -// String SERVER_HOST = "https://www.carboner.cn:8888/api/file/downloadFile?objectKey="; + String SERVER_HOST = "https://www.carboner.cn:8888/api/file/downloadFile?objectKey="; - String SERVER_HOST = ""; +// String SERVER_HOST = ""; } diff --git a/src/main/java/com/cultural/heritage/controller/good/GoodController.java b/src/main/java/com/cultural/heritage/controller/good/GoodController.java index b00c90d..f266c9a 100644 --- a/src/main/java/com/cultural/heritage/controller/good/GoodController.java +++ b/src/main/java/com/cultural/heritage/controller/good/GoodController.java @@ -979,5 +979,29 @@ public class GoodController { + /** + * 小程序端用户根据id查询服务类商品信息(不含预约日期和时间段) + * @param commonRequest 商品id + * @return 服务类商品信息 + */ + @PostMapping("/query/service/id") + @Operation(summary = "小程序端用户根据id查询服务类商品信息(不含预约日期和时间段)", description = "参数:商品id,权限:所有人,方法名:queryServiceGoodMainInfoById") + public BaseResponse queryServiceGoodMainInfoById(@RequestBody CommonRequest commonRequest, HttpServletRequest request) { + if (commonRequest == null || commonRequest.getId() <= 0) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + userService.getLoginUser(request); + Long id = commonRequest.getId(); + Good good = goodService.getById(id); + ThrowUtils.throwIf(good == null, ErrorCode.NOT_FOUND_ERROR, "商品不存在"); + // TODO + good.setGoodImg(FileConstant.SERVER_HOST + good.getGoodImg()); + ServiceGoodCardVO serviceGoodVO = new ServiceGoodCardVO(); + BeanUtils.copyProperties(good, serviceGoodVO); + + return ResultUtils.success(serviceGoodVO); + } + + } diff --git a/src/main/java/com/cultural/heritage/controller/order/AdvanceOrderController.java b/src/main/java/com/cultural/heritage/controller/order/AdvanceOrderController.java index 712eb8e..5196f55 100644 --- a/src/main/java/com/cultural/heritage/controller/order/AdvanceOrderController.java +++ b/src/main/java/com/cultural/heritage/controller/order/AdvanceOrderController.java @@ -4,6 +4,7 @@ package com.cultural.heritage.controller.order; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.cultural.heritage.annotation.AuthCheck; import com.cultural.heritage.common.BaseResponse; @@ -17,6 +18,7 @@ import com.cultural.heritage.exception.ThrowUtils; import com.cultural.heritage.model.dto.CommonRequest; import com.cultural.heritage.model.dto.advanceOrder.AdvanceOrderAddRequest; import com.cultural.heritage.model.dto.advanceOrder.AdvanceOrderQueryRequest; +import com.cultural.heritage.model.dto.order.OrderStatusUpdateRequest; import com.cultural.heritage.model.dto.snapshot.ContactsSnapshot; import com.cultural.heritage.model.dto.snapshot.PhotoProductsSnapshot; import com.cultural.heritage.model.entity.*; @@ -34,6 +36,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -348,4 +351,30 @@ public class AdvanceOrderController { + /** + * Web端管理员更新写真预约订单状态 + * @param orderStatusUpdateRequest 订单状态更新请求体 + * @return 是否更新成功 + */ + @PostMapping("/update/orderStatus") + @Operation(summary = "Web端管理员更新写真预约订单状态", description = "参数:订单状态更新请求体,权限:管理员(admin, boss),方法名:updateOrderStatus") + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + public BaseResponse updateOrderStatus(@RequestBody OrderStatusUpdateRequest orderStatusUpdateRequest) { + if (orderStatusUpdateRequest == null || orderStatusUpdateRequest.getId() <= 0) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + Long id = orderStatusUpdateRequest.getId(); + String orderStatus = orderStatusUpdateRequest.getOrderStatus(); + ThrowUtils.throwIf(StringUtils.isBlank(orderStatus), ErrorCode.OPERATION_ERROR, "订单状态参数为空"); + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.eq("id", id); + updateWrapper.set("orderStatus", orderStatus); + boolean result = advanceOrderService.update(updateWrapper); + ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "订单状态不存在或订单状态更新失败"); + return ResultUtils.success(true); + } + + + + } diff --git a/src/main/java/com/cultural/heritage/controller/order/OrderController.java b/src/main/java/com/cultural/heritage/controller/order/OrderController.java index 2b04556..96b41d0 100644 --- a/src/main/java/com/cultural/heritage/controller/order/OrderController.java +++ b/src/main/java/com/cultural/heritage/controller/order/OrderController.java @@ -18,6 +18,7 @@ import com.cultural.heritage.model.dto.cart.CartOrderItemAddRequest; import com.cultural.heritage.model.dto.cartService.CartExperienceOrderAddRequest; import com.cultural.heritage.model.dto.cartService.CartExperienceOrderItemAddRequest; import com.cultural.heritage.model.dto.order.OrderQueryRequest; +import com.cultural.heritage.model.dto.order.OrderStatusUpdateRequest; import com.cultural.heritage.model.dto.order.OrderUpdateRequest; import com.cultural.heritage.model.dto.order.capital.GeneralGoodSingleBuyAddRequest; import com.cultural.heritage.model.dto.order.capital.OrderMainInfoAddRequest; @@ -39,6 +40,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PostMapping; @@ -359,12 +361,12 @@ public class OrderController { /** - * Web端管理员更新订单状态 + * Web端管理员更新物流单号 * @param orderUpdateRequest 订单状态更新请求体 * @return 是否更新成功 */ @PostMapping("/update") - @Operation(summary = "Web端管理员更新订单状态", description = "参数:订单状态更新请求体,权限:管理员(admin, boss),方法名:updateOrderStatus") + @Operation(summary = "Web端管理员更新物流单号", description = "参数:订单状态更新请求体,权限:管理员(admin, boss),方法名:updateOrderStatus") @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse updateOrderStatus(@RequestBody OrderUpdateRequest orderUpdateRequest) { if (orderUpdateRequest == null || orderUpdateRequest.getId() <= 0) { @@ -377,7 +379,7 @@ public class OrderController { updateWrapper.set("trackingNumber", trackingNumber); updateWrapper.set("orderStatus", OrderStatusConstant.PENDING_DELIVERY); boolean result = orderService.update(updateWrapper); - ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR); + ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "订单状态不存在或订单状态更新失败"); return ResultUtils.success(true); } @@ -566,4 +568,31 @@ public class OrderController { + + /** + * Web端管理员更新订单状态 + * @param orderStatusUpdateRequest 订单状态更新请求体 + * @return 是否更新成功 + */ + @PostMapping("/update/all/orderStatus") + @Operation(summary = "Web端管理员更新订单状态", description = "参数:订单状态更新请求体,权限:管理员(admin, boss),方法名:updateAllOrderStatus") + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + public BaseResponse updateAllOrderStatus(@RequestBody OrderStatusUpdateRequest orderStatusUpdateRequest) { + if (orderStatusUpdateRequest == null || orderStatusUpdateRequest.getId() <= 0) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + Long id = orderStatusUpdateRequest.getId(); + String orderStatus = orderStatusUpdateRequest.getOrderStatus(); + ThrowUtils.throwIf(StringUtils.isBlank(orderStatus), ErrorCode.OPERATION_ERROR, "订单状态参数为空"); + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.eq("id", id); + updateWrapper.set("orderStatus", orderStatus); + boolean result = orderService.update(updateWrapper); + ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "订单状态不存在或订单状态更新失败"); + return ResultUtils.success(true); + } + + + + } diff --git a/src/main/java/com/cultural/heritage/controller/wx/WeChatPayController.java b/src/main/java/com/cultural/heritage/controller/wx/WeChatPayController.java index 34dcd30..66fcd80 100644 --- a/src/main/java/com/cultural/heritage/controller/wx/WeChatPayController.java +++ b/src/main/java/com/cultural/heritage/controller/wx/WeChatPayController.java @@ -23,6 +23,7 @@ import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPayment import com.wechat.pay.java.service.payments.model.Transaction; import com.wechat.pay.java.service.refund.model.Refund; import com.wechat.pay.java.service.refund.model.RefundNotification; +import io.swagger.v3.oas.annotations.Hidden; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; @@ -85,9 +86,11 @@ public class WeChatPayController { + /** * JSAPI 下单回调(商品类) */ + @Hidden @PostMapping("/payment/callback") @Transactional(rollbackFor = Exception.class) @Operation(summary = "JSAPI 下单回调(商品类)", description = "参数:订单id, 权限:所有人, 方法名:callbackPayment") @@ -103,6 +106,8 @@ public class WeChatPayController { + + /** * JSAPI 下单(写真预约类) */ @@ -128,6 +133,7 @@ public class WeChatPayController { /** * JSAPI 下单回调(写真预约类) */ + @Hidden @PostMapping("/payment/photo/callback") @Transactional(rollbackFor = Exception.class) @Operation(summary = "JSAPI 下单回调(写真预约类)", description = "参数:订单id, 权限:所有人, 方法名:callbackPhotoProductsPayment") @@ -211,6 +217,7 @@ public class WeChatPayController { * Web管理员剩余部分退款 * @param commonRequest 订单id */ + @Hidden @PostMapping("/refund/rest/create") @Operation(summary = "Web管理员剩余部分退款", description = "参数:订单id, 权限:web端管理员, 方法名:createRestRefund") @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) @@ -233,6 +240,7 @@ public class WeChatPayController { /** * 全额退款回调(商品类) */ + @Hidden @PostMapping("/refund/callback") @Operation(summary = "全额退款回调(商品类)", description = "参数:订单id, 权限:web端管理员, 方法名:callbackRefund") public BaseResponse callbackRefund(HttpServletRequest request) { @@ -248,6 +256,7 @@ public class WeChatPayController { /** * 全额退款回调(写真预约类) */ + @Hidden @PostMapping("/refund/photo/callback") @Operation(summary = "全额退款回调(写真预约类)", description = "参数:订单id, 权限:web端管理员, 方法名:callbackPhotoProductsRefund") public BaseResponse callbackPhotoProductsRefund(HttpServletRequest request) { @@ -265,6 +274,7 @@ public class WeChatPayController { /** * 部分退款回调 */ + @Hidden @PostMapping("/refund/part/callback") @Operation(summary = "部分退款回调", description = "参数:订单id, 权限:web端管理员, 方法名:callbackRefundPart") public BaseResponse callbackRefundPart(HttpServletRequest request) { @@ -282,6 +292,7 @@ public class WeChatPayController { /** * 剩余退款回调 */ + @Hidden @PostMapping("/refund/rest/callback") @Operation(summary = "剩余退款回调", description = "参数:订单id, 权限:web端管理员, 方法名:callbackRestRefund") public BaseResponse callbackRestRefund(HttpServletRequest request) { diff --git a/src/main/java/com/cultural/heritage/model/dto/order/OrderStatusUpdateRequest.java b/src/main/java/com/cultural/heritage/model/dto/order/OrderStatusUpdateRequest.java new file mode 100644 index 0000000..1b803be --- /dev/null +++ b/src/main/java/com/cultural/heritage/model/dto/order/OrderStatusUpdateRequest.java @@ -0,0 +1,29 @@ +package com.cultural.heritage.model.dto.order; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +@Data +public class OrderStatusUpdateRequest implements Serializable { + + /** + * 订单id + */ + @Schema(description = "订单id", example = "445") + private Long id; + + + /** + * 订单状态 + */ + @Schema(description = "订单状态", example = "待支付") + private String orderStatus; + + + + @Serial + private static final long serialVersionUID = 1L; +} diff --git a/src/main/java/com/cultural/heritage/model/dto/user/UserAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/user/UserAddRequest.java index b00d734..24603b7 100644 --- a/src/main/java/com/cultural/heritage/model/dto/user/UserAddRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/user/UserAddRequest.java @@ -11,7 +11,7 @@ import java.io.Serializable; */ @Data -@Schema(description = "用户创建请求体", requiredProperties = {"userName", "userAccount", "userPassword", "userAvatar", "phone", "userRole"}) +@Schema(description = "用户创建请求体", requiredProperties = {"userName", "userAccount", "userPassword", "userAvatar", "userRole"}) public class UserAddRequest implements Serializable { @@ -40,11 +40,6 @@ public class UserAddRequest implements Serializable { @Schema(description = "用户头像", example = "https://xxx/xxx.jpg") private String userAvatar; - /** - * 手机号 - */ - @Schema(description = "手机号", example = "18845892473") - private String phone; /** * 用户角色 user, admin diff --git a/src/main/java/com/cultural/heritage/model/dto/user/UserQueryRequest.java b/src/main/java/com/cultural/heritage/model/dto/user/UserQueryRequest.java index e31f6bd..f1fa937 100644 --- a/src/main/java/com/cultural/heritage/model/dto/user/UserQueryRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/user/UserQueryRequest.java @@ -30,11 +30,6 @@ public class UserQueryRequest extends PageRequest implements Serializable { @Schema(description = "用户昵称", example = "chenxinzhi") private String userName; - /** - * 手机号 - */ - @Schema(description = "手机号", example = "18845892473") - private String phone; /** * 用户角色:user/admin/ban diff --git a/src/main/java/com/cultural/heritage/model/dto/user/UserUpdateRequest.java b/src/main/java/com/cultural/heritage/model/dto/user/UserUpdateRequest.java index 7fbe271..df8c8c5 100644 --- a/src/main/java/com/cultural/heritage/model/dto/user/UserUpdateRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/user/UserUpdateRequest.java @@ -7,7 +7,7 @@ import java.io.Serial; import java.io.Serializable; @Data -@Schema(description = "用户更新请求体", requiredProperties = {"id", "userPassword", "userName", "userAvatar", "phone", "userRole"}) +@Schema(description = "用户更新请求体", requiredProperties = {"id", "userPassword", "userName", "userAvatar", "userRole"}) public class UserUpdateRequest implements Serializable { @@ -35,11 +35,6 @@ public class UserUpdateRequest implements Serializable { @Schema(description = "用户头像", example = "https://xxx/xxx.jpg") private String userAvatar; - /** - * 手机号 - */ - @Schema(description = "手机号", example = "18845892473") - private String phone; /** * 用户角色 diff --git a/src/main/java/com/cultural/heritage/model/entity/User.java b/src/main/java/com/cultural/heritage/model/entity/User.java index 7d90036..dc9236c 100644 --- a/src/main/java/com/cultural/heritage/model/entity/User.java +++ b/src/main/java/com/cultural/heritage/model/entity/User.java @@ -50,10 +50,6 @@ public class User implements Serializable { */ private String userAvatar; - /** - * 手机号 - */ - private String phone; /** * 积分 diff --git a/src/main/java/com/cultural/heritage/model/vo/user/UserVO.java b/src/main/java/com/cultural/heritage/model/vo/user/UserVO.java index fd43f54..2ea298f 100644 --- a/src/main/java/com/cultural/heritage/model/vo/user/UserVO.java +++ b/src/main/java/com/cultural/heritage/model/vo/user/UserVO.java @@ -2,6 +2,7 @@ package com.cultural.heritage.model.vo.user; import lombok.Data; +import java.io.Serial; import java.io.Serializable; @Data @@ -22,11 +23,6 @@ public class UserVO implements Serializable { */ private String userAvatar; - /** - * 手机号 - */ - private String phone; - /** * 积分 */ @@ -38,6 +34,7 @@ public class UserVO implements Serializable { private String userRole; + @Serial private static final long serialVersionUID = 1L; } diff --git a/src/main/java/com/cultural/heritage/service/user/impl/UserServiceImpl.java b/src/main/java/com/cultural/heritage/service/user/impl/UserServiceImpl.java index ea3e5e8..b80aa73 100644 --- a/src/main/java/com/cultural/heritage/service/user/impl/UserServiceImpl.java +++ b/src/main/java/com/cultural/heritage/service/user/impl/UserServiceImpl.java @@ -15,7 +15,6 @@ import com.cultural.heritage.model.entity.User; import com.cultural.heritage.model.enums.UserRoleEnum; import com.cultural.heritage.model.vo.user.UserVO; import com.cultural.heritage.service.user.UserService; -import com.cultural.heritage.utils.RegexUtils; import com.cultural.heritage.utils.SqlUtils; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; @@ -86,14 +85,12 @@ public class UserServiceImpl extends ServiceImpl implements Us String userName = user.getUserName(); String userPassword = user.getUserPassword(); String userAvatar = user.getUserAvatar(); - String phone = user.getPhone(); String userRole = user.getUserRole(); Long id = user.getId(); ThrowUtils.throwIf(update && id == null, ErrorCode.OPERATION_ERROR, "id字段为null"); - if (StringUtils.isAnyBlank(userName, userAvatar, phone, userRole, userPassword)) { + if (StringUtils.isAnyBlank(userName, userAvatar, userRole, userPassword)) { throw new BusinessException(ErrorCode.PARAMS_ERROR, "存在参数为空"); } - ThrowUtils.throwIf(RegexUtils.isPhoneInvalid(phone), ErrorCode.OPERATION_ERROR, "手机号格式错误"); } @@ -142,7 +139,6 @@ public class UserServiceImpl extends ServiceImpl implements Us Long id = userQueryRequest.getId(); String miniOpenId = userQueryRequest.getMiniOpenId(); String userName = userQueryRequest.getUserName(); - String phone = userQueryRequest.getPhone(); String userRole = userQueryRequest.getUserRole(); String sortField = userQueryRequest.getSortField(); String sortOrder = userQueryRequest.getSortOrder(); @@ -151,7 +147,6 @@ public class UserServiceImpl extends ServiceImpl implements Us queryWrapper.eq(id != null, "id", id); queryWrapper.eq(StringUtils.isNotBlank(miniOpenId), "miniOpenId", miniOpenId); queryWrapper.eq(StringUtils.isNotBlank(userRole), "userRole", userRole); - queryWrapper.eq(StringUtils.isNotBlank(phone), "phone", phone); queryWrapper.like(StringUtils.isNotBlank(userName), "userName", userName); queryWrapper.orderBy(SqlUtils.validSortField(sortField), sortOrder.equals(CommonConstant.SORT_ORDER_ASC), sortField); diff --git a/src/main/java/com/cultural/heritage/service/wx/impl/WeChatServiceImpl.java b/src/main/java/com/cultural/heritage/service/wx/impl/WeChatServiceImpl.java index ed38274..7988140 100644 --- a/src/main/java/com/cultural/heritage/service/wx/impl/WeChatServiceImpl.java +++ b/src/main/java/com/cultural/heritage/service/wx/impl/WeChatServiceImpl.java @@ -512,7 +512,7 @@ public class WeChatServiceImpl implements WeChatService { BigDecimal conditionAmount = couponSnapshot.getConditionAmount(); totalAmount = totalAmount.add(conditionAmount); } - totalAmount = totalAmount.multiply(new BigDecimal("100")); +// totalAmount = totalAmount.multiply(new BigDecimal("100")); userService.addOrSubUserPoints(order.getUserId(), isAdd, totalAmount.intValue()); } @@ -522,7 +522,7 @@ public class WeChatServiceImpl implements WeChatService { */ private void dealUserPointsByPhoto(AdvanceOrder advanceOrder, boolean isAdd) { BigDecimal totalAmount = advanceOrder.getTotalAmount(); - totalAmount = totalAmount.multiply(new BigDecimal("100")); +// totalAmount = totalAmount.multiply(new BigDecimal("100")); userService.addOrSubUserPoints(advanceOrder.getUserId(), isAdd, totalAmount.intValue()); } diff --git a/src/main/java/com/cultural/heritage/test/GoodHandler.java b/src/main/java/com/cultural/heritage/test/GoodHandler.java index a36ee5c..d4e43c1 100644 --- a/src/main/java/com/cultural/heritage/test/GoodHandler.java +++ b/src/main/java/com/cultural/heritage/test/GoodHandler.java @@ -1,89 +1,89 @@ -package com.cultural.heritage.test; - -import com.cultural.heritage.model.dto.CommonRequest; -import com.cultural.heritage.model.entity.Good; -import com.cultural.heritage.service.good.GoodService; -import jakarta.annotation.Resource; -import org.springframework.data.redis.core.*; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Set; - -@RestController -public class GoodHandler { - - @Resource - private RedisTemplate redisTemplate; - - - @Resource - private GoodService goodService; - - @PostMapping("/set") - public void set(@RequestBody CommonRequest commonRequest) { - Long id = commonRequest.getId(); - Good good = goodService.getById(id); - redisTemplate.opsForValue().set("good", good); - } - - @GetMapping("/get/{key}") - public Good get(@PathVariable("key") String key) { - return (Good) redisTemplate.opsForValue().get(key); - } - - @DeleteMapping("/delete/{key}") - public boolean delete(@PathVariable("key") String key) { - redisTemplate.delete(key); - return redisTemplate.hasKey(key); - } - - @GetMapping("/string") - public String stringTest() { - redisTemplate.opsForValue().set("str", "Hello World!"); - return (String) redisTemplate.opsForValue().get("str"); - } - - @GetMapping("/list") - public List listTest() { - ListOperations listOperations = redisTemplate.opsForList(); - listOperations.leftPush("list", "hello"); - listOperations.leftPush("list", "World"); - listOperations.leftPush("list", "Java"); - List list = listOperations.range("list", 0, 2); - return list; - } - - - @GetMapping("/set") - public Set setTest() { - SetOperations setOperations = redisTemplate.opsForSet(); - setOperations.add("set", "Hello"); - setOperations.add("set", "Hello"); - setOperations.add("set", "World"); - setOperations.add("set", "World"); - Set set = setOperations.members("set"); - return set; - } - - - @GetMapping("/zset") - public Set zSetTest() { - ZSetOperations zSetOperations = redisTemplate.opsForZSet(); - zSetOperations.add("zset", "Hello", 1); - zSetOperations.add("zset", "World", 3); - zSetOperations.add("zset", "Hi", 2); - Set zset = zSetOperations.range("zset", 0, 2); - return zset; - } - - @GetMapping("/hash") - public String hashTest() { - HashOperations hashOperations = redisTemplate.opsForHash(); - hashOperations.put("key", "hashKey", "hello"); - String value = hashOperations.get("key", "hashKey"); - return value; - } - - -} +//package com.cultural.heritage.test; +// +//import com.cultural.heritage.model.dto.CommonRequest; +//import com.cultural.heritage.model.entity.Good; +//import com.cultural.heritage.service.good.GoodService; +//import jakarta.annotation.Resource; +//import org.springframework.data.redis.core.*; +//import org.springframework.web.bind.annotation.*; +// +//import java.util.List; +//import java.util.Set; +// +//@RestController +//public class GoodHandler { +// +// @Resource +// private RedisTemplate redisTemplate; +// +// +// @Resource +// private GoodService goodService; +// +// @PostMapping("/set") +// public void set(@RequestBody CommonRequest commonRequest) { +// Long id = commonRequest.getId(); +// Good good = goodService.getById(id); +// redisTemplate.opsForValue().set("good", good); +// } +// +// @GetMapping("/get/{key}") +// public Good get(@PathVariable("key") String key) { +// return (Good) redisTemplate.opsForValue().get(key); +// } +// +// @DeleteMapping("/delete/{key}") +// public boolean delete(@PathVariable("key") String key) { +// redisTemplate.delete(key); +// return redisTemplate.hasKey(key); +// } +// +// @GetMapping("/string") +// public String stringTest() { +// redisTemplate.opsForValue().set("str", "Hello World!"); +// return (String) redisTemplate.opsForValue().get("str"); +// } +// +// @GetMapping("/list") +// public List listTest() { +// ListOperations listOperations = redisTemplate.opsForList(); +// listOperations.leftPush("list", "hello"); +// listOperations.leftPush("list", "World"); +// listOperations.leftPush("list", "Java"); +// List list = listOperations.range("list", 0, 2); +// return list; +// } +// +// +// @GetMapping("/set") +// public Set setTest() { +// SetOperations setOperations = redisTemplate.opsForSet(); +// setOperations.add("set", "Hello"); +// setOperations.add("set", "Hello"); +// setOperations.add("set", "World"); +// setOperations.add("set", "World"); +// Set set = setOperations.members("set"); +// return set; +// } +// +// +// @GetMapping("/zset") +// public Set zSetTest() { +// ZSetOperations zSetOperations = redisTemplate.opsForZSet(); +// zSetOperations.add("zset", "Hello", 1); +// zSetOperations.add("zset", "World", 3); +// zSetOperations.add("zset", "Hi", 2); +// Set zset = zSetOperations.range("zset", 0, 2); +// return zset; +// } +// +// @GetMapping("/hash") +// public String hashTest() { +// HashOperations hashOperations = redisTemplate.opsForHash(); +// hashOperations.put("key", "hashKey", "hello"); +// String value = hashOperations.get("key", "hashKey"); +// return value; +// } +// +// +//} diff --git a/src/main/java/com/cultural/heritage/test/TestRedis.java b/src/main/java/com/cultural/heritage/test/TestRedis.java index 54b9973..90c304e 100644 --- a/src/main/java/com/cultural/heritage/test/TestRedis.java +++ b/src/main/java/com/cultural/heritage/test/TestRedis.java @@ -1,40 +1,38 @@ -package com.cultural.heritage.test; - -import org.springframework.stereotype.Component; - -import java.util.Base64; - -@Component -public class TestRedis { - -// @Resource -// private StringRedisTemplate stringRedisTemplate; +//package com.cultural.heritage.test; // -// @Resource -// private GoodMapper goodMapper; +//import org.springframework.stereotype.Component; // -// @PostConstruct -// public void test() { -// List goodList = goodMapper.selectList(null); +//@Component +//public class TestRedis { // -// Map map = goodList.stream().collect(Collectors.toMap -// (good -> good.getId().toString(), good -> good.getName())); -// stringRedisTemplate.opsForHash().putAll("test", map); -// stringRedisTemplate.opsForHash().get("test", "238"); -// } - - - public static void main(String[] args) { - String encodedStr = "PGgxIHN0eWxlPSJ0ZXh0LWFsaWduOiBjZW50ZXI7Ij7ov5nmmK/lr4zmlofmnKxiYXNlNjTmtYvor5U8L2gxPg=="; // 前端 btoa("Hello world!") - - // Base64 解码 - byte[] decodedBytes = Base64.getDecoder().decode(encodedStr); - String decodedStr = new String(decodedBytes); - - System.out.println("解码后的字符串: " + decodedStr); - } - - - - -} +//// @Resource +//// private StringRedisTemplate stringRedisTemplate; +//// +//// @Resource +//// private GoodMapper goodMapper; +//// +//// @PostConstruct +//// public void test() { +//// List goodList = goodMapper.selectList(null); +//// +//// Map map = goodList.stream().collect(Collectors.toMap +//// (good -> good.getId().toString(), good -> good.getName())); +//// stringRedisTemplate.opsForHash().putAll("test", map); +//// stringRedisTemplate.opsForHash().get("test", "238"); +//// } +// +//// +//// public static void main(String[] args) { +//// String encodedStr = "PGgxIHN0eWxlPSJ0ZXh0LWFsaWduOiBjZW50ZXI7Ij7ov5nmmK/lr4zmlofmnKxiYXNlNjTmtYvor5U8L2gxPg=="; // 前端 btoa("Hello world!") +//// +//// // Base64 解码 +//// byte[] decodedBytes = Base64.getDecoder().decode(encodedStr); +//// String decodedStr = new String(decodedBytes); +//// +//// System.out.println("解码后的字符串: " + decodedStr); +//// } +// +// +// +// +//} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index eb69b63..d722f43 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -132,7 +132,9 @@ wx: #通知地址 # notifyUrl: https://winning-mouse-internally.ngrok-free.app # notifyUrl: http://123.249.108.160:8888 - notifyUrl: http://154.8.193.216:9092 +# notifyUrl: http://154.8.193.216:9092 + notifyUrl: https://www.carboner.cn:8888 + #微信服务器地址 domain: https://api.mch.weixin.qq.com