package com.ssj.bean.conch.conch.domain;

import com.ssj.bean.common.framework.core.domain.BaseEntity;
import com.ssj.framework.weixin.util.DateUtil;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.Date;
import java.util.Objects;

/**
 * @author sh
 * @className IntegralDetail
 * @description 积分明细类
 * @date 2020/6/2
 */
@Entity
@Table(name="scon_integral_detail")
public class IntegralDetail extends BaseEntity {

    private String vipId;
    /**
     * 变动类型 1-增加 2-减少
     */
    private int type;

    /**
     * 变动的积分值
     */
    private int integral;

    /**
     * 变动类目（积分变动详情原因）
     */
    private String title;

    /**
     * 操作类型
     * 1、完成作业 2、作业正确率 3、签到 4、周报对比 5、月报对比
     * 6、周报分享 7、月报分享 8、中奖信息分享、9 积分夺宝 10、积分兑换 11、积分失效
     */
    private int operType;

    /**
     * 积分变动时间
     */
    private Date createTime;

    /**
     * 积分是否失效 1-有效 2-无效
     */
    private int state;

    /**
     * 周报分享和对比，周报开始时间
     */
    private String startTime;

    /**
     * 周报分享和对比，周报结束时间
     */
    private String endTime;

    /**
     * 月报时间 格式 2020-06
     */
    private String reportMonth;

    /**
     * 详细科目
     * 科目或者奖品兑换码
     */
    private String detailCategory;

    public IntegralDetail(){}

    public IntegralDetail(int operType,String detailCategory){
        this.operType = operType;
        this.detailCategory = detailCategory;
        this.state = 1;
        String month = null;
        String startTime = null;
        String title= "";
        int type = 1;
        switch (operType){
            case 1:
                title="写"+detailCategory+"作业";
                break;
            case 2:
                title=detailCategory+"作业正确率";
                break;
            case 3:
                title="每日签到";
                break;
            case 4:
                title=detailCategory+"周报";
                Date beginDateTime = DateUtil.getEndOfLastWeek(new Date());
                LocalDate today = LocalDate.now();
                if (!Objects.equals(today.getDayOfWeek().getValue(), DayOfWeek.SUNDAY.getValue())) {
                    beginDateTime = DateUtil.addDays(beginDateTime, -7);
                }
                startTime=DateUtil.format_yyyyMMdd(beginDateTime);
                break;
            case 5:
                title="月报提高";
                month= DateUtil.format(DateUtil.getBeginOfLastMonth(new Date()).getTime(), "yyyy-MM");
                break;
            case 6:
                title=detailCategory+"周报分享";
                Date beginDateTime2 = DateUtil.getEndOfLastWeek(new Date());
                LocalDate today2 = LocalDate.now();
                if (!Objects.equals(today2.getDayOfWeek().getValue(), DayOfWeek.SUNDAY.getValue())) {
                    beginDateTime2 = DateUtil.addDays(beginDateTime2, -7);
                }
                startTime=DateUtil.format_yyyyMMdd(beginDateTime2);
                break;
            case 7:
                title="月报分享";
                month=DateUtil.format(DateUtil.getBeginOfLastMonth(new Date()).getTime(), "yyyy-MM");
                break;
            case 8:
                title="中奖分享";
                break;
            case 9:
                title="积分抽奖";
                type = 2;
                break;
            case 10:
                title="积分兑换";
                type = 2;
                break;
            case 11:
                title="积分过期";
                type = 2;
                break;
            default:
                break;
        }
        this.title = title;
        this.type = type;
        this.reportMonth = month;
        this.startTime=startTime;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getIntegral() {
        return integral;
    }

    public void setIntegral(int integral) {
        this.integral = integral;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public int getOperType() {
        return operType;
    }

    public void setOperType(int operType) {
        this.operType = operType;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public String getStartTime() {
        return startTime;
    }

    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public String getReportMonth() {
        return reportMonth;
    }

    public void setReportMonth(String reportMonth) {
        this.reportMonth = reportMonth;
    }

    public String getDetailCategory() {
        return detailCategory;
    }

    public void setDetailCategory(String detailCategory) {
        this.detailCategory = detailCategory;
    }

    public String getVipId() {
        return vipId;
    }

    public void setVipId(String vipId) {
        this.vipId = vipId;
    }
}
