提交 c8ac74d4 authored 作者: ww1xhqc's avatar ww1xhqc

[数据模型] 返回聚合对象json。

上级 0b940794
package com.tykj.workflowcore.model_layer.controller;
import com.tykj.workflowcore.base.result.ResultObj;
import com.tykj.workflowcore.base.result.ResultUtil;
import com.tykj.workflowcore.model_layer.entity.vo.AggregationVO;
import com.tykj.workflowcore.model_layer.service.AggregationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
......@@ -22,7 +25,8 @@ public class AggregationController {
AggregationService aggregationService;
@PostMapping("aggregation/add")
public void add(@RequestBody AggregationVO aggregationVO) {
public ResponseEntity add(@RequestBody AggregationVO aggregationVO) {
aggregationService.addAggregation(aggregationVO);
return ResultUtil.success("","保存成功!");
}
}
package com.tykj.workflowcore.model_layer.service.impl;
import com.tykj.workflowcore.base.result.ApiException;
import com.tykj.workflowcore.model_layer.dao.AggregationRelationshipDao;
import com.tykj.workflowcore.model_layer.dao.AggregationDao;
import com.tykj.workflowcore.model_layer.dao.TableInfoDao;
import com.tykj.workflowcore.model_layer.dao.TableInfoExDao;
......@@ -35,7 +36,7 @@ public class AggregationImpl implements AggregationService {
@Autowired
TableInfoExDao tableInfoExDao;
@Autowired
AggregationRelationshipDao aggregationRelationshipDao;
AggregationDao aggregationRelationshipDao;
@Override
public void addAggregation(AggregationVO aggregationVO) {
......@@ -67,7 +68,7 @@ public class AggregationImpl implements AggregationService {
}
if (aggregationRelationship.getRelationship().equals(AggregationType.ONE_TO_MANY)){
//如果是一对多需要 为 aggregationRelationship 生成连接的KEY
String mainTableConnectionKey = sideTableById.get().getModelName()+"_list";
String mainTableConnectionKey = sideTableById.get().getModelName();
Document document = AggregationUtil.addOneToMany(sideTableById.get().getModelName(), mainTableConnectionKey, aggregationRelationship.getSideTableConnectionKey(), mainTableDocument);
tableInfoEx.setXml(document.asXML());
}
......
package com.tykj.workflowcore;
import com.alibaba.fastjson.JSON;
import com.tykj.workflowcore.model_layer.controller.ModelController;
import com.tykj.workflowcore.model_layer.dao.TableInfoDao;
import com.tykj.workflowcore.model_layer.dao.TableInfoExDao;
import com.tykj.workflowcore.model_layer.entity.TableInfo;
import com.tykj.workflowcore.model_layer.entity.vo.TableAndColumnInfoVO;
import com.tykj.workflowcore.model_layer.myEnum.ModelType;
import com.tykj.workflowcore.model_layer.service.ModelService;
import com.tykj.workflowcore.model_layer.service.impl.ModelHelper;
import com.tykj.workflowcore.model_layer.utils.AggregationUtil;
import com.tykj.workflowcore.model_layer.utils.SessionUtil;
import org.aspectj.lang.annotation.Before;
......@@ -23,6 +26,7 @@ import org.hibernate.query.NativeQuery;
import org.hibernate.query.Query;
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
import org.hibernate.tool.schema.TargetType;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
......@@ -77,6 +81,12 @@ class WorkflowCoreApplicationTests {
@Autowired
SessionUtil sessionUtil;
@Autowired
ModelHelper modelHelper;
@Autowired
TableInfoExDao tableInfoExDao;
@Before("")
public void setUp() {
mockMvc = MockMvcBuilders.standaloneSetup(modelController).build();
......@@ -314,7 +324,7 @@ class WorkflowCoreApplicationTests {
carMap.put("card", 1);
arrayList.add(carMap);
SessionImpl news= (SessionImpl) session;
SessionImpl news = (SessionImpl) session;
hashMap.put("carList", arrayList);
......@@ -415,7 +425,7 @@ class WorkflowCoreApplicationTests {
//创建解析器
Document document = DocumentHelper.parseText(xml);
Element classMapping = document.getRootElement().elements().get(0);
String set=" <set name=\"teacher\" table=\"stu_teacher_ref\">\n" +
String set = " <set name=\"teacher\" table=\"stu_teacher_ref\">\n" +
" \t<key column=\"student_id\"/>\n" +
" \t<many-to-many class=\"teacher\" column=\"teacher_id\"/>\n" +
" </set>\n";
......@@ -443,7 +453,7 @@ class WorkflowCoreApplicationTests {
}
}
// @Test
// @Test
// public void tsetCreateXml1(){
// TableInfo wife = tableInfoDao.findByModelName("car");
//// System.out.println(wife);
......@@ -466,5 +476,16 @@ class WorkflowCoreApplicationTests {
// String s = AggregationUtil.addManyToMany("teacher", "stus", xml);
// System.out.println(s);
// }
@Test
public void testJSON() {
String xml = tableInfoExDao.findById(3).get().getXml();
sessionUtil.addXml(xml);
Session session = sessionUtil.getSession();
List list = session.createQuery("from people_car").list();
System.out.println(list);
String jsonExample = modelHelper.getJsonExample(2);
System.out.println(jsonExample);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论