package org.jeecg.modules.orderplatform.util;

import cn.com.ctop.common.module.service.IProjectService;
import org.jeecg.modules.orderplatform.entity.PlatformMaterial;
import org.jeecg.modules.orderplatform.entity.PlatformOrder;
import org.jeecg.modules.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class DictHandler {

    @Autowired
    ISysUserService sysUserService;

    @Autowired
    IProjectService projectService;

    public List<PlatformOrder> dictHandlerOrders(List<PlatformOrder> data){
        data.forEach(platformOrder -> {
            platformOrder.setDesignName(sysUserService.getById(platformOrder.getDesign()).getRealname());
            platformOrder.setCreateByName(sysUserService.getById(platformOrder.getCreateBy()).getRealname());
            platformOrder.setProjectName(projectService.getById(platformOrder.getProject()).getProjectName());
        });
        return data;
    }

    public PlatformOrder dictHandlerOrder(PlatformOrder data){
        data.setDesignName(sysUserService.getById(data.getDesign()).getRealname());
        data.setCreateByName(sysUserService.getById(data.getCreateBy()).getRealname());
        data.setProjectName(projectService.getById(data.getProject()).getProjectName());

        return data;
    }

    public List<PlatformMaterial> dictHandlerMaterial(List<PlatformMaterial> data){
        data.forEach(platformMaterial -> {
            if(!platformMaterial.getClip().isEmpty()){
                platformMaterial.setClipName(sysUserService.getById(platformMaterial.getClip()).getRealname());
            }
            if(!platformMaterial.getPlan().isEmpty()){
                platformMaterial.setPlanName(sysUserService.getById(platformMaterial.getPlan()).getRealname());
            }
            if(!platformMaterial.getShot().isEmpty()){
                platformMaterial.setShotName(sysUserService.getById(platformMaterial.getShot()).getRealname());
            }
            platformMaterial.setProjectName(projectService.getById(platformMaterial.getProjectId()).getProjectName());
        });
        return data;
    }
}
