forked from langhsu/mblog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request langhsu#17 from saxingz/patch-1
Picture cleaning and recycling automatically
- Loading branch information
Showing
16 changed files
with
586 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ rebel.xml | |
|
||
*.db | ||
|
||
!/src/main/java/com/mtons/mblog/base/storage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.mtons.mblog.base.utils; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
/** | ||
* id generate | ||
* | ||
* @author saxing 2019/4/5 9:15 | ||
*/ | ||
public class IdUtils { | ||
|
||
private final static AtomicInteger resource = ResourceLock.getAtomicInteger("ID_GENERATE"); | ||
|
||
/** | ||
* 生成id | ||
* | ||
* @return | ||
*/ | ||
public static long getId(){ | ||
synchronized (resource){ | ||
try { | ||
Thread.sleep(1); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
return System.currentTimeMillis(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/mtons/mblog/base/utils/ResourceLock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.mtons.mblog.base.utils; | ||
|
||
import java.util.concurrent.*; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
/** | ||
* resource lock | ||
* | ||
* @author saxing 2019/4/3 16:20 | ||
*/ | ||
public class ResourceLock { | ||
|
||
private static final ConcurrentHashMap<String, AtomicInteger> lockMap = new ConcurrentHashMap<String, AtomicInteger>(); | ||
|
||
public static AtomicInteger getAtomicInteger(String key) { | ||
if (lockMap.get(key) == null) { | ||
lockMap.putIfAbsent(key, new AtomicInteger(0)); | ||
} | ||
int count = lockMap.get(key).incrementAndGet(); | ||
return lockMap.get(key); | ||
} | ||
|
||
public static void giveUpAtomicInteger(String key) { | ||
if (lockMap.get(key) != null) { | ||
int source = lockMap.get(key).decrementAndGet(); | ||
if (source <= 0) { | ||
lockMap.remove(key); | ||
} | ||
} | ||
} | ||
|
||
public static String getPostKey(Long postId){ | ||
return "POST_OPERATE_{postId}".replace("{postId}", String.valueOf(postId)); | ||
} | ||
|
||
public static String getPicKey(Long picId){ | ||
return "PIC_OPERATE_{pic}".replace("{pic}", String.valueOf(picId)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.mtons.mblog.modules.entity; | ||
|
||
import javax.persistence.*; | ||
import java.io.Serializable; | ||
import java.time.LocalDateTime; | ||
|
||
/** | ||
* 图片 | ||
* | ||
* @author saxing 2019/4/3 21:24 | ||
*/ | ||
@Entity | ||
@Table(name = "mto_pic", | ||
uniqueConstraints = {@UniqueConstraint(name = "md5key", columnNames = {"md5"})} | ||
) | ||
public class Pic implements Serializable { | ||
private static final long serialVersionUID = -2263990565349962964L; | ||
|
||
@Id | ||
private long id; | ||
|
||
@Column(name = "md5", columnDefinition = "varchar(50) NOT NULL DEFAULT ''") | ||
private String md5; | ||
|
||
@Column(name = "path", columnDefinition = "varchar(255) NOT NULL DEFAULT ''") | ||
private String path; | ||
|
||
@Column(name = "amount", columnDefinition = "bigint(20) NOT NULL DEFAULT '0'") | ||
private long amount; | ||
|
||
@Column(name = "create_time") | ||
private LocalDateTime createTime; | ||
|
||
@Column(name = "update_time") | ||
private LocalDateTime updateTime; | ||
|
||
public long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getMd5() { | ||
return md5; | ||
} | ||
|
||
public void setMd5(String md5) { | ||
this.md5 = md5; | ||
} | ||
|
||
public String getPath() { | ||
return path; | ||
} | ||
|
||
public void setPath(String path) { | ||
this.path = path; | ||
} | ||
|
||
public long getAmount() { | ||
return amount; | ||
} | ||
|
||
public void setAmount(long amount) { | ||
this.amount = amount; | ||
} | ||
|
||
public LocalDateTime getCreateTime() { | ||
return createTime; | ||
} | ||
|
||
public void setCreateTime(LocalDateTime createTime) { | ||
this.createTime = createTime; | ||
} | ||
|
||
public LocalDateTime getUpdateTime() { | ||
return updateTime; | ||
} | ||
|
||
public void setUpdateTime(LocalDateTime updateTime) { | ||
this.updateTime = updateTime; | ||
} | ||
} |
Oops, something went wrong.