默认地址问题
This commit is contained in:
parent
6d72575c0b
commit
cf7c708f3a
|
|
@ -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<CustomerAddress> 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<CustomerAddress> 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){
|
||||
|
|
|
|||
|
|
@ -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<CustomerSelection> list = customerSelectionService.selectCustomerSelectionList(customerSelection);
|
||||
return AjaxResult.success(list.stream().map(CustomerSelection::getDeptCategoryId).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* App查询消费者选品列表
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -30,7 +30,9 @@
|
|||
<select id="getCustomerAddressList" resultMap="CustomerAddressResult">
|
||||
<include refid="selectCustomerAddress" />
|
||||
<where>
|
||||
|
||||
<if test="isDefault != null">
|
||||
AND is_default = #{isDefault}
|
||||
</if>
|
||||
<if test="customerId != null">
|
||||
AND customer_id = #{customerId}
|
||||
</if>
|
||||
|
|
@ -53,6 +55,7 @@
|
|||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
order by is_default desc
|
||||
</select>
|
||||
|
||||
<delete id="deleteByIds">
|
||||
|
|
|
|||
Loading…
Reference in New Issue