Commit 836fb0f9 authored by 覃振观's avatar 覃振观 👶

23-12-13: 下班前提交

parent f327ac0a
...@@ -27,6 +27,9 @@ function initializeUI() { ...@@ -27,6 +27,9 @@ function initializeUI() {
function faceGrid(elId, data) { function faceGrid(elId, data) {
var toolbarOptions = UICtrl.getDefaultToolbarOptions({ var toolbarOptions = UICtrl.getDefaultToolbarOptions({
addHandler: function(){
UICtrl.addGridRow(gridManager);
},
updateHandler: function(){ updateHandler: function(){
updateHandler(); updateHandler();
}, },
...@@ -38,17 +41,22 @@ function faceGrid(elId, data) { ...@@ -38,17 +41,22 @@ function faceGrid(elId, data) {
}); });
var gridManager = UICtrl.grid(elId, { var gridManager = UICtrl.grid(elId, {
columns: [ columns: [
{ display: "颜色名称", name: "productFaceColorId", width: 140, minWidth: 60, type: "string", align: "left" }, { display: "颜色名称", name: "productFaceColorId", width: 140, minWidth: 60, type: "string", align: "left", editor: {
{ display: "油墨覆盖率(%)", name: "coverageRate", width: 120, minWidth: 60, type: "string", align: "left" } type: 'text',
required: true
}},
{ display: "油墨覆盖率(%)", name: "coverageRate", width: 120, minWidth: 60, type: "string", align: "left", editor: { type: 'text', required: true } }
], ],
toolbar: toolbarOptions, toolbar: toolbarOptions,
dataType: "local", dataType: "local",
data: data, // data 数据结构 data: ("Rows": [ {}, {} ]) data: data, // data 数据结构 data: ("Rows": [ {}, {} ])
enabledEdit: true,
checkbox: true,
usePager: false, usePager: false,
width: "100%", width: "100%",
height: 150, height: 150,
onDblClickRow : function(data, rowindex, rowobj) { onDblClickRow : function(data, rowindex, rowobj) {
updateHandler(data);
} }
}); });
} }
...@@ -93,7 +101,7 @@ function loadDataTest() { ...@@ -93,7 +101,7 @@ function loadDataTest() {
debugger; debugger;
$('#submitForm').formSet(showData); $('#submitForm').formSet(showData);
var fronData = {}; var fronData = {};
fronData.Rows = data.fronColors; fronData.Rows = data.rawData.fronColors;
faceGrid("#frontFaceGrid", fronData); faceGrid("#frontFaceGrid", fronData);
fronData.Rows = data.backColors; fronData.Rows = data.backColors;
faceGrid("#backFaceGrid", fronData); faceGrid("#backFaceGrid", fronData);
...@@ -120,6 +128,9 @@ var dataMapping = { ...@@ -120,6 +128,9 @@ var dataMapping = {
ProductPublishedConf: [ ProductPublishedConf: [
"rowNum" "rowNum"
, "modulus" , "modulus"
],
fronColors: [
[ "productFaceColorId", "coverageRate" ]
] ]
} }
...@@ -143,7 +154,6 @@ function mapping(dataMapping, rawData) { ...@@ -143,7 +154,6 @@ function mapping(dataMapping, rawData) {
entitySet.tryForEach((entity, index) => { entitySet.tryForEach((entity, index) => {
let beanName = entity[0]; let beanName = entity[0];
if(!isExist(rawData, beanName)) { throw {}; } if(!isExist(rawData, beanName)) { throw {}; }
debugger;
let entityData = rawData[beanName]; let entityData = rawData[beanName];
let propertyNames = entity[1]; let propertyNames = entity[1];
propertyNames.tryForEach((item, index) => { propertyNames.tryForEach((item, index) => {
...@@ -154,6 +164,9 @@ function mapping(dataMapping, rawData) { ...@@ -154,6 +164,9 @@ function mapping(dataMapping, rawData) {
returnData[item] = value; returnData[item] = value;
console.log(item); console.log(item);
return; return;
} else if(item instanceof Array) {
debugger;
return;
} else if(item instanceof Object) { } else if(item instanceof Object) {
let entry = Object.entries(item)[0]; let entry = Object.entries(item)[0];
let property = entry[0]; let property = entry[0];
......
...@@ -19,6 +19,4 @@ public class AppConfig { ...@@ -19,6 +19,4 @@ public class AppConfig {
return new ObjectMapper(); return new ObjectMapper();
} }
@Bean
public Snowflake snowflake() { return new Snowflake(1); }
} }
\ No newline at end of file
package com.huigou.topsun.config;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
/**
* JPAUtils 用于管理 JPA EntityManager 创建工厂
*
* @author qinzhenguan
* @createDate 2023/11/28 08:58
**/
public class JPAUtils {
public static EntityManagerFactory emf = createEntityManagerFactory();
private static EntityManagerFactory createEntityManagerFactory() {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("mysql-jpa");
return emf;
}
public static EntityManager getEntityManger(){
EntityManager entityManager = emf.createEntityManager();
return entityManager;
}
}
\ No newline at end of file
...@@ -2,7 +2,6 @@ package com.huigou.topsun.product.application.impl; ...@@ -2,7 +2,6 @@ package com.huigou.topsun.product.application.impl;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.huigou.topsun.config.JPAUtils;
import com.huigou.topsun.product.application.ProductApplication; import com.huigou.topsun.product.application.ProductApplication;
import com.huigou.topsun.product.domain.*; import com.huigou.topsun.product.domain.*;
import com.huigou.topsun.product.repository.*; import com.huigou.topsun.product.repository.*;
...@@ -10,10 +9,9 @@ import com.huigou.topsun.util.Snowflake; ...@@ -10,10 +9,9 @@ import com.huigou.topsun.util.Snowflake;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager; import javax.persistence.*;
import javax.persistence.EntityTransaction;
import javax.transaction.Transaction;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
...@@ -31,6 +29,10 @@ import java.util.stream.Collectors; ...@@ -31,6 +29,10 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor @RequiredArgsConstructor
public class ProductApplicationImpl implements ProductApplication { public class ProductApplicationImpl implements ProductApplication {
@PersistenceContext(unitName = "system")
private EntityManager entityManager;
// private final EntityManagerFactory entityManagerFactory;
private final ObjectMapper objectMapper; private final ObjectMapper objectMapper;
private final ProductRepository productRepository; private final ProductRepository productRepository;
private final ProductDetailRepository detailRepository; private final ProductDetailRepository detailRepository;
...@@ -94,11 +96,11 @@ public class ProductApplicationImpl implements ProductApplication { ...@@ -94,11 +96,11 @@ public class ProductApplicationImpl implements ProductApplication {
entitys.add(publishedConfRepository.findByProductId(productId)); entitys.add(publishedConfRepository.findByProductId(productId));
entitys.add(productDetail); entitys.add(productDetail);
entitys.add(product); entitys.add(product);
entitys.add(loss);
entitys.add(material);
HashMap<String, Object> listMaps = new HashMap<>(100); Map<String, Object> assemble = assembleResultOfForm(entitys);
resultMap.put("rawData", assembleResultOfForm(entitys)); resultMap.put("rawData", assemble);
listMaps.put("loss", loss);
listMaps.put("material", material);
// --------------------------------- 版面查询 --------------------------------- // --------------------------------- 版面查询 ---------------------------------
if(productDetail != null) { if(productDetail != null) {
...@@ -106,24 +108,25 @@ public class ProductApplicationImpl implements ProductApplication { ...@@ -106,24 +108,25 @@ public class ProductApplicationImpl implements ProductApplication {
ProductFace frontFace = faceRepository.findByProductFaceIdEquals(productDetail.getBackProductFaceId()); ProductFace frontFace = faceRepository.findByProductFaceIdEquals(productDetail.getBackProductFaceId());
ArrayList <ProductFaceColor> fronColors = ArrayList <ProductFaceColor> fronColors =
(ArrayList<ProductFaceColor>) faceColorRepository.findByProductFaceId(productDetail.getBackProductFaceId()); (ArrayList<ProductFaceColor>) faceColorRepository.findByProductFaceId(productDetail.getBackProductFaceId());
resultMap.put("frontFace", frontFace); assemble.put("frontFace", frontFace);
listMaps.put("fronColors", fronColors == null ? new ArrayList<>() : fronColors); assemble.put("fronColors", fronColors == null ? new ArrayList<>() : fronColors);
} else { } else {
ProductFaceColor fc = new ProductFaceColor(); ProductFaceColor fc = new ProductFaceColor();
fc.setProductFaceColorId(111L); fc.setProductFaceColorId(111L);
ArrayList<ProductFaceColor> fronColors = new ArrayList<>(); ArrayList<ProductFaceColor> fronColors = new ArrayList<>();
fronColors.add(fc); fronColors.add(fc);
listMaps.put("fronColors", fronColors); assemble.put("fronColors", fronColors);
} }
if(productDetail.getBackProductFaceId() != null) { if(productDetail.getBackProductFaceId() != null) {
ProductFace backFace = faceRepository.findByProductFaceIdEquals(productDetail.getBackProductFaceId()); ProductFace backFace = faceRepository.findByProductFaceIdEquals(productDetail.getBackProductFaceId());
ArrayList <ProductFaceColor> backColors = ArrayList <ProductFaceColor> backColors =
(ArrayList<ProductFaceColor>) faceColorRepository.findByProductFaceId(productDetail.getBackProductFaceId()); (ArrayList<ProductFaceColor>) faceColorRepository.findByProductFaceId(productDetail.getBackProductFaceId());
resultMap.put("backFace", backFace); assemble.put("backFace", backFace);
listMaps.put("backColors", backColors == null ? new ArrayList<>() : backColors); assemble.put("backColors", backColors == null ? new ArrayList<>() : backColors);
} }
} }
HashMap<String, Object> listMaps = new HashMap<>(100);
listMaps.put("selectedBrand", objectMapper.convertValue(brands, List.class)); listMaps.put("selectedBrand", objectMapper.convertValue(brands, List.class));
listMaps.put("selectedFactory", objectMapper.convertValue(factorys, List.class)); listMaps.put("selectedFactory", objectMapper.convertValue(factorys, List.class));
listMaps.put("selectedColor", objectMapper.convertValue(colors, List.class)); listMaps.put("selectedColor", objectMapper.convertValue(colors, List.class));
...@@ -138,66 +141,65 @@ public class ProductApplicationImpl implements ProductApplication { ...@@ -138,66 +141,65 @@ public class ProductApplicationImpl implements ProductApplication {
} }
@Override @Override
@Transactional(transactionManager="transactionManager")
public HashMap<String, Object> saveOrUpdataOnAllDetail(HashMap<String, Object> newData) { public HashMap<String, Object> saveOrUpdataOnAllDetail(HashMap<String, Object> newData) {
Product product = objectMapper.convertValue(newData.get("Product"), Product.class); Product product = objectMapper.convertValue(newData.get("Product"), Product.class);
ProductDetail productDetail = objectMapper.convertValue(newData.get("ProductDetail"), ProductDetail.class); ProductDetail productDetail = objectMapper.convertValue(newData.get("ProductDetail"), ProductDetail.class);
ProductLooked productLooked = objectMapper.convertValue(newData.get("ProductLooked"), ProductLooked.class); ProductLooked productLooked = objectMapper.convertValue(newData.get("ProductLooked"), ProductLooked.class);
EntityTransaction transaction = null; TypedQuery<Product> query = entityManager.createQuery("SELECT s FROM Product s", Product.class);
EntityManager manager = JPAUtils.getEntityManger(); List<Product> products = query.getResultList();
try {
transaction = manager.getTransaction();
transaction.begin();
if(product != null) { if(product != null) {
Long id = product.getProductId(); Long id = product.getProductId();
if(id == null) { if(id == null) {
product.setProductId(Snowflake.nextId()); product.setProductId(Snowflake.nextId());
manager.persist(product); entityManager.persist(product);
} }
entityManager.merge(product);
} }
if(productDetail != null) { if(productDetail != null) {
Long id = productDetail.getProductDetailId(); Long id = productDetail.getProductDetailId();
if(id == null) { if(id == null) {
productDetail.setProductDetailId(Snowflake.nextId()); productDetail.setProductDetailId(Snowflake.nextId());
manager.persist(productDetail); entityManager.persist(productDetail);
} }
entityManager.merge(productDetail);
} }
if(productLooked != null) { if(productLooked != null) {
Long id = productLooked.getProductLookedId(); Long id = productLooked.getProductLookedId();
if(id == null) { if(id == null) {
productLooked.setProductLookedId(Snowflake.nextId()); productLooked.setProductLookedId(Snowflake.nextId());
manager.persist(productLooked); entityManager.persist(productLooked);
}
} }
manager.flush(); entityManager.merge(productLooked);
} catch (Exception e) {
assert transaction != null;
transaction.rollback();
throw new RuntimeException(e);
} finally {
manager.close();
} }
// String str = null;
// str.length();
entityManager.flush();
return null; return null;
} }
/** /**
* description 返回页面 Form 所需的数据格式 * description 返回页面 Form 所需的数据格式
* @param entitys 所有相关的 实体 (如果需要 update,保留这些实体。提交时候用于比较更新值。) * @param entitys 所有相关的 实体。 必须为 JavaBean 调用了 .getClass().getSimpleName()
* @return java.util.HashMap<java.lang.String, java.lang.Object> * @return java.util.HashMap<java.lang.String, java.lang.Object>
* @author qinzhenguan * @author qinzhenguan
* @createDate 2023/12/5 14:09 * @createDate 2023/12/5 14:09
*/ */
public Map<String, Object> assembleResultOfForm(Set<Object> entitys) { public Map<String, Object> assembleResultOfForm(Set<Object> entitys) {
Map<String, Object> map = new HashMap<>(1024); Map<String, Object> map = new HashMap<>(256);
for(Object item : entitys) { for(Object item : entitys) {
if(item == null) { if(item == null) {
continue; continue;
} }
map.put(item.getClass().getSimpleName(), objectMapper.convertValue(item, if(item instanceof List) {
new TypeReference<Map<? extends String, ?>>() {}) ); map.put((((List<?>) item).get(0)).getClass().getSimpleName(), objectMapper.convertValue(item, List.class));
} else {
map.put(item.getClass().getSimpleName(), objectMapper.convertValue(item, new TypeReference<Map<? extends String, ?>>() {}) );
}
// 这里要获取所有的属性名, 保存对应关系, 属性: 所属实体类; // 这里要获取所有的属性名, 保存对应关系, 属性: 所属实体类;
//map.putAll(mapper.convertValue(item, new TypeReference<Map<? extends String, ?>>() {})); //map.putAll(mapper.convertValue(item, new TypeReference<Map<? extends String, ?>>() {}));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment