package com.ruoyi.web.controller.back;

import com.ruoyi.back.domain.BCustomerQuestionError;
import com.ruoyi.back.service.IBCustomerQuestionErrorService;
import com.ruoyi.common.annotation.Log;
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.core.text.Convert;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 题目纠错Controller
 * 
 * @author mingxue
 * @date 2021-11-29
 */
@RestController
@RequestMapping("/back/bCustomerQuestionError")
public class BCustomerQuestionErrorController extends BaseController
{
    @Autowired
    private IBCustomerQuestionErrorService bCustomerQuestionErrorService;

    /**
     * 查询题目纠错列表
     */
    @PreAuthorize("@ss.hasPermi('back:bCustomerQuestionError:list')")
    @GetMapping("/list")
    public TableDataInfo list(BCustomerQuestionError bCustomerQuestionError)
    {
        startPage();
        List<BCustomerQuestionError> list = bCustomerQuestionErrorService.selectBCustomerQuestionErrorList(bCustomerQuestionError);
        return getDataTable(list);
    }

    /**
     * 导出题目纠错列表
     */
    @PreAuthorize("@ss.hasPermi('back:bCustomerQuestionError:export')")
    @Log(title = "题目纠错", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BCustomerQuestionError bCustomerQuestionError)
    {
        List<BCustomerQuestionError> list = bCustomerQuestionErrorService.selectBCustomerQuestionErrorList(bCustomerQuestionError);
        ExcelUtil<BCustomerQuestionError> util = new ExcelUtil<BCustomerQuestionError>(BCustomerQuestionError.class);
        return util.exportExcel(list, "题目纠错数据");
    }

    /**
     * 获取题目纠错详细信息
     */
    @PreAuthorize("@ss.hasPermi('back:bCustomerQuestionError:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bCustomerQuestionErrorService.selectBCustomerQuestionErrorById(id));
    }

    /**
     * 新增题目纠错
     */
    @PreAuthorize("@ss.hasPermi('back:bCustomerQuestionError:add')")
    @Log(title = "题目纠错", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BCustomerQuestionError bCustomerQuestionError)
    {
        return toAjax(bCustomerQuestionErrorService.insertBCustomerQuestionError(bCustomerQuestionError));
    }

    /**
     * 修改题目纠错
     */
    @PreAuthorize("@ss.hasPermi('back:bCustomerQuestionError:edit')")
    @Log(title = "题目纠错", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BCustomerQuestionError bCustomerQuestionError)
    {
        return toAjax(bCustomerQuestionErrorService.updateBCustomerQuestionError(bCustomerQuestionError));
    }

    @PreAuthorize("@ss.hasPermi('back:bCustomerQuestionError:edit')")
    @Log(title = "题目纠错修改状态", businessType = BusinessType.UPDATE)
    @PutMapping("/updateStatus/{ids}")
    public AjaxResult updateStatus(@PathVariable String ids)
    {
        for(Long id: Convert.toLongArray(ids)){
            BCustomerQuestionError bCustomerQuestionError = new BCustomerQuestionError();
            bCustomerQuestionError.setId(id);
            bCustomerQuestionError.setStatus(1);
            bCustomerQuestionErrorService.updateBCustomerQuestionError(bCustomerQuestionError);
        }
        return AjaxResult.success("修改成功");
    }

    /**
     * 删除题目纠错
     */
    @PreAuthorize("@ss.hasPermi('back:bCustomerQuestionError:remove')")
    @Log(title = "题目纠错", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bCustomerQuestionErrorService.deleteBCustomerQuestionErrorByIds(ids));
    }
}
