package com.wzj.soopin.goods.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzj.soopin.goods.convert.SkuConvert;
import com.wzj.soopin.goods.domain.bo.SkuBo;
import com.wzj.soopin.goods.domain.entity.Sku;
import com.wzj.soopin.goods.domain.vo.SkuVO;
import com.wzj.soopin.goods.service.impl.SkuServiceImpl;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.common.web.core.BaseController;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * sku信息Controller
 *
 * @author zcc
 * &#064;date  2022-11-28
 */
@Tag(name ="sku信息接口列表")
@RestController
@RequestMapping("/pms/sku")
@RequiredArgsConstructor
public class SkuController extends BaseController {

    private final SkuServiceImpl service;
    private final SkuConvert convert;

    @Tag(name ="查询商品信息列表")
    @PostMapping("list")
    public R<IPage<SkuVO>> list(@RequestBody SkuBo query, Page<Sku> page) {
        return R.ok(service.getList(query,page));
    }

    @Tag(name ="导出sku信息列表")
    @Log(title = "sku信息", businessType = BusinessType.EXPORT)
    @PostMapping("export")
    public R<String> export(SkuBo query) {
        List<Sku> list = service.list(query.toWrapper());
        ExcelUtil<SkuVO> util = new ExcelUtil<>(SkuVO.class);
        return R.ok(util.writeExcel(convert.toVO(list), "sku信息数据"));
    }

    @Tag(name ="获取sku信息详细信息")
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") Long id) {
        return R.ok(service.selectSkuByid(id));
    }

    @Tag(name ="新增sku信息")
    @Log(title = "sku信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R add(@RequestBody Sku sku) {
        service.add(sku);
       return R.ok();
    }

    @Tag(name ="修改sku信息")
    @Log(title = "sku信息", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public R edit(@RequestBody Sku sku) {
        return R.ok(service.updateById(sku));
    }

    @Tag(name ="删除sku信息")
    @Log(title = "sku信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public R remove(@PathVariable Long id) {
      return R.ok(service.removeById(id));
    }
}
