Commit 0d993519 authored by huangjie's avatar huangjie

Merge branch 'zuhuduan' of http://192.168.60.201/root/dsk-operate-sys into zuhuduan

parents 0c5b5b25 8db03d08
package com.dsk.web.controller.system;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import com.dsk.common.annotation.Log;
import com.dsk.common.constant.UserConstants;
......@@ -9,8 +10,10 @@ import com.dsk.common.core.domain.R;
import com.dsk.system.domain.SysDept;
import com.dsk.common.enums.BusinessType;
import com.dsk.common.utils.StringUtils;
import com.dsk.system.domain.vo.SysDeptVo;
import com.dsk.system.service.ISysDeptService;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
......@@ -34,9 +37,13 @@ public class SysDeptController extends BaseController {
*/
@SaCheckPermission("system:dept:list")
@GetMapping("/list")
public R<List<SysDept>> list(SysDept dept) {
public R<List<SysDeptVo>> list(SysDept dept) {
List<SysDept> depts = deptService.selectDeptList(dept);
return R.ok(depts);
List<SysDeptVo> deptVos = BeanUtil.copyToList(depts, SysDeptVo.class);
deptVos.forEach(sysDeptVo -> {
sysDeptVo.setExistUsers(deptService.hasChildByDeptId(sysDeptVo.getDeptId()));
});
return R.ok(deptVos);
}
/**
......@@ -106,13 +113,8 @@ public class SysDeptController extends BaseController {
@SaCheckPermission("system:dept:remove")
@Log(title = "部门管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{deptId}")
@Transactional
public R<Void> remove(@PathVariable Long deptId) {
if (deptService.hasChildByDeptId(deptId)) {
return R.warn("存在下级部门,不允许删除");
}
if (deptService.checkDeptExistUser(deptId)) {
return R.warn("部门存在用户,不允许删除");
}
deptService.checkDeptDataScope(deptId);
return toAjax(deptService.deleteDeptById(deptId));
}
......
......@@ -10,9 +10,6 @@ import com.dsk.common.annotation.Log;
import com.dsk.common.core.controller.BaseController;
import com.dsk.common.core.domain.PageQuery;
import com.dsk.common.core.domain.R;
import com.dsk.system.domain.SysDept;
import com.dsk.system.domain.SysRole;
import com.dsk.system.domain.SysUser;
import com.dsk.common.core.page.TableDataInfo;
import com.dsk.common.enums.BusinessType;
import com.dsk.common.excel.ExcelResult;
......@@ -20,6 +17,9 @@ import com.dsk.common.helper.LoginHelper;
import com.dsk.common.utils.StreamUtils;
import com.dsk.common.utils.StringUtils;
import com.dsk.common.utils.poi.ExcelUtil;
import com.dsk.system.domain.SysDept;
import com.dsk.system.domain.SysRole;
import com.dsk.system.domain.SysUser;
import com.dsk.system.domain.vo.SysUserExportVo;
import com.dsk.system.domain.vo.SysUserImportVo;
import com.dsk.system.listener.SysUserImportListener;
......@@ -142,7 +142,6 @@ public class SysUserController extends BaseController {
} else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
return R.fail("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
}
user.setPassword(BCrypt.hashpw(user.getPassword()));
return toAjax(userService.insertUser(user));
}
......
......@@ -157,6 +157,14 @@ tenant:
- sys_user_post
- sys_user_role
- sys_client
- contact_info
- customer_user
- customer_follow_record
- business_user
- business_backlog
- business_follow_record
- business_label
- business_relate_company
# MyBatisPlus配置
......
package com.dsk.common.exception.file;
import org.apache.tomcat.util.http.fileupload.FileUploadException;
import java.util.Arrays;
/**
* 文件上传 误异常类
*
* @author dsk
*/
public class InvalidExtensionException extends FileUploadException
{
private static final long serialVersionUID = 1L;
private String[] allowedExtension;
private String extension;
private String filename;
public InvalidExtensionException(String[] allowedExtension, String extension, String filename)
{
super("文件[" + filename + "]后缀[" + extension + "]不正确,请上传" + Arrays.toString(allowedExtension) + "格式");
this.allowedExtension = allowedExtension;
this.extension = extension;
this.filename = filename;
}
public String[] getAllowedExtension()
{
return allowedExtension;
}
public String getExtension()
{
return extension;
}
public String getFilename()
{
return filename;
}
public static class InvalidImageExtensionException extends InvalidExtensionException
{
private static final long serialVersionUID = 1L;
public InvalidImageExtensionException(String[] allowedExtension, String extension, String filename)
{
super(allowedExtension, extension, filename);
}
}
public static class InvalidFlashExtensionException extends InvalidExtensionException
{
private static final long serialVersionUID = 1L;
public InvalidFlashExtensionException(String[] allowedExtension, String extension, String filename)
{
super(allowedExtension, extension, filename);
}
}
public static class InvalidMediaExtensionException extends InvalidExtensionException
{
private static final long serialVersionUID = 1L;
public InvalidMediaExtensionException(String[] allowedExtension, String extension, String filename)
{
super(allowedExtension, extension, filename);
}
}
public static class InvalidVideoExtensionException extends InvalidExtensionException
{
private static final long serialVersionUID = 1L;
public InvalidVideoExtensionException(String[] allowedExtension, String extension, String filename)
{
super(allowedExtension, extension, filename);
}
}
}
package com.dsk.common.utils;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import com.dsk.common.utils.spring.SpringUtils;
import io.github.linpeilie.Converter;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import java.util.List;
import java.util.Map;
/**
* @author sxk
* @date 2023.08.23
* @description: Mapstruct 工具类
* <p>参考文档:<a href="https://mapstruct.plus/introduction/quick-start.html">mapstruct-plus</a></p>
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class MapStructUtils {
private final static Converter CONVERTER = SpringUtils.getBean(Converter.class);
/**
* 将 T 类型对象,转换为 desc 类型的对象并返回
*
* @param source 数据来源实体
* @param desc 描述对象 转换后的对象
* @return desc
*/
public static <T, V> V convert(T source, Class<V> desc) {
if (ObjectUtil.isNull(source)) {
return null;
}
if (ObjectUtil.isNull(desc)) {
return null;
}
return CONVERTER.convert(source, desc);
}
/**
* 将 T 类型对象,按照配置的映射字段规则,给 desc 类型的对象赋值并返回 desc 对象
*
* @param source 数据来源实体
* @param desc 转换后的对象
* @return desc
*/
public static <T, V> V convert(T source, V desc) {
if (ObjectUtil.isNull(source)) {
return null;
}
if (ObjectUtil.isNull(desc)) {
return null;
}
return CONVERTER.convert(source, desc);
}
/**
* 将 T 类型的集合,转换为 desc 类型的集合并返回
*
* @param sourceList 数据来源实体列表
* @param desc 描述对象 转换后的对象
* @return desc
*/
public static <T, V> List<V> convert(List<T> sourceList, Class<V> desc) {
if (ObjectUtil.isNull(sourceList)) {
return null;
}
if (CollUtil.isEmpty(sourceList)) {
return CollUtil.newArrayList();
}
return CONVERTER.convert(sourceList, desc);
}
/**
* 将 Map 转换为 beanClass 类型的集合并返回
*
* @param map 数据来源
* @param beanClass bean类
* @return bean对象
*/
public static <T> T convert(Map<String, Object> map, Class<T> beanClass) {
if (MapUtil.isEmpty(map)) {
return null;
}
if (ObjectUtil.isNull(beanClass)) {
return null;
}
return CONVERTER.convert(map, beanClass);
}
}
package com.dsk.common.utils;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import java.util.Random;
/**
* 密码工具类
*
* @author sxk
* @date 2023.08.31
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class PasswordUtils {
private static final String LOWER_CASE = "abcdefghijklmnopqrstuvwxyz";
private static final String UPPER_CASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private static final String NUMBERS = "0123456789";
/**
* 生成随机密码
* @param length 密码长度
* @return 新生成的密码
*/
public static String generatePwd(int length) {
StringBuilder password = new StringBuilder();
Random random = new Random();
// 至少包含一个小写字母
password.append(LOWER_CASE.charAt(random.nextInt(LOWER_CASE.length())));
// 至少包含一个大写字母
password.append(UPPER_CASE.charAt(random.nextInt(UPPER_CASE.length())));
// 至少包含一个数字
password.append(NUMBERS.charAt(random.nextInt(NUMBERS.length())));
// 生成剩余部分的密码
for (int i = 0; i < length - 3; i++) {
String characters = LOWER_CASE + UPPER_CASE + NUMBERS;
password.append(characters.charAt(random.nextInt(characters.length())));
}
// 打乱密码中字符的顺序
return shufflePassword(password.toString());
}
public static String shufflePassword(String password) {
char[] passwordArray = password.toCharArray();
Random random = new Random();
for (int i = passwordArray.length - 1; i > 0; i--) {
int index = random.nextInt(i + 1);
char temp = passwordArray[index];
passwordArray[index] = passwordArray[i];
passwordArray[i] = temp;
}
return new String(passwordArray);
}
}
package com.dsk.common.utils.file;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
/**
* 文件类型工具类
*
* @author dsk
*/
public class FileTypeUtils
{
/**
* 获取文件类型
* <p>
* 例如: dsk.txt, 返回: txt
*
* @param file 文件名
* @return 后缀(不含".")
*/
public static String getFileType(File file)
{
if (null == file)
{
return StringUtils.EMPTY;
}
return getFileType(file.getName());
}
/**
* 获取文件类型
* <p>
* 例如: dsk.txt, 返回: txt
*
* @param fileName 文件名
* @return 后缀(不含".")
*/
public static String getFileType(String fileName)
{
int separatorIndex = fileName.lastIndexOf(".");
if (separatorIndex < 0)
{
return "";
}
return fileName.substring(separatorIndex + 1).toLowerCase();
}
/**
* 获取文件类型
*
* @param photoByte 文件字节码
* @return 后缀(不含".")
*/
public static String getFileExtendName(byte[] photoByte)
{
String strFileExtendName = "JPG";
if ((photoByte[0] == 71) && (photoByte[1] == 73) && (photoByte[2] == 70) && (photoByte[3] == 56)
&& ((photoByte[4] == 55) || (photoByte[4] == 57)) && (photoByte[5] == 97))
{
strFileExtendName = "GIF";
}
else if ((photoByte[6] == 74) && (photoByte[7] == 70) && (photoByte[8] == 73) && (photoByte[9] == 70))
{
strFileExtendName = "JPG";
}
else if ((photoByte[0] == 66) && (photoByte[1] == 77))
{
strFileExtendName = "BMP";
}
else if ((photoByte[1] == 80) && (photoByte[2] == 78) && (photoByte[3] == 71))
{
strFileExtendName = "PNG";
}
return strFileExtendName;
}
}
package com.dsk.common.utils.file;
import com.dsk.common.exception.file.FileNameLengthLimitExceededException;
import com.dsk.common.exception.file.FileSizeLimitExceededException;
import com.dsk.common.exception.file.InvalidExtensionException;
import com.dsk.common.utils.DateUtils;
import com.dsk.common.utils.StringUtils;
import com.dsk.common.utils.uuid.Seq;
import org.apache.commons.io.FilenameUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Objects;
/**
* 文件上传工具类
*
* @author dsk
*/
public class FileUploadUtils
{
/**
* 默认大小 50M
*/
public static final long DEFAULT_MAX_SIZE = 50 * 1024 * 1024;
/**
* 默认的文件名最大长度 100
*/
public static final int DEFAULT_FILE_NAME_LENGTH = 100;
/**
* 默认上传的地址
*/
private static String defaultBaseDir = "/home/server/dsk-operate-sys/uploadPath/";
/**
* 资源映射路径 前缀
*/
public static final String RESOURCE_PREFIX = "/profile";
public static void setDefaultBaseDir(String defaultBaseDir)
{
FileUploadUtils.defaultBaseDir = defaultBaseDir;
}
public static String getDefaultBaseDir()
{
return defaultBaseDir;
}
/**
* 以默认配置进行文件上传
*
* @param file 上传的文件
* @return 文件名称
* @throws Exception
*/
public static final String upload(MultipartFile file) throws IOException
{
try
{
return upload(getDefaultBaseDir(), file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
}
catch (Exception e)
{
throw new IOException(e.getMessage(), e);
}
}
/**
* 根据文件路径上传
*
* @param baseDir 相对应用的基目录
* @param file 上传的文件
* @return 文件名称
* @throws IOException
*/
public static final String upload(String baseDir, MultipartFile file) throws IOException
{
try
{
return upload(baseDir, file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
}
catch (Exception e)
{
throw new IOException(e.getMessage(), e);
}
}
/**
* 文件上传
*
* @param baseDir 相对应用的基目录
* @param file 上传的文件
* @param allowedExtension 上传文件类型
* @return 返回上传成功的文件名
* @throws FileSizeLimitExceededException 如果超出最大大小
* @throws FileNameLengthLimitExceededException 文件名太长
* @throws IOException 比如读写文件出错时
*/
public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension)
throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException
{
int fileNamelength = Objects.requireNonNull(file.getOriginalFilename()).length();
if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH)
{
throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
}
assertAllowed(file, allowedExtension);
// String fileName = extractFilename(file);
// String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath();
String absPath = getAbsoluteFile(baseDir, file.getOriginalFilename()).getAbsolutePath();
file.transferTo(Paths.get(absPath));
// return getPathFileName(baseDir, fileName);
return baseDir+file.getOriginalFilename();
}
/**
* 编码文件名
*/
public static final String extractFilename(MultipartFile file)
{
return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(),
FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), getExtension(file));
}
public static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException
{
File desc = new File(uploadDir + File.separator + fileName);
if (!desc.exists())
{
if (!desc.getParentFile().exists())
{
desc.getParentFile().mkdirs();
}
}
return desc;
}
public static final String getPathFileName(String uploadDir, String fileName) throws IOException
{
int dirLastIndex = getDefaultBaseDir().length() + 1;
String currentDir = StringUtils.substring(uploadDir, dirLastIndex);
return RESOURCE_PREFIX + "/" + currentDir + "/" + fileName;
}
/**
* 文件大小校验
*
* @param file 上传的文件
* @return
* @throws FileSizeLimitExceededException 如果超出最大大小
*/
public static final void assertAllowed(MultipartFile file, String[] allowedExtension)
throws FileSizeLimitExceededException, InvalidExtensionException
{
long size = file.getSize();
if (size > DEFAULT_MAX_SIZE)
{
throw new FileSizeLimitExceededException(DEFAULT_MAX_SIZE / 1024 / 1024);
}
String fileName = file.getOriginalFilename();
String extension = getExtension(file);
if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension))
{
if (allowedExtension == MimeTypeUtils.IMAGE_EXTENSION)
{
throw new InvalidExtensionException.InvalidImageExtensionException(allowedExtension, extension,
fileName);
}
else if (allowedExtension == MimeTypeUtils.FLASH_EXTENSION)
{
throw new InvalidExtensionException.InvalidFlashExtensionException(allowedExtension, extension,
fileName);
}
else if (allowedExtension == MimeTypeUtils.MEDIA_EXTENSION)
{
throw new InvalidExtensionException.InvalidMediaExtensionException(allowedExtension, extension,
fileName);
}
else if (allowedExtension == MimeTypeUtils.VIDEO_EXTENSION)
{
throw new InvalidExtensionException.InvalidVideoExtensionException(allowedExtension, extension,
fileName);
}
else
{
throw new InvalidExtensionException(allowedExtension, extension, fileName);
}
}
}
/**
* 判断MIME类型是否是允许的MIME类型
*
* @param extension
* @param allowedExtension
* @return
*/
public static final boolean isAllowedExtension(String extension, String[] allowedExtension)
{
for (String str : allowedExtension)
{
if (str.equalsIgnoreCase(extension))
{
return true;
}
}
return false;
}
/**
* 获取文件名的后缀
*
* @param file 表单文件
* @return 后缀名
*/
public static final String getExtension(MultipartFile file)
{
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
if (StringUtils.isEmpty(extension))
{
extension = MimeTypeUtils.getExtension(Objects.requireNonNull(file.getContentType()));
}
return extension;
}
}
......@@ -37,4 +37,22 @@ public class MimeTypeUtils {
// pdf
"pdf"};
public static String getExtension(String prefix)
{
switch (prefix)
{
case IMAGE_PNG:
return "png";
case IMAGE_JPG:
return "jpg";
case IMAGE_JPEG:
return "jpeg";
case IMAGE_BMP:
return "bmp";
case IMAGE_GIF:
return "gif";
default:
return "";
}
}
}
package com.dsk.common.utils.uuid;
/**
* ID生成器工具类
*
* @author dsk
*/
public class IdUtils
{
/**
* 获取随机UUID
*
* @return 随机UUID
*/
public static String randomUUID()
{
return UUID.randomUUID().toString();
}
/**
* 简化的UUID,去掉了横线
*
* @return 简化的UUID,去掉了横线
*/
public static String simpleUUID()
{
return UUID.randomUUID().toString(true);
}
/**
* 获取随机UUID,使用性能更好的ThreadLocalRandom生成UUID
*
* @return 随机UUID
*/
public static String fastUUID()
{
return UUID.fastUUID().toString();
}
/**
* 简化的UUID,去掉了横线,使用性能更好的ThreadLocalRandom生成UUID
*
* @return 简化的UUID,去掉了横线
*/
public static String fastSimpleUUID()
{
return UUID.fastUUID().toString(true);
}
}
package com.dsk.common.utils.uuid;
import com.dsk.common.utils.DateUtils;
import com.dsk.common.utils.StringUtils;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author dsk 序列生成类
*/
public class Seq
{
// 通用序列类型
public static final String commSeqType = "COMMON";
// 上传序列类型
public static final String uploadSeqType = "UPLOAD";
// 通用接口序列数
private static AtomicInteger commSeq = new AtomicInteger(1);
// 上传接口序列数
private static AtomicInteger uploadSeq = new AtomicInteger(1);
// 机器标识
private static final String machineCode = "A";
/**
* 获取通用序列号
*
* @return 序列值
*/
public static String getId()
{
return getId(commSeqType);
}
/**
* 默认16位序列号 yyMMddHHmmss + 一位机器标识 + 3长度循环递增字符串
*
* @return 序列值
*/
public static String getId(String type)
{
AtomicInteger atomicInt = commSeq;
if (uploadSeqType.equals(type))
{
atomicInt = uploadSeq;
}
return getId(atomicInt, 3);
}
/**
* 通用接口序列号 yyMMddHHmmss + 一位机器标识 + length长度循环递增字符串
*
* @param atomicInt 序列数
* @param length 数值长度
* @return 序列值
*/
public static String getId(AtomicInteger atomicInt, int length)
{
String result = DateUtils.dateTimeNow();
result += machineCode;
result += getSeq(atomicInt, length);
return result;
}
/**
* 序列循环递增字符串[1, 10 的 (length)幂次方), 用0左补齐length位数
*
* @return 序列值
*/
private synchronized static String getSeq(AtomicInteger atomicInt, int length)
{
// 先取值再+1
int value = atomicInt.getAndIncrement();
// 如果更新后值>=10 的 (length)幂次方则重置为1
int maxSeq = (int) Math.pow(10, length);
if (atomicInt.get() >= maxSeq)
{
atomicInt.set(1);
}
// 转字符串,用0左补齐
return StringUtils.padl(value, length);
}
}
This diff is collapsed.
......@@ -2,13 +2,13 @@ package com.dsk.biz.controller;
import com.dsk.biz.domain.bo.BusinessIdDto;
import com.dsk.biz.domain.vo.BusinessFileVo;
import com.dsk.biz.utils.OldFileUtils;
import com.dsk.common.core.controller.BaseController;
import com.dsk.common.core.domain.AjaxResult;
import com.dsk.common.core.page.TableDataInfo;
import com.dsk.common.utils.StringUtils;
import com.dsk.common.utils.file.FileUtils;
import com.dsk.common.utils.file.FileUploadUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
......@@ -30,90 +30,87 @@ import java.util.stream.Collectors;
@RequestMapping("/business/file")
public class BusinessFileController extends BaseController {
// @Autowired
// private ServerConfig serverConfig;
//
// /**
// * 新建文件夹
// */
//// @PreAuthorize("@ss.hasPermi('system:file:add')")
//// @Log(title = "项目资料文档", businessType = BusinessType.INSERT)
// @PostMapping("/new")
// public AjaxResult newFolder(@RequestBody(required=false) BusinessIdDto filePath) {
// return FileUtils.newFolder(filePath.getFilePath()) ? AjaxResult.success() : AjaxResult.error();
// }
//
// /**
// * 删除某个文件或整个文件夹
// */
// @PostMapping("/remove")
// public AjaxResult removeFile(@RequestBody(required=false) BusinessIdDto filePath) {
// return FileUtils.delFolder(filePath.getFilePath()) ? AjaxResult.success() : AjaxResult.error();
// }
//
// /**
// * 分页查询项目的所有文件
// * 获取文件夹中所有文件
// */
// @GetMapping(value = "/list")
// public TableDataInfo getAllFiles(BusinessIdDto filePath) {
// startPage();
// List<BusinessFileVo> allFiles;
// if(StringUtils.isNumeric(filePath.getFilePath())) filePath.setFilePath(ShuZhiHuaConfig.getProfile() + filePath.getFilePath());
// allFiles = FileUtils.getAllFiles(filePath.getFilePath());
// //模糊查询文件
// if(StringUtils.isNotEmpty(filePath.getKeyword())){
// List<BusinessFileVo> allFileName = FileUtils.getAllFileNames(filePath.getFilePath());
// allFiles = allFileName.stream().filter(p -> p.getFilePath().contains(filePath.getKeyword())).collect(Collectors.toList());
// }
// //文件按照时间倒序
// allFiles = allFiles.stream().sorted(Comparator.comparing(BusinessFileVo::getCreatTime).reversed()).collect(Collectors.toList());
// return getDataTable(allFiles);
// }
//
// /**
// * 上传文件及文件夹
// * @param file 文件流
// * @param request 请求头参数
// * @return
// */
// @PostMapping("/upload")
// public AjaxResult uploadFolder(@RequestPart("file") MultipartFile file, HttpServletRequest request) {
// try {
// //获取文件名
// String filename = file.getOriginalFilename();
// String businessFileName = request.getHeader("FilePath");
// // 上传文件路径
// String filePath = ShuZhiHuaConfig.getUploadPath() + businessFileName + "/";
//
// //校验是否上传同名文件
// File newFile = new File(filePath);
// if (newFile.exists()) {
// // 获取当前目录下的文件和文件夹
// File[] files = newFile.listFiles();
// for (File allFile : files) {
// if (filename.equals(allFile.getName())) return error("文件已存在");
// }
// }
//
// // 上传并返回文件全路径
// String fileName = FileUploadUtils.upload(filePath, file);
//// String url = serverConfig.getUrl() + fileName;
// AjaxResult ajax = AjaxResult.success();
// ajax.put("url", fileName);
// return ajax;
// } catch (IOException e) {
// return AjaxResult.error(e.getMessage());
// }
// }
//
// /**
// * 下载文件
// * @param filePath 要下载的文件路径
// * @param response 返回的响应
// */
// @PostMapping("/download")
// public void downloadFolder(@RequestBody BusinessIdDto filePath, HttpServletResponse response) {
// FileUtils.downloadByFilePath(filePath.getFilePath(),response);
// }
/**
* 新建文件夹
*/
// @PreAuthorize("@ss.hasPermi('system:file:add')")
// @Log(title = "项目资料文档", businessType = BusinessType.INSERT)
@PostMapping("/new")
public AjaxResult newFolder(@RequestBody(required=false) BusinessIdDto filePath) {
return OldFileUtils.newFolder(filePath.getFilePath()) ? AjaxResult.success() : AjaxResult.error();
}
/**
* 删除某个文件或整个文件夹
*/
@PostMapping("/remove")
public AjaxResult removeFile(@RequestBody(required=false) BusinessIdDto filePath) {
return OldFileUtils.delFolder(filePath.getFilePath()) ? AjaxResult.success() : AjaxResult.error();
}
/**
* 分页查询项目的所有文件
* 获取文件夹中所有文件
*/
@GetMapping(value = "/list")
public TableDataInfo getAllFiles(BusinessIdDto filePath) {
List<BusinessFileVo> allFiles;
if(StringUtils.isNumeric(filePath.getFilePath())) filePath.setFilePath(FileUploadUtils.getDefaultBaseDir() + filePath.getFilePath());
allFiles = OldFileUtils.getAllFiles(filePath.getFilePath());
//模糊查询文件
if(StringUtils.isNotEmpty(filePath.getKeyword())){
List<BusinessFileVo> allFileName = OldFileUtils.getAllFileNames(filePath.getFilePath());
allFiles = allFileName.stream().filter(p -> p.getFilePath().contains(filePath.getKeyword())).collect(Collectors.toList());
}
//文件按照时间倒序
allFiles = allFiles.stream().sorted(Comparator.comparing(BusinessFileVo::getCreatTime).reversed()).collect(Collectors.toList());
return TableDataInfo.build(allFiles);
}
/**
* 上传文件及文件夹
* @param file 文件流
* @param request 请求头参数
* @return
*/
@PostMapping("/upload")
public AjaxResult uploadFolder(@RequestPart("file") MultipartFile file, HttpServletRequest request) {
try {
//获取文件名
String filename = file.getOriginalFilename();
String businessFileName = request.getHeader("FilePath");
// 上传文件路径
String filePath = FileUploadUtils.getDefaultBaseDir() + businessFileName + "/";
//校验是否上传同名文件
File newFile = new File(filePath);
if (newFile.exists()) {
// 获取当前目录下的文件和文件夹
File[] files = newFile.listFiles();
for (File allFile : files) {
if (filename.equals(allFile.getName())) return AjaxResult.error("文件已存在");
}
}
// 上传并返回文件全路径
String fileName = FileUploadUtils.upload(filePath, file);
// String url = serverConfig.getUrl() + fileName;
AjaxResult ajax = AjaxResult.success();
ajax.put("url", fileName);
return ajax;
} catch (IOException e) {
return AjaxResult.error(e.getMessage());
}
}
/**
* 下载文件
* @param filePath 要下载的文件路径
* @param response 返回的响应
*/
@PostMapping("/download")
public void downloadFolder(@RequestBody BusinessIdDto filePath, HttpServletResponse response) {
OldFileUtils.downloadByFilePath(filePath.getFilePath(),response);
}
}
......@@ -44,7 +44,7 @@ public class CustomerController extends BaseController {
/**
* 查询客户列表
*/
@SaCheckPermission("'customer:list')")
// @SaCheckPermission("'customer:list')")
@GetMapping("/list")
public TableDataInfo<CustomerListVo> selectPageList(CustomerSearchDto dto , PageQuery pageQuery) {
return baseService.selectList(dto,pageQuery);
......@@ -53,7 +53,7 @@ public class CustomerController extends BaseController {
/**
* 客户详情
*/
@SaCheckPermission("'customer:info')")
// @SaCheckPermission("'customer:info')")
@GetMapping("/{customerId}")
public R<CustomerVo> info(@PathVariable("customerId") String customerId) {
return R.ok(baseService.info(customerId));
......@@ -62,7 +62,7 @@ public class CustomerController extends BaseController {
/**
* 添加客户
*/
@SaCheckPermission("'customer:add')")
// @SaCheckPermission("'customer:add')")
@PostMapping()
@RepeatSubmit
public R<Void> add(@RequestBody Customer customer) {
......@@ -89,7 +89,7 @@ public class CustomerController extends BaseController {
/**
* 编辑客户
*/
@SaCheckPermission("'customer:edit'")
// @SaCheckPermission("'customer:edit'")
@PutMapping()
@RepeatSubmit
public R<Void> edit(@RequestBody Customer customer) {
......
......@@ -123,6 +123,10 @@ public class Customer implements Serializable {
* 其它管理体系特点
*/
private String otherMsCharacteistic;
/**
* 租户编号
*/
private String tenantId;
private Long createId;
......
......@@ -53,10 +53,10 @@ public interface BusinessInfoMapper extends BaseMapper<BusinessInfo> {
* @return 项目详情集合
*/
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "userName", value = "u.user_id")
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "userName", value = "u.user_id")
})
public Page<BusinessListVo> selectBusinessInfoList(@Param("page") Page<BusinessListVo> page,@Param("dto") BusinessListDto dto);
Page<BusinessListVo> selectBusinessInfoList(@Param("page") IPage<BusinessListDto> page, @Param("dto") BusinessListDto dto);
/**
* 新增项目详情
......@@ -114,12 +114,28 @@ public interface BusinessInfoMapper extends BaseMapper<BusinessInfo> {
Page<CustomerBusinessListVo> selectCustomerBusinessList(IPage<CustomerBusinessSearchDto> page,@Param("dto") CustomerBusinessSearchDto dto);
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "userName", value = "u.user_id")
})
int selectCountByStatus(BusinessSearchDto dto);
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "userName", value = "u.user_id")
})
List<BusinessAnalyzeVo> selectAmountAnalyze(BusinessSearchDto dto);
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "userName", value = "u.user_id")
})
List<BusinessAnalyzeVo> selectTypeAnalyze(BusinessSearchDto dto);
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "userName", value = "u.user_id")
})
List<BusinessAnalyzeVo> selectCategoryAnalyze(BusinessSearchDto dto);
}
......@@ -11,6 +11,8 @@ import com.dsk.biz.domain.bo.BusinessExcelDto;
import com.dsk.biz.domain.bo.BusinessListDto;
import com.dsk.biz.domain.bo.CustomerBusinessSearchDto;
import com.dsk.biz.domain.vo.*;
import com.dsk.common.annotation.DataColumn;
import com.dsk.common.annotation.DataPermission;
import com.dsk.jsk.service.EnterpriseService;
import com.dsk.biz.mapper.BusinessInfoMapper;
import com.dsk.biz.mapper.BusinessLabelMapper;
......@@ -92,15 +94,14 @@ public class BusinessInfoServiceImpl implements IBusinessInfoService {
@Override
public TableDataInfo<BusinessListVo> selectBusinessInfoList(BusinessListDto dto, PageQuery pageQuery) {
dto.setUserId(LoginHelper.getUserId());
Page<BusinessListVo> page = businessInfoMapper.selectBusinessInfoList(pageQuery.build(), dto);
List<BusinessListVo> businessListVos = page.getRecords();
if (!CollectionUtils.isEmpty(businessListVos) && ObjectUtil.isNotEmpty(dto.getProjectName())) {
for (BusinessListVo vo : businessListVos) {
TableDataInfo<BusinessListVo> result = TableDataInfo.build(businessInfoMapper.selectBusinessInfoList(pageQuery.build(), dto));
if (!CollectionUtils.isEmpty(result.getRows()) && ObjectUtil.isNotEmpty(dto.getProjectName())) {
for (BusinessListVo vo : result.getRows()) {
vo.setProjectName(StringUtils.markInRed(vo.getProjectName(), dto.getProjectName()));
vo.setOwnerCompany(StringUtils.markInRed(vo.getOwnerCompany(), dto.getProjectName()));
}
}
return TableDataInfo.build(page);
return result;
}
......@@ -255,7 +256,7 @@ public class BusinessInfoServiceImpl implements IBusinessInfoService {
businessInfo.setConstructionUnitUipId(vo.getUipId());
businessInfo.setConstructionUnitCid(vo.getCompanyId());
businessInfo.setConstructionPrincipal(vo.getLegalPerson());
businessInfo.setTenantId(LoginHelper.getTenantId());
int addBusiness = businessInfoMapper.insertBusinessInfo(businessInfo);
if (addBusiness > 0) {
//获取登陆用户的部门id
......
......@@ -31,10 +31,6 @@ public class BusinessOverviewServiceImpl implements IBusinessOverviewService {
private DskOpenApiUtil dskOpenApiUtil;
@Override
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "userName", value = "u.user_id")
})
public Map<String, Object> statusStatistics(BusinessSearchDto dto) {
Map<String, Object> resultMap = new HashMap<>();
//总
......@@ -52,28 +48,16 @@ public class BusinessOverviewServiceImpl implements IBusinessOverviewService {
}
@Override
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "userName", value = "u.user_id")
})
public List<BusinessAnalyzeVo> amountAnalyze(BusinessSearchDto dto) {
return businessInfoMapper.selectAmountAnalyze(dto);
}
@Override
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "userName", value = "u.user_id")
})
public List<BusinessAnalyzeVo> typeAnalyze(BusinessSearchDto dto) {
return businessInfoMapper.selectTypeAnalyze(dto);
}
@Override
@DataPermission({
@DataColumn(key = "deptName", value = "d.dept_id"),
@DataColumn(key = "userName", value = "u.user_id")
})
public List<BusinessAnalyzeVo> categoryAnalyze(BusinessSearchDto dto) {
return businessInfoMapper.selectCategoryAnalyze(dto);
}
......
......@@ -61,7 +61,7 @@ public class CustomerServiceImpl implements ICustomerService {
dto.setUserId(LoginHelper.getUserId());
dto.setStatus(ObjectUtils.isEmpty(dto.getStatus()) ? 0 : dto.getStatus());
final TableDataInfo<CustomerListVo> result = TableDataInfo.build(baseMapper.selectList(pageQuery.build(), dto));
if(!ObjectUtils.isEmpty(result.getRows())){
if(!ObjectUtils.isEmpty(result.getRows()) && !ObjectUtils.isEmpty(dto.getCompanyName())){
for (CustomerListVo vo : result.getRows()) {
vo.setCompanyName(StringUtils.markInRed(vo.getCompanyName(), dto.getCompanyName()));
}
......@@ -87,6 +87,7 @@ public class CustomerServiceImpl implements ICustomerService {
Long userId = LoginHelper.getUserId();
customer.setCreateId(userId);
customer.setUpdateId(userId);
customer.setTenantId(LoginHelper.getTenantId());
//查重
Customer verifyCustomer = baseMapper.selectByCompanyNameAndUserId(customer.getCompanyName(), userId);
if (!ObjectUtils.isEmpty(verifyCustomer)) {
......
......@@ -96,13 +96,13 @@
i.construction_unit ownerCompany,
i.construction_unit_uip_id ownerCompanyUipId,
i.construction_unit_cid ownerCompanyCid,
<!-- MAX(f.creat_time) followTime,-->
u.nick_name nickName
<!-- GROUP_CONCAT(DISTINCT l.label) label-->
MAX(f.creat_time) followTime,
u.nick_name nickName,
GROUP_CONCAT(DISTINCT l.label) label
FROM business_info i
LEFT JOIN business_user bu on bu.business_id = i.id
<!-- LEFT JOIN business_follow_record f on f.business_id = i.id-->
<!-- LEFT JOIN business_label l on l.business_id = i.id-->
LEFT JOIN business_follow_record f on f.business_id = i.id
LEFT JOIN business_label l on l.business_id = i.id
LEFT JOIN sys_user u on u.user_id = bu.user_id
LEFT JOIN sys_dept d on d.dept_id = u.dept_id
<where>
......@@ -146,7 +146,7 @@
<choose>
<when test="dto.isPrivate == 1"> and bu.user_id = #{dto.userId} </when>
<!-- 数据范围过滤 -->
<otherwise> and (bu.user_id = #{dto.userId} or i.is_private = 1) ${params.dataScope} </otherwise>
<otherwise> and (bu.user_id = #{dto.userId} or i.is_private = 1) ${dto.params.dataScope} </otherwise>
</choose>
</where>
GROUP BY i.id
......@@ -223,6 +223,7 @@
<if test="supervisorPhone != null">supervisor_phone,</if>
<if test="constructionUnitUipId != null">construction_unit_uip_id,</if>
<if test="constructionUnitCid != null">construction_unit_cid,</if>
tenant_id
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="projectName != null">#{projectName},</if>
......@@ -262,6 +263,7 @@
<if test="supervisorPhone != null">#{supervisorPhone},</if>
<if test="constructionUnitUipId != null">#{constructionUnitUipId},</if>
<if test="constructionUnitCid != null">#{constructionUnitCid},</if>
#{tenantId}
</trim>
</insert>
......
......@@ -21,8 +21,7 @@
<if test="dto.startTime != null and dto.startTime != '' "> and cfr.visit_time &gt;= #{dto.startTime} </if>
<if test="dto.endTime != null and dto.endTime != '' "> and cfr.visit_time &lt;= #{dto.endTime} </if>
<!-- 数据范围过滤 -->
<if test="ew.getCustomSqlSegment != null and ew.getCustomSqlSegment != '' "> ${ew.getCustomSqlSegment}</if>
<if test="dto.params.dataScope != null and params.dataScope != '' "> ${dto.params.dataScope}</if>
<if test="dto.params.dataScope != null and dto.params.dataScope != '' "> ${dto.params.dataScope}</if>
</where>
order by cfr.visit_time desc
</select>
......
package com.dsk.system.domain.vo;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.dsk.common.annotation.ExcelDictFormat;
import com.dsk.common.convert.ExcelDictConvert;
import com.dsk.common.tenant.core.TenantEntity;
import com.dsk.system.domain.SysDept;
import com.dsk.system.domain.SysTenantPackage;
import com.sun.org.apache.xpath.internal.operations.Bool;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
/**
* 部门表 sys_dept
*
* @author Lion Li
*/
@Data
@ExcelIgnoreUnannotated
@AutoMapper(target = SysDept.class)
public class SysDeptVo implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 部门ID
*/
@ExcelProperty(value = "部门id")
private Long deptId;
/**
* 父部门ID
*/
@ExcelProperty(value = "父部门id")
private Long parentId;
/**
* 部门名称
*/
@ExcelProperty(value = "部门名称")
private String deptName;
/**
* 显示顺序
*/
@ExcelProperty(value = "显示顺序")
private Integer orderNum;
/**
* 负责人
*/
@ExcelProperty(value = "负责人")
private String leader;
/**
* 联系电话
*/
@ExcelProperty(value = "联系电话")
private String phone;
/**
* 邮箱
*/
@ExcelProperty(value = "邮箱")
private String email;
/**
* 部门状态:0正常,1停用
*/
@ExcelProperty(value = "部门状态", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=正常,1=停用")
private String status;
/**
* 删除标志(0代表存在 2代表删除)
*/
@ExcelProperty(value = "删除标志", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=存在,2=删除")
private String delFlag;
/**
* 祖级列表
*/
@ExcelProperty(value = "祖级列表")
private String ancestors;
private String parentName;
/**
* 该部门是否存在用户(true代表存在 false代表不存在)
*/
@ExcelProperty(value = "该部门是否存在用户", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "true=存在,false=删除")
private Boolean existUsers;
}
......@@ -17,6 +17,7 @@ import com.dsk.common.core.domain.entity.SysDictType;
import com.dsk.common.core.page.TableDataInfo;
import com.dsk.common.exception.ServiceException;
import com.dsk.common.utils.DingTalkUtil;
import com.dsk.common.utils.PasswordUtils;
import com.dsk.common.utils.StringUtils;
import com.dsk.system.domain.*;
import com.dsk.system.domain.bo.SysTenantBo;
......@@ -33,7 +34,6 @@ import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;
/**
* @author sxk
......@@ -186,7 +186,7 @@ public class ISysTenantServiceImpl implements ISysTenantService {
user.setUserName(bo.getContactPhone());
user.setNickName(bo.getContactUserName());
//生成8位随机密码
String password = generatePassword(8);
String password = PasswordUtils.generatePwd(8);
user.setPassword(BCrypt.hashpw(password));
user.setDeptId(deptId);
userMapper.insert(user);
......@@ -238,20 +238,6 @@ public class ISysTenantServiceImpl implements ISysTenantService {
return true;
}
// 生成随机密码
public static String generatePassword(int length) {
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
StringBuilder password = new StringBuilder();
Random random = new Random();
for (int i = 0; i < length; i++) {
int index = random.nextInt(characters.length());
password.append(characters.charAt(index));
}
return password.toString();
}
/**
* 生成租户id
*
......
......@@ -31,6 +31,7 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* 部门管理 服务实现
......@@ -55,12 +56,12 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
public List<SysDept> selectDeptList(SysDept dept) {
LambdaQueryWrapper<SysDept> lqw = new LambdaQueryWrapper<>();
lqw.eq(SysDept::getDelFlag, "0")
.eq(ObjectUtil.isNotNull(dept.getDeptId()), SysDept::getDeptId, dept.getDeptId())
.eq(ObjectUtil.isNotNull(dept.getParentId()), SysDept::getParentId, dept.getParentId())
.like(StringUtils.isNotBlank(dept.getDeptName()), SysDept::getDeptName, dept.getDeptName())
.eq(StringUtils.isNotBlank(dept.getStatus()), SysDept::getStatus, dept.getStatus())
.orderByAsc(SysDept::getParentId)
.orderByAsc(SysDept::getOrderNum);
.eq(ObjectUtil.isNotNull(dept.getDeptId()), SysDept::getDeptId, dept.getDeptId())
.eq(ObjectUtil.isNotNull(dept.getParentId()), SysDept::getParentId, dept.getParentId())
.like(StringUtils.isNotBlank(dept.getDeptName()), SysDept::getDeptName, dept.getDeptName())
.eq(StringUtils.isNotBlank(dept.getStatus()), SysDept::getStatus, dept.getStatus())
.orderByAsc(SysDept::getParentId)
.orderByAsc(SysDept::getOrderNum);
return baseMapper.selectDeptList(lqw);
}
......@@ -88,10 +89,10 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
return CollUtil.newArrayList();
}
return TreeBuildUtils.build(depts, (dept, tree) ->
tree.setId(dept.getDeptId())
.setParentId(dept.getParentId())
.setName(dept.getDeptName())
.setWeight(dept.getOrderNum()));
tree.setId(dept.getDeptId())
.setParentId(dept.getParentId())
.setName(dept.getDeptName())
.setWeight(dept.getOrderNum()));
}
/**
......@@ -120,7 +121,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
return null;
}
SysDept parentDept = baseMapper.selectOne(new LambdaQueryWrapper<SysDept>()
.select(SysDept::getDeptName).eq(SysDept::getDeptId, dept.getParentId()));
.select(SysDept::getDeptName).eq(SysDept::getDeptId, dept.getParentId()));
dept.setParentName(ObjectUtil.isNotNull(parentDept) ? parentDept.getDeptName() : null);
return dept;
}
......@@ -152,8 +153,8 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
@Override
public long selectNormalChildrenDeptById(Long deptId) {
return baseMapper.selectCount(new LambdaQueryWrapper<SysDept>()
.eq(SysDept::getStatus, UserConstants.DEPT_NORMAL)
.apply(DataBaseHelper.findInSet(deptId, "ancestors")));
.eq(SysDept::getStatus, UserConstants.DEPT_NORMAL)
.apply(DataBaseHelper.findInSet(deptId, "ancestors")));
}
/**
......@@ -165,7 +166,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
@Override
public boolean hasChildByDeptId(Long deptId) {
return baseMapper.exists(new LambdaQueryWrapper<SysDept>()
.eq(SysDept::getParentId, deptId));
.eq(SysDept::getParentId, deptId));
}
/**
......@@ -177,7 +178,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
@Override
public boolean checkDeptExistUser(Long deptId) {
return userMapper.exists(new LambdaQueryWrapper<SysUser>()
.eq(SysUser::getDeptId, deptId));
.eq(SysUser::getDeptId, deptId));
}
/**
......@@ -189,9 +190,9 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
@Override
public boolean checkDeptNameUnique(SysDept dept) {
boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysDept>()
.eq(SysDept::getDeptName, dept.getDeptName())
.eq(SysDept::getParentId, dept.getParentId())
.ne(ObjectUtil.isNotNull(dept.getDeptId()), SysDept::getDeptId, dept.getDeptId()));
.eq(SysDept::getDeptName, dept.getDeptName())
.eq(SysDept::getParentId, dept.getParentId())
.ne(ObjectUtil.isNotNull(dept.getDeptId()), SysDept::getDeptId, dept.getDeptId()));
return !exist;
}
......@@ -248,7 +249,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
}
int result = baseMapper.updateById(dept);
if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())
&& !StringUtils.equals(UserConstants.DEPT_NORMAL, dept.getAncestors())) {
&& !StringUtils.equals(UserConstants.DEPT_NORMAL, dept.getAncestors())) {
// 如果该部门是启用状态,则启用该部门的所有上级部门
updateParentDeptStatusNormal(dept);
}
......@@ -264,8 +265,8 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
String ancestors = dept.getAncestors();
Long[] deptIds = Convert.toLongArray(ancestors);
baseMapper.update(null, new LambdaUpdateWrapper<SysDept>()
.set(SysDept::getStatus, UserConstants.DEPT_NORMAL)
.in(SysDept::getDeptId, Arrays.asList(deptIds)));
.set(SysDept::getStatus, UserConstants.DEPT_NORMAL)
.in(SysDept::getDeptId, Arrays.asList(deptIds)));
}
/**
......@@ -277,7 +278,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
*/
public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) {
List<SysDept> children = baseMapper.selectList(new LambdaQueryWrapper<SysDept>()
.apply(DataBaseHelper.findInSet(deptId, "ancestors")));
.apply(DataBaseHelper.findInSet(deptId, "ancestors")));
List<SysDept> list = new ArrayList<>();
for (SysDept child : children) {
SysDept dept = new SysDept();
......@@ -301,7 +302,38 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
@CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#deptId")
@Override
public int deleteDeptById(Long deptId) {
//如果有子部门,递归删除部门和用户
if (hasChildByDeptId(deptId)) {
List<SysDept> childDepts = baseMapper.selectDeptList(new LambdaQueryWrapper<SysDept>()
.eq(SysDept::getParentId, deptId));
childDepts.forEach(childDept -> {
//如果该子部门有用户,则删除所有用户
checkDelUsers(childDept.getDeptId());
//递归调用
deleteDeptById(childDept.getDeptId());
});
}
//如果该部门有用户,则删除所有用户
checkDelUsers(deptId);
//删除该部门
return baseMapper.deleteById(deptId);
}
/**
* 判断该部门是否有用户,有则删除所有用户
*
* @param deptId 部门ID
*/
private int checkDelUsers(Long deptId) {
//如果该部门有用户
if (checkDeptExistUser(deptId)) {
List<SysUser> childUsers = userMapper.selectList(new LambdaQueryWrapper<SysUser>()
.eq(true, SysUser::getDeptId, deptId));
List<Long> childUsersIds = childUsers.stream().map(SysUser::getUserId).collect(Collectors.toList());
//删除该子部门下所有用户
return userMapper.deleteBatchIds(childUsersIds);
}
return -1;
}
}
package com.dsk.system.service.impl;
import cn.dev33.satoken.secure.BCrypt;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
......@@ -9,6 +10,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dsk.common.utils.DingTalkUtil;
import com.dsk.common.utils.PasswordUtils;
import com.dsk.system.mapper.*;
import com.dsk.system.service.ISysUserService;
import com.dsk.common.constant.CacheNames;
......@@ -270,8 +273,21 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
@Override
@Transactional(rollbackFor = Exception.class)
public int insertUser(SysUser user) {
String password = PasswordUtils.generatePwd(8);
user.setPassword(BCrypt.hashpw(password));
// 新增用户信息
int rows = baseMapper.insert(user);
if (rows>0) {
//租户新增成功,发送短信通知租户
//此处暂用钉钉机器人模拟发送短信
String content = "【央企数字经营管理系统通知】:"
+ user.getNickName()
+ "您好,您已经成功注册央企数字经营管理系统,请使用手机号码登录,初始密码为"
+ password
+ "。友情提示:为了您的账号安全,请立即前往【个人中心】修改密码。";
DingTalkUtil.sendDingTalkMsg(content);
System.out.println("👉🏻:" + content);
}
// 新增用户岗位关联
insertUserPost(user);
// 新增用户与角色管理
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment