查询师傅接口原逻辑修改,并增加新的查询参数

This commit is contained in:
donqi 2022-12-28 23:31:09 +08:00
parent 0d43a7f274
commit 9f08f5943c
4 changed files with 93 additions and 41 deletions

View File

@ -14,6 +14,8 @@ import com.ghy.goods.domain.Goods;
import com.ghy.goods.domain.GoodsCategory;
import com.ghy.goods.service.GoodsCategoryService;
import com.ghy.goods.service.GoodsService;
import com.ghy.system.domain.SysArea;
import com.ghy.system.service.ISysAreaService;
import com.ghy.web.pojo.vo.WorkerListRequest;
import com.ghy.web.pojo.vo.WorkerListResponse;
import com.ghy.web.pojo.vo.WorkerSettledRequest;
@ -65,6 +67,9 @@ public class WorkerController extends BaseController {
@Autowired
private WorkerBankService workerBankService;
@Autowired
private ISysAreaService sysAreaService;
@RequiresPermissions("worker:worker:view")
@GetMapping()
public String worker(){
@ -170,20 +175,31 @@ public class WorkerController extends BaseController {
public TableDataInfo appList(@RequestBody WorkerListRequest workerListRequest)
{
List<WorkerListResponse> resList = new ArrayList<WorkerListResponse>();
// 查询参数
Worker worker = new Worker();
try {
// 查询满足区域条件的师傅区域记录
WorkerArea workerArea = new WorkerArea();
workerArea.setDistrictId(workerListRequest.getAreaId());
List<WorkerArea> workerAreaList = workerAreaService.getWorkerAreaList(workerArea);
List<Long> workerIdsByArea = workerAreaList.stream().map(WorkerArea::getWorkerId).collect(Collectors.toList());
worker.setDistrictId(workerListRequest.getAreaId());
// 查询需要排除的区
if (workerListRequest.getExceptParentAreaId() != null) {
SysArea areaParams = new SysArea();
areaParams.setParentCode(workerListRequest.getExceptParentAreaId().toString());
List<SysArea> exceptAreaList = sysAreaService.selectSysAreaList(areaParams);
List<Long> exceptAreaIds = exceptAreaList.stream().map(SysArea::getAreaId).collect(Collectors.toList());
worker.setExceptDistrictIds(exceptAreaIds);
}
// WorkerArea workerArea = new WorkerArea();
// workerArea.setDistrictId(workerListRequest.getAreaId());
// List<WorkerArea> workerAreaList = workerAreaService.getWorkerAreaList(workerArea);
// List<Long> workerIdsByArea = workerAreaList.stream().map(WorkerArea::getWorkerId).collect(Collectors.toList());
// 查询满足技能条件的师傅技能记录
WorkerGoodsCategory workerGoodsCategory = new WorkerGoodsCategory();
// WorkerGoodsCategory workerGoodsCategory = new WorkerGoodsCategory();
// 判断类目id是否为第三级不是的话需要找到所有符合条件的第三级类目id作为新的条件
if (workerListRequest.getGoodsCategoryId() != null) {
GoodsCategory goodsCategory = goodsCategoryService.selectById(workerListRequest.getGoodsCategoryId());
if (goodsCategory.getLevel() == 0) {
workerGoodsCategory.setGoodsCategoryId(null);
worker.setGoodsCategoryId(null);
} else if (goodsCategory.getLevel() == 1) {
GoodsCategory params = new GoodsCategory();
params.setParentCategoryId(goodsCategory.getGoodsCategoryId());
@ -195,32 +211,31 @@ public class WorkerController extends BaseController {
List<GoodsCategory> thirdCategories = goodsCategoryService.selectGoodsCategoryList(params);
thirdCategoryIds.addAll(thirdCategories.stream().map(GoodsCategory::getGoodsCategoryId).collect(Collectors.toList()));
});
workerGoodsCategory.setGoodsCategoryId(null);
workerGoodsCategory.setGoodsCategoryIds(thirdCategoryIds);
worker.setGoodsCategoryId(null);
worker.setGoodsCategoryIds(thirdCategoryIds);
} else if (goodsCategory.getLevel() == 2) {
GoodsCategory params = new GoodsCategory();
params.setParentCategoryId(goodsCategory.getGoodsCategoryId());
List<GoodsCategory> filteredCategory = goodsCategoryService.selectGoodsCategoryList(params);
List<Long> filteredCategoryIds = filteredCategory.stream().map(GoodsCategory::getGoodsCategoryId).collect(Collectors.toList());
workerGoodsCategory.setGoodsCategoryId(null);
workerGoodsCategory.setGoodsCategoryIds(filteredCategoryIds);
worker.setGoodsCategoryId(null);
worker.setGoodsCategoryIds(filteredCategoryIds);
} else {
workerGoodsCategory.setGoodsCategoryId(workerListRequest.getGoodsCategoryId());
worker.setGoodsCategoryId(workerListRequest.getGoodsCategoryId());
}
}
List<WorkerGoodsCategory> workerGoodsCategoryList = workerGoodsCategoryService.getWorkerGoodsCategory(workerGoodsCategory);
List<Long> workerIdsByCategory = workerGoodsCategoryList.stream().map(WorkerGoodsCategory::getWorkerId).collect(Collectors.toList());
// List<WorkerGoodsCategory> workerGoodsCategoryList = workerGoodsCategoryService.getWorkerGoodsCategory(workerGoodsCategory);
// List<Long> workerIdsByCategory = workerGoodsCategoryList.stream().map(WorkerGoodsCategory::getWorkerId).collect(Collectors.toList());
// 两个list中的workerid取交集
List<Long> resWorkerIds = new ArrayList<>(CollectionUtils.intersection(workerIdsByArea, workerIdsByCategory));
// List<Long> resWorkerIds = new ArrayList<>(CollectionUtils.intersection(workerIdsByArea, workerIdsByCategory));
if (CollectionUtils.isEmpty(resWorkerIds)) {
// 交集不存在的情况直接返回空list
return getDataTable(resList);
}
// if (CollectionUtils.isEmpty(resWorkerIds)) {
// // 交集不存在的情况直接返回空list
// return getDataTable(resList);
// }
startPage();
Worker worker = new Worker();
worker.setWorkerIds(CollectionUtils.isNotEmpty(resWorkerIds) ? resWorkerIds : null);
// worker.setWorkerIds(CollectionUtils.isNotEmpty(resWorkerIds) ? resWorkerIds : null);
worker.setName(workerListRequest.getWorkerName());
List<Worker> list = workerService.getWorkList(worker);
list.forEach(w -> {

View File

@ -16,4 +16,6 @@ public class WorkerListRequest {
private String workerName;
private Long workerId;
private Long exceptParentAreaId;
}

View File

@ -63,4 +63,14 @@ public class Worker extends BaseEntity {
private String registerCode;
private List<Long> workerIds;
private Long districtId;
private List<Long> exceptDistrictIds;
private Long goodsCategoryId;
private List<Long> goodsCategoryIds;
private Long exceptParentAreaId;
}

View File

@ -35,27 +35,52 @@
</sql>
<select id="getWorkerList" parameterType="com.ghy.worker.domain.Worker" resultMap="WorkerResult">
<include refid="selectWorker" />
<where>
<if test="openId != null and openId != ''">
AND open_id = #{openId}
</if>
<if test="workerIds != null and workerIds != ''">
AND w.worker_id IN
<foreach item="item" collection="workerIds" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="name != null and name != ''">
AND w.name LIKE '%${name}%'
</if>
<if test="phone != null and phone != ''">
AND w.phone = #{phone}
</if>
<if test="password != null and password != ''">
AND w.password = #{password}
</if>
</where>
<include refid="selectWorker" /> where w.worker_id in (
SELECT w.worker_id FROM worker w
LEFT JOIN worker_area wa ON wa.worker_id = w.worker_id
LEFT JOIN worker_goods_category wgc ON wgc.worker_id = w.worker_id
<where>
<if test="openId != null and openId != ''">
AND open_id = #{openId}
</if>
<if test="workerIds != null and workerIds != ''">
AND w.worker_id IN
<foreach item="item" collection="workerIds" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="name != null and name != ''">
AND w.name LIKE '%${name}%'
</if>
<if test="phone != null and phone != ''">
AND w.phone = #{phone}
</if>
<if test="password != null and password != ''">
AND w.password = #{password}
</if>
<if test="districtId != null">
AND wa.district_id = #{districtId}
</if>
<if test="exceptDistrictIds != null">
AND wa.district_id not in
<foreach collection="exceptDistrictIds" item="exceptDistrictId" open="(" separator="," close=")">
#{exceptDistrictId}
</foreach>
</if>
<if test="exceptParentAreaId != null">
AND sa.parent_code != #{exceptParentAreaId}
</if>
<if test="goodsCategoryId != null">
AND wgc.goods_category_id = #{goodsCategoryId}
</if>
<if test="goodsCategoryIds != null">
AND wgc.goods_category_id in
<foreach collection="goodsCategoryIds" item="goodsCategoryId" open="(" separator="," close=")">
#{goodsCategoryId}
</foreach>
</if>
</where>
)
</select>
<select id="selectById" parameterType="Long" resultMap="WorkerResult">