feat(frontend): unify attachment management spec and implement fetch+blob download\n\n- Implement forced download via fetch blob, delayed delete etc in repairOrder module\n- Add Attachment Management Unified Standard doctrine to cursorrules-frontend.md so future pages keep consistency\n- Update change log for download preview fix

This commit is contained in:
zlwu committed 2025-07-11 06:36:45 +08:00
1 parent 1540bd1a1b
commit 4ef2208a0c
11 files changed
+1318 -108

No files matched your search

+49 -31
View File
@@ -77,7 +77,7 @@ show_help() {
# 检查环境
check_environment() {
echo -e "${BLUE}🔍 检查运行环境...${NC}"
# 检查Java版本
if command -v java &> /dev/null; then
JAVA_VERSION=$(java -version 2>&1 | head -n 1 | cut -d'"' -f2)
@@ -86,7 +86,7 @@ check_environment() {
echo -e " ❌ ${RED}未找到Java环境${NC}"
return 1
fi
# 检查Maven版本
if command -v mvn &> /dev/null; then
MVN_VERSION=$(mvn -version 2>/dev/null | head -n 1 | cut -d' ' -f3)
@@ -95,7 +95,7 @@ check_environment() {
echo -e " ❌ ${RED}未找到Maven环境${NC}"
return 1
fi
# 检查目标模块
if [ -d "$DEFAULT_MODULE" ]; then
echo -e " ✅ 目标模块: ${GREEN}$DEFAULT_MODULE${NC}"
@@ -103,14 +103,14 @@ check_environment() {
echo -e " ❌ ${RED}未找到目标模块: $DEFAULT_MODULE${NC}"
return 1
fi
# 检查热加载配置
if grep -q "spring-boot-devtools" $DEFAULT_MODULE/pom.xml; then
echo -e " ✅ 热加载配置: ${GREEN}已启用${NC}"
else
echo -e " ⚠️ 热加载配置: ${YELLOW}未配置${NC}"
fi
# 检查配置文件
CONFIG_FILE="$DEFAULT_MODULE/src/main/resources/application-$DEFAULT_PROFILE.yml"
if [ -f "$CONFIG_FILE" ]; then
@@ -119,7 +119,7 @@ check_environment() {
echo -e " ❌ ${RED}未找到配置文件: $CONFIG_FILE${NC}"
return 1
fi
echo -e "${GREEN}✅ 环境检查完成${NC}"
return 0
}
@@ -164,13 +164,27 @@ clean_build() {
# 构建项目
build_project() {
echo -e "${BLUE}🔨 编译项目...${NC}"
echo -e "${BLUE}🔨 编译并打包项目...${NC}"
cd $DEFAULT_MODULE
mvn compile -q
mvn clean package -q
if [ $? -eq 0 ]; then
echo -e "${GREEN}✅ 编译完成${NC}"
echo -e "${GREEN}✅ 编译打包完成${NC}"
else
echo -e "${RED}❌ 编译失败${NC}"
echo -e "${RED}❌ 编译打包失败${NC}"
exit 1
fi
cd ..
}
# 新增:构建 ruoyi-modules
build_ruoyi_modules() {
echo -e "${BLUE}🔨 开始编译并打包 ruoyi-modules...${NC}"
cd ruoyi-modules
mvn clean install -q
if [ $? -eq 0 ]; then
echo -e "${GREEN}✅ ruoyi-modules 编译打包完成${NC}"
else
echo -e "${RED}❌ ruoyi-modules 编译打包失败${NC}"
exit 1
fi
cd ..
@@ -183,7 +197,7 @@ start_application() {
local debug_mode=$3
local hot_reload=$4
local jvm_opts=$5
echo -e "${BLUE}🚀 启动应用...${NC}"
echo -e "${CYAN}配置信息:${NC}"
echo -e " 📂 模块: ${GREEN}$DEFAULT_MODULE${NC}"
@@ -192,42 +206,42 @@ start_application() {
echo -e " 🔥 热加载: ${GREEN}$([ "$hot_reload" = "true" ] && echo "启用" || echo "禁用")${NC}"
echo -e " 🐛 调试模式: ${GREEN}$([ "$debug_mode" = "true" ] && echo "启用" || echo "禁用")${NC}"
echo ""
cd $DEFAULT_MODULE
# 构建Maven命令
MVN_CMD="mvn spring-boot:run"
# 添加环境配置
MVN_CMD="$MVN_CMD -Dspring-boot.run.profiles=$profile"
# 添加端口配置
if [ "$port" != "$DEFAULT_PORT" ]; then
MVN_CMD="$MVN_CMD -Dspring-boot.run.arguments=--server.port=$port"
fi
# 添加JVM参数
if [ -n "$jvm_opts" ]; then
MVN_CMD="$MVN_CMD -Dspring-boot.run.jvmArguments=\"$jvm_opts\""
else
MVN_CMD="$MVN_CMD -Dspring-boot.run.jvmArguments=\"$MAVEN_OPTS\""
fi
# 调试模式
if [ "$debug_mode" = "true" ]; then
MVN_CMD="$MVN_CMD -Dspring-boot.run.jvmArguments=\"$MAVEN_OPTS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005\""
echo -e "${PURPLE}🐛 调试端口: 5005${NC}"
fi
# 禁用热加载
if [ "$hot_reload" = "false" ]; then
MVN_CMD="$MVN_CMD -Dspring.devtools.restart.enabled=false"
fi
echo -e "${CYAN}执行命令: ${WHITE}$MVN_CMD${NC}"
echo -e "${GREEN}==================== 应用启动日志 ====================${NC}"
echo ""
# 执行命令
eval $MVN_CMD
}
@@ -243,7 +257,7 @@ main() {
HOT_RELOAD=true
JVM_OPTS=""
CHECK_ONLY=false
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
@@ -294,37 +308,41 @@ main() {
;;
esac
done
# 显示Logo
show_logo
# 仅检查环境
if [ "$CHECK_ONLY" = "true" ]; then
check_environment
exit $?
fi
# 环境检查
if ! check_environment; then
echo -e "${RED}❌ 环境检查失败,请检查配置${NC}"
exit 1
fi
echo ""
# 端口检查
check_port $PORT
# 清理编译
if [ "$CLEAN_BUILD" = "true" ]; then
clean_build
echo ""
fi
# 编译项目
# 先编译打包 ruoyi-modules
build_ruoyi_modules
echo ""
# 再编译打包 ruoyi-admin
build_project
echo ""
# 启动应用
start_application "$PROFILE" "$PORT" "$DEBUG_MODE" "$HOT_RELOAD" "$JVM_OPTS"
}
@@ -333,4 +351,4 @@ main() {
trap 'echo -e "\n${YELLOW}⚠️ 应用启动已中断${NC}"; exit 1' INT TERM
# 执行主函数
main "$@"
main "$@"
@@ -107,7 +107,7 @@ public class HqPmRepairAttachmentController extends BaseController {
@Log(title = "上传报修附件", businessType = BusinessType.INSERT)
@PostMapping("/upload")
public R<HqPmRepairAttachmentVo> uploadFile(
@RequestParam("orderId") Long orderId,
@RequestParam(value = "orderId", required = false) Long orderId,
@RequestParam(value = "uploadStage", defaultValue = "1") String uploadStage,
@RequestParam("file") MultipartFile file,
@RequestParam(value = "description", required = false) String description) {
@@ -183,4 +183,56 @@ public class HqPmRepairAttachmentController extends BaseController {
}
}
/**
* 更新附件的工单ID(用于新增工单时关联已上传的附件)
*/
// @SaCheckPermission("pm:attachment:edit")
@Log(title = "更新附件工单ID", businessType = BusinessType.UPDATE)
@PutMapping("/{attachmentId}/order/{orderId}")
public R<Void> updateAttachmentOrderId(@PathVariable("attachmentId") Long attachmentId,
@PathVariable("orderId") Long orderId) {
return toAjax(attachmentService.updateAttachmentOrderId(attachmentId, orderId));
}
/**
* 批量更新附件的工单ID(用于新增工单时关联已上传的附件)
*/
// @SaCheckPermission("pm:attachment:edit")
@Log(title = "批量更新附件工单ID", businessType = BusinessType.UPDATE)
@PutMapping("/batch-update-order")
public R<Void> batchUpdateAttachmentOrderId(@RequestBody BatchUpdateOrderIdRequest request) {
if (request.getAttachmentIds() == null || request.getAttachmentIds().isEmpty()) {
return R.fail("附件ID列表不能为空");
}
if (request.getOrderId() == null) {
return R.fail("工单ID不能为空");
}
return toAjax(attachmentService.batchUpdateAttachmentOrderId(request.getAttachmentIds(), request.getOrderId()));
}
/**
* 批量更新附件工单ID的请求参数
*/
public static class BatchUpdateOrderIdRequest {
private List<Long> attachmentIds;
private Long orderId;
public List<Long> getAttachmentIds() {
return attachmentIds;
}
public void setAttachmentIds(List<Long> attachmentIds) {
this.attachmentIds = attachmentIds;
}
public Long getOrderId() {
return orderId;
}
public void setOrderId(Long orderId) {
this.orderId = orderId;
}
}
}
@@ -73,4 +73,14 @@ public interface IHqPmRepairAttachmentService {
*/
void updateOrderAttachmentCount(Long orderId);
/**
* 更新附件的工单ID(用于新增工单时关联已上传的附件)
*/
Boolean updateAttachmentOrderId(Long attachmentId, Long orderId);
/**
* 批量更新附件的工单ID(用于新增工单时关联已上传的附件)
*/
Boolean batchUpdateAttachmentOrderId(List<Long> attachmentIds, Long orderId);
}
@@ -303,6 +303,99 @@ public class HqPmRepairAttachmentServiceImpl implements IHqPmRepairAttachmentSer
repairOrderMapper.update(null, updateWrapper);
}
/**
* 更新附件的工单ID(用于新增工单时关联已上传的附件)
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean updateAttachmentOrderId(Long attachmentId, Long orderId) {
if (attachmentId == null || orderId == null) {
log.warn("更新附件工单ID参数不能为空: attachmentId={}, orderId={}", attachmentId, orderId);
return false;
}
// 检查附件是否存在
HqPmRepairAttachmentVo attachment = queryById(attachmentId);
if (attachment == null) {
log.warn("附件不存在: attachmentId={}", attachmentId);
return false;
}
// 更新附件的工单ID
LambdaUpdateWrapper<HqPmRepairAttachment> updateWrapper = Wrappers.lambdaUpdate();
updateWrapper.eq(HqPmRepairAttachment::getId, attachmentId)
.set(HqPmRepairAttachment::getOrderId, orderId);
boolean success = baseMapper.update(null, updateWrapper) > 0;
if (success) {
log.info("成功更新附件工单ID: attachmentId={}, orderId={}", attachmentId, orderId);
// 更新工单的附件数量
updateOrderAttachmentCount(orderId);
// 如果原来有工单ID,也需要更新原工单的附件数量
if (attachment.getOrderId() != null && !attachment.getOrderId().equals(orderId)) {
updateOrderAttachmentCount(attachment.getOrderId());
}
} else {
log.error("更新附件工单ID失败: attachmentId={}, orderId={}", attachmentId, orderId);
}
return success;
}
/**
* 批量更新附件的工单ID(用于新增工单时关联已上传的附件)
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean batchUpdateAttachmentOrderId(List<Long> attachmentIds, Long orderId) {
if (attachmentIds == null || attachmentIds.isEmpty() || orderId == null) {
log.warn("批量更新附件工单ID参数不能为空: attachmentIds={}, orderId={}", attachmentIds, orderId);
return false;
}
try {
// 获取要更新的附件列表(在更新前)
List<HqPmRepairAttachmentVo> existingAttachments = new ArrayList<>();
for (Long attachmentId : attachmentIds) {
HqPmRepairAttachmentVo attachment = queryById(attachmentId);
if (attachment != null) {
existingAttachments.add(attachment);
}
}
// 批量更新附件的工单ID
LambdaUpdateWrapper<HqPmRepairAttachment> updateWrapper = Wrappers.lambdaUpdate();
updateWrapper.in(HqPmRepairAttachment::getId, attachmentIds)
.set(HqPmRepairAttachment::getOrderId, orderId);
boolean success = baseMapper.update(null, updateWrapper) > 0;
if (success) {
log.info("成功批量更新附件工单ID: attachmentIds={}, orderId={}, count={}",
attachmentIds, orderId, attachmentIds.size());
// 更新新工单的附件数量
updateOrderAttachmentCount(orderId);
// 更新原来有工单ID的附件所属工单的数量
existingAttachments.stream()
.map(HqPmRepairAttachmentVo::getOrderId)
.filter(oldOrderId -> oldOrderId != null && !oldOrderId.equals(orderId))
.distinct()
.forEach(this::updateOrderAttachmentCount);
} else {
log.error("批量更新附件工单ID失败: attachmentIds={}, orderId={}", attachmentIds, orderId);
}
return success;
} catch (Exception e) {
log.error("批量更新附件工单ID异常: attachmentIds={}, orderId={}, error={}",
attachmentIds, orderId, e.getMessage(), e);
throw e;
}
}
/**
* 根据MIME类型获取文件类型
*/
@@ -29,6 +29,7 @@ import org.dromara.common.core.service.UserService;
import java.util.List;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
/**
* 报修工单Service业务层处理
@@ -140,7 +141,14 @@ public class HqPmRepairOrderServiceImpl implements IHqPmRepairOrderService {
private LambdaQueryWrapper<HqPmRepairOrder> buildQueryWrapper(HqPmRepairOrderBo bo) {
LambdaQueryWrapper<HqPmRepairOrder> lqw = Wrappers.lambdaQuery();
lqw.orderByDesc(HqPmRepairOrder::getCreateTime);
lqw.eq(StringUtils.isNotBlank(bo.getOrderNo()), HqPmRepairOrder::getOrderNo, bo.getOrderNo());
// 使用 LIKE 进行模糊匹配,支持输入部分工单编号
lqw.like(StringUtils.isNotBlank(bo.getOrderNo()), HqPmRepairOrder::getOrderNo, bo.getOrderNo());
// 处理创建时间范围过滤条件
Map<String, Object> params = bo.getParams();
lqw.between(params != null && params.get("beginCreateTime") != null && params.get("endCreateTime") != null,
HqPmRepairOrder::getCreateTime,
params.get("beginCreateTime"),
params.get("endCreateTime"));
lqw.like(StringUtils.isNotBlank(bo.getTitle()), HqPmRepairOrder::getTitle, bo.getTitle());
lqw.like(StringUtils.isNotBlank(bo.getDescription()), HqPmRepairOrder::getDescription, bo.getDescription());
lqw.like(StringUtils.isNotBlank(bo.getRepairLocation()), HqPmRepairOrder::getRepairLocation,
+92
View File
@@ -0,0 +1,92 @@
#!/bin/bash
# =============================================================================
# 一键启动脚本 (顺序: 监控中心 → 定时任务 → 主业务)
# 功能: 依次启动 start-monitor.sh、start-job.sh、hot-start.sh
# 位置: backend/start-all.sh
# 作者: zlwu
# 时间: 2025-07-10
# =============================================================================
set -e
# -------------- 编码设置 -----------------------------------------------------
export LANG=zh_CN.UTF-8
export LC_ALL=zh_CN.UTF-8
# 确保 Java 与 Maven 进程使用 UTF-8 编码
export JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 $JAVA_TOOL_OPTIONS"
export MAVEN_OPTS="-Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 $MAVEN_OPTS"
# -------------- 配置区 -------------------------------------------------------
MONITOR_SCRIPT="./start-monitor.sh" # 监控中心启动脚本
MONITOR_PORT=9090 # 监控中心端口
JOB_SCRIPT="./start-job.sh" # 定时任务启动脚本
JOB_PORT=8800 # 定时任务端口
MAIN_SCRIPT="./hot-start.sh" # 主业务启动脚本
# -------------- 辅助函数 -----------------------------------------------------
COLOR_GREEN='\033[0;32m'
COLOR_YELLOW='\033[1;33m'
COLOR_RED='\033[0;31m'
COLOR_CYAN='\033[0;36m'
COLOR_RESET='\033[0m'
# 等待端口就绪
wait_for_port() {
local port=$1
local name=$2
local retry=0
local max_retry=60 # 最多等待 60 次 (约 120s)
printf "${COLOR_CYAN}⏳ 正在等待 %s (端口 %s) 启动" "$name" "$port"
while ! (command -v nc &>/dev/null && nc -z localhost "$port") 2>/dev/null; do
# 若系统无 nc,则使用 lsof 检测
if ! command -v nc &>/dev/null; then
if lsof -Pi :"$port" -sTCP:LISTEN -t >/dev/null 2>&1; then
break
fi
fi
printf "."
sleep 2
retry=$((retry+1))
if [ $retry -ge $max_retry ]; then
printf "\n${COLOR_RED}❌ 等待 %s 启动超时 (端口 %s 未就绪)${COLOR_RESET}\n" "$name" "$port"
exit 1
fi
done
printf "\n${COLOR_GREEN}✅ %s 已启动${COLOR_RESET}\n" "$name"
}
# 启动脚本并后台运行
start_in_background() {
local script=$1
local log_file=$2
bash "$script" > "$log_file" 2>&1 &
echo $!
}
# 捕获退出信号以清理后台进程
cleanup() {
echo -e "\n${COLOR_YELLOW}⚠️ 检测到退出信号,正在关闭后台服务...${COLOR_RESET}"
[[ -n "$MONITOR_PID" ]] && kill "$MONITOR_PID" 2>/dev/null || true
[[ -n "$JOB_PID" ]] && kill "$JOB_PID" 2>/dev/null || true
exit 0
}
trap cleanup INT TERM
# -------------- 启动流程 -----------------------------------------------------
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
cd "$SCRIPT_DIR"
# 1. 启动监控中心
echo -e "${COLOR_GREEN}🚀 启动监控中心...${COLOR_RESET}"
MONITOR_PID=$(start_in_background "$MONITOR_SCRIPT" "logs/monitor.log")
wait_for_port "$MONITOR_PORT" "监控中心"
# 2. 启动定时任务服务
echo -e "${COLOR_GREEN}🚀 启动定时任务服务...${COLOR_RESET}"
JOB_PID=$(start_in_background "$JOB_SCRIPT" "logs/job.log")
wait_for_port "$JOB_PORT" "定时任务服务"
# 3. 启动主业务 (前台运行,方便查看日志)
echo -e "${COLOR_GREEN}🚀 启动主业务服务...${COLOR_RESET}"
exec bash "$MAIN_SCRIPT" "$@"