SkuController.java 3.3 KB
package com.infoloop.tianting.controller;

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.infoloop.tianting.model.common.PageResult;
import com.infoloop.tianting.model.dto.SkuDbDTO.SkuDto;
import com.infoloop.tianting.model.dto.SkuDbDTO.SkuIdsDto;
import com.infoloop.tianting.model.dto.SkuSellQuantityDTO;
import com.infoloop.tianting.model.vo.SkuSellQuantityStatisticsVO;
import com.infoloop.tianting.model.vo.SkuSellQuantityVO;
import com.infoloop.tianting.service.SkuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@Api(tags = "sku")
@ApiSupport(order = 2)
@Slf4j
@Validated
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SkuController {

    private final SkuService skuService;

    @ApiOperation(value = "根据sku ids获取")
    @PostMapping("/skus")
    @ResponseStatus(HttpStatus.OK)
    public List<SkuDto> getSkusByIds(@Valid @RequestBody SkuIdsDto skuIdsDto) {
        return skuService.getSkusByIds(skuIdsDto.getIds());
    }

    @ApiOperation(value = "获取菜品售卖量统计")
    @GetMapping("/stall/{stallId}/skusellquantities/statistics")
    @ResponseStatus(HttpStatus.OK)
    public SkuSellQuantityStatisticsVO querySkuSellQuantityStatistics(@PathVariable("stallId") int stallId) {
        return skuService.querySkuSellQuantityStatistics(stallId);
    }

    @ApiOperation(value = "分页查询菜品售卖量")
    @PostMapping("/skusellquantities/query")
    @ResponseStatus(HttpStatus.OK)
    public PageResult<SkuSellQuantityVO> querySkuSellQuantity(@Valid @RequestBody SkuSellQuantityDTO.QuerySkuSellQuantityDTO querySkuSellQuantityDTO) {
        return skuService.querySkuSellQuantity(querySkuSellQuantityDTO);
    }

    @ApiOperation(value = "批量设置菜品售卖量")
    @PutMapping("/stall/{stallId}/skusellquantities/batchset")
    @ResponseStatus(HttpStatus.CREATED)
    public boolean batchSetSkuSellQuantity(@PathVariable("stallId") int stallId,
                                           @Valid @RequestBody SkuSellQuantityDTO.BatchSetSkuSellQuantityDTO batchSetSkuSellQuantityDTO) {
        return skuService.batchSetSkuSellQuantity(stallId, batchSetSkuSellQuantityDTO);
    }

    @ApiOperation(value = "根据菜品ids批量查询菜品售卖量")
    @PostMapping("/skusellquantities/querybyskuids")
    @ResponseStatus(HttpStatus.OK)
    public List<SkuSellQuantityVO> querySkuSellQuantityBySkuIds(@Valid @RequestBody SkuSellQuantityDTO.QuerySkuSellQuantityBySkuIdsDTO querySkuSellQuantityBySkuIdsDTO) {
        return skuService.querySkuSellQuantityBySkuIds(querySkuSellQuantityBySkuIdsDTO);
    }
}