码迷,mamicode.com
首页 > 其他好文 > 详细

UpdateParameterUtils

时间:2015-08-21 13:46:28      阅读:182      评论:0      收藏:0      [点我收藏+]

标签: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

标签:updateparameterutils

原文地址:http://blog.csdn.net/pingdouble/article/details/47831427

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!