Bläddra i källkod

新建web-core-api module,批量保存roleMenu

shiqian 4 år sedan
förälder
incheckning
be5f9ce8d0

+ 27 - 0
boman-api/boman-api-web-core/pom.xml

@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xmlns="http://maven.apache.org/POM/4.0.0"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<parent>
+    <groupId>com.boman</groupId>
+    <artifactId>boman-api</artifactId>
+    <version>2.5.0-SNAPSHOT</version>
+</parent>
+<modelVersion>4.0.0</modelVersion>
+
+<artifactId>boman-api-web-core</artifactId>
+
+<description>
+    boman-api-web-core系统接口模块
+</description>
+
+<dependencies>
+    <dependency>
+        <groupId>com.boman</groupId>
+        <artifactId>boman-domain</artifactId>
+        <version>2.5.0-SNAPSHOT</version>
+    </dependency>
+
+</dependencies>
+
+</project>

+ 25 - 0
boman-api/boman-api-web-core/src/main/java/com/boman/web/core/api/RemoteObjService.java

@@ -0,0 +1,25 @@
+package com.boman.web.core.api;
+
+import com.boman.common.core.constant.ServiceNameConstants;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+
+/**
+ * @author shiqian
+ * @date 2021年04月07日 10:31
+ **/
+@FeignClient(contextId = "remoteObjService", value = ServiceNameConstants.SYSTEM_SERVICE)
+public interface RemoteObjService {
+
+    /**
+     * 功能描述: 根据id查找
+     *
+     * @param tableName tableName
+     * @param pkName    pkName
+     * @return com.boman.common.core.web.domain.AjaxResult
+     */
+    @GetMapping("common/tableName/{tableName}/pkName/{pkName}")
+    Long getMaxId(@PathVariable("tableName") String tableName, @PathVariable("pkName") String pkName);
+}
+

+ 1 - 0
boman-api/pom.xml

@@ -12,6 +12,7 @@
         <module>boman-api-system</module>
         <module>boman-api-gen</module>
         <module>boman-domain</module>
+        <module>boman-api-web-core</module>
     </modules>
 
     <artifactId>boman-api</artifactId>

+ 6 - 0
boman-modules/boman-system/pom.xml

@@ -90,6 +90,12 @@
             <version>1.18.4</version>
         </dependency>
 
+        <dependency>
+            <groupId>com.boman</groupId>
+            <artifactId>boman-api-web-core</artifactId>
+            <version>2.5.0-SNAPSHOT</version>
+        </dependency>
+
     </dependencies>
 
     <build>

+ 32 - 0
boman-modules/boman-system/src/main/java/com/boman/system/controller/SysRoleMenuController.java

@@ -0,0 +1,32 @@
+package com.boman.system.controller;
+
+import com.boman.common.core.web.domain.AjaxResult;
+import com.boman.system.domain.SysRoleMenu;
+import com.boman.system.service.impl.ISysRoleMenuService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+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 javax.annotation.Resource;
+import java.util.List;
+
+/**
+ * @author shiqian
+ * @date 2021年04月27日 14:31
+ **/
+@RestController
+@RequestMapping("/role/menu")
+public class SysRoleMenuController {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(SysRoleMenuController.class);
+
+    @Resource
+    private ISysRoleMenuService service;
+    @PostMapping
+    public AjaxResult list(@RequestBody List<SysRoleMenu> roleMenuList) {
+        return AjaxResult.success(service.saveList(roleMenuList));
+    }
+}

+ 11 - 0
boman-modules/boman-system/src/main/java/com/boman/system/domain/SysRoleMenu.java

@@ -10,12 +10,23 @@ import org.apache.commons.lang3.builder.ToStringStyle;
  */
 public class SysRoleMenu
 {
+    /** id */
+    private Long id;
+
     /** 角色ID */
     private Long roleId;
     
     /** 菜单ID */
     private Long menuId;
 
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
     public Long getRoleId()
     {
         return roleId;

+ 23 - 0
boman-modules/boman-system/src/main/java/com/boman/system/service/impl/ISysRoleMenuService.java

@@ -0,0 +1,23 @@
+package com.boman.system.service.impl;
+
+import com.boman.system.domain.SysRoleMenu;
+
+import java.util.List;
+
+/**
+ * 参数配置 服务层
+ *
+ * @author ruoyi
+ */
+public interface ISysRoleMenuService {
+
+    /**
+     * 功能描述: 批量保存roleMenu
+     *
+     * @param roleMenuList roleMenuList
+     * @return boolean
+     */
+    int saveList(List<SysRoleMenu> roleMenuList);
+
+
+}

+ 45 - 0
boman-modules/boman-system/src/main/java/com/boman/system/service/impl/SysRoleMenuServiceImpl.java

@@ -0,0 +1,45 @@
+package com.boman.system.service.impl;
+
+import com.boman.system.domain.SysRoleMenu;
+import com.boman.system.mapper.SysRoleMenuMapper;
+import com.boman.web.core.api.RemoteObjService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+import static com.boman.common.core.utils.obj.ObjectUtils.isEmpty;
+
+/**
+ * @author shiqian
+ * @date 2021年04月27日 14:34
+ **/
+public class SysRoleMenuServiceImpl implements ISysRoleMenuService{
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(SysRoleMenuServiceImpl.class);
+
+    @Resource
+    private SysRoleMenuMapper mapper;
+    @Resource
+    private RemoteObjService remoteObjService;
+    /**
+     * 功能描述: 批量保存roleMenu
+     *
+     * @param roleMenuList roleMenuList
+     * @return int
+     */
+    @Override
+    public int saveList(List<SysRoleMenu> roleMenuList) {
+        if (isEmpty(roleMenuList)) {
+            return 0;
+        }
+
+        for (SysRoleMenu sysRoleMenu : roleMenuList) {
+            Long maxId = remoteObjService.getMaxId("sys_role_menu", "id");
+            sysRoleMenu.setId(maxId);
+        }
+
+        return mapper.batchRoleMenu(roleMenuList);
+    }
+}

+ 3 - 2
boman-modules/boman-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml

@@ -5,6 +5,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 <mapper namespace="com.boman.system.mapper.SysRoleMenuMapper">
 
 	<resultMap type="SysRoleMenu" id="SysRoleMenuResult">
+		<result property="id"     column="id"      />
 		<result property="roleId"     column="role_id"      />
 		<result property="menuId"     column="menu_id"      />
 	</resultMap>
@@ -25,9 +26,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  	</delete>
 	
 	<insert id="batchRoleMenu">
-		insert into sys_role_menu(role_id, menu_id) values
+		insert into sys_role_menu(id, role_id, menu_id) values
 		<foreach item="item" index="index" collection="list" separator=",">
-			(#{item.roleId},#{item.menuId})
+			(#{item.id},#{item.roleId},#{item.menuId})
 		</foreach>
 	</insert>
 	

+ 12 - 0
boman-web-core/src/main/java/com/boman/web/core/controller/CommonController.java

@@ -42,4 +42,16 @@ public class CommonController {
         return AjaxResult.success(commonService.getByMap(dto.getTable(), dto.getFixedData()));
     }
 
+    /**
+     * 功能描述: getMaxId
+     *
+     * @param tableName tableName
+     * @param pkName        pkName
+     * @return com.boman.common.core.web.domain.AjaxResult
+     */
+    @GetMapping("tableName/{tableName}/pkName/{pkName}")
+    public Long getMaxId(@PathVariable("tableName") String tableName, @PathVariable("pkName") String pkName) {
+        return commonService.getMaxId(tableName, pkName);
+    }
+
 }

+ 5 - 0
boman-web-core/src/main/java/com/boman/web/core/service/common/CommonServiceImpl.java

@@ -58,4 +58,9 @@ public class CommonServiceImpl implements ICommonService {
         requireNonNull(tableName, "tableName is empty");
         return selectService.getByMap(tableName, condition);
     }
+
+    @Override
+    public Long getMaxId(String tableName, String pkName) {
+        return IdUtils.getMaxId(tableName, pkName);
+    }
 }

+ 2 - 0
boman-web-core/src/main/java/com/boman/web/core/service/common/ICommonService.java

@@ -28,4 +28,6 @@ public interface ICommonService {
      * @return java.util.List<com.alibaba.fastjson.JSONObject>
      */
     List<JSONObject> getByMap(String tableName, JSONObject condition);
+
+    Long getMaxId(String tableName, String pkName);
 }