package org.jeecg.modules.itdmGongDan.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.itdmGongDan.convert.GongDanDetailConvert;
import org.jeecg.modules.itdmGongDan.dto.DeviceCalendarQueryDTO;
import org.jeecg.modules.itdmGongDan.entity.ItdmGongdanDetail;
import org.jeecg.modules.itdmGongDan.service.IItdmGongdanDetailService;
import org.jeecg.modules.itdmGongDan.service.IItdmGongdanMasterService;
import org.jeecg.modules.itdmGongDan.vo.DeviceCalendarDeviceListVO;
import org.jeecg.modules.itdmGongDan.vo.DeviceCalendarVO;
import org.jeecg.modules.weituo.entity.ItdmWeituoInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@Api(tags = "设备日历")
@RequestMapping("/deviceCalendar")
@Slf4j
public class DeviceCalendarController extends JeecgController<ItdmGongdanDetail, IItdmGongdanDetailService> {
    @Autowired
    @SuppressWarnings("all")
    private IItdmGongdanDetailService itdmGongdanDetailService;
    @Autowired
    @SuppressWarnings("all")
    private IItdmGongdanMasterService iItdmGongdanMasterService;

    @ApiOperation(value="设备日历", notes="设备日历")
    @GetMapping(value = "/list")
    public List<DeviceCalendarVO> deviceCalendarLis(DeviceCalendarQueryDTO dto) {

        List<Date> list = itdmGongdanDetailService.workDateList(dto);
        List<DeviceCalendarVO> list1 = list.stream().map(i->{
            List<DeviceCalendarDeviceListVO> deviceList = itdmGongdanDetailService.planDeviceList(i);
            List<DeviceCalendarDeviceListVO> deviceWeituoList = deviceList.stream().map(d->{
                DeviceCalendarQueryDTO dto1 = new DeviceCalendarQueryDTO();
                dto1.setJihuaDeviceId(d.getJihuaDeviceId());
                dto1.setWorkDate(i);
                List<ItdmWeituoInfo> weituoInfoList = itdmGongdanDetailService.weituoList(dto1);
                return GongDanDetailConvert.INSTANCE.convertWeituo(d,weituoInfoList);
            }).collect(Collectors.toList());
            return GongDanDetailConvert.INSTANCE.convertDeviceCalendarVO(i,deviceWeituoList);
        }).collect(Collectors.toList());
        return list1;
    }






}
