行业分类列表获取接口增加parentid参数

This commit is contained in:
sunflower2014 2025-05-27 22:30:13 +08:00
parent 9555c55cfb
commit 7a844be077
3 changed files with 15 additions and 5 deletions

View File

@ -94,6 +94,7 @@ public class IndustryController {
*/ */
@GetMapping @GetMapping
public PageObject<IndustryVO> queryIndustry(@RequestHeader("auth-token") String token, public PageObject<IndustryVO> queryIndustry(@RequestHeader("auth-token") String token,
@RequestParam(value = "parentId", required = false, defaultValue = "-1") long parentId,
@RequestParam(value = "keyword", required = false) String keyword, @RequestParam(value = "keyword", required = false) String keyword,
@RequestParam(value = "page", required = false, defaultValue = "1") int page, @RequestParam(value = "page", required = false, defaultValue = "1") int page,
@RequestParam(value = "size", required = false, defaultValue = "10") int size, @RequestParam(value = "size", required = false, defaultValue = "10") int size,
@ -123,7 +124,7 @@ public class IndustryController {
return PageObject.failedPage(500, "服务端错误,请联系系统管理员!"); return PageObject.failedPage(500, "服务端错误,请联系系统管理员!");
} }
return industryService.queryIndustry(keyword, page, size, orderBy, direction); return industryService.queryIndustry(parentId, keyword, page, size, orderBy, direction);
} }
} }

View File

@ -69,8 +69,11 @@ public interface IndustryMapper {
@Select("<script>" + @Select("<script>" +
"select * from industry" + "select * from industry" +
"<where>" + "<where>" +
"<if test=\"parentId != null\">" +
"parent_id = #{parentId} " +
"</if>" +
"<if test=\"keyword != null and !keyword.isEmpty()\">" + "<if test=\"keyword != null and !keyword.isEmpty()\">" +
"primay_name like concat('%', #{keyword}, '%') or secondary_name like concat('%', #{keyword}, '%') " + "and primay_name like concat('%', #{keyword}, '%') or secondary_name like concat('%', #{keyword}, '%') " +
"</if>" + "</if>" +
"</where>" + "</where>" +
"order by tag.${orderBy} " + "order by tag.${orderBy} " +
@ -78,5 +81,5 @@ public interface IndustryMapper {
"desc" + "desc" +
"</if>" + "</if>" +
"</script>") "</script>")
List<Industry> queryIndustry(@Param("keyword") String keyword, @Param("orderBy") String orderBy, @Param("direction") String direction); List<Industry> queryIndustry(@Param("parentId") Long parentId, @Param("keyword") String keyword, @Param("orderBy") String orderBy, @Param("direction") String direction);
} }

View File

@ -72,7 +72,7 @@ public class IndustryService {
* @param size 分页参数 当前页长度 默认10条 * @param size 分页参数 当前页长度 默认10条
* @return 标签搜索结果 * @return 标签搜索结果
*/ */
public PageObject<IndustryVO> queryIndustry(String keyword,int page, int size, String orderBy, String direction) { public PageObject<IndustryVO> queryIndustry(long parentId, String keyword,int page, int size, String orderBy, String direction) {
if (StringUtils.hasText(orderBy)) { if (StringUtils.hasText(orderBy)) {
switch (orderBy) { switch (orderBy) {
case "updateTime": { case "updateTime": {
@ -88,7 +88,13 @@ public class IndustryService {
List<Industry> industrys; List<Industry> industrys;
try { try {
industrys = industryMapper.queryIndustry(keyword, orderBy, direction); if (parentId == -1) {
industrys = industryMapper.queryIndustry(null, keyword, orderBy, direction);
} else {
industrys = industryMapper.queryIndustry(parentId, keyword, orderBy, direction);
}
} catch (Exception e) { } catch (Exception e) {
log.error("搜索行业分类出错!", e); log.error("搜索行业分类出错!", e);
return PageObject.failedPage(500, "服务端错误,请联系系统管理员!"); return PageObject.failedPage(500, "服务端错误,请联系系统管理员!");