/**
* 判断今天是不是本月的最后一个工作日
*/
public void checkLastWorkDay() {
Calendar cal1 = Calendar.getInstance();
int month = cal1.get(Calendar.MONTH) + 1;
int year = cal1.get(Calendar.YEAR);
int day = cal1.get(Calendar.DATE);
logger.warn(year + "年" + month + "月" + day + "日");
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month - 1);
int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);// 获取该月最大一天
cal.set(Calendar.DAY_OF_MONTH, lastDay);
if (day == lastDay) {
logger.warn("今天是本月的最后一天");
SpringJobUtil.updateNewEndMonthOrg();
} else {
logger.warn("今天不是本月的最后一天");
}
}
/**
* 月底生成一份最新的编制到一个表里
*/
public static void updateNewEndMonthOrg(){
if (isIp()) {
String lockName = ConstantCommon.REDIS_LOCK.UPDATE_NEWEST_ORG_TASK_LOCK;
int expireSecond = 3600;// 秒
boolean flag = RedisShardedPoolUtil.redisClock(lockName, expireSecond);
if (flag) {
RedisShardedPoolUtil.expire(lockName, expireSecond);// 有效期expireSecond秒,防止死锁
System.out.println("获取" + lockName + ",ThreadName:" + Thread.currentThread());
System.out.println("-------执行生成一份最新的编制到一个表里begin--------------");
for (OrgEntity tenant : ConstantCommon.LIST_TENANT) {
DynamicDataSourceHolder.setDataSourceType(tenant.getOrgId());
if (logger.isDebugEnabled()) {
logger.debug("生成最新编制--开始");
}
ErpCommon.getService(OrginazitionNewService.class).updateNewestEndM();
if (logger.isDebugEnabled()) {
logger.debug("生成最新编制--结束");
}
}
System.out.println("-------执行生成一份最新的编制到一个表里end--------------");
RedisShardedPoolUtil.del(lockName);
System.out.println("释放" + lockName + ",ThreadName:" + Thread.currentThread());
}
}
}