/**

 * 

 */

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);

}

}

}

最新文章

  1. Java企业实训 - 01 - Java前奏
  2. Power BI的一些视频演示资源
  3. 显示textarea内容的时候没有自动换行
  4. 使用 Box2D 做一个 JansenWalker 机器人
  5. 【转】Eclipse打JAR包,插件FatJar安装与使用
  6. 那么小伙伴么,问题来了,WPF中,控件的Width=&quot;*&quot;在后台怎么写?
  7. ORCALE用户授权与创建同义词
  8. date命令使用总结【转载】
  9. .NET基础拾遗(8)ADO.NET与数据库开发基础
  10. python re(正则模块)
  11. Android如何查看应用签名信息
  12. docker下编译mangoszero WOW60级服务端(二)
  13. 贝叶斯推断 &amp;&amp; 概率编程初探
  14. Spring Boot MongoDB 查询操作 (BasicQuery ,BSON)
  15. vue从入门到进阶:简介(一)
  16. 剑指offer面试题4: 二维数组中的查找
  17. HashMap 和 HashTable差别
  18. mybatis标签之——&lt;trim&gt;及 &lt;foreach collection&gt;
  19. Android 自定义Adapter实现多视图Item的ListView
  20. Q143 重排链表

热门文章

  1. 淘宝CDN系统架构
  2. css3 背景background
  3. SQLServer修改表字段时进行表连接
  4. 前端-js进阶和JQ源码思维导图笔记
  5. 创建一个dynamics CRM workflow (二) - Build in Workflows
  6. 关于pc端 app端pdf,word xls等文件预览的功能
  7. mvvm模式和mvc模式 概述总结对比
  8. vc++如何创建程序--利用快捷键进行多行注释
  9. Maven安装+配置
  10. nginx获取经过层层代理后的客户端真实IP(使用正则匹配)