فهرست منبع

feat(customer): 添加客户、供应商和伙伴商名称模糊查询功能

- 在CustomerInfoController中修改注释,将工商注册信息查询改为客户名称模糊查询
- 在CustomerInfoServiceImpl中添加系统人员与部门名称回填逻辑
- 在CustomerInfoServiceImpl中为queryCustomerListPage方法添加行业分类回填
- 在CustomerInfoServiceImpl中为listCustomer方法添加平台标识设置和筛选条件
- 修改CustomerInfoServiceImpl中的批量转移业务人员和服务人员逻辑,直接更新客户表而非销售信息表
- 在PartnerInfoService和SupplierInfoService中添加按名称模糊查询方法接口
- 在PartnerInfoController和SupplierInfoController中添加按名称查询的REST接口
- 在PartnerInfoServiceImpl和SupplierInfoServiceImpl中实现按名称模糊查询的具体逻辑
- 在SmsAuthStrategy中实现短信登录功能,解析手机号并验证短信验证码
hurx 1 ماه پیش
والد
کامیت
ae4db073ff

+ 34 - 1
ruoyi-auth/src/main/java/org/dromara/auth/service/impl/SmsAuthStrategy.java

@@ -2,6 +2,7 @@ package org.dromara.auth.service.impl;
 
 import cn.dev33.satoken.stp.StpUtil;
 import cn.dev33.satoken.stp.parameter.SaLoginParameter;
+import com.alibaba.fastjson.JSONObject;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboReference;
@@ -80,7 +81,39 @@ public class SmsAuthStrategy implements IAuthStrategy {
      */
     @Override
     public LoginVo clientLogin(String body, RemoteClientVo client) {
-        return null;
+        SmsLoginBody loginBody = JsonUtils.parseObject(body, SmsLoginBody.class);
+        // 1. 将字符串解析为 JSON 对象
+        JSONObject jsonObject = JSONObject.parseObject(body);
+
+        // 2. 提取 mobile 字段
+        String mobile = jsonObject.getString("mobile");
+        loginBody.setPhonenumber(mobile);
+        ValidatorUtils.validate(loginBody);
+        String tenantId = loginBody.getTenantId();
+        String phonenumber = loginBody.getPhonenumber();
+        String smsCode = loginBody.getSmsCode();
+        LoginUser loginUser = TenantHelper.dynamic(tenantId, () -> {
+            LoginUser user = remoteUserService.getUserInfoByPhonenumber(phonenumber, tenantId);
+            loginService.checkLogin(LoginType.SMS, tenantId, user.getUsername(), () -> !validateSmsCode(tenantId, phonenumber, smsCode));
+            return user;
+        });
+        loginUser.setClientKey(client.getClientKey());
+        loginUser.setDeviceType(client.getDeviceType());
+        SaLoginParameter model = new SaLoginParameter();
+        model.setDeviceType(client.getDeviceType());
+        // 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置
+        // 例如: 后台用户30分钟过期 app用户1天过期
+        model.setTimeout(client.getTimeout());
+        model.setActiveTimeout(client.getActiveTimeout());
+        model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId());
+        // 生成token
+        LoginHelper.login(loginUser, model);
+
+        LoginVo loginVo = new LoginVo();
+        loginVo.setAccessToken(StpUtil.getTokenValue());
+        loginVo.setExpireIn(StpUtil.getTokenTimeout());
+        loginVo.setClientId(client.getClientId());
+        return loginVo;
     }
 
     @Override

+ 1 - 1
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/controller/CustomerInfoController.java

@@ -162,7 +162,7 @@ public class CustomerInfoController extends BaseController {
     }
 
     /**
-     * 获取客户名称查询工商注册信息详细信息
+     * 获取客户名称模糊查询客户列表信息
      *
      * @param customerName 主键
      */

+ 23 - 0
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/controller/PartnerInfoController.java

@@ -6,6 +6,8 @@ import lombok.RequiredArgsConstructor;
 import jakarta.servlet.http.HttpServletResponse;
 import jakarta.validation.constraints.*;
 import cn.dev33.satoken.annotation.SaCheckPermission;
+import org.dromara.common.core.utils.StringUtils;
+import org.dromara.customer.domain.vo.CustomerInfoVo;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.validation.annotation.Validated;
 import org.dromara.common.idempotent.annotation.RepeatSubmit;
@@ -112,4 +114,25 @@ public class PartnerInfoController extends BaseController {
                           @PathVariable("ids") Long[] ids) {
         return toAjax(partnerInfoService.deleteWithValidByIds(List.of(ids), true));
     }
+
+    /**
+     * 获取伙伴商名称模糊查询伙伴商列表信息
+     *
+     * @param partnerName 主键
+     */
+    @GetMapping("/selectByPartnerName/{partnerName}")
+    public R<List<PartnerInfoVo>> selectByPartnerName(
+        @PathVariable("partnerName") String partnerName) {
+
+        if (StringUtils.isBlank(partnerName)) {
+            return R.fail("伙伴商名称不能为空");
+        }
+
+        List<PartnerInfoVo> partnerfoVoList = partnerInfoService.selectByPartnerName(partnerName);
+        if (null == partnerfoVoList || partnerfoVoList.size() == 0) {
+            return R.fail("未查询到伙伴商信息");
+        }
+
+        return R.ok(partnerfoVoList);
+    }
 }

+ 22 - 0
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/controller/SupplierInfoController.java

@@ -8,6 +8,7 @@ import jakarta.validation.constraints.NotNull;
 import lombok.RequiredArgsConstructor;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.dromara.common.core.domain.R;
+import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.core.validate.AddGroup;
 import org.dromara.common.core.validate.EditGroup;
 import org.dromara.common.excel.core.ExcelResult;
@@ -19,6 +20,7 @@ import org.dromara.common.mybatis.core.page.PageQuery;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
 import org.dromara.common.web.core.BaseController;
 import org.dromara.customer.domain.bo.SupplierInfoBo;
+import org.dromara.customer.domain.vo.PartnerInfoVo;
 import org.dromara.customer.domain.vo.SupplierInfoImportVo;
 import org.dromara.customer.domain.vo.SupplierInfoVo;
 import org.dromara.customer.listener.SupplierImportListener;
@@ -254,4 +256,24 @@ public class SupplierInfoController extends BaseController {
         ExcelUtil.exportExcel(new ArrayList<>(), "供应商数据", SupplierInfoImportVo.class, response);
     }
 
+    /**
+     * 获取供应商名称模糊查询供应商列表信息
+     *
+     * @param supplierName 主键
+     */
+    @GetMapping("/selectBySupplierName/{supplierName}")
+    public R<List<SupplierInfoVo>> selectByPartnerName(
+        @PathVariable("supplierName") String supplierName) {
+
+        if (StringUtils.isBlank(supplierName)) {
+            return R.fail("供应商名称不能为空");
+        }
+
+        List<SupplierInfoVo> partnerfoVoList = supplierInfoService.selectBySupplierName(supplierName);
+        if (null == partnerfoVoList || partnerfoVoList.size() == 0) {
+            return R.fail("未查询到供应商信息");
+        }
+
+        return R.ok(partnerfoVoList);
+    }
 }

+ 9 - 0
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/service/IPartnerInfoService.java

@@ -2,6 +2,7 @@ package org.dromara.customer.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.dromara.customer.domain.PartnerInfo;
+import org.dromara.customer.domain.vo.CustomerInfoVo;
 import org.dromara.customer.domain.vo.PartnerInfoVo;
 import org.dromara.customer.domain.bo.PartnerInfoBo;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
@@ -79,4 +80,12 @@ public interface IPartnerInfoService extends IService<PartnerInfo> {
 
     /*根据ids查询伙伴商名称*/
     Map<Long, String> selectPartnerNameByIds(Set<Long> ids);
+
+    /**
+     * 查询伙伴商名称查询伙伴商信息
+     *
+     * @param partnerName 主键
+     * @return 伙伴商信息
+     */
+    List<PartnerInfoVo> selectByPartnerName(String partnerName);
 }

+ 9 - 0
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/service/ISupplierInfoService.java

@@ -6,6 +6,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
 import jakarta.validation.constraints.NotNull;
 import org.dromara.customer.domain.SupplierInfo;
 import org.dromara.customer.domain.bo.*;
+import org.dromara.customer.domain.vo.PartnerInfoVo;
 import org.dromara.customer.domain.vo.SupplierInfoVo;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
 import org.dromara.common.mybatis.core.page.PageQuery;
@@ -145,4 +146,12 @@ public interface ISupplierInfoService extends IService<SupplierInfo> {
      * @return 供应商对象信息
      */
     SupplierInfoVo selectSupplierByEnterpriseName(String enterpriseName);
+
+    /**
+     * 查询供应商名称查询供应商信息
+     *
+     * @param supplierName 主键
+     * @return 供应商信息
+     */
+    List<SupplierInfoVo> selectBySupplierName(String supplierName);
 }

+ 76 - 15
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/service/impl/CustomerInfoServiceImpl.java

@@ -172,6 +172,33 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
 
         vo.setCustomerSalesInfoVo(voObj);
 
+        Set<Long> comStaffIds = new HashSet<>();
+        Set<Long> comDeptIds = new HashSet<>(); //系统的部门
+
+        if (vo.getSalesPersonId() != null) {
+            comStaffIds.add(customerSalesInfo.getSalesPersonId());
+        }
+        if (vo.getServiceStaffId() != null) {
+            comStaffIds.add(customerSalesInfo.getServiceStaffId());
+        }
+        if (vo.getBelongingDepartmentId() != null) {
+            comDeptIds.add(customerSalesInfo.getBelongingDepartmentId());
+        }
+
+        Map<Long, String> comStaffMap = staffIds.isEmpty()
+            ? Collections.emptyMap()
+            : remoteComStaffService.selectStaffNameByIds(staffIds);
+
+        Map<Long, String> comDeptMap = deptIds.isEmpty()//系统的部门
+            ? Collections.emptyMap()
+            : remoteDeptService.selectDeptNameByIds(deptIds);
+
+        /*回填系统的人员与部门*/
+        vo.setSalesPersonName(comStaffMap.get(vo.getSalesPersonId()));
+        vo.setServiceStaffName(comStaffMap.get(vo.getServiceStaffId()));
+        vo.setBelongingDepartmentName(comDeptMap.get(vo.getBelongingDepartmentId()));
+
+
         List<CustomerContact> contactEntities = customerContactMapper.selectListByCustomerId(id);
         vo.setCustomerContactVoList(
             contactEntities != null
@@ -239,6 +266,7 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
                     IndustryCategoryVo::getIndustryCategoryName,
                     (e, r) -> e
                 ));
+            records.forEach(vo -> vo.setIndustryCategory(industryMap.get(vo.getIndustryCategoryId())));
         }
 
         // === 2. 提取客户ID,查询销售信息 ===
@@ -278,6 +306,7 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
                 (existing, replacement) -> existing // 若有重复,保留第一个
             ));
 
+        // === 4. 收集人员和部门ID ===
         Set<Long> staffIds = new HashSet<>();
         Set<Long> deptIds = new HashSet<>();
 
@@ -305,6 +334,31 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
             vo.setServiceStaff(staffMap.get(vo.getServiceStaffId()));
             vo.setBelongingDepartment(deptMap.get(vo.getBelongingDepartmentId()));
         }
+        //系统人员与部门
+        Set<Long> comStaffIds = new HashSet<>();
+        Set<Long> comDeptIds = new HashSet<>();
+
+        for (CustomerInfoVo vo : records) {
+            if (vo.getSalesPersonId() != null) comStaffIds.add(vo.getSalesPersonId());
+            if (vo.getServiceStaffId() != null) comStaffIds.add(vo.getServiceStaffId());
+            if (vo.getBelongingDepartmentId() != null) comDeptIds.add(vo.getBelongingDepartmentId());
+        }
+
+        // === 远程调用获取名称 ===
+        Map<Long, String> comStaffMap = staffIds.isEmpty()
+            ? Collections.emptyMap()
+            : remoteComStaffService.selectStaffNameByIds(comStaffIds);
+
+        Map<Long, String> comDeptMap = deptIds.isEmpty()
+            ? Collections.emptyMap()
+            : remoteDeptService.selectDeptNameByIds(comDeptIds);
+
+        // === 回填系统人员和部门名称到 customerInfoVo ===
+        records.forEach(v -> {
+            v.setSalesPersonName(comStaffMap.get(v.getSalesPersonId()));
+            v.setServiceStaffName(comStaffMap.get(v.getServiceStaffId()));
+            v.setBelongingDepartmentName(comDeptMap.get(v.getBelongingDepartmentId()));
+        });
 
         // === 7. 将销售信息回填到客户VO ===
         for (CustomerInfoVo customerVo : records) {
@@ -471,6 +525,10 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
      */
     @Override
     public TableDataInfo<CustomerListVo> queryCustomerListPage(CustomerListBo bo, PageQuery pageQuery) {
+        // 设置平台标识(暂时注释掉)
+        // if (StringUtils.isBlank(bo.getPlatformCode())) {
+        //     bo.setPlatformCode(PlatformContext.getPlatform());
+        // }
         Page<CustomerListVo> page = baseMapper.selectCustomerListPage(pageQuery.build(), bo);
 
         // 补充业务员名称和信用等级名称
@@ -561,6 +619,9 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
         lqw.orderByDesc(CustomerInfo::getId);
         lqw.eq(StringUtils.isNotBlank(bo.getCustomerNo()), CustomerInfo::getCustomerNo, bo.getCustomerNo());
         lqw.eq(bo.getBelongCompanyId() != null, CustomerInfo::getBelongCompanyId, bo.getBelongCompanyId());
+        lqw.eq(bo.getSalesPersonId() != null, CustomerInfo::getSalesPersonId, bo.getSalesPersonId());
+        lqw.eq(bo.getServiceStaffId() != null, CustomerInfo::getServiceStaffId, bo.getServiceStaffId());
+        lqw.eq(bo.getBelongingDepartmentId() != null, CustomerInfo::getBelongingDepartmentId, bo.getBelongingDepartmentId());
         lqw.like(StringUtils.isNotBlank(bo.getCompanyName()), CustomerInfo::getCompanyName, bo.getCompanyName());
         lqw.like(StringUtils.isNotBlank(bo.getCustomerName()), CustomerInfo::getCustomerName, bo.getCustomerName());
         lqw.like(StringUtils.isNotBlank(bo.getBusinessCustomerName()), CustomerInfo::getBusinessCustomerName, bo.getBusinessCustomerName());
@@ -1208,25 +1269,25 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
         }
 
         try {
-            List<CustomerSalesInfo> updateList = new ArrayList<>();
-            CustomerSalesInfo salesInfo = null;
+            List<CustomerInfo> updateList = new ArrayList<>();
+            CustomerInfo customerInfo = null;
             for (Long customerId : customerIds) {
                 if (customerId == null) {
                     continue;
                 }
 
-                salesInfo = customerSalesInfoMapper.selectByCustomerId(customerId);
-                if (salesInfo != null) {
-                    salesInfo.setSalesPersonId(salesPersonId);
-                    salesInfo.setBelongingDepartmentId(deptId);
-                    updateList.add(salesInfo);
+                customerInfo = baseMapper.selectById(customerId);
+                if (customerInfo != null) {
+                    customerInfo.setSalesPersonId(salesPersonId);
+                    customerInfo.setBelongingDepartmentId(deptId);
+                    updateList.add(customerInfo);
                 } else {
                     log.warn("客户 ID: {} 的销售信息不存在,跳过更新", customerId);
                 }
             }
 
             if (!updateList.isEmpty()) {
-                boolean success = customerSalesInfoMapper.updateBatchById(updateList);
+                boolean success = baseMapper.updateBatchById(updateList);
                 if (success) {
                     log.info("成功转移 {} 个客户的业务人员,目标业务员 ID: {}, 部门 ID: {}",
                         updateList.size(), salesPersonId, deptId);
@@ -1261,24 +1322,24 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
         }
 
         try {
-            List<CustomerSalesInfo> updateList = new ArrayList<>();
-            CustomerSalesInfo salesInfo = null;
+            List<CustomerInfo> updateList = new ArrayList<>();
+            CustomerInfo customerInfo = null;
             for (Long customerId : customerIds) {
                 if (customerId == null) {
                     continue;
                 }
 
-                salesInfo = customerSalesInfoMapper.selectByCustomerId(customerId);
-                if (salesInfo != null) {
-                    salesInfo.setServiceStaffId(serviceStaffId);
-                    updateList.add(salesInfo);
+                customerInfo = baseMapper.selectById(customerId);
+                if (customerInfo != null) {
+                    customerInfo.setServiceStaffId(serviceStaffId);
+                    updateList.add(customerInfo);
                 } else {
                     log.warn("客户 ID: {} 的销售信息不存在,跳过更新", customerId);
                 }
             }
 
             if (!updateList.isEmpty()) {
-                boolean success = customerSalesInfoMapper.updateBatchById(updateList);
+                boolean success = baseMapper.updateBatchById(updateList);
                 if (success) {
                     log.info("成功转移 {} 个客户的客服人员,目标客服人员 ID: {}",
                         updateList.size(), serviceStaffId);

+ 14 - 0
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/service/impl/PartnerInfoServiceImpl.java

@@ -10,7 +10,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.dromara.customer.domain.CustomerInfo;
 import org.dromara.customer.domain.SupplierInfo;
+import org.dromara.customer.domain.vo.CustomerInfoVo;
 import org.springframework.stereotype.Service;
 import org.dromara.customer.domain.bo.PartnerInfoBo;
 import org.dromara.customer.domain.vo.PartnerInfoVo;
@@ -186,4 +188,16 @@ public class PartnerInfoServiceImpl extends ServiceImpl<PartnerInfoMapper, Partn
 
         return resultMap;
     }
+
+    @Override
+    public List<PartnerInfoVo> selectByPartnerName(String partnerName) {
+        if (StringUtils.isBlank(partnerName)) {
+            return Collections.emptyList();
+        }
+
+        LambdaQueryWrapper<PartnerInfo> wrapper = new LambdaQueryWrapper<PartnerInfo>()
+            .like(PartnerInfo::getPartnerName, partnerName);
+
+        return baseMapper.selectVoList(wrapper);
+    }
 }

+ 12 - 0
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/service/impl/SupplierInfoServiceImpl.java

@@ -2410,4 +2410,16 @@ public class SupplierInfoServiceImpl extends ServiceImpl<SupplierInfoMapper, Sup
     public SupplierInfoVo selectSupplierByEnterpriseName(String enterpriseName) {
         return baseMapper.selectVoOne(new LambdaQueryWrapper<SupplierInfo>().eq(SupplierInfo::getEnterpriseName, enterpriseName));
     }
+
+    @Override
+    public List<SupplierInfoVo> selectBySupplierName(String supplierName) {
+        if (StringUtils.isBlank(supplierName)) {
+            return Collections.emptyList();
+        }
+
+        LambdaQueryWrapper<SupplierInfo> wrapper = new LambdaQueryWrapper<SupplierInfo>()
+            .like(SupplierInfo::getEnterpriseName, supplierName);
+
+        return baseMapper.selectVoList(wrapper);
+    }
 }