package com.zzsmart.qomo.kn.cost.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzsmart.qomo.kn.cost.manage.entity.CostMaterialProcessHours;
import com.zzsmart.qomo.kn.cost.manage.mapper.CostMaterialProcessHoursMapper;
import com.zzsmart.qomo.kn.cost.manage.service.CostMaterialProcessHoursService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 物料工时工序表 服务实现类
 * </p>
 *
 * @author
 * @since 2024-06-19
 */
@Service
public class CostMaterialProcessHoursServiceImpl extends ServiceImpl<CostMaterialProcessHoursMapper, CostMaterialProcessHours> implements CostMaterialProcessHoursService {
    @Autowired
    CostMaterialProcessHoursMapper costMaterialProcessHoursMapper;

    /**
     * 查询满足物料编号的工时工序
     *
     * @param materialNos
     */
    @Override
    public Map<String, List<CostMaterialProcessHours>> getProcessHoursByMaterialNo(List<String> materialNos) {
        Map<String, List<CostMaterialProcessHours>> map = new HashMap<>();
        QueryWrapper<CostMaterialProcessHours> queryWrapper = new QueryWrapper();
        if (materialNos != null && materialNos.size() > 0) {
            queryWrapper.in("material_code", materialNos);
            List<CostMaterialProcessHours> costMaterialProcessHours = costMaterialProcessHoursMapper.selectList(queryWrapper);
            for (int i = 0; i < costMaterialProcessHours.size(); i++) {
                CostMaterialProcessHours costMaterialProcessHours1 = costMaterialProcessHours.get(i);
                String materialCode = costMaterialProcessHours1.getMaterialCode();
                if (map.containsKey(materialCode)) {
                    List<CostMaterialProcessHours> list = map.get(materialCode);
                    list.add(costMaterialProcessHours1);
                    map.put(materialCode, list);
                } else {
                    List<CostMaterialProcessHours> list = new ArrayList<>();
                    list.add(costMaterialProcessHours1);
                    map.put(materialCode, list);
                }
            }
        }
        return map;
    }
}
