2024.4.15
node的增删改查
This commit is contained in:
@@ -14,7 +14,7 @@ public class NodeProvider {
|
|||||||
// System.out.println("condition:"+condition.toString());
|
// System.out.println("condition:"+condition.toString());
|
||||||
// 使用StringBuilder来拼接SQL
|
// 使用StringBuilder来拼接SQL
|
||||||
StringBuilder sb=new StringBuilder();
|
StringBuilder sb=new StringBuilder();
|
||||||
sb.append("select * from node where 1=1");
|
sb.append("select * from node where flag>=0");
|
||||||
|
|
||||||
//开如拼接查询条件
|
//开如拼接查询条件
|
||||||
if (condition.containsKey("nodename")){
|
if (condition.containsKey("nodename")){
|
||||||
@@ -39,7 +39,7 @@ public class NodeProvider {
|
|||||||
|
|
||||||
public String GetTotal(Map<String,Object> condition){
|
public String GetTotal(Map<String,Object> condition){
|
||||||
StringBuilder sb=new StringBuilder();
|
StringBuilder sb=new StringBuilder();
|
||||||
sb.append("select count(1) from node where 1=1");
|
sb.append("select count(1) from node where flag>=0");
|
||||||
|
|
||||||
//开如拼接查询条件
|
//开如拼接查询条件
|
||||||
if (condition.containsKey("nodename")){
|
if (condition.containsKey("nodename")){
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.hongliang.videotask.controller;
|
package com.hongliang.videotask.controller;
|
||||||
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckLogin;
|
import com.hongliang.videotask.bean.NodeBean;
|
||||||
import com.hongliang.videotask.common.Response;
|
import com.hongliang.videotask.common.Response;
|
||||||
import com.hongliang.videotask.common.ResponseCode;
|
import com.hongliang.videotask.common.ResponseCode;
|
||||||
import com.hongliang.videotask.service.impl.NodeServiceImpl;
|
import com.hongliang.videotask.service.impl.NodeServiceImpl;
|
||||||
@@ -23,4 +23,22 @@ public class NodeControl {
|
|||||||
return ResponseEntity.ok(new Response(ResponseCode.OK,"success",
|
return ResponseEntity.ok(new Response(ResponseCode.OK,"success",
|
||||||
this.nodeService.GetNodeListByCondition(condition)));
|
this.nodeService.GetNodeListByCondition(condition)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("add")
|
||||||
|
public ResponseEntity<?> InsertNode(@RequestBody NodeBean nodeBean){
|
||||||
|
this.nodeService.InsertNode(nodeBean);
|
||||||
|
return ResponseEntity.ok(new Response(ResponseCode.OK,"success",null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("edit")
|
||||||
|
public ResponseEntity<?> EditNode(@RequestBody NodeBean nodeBean){
|
||||||
|
this.nodeService.EditNode(nodeBean);
|
||||||
|
return ResponseEntity.ok(new Response(ResponseCode.OK,"success",null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("delete")
|
||||||
|
public ResponseEntity<?> DeleteNode(@RequestBody String ids){
|
||||||
|
this.nodeService.DeleteNode(ids);
|
||||||
|
return ResponseEntity.ok(new Response(ResponseCode.OK,"success",null));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,12 +19,20 @@ public interface NodeMapper {
|
|||||||
@SelectProvider(type=NodeProvider.class,method="GetTotal")
|
@SelectProvider(type=NodeProvider.class,method="GetTotal")
|
||||||
int GetTotal(Map<String,Object> condition);
|
int GetTotal(Map<String,Object> condition);
|
||||||
|
|
||||||
@Insert("insert into node (nodename) values (#nodename)")
|
@Insert("insert into node (nodename) values (#{nodename})")
|
||||||
@Options(useGeneratedKeys = true, keyProperty = "id")
|
@Options(useGeneratedKeys = true, keyProperty = "id")
|
||||||
int InsertNode(NodeBean nodeBean);
|
int InsertNode(NodeBean nodeBean);
|
||||||
|
|
||||||
@Update("update node set nodename=#{#nodename} where id=#{id}")
|
@Update("update node set nodename=#{nodename} where id=#{id}")
|
||||||
int UpdateNode(NodeBean nodeBean);
|
int EditNode(NodeBean nodeBean);
|
||||||
|
|
||||||
|
@Update({"<script>",
|
||||||
|
"update node set flag=-1 where id in ",
|
||||||
|
"<foreach collection=\"list\" item=\"id\" index=\"index\" open=\"(\" separator=\",\" close=\")\">",
|
||||||
|
"#{id}",
|
||||||
|
"</foreach>",
|
||||||
|
"</script>"})
|
||||||
|
int DeleteNode(List<Integer> list);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
package com.hongliang.videotask.service;
|
package com.hongliang.videotask.service;
|
||||||
|
|
||||||
|
import com.hongliang.videotask.bean.NodeBean;
|
||||||
import com.hongliang.videotask.bean.PageResultBean;
|
import com.hongliang.videotask.bean.PageResultBean;
|
||||||
|
|
||||||
public interface NodeService {
|
public interface NodeService {
|
||||||
PageResultBean GetNodeListByCondition(String condition);
|
PageResultBean GetNodeListByCondition(String condition);
|
||||||
int GetTotal(String condition);
|
int GetTotal(String condition);
|
||||||
|
int InsertNode(NodeBean nodeBean);
|
||||||
|
int EditNode(NodeBean nodeBean);
|
||||||
|
int DeleteNode(String ids);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package com.hongliang.videotask.service.impl;
|
package com.hongliang.videotask.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.hongliang.videotask.bean.NodeBean;
|
import com.hongliang.videotask.bean.NodeBean;
|
||||||
import com.hongliang.videotask.bean.PageResultBean;
|
import com.hongliang.videotask.bean.PageResultBean;
|
||||||
import com.hongliang.videotask.mappers.NodeMapper;
|
import com.hongliang.videotask.mappers.NodeMapper;
|
||||||
@@ -8,6 +11,8 @@ import com.hongliang.videotask.utils.CommonFuction;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -31,4 +36,19 @@ public class NodeServiceImpl implements NodeService {
|
|||||||
Map<String,Object> map= CommonFuction.JsonStringToMapWithOffset(condition);
|
Map<String,Object> map= CommonFuction.JsonStringToMapWithOffset(condition);
|
||||||
return this.nodeMapper.GetTotal(map);
|
return this.nodeMapper.GetTotal(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int InsertNode(NodeBean nodeBean){
|
||||||
|
return nodeMapper.InsertNode(nodeBean);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int EditNode(NodeBean nodeBean){
|
||||||
|
return nodeMapper.EditNode(nodeBean);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int DeleteNode(String ids){
|
||||||
|
JSONObject jsonObject=JSON.parseObject(ids);
|
||||||
|
JSONArray array=jsonObject.getJSONArray(("id"));
|
||||||
|
List<Integer> list=JSONArray.parseArray(array.toString(),Integer.class);
|
||||||
|
return nodeMapper.DeleteNode(list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ public class CommonFuction {
|
|||||||
int pagenum=Integer.parseInt( map.get("pageNum").toString());
|
int pagenum=Integer.parseInt( map.get("pageNum").toString());
|
||||||
int pagesize=Integer.parseInt(map.get("pageSize").toString());
|
int pagesize=Integer.parseInt(map.get("pageSize").toString());
|
||||||
map.put("offset",(pagenum-1)*pagesize);
|
map.put("offset",(pagenum-1)*pagesize);
|
||||||
// System.out.println("service condition:"+map.toString());
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user