diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/customer/CustomerAddressController.java b/ghy-admin/src/main/java/com/ghy/web/controller/customer/CustomerAddressController.java index ad9e7d08..1d2fa356 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/customer/CustomerAddressController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/customer/CustomerAddressController.java @@ -1,5 +1,6 @@ package com.ghy.web.controller.customer; +import cn.hutool.core.util.ObjectUtil; import com.ghy.common.core.controller.BaseController; import com.ghy.common.core.domain.AjaxResult; import com.ghy.common.utils.ExceptionUtil; @@ -12,6 +13,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; +import java.util.List; +import java.util.Objects; @Controller @RequestMapping("/customer/address") @@ -100,6 +103,20 @@ public class CustomerAddressController extends BaseController { @ResponseBody AjaxResult insertCustomerAddress(@RequestBody CustomerAddress customerAddress){ try { + // 判断下当前是否是默认地址 + if(ObjectUtil.equals(customerAddress.getIsDefault(), 1)){ + CustomerAddress param = new CustomerAddress(); + param.setNeedNameFlag(false); + param.setCustomerId(customerAddress.getCustomerId()); + param.setIsDefault(1); + List sourceDefaultAddress = customerAddressService.getCustomerAddressList(param); + for (CustomerAddress defaultAddress : sourceDefaultAddress) { + CustomerAddress defaultParam = new CustomerAddress(); + defaultParam.setCustomerAddressId(defaultAddress.getCustomerAddressId()); + defaultParam.setIsDefault(0); + customerAddressService.updateCustomerAddress(defaultParam); + } + } customerAddressService.insertCustomerAddress(customerAddress); return AjaxResult.success("操作成功"); }catch (Exception e){ @@ -115,6 +132,22 @@ public class CustomerAddressController extends BaseController { @ResponseBody AjaxResult updateCustomerAddress(@RequestBody CustomerAddress customerAddress){ try { + // 判断下当前是否是默认地址 + if(ObjectUtil.equals(customerAddress.getIsDefault(), 1)){ + CustomerAddress param = new CustomerAddress(); + param.setNeedNameFlag(false); + param.setCustomerId(customerAddress.getCustomerId()); + param.setIsDefault(1); + List sourceDefaultAddress = customerAddressService.getCustomerAddressList(param); + for (CustomerAddress defaultAddress : sourceDefaultAddress) { + if(!Objects.equals(defaultAddress.getCustomerAddressId(), customerAddress.getCustomerAddressId())){ + CustomerAddress defaultParam = new CustomerAddress(); + defaultParam.setCustomerAddressId(defaultAddress.getCustomerAddressId()); + defaultParam.setIsDefault(0); + customerAddressService.updateCustomerAddress(defaultParam); + } + } + } customerAddressService.updateCustomerAddress(customerAddress); return AjaxResult.success("操作成功"); }catch (Exception e){ diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/customer/CustomerSelectionController.java b/ghy-admin/src/main/java/com/ghy/web/controller/customer/CustomerSelectionController.java index 01c917c8..47a81a02 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/customer/CustomerSelectionController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/customer/CustomerSelectionController.java @@ -1,6 +1,7 @@ package com.ghy.web.controller.customer; import java.util.List; +import java.util.stream.Collectors; import com.ghy.common.exception.base.BaseException; import com.ghy.customer.domain.Customer; @@ -62,6 +63,17 @@ public class CustomerSelectionController extends BaseController return getDataTable(list); } + /** + * 查询消费者选品列表 + */ + @PostMapping("/listNoPage") + @ResponseBody + public AjaxResult listNoPage(@RequestBody CustomerSelection customerSelection) + { + List list = customerSelectionService.selectCustomerSelectionList(customerSelection); + return AjaxResult.success(list.stream().map(CustomerSelection::getDeptCategoryId).collect(Collectors.toList())); + } + /** * App查询消费者选品列表 */ diff --git a/ghy-custom/src/main/resources/mapper/customer/CustomerAddressMapper.xml b/ghy-custom/src/main/resources/mapper/customer/CustomerAddressMapper.xml index 6a5c4a39..4b833070 100644 --- a/ghy-custom/src/main/resources/mapper/customer/CustomerAddressMapper.xml +++ b/ghy-custom/src/main/resources/mapper/customer/CustomerAddressMapper.xml @@ -30,7 +30,9 @@