package com.engine.salary.entity.salaryacct.bo;

import com.engine.salary.entity.salaryacct.po.SalaryAcctResultLogPO;
import com.engine.salary.entity.salaryacct.po.SalaryAcctResultPO;
import com.engine.salary.enums.salaryaccounting.SalaryAcctResultDataSourceEnum;
import com.engine.salary.util.db.IdGenerator;
import org.apache.commons.lang3.math.NumberUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author Harryxzy
 * @date 2023/05/12 16:54
 * @description
 */
public class SalaryAcctResultLogBO {

    public static List<SalaryAcctResultLogPO> buildSalaryAcctResultLog(List<SalaryAcctResultPO> salaryAcctResultList, Long uid, SalaryAcctResultDataSourceEnum datasource){
        Date now = new Date();
        List<SalaryAcctResultLogPO> needInsertList = new ArrayList<>();
        salaryAcctResultList.stream().forEach(PO -> {
            needInsertList.add(SalaryAcctResultLogPO.builder()
                    .id(IdGenerator.generate())
                    .datasource(datasource.getValue())
                    .salaryAcctRecordId(PO.getSalaryAcctRecordId())
                    .salaryAcctResultId(PO.getId())
                    .salaryAcctEmpId(PO.getSalaryAcctEmpId())
                    .salaryItemId(PO.getSalaryItemId())
                    .employeeId(PO.getEmployeeId())
                    .operator(uid)
                    .operateTime(now)
                    .deleteType(NumberUtils.INTEGER_ZERO)
                    .updateTime(now)
                    .build());
        });
        return needInsertList;
    }
}
