根據傳入時間推算半月時間段

主方法:

/**
     * 推算4個  半月時間段
     *
     * @param condition
     * @return
     */
    public EvErpPFDemandQC getDateEvTimeRangeQC(EvErpPFDemandQC condition) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(condition.getQueryTime());
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        //獲取當月、下月、下下月時間組
        EvErpPFDemandQC dateOne = getDateFirstAndLast(condition.getQueryTime(), 0);
        EvErpPFDemandQC dateTwo = getDateFirstAndLast(condition.getQueryTime(), 1);
        EvErpPFDemandQC dateThree = getDateFirstAndLast(condition.getQueryTime(), 2);
        if (day <= 15) {
            setCondition(condition, dateOne.getFirst(), dateOne.getFifteen(), dateOne.getSixteen(), dateOne.getLast(), dateTwo.getFirst(), dateTwo.getFifteen(), dateTwo.getSixteen(), dateTwo.getLast());
        } else {
            setCondition(condition, dateOne.getSixteen(), dateOne.getLast(), dateTwo.getFirst(), dateTwo.getFifteen(), dateTwo.getSixteen(), dateTwo.getLast(), dateThree.getFirst(), dateThree.getFifteen());
        }
        return condition;
    }

    

 封裝:

private void setCondition(EvErpPFDemandQC condition, Date startTimeOne, Date endTimeOne, Date startTimeTwo, Date endTimeTwo, Date startTimeThree, Date endTimeThree, Date startTimeFour, Date endTimeFour) {
        condition.setStartTimeOne(startTimeOne);
        condition.setEndTimeOne(endTimeOne);
        condition.setStartTimeTwo(startTimeTwo);
        condition.setEndTimeTwo(endTimeTwo);
        condition.setStartTimeThree(startTimeThree);
        condition.setEndTimeThree(endTimeThree);
        condition.setStartTimeFour(startTimeFour);
        condition.setEndTimeFour(endTimeFour);
    }

   

獲取具體時間時鐘格式值:

 /**
     * 獲取月份開始/結束/月中日期(精確到yyyy-MM-dd HH:mm:ss)
     *
     * @param queryTime
     * @param i
     * @return
     */
    public EvErpPFDemandQC getDateFirstAndLast(Date queryTime, Integer i) {
        EvErpPFDemandQC condition=new EvErpPFDemandQC();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(queryTime);
        calendar.add(Calendar.MONTH, i);//月份
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONDAY);
        int maximum = calendar.getActualMaximum(Calendar.DATE);
        //第一天
        calendar.set(year, month, 1,00, 00, 00);//月份第一天
        condition.setFirst(calendar.getTime());
        //第十六天
        calendar.set(year, month, 16, 00, 00, 00);
        condition.setSixteen(calendar.getTime());
        //第十五天
        calendar.set(year, month, 15, 23, 59, 59);//最後一刻
        condition.setFifteen(calendar.getTime());
        //最後一天
        calendar.set(year, month, maximum, 23, 59, 59);//月份最後一天
        condition.setLast(calendar.getTime());
        return condition;
    }

 實體:

package cn.lionbridgecapital.ev.erp.condition.everpproplexquartz;

import cn.lionbridgecapital.ev.core.pojo.QueryCondition;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.Date;

/**
 * @author wangguangle
 * @date 2019/11/15 20:05
 */
@ApiModel(value = "[XXXXXX數據查詢參數")
@JsonIgnoreProperties(ignoreUnknown = true)
public class EvErpPFDemandQC extends QueryCondition {

    @ApiModelProperty(value = "選擇時間 yyyy-MM-dd HH:mm:ss - yyyy-MM-dd HH:mm:ss")
    private Date queryTime;

    /**
     * 月份第一天
     */
    @JsonIgnore
    private Date startTimeOne;

    /**
     * 第一段結束時間
     */
    @JsonIgnore
    private Date endTimeOne;

    /**
     * 第二段開始時間
     */
    @JsonIgnore
    private Date startTimeTwo;

    /**
     * 第二段結束時間
     */
    @JsonIgnore
    private Date endTimeTwo;

    /**
     * 第三段開始時間
     */
    @JsonIgnore
    private Date startTimeThree;

    /**
     * 第三段結束時間
     */
    @JsonIgnore
    private Date endTimeThree;

    /**
     * 第四段開始時間
     */
    @JsonIgnore
    private Date startTimeFour;

    /**
     * 第四段結束時間
     */
    @JsonIgnore
    private Date endTimeFour;

    /**
     * 月份第一天
     */
    @JsonIgnore
    private Date first;

    /**
     * 月份第15天
     */
    @JsonIgnore
    private Date fifteen;

    /**
     * 月份第16天
     */
    @JsonIgnore
    private Date sixteen;

    /**
     * 月份最後一天
     */
    @JsonIgnore
    private Date last;

    public EvErpPFDemandQC() {
    }

    public Date getQueryTime() {
        return queryTime;
    }

    public void setQueryTime(Date queryTime) {
        this.queryTime = queryTime;
    }

    public Date getStartTimeOne() {
        return startTimeOne;
    }

    public void setStartTimeOne(Date startTimeOne) {
        this.startTimeOne = startTimeOne;
    }

    public Date getEndTimeOne() {
        return endTimeOne;
    }

    public void setEndTimeOne(Date endTimeOne) {
        this.endTimeOne = endTimeOne;
    }

    public Date getStartTimeTwo() {
        return startTimeTwo;
    }

    public void setStartTimeTwo(Date startTimeTwo) {
        this.startTimeTwo = startTimeTwo;
    }

    public Date getEndTimeTwo() {
        return endTimeTwo;
    }

    public void setEndTimeTwo(Date endTimeTwo) {
        this.endTimeTwo = endTimeTwo;
    }

    public Date getStartTimeThree() {
        return startTimeThree;
    }

    public void setStartTimeThree(Date startTimeThree) {
        this.startTimeThree = startTimeThree;
    }

    public Date getEndTimeThree() {
        return endTimeThree;
    }

    public void setEndTimeThree(Date endTimeThree) {
        this.endTimeThree = endTimeThree;
    }

    public Date getStartTimeFour() {
        return startTimeFour;
    }

    public void setStartTimeFour(Date startTimeFour) {
        this.startTimeFour = startTimeFour;
    }

    public Date getEndTimeFour() {
        return endTimeFour;
    }

    public void setEndTimeFour(Date endTimeFour) {
        this.endTimeFour = endTimeFour;
    }

    public Date getFirst() {
        return first;
    }

    public void setFirst(Date first) {
        this.first = first;
    }

    public Date getFifteen() {
        return fifteen;
    }

    public void setFifteen(Date fifteen) {
        this.fifteen = fifteen;
    }

    public Date getSixteen() {
        return sixteen;
    }

    public void setSixteen(Date sixteen) {
        this.sixteen = sixteen;
    }

    public Date getLast() {
        return last;
    }

    public void setLast(Date last) {
        this.last = last;
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章