日期分时段校验规则

package com.sinosoft.lis.g_fs;

import com.sinosoft.lis.pubfun.GlobalInput;
import com.sinosoft.lis.pubfun.PubFun;
import com.sinosoft.lis.pubfun.PubFun1;
import com.sinosoft.lis.schema.LDSysVarSchema;
import com.sinosoft.lis.taskservice.TaskThread;
import com.sinosoft.utility.ExeSQL;
import com.sinosoft.utility.SQLwithBindVariables;
import com.sinosoft.utility.TransferData;
import org.apache.log4j.Logger;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;

/**
* Created by Ontheway on 2018/10/31.
* 资金制盘批处理

    *每个工作日早上8点~下午4:00核心进行自动制盘和推送,非此时间段,系统不进行自动制盘和推送


*/
public class LJMassGetSendToFSBacthTask extends TaskThread {

private static Logger logger = Logger.getLogger(LJMassGetSendToFSBacthTask.class);

String tDealDate = PubFun.getCurrentDate();
private ExeSQL mExeSQL = new ExeSQL();

//年
private String year;
//年月日
private String yearMonth;
//星期中的第几天
private int isTodayDate;
//当前时分秒
private String isTodayHour;

private String mOperate ="GENERATE_BACTH";
String format ="HH:mm:ss";

/**
* 获取星期几和时间
*/
public void getDate(){

Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateNowStr = sdf.format(d);
year=dateNowStr.substring(0,4);//年
yearMonth=dateNowStr.substring(0,10);//年月日
isTodayHour=dateNowStr.substring(11,19);//十分秒

Calendar cal=Calendar.getInstance();
isTodayDate=cal.get(Calendar.DAY_OF_WEEK)-1; //周几
//String.valueOf(isTodayHour);
if(isTodayDate ==0){
isTodayDate=7; //周日
}
logger.info("------年"+year+"------年月日"+yearMonth+"------周"+isTodayDate+"------十分秒"+isTodayHour);
}

@Override
public boolean dealMain() {
logger.info("资金收费发盘批处理运行开始!!!!!" + System.currentTimeMillis());
GlobalInput tGlobalInput = new GlobalInput();
tGlobalInput.ComCode = "00";
tGlobalInput.ManageCom = "86";
tGlobalInput.Operator = "sys";
//代收类型--收费
String typeFlag = "S";
//制盘开始日期
String startDate = yearMonth;
//制盘结束日期
String endDate = yearMonth;

StringBuffer mStrBuff = new StringBuffer();
mStrBuff.append(" SELECT 1 FROM LDWorkCalendar a WHERE a.datetype='N' and year='" + "?year?" + "' and caldate='" + "?caldate?" + "' "); //非工作日
SQLwithBindVariables sqlbv1 = new SQLwithBindVariables();
sqlbv1.sql(mStrBuff.toString());
sqlbv1.put("year", year);
sqlbv1.put("caldate", yearMonth);
String returnOne = mExeSQL.getOneValue(sqlbv1);

logger.info("returnOne-----------"+returnOne);

try {
//年份中的非节假日
if(("").equals(returnOne)){
//收费--契约、保全 理赔
boolean dateQBL = payContract();
logger.info("dateQBL----------"+dateQBL);
if(dateQBL){
logger.info("收费--契约、保全 理赔——时间点校验成功开始制盘啦啦啦啦!!!1");

}
}

//收费--续期 大制盘 不区分节假日
boolean dateXQL = payRenewalLarge();
if(dateXQL){
logger.info("收费--续期大制盘——时间点校验成功开始制盘啦啦啦啦!!!1");

}
//收费--续期 小制盘 不区分节假日
boolean dateXQS = payRenewalSmall();
if(dateXQS){
logger.info("收费--续期小制盘——时间点校验成功开始制盘啦啦啦啦!!!1");

}
} catch (Exception e) {
e.printStackTrace();
return false;
}

return true;
}

/**
* 收费--契约、保全 理赔
* 工作日早上08:00:00点~下午16:00:00
* @return
*/
public boolean payContract(){
try {
Date nowTime=new SimpleDateFormat(format).parse(isTodayHour);
Date startTime=new SimpleDateFormat(format).parse("08:00:00");
Date endTime=new SimpleDateFormat(format).parse("16:00:00");
boolean date = isDate(nowTime, startTime, endTime);
} catch (ParseException e) {
e.printStackTrace();
return false;
}
return true;
}

/**
* 收费--续期
* 每周一、三、五, 大制盘,不区分工作日,
* 早上10:00:00点~下午15:00:00
* @return
*/
public boolean payRenewalLarge(){
try {
if(isTodayDate ==1 || isTodayDate ==3 ||isTodayDate ==5){
Date nowTime=new SimpleDateFormat(format).parse(isTodayHour);
Date startTime=new SimpleDateFormat(format).parse("10:00:00");
Date endTime=new SimpleDateFormat(format).parse("15:00:00");

Calendar sixtyDaysAgo = Calendar.getInstance();
sixtyDaysAgo.add(Calendar.DAY_OF_MONTH, -60);
String endDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(sixtyDaysAgo.getTime());
logger.info("60天前--------"+endDate);
boolean date = isDate(nowTime, startTime, endTime);
}else {
return false;
}
} catch (ParseException e) {
e.printStackTrace();
return false;
}
return true;
}

/**
* 收费--续期
* 每周二、四、六、七,小制盘。不区分工作日,
* 早上10:00:00点~下午15:00:00
* @return
*/
public boolean payRenewalSmall(){
try {
if(isTodayDate ==2 || isTodayDate ==4 ||isTodayDate ==6 ||isTodayDate ==7 ){
Date nowTime=new SimpleDateFormat(format).parse(isTodayHour);
Date startTime=new SimpleDateFormat(format).parse("10:00:00");
Date endTime=new SimpleDateFormat(format).parse("15:00:00");

Calendar sixtyDaysAgo = Calendar.getInstance();
sixtyDaysAgo.add(Calendar.DAY_OF_MONTH, -60);
String endDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(sixtyDaysAgo.getTime());
logger.info("60天前--------"+endDate);

Calendar FiftyNineDaysAgo = Calendar.getInstance();
FiftyNineDaysAgo.add(Calendar.DAY_OF_MONTH, -59);
String FiftyNineDaysAgoEndDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(FiftyNineDaysAgo.getTime());
logger.info("59天前--------"+FiftyNineDaysAgoEndDate);

Calendar FiftyEightDaysAgo = Calendar.getInstance();
FiftyEightDaysAgo.add(Calendar.DAY_OF_MONTH, -58);
String FiftyEightDaysAgoEndDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(FiftyEightDaysAgo.getTime());
logger.info("58天前--------"+FiftyEightDaysAgoEndDate);

boolean date = isDate(nowTime, startTime, endTime);
return true;
}else {
return false;
}
} catch (ParseException e) {
e.printStackTrace();
return false;
}
}




/**
* 判断时间点区间
* @param nowTime 当前时间
* @param startTime 开始时间
* @param endTime 结束时间
* @return
*/
public boolean isDate(Date nowTime,Date startTime,Date endTime ){
if((nowTime.getTime() == startTime.getTime()) || nowTime.getTime()==endTime.getTime()){
logger.info("当前时间-------"+nowTime.getTime());
return true;
}

Calendar date = Calendar.getInstance();
date.setTime(nowTime);

Calendar startDate = Calendar.getInstance();
startDate.setTime(startTime);

Calendar endDate = Calendar.getInstance();
endDate.setTime(endTime);

if(date.after(startDate) && date.before(endDate)){
return true;
}else{
logger.info("---------------时间点有误---------------");
return false;
}
}


public static void main(String[] args) {

LJMassGetSendToFSBacthTask t = new LJMassGetSendToFSBacthTask();
t.getDate();
t.dealMain();
//t.payRenewalSmall();

}









}
posted @ 2018-11-05 14:08  徒手攀岩  阅读(708)  评论(0编辑  收藏  举报