class ArrangementManagementServiceImpl implements ArrangementManagementService {

    @Override
    public CommonResult listArrangements(Date startDate, Date endDate, Integer departmentId){
        JSONObject returnJson = new JSONObject();
//        JSONArray arrangementResultsArray = new JSONArray();

//        List<HashMap<String, List<HashMap>>> arrangementLogs = new ArrayList<>();

        //时间范围内的每一天排班结果
        Date today = startDate;
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        while(today.compareTo(endDate) <= 0){
            //当日排班信息
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(today);

            List<HashMap> arrangementLogInfo = new ArrayList<>();
            List<HashMap> arrangements = arrangementMapper.listByDepartmentIdAndDatePeriod(today, today, departmentId);
            for(HashMap arrangement : arrangements){
                arrangement.remove("appointmentDate");
                arrangement.put("timeSlot", ConstantMap.convert("看诊时间段",
                        Byte.valueOf(String.valueOf(arrangement.get("timeSlot")))));
                arrangement.put("registrationLevel", ConstantMap.convert("挂号级别",
                        Byte.valueOf(String.valueOf(arrangement.get("registrationLevelId")))));
                arrangement.put("isValid", getStatusStr((Boolean)arrangement.get("isValid")));
                arrangementLogInfo.add(arrangement);
            }
            returnJson.put(formatter.format(today), arrangementLogInfo);

            // 下一天
            calendar.add(Calendar.DAY_OF_MONTH, 1);
            java.util.Date tomorrow = calendar.getTime();
            today = new Date(tomorrow.getTime());
        }

        return CommonResult.success(returnJson);


//        JSONArray arrangementResultsArray = new JSONArray();
//
//        JSONArray arrangementsArray = new JSONArray();
//        List<HashMap> arrangements = arrangementMapper.listByDepartmentIdAndDatePeriod(startDate, endDate, departmentId);
//
//        for(HashMap arrangement : arrangements) {
//            JSONObject arrangementResultJson = new JSONObject();
//
//            Date appointmentDate = (Date)arrangement.get("appointmentDate");
//            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
//            arrangement.put("appointmentDate", formatter.format(appointmentDate));
//            arrangement.put("timeSlot", ConstantMap.convert("看诊时间段",
//                    Byte.valueOf(String.valueOf(arrangement.get("timeSlot")))));
//            arrangement.put("registrationLevel", ConstantMap.convert("挂号级别",
//                    Byte.valueOf(String.valueOf(arrangement.get("registrationLevelId")))));
//            arrangement.put("isValid", getStatusStr((Boolean)arrangement.get("isValid")));
//
//            arrangementsArray.add(arrangement);
//        }
//
//        returnJson.put("arrangementResults", arrangementResultsArray);
//        return CommonResult.success(returnJson);
    }

}