全部
This commit is contained in:
@ -25,7 +25,7 @@ import java.nio.charset.StandardCharsets;
|
||||
public class AuthAspect {
|
||||
|
||||
// 授权文件路径
|
||||
private static final String LICENSE_FILE_PATH = "license/yjearth.yj";
|
||||
private static final String LICENSE_FILE_PATH = "license/yjearth.YJ";
|
||||
|
||||
@Pointcut("@annotation(com.yj.earth.annotation.CheckAuth)")
|
||||
public void authPointCut() {
|
||||
|
||||
@ -77,10 +77,10 @@ public class AuthGenerator {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
// 生成加密的授权字符串
|
||||
String authContent = generateAuth("标准版", 1000, 365, "196CB2226A5D5334B9C065ECFC77F4B9");
|
||||
String authContent = generateAuth("标准版", 1000, 365, "3A446222D1FE537F6C9EEF5C2AB3F957");
|
||||
|
||||
// 定义授权文件路径(当前目录下的 yjearth.yj)
|
||||
Path licPath = Paths.get("yjearth.yj");
|
||||
// 定义授权文件路径(当前目录下的 yjearth.YJ)
|
||||
Path licPath = Paths.get("yjearth.YJ");
|
||||
|
||||
// 将授权字符串写入文件
|
||||
Files.write(licPath, authContent.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
@ -21,7 +21,7 @@ import java.nio.file.Paths;
|
||||
public class AuthController {
|
||||
|
||||
// 授权文件存储路径、项目根目录下的 license 目录
|
||||
private static final String AUTH_FILE_PATH = "license/yjearth.yj";
|
||||
private static final String AUTH_FILE_PATH = "license/yjearth.YJ";
|
||||
|
||||
@GetMapping("/info")
|
||||
@Operation(summary = "获取系统授权码")
|
||||
@ -37,10 +37,10 @@ public class AuthController {
|
||||
return ApiResponse.failure("请选择授权文件");
|
||||
}
|
||||
|
||||
// 验证文件名是否为 yjearth.yj
|
||||
// 验证文件名是否为 yjearth.YJ
|
||||
String fileName = file.getOriginalFilename();
|
||||
if (fileName == null || !fileName.equals("yjearth.yj")) {
|
||||
return ApiResponse.failure("请上传 yjearth.yj");
|
||||
if (fileName == null || !fileName.equals("yjearth.YJ")) {
|
||||
return ApiResponse.failure("请上传 yjearth.YJ");
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@ -27,6 +27,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Tag(name = "物资数据管理")
|
||||
@ -97,8 +99,8 @@ public class MatterController {
|
||||
// 用统计出的数量替换分页结果中的数量
|
||||
if (!CollectionUtils.isEmpty(matterPage.getRecords())) {
|
||||
matterPage.getRecords().forEach(matter -> {
|
||||
String matterName = matter.getName();
|
||||
Integer count = goodsTotalMap.get(matterName);
|
||||
String matterId = matter.getId();
|
||||
Integer count = goodsTotalMap.get(matterId);
|
||||
if (count != null) {
|
||||
matter.setNum(count);
|
||||
}
|
||||
@ -113,14 +115,9 @@ public class MatterController {
|
||||
public ApiResponse statistics(@Parameter(description = "点ID列表") @RequestBody List<String> pointIdList) {
|
||||
// 构建Source表的查询条件
|
||||
LambdaQueryWrapper<Source> sourceWrapper = new LambdaQueryWrapper<>();
|
||||
// 根据ID列表查询
|
||||
sourceWrapper.in(Source::getId, pointIdList);
|
||||
// 执行查询、获取所有符合条件的Source列表
|
||||
List<Source> sourceList = sourceService.list(sourceWrapper);
|
||||
|
||||
// 初始化物资统计Map:用于存储 "物资名称 -> 总数量" 的映射关系
|
||||
Map<String, Integer> goodsTotalMap = new HashMap<>();
|
||||
|
||||
if (!CollectionUtils.isEmpty(sourceList)) {
|
||||
for (Source source : sourceList) {
|
||||
try {
|
||||
@ -130,20 +127,10 @@ public class MatterController {
|
||||
.map(Point.Attribute::getGoods)
|
||||
.map(Point.Attribute.Goods::getContent)
|
||||
.ifPresent(contentList -> {
|
||||
// 遍历物资列表中的每个物资项
|
||||
for (Point.Attribute.Goods.GoodsContent goodsContent : contentList) {
|
||||
if (goodsContent == null) continue;
|
||||
|
||||
// 处理物资名称
|
||||
String goodsName = Optional.ofNullable(goodsContent.getName())
|
||||
.orElse("未知物资");
|
||||
|
||||
// 处理物资数量
|
||||
int count = Optional.ofNullable(goodsContent.getCnt())
|
||||
.map(Integer::valueOf)
|
||||
.orElse(0);
|
||||
|
||||
// 累加物资总数量
|
||||
String goodsName = Optional.ofNullable(goodsContent.getName()).orElse("未知物资");
|
||||
int count = Optional.ofNullable(goodsContent.getCnt()).map(Integer::valueOf).orElse(0);
|
||||
goodsTotalMap.merge(goodsName, count, Integer::sum);
|
||||
}
|
||||
});
|
||||
@ -152,22 +139,31 @@ public class MatterController {
|
||||
}
|
||||
}
|
||||
|
||||
// 返回最终的物资统计Map
|
||||
return ApiResponse.success(goodsTotalMap);
|
||||
// 查询物资列表
|
||||
List<Matter> matterList = matterService.list();
|
||||
|
||||
// 以数据库为准、过滤并构建结果
|
||||
Map<String, Integer> resultMap = matterList.stream()
|
||||
.map(Matter::getName) // 提取所有标准物资名称
|
||||
.filter(goodsTotalMap::containsKey) // 只保留在统计结果中存在的物资
|
||||
.collect(Collectors.toMap(
|
||||
Function.identity(), // Key 为物资名称
|
||||
goodsTotalMap::get // Value 为对应的数量
|
||||
));
|
||||
|
||||
// 返回与标准物资匹配的统计结果
|
||||
return ApiResponse.success(resultMap);
|
||||
}
|
||||
|
||||
|
||||
private Map<String, Integer> getGoodCountMap() {
|
||||
// 构建Source表的查询条件
|
||||
// 构建 Source 表的查询条件
|
||||
LambdaQueryWrapper<Source> sourceWrapper = new LambdaQueryWrapper<>();
|
||||
sourceWrapper.eq(Source::getSourceType, "point");
|
||||
|
||||
// 执行查询、获取所有符合条件的Source列表
|
||||
List<Source> sourceList = sourceService.list(sourceWrapper);
|
||||
|
||||
// 初始化物资统计Map:用于存储 "物资名称 -> 总数量" 的映射关系
|
||||
// 初始化物资统计Map: 用于存储 "物资ID -> 总数量" 的映射关系
|
||||
Map<String, Integer> goodsTotalMap = new HashMap<>();
|
||||
|
||||
if (!CollectionUtils.isEmpty(sourceList)) {
|
||||
for (Source source : sourceList) {
|
||||
try {
|
||||
@ -180,18 +176,14 @@ public class MatterController {
|
||||
// 遍历物资列表中的每个物资项
|
||||
for (Point.Attribute.Goods.GoodsContent goodsContent : contentList) {
|
||||
if (goodsContent == null) continue;
|
||||
|
||||
// 处理物资名称
|
||||
String goodsName = Optional.ofNullable(goodsContent.getName())
|
||||
.orElse("未知物资");
|
||||
|
||||
String goodsId = Optional.ofNullable(goodsContent.getId())
|
||||
.orElse("未知物资ID");
|
||||
// 处理物资数量
|
||||
int count = Optional.ofNullable(goodsContent.getCnt())
|
||||
.map(Integer::valueOf)
|
||||
.orElse(0);
|
||||
|
||||
// 累加物资总数量
|
||||
goodsTotalMap.merge(goodsName, count, Integer::sum);
|
||||
goodsTotalMap.merge(goodsId, count, Integer::sum);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
|
||||
@ -4,22 +4,26 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.UUID;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.yj.earth.annotation.CheckAuth;
|
||||
import com.yj.earth.business.domain.MilitaryLibrary;
|
||||
import com.yj.earth.business.domain.MilitaryType;
|
||||
import com.yj.earth.business.domain.*;
|
||||
import com.yj.earth.business.service.MilitaryLibraryService;
|
||||
import com.yj.earth.business.service.SourceService;
|
||||
import com.yj.earth.common.util.ApiResponse;
|
||||
import com.yj.earth.common.util.FileCommonUtil;
|
||||
import com.yj.earth.common.util.JsonUtil;
|
||||
import com.yj.earth.common.util.SQLiteUtil;
|
||||
import com.yj.earth.dto.militaryLibrary.AddMilitaryTypeDto;
|
||||
import com.yj.earth.dto.militaryLibrary.CreateMilitaryLibraryDto;
|
||||
import com.yj.earth.dto.militaryLibrary.DragMilitaryTypeDto;
|
||||
import com.yj.earth.dto.militaryLibrary.UpdateMilitaryTypeNameDto;
|
||||
import com.yj.earth.params.MilitaryParam;
|
||||
import com.yj.earth.params.ModelParam;
|
||||
import com.yj.earth.vo.MilitaryDataVo;
|
||||
import com.yj.earth.vo.MilitaryTypeVo;
|
||||
import com.yj.earth.vo.MilitaryVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
@ -50,6 +54,12 @@ public class MilitaryLibraryController {
|
||||
|
||||
@Resource
|
||||
private MilitaryLibraryService militaryLibraryService;
|
||||
@Resource
|
||||
private SourceService sourceService;
|
||||
@Value("${server.host}")
|
||||
private String serverHost;
|
||||
@Value("${server.port}")
|
||||
private int serverPort;
|
||||
|
||||
@Operation(summary = "创建军标库")
|
||||
@PostMapping("/createMilitaryLibrary")
|
||||
@ -337,13 +347,39 @@ public class MilitaryLibraryController {
|
||||
return ApiResponse.failure("请先创建或导入军标库");
|
||||
}
|
||||
|
||||
// 存储被删除的Source ID列表
|
||||
List<String> deletedSourceIds = new ArrayList<>();
|
||||
// 获取URL
|
||||
String MilitaryDataUrlByModelId = getMilitaryDataUrlByModelId(militaryId);
|
||||
// 查询资源
|
||||
LambdaQueryWrapper<Source> queryWrapper = new LambdaQueryWrapper<>();
|
||||
// 查询类型为 model 的
|
||||
queryWrapper.eq(Source::getSourceType, "military");
|
||||
// 查询列表
|
||||
List<Source> sourceList = sourceService.list(queryWrapper);
|
||||
// 遍历数据
|
||||
for (Source source : sourceList) {
|
||||
// 取出 params 字段
|
||||
String dataParams = source.getParams();
|
||||
if (dataParams != null) {
|
||||
// 转换为 Model 对象
|
||||
MilitaryParam militaryParam = JsonUtil.jsonToObject(dataParams, MilitaryParam.class);
|
||||
if (MilitaryDataUrlByModelId.equals(militaryParam.getUrl())) {
|
||||
// 删除这个资源
|
||||
sourceService.removeById(source.getId());
|
||||
// 添加到被删除的ID列表
|
||||
deletedSourceIds.add(source.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 执行删除
|
||||
String deleteSql = "DELETE FROM military WHERE id = ?";
|
||||
List<Object> params = new ArrayList<>();
|
||||
params.add(militaryId);
|
||||
|
||||
SQLiteUtil.executeUpdate(militaryPath, deleteSql, params);
|
||||
return ApiResponse.success("删除军标成功");
|
||||
return ApiResponse.success(deletedSourceIds);
|
||||
}
|
||||
|
||||
|
||||
@ -514,6 +550,32 @@ public class MilitaryLibraryController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据军标ID获取模型数据访问URL
|
||||
*/
|
||||
private String getMilitaryDataUrlByModelId(String militaryId) {
|
||||
try {
|
||||
// 获取当前启用的军标库路径
|
||||
String militaryLibraryPath = getMilitaryLibrary();
|
||||
if (militaryLibraryPath == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 查询军标对应的类型后缀
|
||||
String sql = "SELECT military_type FROM military WHERE id = ?";
|
||||
List<Object> params = new ArrayList<>();
|
||||
params.add(militaryId);
|
||||
Military military = SQLiteUtil.queryForObject(militaryLibraryPath, sql, params, Military.class);
|
||||
// 得到类型ID
|
||||
String militaryType = military.getMilitaryType();
|
||||
// 拼接完整URL
|
||||
return "http://" + serverHost + ":" + serverPort + "/militaryLibrary/data/military/" + militaryId + "/" + militaryType;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isMilitaryTypeExist(String militaryPath, String typeId)
|
||||
throws SQLException, IllegalAccessException, InstantiationException {
|
||||
String checkSql = "SELECT id FROM military_type WHERE id = ?";
|
||||
|
||||
@ -388,7 +388,6 @@ public class ModelLibraryController {
|
||||
|
||||
// 存储被删除的Source ID列表
|
||||
List<String> deletedSourceIds = new ArrayList<>();
|
||||
|
||||
// 获取URL
|
||||
String modelDataUrlByModelId = getModelDataUrlByModelId(modelId);
|
||||
// 查询资源
|
||||
|
||||
@ -7,7 +7,7 @@ import java.util.List;
|
||||
|
||||
@Data
|
||||
@SourceType("military")
|
||||
public class Military {
|
||||
public class MilitaryParam {
|
||||
private String id;
|
||||
private String url;
|
||||
private Position position;
|
||||
Reference in New Issue
Block a user