refactor(system): 重构系统组件服务结构
- 将产品线选择组件相关VO类从dal层移动到application层并重命名 - 新增CuteUserSelectVo、CuteBaseService、CuteFileUploadService等服务类 - 创建CuteProductLineSelectProService和CuteProductLineSelectService业务服务 - 新增CuteUserSelectService用户选择服务及对应的API接口 - 修改文件上传API使用新的服务类并添加权限控制 - 更新产品线选择API使用新服务类并移除旧的实现方法 - 删除系统用户服务中的旧用户元数据查询方法 - 更新前端用户选择组件调用新的API接口 - 移除旧的用户元数据选项查询API调用
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
export function listMetadata(query) {
|
||||
const params = {
|
||||
blurry: query
|
||||
}
|
||||
return request({
|
||||
url: 'api/component/CuteUserSelect/listMetadata',
|
||||
method: 'post',
|
||||
data: params
|
||||
})
|
||||
}
|
||||
|
||||
export default { listMetadata }
|
||||
|
||||
@@ -68,20 +68,5 @@ export function updateUserEmailByUsername(form) {
|
||||
})
|
||||
}
|
||||
|
||||
export function queryUserMetadataOptions(query) {
|
||||
const params = {
|
||||
page: 1,
|
||||
size: 50,
|
||||
args: {
|
||||
blurry: query
|
||||
}
|
||||
}
|
||||
return request({
|
||||
url: 'api/user/queryUserMetadataOptions',
|
||||
method: 'post',
|
||||
data: params
|
||||
})
|
||||
}
|
||||
|
||||
export default { add, edit, del, resetUserPasswordByIds, queryUserMetadataOptions }
|
||||
export default { add, edit, del, resetUserPasswordByIds }
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
<script>
|
||||
|
||||
import UserService from '@/api/system/user'
|
||||
import CuteUserSelectApi from '@/api/application/cute-user-select'
|
||||
|
||||
export default {
|
||||
name: 'CuteSingleUserSelect',
|
||||
@@ -57,15 +57,15 @@ export default {
|
||||
this.loading = true
|
||||
setTimeout(() => {
|
||||
this.loading = false
|
||||
this.queryUserMetadataOptions(query)
|
||||
this.listMetadata(query)
|
||||
}, 200)
|
||||
} else {
|
||||
this.options = []
|
||||
}
|
||||
},
|
||||
queryUserMetadataOptions(query, options) {
|
||||
listMetadata(query, options) {
|
||||
const that = this
|
||||
UserService.queryUserMetadataOptions(query).then(res => {
|
||||
CuteUserSelectApi.listMetadata(query).then(res => {
|
||||
that.options = res
|
||||
})
|
||||
},
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
<script>
|
||||
|
||||
import UserService from '@/api/system/user'
|
||||
import CuteUserSelectApi from '@/api/application/cute-user-select'
|
||||
|
||||
export default {
|
||||
name: 'CuteUserSelect',
|
||||
@@ -67,15 +67,15 @@ export default {
|
||||
this.loading = true
|
||||
setTimeout(() => {
|
||||
this.loading = false
|
||||
this.queryUserMetadataOptions(query)
|
||||
this.listMetadata(query)
|
||||
}, 200)
|
||||
} else {
|
||||
this.options = []
|
||||
}
|
||||
},
|
||||
queryUserMetadataOptions(query, options) {
|
||||
listMetadata(query, options) {
|
||||
const that = this
|
||||
UserService.queryUserMetadataOptions(query).then(res => {
|
||||
CuteUserSelectApi.listMetadata(query).then(res => {
|
||||
that.options = res
|
||||
})
|
||||
},
|
||||
|
||||
+6
-2
@@ -1,5 +1,6 @@
|
||||
package cn.odboy.system.application;
|
||||
|
||||
import cn.odboy.system.application.service.CuteFileUploadService;
|
||||
import cn.odboy.system.framework.operalog.OperationLog;
|
||||
import cn.odboy.system.service.SystemLocalStorageService;
|
||||
import cn.odboy.system.service.SystemOssStorageService;
|
||||
@@ -7,6 +8,7 @@ import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@@ -19,21 +21,23 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
public class CuteFileUploadApi {
|
||||
|
||||
@Autowired
|
||||
private SystemLocalStorageService systemLocalStorageService;
|
||||
private CuteFileUploadService cuteFileUploadService;
|
||||
@Autowired
|
||||
private SystemOssStorageService systemOssStorageService;
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("上传文件到服务器本地")
|
||||
@PostMapping(value = "/uploadLocal")
|
||||
@PreAuthorize("@el.check()")
|
||||
public ResponseEntity<String> uploadLocal(@RequestParam("file") MultipartFile file) {
|
||||
String fileUrl = systemLocalStorageService.uploadLocal(file);
|
||||
String fileUrl = cuteFileUploadService.uploadLocal(file);
|
||||
return ResponseEntity.ok(fileUrl);
|
||||
}
|
||||
|
||||
@OperationLog
|
||||
@ApiOperation("上传文件到OSS")
|
||||
@PostMapping(value = "/uploadOSS")
|
||||
@PreAuthorize("@el.check()")
|
||||
public ResponseEntity<String> uploadOSS(@RequestParam("file") MultipartFile file) {
|
||||
String fileUrl = systemOssStorageService.uploadFile(file);
|
||||
return ResponseEntity.ok(fileUrl);
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
package cn.odboy.system.application;
|
||||
|
||||
import cn.odboy.system.service.SystemDeptService;
|
||||
import cn.odboy.system.application.service.CuteProductLineSelectService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -16,12 +16,12 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
public class CuteProductLineSelectApi {
|
||||
|
||||
@Autowired
|
||||
private SystemDeptService systemDeptService;
|
||||
private CuteProductLineSelectService cuteProductLineSelectService;
|
||||
|
||||
@ApiOperation("查询部门下拉选择数据源")
|
||||
@PostMapping(value = "/listMetadata")
|
||||
@PreAuthorize("@el.check()")
|
||||
public ResponseEntity<?> listMetadata() {
|
||||
return ResponseEntity.ok(systemDeptService.listDeptSelectDataSource());
|
||||
return ResponseEntity.ok(cuteProductLineSelectService.listMetadata());
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
package cn.odboy.system.application;
|
||||
|
||||
import cn.odboy.system.service.SystemDeptService;
|
||||
import cn.odboy.system.application.service.CuteProductLineSelectProService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -16,12 +16,12 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
public class CuteProductLineSelectProApi {
|
||||
|
||||
@Autowired
|
||||
private SystemDeptService systemDeptService;
|
||||
private CuteProductLineSelectProService cuteProductLineSelectProService;
|
||||
|
||||
@ApiOperation("查询部门下拉选择Pro数据源")
|
||||
@PostMapping(value = "/listMetadata")
|
||||
@PreAuthorize("@el.check()")
|
||||
public ResponseEntity<?> listMetadata() {
|
||||
return ResponseEntity.ok(systemDeptService.listDeptSelectProDataSource());
|
||||
return ResponseEntity.ok(cuteProductLineSelectProService.listMetadata());
|
||||
}
|
||||
}
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package cn.odboy.system.application;
|
||||
|
||||
import cn.odboy.system.application.model.CuteUserSelectVo;
|
||||
import cn.odboy.system.application.service.CuteUserSelectService;
|
||||
import cn.odboy.system.dal.model.request.SystemQueryUserArgs;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@Api(tags = "系统组件:CuteUserSelect")
|
||||
@RequestMapping("/api/component/CuteUserSelect")
|
||||
public class CuteUserSelectApi {
|
||||
|
||||
@Autowired
|
||||
private CuteUserSelectService cuteUserSelectService;
|
||||
|
||||
@ApiOperation("查询用户基础数据")
|
||||
@PostMapping(value = "/listMetadata")
|
||||
@PreAuthorize("@el.check()")
|
||||
public ResponseEntity<List<CuteUserSelectVo>> listMetadata(@Validated @RequestBody SystemQueryUserArgs args) {
|
||||
List<CuteUserSelectVo> collect = cuteUserSelectService.listMetadata(args);
|
||||
return ResponseEntity.ok(collect);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.odboy.system.dal.model.response;
|
||||
package cn.odboy.system.application.model;
|
||||
|
||||
import cn.odboy.base.KitObject;
|
||||
import java.util.List;
|
||||
@@ -22,9 +22,9 @@ import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class SystemProductLineTreeVo extends KitObject {
|
||||
public class CuteProductLineSelectProVo extends KitObject {
|
||||
|
||||
private String value;
|
||||
private String label;
|
||||
private List<SystemProductLineTreeVo> children;
|
||||
private List<CuteProductLineSelectProVo> children;
|
||||
}
|
||||
+2
-2
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.odboy.system.dal.model.response;
|
||||
package cn.odboy.system.application.model;
|
||||
|
||||
import cn.odboy.base.KitObject;
|
||||
import lombok.Getter;
|
||||
@@ -21,7 +21,7 @@ import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class SystemProductLineVo extends KitObject {
|
||||
public class CuteProductLineSelectVo extends KitObject {
|
||||
|
||||
/**
|
||||
* 部门ID(select的value)
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package cn.odboy.system.application.model;
|
||||
|
||||
import cn.odboy.base.KitObject;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class CuteUserSelectVo extends KitObject {
|
||||
|
||||
/**
|
||||
* username
|
||||
*/
|
||||
private String value;
|
||||
/**
|
||||
* nickname
|
||||
*/
|
||||
private String label;
|
||||
private String deptId;
|
||||
private String email;
|
||||
private String phone;
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package cn.odboy.system.application.service;
|
||||
|
||||
import cn.odboy.system.dal.dataobject.SystemDeptTb;
|
||||
import cn.odboy.system.dal.mysql.SystemDeptMapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import java.util.List;
|
||||
|
||||
public class CuteBaseService {
|
||||
|
||||
@Autowired
|
||||
private SystemDeptMapper systemDeptMapper;
|
||||
|
||||
/**
|
||||
* 查询启用的所有部门集合
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
public List<SystemDeptTb> listEnabledDept() {
|
||||
LambdaQueryWrapper<SystemDeptTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemDeptTb::getEnabled, 1);
|
||||
return systemDeptMapper.selectList(wrapper);
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package cn.odboy.system.application.service;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.odboy.framework.context.KitRequestHolder;
|
||||
import cn.odboy.framework.exception.BadRequestException;
|
||||
import cn.odboy.framework.properties.AppProperties;
|
||||
import cn.odboy.framework.server.core.KitFileLocalUploadHelper;
|
||||
import cn.odboy.system.dal.dataobject.SystemLocalStorageTb;
|
||||
import cn.odboy.system.dal.mysql.SystemLocalStorageMapper;
|
||||
import cn.odboy.util.KitFileUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class CuteFileUploadService {
|
||||
|
||||
@Autowired
|
||||
private SystemLocalStorageMapper systemLocalStorageMapper;
|
||||
@Autowired
|
||||
private KitFileLocalUploadHelper fileUploadPathHelper;
|
||||
@Autowired
|
||||
private AppProperties properties;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String uploadLocal(MultipartFile multipartFile) {
|
||||
long size = multipartFile.getSize();
|
||||
KitFileUtil.checkSize(properties.getOss().getMaxSize(), size);
|
||||
String suffix = KitFileUtil.getSuffix(multipartFile.getOriginalFilename());
|
||||
String type = KitFileUtil.getFileType(suffix);
|
||||
String uploadDateStr = DateUtil.format(new Date(), DatePattern.PURE_DATE_FORMAT);
|
||||
File file = KitFileUtil.upload(multipartFile, fileUploadPathHelper.getPath() + uploadDateStr + File.separator);
|
||||
if (file == null) {
|
||||
throw new BadRequestException("上传失败");
|
||||
}
|
||||
try {
|
||||
String formatSize = KitFileUtil.getSize(size);
|
||||
String prefixName = KitFileUtil.getPrefix(multipartFile.getOriginalFilename(), null);
|
||||
SystemLocalStorageTb localStorage = new SystemLocalStorageTb();
|
||||
localStorage.setRealName(file.getName());
|
||||
localStorage.setName(prefixName);
|
||||
localStorage.setSuffix(suffix);
|
||||
localStorage.setPath(file.getPath());
|
||||
localStorage.setType(type);
|
||||
localStorage.setSize(formatSize);
|
||||
localStorage.setDateGroup(uploadDateStr);
|
||||
systemLocalStorageMapper.insert(localStorage);
|
||||
// 构建上传路径 /file/20260117/odboycn-20260117055246428.png
|
||||
HttpServletRequest httpServletRequest = KitRequestHolder.getHttpServletRequest();
|
||||
StringBuffer requestURL = httpServletRequest.getRequestURL();
|
||||
String[] splits = requestURL.toString().split("/api/component/CuteFileUpload");
|
||||
String requestAddress = splits[0];
|
||||
return String.format("%s/file/%s/%s", requestAddress, uploadDateStr, localStorage.getRealName());
|
||||
} catch (Exception e) {
|
||||
log.error("上传文件失败", e);
|
||||
KitFileUtil.del(file);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package cn.odboy.system.application.service;
|
||||
|
||||
import cn.odboy.system.application.model.CuteProductLineSelectProVo;
|
||||
import cn.odboy.system.dal.dataobject.SystemDeptTb;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class CuteProductLineSelectProService extends CuteBaseService {
|
||||
|
||||
/**
|
||||
* 产品线选择组件Pro版 数据源
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
public List<CuteProductLineSelectProVo> listMetadata() {
|
||||
List<SystemDeptTb> depts = this.listEnabledDept();
|
||||
// 查询所有部门并按父子关系组织
|
||||
Map<Long, SystemDeptTb> deptMap =
|
||||
depts.stream().collect(Collectors.toMap(SystemDeptTb::getId, Function.identity()));
|
||||
List<CuteProductLineSelectProVo> options = new ArrayList<>();
|
||||
// 构建树形结构
|
||||
for (SystemDeptTb dept : depts) {
|
||||
// 只处理顶级部门(pid为null或0的部门)
|
||||
if (dept.getPid() == null || dept.getPid() == 0) {
|
||||
CuteProductLineSelectProVo vo = this.buildDeptTreePro(dept, deptMap);
|
||||
options.add(vo);
|
||||
}
|
||||
}
|
||||
// 按排序字段排序
|
||||
options.sort(Comparator.comparingInt(o -> {
|
||||
Long id = Long.valueOf(o.getValue());
|
||||
return deptMap.get(id) != null ? deptMap.get(id).getDeptSort() : 0;
|
||||
}));
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归构建部门树
|
||||
*
|
||||
* @param dept 当前部门
|
||||
* @param deptMap 部门映射
|
||||
* @return CuteProductLineSelectProVo 树节点
|
||||
*/
|
||||
private CuteProductLineSelectProVo buildDeptTreePro(SystemDeptTb dept, Map<Long, SystemDeptTb> deptMap) {
|
||||
CuteProductLineSelectProVo vo = new CuteProductLineSelectProVo();
|
||||
vo.setValue(String.valueOf(dept.getId()));
|
||||
vo.setLabel(dept.getName());
|
||||
// 查找子部门
|
||||
List<CuteProductLineSelectProVo> children = new ArrayList<>();
|
||||
for (SystemDeptTb childDept : deptMap.values()) {
|
||||
if (dept.getId().equals(childDept.getPid())) {
|
||||
children.add(this.buildDeptTreePro(childDept, deptMap));
|
||||
}
|
||||
}
|
||||
// 子部门按排序字段排序
|
||||
children.sort(Comparator.comparingInt(o -> {
|
||||
Long id = Long.valueOf(o.getValue());
|
||||
return deptMap.get(id) != null ? deptMap.get(id).getDeptSort() : 0;
|
||||
}));
|
||||
vo.setChildren(children);
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package cn.odboy.system.application.service;
|
||||
|
||||
import cn.odboy.system.dal.dataobject.SystemDeptTb;
|
||||
import cn.odboy.system.application.model.CuteProductLineSelectVo;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class CuteProductLineSelectService extends CuteBaseService {
|
||||
|
||||
/**
|
||||
* 产品线选择组件 数据源
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
public List<CuteProductLineSelectVo> listMetadata() {
|
||||
List<SystemDeptTb> depts = this.listEnabledDept();
|
||||
return this.buildDeptMetadata(depts);
|
||||
}
|
||||
|
||||
private List<CuteProductLineSelectVo> buildDeptMetadata(List<SystemDeptTb> depts) {
|
||||
// 查询所有部门并按父子关系组织
|
||||
Map<Long, SystemDeptTb> deptMap =
|
||||
depts.stream().collect(Collectors.toMap(SystemDeptTb::getId, Function.identity()));
|
||||
List<CuteProductLineSelectVo> options = new ArrayList<>();
|
||||
for (SystemDeptTb dept : depts) {
|
||||
// 构建部门ID路径
|
||||
List<Long> pathIds = new ArrayList<>();
|
||||
this.buildDeptIdPath(dept, deptMap, pathIds);
|
||||
// 反转路径,从顶级部门到当前部门
|
||||
Collections.reverse(pathIds);
|
||||
CuteProductLineSelectVo dto = new CuteProductLineSelectVo();
|
||||
dto.setValue(dept.getId());
|
||||
dto.setIdPath(pathIds.stream().map(String::valueOf).collect(Collectors.joining("-")));
|
||||
// 保留名称路径用于显示
|
||||
dto.setLabel(this.buildNamePath(dept, deptMap));
|
||||
options.add(dto);
|
||||
}
|
||||
// 按部门名称路径排序
|
||||
options.sort(Comparator.comparing(CuteProductLineSelectVo::getLabel));
|
||||
return options;
|
||||
}
|
||||
|
||||
private void buildDeptIdPath(SystemDeptTb dept, Map<Long, SystemDeptTb> deptMap, List<Long> pathIds) {
|
||||
pathIds.add(dept.getId());
|
||||
if (dept.getPid() != null && dept.getPid() != 0 && deptMap.containsKey(dept.getPid())) {
|
||||
this.buildDeptIdPath(deptMap.get(dept.getPid()), deptMap, pathIds);
|
||||
}
|
||||
}
|
||||
|
||||
private String buildNamePath(SystemDeptTb dept, Map<Long, SystemDeptTb> deptMap) {
|
||||
List<String> pathNames = new ArrayList<>();
|
||||
this.buildDeptNamePath(dept, deptMap, pathNames);
|
||||
Collections.reverse(pathNames);
|
||||
return String.join(" / ", pathNames);
|
||||
}
|
||||
|
||||
private void buildDeptNamePath(SystemDeptTb dept, Map<Long, SystemDeptTb> deptMap, List<String> pathNames) {
|
||||
pathNames.add(dept.getName());
|
||||
if (dept.getPid() != null && dept.getPid() != 0 && deptMap.containsKey(dept.getPid())) {
|
||||
this.buildDeptNamePath(deptMap.get(dept.getPid()), deptMap, pathNames);
|
||||
}
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package cn.odboy.system.application.service;
|
||||
|
||||
import cn.odboy.system.application.model.CuteUserSelectVo;
|
||||
import cn.odboy.system.dal.dataobject.SystemUserTb;
|
||||
import cn.odboy.system.dal.model.request.SystemQueryUserArgs;
|
||||
import cn.odboy.system.dal.mysql.SystemUserMapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CuteUserSelectService {
|
||||
|
||||
@Autowired
|
||||
private SystemUserMapper systemUserMapper;
|
||||
|
||||
/**
|
||||
* 模糊查询用户基础信息,限制返回的条数
|
||||
*
|
||||
* @param args 查询参数
|
||||
* @return /
|
||||
*/
|
||||
public List<CuteUserSelectVo> listMetadata(SystemQueryUserArgs args) {
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.select(SystemUserTb::getUsername, SystemUserTb::getNickName, SystemUserTb::getDeptId, SystemUserTb::getEmail, SystemUserTb::getPhone);
|
||||
wrapper.and(c -> {
|
||||
c.eq(SystemUserTb::getPhone, args.getBlurry());
|
||||
c.or();
|
||||
c.eq(SystemUserTb::getEmail, args.getBlurry());
|
||||
c.or();
|
||||
c.like(SystemUserTb::getUsername, args.getBlurry());
|
||||
c.or();
|
||||
c.like(SystemUserTb::getNickName, args.getBlurry());
|
||||
});
|
||||
return systemUserMapper.selectPage(new Page<>(1, 50), wrapper).convert(m -> {
|
||||
CuteUserSelectVo selectVo = new CuteUserSelectVo();
|
||||
selectVo.setValue(m.getUsername());
|
||||
selectVo.setLabel(m.getNickName());
|
||||
selectVo.setDeptId(Long.toString(m.getDeptId()));
|
||||
selectVo.setEmail(m.getEmail());
|
||||
selectVo.setPhone(m.getPhone());
|
||||
return selectVo;
|
||||
}).getRecords();
|
||||
}
|
||||
}
|
||||
-7
@@ -141,13 +141,6 @@ public class SystemUserController {
|
||||
return ResponseEntity.ok(null);
|
||||
}
|
||||
|
||||
@ApiOperation("查询用户基础数据")
|
||||
@PostMapping(value = "/queryUserMetadataOptions")
|
||||
@PreAuthorize("@el.check('user:list')")
|
||||
public ResponseEntity<List<KitSelectOptionVo>> queryUserMetadataOptions(@Validated @RequestBody KitPageArgs<SystemQueryUserArgs> args) {
|
||||
List<KitSelectOptionVo> collect = systemUserService.queryUserMetadataOptions(args);
|
||||
return ResponseEntity.ok(collect);
|
||||
}
|
||||
|
||||
@ApiOperation("获取用户信息")
|
||||
@PostMapping(value = "/getCurrentUserInfo")
|
||||
|
||||
-139
@@ -27,8 +27,6 @@ import cn.odboy.system.dal.model.export.SystemDeptExportRowVo;
|
||||
import cn.odboy.system.dal.model.request.SystemCreateDeptArgs;
|
||||
import cn.odboy.system.dal.model.request.SystemQueryDeptArgs;
|
||||
import cn.odboy.system.dal.model.response.SystemDeptVo;
|
||||
import cn.odboy.system.dal.model.response.SystemProductLineTreeVo;
|
||||
import cn.odboy.system.dal.model.response.SystemProductLineVo;
|
||||
import cn.odboy.system.dal.mysql.SystemDeptMapper;
|
||||
import cn.odboy.system.framework.permission.core.KitSecurityHelper;
|
||||
import cn.odboy.util.KitBeanUtil;
|
||||
@@ -42,14 +40,11 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@@ -293,43 +288,6 @@ public class SystemDeptService {
|
||||
return depts;
|
||||
}
|
||||
|
||||
/**
|
||||
* 产品线选择组件 数据源
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
public List<SystemProductLineVo> listDeptSelectDataSource() {
|
||||
List<SystemDeptTb> depts = this.listEnabledDepts();
|
||||
return this.buildDeptSelectOptions(depts);
|
||||
}
|
||||
|
||||
/**
|
||||
* 产品线选择组件Pro版 数据源
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
public List<SystemProductLineTreeVo> listDeptSelectProDataSource() {
|
||||
List<SystemDeptTb> depts = this.listEnabledDepts();
|
||||
// 查询所有部门并按父子关系组织
|
||||
Map<Long, SystemDeptTb> deptMap =
|
||||
depts.stream().collect(Collectors.toMap(SystemDeptTb::getId, Function.identity()));
|
||||
List<SystemProductLineTreeVo> options = new ArrayList<>();
|
||||
// 构建树形结构
|
||||
for (SystemDeptTb dept : depts) {
|
||||
// 只处理顶级部门(pid为null或0的部门)
|
||||
if (dept.getPid() == null || dept.getPid() == 0) {
|
||||
SystemProductLineTreeVo vo = this.buildDeptTreePro(dept, deptMap);
|
||||
options.add(vo);
|
||||
}
|
||||
}
|
||||
// 按排序字段排序
|
||||
options.sort(Comparator.comparingInt(o -> {
|
||||
Long id = Long.valueOf(o.getValue());
|
||||
return deptMap.get(id) != null ? deptMap.get(id).getDeptSort() : 0;
|
||||
}));
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据父部门id查询部门集合
|
||||
*
|
||||
@@ -373,103 +331,6 @@ public class SystemDeptService {
|
||||
return systemDeptMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归构建部门树
|
||||
*
|
||||
* @param dept 当前部门
|
||||
* @param deptMap 部门映射
|
||||
* @return SystemProductLineTreeVo 树节点
|
||||
*/
|
||||
private SystemProductLineTreeVo buildDeptTreePro(SystemDeptTb dept, Map<Long, SystemDeptTb> deptMap) {
|
||||
SystemProductLineTreeVo vo = new SystemProductLineTreeVo();
|
||||
vo.setValue(String.valueOf(dept.getId()));
|
||||
vo.setLabel(dept.getName());
|
||||
// 查找子部门
|
||||
List<SystemProductLineTreeVo> children = new ArrayList<>();
|
||||
for (SystemDeptTb childDept : deptMap.values()) {
|
||||
if (dept.getId().equals(childDept.getPid())) {
|
||||
children.add(this.buildDeptTreePro(childDept, deptMap));
|
||||
}
|
||||
}
|
||||
// 子部门按排序字段排序
|
||||
children.sort(Comparator.comparingInt(o -> {
|
||||
Long id = Long.valueOf(o.getValue());
|
||||
return deptMap.get(id) != null ? deptMap.get(id).getDeptSort() : 0;
|
||||
}));
|
||||
vo.setChildren(children);
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 产品线选择组件使用
|
||||
*
|
||||
* @param depts 部门集合
|
||||
* @return /
|
||||
*/
|
||||
private List<SystemProductLineVo> buildDeptSelectOptions(List<SystemDeptTb> depts) {
|
||||
// 查询所有部门并按父子关系组织
|
||||
Map<Long, SystemDeptTb> deptMap =
|
||||
depts.stream().collect(Collectors.toMap(SystemDeptTb::getId, Function.identity()));
|
||||
List<SystemProductLineVo> options = new ArrayList<>();
|
||||
for (SystemDeptTb dept : depts) {
|
||||
// 构建部门ID路径
|
||||
List<Long> pathIds = new ArrayList<>();
|
||||
this.buildDeptIdPath(dept, deptMap, pathIds);
|
||||
// 反转路径,从顶级部门到当前部门
|
||||
Collections.reverse(pathIds);
|
||||
SystemProductLineVo dto = new SystemProductLineVo();
|
||||
dto.setValue(dept.getId());
|
||||
dto.setIdPath(pathIds.stream().map(String::valueOf).collect(Collectors.joining("-")));
|
||||
// 保留名称路径用于显示
|
||||
dto.setLabel(this.buildNamePath(dept, deptMap));
|
||||
options.add(dto);
|
||||
}
|
||||
// 按部门名称路径排序
|
||||
options.sort(Comparator.comparing(SystemProductLineVo::getLabel));
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* 产品线选择组件使用
|
||||
*/
|
||||
private void buildDeptIdPath(SystemDeptTb dept, Map<Long, SystemDeptTb> deptMap, List<Long> pathIds) {
|
||||
pathIds.add(dept.getId());
|
||||
if (dept.getPid() != null && dept.getPid() != 0 && deptMap.containsKey(dept.getPid())) {
|
||||
this.buildDeptIdPath(deptMap.get(dept.getPid()), deptMap, pathIds);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 产品线选择组件使用
|
||||
*/
|
||||
private String buildNamePath(SystemDeptTb dept, Map<Long, SystemDeptTb> deptMap) {
|
||||
List<String> pathNames = new ArrayList<>();
|
||||
this.buildDeptNamePath(dept, deptMap, pathNames);
|
||||
Collections.reverse(pathNames);
|
||||
return String.join(" / ", pathNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* 产品线选择组件使用
|
||||
*/
|
||||
private void buildDeptNamePath(SystemDeptTb dept, Map<Long, SystemDeptTb> deptMap, List<String> pathNames) {
|
||||
pathNames.add(dept.getName());
|
||||
if (dept.getPid() != null && dept.getPid() != 0 && deptMap.containsKey(dept.getPid())) {
|
||||
this.buildDeptNamePath(deptMap.get(dept.getPid()), deptMap, pathNames);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询启用的所有部门集合
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
private List<SystemDeptTb> listEnabledDepts() {
|
||||
LambdaQueryWrapper<SystemDeptTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemDeptTb::getEnabled, 1);
|
||||
return systemDeptMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询部门下所有关联的部门
|
||||
*
|
||||
|
||||
-36
@@ -196,40 +196,4 @@ public class SystemLocalStorageService {
|
||||
}
|
||||
wrapper.orderByDesc(SystemLocalStorageTb::getId);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String uploadLocal(MultipartFile multipartFile) {
|
||||
long size = multipartFile.getSize();
|
||||
KitFileUtil.checkSize(properties.getOss().getMaxSize(), size);
|
||||
String suffix = KitFileUtil.getSuffix(multipartFile.getOriginalFilename());
|
||||
String type = KitFileUtil.getFileType(suffix);
|
||||
String uploadDateStr = DateUtil.format(new Date(), DatePattern.PURE_DATE_FORMAT);
|
||||
File file = KitFileUtil.upload(multipartFile, fileUploadPathHelper.getPath() + uploadDateStr + File.separator);
|
||||
if (file == null) {
|
||||
throw new BadRequestException("上传失败");
|
||||
}
|
||||
try {
|
||||
String formatSize = KitFileUtil.getSize(size);
|
||||
String prefixName = KitFileUtil.getPrefix(multipartFile.getOriginalFilename(), null);
|
||||
SystemLocalStorageTb localStorage = new SystemLocalStorageTb();
|
||||
localStorage.setRealName(file.getName());
|
||||
localStorage.setName(prefixName);
|
||||
localStorage.setSuffix(suffix);
|
||||
localStorage.setPath(file.getPath());
|
||||
localStorage.setType(type);
|
||||
localStorage.setSize(formatSize);
|
||||
localStorage.setDateGroup(uploadDateStr);
|
||||
systemLocalStorageMapper.insert(localStorage);
|
||||
// 构建上传路径 /file/20260117/odboycn-20260117055246428.png
|
||||
HttpServletRequest httpServletRequest = KitRequestHolder.getHttpServletRequest();
|
||||
StringBuffer requestURL = httpServletRequest.getRequestURL();
|
||||
String[] splits = requestURL.toString().split("/api/component/CuteFileUpload");
|
||||
String requestAddress = splits[0];
|
||||
return String.format("%s/file/%s/%s", requestAddress, uploadDateStr, localStorage.getRealName());
|
||||
} catch (Exception e) {
|
||||
log.error("上传文件失败", e);
|
||||
KitFileUtil.del(file);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-31
@@ -17,7 +17,6 @@ package cn.odboy.system.service;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.odboy.base.KitPageArgs;
|
||||
import cn.odboy.base.KitPageResult;
|
||||
import cn.odboy.base.KitSelectOptionVo;
|
||||
import cn.odboy.framework.exception.BadRequestException;
|
||||
@@ -333,36 +332,6 @@ public class SystemUserService {
|
||||
return systemUserMapper.selectCount(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 模糊查询用户基础信息,限制返回的条数
|
||||
*
|
||||
* @param pageArgs 分页参数
|
||||
* @return /
|
||||
*/
|
||||
public List<KitSelectOptionVo> queryUserMetadataOptions(KitPageArgs<SystemQueryUserArgs> pageArgs) {
|
||||
SystemQueryUserArgs args = pageArgs.getArgs();
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.select(
|
||||
SystemUserTb::getId, SystemUserTb::getUsername, SystemUserTb::getNickName, SystemUserTb::getDeptId, SystemUserTb::getEmail, SystemUserTb::getPhone);
|
||||
wrapper.and(c -> {
|
||||
c.eq(SystemUserTb::getPhone, args.getBlurry());
|
||||
c.or();
|
||||
c.eq(SystemUserTb::getEmail, args.getBlurry());
|
||||
c.or();
|
||||
c.like(SystemUserTb::getUsername, args.getBlurry());
|
||||
c.or();
|
||||
c.like(SystemUserTb::getNickName, args.getBlurry());
|
||||
});
|
||||
return systemUserMapper.selectPage(new Page<>(pageArgs.getPage(), 50), wrapper).getRecords().stream().map(m -> {
|
||||
Map<String, Object> ext = new HashMap<>(1);
|
||||
ext.put("id", m.getId());
|
||||
ext.put("deptId", m.getDeptId());
|
||||
ext.put("email", m.getEmail());
|
||||
ext.put("phone", m.getPhone());
|
||||
return KitSelectOptionVo.builder().label(m.getNickName()).value(String.valueOf(m.getId())).ext(ext).build();
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户名查询启用的用户信息
|
||||
*
|
||||
@@ -592,4 +561,5 @@ public class SystemUserService {
|
||||
userVo.setRoles(systemUserRoleService.listUserRoleByUserId(user.getId()));
|
||||
return userVo;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user