Skip to content

Commit

Permalink
增加了 添加节点 的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
miansen committed Jun 23, 2019
1 parent eb56b06 commit bb1d27e
Show file tree
Hide file tree
Showing 20 changed files with 691 additions and 256 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
import cn.roothub.bbs.core.base.PageDataBody;
import cn.roothub.bbs.core.base.Result;
import cn.roothub.bbs.module.node.model.Node;
import cn.roothub.bbs.core.exception.ApiAssert;
import cn.roothub.bbs.module.node.service.NodeService;

import java.util.Date;

/**
* <p></p>
* @author: miansen.wang
Expand All @@ -26,7 +25,14 @@ public class NodeAdminController {

@Autowired
private NodeService nodeService;


/**
* 节点列表页
* @param nodeTitle
* @param p
* @param model
* @return
*/
@RequiresPermissions("node:list")
@RequestMapping(value = "/list",method = RequestMethod.GET)
public String list(@RequestParam(value = "nodeTitle",required = false) String nodeTitle,
Expand All @@ -38,15 +44,30 @@ public String list(@RequestParam(value = "nodeTitle",required = false) String no
model.addAttribute("p", p);
return "/default/admin/node/list";
}


/**
* 编辑节点页面
* @param id
* @param model
* @return
*/
@RequiresPermissions("node:edit")
@RequestMapping(value = "/edit",method = RequestMethod.GET)
public String edit(@RequestParam(value = "id") Integer id, Model model) {
Node node = nodeService.findById(id);
model.addAttribute("node", node);
return "/default/admin/node/edit";
}


/**
* 编辑节点接口
* @param nodeId
* @param nodeTitle
* @param avatarNormal
* @param avatarLarge
* @param nodeDesc
* @return
*/
@RequiresPermissions("node:edit")
@RequestMapping(value = "/edit",method = RequestMethod.POST)
@ResponseBody
Expand All @@ -59,7 +80,12 @@ public Result<String> edit(Integer nodeId, String nodeTitle, String avatarNormal
nodeService.update(nodeId, nodeTitle, avatarNormal, avatarLarge, nodeDesc);
return new Result(true, "更新成功");
}


/**
* 删除节点接口
* @param id
* @return
*/
@RequiresPermissions("node:delete")
@RequestMapping(value = "/delete",method = RequestMethod.POST)
@ResponseBody
Expand All @@ -68,4 +94,54 @@ public Result<String> delete(Integer id){
nodeService.deleteById(id);
return new Result(true, "删除成功");
}

/**
* 添加节点页面
* @return
*/
@RequiresPermissions("node:add")
@RequestMapping(value = "/add",method = RequestMethod.GET)
public String add() {
return "/default/admin/node/add";
}

/**
* 添加节点接口
* @param node
* @return
*/
@RequiresPermissions("node:add")
@RequestMapping(value = "/add",method = RequestMethod.POST)
@ResponseBody
public Result add(@RequestBody Node node){
ApiAssert.notNull(node.getNodeTitle(),"节点名称不能为空");
ApiAssert.isNull(nodeService.findByTitle(node.getNodeTitle()),"节点已存在");
node.setNodeCode(node.getNodeTitle());
node.setAvatarMini(node.getAvatarNormal());
node.setUrl("/n/"+node.getNodeTitle());
node.setCreateDate(new Date());
node.setIsDelete(false);
nodeService.save(node);
return new Result(true,"添加成功");
}

/**
* 父节点页面
* @param nodeTitle
* @param p
* @param model
* @return
*/
@RequiresPermissions("node:add")
@RequestMapping(value = "/parent",method = RequestMethod.GET)
public String parentNode(@RequestParam(value = "nodeTitle",required = false) String nodeTitle,
@RequestParam(value = "p",defaultValue = "1") Integer p,
Model model){
if(StringUtils.isEmpty(nodeTitle)) nodeTitle = null;
PageDataBody<Node> page = nodeService.pageForAdmin(nodeTitle, p, 25);
model.addAttribute("page", page);
model.addAttribute("nodeTitle", nodeTitle);
model.addAttribute("p", p);
return "/default/admin/node/parent_node_list";
}
}
9 changes: 8 additions & 1 deletion src/main/java/cn/roothub/bbs/module/node/dao/NodeDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,14 @@ List<Node> selectAtherParentNode(@Param("nodeCode") String nodeCode,@Param("tabI
* @return
*/
int update(Node node);


/**
* 添加节点
* @param node
* @return
*/
int insert(@Param("node") Node node);

/**
* 删除节点
* @param id:节点ID
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/roothub/bbs/module/node/model/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}

public boolean isDelete() {
public boolean getIsDelete() {
return isDelete;
}

public void setDelete(boolean isDelete) {
public void setIsDelete(boolean isDelete) {
this.isDelete = isDelete;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ public interface NodeService {
* @param nodeDesc:节点描述
*/
void update(Integer nodeId, String nodeTitle, String avatarNormal, String avatarLarge, String nodeDesc);


/**
* 添加节点
* @param node
*/
void save(Node node);

/**
* 删除节点
* @param id:节点ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void update(Integer nodeId, String nodeTitle, String avatarNormal, String
if(!nodeTitle.equals(node.getNodeTitle())) {
topicService.updateNodeTitile(node.getNodeTitle(), nodeTitle);
}
node.setNodeCode(nodeTitle);
node.setNodeTitle(nodeTitle);
node.setAvatarNormal(avatarNormal);
node.setAvatarLarge(avatarLarge);
Expand All @@ -93,6 +94,15 @@ public void update(Integer nodeId, String nodeTitle, String avatarNormal, String
nodeDao.update(node);
}

/**
* 添加节点
* @param node
*/
@Override
public void save(Node node) {
nodeDao.insert(node);
}

/**
* 删除节点
*/
Expand Down
82 changes: 82 additions & 0 deletions src/main/resources/mybatis/mapper/node/NodeDao.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,88 @@
WHERE
node_id = #{nodeId}
</update>

<!--添加节点-->
<insert id="insert" parameterType="cn.roothub.bbs.module.node.model.Node" keyProperty="node.nodeId" useGeneratedKeys="true">
INSERT INTO node
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="node.nodeCode != null and node.nodeCode != ''">
node_code,
</if>
<if test="node.nodeTitle != null and node.nodeTitle != ''">
node_title,
</if>
<if test="node.avatarNormal != null and node.avatarNormal != ''">
avatar_normal,
</if>
<if test="node.avatarMini != null and node.avatarMini != ''">
avatar_mini,
</if>
<if test="node.avatarLarge != null and node.avatarLarge != ''">
avatar_large,
</if>
<if test="node.nodeDesc != null and node.nodeDesc != ''">
node_desc,
</if>
<if test="node.tabId != null and node.tabId != ''">
node_code,
</if>
<if test="node.url != null and node.url != ''">
url,
</if>
<if test="node.parentNodeCode != null and node.parentNodeCode != ''">
parent_node_code,
</if>
<if test="node.createDate != null">
create_date,
</if>
<if test="node.updateDate != null">
update_date,
</if>
<if test="node.isDelete != null">
is_delete,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="node.nodeCode != null and node.nodeCode != ''">
#{node.nodeCode,jdbcType=VARCHAR},
</if>
<if test="node.nodeTitle != null and node.nodeTitle != ''">
#{node.nodeTitle,jdbcType=VARCHAR},
</if>
<if test="node.avatarNormal != null and node.avatarNormal != ''">
#{node.avatarNormal,jdbcType=VARCHAR},
</if>
<if test="node.avatarMini != null and node.avatarMini != ''">
#{node.avatarMini,jdbcType=VARCHAR},
</if>
<if test="node.avatarLarge != null and node.avatarLarge != ''">
#{node.avatarLarge,jdbcType=VARCHAR},
</if>
<if test="node.nodeDesc != null and node.nodeDesc != ''">
#{node.nodeDesc,jdbcType=VARCHAR},
</if>
<if test="node.tabId != null and node.tabId != ''">
#{node.tabId,jdbcType=INTEGER},
</if>
<if test="node.url != null and node.url != ''">
#{node.url,jdbcType=VARCHAR},
</if>
<if test="node.parentNodeCode != null and node.parentNodeCode != ''">
#{node.parentNodeCode,jdbcType=VARCHAR},
</if>
<if test="node.createDate != null">
#{node.createDate,jdbcType=TIMESTAMP},
</if>
<if test="node.updateDate != null">
#{node.updateDate,jdbcType=TIMESTAMP},
</if>
<if test="node.isDelete != null">
#{node.isDelete,jdbcType=BIT},
</if>
</trim>
</insert>

<!-- 删除节点 -->
<update id="deleteById" parameterType="java.lang.Integer">
UPDATE
Expand Down
1 change: 1 addition & 0 deletions src/main/sql/roothub.sql
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ CREATE TABLE `node` (
`update_date` datetime DEFAULT NULL COMMENT '修改时间',
`is_delete` tinyint(1) DEFAULT NULL COMMENT '是否删除 0:否 1:是',
PRIMARY KEY (`node_id`),
UNIQUE KEY `uk_node_title` (`node_title`),
KEY `key_node_code` (`node_code`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COMMENT='节点表';

Expand Down
Loading

0 comments on commit bb1d27e

Please sign in to comment.