change - 传感器阈值设置

main
wenjy 3 years ago
parent 7845e926ac
commit b3e202f71c

@ -1,10 +1,16 @@
package com.ruoyi.web.controller.base;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.alibaba.fastjson.JSONArray;
import com.mysql.cj.xdevapi.JsonArray;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.system.domain.BaseAlarmInfo;
import com.ruoyi.system.domain.dto.BaseAlarmInfoDto;
import com.ruoyi.system.domain.dto.BaseSensorInfoDto;
import com.ruoyi.system.service.IBaseAlarmInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@ -26,143 +32,215 @@ import org.springframework.web.multipart.MultipartFile;
/**
* Controller
*
*
* @author wenjy
* @date 2022-02-07
*/
@Controller
@RequestMapping("/base/sensorInfo")
public class BaseSensorInfoController extends BaseController
{
private String prefix = "base/sensorInfo";
@Autowired
private IBaseSensorInfoService baseSensorInfoService;
@RequiresPermissions("base:sensorInfo:view")
@GetMapping()
public String sensorInfo()
{
return prefix + "/sensorInfo";
}
public class BaseSensorInfoController extends BaseController {
private String prefix = "base/sensorInfo";
/**
*
*/
@RequiresPermissions("base:sensorInfo:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(BaseSensorInfo baseSensorInfo)
{
startPage();
List<BaseSensorInfoDto> list = baseSensorInfoService.selectBaseSensorInfoList(baseSensorInfo);
return getDataTable(list);
}
@Autowired private IBaseSensorInfoService baseSensorInfoService;
/**
*
* @author WenJY
* @date 2022/2/11 10:12
* @return com.ruoyi.common.core.domain.AjaxResult
*/
@RequiresPermissions("base:sensorInfo:importTemplate")
@GetMapping("/importTemplate")
@ResponseBody
public AjaxResult importTemplate() {
ExcelUtil<BaseSensorInfo> util = new ExcelUtil<BaseSensorInfo>(BaseSensorInfo.class);
return util.importTemplateExcel("传感器信息");
}
@Autowired
private IBaseAlarmInfoService baseAlarmInfoService;
/**
*
* @author WenJY
* @date 2022/2/11 10:12
* @param file
* @param updateSupport
* @return com.ruoyi.common.core.domain.AjaxResult
*/
@RequiresPermissions("base:sensorInfo:import")
@PostMapping("/importData")
@ResponseBody
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
ExcelUtil<BaseSensorInfo> util = new ExcelUtil<BaseSensorInfo>(BaseSensorInfo.class);
//读取file文件将文件内容转为list集合
List<BaseSensorInfo> baseSensorInfos = util.importExcel(file.getInputStream());
String message = baseSensorInfoService.importMould(baseSensorInfos,updateSupport);
return AjaxResult.success(message);
}
@RequiresPermissions("base:sensorInfo:view")
@GetMapping()
public String sensorInfo() {
return prefix + "/sensorInfo";
}
/**
*
*/
@RequiresPermissions("base:sensorInfo:export")
@Log(title = "传感器信息", businessType = BusinessType.EXPORT)
@PostMapping("/export")
@ResponseBody
public AjaxResult export(BaseSensorInfo baseSensorInfo)
{
List<BaseSensorInfoDto> list = baseSensorInfoService.selectBaseSensorInfoList(baseSensorInfo);
ExcelUtil<BaseSensorInfoDto> util = new ExcelUtil<BaseSensorInfoDto>(BaseSensorInfoDto.class);
return util.exportExcel(list, "传感器信息数据");
}
/** 查询传感器信息列表 */
@RequiresPermissions("base:sensorInfo:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(BaseSensorInfo baseSensorInfo) {
startPage();
List<BaseSensorInfoDto> list = baseSensorInfoService.selectBaseSensorInfoList(baseSensorInfo);
return getDataTable(list);
}
/**
*
*/
@GetMapping("/add")
public String add()
{
return prefix + "/add";
}
/**
*
*
* @author WenJY
* @date 2022/2/11 10:12
* @return com.ruoyi.common.core.domain.AjaxResult
*/
@RequiresPermissions("base:sensorInfo:importTemplate")
@GetMapping("/importTemplate")
@ResponseBody
public AjaxResult importTemplate() {
ExcelUtil<BaseSensorInfo> util = new ExcelUtil<BaseSensorInfo>(BaseSensorInfo.class);
return util.importTemplateExcel("传感器信息");
}
/**
*
*/
@RequiresPermissions("base:sensorInfo:add")
@Log(title = "传感器信息", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(BaseSensorInfo baseSensorInfo)
{
baseSensorInfo.setCreateBy(ShiroUtils.getLoginName());
baseSensorInfo.setCreateTime(new Date());
return toAjax(baseSensorInfoService.insertBaseSensorInfo(baseSensorInfo));
}
/**
*
*
* @author WenJY
* @date 2022/2/11 10:12
* @param file
* @param updateSupport
* @return com.ruoyi.common.core.domain.AjaxResult
*/
@RequiresPermissions("base:sensorInfo:import")
@PostMapping("/importData")
@ResponseBody
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
ExcelUtil<BaseSensorInfo> util = new ExcelUtil<BaseSensorInfo>(BaseSensorInfo.class);
// 读取file文件将文件内容转为list集合
List<BaseSensorInfo> baseSensorInfos = util.importExcel(file.getInputStream());
String message = baseSensorInfoService.importMould(baseSensorInfos, updateSupport);
return AjaxResult.success(message);
}
/**
*
*/
@GetMapping("/edit/{objId}")
public String edit(@PathVariable("objId") Long objId, ModelMap mmap)
{
BaseSensorInfoDto baseSensorInfo = baseSensorInfoService.selectBaseSensorInfoByObjId(objId);
mmap.put("baseSensorInfo", baseSensorInfo);
return prefix + "/edit";
}
/** 导出传感器信息列表 */
@RequiresPermissions("base:sensorInfo:export")
@Log(title = "传感器信息", businessType = BusinessType.EXPORT)
@PostMapping("/export")
@ResponseBody
public AjaxResult export(BaseSensorInfo baseSensorInfo) {
List<BaseSensorInfoDto> list = baseSensorInfoService.selectBaseSensorInfoList(baseSensorInfo);
ExcelUtil<BaseSensorInfoDto> util = new ExcelUtil<BaseSensorInfoDto>(BaseSensorInfoDto.class);
return util.exportExcel(list, "传感器信息数据");
}
/**
*
*/
@RequiresPermissions("base:sensorInfo:edit")
@Log(title = "传感器信息", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(BaseSensorInfo baseSensorInfo)
{
baseSensorInfo.setUpdateBy(ShiroUtils.getLoginName());
baseSensorInfo.setUpdateTime(new Date());
return toAjax(baseSensorInfoService.updateBaseSensorInfo(baseSensorInfo));
}
/** 新增传感器信息 */
@GetMapping("/add")
public String add() {
return prefix + "/add";
}
/** 新增保存传感器信息 */
@RequiresPermissions("base:sensorInfo:add")
@Log(title = "传感器信息", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(BaseSensorInfo baseSensorInfo) {
baseSensorInfo.setCreateBy(ShiroUtils.getLoginName());
baseSensorInfo.setCreateTime(new Date());
return toAjax(baseSensorInfoService.insertBaseSensorInfo(baseSensorInfo));
}
/** 修改传感器信息 */
@GetMapping("/edit/{objId}")
public String edit(@PathVariable("objId") Long objId, ModelMap mmap) {
BaseSensorInfoDto baseSensorInfo = baseSensorInfoService.selectBaseSensorInfoByObjId(objId);
mmap.put("baseSensorInfo", baseSensorInfo);
return prefix + "/edit";
}
/** 修改保存传感器信息 */
@RequiresPermissions("base:sensorInfo:edit")
@Log(title = "传感器信息", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(BaseSensorInfo baseSensorInfo) {
baseSensorInfo.setUpdateBy(ShiroUtils.getLoginName());
baseSensorInfo.setUpdateTime(new Date());
return toAjax(baseSensorInfoService.updateBaseSensorInfo(baseSensorInfo));
}
/**
*
*/
@RequiresPermissions("base:sensorInfo:remove")
@Log(title = "传感器信息", businessType = BusinessType.DELETE)
@PostMapping( "/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
return toAjax(baseSensorInfoService.deleteBaseSensorInfoByObjIds(ids));
/** 设置传感器阈值 */
@GetMapping("/set/{objId}")
public String set(@PathVariable("objId") Long objId, ModelMap mmap) {
BaseSensorInfoDto baseSensorInfo = baseSensorInfoService.selectBaseSensorInfoByObjId(objId);
mmap.put("baseSensorInfo", baseSensorInfo);
return prefix + "/setAlarmParam";
}
/** 保存传感器阈值 */
@RequiresPermissions("base:sensorInfo:set")
@Log(title = "传感器信息", businessType = BusinessType.UPDATE)
@PostMapping("/set")
@ResponseBody
public AjaxResult setSave(BaseSensorInfoDto baseSensorInfo) {
int paramLength = baseSensorInfo.getParamCode().length;
try{
for(int i=0;i<paramLength;i++){
BaseAlarmInfo baseAlarmInfo = new BaseAlarmInfoDto();
baseAlarmInfo.setSensorId(baseSensorInfo.getSensorId());
baseAlarmInfo.setAlarmtypeId(baseSensorInfo.getParamCode()[i]);
baseAlarmInfo.setMaxValue(baseSensorInfo.getMaxValue()[i]);
baseAlarmInfo.setMinValue(baseSensorInfo.getMinValue()[i]);
baseAlarmInfo.setEnableFlag(baseSensorInfo.getEnableFlag());
baseAlarmInfoService.insertBaseAlarmInfo(baseAlarmInfo);
}
return AjaxResult.success();
}catch(Exception ex){
return AjaxResult.error(ex.getMessage());
}
}
/** 删除传感器信息 */
@RequiresPermissions("base:sensorInfo:remove")
@Log(title = "传感器信息", businessType = BusinessType.DELETE)
@PostMapping("/remove")
@ResponseBody
public AjaxResult remove(String ids) {
return toAjax(baseSensorInfoService.deleteBaseSensorInfoByObjIds(ids));
}
@GetMapping("/getParamList")
@ResponseBody
public AjaxResult getParamList(){
List<JsonRootBean> json = new ArrayList<JsonRootBean>();
json.add(new JsonRootBean("p-01","温度","A2001"));
json.add(new JsonRootBean("p-02","湿度","A2002"));
AjaxResult ajax=new AjaxResult();
ajax.put("code", 200);
ajax.put("value",json);
return ajax;
}
}
/**
* Auto-generated: 2022-03-08 16:13:42
*
* @author bejson.com (i@bejson.com)
* @website http://www.bejson.com/java2pojo/
*/
class JsonRootBean {
public JsonRootBean() {
}
public JsonRootBean(String paramId, String paramName, String paramCode) {
this.paramId = paramId;
this.paramName = paramName;
this.paramCode = paramCode;
}
private String paramId;
private String paramName;
private String paramCode;
public String getParamId() {
return paramId;
}
public void setParamId(String paramId) {
this.paramId = paramId;
}
public String getParamName() {
return paramName;
}
public void setParamName(String paramName) {
this.paramName = paramName;
}
public String getParamCode() {
return paramCode;
}
public void setParamCode(String paramCode) {
this.paramCode = paramCode;
}
}

@ -1172,6 +1172,26 @@ var table = {
}
return url;
},
// 设置参数
setParam: function(id) {
table.set();
$.modal.open("设置" + table.options.modalName, $.operate.setParamUrl(id));
},
// 设置参数访问地址
setParamUrl: function(id) {
var url = "/404.html";
if ($.common.isNotEmpty(id)) {
url = table.options.setParamUrl.replace("{id}", id);
} else {
var id = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
if (id.length == 0) {
$.modal.alertWarning("请至少选择一条记录");
return;
}
url = table.options.setParamUrl.replace("{id}", id);
}
return url;
},
// 保存信息 刷新表格
save: function(url, data, callback) {
var config = {

@ -127,6 +127,7 @@
removeUrl: prefix + "/remove",
exportUrl: prefix + "/export",
importUrl: prefix + "/importData",
setParamUrl: prefix + "/set/{id}",
importTemplateUrl: prefix + "/importTemplate",
modalName: "传感器信息",
columns: [{
@ -209,6 +210,7 @@
align: 'center',
formatter: function(value, row, index) {
var actions = [];
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.setParam(\'' + row.objId + '\')"><i class="fa fa-edit"></i>设置阈值</a> ');
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.objId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.objId + '\')"><i class="fa fa-remove"></i>删除</a>');
return actions.join('');

@ -0,0 +1,163 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
<th:block th:include="include :: header('设置传感器报警阈值')"/>
<th:block th:include="include :: select2-css"/>
<th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-sensorInfo-edit" th:object="${baseSensorInfo}">
<input name="objId" th:field="*{objId}" type="hidden">
<input name="monitorunitId" type="hidden" th:field="*{monitorunitId}" id="treeId"/>
<div class="form-group">
<label class="col-sm-3 control-label">传感器编号:</label>
<div class="col-sm-8">
<input name="sensorId" th:field="*{sensorId}" class="form-control" type="text" readonly="true">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">传感器名称:</label>
<div class="col-sm-8">
<input name="sensorName" th:field="*{sensorName}" class="form-control" type="text" readonly="true">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">是否启用:</label>
<div class="col-sm-8">
<select name="enableFlag" id="enableFlag" class="form-control m-b" th:with="type=${@dict.getType('enable_flag')}">
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
</select>
</div>
</div>
<h4 class="form-header h4">设置阈值参数</h4>
<div class="row">
<div class="form-group">
<label class="col-sm-3 control-label">添加参数:</label>
<div class="col-sm-8">
<div class="input-group">
<input type="text" class="form-control" id="suggest-demo-1">
<div class="input-group-btn">
<button type="button" class="btn btn-white dropdown-toggle form-control" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
</ul>
</div>
</div>
</div>
</div>
<div class="form-group" id="product"/>
</div>
</form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-suggest-js"/>
<th:block th:include="include :: bootstrap-typeahead-js"/>
<th:block th:include="include :: select2-js"/>
<script th:inline="javascript">
var prefix = ctx + "base/sensorInfo";
$("#form-sensorInfo-edit").validate({
focusCleanup: true
});
function submitHandler() {
/*if ($.validate.form()) {
$.operate.save(prefix + "/set", $('#form-sensorInfo-edit').serialize());
}*/
if ($.validate.form()) {
if (arrList.length<1){
$.modal.alertError("未添加参数");
return
}
var formData = new FormData();
formData.append('monitorunitId', $("input[name=monitorunitId]").val());
formData.append('sensorId', $("input[name=sensorId]").val());
formData.append('sensorName', $("input[name=sensorName]").val());
formData.append('enableFlag', $("#enableFlag").select2('val'));
$("input[name='paramCode']").each(function(){
formData.append("paramCode",$(this).attr('data-id'));
});
$("input[name='maxValue']").each(function(){
formData.append("maxValue",$(this).val());
});
$("input[name='minValue']").each(function(){
formData.append("minValue",$(this).val());
});
$.ajax({
url: prefix + "/set",
type: 'post',
cache: false,
data: formData,
processData: false,
contentType: false,
dataType: "json",
success: function(result) {
$.operate.successCallback(result);
}
});
}
}
</script>
<script>
var arrList = new Array();
var productid;
//动态添加成品数量
var testBsSuggest = $("#suggest-demo-1").bsSuggest({
url: ctx + "base/sensorInfo/getParamList",
idField: "paramCode",
effectiveFields: ["paramCode", "paramName"],
keyField: "paramName",//xuanz
effectiveFieldsAlias: {paramCode: "参数编码", paramName: "参数名称"},
searchFields: ["paramName"],
}).on('onDataRequestSuccess', function (e, result) {
console.log('onDataRequestSuccess: ', result);
}).on('onSetSelectValue', function (e, keyword) {
productid = keyword.id;
if ($.inArray(productid, arrList) == -1) {
$("#product").append(
"<div><label class=\"col-sm-2 control-label is-required\">参数名称:</label>\n" +
" <div class=\"col-sm-2\">\n" +
" <input name=\"paramCode\" value='" + keyword.key + "' data-id='" + keyword.id + "' class=\"form-control\" type=\"text\" readonly='true' required>\n" +
" </div>\n" +
" <label class=\"col-sm-2 control-label is-required\" style='margin-left: -35px'>最小值:</label>" +
" <div class=\"col-sm-2\">\n" +
" <input name=\"minValue\" class=\"form-control\" type=\"text\" required>\n" +
" </div>\n" +
" <label class=\"col-sm-2 control-label is-required\" style='margin-left: -35px'>最大值:</label>" +
" <div class=\"col-sm-2\">\n" +
" <input name=\"maxValue\" class=\"form-control\" type=\"text\" required>\n" +
" </div>\n" +
" <div class=\"col-sm-1\">\n" +
" <p style=\"margin-top: 10px\" class=\"glyphicon glyphicon-trash\" aria-hidden=\"true\"></p>\n" +
" </div>" +
"</div>"
);
arrList.push(productid);
console.log(arrList)
} else {
$.modal.msgWarning('参数已添加!');
}
}).on('onUnsetSelectValue', function (e) {
});
//删除添加的成品
$(document).ready(function () {
$(document).on("click", ".glyphicon", function () {
$(this).parent().parent().remove();
arrList.splice(arrList.indexOf(productid), 1);
console.log(arrList)
});
})
</script>
</body>
</html>

@ -37,8 +37,8 @@
<div class="loginForm">
<form id="signupForm" autocomplete="off">
<h1 class="no-margins" style="text-align:center;">用户登录</h1>
<input type="text" name="username" class="form-control uname" placeholder="用户名" />
<input type="password" name="password" class="form-control pword" placeholder="密码" />
<input type="text" name="username" class="form-control uname" value="admin" placeholder="用户名" />
<input type="password" name="password" class="form-control pword" value="admin123" placeholder="密码" />
<div class="row m-t" th:if="${captchaEnabled==true}">
<div class="col-xs-6">
<input type="text" name="validateCode" class="form-control code" placeholder="验证码" maxlength="5" />

@ -598,13 +598,13 @@
tags: ['2'],
nodes: [
{
text: 'Child 1',
href: '#child1',
text: '1#变压器',
href: '#1#变压器',
tags: ['0'],
},
{
text: 'Child 2',
href: '#child2',
text: '2#变压器',
href: '#2#变压器',
tags: ['0']
}
]

@ -33,7 +33,7 @@ public class BaseAlarmInfo extends BaseEntity
/** 阈值(最小) */
@Excel(name = "阈值(最小)")
private String minValue;
private BigDecimal minValue;
/** 是否启用 */
@Excel(name = "是否启用")
@ -75,12 +75,12 @@ public class BaseAlarmInfo extends BaseEntity
{
return maxValue;
}
public void setMinValue(String minValue)
public void setMinValue(BigDecimal minValue)
{
this.minValue = minValue;
}
public String getMinValue()
public BigDecimal getMinValue()
{
return minValue;
}

@ -3,6 +3,8 @@ package com.ruoyi.system.domain.dto;
import com.ruoyi.system.domain.BaseSensorInfo;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author WenJY
* @date 20220211 8:54
@ -10,4 +12,10 @@ import lombok.Data;
@Data
public class BaseSensorInfoDto extends BaseSensorInfo {
private String monitorunitName;
private String[] paramCode;
private BigDecimal[] maxValue;
private BigDecimal[] minValue;
}

Loading…
Cancel
Save