package com.ym.mec.web.controller;

import com.ym.mec.biz.dal.entity.GoodsCategory;
import com.ym.mec.biz.dal.page.GoodsCategoryQueryInfo;
import com.ym.mec.biz.service.GoodsCategoryService;
import com.ym.mec.common.controller.BaseController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RequestMapping("category")
@Api(tags = "商品分类服务")
@RestController
public class GoodsCategoryController extends BaseController {

    @Autowired
    private GoodsCategoryService goodsCategoryService;

    @ApiOperation(value = "删除商品分类")
    @PostMapping("/del")
    @PreAuthorize("@pcs.hasPermissions('category/del')")
    public Object del(Integer id) {
        return succeed(goodsCategoryService.delete(id));
    }

    @ApiOperation(value = "新增、修改商品类型")
    @PostMapping("/upset")
    @PreAuthorize("@pcs.hasPermissions('category/upset')")
    public Object upset(@RequestBody GoodsCategory goodsCategory){
        goodsCategoryService.upsetGoodsCategory(goodsCategory);
        return succeed();
    }

    @ApiOperation(value = "分页查询商品分类列表")
    @GetMapping("/queryPage")
    @PreAuthorize("@pcs.hasPermissions('category/queryPage')")
    public Object queryPage(GoodsCategoryQueryInfo queryInfo) {
        return succeed(goodsCategoryService.queryPage(queryInfo));
    }

    @ApiOperation(value = "分页查询科目默认商品")
    @GetMapping("/querySubjectGoods")
    @PreAuthorize("@pcs.hasPermissions('category/querySubjectGoods')")
    public Object querySubjectGoods(GoodsCategoryQueryInfo queryInfo) {
        return succeed(goodsCategoryService.querySubjectGoods(queryInfo));
    }

    @ApiOperation(value = "修改科目默认商品")
    @PostMapping("/updateSubjectGoods")
    @PreAuthorize("@pcs.hasPermissions('category/updateSubjectGoods')")
    public Object updateSubjectGoods(Long subjectGoodsMapperId,String goodsIds) {
        goodsCategoryService.updateSubjectGoods(subjectGoodsMapperId,goodsIds);
        return succeed();
    }
}
