package com.ruoyi.web.controller.app;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.ValidGroup;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.ss.abnormal.domain.dto.AbnormalSubmitDTO;
import com.ruoyi.ss.abnormal.domain.AbnormalQuery;
import com.ruoyi.ss.abnormal.service.AbnormalConverter;
import com.ruoyi.ss.abnormal.service.AbnormalValidator;
import com.ruoyi.ss.abnormal.service.AbnormalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author wjh
 * 2024/4/30
 */
@Api(tags = "设备故障")
@RestController
@RequestMapping("/app/abnormal")
public class AppAbnormalController extends BaseController {

    @Autowired
    private AbnormalService abnormalService;

    @Autowired
    private AbnormalValidator abnormalValidator;

    @Autowired
    private AbnormalConverter abnormalConverter;

    @ApiOperation("提交设备故障反馈")
    @PostMapping("/submit")
    public AjaxResult submit(@RequestBody @Validated(ValidGroup.FrontCreate.class) AbnormalSubmitDTO data) {
        data.setUserId(getUserId());
        data.setCreateBy(getUsername());
        return success(abnormalService.insertAbnormal(abnormalConverter.toPo(data)));
    }

    @ApiOperation("获取本人提交的故障反馈列表")
    @GetMapping("/list")
    public TableDataInfo list(@Validated(ValidGroup.Query.class) AbnormalQuery query) {
        startPage();
        query.setUserId(getUserId());
        return getDataTable(abnormalService.selectAbnormalList(query));
    }

}
