消费者地址接口
This commit is contained in:
parent
22e2abc461
commit
ae11f0a82c
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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<CustomerAddress> 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<CustomerAddress> 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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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<CustomerAddress> 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<CustomerAddress> 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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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<CustomerAddress> 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<CustomerAddress> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,107 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.ghy.customer.mapper.CustomerAddressMapper">
|
||||||
|
|
||||||
|
<resultMap id="CustomerAddressResult" type="com.ghy.customer.domain.CustomerAddress">
|
||||||
|
<result property="customerAddressId" column="customer_address_id" />
|
||||||
|
<result property="customerId" column="customer_id" />
|
||||||
|
<result property="name" column="name" />
|
||||||
|
<result property="phone" column="phone" />
|
||||||
|
<result property="provinceId" column="province_id"/>
|
||||||
|
<result property="cityId" column="city_id"/>
|
||||||
|
<result property="countryId" column="country_id"/>
|
||||||
|
<result property="address" column="address"/>
|
||||||
|
<result property="status" column="status" />
|
||||||
|
<result property="createBy" column="create_by" />
|
||||||
|
<result property="createTime" column="create_time" />
|
||||||
|
<result property="updateBy" column="update_by" />
|
||||||
|
<result property="updateTime" column="update_time" />
|
||||||
|
<result property="remark" column="remark" />
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="selectCustomerAddress">
|
||||||
|
SELECT customer_address_id, customer_id, name, phone, provinceId, cityId, countryId, status,
|
||||||
|
address, create_by, create_time, remark
|
||||||
|
FROM customer_address
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<select id="getCustomerAddressList" resultMap="CustomerAddressResult">
|
||||||
|
<include refid="selectCustomerAddress" />
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<delete id="deleteByIds">
|
||||||
|
DELETE FROM customer_address WHERE customer_address_id IN
|
||||||
|
<foreach collection="array" item="customerIds" open="(" separator="," close=")">
|
||||||
|
#{customerAddressIds}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<delete id="deleteByCustomerAddressId" parameterType="Long">
|
||||||
|
DELETE FROM customer_address WHERE customer_address_id = #{customerAddressId}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<select id="selectByCustomerId" resultMap="CustomerAddressResult">
|
||||||
|
<include refid="selectCustomerAddress"/>
|
||||||
|
<where>
|
||||||
|
<if test="customerId != null and customerId != 0">
|
||||||
|
AND customer_id = #{customerId}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectByCustomerAddressId" resultMap="CustomerAddressResult">
|
||||||
|
<include refid="selectCustomerAddress"/>
|
||||||
|
<where>
|
||||||
|
<if test="customerAddressId != null and customerAddressId != 0">
|
||||||
|
AND customer_address_id = #{customerAddressId}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<insert id="insertCustomerAddress" parameterType="com.ghy.customer.domain.CustomerAddress" useGeneratedKeys="true" keyProperty="customerAddressId">
|
||||||
|
insert into customer_address(
|
||||||
|
<if test="customerId != null and customerId != 0">customer_id,</if>
|
||||||
|
<if test="name != null and name != ''">name,</if>
|
||||||
|
<if test="phone != null and phone != ''">phone,</if>
|
||||||
|
<if test="provinceId != null and provinceId != 0">province_id,</if>
|
||||||
|
<if test="cityId != null and cityId != 0">city_id,</if>
|
||||||
|
<if test="countryId != null and countryId != 0">country_id,</if>
|
||||||
|
<if test="status != null and status != ''">status,</if>
|
||||||
|
<if test="isDefault != null and isDefault != 0">is_default,</if>
|
||||||
|
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||||
|
<if test="remark != null and remark != ''">remark,</if>
|
||||||
|
create_time
|
||||||
|
)values(
|
||||||
|
<if test="customerId != null and customerId != 0">${customerId},</if>
|
||||||
|
<if test="name != null and name != ''">${name},</if>
|
||||||
|
<if test="phone != null and phone != ''">${phone},</if>
|
||||||
|
<if test="provinceId != null and provinceId != 0">${provinceId},</if>
|
||||||
|
<if test="cityId != null and cityId != 0">${cityId},</if>
|
||||||
|
<if test="countryId != null and countryId != 0">${countryId},</if>
|
||||||
|
<if test="status != null">${status},</if>
|
||||||
|
<if test="isDefault != null and isDefault != 0">${isDefault},</if>
|
||||||
|
<if test="createBy != null and createBy != ''">${createBy},</if>
|
||||||
|
<if test="remark != null and remark != ''">${remark},</if>
|
||||||
|
sysdate()
|
||||||
|
)
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="updateCustomerAddress" parameterType="com.ghy.customer.domain.CustomerAddress">
|
||||||
|
update costomer_address
|
||||||
|
<set>
|
||||||
|
<if test="name != null and name != ''">name = ${name},</if>
|
||||||
|
<if test="phone != null and phone != ''">phone = ${phone},</if>
|
||||||
|
<if test="provinceId != null and provinceId != 0">province_id = ${provinceId},</if>
|
||||||
|
<if test="cityId != null and cityId != 0">city_id = ${cityId},</if>
|
||||||
|
<if test="countryId != null and countryId != 0">country_id = ${countryId},</if>
|
||||||
|
<if test="address != null and address != ''">address = #{address},</if>
|
||||||
|
<if test="isDefault != null and isDefault != ''">is_default = #{isDefault},</if>
|
||||||
|
<if test="status != null and status != ''">status = #{status},</if>
|
||||||
|
<if test="remark != null">remark = #{remark},</if>
|
||||||
|
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||||
|
update_time = sysdate()
|
||||||
|
</set>
|
||||||
|
where customer_address_id = #{customerAddressId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Loading…
Reference in New Issue