drone-service-api/drone-system-api/src/main/java/org/sxkj/system/vo/DeptVO.java
@@ -64,6 +64,10 @@ @JsonInclude(JsonInclude.Include.NON_EMPTY) private Boolean hasChildren; // area_name @ApiModelProperty(value = "区划名称") private String areaName; @Override public List<DeptVO> getChildren() { if (this.children == null) { @@ -111,7 +115,6 @@ */ private String areaCode; private String areaName; /** * 部署模式:0-统一部署,1-独立部署 drone-service/drone-system/src/main/java/org/sxkj/system/controller/DeptController.java
@@ -26,6 +26,7 @@ import org.apache.commons.lang3.StringUtils; import org.springblade.core.boot.ctrl.BladeController; import org.springblade.core.cache.utils.CacheUtil; import org.springblade.core.excel.util.ExcelUtil; import org.springblade.core.log.annotation.ApiLog; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; @@ -37,18 +38,26 @@ import org.springblade.core.tool.constant.RoleConstant; import org.springblade.core.tool.support.Kv; import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.Func; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.multipart.MultipartFile; import org.sxkj.common.node.TreeStringNode; import org.sxkj.common.utils.HeaderUtils; import org.sxkj.system.cache.DictCache; import org.sxkj.system.cache.UserCache; import org.sxkj.system.entity.Dept; import org.sxkj.system.entity.Region; import org.sxkj.system.entity.User; import org.sxkj.system.enums.DictEnum; import org.sxkj.system.excel.DeptExcel; import org.sxkj.system.excel.DeptImporter; import org.sxkj.system.excel.RegionExcel; import org.sxkj.system.excel.RegionImporter; import org.sxkj.system.mapper.DeptMapper; import org.sxkj.system.mapper.UserMapper; import org.sxkj.system.param.DeptAddParam; import org.sxkj.system.param.DeptExportParam; import org.sxkj.system.param.DeptPageParam; import org.sxkj.system.service.IDeptService; import org.sxkj.system.vo.DeptVO; @@ -56,7 +65,9 @@ import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; @@ -287,7 +298,7 @@ */ @GetMapping("/getParentDeptInfo") @ApiOperationSupport(order = 12) @ApiOperation(value = "下拉数据源", notes = "传入id集合") @ApiOperation(value = "通过id查询", notes = "传入id集合") public R getParentDeptInfo(String deptId) { DeptVO list = deptService.getParentDeptInfo(deptId); return R.data(list); @@ -325,4 +336,38 @@ return R.data(list); } /** * 导入机构数据 */ @PostMapping("import-region") @ApiOperationSupport(order = 14) @ApiOperation(value = "导入机构", notes = "传入excel") public R importRegion(MultipartFile file, Integer isCovered) { DeptImporter deptImporter = new DeptImporter(deptService, isCovered == 1); ExcelUtil.save(file, deptImporter, DeptExcel.class); return R.success("操作成功"); } /** * 导出机构数据 */ @GetMapping("export-region") @ApiOperationSupport(order = 15) @ApiOperation(value = "导出机构", notes = "传入user") public void exportRegion(DeptExportParam dept, HttpServletResponse response) { List<DeptExcel> list = deptService.exportDept(dept); ExcelUtil.export(response, "机构数据" + DateUtil.time(), "机构数据表", list, DeptExcel.class); } /** * 导出模板 */ @GetMapping("export-template") @ApiOperationSupport(order = 16) @ApiOperation(value = "导出模板") public void exportUser(HttpServletResponse response) { List<DeptExcel> list = new ArrayList<>(); ExcelUtil.export(response, "机构模板", "机构表", list, DeptExcel.class); } } drone-service/drone-system/src/main/java/org/sxkj/system/excel/DeptExcel.java
New file @@ -0,0 +1,59 @@ /* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.sxkj.system.excel; import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.write.style.ColumnWidth; import com.alibaba.excel.annotation.write.style.ContentRowHeight; import com.alibaba.excel.annotation.write.style.HeadRowHeight; import lombok.Data; import java.io.Serializable; /** * RegionExcel * * @author Chill */ @Data @ColumnWidth(16) @HeadRowHeight(20) @ContentRowHeight(18) public class DeptExcel implements Serializable { private static final long serialVersionUID = 1L; @ExcelProperty("机构编码") @ColumnWidth(20) private String deptCode; @ExcelProperty("机构名称") @ColumnWidth(20) private String deptName; @ExcelProperty("所属区划") @ColumnWidth(20) private String areaName; @ExcelProperty("机构描述") @ColumnWidth(20) private String deptDesc; @ExcelProperty("机构状态") @ColumnWidth(20) private String deptStatus; } drone-service/drone-system/src/main/java/org/sxkj/system/excel/DeptImporter.java
New file @@ -0,0 +1,41 @@ /* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.sxkj.system.excel; import lombok.RequiredArgsConstructor; import org.springblade.core.excel.support.ExcelImporter; import org.sxkj.system.service.IDeptService; import org.sxkj.system.service.IRegionService; import java.util.List; /** * 行政区划数据导入类 * * @author Chill */ @RequiredArgsConstructor public class DeptImporter implements ExcelImporter<DeptExcel> { private final IDeptService service; private final Boolean isCovered; @Override public void save(List<DeptExcel> data) { service.importDept(data, isCovered); } } drone-service/drone-system/src/main/java/org/sxkj/system/mapper/DeptMapper.java
@@ -16,6 +16,7 @@ */ package org.sxkj.system.mapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import org.apache.ibatis.annotations.MapKey; @@ -23,6 +24,8 @@ import org.apache.ibatis.annotations.Param; import org.sxkj.common.node.TreeStringNode; import org.sxkj.system.entity.Dept; import org.sxkj.system.excel.DeptExcel; import org.sxkj.system.param.DeptExportParam; import org.sxkj.system.param.DeptPageParam; import org.sxkj.system.vo.DeptVO; @@ -62,7 +65,7 @@ * @param parentId * @return */ List<DeptVO> lazyTree(String tenantId, Long parentId,Integer level); List<DeptVO> lazyTree(String tenantId, Long parentId, Integer level); /** * 获取部门名 @@ -74,6 +77,7 @@ /** * 获取部门树形结构 * * @param deptId * @return */ @@ -82,6 +86,7 @@ /** * 自定义详情查询-根据系统配置id * * @param dept * @return */ @@ -89,6 +94,7 @@ /** * 下拉机构列表查询 * * @param deptId * @return */ @@ -96,6 +102,7 @@ /** * 查询父级机构信息(一级机构) * * @param deptId * @return */ @@ -103,27 +110,39 @@ /** * 查询机构树(除本机机构以外的机构) * * @param deptId * @return */ @MapKey("id") Map<String, TreeStringNode> getDeptTreeByNotItself(@Param("deptId") String deptId,@Param("deviceSn") String deviceSn); Map<String, TreeStringNode> getDeptTreeByNotItself(@Param("deptId") String deptId, @Param("deviceSn") String deviceSn); /** * 懒加载获取部门树形结构(子集) * * @param parentId * @return */ List<DeptVO> getChildLazyTree(Long parentId,Map<String, Object> param); List<DeptVO> getChildLazyTree(Long parentId, Map<String, Object> param); String getFullRegionName(String areaCode); String getSingleRegionName(String areaCode); /** * 查询部门分页数据 * * @param page * @param deptPageParam * @return */ IPage<DeptVO> selectDeptPage(IPage<DeptVO> page, DeptPageParam deptPageParam); IPage<DeptVO> selectDeptPage(IPage<DeptVO> page, DeptPageParam deptPageParam); /** * 导出部门数据 * * @param deptExportParam * @return */ List<DeptExcel> exportDept(DeptExportParam deptExportParam); } drone-service/drone-system/src/main/java/org/sxkj/system/mapper/DeptMapper.xml
@@ -278,9 +278,10 @@ <select id="selectDeptPage" resultType="org.sxkj.system.vo.DeptVO"> SELECT bd.* bd.*, br.name AS area_name FROM blade_dept bd blade_dept bd LEFT JOIN blade_region br ON br.code = bd.area_code WHERE bd.is_deleted = 0 <if test="param2.deptName!=null and param2.deptName!=''"> @@ -294,5 +295,26 @@ </if> </select> <select id="exportDept" resultType="org.sxkj.system.excel.DeptExcel"> SELECT bd.*, br.name AS area_name FROM blade_dept bd LEFT JOIN blade_region br ON br.code = bd.area_code WHERE bd.is_deleted = 0 <if test="deptName!=null and deptName!=''"> and bd.dept_name like concat(concat('%', #{deptName}),'%') </if> <if test="fullName!=null and fullName!=''"> and bd.full_name like concat(concat('%', #{fullName}),'%') </if> <if test="areaCode!=null and areaCode!=''"> and bd.area_code = #{areaCode} </if> </select> </mapper> drone-service/drone-system/src/main/java/org/sxkj/system/param/DeptExportParam.java
New file @@ -0,0 +1,17 @@ package org.sxkj.system.param; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data public class DeptExportParam { @ApiModelProperty(value = "部门名称") private String deptName; @ApiModelProperty(value = "部门全称") private String fullName; @ApiModelProperty(value = "所属区划") private String areaCode; } drone-service/drone-system/src/main/java/org/sxkj/system/service/IDeptService.java
@@ -16,11 +16,14 @@ */ package org.sxkj.system.service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; import org.springblade.core.tool.api.R; import org.sxkj.common.node.TreeStringNode; import org.sxkj.system.entity.Dept; import org.sxkj.system.excel.DeptExcel; import org.sxkj.system.param.DeptExportParam; import org.sxkj.system.param.DeptPageParam; import org.sxkj.system.vo.DeptVO; @@ -59,7 +62,7 @@ * @param parentId * @return */ List<DeptVO> lazyTree(String tenantId, Long parentId,Integer level); List<DeptVO> lazyTree(String tenantId, Long parentId, Integer level); /** * 获取部门ID @@ -122,6 +125,7 @@ /** * 获取部门树形结构 * * @param dept * @return */ @@ -129,13 +133,15 @@ /** * 自定义详情查询-根据系统配置id * * @param dept * @return */ DeptVO getDetailBySysConfigId(DeptVO dept); DeptVO getDetailBySysConfigId(DeptVO dept); /** * 下拉数据源 * * @param deptId * @return */ @@ -143,6 +149,7 @@ /** * 查询父级机构信息(一级机构) * * @param deptId * @return */ @@ -150,22 +157,25 @@ /** * 查询机构树(除本机机构以外的机构) * * @param deptId * @param deviceSn * @return */ List<TreeStringNode> getDeptTreeByNotItself(String deptId,String deviceSn); List<TreeStringNode> getDeptTreeByNotItself(String deptId, String deviceSn); /** * 懒加载获取部门树形结构(子集) * * @param param * @param parentId * @return */ List<DeptVO> getChildLazyTree(Map<String, Object> param,Long parentId); List<DeptVO> getChildLazyTree(Map<String, Object> param, Long parentId); /** * 部门名称关系map * * @param deptIds * @return */ @@ -173,16 +183,32 @@ /** * 获取部门列表 * * @param areaCode 区域code * @return 部门列表 */ List<DeptVO> deptsByAreaCode(String areaCode); /** * * @param page * @param deptPageParam * @return */ IPage<DeptVO> selectDeptPage(IPage<DeptVO> page, DeptPageParam deptPageParam); IPage<DeptVO> selectDeptPage(IPage<DeptVO> page, DeptPageParam deptPageParam); /** * 导入部门 * * @param data * @param isCovered */ void importDept(List<DeptExcel> data, Boolean isCovered); /** * 导出部门 * * @param dept * @return */ List<DeptExcel> exportDept(DeptExportParam dept); } drone-service/drone-system/src/main/java/org/sxkj/system/service/impl/DeptServiceImpl.java
@@ -17,6 +17,7 @@ package org.sxkj.system.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -30,20 +31,21 @@ import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.StringPool; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.sxkj.common.func.Streams; import org.sxkj.common.model.ResponseResult; import org.sxkj.common.node.TreeStringNode; import org.sxkj.common.utils.NodeTreeUtil; import org.sxkj.system.cache.SysCache; import org.sxkj.system.entity.Dept; import org.sxkj.system.excel.DeptExcel; import org.sxkj.system.mapper.DeptMapper; import org.sxkj.system.param.DeptExportParam; import org.sxkj.system.param.DeptPageParam; import org.sxkj.system.service.IDeptService; import org.sxkj.system.vo.DeptVO; import org.sxkj.system.wrapper.DeptWrapper; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; @@ -307,4 +309,28 @@ public IPage<DeptVO> selectDeptPage(IPage<DeptVO> page, DeptPageParam deptPageParam) { return baseMapper.selectDeptPage(page, deptPageParam); } /** * 导入部门 * @param data * @param isCovered */ @Override public void importDept(List<DeptExcel> data, Boolean isCovered) { List<Dept> list = new ArrayList<>(); data.forEach(deptExcel -> { Dept dept = BeanUtil.copy(deptExcel, Dept.class); list.add(dept); }); if (isCovered) { this.saveOrUpdateBatch(list); } else { this.saveBatch(list); } } @Override public List<DeptExcel> exportDept(DeptExportParam dept) { return baseMapper.exportDept(dept); } }