package com.sw.mes.plan.service.impl;


import com.sw.mes.core.base.BaseServiceImpl;
import com.sw.mes.core.dto.RankResultDto;
import com.sw.mes.fb.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.sw.mes.plan.entity.FbOrderMatchingInfo;
import com.sw.mes.plan.dao.FbOrderMatchingInfoDao;
import com.sw.mes.plan.service.FbOrderMatchingInfoService;

import java.util.List;


/**
 * @Author
 * @Description：
 * @Date: Create in
 * @Modified By:
 */
@Service
@Transactional
public class FbOrderMatchingInfoServiceImpl extends BaseServiceImpl<FbOrderMatchingInfo> implements FbOrderMatchingInfoService {
    FbOrderMatchingInfoDao dao;

    @Autowired
    public void setDao(FbOrderMatchingInfoDao dao) {
        super.setBaseDao(dao);
        this.dao = dao;
    }

    @Async
    @Override
    public void saveAsync(RankResultDto rankResultDto, FbOrderMatchingInfo fbOrderMatchingInfo) {
        if (fbOrderMatchingInfo == null) {
            fbOrderMatchingInfo = new FbOrderMatchingInfo();
        }
        if (StringUtils.isNotBlank(rankResultDto.getSectionNo())) {
            fbOrderMatchingInfo.setSectionNo(rankResultDto.getSectionNo());
        }
        if (StringUtils.isNotBlank(rankResultDto.getProductRank())) {
            fbOrderMatchingInfo.setProductLevel(rankResultDto.getProductRank());
        }
        if (StringUtils.isNotBlank(rankResultDto.getTestRank())) {
            fbOrderMatchingInfo.setProductLevelExperiment(rankResultDto.getTestRank());
        }
        if (StringUtils.isNotBlank(rankResultDto.getGradeType())) {
            fbOrderMatchingInfo.setGradeType(rankResultDto.getGradeType());
        }
        if (StringUtils.isNotBlank(rankResultDto.getOrderNo())) {
            fbOrderMatchingInfo.setFbOrderNo(rankResultDto.getOrderNo());
        }
        if (rankResultDto.getLength() != null) {
            fbOrderMatchingInfo.setLength(rankResultDto.getLength());
        }
        if (StringUtils.isNotBlank(rankResultDto.getSpecs())) {
            fbOrderMatchingInfo.setSpecs(rankResultDto.getSpecs());
        }
        if (StringUtils.isNotBlank(rankResultDto.getConductiveType())) {
            fbOrderMatchingInfo.setConductiveType(rankResultDto.getConductiveType());
        }
        if (StringUtils.isNotBlank(rankResultDto.getDopant())) {
            fbOrderMatchingInfo.setDopant(rankResultDto.getDopant());
        }
        if (StringUtils.isNotBlank(rankResultDto.getType())) {
            fbOrderMatchingInfo.setSectionType(rankResultDto.getType());
        }
        dao.save(fbOrderMatchingInfo);
    }

    @Override
    public List<FbOrderMatchingInfo> findBySectionNo(String sectionNo) {
       return dao.findBySectionNoOrderByIdDesc(sectionNo);
    }
}
