前端-胡立永 1 month ago
parent
commit
31f6ae9734
3 changed files with 23 additions and 17 deletions
  1. +11
    -3
      jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/system/util/AppletUserUtil.java
  2. +0
    -5
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiAddressController.java
  3. +12
    -9
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiAddressServiceImpl.java

+ 11
- 3
jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/system/util/AppletUserUtil.java View File

@ -6,6 +6,8 @@ import org.apache.shiro.subject.Subject;
import org.jeecg.common.api.IAppletUserService;
import org.jeecg.common.system.vo.AppletUser;
import org.jeecg.common.util.SpringContextUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
@ -58,14 +60,20 @@ public class AppletUserUtil {
return user != null ? user.getOpenid() : null;
}
public static HttpServletRequest getCurrentRequest() {
ServletRequestAttributes attributes =
(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
return attributes.getRequest();
}
/**
* 从请求中获取token并解析用户信息
* 从请求中获取token并解析用户信息在用户未登录的情况下可能返回null
*
* @param request HTTP请求
* @return 小程序用户信息
*/
public static AppletUser getAppletUserFromRequest(HttpServletRequest request) {
public static AppletUser getAppletUserFromRequest() {
try {
HttpServletRequest request = getCurrentRequest();
String token = request.getHeader("X-Access-Token");
if (token == null) {
token = request.getParameter("token");


+ 0
- 5
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiAddressController.java View File

@ -45,7 +45,6 @@ public class AppletApiAddressController {
// @AutoLog(value = "地址管理")
@Operation(summary="小程序收货地址-地址列表查询")
@GetMapping(value = "/list")
@IgnoreAuth
public Result<IPage<AppletShippingAddress>> queryPageList(AppletShippingAddress appletShippingAddress,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
@ -63,7 +62,6 @@ public class AppletApiAddressController {
*/
@Operation(summary="小程序收货地址-添加地址")
@PostMapping(value = "/add")
@IgnoreAuth
public Result<String> add(AppletShippingAddress appletShippingAddress) { // 去掉@RequestBody
appletAddressService.save(appletShippingAddress);
return Result.OK("添加成功!");
@ -78,7 +76,6 @@ public class AppletApiAddressController {
//@AutoLog(value = "小程序收货地址-通过id查询")
@Operation(summary="小程序收货地址-通过id查询")
@GetMapping(value = "/getById")
@IgnoreAuth
public Result<AppletShippingAddress> queryById(@RequestParam(name="id",required=true) String id) {
AppletShippingAddress appletShippingAddress = appletAddressService.getById(id);
if(appletShippingAddress==null) {
@ -95,7 +92,6 @@ public class AppletApiAddressController {
*/
@Operation(summary="小程序收货地址-修改地址")
@PutMapping(value = "/update")
@IgnoreAuth
public Result<String> edit(AppletShippingAddress appletShippingAddress) {
appletAddressService.updateById(appletShippingAddress);
return Result.OK("编辑成功!");
@ -109,7 +105,6 @@ public class AppletApiAddressController {
*/
@Operation(summary="小程序收货地址-设置默认地址")
@PutMapping(value = "/setDefault")
@IgnoreAuth
public Result<String> setDefaultAddress(@RequestParam String addressId) {
appletAddressService.setDefaultAddress(addressId);
return Result.OK("设置默认地址成功!");


+ 12
- 9
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiAddressServiceImpl.java View File

@ -5,7 +5,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.util.AppletUserUtil;
import org.jeecg.common.system.vo.AppletUser;
import org.jeecg.modules.applet.service.AppletApiAddressService;
import org.jeecg.modules.demo.appletShippingAddress.entity.AppletShippingAddress;
import org.jeecg.modules.demo.appletShippingAddress.service.IAppletShippingAddressService;
@ -31,6 +33,7 @@ public class AppletApiAddressServiceImpl implements AppletApiAddressService {
String userId = AppletUserUtil.getCurrentAppletUserId();
Page<AppletShippingAddress> page1 = appletShippingAddressService
.lambdaQuery()
.eq(AppletShippingAddress::getUserId, userId)
@ -50,16 +53,16 @@ public class AppletApiAddressServiceImpl implements AppletApiAddressService {
@Override
public void save(AppletShippingAddress appletShippingAddress) {
if (appletShippingAddress == null) {
throw new IllegalArgumentException("地址信息不能为空");
throw new JeecgBootException("地址信息不能为空");
}
if (StrUtil.isBlank(appletShippingAddress.getName())) {
throw new IllegalArgumentException("收货人不能为空");
throw new JeecgBootException("收货人不能为空");
}
if (StrUtil.isBlank(appletShippingAddress.getPhone())) {
throw new IllegalArgumentException("联系电话不能为空");
throw new JeecgBootException("联系电话不能为空");
}
if (StrUtil.isBlank(appletShippingAddress.getDetail())) {
throw new IllegalArgumentException("详细地址不能为空");
throw new JeecgBootException("详细地址不能为空");
}
String userId = AppletUserUtil.getCurrentAppletUserId();
@ -90,16 +93,16 @@ public class AppletApiAddressServiceImpl implements AppletApiAddressService {
@Override
public void updateById(AppletShippingAddress appletShippingAddress) {
if (appletShippingAddress == null || StrUtil.isBlank(appletShippingAddress.getId())) {
throw new IllegalArgumentException("地址信息或ID不能为空");
throw new JeecgBootException("地址信息或ID不能为空");
}
if (StrUtil.isBlank(appletShippingAddress.getName())) {
throw new IllegalArgumentException("收货人不能为空");
throw new JeecgBootException("收货人不能为空");
}
if (StrUtil.isBlank(appletShippingAddress.getPhone())) {
throw new IllegalArgumentException("联系电话不能为空");
throw new JeecgBootException("联系电话不能为空");
}
if (StrUtil.isBlank(appletShippingAddress.getDetail())) {
throw new IllegalArgumentException("详细地址不能为空");
throw new JeecgBootException("详细地址不能为空");
}
appletShippingAddressService.updateById(appletShippingAddress);
@ -113,7 +116,7 @@ public class AppletApiAddressServiceImpl implements AppletApiAddressService {
@Override
public void setDefaultAddress(String addressId) {
if (StrUtil.isBlank(addressId)) {
throw new IllegalArgumentException("地址ID不能为空");
throw new JeecgBootException("地址ID不能为空");
}
String userId = AppletUserUtil.getCurrentAppletUserId();


Loading…
Cancel
Save