ProductController.java 2.55 KB
package com.glsx.smart.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.glsx.plat.common.utils.StringUtils;
import com.glsx.smart.dao.entity.SmartProduct;
import com.glsx.smart.exception.BusinessException;
import com.glsx.smart.exception.ResultEnum;
import com.glsx.smart.pojo.SmartProductReq;
import com.glsx.smart.service.SmartProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>Description:
 * <p>Project: chejia-smart
 *
 * @author wbh
 * @date 2021-03-15
 */
@Slf4j
@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private SmartProductService productService;

    @RequestMapping(value = "/getList", method = {RequestMethod.GET, RequestMethod.POST})
    public PageInfo<SmartProduct> getList(SmartProductReq req) {
        log.info("/product/getList param: {}", JSON.toJSONString(req));
        return productService.getList(req);
    }

    @RequestMapping(value = "/getById", method = {RequestMethod.GET, RequestMethod.POST})
    public SmartProduct getById(Long id) {
        return productService.getById(id);
    }

    @RequestMapping(value = "/save", method = {RequestMethod.POST})
    public void save(@RequestBody SmartProduct product) {
        log.info("$$$$ /product/save param: {}", JSON.toJSONString(product));
        productService.save(product);
    }

    @RequestMapping(value = "/getCommandSetById", method = {RequestMethod.GET, RequestMethod.POST})
    public void getCommandSetById(Long id) {
        if (id == null) {
            throw new BusinessException(ResultEnum.PARAM_ERROR);
        }
        productService.getCommandSetById(id);
    }

    @RequestMapping(value = "/checkShopProductId", method = {RequestMethod.GET, RequestMethod.POST})
    public void checkShopProductId(String shopProductId) {
        if (StringUtils.isBlank(shopProductId)) {
            throw new BusinessException(ResultEnum.PARAM_ERROR);
        }
        productService.checkShopProductId(shopProductId);
    }

    @RequestMapping(value = "/putOnOff", method = {RequestMethod.GET, RequestMethod.POST})
    public void putOnOff(Long id) {
        if (id == null) {
            throw new BusinessException(ResultEnum.PARAM_ERROR);
        }
        productService.putOnOff(id);
    }
}