package com.usky.iot.controller.web;


import com.usky.common.core.bean.ApiResult;
import com.usky.iot.domain.PmProject;
import com.usky.iot.domain.PmWorkReport;
import com.usky.iot.service.PmProjectService;
import com.usky.iot.service.PmWorkReportService;
import com.usky.iot.service.vo.PmProjectWorkTimeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 工作报告表 前端控制器
 * </p>
 *
 * @author fu
 * @since 2024-05-20
 */
@RestController
@RequestMapping("/pmWorkReport")
public class PmWorkReportController {
    @Autowired
    private PmWorkReportService pmWorkReportService;

    @Autowired
    private PmProjectService pmProjectService;

    /**
     * 周工作报告查询
     *
     * @param startDate 开始时间
     * @param endDate   结束时间
     * @param id        报告id
     * @return
     */
    @GetMapping("/week")
    public ApiResult<List<Map<String, List<PmWorkReport>>>> weekWork(@RequestParam(required = false) String startDate,
                                                  @RequestParam(required = false) String endDate,
                                                  @RequestParam(required = false, defaultValue = "0") Integer id) {

        return ApiResult.success(pmWorkReportService.weekWork(startDate, endDate, id));
    }

    /**
     * 添加工作报告
     *
     * @param
     */
    @PostMapping("/add")
    public void add(@RequestBody PmWorkReport pmWorkReport) {
        pmWorkReportService.addReport(pmWorkReport);
    }

    /**
     * 统计工时
     *
     * @return
     */
    @GetMapping("/workTimeTotal")
    public ApiResult<List<Map<String, Object>>> weekWork() {
        return ApiResult.success(pmWorkReportService.countTime());
    }
}