Compare commits
5
Commits
8ff61bc037
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab3d9b748a | ||
|
|
8b18fbc49f | ||
|
|
a227611512 | ||
|
|
cfe0b0c4f0 | ||
|
|
988e5ca7f4 |
@@ -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: |
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.yunhai.campusnotice.common.listener;
|
package com.yunhai.campusnotice.common.listener;
|
||||||
|
|
||||||
import com.yunhai.campusnotice.entity.BaseEntity;
|
import com.yunhai.campusnotice.entity.BaseEntity;
|
||||||
import com.yunhai.platform.auth.LoginUser;
|
import com.yunhai.platform.auth.spring.CurrentBoaUser;
|
||||||
import com.yunhai.platform.auth.UserContextHolder;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.persistence.PrePersist;
|
import javax.persistence.PrePersist;
|
||||||
@@ -10,38 +10,53 @@ import javax.persistence.PreUpdate;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JPA 审计监听器:在实体持久化/更新前自动填充创建人/更新人(平台当前登录人)与时间戳。
|
* JPA 审计监听器:在实体持久化/更新前自动填充创建人/更新人与时间戳。
|
||||||
* 对应 {@link BaseEntity} 的 createBy / updateBy / createTime / updateTime 字段。
|
* 对应 {@link BaseEntity} 的 createBy / updateBy / createTime / updateTime 字段。
|
||||||
* 当前登录人取自基础平台 {@link UserContextHolder}。
|
* 创建人/更新人存用户中心数字用户ID({@link BoaUser#getId()},经 {@link CurrentBoaUser#getUserId()}),
|
||||||
|
* 不存登录账号;无登录态(定时任务等)或未匹配到用户表时留空,不做账号兜底,
|
||||||
|
* 避免同列混存两种口径。
|
||||||
|
* <p>注意:平台 CAS 登录的 {@code LoginUser.userId} 实际填的是登录账号(非数字),
|
||||||
|
* 故此处不能取 UserContextHolder,必须走 {@link CurrentBoaUser}。
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class NoticeAuditListener {
|
public class NoticeAuditListener {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CurrentBoaUser currentBoaUser;
|
||||||
|
|
||||||
@PrePersist
|
@PrePersist
|
||||||
public void prePersist(BaseEntity entity) {
|
public void prePersist(BaseEntity entity) {
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
entity.setCreateTime(now);
|
entity.setCreateTime(now);
|
||||||
entity.setUpdateTime(now);
|
entity.setUpdateTime(now);
|
||||||
String account = currentAccount();
|
Integer userId = currentUserId();
|
||||||
if (account != null) {
|
if (userId != null) {
|
||||||
if (entity.getCreateBy() == null) {
|
if (entity.getCreateBy() == null) {
|
||||||
entity.setCreateBy(account);
|
entity.setCreateBy(userId);
|
||||||
}
|
}
|
||||||
entity.setUpdateBy(account);
|
entity.setUpdateBy(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreUpdate
|
@PreUpdate
|
||||||
public void preUpdate(BaseEntity entity) {
|
public void preUpdate(BaseEntity entity) {
|
||||||
entity.setUpdateTime(LocalDateTime.now());
|
entity.setUpdateTime(LocalDateTime.now());
|
||||||
String account = currentAccount();
|
Integer userId = currentUserId();
|
||||||
if (account != null) {
|
if (userId != null) {
|
||||||
entity.setUpdateBy(account);
|
entity.setUpdateBy(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String currentAccount() {
|
/** 当前登录人数字用户ID(用户中心 BoaUser.id;无登录态/未匹配用户时为 null) */
|
||||||
LoginUser user = UserContextHolder.get();
|
private Integer currentUserId() {
|
||||||
return user == null ? null : user.getLoginName();
|
if (currentBoaUser == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return currentBoaUser.getUserId();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 无请求上下文(定时任务/启动期)时 ThreadLocal 链路可能不可用,审计留空
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,10 +24,10 @@ public abstract class BaseEntity implements Serializable {
|
|||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建人登录账号
|
* 创建人用户ID(用户中心 BoaUser.id;历史存量数据为登录账号字符串,迁移见 sql/audit_by_user_id.sql)
|
||||||
*/
|
*/
|
||||||
@Column(name = "create_by", updatable = false)
|
@Column(name = "create_by", updatable = false)
|
||||||
private String createBy;
|
private Integer createBy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建时间
|
* 创建时间
|
||||||
@@ -36,10 +36,10 @@ public abstract class BaseEntity implements Serializable {
|
|||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新人登录账号
|
* 更新人用户ID(用户中心 BoaUser.id;历史存量数据为登录账号字符串)
|
||||||
*/
|
*/
|
||||||
@Column(name = "update_by")
|
@Column(name = "update_by")
|
||||||
private String updateBy;
|
private Integer updateBy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新时间
|
* 更新时间
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ import javax.persistence.Table;
|
|||||||
@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false)
|
@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false)
|
||||||
public class SysDict extends BaseEntity {
|
public class SysDict extends BaseEntity {
|
||||||
|
|
||||||
|
/** 学校ID(多租户隔离:添加时从 BoaUser.currentRole.schId 填充,查询按校过滤;存量数据见 sql/sys_dict_add_sch_id.sql 回填说明) */
|
||||||
|
@Column(name = "sch_id")
|
||||||
|
private Integer schId;
|
||||||
|
|
||||||
/** 字典类型(如 "dept"=所属分类) */
|
/** 字典类型(如 "dept"=所属分类) */
|
||||||
@Column(name = "dict_type", length = 50)
|
@Column(name = "dict_type", length = 50)
|
||||||
private String dictType;
|
private String dictType;
|
||||||
|
|||||||
@@ -84,9 +84,11 @@ public class NoticeVo {
|
|||||||
/** 附件ID串("1,2,3",列表页下载入口使用;对齐旧 .NET UpFile 字段) */
|
/** 附件ID串("1,2,3",列表页下载入口使用;对齐旧 .NET UpFile 字段) */
|
||||||
private String UpFile;
|
private String UpFile;
|
||||||
|
|
||||||
private String createBy;
|
/** 创建人用户ID(用户中心数字ID;历史存量数据为登录账号字符串) */
|
||||||
|
private Integer createBy;
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
private String updateBy;
|
/** 更新人用户ID(用户中心数字ID;历史存量数据为登录账号字符串) */
|
||||||
|
private Integer updateBy;
|
||||||
private LocalDateTime updateTime;
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,9 +7,20 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface SysDictRepository extends JpaRepository<SysDict, Integer> {
|
public interface SysDictRepository extends JpaRepository<SysDict, Integer> {
|
||||||
|
|
||||||
|
/* 旧方法(未按校过滤):仅作为无登录态上下文的兜底保留 */
|
||||||
|
|
||||||
List<SysDict> findByDictTypeOrderBySortOrderAsc(String dictType);
|
List<SysDict> findByDictTypeOrderBySortOrderAsc(String dictType);
|
||||||
List<SysDict> findByDictTypeAndEnableFlagOrderBySortOrderAsc(String dictType, Integer enableFlag);
|
List<SysDict> findByDictTypeAndEnableFlagOrderBySortOrderAsc(String dictType, Integer enableFlag);
|
||||||
|
|
||||||
/** 按类型+key 取单条字典(发文部门名称解析用) */
|
/** 按类型+key 取单条字典(发文部门名称解析用) */
|
||||||
Optional<SysDict> findByDictTypeAndDictKey(String dictType, String dictKey);
|
Optional<SysDict> findByDictTypeAndDictKey(String dictType, String dictKey);
|
||||||
|
|
||||||
|
/* 按校过滤(多租户隔离):字典业务主链路使用 */
|
||||||
|
|
||||||
|
List<SysDict> findBySchIdAndDictTypeOrderBySortOrderAsc(Integer schId, String dictType);
|
||||||
|
List<SysDict> findBySchIdAndDictTypeAndEnableFlagOrderBySortOrderAsc(Integer schId, String dictType, Integer enableFlag);
|
||||||
|
|
||||||
|
/** 按校+类型+key 取单条字典(发文部门名称解析用) */
|
||||||
|
Optional<SysDict> findBySchIdAndDictTypeAndDictKey(Integer schId, String dictType, String dictKey);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import javax.persistence.criteria.Predicate;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -74,7 +75,7 @@ public class DictService implements IDictService {
|
|||||||
if (dictType == null) {
|
if (dictType == null) {
|
||||||
throw new BizException(ErrorCode.PARAM_ERROR, "参数错误");
|
throw new BizException(ErrorCode.PARAM_ERROR, "参数错误");
|
||||||
}
|
}
|
||||||
List<SysDict> list = sysDictRepository.findByDictTypeAndEnableFlagOrderBySortOrderAsc(dictType, 1);
|
List<SysDict> list = currentSchoolDict(dictType, 1);
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
throw new BizException(ErrorCode.FORBIDDEN, "尚未添加发文部门,请联系管理员添加!");
|
throw new BizException(ErrorCode.FORBIDDEN, "尚未添加发文部门,请联系管理员添加!");
|
||||||
}
|
}
|
||||||
@@ -100,7 +101,7 @@ public class DictService implements IDictService {
|
|||||||
// 非 DEPT 类型需超管权限,本系统暂只支持 DEPT
|
// 非 DEPT 类型需超管权限,本系统暂只支持 DEPT
|
||||||
throw new BizException(ErrorCode.FORBIDDEN, "非超管不得操作!");
|
throw new BizException(ErrorCode.FORBIDDEN, "非超管不得操作!");
|
||||||
}
|
}
|
||||||
List<SysDict> list = sysDictRepository.findByDictTypeOrderBySortOrderAsc(dictType);
|
List<SysDict> list = currentSchoolDict(dictType, null);
|
||||||
return list.stream()
|
return list.stream()
|
||||||
.sorted(Comparator.comparingInt(d -> d.getSortOrder() == null ? 999 : d.getSortOrder()))
|
.sorted(Comparator.comparingInt(d -> d.getSortOrder() == null ? 999 : d.getSortOrder()))
|
||||||
.map(d -> {
|
.map(d -> {
|
||||||
@@ -123,21 +124,23 @@ public class DictService implements IDictService {
|
|||||||
if (!StringUtils.hasText(name)) {
|
if (!StringUtils.hasText(name)) {
|
||||||
throw new BizException(ErrorCode.PARAM_ERROR, "输入字符串格式不正确!");
|
throw new BizException(ErrorCode.PARAM_ERROR, "输入字符串格式不正确!");
|
||||||
}
|
}
|
||||||
// 校验重名
|
Integer schId = currentSchId();
|
||||||
List<SysDict> existing = sysDictRepository.findByDictTypeOrderBySortOrderAsc(DICT_TYPE_DEPT);
|
// 校验重名(本校范围)
|
||||||
|
List<SysDict> existing = currentSchoolDict(DICT_TYPE_DEPT, null);
|
||||||
boolean duplicate = existing.stream().anyMatch(d ->
|
boolean duplicate = existing.stream().anyMatch(d ->
|
||||||
DICT_TYPE_DEPT.equals(d.getDictType()) && name.equals(d.getDictValue()) && d.getEnableFlag() != 3);
|
DICT_TYPE_DEPT.equals(d.getDictType()) && name.equals(d.getDictValue()) && d.getEnableFlag() != 3);
|
||||||
if (duplicate) {
|
if (duplicate) {
|
||||||
throw new BizException(ErrorCode.FORBIDDEN, "已存在该分类,请重新填写!");
|
throw new BizException(ErrorCode.FORBIDDEN, "已存在该分类,请重新填写!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算 sortOrder = max + 1
|
// 计算 sortOrder = max + 1(本校范围)
|
||||||
int maxSort = existing.stream()
|
int maxSort = existing.stream()
|
||||||
.filter(d -> d.getEnableFlag() != 3)
|
.filter(d -> d.getEnableFlag() != 3)
|
||||||
.mapToInt(d -> d.getSortOrder() != null ? d.getSortOrder() : 0)
|
.mapToInt(d -> d.getSortOrder() != null ? d.getSortOrder() : 0)
|
||||||
.max().orElse(0);
|
.max().orElse(0);
|
||||||
|
|
||||||
SysDict dict = new SysDict();
|
SysDict dict = new SysDict();
|
||||||
|
dict.setSchId(schId);
|
||||||
dict.setDictType(DICT_TYPE_DEPT);
|
dict.setDictType(DICT_TYPE_DEPT);
|
||||||
dict.setDictValue(name);
|
dict.setDictValue(name);
|
||||||
dict.setSortOrder(maxSort + 1);
|
dict.setSortOrder(maxSort + 1);
|
||||||
@@ -154,16 +157,16 @@ public class DictService implements IDictService {
|
|||||||
if (serID == null) {
|
if (serID == null) {
|
||||||
throw new BizException(ErrorCode.PARAM_ERROR, "参数错误!");
|
throw new BizException(ErrorCode.PARAM_ERROR, "参数错误!");
|
||||||
}
|
}
|
||||||
// 校验重名(排除自身)
|
Integer schId = currentSchId();
|
||||||
List<SysDict> existing = sysDictRepository.findByDictTypeOrderBySortOrderAsc(DICT_TYPE_DEPT);
|
SysDict dict = requireOwnDict(schId, serID);
|
||||||
|
// 校验重名(本校范围,排除自身)
|
||||||
|
List<SysDict> existing = currentSchoolDict(DICT_TYPE_DEPT, null);
|
||||||
boolean duplicate = existing.stream().anyMatch(d ->
|
boolean duplicate = existing.stream().anyMatch(d ->
|
||||||
!d.getId().equals(serID) && name.equals(d.getDictValue()) && d.getEnableFlag() != 3);
|
!d.getId().equals(serID) && name != null && name.equals(d.getDictValue()) && d.getEnableFlag() != 3);
|
||||||
if (duplicate) {
|
if (duplicate) {
|
||||||
throw new BizException(ErrorCode.FORBIDDEN, "已存在该分类,请重新填写!");
|
throw new BizException(ErrorCode.FORBIDDEN, "已存在该分类,请重新填写!");
|
||||||
}
|
}
|
||||||
|
|
||||||
SysDict dict = sysDictRepository.findById(serID)
|
|
||||||
.orElseThrow(() -> new BizException(ErrorCode.FORBIDDEN, "字典记录不存在"));
|
|
||||||
if (StringUtils.hasText(name)) {
|
if (StringUtils.hasText(name)) {
|
||||||
dict.setDictValue(name);
|
dict.setDictValue(name);
|
||||||
}
|
}
|
||||||
@@ -178,13 +181,19 @@ public class DictService implements IDictService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delDept(Integer serID) {
|
public void delDept(Integer serID) {
|
||||||
SysDict dict = sysDictRepository.findById(serID)
|
Integer schId = currentSchId();
|
||||||
.orElseThrow(() -> new BizException(ErrorCode.FORBIDDEN, "字典记录不存在"));
|
SysDict dict = requireOwnDict(schId, serID);
|
||||||
// 校验是否被通知引用(按 deptId = dictKey 匹配)
|
// 校验是否被通知引用(本校范围,按 deptId = dictKey 匹配)
|
||||||
// C# 中检查 Notify_Message.DeptID == dict.CodeID
|
// C# 中检查 Notify_Message.DeptID == dict.CodeID
|
||||||
// Java 中 Notice.deptId 存的是 dictKey
|
// Java 中 Notice.deptId 存的是 dictKey
|
||||||
List<Notice> referenced = noticeRepository.findAll((root, query, cb) ->
|
List<Notice> referenced = noticeRepository.findAll((root, query, cb) -> {
|
||||||
cb.equal(root.get("deptId"), dict.getDictKey()));
|
List<Predicate> predicates = new ArrayList<>();
|
||||||
|
predicates.add(cb.equal(root.get("deptId"), dict.getDictKey()));
|
||||||
|
if (schId != null) {
|
||||||
|
predicates.add(cb.equal(root.get("schId"), schId));
|
||||||
|
}
|
||||||
|
return cb.and(predicates.toArray(new Predicate[0]));
|
||||||
|
});
|
||||||
if (!referenced.isEmpty()) {
|
if (!referenced.isEmpty()) {
|
||||||
throw new BizException(ErrorCode.FORBIDDEN, "已引用该部门,无法删除!");
|
throw new BizException(ErrorCode.FORBIDDEN, "已引用该部门,无法删除!");
|
||||||
}
|
}
|
||||||
@@ -199,7 +208,8 @@ public class DictService implements IDictService {
|
|||||||
if (!StringUtils.hasText(ids)) {
|
if (!StringUtils.hasText(ids)) {
|
||||||
throw new BizException(ErrorCode.PARAM_ERROR, "参数错误");
|
throw new BizException(ErrorCode.PARAM_ERROR, "参数错误");
|
||||||
}
|
}
|
||||||
List<SysDict> list = sysDictRepository.findByDictTypeOrderBySortOrderAsc(DICT_TYPE_DEPT);
|
Integer schId = currentSchId();
|
||||||
|
List<SysDict> list = currentSchoolDict(DICT_TYPE_DEPT, null);
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
throw new BizException(ErrorCode.FORBIDDEN, "字典类型错误,未找到该字典类型");
|
throw new BizException(ErrorCode.FORBIDDEN, "字典类型错误,未找到该字典类型");
|
||||||
}
|
}
|
||||||
@@ -218,14 +228,16 @@ public class DictService implements IDictService {
|
|||||||
// lambda 中不能修改局部变量,用数组包装
|
// lambda 中不能修改局部变量,用数组包装
|
||||||
final int[] indexOrd = { maxSort };
|
final int[] indexOrd = { maxSort };
|
||||||
|
|
||||||
// 逆序遍历,从最大序号递减
|
// 逆序遍历,从最大序号递减(仅本校记录参与排序,跨校 ID 跳过)
|
||||||
for (int i = idArr.length - 1; i >= 0; i--) {
|
for (int i = idArr.length - 1; i >= 0; i--) {
|
||||||
int id = idArr[i];
|
int id = idArr[i];
|
||||||
sysDictRepository.findById(id).ifPresent(dict -> {
|
sysDictRepository.findById(id)
|
||||||
dict.setSortOrder(indexOrd[0]);
|
.filter(dict -> schId == null || schId.equals(dict.getSchId()))
|
||||||
sysDictRepository.save(dict);
|
.ifPresent(dict -> {
|
||||||
indexOrd[0]--;
|
dict.setSortOrder(indexOrd[0]);
|
||||||
});
|
sysDictRepository.save(dict);
|
||||||
|
indexOrd[0]--;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,17 +257,47 @@ public class DictService implements IDictService {
|
|||||||
|
|
||||||
// ============================ 辅助方法 ============================
|
// ============================ 辅助方法 ============================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取当前学校的字典列表(enableFlag 传 null 不过滤启用态)。
|
||||||
|
* 无学校身份时退回全表查询(对齐 Notice 多租户口径:schId 为空不过滤)。
|
||||||
|
*/
|
||||||
|
private List<SysDict> currentSchoolDict(String dictType, Integer enableFlag) {
|
||||||
|
Integer schId = currentSchId();
|
||||||
|
if (schId == null) {
|
||||||
|
return enableFlag == null
|
||||||
|
? sysDictRepository.findByDictTypeOrderBySortOrderAsc(dictType)
|
||||||
|
: sysDictRepository.findByDictTypeAndEnableFlagOrderBySortOrderAsc(dictType, enableFlag);
|
||||||
|
}
|
||||||
|
return enableFlag == null
|
||||||
|
? sysDictRepository.findBySchIdAndDictTypeOrderBySortOrderAsc(schId, dictType)
|
||||||
|
: sysDictRepository.findBySchIdAndDictTypeAndEnableFlagOrderBySortOrderAsc(schId, dictType, enableFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 定位本校字典记录(跨校/存量未归属 sch_id 的记录一律视为不存在,存量回填见 sql/sys_dict_add_sch_id.sql) */
|
||||||
|
private SysDict requireOwnDict(Integer schId, Integer id) {
|
||||||
|
if (id == null) {
|
||||||
|
throw new BizException(ErrorCode.PARAM_ERROR, "参数错误");
|
||||||
|
}
|
||||||
|
return sysDictRepository.findById(id)
|
||||||
|
.filter(d -> schId != null && schId.equals(d.getSchId()))
|
||||||
|
.orElseThrow(() -> new BizException(ErrorCode.FORBIDDEN, "字典记录不存在"));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 按发文部门字典 key 解析部门名称(对应 C# GetDeptName)。
|
* 按发文部门字典 key 解析部门名称(对应 C# GetDeptName)。
|
||||||
|
* 有学校身份时按校过滤(各校 dict_key 可能重名),无登录态时退回全表兜底。
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String resolveDeptName(String deptId) {
|
public String resolveDeptName(String deptId) {
|
||||||
if (!StringUtils.hasText(deptId)) {
|
if (!StringUtils.hasText(deptId)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return sysDictRepository.findByDictTypeAndDictKey(DICT_TYPE_DEPT, deptId.trim())
|
String key = deptId.trim();
|
||||||
.map(SysDict::getDictValue)
|
Integer schId = currentSchId();
|
||||||
.orElse(null);
|
Optional<SysDict> dict = schId != null
|
||||||
|
? sysDictRepository.findBySchIdAndDictTypeAndDictKey(schId, DICT_TYPE_DEPT, key)
|
||||||
|
: sysDictRepository.findByDictTypeAndDictKey(DICT_TYPE_DEPT, key);
|
||||||
|
return dict.map(SysDict::getDictValue).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -53,11 +53,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 = "notice";
|
|
||||||
|
|
||||||
// ============================ 上传 ============================
|
// ============================ 上传 ============================
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -77,13 +75,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 +89,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 +120,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,8 +273,7 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,9 +286,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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ spring:
|
|||||||
auto-startup: false
|
auto-startup: false
|
||||||
|
|
||||||
# 文件上传存储路径(Docker 部署时与 volume 挂载一致)
|
# 文件上传存储路径(Docker 部署时与 volume 挂载一致)
|
||||||
file:
|
#file:
|
||||||
upload-path: D:/data/upload
|
# upload-path: D:/data/upload
|
||||||
|
|
||||||
# 短信模块配置
|
# 短信模块配置
|
||||||
sms:
|
sms:
|
||||||
@@ -76,3 +76,5 @@ yh:
|
|||||||
# 审批人资格组ID(用户中心组):>0 时 Submit 逐个校验被选人属于该组;
|
# 审批人资格组ID(用户中心组):>0 时 Submit 逐个校验被选人属于该组;
|
||||||
# 0 = 仅校验用户存在(审批资格数据源待产品确认,改造方案 5.1-#5)
|
# 0 = 仅校验用户存在(审批资格数据源待产品确认,改造方案 5.1-#5)
|
||||||
approver-group-id: 0
|
approver-group-id: 0
|
||||||
|
|
||||||
|
FILE_PATH: D:/data/upload
|
||||||
|
|||||||
Reference in New Issue
Block a user