Compare commits
9
Commits
743f7fec43
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70cfc3d62e | ||
|
|
e7fc38e3a7 | ||
|
|
e93149b534 | ||
|
|
e15e272111 | ||
|
|
2d186a1ca9 | ||
|
|
69e628fc28 | ||
|
|
246462d7b0 | ||
|
|
40bc49a46e | ||
|
|
c70d3e68c2 |
@@ -25,7 +25,10 @@ jobs:
|
|||||||
options: --network infra-infra-net
|
options: --network infra-infra-net
|
||||||
steps:
|
steps:
|
||||||
- name: 安装 git / curl(alpine)
|
- name: 安装 git / curl(alpine)
|
||||||
run: apk add --no-cache git curl
|
run: |
|
||||||
|
# 统一走 aliyun 源:dl-cdn 时段性被拦会卡满 60s×2(2026-10-20 事故)
|
||||||
|
sed -i 's#dl-cdn.alpinelinux.org#mirrors.aliyun.com#g' /etc/apk/repositories
|
||||||
|
apk add --no-cache git curl
|
||||||
|
|
||||||
# 内网 Gitea 无法访问 GitHub 拉 actions/checkout,手动 clone 本仓库
|
# 内网 Gitea 无法访问 GitHub 拉 actions/checkout,手动 clone 本仓库
|
||||||
- name: 拉取源码(内网无 GitHub,手动 clone 本仓库)
|
- name: 拉取源码(内网无 GitHub,手动 clone 本仓库)
|
||||||
@@ -55,18 +58,24 @@ jobs:
|
|||||||
- name: 构建 jar(maven 容器,复用宿主 m2 缓存)
|
- name: 构建 jar(maven 容器,复用宿主 m2 缓存)
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
docker rm -f mavenbuild 2>/dev/null || true
|
# 构建容器名必须全局唯一:runner 挂的是宿主 docker.sock,容器名在整个 daemon 上共享
|
||||||
docker run -d --name mavenbuild \
|
# 命名空间。固定名会在多仓/多条 workflow 并发时互相 docker rm -f 掉对方正在构建的
|
||||||
|
# 容器,表现为无编译报错的 exit 137(SIGKILL,2026-10-21 实测复现)。
|
||||||
|
# GITHUB_RUN_ID 实例级唯一,再拼时间戳兜底。
|
||||||
|
BUILD_CONTAINER="mavenbuild-${GITHUB_RUN_ID:-0}-$(date +%s)"
|
||||||
|
echo "BUILD_CONTAINER=${BUILD_CONTAINER}"
|
||||||
|
docker rm -f "$BUILD_CONTAINER" 2>/dev/null || true
|
||||||
|
docker run -d --name "$BUILD_CONTAINER" \
|
||||||
--network infra-infra-net \
|
--network infra-infra-net \
|
||||||
-v /opt/docker/projman-m2:/root/.m2 \
|
-v /opt/docker/projman-m2:/root/.m2 \
|
||||||
-w /build maven:3.6.3-jdk-8 sleep 3600
|
-w /build maven:3.6.3-jdk-8 sleep 3600
|
||||||
docker cp "${PWD}/." mavenbuild:/build/
|
docker cp "${PWD}/." "$BUILD_CONTAINER":/build/
|
||||||
docker exec mavenbuild sh -c "printf '%s' '<settings><profiles><profile><id>nexus-repo</id><repositories><repository><id>nexus-internal</id><url>http://nexus:8081/repository/maven-public/</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots></repository></repositories></profile></profiles><activeProfiles><activeProfile>nexus-repo</activeProfile></activeProfiles></settings>' > /root/.m2/settings.xml"
|
docker exec "$BUILD_CONTAINER" sh -c "printf '%s' '<settings><profiles><profile><id>nexus-repo</id><repositories><repository><id>nexus-internal</id><url>http://nexus:8081/repository/maven-public/</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots></repository></repositories></profile></profiles><activeProfiles><activeProfile>nexus-repo</activeProfile></activeProfiles></settings>' > /root/.m2/settings.xml"
|
||||||
docker exec mavenbuild sh -c 'cd /build && mvn -B -DskipTests clean package'
|
docker exec "$BUILD_CONTAINER" sh -c 'cd /build && mvn -B -DskipTests clean package'
|
||||||
docker exec mavenbuild sh -c 'cd /build/target && cp *.jar app.jar'
|
docker exec "$BUILD_CONTAINER" sh -c 'cd /build/target && cp *.jar app.jar'
|
||||||
mkdir -p "${PWD}/target"
|
mkdir -p "${PWD}/target"
|
||||||
docker cp mavenbuild:/build/target/app.jar "${PWD}/target/app.jar"
|
docker cp "$BUILD_CONTAINER":/build/target/app.jar "${PWD}/target/app.jar"
|
||||||
docker rm -f mavenbuild
|
docker rm -f "$BUILD_CONTAINER"
|
||||||
|
|
||||||
- name: 构建并推送镜像
|
- name: 构建并推送镜像
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -106,14 +106,6 @@ public class DormController {
|
|||||||
dormService.setMonitor(roomId, studentId);
|
dormService.setMonitor(roomId, studentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 从 bschclass 学籍导入全校学生到待安排池(幂等),返回新增人数。 */
|
|
||||||
@PostMapping("ImportStudents")
|
|
||||||
public Map<String, Object> importStudents() {
|
|
||||||
Map<String, Object> r = new java.util.LinkedHashMap<>();
|
|
||||||
r.put("added", dormService.importStudentsFromBschclass());
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Map<String, Object> toObj(Map<String, String> src) {
|
private static Map<String, Object> toObj(Map<String, String> src) {
|
||||||
return src.entrySet().stream().collect(java.util.stream.Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
return src.entrySet().stream().collect(java.util.stream.Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,4 @@ public interface IDormService {
|
|||||||
|
|
||||||
/** 楼栋→楼层→房间树(ztree,供发布选房间;对应 base/GetDormTree)。 */
|
/** 楼栋→楼层→房间树(ztree,供发布选房间;对应 base/GetDormTree)。 */
|
||||||
List<Map<String, Object>> dormTree();
|
List<Map<String, Object>> dormTree();
|
||||||
|
|
||||||
/** 从 bschclass 学籍导入全校学生到「待安排池」(roomId=0),幂等;返回新增人数。 */
|
|
||||||
int importStudentsFromBschclass();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.yunhai.dormnotice.service;
|
package com.yunhai.dormnotice.service;
|
||||||
|
|
||||||
import com.yunhai.dormnotice.entity.UpFile;
|
import com.yunhai.dormnotice.entity.UpFile;
|
||||||
import com.yunhai.dormnotice.model.notice.UpFileVo;
|
|
||||||
import com.yunhai.dormnotice.model.notice.UpFileResultVo;
|
import com.yunhai.dormnotice.model.notice.UpFileResultVo;
|
||||||
|
import com.yunhai.dormnotice.model.notice.UpFileVo;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
@@ -83,7 +83,11 @@ public interface IFileService {
|
|||||||
void downloadZipByTopic(String topicType, Integer topicId, String zipName, HttpServletResponse response);
|
void downloadZipByTopic(String topicType, Integer topicId, String zipName, HttpServletResponse response);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 按附件ID集合打包下载为 ZIP(通知 AllFileDown 用:通知存的是 fileIds 逗号串)。
|
* 按附件记录ID列表打包下载为 ZIP。
|
||||||
|
*
|
||||||
|
* @param fileIds 附件记录ID列表
|
||||||
|
* @param zipName 压缩包显示名(自动追加 .zip)
|
||||||
|
* @param response HTTP 响应
|
||||||
*/
|
*/
|
||||||
void downloadZipByIds(List<Integer> fileIds, String zipName, HttpServletResponse response);
|
void downloadZipByIds(List<Integer> fileIds, String zipName, HttpServletResponse response);
|
||||||
|
|
||||||
|
|||||||
@@ -108,34 +108,68 @@ public class DormService implements IDormService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Map<String, Object>> pendingStudents(String keyword, String gender) {
|
public List<Map<String, Object>> pendingStudents(String keyword, String gender) {
|
||||||
// 待安排池:dorm_student 中 roomId=0/null。池空时惰性从 bschclass 学籍导入一次,
|
// 实时在册 − 已在住:从 bschclass 拉最新全校在册学生,排除已安排进房间(roomId>0)的;
|
||||||
// 让「安排入住」有数据源;导入失败(平台不可达等)不影响页面,返回空池。
|
// 已在池(roomId=0)或从未入库的在册生都会出现在此名单。平台不可达时回退到已保存的待安排池。
|
||||||
List<DormStudent> raw = studentRepository.findByRoomIdOrderByIdAsc(0);
|
List<DormStudent> all = studentRepository.findAll();
|
||||||
if (raw.isEmpty()) {
|
Set<Integer> housedIds = new HashSet<>();
|
||||||
try {
|
Map<Integer, DormStudent> savedById = new HashMap<>();
|
||||||
int n = importStudentsFromBschclass();
|
for (DormStudent d : all) {
|
||||||
if (n > 0) {
|
if (d.getStudentId() == null) {
|
||||||
raw = studentRepository.findByRoomIdOrderByIdAsc(0);
|
continue;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
savedById.put(d.getStudentId(), d);
|
||||||
log.warn("[pendingStudents] 从 bschclass 导入学生失败,返回空池: {}", e.getMessage());
|
if (nz(d.getRoomId()) > 0) {
|
||||||
|
housedIds.add(d.getStudentId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<DormStudent> pool = raw.stream()
|
String kw = keyword == null ? "" : keyword.trim();
|
||||||
.filter(s -> !StringUtils.hasText(gender) || gender.equals(s.getGender()))
|
|
||||||
.filter(s -> !StringUtils.hasText(keyword)
|
|
||||||
|| (s.getStudentName() + s.getClassName() + s.getGuardianName()).contains(keyword))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
List<Map<String, Object>> out = new ArrayList<>();
|
List<Map<String, Object>> out = new ArrayList<>();
|
||||||
for (DormStudent s : pool) {
|
Roster roster = fetchRoster();
|
||||||
|
if (roster != null) {
|
||||||
|
for (SchStudentDto s : roster.students) {
|
||||||
|
if (s.getStuId() == null || housedIds.contains(s.getStuId())) {
|
||||||
|
continue; // 排除已在住
|
||||||
|
}
|
||||||
|
DormStudent saved = savedById.get(s.getStuId());
|
||||||
|
String g = saved != null ? saved.getGender() : null;
|
||||||
|
if (StringUtils.hasText(gender) && !gender.equals(g)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String cn = roster.classNames.get(s.getClassId());
|
||||||
|
if (!kw.isEmpty() && !(String.valueOf(s.getStuName()) + cn + (saved != null ? saved.getGuardianName() : "")).contains(kw)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Map<String, Object> m = new LinkedHashMap<>();
|
||||||
|
m.put("studentId", s.getStuId());
|
||||||
|
m.put("studentName", s.getStuName());
|
||||||
|
m.put("gender", g);
|
||||||
|
m.put("className", cn);
|
||||||
|
m.put("guardianName", saved != null ? saved.getGuardianName() : null);
|
||||||
|
m.put("guardianPhone", saved != null ? saved.getGuardianPhone() : null);
|
||||||
|
m.put("sourceDesc", saved != null && saved.getSourceDesc() != null ? saved.getSourceDesc() : "学籍在册未分配床位");
|
||||||
|
out.add(m);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
// 平台不可达:回退到已保存的待安排池(roomId=0)
|
||||||
|
for (DormStudent d : all) {
|
||||||
|
if (nz(d.getRoomId()) != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (StringUtils.hasText(gender) && !gender.equals(d.getGender())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!kw.isEmpty() && !(String.valueOf(d.getStudentName()) + d.getClassName() + d.getGuardianName()).contains(kw)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Map<String, Object> m = new LinkedHashMap<>();
|
Map<String, Object> m = new LinkedHashMap<>();
|
||||||
m.put("studentId", s.getStudentId());
|
m.put("studentId", d.getStudentId());
|
||||||
m.put("studentName", s.getStudentName());
|
m.put("studentName", d.getStudentName());
|
||||||
m.put("gender", s.getGender());
|
m.put("gender", d.getGender());
|
||||||
m.put("className", s.getClassName());
|
m.put("className", d.getClassName());
|
||||||
m.put("guardianName", s.getGuardianName());
|
m.put("guardianName", d.getGuardianName());
|
||||||
m.put("guardianPhone", s.getGuardianPhone());
|
m.put("guardianPhone", d.getGuardianPhone());
|
||||||
m.put("sourceDesc", s.getSourceDesc());
|
m.put("sourceDesc", d.getSourceDesc());
|
||||||
out.add(m);
|
out.add(m);
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
@@ -317,9 +351,31 @@ public class DormService implements IDormService {
|
|||||||
public void assignStudent(Integer roomId, List<Integer> studentIds) {
|
public void assignStudent(Integer roomId, List<Integer> studentIds) {
|
||||||
DormRoom room = roomRepository.findByRoomId(roomId)
|
DormRoom room = roomRepository.findByRoomId(roomId)
|
||||||
.orElseThrow(() -> new BizException(ErrorCode.FORBIDDEN, "房间不存在"));
|
.orElseThrow(() -> new BizException(ErrorCode.FORBIDDEN, "房间不存在"));
|
||||||
|
// 预取在册名单:待安排名单可能含从未入库的在册生,安排时按 roster 补建 dorm_student
|
||||||
|
Roster roster = fetchRoster();
|
||||||
|
Map<Integer, SchStudentDto> rosterById = new HashMap<>();
|
||||||
|
if (roster != null) {
|
||||||
|
for (SchStudentDto s : roster.students) {
|
||||||
|
if (s.getStuId() != null) {
|
||||||
|
rosterById.put(s.getStuId(), s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
for (Integer sid : studentIds) {
|
for (Integer sid : studentIds) {
|
||||||
DormStudent s = studentRepository.findByStudentId(sid)
|
DormStudent s = studentRepository.findByStudentId(sid).orElse(null);
|
||||||
.orElseThrow(() -> new BizException(ErrorCode.FORBIDDEN, "学生不存在:" + sid));
|
if (s == null) {
|
||||||
|
SchStudentDto dto = rosterById.get(sid);
|
||||||
|
if (dto == null) {
|
||||||
|
throw new BizException(ErrorCode.FORBIDDEN, "学生不存在或不在册:" + sid);
|
||||||
|
}
|
||||||
|
s = new DormStudent();
|
||||||
|
s.setStudentId(sid);
|
||||||
|
s.setStudentName(dto.getStuName());
|
||||||
|
s.setClassName(roster.classNames.get(dto.getClassId()));
|
||||||
|
s.setRoomId(0);
|
||||||
|
s.setIsMonitor(false);
|
||||||
|
s.setSchId(UserContext.getSchId());
|
||||||
|
}
|
||||||
if (nz(s.getRoomId()) != 0) {
|
if (nz(s.getRoomId()) != 0) {
|
||||||
throw new BizException(ErrorCode.FORBIDDEN, s.getStudentName() + " 已安排床位");
|
throw new BizException(ErrorCode.FORBIDDEN, s.getStudentName() + " 已安排床位");
|
||||||
}
|
}
|
||||||
@@ -378,54 +434,41 @@ public class DormService implements IDormService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================ bschclass 学籍导入 ============================
|
// ============================ bschclass 学籍(在册名单) ============================
|
||||||
|
|
||||||
@Override
|
private static final class Roster {
|
||||||
@Transactional
|
final List<SchStudentDto> students;
|
||||||
public int importStudentsFromBschclass() {
|
final Map<Integer, String> classNames;
|
||||||
|
Roster(List<SchStudentDto> students, Map<Integer, String> classNames) {
|
||||||
|
this.students = students;
|
||||||
|
this.classNames = classNames;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 拉取本校在册学生 + 班级名映射;无学校上下文/失败/空返回 null(调用方按空处理)。 */
|
||||||
|
private Roster fetchRoster() {
|
||||||
Integer schId = UserContext.getSchId();
|
Integer schId = UserContext.getSchId();
|
||||||
if (schId == null) {
|
if (schId == null) {
|
||||||
throw new BizException(ErrorCode.PARAM_ERROR, "未获取到学校上下文,无法导入学生");
|
return null;
|
||||||
}
|
}
|
||||||
SchInfoDto info = classService.getSchFirst(schId);
|
SchInfoDto info = classService.getSchFirst(schId);
|
||||||
if (info == null || !StringUtils.hasText(info.getSchSerId())) {
|
if (info == null || !StringUtils.hasText(info.getSchSerId())) {
|
||||||
log.warn("[importStudents] schId={} 未取到 bschclass SchSerId", schId);
|
log.warn("[dorm] schId={} 未取到 bschclass SchSerId", schId);
|
||||||
return 0;
|
return null;
|
||||||
}
|
}
|
||||||
String schSerId = info.getSchSerId();
|
List<SchStudentDto> stus = classService.getSchStuList(info.getSchSerId());
|
||||||
List<SchStudentDto> stus = classService.getSchStuList(schSerId);
|
|
||||||
if (stus == null || stus.isEmpty()) {
|
if (stus == null || stus.isEmpty()) {
|
||||||
return 0;
|
return null;
|
||||||
}
|
}
|
||||||
Map<Integer, String> classNames = new HashMap<>();
|
Map<Integer, String> classNames = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
for (SchClassDto c : classService.getSchClassList(schSerId)) {
|
for (SchClassDto c : classService.getSchClassList(info.getSchSerId())) {
|
||||||
classNames.put(c.getClassId(), c.getClassName());
|
classNames.put(c.getClassId(), c.getClassName());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("[importStudents] 取班级名单失败(班级名留空): {}", e.getMessage());
|
log.warn("[dorm] 取班级名单失败(班级名留空): {}", e.getMessage());
|
||||||
}
|
}
|
||||||
int added = 0;
|
return new Roster(stus, classNames);
|
||||||
for (SchStudentDto s : stus) {
|
|
||||||
if (s.getStuId() == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (studentRepository.findByStudentId(s.getStuId()).isPresent()) {
|
|
||||||
continue; // 已存在(在住或已在池)跳过,幂等
|
|
||||||
}
|
|
||||||
DormStudent d = new DormStudent();
|
|
||||||
d.setStudentId(s.getStuId());
|
|
||||||
d.setStudentName(s.getStuName());
|
|
||||||
d.setClassName(classNames.get(s.getClassId()));
|
|
||||||
d.setRoomId(0);
|
|
||||||
d.setIsMonitor(false);
|
|
||||||
d.setSourceDesc("学籍在册未分配床位");
|
|
||||||
d.setSchId(schId);
|
|
||||||
studentRepository.save(d);
|
|
||||||
added++;
|
|
||||||
}
|
|
||||||
log.info("[importStudents] schId={} schSerId={} 学籍 {} 人,新导入待安排 {} 人", schId, schSerId, stus.size(), added);
|
|
||||||
return added;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================ 辅助 ============================
|
// ============================ 辅助 ============================
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.yunhai.dormnotice.service.impl;
|
package com.yunhai.dormnotice.service.impl;
|
||||||
|
|
||||||
import com.yunhai.dormnotice.entity.UpFile;
|
import com.yunhai.dormnotice.entity.UpFile;
|
||||||
import com.yunhai.dormnotice.model.notice.UpFileVo;
|
|
||||||
import com.yunhai.dormnotice.model.notice.UpFileResultVo;
|
import com.yunhai.dormnotice.model.notice.UpFileResultVo;
|
||||||
|
import com.yunhai.dormnotice.model.notice.UpFileVo;
|
||||||
import com.yunhai.dormnotice.repository.UpFileRepository;
|
import com.yunhai.dormnotice.repository.UpFileRepository;
|
||||||
import com.yunhai.dormnotice.service.IFileService;
|
import com.yunhai.dormnotice.service.IFileService;
|
||||||
import com.yunhai.platform.apistd.BizException;
|
import com.yunhai.platform.apistd.BizException;
|
||||||
@@ -18,7 +18,6 @@ import org.springframework.util.StringUtils;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
@@ -26,15 +25,7 @@ import java.net.URLEncoder;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.time.LocalDate;
|
import java.util.*;
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
@@ -43,7 +34,7 @@ import java.util.zip.ZipOutputStream;
|
|||||||
* 文件上传/下载/删除业务实现。
|
* 文件上传/下载/删除业务实现。
|
||||||
* <p>
|
* <p>
|
||||||
* 存储路径规则:{uploadPath}/{appType}/{yyyyMMdd}/{uuid}.{ext}
|
* 存储路径规则:{uploadPath}/{appType}/{yyyyMMdd}/{uuid}.{ext}
|
||||||
* 与 C# UpLoadFile.FileSave 逻辑等价,但去除分片上传和 Office 转 PDF(后续按需补充)。
|
* UpLoadFile.FileSave 逻辑等价,但去除分片上传和 Office 转 PDF(后续按需补充)。
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class FileService implements IFileService {
|
public class FileService implements IFileService {
|
||||||
@@ -53,11 +44,9 @@ public class FileService implements IFileService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UpFileRepository upFileRepository;
|
private UpFileRepository upFileRepository;
|
||||||
|
|
||||||
@Value("${file.upload-path}")
|
@Value("${FILE_PATH}")
|
||||||
private String uploadPath;
|
private String uploadPath;
|
||||||
|
|
||||||
private static final String DEFAULT_APP_TYPE = "dormnotice";
|
|
||||||
|
|
||||||
// ============================ 上传 ============================
|
// ============================ 上传 ============================
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -77,13 +66,10 @@ public class FileService implements IFileService {
|
|||||||
ext = originalName.substring(dotIdx + 1).toLowerCase();
|
ext = originalName.substring(dotIdx + 1).toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构造存储子路径:{appType}/{yyyyMMdd}/{uuid}.{ext}
|
|
||||||
String dateDir = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
|
||||||
String savedName = UUID.randomUUID().toString().replace("-", "") + (ext.isEmpty() ? "" : "." + ext);
|
String savedName = UUID.randomUUID().toString().replace("-", "") + (ext.isEmpty() ? "" : "." + ext);
|
||||||
String relativePath = (appType == null ? DEFAULT_APP_TYPE : appType) + "/" + dateDir + "/" + savedName;
|
|
||||||
|
|
||||||
// 物理写入
|
// 物理写入
|
||||||
Path fullPath = Paths.get(uploadPath, relativePath);
|
Path fullPath = Paths.get(uploadPath, savedName);
|
||||||
try {
|
try {
|
||||||
Files.createDirectories(fullPath.getParent());
|
Files.createDirectories(fullPath.getParent());
|
||||||
file.transferTo(fullPath.toFile());
|
file.transferTo(fullPath.toFile());
|
||||||
@@ -94,10 +80,10 @@ public class FileService implements IFileService {
|
|||||||
|
|
||||||
// 入库
|
// 入库
|
||||||
UpFile entity = new UpFile();
|
UpFile entity = new UpFile();
|
||||||
entity.setTopicType(appType == null ? DEFAULT_APP_TYPE : appType);
|
entity.setTopicType(appType);
|
||||||
entity.setTopicId(topicId);
|
entity.setTopicId(topicId);
|
||||||
entity.setFileTrueName(originalName);
|
entity.setFileTrueName(originalName);
|
||||||
entity.setFileName(relativePath);
|
entity.setFileName(savedName);
|
||||||
entity.setFileSize((int) file.getSize());
|
entity.setFileSize((int) file.getSize());
|
||||||
entity.setFileType(ext);
|
entity.setFileType(ext);
|
||||||
upFileRepository.save(entity);
|
upFileRepository.save(entity);
|
||||||
@@ -125,8 +111,7 @@ public class FileService implements IFileService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UpFileVo> listByTopic(String appType, Integer topicId) {
|
public List<UpFileVo> listByTopic(String appType, Integer topicId) {
|
||||||
String type = appType == null ? DEFAULT_APP_TYPE : appType;
|
return upFileRepository.findByTopicTypeAndTopicId(appType, topicId).stream()
|
||||||
return upFileRepository.findByTopicTypeAndTopicId(type, topicId).stream()
|
|
||||||
.map(this::toVo)
|
.map(this::toVo)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
@@ -279,17 +264,17 @@ public class FileService implements IFileService {
|
|||||||
@Override
|
@Override
|
||||||
public void downloadZipByTopic(String topicType, Integer topicId, String zipName,
|
public void downloadZipByTopic(String topicType, Integer topicId, String zipName,
|
||||||
HttpServletResponse response) {
|
HttpServletResponse response) {
|
||||||
String type = topicType == null ? DEFAULT_APP_TYPE : topicType;
|
List<UpFile> files = upFileRepository.findByTopicTypeAndTopicId(topicType, topicId);
|
||||||
List<UpFile> files = upFileRepository.findByTopicTypeAndTopicId(type, topicId);
|
|
||||||
downloadZip(files, zipName, response);
|
downloadZip(files, zipName, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============================ 按附件ID列表打包下载 ============================
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void downloadZipByIds(List<Integer> fileIds, String zipName, HttpServletResponse response) {
|
public void downloadZipByIds(List<Integer> fileIds, String zipName, HttpServletResponse response) {
|
||||||
if (fileIds == null || fileIds.isEmpty()) {
|
List<UpFile> files = fileIds == null || fileIds.isEmpty()
|
||||||
throw new BizException(ErrorCode.PARAM_ERROR, "无附件可下载");
|
? Collections.emptyList()
|
||||||
}
|
: upFileRepository.findAllById(fileIds);
|
||||||
List<UpFile> files = upFileRepository.findAllById(fileIds);
|
|
||||||
downloadZip(files, zipName, response);
|
downloadZip(files, zipName, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,9 +287,8 @@ public class FileService implements IFileService {
|
|||||||
if (files == null || files.length == 0) {
|
if (files == null || files.length == 0) {
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
String type = appType != null ? appType : DEFAULT_APP_TYPE;
|
|
||||||
for (MultipartFile file : files) {
|
for (MultipartFile file : files) {
|
||||||
results.add(upload(file, type, null));
|
results.add(upload(file, appType, null));
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -409,7 +410,7 @@ public class NoticeService implements INoticeService {
|
|||||||
@Override
|
@Override
|
||||||
public Map<String, Object> statis(String startTime, String endTime) {
|
public Map<String, Object> statis(String startTime, String endTime) {
|
||||||
List<Notice> list = noticeRepository.findAll();
|
List<Notice> list = noticeRepository.findAll();
|
||||||
LocalDateTime st = parseDt(startTime), et = parseDt(endTime);
|
LocalDateTime st = parseDt(startTime), et = parseDateEnd(endTime);
|
||||||
if (st != null) list = list.stream().filter(n -> !nz(n.getCreateTime()).isBefore(st)).collect(Collectors.toList());
|
if (st != null) list = list.stream().filter(n -> !nz(n.getCreateTime()).isBefore(st)).collect(Collectors.toList());
|
||||||
if (et != null) list = list.stream().filter(n -> !nz(n.getCreateTime()).isAfter(et)).collect(Collectors.toList());
|
if (et != null) list = list.stream().filter(n -> !nz(n.getCreateTime()).isAfter(et)).collect(Collectors.toList());
|
||||||
|
|
||||||
@@ -910,7 +911,8 @@ public class NoticeService implements INoticeService {
|
|||||||
m.put("receiveText", receiveText(n));
|
m.put("receiveText", receiveText(n));
|
||||||
m.put("roomCount", targetRooms(n).size());
|
m.put("roomCount", targetRooms(n).size());
|
||||||
m.put("bedCount", allowCount(n));
|
m.put("bedCount", allowCount(n));
|
||||||
m.put("progress", "draft".equals(n.getNoticeStatus()) ? null : progress(n.getId(), n));
|
// 仅通知类(none)不产生回执行,progress 置空,前端据此显示「仅通知 · 无需回执」而不是 0/0
|
||||||
|
m.put("progress", "draft".equals(n.getNoticeStatus()) || "none".equals(n.getReceiptMode()) ? null : progress(n.getId(), n));
|
||||||
m.put("createBy", n.getCreateBy());
|
m.put("createBy", n.getCreateBy());
|
||||||
m.put("createTime", fmt(n.getCreateTime()));
|
m.put("createTime", fmt(n.getCreateTime()));
|
||||||
m.put("updateBy", n.getUpdateBy());
|
m.put("updateBy", n.getUpdateBy());
|
||||||
@@ -942,7 +944,7 @@ public class NoticeService implements INoticeService {
|
|||||||
m.put("needSupervisor", nz(n.getNeedSupervisor()));
|
m.put("needSupervisor", nz(n.getNeedSupervisor()));
|
||||||
m.put("noticeStatus", n.getNoticeStatus());
|
m.put("noticeStatus", n.getNoticeStatus());
|
||||||
m.put("noticeStatusDesc", DormEnums.statusDesc(n.getNoticeStatus()));
|
m.put("noticeStatusDesc", DormEnums.statusDesc(n.getNoticeStatus()));
|
||||||
m.put("progress", "draft".equals(n.getNoticeStatus()) ? null : progress(n.getId(), n));
|
m.put("progress", "draft".equals(n.getNoticeStatus()) || "none".equals(n.getReceiptMode()) ? null : progress(n.getId(), n));
|
||||||
m.put("ChaoSend", fileItems(n.getFileIds()));
|
m.put("ChaoSend", fileItems(n.getFileIds()));
|
||||||
m.put("tlist", "ALL".equalsIgnoreCase(str(n.getReceiveList()).trim()) ? "all" : new ArrayList<>(targetRoomIds(n)));
|
m.put("tlist", "ALL".equalsIgnoreCase(str(n.getReceiveList()).trim()) ? "all" : new ArrayList<>(targetRoomIds(n)));
|
||||||
m.put("receiveType", "room");
|
m.put("receiveType", "room");
|
||||||
@@ -1108,7 +1110,7 @@ public class NoticeService implements INoticeService {
|
|||||||
if (StringUtils.hasText(ns) && !"all".equals(ns)) {
|
if (StringUtils.hasText(ns) && !"all".equals(ns)) {
|
||||||
out = out.stream().filter(n -> ns.equals(n.getNoticeStatus())).collect(Collectors.toList());
|
out = out.stream().filter(n -> ns.equals(n.getNoticeStatus())).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
LocalDateTime st = parseDt(q.get("startTime")), et = parseDt(q.get("endTime"));
|
LocalDateTime st = parseDt(q.get("startTime")), et = parseDateEnd(q.get("endTime"));
|
||||||
if (st != null) out = out.stream().filter(n -> !nz(n.getEffectiveTime() == null ? n.getCreateTime() : n.getEffectiveTime()).isBefore(st)).collect(Collectors.toList());
|
if (st != null) out = out.stream().filter(n -> !nz(n.getEffectiveTime() == null ? n.getCreateTime() : n.getEffectiveTime()).isBefore(st)).collect(Collectors.toList());
|
||||||
if (et != null) out = out.stream().filter(n -> !nz(n.getEffectiveTime() == null ? n.getCreateTime() : n.getEffectiveTime()).isAfter(et)).collect(Collectors.toList());
|
if (et != null) out = out.stream().filter(n -> !nz(n.getEffectiveTime() == null ? n.getCreateTime() : n.getEffectiveTime()).isAfter(et)).collect(Collectors.toList());
|
||||||
int rt = intg(q.get("readType"), 0);
|
int rt = intg(q.get("readType"), 0);
|
||||||
@@ -1194,6 +1196,18 @@ public class NoticeService implements INoticeService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析查询区间的结束时间:纯日期(yyyy-MM-dd)时取当天末尾 23:59:59.999999999,使区间包含当天
|
||||||
|
*/
|
||||||
|
private LocalDateTime parseDateEnd(Object o) {
|
||||||
|
LocalDateTime t = parseDt(o);
|
||||||
|
if (t == null || o == null) {
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
String s = String.valueOf(o).trim();
|
||||||
|
return s.length() == 10 ? t.toLocalDate().atTime(LocalTime.MAX) : t;
|
||||||
|
}
|
||||||
|
|
||||||
private Map<String, Object> parseFill(Object o) {
|
private Map<String, Object> parseFill(Object o) {
|
||||||
if (o == null) {
|
if (o == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import java.util.stream.Collectors;
|
|||||||
* GetGroupUser 空桩改为显式报错(未接入用户中心对应开放接口时提示,而非静默返回空列表)。
|
* GetGroupUser 空桩改为显式报错(未接入用户中心对应开放接口时提示,而非静默返回空列表)。
|
||||||
* 跨仓调用统一收敛到 {@link YschBaseOpenApi} 门面,Controller 不再直接静态调用。</p>
|
* 跨仓调用统一收敛到 {@link YschBaseOpenApi} 门面,Controller 不再直接静态调用。</p>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserCenterService implements IUserCenterService {
|
public class UserCenterService implements IUserCenterService {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user