Commit 8e076c1e authored by 黎博's avatar 黎博

修改获取场景列表接口

parent 768cca8f
...@@ -29,24 +29,18 @@ public class SceneController { ...@@ -29,24 +29,18 @@ public class SceneController {
AutoProjectService autoProjectService; AutoProjectService autoProjectService;
/** /**
* 获取场景列表 * @param projectId 项目id
* @param sceneName 场景名称
* @param pageNum 第几页 * @param pageNum 第几页
* @param pageSize 每页多少个 * @param pageSize 每页多少个
* @return * @return
*/ */
@GetMapping("/list") @GetMapping("/list")
public JsonResult getSceneList(Integer projectId, public JsonResult getSceneList(Integer projectId,
String sceneName,
@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) { @RequestParam(defaultValue = "10") Integer pageSize) {
IPage<Scene> page = new Page<>(pageNum, pageSize); IPage<Scene> sceneIPage = sceneService.getSceneList(projectId, sceneName, pageNum, pageSize);
IPage<Scene> sceneIPage;
if (projectId == null) {
sceneIPage = sceneService.page(page);
} else {
QueryWrapper<Scene> sceneQueryWrapper = new QueryWrapper<>();
sceneQueryWrapper.eq("project_id", projectId);
sceneIPage = sceneService.page(page, sceneQueryWrapper);
}
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("list", sceneIPage.getRecords()); map.put("list", sceneIPage.getRecords());
map.put("total", sceneIPage.getTotal()); map.put("total", sceneIPage.getTotal());
......
package cn.qg.holmes.entity.auto; package cn.qg.holmes.entity.auto;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
...@@ -23,4 +24,6 @@ public class Scene { ...@@ -23,4 +24,6 @@ public class Scene {
private Date createTime; private Date createTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime; private Date updateTime;
@TableField(exist = false)
private String projectName;
} }
...@@ -2,6 +2,8 @@ package cn.qg.holmes.mapper.auto; ...@@ -2,6 +2,8 @@ package cn.qg.holmes.mapper.auto;
import cn.qg.holmes.entity.auto.Scene; import cn.qg.holmes.entity.auto.Scene;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
public interface SceneMapper extends BaseMapper<Scene> { public interface SceneMapper extends BaseMapper<Scene> {
IPage<Scene> getSceneList(IPage<Scene> page, Integer projectId, String sceneName);
} }
package cn.qg.holmes.service.auto; package cn.qg.holmes.service.auto;
import cn.qg.holmes.entity.auto.Scene; import cn.qg.holmes.entity.auto.Scene;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
public interface SceneService extends IService<Scene> { public interface SceneService extends IService<Scene> {
IPage<Scene> getSceneList(Integer projectId, String sceneName, Integer pageNum, Integer pageSize);
} }
...@@ -3,10 +3,21 @@ package cn.qg.holmes.service.auto.impl; ...@@ -3,10 +3,21 @@ package cn.qg.holmes.service.auto.impl;
import cn.qg.holmes.entity.auto.Scene; import cn.qg.holmes.entity.auto.Scene;
import cn.qg.holmes.mapper.auto.SceneMapper; import cn.qg.holmes.mapper.auto.SceneMapper;
import cn.qg.holmes.service.auto.SceneService; import cn.qg.holmes.service.auto.SceneService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
public class SceneServiceImpl extends ServiceImpl<SceneMapper, Scene> implements SceneService { public class SceneServiceImpl extends ServiceImpl<SceneMapper, Scene> implements SceneService {
@Autowired
SceneMapper sceneMapper;
@Override
public IPage<Scene> getSceneList(Integer projectId, String sceneName, Integer pageNum, Integer pageSize) {
IPage<Scene> page = new Page<>(pageNum, pageSize);
return sceneMapper.getSceneList(page, projectId, sceneName);
}
} }
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.qg.holmes.mapper.auto.SceneMapper">
<select id="getSceneList" resultType="cn.qg.holmes.entity.auto.Scene">
SELECT sc.*, ap.name as projectName
FROM `scene` as sc
INNER JOIN `auto_project` as ap
ON sc.`project_id` = ap.`id`
WHERE 1=1
<if test="projectId != null and projectId != ''">
AND sc.`project_id` = #{projectId}
</if>
<if test="sceneName != null and sceneName !=''">
AND sc.`name` like CONCAT('%', #{sceneName}, '%')
</if>
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment