From 7731d721733f07fa80a198e630e222fd3625668a Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期三, 27 八月 2025 14:30:08 +0800
Subject: [PATCH] yys
---
basic-server/src/main/java/com/ruoyi/basic/service/impl/CustomerServiceImpl.java | 124 +++++++++++++++++++++++++++++++++++++---
1 files changed, 113 insertions(+), 11 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 87042cf..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,22 +1,124 @@
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import org.springframework.stereotype.Service;
+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>
- * 鏈嶅姟瀹炵幇绫�
- * </p>
-*
-* @author ruoyi
-* @since 2025-06-03
-*/
+ * <p>
+ * 鏈嶅姟瀹炵幇绫�
+ * </p>
+ *
+ * @author ruoyi
+ * @since 2025-06-03
+ */
@Service
@RequiredArgsConstructor
- public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements CustomerService {
+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