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.AppSceneCostMaterialProcessHours;
import com.zzsmart.qomo.kn.cost.manage.mapper.AppSceneCostMaterialProcessHoursMapper;
import com.zzsmart.qomo.kn.cost.manage.service.IAppSceneCostMaterialProcessHoursService;
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;

/**
 * @Description: app_scene_cost_material_process_hours
 * @Author: jeecg-boot
 * @Date: 2024-08-02
 * @Version: V1.0
 */
@Service
public class AppSceneCostMaterialProcessHoursServiceImpl extends ServiceImpl<AppSceneCostMaterialProcessHoursMapper, AppSceneCostMaterialProcessHours> implements IAppSceneCostMaterialProcessHoursService {
    @Autowired
    AppSceneCostMaterialProcessHoursMapper costMaterialProcessHoursMapper;

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