package com.boman.system.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.boman.common.core.utils.DateUtils;
//import com.boman.system.common.BaseTableSaveDTO;
import com.boman.system.service.ISysScheduleService;
import org.springframework.stereotype.Service;

import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author tjf
 * @Date: 2021/04/02/9:47
 */
@Service
public class SysScheduleServiceImpl implements ISysScheduleService {

    /**
     * 为日程表定制日程时间接口
     *
     * @param result
     * @return
     */
    @Override
    public List<JSONObject> setDay(List<JSONObject> result) {
        int num = 0;
        for (JSONObject jsonObject : result) {
            num = 0;
            Set<Map.Entry<String, Object>> entries = jsonObject.entrySet();
            //开始时间
            LocalDate beginTime = null;
            //结束时间
            LocalDate endTime = null;
            for (Map.Entry<String, Object> entry : entries) {
                String key = entry.getKey();
                if ("begin_time".equals(key)) {
                    beginTime = LocalDate.parse(entry.getValue().toString());
                    num++;
                } else if ("end_time".equals(key)) {
                    endTime = LocalDate.parse(entry.getValue().toString());
                    num++;
                } else if (num == 2) {
                    if (beginTime != null && endTime != null) {
                        List<LocalDate> datesBetween = DateUtils.getDatesBetween(beginTime, endTime);
                        jsonObject.put("all_date",datesBetween);
                        break;
                    }
                }
            }
        }
        return result;
    }
}
