/**

 * 

 */

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. weixin js接口

    <!DOCTYPE HTML><html><head> <meta http-equiv="content-type" content=& ...

  2. NOIP 2014 T2 联合权值 DFS

    背景 NOIP2014提高组第二题 描述 无向连通图G有n个点,n-1条边.点从1到n依次编号,编号为i的点的权值为Wi ,每条边的长度均为1.图上两点(u, v)的距离定义为u点到v点的最短距离.对 ...

  3. android黑科技系列——手机端破解神器MT的内购VIP功能破解教程

    一.前言 在破解app的时候,我们现在几乎都是在PC端进行操作,但是之前bin神的MT管理器,可以在手机端直接破解,不过也有很大的局限性,但是对于一些简单的app破解没问题的.这个工具其实原理也很简单 ...

  4. NOSQL:redis mongodb

    redis 1 概念及其基本操作:http://blog.nosqlfan.com/html/3139.html 2 安装配置及其操作:http://blog.fens.me/linux-redis- ...

  5. AngularJS指令进阶 -- ngModelController详解

    大家都知道AngularJS中的指令是其尤为复杂的一个部分,但是这也是其比较好玩的地方.这篇文章我们就来说一说如何在我们自定义的指令中,利用ngModel的controller来做双向数据绑定,本文对 ...

  6. JS面向对象(1)——构造函数模式和原型模式

    1.构造函数模式 构造函数用来创建特定的类型的对象.如下所示: function Person(name,age,job){ this.name=name; this.job=job; this.ag ...

  7. Python Tutorial笔记

    Python Tutorial笔记 Python入门指南 中文版及官方英文链接: Python入门指南 (3.5.2) http://www.pythondoc.com/pythontutorial3 ...

  8. javaScript 计算两个日期的天数相差

    一:计算两个日期相差的天数 1 <html> <head> <meta http-equiv="Content-Type" content=" ...

  9. centos7常见的操作01 UTC CST

      CentOS系统将UTC时间修改为CST时间方法 2018-10-31 07:51 世界协调时间(Universal Time Coordinated,UTC): GPS 系统中有两种时间区分,一 ...

  10. let var const

    eslint要求变量声明使用const的,而不是let和var如果可能的话. 如果一个变量只有在声明时才被赋值一次,那么应该使用'const' 'use strict';(function() { v ...