package jnpf.model.personnels.dto.goods;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import jnpf.model.personnels.po.FtbPersonnelsGoodsReceive;
import lombok.Data;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;

@Data
public class FtbPersonnelsGoodsReceiveReturnDTO {

    /**
     * 领取Id
     */
    @NotNull(message = "领取Id不能为空")
    private String id;

    /**
     * 归还状态0未归还1部分归还2已归还3无需归还
     */
    @NotNull(message = "归还状态不能为空")
    private Integer returnStatus;

    /**
     * 归还数量
     */
    @NotNull(message = "归还数量不能为空")
    private Long returnedQuantity;

    /**
     * 归还日期，格式yyyy-MM-dd
     */
    @NotNull(message = "归还日期不能为空")
    private Date returnDate;

    /**
     * 备注
     */
    @Size(max = 500, message = "备注长度不能超过500位")
    private String remarks;

    public LambdaUpdateWrapper<FtbPersonnelsGoodsReceive> convert(FtbPersonnelsGoodsReceiveReturnDTO ftbPersonnelsGoodsReceiveReturnDTO) {
        LambdaUpdateWrapper<FtbPersonnelsGoodsReceive> updateWrapper = Wrappers.lambdaUpdate();
        updateWrapper.eq(FtbPersonnelsGoodsReceive::getId, ftbPersonnelsGoodsReceiveReturnDTO.getId());
        updateWrapper.set(FtbPersonnelsGoodsReceive::getReturnStatus, ftbPersonnelsGoodsReceiveReturnDTO.getReturnStatus());
        if (StrUtil.isNotBlank(ftbPersonnelsGoodsReceiveReturnDTO.getRemarks())) {
            updateWrapper.set(FtbPersonnelsGoodsReceive::getRemark, ftbPersonnelsGoodsReceiveReturnDTO.getRemarks());
        }
        updateWrapper.set(FtbPersonnelsGoodsReceive::getReturnTime, ftbPersonnelsGoodsReceiveReturnDTO.getReturnDate());
        updateWrapper.set(FtbPersonnelsGoodsReceive::getReturnedQuantity, ftbPersonnelsGoodsReceiveReturnDTO.getReturnedQuantity());
        return updateWrapper;
    }

}
