package com.cool.store.entity.tp;

import com.cool.store.entity.StoreDO;
import com.cool.store.utils.TpHelper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.*;

/**
 * <p>
 * 十二分制-积分流水
 * </p>
 *
 * @author wangff
 * @since 2025/11/4
 */
@Table(name = "zxjp_tp_score_journal")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TpScoreJournalDO {
    /**
     * id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 流水号
     */
    @Column(name = "journal_no")
    private String journalNo;

    /**
     * 门店id
     */
    @Column(name = "store_id")
    private String storeId;

    /**
     * 门店编码
     */
    @Column(name = "store_num")
    private String storeNum;

    /**
     * 加盟品牌
     */
    @Column(name = "join_brand")
    private Integer joinBrand;

    /**
     * 加盟模式
     */
    @Column(name = "join_model")
    private Integer joinModel;

    /**
     * 门店类型
     */
    @Column(name = "store_type")
    private Integer storeType;

    /**
     * 门店名称
     */
    @Column(name = "store_name")
    private String storeName;

    /**
     * 发生分值
     */
    @Column(name = "occur_score")
    private String occurScore;

    /**
     * 发生日期
     */
    @Column(name = "occur_date")
    private Date occurDate;

    /**
     * 发生前分值
     */
    @Column(name = "occur_before_score")
    private BigDecimal occurBeforeScore;

    /**
     * 发生后分值
     */
    @Column(name = "occur_after_score")
    private BigDecimal occurAfterScore;

    /**
     * 单据类型，0加分单 1警告书 2处罚书
     */
    @Column(name = "apply_type")
    private Integer applyType;

    /**
     * 来源单号
     */
    @Column(name = "apply_no")
    private String applyNo;

    /**
     * 项目大类
     */
    @Column(name = "project_category")
    private String projectCategory;

    /**
     * 项目名称
     */
    @Column(name = "project_name")
    private String projectName;

    /**
     * 规则id
     */
    @Column(name = "rule_id")
    private Long ruleId;

    /**
     * 规则编码
     */
    @Column(name = "rule_no")
    private String ruleNo;

    /**
     * 规则项目描述
     */
    private String remark;

    /**
     * 创建时间
     */
    @Column(name = "create_time")
    private Date createTime;

    /**
     * 更新时间
     */
    @Column(name = "update_time")
    private Date updateTime;

    public TpScoreJournalDO(StoreDO storeDO, TpApplyFormDO formDO, String occurScore, BigDecimal occurBeforeScore, BigDecimal occurAfterScore, String ruleRemark) {
        this.journalNo = TpHelper.generateScoreJournalNo();
        this.storeId = storeDO.getStoreId();
        this.storeNum = storeDO.getStoreNum();
        this.joinBrand = storeDO.getJoinBrand();
        this.joinModel = storeDO.getJoinModel();
        this.storeType = storeDO.getStoreType();
        this.storeName = storeDO.getStoreName();
        this.occurScore = occurScore;
        this.occurDate = new Date();
        this.occurBeforeScore = occurBeforeScore;
        this.occurAfterScore = occurAfterScore;
        this.applyType = formDO.getType();
        this.applyNo = formDO.getApplyNo();
        this.projectCategory = formDO.getProjectCategory();
        this.projectName = formDO.getProjectName();
        this.ruleId = formDO.getRuleId();
        this.ruleNo = formDO.getRuleNo();
        this.remark = ruleRemark;
    }
}