package jnpf.model.personnels.vo.rewardspunishments;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jnpf.entity.workflow.PunishmentsApproval;
import jnpf.entity.workflow.RewardApproval;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.groups.Default;
import java.math.BigDecimal;
import java.util.Date;

/**
 * @Title: AddStaffEmploymentApplyExcelVO
 * @Author: peng.hao
 * @create: 2024/2/19 17:32
 */
@Getter
@Setter
@EqualsAndHashCode
public class FtbEmploymentRewardExcelVO {
    /**
     * 姓名
     */
    @ExcelProperty(index = 0, value = "姓名")
    @NotBlank(message = "姓名不能为空", groups = Default.class)
    @Pattern(regexp = "^[\\u4e00-\\u9fa5a-zA-Z]{1,20}([·.][\\u4e00-\\u9fa5a-zA-Z]{1,20})*$", message = "请输入中文或英文名称，名字中间允许添加符号.或·")
    private String workerName;

    @ExcelIgnore
    private String userId;

    /**
     * 员工ID
     */
    @ExcelProperty(index = 1, value = "员工ID")
    @NotBlank(message = "员工ID不能为空", groups = Default.class)
    private String employeeID;
    /**
     * 组织
     */
    @ExcelProperty(index = 2, value = "组织")
    private String currOrgName;

    @ExcelIgnore
    private String currOrgId;

    /**
     * 岗位
     */
    @ExcelProperty(index = 3, value = "岗位")
    private String currPositionName;

    @ExcelIgnore
    private String currPositionId;

    /**
     * 奖惩类别
     */
    @ExcelProperty(index = 4, value = "奖惩类别")
    @NotBlank(message = "奖惩类别不能为空", groups = Default.class)
    private String type;
    /**
     * 奖惩类型名称
     */
    @ExcelProperty(index = 5, value = "奖惩类型名称")
    @NotBlank(message = "奖惩类型名称不能为空", groups = Default.class)
    private String punishmentTypeName;

    /**
     * 奖惩类别
     */
    @ExcelIgnore
    private String punishmentTypeId;
    /**
     * 奖惩金额
     */
    @ExcelProperty(index = 6, value = "奖惩金额")
    @NotNull(message = "奖惩金额不能为空", groups = Default.class)
    private String amount;

    @ExcelIgnore
    private BigDecimal amountReal;
    /**
     * 薪酬核算日期
     */
    @ExcelProperty(index = 7, value = "薪酬核算日期")
    @NotNull(message = "薪酬核算日期不能为空", groups = Default.class)
    private String day;

    @ExcelIgnore
    private Date dayReal;
    /**
     * 奖惩原因
     */
    @ExcelProperty(index = 8, value = "奖惩原因")
    @Length(max = 500, message = "奖惩原因不能超过500个字符", groups = Default.class)
    private String rewardReason;

    /**
     * 是否记入员工档案,0否1是
     */
    @JsonIgnore
    @ExcelIgnore
    private Integer isRecorded;

    /**
     * 乐捐
     *
     * @param rewardExcelVO
     * @return
     */
    public static PunishmentsApproval convertDonate(FtbEmploymentRewardExcelVO rewardExcelVO) {
        if (rewardExcelVO == null) {
            return null;
        }
        PunishmentsApproval punishmentsApproval = new PunishmentsApproval();
        punishmentsApproval.setDay(rewardExcelVO.getDayReal());
        punishmentsApproval.setAmount(rewardExcelVO.getAmountReal());
        punishmentsApproval.setRewardReason(rewardExcelVO.getRewardReason());
        punishmentsApproval.setStatus(4);
        punishmentsApproval.setOrgName(rewardExcelVO.getCurrOrgName());
        punishmentsApproval.setPostName(rewardExcelVO.getCurrPositionName());
        punishmentsApproval.setTypeName(rewardExcelVO.getPunishmentTypeName());
        punishmentsApproval.setType(rewardExcelVO.getPunishmentTypeId());
        punishmentsApproval.setIsRecorded(rewardExcelVO.getIsRecorded());
        punishmentsApproval.setUserId(rewardExcelVO.getUserId());
        punishmentsApproval.setLastModifyTime(new Date());
        return punishmentsApproval;
    }

    /**
     * 奖励
     */
    public static RewardApproval convertReward(FtbEmploymentRewardExcelVO rewardExcelVO) {
        if (rewardExcelVO == null) {
            return null;
        }
        RewardApproval rewardApproval = new RewardApproval();
        rewardApproval.setType(rewardExcelVO.getPunishmentTypeId());
        rewardApproval.setStatus(4);
        rewardApproval.setTypeName(rewardExcelVO.getPunishmentTypeName());
        rewardApproval.setAmount(rewardExcelVO.getAmountReal());
        rewardApproval.setDay(rewardExcelVO.getDayReal());
        rewardApproval.setRewardReason(rewardExcelVO.getRewardReason());
        rewardApproval.setUserId(rewardExcelVO.getUserId());
        rewardApproval.setIsRecorded(rewardExcelVO.getIsRecorded());
        rewardApproval.setOrgName(rewardExcelVO.getCurrOrgName());
        rewardApproval.setPostName(rewardExcelVO.getCurrPositionName());
        rewardApproval.setLastModifyTime(new Date());
        return rewardApproval;
    }
}
