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.

88 lines
2.8 KiB

2 months ago
package com.dsideal.Res.Util;
10 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对象
private static final Logger log = LoggerFactory.getLogger(PkUtil.class);
public static Map<Integer, String> identityMap = new HashMap<>();
/**
*
*
* 2018-12-11
*/
public static void InitPersonNumPk() {
//初始化字典
InitIdentityMap();
for (Integer key : identityMap.keySet()) {
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");
//初始化要删除掉
RedisKit.del(identityMap.get(key) + "_identity_pk_num");
RedisKit.incrBy(identityMap.get(key) + "_identity_pk_num", identity_pk_num);
log.info("初始化人员身份主键生成器成功:" + identityMap.get(key));
}
}
/**
*
*
* 2018-12-11
*/
public static void InitOrgNumPk() {
String sql = Db.getSql("organization.getMaxPkByOrg");
Record record = Db.findFirst(sql);
int org_pk_num = record.getInt("org_pk_num");
//初始化要删除掉
RedisKit.del("org_pk_num");
RedisKit.incrBy("org_pk_num", org_pk_num);
}
/**
*
*
* 2018-12-21
*/
public static void InitIdentityMap() {
if (identityMap.isEmpty()) {
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
*
* @param identity_id
*/
public static long GetPersonNumPk(int identity_id, int count) {
String redisPrefix = identityMap.get(identity_id);
return RedisKit.incrBy(redisPrefix + "_identity_pk_num", count);
}
/**
* :
* :
* 2018-11-22
*/
public static long GetOrgNumPk(int count) {
return RedisKit.incrBy("org_pk_num", count);
}
}