refactor(system): 统一使用VO对象进行数据传输和处理

This commit is contained in:
2026-01-07 18:37:59 +08:00
parent e88d535153
commit 6364b0f577
34 changed files with 300 additions and 297 deletions
@@ -67,8 +67,8 @@ public class SystemMenuController {
@ApiOperation("返回全部的菜单") @ApiOperation("返回全部的菜单")
@PostMapping(value = "/listMenuByPid") @PostMapping(value = "/listMenuByPid")
@PreAuthorize("@el.check('menu:list','roles:list')") @PreAuthorize("@el.check('menu:list','roles:list')")
public ResponseEntity<List<SystemMenuTb>> listMenuByPid(@RequestParam Long pid) { public ResponseEntity<List<SystemMenuVo>> listMenuByPid(@RequestParam Long pid) {
List<SystemMenuTb> systemMenuTbs = systemMenuService.listMenuByPid(pid); List<SystemMenuVo> systemMenuTbs = systemMenuService.listMenuByPid(pid);
return ResponseEntity.ok(systemMenuTbs); return ResponseEntity.ok(systemMenuTbs);
} }
@@ -21,7 +21,7 @@ import cn.odboy.base.KitSelectOptionVo;
import cn.odboy.system.dal.dataobject.SystemUserTb; import cn.odboy.system.dal.dataobject.SystemUserTb;
import cn.odboy.system.dal.model.SystemQueryUserArgs; import cn.odboy.system.dal.model.SystemQueryUserArgs;
import cn.odboy.system.dal.model.SystemUpdateUserPasswordArgs; import cn.odboy.system.dal.model.SystemUpdateUserPasswordArgs;
import cn.odboy.system.dal.model.SystemUserInfoVo; import cn.odboy.system.dal.model.SystemUserJwtVo;
import cn.odboy.system.dal.model.SystemUserVo; import cn.odboy.system.dal.model.SystemUserVo;
import cn.odboy.system.framework.operalog.OperationLog; import cn.odboy.system.framework.operalog.OperationLog;
import cn.odboy.system.framework.permission.core.KitSecurityHelper; import cn.odboy.system.framework.permission.core.KitSecurityHelper;
@@ -151,8 +151,8 @@ public class SystemUserController {
@ApiOperation("获取用户信息") @ApiOperation("获取用户信息")
@PostMapping(value = "/getCurrentUserInfo") @PostMapping(value = "/getCurrentUserInfo")
public ResponseEntity<SystemUserInfoVo> getUserInfo() { public ResponseEntity<SystemUserJwtVo> getUserInfo() {
SystemUserInfoVo userInfoVo = systemAuthService.getCurrentUserInfoVo(); SystemUserJwtVo userInfoVo = systemAuthService.getCurrentUserInfo();
return ResponseEntity.ok(userInfoVo); return ResponseEntity.ok(userInfoVo);
} }
} }
@@ -1,7 +1,6 @@
package cn.odboy.system.dal.model; package cn.odboy.system.dal.model;
import cn.odboy.system.dal.dataobject.SystemDeptTb; import cn.odboy.system.dal.dataobject.SystemDeptTb;
import cn.odboy.system.dal.dataobject.SystemMenuTb;
import cn.odboy.system.dal.dataobject.SystemRoleTb; import cn.odboy.system.dal.dataobject.SystemRoleTb;
import cn.odboy.system.dal.dataobject.SystemUserTb; import cn.odboy.system.dal.dataobject.SystemUserTb;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@@ -16,7 +15,7 @@ public class SystemRoleVo extends SystemRoleTb {
@ApiModelProperty(value = "用户", hidden = true) @ApiModelProperty(value = "用户", hidden = true)
private Set<SystemUserTb> users; private Set<SystemUserTb> users;
@ApiModelProperty(value = "菜单", hidden = true) @ApiModelProperty(value = "菜单", hidden = true)
private Set<SystemMenuTb> menus; private Set<SystemMenuVo> menus;
@ApiModelProperty(value = "部门", hidden = true) @ApiModelProperty(value = "部门", hidden = true)
private Set<SystemDeptTb> depts; private Set<SystemDeptTb> depts;
} }
@@ -12,6 +12,7 @@ import lombok.Setter;
@Getter @Getter
@Setter @Setter
public class SystemUserVo extends SystemUserTb { public class SystemUserVo extends SystemUserTb {
@ApiModelProperty(value = "用户部门") @ApiModelProperty(value = "用户部门")
private SystemDeptTb dept; private SystemDeptTb dept;
@ApiModelProperty(value = "用户角色") @ApiModelProperty(value = "用户角色")
@@ -5,6 +5,7 @@ import cn.odboy.base.KitPageResult;
import cn.odboy.framework.properties.AppProperties; import cn.odboy.framework.properties.AppProperties;
import cn.odboy.framework.redis.KitRedisHelper; import cn.odboy.framework.redis.KitRedisHelper;
import cn.odboy.system.dal.model.SystemUserJwtVo; import cn.odboy.system.dal.model.SystemUserJwtVo;
import cn.odboy.system.dal.model.SystemUserOnlineExportRowVo;
import cn.odboy.system.dal.model.SystemUserOnlineVo; import cn.odboy.system.dal.model.SystemUserOnlineVo;
import cn.odboy.system.framework.permission.core.handler.TokenProvider; import cn.odboy.system.framework.permission.core.handler.TokenProvider;
import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitBeanUtil;
@@ -167,9 +168,7 @@ public class SystemUserOnlineInfoDAO {
public void exportOnlineUserXlsx(HttpServletResponse response, String username) { public void exportOnlineUserXlsx(HttpServletResponse response, String username) {
List<SystemUserOnlineVo> userOnlineVos = this.queryUserOnlineModelListByUsername(username); List<SystemUserOnlineVo> userOnlineVos = this.queryUserOnlineModelListByUsername(username);
// KitXlsxExportUtil.exportFile(response, "在线用户数据", userOnlineVos, SystemUserOnlineExportRowVo.class, List<SystemUserOnlineExportRowVo> rowVos = KitBeanUtil.copyToList(userOnlineVos, SystemUserOnlineExportRowVo.class);
// (dataObject) -> CollUtil.newArrayList(KitBeanUtil.copyProperties(dataObject, SystemUserOnlineExportRowVo.class))); KitExcelExporter.exportSimple(response, "在线用户数据", SystemUserOnlineExportRowVo.class, rowVos);
List<SystemUserOnlineVo> rowVos = KitBeanUtil.copyToList(userOnlineVos, SystemUserOnlineVo.class);
KitExcelExporter.exportSimple(response, "在线用户数据", SystemUserOnlineVo.class, rowVos);
} }
} }
@@ -71,6 +71,7 @@ public class SystemAuthService {
// 返回 token 与 用户信息 // 返回 token 与 用户信息
Map<String, Object> authInfo = new HashMap<>(2) {{ Map<String, Object> authInfo = new HashMap<>(2) {{
put("token", String.format("%s %s", SystemConst.TOKEN_PREFIX, token)); put("token", String.format("%s %s", SystemConst.TOKEN_PREFIX, token));
// 这里是为了清空密码
put("user", KitBeanUtil.copyToClass(jwtUser, SystemUserInfoVo.class)); put("user", KitBeanUtil.copyToClass(jwtUser, SystemUserInfoVo.class));
}}; }};
if (properties.getLogin().isSingle()) { if (properties.getLogin().isSingle()) {
@@ -83,10 +84,12 @@ public class SystemAuthService {
return authInfo; return authInfo;
} }
public SystemUserInfoVo getCurrentUserInfoVo() { public SystemUserJwtVo getCurrentUserInfo() {
SystemUserJwtVo jwtUser = (SystemUserJwtVo) KitSecurityHelper.getCurrentUser(); SystemUserJwtVo jwtUser = (SystemUserJwtVo) KitSecurityHelper.getCurrentUser();
// 转换是为了去掉密码 if (jwtUser.getUser() != null) {
return KitBeanUtil.copyToClass(jwtUser, SystemUserInfoVo.class); jwtUser.getUser().setPassword(null);
}
return jwtUser;
} }
public Map<String, Object> getCaptchaInfo() { public Map<String, Object> getCaptchaInfo() {
@@ -19,6 +19,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.odboy.system.constant.SystemDataScopeEnum; import cn.odboy.system.constant.SystemDataScopeEnum;
import cn.odboy.system.dal.dataobject.SystemDeptTb; import cn.odboy.system.dal.dataobject.SystemDeptTb;
import cn.odboy.system.dal.dataobject.SystemRoleTb; import cn.odboy.system.dal.dataobject.SystemRoleTb;
import cn.odboy.system.dal.model.SystemDeptVo;
import cn.odboy.system.dal.model.SystemRoleVo; import cn.odboy.system.dal.model.SystemRoleVo;
import cn.odboy.system.dal.model.SystemUserVo; import cn.odboy.system.dal.model.SystemUserVo;
import java.util.ArrayList; import java.util.ArrayList;
@@ -81,7 +82,7 @@ public class SystemDataService {
List<SystemDeptTb> deptList = systemRoleDeptService.listDeptByRoleId(role.getId()); List<SystemDeptTb> deptList = systemRoleDeptService.listDeptByRoleId(role.getId());
for (SystemDeptTb dept : deptList) { for (SystemDeptTb dept : deptList) {
deptIds.add(dept.getId()); deptIds.add(dept.getId());
List<SystemDeptTb> deptChildren = systemDeptService.listDeptByPid(dept.getId()); List<SystemDeptVo> deptChildren = systemDeptService.listDeptByPid(dept.getId());
if (CollUtil.isNotEmpty(deptChildren)) { if (CollUtil.isNotEmpty(deptChildren)) {
deptIds.addAll(systemDeptService.queryChildDeptIdByDeptIds(deptChildren)); deptIds.addAll(systemDeptService.queryChildDeptIdByDeptIds(deptChildren));
} }
@@ -34,6 +34,7 @@ import cn.odboy.system.dal.mysql.SystemDeptMapper;
import cn.odboy.system.framework.permission.core.KitSecurityHelper; import cn.odboy.system.framework.permission.core.KitSecurityHelper;
import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitBeanUtil;
import cn.odboy.util.KitClassUtil; import cn.odboy.util.KitClassUtil;
import cn.odboy.util.KitValidUtil;
import cn.odboy.util.xlsx.KitExcelExporter; import cn.odboy.util.xlsx.KitExcelExporter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@@ -69,7 +70,8 @@ public class SystemDeptService {
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void saveDept(SystemCreateDeptArgs args) { public void saveDept(SystemCreateDeptArgs args) {
systemDeptMapper.insert(KitBeanUtil.copyToClass(args, SystemDeptTb.class)); SystemDeptTb deptTb = KitBeanUtil.copyToClass(args, SystemDeptTb.class);
systemDeptMapper.insert(deptTb);
this.updateDeptSubCnt(args.getPid()); this.updateDeptSubCnt(args.getPid());
} }
@@ -146,17 +148,16 @@ public class SystemDeptService {
} }
private List<SystemDeptTb> queryDeptByArgs(SystemQueryDeptArgs args) { private List<SystemDeptTb> queryDeptByArgs(SystemQueryDeptArgs args) {
KitValidUtil.notNull(args);
LambdaQueryWrapper<SystemDeptTb> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SystemDeptTb> wrapper = new LambdaQueryWrapper<>();
if (args != null) { wrapper.in(CollUtil.isNotEmpty(args.getIds()), SystemDeptTb::getId, args.getIds());
wrapper.in(CollUtil.isNotEmpty(args.getIds()), SystemDeptTb::getId, args.getIds()); wrapper.like(StrUtil.isNotBlank(args.getName()), SystemDeptTb::getName, args.getName());
wrapper.like(StrUtil.isNotBlank(args.getName()), SystemDeptTb::getName, args.getName()); wrapper.eq(args.getEnabled() != null, SystemDeptTb::getEnabled, args.getEnabled());
wrapper.eq(args.getEnabled() != null, SystemDeptTb::getEnabled, args.getEnabled()); wrapper.eq(args.getPid() != null, SystemDeptTb::getPid, args.getPid());
wrapper.eq(args.getPid() != null, SystemDeptTb::getPid, args.getPid()); wrapper.isNull(args.getPidIsNull() != null, SystemDeptTb::getPid);
wrapper.isNull(args.getPidIsNull() != null, SystemDeptTb::getPid); if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) { wrapper.between(SystemDeptTb::getCreateTime, args.getCreateTime().get(0),
wrapper.between(SystemDeptTb::getCreateTime, args.getCreateTime().get(0), args.getCreateTime().get(1));
args.getCreateTime().get(1));
}
} }
wrapper.orderByAsc(SystemDeptTb::getDeptSort); wrapper.orderByAsc(SystemDeptTb::getDeptSort);
return systemDeptMapper.selectList(wrapper); return systemDeptMapper.selectList(wrapper);
@@ -221,10 +222,10 @@ public class SystemDeptService {
* @param depts / * @param depts /
* @return / * @return /
*/ */
private Set<SystemDeptTb> queryRelationDeptByArgs(List<SystemDeptTb> deptTbList, Set<SystemDeptTb> depts) { private Set<SystemDeptTb> queryRelationDeptByArgs(List<SystemDeptVo> deptTbList, Set<SystemDeptTb> depts) {
for (SystemDeptTb dept : deptTbList) { for (SystemDeptTb dept : deptTbList) {
depts.add(dept); depts.add(dept);
List<SystemDeptTb> deptList = this.listDeptByPid(dept.getId()); List<SystemDeptVo> deptList = this.listDeptByPid(dept.getId());
if (CollUtil.isNotEmpty(deptList)) { if (CollUtil.isNotEmpty(deptList)) {
queryRelationDeptByArgs(deptList, depts); queryRelationDeptByArgs(deptList, depts);
} }
@@ -232,11 +233,11 @@ public class SystemDeptService {
return depts; return depts;
} }
public List<Long> queryChildDeptIdByDeptIds(List<SystemDeptTb> deptList) { public List<Long> queryChildDeptIdByDeptIds(List<SystemDeptVo> deptList) {
List<Long> list = new ArrayList<>(); List<Long> list = new ArrayList<>();
for (SystemDeptTb systemDeptTb : deptList) { for (SystemDeptVo systemDeptTb : deptList) {
if (systemDeptTb != null && systemDeptTb.getEnabled()) { if (systemDeptTb != null && systemDeptTb.getEnabled()) {
List<SystemDeptTb> deptList1 = this.listDeptByPid(systemDeptTb.getId()); List<SystemDeptVo> deptList1 = this.listDeptByPid(systemDeptTb.getId());
if (CollUtil.isNotEmpty(deptList1)) { if (CollUtil.isNotEmpty(deptList1)) {
list.addAll(queryChildDeptIdByDeptIds(deptList1)); list.addAll(queryChildDeptIdByDeptIds(deptList1));
} }
@@ -253,7 +254,7 @@ public class SystemDeptService {
* @param deptList / * @param deptList /
* @return / * @return /
*/ */
private List<SystemDeptTb> querySuperiorDeptByPid(SystemDeptTb dept, List<SystemDeptTb> deptList) { private List<SystemDeptVo> querySuperiorDeptByPid(SystemDeptTb dept, List<SystemDeptVo> deptList) {
if (dept.getPid() == null) { if (dept.getPid() == null) {
deptList.addAll(this.listRootDept()); deptList.addAll(this.listRootDept());
return deptList; return deptList;
@@ -262,10 +263,10 @@ public class SystemDeptService {
return querySuperiorDeptByPid(this.getDeptById(dept.getPid()), deptList); return querySuperiorDeptByPid(this.getDeptById(dept.getPid()), deptList);
} }
private List<SystemDeptTb> listRootDept() { private List<SystemDeptVo> listRootDept() {
LambdaQueryWrapper<SystemDeptTb> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SystemDeptTb> wrapper = new LambdaQueryWrapper<>();
wrapper.isNull(SystemDeptTb::getPid); wrapper.isNull(SystemDeptTb::getPid);
return systemDeptMapper.selectList(wrapper); return KitBeanUtil.copyToList(systemDeptMapper.selectList(wrapper), SystemDeptVo.class);
} }
/** /**
@@ -274,14 +275,14 @@ public class SystemDeptService {
* @return / * @return /
*/ */
public KitPageResult<SystemDeptVo> searchDeptTree(List<Long> ids, Boolean exclude) { public KitPageResult<SystemDeptVo> searchDeptTree(List<Long> ids, Boolean exclude) {
Set<SystemDeptTb> deptSet1 = new LinkedHashSet<>(); Set<SystemDeptVo> deptSet1 = new LinkedHashSet<>();
for (Long id : ids) { for (Long id : ids) {
// 同级数据 // 同级数据
SystemDeptTb dept = this.getDeptById(id); SystemDeptTb dept = this.getDeptById(id);
// 上级数据 // 上级数据
List<SystemDeptTb> depts = this.querySuperiorDeptByPid(dept, new ArrayList<>()); List<SystemDeptVo> depts = this.querySuperiorDeptByPid(dept, new ArrayList<>());
if (exclude) { if (exclude) {
for (SystemDeptTb data : depts) { for (SystemDeptVo data : depts) {
if (data.getId().equals(dept.getPid())) { if (data.getId().equals(dept.getPid())) {
data.setSubCount(data.getSubCount() - 1); data.setSubCount(data.getSubCount() - 1);
} }
@@ -291,7 +292,7 @@ public class SystemDeptService {
} }
deptSet1.addAll(depts); deptSet1.addAll(depts);
} }
List<SystemDeptVo> deptList = KitBeanUtil.copyToList(new ArrayList<>(deptSet1), SystemDeptVo.class); List<SystemDeptVo> deptList = new ArrayList<>(deptSet1);
// 构建部门树 // 构建部门树
Set<SystemDeptVo> trees = new LinkedHashSet<>(); Set<SystemDeptVo> trees = new LinkedHashSet<>();
Set<SystemDeptVo> deptSet = new LinkedHashSet<>(); Set<SystemDeptVo> deptSet = new LinkedHashSet<>();
@@ -358,9 +359,9 @@ public class SystemDeptService {
// 根部门 // 根部门
depts.add(this.getDeptById(id)); depts.add(this.getDeptById(id));
// 子部门 // 子部门
List<SystemDeptTb> deptList = listDeptByPid(id); List<SystemDeptVo> deptList = this.listDeptByPid(id);
if (CollectionUtil.isNotEmpty(deptList)) { if (CollectionUtil.isNotEmpty(deptList)) {
depts = queryRelationDeptByArgs(deptList, depts); queryRelationDeptByArgs(deptList, depts);
} }
} }
return depts; return depts;
@@ -464,10 +465,10 @@ public class SystemDeptService {
return vo; return vo;
} }
public List<SystemDeptTb> listDeptByPid(long pid) { public List<SystemDeptVo> listDeptByPid(long pid) {
LambdaQueryWrapper<SystemDeptTb> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SystemDeptTb> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(SystemDeptTb::getPid, pid); wrapper.eq(SystemDeptTb::getPid, pid);
return systemDeptMapper.selectList(wrapper); return KitBeanUtil.copyToList(systemDeptMapper.selectList(wrapper), SystemDeptVo.class);
} }
public void exportDeptXlsx(HttpServletResponse response, SystemQueryDeptArgs args) throws Exception { public void exportDeptXlsx(HttpServletResponse response, SystemQueryDeptArgs args) throws Exception {
@@ -27,6 +27,7 @@ import cn.odboy.system.dal.mysql.SystemDictDetailMapper;
import cn.odboy.system.dal.mysql.SystemDictMapper; import cn.odboy.system.dal.mysql.SystemDictMapper;
import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitBeanUtil;
import cn.odboy.util.KitPageUtil; import cn.odboy.util.KitPageUtil;
import cn.odboy.util.KitValidUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -55,6 +56,8 @@ public class SystemDictDetailService {
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void saveDictDetail(SystemCreateDictDetailArgs args) { public void saveDictDetail(SystemCreateDictDetailArgs args) {
KitValidUtil.notNull(args);
KitValidUtil.notNull(args.getDict());
SystemDictDetailTb dictDetail = KitBeanUtil.copyToClass(args, SystemDictDetailTb.class); SystemDictDetailTb dictDetail = KitBeanUtil.copyToClass(args, SystemDictDetailTb.class);
dictDetail.setDictId(args.getDict().getId()); dictDetail.setDictId(args.getDict().getId());
systemDictDetailMapper.insert(dictDetail); systemDictDetailMapper.insert(dictDetail);
@@ -104,8 +107,7 @@ public class SystemDictDetailService {
* @param page 分页参数 * @param page 分页参数
* @return / * @return /
*/ */
public KitPageResult<SystemDictDetailVo> searchDictDetail(SystemQueryDictDetailArgs args, public KitPageResult<SystemDictDetailVo> searchDictDetail(SystemQueryDictDetailArgs args, Page<SystemDictDetailTb> page) {
Page<SystemDictDetailTb> page) {
IPage<SystemDictDetailVo> iPage = systemDictDetailMapper.selectPageByArgs(page, args).convert(i -> KitBeanUtil.copyToClass(i, SystemDictDetailVo.class)); IPage<SystemDictDetailVo> iPage = systemDictDetailMapper.selectPageByArgs(page, args).convert(i -> KitBeanUtil.copyToClass(i, SystemDictDetailVo.class));
List<Long> dictIds = iPage.getRecords().stream().map(SystemDictDetailTb::getDictId).collect(Collectors.toList()); List<Long> dictIds = iPage.getRecords().stream().map(SystemDictDetailTb::getDictId).collect(Collectors.toList());
Map<Long, SystemDictTb> id2ItemMap = systemDictMapper.selectByIds(dictIds).stream().collect(Collectors.toMap(SystemDictTb::getId, i -> i)); Map<Long, SystemDictTb> id2ItemMap = systemDictMapper.selectByIds(dictIds).stream().collect(Collectors.toMap(SystemDictTb::getId, i -> i));
@@ -129,11 +131,12 @@ public class SystemDictDetailService {
if (systemDictTb == null) { if (systemDictTb == null) {
return new ArrayList<>(); return new ArrayList<>();
} }
return this.listDictDetailByDictId(systemDictTb.getId()).stream().map(m -> { List<SystemDictDetailTb> detailTbs = this.listDictDetailByDictId(systemDictTb.getId());
SystemDictDetailVo detailVo = KitBeanUtil.copyToClass(m, SystemDictDetailVo.class); List<SystemDictDetailVo> detailVos = KitBeanUtil.copyToList(detailTbs, SystemDictDetailVo.class);
for (SystemDictDetailVo detailVo : detailVos) {
detailVo.setDict(systemDictTb); detailVo.setDict(systemDictTb);
return detailVo; }
}).collect(Collectors.toList()); return detailVos;
} }
public Map<String, List<SystemDictDetailVo>> getDictDetailMap(String dictName) { public Map<String, List<SystemDictDetailVo>> getDictDetailMap(String dictName) {
@@ -26,6 +26,7 @@ import cn.odboy.system.dal.model.SystemQueryDictArgs;
import cn.odboy.system.dal.mysql.SystemDictMapper; import cn.odboy.system.dal.mysql.SystemDictMapper;
import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitBeanUtil;
import cn.odboy.util.KitPageUtil; import cn.odboy.util.KitPageUtil;
import cn.odboy.util.KitValidUtil;
import cn.odboy.util.xlsx.KitExcelExporter; import cn.odboy.util.xlsx.KitExcelExporter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -52,7 +53,8 @@ public class SystemDictService {
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void saveDict(SystemCreateDictArgs args) { public void saveDict(SystemCreateDictArgs args) {
systemDictMapper.insert(KitBeanUtil.copyToClass(args, SystemDictTb.class)); SystemDictTb dictTb = KitBeanUtil.copyToClass(args, SystemDictTb.class);
systemDictMapper.insert(dictTb);
} }
/** /**
@@ -96,10 +98,9 @@ public class SystemDictService {
} }
private void injectQueryParams(SystemQueryDictArgs args, LambdaQueryWrapper<SystemDictTb> wrapper) { private void injectQueryParams(SystemQueryDictArgs args, LambdaQueryWrapper<SystemDictTb> wrapper) {
if (args != null) { KitValidUtil.notNull(args);
wrapper.and(StrUtil.isNotBlank(args.getBlurry()), c -> c.like(SystemDictTb::getName, args.getBlurry()).or() wrapper.and(StrUtil.isNotBlank(args.getBlurry()), c -> c.like(SystemDictTb::getName, args.getBlurry()).or()
.like(SystemDictTb::getDescription, args.getBlurry())); .like(SystemDictTb::getDescription, args.getBlurry()));
}
} }
public List<SystemDictTb> queryDictByArgs(SystemQueryDictArgs args) { public List<SystemDictTb> queryDictByArgs(SystemQueryDictArgs args) {
@@ -26,6 +26,7 @@ import cn.odboy.system.dal.model.SystemQueryJobArgs;
import cn.odboy.system.dal.mysql.SystemJobMapper; import cn.odboy.system.dal.mysql.SystemJobMapper;
import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitBeanUtil;
import cn.odboy.util.KitPageUtil; import cn.odboy.util.KitPageUtil;
import cn.odboy.util.KitValidUtil;
import cn.odboy.util.xlsx.KitExcelExporter; import cn.odboy.util.xlsx.KitExcelExporter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -56,7 +57,8 @@ public class SystemJobService {
if (job != null) { if (job != null) {
throw new BadRequestException("职位名称已存在"); throw new BadRequestException("职位名称已存在");
} }
systemJobMapper.insert(KitBeanUtil.copyToClass(args, SystemJobTb.class)); SystemJobTb systemJobTb = KitBeanUtil.copyToClass(args, SystemJobTb.class);
systemJobMapper.insert(systemJobTb);
} }
/** /**
@@ -127,13 +129,12 @@ public class SystemJobService {
} }
public void injectQueryParams(SystemQueryJobArgs args, LambdaQueryWrapper<SystemJobTb> wrapper) { public void injectQueryParams(SystemQueryJobArgs args, LambdaQueryWrapper<SystemJobTb> wrapper) {
if (args != null) { KitValidUtil.notNull(args);
wrapper.like(StrUtil.isNotBlank(args.getName()), SystemJobTb::getName, args.getName()); wrapper.like(StrUtil.isNotBlank(args.getName()), SystemJobTb::getName, args.getName());
wrapper.eq(args.getEnabled() != null, SystemJobTb::getEnabled, args.getEnabled()); wrapper.eq(args.getEnabled() != null, SystemJobTb::getEnabled, args.getEnabled());
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) { if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
wrapper.between(SystemJobTb::getCreateTime, args.getCreateTime().get(0), wrapper.between(SystemJobTb::getCreateTime, args.getCreateTime().get(0),
args.getCreateTime().get(1)); args.getCreateTime().get(1));
}
} }
wrapper.orderByDesc(SystemJobTb::getJobSort, SystemJobTb::getId); wrapper.orderByDesc(SystemJobTb::getJobSort, SystemJobTb::getId);
} }
@@ -33,6 +33,7 @@ import cn.odboy.system.dal.mysql.SystemLocalStorageMapper;
import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitBeanUtil;
import cn.odboy.util.KitFileUtil; import cn.odboy.util.KitFileUtil;
import cn.odboy.util.KitPageUtil; import cn.odboy.util.KitPageUtil;
import cn.odboy.util.KitValidUtil;
import cn.odboy.util.xlsx.KitExcelExporter; import cn.odboy.util.xlsx.KitExcelExporter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -139,16 +140,15 @@ public class SystemLocalStorageService {
} }
private void injectQueryParams(SystemQueryStorageArgs args, LambdaQueryWrapper<SystemLocalStorageTb> wrapper) { private void injectQueryParams(SystemQueryStorageArgs args, LambdaQueryWrapper<SystemLocalStorageTb> wrapper) {
if (args != null) { KitValidUtil.notNull(args);
wrapper.and(StrUtil.isNotBlank(args.getBlurry()), wrapper.and(StrUtil.isNotBlank(args.getBlurry()),
c -> c.like(SystemLocalStorageTb::getName, args.getBlurry()).or() c -> c.like(SystemLocalStorageTb::getName, args.getBlurry()).or()
.like(SystemLocalStorageTb::getSuffix, args.getBlurry()).or() .like(SystemLocalStorageTb::getSuffix, args.getBlurry()).or()
.like(SystemLocalStorageTb::getType, args.getBlurry()).or() .like(SystemLocalStorageTb::getType, args.getBlurry()).or()
.like(SystemLocalStorageTb::getCreateBy, args.getBlurry())); .like(SystemLocalStorageTb::getCreateBy, args.getBlurry()));
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) { if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
wrapper.between(SystemLocalStorageTb::getUpdateTime, args.getCreateTime().get(0), wrapper.between(SystemLocalStorageTb::getUpdateTime, args.getCreateTime().get(0),
args.getCreateTime().get(1)); args.getCreateTime().get(1));
}
} }
wrapper.orderByDesc(SystemLocalStorageTb::getId); wrapper.orderByDesc(SystemLocalStorageTb::getId);
} }
@@ -171,8 +171,6 @@ public class SystemLocalStorageService {
public void exportLocalStorageXlsx(HttpServletResponse response, SystemQueryStorageArgs args) { public void exportLocalStorageXlsx(HttpServletResponse response, SystemQueryStorageArgs args) {
List<SystemLocalStorageTb> systemLocalStorageTbs = this.queryLocalStorageByArgs(args); List<SystemLocalStorageTb> systemLocalStorageTbs = this.queryLocalStorageByArgs(args);
// KitXlsxExportUtil.exportFile(response, "文件上传记录数据", systemLocalStorageTbs, SystemLocalStorageExportRowVo.class,
// (dataObject) -> CollUtil.newArrayList(KitBeanUtil.copyProperties(dataObject, SystemLocalStorageExportRowVo.class)));
List<SystemLocalStorageExportRowVo> rowVos = KitBeanUtil.copyToList(systemLocalStorageTbs, SystemLocalStorageExportRowVo.class); List<SystemLocalStorageExportRowVo> rowVos = KitBeanUtil.copyToList(systemLocalStorageTbs, SystemLocalStorageExportRowVo.class);
KitExcelExporter.exportSimple(response, "文件上传记录数据", SystemLocalStorageExportRowVo.class, rowVos); KitExcelExporter.exportSimple(response, "文件上传记录数据", SystemLocalStorageExportRowVo.class, rowVos);
} }
@@ -34,6 +34,7 @@ import cn.odboy.system.dal.mysql.SystemMenuMapper;
import cn.odboy.system.framework.permission.core.KitSecurityHelper; import cn.odboy.system.framework.permission.core.KitSecurityHelper;
import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitBeanUtil;
import cn.odboy.util.KitClassUtil; import cn.odboy.util.KitClassUtil;
import cn.odboy.util.KitValidUtil;
import cn.odboy.util.xlsx.KitExcelExporter; import cn.odboy.util.xlsx.KitExcelExporter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -152,10 +153,10 @@ public class SystemMenuService {
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void deleteMenuByIds(Set<Long> ids) { public void deleteMenuByIds(Set<Long> ids) {
Set<SystemMenuTb> menuSet = new HashSet<>(); Set<SystemMenuVo> menuSet = new HashSet<>();
for (Long id : ids) { for (Long id : ids) {
List<SystemMenuTb> menuList = this.listMenuByPid(id); List<SystemMenuVo> menuList = this.listMenuByPid(id);
menuSet.add(systemMenuMapper.selectById(id)); menuSet.add(this.getMenuVoById(id));
menuSet = this.queryChildMenuByArgs(menuList, menuSet); menuSet = this.queryChildMenuByArgs(menuList, menuSet);
} }
List<Long> menuIds = List<Long> menuIds =
@@ -169,6 +170,10 @@ public class SystemMenuService {
} }
} }
private SystemMenuVo getMenuVoById(Long id) {
return KitBeanUtil.copyToClass(systemMenuMapper.selectById(id), SystemMenuVo.class);
}
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void updateMenuSubCnt(Long menuId) { public void updateMenuSubCnt(Long menuId) {
if (menuId != null) { if (menuId != null) {
@@ -215,7 +220,7 @@ public class SystemMenuService {
* @param currentUserId / * @param currentUserId /
* @return / * @return /
*/ */
public List<SystemMenuTb> listMenuByUserId(Long currentUserId) { public List<SystemMenuVo> listMenuByUserId(Long currentUserId) {
List<SystemRoleVo> roles = systemUserRoleService.queryRoleByUsersId(currentUserId); List<SystemRoleVo> roles = systemUserRoleService.queryRoleByUsersId(currentUserId);
Set<Long> roleIds = roles.stream().map(SystemRoleTb::getId).collect(Collectors.toSet()); Set<Long> roleIds = roles.stream().map(SystemRoleTb::getId).collect(Collectors.toSet());
return new ArrayList<>(systemRoleMenuService.queryMenuByRoleIds(roleIds)); return new ArrayList<>(systemRoleMenuService.queryMenuByRoleIds(roleIds));
@@ -228,10 +233,10 @@ public class SystemMenuService {
* @param menuSet / * @param menuSet /
* @return / * @return /
*/ */
public Set<SystemMenuTb> queryChildMenuByArgs(List<SystemMenuTb> menuList, Set<SystemMenuTb> menuSet) { public Set<SystemMenuVo> queryChildMenuByArgs(List<SystemMenuVo> menuList, Set<SystemMenuVo> menuSet) {
for (SystemMenuTb menu : menuList) { for (SystemMenuVo menu : menuList) {
menuSet.add(menu); menuSet.add(menu);
List<SystemMenuTb> menus = this.listMenuByPid(menu.getId()); List<SystemMenuVo> menus = this.listMenuByPid(menu.getId());
if (CollUtil.isNotEmpty(menus)) { if (CollUtil.isNotEmpty(menus)) {
queryChildMenuByArgs(menus, menuSet); queryChildMenuByArgs(menus, menuSet);
} }
@@ -245,13 +250,13 @@ public class SystemMenuService {
* @param pid / * @param pid /
* @return / * @return /
*/ */
public List<SystemMenuTb> listMenuByPid(Long pid) { public List<SystemMenuVo> listMenuByPid(Long pid) {
List<SystemMenuTb> menus; List<SystemMenuVo> menus;
if (pid != null && !pid.equals(0L)) { if (pid != null && !pid.equals(0L)) {
LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(SystemMenuTb::getPid, pid); wrapper.eq(SystemMenuTb::getPid, pid);
wrapper.orderByAsc(SystemMenuTb::getMenuSort); wrapper.orderByAsc(SystemMenuTb::getMenuSort);
return systemMenuMapper.selectList(wrapper); return KitBeanUtil.copyToList(systemMenuMapper.selectList(wrapper), SystemMenuVo.class);
} else { } else {
menus = this.listRootMenu(); menus = this.listRootMenu();
} }
@@ -265,13 +270,13 @@ public class SystemMenuService {
* @param menus / * @param menus /
* @return / * @return /
*/ */
public List<SystemMenuTb> querySuperiorMenuByArgs(SystemMenuTb menu, List<SystemMenuTb> menus) { public List<SystemMenuVo> querySuperiorMenuByArgs(SystemMenuTb menu, List<SystemMenuVo> menus) {
if (menu.getPid() == null) { if (menu.getPid() == null) {
menus.addAll(this.listRootMenu()); menus.addAll(this.listRootMenu());
return menus; return menus;
} }
menus.addAll(this.listMenuByPid(menu.getPid())); menus.addAll(this.listMenuByPid(menu.getPid()));
return querySuperiorMenuByArgs(systemMenuMapper.selectById(menu.getPid()), menus); return querySuperiorMenuByArgs(this.getMenuVoById(menu.getPid()), menus);
} }
/** /**
@@ -373,8 +378,8 @@ public class SystemMenuService {
return menuVo1; return menuVo1;
} }
public List<SystemMenuTb> listMenuByIds(List<Long> ids) { public List<SystemMenuVo> listMenuByIds(List<Long> ids) {
return systemMenuMapper.selectByIds(ids); return KitBeanUtil.copyToList(systemMenuMapper.selectByIds(ids), SystemMenuVo.class);
} }
private SystemMenuTb getMenuByComponentName(String componentName) { private SystemMenuTb getMenuByComponentName(String componentName) {
@@ -396,53 +401,51 @@ public class SystemMenuService {
} }
private List<SystemMenuTb> queryMenuByArgs(SystemQueryMenuArgs args) { private List<SystemMenuTb> queryMenuByArgs(SystemQueryMenuArgs args) {
KitValidUtil.notNull(args);
LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>();
if (args != null) { wrapper.isNull(args.getPidIsNull() != null, SystemMenuTb::getPid);
wrapper.isNull(args.getPidIsNull() != null, SystemMenuTb::getPid); wrapper.eq(args.getPid() != null, SystemMenuTb::getPid, args.getPid());
wrapper.eq(args.getPid() != null, SystemMenuTb::getPid, args.getPid()); wrapper.and(StrUtil.isNotBlank(args.getBlurry()),
wrapper.and(StrUtil.isNotBlank(args.getBlurry()), c -> c.like(SystemMenuTb::getTitle, args.getBlurry()).or()
c -> c.like(SystemMenuTb::getTitle, args.getBlurry()).or() .like(SystemMenuTb::getComponentName, args.getBlurry()).or()
.like(SystemMenuTb::getComponentName, args.getBlurry()).or() .like(SystemMenuTb::getPermission, args.getBlurry()));
.like(SystemMenuTb::getPermission, args.getBlurry())); if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) { wrapper.between(SystemMenuTb::getCreateTime, args.getCreateTime().get(0),
wrapper.between(SystemMenuTb::getCreateTime, args.getCreateTime().get(0), args.getCreateTime().get(1));
args.getCreateTime().get(1));
}
} }
wrapper.orderByAsc(SystemMenuTb::getMenuSort); wrapper.orderByAsc(SystemMenuTb::getMenuSort);
return systemMenuMapper.selectList(wrapper); return systemMenuMapper.selectList(wrapper);
} }
private List<SystemMenuTb> listRootMenu() { private List<SystemMenuVo> listRootMenu() {
LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>();
wrapper.isNull(SystemMenuTb::getPid); wrapper.isNull(SystemMenuTb::getPid);
wrapper.orderByAsc(SystemMenuTb::getMenuSort); wrapper.orderByAsc(SystemMenuTb::getMenuSort);
return systemMenuMapper.selectList(wrapper); return KitBeanUtil.copyToList(systemMenuMapper.selectList(wrapper), SystemMenuVo.class);
} }
public List<SystemMenuRouterVo> buildFrontMenus() { public List<SystemMenuRouterVo> buildFrontMenus() {
List<SystemMenuTb> menuList = this.listMenuByUserId(KitSecurityHelper.getCurrentUserId()); List<SystemMenuVo> originMenus = this.listMenuByUserId(KitSecurityHelper.getCurrentUserId());
List<SystemMenuVo> originMenus = KitBeanUtil.copyToList(menuList, SystemMenuVo.class);
List<SystemMenuVo> targetMenus = this.buildMenuTree(originMenus); List<SystemMenuVo> targetMenus = this.buildMenuTree(originMenus);
return this.buildMenuVo(targetMenus); return this.buildMenuVo(targetMenus);
} }
public Set<Long> listChildMenuSetByMenuId(Long id) { public Set<Long> listChildMenuSetByMenuId(Long id) {
Set<SystemMenuTb> menuSet = new HashSet<>(); Set<SystemMenuVo> menuSet = new HashSet<>();
List<SystemMenuTb> menuList = this.listMenuByPid(id); List<SystemMenuVo> menuList = this.listMenuByPid(id);
menuSet.add(systemMenuMapper.selectById(id)); menuSet.add(this.getMenuVoById(id));
menuSet = this.queryChildMenuByArgs(menuList, menuSet); menuSet = this.queryChildMenuByArgs(menuList, menuSet);
return menuSet.stream().map(SystemMenuTb::getId).collect(Collectors.toSet()); return menuSet.stream().map(SystemMenuTb::getId).collect(Collectors.toSet());
} }
public List<SystemMenuVo> listMenuSuperior(List<Long> ids) { public List<SystemMenuVo> listMenuSuperior(List<Long> ids) {
Set<SystemMenuTb> menus; Set<SystemMenuVo> menus;
List<SystemMenuVo> systemMenuTbs; List<SystemMenuVo> systemMenuTbs;
if (CollectionUtil.isNotEmpty(ids)) { if (CollectionUtil.isNotEmpty(ids)) {
menus = new LinkedHashSet<>(this.listMenuByIds(ids)); menus = new LinkedHashSet<>(this.listMenuByIds(ids));
for (SystemMenuTb menu : menus) { for (SystemMenuTb menu : menus) {
List<SystemMenuTb> menuList = this.querySuperiorMenuByArgs(menu, new ArrayList<>()); List<SystemMenuVo> menuList = this.querySuperiorMenuByArgs(menu, new ArrayList<>());
for (SystemMenuTb data : menuList) { for (SystemMenuVo data : menuList) {
if (data.getId().equals(menu.getPid())) { if (data.getId().equals(menu.getPid())) {
data.setSubCount(data.getSubCount() - 1); data.setSubCount(data.getSubCount() - 1);
} }
@@ -451,28 +454,16 @@ public class SystemMenuService {
} }
// 编辑菜单时不显示自己以及自己下级的数据, 避免出现PID数据环形问题 // 编辑菜单时不显示自己以及自己下级的数据, 避免出现PID数据环形问题
menus = menus.stream().filter(i -> !ids.contains(i.getId())).collect(Collectors.toSet()); menus = menus.stream().filter(i -> !ids.contains(i.getId())).collect(Collectors.toSet());
List<SystemMenuTb> newMenuList = new ArrayList<>(menus); List<SystemMenuVo> newMenuList = new ArrayList<>(menus);
systemMenuTbs = this.buildMenuTree(KitBeanUtil.copyToList(newMenuList, SystemMenuVo.class)); systemMenuTbs = this.buildMenuTree(newMenuList);
} else { } else {
List<SystemMenuTb> newMenuList = this.listMenuByPid(null); systemMenuTbs = this.listMenuByPid(null);
systemMenuTbs = KitBeanUtil.copyToList(newMenuList, SystemMenuVo.class);
} }
return systemMenuTbs; return systemMenuTbs;
} }
public void exportMenuXlsx(HttpServletResponse response, SystemQueryMenuArgs args) throws Exception { public void exportMenuXlsx(HttpServletResponse response, SystemQueryMenuArgs args) throws Exception {
List<SystemMenuTb> systemMenuTbs = this.queryAllMenu(args, false); List<SystemMenuTb> systemMenuTbs = this.queryAllMenu(args, false);
// KitXlsxExportUtil.exportFile(response, "菜单数据", systemMenuTbs, SystemMenuExportRowVo.class, (dataObject -> {
// SystemMenuExportRowVo rowVo = new SystemMenuExportRowVo();
// rowVo.setTitle(dataObject.getTitle());
// rowVo.setType(dataObject.getType() == null ? "目录" : dataObject.getType() == 1 ? "菜单" : "按钮");
// rowVo.setPermission(dataObject.getPermission());
// rowVo.setIFrame(dataObject.getIFrame() ? SystemYesOrNoChConst.YES_STR : SystemYesOrNoChConst.NO_STR);
// rowVo.setHidden(dataObject.getHidden() ? SystemYesOrNoChConst.NO_STR : SystemYesOrNoChConst.YES_STR);
// rowVo.setCache(dataObject.getCache() ? SystemYesOrNoChConst.YES_STR : SystemYesOrNoChConst.NO_STR);
// rowVo.setCreateTime(dataObject.getCreateTime());
// return CollUtil.newArrayList(rowVo);
// }));
List<SystemMenuExportRowVo> rowVos = new ArrayList<>(); List<SystemMenuExportRowVo> rowVos = new ArrayList<>();
for (SystemMenuTb dataObject : systemMenuTbs) { for (SystemMenuTb dataObject : systemMenuTbs) {
SystemMenuExportRowVo rowVo = new SystemMenuExportRowVo(); SystemMenuExportRowVo rowVo = new SystemMenuExportRowVo();
@@ -34,6 +34,7 @@ import cn.odboy.system.dal.mysql.SystemQuartzLogMapper;
import cn.odboy.system.framework.quartz.QuartzManage; import cn.odboy.system.framework.quartz.QuartzManage;
import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitBeanUtil;
import cn.odboy.util.KitPageUtil; import cn.odboy.util.KitPageUtil;
import cn.odboy.util.KitValidUtil;
import cn.odboy.util.xlsx.KitExcelExporter; import cn.odboy.util.xlsx.KitExcelExporter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -199,36 +200,27 @@ public class SystemQuartzJobService {
* @param page 分页参数 * @param page 分页参数
* @return / * @return /
*/ */
public KitPageResult<SystemQuartzJobTb> searchQuartzJobByArgs(SystemQueryQuartzJobArgs args, public KitPageResult<SystemQuartzJobTb> searchQuartzJobByArgs(SystemQueryQuartzJobArgs args, Page<SystemQuartzJobTb> page) {
Page<SystemQuartzJobTb> page) {
LambdaQueryWrapper<SystemQuartzJobTb> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SystemQuartzJobTb> wrapper = new LambdaQueryWrapper<>();
this.injectQuartzJobQueryParams(args, wrapper); this.injectQuartzJobQueryParams(args, wrapper);
return KitPageUtil.toPage(systemQuartzJobMapper.selectPage(page, wrapper)); return KitPageUtil.toPage(systemQuartzJobMapper.selectPage(page, wrapper));
} }
private void injectQuartzJobQueryParams(SystemQueryQuartzJobArgs args, private void injectQuartzJobQueryParams(SystemQueryQuartzJobArgs args, LambdaQueryWrapper<SystemQuartzJobTb> wrapper) {
LambdaQueryWrapper<SystemQuartzJobTb> wrapper) { KitValidUtil.notNull(args);
if (args != null) { wrapper.like(StrUtil.isNotBlank(args.getJobName()), SystemQuartzJobTb::getJobName, args.getJobName());
wrapper.like(StrUtil.isNotBlank(args.getJobName()), SystemQuartzJobTb::getJobName, if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
args.getJobName()); wrapper.between(SystemQuartzJobTb::getUpdateTime, args.getCreateTime().get(0), args.getCreateTime().get(1));
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
wrapper.between(SystemQuartzJobTb::getUpdateTime, args.getCreateTime().get(0),
args.getCreateTime().get(1));
}
} }
wrapper.orderByDesc(SystemQuartzJobTb::getId); wrapper.orderByDesc(SystemQuartzJobTb::getId);
} }
private void injectQuartzLogQueryParams(SystemQueryQuartzJobArgs args, private void injectQuartzLogQueryParams(SystemQueryQuartzJobArgs args, LambdaQueryWrapper<SystemQuartzLogTb> wrapper) {
LambdaQueryWrapper<SystemQuartzLogTb> wrapper) { KitValidUtil.notNull(args);
if (args != null) { wrapper.like(StrUtil.isNotBlank(args.getJobName()), SystemQuartzLogTb::getJobName, args.getJobName());
wrapper.like(StrUtil.isNotBlank(args.getJobName()), SystemQuartzLogTb::getJobName, wrapper.eq(args.getIsSuccess() != null, SystemQuartzLogTb::getIsSuccess, args.getIsSuccess());
args.getJobName()); if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
wrapper.eq(args.getIsSuccess() != null, SystemQuartzLogTb::getIsSuccess, args.getIsSuccess()); wrapper.between(SystemQuartzLogTb::getCreateTime, args.getCreateTime().get(0), args.getCreateTime().get(1));
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
wrapper.between(SystemQuartzLogTb::getCreateTime, args.getCreateTime().get(0),
args.getCreateTime().get(1));
}
} }
wrapper.orderByDesc(SystemQuartzLogTb::getId); wrapper.orderByDesc(SystemQuartzLogTb::getId);
} }
@@ -18,8 +18,10 @@ package cn.odboy.system.service;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.odboy.system.dal.dataobject.SystemMenuTb; import cn.odboy.system.dal.dataobject.SystemMenuTb;
import cn.odboy.system.dal.dataobject.SystemRoleMenuTb; import cn.odboy.system.dal.dataobject.SystemRoleMenuTb;
import cn.odboy.system.dal.model.SystemMenuVo;
import cn.odboy.system.dal.mysql.SystemMenuMapper; import cn.odboy.system.dal.mysql.SystemMenuMapper;
import cn.odboy.system.dal.mysql.SystemRoleMenuMapper; import cn.odboy.system.dal.mysql.SystemRoleMenuMapper;
import cn.odboy.util.KitBeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
@@ -46,10 +48,10 @@ public class SystemRoleMenuService {
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void batchInsertRoleMenu(Set<SystemMenuTb> menus, Long roleId) { public void batchInsertRoleMenu(Set<SystemMenuVo> menus, Long roleId) {
if (CollUtil.isNotEmpty(menus)) { if (CollUtil.isNotEmpty(menus)) {
List<SystemRoleMenuTb> records = new ArrayList<>(); List<SystemRoleMenuTb> records = new ArrayList<>();
for (SystemMenuTb menu : menus) { for (SystemMenuVo menu : menus) {
SystemRoleMenuTb record = new SystemRoleMenuTb(); SystemRoleMenuTb record = new SystemRoleMenuTb();
record.setMenuId(menu.getId()); record.setMenuId(menu.getId());
record.setRoleId(roleId); record.setRoleId(roleId);
@@ -68,7 +70,7 @@ public class SystemRoleMenuService {
} }
} }
public LinkedHashSet<SystemMenuTb> queryMenuByRoleIds(Set<Long> roleIds) { public LinkedHashSet<SystemMenuVo> queryMenuByRoleIds(Set<Long> roleIds) {
if (CollUtil.isEmpty(roleIds)) { if (CollUtil.isEmpty(roleIds)) {
return new LinkedHashSet<>(); return new LinkedHashSet<>();
} }
@@ -84,7 +86,10 @@ public class SystemRoleMenuService {
// 排除"按钮" // 排除"按钮"
menuWrapper.ne(SystemMenuTb::getType, 2); menuWrapper.ne(SystemMenuTb::getType, 2);
menuWrapper.orderByAsc(SystemMenuTb::getMenuSort); menuWrapper.orderByAsc(SystemMenuTb::getMenuSort);
return new LinkedHashSet<>(systemMenuMapper.selectList(menuWrapper));
List<SystemMenuTb> systemMenuTbs = systemMenuMapper.selectList(menuWrapper);
List<SystemMenuVo> systemMenuVos = KitBeanUtil.copyToList(systemMenuTbs, SystemMenuVo.class);
return new LinkedHashSet<>(systemMenuVos);
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@@ -25,6 +25,7 @@ import cn.odboy.system.dal.dataobject.SystemMenuTb;
import cn.odboy.system.dal.dataobject.SystemRoleTb; import cn.odboy.system.dal.dataobject.SystemRoleTb;
import cn.odboy.system.dal.dataobject.SystemUserTb; import cn.odboy.system.dal.dataobject.SystemUserTb;
import cn.odboy.system.dal.model.SystemCreateRoleArgs; import cn.odboy.system.dal.model.SystemCreateRoleArgs;
import cn.odboy.system.dal.model.SystemMenuVo;
import cn.odboy.system.dal.model.SystemQueryRoleArgs; import cn.odboy.system.dal.model.SystemQueryRoleArgs;
import cn.odboy.system.dal.model.SystemRoleCodeVo; import cn.odboy.system.dal.model.SystemRoleCodeVo;
import cn.odboy.system.dal.model.SystemRoleExportRowVo; import cn.odboy.system.dal.model.SystemRoleExportRowVo;
@@ -33,6 +34,7 @@ import cn.odboy.system.dal.mysql.SystemRoleMapper;
import cn.odboy.system.framework.permission.core.KitSecurityHelper; import cn.odboy.system.framework.permission.core.KitSecurityHelper;
import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitBeanUtil;
import cn.odboy.util.KitPageUtil; import cn.odboy.util.KitPageUtil;
import cn.odboy.util.KitValidUtil;
import cn.odboy.util.xlsx.KitExcelExporter; import cn.odboy.util.xlsx.KitExcelExporter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -70,7 +72,8 @@ public class SystemRoleService {
if (this.getRoleByName(args.getName()) != null) { if (this.getRoleByName(args.getName()) != null) {
throw new BadRequestException("角色名称已存在"); throw new BadRequestException("角色名称已存在");
} }
systemRoleMapper.insert(KitBeanUtil.copyToClass(args, SystemRoleTb.class)); SystemRoleTb roleTb = KitBeanUtil.copyToClass(args, SystemRoleTb.class);
systemRoleMapper.insert(roleTb);
// 判断是否有部门数据, 若有, 则需创建关联 // 判断是否有部门数据, 若有, 则需创建关联
if (CollectionUtil.isNotEmpty(args.getDepts())) { if (CollectionUtil.isNotEmpty(args.getDepts())) {
systemRoleDeptService.batchInsertRoleDept(args.getDepts(), args.getId()); systemRoleDeptService.batchInsertRoleDept(args.getDepts(), args.getId());
@@ -91,7 +94,7 @@ public class SystemRoleService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void updateRoleById(SystemRoleVo args) { public void updateRoleById(SystemRoleVo args) {
checkRoleLevels(args.getLevel()); checkRoleLevels(args.getLevel());
SystemRoleVo role = KitBeanUtil.copyToClass(systemRoleMapper.selectById(args.getId()), SystemRoleVo.class); SystemRoleVo role = this.getRoleVoById(args.getId());
SystemRoleTb role1 = this.getRoleByName(args.getName()); SystemRoleTb role1 = this.getRoleByName(args.getName());
if (role1 != null && !role1.getId().equals(role.getId())) { if (role1 != null && !role1.getId().equals(role.getId())) {
throw new BadRequestException("角色名称已存在"); throw new BadRequestException("角色名称已存在");
@@ -111,6 +114,10 @@ public class SystemRoleService {
} }
} }
private SystemRoleVo getRoleVoById(Long id) {
return KitBeanUtil.copyToClass(systemRoleMapper.selectById(id), SystemRoleVo.class);
}
/** /**
* 修改绑定的菜单 * 修改绑定的菜单
* *
@@ -122,8 +129,9 @@ public class SystemRoleService {
// 更新菜单 // 更新菜单
systemRoleMenuService.deleteRoleMenuByRoleId(role.getId()); systemRoleMenuService.deleteRoleMenuByRoleId(role.getId());
// 判断是否为空 // 判断是否为空
if (CollUtil.isNotEmpty(args.getMenus())) { Set<SystemMenuVo> menus = args.getMenus();
systemRoleMenuService.batchInsertRoleMenu(args.getMenus(), role.getId()); if (CollUtil.isNotEmpty(menus)) {
systemRoleMenuService.batchInsertRoleMenu(menus, role.getId());
} }
} }
@@ -163,19 +171,18 @@ public class SystemRoleService {
* @return / * @return /
*/ */
public List<SystemRoleVo> queryRoleByArgs(SystemQueryRoleArgs args) { public List<SystemRoleVo> queryRoleByArgs(SystemQueryRoleArgs args) {
KitValidUtil.notNull(args);
// 查询角色基本信息 // 查询角色基本信息
LambdaQueryWrapper<SystemRoleTb> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SystemRoleTb> wrapper = new LambdaQueryWrapper<>();
if (args != null) { wrapper.and(StrUtil.isNotBlank(args.getBlurry()),
wrapper.and(StrUtil.isNotBlank(args.getBlurry()), c -> c.like(SystemRoleTb::getName, args.getBlurry()).or()
c -> c.like(SystemRoleTb::getName, args.getBlurry()).or() .like(SystemRoleTb::getDescription, args.getBlurry()));
.like(SystemRoleTb::getDescription, args.getBlurry())); if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) { wrapper.between(SystemRoleTb::getCreateTime, args.getCreateTime().get(0),
wrapper.between(SystemRoleTb::getCreateTime, args.getCreateTime().get(0), args.getCreateTime().get(1));
args.getCreateTime().get(1));
}
} }
wrapper.orderByAsc(SystemRoleTb::getLevel); wrapper.orderByAsc(SystemRoleTb::getLevel);
if (args != null && args.getSize() != null) { if (args.getSize() != null) {
Page<SystemRoleTb> rolePage = new Page<>(args.getPage(), args.getSize()); Page<SystemRoleTb> rolePage = new Page<>(args.getPage(), args.getSize());
Page<SystemRoleTb> page = systemRoleMapper.selectPage(rolePage, wrapper); Page<SystemRoleTb> page = systemRoleMapper.selectPage(rolePage, wrapper);
List<SystemRoleTb> roles = page.getRecords(); List<SystemRoleTb> roles = page.getRecords();
@@ -232,15 +239,14 @@ public class SystemRoleService {
} }
public Long countRoleByArgs(SystemQueryRoleArgs args) { public Long countRoleByArgs(SystemQueryRoleArgs args) {
KitValidUtil.notNull(args);
LambdaQueryWrapper<SystemRoleTb> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SystemRoleTb> wrapper = new LambdaQueryWrapper<>();
if (args != null) { wrapper.and(StrUtil.isNotBlank(args.getBlurry()),
wrapper.and(StrUtil.isNotBlank(args.getBlurry()), c -> c.like(SystemRoleTb::getName, args.getBlurry()).or()
c -> c.like(SystemRoleTb::getName, args.getBlurry()).or() .like(SystemRoleTb::getDescription, args.getBlurry()));
.like(SystemRoleTb::getDescription, args.getBlurry())); if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) { wrapper.between(SystemRoleTb::getCreateTime, args.getCreateTime().get(0),
wrapper.between(SystemRoleTb::getCreateTime, args.getCreateTime().get(0), args.getCreateTime().get(1));
args.getCreateTime().get(1));
}
} }
return systemRoleMapper.selectCount(wrapper); return systemRoleMapper.selectCount(wrapper);
} }
@@ -18,9 +18,9 @@ package cn.odboy.system.service;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.odboy.framework.exception.BadRequestException; import cn.odboy.framework.exception.BadRequestException;
import cn.odboy.system.dal.dataobject.SystemDeptTb; import cn.odboy.system.dal.dataobject.SystemDeptTb;
import cn.odboy.system.dal.dataobject.SystemMenuTb;
import cn.odboy.system.dal.dataobject.SystemRoleTb; import cn.odboy.system.dal.dataobject.SystemRoleTb;
import cn.odboy.system.dal.dataobject.SystemUserRoleTb; import cn.odboy.system.dal.dataobject.SystemUserRoleTb;
import cn.odboy.system.dal.model.SystemMenuVo;
import cn.odboy.system.dal.model.SystemRoleVo; import cn.odboy.system.dal.model.SystemRoleVo;
import cn.odboy.system.dal.model.SystemUserVo; import cn.odboy.system.dal.model.SystemUserVo;
import cn.odboy.system.dal.mysql.SystemRoleMapper; import cn.odboy.system.dal.mysql.SystemRoleMapper;
@@ -86,8 +86,7 @@ public class SystemUserRoleService {
} }
SystemRoleVo roleVo = KitBeanUtil.copyToClass(role, SystemRoleVo.class); SystemRoleVo roleVo = KitBeanUtil.copyToClass(role, SystemRoleVo.class);
// 查询关联的菜单信息 // 查询关联的菜单信息
Set<SystemMenuTb> menus = systemRoleMenuService.queryMenuByRoleIds( Set<SystemMenuVo> menus = systemRoleMenuService.queryMenuByRoleIds(Collections.singleton(role.getId()));
Collections.singleton(role.getId()));
roleVo.setMenus(menus); roleVo.setMenus(menus);
// 查询关联的部门信息 // 查询关联的部门信息
@@ -32,6 +32,7 @@ import cn.odboy.system.dal.dataobject.SystemRoleTb;
import cn.odboy.system.dal.dataobject.SystemUserJobTb; import cn.odboy.system.dal.dataobject.SystemUserJobTb;
import cn.odboy.system.dal.dataobject.SystemUserRoleTb; import cn.odboy.system.dal.dataobject.SystemUserRoleTb;
import cn.odboy.system.dal.dataobject.SystemUserTb; import cn.odboy.system.dal.dataobject.SystemUserTb;
import cn.odboy.system.dal.model.SystemDeptVo;
import cn.odboy.system.dal.model.SystemQueryUserArgs; import cn.odboy.system.dal.model.SystemQueryUserArgs;
import cn.odboy.system.dal.model.SystemUpdateUserPasswordArgs; import cn.odboy.system.dal.model.SystemUpdateUserPasswordArgs;
import cn.odboy.system.dal.model.SystemUserExportRowVo; import cn.odboy.system.dal.model.SystemUserExportRowVo;
@@ -44,6 +45,7 @@ import cn.odboy.util.KitBeanUtil;
import cn.odboy.util.KitFileUtil; import cn.odboy.util.KitFileUtil;
import cn.odboy.util.KitPageUtil; import cn.odboy.util.KitPageUtil;
import cn.odboy.util.KitRsaEncryptUtil; import cn.odboy.util.KitRsaEncryptUtil;
import cn.odboy.util.KitValidUtil;
import cn.odboy.util.xlsx.KitExcelExporter; import cn.odboy.util.xlsx.KitExcelExporter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -400,26 +402,25 @@ public class SystemUserService {
* @return / * @return /
*/ */
private LambdaQueryWrapper<SystemUserTb> buildUserQueryWrapper(SystemQueryUserArgs args) { private LambdaQueryWrapper<SystemUserTb> buildUserQueryWrapper(SystemQueryUserArgs args) {
KitValidUtil.notNull(args);
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
if (args != null) { if (args.getId() != null) {
if (args.getId() != null) { wrapper.eq(SystemUserTb::getId, args.getId());
wrapper.eq(SystemUserTb::getId, args.getId()); }
} if (args.getEnabled() != null) {
if (args.getEnabled() != null) { wrapper.eq(SystemUserTb::getEnabled, args.getEnabled());
wrapper.eq(SystemUserTb::getEnabled, args.getEnabled()); }
} if (CollUtil.isNotEmpty(args.getDeptIds())) {
if (CollUtil.isNotEmpty(args.getDeptIds())) { wrapper.in(SystemUserTb::getDeptId, args.getDeptIds());
wrapper.in(SystemUserTb::getDeptId, args.getDeptIds()); }
} if (StrUtil.isNotBlank(args.getBlurry())) {
if (StrUtil.isNotBlank(args.getBlurry())) { wrapper.and(w -> w.like(SystemUserTb::getUsername, args.getBlurry())
wrapper.and(w -> w.like(SystemUserTb::getUsername, args.getBlurry()) .or().like(SystemUserTb::getNickName, args.getBlurry())
.or().like(SystemUserTb::getNickName, args.getBlurry()) .or().like(SystemUserTb::getEmail, args.getBlurry()));
.or().like(SystemUserTb::getEmail, args.getBlurry())); }
} if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) { wrapper.between(SystemUserTb::getCreateTime, args.getCreateTime().get(0),
wrapper.between(SystemUserTb::getCreateTime, args.getCreateTime().get(0), args.getCreateTime().get(1));
args.getCreateTime().get(1));
}
} }
wrapper.orderByDesc(SystemUserTb::getCreateTime); wrapper.orderByDesc(SystemUserTb::getCreateTime);
return wrapper; return wrapper;
@@ -487,7 +488,7 @@ public class SystemUserService {
if (!ObjectUtils.isEmpty(args.getDeptId())) { if (!ObjectUtils.isEmpty(args.getDeptId())) {
args.getDeptIds().add(args.getDeptId()); args.getDeptIds().add(args.getDeptId());
// 先查找是否存在子节点 // 先查找是否存在子节点
List<SystemDeptTb> data = systemDeptService.listDeptByPid(args.getDeptId()); List<SystemDeptVo> data = systemDeptService.listDeptByPid(args.getDeptId());
// 然后把子节点的ID都加入到集合中 // 然后把子节点的ID都加入到集合中
args.getDeptIds().addAll(systemDeptService.queryChildDeptIdByDeptIds(data)); args.getDeptIds().addAll(systemDeptService.queryChildDeptIdByDeptIds(data));
} }
@@ -33,6 +33,7 @@ import cn.odboy.util.KitBeanUtil;
import cn.odboy.util.KitDateUtil; import cn.odboy.util.KitDateUtil;
import cn.odboy.util.KitFileUtil; import cn.odboy.util.KitFileUtil;
import cn.odboy.util.KitPageUtil; import cn.odboy.util.KitPageUtil;
import cn.odboy.util.KitValidUtil;
import cn.odboy.util.xlsx.KitExcelExporter; import cn.odboy.util.xlsx.KitExcelExporter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -68,33 +69,27 @@ public class SystemMinioStorageServiceImpl extends ServiceImpl<SystemOssStorageM
private SystemOssStorageMapper systemOssStorageMapper; private SystemOssStorageMapper systemOssStorageMapper;
@Override @Override
public KitPageResult<SystemOssStorageVo> searchOssStorage(SystemQueryStorageArgs args, public KitPageResult<SystemOssStorageVo> searchOssStorage(SystemQueryStorageArgs args, Page<SystemOssStorageTb> page) {
Page<SystemOssStorageTb> page) { IPage<SystemOssStorageVo> ossStorageTbs = this.selectOssStorageByArgs(args, page);
IPage<SystemOssStorageTb> ossStorageTbs = this.selectOssStorageByArgs(args, page); for (SystemOssStorageVo storageVo : ossStorageTbs.getRecords()) {
IPage<SystemOssStorageVo> convert = ossStorageTbs.convert(c -> {
SystemOssStorageVo storageVo = KitBeanUtil.copyToClass(c, SystemOssStorageVo.class);
storageVo.setFileSizeDesc(KitFileUtil.getSize(storageVo.getFileSize())); storageVo.setFileSizeDesc(KitFileUtil.getSize(storageVo.getFileSize()));
return storageVo; }
}); return KitPageUtil.toPage(ossStorageTbs);
return KitPageUtil.toPage(convert);
} }
private IPage<SystemOssStorageTb> selectOssStorageByArgs(SystemQueryStorageArgs args, private IPage<SystemOssStorageVo> selectOssStorageByArgs(SystemQueryStorageArgs args, Page<SystemOssStorageTb> page) {
Page<SystemOssStorageTb> page) { KitValidUtil.notNull(args);
LambdaQueryWrapper<SystemOssStorageTb> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SystemOssStorageTb> wrapper = new LambdaQueryWrapper<>();
if (args != null) { wrapper.and(StrUtil.isNotBlank(args.getBlurry()),
wrapper.and(StrUtil.isNotBlank(args.getBlurry()), c -> c.like(SystemOssStorageTb::getFileName, args.getBlurry()).or()
c -> c.like(SystemOssStorageTb::getFileName, args.getBlurry()).or() .like(SystemOssStorageTb::getFilePrefix, args.getBlurry()).or()
.like(SystemOssStorageTb::getFilePrefix, args.getBlurry()).or() .like(SystemOssStorageTb::getFileMime, args.getBlurry()).or()
.like(SystemOssStorageTb::getFileMime, args.getBlurry()).or() .like(SystemOssStorageTb::getFileMd5, args.getBlurry()));
.like(SystemOssStorageTb::getFileMd5, args.getBlurry())); if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) { wrapper.between(SystemOssStorageTb::getUpdateTime, args.getCreateTime().get(0), args.getCreateTime().get(1));
wrapper.between(SystemOssStorageTb::getUpdateTime, args.getCreateTime().get(0),
args.getCreateTime().get(1));
}
} }
wrapper.orderByAsc(SystemOssStorageTb::getId); wrapper.orderByAsc(SystemOssStorageTb::getId);
return systemOssStorageMapper.selectPage(page, wrapper); return systemOssStorageMapper.selectPage(page, wrapper).convert(i -> KitBeanUtil.copyToClass(i, SystemOssStorageVo.class));
} }
@Override @Override
@@ -67,8 +67,8 @@ public class SystemMenuController {
@ApiOperation("返回全部的菜单") @ApiOperation("返回全部的菜单")
@PostMapping(value = "/listMenuByPid") @PostMapping(value = "/listMenuByPid")
@PreAuthorize("@el.check('menu:list','roles:list')") @PreAuthorize("@el.check('menu:list','roles:list')")
public ResponseEntity<List<SystemMenuTb>> listMenuByPid(@RequestParam Long pid) { public ResponseEntity<List<SystemMenuVo>> listMenuByPid(@RequestParam Long pid) {
List<SystemMenuTb> systemMenuTbs = systemMenuService.listMenuByPid(pid); List<SystemMenuVo> systemMenuTbs = systemMenuService.listMenuByPid(pid);
return ResponseEntity.ok(systemMenuTbs); return ResponseEntity.ok(systemMenuTbs);
} }
@@ -1,7 +1,6 @@
package cn.odboy.system.dal.model; package cn.odboy.system.dal.model;
import cn.odboy.system.dal.dataobject.SystemDeptTb; import cn.odboy.system.dal.dataobject.SystemDeptTb;
import cn.odboy.system.dal.dataobject.SystemMenuTb;
import cn.odboy.system.dal.dataobject.SystemRoleTb; import cn.odboy.system.dal.dataobject.SystemRoleTb;
import cn.odboy.system.dal.dataobject.SystemUserTb; import cn.odboy.system.dal.dataobject.SystemUserTb;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@@ -16,7 +15,7 @@ public class SystemRoleVo extends SystemRoleTb {
@ApiModelProperty(value = "用户", hidden = true) @ApiModelProperty(value = "用户", hidden = true)
private Set<SystemUserTb> users; private Set<SystemUserTb> users;
@ApiModelProperty(value = "菜单", hidden = true) @ApiModelProperty(value = "菜单", hidden = true)
private Set<SystemMenuTb> menus; private Set<SystemMenuVo> menus;
@ApiModelProperty(value = "部门", hidden = true) @ApiModelProperty(value = "部门", hidden = true)
private Set<SystemDeptTb> depts; private Set<SystemDeptTb> depts;
} }
@@ -168,8 +168,6 @@ public class SystemUserOnlineInfoDAO {
public void exportOnlineUserXlsx(HttpServletResponse response, String username) { public void exportOnlineUserXlsx(HttpServletResponse response, String username) {
List<SystemUserOnlineVo> userOnlineVos = this.queryUserOnlineModelListByUsername(username); List<SystemUserOnlineVo> userOnlineVos = this.queryUserOnlineModelListByUsername(username);
// KitXlsxExportUtil.exportFile(response, "在线用户数据", userOnlineVos, SystemUserOnlineExportRowVo.class,
// (dataObject) -> CollUtil.newArrayList(KitBeanUtil.copyProperties(dataObject, SystemUserOnlineExportRowVo.class)));
List<SystemUserOnlineExportRowVo> rowVos = KitBeanUtil.copyToList(userOnlineVos, SystemUserOnlineExportRowVo.class); List<SystemUserOnlineExportRowVo> rowVos = KitBeanUtil.copyToList(userOnlineVos, SystemUserOnlineExportRowVo.class);
KitExcelExporter.exportSimple(response, "在线用户数据", SystemUserOnlineExportRowVo.class, rowVos); KitExcelExporter.exportSimple(response, "在线用户数据", SystemUserOnlineExportRowVo.class, rowVos);
} }
@@ -71,6 +71,7 @@ public class SystemAuthService {
// 返回 token 与 用户信息 // 返回 token 与 用户信息
Map<String, Object> authInfo = new HashMap<>(2) {{ Map<String, Object> authInfo = new HashMap<>(2) {{
put("token", String.format("%s %s", SystemConst.TOKEN_PREFIX, token)); put("token", String.format("%s %s", SystemConst.TOKEN_PREFIX, token));
// 这里是为了清空密码
put("user", KitBeanUtil.copyToClass(jwtUser, SystemUserInfoVo.class)); put("user", KitBeanUtil.copyToClass(jwtUser, SystemUserInfoVo.class));
}}; }};
if (properties.getLogin().isSingle()) { if (properties.getLogin().isSingle()) {
@@ -19,6 +19,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.odboy.system.constant.SystemDataScopeEnum; import cn.odboy.system.constant.SystemDataScopeEnum;
import cn.odboy.system.dal.dataobject.SystemDeptTb; import cn.odboy.system.dal.dataobject.SystemDeptTb;
import cn.odboy.system.dal.dataobject.SystemRoleTb; import cn.odboy.system.dal.dataobject.SystemRoleTb;
import cn.odboy.system.dal.model.SystemDeptVo;
import cn.odboy.system.dal.model.SystemRoleVo; import cn.odboy.system.dal.model.SystemRoleVo;
import cn.odboy.system.dal.model.SystemUserVo; import cn.odboy.system.dal.model.SystemUserVo;
import java.util.ArrayList; import java.util.ArrayList;
@@ -81,7 +82,7 @@ public class SystemDataService {
List<SystemDeptTb> deptList = systemRoleDeptService.listDeptByRoleId(role.getId()); List<SystemDeptTb> deptList = systemRoleDeptService.listDeptByRoleId(role.getId());
for (SystemDeptTb dept : deptList) { for (SystemDeptTb dept : deptList) {
deptIds.add(dept.getId()); deptIds.add(dept.getId());
List<SystemDeptTb> deptChildren = systemDeptService.listDeptByPid(dept.getId()); List<SystemDeptVo> deptChildren = systemDeptService.listDeptByPid(dept.getId());
if (CollUtil.isNotEmpty(deptChildren)) { if (CollUtil.isNotEmpty(deptChildren)) {
deptIds.addAll(systemDeptService.queryChildDeptIdByDeptIds(deptChildren)); deptIds.addAll(systemDeptService.queryChildDeptIdByDeptIds(deptChildren));
} }
@@ -70,7 +70,8 @@ public class SystemDeptService {
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void saveDept(SystemCreateDeptArgs args) { public void saveDept(SystemCreateDeptArgs args) {
systemDeptMapper.insert(KitBeanUtil.copyToClass(args, SystemDeptTb.class)); SystemDeptTb deptTb = KitBeanUtil.copyToClass(args, SystemDeptTb.class);
systemDeptMapper.insert(deptTb);
this.updateDeptSubCnt(args.getPid()); this.updateDeptSubCnt(args.getPid());
} }
@@ -221,10 +222,10 @@ public class SystemDeptService {
* @param depts / * @param depts /
* @return / * @return /
*/ */
private Set<SystemDeptTb> queryRelationDeptByArgs(List<SystemDeptTb> deptTbList, Set<SystemDeptTb> depts) { private Set<SystemDeptTb> queryRelationDeptByArgs(List<SystemDeptVo> deptTbList, Set<SystemDeptTb> depts) {
for (SystemDeptTb dept : deptTbList) { for (SystemDeptTb dept : deptTbList) {
depts.add(dept); depts.add(dept);
List<SystemDeptTb> deptList = this.listDeptByPid(dept.getId()); List<SystemDeptVo> deptList = this.listDeptByPid(dept.getId());
if (CollUtil.isNotEmpty(deptList)) { if (CollUtil.isNotEmpty(deptList)) {
queryRelationDeptByArgs(deptList, depts); queryRelationDeptByArgs(deptList, depts);
} }
@@ -232,11 +233,11 @@ public class SystemDeptService {
return depts; return depts;
} }
public List<Long> queryChildDeptIdByDeptIds(List<SystemDeptTb> deptList) { public List<Long> queryChildDeptIdByDeptIds(List<SystemDeptVo> deptList) {
List<Long> list = new ArrayList<>(); List<Long> list = new ArrayList<>();
for (SystemDeptTb systemDeptTb : deptList) { for (SystemDeptVo systemDeptTb : deptList) {
if (systemDeptTb != null && systemDeptTb.getEnabled()) { if (systemDeptTb != null && systemDeptTb.getEnabled()) {
List<SystemDeptTb> deptList1 = this.listDeptByPid(systemDeptTb.getId()); List<SystemDeptVo> deptList1 = this.listDeptByPid(systemDeptTb.getId());
if (CollUtil.isNotEmpty(deptList1)) { if (CollUtil.isNotEmpty(deptList1)) {
list.addAll(queryChildDeptIdByDeptIds(deptList1)); list.addAll(queryChildDeptIdByDeptIds(deptList1));
} }
@@ -253,7 +254,7 @@ public class SystemDeptService {
* @param deptList / * @param deptList /
* @return / * @return /
*/ */
private List<SystemDeptTb> querySuperiorDeptByPid(SystemDeptTb dept, List<SystemDeptTb> deptList) { private List<SystemDeptVo> querySuperiorDeptByPid(SystemDeptTb dept, List<SystemDeptVo> deptList) {
if (dept.getPid() == null) { if (dept.getPid() == null) {
deptList.addAll(this.listRootDept()); deptList.addAll(this.listRootDept());
return deptList; return deptList;
@@ -262,10 +263,10 @@ public class SystemDeptService {
return querySuperiorDeptByPid(this.getDeptById(dept.getPid()), deptList); return querySuperiorDeptByPid(this.getDeptById(dept.getPid()), deptList);
} }
private List<SystemDeptTb> listRootDept() { private List<SystemDeptVo> listRootDept() {
LambdaQueryWrapper<SystemDeptTb> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SystemDeptTb> wrapper = new LambdaQueryWrapper<>();
wrapper.isNull(SystemDeptTb::getPid); wrapper.isNull(SystemDeptTb::getPid);
return systemDeptMapper.selectList(wrapper); return KitBeanUtil.copyToList(systemDeptMapper.selectList(wrapper), SystemDeptVo.class);
} }
/** /**
@@ -274,14 +275,14 @@ public class SystemDeptService {
* @return / * @return /
*/ */
public KitPageResult<SystemDeptVo> searchDeptTree(List<Long> ids, Boolean exclude) { public KitPageResult<SystemDeptVo> searchDeptTree(List<Long> ids, Boolean exclude) {
Set<SystemDeptTb> deptSet1 = new LinkedHashSet<>(); Set<SystemDeptVo> deptSet1 = new LinkedHashSet<>();
for (Long id : ids) { for (Long id : ids) {
// 同级数据 // 同级数据
SystemDeptTb dept = this.getDeptById(id); SystemDeptTb dept = this.getDeptById(id);
// 上级数据 // 上级数据
List<SystemDeptTb> depts = this.querySuperiorDeptByPid(dept, new ArrayList<>()); List<SystemDeptVo> depts = this.querySuperiorDeptByPid(dept, new ArrayList<>());
if (exclude) { if (exclude) {
for (SystemDeptTb data : depts) { for (SystemDeptVo data : depts) {
if (data.getId().equals(dept.getPid())) { if (data.getId().equals(dept.getPid())) {
data.setSubCount(data.getSubCount() - 1); data.setSubCount(data.getSubCount() - 1);
} }
@@ -291,7 +292,7 @@ public class SystemDeptService {
} }
deptSet1.addAll(depts); deptSet1.addAll(depts);
} }
List<SystemDeptVo> deptList = KitBeanUtil.copyToList(new ArrayList<>(deptSet1), SystemDeptVo.class); List<SystemDeptVo> deptList = new ArrayList<>(deptSet1);
// 构建部门树 // 构建部门树
Set<SystemDeptVo> trees = new LinkedHashSet<>(); Set<SystemDeptVo> trees = new LinkedHashSet<>();
Set<SystemDeptVo> deptSet = new LinkedHashSet<>(); Set<SystemDeptVo> deptSet = new LinkedHashSet<>();
@@ -358,9 +359,9 @@ public class SystemDeptService {
// 根部门 // 根部门
depts.add(this.getDeptById(id)); depts.add(this.getDeptById(id));
// 子部门 // 子部门
List<SystemDeptTb> deptList = listDeptByPid(id); List<SystemDeptVo> deptList = this.listDeptByPid(id);
if (CollectionUtil.isNotEmpty(deptList)) { if (CollectionUtil.isNotEmpty(deptList)) {
depts = queryRelationDeptByArgs(deptList, depts); queryRelationDeptByArgs(deptList, depts);
} }
} }
return depts; return depts;
@@ -464,10 +465,10 @@ public class SystemDeptService {
return vo; return vo;
} }
public List<SystemDeptTb> listDeptByPid(long pid) { public List<SystemDeptVo> listDeptByPid(long pid) {
LambdaQueryWrapper<SystemDeptTb> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SystemDeptTb> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(SystemDeptTb::getPid, pid); wrapper.eq(SystemDeptTb::getPid, pid);
return systemDeptMapper.selectList(wrapper); return KitBeanUtil.copyToList(systemDeptMapper.selectList(wrapper), SystemDeptVo.class);
} }
public void exportDeptXlsx(HttpServletResponse response, SystemQueryDeptArgs args) throws Exception { public void exportDeptXlsx(HttpServletResponse response, SystemQueryDeptArgs args) throws Exception {
@@ -27,6 +27,7 @@ import cn.odboy.system.dal.mysql.SystemDictDetailMapper;
import cn.odboy.system.dal.mysql.SystemDictMapper; import cn.odboy.system.dal.mysql.SystemDictMapper;
import cn.odboy.util.KitBeanUtil; import cn.odboy.util.KitBeanUtil;
import cn.odboy.util.KitPageUtil; import cn.odboy.util.KitPageUtil;
import cn.odboy.util.KitValidUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -55,6 +56,8 @@ public class SystemDictDetailService {
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void saveDictDetail(SystemCreateDictDetailArgs args) { public void saveDictDetail(SystemCreateDictDetailArgs args) {
KitValidUtil.notNull(args);
KitValidUtil.notNull(args.getDict());
SystemDictDetailTb dictDetail = KitBeanUtil.copyToClass(args, SystemDictDetailTb.class); SystemDictDetailTb dictDetail = KitBeanUtil.copyToClass(args, SystemDictDetailTb.class);
dictDetail.setDictId(args.getDict().getId()); dictDetail.setDictId(args.getDict().getId());
systemDictDetailMapper.insert(dictDetail); systemDictDetailMapper.insert(dictDetail);
@@ -104,8 +107,7 @@ public class SystemDictDetailService {
* @param page 分页参数 * @param page 分页参数
* @return / * @return /
*/ */
public KitPageResult<SystemDictDetailVo> searchDictDetail(SystemQueryDictDetailArgs args, public KitPageResult<SystemDictDetailVo> searchDictDetail(SystemQueryDictDetailArgs args, Page<SystemDictDetailTb> page) {
Page<SystemDictDetailTb> page) {
IPage<SystemDictDetailVo> iPage = systemDictDetailMapper.selectPageByArgs(page, args).convert(i -> KitBeanUtil.copyToClass(i, SystemDictDetailVo.class)); IPage<SystemDictDetailVo> iPage = systemDictDetailMapper.selectPageByArgs(page, args).convert(i -> KitBeanUtil.copyToClass(i, SystemDictDetailVo.class));
List<Long> dictIds = iPage.getRecords().stream().map(SystemDictDetailTb::getDictId).collect(Collectors.toList()); List<Long> dictIds = iPage.getRecords().stream().map(SystemDictDetailTb::getDictId).collect(Collectors.toList());
Map<Long, SystemDictTb> id2ItemMap = systemDictMapper.selectByIds(dictIds).stream().collect(Collectors.toMap(SystemDictTb::getId, i -> i)); Map<Long, SystemDictTb> id2ItemMap = systemDictMapper.selectByIds(dictIds).stream().collect(Collectors.toMap(SystemDictTb::getId, i -> i));
@@ -129,11 +131,12 @@ public class SystemDictDetailService {
if (systemDictTb == null) { if (systemDictTb == null) {
return new ArrayList<>(); return new ArrayList<>();
} }
return this.listDictDetailByDictId(systemDictTb.getId()).stream().map(m -> { List<SystemDictDetailTb> detailTbs = this.listDictDetailByDictId(systemDictTb.getId());
SystemDictDetailVo detailVo = KitBeanUtil.copyToClass(m, SystemDictDetailVo.class); List<SystemDictDetailVo> detailVos = KitBeanUtil.copyToList(detailTbs, SystemDictDetailVo.class);
for (SystemDictDetailVo detailVo : detailVos) {
detailVo.setDict(systemDictTb); detailVo.setDict(systemDictTb);
return detailVo; }
}).collect(Collectors.toList()); return detailVos;
} }
public Map<String, List<SystemDictDetailVo>> getDictDetailMap(String dictName) { public Map<String, List<SystemDictDetailVo>> getDictDetailMap(String dictName) {
@@ -53,7 +53,8 @@ public class SystemDictService {
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void saveDict(SystemCreateDictArgs args) { public void saveDict(SystemCreateDictArgs args) {
systemDictMapper.insert(KitBeanUtil.copyToClass(args, SystemDictTb.class)); SystemDictTb dictTb = KitBeanUtil.copyToClass(args, SystemDictTb.class);
systemDictMapper.insert(dictTb);
} }
/** /**
@@ -57,7 +57,8 @@ public class SystemJobService {
if (job != null) { if (job != null) {
throw new BadRequestException("职位名称已存在"); throw new BadRequestException("职位名称已存在");
} }
systemJobMapper.insert(KitBeanUtil.copyToClass(args, SystemJobTb.class)); SystemJobTb systemJobTb = KitBeanUtil.copyToClass(args, SystemJobTb.class);
systemJobMapper.insert(systemJobTb);
} }
/** /**
@@ -171,8 +171,6 @@ public class SystemLocalStorageService {
public void exportLocalStorageXlsx(HttpServletResponse response, SystemQueryStorageArgs args) { public void exportLocalStorageXlsx(HttpServletResponse response, SystemQueryStorageArgs args) {
List<SystemLocalStorageTb> systemLocalStorageTbs = this.queryLocalStorageByArgs(args); List<SystemLocalStorageTb> systemLocalStorageTbs = this.queryLocalStorageByArgs(args);
// KitXlsxExportUtil.exportFile(response, "文件上传记录数据", systemLocalStorageTbs, SystemLocalStorageExportRowVo.class,
// (dataObject) -> CollUtil.newArrayList(KitBeanUtil.copyProperties(dataObject, SystemLocalStorageExportRowVo.class)));
List<SystemLocalStorageExportRowVo> rowVos = KitBeanUtil.copyToList(systemLocalStorageTbs, SystemLocalStorageExportRowVo.class); List<SystemLocalStorageExportRowVo> rowVos = KitBeanUtil.copyToList(systemLocalStorageTbs, SystemLocalStorageExportRowVo.class);
KitExcelExporter.exportSimple(response, "文件上传记录数据", SystemLocalStorageExportRowVo.class, rowVos); KitExcelExporter.exportSimple(response, "文件上传记录数据", SystemLocalStorageExportRowVo.class, rowVos);
} }
@@ -153,10 +153,10 @@ public class SystemMenuService {
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void deleteMenuByIds(Set<Long> ids) { public void deleteMenuByIds(Set<Long> ids) {
Set<SystemMenuTb> menuSet = new HashSet<>(); Set<SystemMenuVo> menuSet = new HashSet<>();
for (Long id : ids) { for (Long id : ids) {
List<SystemMenuTb> menuList = this.listMenuByPid(id); List<SystemMenuVo> menuList = this.listMenuByPid(id);
menuSet.add(systemMenuMapper.selectById(id)); menuSet.add(this.getMenuVoById(id));
menuSet = this.queryChildMenuByArgs(menuList, menuSet); menuSet = this.queryChildMenuByArgs(menuList, menuSet);
} }
List<Long> menuIds = List<Long> menuIds =
@@ -170,6 +170,10 @@ public class SystemMenuService {
} }
} }
private SystemMenuVo getMenuVoById(Long id) {
return KitBeanUtil.copyToClass(systemMenuMapper.selectById(id), SystemMenuVo.class);
}
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void updateMenuSubCnt(Long menuId) { public void updateMenuSubCnt(Long menuId) {
if (menuId != null) { if (menuId != null) {
@@ -216,7 +220,7 @@ public class SystemMenuService {
* @param currentUserId / * @param currentUserId /
* @return / * @return /
*/ */
public List<SystemMenuTb> listMenuByUserId(Long currentUserId) { public List<SystemMenuVo> listMenuByUserId(Long currentUserId) {
List<SystemRoleVo> roles = systemUserRoleService.queryRoleByUsersId(currentUserId); List<SystemRoleVo> roles = systemUserRoleService.queryRoleByUsersId(currentUserId);
Set<Long> roleIds = roles.stream().map(SystemRoleTb::getId).collect(Collectors.toSet()); Set<Long> roleIds = roles.stream().map(SystemRoleTb::getId).collect(Collectors.toSet());
return new ArrayList<>(systemRoleMenuService.queryMenuByRoleIds(roleIds)); return new ArrayList<>(systemRoleMenuService.queryMenuByRoleIds(roleIds));
@@ -229,10 +233,10 @@ public class SystemMenuService {
* @param menuSet / * @param menuSet /
* @return / * @return /
*/ */
public Set<SystemMenuTb> queryChildMenuByArgs(List<SystemMenuTb> menuList, Set<SystemMenuTb> menuSet) { public Set<SystemMenuVo> queryChildMenuByArgs(List<SystemMenuVo> menuList, Set<SystemMenuVo> menuSet) {
for (SystemMenuTb menu : menuList) { for (SystemMenuVo menu : menuList) {
menuSet.add(menu); menuSet.add(menu);
List<SystemMenuTb> menus = this.listMenuByPid(menu.getId()); List<SystemMenuVo> menus = this.listMenuByPid(menu.getId());
if (CollUtil.isNotEmpty(menus)) { if (CollUtil.isNotEmpty(menus)) {
queryChildMenuByArgs(menus, menuSet); queryChildMenuByArgs(menus, menuSet);
} }
@@ -246,13 +250,13 @@ public class SystemMenuService {
* @param pid / * @param pid /
* @return / * @return /
*/ */
public List<SystemMenuTb> listMenuByPid(Long pid) { public List<SystemMenuVo> listMenuByPid(Long pid) {
List<SystemMenuTb> menus; List<SystemMenuVo> menus;
if (pid != null && !pid.equals(0L)) { if (pid != null && !pid.equals(0L)) {
LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(SystemMenuTb::getPid, pid); wrapper.eq(SystemMenuTb::getPid, pid);
wrapper.orderByAsc(SystemMenuTb::getMenuSort); wrapper.orderByAsc(SystemMenuTb::getMenuSort);
return systemMenuMapper.selectList(wrapper); return KitBeanUtil.copyToList(systemMenuMapper.selectList(wrapper), SystemMenuVo.class);
} else { } else {
menus = this.listRootMenu(); menus = this.listRootMenu();
} }
@@ -266,13 +270,13 @@ public class SystemMenuService {
* @param menus / * @param menus /
* @return / * @return /
*/ */
public List<SystemMenuTb> querySuperiorMenuByArgs(SystemMenuTb menu, List<SystemMenuTb> menus) { public List<SystemMenuVo> querySuperiorMenuByArgs(SystemMenuTb menu, List<SystemMenuVo> menus) {
if (menu.getPid() == null) { if (menu.getPid() == null) {
menus.addAll(this.listRootMenu()); menus.addAll(this.listRootMenu());
return menus; return menus;
} }
menus.addAll(this.listMenuByPid(menu.getPid())); menus.addAll(this.listMenuByPid(menu.getPid()));
return querySuperiorMenuByArgs(systemMenuMapper.selectById(menu.getPid()), menus); return querySuperiorMenuByArgs(this.getMenuVoById(menu.getPid()), menus);
} }
/** /**
@@ -374,8 +378,8 @@ public class SystemMenuService {
return menuVo1; return menuVo1;
} }
public List<SystemMenuTb> listMenuByIds(List<Long> ids) { public List<SystemMenuVo> listMenuByIds(List<Long> ids) {
return systemMenuMapper.selectByIds(ids); return KitBeanUtil.copyToList(systemMenuMapper.selectByIds(ids), SystemMenuVo.class);
} }
private SystemMenuTb getMenuByComponentName(String componentName) { private SystemMenuTb getMenuByComponentName(String componentName) {
@@ -413,36 +417,35 @@ public class SystemMenuService {
return systemMenuMapper.selectList(wrapper); return systemMenuMapper.selectList(wrapper);
} }
private List<SystemMenuTb> listRootMenu() { private List<SystemMenuVo> listRootMenu() {
LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>();
wrapper.isNull(SystemMenuTb::getPid); wrapper.isNull(SystemMenuTb::getPid);
wrapper.orderByAsc(SystemMenuTb::getMenuSort); wrapper.orderByAsc(SystemMenuTb::getMenuSort);
return systemMenuMapper.selectList(wrapper); return KitBeanUtil.copyToList(systemMenuMapper.selectList(wrapper), SystemMenuVo.class);
} }
public List<SystemMenuRouterVo> buildFrontMenus() { public List<SystemMenuRouterVo> buildFrontMenus() {
List<SystemMenuTb> menuList = this.listMenuByUserId(KitSecurityHelper.getCurrentUserId()); List<SystemMenuVo> originMenus = this.listMenuByUserId(KitSecurityHelper.getCurrentUserId());
List<SystemMenuVo> originMenus = KitBeanUtil.copyToList(menuList, SystemMenuVo.class);
List<SystemMenuVo> targetMenus = this.buildMenuTree(originMenus); List<SystemMenuVo> targetMenus = this.buildMenuTree(originMenus);
return this.buildMenuVo(targetMenus); return this.buildMenuVo(targetMenus);
} }
public Set<Long> listChildMenuSetByMenuId(Long id) { public Set<Long> listChildMenuSetByMenuId(Long id) {
Set<SystemMenuTb> menuSet = new HashSet<>(); Set<SystemMenuVo> menuSet = new HashSet<>();
List<SystemMenuTb> menuList = this.listMenuByPid(id); List<SystemMenuVo> menuList = this.listMenuByPid(id);
menuSet.add(systemMenuMapper.selectById(id)); menuSet.add(this.getMenuVoById(id));
menuSet = this.queryChildMenuByArgs(menuList, menuSet); menuSet = this.queryChildMenuByArgs(menuList, menuSet);
return menuSet.stream().map(SystemMenuTb::getId).collect(Collectors.toSet()); return menuSet.stream().map(SystemMenuTb::getId).collect(Collectors.toSet());
} }
public List<SystemMenuVo> listMenuSuperior(List<Long> ids) { public List<SystemMenuVo> listMenuSuperior(List<Long> ids) {
Set<SystemMenuTb> menus; Set<SystemMenuVo> menus;
List<SystemMenuVo> systemMenuTbs; List<SystemMenuVo> systemMenuTbs;
if (CollectionUtil.isNotEmpty(ids)) { if (CollectionUtil.isNotEmpty(ids)) {
menus = new LinkedHashSet<>(this.listMenuByIds(ids)); menus = new LinkedHashSet<>(this.listMenuByIds(ids));
for (SystemMenuTb menu : menus) { for (SystemMenuTb menu : menus) {
List<SystemMenuTb> menuList = this.querySuperiorMenuByArgs(menu, new ArrayList<>()); List<SystemMenuVo> menuList = this.querySuperiorMenuByArgs(menu, new ArrayList<>());
for (SystemMenuTb data : menuList) { for (SystemMenuVo data : menuList) {
if (data.getId().equals(menu.getPid())) { if (data.getId().equals(menu.getPid())) {
data.setSubCount(data.getSubCount() - 1); data.setSubCount(data.getSubCount() - 1);
} }
@@ -451,28 +454,16 @@ public class SystemMenuService {
} }
// 编辑菜单时不显示自己以及自己下级的数据, 避免出现PID数据环形问题 // 编辑菜单时不显示自己以及自己下级的数据, 避免出现PID数据环形问题
menus = menus.stream().filter(i -> !ids.contains(i.getId())).collect(Collectors.toSet()); menus = menus.stream().filter(i -> !ids.contains(i.getId())).collect(Collectors.toSet());
List<SystemMenuTb> newMenuList = new ArrayList<>(menus); List<SystemMenuVo> newMenuList = new ArrayList<>(menus);
systemMenuTbs = this.buildMenuTree(KitBeanUtil.copyToList(newMenuList, SystemMenuVo.class)); systemMenuTbs = this.buildMenuTree(newMenuList);
} else { } else {
List<SystemMenuTb> newMenuList = this.listMenuByPid(null); systemMenuTbs = this.listMenuByPid(null);
systemMenuTbs = KitBeanUtil.copyToList(newMenuList, SystemMenuVo.class);
} }
return systemMenuTbs; return systemMenuTbs;
} }
public void exportMenuXlsx(HttpServletResponse response, SystemQueryMenuArgs args) throws Exception { public void exportMenuXlsx(HttpServletResponse response, SystemQueryMenuArgs args) throws Exception {
List<SystemMenuTb> systemMenuTbs = this.queryAllMenu(args, false); List<SystemMenuTb> systemMenuTbs = this.queryAllMenu(args, false);
// KitXlsxExportUtil.exportFile(response, "菜单数据", systemMenuTbs, SystemMenuExportRowVo.class, (dataObject -> {
// SystemMenuExportRowVo rowVo = new SystemMenuExportRowVo();
// rowVo.setTitle(dataObject.getTitle());
// rowVo.setType(dataObject.getType() == null ? "目录" : dataObject.getType() == 1 ? "菜单" : "按钮");
// rowVo.setPermission(dataObject.getPermission());
// rowVo.setIFrame(dataObject.getIFrame() ? SystemYesOrNoChConst.YES_STR : SystemYesOrNoChConst.NO_STR);
// rowVo.setHidden(dataObject.getHidden() ? SystemYesOrNoChConst.NO_STR : SystemYesOrNoChConst.YES_STR);
// rowVo.setCache(dataObject.getCache() ? SystemYesOrNoChConst.YES_STR : SystemYesOrNoChConst.NO_STR);
// rowVo.setCreateTime(dataObject.getCreateTime());
// return CollUtil.newArrayList(rowVo);
// }));
List<SystemMenuExportRowVo> rowVos = new ArrayList<>(); List<SystemMenuExportRowVo> rowVos = new ArrayList<>();
for (SystemMenuTb dataObject : systemMenuTbs) { for (SystemMenuTb dataObject : systemMenuTbs) {
SystemMenuExportRowVo rowVo = new SystemMenuExportRowVo(); SystemMenuExportRowVo rowVo = new SystemMenuExportRowVo();
@@ -18,8 +18,10 @@ package cn.odboy.system.service;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.odboy.system.dal.dataobject.SystemMenuTb; import cn.odboy.system.dal.dataobject.SystemMenuTb;
import cn.odboy.system.dal.dataobject.SystemRoleMenuTb; import cn.odboy.system.dal.dataobject.SystemRoleMenuTb;
import cn.odboy.system.dal.model.SystemMenuVo;
import cn.odboy.system.dal.mysql.SystemMenuMapper; import cn.odboy.system.dal.mysql.SystemMenuMapper;
import cn.odboy.system.dal.mysql.SystemRoleMenuMapper; import cn.odboy.system.dal.mysql.SystemRoleMenuMapper;
import cn.odboy.util.KitBeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
@@ -46,10 +48,10 @@ public class SystemRoleMenuService {
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void batchInsertRoleMenu(Set<SystemMenuTb> menus, Long roleId) { public void batchInsertRoleMenu(Set<SystemMenuVo> menus, Long roleId) {
if (CollUtil.isNotEmpty(menus)) { if (CollUtil.isNotEmpty(menus)) {
List<SystemRoleMenuTb> records = new ArrayList<>(); List<SystemRoleMenuTb> records = new ArrayList<>();
for (SystemMenuTb menu : menus) { for (SystemMenuVo menu : menus) {
SystemRoleMenuTb record = new SystemRoleMenuTb(); SystemRoleMenuTb record = new SystemRoleMenuTb();
record.setMenuId(menu.getId()); record.setMenuId(menu.getId());
record.setRoleId(roleId); record.setRoleId(roleId);
@@ -68,7 +70,7 @@ public class SystemRoleMenuService {
} }
} }
public LinkedHashSet<SystemMenuTb> queryMenuByRoleIds(Set<Long> roleIds) { public LinkedHashSet<SystemMenuVo> queryMenuByRoleIds(Set<Long> roleIds) {
if (CollUtil.isEmpty(roleIds)) { if (CollUtil.isEmpty(roleIds)) {
return new LinkedHashSet<>(); return new LinkedHashSet<>();
} }
@@ -84,7 +86,10 @@ public class SystemRoleMenuService {
// 排除"按钮" // 排除"按钮"
menuWrapper.ne(SystemMenuTb::getType, 2); menuWrapper.ne(SystemMenuTb::getType, 2);
menuWrapper.orderByAsc(SystemMenuTb::getMenuSort); menuWrapper.orderByAsc(SystemMenuTb::getMenuSort);
return new LinkedHashSet<>(systemMenuMapper.selectList(menuWrapper));
List<SystemMenuTb> systemMenuTbs = systemMenuMapper.selectList(menuWrapper);
List<SystemMenuVo> systemMenuVos = KitBeanUtil.copyToList(systemMenuTbs, SystemMenuVo.class);
return new LinkedHashSet<>(systemMenuVos);
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@@ -25,6 +25,7 @@ import cn.odboy.system.dal.dataobject.SystemMenuTb;
import cn.odboy.system.dal.dataobject.SystemRoleTb; import cn.odboy.system.dal.dataobject.SystemRoleTb;
import cn.odboy.system.dal.dataobject.SystemUserTb; import cn.odboy.system.dal.dataobject.SystemUserTb;
import cn.odboy.system.dal.model.SystemCreateRoleArgs; import cn.odboy.system.dal.model.SystemCreateRoleArgs;
import cn.odboy.system.dal.model.SystemMenuVo;
import cn.odboy.system.dal.model.SystemQueryRoleArgs; import cn.odboy.system.dal.model.SystemQueryRoleArgs;
import cn.odboy.system.dal.model.SystemRoleCodeVo; import cn.odboy.system.dal.model.SystemRoleCodeVo;
import cn.odboy.system.dal.model.SystemRoleExportRowVo; import cn.odboy.system.dal.model.SystemRoleExportRowVo;
@@ -71,7 +72,8 @@ public class SystemRoleService {
if (this.getRoleByName(args.getName()) != null) { if (this.getRoleByName(args.getName()) != null) {
throw new BadRequestException("角色名称已存在"); throw new BadRequestException("角色名称已存在");
} }
systemRoleMapper.insert(KitBeanUtil.copyToClass(args, SystemRoleTb.class)); SystemRoleTb roleTb = KitBeanUtil.copyToClass(args, SystemRoleTb.class);
systemRoleMapper.insert(roleTb);
// 判断是否有部门数据, 若有, 则需创建关联 // 判断是否有部门数据, 若有, 则需创建关联
if (CollectionUtil.isNotEmpty(args.getDepts())) { if (CollectionUtil.isNotEmpty(args.getDepts())) {
systemRoleDeptService.batchInsertRoleDept(args.getDepts(), args.getId()); systemRoleDeptService.batchInsertRoleDept(args.getDepts(), args.getId());
@@ -92,7 +94,7 @@ public class SystemRoleService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void updateRoleById(SystemRoleVo args) { public void updateRoleById(SystemRoleVo args) {
checkRoleLevels(args.getLevel()); checkRoleLevels(args.getLevel());
SystemRoleVo role = KitBeanUtil.copyToClass(systemRoleMapper.selectById(args.getId()), SystemRoleVo.class); SystemRoleVo role = this.getRoleVoById(args.getId());
SystemRoleTb role1 = this.getRoleByName(args.getName()); SystemRoleTb role1 = this.getRoleByName(args.getName());
if (role1 != null && !role1.getId().equals(role.getId())) { if (role1 != null && !role1.getId().equals(role.getId())) {
throw new BadRequestException("角色名称已存在"); throw new BadRequestException("角色名称已存在");
@@ -112,6 +114,10 @@ public class SystemRoleService {
} }
} }
private SystemRoleVo getRoleVoById(Long id) {
return KitBeanUtil.copyToClass(systemRoleMapper.selectById(id), SystemRoleVo.class);
}
/** /**
* 修改绑定的菜单 * 修改绑定的菜单
* *
@@ -123,8 +129,9 @@ public class SystemRoleService {
// 更新菜单 // 更新菜单
systemRoleMenuService.deleteRoleMenuByRoleId(role.getId()); systemRoleMenuService.deleteRoleMenuByRoleId(role.getId());
// 判断是否为空 // 判断是否为空
if (CollUtil.isNotEmpty(args.getMenus())) { Set<SystemMenuVo> menus = args.getMenus();
systemRoleMenuService.batchInsertRoleMenu(args.getMenus(), role.getId()); if (CollUtil.isNotEmpty(menus)) {
systemRoleMenuService.batchInsertRoleMenu(menus, role.getId());
} }
} }
@@ -21,6 +21,7 @@ import cn.odboy.system.dal.dataobject.SystemDeptTb;
import cn.odboy.system.dal.dataobject.SystemMenuTb; import cn.odboy.system.dal.dataobject.SystemMenuTb;
import cn.odboy.system.dal.dataobject.SystemRoleTb; import cn.odboy.system.dal.dataobject.SystemRoleTb;
import cn.odboy.system.dal.dataobject.SystemUserRoleTb; import cn.odboy.system.dal.dataobject.SystemUserRoleTb;
import cn.odboy.system.dal.model.SystemMenuVo;
import cn.odboy.system.dal.model.SystemRoleVo; import cn.odboy.system.dal.model.SystemRoleVo;
import cn.odboy.system.dal.model.SystemUserVo; import cn.odboy.system.dal.model.SystemUserVo;
import cn.odboy.system.dal.mysql.SystemRoleMapper; import cn.odboy.system.dal.mysql.SystemRoleMapper;
@@ -86,8 +87,7 @@ public class SystemUserRoleService {
} }
SystemRoleVo roleVo = KitBeanUtil.copyToClass(role, SystemRoleVo.class); SystemRoleVo roleVo = KitBeanUtil.copyToClass(role, SystemRoleVo.class);
// 查询关联的菜单信息 // 查询关联的菜单信息
Set<SystemMenuTb> menus = systemRoleMenuService.queryMenuByRoleIds( Set<SystemMenuVo> menus = systemRoleMenuService.queryMenuByRoleIds(Collections.singleton(role.getId()));
Collections.singleton(role.getId()));
roleVo.setMenus(menus); roleVo.setMenus(menus);
// 查询关联的部门信息 // 查询关联的部门信息
@@ -32,6 +32,7 @@ import cn.odboy.system.dal.dataobject.SystemRoleTb;
import cn.odboy.system.dal.dataobject.SystemUserJobTb; import cn.odboy.system.dal.dataobject.SystemUserJobTb;
import cn.odboy.system.dal.dataobject.SystemUserRoleTb; import cn.odboy.system.dal.dataobject.SystemUserRoleTb;
import cn.odboy.system.dal.dataobject.SystemUserTb; import cn.odboy.system.dal.dataobject.SystemUserTb;
import cn.odboy.system.dal.model.SystemDeptVo;
import cn.odboy.system.dal.model.SystemQueryUserArgs; import cn.odboy.system.dal.model.SystemQueryUserArgs;
import cn.odboy.system.dal.model.SystemUpdateUserPasswordArgs; import cn.odboy.system.dal.model.SystemUpdateUserPasswordArgs;
import cn.odboy.system.dal.model.SystemUserExportRowVo; import cn.odboy.system.dal.model.SystemUserExportRowVo;
@@ -487,7 +488,7 @@ public class SystemUserService {
if (!ObjectUtils.isEmpty(args.getDeptId())) { if (!ObjectUtils.isEmpty(args.getDeptId())) {
args.getDeptIds().add(args.getDeptId()); args.getDeptIds().add(args.getDeptId());
// 先查找是否存在子节点 // 先查找是否存在子节点
List<SystemDeptTb> data = systemDeptService.listDeptByPid(args.getDeptId()); List<SystemDeptVo> data = systemDeptService.listDeptByPid(args.getDeptId());
// 然后把子节点的ID都加入到集合中 // 然后把子节点的ID都加入到集合中
args.getDeptIds().addAll(systemDeptService.queryChildDeptIdByDeptIds(data)); args.getDeptIds().addAll(systemDeptService.queryChildDeptIdByDeptIds(data));
} }