package com.ruoyi.web.app;

import com.ruoyi.bst.device.domain.DeviceVO;
import com.ruoyi.bst.device.service.DeviceService;
import com.ruoyi.bst.fault.domain.Fault;
import com.ruoyi.bst.fault.domain.FaultQuery;
import com.ruoyi.bst.fault.domain.FaultVO;
import com.ruoyi.bst.fault.domain.enums.FaultHandleStatus;
import com.ruoyi.bst.fault.domain.enums.FaultStatus;
import com.ruoyi.bst.fault.service.FaultConverter;
import com.ruoyi.bst.fault.service.FaultService;
import com.ruoyi.bst.order.domain.OrderVO;
import com.ruoyi.bst.order.service.OrderService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.collection.CollectionUtils;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 故障申报前台
 */
@RestController
@RequestMapping("/app/fault")
public class AppFaultController extends BaseController {

    @Autowired
    private FaultService  faultService;

    @Autowired
    private FaultConverter faultConverter;

    /**
     * 新增故障申报
     * @param fault
     * @return
     */
    @ApiOperation("故障申报")
    @PostMapping
    public AjaxResult add(@RequestBody FaultVO fault) {
        fault.setUserId(getUserId());
        fault.setCreateBy(getUsername());
        return success(faultService.insertFault(faultConverter.toPo(fault)));
    }

    /**
     * 历史申报查询
     * @param query
     * @return
     */
    @ApiOperation("查询历史申报")
    @GetMapping
    public TableDataInfo get(FaultQuery query) {
        startPage();
        query.setUserId(getUserId());
        List<FaultVO> list = faultService.selectFaultList(query);
        return getDataTable(list);
    }

}
