package com.bonus.sgzb.app.service.impl;

import com.bonus.sgzb.app.domain.StorageStatus;
import com.bonus.sgzb.app.mapper.HoldingLedgerMapper;
import com.bonus.sgzb.app.service.HoldingLedgerService;
import com.bonus.sgzb.base.api.domain.MachinePart;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author：梁超
 * @date：2024/4/19 - 17:48
 */

@Service
public class HoldingLedgerImpl implements HoldingLedgerService {

    @Resource
    private HoldingLedgerMapper holdingLedgerMapper;

    @Override
    public List<StorageStatus> getHoldingLedger(StorageStatus storageStatus) {
        List<StorageStatus> holdingLedger = holdingLedgerMapper.getHoldingLedger(storageStatus);
        if (holdingLedger.size() > 0) {
            for (StorageStatus bean : holdingLedger) {
                List<MachinePart> wholeSetDetails = holdingLedgerMapper.getWholeSetDetails(bean);
                for (MachinePart wholeSetDetail : wholeSetDetails) {
                    //获取生产厂家
                    String maSupplierInfo = holdingLedgerMapper.getMaSupplier(wholeSetDetail);
                    if (StringUtils.isBlank(maSupplierInfo)) {
                        wholeSetDetail.setSupplier(null);
                    } else {
                        wholeSetDetail.setSupplier(maSupplierInfo);
                    }

                    //获取总保有量、在库数、在用数
                    StorageStatus status = holdingLedgerMapper.getHoldingLedgerUserNum(wholeSetDetail);
                    wholeSetDetail.setNum(status.getNum());
                    wholeSetDetail.setUsNum(status.getUsNum());
                    wholeSetDetail.setAllNum(status.getAllNum());
                }
                bean.setWholeSetDetails(wholeSetDetails);
            }
        }
        return holdingLedger;
    }
}
