pom.xml
@@ -220,6 +220,10 @@ <artifactId>fastjson</artifactId> <version>1.2.47</version> </dependency> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> </dependency> </dependencies> <build> src/main/java/org/springblade/modules/desk/controller/NoticeController.java
@@ -95,7 +95,7 @@ @ApiOperation(value = "分页", notes = "传入notice") public R<IPage<NoticeVO>> page(@ApiIgnore NoticeVO notice, Query query) { //通过deptId获取组织机构信息 Dept dept = iDeptService.getById(notice.getDeptId()); // Dept dept = iDeptService.getById(notice.getDeptId()); // if (dept.getDeptCategory() == 1) { // notice.setCategory(1); // } else { src/main/java/org/springblade/modules/desk/mapper/NoticeMapper.xml
@@ -37,9 +37,14 @@ <select id="selectNoticePage" resultMap="noticeVOResultMap"> SELECT n.*, d.dict_value AS categoryName d.dict_value AS categoryName, bd.dept_name deptName FROM blade_notice n left join blade_dept bd on bd.id = n.dept_id LEFT JOIN ( SELECT * FROM blade_dict WHERE code = 'notice' ) d ON src/main/java/org/springblade/modules/desk/service/impl/NoticeServiceImpl.java
@@ -45,9 +45,9 @@ // 若不使用mybatis-plus自带的分页方法,则不会自动带入tenantId,所以我们需要自行注入 notice.setTenantId(AuthUtil.getTenantId()); List<NoticeVO> noticeVOS = baseMapper.selectNoticePage(page, notice); noticeVOS.forEach(noticeVO -> { noticeVO.setDeptName(deptService.getById(noticeVO.getDeptId()).getDeptName()); }); // noticeVOS.forEach(noticeVO -> { // noticeVO.setDeptName(deptService.getById(noticeVO.getDeptId()).getDeptName()); // }); return page.setRecords(noticeVOS); } src/main/java/org/springblade/modules/exam/controller/ExamScoreController.java
@@ -18,7 +18,9 @@ import org.springblade.modules.exam.service.ExamScoreService; import org.springblade.modules.exam.util.SecurityPaperUtil; import org.springblade.modules.exam.vo.ExamScoreVO; import org.springblade.modules.system.entity.Role; import org.springblade.modules.system.entity.User; import org.springblade.modules.system.service.IRoleService; import org.springblade.modules.system.service.IUserService; import org.springblade.modules.system.vo.UserVO; import org.springframework.web.bind.annotation.*; @@ -44,6 +46,8 @@ private final IUserService userService; private final ExamPaperService examPaperService; private final IRoleService roleService; /** * 自定义分页 @@ -124,6 +128,13 @@ result = pre + (decimalFormat.format(count++)); } user.setSecuritynumber(result); //修改为持证保安 user.setHold("1"); //分配保安角色 Role role = new Role(); role.setRoleAlias("保安"); Role oneRole = roleService.getOne(Condition.getQueryWrapper(role)); user.setRoleId(oneRole.getId().toString()); //更新保安数据 userService.updateById(user); } src/main/java/org/springblade/modules/exam/service/impl/ExamScoreServiceImpl.java
@@ -20,7 +20,9 @@ import org.springblade.modules.exam.util.SecurityPaperUtil; import org.springblade.modules.exam.vo.ExamResultVO; import org.springblade.modules.exam.vo.ExamScoreVO; import org.springblade.modules.system.entity.Role; import org.springblade.modules.system.entity.User; import org.springblade.modules.system.service.IRoleService; import org.springblade.modules.system.service.IUserService; import org.springblade.modules.system.vo.UserVO; import org.springblade.modules.training.entity.TrainingRegistration; @@ -52,6 +54,8 @@ private final ApplyService applyService; private final TrainingRegistrationService trainingRegistrationService; private final IRoleService roleService; /** * 自定义分页数据 @@ -235,6 +239,13 @@ result = pre + (decimalFormat.format(count++)); } user.setSecuritynumber(result); //修改为持证保安 user.setHold("1"); //分配保安角色 Role role = new Role(); role.setRoleAlias("保安"); Role oneRole = roleService.getOne(Condition.getQueryWrapper(role)); user.setRoleId(oneRole.getId().toString()); //更新保安数据 userService.updateById(user); } src/main/java/org/springblade/modules/information/controller/FtpMain.java
New file @@ -0,0 +1,40 @@ package org.springblade.modules.information.controller; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; public class FtpMain { public static void main(String[] args) throws FileNotFoundException { //ftp服务器IP地址 String ftpHost = "192.168.0.105"; //ftp服务器端口 int ftpPort = 21; //ftp服务器用户名 String ftpUserName = "yly"; //ftp服务器密码 String ftpPassword = "Yly@123"; //ftp服务器路径 String ftpPath = ""; //本地路径 String localPath = "D:\\anbao"; //文件名 String fileName = "fz.py"; //下载 //将ftp根目录下的文件下载至E盘 //FtpUtil.downloadFtpFile(ftpHost, ftpUserName, ftpPassword, ftpPort, ftpPath, localPath, fileName); //上传 //将E盘的文件上传至ftp根目录 FileInputStream in=new FileInputStream(new File("D:\\" + fileName)); FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "/", fileName, in); //删除 //删除ftp根目录下的文件 //FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "fz.py"); } } src/main/java/org/springblade/modules/information/controller/FtpUploadFile.java
@@ -110,9 +110,9 @@ } public static void main(String[] args) { String ftpHost = "192.168.0.109"; String ftpUserName = "anonymous"; String ftpPassword = ""; String ftpHost = "192.168.0.105"; String ftpUserName = "yly"; String ftpPassword = "Yly@123"; int ftpPort = 21; //String ftpPath = ""; //目录名, ""表示根目录 String ftpPath = ""; //目录名最好是英文,中文目录暂时还未成功上传 src/main/java/org/springblade/modules/information/controller/FtpUtil.java
@@ -1,95 +1,304 @@ package org.springblade.modules.information.controller; import sun.net.ftp.FtpClient; import sun.net.ftp.FtpProtocolException; import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.SocketException; import java.io.*; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.ArrayList; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPReply; /** * ftp工具类 * @author lijj */ public class FtpUtil { FtpClient ftpClient; private final static Log logger = LogFactory.getLog(FtpUtil.class); /** 本地字符编码 */ private static String LOCAL_CHARSET = "GBK"; // FTP协议里面,规定文件名编码为iso-8859-1 private static String SERVER_CHARSET = "ISO-8859-1"; /** * 连接FTP服务 * 获取FTPClient对象 * * @param url //IP地址 * @param port//端口号 * @param username//用户名 * @param password//密码 * @param ftpHost * FTP主机服务器 * * @param ftpPassword * FTP 登录密码 * * @param ftpUserName * FTP登录用户名 * * @param ftpPort * FTP端口 默认为21 * * @return */ public static FtpClient connectFTP(String url, int port, String username, String password) { //创建ftp FtpClient ftp = null; public static FTPClient getFTPClient(String ftpHost, int ftpPort, String ftpUserName, String ftpPassword) { FTPClient ftpClient = null; try { //创建地址 SocketAddress addr = new InetSocketAddress(url, port); //连接 ftp = FtpClient.create(); ftp.connect(addr); //登陆 ftp.login(username, password.toCharArray()); ftp.setBinaryType(); } catch (FtpProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return ftp; } /** * 取ftp上的文件内容 * * @param ftpFile * @param ftp * @return */ public static List<String> download(String ftpFile, FtpClient ftp) { List<String> list = new ArrayList<String>(); String str = ""; InputStream is = null; BufferedReader br = null; try { // 获取ftp上的文件 is = ftp.getFileStream(ftpFile); //转为字节流 br = new BufferedReader(new InputStreamReader(is)); while ((str = br.readLine()) != null) { list.add(str); ftpClient = new FTPClient(); ftpClient.connect(ftpHost, ftpPort);// 连接FTP服务器 ftpClient.login(ftpUserName, ftpPassword);// 登陆FTP服务器 if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) { logger.info("未连接到FTP,用户名或密码错误。"); ftpClient.disconnect(); } else { logger.info("FTP连接成功。"); } br.close(); } catch (FtpProtocolException e) { } catch (SocketException e) { e.printStackTrace(); logger.info("FTP的IP地址可能错误,请正确配置。"); } catch (IOException e) { e.printStackTrace(); logger.info("FTP的端口错误,请正确配置。"); } return ftpClient; } /** * 从FTP服务器下载文件 * * @param ftpHost FTP IP地址 * * @param ftpUserName FTP 用户名 * * @param ftpPassword FTP用户名密码 * * @param ftpPort FTP端口 * * @param ftpPath FTP服务器中文件所在路径 格式: ftptest/aa * * @param localPath 下载到本地的位置 格式:H:/download * * @param fileName 文件名称 */ public static void downloadFtpFile(String ftpHost, String ftpUserName, String ftpPassword, int ftpPort, String ftpPath, String localPath, String fileName) { FTPClient ftpClient = null; try { ftpClient = getFTPClient(ftpHost, ftpPort, ftpUserName, ftpPassword); // 设置上传文件的类型为二进制类型 if (FTPReply.isPositiveCompletion(ftpClient.sendCommand("OPTS UTF8", "ON"))) {// 开启服务器对UTF-8的支持,如果服务器支持就用UTF-8编码,否则就使用本地编码(GBK). LOCAL_CHARSET = "UTF-8"; } ftpClient.setControlEncoding(LOCAL_CHARSET); ftpClient.enterLocalPassiveMode();// 设置被动模式 ftpClient.setFileType(FTP.BINARY_FILE_TYPE);// 设置传输的模式 // 上传文件 //对中文文件名进行转码,否则中文名称的文件下载失败 String fileNameTemp = new String(fileName.getBytes(LOCAL_CHARSET), SERVER_CHARSET); ftpClient.changeWorkingDirectory(ftpPath); InputStream retrieveFileStream = ftpClient.retrieveFileStream(fileNameTemp); // 第一种方式下载文件(推荐) /* File localFile = new File(localPath + File.separatorChar + fileName); OutputStream os = new FileOutputStream(localFile); ftpClient.retrieveFile(fileName, os); os.close();*/ // 第二种方式下载:将输入流转成字节,再生成文件,这种方式方便将字节数组直接返回给前台jsp页面 byte[] input2byte = input2byte(retrieveFileStream); byte2File(input2byte, localPath, fileName); if(null != retrieveFileStream){ retrieveFileStream.close(); } } catch (FileNotFoundException e) { logger.error("没有找到" + ftpPath + "文件"); e.printStackTrace(); } catch (SocketException e) { logger.error("连接FTP失败."); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); logger.error("文件读取错误。"); e.printStackTrace(); } finally { if (ftpClient.isConnected()) { try { //退出登录 ftpClient.logout(); //关闭连接 ftpClient.disconnect(); } catch (IOException e) { } } } return list; } public static void main(String[] args) { FtpClient ftp = connectFTP("192.168.0.109",21,"anonymous",""); List<String> list = download("D:\\anbao", ftp); for (int i = 0; i < list.size(); i++) { String strOut = null; if (list.get(i).toString() != null) { try { byte[] bs = list.get(i).toString().getBytes(); strOut = new String(bs, "utf-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block public static boolean uploadFile(String ftpHost, int ftpPort, String ftpUserName, String ftpPassword, String basePath, String filePath, String filename, InputStream input) { boolean result = false; FTPClient ftpClient = null; try { int reply; ftpClient = getFTPClient(ftpHost, ftpPort, ftpUserName, ftpPassword); reply = ftpClient.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftpClient.disconnect(); return result; } // 切换到上传目录 if (!ftpClient.changeWorkingDirectory(basePath + filePath)) { // 如果目录不存在创建目录 String[] dirs = filePath.split("/"); String tempPath = basePath; for (String dir : dirs) { if (null == dir || "".equals(dir)) continue; tempPath += "/" + dir; if (!ftpClient.changeWorkingDirectory(tempPath)) { if (!ftpClient.makeDirectory(tempPath)) { return result; } else { ftpClient.changeWorkingDirectory(tempPath); } } } } // 设置上传文件的类型为二进制类型 if (FTPReply.isPositiveCompletion(ftpClient.sendCommand("OPTS UTF8", "ON"))) {// 开启服务器对UTF-8的支持,如果服务器支持就用UTF-8编码,否则就使用本地编码(GBK). LOCAL_CHARSET = "UTF-8"; } ftpClient.setControlEncoding(LOCAL_CHARSET); ftpClient.enterLocalPassiveMode();// 设置被动模式 ftpClient.setFileType(FTP.BINARY_FILE_TYPE);// 设置传输的模式 // 上传文件 filename = new String(filename.getBytes(LOCAL_CHARSET), SERVER_CHARSET); if (!ftpClient.storeFile(filename, input)) { return result; } if(null != input){ input.close(); } result = true; } catch (IOException e) { e.printStackTrace(); } finally { if (ftpClient.isConnected()) { try { //退出登录 ftpClient.logout(); //关闭连接 ftpClient.disconnect(); } catch (IOException ioe) { } } } return result; } public static boolean deleteFile(String ftpHost, int ftpPort, String ftpUserName, String ftpPassword, String pathname, String filename) { boolean flag = false; FTPClient ftpClient = new FTPClient(); try { ftpClient = getFTPClient(ftpHost, ftpPort, ftpUserName, ftpPassword); // 验证FTP服务器是否登录成功 int replyCode = ftpClient.getReplyCode(); if (!FTPReply.isPositiveCompletion(replyCode)) { return flag; } // 切换FTP目录 ftpClient.changeWorkingDirectory(pathname); // 设置上传文件的类型为二进制类型 if (FTPReply.isPositiveCompletion(ftpClient.sendCommand("OPTS UTF8", "ON"))) {// 开启服务器对UTF-8的支持,如果服务器支持就用UTF-8编码,否则就使用本地编码(GBK). LOCAL_CHARSET = "UTF-8"; } ftpClient.setControlEncoding(LOCAL_CHARSET); ftpClient.enterLocalPassiveMode();// 设置被动模式 ftpClient.setFileType(FTP.BINARY_FILE_TYPE);// 设置传输的模式 //对中文名称进行转码 filename = new String(filename.getBytes(LOCAL_CHARSET), SERVER_CHARSET); ftpClient.dele(filename); flag = true; } catch (Exception e) { e.printStackTrace(); } finally { if (ftpClient.isConnected()) { try { //退出登录 ftpClient.logout(); //关闭连接 ftpClient.disconnect(); } catch (IOException e) { } } } return flag; } // 将字节数组转换为输入流 public static final InputStream byte2Input(byte[] buf) { return new ByteArrayInputStream(buf); } // 将输入流转为byte[] public static final byte[] input2byte(InputStream inStream) throws IOException { ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); byte[] buff = new byte[100]; int rc = 0; while ((rc = inStream.read(buff, 0, 100)) > 0) { swapStream.write(buff, 0, rc); } byte[] in2b = swapStream.toByteArray(); return in2b; } // 将byte[]转为文件 public static void byte2File(byte[] buf, String filePath, String fileName) { BufferedOutputStream bos = null; FileOutputStream fos = null; File file = null; try { File dir = new File(filePath); if (!dir.exists() && dir.isDirectory()) { dir.mkdirs(); } file = new File(filePath + File.separator + fileName); fos = new FileOutputStream(file); bos = new BufferedOutputStream(fos); bos.write(buf); } catch (Exception e) { e.printStackTrace(); } finally { if (bos != null) { try { bos.close(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(strOut); System.out.println(list.get(i).toString()); if (fos != null) { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } } } } src/main/java/org/springblade/modules/permit/controller/PermitController.java
@@ -17,6 +17,7 @@ package org.springblade.modules.permit.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; src/main/java/org/springblade/modules/system/controller/DeptController.java
@@ -34,6 +34,7 @@ import org.springblade.core.tool.utils.Func; import org.springblade.modules.system.entity.Dept; import org.springblade.modules.system.entity.User; import org.springblade.modules.system.node.TreeNodes; import org.springblade.modules.system.service.IDeptService; import org.springblade.modules.system.service.IUserService; import org.springblade.modules.system.vo.DeptVO; @@ -139,6 +140,16 @@ return R.data(tree); } /** * 懒加载获取部门树形结构(包含用户数据),只查下一级的数据 * @return */ @GetMapping("/lazy-tree-users") public R<List<TreeNodes>> lazyTreeUsers(String tenantId, Long parentId, BladeUser bladeUser) { List<TreeNodes> tree = deptService.lazyTreeUsers(Func.toStrWithEmpty(tenantId, bladeUser.getTenantId()), parentId); return R.data(tree); } /** * 懒加载获取部门树形结构(包含用户数据)app @@ -164,8 +175,8 @@ */ @GetMapping("/security_lazy-tree") @ApiOperation(value = "懒加载树形结构", notes = "树形结构") public R<List<DeptVO>> securityLazyTree(String tenantId, Long parentId, BladeUser bladeUser) { List<DeptVO> tree = deptService.securityLazyTree(Func.toStrWithEmpty(tenantId, bladeUser.getTenantId()), parentId); public R<List<DeptVO>> securityLazyTree(String jurisdiction, Long parentId) { List<DeptVO> tree = deptService.securityLazyTree(jurisdiction, parentId); return R.data(tree); } src/main/java/org/springblade/modules/system/controller/UserController.java
@@ -44,9 +44,12 @@ import org.springblade.core.tool.support.Kv; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.DigestUtil; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.StringPool; import org.springblade.modules.experience.entity.Experience; import org.springblade.modules.experience.service.IExperienceService; import org.springblade.modules.jurisdiction.entity.Jurisdiction; import org.springblade.modules.jurisdiction.service.JurisdictionService; import org.springblade.modules.system.entity.Dept; import org.springblade.modules.system.entity.Role; import org.springblade.modules.system.entity.User; @@ -88,6 +91,8 @@ private final IDeptService iDeptService; private final IRoleService roleService; private final IExperienceService experienceService; private final JurisdictionService jurisdictionService; /** * 查询单条 @@ -140,8 +145,8 @@ @ApiOperationSupport(order = 3) @ApiOperation(value = "列表", notes = "传入account和realName") //@PreAuth(RoleConstant.HAS_ROLE_ADMIN) public R<IPage<UserVO>> pages(@ApiIgnore UserVO user, Query query, Long deptId, BladeUser bladeUser) { IPage<UserVO> pages = userService.selectUserPages(Condition.getPage(query), user, deptId, "000000"); public R<IPage<UserVO>> pages(@ApiIgnore UserVO user, Query query) { IPage<UserVO> pages = userService.selectUserPages(Condition.getPage(query), user); return R.data(pages); } @@ -183,6 +188,16 @@ } } //根据 deptId 查询dept信息,公安管理员 Dept dept = iDeptService.getById(user.getDeptId()); Long sid = 1123598813738675201L; if (dept.getParentId().equals(sid)){ //获取辖区的数据 Jurisdiction jurisdiction = new Jurisdiction(); jurisdiction.setDeptName(dept.getDeptName()); Jurisdiction one = jurisdictionService.getOne(Condition.getQueryWrapper(jurisdiction)); user.setJurisdiction(one.getId().toString()); } return R.status(userService.submit(user)); } @@ -415,8 +430,10 @@ @GetMapping("/zc") public R zc(String username,String password) { User user = new User(); user.setTenantId("000000"); user.setAccount(username); user.setPassword(DigestUtil.encrypt(password)); user.setRoleId("1428177141018771458"); userService.saveOrUpdate(user); return R.success("注册成功"); } @@ -447,6 +464,10 @@ user.setRoleId(oneRole.getId().toString()); } } //密码加密 if (Func.isNotEmpty(user.getPassword())) { user.setPassword(DigestUtil.encrypt(user.getPassword())); } //用户新增 boolean status = userService.save(user); //获取从业记录 src/main/java/org/springblade/modules/system/mapper/DeptMapper.java
@@ -18,8 +18,10 @@ import com.baomidou.mybatisplus.annotation.SqlParser; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.MapKey; import org.apache.ibatis.annotations.Param; import org.springblade.modules.system.entity.Dept; import org.springblade.modules.system.node.TreeNodes; import org.springblade.modules.system.vo.DeptVO; import java.util.List; @@ -86,7 +88,7 @@ /** * 懒加载获取部门树形结构,不包含顶级管理员公安局 */ List<DeptVO> securityLazyTree(String tenantId, Long parentId); List<DeptVO> securityLazyTree(String jurisdiction, Long parentId); /** * 懒加载获取部门树形结构(包含用户数据) @@ -108,4 +110,12 @@ */ @SqlParser(filter=true) List<DeptVO> lazyTreeUserApp(@Param("type")Integer type,@Param("jurisdiction")String jurisdiction); /** * 懒加载获取部门树形结构(包含用户数据),只查下一级的数据 * @return */ @MapKey(value = "id") @SqlParser(filter=true) Map<Long, TreeNodes> lazyTreeUsers(@Param("parentId") Long parentId); } src/main/java/org/springblade/modules/system/mapper/DeptMapper.xml
@@ -119,11 +119,15 @@ ) AS "has_children" FROM blade_dept dept left join sys_information si on si.departmentid = dept.id WHERE dept.parent_id = #{param2} AND dept.is_deleted = 0 and dept_category = 1 <if test="param1!=null and param1!=''"> and dept.tenant_id = #{param1} and si.jurisdiction = #{param1} </if> ORDER BY dept.sort </select> @@ -160,20 +164,7 @@ <!--懒加载获取部门树形结构(包含用户数据)app--> <select id="lazyTreeUserApp" resultType="org.springblade.modules.system.vo.DeptAndUserVO" > select DISTINCT c.id, c.parent_id, c.title, c.value, c.key, ( SELECT CASE WHEN count(1) > 0 THEN 1 ELSE 0 END FROM blade_dept where id = c.parent_id and dept_category=1 ) AS "has_children" * from ( (SELECT dept.id, @@ -287,7 +278,7 @@ dept.is_deleted = 0 <if test="parentId!=null and parentId!=''"> and dept_category=1 AND dept.id = #{parentId} AND dept.parent_id = #{parentId} </if> ) @@ -316,6 +307,60 @@ </select> <!--懒加载获取部门树形结构(包含用户数据)--> <select id="lazyTreeUsers" resultType="org.springblade.modules.system.node.TreeNodes" > select DISTINCT * from ( (SELECT dept.id, dept.parent_id parentId, dept.dept_name AS title, dept.id AS "value", dept.id AS "key", ( SELECT CASE WHEN count(1) > 0 THEN 1 ELSE 0 END FROM blade_dept WHERE parent_id = dept.id and is_deleted = 0 ) AS "has_children" FROM blade_dept dept WHERE dept.is_deleted = 0 <if test="parentId!=null and parentId!='' or parentId==0"> and dept_category=1 AND dept.parent_id = #{parentId} </if> ) union (select bu.id, bu.dept_id parentId, bu.real_name AS title, bu.id AS "value", bu.id AS "key", 0 as "has_children" from blade_user bu left join blade_dept bd on bd.id = bu.dept_id where 1=1 and bu.is_deleted = 0 <if test="parentId!=null and parentId!='' or parentId==0"> and dept_category=1 AND bu.dept_id = #{parentId} </if> ) )c </select> <select id="lazyTrees" resultMap="treeNodeResultMap" > SELECT src/main/java/org/springblade/modules/system/mapper/DictBizMapper.xml
@@ -76,7 +76,6 @@ blade_dict_biz bdb where 1=1 and bdb.parent_id = 0 </select> src/main/java/org/springblade/modules/system/mapper/UserMapper.java
@@ -46,7 +46,7 @@ * @param tenantId * @return */ List<UserVO> selectUserPages(IPage<UserVO> page, @Param("user") UserVO user, @Param("deptIdList") List<Long> deptIdList, @Param("tenantId") String tenantId); List<UserVO> selectUserPages(IPage<UserVO> page, @Param("user") UserVO user); /** src/main/java/org/springblade/modules/system/mapper/UserMapper.xml
@@ -60,6 +60,10 @@ on bu.dept_id = bd.id left join sys_information si on si.departmentid = bd.id left join sys_live_location sll on sll.worker_id = bu.id @@ -69,12 +73,6 @@ br.id = bu.role_id where bu.is_deleted = 0 <if test="tenantId!=null and tenantId != ''"> and bu.tenant_id = #{tenantId} </if> <if test="user.tenantId!=null and user.tenantId != ''"> and bu.tenant_id = #{user.tenantId} </if> <if test="user.account!=null and user.account != ''"> and bu.account = #{user.account} </if> @@ -82,7 +80,7 @@ and bu.hold = #{user.hold} </if> <if test="user.deptId!=null and user.deptId != ''"> and (bd.parent_id = #{user.deptId} or bd.id = #{user.deptId}) and bu.dept_id = #{user.deptId} </if> <if test="user.roleId!=null and user.roleId != ''"> and bu.role_id = #{user.roleId} @@ -94,7 +92,7 @@ and bu.status = #{user.status} </if> <if test="user.jurisdiction!=null and user.jurisdiction != '' and user.jurisdiction!='1123598813738675201'"> and bu.jurisdiction = #{user.jurisdiction} and si.jurisdiction = #{user.jurisdiction} </if> <if test="user.realName!=null and user.realName != ''"> and bu.real_name like concat('%', #{user.realName},'%') @@ -107,19 +105,6 @@ </if> <if test="user.examinationType!=null and user.examinationType != ''"> and bu.examination_type = #{user.examinationType} </if> <if test="deptIdList!=null and deptIdList.size>0"> and bu.id in ( SELECT user_id FROM blade_user_dept WHERE dept_id IN <foreach collection="deptIdList" index="index" item="item" open="(" separator="," close=")"> #{item} </foreach> ) </if> ORDER BY bu.id </select> src/main/java/org/springblade/modules/system/node/TreeNodes.java
New file @@ -0,0 +1,42 @@ package org.springblade.modules.system.node; import lombok.Data; import java.util.ArrayList; import java.util.List; /** * @author zhongrj * avue 返回格式 */ @Data public class TreeNodes { /** * id */ private Long id; /** * key */ private Long key; /** * 父id */ private Long parentId; /** * 树节点名称 */ private String title; /** * 子节点 */ private List<TreeNodes> children = new ArrayList<>(); /** * 是否有子节点 */ private Boolean hasChildren; } src/main/java/org/springblade/modules/system/service/IDeptService.java
@@ -18,6 +18,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import org.springblade.modules.system.entity.Dept; import org.springblade.modules.system.node.TreeNodes; import org.springblade.modules.system.vo.DeptVO; import java.util.List; @@ -129,7 +130,7 @@ /** * 懒加载获取部门树形结构,不包含顶级管理员公安局 */ List<DeptVO> securityLazyTree(String tenantId, Long parentId); List<DeptVO> securityLazyTree(String jurisdiction, Long parentId); List<String> selectIn(); /** @@ -150,4 +151,10 @@ * @return */ List<DeptVO> lazyTreeUserApp(Integer type,String jurisdiction); /** * 懒加载获取部门树形结构(包含用户数据),只查下一级的数据 * @return */ List<TreeNodes> lazyTreeUsers(String tenantId, Long parentId); } src/main/java/org/springblade/modules/system/service/IUserService.java
@@ -69,11 +69,9 @@ * * @param page * @param user * @param deptId * @param tenantId * @return */ IPage<UserVO> selectUserPages(IPage<UserVO> page, UserVO user, Long deptId, String tenantId); IPage<UserVO> selectUserPages(IPage<UserVO> page, UserVO user); /** * 自定义分页 src/main/java/org/springblade/modules/system/service/impl/DeptServiceImpl.java
@@ -28,11 +28,14 @@ import org.springblade.core.tool.utils.StringPool; import org.springblade.modules.system.entity.Dept; import org.springblade.modules.system.mapper.DeptMapper; import org.springblade.modules.system.node.TreeNode; import org.springblade.modules.system.node.TreeNodes; import org.springblade.modules.system.service.IDeptService; import org.springblade.modules.system.vo.DeptVO; import org.springblade.modules.system.wrapper.DeptWrapper; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -188,11 +191,8 @@ * 懒加载获取部门树形结构,不包含顶级管理员公安局 */ @Override public List<DeptVO> securityLazyTree(String tenantId, Long parentId) { if (AuthUtil.isAdministrator()) { tenantId = StringPool.EMPTY; } return ForestNodeMerger.merge(baseMapper.securityLazyTree(tenantId, parentId)); public List<DeptVO> securityLazyTree(String jurisdiction, Long parentId) { return ForestNodeMerger.merge(baseMapper.securityLazyTree(jurisdiction, parentId)); } @Override @@ -235,4 +235,23 @@ public List<DeptVO> lazyTreeUserApp(Integer type,String jurisdiction) { return ForestNodeMerger.merge(baseMapper.lazyTreeUserApp(type,jurisdiction)); } /** * 懒加载获取部门树形结构(包含用户数据),只查下一级的数据 * @return */ @Override public List<TreeNodes> lazyTreeUsers(String tenantId, Long parentId) { Map<Long,TreeNodes> map = baseMapper.lazyTreeUsers(parentId); System.out.println("map = " + map.size()); List<TreeNodes> tree = new ArrayList<>(); map.forEach((id,treeNodes) ->{ if (map.containsKey(treeNodes.getParentId())){ map.get(treeNodes.getParentId()).getChildren().add(treeNodes); }else { tree.add(treeNodes); } }); return tree; } } src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java
@@ -138,9 +138,8 @@ } @Override public IPage<UserVO> selectUserPages(IPage<UserVO> page, UserVO user, Long deptId, String tenantId) { List<Long> deptIdList = SysCache.getDeptChildIds(deptId); return page.setRecords(baseMapper.selectUserPages(page, user, deptIdList, tenantId)); public IPage<UserVO> selectUserPages(IPage<UserVO> page, UserVO user) { return page.setRecords(baseMapper.selectUserPages(page, user)); } @Override