package org.jeecg.modules.iot.controller;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
import org.jeecg.common.system.base.controller.JeecgController;
|
import org.jeecg.common.system.query.QueryGenerator;
|
import org.jeecg.modules.iot.entity.EmptyParameter;
|
import org.jeecg.modules.iot.entity.Equipment;
|
import org.jeecg.modules.iot.entity.ServerDeploy;
|
import org.jeecg.modules.iot.service.IEmptyParameterService;
|
import org.jeecg.modules.iot.service.IEquipmentService;
|
import org.jeecg.modules.iot.service.IServerDeployService;
|
import org.jeecg.modules.iot.util.HttpClientUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
|
/**
|
* @Description: 虚设备参数
|
* @Author: cuikaidong
|
* @Date: 2025-1-7
|
* @Version: V1.0
|
*/
|
@Api(tags = "虚设备参数")
|
@RestController
|
@RequestMapping("/empty/parameter")
|
@Slf4j
|
public class EmptyParameterController extends JeecgController<EmptyParameter, IEmptyParameterService> {
|
|
@Autowired
|
private IServerDeployService serverDeployService;
|
@Autowired
|
private IEmptyParameterService emptyParameterService;
|
@Autowired
|
private IEquipmentService equipmentService;
|
|
/**
|
* 分页列表查询
|
*
|
* @param emptyParameter
|
* @param pageNo
|
* @param pageSize
|
* @return
|
*/
|
@ApiOperation(value = "虚设备参数-分页列表查询", notes = "虚设备参数-分页列表查询")
|
@GetMapping(value = "/list")
|
public Result<?> queryPageList(EmptyParameter emptyParameter,
|
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
HttpServletRequest req) {
|
QueryWrapper<EmptyParameter> queryWrapper = QueryGenerator.initQueryWrapper(emptyParameter, req.getParameterMap());
|
Page<EmptyParameter> page = new Page<>(pageNo, pageSize);
|
IPage<EmptyParameter> pageList = emptyParameterService.page(page, queryWrapper);
|
List<EmptyParameter> records = pageList.getRecords();
|
if (records.size() > 0) {
|
// 根据设备id查询设备编号
|
Equipment equipment = equipmentService.getById(records.get(0).getEquipmentId());
|
records.forEach(e -> {
|
e.setEqptCode(equipment.getEqptCode());
|
e.setEqptName(equipment.getEqptName());
|
e.setServeId(equipment.getServerId());
|
});
|
}
|
return Result.ok(pageList);
|
}
|
|
/**
|
* 通过id查询
|
*
|
* @param id
|
* @return
|
*/
|
@GetMapping(value = "/queryById")
|
public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
|
EmptyParameter RealParameter = emptyParameterService.getById(id);
|
return Result.ok(RealParameter);
|
}
|
|
/**
|
* 保存脚本
|
*
|
* @param emptyParameter
|
* @return
|
*/
|
@AutoLog(value = "虚设备参数-保存脚本")
|
@ApiOperation(value = "虚设备参数-保存脚本", notes = "虚设备参数-保存脚本")
|
@PostMapping(value = "/preserveScript")
|
public Result<?> preserveScript(@RequestBody EmptyParameter emptyParameter) {
|
return emptyParameterService.preserveScript(emptyParameter);
|
}
|
|
/**
|
* 编译脚本
|
*
|
* @param emptyParameter
|
* @return
|
*/
|
@AutoLog(value = "虚设备参数-编译脚本")
|
@ApiOperation(value = "虚设备参数-编译脚本", notes = "虚设备参数-编译脚本")
|
@PostMapping(value = "/handleCompile")
|
public Result<?> handleCompile(@RequestBody EmptyParameter emptyParameter) {
|
return emptyParameterService.handleCompile(emptyParameter);
|
}
|
|
/**
|
* 虚设备参数添加
|
*
|
* @param emptyParameter
|
* @return
|
*/
|
@AutoLog(value = "虚设备参数-添加")
|
@ApiOperation(value = "虚设备参数-添加", notes = "虚设备参数-添加")
|
@PostMapping(value = "/add")
|
public Result<?> add(@RequestBody EmptyParameter emptyParameter) {
|
// 验证编码名称是否重复
|
if (emptyParameterService.findEmptyParameterByName(emptyParameter)) {
|
return Result.error("参数名称已存在!");
|
}
|
emptyParameter.setParameterCode(emptyParameterService.findEmptyParameterCode(emptyParameter.getEquipmentId()));
|
emptyParameter.setDataLength("1");
|
emptyParameterService.save(emptyParameter);
|
return Result.ok("添加成功!");
|
}
|
|
/**
|
* 批量新增
|
*
|
* @param emptyParameter
|
* @return
|
*/
|
@AutoLog(value = "虚设备参数-批量新增")
|
@ApiOperation(value = "虚设备参数-批量新增", notes = "虚设备参数-批量新增")
|
@PostMapping(value = "/addBatch")
|
public Result<?> addBatch(@RequestBody List<EmptyParameter> emptyParameter) {
|
Integer parameterCode = emptyParameterService.findEmptyParameterCode(emptyParameter.get(0).getEquipmentId());
|
final int[] code = {parameterCode - 1};
|
for (EmptyParameter e : emptyParameter) {
|
code[0] = code[0] + 1;
|
e.setParameterCode(code[0]);
|
// 验证编码名称是否重复
|
if (emptyParameterService.findEmptyParameterByName(e)) {
|
return Result.error(e.getParameterName() + "参数名称已存在!");
|
}
|
}
|
emptyParameterService.saveBatch(emptyParameter);
|
return Result.ok("批量添加成功!");
|
}
|
|
|
/**
|
* 编辑
|
*
|
* @param realParameter
|
* @return
|
*/
|
@AutoLog(value = "虚设备参数-编辑")
|
@ApiOperation(value = "虚设备参数-编辑", notes = "虚设备参数-编辑")
|
@PutMapping(value = "/edit")
|
public Result<?> edit(@RequestBody EmptyParameter realParameter) {
|
realParameter.setCreateTime(new Date());
|
emptyParameterService.updateById(realParameter);
|
return Result.ok("编辑成功!");
|
}
|
|
/**
|
* 通过id删除
|
*
|
* @param id
|
* @return
|
*/
|
@AutoLog(value = "虚设备参数-通过id删除")
|
@ApiOperation(value = "虚设备参数-通过id删除", notes = "虚设备参数-通过id删除")
|
@DeleteMapping(value = "/delete")
|
public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
|
EmptyParameter emptyParameter = emptyParameterService.getById(id);
|
if (emptyParameter.getType().equals("0")) {
|
//删除虚设备时调用`
|
Map<String, String> param = new HashMap<>();
|
Equipment equipment = equipmentService.getById(emptyParameter.getEquipmentId());
|
ServerDeploy serverDeploy = serverDeployService.getById(equipment.getServerId());
|
param.put("path", "D:/iot/" + serverDeploy.getServerCode() + "/script");
|
HttpClientUtil.doGet("http://localhost:3002/ScriptCompiler/ProjectPath", param);
|
param.clear();
|
param.put("deviceid", emptyParameter.getEquipmentId());
|
|
param.put("id", equipment.getEqptName());
|
HttpClientUtil.doGet("http://localhost:3002/ScriptCompiler/DeleteParameterScript", param);
|
}
|
emptyParameterService.removeById(id);
|
return Result.ok("删除成功!");
|
}
|
|
|
/**
|
* 根据函数类型查询函数信息
|
*
|
* @param functionType 函数类型
|
* @return
|
*/
|
@ApiOperation(value = "根据函数类型查询函数信息", notes = "根据函数类型查询函数信息")
|
@GetMapping(value = "/function")
|
public Result<?> queryFunctionList(@RequestParam(name = "functionType", required = true) String functionType) {
|
return Result.ok(equipmentService.findFunctionInformationList(functionType));
|
}
|
}
|