package com.younike.store.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import com.younike.common.bean.APIResult;
import com.younike.common.bean.ResultGenerator;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import com.younike.common.core.page.PageParam;
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.younike.common.annotation.OpLog;
import com.younike.common.core.controller.BaseController;
import com.younike.common.constant.BusinessType;
import com.younike.service.pojo.StoreCategory;
import com.younike.service.service.IStoreCategoryService;

/**
 * 门店分类Controller
 *
 * @author dail
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/storeCategory")
public class StoreCategoryController extends BaseController {
    @Autowired
    private IStoreCategoryService storeCategoryService;

//    /**
//     * 查询门店分类列表
//     */
    @RequiresPermissions("category:list")
    @PostMapping("/list")
    public Page list(@RequestBody PageParam<StoreCategory> page) {

        return storeCategoryService.page(page);
    }


    /**
     * 获取门店分类详细信息
     */
    @RequiresPermissions("category:query")
    @GetMapping(value = "/{storeCategoryId}")
    public APIResult getInfo(@PathVariable("storeCategoryId") String storeCategoryId) {
        return ResultGenerator.getSuccessResult(storeCategoryService.getById(storeCategoryId));
    }

    /**
     * 新增门店分类
     */
    @RequiresPermissions("category:add")
    @OpLog(title = "门店分类", type = BusinessType.INSERT)
    @PostMapping
    public APIResult add(@RequestBody StoreCategory storeCategory) {
        return ResultGenerator.getSuccessResult(storeCategoryService.save(storeCategory));
    }

    /**
     * 修改门店分类
     */
    @RequiresPermissions("category:edit")
    @OpLog(title = "门店分类", type = BusinessType.UPDATE)
    @PutMapping
    public APIResult edit(@RequestBody StoreCategory storeCategory) {
        return ResultGenerator.getSuccessResult(storeCategoryService.updateById(storeCategory));
    }

    /**
     * 删除门店分类
     */
    @RequiresPermissions("category:remove")
    @OpLog(title = "门店分类", type = BusinessType.DELETE)
    @DeleteMapping("/{storeCategoryIds}")
    public APIResult remove(@PathVariable List<String> storeCategoryIds) {
        return ResultGenerator.getSuccessResult(storeCategoryService.removeByIds(storeCategoryIds));
    }


    /**
     * 获取门店分类树状图
     */
    @GetMapping("/storeCategoryTree")
    public APIResult getStoreCategoryTree(@RequestBody StoreCategory storeCategory) {
        return ResultGenerator.getSuccessResult(storeCategoryService.getStoreCategoryTree(storeCategory));
    }
}
