Переглянути джерело

feat(mini): 添加mini端收货地址管理和企业信息功能

- 实现mini端收货地址增删改查接口
- 添加mini端企业信息查询和修改接口
- 集成登录验证和权限控制
- 实现地址默认设置功能
- 添加数据校验和重复提交防护
hurx 1 місяць тому
батько
коміт
b53deaba63

+ 165 - 0
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/controller/mini/MiniCustomerAddressController.java

@@ -0,0 +1,165 @@
+package org.dromara.customer.controller.mini;
+
+import jakarta.validation.constraints.NotEmpty;
+import jakarta.validation.constraints.NotNull;
+import lombok.RequiredArgsConstructor;
+import org.dromara.common.core.domain.R;
+import org.dromara.common.core.enums.IsDefault;
+import org.dromara.common.core.validate.AddGroup;
+import org.dromara.common.core.validate.EditGroup;
+import org.dromara.common.idempotent.annotation.RepeatSubmit;
+import org.dromara.common.log.annotation.Log;
+import org.dromara.common.log.enums.BusinessType;
+import org.dromara.common.mybatis.core.page.PageQuery;
+import org.dromara.common.mybatis.core.page.TableDataInfo;
+import org.dromara.common.satoken.utils.LoginHelper;
+import org.dromara.common.web.core.BaseController;
+import org.dromara.customer.domain.bo.CustomerShippingAddressBo;
+import org.dromara.customer.domain.vo.CustomerShippingAddressVo;
+import org.dromara.customer.service.ICustomerShippingAddressService;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ *mini端 - 收货地址管理
+ *
+ * @author Claude
+ */
+@Validated
+@RequiredArgsConstructor
+@RestController
+@RequestMapping("/miniAddress")
+public class MiniCustomerAddressController extends BaseController {
+
+    private final ICustomerShippingAddressService customerShippingAddressService;
+
+    /**
+     *mini 查询当前企业的收货地址列表
+     * mini端用户只能查询自己企业的地址
+     */
+    @GetMapping("/list")
+    public TableDataInfo<CustomerShippingAddressVo> list(CustomerShippingAddressBo bo, PageQuery pageQuery) {
+        // 获取当前登录用户的企业ID
+        Long customerId = LoginHelper.getLoginUser().getCustomerId();
+        // 强制设置企业ID,防止越权访问
+        bo.setCustomerId(customerId);
+
+        return customerShippingAddressService.queryPageList(bo, pageQuery);
+    }
+
+    /**
+     * 获取收货地址详细信息
+     * mini端用户只能查询自己企业的地址
+     *
+     * @param id 主键
+     */
+    @GetMapping("/{id}")
+    public R<CustomerShippingAddressVo> getInfo(@NotNull(message = "主键不能为空")
+                                                @PathVariable("id") Long id) {
+        // 查询地址信息
+        CustomerShippingAddressVo vo = customerShippingAddressService.queryById(id);
+
+        // 验证地址是否属于当前用户的企业
+        if (vo != null) {
+            Long customerId = LoginHelper.getLoginUser().getCustomerId();
+            if (!customerId.equals(vo.getCustomerId())) {
+                return R.fail("无权访问该地址");
+            }
+        }
+
+        return R.ok(vo);
+    }
+
+    /**
+     *mini 新增收货地址
+     */
+    @Log(title = "PC端-收货地址", businessType = BusinessType.INSERT)
+    @RepeatSubmit()
+    @PostMapping()
+    public R<Void> add(@Validated(AddGroup.class) @RequestBody CustomerShippingAddressBo bo) {
+        // 获取当前登录用户的企业ID
+        Long customerId = LoginHelper.getLoginUser().getCustomerId();
+        // 强制设置企业ID,防止为其他企业添加地址
+        bo.setCustomerId(customerId);
+
+        return toAjax(customerShippingAddressService.insertByBo(bo));
+    }
+
+    /**
+     *mini 修改收货地址
+     */
+    @Log(title = "PC端-收货地址", businessType = BusinessType.UPDATE)
+    @RepeatSubmit()
+    @PutMapping()
+    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CustomerShippingAddressBo bo) {
+        // 获取当前登录用户的企业ID
+        Long customerId = LoginHelper.getLoginUser().getCustomerId();
+
+        // 验证地址是否属于当前用户的企业
+        CustomerShippingAddressVo existingAddress = customerShippingAddressService.queryById(bo.getId());
+        if (existingAddress == null) {
+            return R.fail("地址不存在");
+        }
+        if (!customerId.equals(existingAddress.getCustomerId())) {
+            return R.fail("无权修改该地址");
+        }
+
+        // 强制设置企业ID
+        bo.setCustomerId(customerId);
+
+        return toAjax(customerShippingAddressService.updateByBo(bo));
+    }
+
+    /**
+     *mini 删除收货地址
+     *
+     * @param ids 主键串
+     */
+    @Log(title = "PC端-收货地址", businessType = BusinessType.DELETE)
+    @DeleteMapping("/{ids}")
+    public R<Void> remove(@NotEmpty(message = "主键不能为空")
+                          @PathVariable("ids") Long[] ids) {
+        // 获取当前登录用户的企业ID
+        Long customerId = LoginHelper.getLoginUser().getCustomerId();
+
+        // 验证所有地址是否都属于当前用户的企业
+        for (Long id : ids) {
+            CustomerShippingAddressVo address = customerShippingAddressService.queryById(id);
+            if (address == null) {
+                return R.fail("地址ID " + id + " 不存在");
+            }
+            if (!customerId.equals(address.getCustomerId())) {
+                return R.fail("无权删除地址ID " + id);
+            }
+        }
+
+        return toAjax(customerShippingAddressService.deleteWithValidByIds(List.of(ids), true));
+    }
+
+    /**
+     *mini 设置默认地址
+     */
+    @Log(title = "PC端-收货地址", businessType = BusinessType.UPDATE)
+    @PutMapping("/default")
+    public R<Void> changeDefaultAddress(@RequestBody CustomerShippingAddressBo bo) {
+        // 获取当前登录用户的企业ID
+        Long customerId = LoginHelper.getLoginUser().getCustomerId();
+
+        // 验证地址是否属于当前用户的企业
+        CustomerShippingAddressVo address = customerShippingAddressService.queryById(bo.getId());
+        if (address == null) {
+            return R.fail("地址不存在");
+        }
+        if (!customerId.equals(address.getCustomerId())) {
+            return R.fail("无权设置该地址为默认");
+        }
+
+        // 强制设置企业ID
+        bo.setCustomerId(customerId);
+        bo.setDefaultAddress(IsDefault.Yes.getCode());
+
+        return toAjax(customerShippingAddressService.changeDefaultAddress(bo));
+    }
+}

+ 69 - 0
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/controller/mini/MiniEnterpriseController.java

@@ -0,0 +1,69 @@
+package org.dromara.customer.controller.mini;
+
+import lombok.RequiredArgsConstructor;
+import org.dromara.common.core.domain.R;
+import org.dromara.common.log.annotation.Log;
+import org.dromara.common.log.enums.BusinessType;
+import org.dromara.common.satoken.utils.LoginHelper;
+import org.dromara.common.web.core.BaseController;
+import org.dromara.customer.domain.bo.CustomerInfoBo;
+import org.dromara.customer.domain.vo.CustomerInfoVo;
+import org.dromara.customer.service.ICustomerInfoService;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ *mini端 - 企业信息
+ *
+ * @author Claude
+ */
+@Validated
+@RequiredArgsConstructor
+@RestController
+@RequestMapping("/miniEnterprise")
+public class MiniEnterpriseController extends BaseController {
+
+    private final ICustomerInfoService customerInfoService;
+
+    /**
+     *mini 查询当前企业信息
+     *mini端用户只能查询自己所属企业的信息
+     */
+    @GetMapping("/info")
+    public R<CustomerInfoVo> getInfo() {
+        // 获取当前登录用户的企业ID
+        Long customerId = LoginHelper.getLoginUser().getCustomerId();
+        if (customerId == null) {
+            return R.fail("用户未登录或企业信息不存在");
+        }
+
+        // 查询企业信息
+        CustomerInfoVo vo = customerInfoService.queryById(customerId);
+        if (vo == null) {
+            return R.fail("企业信息不存在");
+        }
+
+        return R.ok(vo);
+    }
+
+    /**
+     *mini 修改当前企业信息
+     * mini端用户只能修改自己所属企业的信息
+     */
+    @Log(title = "PC端-企业信息", businessType = BusinessType.UPDATE)
+    @PutMapping("/updateEnterprise")
+    public R<Void> updateInfo(@Validated @RequestBody CustomerInfoBo bo) {
+        // 获取当前登录用户的企业ID
+        Long customerId = LoginHelper.getLoginUser().getCustomerId();
+        if (customerId == null) {
+            return R.fail("用户未登录或企业信息不存在");
+        }
+
+        // 强制设置企业ID,防止越权修改其他企业信息
+        bo.setId(customerId);
+
+        // 调用Service更新企业信息
+        boolean result = customerInfoService.pcUpdateCustomerInfo(bo);
+        return toAjax(result);
+    }
+}