package com.yiqi.admin.controller.core;

import java.util.List;

import com.yiqi.common.core.domain.R;
import com.yiqi.core.domain.vo.ClothFlawVo;
import com.yiqi.core.service.IClothFlawTypeService;
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.ClothFlaw;
import com.yiqi.core.service.IClothFlawService;
import com.yiqi.common.core.page.TableDataInfo;

/**
 * 衣服瑕疵Controller
 *
 * @author ruoyi
 * @date 2023-08-03
 */
@Api(tags = "衣服瑕疵管理")
@RestController
@RequestMapping("/mapi/core/flaw")
public class ClothFlawController extends BaseController {
    @Autowired
    private IClothFlawService clothFlawService;
    @Autowired
    private IClothFlawTypeService clothFlawTypeService;

    @ApiOperation("获取所有衣服瑕疵")
    @GetMapping("all")
    public R allGroupByType() throws Exception{
        return R.ok(clothFlawService.allClothFlaw());
    }

    /**
    * 查询衣服瑕疵列表
    */
    @PreAuthorize("@ss.hasPermi('cloth:flaw:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClothFlaw clothFlaw) {
        startPage();
        List<ClothFlawVo> list = clothFlawService.selectClothFlawList(clothFlaw);
        return getDataTable(list);
    }

    /**
     * 获取衣服瑕疵详细信息
     */
    @PreAuthorize("@ss.hasPermi('cloth:flaw:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(clothFlawService.selectClothFlawById(id));
    }

    /**
     * 新增衣服瑕疵
     */
    @PreAuthorize("@ss.hasPermi('cloth:flaw:add')")
    @Log(title = "衣服瑕疵", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClothFlaw clothFlaw) {
        return toAjax(clothFlawService.insertClothFlaw(clothFlaw));
    }

    /**
     * 修改衣服瑕疵
     */
    @PreAuthorize("@ss.hasPermi('cloth:flaw:edit')")
    @Log(title = "衣服瑕疵", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClothFlaw clothFlaw) {
        return toAjax(clothFlawService.updateClothFlaw(clothFlaw));
    }

    /**
     * 删除衣服瑕疵
     */
    @PreAuthorize("@ss.hasPermi('cloth:flaw:remove')")
    @Log(title = "衣服瑕疵", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(clothFlawService.deleteClothFlawByIds(ids));
    }

    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('cloth:flaw:edit')")
    @Log(title = "衣服瑕疵", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody ClothFlaw clothFlaw) {
        clothFlaw.setUpdateBy(getUsername());
        return toAjax(clothFlawService.updateFlawStatus(clothFlaw));
    }
}
