/**

 * 

 */

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. npm run dev 出现警告

    WARNING in ./node_modules/_webpack@3.10.0@webpack/buildin/global.js There are multiple modules with ...

  2. HUdson2092整数解

    2019-05-17 16:04:37 加油,坚持就是胜利,fightting m / i的情况,i可能等于0 #include <bits/stdc++.h> using namespa ...

  3. LeetCode Weekly Contest 25

    1. 507. Perfect Number 显然小于2的都不满足(尤其是负数的情况),进一步,显然质数都不满足,所以小于4的数,直接return false. 然后依次暴力枚举判断到sqrt(n), ...

  4. Datatable筛选数据

    DataRow[] drArr = dt.Select("C1=’abc’");//查询 还可以这样操作: DataRow[] drArr = dt.Select("C1 ...

  5. The name ‘InitialzeComponent’ does not exist in the current context

    在Visual Studio中创建Windows Store项目,在MainPage.xaml.cs中出现错误: The name 'InitialzeComponent' does not exis ...

  6. 通过Hibernate实现添加功能

    package com.demo.dao; import org.hibernate.Session; import org.hibernate.SessionFactory; import org. ...

  7. BeautifulSoup 库的使用记录

    BeautifulSoup 有何用途 如果我们需要通过脚本来抓取网络中的数据时,使用传统的字符解析等方法时是非常低效的,而BeautifulSoup则可以方便的通过接口来获取标签中所想要得到的数据.主 ...

  8. XML 之 命名空间详解

    最近学xml 遇到了点小问题qaq 找了n多的博客大佬,反复看了半小时终于明白了,可能我太蠢了... 基础的知识就不赘述,直接放“栗子”,切重点: <?xml version="1.0 ...

  9. axis2 1.7.1使用教程

    写在前面 本文只说Axis2的用法. 1.下载与部署 需要下载两个文件: 下载地址:http://mirrors.cnnic.cn/apache/axis/axis2/java/core/1.7.1/ ...

  10. Mac使用ssh登录远程linux系统查看jetty日志及同时使用github工具

    转载请注明出处:http://www.houxiurong.com/?post=27 Mac默认是安装了ssh工具软件的. 先用mac的 终端工具生成 id_rsa 和id_rsa.pub 秘钥,生成 ...