package com.yiqi.admin.controller.core;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yiqi.common.core.domain.R;
import com.yiqi.common.enums.DeleteStatus;
import com.yiqi.common.enums.StatusType;
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.ClothType;
import com.yiqi.core.service.IClothTypeService;
import com.yiqi.common.core.page.TableDataInfo;

/**
 * 衣服种类Controller
 *
 * @author ruoyi
 * @date 2023-08-03
 */
@RestController
@RequestMapping("/mapi/core/clothType")
public class ClothTypeController extends BaseController {
    @Autowired
    private IClothTypeService clothTypeService;

    @ApiOperation("获取所有衣服种类")
    @GetMapping("/all")
    public R all() throws Exception{
        return R.ok(clothTypeService.list(new QueryWrapper<ClothType>().lambda()
                .eq(ClothType::getDelFlag, DeleteStatus.OK.getCode())
                .eq(ClothType::getStatus, StatusType.OK.getCode())
                .orderByAsc(ClothType::getSort)));
    }

    /**
    * 查询衣服种类列表
    */
    @PreAuthorize("@ss.hasPermi('cloth:clothType:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClothType clothType) {
        startPage();
        List<ClothType> list = clothTypeService.selectClothTypeList(clothType);
        return getDataTable(list);
    }

    /**
     * 获取衣服种类详细信息
     */
    @PreAuthorize("@ss.hasPermi('cloth:clothType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(clothTypeService.selectClothTypeById(id));
    }

    /**
     * 新增衣服种类
     */
    @PreAuthorize("@ss.hasPermi('cloth:clothType:add')")
    @Log(title = "衣服种类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClothType clothType) {
        return toAjax(clothTypeService.insertClothType(clothType));
    }

    /**
     * 修改衣服种类
     */
    @PreAuthorize("@ss.hasPermi('cloth:clothType:edit')")
    @Log(title = "衣服种类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClothType clothType) {
        return toAjax(clothTypeService.updateClothType(clothType));
    }

    /**
     * 删除衣服种类
     */
    @PreAuthorize("@ss.hasPermi('cloth:clothType:remove')")
    @Log(title = "衣服种类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(clothTypeService.deleteClothTypeByIds(ids));
    }

    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('cloth:clothType:edit')")
    @Log(title = "衣服种类", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody ClothType clothType) {
        return toAjax(clothTypeService.updateTypeStatus(clothType));
    }
}
