diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiIndexController.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiIndexController.java index 5606afc..0edeccd 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiIndexController.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiIndexController.java @@ -42,4 +42,5 @@ public class AppletApiIndexController { List bannerList = appletIndexService.getBannerList(); return Result.OK(bannerList); } + } \ No newline at end of file diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiProductController.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiProductController.java index 44f4a46..dfc6721 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiProductController.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/controller/AppletApiProductController.java @@ -71,16 +71,12 @@ public class AppletApiProductController { @Operation(summary = "产品详情查询", description = "获取单个产品详细信息") @GetMapping(value = "/detail") @IgnoreAuth - public Result detail( - @Parameter(description = "产品ID", required = true) @RequestParam String id) { - + public Result 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); } diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiAddressService.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiAddressService.java new file mode 100644 index 0000000..d329afa --- /dev/null +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiAddressService.java @@ -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 page(Page 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 list); +// + +} diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiCarService.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiCarService.java new file mode 100644 index 0000000..c8d6e2b --- /dev/null +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiCarService.java @@ -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 page(Page 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 list); + + +} diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiIndexService.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiIndexService.java index 2b3d47a..767307e 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiIndexService.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/AppletApiIndexService.java @@ -17,4 +17,5 @@ public interface AppletApiIndexService { * 获取Banner列表 */ List getBannerList(); + } \ No newline at end of file diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiAddressServiceImpl.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiAddressServiceImpl.java new file mode 100644 index 0000000..8ad9b2e --- /dev/null +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiAddressServiceImpl.java @@ -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 page(Page page, AppletShippingAddress address) { + + String userId = AppletUserUtil.getCurrentAppletUserId(); + + Page 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); + } + +} diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiCarServiceImpl.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiCarServiceImpl.java new file mode 100644 index 0000000..a86be74 --- /dev/null +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiCarServiceImpl.java @@ -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 page(Page page, AppletCar appletCar) { + String userId = AppletUserUtil.getCurrentAppletUserId(); + Page 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 ids) { + // 获取当前登录的小程序用户ID + String userId = AppletUserUtil.getCurrentAppletUserId(); + // 查询这些ID中属于当前用户的购物车项 + List appletCars = appletCarService + .lambdaQuery() + .in(AppletCar::getId, ids) // 匹配购物车ID列表 + .eq(AppletCar::getUserId, userId) // 匹配用户ID + .list(); + // 提取属于当前用户的购物车ID列表 + List userCarIds = appletCars.stream() + .map(AppletCar::getId) + .collect(Collectors.toList()); + // 执行删除操作(只会删除属于当前用户的购物车项) + if (!userCarIds.isEmpty()) { + appletCarService.removeByIds(userCarIds); + } + } +} \ No newline at end of file diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiConfigServiceImpl.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiConfigServiceImpl.java index 60c6632..5037346 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiConfigServiceImpl.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiConfigServiceImpl.java @@ -25,7 +25,6 @@ public class AppletApiConfigServiceImpl implements AppletApiConfigService { public List getConfigList() { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.orderByAsc(AppletConfig::getCode); - return appletConfigService.list(queryWrapper); } } \ No newline at end of file diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiIndexServiceImpl.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiIndexServiceImpl.java index 0033b34..887c894 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiIndexServiceImpl.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiIndexServiceImpl.java @@ -33,4 +33,5 @@ public class AppletApiIndexServiceImpl implements AppletApiIndexService { // 按类型分组 return list; } + } \ No newline at end of file diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiLoginService.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiLoginService.java index 305b2a3..67f70d8 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiLoginService.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/applet/service/impl/AppletApiLoginService.java @@ -205,8 +205,6 @@ public class AppletApiLoginService { throw new JeecgBootException("创建用户失败"); } } - - /** * 更新用户信息 * @@ -255,6 +253,8 @@ public class AppletApiLoginService { */ public Result getUserInfo() { try { + + // 获取当前登录用户 AppletUser user = AppletUserUtil.getCurrentAppletUser(); if (user == null) { diff --git a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletShippingAddress/entity/AppletShippingAddress.java b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletShippingAddress/entity/AppletShippingAddress.java index 52d1de4..51e37b8 100644 --- a/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletShippingAddress/entity/AppletShippingAddress.java +++ b/jeecg-boot/jeecg-boot-module/jeecgboot-boot-applet/src/main/java/org/jeecg/modules/demo/appletShippingAddress/entity/AppletShippingAddress.java @@ -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; }