提交 cf5ab4d5 authored 作者: 黄夏豪's avatar 黄夏豪

修复了 insertValues 日期无法正常上传的BUG

上级 73f175b4
......@@ -31,6 +31,7 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 下面是我引入的东西 zsp-->
<dependency>
<groupId>com.github.caspar-chen</groupId>
......@@ -95,16 +96,28 @@
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*</include>
</includes>
<excludes>
<exclude>**/.svn/*</exclude>
</excludes>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<!-- <plugin>-->
<!-- <groupId>org.springframework.boot</groupId>-->
......
......@@ -9,7 +9,6 @@ import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
* @author admin
*/
@SpringBootApplication
@EnableJpaAuditing
public class WorkflowCoreApplication {
......
......@@ -20,7 +20,6 @@ public class WorkflowCoreRunner implements CommandLineRunner {
return getClass().getClassLoader();
}
@Override
public void run(String... args) {
System.out.println("核心成功启动");
......@@ -31,7 +30,6 @@ public class WorkflowCoreRunner implements CommandLineRunner {
public void createXmlMkdir(){
File file = new File(this.getClass().getClassLoader().getResource("").getPath()+"\\xml");
if (!file.exists()){
file.mkdir();
}
}
......
package com.tykj.workflowcore.model_layer.controller;
import com.tykj.workflowcore.model_layer.dao.ColumnInfoDao;
import com.tykj.workflowcore.model_layer.model.ColumnInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @ClassName ColumnController
* @Description TODO
* @Author WWW
* @Date 2021/2/24 14:33
* @Version 1.0
*/
@RestController
@RequestMapping("/Column")
public class ColumnController {
@Autowired
private ColumnInfoDao columnInfoDao;
@PostMapping("/addColumnInfo")
public ColumnInfo addColumnInfo(@RequestBody ColumnInfo columnInfo) {
ColumnInfo save = columnInfoDao.save(columnInfo);
if (save != null) {
return save;
}
return null;
}
@GetMapping("/getInfo")
public List<ColumnInfo> getAll() {
List<ColumnInfo> all = columnInfoDao.findAll();
return all;
}
@GetMapping("/getInfo/{id}")
public ColumnInfo getOne(@PathVariable("id") long id) {
ColumnInfo one = columnInfoDao.findById(id).get();
return one;
}
}
......@@ -47,9 +47,9 @@ public class ModelController {
}
@PostMapping("/addModel")
public ResponseEntity addModel(@RequestBody String jsonStr) throws Exception {
TableVO tableVO = modelService.addModel(jsonStr);
//入参使用VO直接接收即可
//jsonStr -> TableVo
public ResponseEntity addModel(@RequestBody TableVO tableVO) throws Exception {
List<TableInfo> tableInfos = modelService.ListAllEntities();
for (TableInfo tableInfo : tableInfos) {
if (tableVO.getModelName()!=null&&tableVO.getModelName().equals(tableInfo.getName())){
......@@ -57,7 +57,8 @@ public class ModelController {
}
}
modelService.NewTable(tableVO);
return new ResponseEntity(HttpStatus.ACCEPTED);
return new ResponseEntity(HttpStatus.OK);
}
@PostMapping("/insertValues")
......
package com.tykj.workflowcore.model_layer.controller;
import com.tykj.workflowcore.model_layer.dao.TableInfoDao;
import com.tykj.workflowcore.model_layer.model.TableInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* @ClassName TableInfoController
* @Description TODO
* @Author WWW
* @Date 2021/2/24 13:46
* @Version 1.0
*/
@RestController
@RequestMapping("/table")
public class TableInfoController {
@Autowired
private TableInfoDao tableInfoDao;
@PostMapping("/addTable")
public TableInfo addTable(@RequestParam("tableName") String tableName) {
TableInfo tableInfo = new TableInfo();
tableInfo.setName(tableName);
TableInfo save = tableInfoDao.save(tableInfo);
if (save!=null){
return save;
}
return null;
}
}
......@@ -52,12 +52,10 @@ public class TableInfo implements Serializable {
@Column(name = "xml",columnDefinition="TEXT")
private String XML;
@LastModifiedDate
@Column(nullable = false,name = "update_time")
@Column(name = "update_time")
private Date updateTime;
@CreatedDate
@Column(nullable = false, updatable = false,name = "create_time")
@Column(name = "create_time")
private Date createTime;
......
......@@ -16,8 +16,13 @@ import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.internal.SessionImpl;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
import org.hibernate.tool.schema.TargetType;
import org.hibernate.type.IntegerType;
import org.hibernate.type.StringType;
import org.hibernate.type.TimestampType;
import org.hibernate.type.Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.domain.Specification;
......@@ -37,6 +42,9 @@ import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
......@@ -182,12 +190,9 @@ public class ModelImpl implements ModelService {
map.keySet()) {
//查找对应的表
Specification spec = (Specification) (root, criteriaQuery, criteriaBuilder) -> {
Predicate equal = null;
if (StringUtils.isEmpty("Name")) {
Path name = root.get("Name");
equal = criteriaBuilder.equal(name, tableName);
}
Path name = root.get("Name");
equal = criteriaBuilder.equal(name, tableName);
return equal;
};
Optional one = tableInfoDao.findOne(spec);
......@@ -226,6 +231,35 @@ public class ModelImpl implements ModelService {
SessionFactory newSessionFactory = metadata.buildSessionFactory();
//保存对象
Session newSession = newSessionFactory.openSession();
SessionImpl session = (SessionImpl) newSession;
EntityPersister entityPersister = session.getEntityPersister(tableName, map);
Type[] propertyTypes = entityPersister.getPropertyTypes();
String[] propertyNames = entityPersister.getEntityPersister().getPropertyNames();
Object[] propertyValuesToInsert = entityPersister.getPropertyValuesToInsert(map, null, session);
for (int i = 0; i < propertyValuesToInsert.length; i++) {
Object value = propertyValuesToInsert[i];
Type propertyType = propertyTypes[i];
//先将Type转为java类
if (propertyType instanceof TimestampType){
try {
Date parse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse((String) value);
map.put(propertyNames[i],parse);
} catch (ParseException e) {
e.printStackTrace();
}
}
if (propertyType instanceof IntegerType){
//然后调用强转方法
}
if (propertyType instanceof StringType){
//然后调用强转方法
}
}
newSession.saveOrUpdate(tableName,map);
}
}
package com.tykj.workflowcore.workflow_editer.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @author zsp
* @version V1.0
* @class WebMvcConfig
* @packageName com.example.personnelmanager.common.config
* @data 2020/6/11
**/
@Configuration
public class WebMvcConfig {
@Value("${file.path}")
String filePath;
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOriginPatterns("*")
.allowCredentials(true)
.allowedMethods("GET", "POST", "DELETE", "PUT","PATCH")
.maxAge(3600);
}
/*
* 静态资源配置
**/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/file/**").addResourceLocations("file:" + filePath);
}
};
}
}
......@@ -61,8 +61,9 @@ public class WorkFlowServiceImpl implements WorkFlowService {
@Autowired
private NodePageService nodePageService;
@Value("${file.path}")
String path;
@Autowired
ClassLoader classLoader;
@Override
public String saveXml(@RequestParam("file") MultipartFile file) {
......@@ -77,8 +78,8 @@ public class WorkFlowServiceImpl implements WorkFlowService {
fileName = UUID.randomUUID() + suffixName;
System.out.println(fileName);
//指定本地存入路径
File fileNew = new File(path + fileName);
realPath = path+fileName;
File fileNew = new File(classLoader.getResource("").getPath() + fileName);
realPath = classLoader.getResource("").getPath()+fileName;
try {
file.transferTo(fileNew);
} catch (IOException e) {
......@@ -133,8 +134,6 @@ public class WorkFlowServiceImpl implements WorkFlowService {
Long id = flowsInfoVo.getId();
String flowKey = flowsInfoVo.getFlowKey();
String fileXml = flowsInfoVo.getFileXml();
// String flowName = flowsInfoVo.getFlowName();
// String flowDescribe = flowsInfoVo.getFlowDescribe();
List<NodePage> nodePages = flowsInfoVo.getNodePages();
for (NodePage nodePage : nodePages) {
......@@ -143,7 +142,7 @@ public class WorkFlowServiceImpl implements WorkFlowService {
//生成xml文件
File f = null;
try {
f = new File(path+"/xml/"+flowKey+"bpmn20.xml");
f = new File(classLoader.getResource("").getPath()+"/xml/"+flowKey+"bpmn20.xml");
// 判断文件是否存在
if(!f.exists()){
f.createNewFile();
......@@ -186,7 +185,7 @@ public class WorkFlowServiceImpl implements WorkFlowService {
flowsInfo.setCreateTime(new Date());
//状态为未部署
flowsInfo.setState(1);
flowsInfo.setFilePath(path+"/xml/"+flowKey+"bpmn20.xml");
flowsInfo.setFilePath(classLoader.getResource("").getPath()+"/xml/"+flowKey+"bpmn20.xml");
flowsInfo.setId(id);
//更新并保存
flowsInfoMapper.save(flowsInfo);
......
spring:
datasource:
username: root
password: Huang123+
url: jdbc:mysql://47.106.142.73:3306/www?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8&nullCatalogMeansCurrent=true
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
show-sql: true
hibernate:
ddl-auto: update
\ No newline at end of file
package com.tykj.workflowcore;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class WorkflowCoreApplicationTests {
@Test
void contextLoads() {
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论