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.AppSceneCostProductProcessMaintenance;
import com.zzsmart.qomo.kn.cost.manage.mapper.AppSceneCostProductProcessMaintenanceMapper;
import com.zzsmart.qomo.kn.cost.manage.service.IAppSceneCostProductProcessMaintenanceService;
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_product_process_maintenance
 * @Author: jeecg-boot
 * @Date: 2024-09-08
 * @Version: V1.0
 */
@Service
public class AppSceneCostProductProcessMaintenanceServiceImpl extends ServiceImpl<AppSceneCostProductProcessMaintenanceMapper, AppSceneCostProductProcessMaintenance> implements IAppSceneCostProductProcessMaintenanceService {

    @Autowired
    AppSceneCostProductProcessMaintenanceMapper costMaterialProcessHoursMapper;

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