package com.yiqi.admin.controller.core;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.yiqi.common.constant.UrlConstants;
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.ClothRewashReasonType;
import com.yiqi.core.service.IClothRewashReasonTypeService;
import com.yiqi.common.utils.poi.ExcelUtil;
import com.yiqi.common.core.page.TableDataInfo;

/**
 * 衣服重洗原因类别Controller
 *
 * @author ruoyi
 * @date 2023-09-23
 */
@Api(tags = "管理后台 - 衣服重洗原因类别")
@RestController
@RequestMapping(UrlConstants.managerApi + "/cloth/rewashType")
public class ClothRewashReasonTypeController extends BaseController {
    @Autowired
    private IClothRewashReasonTypeService clothRewashReasonTypeService;

    /**
     * 查询衣服重洗原因类别列表
     */
    @PreAuthorize("@ss.hasPermi('cloth:rewashType:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询衣服重洗原因类别列表")
    public TableDataInfo list(ClothRewashReasonType clothRewashReasonType) {
        startPage();
        List<ClothRewashReasonType> list = clothRewashReasonTypeService.selectClothRewashReasonTypeList(clothRewashReasonType);
        return getDataTable(list);
    }

    /**
     * 导出衣服重洗原因类别列表
     */
    @PreAuthorize("@ss.hasPermi('cloth:rewashType:export')")
    @Log(title = "衣服重洗原因类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出衣服重洗原因类别列表")
    public void export(HttpServletResponse response, ClothRewashReasonType clothRewashReasonType) {
        List<ClothRewashReasonType> list = clothRewashReasonTypeService.selectClothRewashReasonTypeList(clothRewashReasonType);
        ExcelUtil<ClothRewashReasonType> util = new ExcelUtil<ClothRewashReasonType>(ClothRewashReasonType. class);
        util.exportExcel(response, list, "衣服重洗原因类别数据");
    }

    /**
     * 获取衣服重洗原因类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('cloth:rewashType:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取衣服重洗原因类别详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(clothRewashReasonTypeService.selectClothRewashReasonTypeById(id));
    }

    /**
     * 新增衣服重洗原因类别
     */
    @PreAuthorize("@ss.hasPermi('cloth:rewashType:add')")
    @Log(title = "衣服重洗原因类别", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增衣服重洗原因类别")
    public AjaxResult add(@RequestBody ClothRewashReasonType clothRewashReasonType) {
        clothRewashReasonType.setCreateById(getUserId());
        clothRewashReasonType.setCreateBy(getUsername());
        return toAjax(clothRewashReasonTypeService.insertClothRewashReasonType(clothRewashReasonType));
    }

    /**
     * 修改衣服重洗原因类别
     */
    @PreAuthorize("@ss.hasPermi('cloth:rewashType:edit')")
    @Log(title = "衣服重洗原因类别", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改衣服重洗原因类别")
    public AjaxResult edit(@RequestBody ClothRewashReasonType clothRewashReasonType) {
        clothRewashReasonType.setUpdateById(getUserId());
        clothRewashReasonType.setUpdateBy(getUsername());
        return toAjax(clothRewashReasonTypeService.updateClothRewashReasonType(clothRewashReasonType));
    }

    /**
     * 删除衣服重洗原因类别
     */
    @PreAuthorize("@ss.hasPermi('cloth:rewashType:remove')")
    @Log(title = "衣服重洗原因类别", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除衣服重洗原因类别")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(clothRewashReasonTypeService.deleteClothRewashReasonTypeByIds(ids));
    }

}
