package com.sckw.product.controller.operation;

import com.sckw.core.exception.CustomPromptException;
import com.sckw.core.utils.CollectionUtils;
import com.sckw.core.web.constant.HttpStatus;
import com.sckw.core.web.response.HttpResult;
import com.sckw.excel.utils.ExcelUtil;
import com.sckw.product.model.OperationGoodsListExport;
import com.sckw.product.model.vo.req.OperatorGoodsExportQueryVO;
import com.sckw.product.model.vo.req.OperatorGoodsListQueryVO;
import com.sckw.product.model.vo.req.OperatorGoodsStsQueryVO;
import com.sckw.product.service.operation.GoodsManagerService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @desc: 运营端商品管理
 * @author: yzc
 * @date: 2023-09-14 9:13
 */

@RestController
@RequestMapping(value = "/goodsManager")
@RequiredArgsConstructor
public class GoodsManagerController {

    private final GoodsManagerService goodsManagerService;

    /**
     * @desc: 运营端分页查询商品
     * @author: lt
     * @date: 2023-09-14 09:43
     * @Param param:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @PostMapping(value = "/select", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult select(@RequestBody @Validated OperatorGoodsListQueryVO params) {
        return HttpResult.ok(goodsManagerService.select(params));
    }

    /**
     * @desc: 运营端商品详情
     * @author: lt
     * @date: 2023-09-14 09:43
     * @Param param:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @GetMapping("/detail")
    public HttpResult detail(@RequestParam Long id) {
        return HttpResult.ok(goodsManagerService.getDetail(id));
    }

    /**
     * @desc: 运营端商品数量统计
     * @author: lt
     * @date: 2023-09-14 09:43
     * @Param param:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @PostMapping(value = "/statistic", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult statistic(@RequestBody OperatorGoodsStsQueryVO params) {
        return HttpResult.ok(goodsManagerService.statistic(params));
    }

    /**
     * @desc: 导出
     * @author: lt
     * @date: 2023-09-14 15:00
     * @Param params:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @PostMapping(value = "/export", produces = MediaType.APPLICATION_JSON_VALUE)
    public void export(@RequestBody @Validated OperatorGoodsExportQueryVO params, HttpServletResponse response) {
        List<OperationGoodsListExport> list = goodsManagerService.export(params);
        if (CollectionUtils.isEmpty(list)) {
            throw new CustomPromptException(HttpStatus.SUCCESS_CODE, "暂无数据，请确认");
        }
        ExcelUtil.downData(response, OperationGoodsListExport.class, list);
    }
}
