查询分类接口
This commit is contained in:
parent
5435a970ea
commit
2784b050f3
44
src/main/java/iet/ustb/sf/controller/CategoryController.java
Normal file
44
src/main/java/iet/ustb/sf/controller/CategoryController.java
Normal file
@ -0,0 +1,44 @@
|
||||
package iet.ustb.sf.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import iet.ustb.sf.common.R;
|
||||
import iet.ustb.sf.domain.Category;
|
||||
import iet.ustb.sf.service.CategoryService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 目标管控-分类
|
||||
* CategoryController
|
||||
*
|
||||
* @author huangge1199
|
||||
* @since 2025/8/5 15:22:51
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/mbgk/category")
|
||||
@Tag(name = "目标管控-分类")
|
||||
public class CategoryController {
|
||||
|
||||
@Resource
|
||||
private CategoryService categoryService;
|
||||
|
||||
/**
|
||||
* 查询分类
|
||||
* @param params 分类参数
|
||||
* @return 结果
|
||||
*/
|
||||
@Operation(summary = "查询分类")
|
||||
@PostMapping("/showCategory")
|
||||
public R<List<Category>> showCategory(@RequestBody JSONObject params) {
|
||||
Category category = params.getObject("category", Category.class);
|
||||
List<Category> result = categoryService.showCategory(category);
|
||||
return R.ok(result);
|
||||
}
|
||||
}
|
@ -88,7 +88,7 @@ public class TargetData {
|
||||
}
|
||||
TargetData other = (TargetData) that;
|
||||
return (this.getTargetId() == null ? other.getTargetId() == null : this.getTargetId().equals(other.getTargetId()))
|
||||
&& (this.getxShow() == null ? other.getxShow() == null : this.getxShow().equals(other.getxShow()))
|
||||
&& (this.getXShow() == null ? other.getXShow() == null : this.getXShow().equals(other.getXShow()))
|
||||
&& (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
|
||||
&& (this.getSetDate() == null ? other.getSetDate() == null : this.getSetDate().equals(other.getSetDate()))
|
||||
&& (this.getCycle() == null ? other.getCycle() == null : this.getCycle().equals(other.getCycle()))
|
||||
@ -103,7 +103,7 @@ public class TargetData {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((getTargetId() == null) ? 0 : getTargetId().hashCode());
|
||||
result = prime * result + ((getxShow() == null) ? 0 : getxShow().hashCode());
|
||||
result = prime * result + ((getXShow() == null) ? 0 : getXShow().hashCode());
|
||||
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
|
||||
result = prime * result + ((getSetDate() == null) ? 0 : getSetDate().hashCode());
|
||||
result = prime * result + ((getCycle() == null) ? 0 : getCycle().hashCode());
|
||||
|
@ -2,6 +2,9 @@ package iet.ustb.sf.mapper;
|
||||
|
||||
import iet.ustb.sf.domain.Target;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author hyy
|
||||
@ -11,6 +14,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
*/
|
||||
public interface TargetMapper extends BaseMapper<Target> {
|
||||
|
||||
@Select("select distinct mbgk_target.topic from mbgk_target where organization = #{organization}")
|
||||
List<String> getTopicsByOrganization(String organization);
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,4 +11,6 @@ import java.util.List;
|
||||
* @createDate 2025-08-05 15:22:02
|
||||
*/
|
||||
public interface CategoryService extends IService<Category> {
|
||||
|
||||
List<Category> showCategory(Category category);
|
||||
}
|
||||
|
@ -5,12 +5,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import iet.ustb.sf.domain.Category;
|
||||
import iet.ustb.sf.exception.ErrorCode;
|
||||
import iet.ustb.sf.exception.ThrowUtils;
|
||||
import iet.ustb.sf.mapper.TargetMapper;
|
||||
import iet.ustb.sf.service.CategoryService;
|
||||
import iet.ustb.sf.mapper.CategoryMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -21,6 +23,44 @@ import java.util.List;
|
||||
@Service
|
||||
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category>
|
||||
implements CategoryService {
|
||||
|
||||
@Resource
|
||||
private CategoryMapper categoryMapper;
|
||||
|
||||
@Resource
|
||||
private TargetMapper targetMapper;
|
||||
|
||||
@Override
|
||||
public List<Category> showCategory(Category category) {
|
||||
boolean bl = StringUtils.isEmpty(category.getTopic()) && StringUtils.isEmpty(category.getOrganization());
|
||||
ThrowUtils.throwIf(bl, ErrorCode.PARAMS_ERROR, "主题和组织必须传入一个!");
|
||||
|
||||
QueryWrapper<Category> queryWrapper = new QueryWrapper<>();
|
||||
if (!StringUtils.isEmpty(category.getOrganization())) {
|
||||
queryWrapper.like("organization", category.getOrganization());
|
||||
}
|
||||
List<Category> categoryList = new ArrayList<>();
|
||||
if (StringUtils.isEmpty(category.getTopic())) {
|
||||
List<String> topicList = targetMapper.getTopicsByOrganization(category.getOrganization());
|
||||
for (String topic : topicList) {
|
||||
Category tmp = Category.builder().organization(category.getOrganization()).topic(topic).build();
|
||||
categoryList.add(tmp);
|
||||
}
|
||||
return categoryList;
|
||||
} else {
|
||||
queryWrapper.eq("topic", category.getTopic());
|
||||
}
|
||||
if (StringUtils.isEmpty(category.getParentId())) {
|
||||
queryWrapper.isNull("parent_id");
|
||||
} else {
|
||||
queryWrapper.eq("parent_id", category.getParentId());
|
||||
}
|
||||
categoryList = categoryMapper.selectList(queryWrapper);
|
||||
for (Category tmp : categoryList) {
|
||||
tmp.setOrganization(category.getOrganization());
|
||||
}
|
||||
return categoryList;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user