修复:初始化数据,指定id插入不生效问题
调整:app端接口
This commit is contained in:
@@ -14,26 +14,22 @@ import com.cool.modules.base.entity.sys.BaseSysMenuEntity;
|
||||
import com.cool.modules.base.service.sys.BaseSysConfService;
|
||||
import com.cool.modules.base.service.sys.BaseSysMenuService;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
|
||||
/**
|
||||
* 数据库初始数据初始化 在 classpath:cool/data/db 目录下创建.json文件 并定义表数据, 由该类统一执行初始化
|
||||
@@ -94,7 +90,7 @@ public class DBFromJsonInit implements ApplicationRunner {
|
||||
}
|
||||
|
||||
private void analysisResources(Resource[] resources)
|
||||
throws IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
||||
throws IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
||||
String prefix = "db_";
|
||||
for (Resource resource : resources) {
|
||||
File resourceFile = new File(resource.getURL().getFile());
|
||||
@@ -119,7 +115,7 @@ public class DBFromJsonInit implements ApplicationRunner {
|
||||
}
|
||||
|
||||
private void analysisJson(JSONObject jsonObject)
|
||||
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
||||
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
||||
Map<String, Class<?>> tableMap = EntityUtils.findTableMap();
|
||||
for (String tableName : jsonObject.keySet()) {
|
||||
JSONArray records = jsonObject.getJSONArray(tableName);
|
||||
@@ -134,24 +130,22 @@ public class DBFromJsonInit implements ApplicationRunner {
|
||||
/**
|
||||
* 插入列表数据
|
||||
*/
|
||||
private void insertList(BaseMapper<?> baseMapper, Class<?> entityClass,
|
||||
JSONArray records)
|
||||
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
||||
private void insertList(BaseMapper baseMapper, Class<?> entityClass,
|
||||
JSONArray records)
|
||||
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
||||
// 插入数据
|
||||
List list = new ArrayList<>();
|
||||
for (int i = 0; i < records.size(); i++) {
|
||||
JSONObject record = records.getJSONObject(i);
|
||||
Object entity = JSONUtil.toBean(record, entityClass);
|
||||
Method getIdMethod = entityClass.getMethod("getId");
|
||||
Object id = getIdMethod.invoke(entity);
|
||||
if (ObjUtil.isNotEmpty(id) && ObjUtil.isNotEmpty(
|
||||
baseMapper.selectOneById((Long) id))) {
|
||||
baseMapper.selectOneById((Long) id))) {
|
||||
// 数据库已经有值了
|
||||
continue;
|
||||
}
|
||||
list.add(entity);
|
||||
baseMapper.insertSelectiveWithPk(entity);
|
||||
}
|
||||
baseMapper.insertBatch(list);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,18 +3,14 @@ package com.cool.modules.base.controller.admin;
|
||||
import com.cool.core.annotation.CoolRestController;
|
||||
import com.cool.core.enums.UserTypeEnum;
|
||||
import com.cool.core.eps.CoolEps;
|
||||
import com.cool.core.file.FileUploadStrategyFactory;
|
||||
import com.cool.core.request.R;
|
||||
import com.cool.modules.base.dto.sys.BaseSysLoginDto;
|
||||
import com.cool.modules.base.service.sys.BaseSysLoginService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* 系统开放接口,无需权限校验
|
||||
@@ -28,8 +24,6 @@ public class AdminBaseOpenController {
|
||||
|
||||
final private CoolEps coolEps;
|
||||
|
||||
final private FileUploadStrategyFactory fileUploadStrategyFactory;
|
||||
|
||||
@Operation(summary = "实体信息与路径", description = "系统所有的实体信息与路径,供前端自动生成代码与服务")
|
||||
@GetMapping("/eps")
|
||||
public R eps() {
|
||||
@@ -61,17 +55,4 @@ public class AdminBaseOpenController {
|
||||
public R refreshToken(String refreshToken) {
|
||||
return R.ok(baseSysLoginService.refreshToken(refreshToken));
|
||||
}
|
||||
|
||||
@Operation(summary = "文件上传")
|
||||
@PostMapping(value = "/upload", consumes = { MediaType.MULTIPART_FORM_DATA_VALUE, MediaType.ALL_VALUE })
|
||||
public R upload(@RequestPart(value = "file", required = false) @Parameter(description = "文件") MultipartFile[] files,
|
||||
HttpServletRequest request) {
|
||||
return R.ok(fileUploadStrategyFactory.upload(files, request));
|
||||
}
|
||||
|
||||
@Operation(summary = "文件上传模式")
|
||||
@GetMapping("/uploadMode")
|
||||
public R uploadMode() {
|
||||
return R.ok(fileUploadStrategyFactory.getMode());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,18 @@ package com.cool.modules.base.controller.app;
|
||||
import com.cool.core.annotation.CoolRestController;
|
||||
import com.cool.core.annotation.TokenIgnore;
|
||||
import com.cool.core.eps.CoolEps;
|
||||
import com.cool.core.file.FileUploadStrategyFactory;
|
||||
import com.cool.core.request.R;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* app通用接口
|
||||
@@ -19,10 +26,26 @@ public class AppBaseCommController {
|
||||
|
||||
final private CoolEps coolEps;
|
||||
|
||||
final private FileUploadStrategyFactory fileUploadStrategyFactory;
|
||||
|
||||
@TokenIgnore
|
||||
@Operation(summary = "实体信息与路径", description = "系统所有的实体信息与路径,供前端自动生成代码与服务")
|
||||
@GetMapping("/eps")
|
||||
public R eps() {
|
||||
return R.ok(coolEps.getApp());
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "文件上传")
|
||||
@PostMapping(value = "/upload", consumes = { MediaType.MULTIPART_FORM_DATA_VALUE, MediaType.ALL_VALUE })
|
||||
public R upload(@RequestPart(value = "file", required = false) @Parameter(description = "文件") MultipartFile[] files,
|
||||
HttpServletRequest request) {
|
||||
return R.ok(fileUploadStrategyFactory.upload(files, request));
|
||||
}
|
||||
|
||||
@Operation(summary = "文件上传模式")
|
||||
@GetMapping("/uploadMode")
|
||||
public R uploadMode() {
|
||||
return R.ok(fileUploadStrategyFactory.getMode());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user