package com.sw.mes.yb.pad.service.impl;


import com.sw.mes.core.base.BaseServiceImpl;
import com.sw.mes.yb.pad.dao.ProductionPaintingLineHeadTailExceptionDao;
import com.sw.mes.yb.pad.entity.ProductionPaintingLineHeadTailException;
import com.sw.mes.yb.pad.entity.dto.ProductionPaintingLineHeadTailExceptionDto;
import com.sw.mes.yb.pad.service.ProductionPaintingLineHeadTailExceptionService;
import com.sw.mes.yb.production.entity.LongCrystal;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
* @Author
* @Description：
* @Date: Create in
* @Modified By:
*/
@Service
@Transactional
public class ProductionPaintingLineHeadTailExceptionServiceImpl extends BaseServiceImpl<ProductionPaintingLineHeadTailException> implements ProductionPaintingLineHeadTailExceptionService {
    ProductionPaintingLineHeadTailExceptionDao dao;
	@Autowired
    public void setDao(ProductionPaintingLineHeadTailExceptionDao dao) {
        super.setBaseDao(dao);
        this.dao=dao;
    }

    @Autowired
    ModelMapper modelMapper;

    @Override
    public void saveByType(LongCrystal longCrystal, List<ProductionPaintingLineHeadTailExceptionDto> exceptionDtos, int location) {
        if(null != exceptionDtos && exceptionDtos.size() > 0){
            for(ProductionPaintingLineHeadTailExceptionDto dto:exceptionDtos){
                ProductionPaintingLineHeadTailException productionPaintingLineHeadTailException = toLazy(dto);
                productionPaintingLineHeadTailException.setLocation(location);
                productionPaintingLineHeadTailException.setCrystalNo(longCrystal.getCrystalNo());
                dao.save(productionPaintingLineHeadTailException);
            }
        }
    }

    @Override
    public void deleteByCrystalNo(String crystalNo) {
        dao.deleteByCrystalNo(crystalNo);
    }

    private ProductionPaintingLineHeadTailException toLazy(ProductionPaintingLineHeadTailExceptionDto dto) {
        return modelMapper.map(dto, ProductionPaintingLineHeadTailException.class);
    }
}
