package cn.iocoder.lyzsys.module.tjt.service.report.builder;

import lombok.Data;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.stereotype.Component;

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

@Component
public class ProjectLeadQuarterOutputExcelBuilder extends AbstractProjectOutputExcelBuilder {

    public Workbook build(ExportData data) {
        Workbook workbook = createWorkbook();
        Sheet sheet = createSheet(workbook, "项目负责人计取", "项目负责人计取");
        setColumnWidths(sheet, 8, 24, 14, 20, 12, 20, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12);

        CellStyle titleStyle = createTitleStyle(workbook);
        CellStyle infoStyle = createInfoStyle(workbook);
        CellStyle headerStyle = createHeaderStyle(workbook);
        CellStyle cellStyle = createCellStyle(workbook);

        int rowIndex = 0;
        rowIndex = writeMergedTitleRow(sheet, rowIndex, "项目负责人年度/季度计取表", titleStyle, 16);

        Row infoRow = sheet.createRow(rowIndex++);
        writeLabelValue(infoRow, 0, 1, "项目名称", data.getProjectName(), infoStyle);
        writeLabelValue(infoRow, 4, 5, "年度", data.getYear(), infoStyle);

        rowIndex = writeRow(sheet, rowIndex, headerStyle, (Object[]) new String[]{
                "序号", "规划内容", "项目经理人员", "项目经理比例", "项目负责人人员", "项目负责人比例",
                "项目经理一季度", "项目经理二季度", "项目经理三季度", "项目经理四季度", "项目经理年度合计",
                "项目负责人一季度", "项目负责人二季度", "项目负责人三季度", "项目负责人四季度",
                "项目负责人年度合计", "项目经理/项目负责人合计"
        });

        int serialNo = 1;
        for (LeadQuarterRow rowData : data.getRows()) {
            Row row = sheet.createRow(rowIndex++);
            setText(row, 0, serialNo++, cellStyle);
            setText(row, 1, rowData.getPlanningContent(), cellStyle);
            setText(row, 2, rowData.getProjectManagerNames(), cellStyle);
            setText(row, 3, percentText(rowData.getProjectManagerRatio()), cellStyle);
            setText(row, 4, rowData.getEngineeringPrincipalNames(), cellStyle);
            setText(row, 5, percentText(rowData.getEngineeringPrincipalRatio()), cellStyle);
            setText(row, 6, text(rowData.getProjectManagerQuarterOneAmount()), cellStyle);
            setText(row, 7, text(rowData.getProjectManagerQuarterTwoAmount()), cellStyle);
            setText(row, 8, text(rowData.getProjectManagerQuarterThreeAmount()), cellStyle);
            setText(row, 9, text(rowData.getProjectManagerQuarterFourAmount()), cellStyle);
            setText(row, 10, text(rowData.getProjectManagerYearTotalAmount()), cellStyle);
            setText(row, 11, text(rowData.getEngineeringPrincipalQuarterOneAmount()), cellStyle);
            setText(row, 12, text(rowData.getEngineeringPrincipalQuarterTwoAmount()), cellStyle);
            setText(row, 13, text(rowData.getEngineeringPrincipalQuarterThreeAmount()), cellStyle);
            setText(row, 14, text(rowData.getEngineeringPrincipalQuarterFourAmount()), cellStyle);
            setText(row, 15, text(rowData.getEngineeringPrincipalYearTotalAmount()), cellStyle);
            setText(row, 16, text(rowData.getTotalAmount()), cellStyle);
        }
        return workbook;
    }

    @Data
    public static class ExportData {
        private String projectName;
        private Integer year;
        private List<LeadQuarterRow> rows;
    }

    @Data
    public static class LeadQuarterRow {
        private String planningContent;
        private String projectManagerNames;
        private BigDecimal projectManagerRatio;
        private String engineeringPrincipalNames;
        private BigDecimal engineeringPrincipalRatio;
        private BigDecimal projectManagerQuarterOneAmount;
        private BigDecimal projectManagerQuarterTwoAmount;
        private BigDecimal projectManagerQuarterThreeAmount;
        private BigDecimal projectManagerQuarterFourAmount;
        private BigDecimal projectManagerYearTotalAmount;
        private BigDecimal engineeringPrincipalQuarterOneAmount;
        private BigDecimal engineeringPrincipalQuarterTwoAmount;
        private BigDecimal engineeringPrincipalQuarterThreeAmount;
        private BigDecimal engineeringPrincipalQuarterFourAmount;
        private BigDecimal engineeringPrincipalYearTotalAmount;
        private BigDecimal totalAmount;
    }

}
