<task:scheduled ref="task" method="checkLastWorkDay" cron="0 0 0 * * ? "/><!-- 天天更新編制快照 -->redis
/**
* 判斷今天是否是本月的最後一個工做日
*/
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("今天不是本月的最後一天");
}
}spa
/**
* 月底生成一份最新的編制到一個表裏
*/
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--------------");debug
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("生成最新編制--結束");
}get
}it
System.out.println("-------執行生成一份最新的編制到一個表裏end--------------");
RedisShardedPoolUtil.del(lockName);
System.out.println("釋放" + lockName + ",ThreadName:" + Thread.currentThread());
}
}
}io