package jnpf.model.personnels.req.transfer;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSON;
import jnpf.model.personnels.dto.salary.BaseSalaryStructureDTO;
import jnpf.model.personnels.dto.turnover.FtbPersonnelsTurnoverHandoverDTO;
import jnpf.model.personnels.po.FtbPersonnelsTransferManage;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;

@Data
public class FtbHandleTransferDTO extends BaseSalaryStructureDTO {

    /**
     * 重新办理时传入之前的办理id
     */
    private String id;

    /**
     * 调动类型0调岗1晋升2降职3调店
     */
    @NotNull(message = "调动类型不能为空")
    private Integer state;

    /**
     * 调动人用户id
     */
    @NotBlank(message = "用户id不能为空")
    private String userId;

    /**
     * 调动前组织id
     */
    @NotBlank(message = "调动前组织id不能为空")
    private String beforeOrgId;
    /**
     * 调动前组织名称
     */
    private String beforeOrgName;
    /**
     * 调动前岗位id
     */
    @NotBlank(message = "调动前岗位id不能为空")
    private String beforePostId;
    /**
     * 调动前岗位名称
     */
    private String beforePostName;
    /**
     * 调动前职级id
     */
    private String beforeRankId;
    /**
     * 调动前职级名称
     */
    private String beforeRankName;
    /**
     * 调动后组织id
     */
    @NotBlank(message = "调动后组织id不能为空")
    private String afterOrgId;
    /**
     * 调动后组织名称
     */
    private String afterOrgName;

    /**
     * 调动后岗位id
     */
    @NotBlank(message = "调动后岗位id不能为空")
    private String afterPostId;
    /**
     * 调动后岗位名称
     */
    private String afterPostName;
    /**
     * 调动后职级id
     */
    private String afterRankId;
    /**
     * 调动后职级名称
     */
    private String afterRankName;

    /**
     * 生效时间
     */
    @NotNull(message = "生效时间不能为空")
    private Date effectiveDate;

    /**
     * 调动前班组id
     */
    private String beforeTeamId;

    /**
     * 调动后班组id
     */
    private String afterTeamId;
    /**
     * 调动备注
     */
    private String remarks;

    /**
     * 附件
     */
    private String files;

    /**
     * 工作/物品交接列表
     */
    private List<FtbPersonnelsTurnoverHandoverDTO> workerPositionHandoverList;

    /**
     * 调动前班组名称
     */
    private String beforeTeamName;

    /**
     * 调动后班组名称
     */
    private String afterTeamName;

    /**
     * 调动前直属主管id
     */
    private String beforeDirectSupervisorId;
    /**
     * 调动前直属主管名称
     */
    private String beforeDirectSupervisorName;

    /**
     * 调动后直属主管id
     */
    private String afterDirectSupervisorId;
    /**
     * 调动后直属主管名称
     */
    private String afterDirectSupervisorName;
    /**
     * 来源0非员工申请1员工申请
     */
    private Integer source;

    public FtbPersonnelsTransferManage convert(FtbHandleTransferDTO ftbHandleTransferDTO) {
        if (ftbHandleTransferDTO == null) {
            return null;
        }
        FtbPersonnelsTransferManage ftbPersonnelsTransferManage = new FtbPersonnelsTransferManage();
        ftbPersonnelsTransferManage.setUserId(ftbHandleTransferDTO.getUserId());
        ftbPersonnelsTransferManage.setBeforeOrgId(ftbHandleTransferDTO.getBeforeOrgId());
        ftbPersonnelsTransferManage.setBeforeOrgName(ftbHandleTransferDTO.getBeforeOrgName());
        ftbPersonnelsTransferManage.setBeforePostId(ftbHandleTransferDTO.getBeforePostId());
        ftbPersonnelsTransferManage.setBeforePostName(ftbHandleTransferDTO.getBeforePostName());
        ftbPersonnelsTransferManage.setBeforeRankId(ftbHandleTransferDTO.getBeforeRankId());
        ftbPersonnelsTransferManage.setBeforeRankName(ftbHandleTransferDTO.getBeforeRankName());
        ftbPersonnelsTransferManage.setBeforeTeamName(ftbHandleTransferDTO.getBeforeTeamName());
        ftbPersonnelsTransferManage.setBeforeTeamId(ftbHandleTransferDTO.getBeforeTeamId());

        ftbPersonnelsTransferManage.setAfterOrgId(ftbHandleTransferDTO.getAfterOrgId());
        ftbPersonnelsTransferManage.setAfterOrgName(ftbHandleTransferDTO.getAfterOrgName());
        ftbPersonnelsTransferManage.setAfterPostId(ftbHandleTransferDTO.getAfterPostId());
        ftbPersonnelsTransferManage.setAfterPostName(ftbHandleTransferDTO.getAfterPostName());
        ftbPersonnelsTransferManage.setAfterRankId(ftbHandleTransferDTO.getAfterRankId());
        ftbPersonnelsTransferManage.setAfterRankName(ftbHandleTransferDTO.getAfterRankName());

        ftbPersonnelsTransferManage.setAfterTeamId(ftbHandleTransferDTO.getAfterTeamId());
        ftbPersonnelsTransferManage.setAfterTeamName(ftbHandleTransferDTO.getAfterTeamName());

        ftbPersonnelsTransferManage.setEffectiveDate(ftbHandleTransferDTO.getEffectiveDate());
        ftbPersonnelsTransferManage.setSalaryStructure(ftbHandleTransferDTO.getIsAdjustSalary());
        // 调动类型
        ftbPersonnelsTransferManage.setState(ftbHandleTransferDTO.getState());
        // 薪酬
        ftbPersonnelsTransferManage.setSalaryType(ftbHandleTransferDTO.getSalaryType());
        ftbPersonnelsTransferManage.setPayrollSequence(ftbHandleTransferDTO.getPayrollSequence());
        ftbPersonnelsTransferManage.setPayrollSequenceId(ftbHandleTransferDTO.getPayrollSequenceId());
        ftbPersonnelsTransferManage.setSalaryStructureList(JSON.toJSONString(ftbHandleTransferDTO.getSalaryList()));
        ftbPersonnelsTransferManage.setSalaryTotal(ftbHandleTransferDTO.getSalaryTotal());
        ftbPersonnelsTransferManage.setPayrollSequenceName(ftbHandleTransferDTO.getPayrollSequenceName());

        ftbPersonnelsTransferManage.setRemarks(ftbHandleTransferDTO.getRemarks());
        ftbPersonnelsTransferManage.setFiles(ftbHandleTransferDTO.getFiles());
        ftbPersonnelsTransferManage.setBeforeTeamName(ftbHandleTransferDTO.getBeforeTeamName());
        ftbPersonnelsTransferManage.setAfterTeamName(ftbHandleTransferDTO.getAfterTeamName());
        // 物品/工作交接列表
        if (CollUtil.isNotEmpty(ftbHandleTransferDTO.getWorkerPositionHandoverList())) {
            ftbPersonnelsTransferManage.setWorkHandover(JSON.toJSONString(ftbHandleTransferDTO.getWorkerPositionHandoverList()));
        }
        // 判断生效时间是否是当前时间
        if (new Date().after(ftbHandleTransferDTO.getEffectiveDate())) {
            ftbPersonnelsTransferManage.setImplementType(1);
        } else {
            ftbPersonnelsTransferManage.setImplementType(0);
        }
        ftbPersonnelsTransferManage.setTaskInfoId(ftbHandleTransferDTO.getTaskId());

        ftbPersonnelsTransferManage.setBeforeDirectSupervisorId(ftbHandleTransferDTO.getBeforeDirectSupervisorId());
        ftbPersonnelsTransferManage.setBeforeDirectSupervisorName(ftbHandleTransferDTO.getBeforeDirectSupervisorName());
        ftbPersonnelsTransferManage.setAfterDirectSupervisorId(ftbHandleTransferDTO.getAfterDirectSupervisorId());
        ftbPersonnelsTransferManage.setAfterDirectSupervisorName(ftbHandleTransferDTO.getAfterDirectSupervisorName());
        ftbPersonnelsTransferManage.setSource(ftbHandleTransferDTO.getSource());
        return ftbPersonnelsTransferManage;
    }

}
