From 8cbe4f260becf406eadbed757d4cbb52da6cb831 Mon Sep 17 00:00:00 2001 From: Trae AI Date: Wed, 4 Feb 2026 09:55:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=AD=9B=E9=80=89=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=9A=E5=88=86=E7=A6=BB=E4=B8=AA=E4=BA=BA=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=B8=8E=E5=85=AC=E6=B5=B7=E6=B1=A0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=9A=84=E7=AD=9B=E9=80=89=E5=8F=98=E9=87=8F=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=B7=B2=E8=B7=9F=E8=BF=9B/=E6=9C=AA=E8=B7=9F?= =?UTF-8?q?=E8=BF=9B=E6=8C=89=E9=92=AE=E7=AD=9B=E9=80=89=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=B6=88=E5=A4=B1=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/aspect/ReadWriteSeparationAspect.java | 66 --- .../example/web/config/DataSourceConfig.java | 18 +- .../web/service/impl/UserServiceImpl.java | 3 +- web/src/main/resources/application.yaml | 22 - web/src/main/resources/mapper/UsersMapper.xml | 52 +- web/src/main/resources/static/index.html | 444 ++++++++++++------ web/src/main/resources/static/login.html | 107 +---- 7 files changed, 334 insertions(+), 378 deletions(-) delete mode 100644 web/src/main/java/com/example/web/aspect/ReadWriteSeparationAspect.java diff --git a/web/src/main/java/com/example/web/aspect/ReadWriteSeparationAspect.java b/web/src/main/java/com/example/web/aspect/ReadWriteSeparationAspect.java deleted file mode 100644 index e501121..0000000 --- a/web/src/main/java/com/example/web/aspect/ReadWriteSeparationAspect.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.example.web.aspect; - -import com.example.web.config.DataSourceContextHolder; -import org.aspectj.lang.JoinPoint; -import org.aspectj.lang.annotation.After; -import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Before; -import org.aspectj.lang.annotation.Pointcut; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -@Aspect -@Component -public class ReadWriteSeparationAspect { - - private static final Logger logger = LoggerFactory.getLogger(ReadWriteSeparationAspect.class); - - // 定义切入点,拦截所有Mapper方法 - @Pointcut("execution(* com.example.web.mapper.*Mapper.*(..))") - public void mapperPointcut() { - } - - @Before("mapperPointcut()") - public void beforeMapperMethod(JoinPoint joinPoint) { - String methodName = joinPoint.getSignature().getName(); - String className = joinPoint.getTarget().getClass().getSimpleName(); - - // 获取当前使用的数据源 - String currentDataSource = DataSourceContextHolder.getDataSource(); - - // 根据方法名判断是读操作还是写操作 - if (isReadOperation(methodName)) { - // 读操作使用从库 - String slaveDataSource = currentDataSource.contains("wechat") ? "wechat-slave" : "primary-slave"; - DataSourceContextHolder.setDataSource(slaveDataSource); - logger.debug("切换到从库数据源: {},执行方法: {}.{}", slaveDataSource, className, methodName); - } else { - // 写操作使用主库 - String masterDataSource = currentDataSource.contains("wechat") ? "wechat" : "primary"; - DataSourceContextHolder.setDataSource(masterDataSource); - logger.debug("切换到主库数据源: {},执行方法: {}.{}", masterDataSource, className, methodName); - } - } - - @After("mapperPointcut()") - public void afterMapperMethod() { - // 方法执行完成后清除数据源上下文 - DataSourceContextHolder.clearDataSource(); - } - - /** - * 判断是否为读操作 - * @param methodName 方法名 - * @return 是否为读操作 - */ - private boolean isReadOperation(String methodName) { - // 通常查询方法以find、get、select、query、list、count等开头的方法为读操作 - return methodName.startsWith("find") || - methodName.startsWith("get") || - methodName.startsWith("select") || - methodName.startsWith("query") || - methodName.startsWith("list") || - methodName.startsWith("count"); - } -} \ No newline at end of file diff --git a/web/src/main/java/com/example/web/config/DataSourceConfig.java b/web/src/main/java/com/example/web/config/DataSourceConfig.java index f484069..d2f95d8 100644 --- a/web/src/main/java/com/example/web/config/DataSourceConfig.java +++ b/web/src/main/java/com/example/web/config/DataSourceConfig.java @@ -19,27 +19,13 @@ public class DataSourceConfig { public DataSource primaryDataSource() { return DataSourceBuilder.create().build(); } - - // userlogin从库数据源 - @Bean(name = "primarySlaveDataSource") - @ConfigurationProperties(prefix = "spring.datasource.primary-slave") - public DataSource primarySlaveDataSource() { - return DataSourceBuilder.create().build(); - } - + // 第二个数据源(wechat_app) @Bean(name = "wechatDataSource") @ConfigurationProperties(prefix = "spring.datasource.wechat") public DataSource wechatDataSource() { return DataSourceBuilder.create().build(); } - - // wechat_app从库数据源 - @Bean(name = "wechatSlaveDataSource") - @ConfigurationProperties(prefix = "spring.datasource.wechat-slave") - public DataSource wechatSlaveDataSource() { - return DataSourceBuilder.create().build(); - } // 动态数据源配置 @Primary @@ -49,9 +35,7 @@ public class DataSourceConfig { dynamicDataSource.setDefaultTargetDataSource(primaryDataSource()); Map dataSources = new HashMap<>(); dataSources.put("primary", primaryDataSource()); - dataSources.put("primary-slave", primarySlaveDataSource()); dataSources.put("wechat", wechatDataSource()); - dataSources.put("wechat-slave", wechatSlaveDataSource()); dynamicDataSource.setTargetDataSources(dataSources); return dynamicDataSource; } diff --git a/web/src/main/java/com/example/web/service/impl/UserServiceImpl.java b/web/src/main/java/com/example/web/service/impl/UserServiceImpl.java index 39a622a..7c8f210 100644 --- a/web/src/main/java/com/example/web/service/impl/UserServiceImpl.java +++ b/web/src/main/java/com/example/web/service/impl/UserServiceImpl.java @@ -180,8 +180,7 @@ public class UserServiceImpl implements UserService { int offset = (page - 1) * size; params.put("offset", offset); params.put("limit", size); - params.put("followup", ""); // 公海池数据没有负责人信息 - return usersMapper.findWithPagination(params); + return usersMapper.findPublicWithPagination(params); } @Override diff --git a/web/src/main/resources/application.yaml b/web/src/main/resources/application.yaml index bfac76f..42681fd 100644 --- a/web/src/main/resources/application.yaml +++ b/web/src/main/resources/application.yaml @@ -11,17 +11,6 @@ spring: idle-timeout: 600000 minimum-idle: 5 maximum-pool-size: 20 - # userlogin从库数据库 - primary-slave: - jdbc-url: jdbc:mysql://1.95.162.61:3306/userlogin?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true - username: root - password: schl@2025 - driver-class-name: com.mysql.cj.jdbc.Driver - hikari: - max-lifetime: 1200000 - idle-timeout: 600000 - minimum-idle: 5 - maximum-pool-size: 30 # wechat_app数据库 wechat: jdbc-url: jdbc:mysql://1.95.162.61:3306/wechat_app?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true @@ -33,17 +22,6 @@ spring: idle-timeout: 600000 minimum-idle: 5 maximum-pool-size: 20 - # wechat_app从库数据库 - wechat-slave: - jdbc-url: jdbc:mysql://1.95.162.61:3306/wechat_app?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true - username: root - password: schl@2025 - driver-class-name: com.mysql.cj.jdbc.Driver - hikari: - max-lifetime: 1200000 - idle-timeout: 600000 - minimum-idle: 5 - maximum-pool-size: 30 server: port: 8083 diff --git a/web/src/main/resources/mapper/UsersMapper.xml b/web/src/main/resources/mapper/UsersMapper.xml index 9af5b17..b2acd1e 100644 --- a/web/src/main/resources/mapper/UsersMapper.xml +++ b/web/src/main/resources/mapper/UsersMapper.xml @@ -105,25 +105,27 @@ SELECT u.* FROM users u - JOIN usermanagements um ON u.userId = um.userId + LEFT JOIN usermanagements um ON u.userId = um.userId WHERE u.type != 'Colleague' - AND (um.managercompany IS NULL OR um.managercompany = '') - AND (um.managerdepartment IS NULL OR um.managerdepartment = '') - AND (um.organization IS NULL OR um.organization = '') - AND (um.role IS NULL OR um.role = '') - AND (um.userName IS NULL OR um.userName = '') + AND ((um.userId IS NULL) OR + (um.managercompany IS NULL OR um.managercompany = '') AND + (um.managerdepartment IS NULL OR um.managerdepartment = '') AND + (um.organization IS NULL OR um.organization = '') AND + (um.role IS NULL OR um.role = '') AND + (um.userName IS NULL OR um.userName = '')) AND u.phoneNumber = #{phoneNumber} @@ -197,13 +200,14 @@ - - - - - - - 类型: + 类型: ' : ''; + + var row = '' + + checkboxCell + + '' + (user.nickName || '-') + '' + + '' + (user.phoneNumber || '-') + '' + + '' + mapUserType(user.type) + '' + + '' + formatDateTime(user.created_at) + '' + + '' + (user.followup || '-') + '' + + '' + responseTime + '' + + managerCell + + ' ' + + ''; + publicBody.innerHTML += row; + + // 有数据时显示分页控件 + publicPagination.style.display = 'flex'; + } + + // 渲染分页控件 + renderPublicPagination(publicPage, totalPages, total); + } else { + publicEmpty.style.display = 'block'; + // 没有数据时隐藏分页控件 + publicPagination.style.display = 'none'; + } + } + function objectToQueryString(obj) { return Object.keys(obj) .map(key => key + '=' + encodeURIComponent(obj[key])) @@ -5257,8 +5407,8 @@ } // 按负责人筛选 - if (currentManagerFilter) { - return user.managerName === currentManagerFilter; + if (personalManagerFilter) { + return user.managerName === personalManagerFilter; } // 其他情况,不过滤 @@ -5381,33 +5531,33 @@ } // 按负责人筛选 - if (currentManagerFilter) { - console.log('公海池筛选负责人:', currentManagerFilter, '用户负责人:', user.managerName); - if (user.managerName !== currentManagerFilter) { + if (publicManagerFilter) { + console.log('公海池筛选负责人:', publicManagerFilter, '用户负责人:', user.managerName); + if (user.managerName !== publicManagerFilter) { return false; } } // 按手机号搜索 - if (currentPhoneSearch) { - if (!user.phoneNumber || !user.phoneNumber.includes(currentPhoneSearch)) { + if (publicPhoneSearch) { + if (!user.phoneNumber || !user.phoneNumber.includes(publicPhoneSearch)) { return false; } } // 按创建时间范围筛选 - if (currentStartDate || currentEndDate) { + if (publicStartDate || publicEndDate) { var userCreatedAt = new Date(user.created_at); - if (currentStartDate) { - var startDate = new Date(currentStartDate); + if (publicStartDate) { + var startDate = new Date(publicStartDate); if (userCreatedAt < startDate) { return false; } } - if (currentEndDate) { - var endDate = new Date(currentEndDate); + if (publicEndDate) { + var endDate = new Date(publicEndDate); // 设置结束日期为当天的23:59:59 endDate.setHours(23, 59, 59, 999); if (userCreatedAt > endDate) { @@ -5417,16 +5567,16 @@ } // 按类型筛选 - if (currentTypeFilter) { + if (publicTypeFilter) { var userType = user.type || ''; - console.log('公海池筛选类型:', currentTypeFilter, '用户类型:', userType); + console.log('公海池筛选类型:', publicTypeFilter, '用户类型:', userType); // 特殊处理seller和buyer类型,直接比较英文 - if (currentTypeFilter === 'seller') { + if (publicTypeFilter === 'seller') { if (userType !== 'seller' && userType !== '供应商') { return false; } - } else if (currentTypeFilter === 'buyer') { + } else if (publicTypeFilter === 'buyer') { if (userType !== 'buyer' && userType !== '大贸易客户') { return false; } @@ -5439,7 +5589,7 @@ 'defective_egg': '次品蛋专项类', 'other': '其他类型' }; - var filterValue = typeMap[currentTypeFilter] || currentTypeFilter; + var filterValue = typeMap[publicTypeFilter] || publicTypeFilter; if (userType !== filterValue) { return false; } @@ -6132,7 +6282,7 @@ prevBtn.onclick = function() { if (current > 1) { publicPage = current - 1; - loadPublicData(); + displayFilteredPublicData(); } }; pagination.appendChild(prevBtn); @@ -6185,7 +6335,7 @@ nextBtn.onclick = function() { if (current < total) { publicPage = current + 1; - loadPublicData(); + displayFilteredPublicData(); } }; pagination.appendChild(nextBtn); @@ -6406,7 +6556,7 @@ firstBtn.onclick = function() { if (current > 1) { publicPage = 1; - loadPublicData(); + displayFilteredPublicData(); } }; pagination.appendChild(firstBtn); @@ -6448,7 +6598,7 @@ lastBtn.onclick = function() { if (current < total) { publicPage = total; - loadPublicData(); + displayFilteredPublicData(); } }; pagination.appendChild(lastBtn); @@ -6478,7 +6628,7 @@ pageSizeSelect.onchange = function() { publicPageSize = parseInt(this.value); publicPage = 1; - loadPublicData(); + displayFilteredPublicData(); }; pageSizeContainer.appendChild(pageSizeText); @@ -6506,7 +6656,7 @@ var jumpPage = parseInt(jumpInput.value); if (jumpPage >= 1 && jumpPage <= total) { publicPage = jumpPage; - loadPublicData(); + displayFilteredPublicData(); } }; @@ -7436,11 +7586,11 @@ organization: usersManagements.organization || '', role: usersManagements.role || '', filter: personalFilter, - managerName: currentManagerFilter || '', - phoneNumber: currentPhoneSearch || '', - startDate: currentStartDate || '', - endDate: currentEndDate || '', - type: currentTypeFilter || '' + managerName: personalManagerFilter || '', + phoneNumber: personalPhoneSearch || '', + startDate: personalStartDate || '', + endDate: personalEndDate || '', + type: personalTypeFilter || '' }; var url = '/KH/api/users?' + objectToQueryString(params); diff --git a/web/src/main/resources/static/login.html b/web/src/main/resources/static/login.html index 12cd723..68ead39 100644 --- a/web/src/main/resources/static/login.html +++ b/web/src/main/resources/static/login.html @@ -107,9 +107,6 @@