package com.saye.hrs.service.impl;

import com.saye.hrs.commons.date.DateDUtil;
import com.saye.hrs.mapper.OrderMapper;
import com.saye.hrs.service.OrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * @author makejava
 * @since 2021-09-16 16:26:19
 */
@Service
public class OrderServiceImpl implements OrderService {
    @Resource
    private OrderMapper orderMapper;

    @Override
    public HashMap<Object, Object> findOrderById(HashMap<Object,Object> map) {
        return this.orderMapper.findOrderById(map);
    }

    @Override
    public  List<HashMap<Object, Object>> findOrderList(HashMap<Object,Object> map) {
        return this.orderMapper.findOrderList(map);
    }

    @Override
    public void insertOrder(HashMap<Object,Object> map) {
        this.orderMapper.insertOrder(map);
    }

    @Override
    public void updateOrder(HashMap<Object,Object> map) {
        this.orderMapper.updateOrder(map);
    }

    @Override
    public void deleteOrderById(HashMap<Object,Object> map) {
        this.orderMapper.deleteOrderById(map);
    }

	@Override
	public void cancelOrder(HashMap<Object, Object> map) {
		this.orderMapper.cancelOrder(map);
	}

	@Override
	public HashMap<Object, Object> findHomeData() {
		
		HashMap<Object,Object> requestMap = new HashMap<Object,Object>();
		requestMap.put("his_date", DateDUtil.DateToStr("yyyyMMdd", new Date()));
		requestMap.put("noHis_date", DateDUtil.DateToStr("yyyy-MM-dd", new Date()));
		HashMap<Object,Object> map = this.orderMapper.findHomeData(requestMap);
		Date date = new Date();
		String[] array = new String[7];
		for(int i=0;i<7;i++) {
			array[i] = DateDUtil.getPlusDays("yyyyMMdd", date, i);
		}
		//未来一周预约情况
		List<HashMap<Object,Object>> list = this.orderMapper.findOrderWeekNum(array);
		//最近一周充值情况
		for(int i=0;i<7;i++) {
			array[i] = DateDUtil.getPlusDays("yyyyMMdd", date,-i-1);
		}
		List<HashMap<Object,Object>> list1 = this.orderMapper.findRechargeWeekNum(array);
		//热门科室
		List<HashMap<Object,Object>> list2 = this.orderMapper.findOfficeOrderNum();

		//近7日住院充值趋势
		List<HashMap<Object,Object>> list3 = this.orderMapper.findhospitalizedWeekNum(array);
		map.put("weekOrder", list);
		map.put("weekrecharge", list1);
		map.put("weekhospitalized", list3);
		map.put("office", list2);
		return map;
	}

	@Override
	public void setWXLoginTime(HashMap<Object, Object> map) {
		map.put("login_time", DateDUtil.getTheCurrentTime());
		this.orderMapper.setWXLoginTime(map);
	}

	@Override
	public void generateOrderNotice() {
		HashMap<Object,Object> map = new HashMap<Object,Object>();
		map.put("yyrq", DateDUtil.getPlusDays("yyyyMMdd", new Date(), 1));
		this.orderMapper.generateOrderNotice(map);
	}

	@Override
	public List<HashMap<Object,Object>> findRechargeWait() {
		//查询等待支付的订单
		return this.orderMapper.findRechargeWait();
	}

	@Override
	public void addRefund(HashMap<Object, Object> map) {
		
		this.orderMapper.addRefund(map);
	}

	@Override
	public void addRefundMessageNotice(HashMap<Object, Object> map) {
		
		this.orderMapper.addRefundMessageNotice(map);
	}

	@Override
	public HashMap<Object, Object> findOrderNotice() {
		
		return this.orderMapper.findOrderNotice();
	}

	@Override
	public void updateOrderNotice(HashMap<Object, Object> map) {
		
		this.orderMapper.updateOrderNotice(map);
	}

	@Override
	public List<HashMap<Object, Object>> findDistinctOrderOffice() {

		return this.orderMapper.findDistinctOrderOffice();
	}
}
