package cn.wisenergy.web.admin.controller.app;

import cn.wisenergy.common.utils.DateUtil;
import cn.wisenergy.common.utils.exception.Result;
import cn.wisenergy.model.dto.CalendarDto;
import cn.wisenergy.model.dto.SubtotalDto;
import cn.wisenergy.service.WorkCollectService;
import cn.wisenergy.web.admin.controller.common.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
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;


@RestController
@RequestMapping(value = "/work/collect")
@Api(tags = "小程序工单日历模块")
@Slf4j
public class WorkCollectController extends BaseController {

    @Autowired
    private WorkCollectService workCollectService;

    @ApiOperation(value = "日历->月详细", notes = "日历展示", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "int", required = true),
            @ApiImplicitParam(name = "workMonth", value = "工单日期(yyyy-MM)", dataType = "String", required = true)
    })
    @GetMapping(value = "/month")
    public Result<List<CalendarDto>> calendarMonth(Integer userId, String workMonth) {
        log.info("WorkCollectController[]calendarMonth[]input.param.userId:{},workMonth:{}", userId, workMonth);
        Date date = DateUtil.convertStrToDate(workMonth, "yyyy-MM");
        List<CalendarDto> calendarDtos = workCollectService.calendarMonth(userId, date);
        return getResult( calendarDtos);
    }

    @ApiOperation(value = "日历->日详细", notes = "某日填报情况", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "int", required = true),
            @ApiImplicitParam(name = "workDay", value = "工单日期(yyyy-MM-dd)", dataType = "String", required = true)
    })
    @GetMapping(value = "/day")
    public Result<SubtotalDto> calendarDay(Integer userId, String workDay) {
        log.info("WorkCollectController[]calendarDay[]input.param.userId:{},workDay:{}", userId, workDay);
        Date date = DateUtil.convertStrToDate(workDay, "yyyy-MM-dd");
        SubtotalDto subtotalDto = workCollectService.calendarDay(userId, date);
        return getResult(subtotalDto);
    }



}
