diff --git a/src/main/java/com/gxwebsoft/shop/controller/ShopUserAddressController.java b/src/main/java/com/gxwebsoft/shop/controller/ShopUserAddressController.java index ede00af..854586b 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/ShopUserAddressController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/ShopUserAddressController.java @@ -1,129 +1,132 @@ -package com.gxwebsoft.shop.controller; + package com.gxwebsoft.shop.controller; -import com.gxwebsoft.common.core.web.BaseController; -import com.gxwebsoft.shop.service.ShopUserAddressService; -import com.gxwebsoft.shop.entity.ShopUserAddress; -import com.gxwebsoft.shop.param.ShopUserAddressParam; -import com.gxwebsoft.common.core.web.ApiResult; -import com.gxwebsoft.common.core.web.PageResult; -import com.gxwebsoft.common.core.web.PageParam; -import com.gxwebsoft.common.core.web.BatchParam; -import com.gxwebsoft.common.core.annotation.OperationLog; -import com.gxwebsoft.common.system.entity.User; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; + import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; + import com.gxwebsoft.common.core.web.BaseController; + import com.gxwebsoft.shop.service.ShopUserAddressService; + import com.gxwebsoft.shop.entity.ShopUserAddress; + import com.gxwebsoft.shop.param.ShopUserAddressParam; + import com.gxwebsoft.common.core.web.ApiResult; + import com.gxwebsoft.common.core.web.PageResult; + import com.gxwebsoft.common.core.web.BatchParam; + import com.gxwebsoft.common.core.annotation.OperationLog; + import com.gxwebsoft.common.system.entity.User; + import io.swagger.annotations.Api; + import io.swagger.annotations.ApiOperation; + import org.springframework.security.access.prepost.PreAuthorize; + import org.springframework.web.bind.annotation.*; -import javax.annotation.Resource; -import java.util.List; + import javax.annotation.Resource; + import java.util.List; -/** - * 收货地址控制器 - * - * @author 科技小王子 - * @since 2025-07-22 23:06:40 - */ -@Api(tags = "收货地址管理") -@RestController -@RequestMapping("/api/shop/shop-user-address") -public class ShopUserAddressController extends BaseController { - @Resource - private ShopUserAddressService shopUserAddressService; + /** + * 收货地址控制器 + * + * @author 科技小王子 + * @since 2025-07-22 23:06:40 + */ + @Api(tags = "收货地址管理") + @RestController + @RequestMapping("/api/shop/shop-user-address") + public class ShopUserAddressController extends BaseController { + @Resource + private ShopUserAddressService shopUserAddressService; - @PreAuthorize("hasAuthority('shop:shopUserAddress:list')") - @ApiOperation("分页查询收货地址") - @GetMapping("/page") - public ApiResult> page(ShopUserAddressParam param) { - // 使用关联查询 - return success(shopUserAddressService.pageRel(param)); - } - - @PreAuthorize("hasAuthority('shop:shopUserAddress:list')") - @ApiOperation("查询全部收货地址") - @GetMapping() - public ApiResult> list(ShopUserAddressParam param) { - // 使用关联查询 - return success(shopUserAddressService.listRel(param)); - } + @PreAuthorize("hasAuthority('shop:shopUserAddress:list')") + @ApiOperation("分页查询收货地址") + @GetMapping("/page") + public ApiResult> page(ShopUserAddressParam param) { + // 使用关联查询 + return success(shopUserAddressService.pageRel(param)); + } - @PreAuthorize("hasAuthority('shop:shopUserAddress:list')") - @ApiOperation("根据id查询收货地址") - @GetMapping("/{id}") - public ApiResult get(@PathVariable("id") Integer id) { - // 使用关联查询 - return success(shopUserAddressService.getByIdRel(id)); - } + @PreAuthorize("hasAuthority('shop:shopUserAddress:list')") + @ApiOperation("查询全部收货地址") + @GetMapping() + public ApiResult> list(ShopUserAddressParam param) { + // 使用关联查询 + return success(shopUserAddressService.listRel(param)); + } - @PreAuthorize("hasAuthority('shop:shopUserAddress:save')") - @OperationLog - @ApiOperation("添加收货地址") - @PostMapping() - public ApiResult save(@RequestBody ShopUserAddress shopUserAddress) { - // 记录当前登录用户id - User loginUser = getLoginUser(); - if (loginUser != null) { - shopUserAddress.setUserId(loginUser.getUserId()); + @PreAuthorize("hasAuthority('shop:shopUserAddress:list')") + @ApiOperation("根据id查询收货地址") + @GetMapping("/{id}") + public ApiResult get(@PathVariable("id") Integer id) { + // 使用关联查询 + return success(shopUserAddressService.getByIdRel(id)); } - if (shopUserAddressService.save(shopUserAddress)) { - return success("添加成功"); + + @PreAuthorize("hasAuthority('shop:shopUserAddress:save')") + @OperationLog + @ApiOperation("添加收货地址") + @PostMapping() + public ApiResult save(@RequestBody ShopUserAddress shopUserAddress) { + // 记录当前登录用户id + User loginUser = getLoginUser(); + if (loginUser != null) { + shopUserAddress.setUserId(loginUser.getUserId()); + if (shopUserAddressService.count(new LambdaQueryWrapper().eq(ShopUserAddress::getUserId, loginUser.getUserId()).eq(ShopUserAddress::getAddress, shopUserAddress.getAddress())) > 0) { + return success("该地址已存在"); + } + } + if (shopUserAddressService.save(shopUserAddress)) { + return success("添加成功"); + } + return fail("添加失败"); } - return fail("添加失败"); - } - @PreAuthorize("hasAuthority('shop:shopUserAddress:update')") - @OperationLog - @ApiOperation("修改收货地址") - @PutMapping() - public ApiResult update(@RequestBody ShopUserAddress shopUserAddress) { - if (shopUserAddressService.updateById(shopUserAddress)) { - return success("修改成功"); + @PreAuthorize("hasAuthority('shop:shopUserAddress:update')") + @OperationLog + @ApiOperation("修改收货地址") + @PutMapping() + public ApiResult update(@RequestBody ShopUserAddress shopUserAddress) { + if (shopUserAddressService.updateById(shopUserAddress)) { + return success("修改成功"); + } + return fail("修改失败"); } - return fail("修改失败"); - } - @PreAuthorize("hasAuthority('shop:shopUserAddress:remove')") - @OperationLog - @ApiOperation("删除收货地址") - @DeleteMapping("/{id}") - public ApiResult remove(@PathVariable("id") Integer id) { - if (shopUserAddressService.removeById(id)) { - return success("删除成功"); + @PreAuthorize("hasAuthority('shop:shopUserAddress:remove')") + @OperationLog + @ApiOperation("删除收货地址") + @DeleteMapping("/{id}") + public ApiResult remove(@PathVariable("id") Integer id) { + if (shopUserAddressService.removeById(id)) { + return success("删除成功"); + } + return fail("删除失败"); } - return fail("删除失败"); - } - @PreAuthorize("hasAuthority('shop:shopUserAddress:save')") - @OperationLog - @ApiOperation("批量添加收货地址") - @PostMapping("/batch") - public ApiResult saveBatch(@RequestBody List list) { - if (shopUserAddressService.saveBatch(list)) { - return success("添加成功"); + @PreAuthorize("hasAuthority('shop:shopUserAddress:save')") + @OperationLog + @ApiOperation("批量添加收货地址") + @PostMapping("/batch") + public ApiResult saveBatch(@RequestBody List list) { + if (shopUserAddressService.saveBatch(list)) { + return success("添加成功"); + } + return fail("添加失败"); } - return fail("添加失败"); - } - @PreAuthorize("hasAuthority('shop:shopUserAddress:update')") - @OperationLog - @ApiOperation("批量修改收货地址") - @PutMapping("/batch") - public ApiResult removeBatch(@RequestBody BatchParam batchParam) { - if (batchParam.update(shopUserAddressService, "id")) { - return success("修改成功"); + @PreAuthorize("hasAuthority('shop:shopUserAddress:update')") + @OperationLog + @ApiOperation("批量修改收货地址") + @PutMapping("/batch") + public ApiResult removeBatch(@RequestBody BatchParam batchParam) { + if (batchParam.update(shopUserAddressService, "id")) { + return success("修改成功"); + } + return fail("修改失败"); } - return fail("修改失败"); - } - @PreAuthorize("hasAuthority('shop:shopUserAddress:remove')") - @OperationLog - @ApiOperation("批量删除收货地址") - @DeleteMapping("/batch") - public ApiResult removeBatch(@RequestBody List ids) { - if (shopUserAddressService.removeByIds(ids)) { - return success("删除成功"); + @PreAuthorize("hasAuthority('shop:shopUserAddress:remove')") + @OperationLog + @ApiOperation("批量删除收货地址") + @DeleteMapping("/batch") + public ApiResult removeBatch(@RequestBody List ids) { + if (shopUserAddressService.removeByIds(ids)) { + return success("删除成功"); + } + return fail("删除失败"); } - return fail("删除失败"); - } -} + } diff --git a/src/main/java/com/gxwebsoft/shop/entity/ShopUserAddress.java b/src/main/java/com/gxwebsoft/shop/entity/ShopUserAddress.java index 13d1aa0..ee3cccf 100644 --- a/src/main/java/com/gxwebsoft/shop/entity/ShopUserAddress.java +++ b/src/main/java/com/gxwebsoft/shop/entity/ShopUserAddress.java @@ -63,6 +63,9 @@ public class ShopUserAddress implements Serializable { @ApiModelProperty(value = "默认收货地址") private Boolean isDefault; + @ApiModelProperty(value = "排序号") + private Integer sortNumber; + @ApiModelProperty(value = "用户ID") private Integer userId; diff --git a/src/main/java/com/gxwebsoft/shop/mapper/xml/ShopUserAddressMapper.xml b/src/main/java/com/gxwebsoft/shop/mapper/xml/ShopUserAddressMapper.xml index 9bcf5f0..37b630f 100644 --- a/src/main/java/com/gxwebsoft/shop/mapper/xml/ShopUserAddressMapper.xml +++ b/src/main/java/com/gxwebsoft/shop/mapper/xml/ShopUserAddressMapper.xml @@ -52,6 +52,9 @@ AND a.user_id = #{param.userId} + + AND a.sort_number = #{param.sortNumber} + AND a.create_time >= #{param.createTimeStart} diff --git a/src/main/java/com/gxwebsoft/shop/param/ShopUserAddressParam.java b/src/main/java/com/gxwebsoft/shop/param/ShopUserAddressParam.java index 2394844..1df00dc 100644 --- a/src/main/java/com/gxwebsoft/shop/param/ShopUserAddressParam.java +++ b/src/main/java/com/gxwebsoft/shop/param/ShopUserAddressParam.java @@ -66,6 +66,10 @@ public class ShopUserAddressParam extends BaseParam { @QueryField(type = QueryType.EQ) private Boolean isDefault; + @ApiModelProperty(value = "排序号") + @QueryField(type = QueryType.EQ) + private Integer sortNumber; + @ApiModelProperty(value = "用户ID") @QueryField(type = QueryType.EQ) private Integer userId; diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 7bb4f72..726af3e 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -21,6 +21,12 @@ logging: socketio: host: 0.0.0.0 #IP地址 +redis: + database: 0 + host: 1Panel-redis-Q1LE + port: 6379 + password: redis_WSDb88 + # MQTT配置 mqtt: enabled: false # 添加开关来禁用MQTT服务 diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index e0fd614..2b57dab 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,6 +1,6 @@ # 端口 server: - port: 9003 + port: 9000 # 多环境配置 spring: profiles: @@ -46,7 +46,7 @@ spring: max-request-size: 100MB redis: database: 0 - host: 1Panel-redis-5nN7 + host: 127.0.0.1 port: 6379 password: