From 67f8738c5ea04510f6576c60e8182fd077173059 Mon Sep 17 00:00:00 2001 From: Yifei Kuang Date: Sun, 12 Jan 2025 23:35:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B8=88=E5=82=85=E5=88=97=E8=A1=A8=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=8C=BA=E5=9F=9F=E5=92=8C=E7=B1=BB=E7=9B=AE=E7=AD=9B?= =?UTF-8?q?=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/worker/WorkerController.java | 78 +++++- .../ghy/web/pojo/vo/WorkerListRequest.java | 12 + .../resources/templates/worker/worker.html | 226 +++++++++++++++++- .../mapper/worker/WorkerAreaMapper.xml | 9 + 4 files changed, 311 insertions(+), 14 deletions(-) diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/worker/WorkerController.java b/ghy-admin/src/main/java/com/ghy/web/controller/worker/WorkerController.java index 76ac3a04..e96e1beb 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/worker/WorkerController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/worker/WorkerController.java @@ -133,32 +133,84 @@ public class WorkerController extends BaseController { try { // 查询满足区域条件的师傅区域记录 - List workerIdsByArea; + List workerIdsByArea = new ArrayList<>(); if(workerListRequest.getAreaId() != null){ WorkerArea workerArea = new WorkerArea(); workerArea.setDistrictId(workerListRequest.getAreaId()); + // 如果有省市区的查询条件,需要构建完整的区域查询条件 + boolean flag = StringUtils.isNotEmpty(workerListRequest.getDistrictId()) || StringUtils.isNotEmpty(workerListRequest.getProvinceId()) + || StringUtils.isNotEmpty(workerListRequest.getCityId()) || StringUtils.isNotEmpty(workerListRequest.getStreetId()); + if(flag){ + workerArea.setDistrictId(null); + } + if(StringUtils.isNotEmpty(workerListRequest.getDistrictId())){ + workerArea.setDistrictId(Long.valueOf(workerListRequest.getDistrictId())); + } + if(StringUtils.isNotEmpty(workerListRequest.getProvinceId())) { + workerArea.setProvinceId(Long.valueOf(workerListRequest.getProvinceId())); + } + if(StringUtils.isNotEmpty(workerListRequest.getCityId())) { + workerArea.setCityId(Long.valueOf(workerListRequest.getCityId())); + } + if(StringUtils.isNotEmpty(workerListRequest.getStreetId())) { + workerArea.setStreetId(Long.valueOf(workerListRequest.getStreetId())); + } List workerAreaList = workerAreaService.getWorkerAreaList(workerArea); - workerIdsByArea = workerAreaList.stream().map(WorkerArea::getWorkerId).collect(Collectors.toList()); - }else { - workerIdsByArea = new ArrayList<>(); + workerIdsByArea = workerAreaList.stream() + .map(WorkerArea::getWorkerId) + .collect(Collectors.toList()); } // 查询满足技能条件的师傅技能记录 - List workerIdsByCategory; - if(workerListRequest.getGoodsCategoryId()!=null){ + List workerIdsByCategory = new ArrayList<>(); + if(workerListRequest.getGoodsCategoryId() != null){ WorkerGoodsCategory workerGoodsCategory = new WorkerGoodsCategory(); workerGoodsCategory.setGoodsCategoryId(workerListRequest.getGoodsCategoryId()); + // 如果选择了上级类目但未选择最终类目,则查询该类目下所有子类目 + if(StringUtils.isNotEmpty(workerListRequest.getCategoryLevel1()) + && workerListRequest.getGoodsCategoryId() == null) { + GoodsCategory param = new GoodsCategory(); + param.setParentCategoryId(Long.valueOf(workerListRequest.getCategoryLevel1())); + List subCategories = goodsCategoryService.selectGoodsCategoryList(param); + List categoryIds = subCategories.stream() + .map(x->x.getGoodsCategoryId().toString()) + .collect(Collectors.toList()); + workerGoodsCategory.setCategoryIds(categoryIds); + } + // 如果选择了二级类目但未选择三级类目 + else if(StringUtils.isNotEmpty(workerListRequest.getCategoryLevel2()) + && workerListRequest.getGoodsCategoryId() == null) { + GoodsCategory param = new GoodsCategory(); + param.setParentCategoryId(Long.valueOf(workerListRequest.getCategoryLevel2())); + List subCategories = goodsCategoryService.selectGoodsCategoryList(param); + List categoryIds = subCategories.stream() + .map(x->x.getGoodsCategoryId().toString()) + .collect(Collectors.toList()); + workerGoodsCategory.setCategoryIds(categoryIds); + } List workerGoodsCategoryList = workerGoodsCategoryService.getWorkerGoodsCategory(workerGoodsCategory); - workerIdsByCategory = workerGoodsCategoryList.stream().map(WorkerGoodsCategory::getWorkerId).collect(Collectors.toList()); - }else { - workerIdsByCategory = new ArrayList<>(); + workerIdsByCategory = workerGoodsCategoryList.stream() + .map(WorkerGoodsCategory::getWorkerId) + .collect(Collectors.toList()); } // 两个list中的workerid取交集 - List resWorkerIds = new ArrayList<>(CollectionUtils.intersection(workerIdsByArea, workerIdsByCategory)); - if (CollectionUtils.isEmpty(resWorkerIds) && (workerListRequest.getAreaId() != null || workerListRequest.getGoodsCategoryId()!=null)) { - // 交集不存在的情况直接返回空list - return getDataTable(resList); + List resWorkerIds = new ArrayList<>(); + if(!workerIdsByArea.isEmpty() && !workerIdsByCategory.isEmpty()) { + resWorkerIds.addAll(CollectionUtils.intersection(workerIdsByArea, workerIdsByCategory)); + } else if(!workerIdsByArea.isEmpty()) { + resWorkerIds.addAll(workerIdsByArea); + } else if(!workerIdsByCategory.isEmpty()) { + resWorkerIds.addAll(workerIdsByCategory); + } + + if (!resWorkerIds.isEmpty() || + workerListRequest.getAreaId() != null || + workerListRequest.getGoodsCategoryId() != null) { + // 有查询条件但无匹配结果时直接返回空列表 + if(resWorkerIds.isEmpty()) { + return getDataTable(resList); + } } startPage(); diff --git a/ghy-admin/src/main/java/com/ghy/web/pojo/vo/WorkerListRequest.java b/ghy-admin/src/main/java/com/ghy/web/pojo/vo/WorkerListRequest.java index 8412c934..e01262a0 100644 --- a/ghy-admin/src/main/java/com/ghy/web/pojo/vo/WorkerListRequest.java +++ b/ghy-admin/src/main/java/com/ghy/web/pojo/vo/WorkerListRequest.java @@ -29,4 +29,16 @@ public class WorkerListRequest extends BaseEntity { private boolean justShowCurWorkerArea; private String keyWords; + + private String provinceId; + + private String cityId; + + private String districtId; + + private String streetId; + + private String categoryLevel1; + + private String categoryLevel2; } diff --git a/ghy-admin/src/main/resources/templates/worker/worker.html b/ghy-admin/src/main/resources/templates/worker/worker.html index da772d05..89f2022b 100644 --- a/ghy-admin/src/main/resources/templates/worker/worker.html +++ b/ghy-admin/src/main/resources/templates/worker/worker.html @@ -35,6 +35,33 @@ - +
  • + 服务区域: + + + + +
  • +
  • + 服务技能: + + + +
  •  搜索  重置 @@ -87,6 +114,37 @@ $('#scroll-up').toTop(opt); } queryUserList(); + + // 初始化区域下拉框 + $.ajax({ + url: ctx + "system/area/list", + type: "post", + data: {levelType: 1}, // 查询levelType为1的省级区域 + success: function(data) { + console.log("区域数据:", data); // 添加日志查看返回的数据结构 + var html = ''; + // 检查data.data,因为可能返回的是AjaxResult格式 + var areaList = data.data || data; + $.each(areaList, function(i, item) { + html += ''; + }); + $("#provinceId").html(html); + } + }); + + // 初始化技能类别下拉框 + $.ajax({ + url: ctx + "goods/category/list", + type: "post", + data: {parentCategoryId: 1}, // 查询parentCategoryId为1的一级类目 + success: function(data) { + var html = ''; + $.each(data, function(i, item) { + html += ''; + }); + $("#categoryLevel1").html(html); + } + }); }); function queryUserList() { @@ -99,6 +157,39 @@ sortName: "createTime", sortOrder: "desc", modalName: "师傅", + queryParams: function(params) { + // 先获取默认的分页参数 + var defaultParams = { + pageSize: params.limit, + pageNum: params.offset / params.limit + 1, + searchValue: params.search, + orderByColumn: params.sort, + isAsc: params.order + }; + + // 获取表单参数 + var curParams = $.common.formToJSON("user-form"); + + // 处理区域ID,使用最后一个选中的非空区域值作为对应字段 + var streetId = $("#streetId").val(); + var districtId = $("#districtId").val(); + var cityId = $("#cityId").val(); + var provinceId = $("#provinceId").val(); + + if(streetId) { + curParams.streetId = streetId; // 使用streetId字段 + curParams.areaId = districtId; // 区县ID作为areaId + } else if(districtId) { + curParams.areaId = districtId; + } else if(cityId) { + curParams.areaId = cityId; + } else if(provinceId) { + curParams.areaId = provinceId; + } + + // 合并默认参数和自定义参数 + return $.extend(defaultParams, curParams); + }, columns: [{ checkbox: true }, @@ -204,6 +295,139 @@ $.operate.post(prefix + "/changeStatus", { "workerId": workerId, "status": 0 }); }) } + + // 区域联动处理 + function areaChange(obj, nextId) { + var parentCode = $(obj).val(); + if (parentCode) { + $.ajax({ + url: ctx + "system/area/list", + type: "post", + data: {parentCode: parentCode}, + success: function(data) { + console.log("下级区域数据:", data); + var html = ''; + var areaList = data.data || data; + $.each(areaList, function(i, item) { + html += ''; + }); + $("#" + nextId).html(html); + // 清空下级选项 + clearLowerLevels(nextId); + } + }); + } else { + $("#" + nextId).html(''); + // 清空下级选项 + clearLowerLevels(nextId); + } + } + + // 获取区域层级名称 + function getAreaLevelName(levelId) { + switch(levelId) { + case 'cityId': + return '所有城市'; + case 'districtId': + return '所有区县'; + case 'streetId': + return '所有街道'; + default: + return '所有'; + } + } + + // 清空下级选项 + function clearLowerLevels(currentId) { + var levels = ['cityId', 'districtId', 'streetId']; + var startClearing = false; + + for(var i = 0; i < levels.length; i++) { + if(startClearing) { + $("#" + levels[i]).html(''); + } + if(levels[i] === currentId) { + startClearing = true; + } + } + } + + // 类目联动处理 + function categoryChange(obj, nextId) { + var parentId = $(obj).val(); + if (parentId) { + $.ajax({ + url: ctx + "goods/category/list", + type: "post", + data: {parentCategoryId: parentId}, // 直接使用选中的ID作为父类目ID查询 + success: function(data) { + var html = ''; + $.each(data, function(i, item) { + html += ''; + }); + $("#" + nextId).html(html); + // 清空下级选项 + if(nextId === 'categoryLevel2') { + $("#categoryLevel3").html(''); + } + } + }); + } else { + $("#" + nextId).html(''); + if(nextId === 'categoryLevel2') { + $("#categoryLevel3").html(''); + } + } + } + + // 修改重置函数,确保重置时清空所有区域选择 + $.form.reset = function() { + var currentForm = document.getElementById("user-form"); + currentForm.reset(); + // 手动清空所有区域下拉框 + $("#provinceId").html(''); + $("#cityId").html(''); + $("#districtId").html(''); + $("#streetId").html(''); + // 手动清空所有类目下拉框 + $("#categoryLevel2").html(''); + $("#categoryLevel3").html(''); + // 重新加载一级数据 + loadInitialData(); + $.table.search(); + } + + // 添加初始数据加载函数 + function loadInitialData() { + // 加载省份数据 + $.ajax({ + url: ctx + "system/area/list", + type: "post", + data: {levelType: 1}, + success: function(data) { + var html = ''; + var areaList = data.data || data; + $.each(areaList, function(i, item) { + html += ''; + }); + $("#provinceId").html(html); + } + }); + + // 加载一级类目 + $.ajax({ + url: ctx + "goods/category/list", + type: "post", + data: {parentCategoryId: 1}, + success: function(data) { + var html = ''; + $.each(data, function(i, item) { + html += ''; + }); + $("#categoryLevel1").html(html); + } + }); + } @@ -216,7 +440,7 @@   下载模板 - 提示:仅允许导入“xls”或“xlsx”格式文件! + 提示:仅允许导入"xls"或"xlsx"格式文件! diff --git a/ghy-worker/src/main/resources/mapper/worker/WorkerAreaMapper.xml b/ghy-worker/src/main/resources/mapper/worker/WorkerAreaMapper.xml index 3650c76d..d23366ee 100644 --- a/ghy-worker/src/main/resources/mapper/worker/WorkerAreaMapper.xml +++ b/ghy-worker/src/main/resources/mapper/worker/WorkerAreaMapper.xml @@ -66,6 +66,15 @@ AND wa.district_id = #{districtId} + + AND wa.province_id = #{provinceId} + + + AND wa.city_id = #{cityId} + + + AND wa.street_id = #{streetId} + AND wa.city_id in