package com.ruoyi.system.domain.excel;

import com.ruoyi.common.annotation.Excel;
import com.ruoyi.system.domain.ProjectUserCost;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author denis
 * @date 2023/7/11 14:18
 */
@Data
public class ProjectCostSummaryForExcel {

    @Excel(name = "项目名称")
    private String projectName;
    @Excel(name = "人员")
    private String content;
    private Long userId;
    private String projectId;
    @Excel(name = "工时", isStatistics = true)
    private String timesStr;
    private BigDecimal times;
    @Excel(name = "成本", isStatistics = true)
    private String costStr;
    private BigDecimal cost;

    public static ProjectCostSummaryForExcel init(ProjectUserCost cost, String userName, String projectName) {
        ProjectCostSummaryForExcel excel = new ProjectCostSummaryForExcel();
        excel.setProjectId(cost.getProjectId());
        excel.setProjectName(projectName);
        excel.setContent(userName + "（" + cost.getCostDay() + "）");
        excel.setTimes(cost.getCostDay());
        excel.setCost(cost.getPostCost());
        return excel;
    }

    public void setTimes(BigDecimal times) {
        this.times = times;
        this.timesStr = this.times == null ? "-" : String.format("%.2f", this.times);
    }

    public void setCost(BigDecimal cost) {
        this.cost = cost;
        this.costStr = this.cost == null ? "-" : String.format("%.2f", this.cost);
    }

    public void add(ProjectUserCost cost, String userName, String projectName) {
        addTime(cost.getCostDay());
        addCost(cost.getPostCost());
        this.content = this.content + " " + userName + "（" + cost.getCostDay() + "）";
    }

    public void addTime(BigDecimal t) {
        if (this.times != null && t != null) {
            setTimes(this.times.add(t));
        } else if (this.times == null) {
            setTimes(t);
        }
    }

    public void addCost(BigDecimal c) {
        if (this.cost != null && c != null) {
            setCost(this.cost.add(c));
        } else if (this.cost == null) {
            setCost(c);
        }
    }
}
