package com.cool.store.response;

import com.alibaba.excel.util.CollectionUtils;
import com.cool.store.dto.TallyBookDetailDTO;
import com.cool.store.entity.TallyBookDetailDO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

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

/**
 * @Author: WangShuo
 * @Date: 2025/04/01/14:07
 * @Version 1.0
 * @注释:
 */
@Data
public class TallyBookDetailResponse {
    @ApiModelProperty(value = "明细")
    private List<TallyBookDetailDTO> list;
    @ApiModelProperty(value = "成本总计")
    private BigDecimal total;
    @ApiModelProperty(value = "年")
    private Integer year;
    @ApiModelProperty(value = "月")
    private Integer month;

    public List<TallyBookDetailDTO> toDTO(List<TallyBookDetailDO> list){
        if (CollectionUtils.isEmpty(list)){
            return null;
        }
        return list.stream().map(item -> {
            TallyBookDetailDTO dto = new TallyBookDetailDTO();
            dto.setFieldName(item.getFieldName());
            dto.setFieldValue(item.getFieldValue());
            return dto;
        }).collect(Collectors.toList());
    }
}
