Commit f327ac0a authored by 覃振观's avatar 覃振观 👶

23-12-12: 下班前提交

parent 88ffcd84
...@@ -55,12 +55,12 @@ function faceGrid(elId, data) { ...@@ -55,12 +55,12 @@ function faceGrid(elId, data) {
function save() { function save() {
checkUpdata(); checkUpdata();
debugger;
let upData = window.dataSet.upData; let upData = window.dataSet.upData;
if(!upData) { return; } if(!upData) { return; }
Public.ajax(web_app.name + "/product/saveProductAndDetail.ajax", { Public.ajax(web_app.name + "/product/saveOrUpdataOnAllDetail.ajax", {
data: JSON.stringify(upData) data: JSON.stringify(upData)
}, function (data) { }, function (data) {
debugger;
}); });
} }
...@@ -90,6 +90,7 @@ function loadDataTest() { ...@@ -90,6 +90,7 @@ function loadDataTest() {
data: params.get("data") data: params.get("data")
}, function (data) { }, function (data) {
var showData = mapping(dataMapping, data.rawData); var showData = mapping(dataMapping, data.rawData);
debugger;
$('#submitForm').formSet(showData); $('#submitForm').formSet(showData);
var fronData = {}; var fronData = {};
fronData.Rows = data.fronColors; fronData.Rows = data.fronColors;
...@@ -116,17 +117,25 @@ var dataMapping = { ...@@ -116,17 +117,25 @@ var dataMapping = {
"productLength" "productLength"
, "productWidth" , "productWidth"
], ],
// ProductLoss: [ ProductPublishedConf: [
// "customerName" "rowNum"
// ], , "modulus"
]
} }
/** /**
* 遍历映射配置,构建映射关系 * 遍历映射配置,构建映射关系
* @param dataMapping 映射配置 * @param dataMapping 映射配置
* @param rawData 源数据 * @param rawData 源数据:    若有此输入,将认为当前是更新动作、  无此输入则认为当前是插入动作
*/ */
function mapping(dataMapping, rawData) { function mapping(dataMapping, rawData) {
window.dataSet = {};
if(!rawData) {
window.dataSet.isInsert = true;
var rawData = {};
}else {
window.dataSet.isInsert = false;
}
let mapper = {}; let mapper = {};
delete dataMapping.Mapper; delete dataMapping.Mapper;
let entitySet = Object.entries(dataMapping); let entitySet = Object.entries(dataMapping);
...@@ -134,6 +143,7 @@ function mapping(dataMapping, rawData) { ...@@ -134,6 +143,7 @@ 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) => {
...@@ -141,9 +151,6 @@ function mapping(dataMapping, rawData) { ...@@ -141,9 +151,6 @@ function mapping(dataMapping, rawData) {
if(!isExist(entityData, item, beanName)) { throw {}; } if(!isExist(entityData, item, beanName)) { throw {}; }
let value = entityData[item]; let value = entityData[item];
mapper[item] = beanName; mapper[item] = beanName;
if(item === "factoryName") {
console.log('1')
}
returnData[item] = value; returnData[item] = value;
console.log(item); console.log(item);
return; return;
...@@ -168,7 +175,6 @@ function mapping(dataMapping, rawData) { ...@@ -168,7 +175,6 @@ function mapping(dataMapping, rawData) {
// 这里写死 映射对象为:‘dataMapping’ // 这里写死 映射对象为:‘dataMapping’
window.dataMapping = dataMapping; window.dataMapping = dataMapping;
// 这里写死 数据集:‘dataSet: { rawData: {}, newData: {} }’ // 这里写死 数据集:‘dataSet: { rawData: {}, newData: {} }’
window.dataSet = {};
window.dataSet.rawData = rawData; window.dataSet.rawData = rawData;
window.dataSet.newData = JSON.parse(JSON.stringify(dataSet.rawData)); window.dataSet.newData = JSON.parse(JSON.stringify(dataSet.rawData));
return returnData; return returnData;
...@@ -184,16 +190,21 @@ Array.prototype.tryForEach = function (callback, thisArg) { ...@@ -184,16 +190,21 @@ Array.prototype.tryForEach = function (callback, thisArg) {
* 检测数据中是否存在对应属性 * 检测数据中是否存在对应属性
* @param obj 需要检测数据 * @param obj 需要检测数据
* @param property 需要检测的属性 * @param property 需要检测的属性
* @param objName 检测的 * @param objName 检测的对象
* @returns {boolean} * @returns {boolean}
*/ */
function isExist(obj, property, objName) { function isExist(obj, property, objName) {
if(window.dataSet.isInsert) {
obj[property] = {};
return true;
} else {
if(!objName) { objName = 'rawData'; } if(!objName) { objName = 'rawData'; }
// 这里注意,后端返回的类名是否与映射配置一致 // 这里注意,后端返回的类名是否与映射配置一致
if(!obj[property]) { if(!obj[property]) {
console.error('No data for name of ' + property + ' in ' + objName + ' !'); console.error('No data for name of ' + property + ' in ' + objName + ' !');
return false; return false;
} }
}
return true; return true;
} }
......
...@@ -40,13 +40,13 @@ ...@@ -40,13 +40,13 @@
<div class="ui-tab-content" style="padding: 2px; padding-right: 0;"> <div class="ui-tab-content" style="padding: 2px; padding-right: 0;">
<div class="layout" id='detailFormDiv'> <div class="layout" id='detailFormDiv'>
<x:inputC name="factoryName" required="true" label="制造工厂" labelCol="2" maxLength="64" fieldCol="4" /> <x:inputC name="factoryName" required="true" label="制造工厂" labelCol="2" maxLength="64" fieldCol="4" />
<x:inputC name="customerName" required="true" label="客户名称" labelCol="2" maxLength="64" fieldCol="4" /> <%-- <x:inputC name="customerName" required="true" label="客户名称" labelCol="2" maxLength="64" fieldCol="4" />--%>
<x:title title="外观描述" name="group" hideTable="#info" /> <x:title title="外观描述" name="group" hideTable="#info" />
<x:inputC name="productLength" required="true" label="长度" labelCol="2" maxLength="64" fieldCol="4" /> <x:inputC name="productLength" required="true" label="长度" labelCol="2" maxLength="64" fieldCol="4" />
<x:inputC name="productWidth" required="true" label="宽度" labelCol="2" maxLength="64" fieldCol="4" /> <x:inputC name="productWidth" required="true" label="宽度" labelCol="2" maxLength="64" fieldCol="4" />
<x:title title="排版参数" name="group" hideTable="#info" /> <x:title title="排版参数" name="group" hideTable="#info" />
<x:inputC name="modulus" required="true" label="模数" labelCol="2" maxLength="64" fieldCol="4" /> <x:inputC name="modulus" required="true" label="模数" labelCol="2" maxLength="64" fieldCol="4" />
<x:inputC name="row_num" required="true" label="行数" labelCol="2" maxLength="64" fieldCol="4" /> <x:inputC name="rowNum" required="true" label="行数" labelCol="2" maxLength="64" fieldCol="4" />
<div id="layout" style="height: 280px; display: contents;"> <div id="layout" style="height: 280px; display: contents;">
<div position="left" title="正面颜色" > <div position="left" title="正面颜色" >
......
...@@ -2,6 +2,7 @@ package com.huigou.topsun.product.application.impl; ...@@ -2,6 +2,7 @@ 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,6 +11,9 @@ import lombok.RequiredArgsConstructor; ...@@ -10,6 +11,9 @@ 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 javax.persistence.EntityManager;
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;
...@@ -17,25 +21,29 @@ import java.util.*; ...@@ -17,25 +21,29 @@ import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
// @RequiredArgsConstructor 通过构造方法注入 ProductApplication(Class a) { this.a = a; }
/** /**
* @author 16508 * @author 16508
* @description 针对表【product(产品)】的数据库操作Service实现 * @description 针对表【product(产品)】的数据库操作Service实现
* @@createDate 2023-11-22 10:24:31 * @createDate 2023-11-22 10:24:31
*/ */
@Service @Service
@RequiredArgsConstructor //通过构造方法注入 ProductApplication(Class a) { this.a = a; } @RequiredArgsConstructor
public class ProductApplicationImpl implements ProductApplication { public class ProductApplicationImpl implements ProductApplication {
private final ObjectMapper objectMapper; private final ObjectMapper objectMapper;
private final Snowflake snowflake;
private final ProductRepository productRepository; private final ProductRepository productRepository;
private final ProductDetailRepository detailRepository; private final ProductDetailRepository detailRepository;
// 类型 // 类型
private final BrandRepository brandRepository; private final BrandRepository brandRepository;
private final FactoryRepository factoryRepository; private final FactoryRepository factoryRepository;
private final ColorRepository colorRepository; private final ColorRepository colorRepository;
private final ProductCategoryRepository categoryRepository; private final ProductCategoryRepository categoryRepository;
// 详细信息 // 详细信息
private final ProductTypesetConfRepository typesetConfRepository; private final ProductTypesetConfRepository typesetConfRepository;
private final ProductLookedRepository lookedRepository; private final ProductLookedRepository lookedRepository;
private final ProductPublishedConfRepository publishedConfRepository; private final ProductPublishedConfRepository publishedConfRepository;
...@@ -69,10 +77,6 @@ public class ProductApplicationImpl implements ProductApplication { ...@@ -69,10 +77,6 @@ public class ProductApplicationImpl implements ProductApplication {
Map<String, Object> resultMap = new HashMap<>(200); Map<String, Object> resultMap = new HashMap<>(200);
Long productId = product.getProductId(); Long productId = product.getProductId();
ProductDetail productDetail = detailRepository.findByProductId(productId); ProductDetail productDetail = detailRepository.findByProductId(productId);
// EntityManager manager = JPAUtils.getEntityManger();
// manager.getTransaction().begin();
// manager.flush();
// manager.close();
// --------------------------------- 类别查询 --------------------------------- // --------------------------------- 类别查询 ---------------------------------
ArrayList<Brand> brands = (ArrayList<Brand>)brandRepository.findAll(); ArrayList<Brand> brands = (ArrayList<Brand>)brandRepository.findAll();
...@@ -138,8 +142,41 @@ public class ProductApplicationImpl implements ProductApplication { ...@@ -138,8 +142,41 @@ public class ProductApplicationImpl implements ProductApplication {
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;
EntityManager manager = JPAUtils.getEntityManger();
try {
transaction = manager.getTransaction();
transaction.begin();
if(product != null) { if(product != null) {
product.getProductId(); Long id = product.getProductId();
if(id == null) {
product.setProductId(Snowflake.nextId());
manager.persist(product);
}
}
if(productDetail != null) {
Long id = productDetail.getProductDetailId();
if(id == null) {
productDetail.setProductDetailId(Snowflake.nextId());
manager.persist(productDetail);
}
}
if(productLooked != null) {
Long id = productLooked.getProductLookedId();
if(id == null) {
productLooked.setProductLookedId(Snowflake.nextId());
manager.persist(productLooked);
}
}
manager.flush();
} catch (Exception e) {
assert transaction != null;
transaction.rollback();
throw new RuntimeException(e);
} finally {
manager.close();
} }
return null; return null;
......
...@@ -12,7 +12,7 @@ public class Snowflake { ...@@ -12,7 +12,7 @@ public class Snowflake {
// 开始时间 // 开始时间
private static final long OFFSET = 1686211627000L; private static final long OFFSET = 1686211627000L;
private static long WORKER_ID ; private static long WORKER_ID = 1L;
/** 机器ID位 **/ /** 机器ID位 **/
private static final long WORKER_ID_BITS = 4L; private static final long WORKER_ID_BITS = 4L;
...@@ -28,9 +28,9 @@ public class Snowflake { ...@@ -28,9 +28,9 @@ public class Snowflake {
private static long lastTimestamp = 0L; private static long lastTimestamp = 0L;
private static long sequence = 0L; private static long sequence = 0L;
public Snowflake(long workerId) { // public Snowflake(long workerId) {
WORKER_ID = workerId; // WORKER_ID = workerId;
} // }
public static synchronized long nextId() { public static synchronized long nextId() {
long timestamp = timeGen(); long timestamp = timeGen();
......
...@@ -18,7 +18,7 @@ public class TestSnowflake { ...@@ -18,7 +18,7 @@ public class TestSnowflake {
generateTest(); generateTest();
new Snowflake(1); // new Snowflake(1);
final Long id = Snowflake.nextId(); final Long id = Snowflake.nextId();
Date date = new Date(); Date date = new Date();
date.setTime( (id>>18) + 1686211627000L ); date.setTime( (id>>18) + 1686211627000L );
...@@ -55,11 +55,12 @@ public class TestSnowflake { ...@@ -55,11 +55,12 @@ public class TestSnowflake {
public class TreadA extends Thread { public class TreadA extends Thread {
@Override
public void run() { public void run() {
super.run(); super.run();
//long timestamp = timeGen(); //long timestamp = timeGen();
for(int i = 0; i < 30000; i++) { for(int i = 0; i < 30000; i++) {
new Snowflake(1); // new Snowflake(1);
long id = Snowflake.nextId(); long id = Snowflake.nextId();
list.add(id); list.add(id);
} }
...@@ -69,10 +70,11 @@ public class TestSnowflake { ...@@ -69,10 +70,11 @@ public class TestSnowflake {
public class TreadB extends Thread { public class TreadB extends Thread {
@Override
public void run() { public void run() {
super.run(); super.run();
for(int i = 0; i < 30000; i++) { for(int i = 0; i < 30000; i++) {
new Snowflake(1); // new Snowflake(1);
long id = Snowflake.nextId(); long id = Snowflake.nextId();
list.add(id); list.add(id);
} }
......
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