123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- package com.huimv.env.admin.controller;
- import cn.hutool.core.util.ObjectUtil;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.huimv.env.admin.common.utils.Result;
- import com.huimv.env.admin.common.utils.ResultCode;
- import com.huimv.env.admin.entity.Terminal;
- import com.huimv.env.admin.entity.vo.*;
- import com.huimv.env.admin.entity.Gateway;
- import com.huimv.env.admin.service.IGatewayService;
- import com.huimv.env.admin.service.ITerminalService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import java.util.List;
- /**
- * <p>
- * 采集网关 前端控制器
- * </p>
- *
- * @author newspaper
- * @since 2024-05-07
- */
- @RestController
- @CrossOrigin
- @RequestMapping("/gateway")
- public class GatewayController {
- @Autowired
- private IGatewayService gatewayService;
- @Autowired
- private ITerminalService terminalService;
- @PostMapping("/add")
- public Result add(@RequestBody GateWayAddParam gateWayAddParam){
- List<Gateway> gatewayList = gatewayService.list(new QueryWrapper<Gateway>().lambda().eq(Gateway::getDeviceCode, gateWayAddParam.getDeviceCode()));
- if (ObjectUtil.isNotEmpty(gatewayList)){
- return new Result(10001,"网关编号已存在",false);
- }
- Gateway gateway = new Gateway();
- gateway.setDeviceCode(gateWayAddParam.getDeviceCode());
- gateway.setDeviceName(gateWayAddParam.getDeviceName());
- gateway.setLocationId(gateWayAddParam.getLocationId());
- gateway.setType(gateWayAddParam.getType());
- gateway.setFarmId(gateWayAddParam.getFarmId());
- gatewayService.save(gateway);
- return Result.SUCCESS();
- }
- @PostMapping("/page")
- public Result page(@RequestBody GateWayPageParam gateWayPageParam){
- Page<Gateway> page = new Page<>(gateWayPageParam.getPageNum(),gateWayPageParam.getPageSize());
- Page<Gateway> gatewayPage = gatewayService.page(page,new QueryWrapper<Gateway>().lambda()
- .eq(Gateway::getFarmId,gateWayPageParam.getFarmId())
- .like(ObjectUtil.isNotEmpty(gateWayPageParam.getDeviceCode()),Gateway::getDeviceCode,gateWayPageParam.getDeviceCode()));
- return new Result(ResultCode.SUCCESS,gatewayPage);
- }
- @PostMapping("/list")
- public Result list(@RequestBody GateWayListParam gateWayListParam){
- List<Gateway> gatewayList = gatewayService.list(new QueryWrapper<Gateway>().lambda().eq(ObjectUtil.isNotEmpty(gateWayListParam.getFarmId()), Gateway::getFarmId, gateWayListParam.getFarmId()));
- return new Result(ResultCode.SUCCESS,gatewayList);
- }
- @PostMapping("/update")
- public Result update(@RequestBody GateWayUpdateParam gateWayUpdateParam){
- Gateway gateway = gatewayService.getById(gateWayUpdateParam.getId());
- List<Gateway> gatewayList = gatewayService.list(new QueryWrapper<Gateway>().lambda().eq(Gateway::getDeviceCode, gateWayUpdateParam.getDeviceCode()).ne(Gateway::getId,gateWayUpdateParam.getId()));
- if (ObjectUtil.isNotEmpty(gatewayList)){
- return new Result(10001,"网关编号已存在",false);
- }
- gateway.setDeviceCode(gateWayUpdateParam.getDeviceCode());
- gateway.setDeviceName(gateWayUpdateParam.getDeviceName());
- gateway.setLocationId(gateWayUpdateParam.getLocationId());
- gateway.setType(gateWayUpdateParam.getType());
- gateway.setFarmId(gateWayUpdateParam.getFarmId());
- gatewayService.updateById(gateway);
- return Result.SUCCESS();
- }
- @PostMapping("/delete")
- public Result delete(@RequestBody GateWayDeleteParam gateWayDeleteParam){
- List<Terminal> terminalList = terminalService.list(new QueryWrapper<Terminal>().lambda().eq(Terminal::getGatewayId, gateWayDeleteParam.getId()));
- if (ObjectUtil.isNotEmpty(terminalList)){
- return new Result(10001,"网关存在下属终端",false);
- }
- gatewayService.removeById(gateWayDeleteParam.getId());
- return Result.SUCCESS();
- }
- }
|