From befc0e5606ab7c913dda0346152a4150d0ee5f79 Mon Sep 17 00:00:00 2001 From: liding <756868258@qq.com> Date: 星期五, 06 六月 2025 09:35:59 +0800 Subject: [PATCH] 供应商,客户优化 --- basic-server/src/main/java/com/ruoyi/basic/service/impl/CustomerServiceImpl.java | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 102 insertions(+), 0 deletions(-) diff --git a/basic-server/src/main/java/com/ruoyi/basic/service/impl/CustomerServiceImpl.java b/basic-server/src/main/java/com/ruoyi/basic/service/impl/CustomerServiceImpl.java index dc873b3..2186ae5 100644 --- a/basic-server/src/main/java/com/ruoyi/basic/service/impl/CustomerServiceImpl.java +++ b/basic-server/src/main/java/com/ruoyi/basic/service/impl/CustomerServiceImpl.java @@ -1,11 +1,23 @@ package com.ruoyi.basic.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ruoyi.basic.dto.CustomerDto; import com.ruoyi.basic.entity.Customer; import com.ruoyi.basic.mapper.CustomerMapper; import com.ruoyi.basic.service.CustomerService; +import com.ruoyi.common.utils.bean.BeanUtils; +import com.ruoyi.common.utils.poi.ExcelUtil; +import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import java.util.List; +import java.util.Objects; /** * <p> @@ -18,5 +30,95 @@ @Service @RequiredArgsConstructor public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements CustomerService { + + private final CustomerMapper customerMapper; + @Override + public IPage<Customer> selectCustomerList(Page page, CustomerDto customerDto) { + LambdaQueryWrapper<Customer> queryWrapper = new LambdaQueryWrapper<>(); + // 鍏ㄥ眬妯$硦鎼滅储瀛楁 + if (StringUtils.hasText(customerDto.getSearchAll())) { + String keyword = customerDto.getSearchAll(); + queryWrapper.and(wrapper -> wrapper + .like(Customer::getCustomerName, keyword) + .or() + .like(Customer::getTaxpayerId, keyword) + .or() + .like(Customer::getBusinessAddress, keyword) + ); + } else { + // 鍗曠嫭鏉′欢鏌ヨ + if (StringUtils.hasText(customerDto.getCustomerName())) { + queryWrapper.like(Customer::getCustomerName, customerDto.getCustomerName()); + } + if (StringUtils.hasText(customerDto.getTaxpayerId())) { + queryWrapper.like(Customer::getTaxpayerId, customerDto.getTaxpayerId()); + } + if (StringUtils.hasText(customerDto.getBusinessAddress())) { + queryWrapper.like(Customer::getBusinessAddress, customerDto.getBusinessAddress()); + } + } + // 榛樿鎸夊垱寤烘椂闂村�掑簭鎺掑垪 + queryWrapper.orderByDesc(Customer::getCreateTime); + return customerMapper.selectPage(page, queryWrapper); + } + + @Override + public List<Customer> customerList() { + return customerMapper.selectList(null); + } + + @Override + public int addOrEditCustomer(CustomerDto customerDto) { + Customer customer = new Customer(); + BeanUtils.copyProperties(customerDto, customer); + if (customerDto.getBids().size() != 3) { + throw new RuntimeException("璇烽�夋嫨缁忚惀鍦板潃鐪佸競鍖�"); + } + + if (customerDto.getCids().size() != 3) { + throw new RuntimeException("璇烽�夋嫨鑱旂郴鍦板潃鐪佸競鍖�"); + } + + customer.setBusinessProvinceId(customerDto.getBids().get(0)); + customer.setBusinessCityId(customerDto.getBids().get(1)); + customer.setBusinessDistrictId(customerDto.getBids().get(2)); + + customer.setProvinceId(customerDto.getCids().get(0)); + customer.setCityId(customerDto.getCids().get(1)); + customer.setDistrictId(customerDto.getCids().get(2)); + + if (Objects.isNull(customerDto.getId())) { + return customerMapper.insert(customer); + } else { + return customerMapper.updateById(customer); + } + } + + @Override + public int delCustomerByIds(Long[] ids) { + // 妫�鏌ュ弬鏁� + if (ids == null || ids.length == 0) { + return 0; + } + // 鏋勯�犳洿鏂版潯浠� + UpdateWrapper<Customer> updateWrapper = new UpdateWrapper<>(); + updateWrapper.in("id", ids) + .set("deleted", 1); // 璁剧疆 deleted 涓� 1 琛ㄧず宸插垹闄� + // 鎵ц鎵归噺閫昏緫鍒犻櫎 + return customerMapper.update(null, updateWrapper); + } + + @Override + public void customerExport(HttpServletResponse response, CustomerDto customerDto) { + List<Long> ids = customerDto.getIds(); + List<Customer> list; + if (ids != null && ids.size() > 0) { + list = customerMapper.selectByIds(ids); + } else { + list = customerMapper.selectList(null); + } + ExcelUtil<Customer> util = new ExcelUtil<>(Customer.class); + util.exportExcel(response, list, "瀹㈡埛鏁版嵁"); + } } -- Gitblit v1.9.3