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

import java.util.List;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.PageInfo;
import com.glsx.smart.dao.entity.SmartDeviceOrder;
import com.glsx.smart.dao.entity.SmartProduct;
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;

    /**
     * 分页获取产品列表。
     *
     * @param req 请求体
     * @return 结果
     */
    @RequestMapping(value = "/getPageList", method = {RequestMethod.GET, RequestMethod.POST})
    public PageInfo<SmartProduct> getPageList(SmartProduct req) {
        log.info("$$$$ /product/getPageList param: {}", JSON.toJSONString(req));
        return productService.getPageList(req);
    }

    /**
     * 获取产品列表,不分页。
     *
     * @param req 请求体
     * @return 结果
     */
    @RequestMapping(value = "/getList", method = {RequestMethod.GET, RequestMethod.POST})
    public List<SmartProduct> getList(SmartProduct req) {
        log.info("$$$$ /product/getList param: {}", JSON.toJSONString(req));
        return productService.getList(req);
    }

    /**
     * 获取产品列表。
     *
     * @param req 请求体
     * @return 结果
     */
    @RequestMapping(value = "/getListByCondition", method = {RequestMethod.GET, RequestMethod.POST})
    public List<SmartProduct> getListByCondition(@RequestBody SmartProduct req) {
        log.info("/product/getListByCondition param: {}", JSON.toJSONString(req));
        return productService.getListByCondition(req);
    }

    /**
     * 根据 id 查询产品详情。
     *
     * @param id 产品 id
     * @return 结果
     */
    @RequestMapping(value = "/getById", method = {RequestMethod.GET, RequestMethod.POST})
    public SmartProduct getById(Long id) {
        log.info("$$$$ /product/getById param: {}", id);
        return productService.getById(id);
    }

    /**
     * 获取结构化的产品数据。
     *
     * @return 结果
     */
    @RequestMapping(value = "/getProductAndCategory",
            method = {RequestMethod.GET, RequestMethod.POST})
    public JSONArray getProductAndCategory() {
        log.info("$$$$ /product/getProductAndCategory...");
        return productService.getProductTree();
    }

    /**
     * 保存产品。无则插入,有则更新。
     *
     * @param product 产品
     * @return 是否成功
     */
    @RequestMapping(value = "/save", method = {RequestMethod.POST})
    public Boolean save(@RequestBody SmartProduct product) {
        log.info("$$$$ /product/save param: {}", JSON.toJSONString(product));
        return productService.save(product);
    }

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

    /**
     * 上下架产品。
     *
     * @param id 产品 id
     * @return 是否成功
     */
    @RequestMapping(value = "/putOnOff", method = {RequestMethod.GET, RequestMethod.POST})
    public Boolean putOnOff(Long id) {
        log.info("$$$$ /product/putOnOff param: {}", id);
        return productService.putOnOff(id);
    }
}