package com.muyu.breakdown.controller;

import cn.hutool.http.server.HttpServerResponse;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.muyu.breakdown.domain.SysCarFaultLog;
import com.muyu.breakdown.service.SysCarFaultLogService;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @ClassDescription:
 * @JdkVersion: 1.8
 * @Author: YZL
 * @Created: 2024/9/22 21:08
 */
@RestController
@RequestMapping("/log")
public class sysCarFaultLogController extends BaseController {
    @Autowired
    private SysCarFaultLogService service;

    @PostMapping("/list")
    public Result<TableDataInfo<SysCarFaultLog>> list(@RequestBody SysCarFaultLog sysCarFaultLog){
        startPage();
        List<SysCarFaultLog> list = service.selectSysCarFaultLogList(sysCarFaultLog);
        return getDataTable(list);
    }

    @PostMapping("/listStatusIgnore")
    public Result<TableDataInfo<SysCarFaultLog>>listStatusIgnore(@RequestBody  SysCarFaultLog sysCarFaultLog){
        startPage();
        List<SysCarFaultLog> list = service.listStatusIgnore(sysCarFaultLog);
        return getDataTable(list);
    }




    @PostMapping("/listStatusSolve")
    public Result<TableDataInfo<SysCarFaultLog>>listStatusSolve(@RequestBody SysCarFaultLog sysCarFaultLog){
        startPage();
        List<SysCarFaultLog> list = service.listStatusSolve(sysCarFaultLog);
        return getDataTable(list);
    }

    @PostMapping("/listStatusProcess")
    public Result<TableDataInfo<SysCarFaultLog>>listStatusProcess(@RequestBody SysCarFaultLog sysCarFaultLog){
        startPage();
        List<SysCarFaultLog> list = service.listStatusProcess(sysCarFaultLog);
        return getDataTable(list);
    }

    @PostMapping("/add")
    public Result<Integer> add(@RequestBody SysCarFaultLog sysCarFaultLog){

        return toAjax(service.save(sysCarFaultLog));
    }

    @PostMapping("/export")
    public void  export(HttpServletResponse response, SysCarFaultLog sysCarFaultLog){
        List<SysCarFaultLog> list = service.selectSysCarFaultLogList(sysCarFaultLog);
        ExcelUtil<SysCarFaultLog> util = new ExcelUtil<SysCarFaultLog>(SysCarFaultLog.class);
        util.exportExcel(response,list,"车辆故障记录数据");
    }

    /**
     *  修改为忽略
     * @param idsStr
     * @return
     */
    @PutMapping("/updateStatusById/{ids}")
    public Result updateStatusById(@PathVariable("ids")String idsStr){
        Long[] ids = Arrays.stream(idsStr.split(","))
                .map(Long::valueOf)
                .toArray(Long[]::new);
        UpdateWrapper<SysCarFaultLog> wrapper = new UpdateWrapper<>();
        wrapper.in("id",ids).set("status",3);
        boolean update = service.update(null, wrapper);
        return Result.success(update);
    }


}
