燕山石化溯源三维电子沙盘-【后端】-服务
1
13693261870
2024-11-13 2f55cebbad3dea187a5f91d16ec80a9677dab699
src/main/java/com/yssh/controller/LocationController.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,75 @@
package com.yssh.controller;
import com.yssh.utils.CacheUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.web.bind.annotation.DeleteMapping;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.yssh.entity.Location;
import com.yssh.service.LocationService;
import com.yssh.utils.Result;
import javax.annotation.Resource;
@Api(tags="厂区热点点位")
@RestController
@RequestMapping("/location")
@SuppressWarnings("rawtypes")
public class LocationController {
    @Resource
    private LocationService locationService;
    @ApiOperation(value = "条件查询点位数据", notes = "根据名称及其类型查询点位详细信息")
    @GetMapping("/query")
    public Result query(
            @RequestParam(value = "name", required = false) String name,
            @RequestParam(value = "type", required = false) String type) {
        List<Location> data = locationService.query(name, type);
        return Result.OK(data);
    }
    @GetMapping("/list")
    @ApiOperation(value = "查询所有点位数据", notes = "查询所有厂区热点点位数据")
    public Result list() {
        //List<Location> list = locationService.getAll();
        String key = "locationService.getAll";
        List<Location> list = CacheUtils.getListByKey(key);
        if (null == list) {
            list = locationService.getAll();
            CacheUtils.putListByKey(key, list);
        }
        return Result.OK(list);
    }
    @ApiOperation(value = "新增点位数据", notes = "新增点位详情数据")
    @PostMapping
    public Result insertLocation(@RequestBody Location location) {
        int i = locationService.insertLocation(location);
        if (i == 0) {
            return Result.error("插入失败");
        }
        return Result.OK("插入成功");
    }
    @ApiOperation(value = "删除点位数据", notes = "删除点位详情数据")
    @DeleteMapping("/{id}")
    public Result deleteLocation(@PathVariable String id) {
        int i = locationService.deleteLocation(id);
        if (i == 0) {
            return Result.error("删除失败");
        }
        return Result.OK("删除成功");
    }
}