diff --git a/ghy-custom/src/main/java/com/ghy/customer/mapper/CustomerMapper.java b/ghy-custom/src/main/java/com/ghy/customer/mapper/CustomerMapper.java index 2d50104b..e72449ad 100644 --- a/ghy-custom/src/main/java/com/ghy/customer/mapper/CustomerMapper.java +++ b/ghy-custom/src/main/java/com/ghy/customer/mapper/CustomerMapper.java @@ -1,7 +1,41 @@ package com.ghy.customer.mapper; +import com.ghy.customer.domain.Customer; + +/** + * @author clunt + * 消费者Mapper + */ public interface CustomerMapper { + /** + * @param customerId 消费者id + * @return 消费者信息 + */ + Customer selectByCustomerId(Long customerId); + /** + * @param customerId 消费者ids + * @return 删除成功条数 + */ + int deleteByIds(Long [] customerId); + + /** + * @param customerId 消费者id + * @return 删除成功条数 + */ + int deleteByCustomerId(Long customerId); + + /** + * @param customer 消费者对象 + * @return 入库成功条数 + */ + int insertCustomer(Customer customer); + + /** + * @param customer 消费者对象 + * @return 更新成功条数 + */ + int updateCustomer(Customer customer); } \ No newline at end of file diff --git a/ghy-custom/src/main/java/com/ghy/customer/service/CustomerService.java b/ghy-custom/src/main/java/com/ghy/customer/service/CustomerService.java index 867dd74b..062ad2e8 100644 --- a/ghy-custom/src/main/java/com/ghy/customer/service/CustomerService.java +++ b/ghy-custom/src/main/java/com/ghy/customer/service/CustomerService.java @@ -1,4 +1,41 @@ package com.ghy.customer.service; +import com.ghy.customer.domain.Customer; + +/** + * @author clunt + * 消费者service层 + */ public interface CustomerService { + + /** + * @param customerId 消费者id + * @return 消费者信息 + */ + Customer selectByCustomerId(Long customerId); + + /** + * @param ids 消费者ids + * @return 删除成功条数 + */ + int deleteByIds(String ids); + + /** + * @param customerId 消费者id + * @return 删除成功条数 + */ + int deleteByCustomerId(Long customerId); + + /** + * @param customer 消费者对象 + * @return 入库成功条数 + */ + int insertCustomer(Customer customer); + + /** + * @param customer 消费者对象 + * @return 更新成功条数 + */ + int updateCustomer(Customer customer); + } diff --git a/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerServiceImpl.java b/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerServiceImpl.java index fefa0d72..39d0d3e7 100644 --- a/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerServiceImpl.java +++ b/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerServiceImpl.java @@ -1,11 +1,65 @@ package com.ghy.customer.service.impl; +import com.ghy.common.core.text.Convert; +import com.ghy.common.exception.ServiceException; +import com.ghy.customer.domain.Customer; +import com.ghy.customer.mapper.CustomerMapper; import com.ghy.customer.service.CustomerService; import org.springframework.stereotype.Service; +import javax.annotation.Resource; + +/** + * @author clunt + * 消费者Impl层 + */ @Service public class CustomerServiceImpl implements CustomerService { + @Resource + private CustomerMapper customerMapper; + @Override + public Customer selectByCustomerId(Long customerId) { + return customerMapper.selectByCustomerId(customerId); + } + @Override + public int deleteByIds(String ids) { + Long [] customerIds = Convert.toLongArray(ids); + for (Long customerId : customerIds) + { + Customer customer = selectByCustomerId(customerId); + if (countUserCustomer(customer) > 0) + { + throw new ServiceException(String.format("%1$s正在使用,不能删除", customer.getName())); + } + } + return customerMapper.deleteByIds(customerIds); + } + + @Override + public int deleteByCustomerId(Long customerId) { + Customer customer = selectByCustomerId(customerId); + if (countUserCustomer(customer) > 0) + { + throw new ServiceException(String.format("%1$s正在使用,不能删除", customer.getName())); + } + return customerMapper.deleteByCustomerId(customerId); + } + + @Override + public int insertCustomer(Customer customer) { + return customerMapper.insertCustomer(customer); + } + + @Override + public int updateCustomer(Customer customer) { + return customerMapper.updateCustomer(customer); + } + + public int countUserCustomer(Customer customer) { + //TODO 需要校验用户是否在被使用。 + return 0; + } } diff --git a/ghy-custom/src/main/resources/mapper.customer/CustomerMapper.xml b/ghy-custom/src/main/resources/mapper.customer/CustomerMapper.xml index 0cf445e3..67faf487 100644 --- a/ghy-custom/src/main/resources/mapper.customer/CustomerMapper.xml +++ b/ghy-custom/src/main/resources/mapper.customer/CustomerMapper.xml @@ -3,7 +3,13 @@ - + + + + + + + @@ -11,60 +17,71 @@ - - SELECT goods_imgs_id, goods_id, img_url, create_by, create_time, remark - FROM goods_imgs + + SELECT customer_id, name, account, phone, open_id, status, + customer_logo_url, create_by, create_time, remark + FROM customer - - DELETE FROM goods_imgs WHERE goods_imgs_id IN - - #{goodsImgsId} + + DELETE FROM customer WHERE customer_id IN + + #{customerIds} - - DELETE FROM goods_imgs WHERE goods_id = #{goodsId} + + DELETE FROM customer WHERE customer_id = #{customerId} - + - - AND goods_id = #{goodsId} + + AND customer = #{customerId} - - - INSERT INTO goods_imgs( - goods_imgs_id, - goods_id, - img_url, - remark, - create_by, - create_time) - VALUES( - #{goodsImgsId}, - #{goodsId}, - #{imgUrl}, - #{remark}, - #{createBy}, - sysdate()); - + + insert into customer( + customer_id, + name, + account, + phone, + customer_logo_url, + open_id, + status, + remark, + create_by, + create_time + )values( + ${customer_id}, + ${name}, + ${account}, + ${phone}, + ${customer_logo_url}, + ${open_id}, + ${status}, + ${remark}, + ${create_by}, + sysdate() + ) - - - UPDATE goods_imgs - - goods_id = #{goodsId}, - img_url = #{imgUrl}, - update_time = sysdate() - - WHERE goods_imgs_id = #{goodsImgsId}; - + + update costomer + + name = ${name}, + account = ${account}, + phone = ${phone}, + customer_logo_url = ${customer_logo_url}, + status = #{status}, + remark = #{remark}, + update_by = #{updateBy}, + update_time = sysdate() + + where customer_id = #{customerId} \ No newline at end of file