mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 04:39:00 +08:00
🎨 Improving structure / format of the code.
This commit is contained in:
1 parent
1b0537c4dc
commit
079973c722
29 files changed
+410
-478
No files matched your search
+1
-1
@@ -99,7 +99,7 @@ public class MiniAppLoginHandler extends AbstractLoginHandler {
|
||||
}
|
||||
|
||||
private AppUserInfo createAndSaveAppUserInfo(String openId) {
|
||||
return appUserService.saveOrUpdateByLoginType(LoginTypeEnum.MINI_APP,openId);
|
||||
return appUserService.saveOrUpdateByLoginType(LoginTypeEnum.MINI_APP, openId);
|
||||
}
|
||||
|
||||
}
|
||||
+4
-4
@@ -55,7 +55,7 @@ public class AppMobileServiceImpl implements AppMobileService {
|
||||
@Override
|
||||
public R<Boolean> sendSmsCode(String mobile) {
|
||||
String codeObj = redisTemplate.opsForValue()
|
||||
.get(CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.APPSMS.getType() + StringPool.AT + mobile);
|
||||
.get(CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.APPSMS.getType() + StringPool.AT + mobile);
|
||||
|
||||
if (StrUtil.isNotBlank(codeObj)) {
|
||||
log.info("手机号验证码未过期:{},{}", mobile, codeObj);
|
||||
@@ -64,9 +64,9 @@ public class AppMobileServiceImpl implements AppMobileService {
|
||||
|
||||
String code = RandomUtil.randomNumbers(Integer.parseInt(SecurityConstants.CODE_SIZE));
|
||||
log.debug("手机号生成验证码成功:{},{}", mobile, code);
|
||||
redisTemplate.opsForValue()
|
||||
.set(CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.APPSMS.getType() + StringPool.AT + mobile, code,
|
||||
SecurityConstants.CODE_TIME, TimeUnit.SECONDS);
|
||||
redisTemplate.opsForValue().set(
|
||||
CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.APPSMS.getType() + StringPool.AT + mobile, code,
|
||||
SecurityConstants.CODE_TIME, TimeUnit.SECONDS);
|
||||
return R.ok(Boolean.TRUE, code);
|
||||
}
|
||||
|
||||
|
||||
-1
@@ -340,5 +340,4 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
||||
return appUserDTO;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+2
-5
@@ -50,11 +50,8 @@ public enum StyleTypeEnum {
|
||||
private String description;
|
||||
|
||||
public static String getDesc(String style) {
|
||||
return Arrays.stream(StyleTypeEnum.values())
|
||||
.filter(styleTypeEnum -> styleTypeEnum.getStyle().equals(style))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getDescription();
|
||||
return Arrays.stream(StyleTypeEnum.values()).filter(styleTypeEnum -> styleTypeEnum.getStyle().equals(style))
|
||||
.findFirst().get().getDescription();
|
||||
}
|
||||
|
||||
}
|
||||
+10
-10
@@ -13,16 +13,16 @@ import lombok.Getter;
|
||||
@AllArgsConstructor
|
||||
public enum YesNoEnum {
|
||||
|
||||
YES("1", "是"),
|
||||
NO("0", "否");
|
||||
YES("1", "是"), NO("0", "否");
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
private String code;
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String desc;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String desc;
|
||||
}
|
||||
-4
@@ -17,10 +17,7 @@
|
||||
package com.pig4cloud.pigx.common.log.event;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.TypeUtil;
|
||||
import com.fasterxml.jackson.annotation.JsonFilter;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ser.FilterProvider;
|
||||
@@ -41,7 +38,6 @@ import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.validation.BindingResult;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
+37
-39
@@ -42,49 +42,47 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
@RequiredArgsConstructor
|
||||
public class PigxDefaultUserDetailsServiceImpl implements PigxUserDetailsService {
|
||||
|
||||
private final RemoteUserService remoteUserService;
|
||||
private final RemoteUserService remoteUserService;
|
||||
|
||||
private final CacheManager cacheManager;
|
||||
private final CacheManager cacheManager;
|
||||
|
||||
/**
|
||||
* 用户密码登录
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return
|
||||
* @throws UsernameNotFoundException
|
||||
*/
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public UserDetails loadUserByUsername(String username) {
|
||||
Cache cache = cacheManager.getCache(CacheConstants.USER_DETAILS);
|
||||
if (cache != null && cache.get(username) != null) {
|
||||
return cache.get(username, PigxUser.class);
|
||||
}
|
||||
/**
|
||||
* 用户密码登录
|
||||
* @param username 用户名
|
||||
* @return
|
||||
* @throws UsernameNotFoundException
|
||||
*/
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public UserDetails loadUserByUsername(String username) {
|
||||
Cache cache = cacheManager.getCache(CacheConstants.USER_DETAILS);
|
||||
if (cache != null && cache.get(username) != null) {
|
||||
return cache.get(username, PigxUser.class);
|
||||
}
|
||||
|
||||
R<UserInfo> result = remoteUserService.info(username, SecurityConstants.FROM_IN);
|
||||
UserDetails userDetails = getUserDetails(result);
|
||||
cache.put(username, userDetails);
|
||||
return userDetails;
|
||||
}
|
||||
R<UserInfo> result = remoteUserService.info(username, SecurityConstants.FROM_IN);
|
||||
UserDetails userDetails = getUserDetails(result);
|
||||
cache.put(username, userDetails);
|
||||
return userDetails;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户实体查询
|
||||
*
|
||||
* @param pigxUser user
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public UserDetails loadUserByUser(PigxUser pigxUser) {
|
||||
// 避免 C端用户通过接口调用B端接口的安全问题
|
||||
if (UserTypeEnum.TOB.getStatus().equals(pigxUser.getUserType())) {
|
||||
return loadUserByUsername(pigxUser.getUsername());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* 通过用户实体查询
|
||||
* @param pigxUser user
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public UserDetails loadUserByUser(PigxUser pigxUser) {
|
||||
// 避免 C端用户通过接口调用B端接口的安全问题
|
||||
if (UserTypeEnum.TOB.getStatus().equals(pigxUser.getUserType())) {
|
||||
return loadUserByUsername(pigxUser.getUsername());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
|
||||
}
|
||||
+4
-9
@@ -73,15 +73,13 @@ public class RemoteServiceImpl implements IRemoteService {
|
||||
ThreadUtil.execute(() -> {
|
||||
try {
|
||||
ProcessInstanceRecord processInstanceRecord = processInstanceRecordService.lambdaQuery()
|
||||
.eq(ProcessInstanceRecord::getProcessInstanceId, processInstanceId)
|
||||
.one();
|
||||
.eq(ProcessInstanceRecord::getProcessInstanceId, processInstanceId).one();
|
||||
|
||||
int index = 10;
|
||||
while (index > 0 && processInstanceRecord == null) {
|
||||
TimeUnit.SECONDS.sleep(5);
|
||||
processInstanceRecord = processInstanceRecordService.lambdaQuery()
|
||||
.eq(ProcessInstanceRecord::getProcessInstanceId, processInstanceId)
|
||||
.one();
|
||||
.eq(ProcessInstanceRecord::getProcessInstanceId, processInstanceId).one();
|
||||
index--;
|
||||
}
|
||||
|
||||
@@ -130,11 +128,8 @@ public class RemoteServiceImpl implements IRemoteService {
|
||||
*/
|
||||
@Override
|
||||
public R<List<Long>> queryUserIdListByDepIdList(List<Long> depIdList) {
|
||||
List<Long> list = userService.getUserIdListByDeptIdList(depIdList)
|
||||
.getData()
|
||||
.stream()
|
||||
.map(SysUser::getUserId)
|
||||
.collect(Collectors.toList());
|
||||
List<Long> list = userService.getUserIdListByDeptIdList(depIdList).getData().stream().map(SysUser::getUserId)
|
||||
.collect(Collectors.toList());
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -47,12 +47,12 @@ public class RouterFunctionConfiguration {
|
||||
@Bean
|
||||
public RouterFunction routerFunction() {
|
||||
return RouterFunctions
|
||||
.route(RequestPredicates.path("/code/create").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)),
|
||||
imageCodeCreateHandler)
|
||||
.andRoute(RequestPredicates.path("/code/image").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)),
|
||||
imageCodeMathHandler)
|
||||
.andRoute(RequestPredicates.POST("/code/check").and(RequestPredicates.accept(MediaType.ALL)),
|
||||
imageCodeCheckHandler);
|
||||
.route(RequestPredicates.path("/code/create").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)),
|
||||
imageCodeCreateHandler)
|
||||
.andRoute(RequestPredicates.path("/code/image").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)),
|
||||
imageCodeMathHandler)
|
||||
.andRoute(RequestPredicates.POST("/code/check").and(RequestPredicates.accept(MediaType.ALL)),
|
||||
imageCodeCheckHandler);
|
||||
|
||||
}
|
||||
|
||||
|
||||
+5
-6
@@ -49,7 +49,7 @@ public class ImageCodeMathHandler implements HandlerFunction<ServerResponse> {
|
||||
|
||||
private static final Integer DEFAULT_IMAGE_HEIGHT = 40;
|
||||
|
||||
private final RedisTemplate<String,String> redisTemplate;
|
||||
private final RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
@Override
|
||||
public Mono<ServerResponse> handle(ServerRequest serverRequest) {
|
||||
@@ -59,16 +59,15 @@ public class ImageCodeMathHandler implements HandlerFunction<ServerResponse> {
|
||||
|
||||
// 保存验证码信息
|
||||
Optional<String> randomStr = serverRequest.queryParam("randomStr");
|
||||
randomStr.ifPresent(s -> redisTemplate.opsForValue()
|
||||
.set(CacheConstants.DEFAULT_CODE_KEY + s, result, SecurityConstants.CODE_TIME, TimeUnit.SECONDS));
|
||||
randomStr.ifPresent(s -> redisTemplate.opsForValue().set(CacheConstants.DEFAULT_CODE_KEY + s, result,
|
||||
SecurityConstants.CODE_TIME, TimeUnit.SECONDS));
|
||||
|
||||
// 转换流信息写出
|
||||
FastByteArrayOutputStream os = new FastByteArrayOutputStream();
|
||||
captcha.out(os);
|
||||
|
||||
return ServerResponse.status(HttpStatus.OK)
|
||||
.contentType(MediaType.IMAGE_JPEG)
|
||||
.body(BodyInserters.fromResource(new ByteArrayResource(os.toByteArray())));
|
||||
return ServerResponse.status(HttpStatus.OK).contentType(MediaType.IMAGE_JPEG)
|
||||
.body(BodyInserters.fromResource(new ByteArrayResource(os.toByteArray())));
|
||||
}
|
||||
|
||||
}
|
||||
+4
-6
@@ -47,9 +47,8 @@ public class DataUtil {
|
||||
|
||||
optionalDept.ifPresent(list::add);
|
||||
|
||||
List<SysDept> collect = allDeptList.stream()
|
||||
.filter(w -> w.getParentId() == deptId)
|
||||
.collect(Collectors.toList());
|
||||
List<SysDept> collect = allDeptList.stream().filter(w -> w.getParentId() == deptId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (CollUtil.isEmpty(collect)) {
|
||||
return list;
|
||||
@@ -73,9 +72,8 @@ public class DataUtil {
|
||||
List<SysMenu> list = new ArrayList<>();
|
||||
list.add(allMenuList.stream().filter(w -> w.getMenuId() == menuId).findFirst().get());
|
||||
|
||||
List<SysMenu> collect = allMenuList.stream()
|
||||
.filter(w -> w.getParentId() == menuId)
|
||||
.collect(Collectors.toList());
|
||||
List<SysMenu> collect = allMenuList.stream().filter(w -> w.getParentId() == menuId)
|
||||
.collect(Collectors.toList());
|
||||
if (CollUtil.isEmpty(collect)) {
|
||||
return list;
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,9 +3,9 @@ package com.pig4cloud.pigx.admin.api.vo;
|
||||
import com.alibaba.excel.annotation.ExcelIgnore;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.pig4cloud.pigx.common.excel.annotation.ExcelLine;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
|
||||
+2
-2
@@ -4,10 +4,10 @@ import com.alibaba.excel.annotation.ExcelIgnore;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.annotation.write.style.ColumnWidth;
|
||||
import com.pig4cloud.pigx.common.excel.annotation.ExcelLine;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
+1
-1
@@ -4,9 +4,9 @@ import com.alibaba.excel.annotation.ExcelIgnore;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.annotation.write.style.ColumnWidth;
|
||||
import com.pig4cloud.pigx.common.excel.annotation.ExcelLine;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
+1
-1
@@ -4,9 +4,9 @@ import com.alibaba.excel.annotation.ExcelIgnore;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.annotation.write.style.ColumnWidth;
|
||||
import com.pig4cloud.pigx.common.excel.annotation.ExcelLine;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public class ClientDetailsInitRunner implements InitializingBean {
|
||||
|
||||
private final SysTenantService tenantService;
|
||||
|
||||
private final RedisTemplate<String,String> redisTemplate;
|
||||
private final RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
/**
|
||||
* WebServerInitializedEvent 使用 TransactionalEventListener 时启动时无法获取到事件
|
||||
|
||||
+1
-1
@@ -28,13 +28,13 @@ import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
|
||||
import com.pig4cloud.pigx.common.log.annotation.SysLog;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import javax.validation.Valid;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
+8
-10
@@ -92,8 +92,9 @@ public class SysDictController {
|
||||
public R<IPage> getDictPage(@ParameterObject Page page, @ParameterObject SysDict sysDict) {
|
||||
return R.ok(sysDictService.page(page,
|
||||
Wrappers.<SysDict>lambdaQuery()
|
||||
.eq(StrUtil.isNotBlank(sysDict.getSystemFlag()), SysDict::getSystemFlag, sysDict.getSystemFlag())
|
||||
.like(StrUtil.isNotBlank(sysDict.getDictType()), SysDict::getDictType, sysDict.getDictType())));
|
||||
.eq(StrUtil.isNotBlank(sysDict.getSystemFlag()), SysDict::getSystemFlag,
|
||||
sysDict.getSystemFlag())
|
||||
.like(StrUtil.isNotBlank(sysDict.getDictType()), SysDict::getDictType, sysDict.getDictType())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,10 +105,8 @@ public class SysDictController {
|
||||
@GetMapping("/type/{type}")
|
||||
@Cacheable(value = CacheConstants.DICT_DETAILS, key = "#type", unless = "#result.data.isEmpty()")
|
||||
public R<List<SysDictItem>> getDictByType(@PathVariable String type) {
|
||||
return R.ok(sysDictItemService.list(Wrappers.<SysDictItem>query()
|
||||
.lambda()
|
||||
.eq(SysDictItem::getDictType, type)
|
||||
.orderByDesc(SysDictItem::getSortOrder)));
|
||||
return R.ok(sysDictItemService.list(Wrappers.<SysDictItem>query().lambda().eq(SysDictItem::getDictType, type)
|
||||
.orderByDesc(SysDictItem::getSortOrder)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,10 +154,9 @@ public class SysDictController {
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public R getDictList(String name) {
|
||||
return R.ok(sysDictService.list(Wrappers.<SysDict>lambdaQuery()
|
||||
.like(StrUtil.isNotBlank(name), SysDict::getDictType, name)
|
||||
.or()
|
||||
.like(StrUtil.isNotBlank(name), SysDict::getDescription, name)));
|
||||
return R.ok(sysDictService
|
||||
.list(Wrappers.<SysDict>lambdaQuery().like(StrUtil.isNotBlank(name), SysDict::getDictType, name).or()
|
||||
.like(StrUtil.isNotBlank(name), SysDict::getDescription, name)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -106,7 +106,7 @@ public class SysFileController {
|
||||
public R upload(@RequestPart("file") MultipartFile file, @RequestParam(value = "dir", required = false) String dir,
|
||||
@RequestParam(value = "groupId", required = false) Long groupId,
|
||||
@RequestParam(value = "type", required = false) String type) {
|
||||
return sysFileService.uploadFile(file, dir,groupId, type);
|
||||
return sysFileService.uploadFile(file, dir, groupId, type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -115,7 +115,7 @@ public class SysMessageController {
|
||||
@PreAuthorize("@pms.hasPermission('sys_message_export')")
|
||||
public List<SysMessageEntity> export(SysMessageEntity sysMessage, Long[] ids) {
|
||||
return sysMessageService
|
||||
.list(Wrappers.lambdaQuery(sysMessage).in(ArrayUtil.isNotEmpty(ids), SysMessageEntity::getId, ids));
|
||||
.list(Wrappers.lambdaQuery(sysMessage).in(ArrayUtil.isNotEmpty(ids), SysMessageEntity::getId, ids));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -38,7 +38,6 @@ import com.pig4cloud.pigx.common.security.util.SecurityUtils;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import javax.validation.Valid;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springdoc.api.annotations.ParameterObject;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -46,6 +45,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
||||
-1
@@ -48,4 +48,3 @@ public interface SysScheduleService extends IService<SysScheduleEntity> {
|
||||
List<SysScheduleEntity> selectListByScope(LocalDate startDate, LocalDate endDate);
|
||||
|
||||
}
|
||||
|
||||
+5
-5
@@ -62,7 +62,7 @@ public class MobileServiceImpl implements MobileService {
|
||||
@Override
|
||||
public R<Boolean> sendSmsCode(String mobile) {
|
||||
List<SysUser> userList = userMapper
|
||||
.selectList(Wrappers.<SysUser>query().lambda().eq(SysUser::getPhone, mobile));
|
||||
.selectList(Wrappers.<SysUser>query().lambda().eq(SysUser::getPhone, mobile));
|
||||
|
||||
if (CollUtil.isEmpty(userList)) {
|
||||
log.info("手机号未注册:{}", mobile);
|
||||
@@ -70,7 +70,7 @@ public class MobileServiceImpl implements MobileService {
|
||||
}
|
||||
|
||||
String codeObj = redisTemplate.opsForValue()
|
||||
.get(CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.SMS.getType() + StringPool.AT + mobile);
|
||||
.get(CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.SMS.getType() + StringPool.AT + mobile);
|
||||
|
||||
if (StrUtil.isNotBlank(codeObj)) {
|
||||
log.info("手机号验证码未过期:{},{}", mobile, codeObj);
|
||||
@@ -79,9 +79,9 @@ public class MobileServiceImpl implements MobileService {
|
||||
|
||||
String code = RandomUtil.randomNumbers(Integer.parseInt(SecurityConstants.CODE_SIZE));
|
||||
log.debug("手机号生成验证码成功:{},{}", mobile, code);
|
||||
redisTemplate.opsForValue()
|
||||
.set(CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.SMS.getType() + StringPool.AT + mobile, code,
|
||||
SecurityConstants.CODE_TIME, TimeUnit.SECONDS);
|
||||
redisTemplate.opsForValue().set(
|
||||
CacheConstants.DEFAULT_CODE_KEY + LoginTypeEnum.SMS.getType() + StringPool.AT + mobile, code,
|
||||
SecurityConstants.CODE_TIME, TimeUnit.SECONDS);
|
||||
return R.ok(Boolean.TRUE, code);
|
||||
}
|
||||
|
||||
|
||||
+243
-259
@@ -58,300 +58,284 @@ import java.util.stream.Collectors;
|
||||
@AllArgsConstructor
|
||||
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements SysDeptService {
|
||||
|
||||
private final SysUserMapper userMapper;
|
||||
private final SysUserMapper userMapper;
|
||||
|
||||
private final SysDeptMapper deptMapper;
|
||||
private final SysDeptMapper deptMapper;
|
||||
|
||||
private final SysPostMapper postMapper;
|
||||
private final SysPostMapper postMapper;
|
||||
|
||||
private final SysRoleMapper roleMapper;
|
||||
private final SysRoleMapper roleMapper;
|
||||
|
||||
private final SysUserPostMapper userPostMapper;
|
||||
private final SysUserPostMapper userPostMapper;
|
||||
|
||||
/**
|
||||
* 删除部门
|
||||
* @param id 部门 ID
|
||||
* @return 成功、失败
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean removeDeptById(Long id) {
|
||||
// 级联删除部门
|
||||
List<Long> idList = this.listDescendant(id).stream().map(SysDept::getDeptId).collect(Collectors.toList());
|
||||
/**
|
||||
* 删除部门
|
||||
* @param id 部门 ID
|
||||
* @return 成功、失败
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean removeDeptById(Long id) {
|
||||
// 级联删除部门
|
||||
List<Long> idList = this.listDescendant(id).stream().map(SysDept::getDeptId).collect(Collectors.toList());
|
||||
|
||||
Optional.ofNullable(idList).filter(CollUtil::isNotEmpty).ifPresent(this::removeByIds);
|
||||
Optional.ofNullable(idList).filter(CollUtil::isNotEmpty).ifPresent(this::removeByIds);
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部部门树
|
||||
* @param deptName
|
||||
* @param parentId
|
||||
* @return 树 部门名称
|
||||
*/
|
||||
@Override
|
||||
public List<Tree<Long>> selectTree(String deptName, Long parentId) {
|
||||
// 查询全部部门
|
||||
List<SysDept> deptAllList = deptMapper
|
||||
.selectList(Wrappers.<SysDept>lambdaQuery().like(StrUtil.isNotBlank(deptName), SysDept::getName, deptName));
|
||||
// 查询数据权限内部门
|
||||
List<Long> deptOwnIdList = deptMapper
|
||||
.selectListByScope(
|
||||
Wrappers.<SysDept>lambdaQuery().like(StrUtil.isNotBlank(deptName), SysDept::getName, deptName),
|
||||
DataScope.of())
|
||||
.stream()
|
||||
.map(SysDept::getDeptId)
|
||||
.collect(Collectors.toList());
|
||||
/**
|
||||
* 查询全部部门树
|
||||
* @param deptName
|
||||
* @param parentId
|
||||
* @return 树 部门名称
|
||||
*/
|
||||
@Override
|
||||
public List<Tree<Long>> selectTree(String deptName, Long parentId) {
|
||||
// 查询全部部门
|
||||
List<SysDept> deptAllList = deptMapper.selectList(
|
||||
Wrappers.<SysDept>lambdaQuery().like(StrUtil.isNotBlank(deptName), SysDept::getName, deptName));
|
||||
// 查询数据权限内部门
|
||||
List<Long> deptOwnIdList = deptMapper.selectListByScope(
|
||||
Wrappers.<SysDept>lambdaQuery().like(StrUtil.isNotBlank(deptName), SysDept::getName, deptName),
|
||||
DataScope.of()).stream().map(SysDept::getDeptId).collect(Collectors.toList());
|
||||
|
||||
// 权限内部门
|
||||
List<TreeNode<Long>> collect = deptAllList.stream()
|
||||
.filter(dept -> dept.getDeptId().intValue() != dept.getParentId())
|
||||
.sorted(Comparator.comparingInt(SysDept::getSortOrder))
|
||||
.map(dept -> {
|
||||
TreeNode<Long> treeNode = new TreeNode<>();
|
||||
treeNode.setId(dept.getDeptId());
|
||||
treeNode.setParentId(dept.getParentId());
|
||||
treeNode.setName(dept.getName());
|
||||
treeNode.setWeight(dept.getSortOrder());
|
||||
// 有权限不返回标识
|
||||
Map<String, Object> extra = new HashMap<>(8);
|
||||
extra.put("isLock", !deptOwnIdList.contains(dept.getDeptId()));
|
||||
extra.put("createTime", dept.getCreateTime());
|
||||
treeNode.setExtra(extra);
|
||||
return treeNode;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
// 权限内部门
|
||||
List<TreeNode<Long>> collect = deptAllList.stream()
|
||||
.filter(dept -> dept.getDeptId().intValue() != dept.getParentId())
|
||||
.sorted(Comparator.comparingInt(SysDept::getSortOrder)).map(dept -> {
|
||||
TreeNode<Long> treeNode = new TreeNode<>();
|
||||
treeNode.setId(dept.getDeptId());
|
||||
treeNode.setParentId(dept.getParentId());
|
||||
treeNode.setName(dept.getName());
|
||||
treeNode.setWeight(dept.getSortOrder());
|
||||
// 有权限不返回标识
|
||||
Map<String, Object> extra = new HashMap<>(8);
|
||||
extra.put("isLock", !deptOwnIdList.contains(dept.getDeptId()));
|
||||
extra.put("createTime", dept.getCreateTime());
|
||||
treeNode.setExtra(extra);
|
||||
return treeNode;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
// 模糊查询 不组装树结构 直接返回 表格方便编辑
|
||||
if (StrUtil.isNotBlank(deptName)) {
|
||||
return collect.stream().map(node -> {
|
||||
Tree<Long> tree = new Tree<>();
|
||||
tree.putAll(node.getExtra());
|
||||
BeanUtils.copyProperties(node, tree);
|
||||
return tree;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
// 模糊查询 不组装树结构 直接返回 表格方便编辑
|
||||
if (StrUtil.isNotBlank(deptName)) {
|
||||
return collect.stream().map(node -> {
|
||||
Tree<Long> tree = new Tree<>();
|
||||
tree.putAll(node.getExtra());
|
||||
BeanUtils.copyProperties(node, tree);
|
||||
return tree;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return TreeUtil.build(collect, parentId == null ? 0 : parentId);
|
||||
}
|
||||
return TreeUtil.build(collect, parentId == null ? 0 : parentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出部门
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<DeptExcelVO> listExcelVo() {
|
||||
List<SysDept> list = this.list();
|
||||
List<DeptExcelVO> deptExcelVos = list.stream().map(item -> {
|
||||
DeptExcelVO deptExcelVo = new DeptExcelVO();
|
||||
deptExcelVo.setName(item.getName());
|
||||
Optional<String> first = this.list()
|
||||
.stream()
|
||||
.filter(it -> item.getParentId().equals(it.getDeptId()))
|
||||
.map(SysDept::getName)
|
||||
.findFirst();
|
||||
deptExcelVo.setParentName(first.orElse("根部门"));
|
||||
deptExcelVo.setSortOrder(item.getSortOrder());
|
||||
return deptExcelVo;
|
||||
}).collect(Collectors.toList());
|
||||
return deptExcelVos;
|
||||
}
|
||||
/**
|
||||
* 导出部门
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<DeptExcelVO> listExcelVo() {
|
||||
List<SysDept> list = this.list();
|
||||
List<DeptExcelVO> deptExcelVos = list.stream().map(item -> {
|
||||
DeptExcelVO deptExcelVo = new DeptExcelVO();
|
||||
deptExcelVo.setName(item.getName());
|
||||
Optional<String> first = this.list().stream().filter(it -> item.getParentId().equals(it.getDeptId()))
|
||||
.map(SysDept::getName).findFirst();
|
||||
deptExcelVo.setParentName(first.orElse("根部门"));
|
||||
deptExcelVo.setSortOrder(item.getSortOrder());
|
||||
return deptExcelVo;
|
||||
}).collect(Collectors.toList());
|
||||
return deptExcelVos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R importDept(List<DeptExcelVO> excelVOList, BindingResult bindingResult) {
|
||||
List<ErrorMessage> errorMessageList = (List<ErrorMessage>) bindingResult.getTarget();
|
||||
@Override
|
||||
public R importDept(List<DeptExcelVO> excelVOList, BindingResult bindingResult) {
|
||||
List<ErrorMessage> errorMessageList = (List<ErrorMessage>) bindingResult.getTarget();
|
||||
|
||||
List<SysDept> deptList = this.list();
|
||||
for (DeptExcelVO item : excelVOList) {
|
||||
Set<String> errorMsg = new HashSet<>();
|
||||
boolean exsitUsername = deptList.stream().anyMatch(sysDept -> item.getName().equals(sysDept.getName()));
|
||||
if (exsitUsername) {
|
||||
errorMsg.add("部门名称已经存在");
|
||||
}
|
||||
SysDept one = this.getOne(Wrappers.<SysDept>lambdaQuery().eq(SysDept::getName, item.getParentName()));
|
||||
if (item.getParentName().equals("根部门")) {
|
||||
one = new SysDept();
|
||||
one.setDeptId(0L);
|
||||
}
|
||||
if (one == null) {
|
||||
errorMsg.add("上级部门不存在");
|
||||
}
|
||||
if (CollUtil.isEmpty(errorMsg)) {
|
||||
SysDept sysDept = new SysDept();
|
||||
sysDept.setName(item.getName());
|
||||
sysDept.setParentId(one.getDeptId());
|
||||
sysDept.setSortOrder(item.getSortOrder());
|
||||
baseMapper.insert(sysDept);
|
||||
}
|
||||
else {
|
||||
// 数据不合法情况
|
||||
errorMessageList.add(new ErrorMessage(item.getLineNum(), errorMsg));
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(errorMessageList)) {
|
||||
return R.failed(errorMessageList);
|
||||
}
|
||||
return R.ok(null, "部门导入成功");
|
||||
}
|
||||
List<SysDept> deptList = this.list();
|
||||
for (DeptExcelVO item : excelVOList) {
|
||||
Set<String> errorMsg = new HashSet<>();
|
||||
boolean exsitUsername = deptList.stream().anyMatch(sysDept -> item.getName().equals(sysDept.getName()));
|
||||
if (exsitUsername) {
|
||||
errorMsg.add("部门名称已经存在");
|
||||
}
|
||||
SysDept one = this.getOne(Wrappers.<SysDept>lambdaQuery().eq(SysDept::getName, item.getParentName()));
|
||||
if (item.getParentName().equals("根部门")) {
|
||||
one = new SysDept();
|
||||
one.setDeptId(0L);
|
||||
}
|
||||
if (one == null) {
|
||||
errorMsg.add("上级部门不存在");
|
||||
}
|
||||
if (CollUtil.isEmpty(errorMsg)) {
|
||||
SysDept sysDept = new SysDept();
|
||||
sysDept.setName(item.getName());
|
||||
sysDept.setParentId(one.getDeptId());
|
||||
sysDept.setSortOrder(item.getSortOrder());
|
||||
baseMapper.insert(sysDept);
|
||||
}
|
||||
else {
|
||||
// 数据不合法情况
|
||||
errorMessageList.add(new ErrorMessage(item.getLineNum(), errorMsg));
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(errorMessageList)) {
|
||||
return R.failed(errorMessageList);
|
||||
}
|
||||
return R.ok(null, "部门导入成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有子节点 (包含当前节点)
|
||||
* @param deptId 部门ID 目标部门ID
|
||||
* @return ID
|
||||
*/
|
||||
@Override
|
||||
public List<SysDept> listDescendant(Long deptId) {
|
||||
// 查询全部部门
|
||||
List<SysDept> allDeptList = baseMapper.selectList(Wrappers.emptyWrapper());
|
||||
/**
|
||||
* 查询所有子节点 (包含当前节点)
|
||||
* @param deptId 部门ID 目标部门ID
|
||||
* @return ID
|
||||
*/
|
||||
@Override
|
||||
public List<SysDept> listDescendant(Long deptId) {
|
||||
// 查询全部部门
|
||||
List<SysDept> allDeptList = baseMapper.selectList(Wrappers.emptyWrapper());
|
||||
|
||||
// 递归查询所有子节点
|
||||
List<SysDept> resDeptList = new ArrayList<>();
|
||||
recursiveDept(allDeptList, deptId, resDeptList);
|
||||
// 递归查询所有子节点
|
||||
List<SysDept> resDeptList = new ArrayList<>();
|
||||
recursiveDept(allDeptList, deptId, resDeptList);
|
||||
|
||||
// 添加当前节点
|
||||
resDeptList.addAll(allDeptList.stream().filter(sysDept -> deptId.equals(sysDept.getDeptId())).collect(Collectors.toList()));
|
||||
return resDeptList;
|
||||
}
|
||||
// 添加当前节点
|
||||
resDeptList.addAll(allDeptList.stream().filter(sysDept -> deptId.equals(sysDept.getDeptId()))
|
||||
.collect(Collectors.toList()));
|
||||
return resDeptList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门负责人
|
||||
*
|
||||
* 1. 根据dept 查询用户 2. 筛选用户列表中 post
|
||||
* @param deptId deptId
|
||||
* @return user id list
|
||||
*/
|
||||
@Override
|
||||
public List<Long> listDeptLeader(Long deptId) {
|
||||
List<SysUser> sysUserList = userMapper
|
||||
.selectList(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getDeptId, deptId));
|
||||
if (CollUtil.isEmpty(sysUserList)) {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* 获取部门负责人
|
||||
*
|
||||
* 1. 根据dept 查询用户 2. 筛选用户列表中 post
|
||||
* @param deptId deptId
|
||||
* @return user id list
|
||||
*/
|
||||
@Override
|
||||
public List<Long> listDeptLeader(Long deptId) {
|
||||
List<SysUser> sysUserList = userMapper
|
||||
.selectList(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getDeptId, deptId));
|
||||
if (CollUtil.isEmpty(sysUserList)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SysPost deptLeader = postMapper
|
||||
.selectOne(Wrappers.<SysPost>lambdaQuery().eq(SysPost::getPostCode, "DEPT_LEADER"));
|
||||
if (deptLeader == null) {
|
||||
return null;
|
||||
}
|
||||
SysPost deptLeader = postMapper
|
||||
.selectOne(Wrappers.<SysPost>lambdaQuery().eq(SysPost::getPostCode, "DEPT_LEADER"));
|
||||
if (deptLeader == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Long> userIdList = sysUserList.stream().map(SysUser::getUserId).collect(Collectors.toList());
|
||||
return userPostMapper.selectList(Wrappers.<SysUserPost>lambdaQuery().in(SysUserPost::getUserId, userIdList))
|
||||
.stream()
|
||||
.filter(post -> Objects.equals(post.getPostId(), deptLeader.getPostId()))
|
||||
.map(SysUserPost::getUserId)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
List<Long> userIdList = sysUserList.stream().map(SysUser::getUserId).collect(Collectors.toList());
|
||||
return userPostMapper.selectList(Wrappers.<SysUserPost>lambdaQuery().in(SysUserPost::getUserId, userIdList))
|
||||
.stream().filter(post -> Objects.equals(post.getPostId(), deptLeader.getPostId()))
|
||||
.map(SysUserPost::getUserId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据父部门ID和类型获取组织树
|
||||
* @param parentDeptId 父部门ID
|
||||
* @param type 类型
|
||||
* @return 组织树信息
|
||||
*/
|
||||
public Map<String, Object> listOrgTree(Long parentDeptId, String type) {
|
||||
/**
|
||||
* 根据父部门ID和类型获取组织树
|
||||
* @param parentDeptId 父部门ID
|
||||
* @param type 类型
|
||||
* @return 组织树信息
|
||||
*/
|
||||
public Map<String, Object> listOrgTree(Long parentDeptId, String type) {
|
||||
|
||||
List<OrgTreeVO> orgs = new LinkedList<>();
|
||||
List<OrgTreeVO> orgs = new LinkedList<>();
|
||||
|
||||
if (StrUtil.equals(type, OrgTypeEnum.ROLE.getType())) {
|
||||
// 角色
|
||||
List<SysRole> roleList = roleMapper.selectList(Wrappers.emptyWrapper());
|
||||
if (StrUtil.equals(type, OrgTypeEnum.ROLE.getType())) {
|
||||
// 角色
|
||||
List<SysRole> roleList = roleMapper.selectList(Wrappers.emptyWrapper());
|
||||
|
||||
roleList.forEach(role -> {
|
||||
OrgTreeVO orgTreeVo = new OrgTreeVO();
|
||||
orgTreeVo.setId(role.getRoleId());
|
||||
orgTreeVo.setName(role.getRoleName());
|
||||
orgTreeVo.setType(OrgTypeEnum.ROLE.getType());
|
||||
orgTreeVo.setSelected(false);
|
||||
orgs.add(orgTreeVo);
|
||||
});
|
||||
roleList.forEach(role -> {
|
||||
OrgTreeVO orgTreeVo = new OrgTreeVO();
|
||||
orgTreeVo.setId(role.getRoleId());
|
||||
orgTreeVo.setName(role.getRoleName());
|
||||
orgTreeVo.setType(OrgTypeEnum.ROLE.getType());
|
||||
orgTreeVo.setSelected(false);
|
||||
orgs.add(orgTreeVo);
|
||||
});
|
||||
|
||||
return Dict.create()
|
||||
.set("roleList", orgs)
|
||||
.set("childDepartments", orgs)
|
||||
.set("employees", new ArrayList<>());
|
||||
}
|
||||
return Dict.create().set("roleList", orgs).set("childDepartments", orgs).set("employees",
|
||||
new ArrayList<>());
|
||||
}
|
||||
|
||||
Dict dict = Dict.create()
|
||||
.set("titleDepartments", new ArrayList<>())
|
||||
.set("roleList", new ArrayList<>())
|
||||
.set("employees", new ArrayList<>());
|
||||
Dict dict = Dict.create().set("titleDepartments", new ArrayList<>()).set("roleList", new ArrayList<>())
|
||||
.set("employees", new ArrayList<>());
|
||||
|
||||
List<SysDept> deptList = this.list(
|
||||
Wrappers.<SysDept>lambdaQuery().eq(Objects.nonNull(parentDeptId), SysDept::getParentId, parentDeptId));
|
||||
List<SysDept> deptList = this.list(
|
||||
Wrappers.<SysDept>lambdaQuery().eq(Objects.nonNull(parentDeptId), SysDept::getParentId, parentDeptId));
|
||||
|
||||
// 查询所有部门及员工
|
||||
List<OrgTreeVO> deptVoList = new ArrayList<>();
|
||||
deptList.forEach(dept -> {
|
||||
OrgTreeVO orgTreeVo = new OrgTreeVO();
|
||||
orgTreeVo.setId(dept.getDeptId());
|
||||
orgTreeVo.setName(dept.getName());
|
||||
orgTreeVo.setType(OrgTypeEnum.DEPT.getType());
|
||||
orgTreeVo.setSelected(false);
|
||||
deptVoList.add(orgTreeVo);
|
||||
});
|
||||
dict.set("childDepartments", deptVoList);
|
||||
// 查询所有部门及员工
|
||||
List<OrgTreeVO> deptVoList = new ArrayList<>();
|
||||
deptList.forEach(dept -> {
|
||||
OrgTreeVO orgTreeVo = new OrgTreeVO();
|
||||
orgTreeVo.setId(dept.getDeptId());
|
||||
orgTreeVo.setName(dept.getName());
|
||||
orgTreeVo.setType(OrgTypeEnum.DEPT.getType());
|
||||
orgTreeVo.setSelected(false);
|
||||
deptVoList.add(orgTreeVo);
|
||||
});
|
||||
dict.set("childDepartments", deptVoList);
|
||||
|
||||
if (!StrUtil.equals(type, OrgTypeEnum.DEPT.getType())) {
|
||||
if (!StrUtil.equals(type, OrgTypeEnum.DEPT.getType())) {
|
||||
|
||||
List<OrgTreeVO> userVoList = new ArrayList<>();
|
||||
List<OrgTreeVO> userVoList = new ArrayList<>();
|
||||
|
||||
List<SysUser> userList = userMapper
|
||||
.selectList(Wrappers.<SysUser>lambdaQuery().in(SysUser::getDeptId, CollUtil.toList(parentDeptId)));
|
||||
List<SysUser> userList = userMapper
|
||||
.selectList(Wrappers.<SysUser>lambdaQuery().in(SysUser::getDeptId, CollUtil.toList(parentDeptId)));
|
||||
|
||||
userList.forEach(user -> {
|
||||
OrgTreeVO orgTreeVo = new OrgTreeVO();
|
||||
orgTreeVo.setId(user.getUserId());
|
||||
orgTreeVo.setName(user.getUsername());
|
||||
orgTreeVo.setType(OrgTypeEnum.USER.getType());
|
||||
orgTreeVo.setSelected(false);
|
||||
orgTreeVo.setAvatar(user.getAvatar());
|
||||
userVoList.add(orgTreeVo);
|
||||
});
|
||||
dict.set("employees", userVoList);
|
||||
}
|
||||
userList.forEach(user -> {
|
||||
OrgTreeVO orgTreeVo = new OrgTreeVO();
|
||||
orgTreeVo.setId(user.getUserId());
|
||||
orgTreeVo.setName(user.getUsername());
|
||||
orgTreeVo.setType(OrgTypeEnum.USER.getType());
|
||||
orgTreeVo.setSelected(false);
|
||||
orgTreeVo.setAvatar(user.getAvatar());
|
||||
userVoList.add(orgTreeVo);
|
||||
});
|
||||
dict.set("employees", userVoList);
|
||||
}
|
||||
|
||||
if (parentDeptId > 0) {
|
||||
List<SysDept> allDept = this.list();
|
||||
List<SysDept> depts = DataUtil.selectParentByDept(parentDeptId, allDept);
|
||||
dict.set("titleDepartments", CollUtil.reverse(depts));
|
||||
}
|
||||
if (parentDeptId > 0) {
|
||||
List<SysDept> allDept = this.list();
|
||||
List<SysDept> depts = DataUtil.selectParentByDept(parentDeptId, allDept);
|
||||
dict.set("titleDepartments", CollUtil.reverse(depts));
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
return dict;
|
||||
}
|
||||
|
||||
/**
|
||||
* 模糊搜索用户
|
||||
* @param username 用户名/拼音/首字母
|
||||
* @return 匹配到的用户
|
||||
*/
|
||||
public List<OrgTreeVO> getOrgTreeUser(String username) {
|
||||
return userMapper.selectList(Wrappers.<SysUser>lambdaQuery().like(SysUser::getUsername, username))
|
||||
.stream()
|
||||
.map(user -> {
|
||||
OrgTreeVO orgTreeVo = new OrgTreeVO();
|
||||
orgTreeVo.setId(user.getUserId());
|
||||
orgTreeVo.setName(user.getUsername());
|
||||
orgTreeVo.setType(OrgTypeEnum.USER.getType());
|
||||
orgTreeVo.setSelected(false);
|
||||
orgTreeVo.setAvatar(user.getAvatar());
|
||||
return orgTreeVo;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
/**
|
||||
* 模糊搜索用户
|
||||
* @param username 用户名/拼音/首字母
|
||||
* @return 匹配到的用户
|
||||
*/
|
||||
public List<OrgTreeVO> getOrgTreeUser(String username) {
|
||||
return userMapper.selectList(Wrappers.<SysUser>lambdaQuery().like(SysUser::getUsername, username)).stream()
|
||||
.map(user -> {
|
||||
OrgTreeVO orgTreeVo = new OrgTreeVO();
|
||||
orgTreeVo.setId(user.getUserId());
|
||||
orgTreeVo.setName(user.getUsername());
|
||||
orgTreeVo.setType(OrgTypeEnum.USER.getType());
|
||||
orgTreeVo.setSelected(false);
|
||||
orgTreeVo.setAvatar(user.getAvatar());
|
||||
return orgTreeVo;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归查询所有子节点。
|
||||
* @param allDeptList 所有部门列表
|
||||
* @param parentId 父部门ID
|
||||
* @param resDeptList 结果集合
|
||||
*/
|
||||
private void recursiveDept(List<SysDept> allDeptList, Long parentId, List<SysDept> resDeptList) {
|
||||
// 使用 Stream API 进行筛选和遍历
|
||||
allDeptList.stream().filter(sysDept -> sysDept.getParentId().equals(parentId)).forEach(sysDept -> {
|
||||
resDeptList.add(sysDept);
|
||||
recursiveDept(allDeptList, sysDept.getDeptId(), resDeptList);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 递归查询所有子节点。
|
||||
* @param allDeptList 所有部门列表
|
||||
* @param parentId 父部门ID
|
||||
* @param resDeptList 结果集合
|
||||
*/
|
||||
private void recursiveDept(List<SysDept> allDeptList, Long parentId, List<SysDept> resDeptList) {
|
||||
// 使用 Stream API 进行筛选和遍历
|
||||
allDeptList.stream().filter(sysDept -> sysDept.getParentId().equals(parentId)).forEach(sysDept -> {
|
||||
resDeptList.add(sysDept);
|
||||
recursiveDept(allDeptList, sysDept.getDeptId(), resDeptList);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -83,8 +83,8 @@ public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> impleme
|
||||
}
|
||||
|
||||
if (ArrayUtil.isNotEmpty(sysLog.getCreateTime())) {
|
||||
wrapper.ge(SysLog::getCreateTime, sysLog.getCreateTime()[0])
|
||||
.le(SysLog::getCreateTime, sysLog.getCreateTime()[1]);
|
||||
wrapper.ge(SysLog::getCreateTime, sysLog.getCreateTime()[0]).le(SysLog::getCreateTime,
|
||||
sysLog.getCreateTime()[1]);
|
||||
}
|
||||
|
||||
return baseMapper.selectPage(page, wrapper);
|
||||
|
||||
+21
-26
@@ -76,8 +76,8 @@ public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMess
|
||||
}
|
||||
|
||||
// 删除原有用户
|
||||
relationMapper.delete(Wrappers.<SysMessageRelationEntity>lambdaQuery()
|
||||
.eq(SysMessageRelationEntity::getMsgId, messageEntity.getId()));
|
||||
relationMapper.delete(Wrappers.<SysMessageRelationEntity>lambdaQuery().eq(SysMessageRelationEntity::getMsgId,
|
||||
messageEntity.getId()));
|
||||
|
||||
List<OrgTreeVO> userList = sysMessage.getUserList();
|
||||
if (CollUtil.isNotEmpty(userList)) {
|
||||
@@ -106,16 +106,15 @@ public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMess
|
||||
@Override
|
||||
public IPage<SysMessageVO> pageUserMessage(Page page, SysMessageVO sysMessage) {
|
||||
MPJLambdaWrapper<SysMessageEntity> wrapper = new MPJLambdaWrapper<SysMessageEntity>()
|
||||
.selectAll(SysMessageEntity.class)
|
||||
.select(SysMessageRelationEntity::getReadFlag)
|
||||
.leftJoin(SysMessageRelationEntity.class, SysMessageRelationEntity::getMsgId, SysMessageEntity::getId)
|
||||
.eq(SysMessageRelationEntity::getUserId, SecurityUtils.getUser().getId())
|
||||
.eq(SysMessageEntity::getSendFlag, YesNoEnum.YES.getCode())
|
||||
.eq(StrUtil.isNotBlank(sysMessage.getCategory()), SysMessageEntity::getCategory, sysMessage.getCategory())
|
||||
.eq(StrUtil.isNotBlank(sysMessage.getReadFlag()), SysMessageRelationEntity::getReadFlag,
|
||||
sysMessage.getReadFlag())
|
||||
.orderByDesc(SysMessageEntity::getSort)
|
||||
.orderByDesc(SysMessageEntity::getCreateTime);
|
||||
.selectAll(SysMessageEntity.class).select(SysMessageRelationEntity::getReadFlag)
|
||||
.leftJoin(SysMessageRelationEntity.class, SysMessageRelationEntity::getMsgId, SysMessageEntity::getId)
|
||||
.eq(SysMessageRelationEntity::getUserId, SecurityUtils.getUser().getId())
|
||||
.eq(SysMessageEntity::getSendFlag, YesNoEnum.YES.getCode())
|
||||
.eq(StrUtil.isNotBlank(sysMessage.getCategory()), SysMessageEntity::getCategory,
|
||||
sysMessage.getCategory())
|
||||
.eq(StrUtil.isNotBlank(sysMessage.getReadFlag()), SysMessageRelationEntity::getReadFlag,
|
||||
sysMessage.getReadFlag())
|
||||
.orderByDesc(SysMessageEntity::getSort).orderByDesc(SysMessageEntity::getCreateTime);
|
||||
return baseMapper.selectJoinPage(page, SysMessageVO.class, wrapper);
|
||||
}
|
||||
|
||||
@@ -129,9 +128,8 @@ public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMess
|
||||
SysMessageRelationEntity relationEntity = new SysMessageRelationEntity();
|
||||
relationEntity.setReadFlag(YesNoEnum.YES.getCode());
|
||||
relationMapper.update(relationEntity,
|
||||
Wrappers.<SysMessageRelationEntity>lambdaQuery()
|
||||
.eq(SysMessageRelationEntity::getMsgId, id)
|
||||
.eq(SysMessageRelationEntity::getUserId, SecurityUtils.getUser().getId()));
|
||||
Wrappers.<SysMessageRelationEntity>lambdaQuery().eq(SysMessageRelationEntity::getMsgId, id)
|
||||
.eq(SysMessageRelationEntity::getUserId, SecurityUtils.getUser().getId()));
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@@ -151,10 +149,8 @@ public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMess
|
||||
return SysMessageVO;
|
||||
}
|
||||
List<Long> userIdList = relationMapper
|
||||
.selectList(Wrappers.<SysMessageRelationEntity>lambdaQuery().eq(SysMessageRelationEntity::getMsgId, id))
|
||||
.stream()
|
||||
.map(SysMessageRelationEntity::getUserId)
|
||||
.collect(Collectors.toList());
|
||||
.selectList(Wrappers.<SysMessageRelationEntity>lambdaQuery().eq(SysMessageRelationEntity::getMsgId, id))
|
||||
.stream().map(SysMessageRelationEntity::getUserId).collect(Collectors.toList());
|
||||
|
||||
if (CollUtil.isNotEmpty(userIdList)) {
|
||||
List<OrgTreeVO> orgNodeUserVoList = userMapper.selectBatchIds(userIdList).stream().map(user -> {
|
||||
@@ -181,13 +177,12 @@ public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMess
|
||||
@Override
|
||||
public Page pageUserRead(Page page, Long messageId, String name) {
|
||||
MPJLambdaWrapper<SysMessageRelationEntity> wrapper = new MPJLambdaWrapper<SysMessageRelationEntity>()
|
||||
.selectAll(SysMessageRelationEntity.class)
|
||||
.select(SysUser::getUsername, SysUser::getName, SysUser::getUserId)
|
||||
.select(SysMessageEntity::getTitle)
|
||||
.leftJoin(SysUser.class, SysUser::getUserId, SysMessageRelationEntity::getUserId)
|
||||
.leftJoin(SysMessageEntity.class, SysMessageEntity::getId, SysMessageRelationEntity::getMsgId)
|
||||
.eq(SysMessageRelationEntity::getMsgId, messageId)
|
||||
.like(StrUtil.isNotBlank(name), SysUser::getName, name);
|
||||
.selectAll(SysMessageRelationEntity.class)
|
||||
.select(SysUser::getUsername, SysUser::getName, SysUser::getUserId).select(SysMessageEntity::getTitle)
|
||||
.leftJoin(SysUser.class, SysUser::getUserId, SysMessageRelationEntity::getUserId)
|
||||
.leftJoin(SysMessageEntity.class, SysMessageEntity::getId, SysMessageRelationEntity::getMsgId)
|
||||
.eq(SysMessageRelationEntity::getMsgId, messageId)
|
||||
.like(StrUtil.isNotBlank(name), SysUser::getName, name);
|
||||
return relationMapper.selectJoinPage(page, SysMessageReadVO.class, wrapper);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -90,8 +90,8 @@ public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant
|
||||
@Override
|
||||
@Cacheable(value = CacheConstants.TENANT_DETAILS)
|
||||
public List<SysTenant> getNormalTenant() {
|
||||
return baseMapper
|
||||
.selectList(Wrappers.<SysTenant>lambdaQuery().eq(SysTenant::getStatus, TenantStateEnum.NORMAL.getCode()));
|
||||
return baseMapper.selectList(
|
||||
Wrappers.<SysTenant>lambdaQuery().eq(SysTenant::getStatus, TenantStateEnum.NORMAL.getCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+29
-46
@@ -40,7 +40,6 @@ import com.pig4cloud.pigx.admin.mapper.SysUserRoleMapper;
|
||||
import com.pig4cloud.pigx.admin.service.*;
|
||||
import com.pig4cloud.pigx.common.audit.annotation.Audit;
|
||||
import com.pig4cloud.pigx.common.core.constant.CacheConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
|
||||
import com.pig4cloud.pigx.common.core.exception.ErrorCodes;
|
||||
import com.pig4cloud.pigx.common.core.util.MsgUtils;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
@@ -122,7 +121,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
String defaultRole = ParamResolver.getStr("USER_DEFAULT_ROLE");
|
||||
// 默认角色
|
||||
SysRole sysRole = sysRoleService
|
||||
.getOne(Wrappers.<SysRole>lambdaQuery().eq(SysRole::getRoleCode, defaultRole));
|
||||
.getOne(Wrappers.<SysRole>lambdaQuery().eq(SysRole::getRoleCode, defaultRole));
|
||||
userDto.setRole(Collections.singletonList(sysRole.getRoleId()));
|
||||
}
|
||||
|
||||
@@ -146,20 +145,16 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
UserInfo userInfo = new UserInfo();
|
||||
userInfo.setSysUser(sysUser);
|
||||
// 设置角色列表 (ID)
|
||||
List<Long> roleIds = sysRoleService.findRolesByUserId(sysUser.getUserId())
|
||||
.stream()
|
||||
.map(SysRole::getRoleId)
|
||||
.collect(Collectors.toList());
|
||||
List<Long> roleIds = sysRoleService.findRolesByUserId(sysUser.getUserId()).stream().map(SysRole::getRoleId)
|
||||
.collect(Collectors.toList());
|
||||
userInfo.setRoles(ArrayUtil.toArray(roleIds, Long.class));
|
||||
|
||||
// 设置权限列表(menu.permission)
|
||||
Set<String> permissions = new HashSet<>();
|
||||
roleIds.forEach(roleId -> {
|
||||
List<String> permissionList = sysMenuService.findMenuByRoleId(roleId)
|
||||
.stream()
|
||||
.filter(menu -> StrUtil.isNotEmpty(menu.getPermission()))
|
||||
.map(SysMenu::getPermission)
|
||||
.collect(Collectors.toList());
|
||||
List<String> permissionList = sysMenuService.findMenuByRoleId(roleId).stream()
|
||||
.filter(menu -> StrUtil.isNotEmpty(menu.getPermission())).map(SysMenu::getPermission)
|
||||
.collect(Collectors.toList());
|
||||
permissions.addAll(permissionList);
|
||||
});
|
||||
userInfo.setPermissions(ArrayUtil.toArray(permissions, String.class));
|
||||
@@ -241,7 +236,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
// 更新用户角色表
|
||||
if (userDto.getRole() != null) {
|
||||
sysUserRoleMapper
|
||||
.delete(Wrappers.<SysUserRole>lambdaQuery().eq(SysUserRole::getUserId, userDto.getUserId()));
|
||||
.delete(Wrappers.<SysUserRole>lambdaQuery().eq(SysUserRole::getUserId, userDto.getUserId()));
|
||||
userDto.getRole().stream().map(roleId -> {
|
||||
SysUserRole userRole = new SysUserRole();
|
||||
userRole.setUserId(sysUser.getUserId());
|
||||
@@ -253,7 +248,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
// 更新用户岗位表
|
||||
if (userDto.getPost() != null) {
|
||||
sysUserPostMapper
|
||||
.delete(Wrappers.<SysUserPost>lambdaQuery().eq(SysUserPost::getUserId, userDto.getUserId()));
|
||||
.delete(Wrappers.<SysUserPost>lambdaQuery().eq(SysUserPost::getUserId, userDto.getUserId()));
|
||||
userDto.getPost().stream().map(postId -> {
|
||||
SysUserPost userPost = new SysUserPost();
|
||||
userPost.setUserId(sysUser.getUserId());
|
||||
@@ -297,15 +292,11 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
List<UserExcelVO> userExcelVOList = voList.stream().map(userVO -> {
|
||||
UserExcelVO excelVO = new UserExcelVO();
|
||||
BeanUtils.copyProperties(userVO, excelVO);
|
||||
String roleNameList = userVO.getRoleList()
|
||||
.stream()
|
||||
.map(SysRole::getRoleName)
|
||||
.collect(Collectors.joining(StrUtil.COMMA));
|
||||
String roleNameList = userVO.getRoleList().stream().map(SysRole::getRoleName)
|
||||
.collect(Collectors.joining(StrUtil.COMMA));
|
||||
excelVO.setRoleNameList(roleNameList);
|
||||
String postNameList = userVO.getPostList()
|
||||
.stream()
|
||||
.map(SysPost::getPostName)
|
||||
.collect(Collectors.joining(StrUtil.COMMA));
|
||||
String postNameList = userVO.getPostList().stream().map(SysPost::getPostName)
|
||||
.collect(Collectors.joining(StrUtil.COMMA));
|
||||
excelVO.setPostNameList(postNameList);
|
||||
return excelVO;
|
||||
}).collect(Collectors.toList());
|
||||
@@ -334,7 +325,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
Set<String> errorMsg = new HashSet<>();
|
||||
// 校验用户名是否存在
|
||||
boolean exsitUserName = userList.stream()
|
||||
.anyMatch(sysUser -> excel.getUsername().equals(sysUser.getUsername()));
|
||||
.anyMatch(sysUser -> excel.getUsername().equals(sysUser.getUsername()));
|
||||
|
||||
if (exsitUserName) {
|
||||
errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_USER_USERNAME_EXISTING, excel.getUsername()));
|
||||
@@ -342,8 +333,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
|
||||
// 判断输入的部门名称列表是否合法
|
||||
Optional<SysDept> deptOptional = deptList.stream()
|
||||
.filter(dept -> excel.getDeptName().equals(dept.getName()))
|
||||
.findFirst();
|
||||
.filter(dept -> excel.getDeptName().equals(dept.getName())).findFirst();
|
||||
if (!deptOptional.isPresent()) {
|
||||
errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_DEPT_DEPTNAME_INEXISTENCE, excel.getDeptName()));
|
||||
}
|
||||
@@ -351,8 +341,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
// 判断输入的角色名称列表是否合法
|
||||
List<String> roleNameList = StrUtil.split(excel.getRoleNameList(), StrUtil.COMMA);
|
||||
List<SysRole> roleCollList = roleList.stream()
|
||||
.filter(role -> roleNameList.stream().anyMatch(name -> role.getRoleName().equals(name)))
|
||||
.collect(Collectors.toList());
|
||||
.filter(role -> roleNameList.stream().anyMatch(name -> role.getRoleName().equals(name)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (roleCollList.size() != roleNameList.size()) {
|
||||
errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_ROLE_ROLENAME_INEXISTENCE, excel.getRoleNameList()));
|
||||
@@ -361,8 +351,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
// 判断输入的部门名称列表是否合法
|
||||
List<String> postNameList = StrUtil.split(excel.getPostNameList(), StrUtil.COMMA);
|
||||
List<SysPost> postCollList = postList.stream()
|
||||
.filter(post -> postNameList.stream().anyMatch(name -> post.getPostName().equals(name)))
|
||||
.collect(Collectors.toList());
|
||||
.filter(post -> postNameList.stream().anyMatch(name -> post.getPostName().equals(name)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (postCollList.size() != postNameList.size()) {
|
||||
errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_POST_POSTNAME_INEXISTENCE, excel.getPostNameList()));
|
||||
@@ -467,9 +457,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
}
|
||||
String password = ENCODER.encode(userDto.getNewpassword1());
|
||||
|
||||
this.update(Wrappers.<SysUser>lambdaUpdate()
|
||||
.set(SysUser::getPassword, password)
|
||||
.eq(SysUser::getUserId, userVO.getUserId()));
|
||||
this.update(Wrappers.<SysUser>lambdaUpdate().set(SysUser::getPassword, password).eq(SysUser::getUserId,
|
||||
userVO.getUserId()));
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@@ -478,24 +467,20 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
PigxUser user = SecurityUtils.getUser();
|
||||
LambdaUpdateWrapper<SysUser> wrapper = null;
|
||||
if (type.equals("wechat")) {
|
||||
wrapper = Wrappers.<SysUser>lambdaUpdate()
|
||||
.set(SysUser::getWxOpenid, null)
|
||||
.eq(SysUser::getUserId, user.getId());
|
||||
wrapper = Wrappers.<SysUser>lambdaUpdate().set(SysUser::getWxOpenid, null).eq(SysUser::getUserId,
|
||||
user.getId());
|
||||
}
|
||||
else if (type.equals("gitee")) {
|
||||
wrapper = Wrappers.<SysUser>lambdaUpdate()
|
||||
.set(SysUser::getGiteeLogin, null)
|
||||
.eq(SysUser::getUserId, user.getId());
|
||||
wrapper = Wrappers.<SysUser>lambdaUpdate().set(SysUser::getGiteeLogin, null).eq(SysUser::getUserId,
|
||||
user.getId());
|
||||
}
|
||||
else if (type.equals("osc")) {
|
||||
wrapper = Wrappers.<SysUser>lambdaUpdate()
|
||||
.set(SysUser::getOscId, null)
|
||||
.eq(SysUser::getUserId, user.getId());
|
||||
wrapper = Wrappers.<SysUser>lambdaUpdate().set(SysUser::getOscId, null).eq(SysUser::getUserId,
|
||||
user.getId());
|
||||
}
|
||||
else if (type.equals("tencent")) {
|
||||
wrapper = Wrappers.<SysUser>lambdaUpdate()
|
||||
.set(SysUser::getQqOpenid, null)
|
||||
.eq(SysUser::getUserId, user.getId());
|
||||
wrapper = Wrappers.<SysUser>lambdaUpdate().set(SysUser::getQqOpenid, null).eq(SysUser::getUserId,
|
||||
user.getId());
|
||||
}
|
||||
if (wrapper == null) {
|
||||
return R.failed("解绑账号类型不存在");
|
||||
@@ -523,9 +508,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
@Override
|
||||
public List<Long> listUserIdByRoleIds(List<Long> roleIdList) {
|
||||
return sysUserRoleMapper.selectList(Wrappers.<SysUserRole>lambdaQuery().in(SysUserRole::getRoleId, roleIdList))
|
||||
.stream()
|
||||
.map(SysUserRole::getUserId)
|
||||
.collect(Collectors.toList());
|
||||
.stream().map(SysUserRole::getUserId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
+17
-26
@@ -186,8 +186,8 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
|
||||
// 获取模板信息,Lambda 表达式简化代码
|
||||
GenTemplateEntity genTemplateEntity = Optional
|
||||
.ofNullable(genTemplateService.getById(GeneratorStyleEnum.VFORM_JSON.getTemplateId()))
|
||||
.orElseThrow(() -> new Exception("模板不存在"));
|
||||
.ofNullable(genTemplateService.getById(GeneratorStyleEnum.VFORM_JSON.getTemplateId()))
|
||||
.orElseThrow(() -> new Exception("模板不存在"));
|
||||
|
||||
// 渲染模板并返回结果
|
||||
return VelocityKit.renderStr(genTemplateEntity.getTemplateCode(), dataModel);
|
||||
@@ -218,8 +218,8 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
|
||||
// 获取模板信息
|
||||
GenTemplateEntity genTemplateEntity = Optional
|
||||
.ofNullable(genTemplateService.getById(GeneratorStyleEnum.VFORM_FORM.getTemplateId()))
|
||||
.orElseThrow(() -> new Exception("模板不存在"));
|
||||
.ofNullable(genTemplateService.getById(GeneratorStyleEnum.VFORM_FORM.getTemplateId()))
|
||||
.orElseThrow(() -> new Exception("模板不存在"));
|
||||
|
||||
// 渲染模板并返回结果
|
||||
return VelocityKit.renderStr(genTemplateEntity.getTemplateCode(), dataModel);
|
||||
@@ -235,10 +235,9 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
GenTable table = tableService.getById(tableId);
|
||||
// 获取字段列表
|
||||
List<GenTableColumnEntity> fieldList = columnService.lambdaQuery()
|
||||
.eq(GenTableColumnEntity::getDsName, table.getDsName())
|
||||
.eq(GenTableColumnEntity::getTableName, table.getTableName())
|
||||
.orderByAsc(GenTableColumnEntity::getSort)
|
||||
.list();
|
||||
.eq(GenTableColumnEntity::getDsName, table.getDsName())
|
||||
.eq(GenTableColumnEntity::getTableName, table.getTableName()).orderByAsc(GenTableColumnEntity::getSort)
|
||||
.list();
|
||||
|
||||
table.setFieldList(fieldList);
|
||||
|
||||
@@ -278,9 +277,8 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
String childTableName = table.getChildTableName();
|
||||
if (StrUtil.isNotBlank(childTableName)) {
|
||||
List<GenTableColumnEntity> childFieldList = columnService.lambdaQuery()
|
||||
.eq(GenTableColumnEntity::getDsName, table.getDsName())
|
||||
.eq(GenTableColumnEntity::getTableName, table.getChildTableName())
|
||||
.list();
|
||||
.eq(GenTableColumnEntity::getDsName, table.getDsName())
|
||||
.eq(GenTableColumnEntity::getTableName, table.getChildTableName()).list();
|
||||
dataModel.put("childFieldList", childFieldList);
|
||||
dataModel.put("childTableName", childTableName);
|
||||
dataModel.put("mainField", NamingCase.toCamelCase(table.getMainField()));
|
||||
@@ -307,25 +305,18 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
*/
|
||||
private void setFieldTypeList(Map<String, Object> dataModel, GenTable table) {
|
||||
// 按字段类型分组,使用 Map 存储不同类型的字段列表
|
||||
Map<Boolean, List<GenTableColumnEntity>> typeMap = table.getFieldList()
|
||||
.stream()
|
||||
.collect(Collectors
|
||||
Map<Boolean, List<GenTableColumnEntity>> typeMap = table.getFieldList().stream().collect(Collectors
|
||||
.partitioningBy(columnEntity -> BooleanUtil.toBoolean(columnEntity.getPrimaryPk().toString())));
|
||||
|
||||
// 从分组后的 Map 中获取不同类型的字段列表
|
||||
List<GenTableColumnEntity> primaryList = typeMap.get(true);
|
||||
List<GenTableColumnEntity> formList = typeMap.get(false)
|
||||
.stream()
|
||||
.filter(columnEntity -> BooleanUtil.toBoolean(columnEntity.getFormItem()))
|
||||
.collect(Collectors.toList());
|
||||
List<GenTableColumnEntity> gridList = typeMap.get(false)
|
||||
.stream()
|
||||
.filter(columnEntity -> BooleanUtil.toBoolean(columnEntity.getGridItem()))
|
||||
.collect(Collectors.toList());
|
||||
List<GenTableColumnEntity> queryList = typeMap.get(false)
|
||||
.stream()
|
||||
.filter(columnEntity -> BooleanUtil.toBoolean(columnEntity.getQueryItem()))
|
||||
.collect(Collectors.toList());
|
||||
List<GenTableColumnEntity> formList = typeMap.get(false).stream()
|
||||
.filter(columnEntity -> BooleanUtil.toBoolean(columnEntity.getFormItem())).collect(Collectors.toList());
|
||||
List<GenTableColumnEntity> gridList = typeMap.get(false).stream()
|
||||
.filter(columnEntity -> BooleanUtil.toBoolean(columnEntity.getGridItem())).collect(Collectors.toList());
|
||||
List<GenTableColumnEntity> queryList = typeMap.get(false).stream()
|
||||
.filter(columnEntity -> BooleanUtil.toBoolean(columnEntity.getQueryItem()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (CollUtil.isNotEmpty(primaryList)) {
|
||||
dataModel.put("pk", primaryList.get(0));
|
||||
|
||||
Reference in new issue
Block a user