Ver Fonte

增加菜单管理接口

chenwen há 2 anos atrás
pai
commit
633a810076

+ 14 - 5
src/main/java/com/hb/proj/auth/controller/MenuController.java

@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RestController;
 import com.hb.proj.allconfig.AccessToken;
 import com.hb.proj.auth.service.MenuService;
 import com.hb.proj.model.MenuPO;
+import com.hb.proj.model.MenuVO;
 import com.hb.proj.utils.RespVO;
 import com.hb.proj.utils.RespVOBuilder;
 
@@ -34,7 +35,7 @@ public class MenuController {
 	 * @return
 	 */
 	@GetMapping("/get")
-	public RespVO<Object> get(@NotBlank(message = "菜单编号不能为空") String menuId){
+	public RespVO<MenuVO> get(@NotBlank(message = "菜单编号不能为空") String menuId){
 		
 		return RespVOBuilder.ok(service.getMenu(menuId));
 	}
@@ -47,7 +48,7 @@ public class MenuController {
 	 * @return
 	 */
 	@PostMapping("/add")
-	public RespVO<Object> add(@Validated MenuPO  menu,AccessToken token){
+	public RespVO<String> add(@Validated MenuPO  menu,AccessToken token){
 		
 		if(StringUtils.isBlank(menu.getFatherMenuId())){
 			menu.setFatherMenuId("0");
@@ -64,18 +65,26 @@ public class MenuController {
 	/**
 	 * 更新菜单
 	 * @param menu  菜单实体
-	 * @param oldFatherMenuId 菜单原上级菜单id
 	 * @param token 登录人信息,自动从请求获取
 	 * @return
 	 */
 	@PostMapping("/update")
-	public RespVO<Object> update(@Validated MenuPO  menu,String oldFatherMenuId,AccessToken token){
+	public RespVO<Object> update(@Validated MenuPO  menu,AccessToken token){
 		if(StringUtils.isEmpty(menu.getFatherMenuId())){
 			menu.setFatherMenuId("0");
 		}
 		menu.setModifyBy(token!=null?token.getTokenId():"unknow");
+		
+		MenuVO dbMenu=service.getMenu(menu.getMenuId());
+		
+		//非更新数据保留原值
+		menu.setAssistCode(dbMenu.getAssistCode());
+		menu.setCreateBy(dbMenu.getCreateBy());
+		menu.setCreateTime(dbMenu.getCreateTime());
+		menu.setDelIf(dbMenu.getDelIf());
+		
 		String fatherMenuId=menu.getFatherMenuId();
-		if (!oldFatherMenuId.equals(fatherMenuId)) { // 隶属关系变动后,修正assistCode
+		if (!fatherMenuId.equals(dbMenu.getFatherMenuId())) { // 隶属关系变动后,修正assistCode
 			String newAssistCode =service.generateLeveledCode(fatherMenuId);
 			if(newAssistCode==null){
 				return RespVOBuilder.error("指定的父菜单不存在");

+ 10 - 10
src/main/java/com/hb/proj/auth/service/MenuService.java

@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import com.hb.proj.model.MenuPO;
+import com.hb.proj.model.MenuVO;
 import com.hb.proj.utils.PinyinFromHanzi;
 import com.hb.xframework.dao.core.SpringJdbcDAO;
 import com.hb.xframework.dao.util.UUIDHexGenerator;
@@ -30,21 +31,20 @@ public class MenuService {
 		return dao.queryForList(sql.toString(),fatherMenuId);
 	}
 	
-	public Map<String,Object> getMenu(String menuId){
+	public MenuVO getMenu(String menuId){
 		StringBuilder sql=new StringBuilder(100);
 		sql.append("select menu.*,");
 		sql.append("(select sm.menu_name from tsys_menu sm where sm.menu_id=menu.father_menu_id) father_menu_name");
 		sql.append(" from tsys_menu menu where menu.menu_id=?");
-		return dao.queryForMap(sql.toString(), menuId);
+		return dao.queryForPojo(sql.toString(),MenuVO.class, menuId);
 	}
 	
 	public String  addMenu(MenuPO menu){
 		UUIDHexGenerator uuid=new UUIDHexGenerator();
-		menu.setModifyTime(new Date());
 		menu.setMenuId(uuid.generate());
-		if(StringUtils.isEmpty(menu.getFatherMenuId())){
-			menu.setFatherMenuId("0");
-		}
+		menu.setModifyTime(new Date());
+		menu.setCreateTime(new Date());
+		menu.setDelIf(false);
 		if(menu.getDisplayNum()==null){
 			Number num=getMenuMaxDispNum(menu.getFatherMenuId());
 			menu.setDisplayNum(num==null?0:(num.intValue()+1));
@@ -54,9 +54,9 @@ public class MenuService {
 		//增加菜单的时候,自动增加浏览功能项
 		Map<String,Object>  fun=new HashMap<String,Object>();
 		fun.put("funId", uuid.generate());
-		fun.put("createTime", new Date());
+		fun.put("modifyTime", new Date());
 		fun.put("menuId",menu.getMenuId());
-		fun.put("createBy", menu.getModifyBy());
+		fun.put("modifyBy", menu.getModifyBy());
 		fun.put("funCode", PinyinFromHanzi.getPinyin(menu.getMenuName()).toUpperCase()+"_BROWSE");
 		fun.put("funName", "浏览");
 		
@@ -102,11 +102,11 @@ public class MenuService {
 			superAssistCode="C";
 		}
 		else{
-			Map<String,Object> superMenu=getMenu(superId);
+			MenuVO superMenu=getMenu(superId);
 			if(superMenu==null){
 				return null;
 			}
-			superAssistCode=(String)superMenu.get("assistCode");
+			superAssistCode=superMenu.getAssistCode();
 			if(StringUtils.isEmpty(superAssistCode)){
 				superAssistCode="C";
 			}

+ 10 - 0
src/main/java/com/hb/proj/model/MenuPO.java

@@ -30,6 +30,8 @@ public class MenuPO {
 	private String  targetDepth;
 	
 	private String assistCode;
+	
+	private Boolean delIf;
 
 	public String getMenuId() {
 		return menuId;
@@ -128,4 +130,12 @@ public class MenuPO {
 	public void setCreateBy(String createBy) {
 		this.createBy = createBy;
 	}
+
+	public Boolean getDelIf() {
+		return delIf;
+	}
+
+	public void setDelIf(Boolean delIf) {
+		this.delIf = delIf;
+	}
 }

+ 14 - 0
src/main/java/com/hb/proj/model/MenuVO.java

@@ -0,0 +1,14 @@
+package com.hb.proj.model;
+
+public class MenuVO extends MenuPO {
+
+	private String fatherMenuName;
+
+	public String getFatherMenuName() {
+		return fatherMenuName;
+	}
+
+	public void setFatherMenuName(String fatherMenuName) {
+		this.fatherMenuName = fatherMenuName;
+	}
+}