You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.9 KiB

2 months ago
package com.dsideal.Base.Util;
11 months ago
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
public class PkUtil {
//在独立的main函数中使用下面的方式进行声明logback对象
3 months ago
private static Logger log = LoggerFactory.getLogger(PkUtil.class);
11 months ago
public static Map<Integer, String> identityMap = new HashMap<>();
/**
*
*
* 2018-12-11
*/
public static void InitPersonNumPk() {
//初始化字典
InitIdentityMap();
1 month ago
11 months ago
for (Integer key : identityMap.keySet()) {
3 months ago
//初始化要删除掉
RedisKit.Del(identityMap.get(key) + "_identity_pk_num");
11 months ago
String sql = Db.getSql("loginPerson.getMaxPkByIdentityId");
int identity_id = key;
Record record = Db.findFirst(sql, identity_id);
int identity_pk_num = record.getInt("identity_pk_num");
10 months ago
RedisKit.incrBy(identityMap.get(key) + "_identity_pk_num", identity_pk_num);
11 months ago
log.info("初始化人员身份主键生成器成功:" + identityMap.get(key));
}
}
/**
*
*
* 2018-12-11
*/
public static void InitOrgNumPk() {
3 months ago
//初始化要删除掉
RedisKit.Del("org_pk_num");
11 months ago
String sql = Db.getSql("organization.getMaxPkByOrg");
Record record = Db.findFirst(sql);
3 months ago
int org_pk_num = 0;
if (record != null && record.get("org_pk_num") != null) org_pk_num = record.getInt("org_pk_num");
10 months ago
RedisKit.incrBy("org_pk_num", org_pk_num);
11 months ago
}
/**
*
*
* 2018-12-21
*/
public static void InitIdentityMap() {
11 months ago
if (identityMap.isEmpty()) {
11 months ago
identityMap.put(1, "sys");
identityMap.put(2, "shi");
identityMap.put(3, "qu");
identityMap.put(4, "dw");
identityMap.put(5, "tea");
identityMap.put(6, "stu");
}
}
/**
* :()
* :
* 2018-11-22
*
3 months ago
* @param identity_id
11 months ago
*/
public static long GetPersonNumPk(int identity_id, int count) {
String redisPrefix = identityMap.get(identity_id);
3 months ago
long maxPk = RedisKit.incrBy(redisPrefix + "_identity_pk_num", count);
return maxPk;
11 months ago
}
/**
* :
* :
* 2018-11-22
*/
public static long GetOrgNumPk(int count) {
10 months ago
return RedisKit.incrBy("org_pk_num", count);
11 months ago
}
}