package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi;

import cn.estsh.i3plus.ext.mes.pcn.api.busi.IWorkOrderCreateSnErrorRecordService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesWorkOrderCreateSnErrorRecord;
import cn.estsh.i3plus.ext.mes.pcn.pojo.repository.MesWorkOrderCreateSnErrorRecordRepository;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @Description :
 * @Reference :
 * @Author : wangjie
 * @CreateDate : 2019-04-23
 * @Modify:
 **/
@Service
public class WorkOrderCreateSnErrorRecordService implements IWorkOrderCreateSnErrorRecordService {
    public static final Logger LOGGER = LoggerFactory.getLogger(WorkOrderCreateSnErrorRecordService.class);

    @Autowired
    private MesWorkOrderCreateSnErrorRecordRepository workOrderCreateSnErrorRecordRepository;

    @Override
    public void insertWorkOrderCreateSnErrorRecordNoRollback(MesWorkOrderCreateSnErrorRecord record) {
        workOrderCreateSnErrorRecordRepository.insert(record);
    }

    @Override
    public List<MesWorkOrderCreateSnErrorRecord> getWorkOrderCreateSnErrorRecordList(String organizeCode) {
        if (StringUtils.isEmpty(organizeCode)) {
            return null;
        }
        return workOrderCreateSnErrorRecordRepository.findByProperty(
                new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue()});
    }

    @Override
    public MesWorkOrderCreateSnErrorRecord getWorkOrderCreateSnErrorRecordByWorkOrderNo(String organizeCode, String workOrderNo) {
        if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(workOrderNo)) {
            return null;
        }
        return workOrderCreateSnErrorRecordRepository.getByProperty(
                new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.WORK_ORDER_NO},
                new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), workOrderNo});
    }

}
