/**

 * 

 */

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的更多相关文章

随机推荐

  1. 网络:万维网(WWW)

    ylbtech-网络:万维网(WWW) www (万维网缩写)同义词 万维网一般指www(万维网缩写)WWW是环球信息网的缩写,(亦作“Web”.“WWW”.“'W3'”,英文全称为“World Wi ...

  2. angular里使用vue/vue组件怎么在angular里用

    欢迎加入前端交流群交流知识&&获取视频资料:749539640 如何在angularjs(1)中使用vue参考: https://medium.com/@graphicbeacon/h ...

  3. [CSharp] C#开源大全

    商业协作和项目管理平台-TeamLab 网络视频会议软件-VMukti 驰骋工作流程引擎-ccflow [免费]正则表达式测试工具-Regex-Tester Windows-Phone-7-SDK E ...

  4. python之路——二分查找算法

    楔子 如果有这样一个列表,让你从这个列表中找到66的位置,你要怎么做? l = [2,3,5,10,15,16,18,22,26,30,32,35,41,42,43,55,56,66,67,69,72 ...

  5. idea的环境变量设置(Enviroment variables)

  6. 关于各浏览器下Hack的写法

    下面是我收集有关于各浏览器下Hack的写法: 1.Firefox @-moz-document url-prefix() { .selector { property: value; } } 上面是仅 ...

  7. Android stroke 边框线 某一边

    有时候需要给View加边框线,我们经常是四边一起加,就像这样: <shape xmlns:android="http://schemas.android.com/apk/res/and ...

  8. Selenium3+python自动化008-常用操作

    一.元素常用操作 1. clear()            清除文本 2. send_keys()        模拟输入 3. click()            单击元素 4.get_attr ...

  9. Js中的4个事件

    除了加载文档的事件onload和鼠标相关的一些事件如onclick,onmouseover等.js还有一些相对不常用的事件,这些事件也有各自的应用场景,本文就介绍 onkeydown,oncontex ...

  10. Python中生成器,迭代器,以及一些常用的内置函数.

    知识点总结 生成器 生成器的本质就是迭代器. 迭代器:Python中提供的已经写好的工具或者通过数据转化得来的. 生成器:需要我们自己用Python代码构建的 创建生成器的三种方法: 通过生成器函数 ...