package com.usky.iot.controller.web;


import com.aliyuncs.exceptions.ClientException;
import com.usky.common.core.bean.ApiResult;
import com.usky.common.log.annotation.Log;
import com.usky.common.log.enums.BusinessType;
import com.usky.iot.domain.PmWorkReport;
import com.usky.iot.service.PmWorkReportService;
import com.usky.iot.service.config.DingTalkAndMessage;
import com.usky.iot.service.vo.PmProjectTotalWorkTimeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
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;

    /**
     * 周工作报告查询
     *
     * @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
     */
    @Log(title = "新增/编辑工作报告", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public void add(@RequestBody PmWorkReport pmWorkReport) {
        pmWorkReportService.addReport(pmWorkReport);
    }

    /**
     * 统计工时
     *
     * @return
     */
    @GetMapping("/workTimeTotal")
    public ApiResult<PmProjectTotalWorkTimeVo> weekWork(@RequestParam(value = "nowYear", required = false) Integer nowYear,
                                                        @RequestParam(value = "dateType") Integer dateType,
                                                        @RequestParam(value = "dateNum") Integer dateNum) {
        return ApiResult.success(pmWorkReportService.countTime(nowYear, dateType, dateNum));
    }

    /**
     * 删除工作报告
     *
     * @param reportId 报告id
     */
    @Log(title = "删除工作报告", businessType = BusinessType.DELETE)
    @DeleteMapping("/del/{reportId}")
    public void del(@PathVariable("reportId") Integer reportId) {
        pmWorkReportService.deleteContent(reportId);
    }

    /**
     * 定时报告查询
     */
    @GetMapping("/timedReports")
    public ApiResult<List<PmWorkReport>> timedReportQuery() {
        return ApiResult.success(pmWorkReportService.timedReportQuery());
    }

}