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的更多相关文章
随机推荐
- GStreamer基础教程01 - Hello World
摘要 在面对一个新的软件库时,第一步通常实现一个“hello world”程序,来了解库的用法.对于GStreamer,我们可以实现一个极简的播放器,来了解GStreamer的使用. 环境配置 为了快 ...
- 部署hexo后github pages页面未更新或无法打开问题
title: 部署hexo后github pages页面未更新或无法打开问题 date: 2018-03-30 15:34:29 categories: methods tags: hexo gith ...
- C#中图片转换为Base64编码,Base64编码转换为图片
#region 图片转为base64编码的字符串 public string ImgToBase64String(string Imagefilename) { try { Bitmap bmp = ...
- (转)Java进阶java int与Integer的区别
Java进阶java int与Integer的区别 前言 int与Integer的区别从大的方面来说就是基本数据类型与其包装类的区别: int 是基本类型,直接存数值,而Integer是对象,用一个引 ...
- 数据结构——栈的实现(数组、Java)
巩固数据结构 栈是一种有限制的线性表 只能对表尾进行操作 package com.shine.test.datastruct; import java.util.Arrays; public clas ...
- 三维点集拟合:平面拟合、RANSAC、ICP算法
ACM算法分类:http://www.kuqin.com/algorithm/20080229/4071.html 一: 拟合一个平面:使用SVD分解,代码里面去找吧 空间平面方程的一般表达式为: A ...
- java学习笔记5——String类常用方法
1.字符串长度计算: int i = String1.length(); 2.字符串比较:1) equals()和equalsIgnoreCase //比较两个字符串对象的实体是否相同,相同输出tru ...
- java中4种修饰符访问权限的区别及详解全过程
java中4种修饰符访问权限的区别及详解全过程 http://jingyan.baidu.com/article/fedf0737700b3335ac8977ca.html java中4中修饰符分别为 ...
- java equals的用法
equals方法,用于比较两个对象是否相同,它其实就是使用两个对象的内存地址在比较.Object类中的equals方法内部使用的就是==比较运算符. package Xuexi; public cla ...
- JS 100元购物卡,牙刷5元,香皂2元、洗发水15元 100元正好花完有多少种可能
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...