Commit 834b90fb authored by 覃振观's avatar 覃振观 👶

23-12-12: 所有主键改为数字类型。产品编码使用单独字段显示。

parent 2deeb9f9
...@@ -54,12 +54,14 @@ function faceGrid(elId, data) { ...@@ -54,12 +54,14 @@ function faceGrid(elId, data) {
} }
function save() { function save() {
$('#submitForm').ajaxSubmit({ checkUpdata();
url: web_app.name + '/product/saveProductAndDetail.ajax', let upData = window.dataSet.upData;
param:{ rawData: JSON.stringify(rawData) }, if(!upData) { return; }
success: function(data) { Public.ajax(web_app.name + "/product/saveProductAndDetail.ajax", {
data: JSON.stringify(upData)
}, function (data) {
debugger; debugger;
}
}); });
} }
......
package com.huigou.topsun.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.huigou.topsun.util.Snowflake;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* AppConfig Bean配置
*
* @author qinzhenguan
* @createDate 2023/12/12 08:38
**/
@Configuration
public class AppConfig {
@Bean
public ObjectMapper objectMapper() {
return new ObjectMapper();
}
@Bean
public Snowflake snowflake() { return new Snowflake(1); }
}
\ No newline at end of file
...@@ -8,7 +8,7 @@ import javax.persistence.Persistence; ...@@ -8,7 +8,7 @@ import javax.persistence.Persistence;
* JPAUtils 用于管理 JPA EntityManager 创建工厂 * JPAUtils 用于管理 JPA EntityManager 创建工厂
* *
* @author qinzhenguan * @author qinzhenguan
* @create 2023/11/28 08:58 * @createDate 2023/11/28 08:58
**/ **/
public class JPAUtils { public class JPAUtils {
......
...@@ -34,11 +34,11 @@ public interface ProductApplication { ...@@ -34,11 +34,11 @@ public interface ProductApplication {
/** /**
* description 对比所有对象,并保存更改的数据。 * description 对比所有对象,并保存更改的数据。
*
* @param rawMap 原数据 * @param rawMap 原数据
* @param updateMap 提交的数据
* @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/8 17:19 * @createDate 2023/12/8 17:19
*/ */
HashMap<String, Object> saveProductAndDetail(HashMap<String, Object> rawMap, HashMap<String, Object> updateMap); HashMap<String, Object> saveOrUpdataOnAllDetail(HashMap<String, Object> newData);
} }
package com.huigou.topsun.product.controller; package com.huigou.topsun.product.controller;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.DeserializationFeature;
...@@ -31,6 +30,9 @@ public class ProductController extends CommonController { ...@@ -31,6 +30,9 @@ public class ProductController extends CommonController {
@Autowired @Autowired
private ProductApplication productService; private ProductApplication productService;
@Autowired
private ObjectMapper objectMapper;
@Override @Override
protected String getPagePath() { protected String getPagePath() {
return "/biz/topsun/product/"; return "/biz/topsun/product/";
...@@ -56,16 +58,15 @@ public class ProductController extends CommonController { ...@@ -56,16 +58,15 @@ public class ProductController extends CommonController {
map4.put("六六六", "666"); map4.put("六六六", "666");
map4.put("七七七", "777"); map4.put("七七七", "777");
map4.put("八八八", "888"); map4.put("八八八", "888");
this.putAttribute("selectedCategory", map4);
return forward("product"); return forward("product");
} }
public String forwardProductDetail() { public String forwardProductDetail() {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
SDO sdo = this.getSDO(); SDO sdo = this.getSDO();
HashMap<String, Object> param; HashMap<String, Object> param;
try { try {
param = mapper.readValue(sdo.getString("data"), new TypeReference<HashMap<String, Object>>() {}); param = objectMapper.readValue(sdo.getString("data"), new TypeReference<HashMap<String, Object>>() {});
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
...@@ -73,12 +74,11 @@ public class ProductController extends CommonController { ...@@ -73,12 +74,11 @@ public class ProductController extends CommonController {
} }
public String loadProductDetail() { public String loadProductDetail() {
ObjectMapper mapper = new ObjectMapper();
SDO sdo = this.getSDO(); SDO sdo = this.getSDO();
Product product ; Product product ;
try { try {
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
product = mapper.readValue(sdo.getString("data") + "", Product.class); product = objectMapper.readValue(sdo.getString("data") + "", Product.class);
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
...@@ -87,15 +87,15 @@ public class ProductController extends CommonController { ...@@ -87,15 +87,15 @@ public class ProductController extends CommonController {
return toResult(resultMap); return toResult(resultMap);
} }
public String saveProductAndDetail() throws JsonProcessingException { public String saveOrUpdataOnAllDetail() throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
SDO sdo = this.getSDO(); SDO sdo = this.getSDO();
String updateJson = sdo.toString(); HashMap<String, Object> newData;
HashMap<String,Object> updateMap = mapper.readValue(updateJson, new TypeReference<HashMap<String,Object>>() {}); try {
HashMap<String,Object> rawMap = mapper.readValue(updateMap.get("rawData") + "", new TypeReference<HashMap<String,Object>>() {}); newData = objectMapper.readValue(sdo.getString("data"), new TypeReference<HashMap<String, Object>>() {});
updateMap.remove("rawData"); } catch (JsonProcessingException e) {
throw new RuntimeException(e);
HashMap<String,Object> resultMap = productService.saveProductAndDetail(rawMap, updateMap); }
HashMap<String,Object> resultMap = productService.saveOrUpdataOnAllDetail(newData);
return success(resultMap); return success(resultMap);
} }
......
...@@ -18,7 +18,7 @@ public class Brand implements Serializable { ...@@ -18,7 +18,7 @@ public class Brand implements Serializable {
*/ */
@Id @Id
@Column(name = "brand_id") @Column(name = "brand_id")
private String brandId; private Long brandId;
/** /**
* 品牌名称 * 品牌名称
......
...@@ -18,7 +18,7 @@ public class Color implements Serializable { ...@@ -18,7 +18,7 @@ public class Color implements Serializable {
*/ */
@Id @Id
@Column(name = "color_id") @Column(name = "color_id")
private String colorId; private Long colorId;
/** /**
* 颜色名称 * 颜色名称
......
...@@ -18,7 +18,7 @@ public class Factory implements Serializable { ...@@ -18,7 +18,7 @@ public class Factory implements Serializable {
*/ */
@Id @Id
@Column(name = "factory_id") @Column(name = "factory_id")
private String factoryId; private Long factoryId;
/** /**
* 工厂名称 * 工厂名称
......
...@@ -21,8 +21,8 @@ public class Product implements Serializable { ...@@ -21,8 +21,8 @@ public class Product implements Serializable {
* 产品ID * 产品ID
*/ */
@Id @Id
@Column(name = "product_id", nullable = false, length = 32) @Column(name = "product_id", nullable = false)
private String productId; private Long productId;
/** /**
* 产品名称 * 产品名称
...@@ -170,11 +170,11 @@ public class Product implements Serializable { ...@@ -170,11 +170,11 @@ public class Product implements Serializable {
.toString(); .toString();
} }
public String getProductId() { public Long getProductId() {
return this.productId; return this.productId;
} }
public void setProductId(String productId) { public void setProductId(Long productId) {
this.productId = productId; this.productId = productId;
} }
......
...@@ -18,7 +18,7 @@ public class ProductCategory implements Serializable { ...@@ -18,7 +18,7 @@ public class ProductCategory implements Serializable {
*/ */
@Id @Id
@Column(name = "product_category_id") @Column(name = "product_category_id")
private String productCategoryId; private Long productCategoryId;
/** /**
* 产品类别名称 * 产品类别名称
......
...@@ -22,13 +22,13 @@ public class ProductDetail implements Serializable { ...@@ -22,13 +22,13 @@ public class ProductDetail implements Serializable {
*/ */
@Id @Id
@Column(name = "product_detail_id", nullable = false, length = 32) @Column(name = "product_detail_id", nullable = false, length = 32)
private String productDetailId; private Long productDetailId;
/** /**
* 产品ID * 产品ID
*/ */
@Column(name = "product_id", nullable = true, length = 32) @Column(name = "product_id", nullable = true, length = 32)
private String productId; private Long productId;
/** /**
* 工厂名称 * 工厂名称
...@@ -139,19 +139,19 @@ public class ProductDetail implements Serializable { ...@@ -139,19 +139,19 @@ public class ProductDetail implements Serializable {
.toString(); .toString();
} }
public String getProductDetailId() { public Long getProductDetailId() {
return this.productDetailId; return this.productDetailId;
} }
public void setProductDetailId(String productDetailId) { public void setProductDetailId(Long productDetailId) {
this.productDetailId = productDetailId; this.productDetailId = productDetailId;
} }
public String getProductId() { public Long getProductId() {
return this.productId; return this.productId;
} }
public void setProductId(String productId) { public void setProductId(Long productId) {
this.productId = productId; this.productId = productId;
} }
......
...@@ -18,7 +18,7 @@ public class ProductFace implements Serializable { ...@@ -18,7 +18,7 @@ public class ProductFace implements Serializable {
*/ */
@Id @Id
@Column(name = "product_face_id") @Column(name = "product_face_id")
private String productFaceId; private Long productFaceId;
/** /**
* 产品版面图片 * 产品版面图片
......
...@@ -18,19 +18,19 @@ public class ProductFaceColor implements Serializable { ...@@ -18,19 +18,19 @@ public class ProductFaceColor implements Serializable {
*/ */
@Id @Id
@Column(name = "product_face_color_id") @Column(name = "product_face_color_id")
private String productFaceColorId; private Long productFaceColorId;
/** /**
* 产品版面ID * 产品版面ID
*/ */
@Column(name = "product_face_id") @Column(name = "product_face_id")
private String productFaceId; private Long productFaceId;
/** /**
* 颜色ID * 颜色ID
*/ */
@Column(name = "color_id") @Column(name = "color_id")
private String colorId; private Long colorId;
/** /**
* 覆盖率(单位%) * 覆盖率(单位%)
......
...@@ -22,13 +22,13 @@ public class ProductLooked implements Serializable { ...@@ -22,13 +22,13 @@ public class ProductLooked implements Serializable {
*/ */
@Id @Id
@Column(name = "product_looked_id", nullable = false, length = 32) @Column(name = "product_looked_id", nullable = false, length = 32)
private String productLookedId; private Long productLookedId;
/** /**
* 产品ID * 产品ID
*/ */
@Column(name = "product_id", nullable = true, length = 32) @Column(name = "product_id", nullable = true, length = 32)
private String productId; private Long productId;
/** /**
* 长;单位cm * 长;单位cm
...@@ -169,19 +169,19 @@ public class ProductLooked implements Serializable { ...@@ -169,19 +169,19 @@ public class ProductLooked implements Serializable {
.toString(); .toString();
} }
public String getProductLookedId() { public Long getProductLookedId() {
return this.productLookedId; return this.productLookedId;
} }
public void setProductLookedId(String productLookedId) { public void setProductLookedId(Long productLookedId) {
this.productLookedId = productLookedId; this.productLookedId = productLookedId;
} }
public String getProductId() { public Long getProductId() {
return this.productId; return this.productId;
} }
public void setProductId(String productId) { public void setProductId(Long productId) {
this.productId = productId; this.productId = productId;
} }
......
...@@ -18,13 +18,13 @@ public class ProductLoss implements Serializable { ...@@ -18,13 +18,13 @@ public class ProductLoss implements Serializable {
*/ */
@Id @Id
@Column(name = "product_loss_id") @Column(name = "product_loss_id")
private String productLossId; private Long productLossId;
/** /**
* 产品ID * 产品ID
*/ */
@Column(name = "product_id") @Column(name = "product_id")
private String productId; private Long productId;
/** /**
* 产品最大loss数量 * 产品最大loss数量
......
...@@ -18,13 +18,13 @@ public class ProductMaterial implements Serializable { ...@@ -18,13 +18,13 @@ public class ProductMaterial implements Serializable {
*/ */
@Id @Id
@Column(name = "product_material_id") @Column(name = "product_material_id")
private String productMaterialId; private Long productMaterialId;
/** /**
* 产品ID * 产品ID
*/ */
@Column(name = "product_id") @Column(name = "product_id")
private String productId; private Long productId;
/** /**
* 物料ID * 物料ID
......
...@@ -22,13 +22,13 @@ public class ProductProcess implements Serializable { ...@@ -22,13 +22,13 @@ public class ProductProcess implements Serializable {
*/ */
@Id @Id
@Column(name = "product_process_id", nullable = false, length = 32) @Column(name = "product_process_id", nullable = false, length = 32)
private String productProcessId; private Long productProcessId;
/** /**
* 工艺id * 工艺id
*/ */
@Column(name = "product_technology_id", nullable = true, length = 32) @Column(name = "product_technology_id", nullable = true, length = 32)
private String productTechnologyId; private Long productTechnologyId;
/** /**
* 生成顺序 * 生成顺序
...@@ -92,19 +92,19 @@ public class ProductProcess implements Serializable { ...@@ -92,19 +92,19 @@ public class ProductProcess implements Serializable {
.toString(); .toString();
} }
public String getProductProcessId() { public Long getProductProcessId() {
return this.productProcessId; return this.productProcessId;
} }
public void setProductProcessId(String productProcessId) { public void setProductProcessId(Long productProcessId) {
this.productProcessId = productProcessId; this.productProcessId = productProcessId;
} }
public String getProductTechnologyId() { public Long getProductTechnologyId() {
return this.productTechnologyId; return this.productTechnologyId;
} }
public void setProductTechnologyId(String productTechnologyId) { public void setProductTechnologyId(Long productTechnologyId) {
this.productTechnologyId = productTechnologyId; this.productTechnologyId = productTechnologyId;
} }
......
...@@ -18,13 +18,13 @@ public class ProductPublishedConf implements Serializable { ...@@ -18,13 +18,13 @@ public class ProductPublishedConf implements Serializable {
*/ */
@Id @Id
@Column(name = "product_published_conf_id") @Column(name = "product_published_conf_id")
private String productPublishedConfId; private Long productPublishedConfId;
/** /**
* 产品ID * 产品ID
*/ */
@Column(name = "product_id") @Column(name = "product_id")
private String productId; private Long productId;
/** /**
* 模数 * 模数
......
...@@ -22,13 +22,13 @@ public class ProductRiskDescription implements Serializable { ...@@ -22,13 +22,13 @@ public class ProductRiskDescription implements Serializable {
*/ */
@Id @Id
@Column(name = "product_risk_description_id", nullable = false, length = 32) @Column(name = "product_risk_description_id", nullable = false, length = 32)
private String productRiskDescriptionId; private Long productRiskDescriptionId;
/** /**
* 产品id * 产品id
*/ */
@Column(name = "product_id", nullable = true, length = 32) @Column(name = "product_id", nullable = true, length = 32)
private String productId; private Long productId;
/** /**
* 序号 * 序号
...@@ -67,19 +67,19 @@ public class ProductRiskDescription implements Serializable { ...@@ -67,19 +67,19 @@ public class ProductRiskDescription implements Serializable {
.toString(); .toString();
} }
public String getProductRiskDescriptionId() { public Long getProductRiskDescriptionId() {
return this.productRiskDescriptionId; return this.productRiskDescriptionId;
} }
public void setProductRiskDescriptionId(String productRiskDescriptionId) { public void setProductRiskDescriptionId(Long productRiskDescriptionId) {
this.productRiskDescriptionId = productRiskDescriptionId; this.productRiskDescriptionId = productRiskDescriptionId;
} }
public String getProductId() { public Long getProductId() {
return this.productId; return this.productId;
} }
public void setProductId(String productId) { public void setProductId(Long productId) {
this.productId = productId; this.productId = productId;
} }
......
...@@ -21,14 +21,14 @@ public class ProductTechnology implements Serializable { ...@@ -21,14 +21,14 @@ public class ProductTechnology implements Serializable {
* 产品工艺id * 产品工艺id
*/ */
@Id @Id
@Column(name = "product_technology_id", nullable = false, length = 32) @Column(name = "product_technology_id", nullable = false)
private String productTechnologyId; private Long productTechnologyId;
/** /**
* 产品id * 产品id
*/ */
@Column(name = "product_id", nullable = true, length = 32) @Column(name = "product_id", nullable = true)
private String productId; private Long productId;
/** /**
* 产品工艺制程 * 产品工艺制程
...@@ -211,19 +211,19 @@ public class ProductTechnology implements Serializable { ...@@ -211,19 +211,19 @@ public class ProductTechnology implements Serializable {
.toString(); .toString();
} }
public String getProductTechnologyId() { public Long getProductTechnologyId() {
return this.productTechnologyId; return this.productTechnologyId;
} }
public void setProductTechnologyId(String productTechnologyId) { public void setProductTechnologyId(Long productTechnologyId) {
this.productTechnologyId = productTechnologyId; this.productTechnologyId = productTechnologyId;
} }
public String getProductId() { public Long getProductId() {
return this.productId; return this.productId;
} }
public void setProductId(String productId) { public void setProductId(Long productId) {
this.productId = productId; this.productId = productId;
} }
......
...@@ -18,13 +18,13 @@ public class ProductTypesetConf implements Serializable { ...@@ -18,13 +18,13 @@ public class ProductTypesetConf implements Serializable {
*/ */
@Id @Id
@Column(name = "product_typeset_conf_id") @Column(name = "product_typeset_conf_id")
private String productTypesetConfId; private Long productTypesetConfId;
/** /**
* 产品ID * 产品ID
*/ */
@Column(name = "product_id") @Column(name = "product_id")
private String productId; private Long productId;
/** /**
* 印张长度(单位cm) * 印张长度(单位cm)
......
...@@ -9,5 +9,5 @@ import org.springframework.data.jpa.repository.JpaRepository; ...@@ -9,5 +9,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
* @Description: * @Description:
*/ */
public interface ProductDetailRepository extends JpaRepository<ProductDetail,String> { public interface ProductDetailRepository extends JpaRepository<ProductDetail,String> {
ProductDetail findByProductId(String productId); ProductDetail findByProductId(Long productId);
} }
...@@ -10,8 +10,8 @@ import org.springframework.data.jpa.repository.JpaRepository; ...@@ -10,8 +10,8 @@ import org.springframework.data.jpa.repository.JpaRepository;
* @Description: * @Description:
*/ */
public interface ProductLookedRepository extends JpaRepository<ProductLooked,String> { public interface ProductLookedRepository extends JpaRepository<ProductLooked,String> {
ProductLooked findByProductId(String productId); ProductLooked findByProductId(Long productId);
ProductLooked findByProductIdEquals(String productId); ProductLooked findByProductIdEquals(Long productId);
} }
...@@ -11,6 +11,6 @@ import java.util.List; ...@@ -11,6 +11,6 @@ import java.util.List;
* @Description: * @Description:
*/ */
public interface ProductLossRepository extends JpaRepository<ProductLoss,String> { public interface ProductLossRepository extends JpaRepository<ProductLoss,String> {
List<ProductLoss> findByProductId(String productId); List<ProductLoss> findByProductId(Long productId);
} }
...@@ -11,5 +11,5 @@ import java.util.List; ...@@ -11,5 +11,5 @@ import java.util.List;
* @Description: * @Description:
*/ */
public interface ProductMaterialRepository extends JpaRepository<ProductMaterial,String> { public interface ProductMaterialRepository extends JpaRepository<ProductMaterial,String> {
List<ProductMaterial> findByProductId(String productId); List<ProductMaterial> findByProductId(Long productId);
} }
...@@ -9,7 +9,7 @@ import org.springframework.data.jpa.repository.JpaRepository; ...@@ -9,7 +9,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
* @Description: * @Description:
*/ */
public interface ProductPublishedConfRepository extends JpaRepository<ProductPublishedConf,String> { public interface ProductPublishedConfRepository extends JpaRepository<ProductPublishedConf,String> {
ProductPublishedConf findByProductId(String productId); ProductPublishedConf findByProductId(Long productId);
ProductPublishedConf getProductPublishedConfByProductId(String productId); ProductPublishedConf getProductPublishedConfByProductId(String productId);
} }
...@@ -9,5 +9,5 @@ import org.springframework.data.jpa.repository.JpaRepository; ...@@ -9,5 +9,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
* @Description: * @Description:
*/ */
public interface ProductTypesetConfRepository extends JpaRepository<ProductTypesetConf,String> { public interface ProductTypesetConfRepository extends JpaRepository<ProductTypesetConf,String> {
ProductTypesetConf findByProductId(String productId); ProductTypesetConf findByProductId(Long productId);
} }
package com.huigou.topsun.util;
import java.util.concurrent.ThreadLocalRandom;
/**
* |00000000|00000000|00000000|00000000|00000000|00000000|00000000|00000000|
* |--|xxxxxxxxxxxxxx 41bit 时间戳(毫秒) xxxxxxxxxxxxxxx|--|--------|--------|
* |---------------------------------------4bit机器id|xxxx|--------|--------|
* |------------------------------------------16bit自增序列|xxxxxxxx|xxxxxxxx|
*/
public class Snowflake {
// 开始时间
private static final long OFFSET = 1686211627000L;
private static long WORKER_ID ;
/** 机器ID位 **/
private static final long WORKER_ID_BITS = 4L;
/** 自增序列位 **/
private static final long SEQUENCE_ID_BITS = 16L;
private static final long WORKER_SHIFT_BITS = SEQUENCE_ID_BITS;
private static final long OFFSET_SHIFT_BITS = WORKER_ID_BITS + WORKER_SHIFT_BITS;
private static long SEQUENCE_MAX = (1 << SEQUENCE_ID_BITS) - 1;
private static long lastTimestamp = 0L;
private static long sequence = 0L;
public Snowflake(long workerId) {
WORKER_ID = workerId;
}
public static synchronized long nextId() {
long timestamp = timeGen();
if(timestamp < lastTimestamp) {
System.out.println("时钟回拨");
// 可以加入 ‘时钟序列’ 位,并缓存。
}
if(timestamp == lastTimestamp) {
sequence = ++sequence & SEQUENCE_MAX;
// 到达最大序列时等待
if(sequence == 0L) {
timestamp = tilNexMillis(lastTimestamp);
}
//timestamp = sequence != 0 ? timestamp : tilNexMillis(lastTimestamp);
} else {
// 初始序列 随机 1 - 3
sequence = ThreadLocalRandom.current().nextLong(1, 3);
}
lastTimestamp = timestamp;
// 时间戳 | 机器id | 序列号
return (timestamp - OFFSET) << OFFSET_SHIFT_BITS
| (WORKER_ID << WORKER_SHIFT_BITS)
| sequence;
}
protected static long tilNexMillis(long lastTimestamp) {
long timestamp = timeGen();
while (timestamp <= lastTimestamp) {
timestamp = timeGen();
}
return timestamp;
}
protected static long timeGen() {
return System.currentTimeMillis();
}
}
package com.huigou.topsun.util;
import org.junit.Test;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
public class TestSnowflake {
public List<Long> list = new CopyOnWriteArrayList<>();
@Test
public void run() throws InterruptedException {
generateTest();
new Snowflake(1);
final Long id = Snowflake.nextId();
Date date = new Date();
date.setTime( (id>>18) + 1686211627000L );
System.out.println(id);
}
public void generateTest()throws InterruptedException {
TreadA t1 = new TreadA();
TreadB t2 = new TreadB();
t1.start();
t2.start();
while (list.size() < 60000) {
Thread.sleep(500);
}
System.out.println(list.size());
Map<Object, Long> map = list.stream().collect(Collectors.groupingBy(l -> l, Collectors.counting()));
Map<Object, Long> sortedByCount = map.entrySet().stream()
.sorted((e1, e2) -> e2.getValue().compareTo(e1.getValue()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
List<Object> countList = map.entrySet().stream().filter(f -> f.getValue() > 1).map(Map.Entry::getKey).collect(Collectors.toList());
if(countList.size() > 0) {
System.out.println("x");
}
}
protected static long timeGen() {
return System.currentTimeMillis() / 1000;
}
public class TreadA extends Thread {
public void run() {
super.run();
//long timestamp = timeGen();
for(int i = 0; i < 30000; i++) {
new Snowflake(1);
long id = Snowflake.nextId();
list.add(id);
}
}
}
public class TreadB extends Thread {
public void run() {
super.run();
for(int i = 0; i < 30000; i++) {
new Snowflake(1);
long id = Snowflake.nextId();
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