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

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

View File

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

View File

@ -63,4 +63,14 @@ public class Worker extends BaseEntity {
private String registerCode; private String registerCode;
private List<Long> workerIds; 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> </sql>
<select id="getWorkerList" parameterType="com.ghy.worker.domain.Worker" resultMap="WorkerResult"> <select id="getWorkerList" parameterType="com.ghy.worker.domain.Worker" resultMap="WorkerResult">
<include refid="selectWorker" /> <include refid="selectWorker" /> where w.worker_id in (
<where> SELECT w.worker_id FROM worker w
<if test="openId != null and openId != ''"> LEFT JOIN worker_area wa ON wa.worker_id = w.worker_id
AND open_id = #{openId} LEFT JOIN worker_goods_category wgc ON wgc.worker_id = w.worker_id
</if> <where>
<if test="workerIds != null and workerIds != ''"> <if test="openId != null and openId != ''">
AND w.worker_id IN AND open_id = #{openId}
<foreach item="item" collection="workerIds" open="(" separator="," close=")"> </if>
#{item} <if test="workerIds != null and workerIds != ''">
</foreach> AND w.worker_id IN
</if> <foreach item="item" collection="workerIds" open="(" separator="," close=")">
<if test="name != null and name != ''"> #{item}
AND w.name LIKE '%${name}%' </foreach>
</if> </if>
<if test="phone != null and phone != ''"> <if test="name != null and name != ''">
AND w.phone = #{phone} AND w.name LIKE '%${name}%'
</if> </if>
<if test="password != null and password != ''"> <if test="phone != null and phone != ''">
AND w.password = #{password} AND w.phone = #{phone}
</if> </if>
</where> <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>
<select id="selectById" parameterType="Long" resultMap="WorkerResult"> <select id="selectById" parameterType="Long" resultMap="WorkerResult">