设备列表-设备增删改查
This commit is contained in:
@ -1,17 +1,19 @@
|
||||
package com.xzzn.web.controller.ems;
|
||||
|
||||
import com.xzzn.common.config.RuoYiConfig;
|
||||
import com.xzzn.common.core.controller.BaseController;
|
||||
import com.xzzn.common.core.domain.AjaxResult;
|
||||
import com.xzzn.common.core.page.TableDataInfo;
|
||||
import com.xzzn.common.utils.file.FileUploadUtils;
|
||||
import com.xzzn.common.utils.file.MimeTypeUtils;
|
||||
import com.xzzn.ems.domain.EmsDevicesSetting;
|
||||
import com.xzzn.ems.domain.EmsSiteSetting;
|
||||
import com.xzzn.ems.domain.vo.SiteDeviceListVo;
|
||||
import com.xzzn.ems.service.IEmsDeviceSettingService;
|
||||
import com.xzzn.ems.service.IEmsSiteService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -56,9 +58,9 @@ public class EmsSiteConfigController extends BaseController{
|
||||
* 获取设备详细信息
|
||||
*/
|
||||
@GetMapping("/getDeviceDetailInfo")
|
||||
public AjaxResult getDeviceDetailInfo(@RequestParam String deviceId)
|
||||
public AjaxResult getDeviceDetailInfo(@RequestParam Long id)
|
||||
{
|
||||
return success(iEmsDeviceSettingService.getDeviceDetailInfo(deviceId));
|
||||
return success(iEmsDeviceSettingService.getDeviceDetailInfo(id));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,4 +71,69 @@ public class EmsSiteConfigController extends BaseController{
|
||||
{
|
||||
return success(iEmsSiteService.getAllDeviceList(siteId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有设备类别
|
||||
*/
|
||||
@GetMapping("/getDeviceCategory")
|
||||
public AjaxResult getDeviceCategory()
|
||||
{
|
||||
return success(iEmsDeviceSettingService.getDeviceCategory());
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增设备
|
||||
*/
|
||||
@PostMapping("/addDevice")
|
||||
public AjaxResult addDevice(@RequestBody EmsDevicesSetting devicesSetting)
|
||||
{
|
||||
int result = iEmsDeviceSettingService.addDevice(devicesSetting);
|
||||
if (result > 0) {
|
||||
return AjaxResult.success(result);
|
||||
} else {
|
||||
return AjaxResult.error("该设备已存在");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传设备图片
|
||||
*/
|
||||
@PostMapping("/uploadDeviceImg")
|
||||
public AjaxResult uploadDeviceImg(@RequestParam("avatarfile") MultipartFile file) throws Exception
|
||||
{
|
||||
if (!file.isEmpty()) {
|
||||
String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION);
|
||||
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
ajax.put("imgUrl", avatar);
|
||||
return ajax;
|
||||
}
|
||||
return error("上传图片异常,请联系管理员");
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改Modbus设备配置
|
||||
*/
|
||||
@PostMapping("/updateDevice")
|
||||
public AjaxResult updateDevice(@RequestBody EmsDevicesSetting emsDevicesSetting)
|
||||
{
|
||||
int result = iEmsDeviceSettingService.updateDevice(emsDevicesSetting);
|
||||
if (result > 0) {
|
||||
return AjaxResult.success(result);
|
||||
} else if (result == -1) {
|
||||
return AjaxResult.error("数据不存在");
|
||||
} else if (result == -2) {
|
||||
return AjaxResult.error("该设备已存在");
|
||||
}
|
||||
return AjaxResult.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除Modbus设备配置
|
||||
*/
|
||||
@DeleteMapping("/deleteService/{id}")
|
||||
public AjaxResult deleteService(@PathVariable Long id)
|
||||
{
|
||||
return toAjax(iEmsDeviceSettingService.deleteEmsDevicesSettingById(id));
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,7 +12,8 @@ public enum DeviceCategory
|
||||
STACK("STACK", "电池堆"),
|
||||
CLUSTER("CLUSTER", "电池簇"),
|
||||
BATTERY("BATTERY", "单体电池"),
|
||||
AMMETER("AMMETER", "电表");
|
||||
AMMETER("AMMETER", "电表"),
|
||||
COOLING("COOLING", "冷液体");
|
||||
|
||||
private final String code;
|
||||
private final String info;
|
||||
|
||||
@ -11,7 +11,7 @@ import com.xzzn.common.annotation.Excel;
|
||||
* Modbus设备配置对象 ems_devices_setting
|
||||
*
|
||||
* @author xzzn
|
||||
* @date 2025-07-02
|
||||
* @date 2025-07-12
|
||||
*/
|
||||
public class EmsDevicesSetting extends BaseEntity
|
||||
{
|
||||
@ -102,6 +102,10 @@ public class EmsDevicesSetting extends BaseEntity
|
||||
@Excel(name = "设备类别,例如“STACK/CLUSTER/PCS等”")
|
||||
private String deviceCategory;
|
||||
|
||||
/** 设备图像地址 */
|
||||
@Excel(name = "设备图像地址")
|
||||
private String pictureUrl;
|
||||
|
||||
public void setId(Long id)
|
||||
{
|
||||
this.id = id;
|
||||
@ -312,6 +316,16 @@ public class EmsDevicesSetting extends BaseEntity
|
||||
return deviceCategory;
|
||||
}
|
||||
|
||||
public void setPictureUrl(String pictureUrl)
|
||||
{
|
||||
this.pictureUrl = pictureUrl;
|
||||
}
|
||||
|
||||
public String getPictureUrl()
|
||||
{
|
||||
return pictureUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
@ -336,6 +350,7 @@ public class EmsDevicesSetting extends BaseEntity
|
||||
.append("deviceId", getDeviceId())
|
||||
.append("parentId", getParentId())
|
||||
.append("deviceCategory", getDeviceCategory())
|
||||
.append("pictureUrl", getPictureUrl())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,6 +19,10 @@ public class SiteDeviceListVo {
|
||||
private String communicationStatus;
|
||||
/** 设备类型 */
|
||||
private String deviceCategory;
|
||||
/** 设备类型 */
|
||||
private String pictureUrl;
|
||||
/** 唯一标识 */
|
||||
private String id;
|
||||
|
||||
public String getSiteId() {
|
||||
return siteId;
|
||||
@ -75,4 +79,20 @@ public class SiteDeviceListVo {
|
||||
public void setDeviceCategory(String deviceCategory) {
|
||||
this.deviceCategory = deviceCategory;
|
||||
}
|
||||
|
||||
public String getPictureUrl() {
|
||||
return pictureUrl;
|
||||
}
|
||||
|
||||
public void setPictureUrl(String pictureUrl) {
|
||||
this.pictureUrl = pictureUrl;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,17 +76,12 @@ public interface EmsDevicesSettingMapper
|
||||
*/
|
||||
public List<Map<String, Object>> getDeviceInfosBySiteIdAndCategory(@Param("siteId")String siteId, @Param("deviceCategory")String deviceCategory);
|
||||
|
||||
/**
|
||||
* 获取该设备的详细数据
|
||||
* @param deviceId
|
||||
* @return
|
||||
*/
|
||||
public EmsDevicesSetting getDeviceDetailInfo(String deviceId);
|
||||
|
||||
/**
|
||||
* 获取该设备下的总表
|
||||
* @param siteId
|
||||
* @return
|
||||
*/
|
||||
public List<Map<String, Object>> getLoadNameList(String siteId);
|
||||
|
||||
public EmsDevicesSetting getDeviceBySiteAndDeviceId(@Param("deviceId")String deviceId, @Param("siteId")String siteId);
|
||||
}
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
package com.xzzn.ems.service;
|
||||
|
||||
import com.xzzn.common.enums.DeviceCategory;
|
||||
import com.xzzn.ems.domain.EmsDevicesSetting;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备信息 服务层
|
||||
*
|
||||
@ -9,5 +12,13 @@ import com.xzzn.ems.domain.EmsDevicesSetting;
|
||||
public interface IEmsDeviceSettingService
|
||||
{
|
||||
|
||||
public EmsDevicesSetting getDeviceDetailInfo(String deviceId);
|
||||
public EmsDevicesSetting getDeviceDetailInfo(Long deviceId);
|
||||
|
||||
public int addDevice(EmsDevicesSetting devicesSetting);
|
||||
|
||||
public int updateDevice(EmsDevicesSetting emsDevicesSetting);
|
||||
|
||||
public int deleteEmsDevicesSettingById(Long id);
|
||||
|
||||
public List<DeviceCategory> getDeviceCategory();
|
||||
}
|
||||
|
||||
@ -1,11 +1,17 @@
|
||||
package com.xzzn.ems.service.impl;
|
||||
|
||||
import com.xzzn.common.enums.DeviceCategory;
|
||||
import com.xzzn.common.utils.DateUtils;
|
||||
import com.xzzn.common.utils.StringUtils;
|
||||
import com.xzzn.ems.domain.EmsDevicesSetting;
|
||||
import com.xzzn.ems.mapper.EmsDevicesSettingMapper;
|
||||
import com.xzzn.ems.service.IEmsDeviceSettingService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 站点信息 服务层实现
|
||||
*
|
||||
@ -18,11 +24,86 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
|
||||
|
||||
/**
|
||||
* 获取设备详细信息
|
||||
* @param deviceId
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public EmsDevicesSetting getDeviceDetailInfo(String deviceId) {
|
||||
return emsDevicesMapper.getDeviceDetailInfo(deviceId);
|
||||
public EmsDevicesSetting getDeviceDetailInfo(Long id) {
|
||||
return emsDevicesMapper.selectEmsDevicesSettingById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增设备
|
||||
* @param devicesSetting
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int addDevice(EmsDevicesSetting devicesSetting) {
|
||||
boolean flag = checkDeviceExist(devicesSetting);
|
||||
if (flag) {
|
||||
return -1;
|
||||
}
|
||||
devicesSetting.setCreateTime(DateUtils.getNowDate());
|
||||
return emsDevicesMapper.insertEmsDevicesSetting(devicesSetting);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新设备
|
||||
* @param devicesSetting
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int updateDevice(EmsDevicesSetting devicesSetting) {
|
||||
boolean checkExist = false;
|
||||
if (devicesSetting.getId() != null) {
|
||||
// 根据id判断该数据是否存在
|
||||
EmsDevicesSetting existDevice = emsDevicesMapper.selectEmsDevicesSettingById(devicesSetting.getId());
|
||||
if (existDevice == null) {
|
||||
return -1;
|
||||
}
|
||||
// 存在判断是否修改deviceId和siteId
|
||||
String deviceId = existDevice.getDeviceId();
|
||||
String siteId = existDevice.getSiteId();
|
||||
if (!deviceId.equals(devicesSetting.getDeviceId())
|
||||
|| !siteId.equals(devicesSetting.getSiteId())) {
|
||||
checkExist = checkDeviceExist(devicesSetting);
|
||||
}
|
||||
}
|
||||
// 已修改校验修改后数据是否存在
|
||||
if (checkExist) {
|
||||
return -2;
|
||||
}
|
||||
devicesSetting.setUpdateTime(DateUtils.getNowDate());
|
||||
return emsDevicesMapper.updateEmsDevicesSetting(devicesSetting);
|
||||
}
|
||||
|
||||
private boolean checkDeviceExist(EmsDevicesSetting devicesSetting) {
|
||||
String deviceId = devicesSetting.getDeviceId();
|
||||
String siteId = devicesSetting.getSiteId();
|
||||
if (!StringUtils.isEmpty(deviceId) && !StringUtils.isEmpty(siteId)) {
|
||||
EmsDevicesSetting emsDevicesSetting = emsDevicesMapper.getDeviceBySiteAndDeviceId(deviceId, siteId);
|
||||
if (emsDevicesSetting != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备配置信息
|
||||
*
|
||||
* @param id Modbus设备配置主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteEmsDevicesSettingById(Long id){
|
||||
|
||||
return emsDevicesMapper.deleteEmsDevicesSettingById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceCategory> getDeviceCategory() {
|
||||
List<DeviceCategory> deviceList = Arrays.asList(DeviceCategory.values());
|
||||
return deviceList;
|
||||
}
|
||||
}
|
||||
|
||||
@ -402,7 +402,8 @@ public class SingleSiteServiceImpl implements ISingleSiteService {
|
||||
} else if (AMMETER_DEVICE_METE.equals(ammeterId)) {
|
||||
AmmeterMeteDataVo ammeterMeteDataVo = new AmmeterMeteDataVo();
|
||||
ammeterMeteDataVo.setDeviceName(ammeterDevice.get("deviceName").toString());
|
||||
ammeterMeteDataVo.setEmsCommunicationStatus(ammeterDevice.get("communicationStatus").toString());
|
||||
ammeterMeteDataVo.setEmsCommunicationStatus(ammeterDevice.get("communicationStatus") == null? "" :
|
||||
ammeterDevice.get("communicationStatus").toString());
|
||||
// 处理储能表数据
|
||||
dealAmmeterMeteData(ammeterData,ammeterMeteDataVo);
|
||||
ammeterResponse.setAmmeterMeteDataVoList(ammeterMeteDataVo);
|
||||
|
||||
@ -26,10 +26,11 @@
|
||||
<result property="deviceId" column="device_id" />
|
||||
<result property="parentId" column="parent_id" />
|
||||
<result property="deviceCategory" column="device_category" />
|
||||
<result property="pictureUrl" column="picture_url" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectEmsDevicesSettingVo">
|
||||
select id, device_name, device_type, slave_id, timeout_ms, retries, ip_address, ip_port, serial_port, baud_rate, data_bits, stop_bits, parity, description, created_at, updated_at, site_id, communication_status, device_id, parent_id, device_category from ems_devices_setting
|
||||
select id, device_name, device_type, slave_id, timeout_ms, retries, ip_address, ip_port, serial_port, baud_rate, data_bits, stop_bits, parity, description, created_at, updated_at, site_id, communication_status, device_id, parent_id, device_category, picture_url from ems_devices_setting
|
||||
</sql>
|
||||
|
||||
<select id="selectEmsDevicesSettingList" parameterType="EmsDevicesSetting" resultMap="EmsDevicesSettingResult">
|
||||
@ -55,6 +56,7 @@
|
||||
<if test="deviceId != null and deviceId != ''"> and device_id = #{deviceId}</if>
|
||||
<if test="parentId != null and parentId != ''"> and parent_id = #{parentId}</if>
|
||||
<if test="deviceCategory != null and deviceCategory != ''"> and device_category = #{deviceCategory}</if>
|
||||
<if test="pictureUrl != null and pictureUrl != ''"> and picture_url = #{pictureUrl}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
@ -86,6 +88,7 @@
|
||||
<if test="deviceId != null and deviceId != ''">device_id,</if>
|
||||
<if test="parentId != null">parent_id,</if>
|
||||
<if test="deviceCategory != null">device_category,</if>
|
||||
<if test="pictureUrl != null">picture_url,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="deviceName != null and deviceName != ''">#{deviceName},</if>
|
||||
@ -108,6 +111,7 @@
|
||||
<if test="deviceId != null and deviceId != ''">#{deviceId},</if>
|
||||
<if test="parentId != null">#{parentId},</if>
|
||||
<if test="deviceCategory != null">#{deviceCategory},</if>
|
||||
<if test="pictureUrl != null">#{pictureUrl},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
@ -134,6 +138,7 @@
|
||||
<if test="deviceId != null and deviceId != ''">device_id = #{deviceId},</if>
|
||||
<if test="parentId != null">parent_id = #{parentId},</if>
|
||||
<if test="deviceCategory != null">device_category = #{deviceCategory},</if>
|
||||
<if test="pictureUrl != null">picture_url = #{pictureUrl},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
@ -180,9 +185,10 @@
|
||||
from ems_devices_setting where site_id = #{siteId} and device_category = #{deviceCategory}
|
||||
</select>
|
||||
|
||||
<select id="getDeviceDetailInfo" parameterType="String" resultMap="EmsDevicesSettingResult">
|
||||
<select id="getDeviceBySiteAndDeviceId" parameterType="String" resultMap="EmsDevicesSettingResult">
|
||||
<include refid="selectEmsDevicesSettingVo"/>
|
||||
where device_id = #{deviceId}
|
||||
AND site_id = #{siteId}
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
|
||||
@ -137,7 +137,9 @@
|
||||
select es.site_id as siteId,es.site_name as siteName,
|
||||
ed.device_id as deviceId,ed.device_name as deviceName,
|
||||
ed.device_type as deviceType,ed.communication_status as communicationStatus,
|
||||
ed.device_category as deviceCategory
|
||||
ed.device_category as deviceCategory,
|
||||
ed.picture_url as pictureUrl,
|
||||
ed.id
|
||||
from ems_site_setting es INNER JOIN ems_devices_setting ed on es.site_id = ed.site_id
|
||||
where 1=1
|
||||
<if test="siteId != null and siteId != ''">
|
||||
|
||||
Reference in New Issue
Block a user