package com.sw.mes.fb.accessory.service.impl;


import com.sw.mes.core.base.BaseServiceImpl;
import com.sw.mes.fb.accessory.dao.FbAccessoryOrderDao;
import com.sw.mes.fb.accessory.domain.OrderUpdate;
import com.sw.mes.fb.accessory.entity.FbAccessoryOrder;
import com.sw.mes.fb.accessory.service.FbAccessoryOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;


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

    /**
     * 建立监控记录
     * @param orderUpdate
     * @return
     */
    @Override
    public FbAccessoryOrder generateMonitorOrder(OrderUpdate orderUpdate) {
        FbAccessoryOrder order = new FbAccessoryOrder();
        order.setDeviceNo(orderUpdate.getDeviceNo());
        order.setDeviceSeat(orderUpdate.getDeviceSeat());
        order.setDeviceType(orderUpdate.getDeviceType());

        order.setMaterialIdBefore(orderUpdate.getBefore().getMaterialId());
        order.setMaterialTypeBefore(orderUpdate.getBefore().getMaterialType());
        order.setMaterialCodeBefore(orderUpdate.getBefore().getMaterialCode());
        order.setMaterialNameBefore(orderUpdate.getBefore().getMaterialName());
        order.setGoodsCodeBefore(orderUpdate.getBefore().getGoodsCode());
        order.setUserLifeBefore(orderUpdate.getBefore().getUseLife());
        order.setUseTimeBefore(orderUpdate.getBefore().getUseTime());
        order.setRemainLifeBefore(orderUpdate.getBefore().getRemainLife());
        order.setSpecificationBefore(orderUpdate.getBefore().getSpecification());
        order.setFactoryBefore(orderUpdate.getBefore().getFactory());

        order.setMaterialIdAfter(orderUpdate.getAfter().getMaterialId());
        order.setMaterialTypeAfter(orderUpdate.getAfter().getMaterialType());
        order.setMaterialCodeAfter(orderUpdate.getAfter().getMaterialCode());
        order.setMaterialNameAfter(orderUpdate.getAfter().getMaterialName());
        order.setGoodsCodeAfter(orderUpdate.getAfter().getGoodsCode());
        order.setUserLifeAfter(orderUpdate.getAfter().getUseLife());
        order.setUseTimeAfter(orderUpdate.getAfter().getUseTime());
        order.setRemainLifeAfter(orderUpdate.getAfter().getRemainLife());
        order.setSpecificationAfter(orderUpdate.getAfter().getSpecification());
        order.setFactoryAfter(orderUpdate.getAfter().getFactory());

        order.setUpDate(orderUpdate.getUpDate());
        order.setUpUser(orderUpdate.getUpUser());
        order.setUpUserId(orderUpdate.getUpUserId());
        order.setUpClassNo(orderUpdate.getUpClassNo());
        order.setUpTeamGroup(orderUpdate.getUpTeamGroup());

        order.setDownDate(orderUpdate.getDownDate());
        order.setDownUser(orderUpdate.getDownUser());
        order.setDownUserId(orderUpdate.getDownUserId());
        order.setDownClassNo(orderUpdate.getDownClassNo());
        order.setDownTeamGroup(orderUpdate.getDownTeamGroup());

        order.setCreateTime(orderUpdate.getCreateDate());
        order.setRemark(orderUpdate.getRemark());
        return order;
    }

    @Override
    public FbAccessoryOrder findByGoodsCodeBefore(String goodsCodeBefore) {
        List<FbAccessoryOrder> list = dao.findByGoodsCodeBeforeOrderByIdDesc(goodsCodeBefore);
        if (list.size() > 0){
            return list.get(0);
        }
        return null;
    }

    @Override
    public FbAccessoryOrder findByGoodsCodeAfter(String goodsCodeAfter) {
        List<FbAccessoryOrder> list = dao.findByGoodsCodeAfterOrderByIdDesc(goodsCodeAfter);
        if (list.size() > 0){
            return list.get(0);
        }
        return null;
    }
}
