package com.fjs.scenic.service.ord.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fjs.scenic.entity.order.ErrorOrder;
import com.fjs.scenic.mapper.order.ErrorOrderMapper;
import com.fjs.scenic.service.ord.ErrorOrderService;

@Service
public class ErrorOrderServiceImpl implements ErrorOrderService{
	
	@Autowired
	private ErrorOrderMapper mapper;
	
	@Override
	public List<ErrorOrder> select(ErrorOrder record) {
		return mapper.select(record);
	}

	@Override
	public void delete(ErrorOrder record) {
		mapper.delete(record);
	}
	
	@Override
    public int update(ErrorOrder obj) {
        return mapper.updateByPrimaryKeySelective(obj);
    }

	@Override
	public List<ErrorOrder> selectByParam(String field, String param) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("field", field);
		map.put("param", param);
		return mapper.selectByParam(map);
	}

	@Override
	public void updateByParam(String param) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("param", param);
		mapper.updateByParam(map);
	}

	@Override
	public void deleteByParam(String param) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("param", param);
		mapper.deleteByParam(map);
	}

	@Override
	public List<ErrorOrder> selectByJoin(String field, String param) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("field", field);
		map.put("param", param);
		return mapper.selectByJoin(map);
	}

	@Override
	public void inseterErrorOrder(String orderNo, String type, String desc) {
		List<ErrorOrder> eos = mapper.getErrorOrderByOrderNo(orderNo);
		if(eos==null || eos.size()<=0){
			ErrorOrder record = new ErrorOrder();
			record.setOrderNo(orderNo);
			record.setType(type);
			record.setTime(new Date());
			record.setDescription(desc);
			mapper.insert(record);
		}
		
	}

	@Override
	public void inseterErrorOrder(String orderNo, String type, String cashFee, String desc) {
		List<ErrorOrder> eos = mapper.getErrorOrderByOrderNo(orderNo);
		if(eos==null || eos.size()<=0){
			ErrorOrder record = new ErrorOrder();
			record.setOrderNo(orderNo);
			record.setType(type);
			record.setTime(new Date());
			record.setDescription(desc);
			record.setPrice(Integer.parseInt(cashFee));
			mapper.insert(record);
		}

	}

	@Override
	public void taskErrorOrder(ErrorOrder errorOrder) {
		List<ErrorOrder> eos = mapper.getErrorOrderByNumlt3();
		if(eos!=null && eos.size()>0){
			eos.forEach(eo->{
				
			});
		}
	}
}
