package com.tuoheng.miniprogram.controller;


import com.tuoheng.common.core.common.BaseController;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.miniprogram.dao.UserMapper;
import com.tuoheng.miniprogram.entity.dto.WorkOrderDto;
import com.tuoheng.miniprogram.entity.query.HandleQuery;
import com.tuoheng.miniprogram.entity.query.WorkOrderQuery;
import com.tuoheng.miniprogram.enums.DistributionWorkorderRequest;
import com.tuoheng.miniprogram.service.IWorkOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author ChengWang
 * @Date 2022/12/6
 */
@RestController
@RequestMapping("/workOrder")
@Slf4j
public class WorkOrderController extends BaseController {

    @Autowired
    private IWorkOrderService workOrderService;

    @Autowired
    private UserMapper userMapper;


    /**
     * 新增
     * @param dto
     * @return
     */
    @PostMapping("/add")
    public JsonResult add(@RequestBody WorkOrderDto dto){
        return workOrderService.addInfo(dto);
    }

    /**
     * 批量生成工单
     */
    @PostMapping("/generate/{idList}")
    public JsonResult generate(@PathVariable("idList") List<String> idList) {
        return workOrderService.generate(idList);
    }

    /**
     * 代办工单
     * @param query
     * @return
     */
    @GetMapping("/getTodoList")
    public JsonResult getTodoList(WorkOrderQuery query){
        return workOrderService.getTodoList(query);
    }

    /**
     * 处理工单
     * @param query
     * @return
     */
    @GetMapping("/handle")
    public JsonResult handle(HandleQuery query){
        return workOrderService.handle(query);
    }

    /**
     * 分配工单
     */
    @PostMapping("/distribution")
    public JsonResult distribution(@RequestBody DistributionWorkorderRequest request) {
        log.info("进入分配工单接口, request={}", request);
        return workOrderService.distribution(request);
    }

    /**
     * 已完成工单
     * @param query
     * @return
     */
    @GetMapping("/completed")
    public JsonResult completed(WorkOrderQuery query){
        return workOrderService.getCompleted(query);
    }

    /**
     * 工单详情
     * @param query
     * @return
     */
    @GetMapping("/details")
    public JsonResult details(HandleQuery query){
        return workOrderService.details(query);
    }

    /**
     * 统计近七天工单数量
     * @return
     */
    @GetMapping("/weekCount")
    public JsonResult weekCount(){
        return workOrderService.weekCount();
    }

    /**
     * 统计上个月工单数量
     * @return
     */
    @GetMapping("/monthCount")
    public JsonResult monthCount(){
        return workOrderService.mothCount();
    }



}
