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


import com.sw.mes.core.base.BaseServiceImpl;
import com.sw.mes.core.context.BaseContextHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.sw.mes.yb.production.entity.FbProductCard;
import com.sw.mes.yb.production.dao.FbProductCardDao;
import com.sw.mes.yb.production.service.FbProductCardService;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.Date;
import java.util.List;


/**
 * @Author
 * @Description：
 * @Date: Create in
 * @Modified By:
 */
@Service
@Transactional
public class FbProductCardServiceImpl extends BaseServiceImpl<FbProductCard> implements FbProductCardService {
    FbProductCardDao dao;

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

    @Override
    public FbProductCard findBySpecification(String specification) {
        List<FbProductCard> fbProductCardList = dao.findBySpecification(specification);
        if (fbProductCardList.size() > 0) {
            return fbProductCardList.get(0);
        }
        return null;
    }

    @Override
    public void softDelete(Serializable id) {
        FbProductCard entity = get(id);
        if (entity == null) {
            throw new RuntimeException("标准卡不存在");
        }
        entity.setDeletedTime(new Date());
        entity.setDeletedUser(BaseContextHandler.getUsername());
        entity.setDeletedUserId(BaseContextHandler.getUserID());
        entity.setDeleted(true);
        saveOrUpdate(entity);
    }
}
