SceneController.java 2.88 KB
package com.glsx.smart.controller;

import com.alibaba.fastjson.JSON;
import com.glsx.plat.core.web.R;
import com.glsx.smart.dao.entity.SmartScene;
import com.glsx.smart.pojo.OrderResponse;
import com.glsx.smart.service.SmartSceneDataService;
import com.glsx.smart.service.SmartSceneService;
import io.swagger.annotations.Api;
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;

import java.util.Date;
import java.util.List;

/**
 * <p>Description:
 * <p>Project: chejia-smart
 *
 * @author wbh
 * @date 2021-03-15
 */
@Slf4j
@RestController
@RequestMapping("/scene")
@Api(value = "场景管理", tags = {"场景管理"})
public class SceneController {

    @Autowired
    private SmartSceneService sceneService;

    @Autowired
    private SmartSceneDataService sceneDataService;

    @RequestMapping(value = "/getList", method = {RequestMethod.GET, RequestMethod.POST})
    public List<SmartScene> getList(@RequestBody SmartScene scene) {
        log.info("/scene/getList param: {}", JSON.toJSONString(scene));
        return sceneService.getList(scene);
    }

    @RequestMapping(value = "/getById", method = {RequestMethod.GET, RequestMethod.POST})
    public SmartScene getById(Long id) {
        log.info("/scene/getById param: {}", id);
        SmartScene scene = sceneService.getById(id);
        if(scene != null){
            scene.setDataList(sceneDataService.getBySceneId(id));
        }
        return scene;
    }

    @RequestMapping(value = "/add", method = {RequestMethod.POST})
    public boolean save(@RequestBody SmartScene scene) {
        scene.setCreateTime(new Date());
        log.info("用户新增调用/scene/add param: {}", JSON.toJSONString(scene));
        return sceneService.insert(scene) > 0 ? true : false;
    }

    @RequestMapping(value = "/update", method = {RequestMethod.POST})
    public boolean update(@RequestBody SmartScene scene) {
        scene.setUpdateTime(new Date());
        log.info("用户更新调用/scene/update param: {}", JSON.toJSONString(scene));
        return sceneService.update(scene) > 0 ? true : false;
    }

    @RequestMapping(value = "/updateStatus", method = {RequestMethod.POST})
    public boolean updateStatus(@RequestBody SmartScene scene) {
        scene.setUpdateTime(new Date());
        log.info("用户更新调用/scene/updateStatus param: {}", JSON.toJSONString(scene));
        return sceneService.updateByPrimaryKeySelective(scene) > 0 ? true : false;
    }

    @RequestMapping(value = "/issueOrder", method = {RequestMethod.POST})
    public List<OrderResponse> issueOrder(@RequestBody SmartScene scene) {
        return sceneService.issueOrder(scene);
    }

}