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 new file mode 100644 index 00000000..af7e98dc --- /dev/null +++ b/ghy-admin/src/main/java/com/ghy/web/controller/customer/CustomerAddressController.java @@ -0,0 +1,125 @@ +package com.ghy.web.controller.customer; + +import com.ghy.common.core.controller.BaseController; +import com.ghy.common.core.domain.AjaxResult; +import com.ghy.common.utils.ExceptionUtil; +import com.ghy.customer.domain.CustomerAddress; +import com.ghy.customer.service.CustomerAddressService; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.annotation.Resource; + +@Controller +@RequestMapping("/customer/address") +public class CustomerAddressController extends BaseController { + + @Resource + private CustomerAddressService customerAddressService; + + /** + * @param customerAddress 筛选符合条件的地址list + * @return 地址list + */ + @PostMapping("/list") + @ResponseBody + AjaxResult getCustomerAddressList(CustomerAddress customerAddress){ + try { + return AjaxResult.success(customerAddressService.getCustomerAddressList(customerAddress)); + }catch (Exception e){ + return AjaxResult.error(ExceptionUtil.getExceptionMessage(e)); + } + } + + /** + * @param ids 地址id + * @return 删除成功条数 + */ + @PostMapping("/deleteByIds") + @ResponseBody + AjaxResult deleteByIds(String [] ids){ + try { + customerAddressService.deleteByIds(ids); + return AjaxResult.success("操作成功"); + }catch (Exception e){ + return AjaxResult.error(ExceptionUtil.getExceptionMessage(e)); + } + } + + /** + * @param customerAddressId 地址id + * @return 删除成功条数 + */ + @PostMapping("/delete") + @ResponseBody + AjaxResult deleteByCustomerAddressId(Long customerAddressId){ + try { + customerAddressService.deleteByCustomerAddressId(customerAddressId); + return AjaxResult.success("操作成功"); + }catch (Exception e){ + return AjaxResult.error(ExceptionUtil.getExceptionMessage(e)); + } + } + + /** + * @param customerId 消费者id + * @return 消费者所有的地址list + */ + @PostMapping("/getByCustomerId") + @ResponseBody + AjaxResult selectByCustomerId(Long customerId){ + try { + return AjaxResult.success(customerAddressService.selectByCustomerId(customerId)); + }catch (Exception e){ + return AjaxResult.error(ExceptionUtil.getExceptionMessage(e)); + } + } + + /** + * @param customerAddressId 地址id + * @return 地址 + */ + @PostMapping("/getByCustomerAddressId") + @ResponseBody + AjaxResult selectByCustomerAddressId(Long customerAddressId){ + try { + return AjaxResult.success(customerAddressService.selectByCustomerAddressId(customerAddressId)); + }catch (Exception e){ + return AjaxResult.error(ExceptionUtil.getExceptionMessage(e)); + } + } + + /** + * @param customerAddress 地址信息 + * @return 新增成功条数 + */ + @PostMapping("/insert") + @ResponseBody + AjaxResult insertCustomerAddress(CustomerAddress customerAddress){ + try { + + return AjaxResult.success("操作成功"); + }catch (Exception e){ + return AjaxResult.error(ExceptionUtil.getExceptionMessage(e)); + } + } + + /** + * @param customerAddress 修改地址信息 + * @return 修改成功条数 + */ + @PostMapping("/update") + @ResponseBody + AjaxResult updateCustomerAddress(CustomerAddress customerAddress){ + try { + customerAddressService.updateCustomerAddress(customerAddress); + return AjaxResult.success("操作成功"); + }catch (Exception e){ + return AjaxResult.error(ExceptionUtil.getExceptionMessage(e)); + } + } + + +} diff --git a/ghy-custom/src/main/java/com/ghy/customer/domain/CustomerAddress.java b/ghy-custom/src/main/java/com/ghy/customer/domain/CustomerAddress.java new file mode 100644 index 00000000..e30a8b9a --- /dev/null +++ b/ghy-custom/src/main/java/com/ghy/customer/domain/CustomerAddress.java @@ -0,0 +1,44 @@ +package com.ghy.customer.domain; + +import com.ghy.common.annotation.Excel; +import com.ghy.common.core.domain.BaseEntity; +import lombok.Data; + +/** + * @author clunt + * 消费者地址 + */ +@Data +public class CustomerAddress extends BaseEntity { + + @Excel(name = "消费者地址id", cellType = Excel.ColumnType.NUMERIC) + private Long customerAddressId; + + @Excel(name = "消费者id", cellType = Excel.ColumnType.NUMERIC) + private Long customerId; + + @Excel(name = "收件人姓名", cellType = Excel.ColumnType.STRING) + private String name; + + @Excel(name = "收件人手机号", cellType = Excel.ColumnType.STRING) + private String phone; + + @Excel(name = "省", cellType = Excel.ColumnType.NUMERIC) + private Long provinceId; + + @Excel(name = "市", cellType = Excel.ColumnType.NUMERIC) + private Long cityId; + + @Excel(name = "区", cellType = Excel.ColumnType.NUMERIC) + private Long countryId; + + @Excel(name = "详细地址") + private String address; + + @Excel(name = "是否默认地址,0.普通地址, 1.默认地址", cellType = Excel.ColumnType.STRING) + private Integer isDefault; + + @Excel(name = "是否有效,0.有效, 1.无效", cellType = Excel.ColumnType.STRING) + private Integer status; + +} diff --git a/ghy-custom/src/main/java/com/ghy/customer/mapper/CustomerAddressMapper.java b/ghy-custom/src/main/java/com/ghy/customer/mapper/CustomerAddressMapper.java new file mode 100644 index 00000000..73b9d2d8 --- /dev/null +++ b/ghy-custom/src/main/java/com/ghy/customer/mapper/CustomerAddressMapper.java @@ -0,0 +1,51 @@ +package com.ghy.customer.mapper; + +import com.ghy.customer.domain.CustomerAddress; + +import java.util.List; + +public interface CustomerAddressMapper { + + /** + * @param customerAddress 筛选符合条件的地址list + * @return 地址list + */ + List getCustomerAddressList(CustomerAddress customerAddress); + + /** + * @param ids 地址id + * @return 删除成功条数 + */ + int deleteByIds(String [] ids); + + /** + * @param customerAddressId 地址id + * @return 删除成功条数 + */ + int deleteByCustomerAddressId(Long customerAddressId); + + /** + * @param customerId 消费者id + * @return 消费者所有的地址list + */ + List selectByCustomerId(Long customerId); + + /** + * @param customerAddressId 地址id + * @return 地址 + */ + CustomerAddress selectByCustomerAddressId(Long customerAddressId); + + /** + * @param customerAddress 地址信息 + * @return 新增成功条数 + */ + int insertCustomerAddress(CustomerAddress customerAddress); + + /** + * @param customerAddress 修改地址信息 + * @return 修改成功条数 + */ + int updateCustomerAddress(CustomerAddress customerAddress); + +} diff --git a/ghy-custom/src/main/java/com/ghy/customer/service/CustomerAddressService.java b/ghy-custom/src/main/java/com/ghy/customer/service/CustomerAddressService.java new file mode 100644 index 00000000..68fef1d1 --- /dev/null +++ b/ghy-custom/src/main/java/com/ghy/customer/service/CustomerAddressService.java @@ -0,0 +1,51 @@ +package com.ghy.customer.service; + +import com.ghy.customer.domain.CustomerAddress; + +import java.util.List; + +public interface CustomerAddressService { + + /** + * @param customerAddress 筛选符合条件的地址list + * @return 地址list + */ + List getCustomerAddressList(CustomerAddress customerAddress); + + /** + * @param ids 地址id + * @return 删除成功条数 + */ + int deleteByIds(String [] ids); + + /** + * @param customerAddressId 地址id + * @return 删除成功条数 + */ + int deleteByCustomerAddressId(Long customerAddressId); + + /** + * @param customerId 消费者id + * @return 消费者所有的地址list + */ + List selectByCustomerId(Long customerId); + + /** + * @param customerAddressId 地址id + * @return 地址 + */ + CustomerAddress selectByCustomerAddressId(Long customerAddressId); + + /** + * @param customerAddress 地址信息 + * @return 新增成功条数 + */ + int insertCustomerAddress(CustomerAddress customerAddress); + + /** + * @param customerAddress 修改地址信息 + * @return 修改成功条数 + */ + int updateCustomerAddress(CustomerAddress customerAddress); + +} diff --git a/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerAddressServiceImpl.java b/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerAddressServiceImpl.java new file mode 100644 index 00000000..799847b7 --- /dev/null +++ b/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerAddressServiceImpl.java @@ -0,0 +1,53 @@ +package com.ghy.customer.service.impl; + +import com.ghy.customer.domain.CustomerAddress; +import com.ghy.customer.mapper.CustomerAddressMapper; +import com.ghy.customer.service.CustomerAddressService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +@Slf4j +@Service +public class CustomerAddressServiceImpl implements CustomerAddressService { + + @Resource + private CustomerAddressMapper customerAddressMapper; + + @Override + public List getCustomerAddressList(CustomerAddress customerAddress) { + return customerAddressMapper.getCustomerAddressList(customerAddress); + } + + @Override + public int deleteByIds(String[] ids) { + return customerAddressMapper.deleteByIds(ids); + } + + @Override + public int deleteByCustomerAddressId(Long customerAddressId) { + return customerAddressMapper.deleteByCustomerAddressId(customerAddressId); + } + + @Override + public List selectByCustomerId(Long customerId) { + return customerAddressMapper.selectByCustomerId(customerId); + } + + @Override + public CustomerAddress selectByCustomerAddressId(Long customerAddressId) { + return customerAddressMapper.selectByCustomerAddressId(customerAddressId); + } + + @Override + public int insertCustomerAddress(CustomerAddress customerAddress) { + return customerAddressMapper.insertCustomerAddress(customerAddress); + } + + @Override + public int updateCustomerAddress(CustomerAddress customerAddress) { + return customerAddressMapper.updateCustomerAddress(customerAddress); + } +} diff --git a/ghy-custom/src/main/resources/mapper/customer/CustomerAddressMapper.xml b/ghy-custom/src/main/resources/mapper/customer/CustomerAddressMapper.xml new file mode 100644 index 00000000..00f16ffb --- /dev/null +++ b/ghy-custom/src/main/resources/mapper/customer/CustomerAddressMapper.xml @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + + + + SELECT customer_address_id, customer_id, name, phone, provinceId, cityId, countryId, status, + address, create_by, create_time, remark + FROM customer_address + + + + + + DELETE FROM customer_address WHERE customer_address_id IN + + #{customerAddressIds} + + + + + DELETE FROM customer_address WHERE customer_address_id = #{customerAddressId} + + + + + + + + insert into customer_address( + customer_id, + name, + phone, + province_id, + city_id, + country_id, + status, + is_default, + create_by, + remark, + create_time + )values( + ${customerId}, + ${name}, + ${phone}, + ${provinceId}, + ${cityId}, + ${countryId}, + ${status}, + ${isDefault}, + ${createBy}, + ${remark}, + sysdate() + ) + + + + update costomer_address + + name = ${name}, + phone = ${phone}, + province_id = ${provinceId}, + city_id = ${cityId}, + country_id = ${countryId}, + address = #{address}, + is_default = #{isDefault}, + status = #{status}, + remark = #{remark}, + update_by = #{updateBy}, + update_time = sysdate() + + where customer_address_id = #{customerAddressId} + + + \ No newline at end of file