|
@@ -2,11 +2,13 @@ package com.txz.mall.controller;
|
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.github.pagehelper.PageInfo;
|
|
|
|
+import com.txz.mall.core.AuthService;
|
|
import com.txz.mall.core.Result;
|
|
import com.txz.mall.core.Result;
|
|
import com.txz.mall.core.ResultCode;
|
|
import com.txz.mall.core.ResultCode;
|
|
import com.txz.mall.model.UserAddress;
|
|
import com.txz.mall.model.UserAddress;
|
|
import com.txz.mall.service.StoreOrderService;
|
|
import com.txz.mall.service.StoreOrderService;
|
|
import com.txz.mall.service.UserAddressService;
|
|
import com.txz.mall.service.UserAddressService;
|
|
|
|
+import com.txz.mall.web.param.UserAddressParam;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
@@ -22,7 +24,7 @@ import java.util.List;
|
|
/**
|
|
/**
|
|
* Created by CodeGenerator on 2025/07/15.
|
|
* Created by CodeGenerator on 2025/07/15.
|
|
*/
|
|
*/
|
|
-@Api(tags = "[APP]收获地址管理")
|
|
|
|
|
|
+@Api(tags = "后台收获地址管理")
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/user/address")
|
|
@RequestMapping("/user/address")
|
|
public class UserAddressController {
|
|
public class UserAddressController {
|
|
@@ -35,68 +37,72 @@ public class UserAddressController {
|
|
@Resource
|
|
@Resource
|
|
private StoreOrderService storeOrderService;
|
|
private StoreOrderService storeOrderService;
|
|
|
|
|
|
- @PostMapping("/add")
|
|
|
|
- @ApiOperation(value = "收获地址新增")
|
|
|
|
- public Result<Long> add(@RequestBody UserAddress userAddress) {
|
|
|
|
- if (userAddress == null) {
|
|
|
|
- return Result.fail(ResultCode.OBJECT_IS_NULL);
|
|
|
|
- }
|
|
|
|
- try {
|
|
|
|
- userAddress.setCreateTime(new Date());
|
|
|
|
- userAddress.setCreateUserId(userAddress.getUid());
|
|
|
|
- userAddressService.save(userAddress);
|
|
|
|
- if (userAddress.getIsDefault() == 1) {
|
|
|
|
- checkOnlyAddress(userAddress, userAddress.getId());
|
|
|
|
- }
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("新增对象操作异常e:{}", e);
|
|
|
|
- return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
|
- }
|
|
|
|
- return Result.success(userAddress.getId());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @PostMapping("/delete")
|
|
|
|
- @ApiOperation(value = "收获地址删除")
|
|
|
|
- public Result delete(@RequestParam Long id) {
|
|
|
|
- if (id == null) {
|
|
|
|
- return Result.fail(ResultCode.ID_IS_NULL);
|
|
|
|
- }
|
|
|
|
- try {
|
|
|
|
- UserAddress userAddress = new UserAddress();
|
|
|
|
- userAddress.setId(id);
|
|
|
|
- userAddress.setIsDelete(1);
|
|
|
|
- userAddressService.update(userAddress);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("删除对象操作异常e:{}", e);
|
|
|
|
- return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
|
- }
|
|
|
|
- return Result.success();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @PostMapping("/update")
|
|
|
|
- @ApiOperation(value = "收获地址更新")
|
|
|
|
- public Result update(@RequestBody UserAddress userAddress) {
|
|
|
|
- if (userAddress == null) {
|
|
|
|
- return Result.fail(ResultCode.OBJECT_IS_NULL);
|
|
|
|
- }
|
|
|
|
- if (userAddress.getId() == null) {
|
|
|
|
- return Result.fail(ResultCode.ID_IS_NULL);
|
|
|
|
- }
|
|
|
|
- try {
|
|
|
|
- userAddress.setUpdateTime(new Date());
|
|
|
|
-// userAddress.setUpdateUserId(userId);
|
|
|
|
- userAddressService.update(userAddress);
|
|
|
|
- if (userAddress.getIsDefault() == 1) {
|
|
|
|
- checkOnlyAddress(userAddress, userAddress.getId());
|
|
|
|
- }
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("更新对象操作异常e:{}", e);
|
|
|
|
- return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
|
- }
|
|
|
|
- return Result.success();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @PostMapping("/detail")
|
|
|
|
|
|
+// @PostMapping("/add")
|
|
|
|
+// @ApiOperation(value = "收获地址新增")
|
|
|
|
+// public Result<Long> add(@RequestBody UserAddress userAddress) {
|
|
|
|
+// Long tokenUserId = AuthService.getTokenUserId(null);
|
|
|
|
+// userAddress.setUid(tokenUserId);
|
|
|
|
+// if (userAddress == null) {
|
|
|
|
+// return Result.fail(ResultCode.OBJECT_IS_NULL);
|
|
|
|
+// }
|
|
|
|
+// try {
|
|
|
|
+// userAddress.setCreateTime(new Date());
|
|
|
|
+// userAddress.setCreateUserId(userAddress.getUid());
|
|
|
|
+// userAddressService.save(userAddress);
|
|
|
|
+// if (userAddress.getIsDefault() == 1) {
|
|
|
|
+// checkOnlyAddress(userAddress, userAddress.getId());
|
|
|
|
+// }
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
+// log.error("新增对象操作异常e:{}", e);
|
|
|
|
+// return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
|
+// }
|
|
|
|
+// return Result.success(userAddress.getId());
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+// @DeleteMapping("/delete")
|
|
|
|
+// @ApiOperation(value = "收获地址删除")
|
|
|
|
+// public Result delete(@RequestParam Long id) {
|
|
|
|
+// if (id == null) {
|
|
|
|
+// return Result.fail(ResultCode.ID_IS_NULL);
|
|
|
|
+// }
|
|
|
|
+// try {
|
|
|
|
+// UserAddress userAddress = new UserAddress();
|
|
|
|
+// userAddress.setId(id);
|
|
|
|
+// userAddress.setIsDelete(1);
|
|
|
|
+// userAddressService.update(userAddress);
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
+// log.error("删除对象操作异常e:{}", e);
|
|
|
|
+// return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
|
+// }
|
|
|
|
+// return Result.success();
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+// @PutMapping("/update")
|
|
|
|
+// @ApiOperation(value = "收获地址更新")
|
|
|
|
+// public Result update(@RequestBody UserAddress userAddress) {
|
|
|
|
+// Long tokenUserId = AuthService.getTokenUserId(null);
|
|
|
|
+// userAddress.setUid(tokenUserId);
|
|
|
|
+// if (userAddress == null) {
|
|
|
|
+// return Result.fail(ResultCode.OBJECT_IS_NULL);
|
|
|
|
+// }
|
|
|
|
+// if (userAddress.getId() == null) {
|
|
|
|
+// return Result.fail(ResultCode.ID_IS_NULL);
|
|
|
|
+// }
|
|
|
|
+// try {
|
|
|
|
+// userAddress.setUpdateTime(new Date());
|
|
|
|
+//// userAddress.setUpdateUserId(userId);
|
|
|
|
+// userAddressService.update(userAddress);
|
|
|
|
+// if (userAddress.getIsDefault() == 1) {
|
|
|
|
+// checkOnlyAddress(userAddress, userAddress.getId());
|
|
|
|
+// }
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
+// log.error("更新对象操作异常e:{}", e);
|
|
|
|
+// return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
|
+// }
|
|
|
|
+// return Result.success();
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ @GetMapping("/detail")
|
|
@ApiOperation(value = "收获地址获取详情")
|
|
@ApiOperation(value = "收获地址获取详情")
|
|
public Result<UserAddress> detail(@RequestParam Long id) {
|
|
public Result<UserAddress> detail(@RequestParam Long id) {
|
|
if (id == null) {
|
|
if (id == null) {
|
|
@@ -114,10 +120,13 @@ public class UserAddressController {
|
|
|
|
|
|
@PostMapping("/list")
|
|
@PostMapping("/list")
|
|
@ApiOperation(value = "收获地址获取列表")
|
|
@ApiOperation(value = "收获地址获取列表")
|
|
- public Result<List<UserAddress>> list(@RequestBody UserAddress userAddress, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) {
|
|
|
|
- PageHelper.startPage(page, size);
|
|
|
|
|
|
+ public Result<List<UserAddress>> list(@RequestBody UserAddressParam userAddress) {
|
|
|
|
|
|
- Condition condition = new Condition(userAddress.getClass());
|
|
|
|
|
|
+ // Long tokenUserId = AuthService.getTokenUserId(null);
|
|
|
|
+ // userAddress.setUid(tokenUserId);
|
|
|
|
+ PageHelper.startPage(userAddress.getPage(), userAddress.getSize());
|
|
|
|
+
|
|
|
|
+ Condition condition = new Condition(UserAddress.class);
|
|
Example.Criteria criteria = condition.createCriteria();
|
|
Example.Criteria criteria = condition.createCriteria();
|
|
criteria.andEqualTo("isDelete", 0);
|
|
criteria.andEqualTo("isDelete", 0);
|
|
condition.setOrderByClause("create_time DESC");
|
|
condition.setOrderByClause("create_time DESC");
|
|
@@ -135,33 +144,33 @@ public class UserAddressController {
|
|
return Result.success(pageInfo);
|
|
return Result.success(pageInfo);
|
|
}
|
|
}
|
|
|
|
|
|
- @PostMapping("/default")
|
|
|
|
- @ApiOperation(value = "设置默认地址")
|
|
|
|
- public Result defaultAddress(@RequestParam("id") Long id) {
|
|
|
|
- if (id == null) {
|
|
|
|
- return Result.fail(ResultCode.OBJECT_IS_NULL);
|
|
|
|
- }
|
|
|
|
- try {
|
|
|
|
- UserAddress userAddress = new UserAddress();
|
|
|
|
- userAddress.setUpdateTime(new Date());
|
|
|
|
-// userAddress.setUpdateUserId(userId);
|
|
|
|
- userAddress.setId(id);
|
|
|
|
- userAddress.setIsDefault(1);
|
|
|
|
- userAddressService.update(userAddress);
|
|
|
|
-
|
|
|
|
- UserAddress address = userAddressService.findById(id);
|
|
|
|
- if (address == null) {
|
|
|
|
- return Result.fail(ResultCode.OBJECT_IS_NULL);
|
|
|
|
- }
|
|
|
|
- checkOnlyAddress(address, id);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("更新对象操作异常e:{}", e);
|
|
|
|
- return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
|
- }
|
|
|
|
- return Result.success();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @PostMapping("/getDefault")
|
|
|
|
|
|
+// @PutMapping("/default")
|
|
|
|
+// @ApiOperation(value = "设置默认地址")
|
|
|
|
+// public Result defaultAddress(@RequestParam("id") Long id) {
|
|
|
|
+// if (id == null) {
|
|
|
|
+// return Result.fail(ResultCode.OBJECT_IS_NULL);
|
|
|
|
+// }
|
|
|
|
+// try {
|
|
|
|
+// UserAddress userAddress = new UserAddress();
|
|
|
|
+// userAddress.setUpdateTime(new Date());
|
|
|
|
+//// userAddress.setUpdateUserId(userId);
|
|
|
|
+// userAddress.setId(id);
|
|
|
|
+// userAddress.setIsDefault(1);
|
|
|
|
+// userAddressService.update(userAddress);
|
|
|
|
+//
|
|
|
|
+// UserAddress address = userAddressService.findById(id);
|
|
|
|
+// if (address == null) {
|
|
|
|
+// return Result.fail(ResultCode.OBJECT_IS_NULL);
|
|
|
|
+// }
|
|
|
|
+// checkOnlyAddress(address, id);
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
+// log.error("更新对象操作异常e:{}", e);
|
|
|
|
+// return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
|
+// }
|
|
|
|
+// return Result.success();
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ @GetMapping("/getDefault")
|
|
@ApiOperation(value = "获取默认地址")
|
|
@ApiOperation(value = "获取默认地址")
|
|
public Result<UserAddress> getDefault(@RequestParam("uid") Long uid) {
|
|
public Result<UserAddress> getDefault(@RequestParam("uid") Long uid) {
|
|
if (uid == null) {
|
|
if (uid == null) {
|