package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.ActSuppliesDetails;
import com.ruoyi.system.mapper.ActMaterialMapper;
import com.ruoyi.system.mapper.ActSuppliesDetailsMapper;
import com.ruoyi.system.service.ActMaterialService;
import com.ruoyi.system.vo.ActMaterialVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 2024/3/19
 */
@Service
public class ActMaterialServiceImpl implements ActMaterialService {
    private ActMaterialMapper actMaterialMapper;
    private ActSuppliesDetailsMapper actSuppliesDetailsMapper;
    public ActMaterialServiceImpl(ActMaterialMapper actMaterialMapper, ActSuppliesDetailsMapper actSuppliesDetailsMapper){
        this.actMaterialMapper = actMaterialMapper;
        this.actSuppliesDetailsMapper = actSuppliesDetailsMapper;
    }
    @Override
    public AjaxResult getDateOfId(String mineId) {
        if (mineId == null || mineId.equals("")){
            return AjaxResult.error();
        }
        List<ActMaterialVO> actMaterialVO = actMaterialMapper.getDateOfId(mineId);
        if (actMaterialVO == null || actMaterialVO.size() == 0){
            ActSuppliesDetails actSuppliesDetails = new ActSuppliesDetails();
            List<ActSuppliesDetails> details = actSuppliesDetailsMapper.selectActSuppliesDetailsMaterialListPZ(actSuppliesDetails);
            if (mineId.equals("011704")){
                details.parallelStream()
                        .filter(v -> v.getCode().startsWith("30") || v.getCode().startsWith("31") || v.getCode().startsWith("32") ||
                                v.getCode().startsWith("33") || v.getCode().startsWith("34") || v.getCode().startsWith("35") ||
                                v.getCode().startsWith("36"))
                        .forEach(v -> v.setCodes("04"));
                details.parallelStream().filter(v -> v.getCode().startsWith("6199")).forEach(v -> v.setCodes("10"));
            }
            return AjaxResult.success(details);
        }
        return AjaxResult.success(actMaterialVO);
    }
}
