package com.mortals.xhx.module.attendance.model;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;
import java.math.BigDecimal;
import cn.hutool.core.date.DateUtil;
import java.util.Date;
import java.util.stream.Collectors;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mortals.framework.annotation.Excel;
import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.common.utils.BeanUtil;
import com.mortals.xhx.module.attendance.model.vo.AttendanceRecordErrorVo;
import lombok.Data;
import org.springframework.beans.BeanUtils;

/**
 * 考勤打卡记录异常信息实体对象
 *
 * @author zxfei
 * @date 2024-01-11
 */
@Data
public class AttendanceRecordErrorEntity extends AttendanceRecordErrorVo {
    private static final long serialVersionUID = 1L;

    /**
     * 员工ID
     */
    private Long staffId;
    /**
     * 员工姓名
     */
    @Excel(name = "员工姓名",sort = 1)
    private String staffName;
    /**
     * 工号
     */
    @Excel(name = "工号",sort = 2)
    private String workNum;
    /**
     * 所属部门
     */
    private Long deptId;
    /**
     * 所属部门名称
     */
    @Excel(name = "所属部门",sort = 4)
    private String deptName;
    /**
     * 职位ID
     */
    private Long positionId;
    /**
     * 职位名称
     */
    private String positionName;
    /**
     * 所属考勤组ID
     */
    private Long attendanceGroupId;
    /**
     * 所属考勤组名称
     */
    @Excel(name = "所属考勤组",sort = 5)
    private String attendanceGroupName;
    /**
     * 班次ID
     */
    private Long shiftsId;
    /**
     * 班次名称
     */
    private String shiftsName;
    /**
     * 上下班时间
     */
    @JsonFormat(pattern = "HH:mm")
    @JSONField(format = "HH:mm")
    @Excel(name = "上下班时间",sort = 9,dateFormat = "HH:mm")
    private Date goOffDateTime;
    /**
     * 异常时间
     */
    @Excel(name = "异常时间",sort = 7, width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date errorDateTime;
    /**
     * 实际打卡时间
     */
    @Excel(name = "实际打卡时间",sort = 10, width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date actualAttendanceDateTime;
    /**
     * 处理时间
     */
    @Excel(name = "处理时间",sort = 11, width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date operDateTime;
    /**
     * 处理人
     */
    private String opertor;
    /**
     * 异常状态(0.缺卡,1.早退,2.缺卡)
     */
    @Excel(name = "异常状态",sort = 6,readConverterExp = "0=缺卡,1=早退,2=迟到,3=正常,4=事假半天,5=事假全天")
    private Integer errorStatus;
    /**
     * 处理状态(0.未处理,1.已处理)
     */
    @Excel(name = "处理状态",sort = 12,readConverterExp = "0=未处理,1=已处理")
    private Integer processStatus;
    /**
     * 处理结果
     */
    @Excel(name = "处理结果",sort = 8,readConverterExp = "0=缺卡,1=早退,2=迟到,3=正常,4=事假半天,5=事假全天")
    private String processResult;
    /**
     * 备注
     */
    private String remark;
    /**
     * 所属大厅
     */
    private Long salaId;
    /**
     * 所属大厅名称
     */
    @Excel(name = "所属大厅",sort = 3)
    private String salaName;
    @Override
    public int hashCode() {
        return (this.getStaffId()+this.getProcessStatus()+this.getShiftsId()+this.getErrorDateTime().getTime()+"").hashCode();
    }
    @Override
    public boolean equals(Object obj) {
        if (obj == null) return false;
        if (obj instanceof AttendanceRecordErrorEntity) {
            AttendanceRecordErrorEntity tmp = (AttendanceRecordErrorEntity) obj;
/*            if (this.getId() == tmp.getId()) {
                return true;
            }*/

            if(this.getStaffId()==tmp.getStaffId()&&this.getProcessStatus()==tmp.getErrorStatus()
            &&this.getShiftsId()==tmp.getShiftsId()&&this.getErrorDateTime().getTime()==tmp.getErrorDateTime().getTime()){
                return true;
            }

        }
        return false;
    }

    public void initAttrValue(){
        this.staffId = null;
        this.staffName = "";
        this.workNum = "";
        this.deptId = null;
        this.deptName = "";
        this.positionId = null;
        this.positionName = "";
        this.attendanceGroupId = null;
        this.attendanceGroupName = "";
        this.shiftsId = null;
        this.shiftsName = "";
        this.goOffDateTime = null;
        this.errorDateTime = null;
        this.actualAttendanceDateTime = null;
        this.operDateTime = null;
        this.opertor = "";
        this.errorStatus = 0;
        this.processStatus = 0;
        this.processResult = "";
        this.remark = "";
        this.salaId = null;
        this.salaName = "";
    }


    public static void main(String[] args) {
        List<AttendanceRecordErrorEntity> list = new ArrayList<>();

        AttendanceRecordErrorEntity entity = new AttendanceRecordErrorEntity();
        entity.initAttrValue();

        entity.setStaffId(47L);
        entity.setProcessStatus(0);
        entity.setShiftsId(20L);
        entity.setErrorDateTime(DateUtil.parseDateTime("2024-07-12 12:00:00"));

        list.add(entity);

        AttendanceRecordErrorEntity  entity1 = new AttendanceRecordErrorEntity();
        BeanUtils.copyProperties(entity,entity1);
        entity1.setShiftsId(21L);
       // entity1.setErrorDateTime(DateUtil.parseDateTime("2024-07-12 12:00:01"));

        list.add(entity1);
        System.out.println(JSONObject.toJSONString(list));

        List<AttendanceRecordErrorEntity> collect = list.stream().distinct().collect(Collectors.toList());

        System.out.println("去重后");
        System.out.println(JSON.toJSONString(collect));


    }


}