/**

 * 

 */

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. ZOJ-3988 2017CCPC-秦皇岛 Prime Set 二分图最大匹配 匈牙利

    题面 题意:给你n个数,你可以选择2个和为质数的数为一对,每个数可以重复选择,你最多选k对,问你最多能选多少个不同数出来 题解:首先思考怎么样的数和为质数,2个偶数相加不行,除了1+1以外2个奇数相加 ...

  2. .NET前后台-JS获取/设置iframe内对象元素并进行数据处理

    转载请注明出处:果冻栋吖 这个主要是修改H3BPM一个批量审批的功能时候做的.先看下图: H3自带了批量审批的功能,也就是按钮1,有审批意见3,但是如果3里边不填写内容点击1之后,效果就是表单里边没有 ...

  3. IO编程 - 转载自廖雪峰的博文

    IO在计算机中指Input/Output,也就是输入和输出.由于程序和运行时数据是在内存中驻留,由CPU这个超快的计算核心来执行,涉及到数据交换的地方,通常是磁盘.网络等,就需要IO接口. 比如你打开 ...

  4. MySQL视图、触发器、事务、存储过程、函数

    视图.触发器.事务.存储过程.函数   阅读目录 一 视图 二 触发器 三 事务 四 存储过程 五 函数 六 流程控制 一 视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据 ...

  5. CentOS6.5下nginx-1.8.1.tar.gz的单节点搭建(图文详解)

    不多说,直接上干货! [hadoop@djt002 local]$ su root Password: [root@djt002 local]# ll total drwxr-xr-x. root r ...

  6. Core篇——初探IdentityServer4(OpenID Connect模式)

    Core篇——初探IdentityServer4(OpenID Connect客户端验证) 目录 1.Oauth2协议授权码模式介绍2.IdentityServer4的OpenID Connect客户 ...

  7. 多个tomcat配置,解决冲突问题

    一.一般修改 路径: /opt/apache-tomcat/conf/server.xml 1.第一个tomcat使用默认配置 2.第二个tomcat一般配置 二.特殊修改 1.第二个tomcat特殊 ...

  8. JqGrid saveRow方法报404错误

    TCX_1807工艺配置/检测项配置页面为jqgrid可编辑页面,使用的脚本为 ){ jQuery('#gridList').saveRow(lastId, true);//保存上一个修改的单元行 } ...

  9. Android线性渐变

    布局实现: 1. 在res中建立drawable文件夹. 2. 在drawable文件夹中建立shape.xml. 3. shape.xml的代码如下: <?xml version=" ...

  10. 【Oracle】ORA-38171: Insufficient privileges for SQL management object operation

    问题: 使用SQL PLAN MANAGEMENT的时候运行下面的存储过程报错. SYS@GOOD> conn scott/tiger Connected. SCOTT@GOOD> DEC ...