UpdateParameterUtils
/**
*
*/
package com.neptune.business.api.job;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.neptune.business.api.exception.BusinessErrorCode;
import com.neptune.business.api.exception.BusinessException;
import com.neptune.business.api.model.ParameterConfigurationModel;
import com.neptune.business.api.service.IParameterConfigurationService;
import com.neptune.business.api.utils.TimeAlgorithm;
import com.neptune.business.entity.ParameterConfiguration;
import com.neptune.business.enums.HistoryStatus;
/**
* @author Energizer.lai 定時更新配置表中的信息
*/
@Service
@Transactional
public class UpdateParameterUtils {
protected static Logger logger = Logger.getLogger(UpdateParameterUtils.class.getName());
@Autowired
private IParameterConfigurationService parameterConfigurationService;
/*
@Scheduled(cron = "0 1/3 * * * ?")
// 每小时的33分钟開始运行,每3分钟运行1次
*/ public void updateYearAndMoth() throws Exception {
try {
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mmss");
logger.info("开始進行UpdateParameter job" + sf.format(new Date()));
ParameterConfigurationModel pm = parameterConfigurationService.getParameterYearAndMothValue(null);
if (pm == null) {
logger.error(BusinessErrorCode.message3006 + BusinessErrorCode.code3006);
throw new BusinessException(BusinessErrorCode.message3006, BusinessErrorCode.code3006);
}
ParameterConfiguration update = parameterConfigurationService.findByPKId(ParameterConfiguration.class, pm.getId());
ParameterConfiguration pmEn = new ParameterConfiguration();
if (StringUtils.isNotEmpty(pm.getConsumptionDate())) {
}
if (StringUtils.isNotEmpty(pm.getConsumptionMonth())) {
}
if (StringUtils.isNotEmpty(pm.getConsumptionYear())) {
}
Integer date = Integer.valueOf(pm.getConsumptionDate()) + 1;
Integer moth = Integer.valueOf(pm.getConsumptionMonth());
Integer year = Integer.valueOf(pm.getConsumptionYear());
int size = 1000;
for (int i = 0; i < size; i++) {
// 是不是闰年
boolean isLeapYear = TimeAlgorithm.isLeapYear(year);
if (isLeapYear) {
// 2月份是29天
if (pm.getConsumptionMonth().equals("02")) {
if (date > 29) {
moth = moth + 1;
date = 1;
break;
}
}
} else {
if (pm.getConsumptionMonth().equals("02")) {
if (date > 28) {
moth = moth + 1;
date = 1;
break;
}
}
}
String[] mothArrays = { "1", "3", "5", "7", "9", "10", "12" };
boolean is31 = TimeAlgorithm.contains(mothArrays, pm.getConsumptionMonth());
if (is31) {
if (date >= 31) {
moth = moth + 1;
date = 1;
}
break;
} else {
if (date >= 30) {
moth = moth + 1;
date = 1;
}
break;
}
}
if (Integer.valueOf(pm.getConsumptionMonth()) > 12 && Integer.valueOf(pm.getConsumptionMonth()) > 0) {
moth = 1;
year += 1;
}
String mothStr =String.valueOf(moth);
String dateStr =String.valueOf(date);
if (mothStr.length()!=2) {
mothStr="0"+mothStr;
}
if (dateStr.length()!=2) {
dateStr="0"+dateStr;
}
pmEn.setConsumptionMonth(mothStr);
pmEn.setConsumptionYear(String.valueOf(year));
pmEn.setConsumptionDate(dateStr);
pmEn.setHistoryStatus(HistoryStatus.HISTORYCURRENTSTATE.getCode());
pmEn.setCreateTime(new Date());
pmEn.setCreateName("System.job");
parameterConfigurationService.insert(pmEn);
update.setHistoryStatus(HistoryStatus.HISTORYSTATE.getCode());
update.setUpdateName("System.job");
update.setUpdateTime(new Date());
parameterConfigurationService.update(update);
logger.info("UpdateParameter job結束" + sf.format(new Date()));
} catch (Exception e) {
e.printStackTrace();
logger.error(BusinessErrorCode.message3006 + BusinessErrorCode.code3006 + e.getMessage());
throw new BusinessException("job" + BusinessErrorCode.message3006, BusinessErrorCode.code3006);
}
}
}
UpdateParameterUtils的更多相关文章
随机推荐
- 2017-3-9 leetcode 283 287 289
今天操作系统课,没能安心睡懒觉23333,妹抖龙更新,可惜感觉水分不少....怀念追RE0的感觉 =================================================== ...
- 网络:万维网(WWW)
ylbtech-网络:万维网(WWW) www (万维网缩写)同义词 万维网一般指www(万维网缩写)WWW是环球信息网的缩写,(亦作“Web”.“WWW”.“'W3'”,英文全称为“World Wi ...
- php pdo具体操作
0x01:测试PDO是否安装成功 运行如下代码,如果提示参数错误,说明PDO已经安装,如果说明对象不存在,则修改PHP配置文件php.ini,取消php_pdo_yourssqlserverhere. ...
- Android 用Handler和Message实现计时效果及其中一些疑问
本来是打算继续做天气预报的优化的,但因为某些原因,我要先把之前做的小应用优化一下.所以今天就插播一下用Handler和Message实现计时效果. 首先,简要说明一下,这个应用有两个显示数字的Text ...
- Android WiFi热点完全研究(自定义创建、跳转系统界面设置、读取配置、切换,Android6.0适配)
前言: WiFi热点设置页面的安全性选项在Android 4.x上有“无”.“WPA PSK”.“WPA2 PSK”三个选项,在Android 5.0(含)之后去掉了WPA PSK选项(部分手机厂家会 ...
- IM系统中如何保证消息的可靠投递(即QoS机制)
消息的可靠性,即消息的不丢失和不重复,是im系统中的一个难点.当初qq在技术上(当时叫oicq)因为以下两点原因才打败了icq:1)qq的消息投递可靠(消息不丢失,不重复)2)qq的垃圾消息少(它 ...
- 【Oracle】RMAN备份
1. 完全备份 RMAN> backup as backupset database; Starting allocated channel: ORA_DISK_1 channel ORA_DI ...
- Linux学习之路三:重要概念之Linux系统层次结构
上图来自Unix编程圣经<APUE>英文第二版.如图,处于最中心的是系统内核,负责机器硬件资源管理,进程管理等:shell,函数库(值得记住的是C标准函数库)和某些应用程序均直接构建于内核 ...
- 企业级任务调度框架Quartz(5) Quartz的声明式配置
前序: 前面我们已经通过编程的方式实现了多个作业任务执行具体操作的演示:但具体到实际的时候,如果我们要在 Job 启动之后改变它的执行时间和频度,则必须去修改源代码重新编译,我们很难去以编程的 ...
- LSTM比较RNN
LSTM只能避免RNN的梯度消失(gradient vanishing),但是不能对抗梯度爆炸问题(Exploding Gradient). 梯度膨胀(gradient explosion)不是个严重 ...