package com.yiqi.admin.controller.core;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yiqi.common.constant.UrlConstants;
import com.yiqi.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yiqi.common.annotation.Log;
import com.yiqi.common.core.controller.BaseController;
import com.yiqi.common.core.domain.AjaxResult;
import com.yiqi.common.enums.BusinessType;
import com.yiqi.core.domain.ClothWashProblem;
import com.yiqi.core.service.IClothWashProblemService;
import com.yiqi.common.utils.poi.ExcelUtil;
import com.yiqi.common.core.page.TableDataInfo;

/**
 * 洗衣问题Controller
 *
 * @author xiaohei
 * @date 2023-11-16
 */
@Api(tags = "管理后台 - 洗衣问题")
@RestController
@RequestMapping(UrlConstants.managerApi + "/cloth/washProblem")
public class ClothWashProblemController extends BaseController {
    @Autowired
    private IClothWashProblemService clothWashProblemService;

    @ApiOperation("查询所有的洗衣问题")
    @GetMapping(value = "all")
    public R<List<ClothWashProblem>> all() throws Exception{
        return R.ok(clothWashProblemService.list());
    }

    //<editor-folder desc="基础函数">
    /**
     * 查询洗衣问题列表
     */
    @PreAuthorize("@ss.hasPermi('cloth:washProblem:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询洗衣问题列表")
    public TableDataInfo list(ClothWashProblem clothWashProblem) {
        startPage();
        List<ClothWashProblem> list = clothWashProblemService.selectClothWashProblemList(clothWashProblem);
        return getDataTable(list);
    }

    /**
     * 导出洗衣问题列表
     */
    @PreAuthorize("@ss.hasPermi('cloth:washProblem:export')")
    @Log(title = "洗衣问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出洗衣问题列表")
    public void export(HttpServletResponse response, ClothWashProblem clothWashProblem) {
        List<ClothWashProblem> list = clothWashProblemService.selectClothWashProblemList(clothWashProblem);
        ExcelUtil<ClothWashProblem> util = new ExcelUtil<ClothWashProblem>(ClothWashProblem. class);
        util.exportExcel(response, list, "洗衣问题数据");
    }

    /**
     * 获取洗衣问题详细信息
     */
    @PreAuthorize("@ss.hasPermi('cloth:washProblem:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取洗衣问题详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(clothWashProblemService.selectClothWashProblemById(id));
    }

    /**
     * 新增洗衣问题
     */
    @PreAuthorize("@ss.hasPermi('cloth:washProblem:add')")
    @Log(title = "洗衣问题", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增洗衣问题")
    public AjaxResult add(@RequestBody ClothWashProblem clothWashProblem) {
        clothWashProblem.setCreateById(getUserId());
        clothWashProblem.setCreateBy(getUsername());
        return toAjax(clothWashProblemService.insertClothWashProblem(clothWashProblem));
    }

    /**
     * 修改洗衣问题
     */
    @PreAuthorize("@ss.hasPermi('cloth:washProblem:edit')")
    @Log(title = "洗衣问题", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改洗衣问题")
    public AjaxResult edit(@RequestBody ClothWashProblem clothWashProblem) {
        clothWashProblem.setUpdateById(getUserId());
        clothWashProblem.setUpdateBy(getUsername());
        return toAjax(clothWashProblemService.updateClothWashProblem(clothWashProblem));
    }

    /**
     * 删除洗衣问题
     */
    @PreAuthorize("@ss.hasPermi('cloth:washProblem:remove')")
    @Log(title = "洗衣问题", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除洗衣问题")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(clothWashProblemService.deleteClothWashProblemByIds(ids));
    }


    //</editor-folder>
}
