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

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.dsideal.Base.Util;
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 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()) {
//初始化要删除掉
RedisKit.Del(identityMap.get(key) + "_identity_pk_num");
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.incrBy(identityMap.get(key) + "_identity_pk_num", identity_pk_num);
log.info("初始化人员身份主键生成器成功:" + identityMap.get(key));
}
}
/**
* 功能:初始化组织机构主键
* 作者:黄海
* 时间2018-12-11
*/
public static void InitOrgNumPk() {
//初始化要删除掉
RedisKit.Del("org_pk_num");
String sql = Db.getSql("organization.getMaxPkByOrg");
Record record = Db.findFirst(sql);
int org_pk_num = 0;
if (record != null && record.get("org_pk_num") != null) org_pk_num = record.getInt("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);
long maxPk = RedisKit.incrBy(redisPrefix + "_identity_pk_num", count);
return maxPk;
}
/**
* 功能:获取组织机构的最大值
* 作者:黄海
* 时间2018-11-22
*/
public static long GetOrgNumPk(int count) {
return RedisKit.incrBy("org_pk_num", count);
}
}