package com.goafanti.order.service.impl;

import com.goafanti.common.constant.AFTConstants;
import com.goafanti.common.dao.TOrderAssistMapper;
import com.goafanti.common.dao.TOrderNewMapper;
import com.goafanti.common.dao.TOrderServiceMapper;
import com.goafanti.common.model.TOrderAssist;
import com.goafanti.common.model.TOrderNew;
import com.goafanti.common.utils.DateUtils;
import com.goafanti.core.mybatis.BaseMybatisDao;
import com.goafanti.order.bo.TOrderServiceBo;
import com.goafanti.order.bo.assistListBo;
import com.goafanti.order.service.OrderAssistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderAssistServiceImpl extends BaseMybatisDao<TOrderAssistMapper> implements OrderAssistService {
    @Autowired
    private TOrderAssistMapper tOrderAssistMapper;
    @Autowired
    private TOrderServiceMapper tOrderServiceMapper;
    @Override
    public int addAssist(TOrderAssist in) {
        return tOrderAssistMapper.insertSelective(in);
    }

    @Override
    public List<assistListBo> assistList(String orderNo) {
        return tOrderAssistMapper.assistList(orderNo);
    }

    @Override
    public int addAssistCheck(TOrderAssist in) {
        List<assistListBo> list = assistList(in.getOrderNo());
        for (assistListBo bo : list) {
            if (bo.getAid().equals(in.getAid())){
                return -1;
            }
        }

        return 0;
    }



    @Override
    public int deleteAssist(Integer id) {
        return tOrderAssistMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int addOrderService(TOrderServiceBo in) {
        if (in.getServiceTimes()!=null)in.setServiceTime(DateUtils.StringToDate(in.getServiceTimes(), AFTConstants.YYYYMMDD));
        return tOrderServiceMapper.insertSelective(in);
    }

    @Override
    public int deleteOrderService(Integer id) {
        return tOrderServiceMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<TOrderServiceBo> orderServiceList(String orderNo) {
        return tOrderServiceMapper.orderServiceList(orderNo);
    }
}
