师傅列表支持区域和类目筛选
This commit is contained in:
parent
8a8cd9353b
commit
67f8738c5e
|
|
@ -133,33 +133,85 @@ public class WorkerController extends BaseController {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 查询满足区域条件的师傅区域记录
|
// 查询满足区域条件的师傅区域记录
|
||||||
List<Long> workerIdsByArea;
|
List<Long> workerIdsByArea = new ArrayList<>();
|
||||||
if(workerListRequest.getAreaId() != null){
|
if(workerListRequest.getAreaId() != null){
|
||||||
WorkerArea workerArea = new WorkerArea();
|
WorkerArea workerArea = new WorkerArea();
|
||||||
workerArea.setDistrictId(workerListRequest.getAreaId());
|
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<WorkerArea> workerAreaList = workerAreaService.getWorkerAreaList(workerArea);
|
List<WorkerArea> workerAreaList = workerAreaService.getWorkerAreaList(workerArea);
|
||||||
workerIdsByArea = workerAreaList.stream().map(WorkerArea::getWorkerId).collect(Collectors.toList());
|
workerIdsByArea = workerAreaList.stream()
|
||||||
}else {
|
.map(WorkerArea::getWorkerId)
|
||||||
workerIdsByArea = new ArrayList<>();
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询满足技能条件的师傅技能记录
|
// 查询满足技能条件的师傅技能记录
|
||||||
List<Long> workerIdsByCategory;
|
List<Long> workerIdsByCategory = new ArrayList<>();
|
||||||
if(workerListRequest.getGoodsCategoryId() != null){
|
if(workerListRequest.getGoodsCategoryId() != null){
|
||||||
WorkerGoodsCategory workerGoodsCategory = new WorkerGoodsCategory();
|
WorkerGoodsCategory workerGoodsCategory = new WorkerGoodsCategory();
|
||||||
workerGoodsCategory.setGoodsCategoryId(workerListRequest.getGoodsCategoryId());
|
workerGoodsCategory.setGoodsCategoryId(workerListRequest.getGoodsCategoryId());
|
||||||
|
// 如果选择了上级类目但未选择最终类目,则查询该类目下所有子类目
|
||||||
|
if(StringUtils.isNotEmpty(workerListRequest.getCategoryLevel1())
|
||||||
|
&& workerListRequest.getGoodsCategoryId() == null) {
|
||||||
|
GoodsCategory param = new GoodsCategory();
|
||||||
|
param.setParentCategoryId(Long.valueOf(workerListRequest.getCategoryLevel1()));
|
||||||
|
List<GoodsCategory> subCategories = goodsCategoryService.selectGoodsCategoryList(param);
|
||||||
|
List<String> 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<GoodsCategory> subCategories = goodsCategoryService.selectGoodsCategoryList(param);
|
||||||
|
List<String> categoryIds = subCategories.stream()
|
||||||
|
.map(x->x.getGoodsCategoryId().toString())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
workerGoodsCategory.setCategoryIds(categoryIds);
|
||||||
|
}
|
||||||
List<WorkerGoodsCategory> workerGoodsCategoryList = workerGoodsCategoryService.getWorkerGoodsCategory(workerGoodsCategory);
|
List<WorkerGoodsCategory> workerGoodsCategoryList = workerGoodsCategoryService.getWorkerGoodsCategory(workerGoodsCategory);
|
||||||
workerIdsByCategory = workerGoodsCategoryList.stream().map(WorkerGoodsCategory::getWorkerId).collect(Collectors.toList());
|
workerIdsByCategory = workerGoodsCategoryList.stream()
|
||||||
}else {
|
.map(WorkerGoodsCategory::getWorkerId)
|
||||||
workerIdsByCategory = new ArrayList<>();
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 两个list中的workerid取交集
|
// 两个list中的workerid取交集
|
||||||
List<Long> resWorkerIds = new ArrayList<>(CollectionUtils.intersection(workerIdsByArea, workerIdsByCategory));
|
List<Long> resWorkerIds = new ArrayList<>();
|
||||||
if (CollectionUtils.isEmpty(resWorkerIds) && (workerListRequest.getAreaId() != null || workerListRequest.getGoodsCategoryId()!=null)) {
|
if(!workerIdsByArea.isEmpty() && !workerIdsByCategory.isEmpty()) {
|
||||||
// 交集不存在的情况直接返回空list
|
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);
|
return getDataTable(resList);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
startPage();
|
startPage();
|
||||||
Worker worker = new Worker();
|
Worker worker = new Worker();
|
||||||
|
|
|
||||||
|
|
@ -29,4 +29,16 @@ public class WorkerListRequest extends BaseEntity {
|
||||||
private boolean justShowCurWorkerArea;
|
private boolean justShowCurWorkerArea;
|
||||||
|
|
||||||
private String keyWords;
|
private String keyWords;
|
||||||
|
|
||||||
|
private String provinceId;
|
||||||
|
|
||||||
|
private String cityId;
|
||||||
|
|
||||||
|
private String districtId;
|
||||||
|
|
||||||
|
private String streetId;
|
||||||
|
|
||||||
|
private String categoryLevel1;
|
||||||
|
|
||||||
|
private String categoryLevel2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,33 @@
|
||||||
<span>-</span>
|
<span>-</span>
|
||||||
<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
|
<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
服务区域:
|
||||||
|
<select name="provinceId" id="provinceId" onchange="areaChange(this, 'cityId')">
|
||||||
|
<option value="">所有省份</option>
|
||||||
|
</select>
|
||||||
|
<select name="cityId" id="cityId" onchange="areaChange(this, 'districtId')">
|
||||||
|
<option value="">所有城市</option>
|
||||||
|
</select>
|
||||||
|
<select name="districtId" id="districtId" onchange="areaChange(this, 'streetId')">
|
||||||
|
<option value="">所有区县</option>
|
||||||
|
</select>
|
||||||
|
<select name="streetId" id="streetId">
|
||||||
|
<option value="">所有街道</option>
|
||||||
|
</select>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
服务技能:
|
||||||
|
<select name="categoryLevel1" id="categoryLevel1" onchange="categoryChange(this, 'categoryLevel2')">
|
||||||
|
<option value="">所有类目</option>
|
||||||
|
</select>
|
||||||
|
<select name="categoryLevel2" id="categoryLevel2" onchange="categoryChange(this, 'categoryLevel3')">
|
||||||
|
<option value="">二级类目</option>
|
||||||
|
</select>
|
||||||
|
<select name="goodsCategoryId" id="categoryLevel3">
|
||||||
|
<option value="">三级类目</option>
|
||||||
|
</select>
|
||||||
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i> 搜索</a>
|
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i> 搜索</a>
|
||||||
<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i> 重置</a>
|
<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i> 重置</a>
|
||||||
|
|
@ -87,6 +114,37 @@
|
||||||
$('#scroll-up').toTop(opt);
|
$('#scroll-up').toTop(opt);
|
||||||
}
|
}
|
||||||
queryUserList();
|
queryUserList();
|
||||||
|
|
||||||
|
// 初始化区域下拉框
|
||||||
|
$.ajax({
|
||||||
|
url: ctx + "system/area/list",
|
||||||
|
type: "post",
|
||||||
|
data: {levelType: 1}, // 查询levelType为1的省级区域
|
||||||
|
success: function(data) {
|
||||||
|
console.log("区域数据:", data); // 添加日志查看返回的数据结构
|
||||||
|
var html = '<option value="">所有省份</option>';
|
||||||
|
// 检查data.data,因为可能返回的是AjaxResult格式
|
||||||
|
var areaList = data.data || data;
|
||||||
|
$.each(areaList, function(i, item) {
|
||||||
|
html += '<option value="' + item.areaCode + '">' + item.areaName + '</option>';
|
||||||
|
});
|
||||||
|
$("#provinceId").html(html);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 初始化技能类别下拉框
|
||||||
|
$.ajax({
|
||||||
|
url: ctx + "goods/category/list",
|
||||||
|
type: "post",
|
||||||
|
data: {parentCategoryId: 1}, // 查询parentCategoryId为1的一级类目
|
||||||
|
success: function(data) {
|
||||||
|
var html = '<option value="">所有类目</option>';
|
||||||
|
$.each(data, function(i, item) {
|
||||||
|
html += '<option value="' + item.goodsCategoryId + '">' + item.goodsCategoryName + '</option>';
|
||||||
|
});
|
||||||
|
$("#categoryLevel1").html(html);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function queryUserList() {
|
function queryUserList() {
|
||||||
|
|
@ -99,6 +157,39 @@
|
||||||
sortName: "createTime",
|
sortName: "createTime",
|
||||||
sortOrder: "desc",
|
sortOrder: "desc",
|
||||||
modalName: "师傅",
|
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: [{
|
columns: [{
|
||||||
checkbox: true
|
checkbox: true
|
||||||
},
|
},
|
||||||
|
|
@ -204,6 +295,139 @@
|
||||||
$.operate.post(prefix + "/changeStatus", { "workerId": workerId, "status": 0 });
|
$.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 = '<option value="">' + getAreaLevelName(nextId) + '</option>';
|
||||||
|
var areaList = data.data || data;
|
||||||
|
$.each(areaList, function(i, item) {
|
||||||
|
html += '<option value="' + item.areaCode + '">' + item.areaName + '</option>';
|
||||||
|
});
|
||||||
|
$("#" + nextId).html(html);
|
||||||
|
// 清空下级选项
|
||||||
|
clearLowerLevels(nextId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$("#" + nextId).html('<option value="">' + getAreaLevelName(nextId) + '</option>');
|
||||||
|
// 清空下级选项
|
||||||
|
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('<option value="">' + getAreaLevelName(levels[i]) + '</option>');
|
||||||
|
}
|
||||||
|
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 = '<option value="">' + (nextId === 'categoryLevel2' ? '所有二级类目' : '所有三级类目') + '</option>';
|
||||||
|
$.each(data, function(i, item) {
|
||||||
|
html += '<option value="' + item.goodsCategoryId + '">' + item.goodsCategoryName + '</option>';
|
||||||
|
});
|
||||||
|
$("#" + nextId).html(html);
|
||||||
|
// 清空下级选项
|
||||||
|
if(nextId === 'categoryLevel2') {
|
||||||
|
$("#categoryLevel3").html('<option value="">所有三级类目</option>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$("#" + nextId).html('<option value="">' + (nextId === 'categoryLevel2' ? '所有二级类目' : '所有三级类目') + '</option>');
|
||||||
|
if(nextId === 'categoryLevel2') {
|
||||||
|
$("#categoryLevel3").html('<option value="">所有三级类目</option>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改重置函数,确保重置时清空所有区域选择
|
||||||
|
$.form.reset = function() {
|
||||||
|
var currentForm = document.getElementById("user-form");
|
||||||
|
currentForm.reset();
|
||||||
|
// 手动清空所有区域下拉框
|
||||||
|
$("#provinceId").html('<option value="">所有省份</option>');
|
||||||
|
$("#cityId").html('<option value="">所有城市</option>');
|
||||||
|
$("#districtId").html('<option value="">所有区县</option>');
|
||||||
|
$("#streetId").html('<option value="">所有街道</option>');
|
||||||
|
// 手动清空所有类目下拉框
|
||||||
|
$("#categoryLevel2").html('<option value="">二级类目</option>');
|
||||||
|
$("#categoryLevel3").html('<option value="">三级类目</option>');
|
||||||
|
// 重新加载一级数据
|
||||||
|
loadInitialData();
|
||||||
|
$.table.search();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加初始数据加载函数
|
||||||
|
function loadInitialData() {
|
||||||
|
// 加载省份数据
|
||||||
|
$.ajax({
|
||||||
|
url: ctx + "system/area/list",
|
||||||
|
type: "post",
|
||||||
|
data: {levelType: 1},
|
||||||
|
success: function(data) {
|
||||||
|
var html = '<option value="">所有省份</option>';
|
||||||
|
var areaList = data.data || data;
|
||||||
|
$.each(areaList, function(i, item) {
|
||||||
|
html += '<option value="' + item.areaCode + '">' + item.areaName + '</option>';
|
||||||
|
});
|
||||||
|
$("#provinceId").html(html);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 加载一级类目
|
||||||
|
$.ajax({
|
||||||
|
url: ctx + "goods/category/list",
|
||||||
|
type: "post",
|
||||||
|
data: {parentCategoryId: 1},
|
||||||
|
success: function(data) {
|
||||||
|
var html = '<option value="">所有类目</option>';
|
||||||
|
$.each(data, function(i, item) {
|
||||||
|
html += '<option value="' + item.goodsCategoryId + '">' + item.goodsCategoryName + '</option>';
|
||||||
|
});
|
||||||
|
$("#categoryLevel1").html(html);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
<!-- 导入区域 -->
|
<!-- 导入区域 -->
|
||||||
|
|
@ -216,7 +440,7 @@
|
||||||
<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
|
<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
|
||||||
</div>
|
</div>
|
||||||
<font color="red" class="pull-left mt10">
|
<font color="red" class="pull-left mt10">
|
||||||
提示:仅允许导入“xls”或“xlsx”格式文件!
|
提示:仅允许导入"xls"或"xlsx"格式文件!
|
||||||
</font>
|
</font>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,15 @@
|
||||||
<if test="districtId != null">
|
<if test="districtId != null">
|
||||||
AND wa.district_id = #{districtId}
|
AND wa.district_id = #{districtId}
|
||||||
</if>
|
</if>
|
||||||
|
<if test="provinceId != null">
|
||||||
|
AND wa.province_id = #{provinceId}
|
||||||
|
</if>
|
||||||
|
<if test="cityId != null">
|
||||||
|
AND wa.city_id = #{cityId}
|
||||||
|
</if>
|
||||||
|
<if test="streetId != null">
|
||||||
|
AND wa.street_id = #{streetId}
|
||||||
|
</if>
|
||||||
<if test="cityIds != null and cityIds.size > 0">
|
<if test="cityIds != null and cityIds.size > 0">
|
||||||
AND wa.city_id in
|
AND wa.city_id in
|
||||||
<foreach collection="cityIds" item="cityId" open="(" separator="," close=")">
|
<foreach collection="cityIds" item="cityId" open="(" separator="," close=")">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue