ProductController.java 3.19 KB
package com.glsx.admin.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.glsx.admin.exception.BusinessException;
import com.glsx.admin.exception.ResultEnum;
import com.glsx.admin.pojo.request.SmartProductReq;
import com.glsx.admin.remote.ProductFeignClient;
import com.glsx.plat.common.utils.StringUtils;
import com.glsx.plat.core.web.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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 ProductFeignClient productFeignClient;

    /**
     * 获取产品列表。
     *
     * @param req 请求体
     * @return 结果
     */
    @RequestMapping(value = "/getList", method = {RequestMethod.GET, RequestMethod.POST})
    public R getList(SmartProductReq req) {
        log.info("$$$$ /product/getList param: {}", JSON.toJSONString(req));
        PageInfo<SmartProductReq> pageInfo = productFeignClient.getList(req);
        return R.ok().putPageData(pageInfo);
    }

    /**
     * 根据 id 查询产品详情。
     *
     * @param id 产品 id
     * @return 结果
     */
    @RequestMapping(value = "/getById", method = {RequestMethod.GET, RequestMethod.POST})
    public SmartProductReq getById(Long id) {
        return null;
    }

    /**
     * 保存产品。无则插入,有则更新。
     *
     * @param product 产品
     */
    @RequestMapping(value = "/save", method = {RequestMethod.POST})
    public void save(@RequestBody @Validated SmartProductReq product) {
        log.info("$$$$ /product/save param: {}", JSON.toJSONString(product));
    }

    /**
     * 根据产品 id 获取指令集。
     *
     * @param id 产品 id
     */
    @RequestMapping(value = "/getCommandSetById", method = {RequestMethod.GET, RequestMethod.POST})
    public void getCommandSetById(Long id) {
        log.info("$$$$ /product/getCommandSetById param: {}", id);
    }

    /**
     * 校验商城商品 id。
     *
     * @param shopProductId 商品 id
     */
    @RequestMapping(value = "/checkShopProductId", method = {RequestMethod.GET, RequestMethod.POST})
    public Boolean checkShopProductId(String shopProductId) {
        log.info("$$$$ /product/checkShopProductId param: {}", shopProductId);
        if (StringUtils.isBlank(shopProductId)) {
            throw new BusinessException(ResultEnum.PARAM_ERROR);
        }
        return null;
    }

    /**
     * 上下架产品。
     *
     * @param id 产品 id
     */
    @RequestMapping(value = "/putOnOff", method = {RequestMethod.GET, RequestMethod.POST})
    public void putOnOff(Long id) {
        log.info("$$$$ /product/putOnOff param: {}", id);
        if (id == null) {
            throw new BusinessException(ResultEnum.PARAM_ERROR);
        }
    }
}