package com.xisc.pm.api.dto;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.choerodon.core.exception.CommonException;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 组合板信息DTO
 * @author jun.zeng
 *
 */
@Data
public class PmCompositeBlockDTO implements Serializable {
    
    private static final long serialVersionUID = -3377573848722109294L;

    @ApiModelProperty("Block号,前端输入")
    private Integer blockNo;
    
    @ApiModelProperty("组合板长度,前端输入")
    private BigDecimal blockLength;
    
    @ApiModelProperty("组合板宽度,前端输入")
    private BigDecimal blockWidth;
    
    @ApiModelProperty("小板个数,前端输入")
    private Integer blkSpNum;
    
    @ApiModelProperty("合同个数,前端输入")
    private Integer blkOrderNum ;
    
    @ApiModelProperty("子板信息,前端输入")
    private List<PmSmallPlateDTO> smallPlateDTOList ;
    
    public Map<String , BigDecimal> check() {
        if(this.blockLength == null) {
            throw new CommonException("pm.pm_pro_cont_009", "组合子板长");
        }
        if(this.blockWidth == null) {
            throw new CommonException("pm.pm_pro_cont_009", "组合子板宽");
        }
        if(this.blkSpNum == null || blkSpNum == 0) {
            throw new CommonException("pm.pm_pro_cont_009", "小板数");
        }
        if(this.blkOrderNum == null || blkOrderNum == 0) {
            throw new CommonException("pm.pm_pro_cont_009", "合同数");
        }
        if(this.smallPlateDTOList == null ) {
            throw new CommonException("pm.pm_pro_cont_009", "子板");
        }
        if(this.smallPlateDTOList.size() != blkSpNum) {
            throw new CommonException("pm.pm_pro_cont_046", "子板");
        }
        Map<String , BigDecimal> calcAllOrderPlateCountMap = new HashMap<String, BigDecimal>();
        for (PmSmallPlateDTO pmSmallPlateDTO : smallPlateDTOList) {
            calcAllOrderPlateCountMap.put(pmSmallPlateDTO.getOrderNo(), BigDecimal.valueOf(pmSmallPlateDTO.getOrderBlockNum()));
            pmSmallPlateDTO.check();
        }
        return calcAllOrderPlateCountMap;
    }
    
}
