Browse Source

地址和购物车模块

master
Bobi 2 days ago
parent
commit
7be5cfa902
11 changed files with 344 additions and 8 deletions
  1. +1
    -0
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiIndexController.java
  2. +1
    -5
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiProductController.java
  3. +59
    -0
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiAddressService.java
  4. +54
    -0
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiCarService.java
  5. +1
    -0
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiIndexService.java
  6. +108
    -0
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiAddressServiceImpl.java
  7. +113
    -0
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiCarServiceImpl.java
  8. +0
    -1
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiConfigServiceImpl.java
  9. +1
    -0
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiIndexServiceImpl.java
  10. +2
    -2
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiLoginService.java
  11. +4
    -0
      jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletShippingAddress/entity/AppletShippingAddress.java

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

@ -42,4 +42,5 @@ public class AppletApiIndexController {
List<AppletBanner> bannerList = appletIndexService.getBannerList();
return Result.OK(bannerList);
}
}

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

@ -71,16 +71,12 @@ public class AppletApiProductController {
@Operation(summary = "产品详情查询", description = "获取单个产品详细信息")
@GetMapping(value = "/detail")
@IgnoreAuth
public Result<AppletProduct> detail(
@Parameter(description = "产品ID", required = true) @RequestParam String id) {
public Result<AppletProduct> detail(@Parameter(description = "产品ID", required = true) @RequestParam String id) {
log.info("产品详情查询 - id: {}", id);
AppletProduct appletProduct = appletProductService.getProductById(id);
if (appletProduct == null) {
return Result.error("产品不存在");
}
return Result.OK(appletProduct);
}


+ 59
- 0
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiAddressService.java View File

@ -0,0 +1,59 @@
package org.jeecg.modules.applet.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.demo.appletShippingAddress.entity.AppletShippingAddress;
public interface AppletApiAddressService {
/**
* 分页查询地址
*
* @param page
* @return
*/
IPage<AppletShippingAddress> page(Page<AppletShippingAddress> page, AppletShippingAddress appletShippingAddress);
/**
* 添加地址
*
* @param appletShippingAddress
*/
void save(AppletShippingAddress appletShippingAddress);
/**
* 通过id查询
*
* @param id
* @return
*/
AppletShippingAddress getById(String id);
/**
* 修改地址
*
* @param appletShippingAddress
*/
void updateById(AppletShippingAddress appletShippingAddress);
// /**
// * 通过id删除
// *
// * @param id
// */
// void removeById(String id);
//
// /**
// * 批量删除
// *
// * @param list
// */
//
// void removeByIds(List<String> list);
//
}

+ 54
- 0
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiCarService.java View File

@ -0,0 +1,54 @@
package org.jeecg.modules.applet.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.demo.appletCar.entity.AppletCar;
import java.util.List;
public interface AppletApiCarService {
/**
* 查询购物车列表
*
* @param page
* @param queryWrapper
* @return
*/
IPage<AppletCar> page(Page<AppletCar> page, AppletCar appletCar);
/**
* 添加购物车
*
* @param appletCar
*/
void save(AppletCar appletCar);
/**
* 根据id查询购物车
*
* @param id
* @return
*/
AppletCar getById(String id);
/**
* 修改购物车
*
* @param appletCar
*/
void updateById(AppletCar appletCar);
/**
* 批量删除购物车
*
* @param list
*/
void removeByIds(List<String> list);
}

+ 1
- 0
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiIndexService.java View File

@ -17,4 +17,5 @@ public interface AppletApiIndexService {
* 获取Banner列表
*/
List<AppletBanner> getBannerList();
}

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

@ -0,0 +1,108 @@
package org.jeecg.modules.applet.service.impl;
import cn.hutool.core.util.StrUtil;
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.system.util.AppletUserUtil;
import org.jeecg.modules.applet.service.AppletApiAddressService;
import org.jeecg.modules.demo.appletShippingAddress.entity.AppletShippingAddress;
import org.jeecg.modules.demo.appletShippingAddress.service.IAppletShippingAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
@Slf4j
public class AppletApiAddressServiceImpl implements AppletApiAddressService {
@Autowired
private IAppletShippingAddressService appletShippingAddressService;
/**
* 查询地址列表
*
* @param page
* @param address
* @return
*/
@Override
public IPage<AppletShippingAddress> page(Page<AppletShippingAddress> page, AppletShippingAddress address) {
String userId = AppletUserUtil.getCurrentAppletUserId();
Page<AppletShippingAddress> page1 = appletShippingAddressService
.lambdaQuery()
.eq(AppletShippingAddress::getUserId, userId)//getId -> getUserId
.orderByDesc(AppletShippingAddress::getDefaultFlag)
//如果你要写查询条件这样写
//.eq(AppletShippingAddress::getCity, address.getCity())//这个是 等于
//.eq(StrUtil.isNotBlank((address.getCity()), AppletShippingAddress::getCity, address.getCity())//这样加条件不为空
.page(page);
return page1;
}
/**
* 新增地址
*
* @param appletShippingAddress
*/
@Override
public void save(AppletShippingAddress appletShippingAddress) {
if (appletShippingAddress == null) {
throw new IllegalArgumentException("地址信息不能为空");
}
if (StrUtil.isBlank(appletShippingAddress.getName())) {
throw new IllegalArgumentException("收货人不能为空");
}
if (StrUtil.isBlank(appletShippingAddress.getPhone())) {
throw new IllegalArgumentException("联系电话不能为空");
}
if (StrUtil.isBlank(appletShippingAddress.getDetail())) {
throw new IllegalArgumentException("详细地址不能为空");
}
String userId = AppletUserUtil.getCurrentAppletUserId();
appletShippingAddress.setUserId(userId);
appletShippingAddressService.save(appletShippingAddress);
}
/**
* 根据id查询地址
*
* @param id
* @return
*/
@Override
public AppletShippingAddress getById(String id) {
AppletShippingAddress byId = appletShippingAddressService.getById(id);
return byId;
}
/**
* 修改地址
*
* @param appletShippingAddress
*/
@Override
public void updateById(AppletShippingAddress appletShippingAddress) {
if (appletShippingAddress == null || StrUtil.isBlank(appletShippingAddress.getId())) {
throw new IllegalArgumentException("地址信息或ID不能为空");
}
if (StrUtil.isBlank(appletShippingAddress.getName())) {
throw new IllegalArgumentException("收货人不能为空");
}
if (StrUtil.isBlank(appletShippingAddress.getPhone())) {
throw new IllegalArgumentException("联系电话不能为空");
}
if (StrUtil.isBlank(appletShippingAddress.getDetail())) {
throw new IllegalArgumentException("详细地址不能为空");
}
appletShippingAddressService.updateById(appletShippingAddress);
}
}

+ 113
- 0
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiCarServiceImpl.java View File

@ -0,0 +1,113 @@
package org.jeecg.modules.applet.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.system.util.AppletUserUtil;
import org.jeecg.modules.applet.service.AppletApiCarService;
import org.jeecg.modules.demo.appletCar.entity.AppletCar;
import org.jeecg.modules.demo.appletCar.service.IAppletCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class AppletApiCarServiceImpl implements AppletApiCarService {
@Autowired
private IAppletCarService appletCarService;
/**
* 购物车列表查询
*
* @param page
* @param appletCar
* @return
*/
@Override
public IPage<AppletCar> page(Page<AppletCar> page, AppletCar appletCar) {
String userId = AppletUserUtil.getCurrentAppletUserId();
Page<AppletCar> page1 = appletCarService
.lambdaQuery()
.eq(AppletCar::getUserId, userId)
.page(page);
return page1;
}
/**
* 添加购物车
*
* @param appletCar
*/
@Override
public void save(AppletCar appletCar) {
appletCarService.save(appletCar);
}
/**
* 根据id查询购物车
*
* @param id 购物车id
* @return 购物车对象
*/
@Override
public AppletCar getById(String id) {
// 获取当前登录的小程序用户ID
String userId = AppletUserUtil.getCurrentAppletUserId();
// 使用LambdaQuery构造查询条件同时匹配购物车ID和用户ID确保数据隔离
AppletCar appletCar = appletCarService
.lambdaQuery()
.eq(AppletCar::getId, id) // 匹配购物车ID
.eq(AppletCar::getUserId, userId) // 匹配用户ID
.one(); // 查询单个结果
return appletCar;
}
/**
* 修改购物车
*
* @param appletCar
*/
@Override
public void updateById(AppletCar appletCar) {
// 获取当前登录的小程序用户ID
String userId = AppletUserUtil.getCurrentAppletUserId();
// 验证该购物车是否属于当前用户
AppletCar existingCar = appletCarService
.lambdaQuery()
.eq(AppletCar::getId, appletCar.getId()) // 匹配购物车ID
.eq(AppletCar::getUserId, userId) // 匹配用户ID
.one();
// 如果购物车存在且属于当前用户则执行更新操作
if (existingCar != null) {
appletCarService.updateById(appletCar);
}
}
/**
* 批量删除购物车
*
* @param ids 购物车ID列表
*/
@Override
public void removeByIds(List<String> ids) {
// 获取当前登录的小程序用户ID
String userId = AppletUserUtil.getCurrentAppletUserId();
// 查询这些ID中属于当前用户的购物车项
List<AppletCar> appletCars = appletCarService
.lambdaQuery()
.in(AppletCar::getId, ids) // 匹配购物车ID列表
.eq(AppletCar::getUserId, userId) // 匹配用户ID
.list();
// 提取属于当前用户的购物车ID列表
List<String> userCarIds = appletCars.stream()
.map(AppletCar::getId)
.collect(Collectors.toList());
// 执行删除操作只会删除属于当前用户的购物车项
if (!userCarIds.isEmpty()) {
appletCarService.removeByIds(userCarIds);
}
}
}

+ 0
- 1
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiConfigServiceImpl.java View File

@ -25,7 +25,6 @@ public class AppletApiConfigServiceImpl implements AppletApiConfigService {
public List<AppletConfig> getConfigList() {
LambdaQueryWrapper<AppletConfig> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.orderByAsc(AppletConfig::getCode);
return appletConfigService.list(queryWrapper);
}
}

+ 1
- 0
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiIndexServiceImpl.java View File

@ -33,4 +33,5 @@ public class AppletApiIndexServiceImpl implements AppletApiIndexService {
// 按类型分组
return list;
}
}

+ 2
- 2
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiLoginService.java View File

@ -205,8 +205,6 @@ public class AppletApiLoginService {
throw new JeecgBootException("创建用户失败");
}
}
/**
* 更新用户信息
*
@ -255,6 +253,8 @@ public class AppletApiLoginService {
*/
public Result<AppletUser> getUserInfo() {
try {
// 获取当前登录用户
AppletUser user = AppletUserUtil.getCurrentAppletUser();
if (user == null) {


+ 4
- 0
jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletShippingAddress/entity/AppletShippingAddress.java View File

@ -81,4 +81,8 @@ public class AppletShippingAddress implements Serializable {
@Excel(name = "是否默认", width = 15)
@Schema(description = "是否默认")
private java.lang.Integer defaultFlag;
/**用户*/
@Excel(name = "用户", width = 15)
@Schema(description = "用户")
private java.lang.String userId;
}

Loading…
Cancel
Save