package com.saye.hrs.service.impl;

import com.saye.hrs.commons.date.DateDUtil;
import com.saye.hrs.commons.string.StringDUtil;
import com.saye.hrs.mapper.DoctorMapper;
import com.saye.hrs.service.DoctorService;
import org.springframework.stereotype.Service;

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

/**
 * (Doctor)表服务实现类
 *
 * @author makejava
 * @since 2021-09-16 15:17:21
 */
@Service
public class DoctorServiceImpl implements DoctorService {
    @Resource
    private DoctorMapper doctorMapper;

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

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

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

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

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

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

        List<String> array = (List<String>) map.get("dayList");
        List<HashMap<Object, Object>> list = this.doctorMapper.findDoctorSchedualList(map);

        for(HashMap<Object, Object> dsMap:list){
            String work_date = (String) dsMap.get("WORK_DATE");
            String work_time = (String) dsMap.get("WORK_TIME");
            String limit_num = (String) dsMap.get("LIMIT_NUM");
            List<String> workDate = Arrays.asList(work_date.split(","));
            List<String> workTime = Arrays.asList(work_time.split(","));
            List<String> limitNum = Arrays.asList(limit_num.split(","));
            int index = 0;
            for(int i=0;i<array.size(); i++){
                if ((index = workDate.indexOf(array.get(i)))>=0){
                    if("0".equals(workTime.get(index))){
                        dsMap.put("dayMorning"+i,limitNum.get(index));
                        dsMap.put("dayAfternoon"+i,"休");
                    }else{
                        dsMap.put("dayMorning"+i,"休");
                        dsMap.put("dayAfternoon"+i,limitNum.get(index));
                    }
                }else{
                    dsMap.put("dayMorning"+i,"休");
                    dsMap.put("dayAfternoon"+i,"休");
                }
            }
        }
        return list;
    }
}
