mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
1、新增组织编辑修改首购价格能力;2、账单分页支持非管理端只允许查看本组织下;3、统计公共入参和方法抽象、过期组织接口分离移到system、新增销售额统计接口;
This commit is contained in:
+6
@@ -1,6 +1,7 @@
|
||||
package com.cf.imes.framework.id.config;
|
||||
|
||||
import com.cf.imes.framework.id.core.util.SnowflakeIdWorker3rd;
|
||||
import com.cf.imes.framework.id.core.util.SnowflakeSerialNoWorker3rd;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@@ -16,4 +17,9 @@ public class ChenfengIDAutoConfiguration {
|
||||
public SnowflakeIdWorker3rd idWorker() {
|
||||
return new SnowflakeIdWorker3rd();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SnowflakeSerialNoWorker3rd serialNoWorker3rd() {
|
||||
return new SnowflakeSerialNoWorker3rd();
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.cf.imes.framework.id.core.util;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class SerialNoMinuteCounter {
|
||||
private static final long MASK = 0x7FFFFFFFFFFFFFFFL;
|
||||
private final AtomicLong atom;
|
||||
|
||||
public SerialNoMinuteCounter() {
|
||||
atom = new AtomicLong(0);
|
||||
}
|
||||
|
||||
public final long incrementAndGet() {
|
||||
return atom.incrementAndGet() & MASK;
|
||||
}
|
||||
|
||||
public long get() {
|
||||
return atom.get() & MASK;
|
||||
}
|
||||
|
||||
public void set(long newValue) {
|
||||
atom.set(newValue & MASK);
|
||||
}
|
||||
|
||||
}
|
||||
-40
@@ -4,9 +4,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* @ClassName: SnowflakeIdWorker3rd
|
||||
@@ -39,10 +36,6 @@ public class SnowflakeIdWorker3rd {
|
||||
private final MinuteCounter counter = new MinuteCounter();
|
||||
/** 预支时间标志 */
|
||||
boolean isAdvance = false;
|
||||
/** 时间格式 */
|
||||
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyMMddHHmmss");
|
||||
/** 上次时间格式 */
|
||||
private final AtomicReference<String> lastTimestampStr = new AtomicReference<>("");
|
||||
|
||||
// ==============================Constructors=====================================
|
||||
|
||||
@@ -133,37 +126,4 @@ public class SnowflakeIdWorker3rd {
|
||||
// String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
|
||||
return Integer.valueOf(timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取下一个流水号
|
||||
*
|
||||
* @return SerialNo
|
||||
*/
|
||||
public String nextSerialNo() {
|
||||
String now = LocalDateTime.now().format(FORMATTER);
|
||||
|
||||
// 跨秒重置序列号
|
||||
String last = lastTimestampStr.get();
|
||||
if (!now.equals(last)) {
|
||||
// 仅在跨秒时重置序列号
|
||||
if (lastTimestampStr.compareAndSet(last, now)) {
|
||||
counter.set(0);
|
||||
}
|
||||
}
|
||||
|
||||
// 原子递增序列号
|
||||
int seq = counter.incrementAndGet();
|
||||
|
||||
// 序列号100000(5位)以内
|
||||
if (seq > 9999) {
|
||||
if (counter.compareAndSet(seq, 1)) {
|
||||
seq = 1;
|
||||
} else {
|
||||
seq = counter.incrementAndGet();
|
||||
}
|
||||
}
|
||||
|
||||
// 拼接时间 + 序列号
|
||||
return String.format("%s%05d", now, seq);
|
||||
}
|
||||
}
|
||||
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
package com.cf.imes.framework.id.core.util;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* @ClassName: SnowflakeSerialNoWorker3rd
|
||||
* @Description:snowflake算法改进
|
||||
* @author: yonnie
|
||||
* @date: 2025/09/29 16:00
|
||||
* @version V1.1
|
||||
*
|
||||
* 将产生的Id类型更改为Integer 64bit <br>
|
||||
* 把时间戳的单位改为秒,使用48bit的时间戳
|
||||
* 16bit作为自增值即 2^16 = 65535
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class SnowflakeSerialNoWorker3rd {
|
||||
/** 初始时间 (2025-01-01 00:00:00: 1735660800) */
|
||||
// private final long twepoch = 28927680;// 1735660800000L/1000/60;
|
||||
private final long twepoch = 1735660800;
|
||||
/** 序列在id中占位数 */
|
||||
private final long sequenceBits = 16L;
|
||||
/** 时间截向左移16bit */
|
||||
private final long timestampLeftShift = sequenceBits;
|
||||
/** 生成序列的MASK (0xFFFF) */
|
||||
private final long sequenceMask = -1 ^ (-1 << sequenceBits);
|
||||
/** 分钟内序 (0~65535) */
|
||||
private long sequence = 0;
|
||||
private long laterSequence = 0;
|
||||
/** 上次生成ID的时间戳 */
|
||||
private long lastTimestamp = -1;
|
||||
private final SerialNoMinuteCounter counter = new SerialNoMinuteCounter();
|
||||
/** 预支时间标志 */
|
||||
boolean isAdvance = false;
|
||||
/** 时间格式 */
|
||||
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyMMddHHmmss");
|
||||
|
||||
// ==============================Constructors=====================================
|
||||
|
||||
public SnowflakeSerialNoWorker3rd() {
|
||||
// constructor
|
||||
}
|
||||
|
||||
// ==============================Test=============================================
|
||||
|
||||
/** 测试 */
|
||||
public static void main(String[] args) {
|
||||
SnowflakeSerialNoWorker3rd idWorker = new SnowflakeSerialNoWorker3rd();
|
||||
for (long i = 0; i < 1000; i++) {
|
||||
System.out.println(i + ": " + idWorker.nextSerialNo());
|
||||
}
|
||||
}
|
||||
|
||||
// ==============================Methods==========================================
|
||||
|
||||
/**
|
||||
* 获得下一个ID (该方法是线程安全)
|
||||
*
|
||||
* @return SnowflakeId
|
||||
*/
|
||||
public synchronized long nextId() {
|
||||
long timestamp = timeGen();
|
||||
// System.out.println("timeGen: " + Long.toString(timestamp));
|
||||
// 如果当前时间小于上一次ID生成的时间戳,说明系统时钟修改过
|
||||
if (timestamp < lastTimestamp) {
|
||||
throw new RuntimeException(String.format(
|
||||
"Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
|
||||
}
|
||||
|
||||
if (timestamp > counter.get()) {
|
||||
counter.set(timestamp);
|
||||
isAdvance = false;
|
||||
}
|
||||
|
||||
// 如果是同时间生成的,则进行秒内序列
|
||||
if (lastTimestamp == timestamp || isAdvance) {
|
||||
if (!isAdvance) {
|
||||
sequence = (sequence + 1) & sequenceMask;
|
||||
}
|
||||
|
||||
// 秒内自增列溢出
|
||||
if (sequence == 0) {
|
||||
// 预支下一秒获得新的时间戳
|
||||
isAdvance = true;
|
||||
long laterTimestamp = counter.get();
|
||||
if (laterSequence == 0) {
|
||||
laterTimestamp = counter.incrementAndGet();
|
||||
}
|
||||
long nextId = ((laterTimestamp - twepoch) << timestampLeftShift) | laterSequence;
|
||||
laterSequence = (laterSequence + 1) & sequenceMask;
|
||||
return nextId;
|
||||
}
|
||||
} else { // 时间戳改变,秒内序列置0
|
||||
sequence = 0;
|
||||
laterSequence = 0;
|
||||
}
|
||||
// 上次生成ID的时间截
|
||||
lastTimestamp = timestamp;
|
||||
// 移位并或运算拼成64位的ID
|
||||
return ((timestamp - twepoch) << timestampLeftShift) | sequence;
|
||||
}
|
||||
|
||||
public String nextSerialNo() {
|
||||
return LocalDateTime.now().format(FORMATTER) + String.valueOf(nextId()).substring(8);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回以秒为单位的当前时间
|
||||
*
|
||||
* @return 当前时间(秒)
|
||||
*/
|
||||
protected long timeGen() {
|
||||
// String timestamp = String.valueOf(System.currentTimeMillis() / 1000 / 60);
|
||||
// String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
|
||||
// return Long.valueOf(timestamp);
|
||||
return System.currentTimeMillis() / 1000;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user