Commit 68a30bbe authored by 赵啸非's avatar 赵啸非

添加设备相关信息

parent 32d63558
Pipeline #2629 canceled with stages
package com.mortals.xhx.common.pdu;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.web.BaseForm;
public class LoginForm extends BaseForm {
private String loginName;
private String password;
private String securityCode;
public String getLoginName() {
return loginName;
}
public void setLoginName(String loginName) {
this.loginName = loginName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getSecurityCode() {
return securityCode;
}
public void setSecurityCode(String securityCode) {
this.securityCode = securityCode;
}
@Override
public String toString() {
return "loginName:" + this.loginName + " password:" + this.password;
}
@Override
public boolean validate() throws AppException {
if (loginName == null || loginName.trim().length() == 0) {
throw new AppException("帐号不能为空!");
}
if (password == null || password.trim().length() == 0) {
throw new AppException("密码不能为空!");
}
// if (securityCode == null || securityCode.trim().length() == 0) {
// throw new AppException("验证码不能为空!");
// }
return super.validate();
}
}
package com.mortals.xhx.common.pdu.device;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
public class DeviceReq implements Serializable {
/**
* 1:新增,2:修改,3:删除,4:激活,5:启用,6:停用
*/
private Integer receiveMethod;
/**
* 产品id
*/
private Long productId;
/**
* 产品编码
*/
private String productCode;
/**
* 设备生产厂商ID
*/
private Long deviceFirmId;
/**
* 设备生产厂商名称
*/
private String deviceFirmname;
/**
* 设备名称
*/
private String deviceName;
/**
* 设备编码(暂定mac地址)
*/
private String deviceCode;
/**
* 设备Mac
*/
private String deviceMac;
/**
* 所属站点Id
*/
private Long siteId;
/**
* 所属站点编码
*/
private String siteCode;
/**
* 所属站点名称
*/
private String siteName;
/**
* 设备备注信息
*/
private String deviceRemark;
/**
* 设备
*/
private String homeUrl;
/**
* 设备访问ip
*/
private String ip;
/**
* 中心设备编码
*/
private String centernum;
/**
* 端口
*/
private String port;
/**
* 经度
*/
private String lon;
/**
* 纬度
*/
private String lati;
/**
* 楼层
*/
private Integer deviceInBuilding;
/**
* 所属楼栋
*/
private Integer deviceInFloor;
/**
* 负责人
*/
private String leadingOfficial;
/**
* 联系电话
*/
private String leadingOfficialTelephone;
/**
* 保修期至
*/
private Date defectsLiabilityPeriod;
/**
* 设备状态 (0.未激活,1.离线,2.在线)
*/
private Integer deviceStatus;
/**
* 设备来源(0.旧设备,1.新设备)
*/
private Integer source;
/**
* 激活(0.否,1.是)
*/
private Integer active;
/**
* 设备版本信息
*/
private String deviceVersion;
}
package com.mortals.xhx.feign.device;
import com.mortals.framework.common.Rest;
import com.mortals.xhx.common.pdu.LoginForm;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.device.DevicePdu;
import com.mortals.xhx.common.pdu.device.DeviceReq;
import com.mortals.xhx.feign.IFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
......@@ -59,6 +61,25 @@ public interface IDeviceFeign extends IFeign {
Rest<RespData<DevicePdu>> save(@RequestBody DevicePdu devicePdu,@RequestHeader("Authorization") String authorization);
/**
* 获取token
*
* @param loginForm
* @return
*/
@PostMapping(value = "/api/getToken")
Rest<String> getToken(@RequestBody LoginForm loginForm);
/**
* 设备回调
*
* @param deviceReq
* @return
*/
@PostMapping(value = "/api/receive")
Rest<String> deviceCall(@RequestBody DeviceReq deviceReq, @RequestHeader("Authorization") String authorization);
}
......@@ -87,6 +108,16 @@ class DeviceFeignFallbackFactory implements FallbackFactory<IDeviceFeign> {
public Rest<RespData<DevicePdu>> save(DevicePdu devicePdu, String authorization) {
return Rest.fail("暂时无法保存设备,请稍后再试!");
}
@Override
public Rest<String> getToken(LoginForm loginForm) {
return Rest.fail("暂时无法获取token,请稍后再试!");
}
@Override
public Rest<String> deviceCall(DeviceReq deviceReq, String authorization) {
return Rest.fail("暂时无法保存设备,请稍后再试!");
}
};
}
}
......
......@@ -16,3 +16,24 @@ ALTER TABLE mortals_xhx_matter_datum_print ADD COLUMN `mobile` varchar(64) defau
2023-03-22
-- ----------------------------
INSERT INTO `mortals_xhx_task` (`id`, `name`, `taskKey`, `status`, `excuteService`, `excuteParam`, `excuteHost`, `excuteStrategy`, `excuteDate`, `excuteTime`, `remark`, `lastExcuteHost`, `lastExcuteTime`, `interimExcuteStatus`, `createTime`, `createUserId`, `createUserName`) VALUES ('4', '同步设备', 'SyncSiteDeviceTask', '0', 'SyncSiteDeviceTask', NULL, NULL, '4', '120', '00:00', NULL, '127.0.1.1', '2023-02-26 22:15:59', '0', '2023-02-25 14:34:12', '1', NULL);
-- ----------------------------
2023-06-21
-- ----------------------------
ALTER TABLE mortals_xhx_device
ADD COLUMN `deviceFirmId` bigint(20) DEFAULT NULL COMMENT '设备生产厂商ID' AFTER siteName;
ALTER TABLE mortals_xhx_device
ADD COLUMN `deviceFirmname` varchar(200) DEFAULT NULL COMMENT '设备生产厂商名称' AFTER deviceFirmId;
ALTER TABLE mortals_xhx_device
ADD COLUMN `ip` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '设备访问ip' AFTER deviceFirmname;
ALTER TABLE mortals_xhx_device
ADD COLUMN `port` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '端口' AFTER ip;
ALTER TABLE mortals_xhx_device
ADD COLUMN `enabled` tinyint(2) DEFAULT NULL COMMENT '启用状态 (0.停止,1.启用)' AFTER port;
ALTER TABLE mortals_xhx_device
ADD COLUMN `onlineTime` datetime DEFAULT NULL COMMENT '最近上线时间' AFTER enabled;
ALTER TABLE mortals_xhx_device
ADD COLUMN `offlineTime` datetime DEFAULT NULL COMMENT '最近离线时间' AFTER onlineTime;
\ No newline at end of file
......@@ -4,8 +4,10 @@ import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import cn.hutool.core.util.StrUtil;
import com.mortals.framework.model.OperateLogPdu;
import com.mortals.framework.service.IMessageProduceService;
import com.mortals.xhx.common.code.OperTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
......@@ -43,6 +45,16 @@ public class OperlogAspect extends FileLogServiceImpl implements ILogService {
String content, String ip, Date logDate) {
super.doHandlerLog(platformMark, userId, userName, loginName, requestUrl, content, ip, logDate);
operLogService.insertOperLog(ip, requestUrl, userId, userName, loginName, content);
int operType = OperTypeEnum.OTHER.getValue();
//判断内容包含
if (StrUtil.contains(content, "查询") || StrUtil.contains(content, "查看")) {
operType = OperTypeEnum.SEARCH.getValue();
} else if (StrUtil.contains(content, "保存") || StrUtil.contains(content, "新增") || StrUtil.contains(content, "修改")) {
operType = OperTypeEnum.SAVE.getValue();
} else if (StrUtil.contains(content, "删除")) {
operType = OperTypeEnum.DELETE.getValue();
}
OperateLogPdu operateLogPdu = new OperateLogPdu();
operateLogPdu.initAttrValue();
operateLogPdu.setIp(ip);
......@@ -53,7 +65,7 @@ public class OperlogAspect extends FileLogServiceImpl implements ILogService {
operateLogPdu.setPlatformMark(platformMark);
operateLogPdu.setLogDate(logDate);
operateLogPdu.setContent(content);
operateLogPdu.setOperType(1);
operateLogPdu.setOperType(operType);
messageProduceService.syncOperSend(operateLogPdu);
}
......
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 设备请求方式,1:新增,2:修改,3:删除,4:激活,5:启用,6:停用
*
* @author zxfei
*/
public enum DeviceMethodEnum {
ADD(1, "新增"),
UPDATE(2, "修改"),
DEL(3, "删除"),
ACTIVE(4, "激活"),
ENABLED(5, "启用"),
STOP(6, "停用"),
ONLINE(7, "上线"),
OFFLINE(8, "下线")
;
private Integer value;
private String desc;
DeviceMethodEnum(Integer value, String desc) {
this.value = value;
this.desc = desc;
}
public Integer getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static DeviceMethodEnum getByValue(Integer value) {
for (DeviceMethodEnum deviceTypeEnum : DeviceMethodEnum.values()) {
if (deviceTypeEnum.getValue() == value) {
return deviceTypeEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(Integer... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (DeviceMethodEnum item : DeviceMethodEnum.values()) {
try {
boolean hasE = false;
for (Integer e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 设备状态 (0.未激活,1.离线,2.在线)枚举类
*
* @author zxfei
*/
public enum DeviceStatusEnum {
未激活(0, "未激活"),
离线(1, "离线"),
在线(2, "在线");
private Integer value;
private String desc;
DeviceStatusEnum(Integer value, String desc) {
this.value = value;
this.desc = desc;
}
public Integer getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static DeviceStatusEnum getByValue(Integer value) {
for (DeviceStatusEnum deviceStatusEnum : DeviceStatusEnum.values()) {
if (deviceStatusEnum.getValue() == value) {
return deviceStatusEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(Integer... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (DeviceStatusEnum item : DeviceStatusEnum.values()) {
try {
boolean hasE = false;
for (Integer e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 启用状态 (0.停止,1.启用)枚举类
*
* @author zxfei
*/
public enum EnabledEnum {
停止(0, "停止"),
启用(1, "启用");
private Integer value;
private String desc;
EnabledEnum(Integer value, String desc) {
this.value = value;
this.desc = desc;
}
public Integer getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static EnabledEnum getByValue(Integer value) {
for (EnabledEnum enabledEnum : EnabledEnum.values()) {
if (enabledEnum.getValue() == value) {
return enabledEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(Integer... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (EnabledEnum item : EnabledEnum.values()) {
try {
boolean hasE = false;
for (Integer e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
......@@ -3,20 +3,19 @@ package com.mortals.xhx.common.code;
import java.util.HashMap;
import java.util.Map;
/**
* Created by chendilin on 2018/3/7.
*/
public enum OperTypeEnum {
SAVE(0,"添加"),
UPDATE(1,"更新"),
DELETE(2,"删除"),
OTHER(-1,"其它");
SAVE(0, "添加"),
UPDATE(1, "更新"),
DELETE(2, "删除"),
SEARCH(3, "查询"),
OTHER(-1, "其它");
private int value;
private String msg;
private OperTypeEnum(int value,String msg) {
private OperTypeEnum(int value, String msg) {
this.value = value;
this.msg = msg;
}
......@@ -25,11 +24,11 @@ public enum OperTypeEnum {
return this.value;
}
public static Map<String,String> getEnumMap(){
Map<String,String> resultMap = new HashMap<>();
public static Map<String, String> getEnumMap() {
Map<String, String> resultMap = new HashMap<>();
OperTypeEnum[] operTypeEnum = OperTypeEnum.values();
for (OperTypeEnum typeEnum : operTypeEnum) {
resultMap.put(String.valueOf(typeEnum.value),typeEnum.msg);
resultMap.put(String.valueOf(typeEnum.value), typeEnum.msg);
}
return resultMap;
}
......
package com.mortals.xhx.module.device.model;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mortals.framework.annotation.Excel;
import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.module.device.model.vo.DeviceVo;
import lombok.Data;
/**
* 设备实体对象
*
* @author zxfei
* @date 2023-02-25
*/
* 设备实体对象
*
* @author zxfei
* @date 2023-06-21
*/
@Data
public class DeviceEntity extends DeviceVo {
private static final long serialVersionUID = 1L;
......@@ -79,252 +85,34 @@ public class DeviceEntity extends DeviceVo {
* 设备来源(0.旧设备,1.新设备)
*/
private Integer source;
public DeviceEntity(){}
/**
* 获取 设备id
* @return Long
*/
public Long getDeviceId(){
return deviceId;
}
/**
* 设置 设备id
* @param deviceId
*/
public void setDeviceId(Long deviceId){
this.deviceId = deviceId;
}
/**
* 获取 设备名称
* @return String
*/
public String getDeviceName(){
return deviceName;
}
/**
* 设置 设备名称
* @param deviceName
*/
public void setDeviceName(String deviceName){
this.deviceName = deviceName;
}
/**
* 获取 设备编码
* @return String
*/
public String getDeviceCode(){
return deviceCode;
}
/**
* 设置 设备编码
* @param deviceCode
*/
public void setDeviceCode(String deviceCode){
this.deviceCode = deviceCode;
}
/**
* 获取 设备的MAC地址
* @return String
*/
public String getDeviceMac(){
return deviceMac;
}
/**
* 设置 设备的MAC地址
* @param deviceMac
* 设备生产厂商ID
*/
public void setDeviceMac(String deviceMac){
this.deviceMac = deviceMac;
}
/**
* 获取 站点Id
* @return Long
*/
public Long getSiteId(){
return siteId;
}
/**
* 设置 站点Id
* @param siteId
*/
public void setSiteId(Long siteId){
this.siteId = siteId;
}
private Long deviceFirmId;
/**
* 获取 站点编号,来源基础服务平台
* @return String
* 设备生产厂商名称
*/
public String getSiteCode(){
return siteCode;
}
private String deviceFirmname;
/**
* 设置 站点编号,来源基础服务平台
* @param siteCode
* 设备访问ip
*/
public void setSiteCode(String siteCode){
this.siteCode = siteCode;
}
private String ip;
/**
* 获取 站点名称
* @return String
* 端口
*/
public String getSiteName(){
return siteName;
}
private String port;
/**
* 设置 站点名称
* @param siteName
* 启用状态 (0.停止,1.启用)
*/
public void setSiteName(String siteName){
this.siteName = siteName;
}
/**
* 获取 产品编码
* @return String
*/
public String getProductCode(){
return productCode;
}
private Integer enabled;
/**
* 设置 产品编码
* @param productCode
* 最近上线时间
*/
public void setProductCode(String productCode){
this.productCode = productCode;
}
/**
* 获取 产品名称
* @return String
*/
public String getProductName(){
return productName;
}
/**
* 设置 产品名称
* @param productName
*/
public void setProductName(String productName){
this.productName = productName;
}
/**
* 获取 设备来源(0.子设备,1.网关设备,2.直连设备)
* @return Integer
*/
public Integer getDeviceSrc(){
return deviceSrc;
}
/**
* 设置 设备来源(0.子设备,1.网关设备,2.直连设备)
* @param deviceSrc
*/
public void setDeviceSrc(Integer deviceSrc){
this.deviceSrc = deviceSrc;
}
private Date onlineTime;
/**
* 获取 经度
* @return String
* 最近离线时间
*/
public String getLon(){
return lon;
}
/**
* 设置 经度
* @param lon
*/
public void setLon(String lon){
this.lon = lon;
}
/**
* 获取 纬度
* @return String
*/
public String getLati(){
return lati;
}
/**
* 设置 纬度
* @param lati
*/
public void setLati(String lati){
this.lati = lati;
}
/**
* 获取 负责人
* @return String
*/
public String getLeadingOfficial(){
return leadingOfficial;
}
/**
* 设置 负责人
* @param leadingOfficial
*/
public void setLeadingOfficial(String leadingOfficial){
this.leadingOfficial = leadingOfficial;
}
/**
* 获取 联系电话
* @return String
*/
public String getLeadingOfficialTelephone(){
return leadingOfficialTelephone;
}
/**
* 设置 联系电话
* @param leadingOfficialTelephone
*/
public void setLeadingOfficialTelephone(String leadingOfficialTelephone){
this.leadingOfficialTelephone = leadingOfficialTelephone;
}
/**
* 获取 设备状态 (0.未激活,1.离线,2.在线)
* @return Integer
*/
public Integer getDeviceStatus(){
return deviceStatus;
}
/**
* 设置 设备状态 (0.未激活,1.离线,2.在线)
* @param deviceStatus
*/
public void setDeviceStatus(Integer deviceStatus){
this.deviceStatus = deviceStatus;
}
/**
* 获取 备注
* @return String
*/
public String getDeviceRemark(){
return deviceRemark;
}
/**
* 设置 备注
* @param deviceRemark
*/
public void setDeviceRemark(String deviceRemark){
this.deviceRemark = deviceRemark;
}
/**
* 获取 设备来源(0.旧设备,1.新设备)
* @return Integer
*/
public Integer getSource(){
return source;
}
/**
* 设置 设备来源(0.旧设备,1.新设备)
* @param source
*/
public void setSource(Integer source){
this.source = source;
}
private Date offlineTime;
@Override
public int hashCode() {
return this.getId().hashCode();
......@@ -341,62 +129,54 @@ public class DeviceEntity extends DeviceVo {
return false;
}
public String toString(){
StringBuilder sb = new StringBuilder("");
sb.append(",deviceId:").append(getDeviceId());
sb.append(",deviceName:").append(getDeviceName());
sb.append(",deviceCode:").append(getDeviceCode());
sb.append(",deviceMac:").append(getDeviceMac());
sb.append(",siteId:").append(getSiteId());
sb.append(",siteCode:").append(getSiteCode());
sb.append(",siteName:").append(getSiteName());
sb.append(",productCode:").append(getProductCode());
sb.append(",productName:").append(getProductName());
sb.append(",deviceSrc:").append(getDeviceSrc());
sb.append(",lon:").append(getLon());
sb.append(",lati:").append(getLati());
sb.append(",leadingOfficial:").append(getLeadingOfficial());
sb.append(",leadingOfficialTelephone:").append(getLeadingOfficialTelephone());
sb.append(",deviceStatus:").append(getDeviceStatus());
sb.append(",deviceRemark:").append(getDeviceRemark());
sb.append(",source:").append(getSource());
return sb.toString();
}
public void initAttrValue(){
this.deviceId = null;
this.deviceId = -1L;
this.deviceName = null;
this.deviceName = "";
this.deviceCode = null;
this.deviceCode = "";
this.deviceMac = null;
this.deviceMac = "";
this.siteId = null;
this.siteId = -1L;
this.siteCode = null;
this.siteCode = "";
this.siteName = null;
this.siteName = "";
this.productCode = null;
this.productCode = "";
this.productName = null;
this.productName = "";
this.deviceSrc = 2;
this.lon = null;
this.lon = "";
this.lati = null;
this.lati = "";
this.leadingOfficial = null;
this.leadingOfficial = "";
this.leadingOfficialTelephone = null;
this.leadingOfficialTelephone = "";
this.deviceStatus = null;
this.deviceStatus = 0;
this.deviceRemark = null;
this.deviceRemark = "";
this.source = 1;
this.deviceFirmId = -1L;
this.deviceFirmname = "";
this.ip = "";
this.port = "";
this.enabled = 0;
this.onlineTime = null;
this.offlineTime = null;
}
}
\ No newline at end of file
package com.mortals.xhx.module.device.model;
import java.util.Date;
import java.util.List;
import com.mortals.xhx.module.device.model.DeviceEntity;
/**
* 设备查询对象
*
* @author zxfei
* @date 2023-02-25
*/
* 设备查询对象
*
* @author zxfei
* @date 2023-06-21
*/
public class DeviceQuery extends DeviceEntity {
/** 开始 主键ID,主键,自增长 */
private Long idStart;
......@@ -201,6 +202,63 @@ public class DeviceQuery extends DeviceEntity {
/** 结束 更新时间 */
private String updateTimeEnd;
/** 开始 设备生产厂商ID */
private Long deviceFirmIdStart;
/** 结束 设备生产厂商ID */
private Long deviceFirmIdEnd;
/** 增加 设备生产厂商ID */
private Long deviceFirmIdIncrement;
/** 设备生产厂商ID列表 */
private List <Long> deviceFirmIdList;
/** 设备生产厂商ID排除列表 */
private List <Long> deviceFirmIdNotList;
/** 设备生产厂商名称 */
private List<String> deviceFirmnameList;
/** 设备生产厂商名称排除列表 */
private List <String> deviceFirmnameNotList;
/** 设备访问ip */
private List<String> ipList;
/** 设备访问ip排除列表 */
private List <String> ipNotList;
/** 端口 */
private List<String> portList;
/** 端口排除列表 */
private List <String> portNotList;
/** 开始 启用状态 (0.停止,1.启用) */
private Integer enabledStart;
/** 结束 启用状态 (0.停止,1.启用) */
private Integer enabledEnd;
/** 增加 启用状态 (0.停止,1.启用) */
private Integer enabledIncrement;
/** 启用状态 (0.停止,1.启用)列表 */
private List <Integer> enabledList;
/** 启用状态 (0.停止,1.启用)排除列表 */
private List <Integer> enabledNotList;
/** 开始 最近上线时间 */
private String onlineTimeStart;
/** 结束 最近上线时间 */
private String onlineTimeEnd;
/** 开始 最近离线时间 */
private String offlineTimeStart;
/** 结束 最近离线时间 */
private String offlineTimeEnd;
/** OR条件集合,列表项之间是OR,项内容之间是AND,如:(list[0].1 and list[0].2) or (list[1].3 and list[1].4) */
private List<DeviceQuery> orConditionList;
......@@ -1305,6 +1363,328 @@ public class DeviceQuery extends DeviceEntity {
this.updateTimeEnd = updateTimeEnd;
}
/**
* 获取 开始 设备生产厂商ID
* @return deviceFirmIdStart
*/
public Long getDeviceFirmIdStart(){
return this.deviceFirmIdStart;
}
/**
* 设置 开始 设备生产厂商ID
* @param deviceFirmIdStart
*/
public void setDeviceFirmIdStart(Long deviceFirmIdStart){
this.deviceFirmIdStart = deviceFirmIdStart;
}
/**
* 获取 结束 设备生产厂商ID
* @return $deviceFirmIdEnd
*/
public Long getDeviceFirmIdEnd(){
return this.deviceFirmIdEnd;
}
/**
* 设置 结束 设备生产厂商ID
* @param deviceFirmIdEnd
*/
public void setDeviceFirmIdEnd(Long deviceFirmIdEnd){
this.deviceFirmIdEnd = deviceFirmIdEnd;
}
/**
* 获取 增加 设备生产厂商ID
* @return deviceFirmIdIncrement
*/
public Long getDeviceFirmIdIncrement(){
return this.deviceFirmIdIncrement;
}
/**
* 设置 增加 设备生产厂商ID
* @param deviceFirmIdIncrement
*/
public void setDeviceFirmIdIncrement(Long deviceFirmIdIncrement){
this.deviceFirmIdIncrement = deviceFirmIdIncrement;
}
/**
* 获取 设备生产厂商ID
* @return deviceFirmIdList
*/
public List<Long> getDeviceFirmIdList(){
return this.deviceFirmIdList;
}
/**
* 设置 设备生产厂商ID
* @param deviceFirmIdList
*/
public void setDeviceFirmIdList(List<Long> deviceFirmIdList){
this.deviceFirmIdList = deviceFirmIdList;
}
/**
* 获取 设备生产厂商ID
* @return deviceFirmIdNotList
*/
public List<Long> getDeviceFirmIdNotList(){
return this.deviceFirmIdNotList;
}
/**
* 设置 设备生产厂商ID
* @param deviceFirmIdNotList
*/
public void setDeviceFirmIdNotList(List<Long> deviceFirmIdNotList){
this.deviceFirmIdNotList = deviceFirmIdNotList;
}
/**
* 获取 设备生产厂商名称
* @return deviceFirmnameList
*/
public List<String> getDeviceFirmnameList(){
return this.deviceFirmnameList;
}
/**
* 设置 设备生产厂商名称
* @param deviceFirmnameList
*/
public void setDeviceFirmnameList(List<String> deviceFirmnameList){
this.deviceFirmnameList = deviceFirmnameList;
}
/**
* 获取 设备生产厂商名称
* @return deviceFirmnameNotList
*/
public List<String> getDeviceFirmnameNotList(){
return this.deviceFirmnameNotList;
}
/**
* 设置 设备生产厂商名称
* @param deviceFirmnameNotList
*/
public void setDeviceFirmnameNotList(List<String> deviceFirmnameNotList){
this.deviceFirmnameNotList = deviceFirmnameNotList;
}
/**
* 获取 设备访问ip
* @return ipList
*/
public List<String> getIpList(){
return this.ipList;
}
/**
* 设置 设备访问ip
* @param ipList
*/
public void setIpList(List<String> ipList){
this.ipList = ipList;
}
/**
* 获取 设备访问ip
* @return ipNotList
*/
public List<String> getIpNotList(){
return this.ipNotList;
}
/**
* 设置 设备访问ip
* @param ipNotList
*/
public void setIpNotList(List<String> ipNotList){
this.ipNotList = ipNotList;
}
/**
* 获取 端口
* @return portList
*/
public List<String> getPortList(){
return this.portList;
}
/**
* 设置 端口
* @param portList
*/
public void setPortList(List<String> portList){
this.portList = portList;
}
/**
* 获取 端口
* @return portNotList
*/
public List<String> getPortNotList(){
return this.portNotList;
}
/**
* 设置 端口
* @param portNotList
*/
public void setPortNotList(List<String> portNotList){
this.portNotList = portNotList;
}
/**
* 获取 开始 启用状态 (0.停止,1.启用)
* @return enabledStart
*/
public Integer getEnabledStart(){
return this.enabledStart;
}
/**
* 设置 开始 启用状态 (0.停止,1.启用)
* @param enabledStart
*/
public void setEnabledStart(Integer enabledStart){
this.enabledStart = enabledStart;
}
/**
* 获取 结束 启用状态 (0.停止,1.启用)
* @return $enabledEnd
*/
public Integer getEnabledEnd(){
return this.enabledEnd;
}
/**
* 设置 结束 启用状态 (0.停止,1.启用)
* @param enabledEnd
*/
public void setEnabledEnd(Integer enabledEnd){
this.enabledEnd = enabledEnd;
}
/**
* 获取 增加 启用状态 (0.停止,1.启用)
* @return enabledIncrement
*/
public Integer getEnabledIncrement(){
return this.enabledIncrement;
}
/**
* 设置 增加 启用状态 (0.停止,1.启用)
* @param enabledIncrement
*/
public void setEnabledIncrement(Integer enabledIncrement){
this.enabledIncrement = enabledIncrement;
}
/**
* 获取 启用状态 (0.停止,1.启用)
* @return enabledList
*/
public List<Integer> getEnabledList(){
return this.enabledList;
}
/**
* 设置 启用状态 (0.停止,1.启用)
* @param enabledList
*/
public void setEnabledList(List<Integer> enabledList){
this.enabledList = enabledList;
}
/**
* 获取 启用状态 (0.停止,1.启用)
* @return enabledNotList
*/
public List<Integer> getEnabledNotList(){
return this.enabledNotList;
}
/**
* 设置 启用状态 (0.停止,1.启用)
* @param enabledNotList
*/
public void setEnabledNotList(List<Integer> enabledNotList){
this.enabledNotList = enabledNotList;
}
/**
* 获取 开始 最近上线时间
* @return onlineTimeStart
*/
public String getOnlineTimeStart(){
return this.onlineTimeStart;
}
/**
* 设置 开始 最近上线时间
* @param onlineTimeStart
*/
public void setOnlineTimeStart(String onlineTimeStart){
this.onlineTimeStart = onlineTimeStart;
}
/**
* 获取 结束 最近上线时间
* @return onlineTimeEnd
*/
public String getOnlineTimeEnd(){
return this.onlineTimeEnd;
}
/**
* 设置 结束 最近上线时间
* @param onlineTimeEnd
*/
public void setOnlineTimeEnd(String onlineTimeEnd){
this.onlineTimeEnd = onlineTimeEnd;
}
/**
* 获取 开始 最近离线时间
* @return offlineTimeStart
*/
public String getOfflineTimeStart(){
return this.offlineTimeStart;
}
/**
* 设置 开始 最近离线时间
* @param offlineTimeStart
*/
public void setOfflineTimeStart(String offlineTimeStart){
this.offlineTimeStart = offlineTimeStart;
}
/**
* 获取 结束 最近离线时间
* @return offlineTimeEnd
*/
public String getOfflineTimeEnd(){
return this.offlineTimeEnd;
}
/**
* 设置 结束 最近离线时间
* @param offlineTimeEnd
*/
public void setOfflineTimeEnd(String offlineTimeEnd){
this.offlineTimeEnd = offlineTimeEnd;
}
/**
* 设置 主键ID,主键,自增长
* @param id
......@@ -1967,6 +2347,173 @@ public class DeviceQuery extends DeviceEntity {
}
/**
* 设置 设备生产厂商ID
* @param deviceFirmId
*/
public DeviceQuery deviceFirmId(Long deviceFirmId){
setDeviceFirmId(deviceFirmId);
return this;
}
/**
* 设置 开始 设备生产厂商ID
* @param deviceFirmIdStart
*/
public DeviceQuery deviceFirmIdStart(Long deviceFirmIdStart){
this.deviceFirmIdStart = deviceFirmIdStart;
return this;
}
/**
* 设置 结束 设备生产厂商ID
* @param deviceFirmIdEnd
*/
public DeviceQuery deviceFirmIdEnd(Long deviceFirmIdEnd){
this.deviceFirmIdEnd = deviceFirmIdEnd;
return this;
}
/**
* 设置 增加 设备生产厂商ID
* @param deviceFirmIdIncrement
*/
public DeviceQuery deviceFirmIdIncrement(Long deviceFirmIdIncrement){
this.deviceFirmIdIncrement = deviceFirmIdIncrement;
return this;
}
/**
* 设置 设备生产厂商ID
* @param deviceFirmIdList
*/
public DeviceQuery deviceFirmIdList(List<Long> deviceFirmIdList){
this.deviceFirmIdList = deviceFirmIdList;
return this;
}
/**
* 设置 设备生产厂商ID
* @param deviceFirmIdNotList
*/
public DeviceQuery deviceFirmIdNotList(List<Long> deviceFirmIdNotList){
this.deviceFirmIdNotList = deviceFirmIdNotList;
return this;
}
/**
* 设置 设备生产厂商名称
* @param deviceFirmname
*/
public DeviceQuery deviceFirmname(String deviceFirmname){
setDeviceFirmname(deviceFirmname);
return this;
}
/**
* 设置 设备生产厂商名称
* @param deviceFirmnameList
*/
public DeviceQuery deviceFirmnameList(List<String> deviceFirmnameList){
this.deviceFirmnameList = deviceFirmnameList;
return this;
}
/**
* 设置 设备访问ip
* @param ip
*/
public DeviceQuery ip(String ip){
setIp(ip);
return this;
}
/**
* 设置 设备访问ip
* @param ipList
*/
public DeviceQuery ipList(List<String> ipList){
this.ipList = ipList;
return this;
}
/**
* 设置 端口
* @param port
*/
public DeviceQuery port(String port){
setPort(port);
return this;
}
/**
* 设置 端口
* @param portList
*/
public DeviceQuery portList(List<String> portList){
this.portList = portList;
return this;
}
/**
* 设置 启用状态 (0.停止,1.启用)
* @param enabled
*/
public DeviceQuery enabled(Integer enabled){
setEnabled(enabled);
return this;
}
/**
* 设置 开始 启用状态 (0.停止,1.启用)
* @param enabledStart
*/
public DeviceQuery enabledStart(Integer enabledStart){
this.enabledStart = enabledStart;
return this;
}
/**
* 设置 结束 启用状态 (0.停止,1.启用)
* @param enabledEnd
*/
public DeviceQuery enabledEnd(Integer enabledEnd){
this.enabledEnd = enabledEnd;
return this;
}
/**
* 设置 增加 启用状态 (0.停止,1.启用)
* @param enabledIncrement
*/
public DeviceQuery enabledIncrement(Integer enabledIncrement){
this.enabledIncrement = enabledIncrement;
return this;
}
/**
* 设置 启用状态 (0.停止,1.启用)
* @param enabledList
*/
public DeviceQuery enabledList(List<Integer> enabledList){
this.enabledList = enabledList;
return this;
}
/**
* 设置 启用状态 (0.停止,1.启用)
* @param enabledNotList
*/
public DeviceQuery enabledNotList(List<Integer> enabledNotList){
this.enabledNotList = enabledNotList;
return this;
}
/**
* 获取 OR条件集合,列表项之间是OR,项内容之间是AND,如:(list[0].1 and list[0].2) or (list[1].3 and list[1].4)
* @return orConditionList
......
package com.mortals.xhx.module.device.service;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.device.dao.DeviceDao;
import com.mortals.xhx.module.device.model.DeviceEntity;
/**
* DeviceService
......@@ -10,5 +12,20 @@ import com.mortals.xhx.module.device.model.DeviceEntity;
* @date 2023-02-25
*/
public interface DeviceService extends ICRUDService<DeviceEntity,Long>{
DeviceDao getDao();
/**
* 设备激活
* @param deviceCode
* @param context
*/
void active(String deviceCode, Context context);
/**
* 设备启用停用
* @param id
* @param context
*/
void deviceEnabled(Long id, Integer status, Context context);
}
\ No newline at end of file
package com.mortals.xhx.module.device.service.impl;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.common.code.DeviceMethodEnum;
import com.mortals.xhx.common.code.DeviceStatusEnum;
import com.mortals.xhx.common.code.EnabledEnum;
import com.mortals.xhx.common.pdu.LoginForm;
import com.mortals.xhx.common.pdu.device.DeviceReq;
import com.mortals.xhx.feign.device.IDeviceFeign;
import com.mortals.xhx.module.device.dao.DeviceDao;
import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.model.DeviceQuery;
import com.mortals.xhx.module.device.service.DeviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Date;
/**
* DeviceService
* 设备 service实现
......@@ -13,6 +31,57 @@ import org.springframework.stereotype.Service;
* @date 2023-02-25
*/
@Service("deviceService")
@Slf4j
public class DeviceServiceImpl extends AbstractCRUDServiceImpl<DeviceDao, DeviceEntity, Long> implements DeviceService {
@Autowired
private IDeviceFeign deviceFeign;
@Value("${token.loginName:'admin'}")
private String loginName;
@Value("${token.password:'admin'}")
private String password;
@Override
public void active(String deviceCode, Context context) {
DeviceEntity deviceEntity = this.selectOne(new DeviceQuery().deviceCode(deviceCode));
if (ObjectUtils.isEmpty(deviceEntity)) throw new AppException("当前设备不存在!");
if (deviceEntity.getDeviceStatus() > DeviceStatusEnum.未激活.getValue())
throw new AppException("当前设备已激活!");
deviceEntity.setDeviceStatus(DeviceStatusEnum.离线.getValue());
deviceEntity.setEnabled(EnabledEnum.启用.getValue());
this.getDao().update(deviceEntity);
String token = getToken();
DeviceReq deviceReq = new DeviceReq();
deviceReq.setReceiveMethod(DeviceMethodEnum.ACTIVE.getValue());
deviceReq.setDeviceCode(deviceCode);
Rest<String> rest = deviceFeign.deviceCall(deviceReq, token);
log.info("激活结果:{}", JSON.toJSONString(rest));
}
@Override
public void deviceEnabled(Long id, Integer enabled, Context context) {
DeviceEntity deviceEntity = this.get(id, context);
if (ObjectUtils.isEmpty(deviceEntity)) throw new AppException("当前设备不存在!");
deviceEntity.setEnabled(enabled);
deviceEntity.setUpdateTime(new Date());
deviceEntity.setUpdateUserId(getContextUserId(context));
this.getDao().update(deviceEntity);
String token = getToken();
DeviceReq deviceReq = new DeviceReq();
deviceReq.setReceiveMethod(DeviceMethodEnum.ENABLED.getValue());
deviceReq.setDeviceCode(deviceEntity.getDeviceCode());
Rest<String> rest = deviceFeign.deviceCall(deviceReq, token);
log.info("启用结果:{}", JSON.toJSONString(rest));
}
private String getToken() {
LoginForm loginForm = new LoginForm();
loginForm.setLoginName(loginName);
loginForm.setPassword(password);
Rest<String> rest = deviceFeign.getToken(loginForm);
String token = rest.getData();
return token;
}
}
\ No newline at end of file
package com.mortals.xhx.module.device.web;
import com.mortals.framework.model.Context;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.service.DeviceService;
import com.mortals.xhx.common.code.DeviceMethodEnum;
import com.mortals.xhx.common.code.EnabledEnum;
import com.mortals.xhx.common.pdu.LoginForm;
import com.mortals.xhx.common.pdu.device.DeviceReq;
import com.mortals.xhx.feign.device.IDeviceFeign;
import com.mortals.xhx.module.device.model.DeviceQuery;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.mortals.framework.model.Context;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.service.DeviceService;
import org.apache.commons.lang3.ArrayUtils;
import com.mortals.framework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject;
import java.util.Arrays;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import static com.mortals.framework.ap.SysConstains.*;
/**
*
* 设备
*
* @author zxfei
* @date 2023-02-25
*/
* 设备
*
* @author zxfei
* @date 2023-02-25
*/
@RestController
@RequestMapping("device")
public class DeviceController extends BaseCRUDJsonBodyMappingController<DeviceService,DeviceEntity,Long> {
@Slf4j
public class DeviceController extends BaseCRUDJsonBodyMappingController<DeviceService, DeviceEntity, Long> {
@Autowired
private ParamService paramService;
public DeviceController(){
super.setModuleDesc( "设备");
@Autowired
private IDeviceFeign deviceFeign;
@Value("${token.loginName:'admin'}")
private String loginName;
@Value("${token.password:'admin'}")
private String password;
public DeviceController() {
super.setModuleDesc("设备");
}
@Override
protected void init(Map<String, Object> model, Context context) {
this.addDict(model, "deviceSrc", paramService.getParamBySecondOrganize("Device","deviceSrc"));
this.addDict(model, "deviceStatus", paramService.getParamBySecondOrganize("Device","deviceStatus"));
this.addDict(model, "source", paramService.getParamBySecondOrganize("Device","source"));
this.addDict(model, "deviceSrc", paramService.getParamBySecondOrganize("Device", "deviceSrc"));
this.addDict(model, "deviceStatus", paramService.getParamBySecondOrganize("Device", "deviceStatus"));
this.addDict(model, "source", paramService.getParamBySecondOrganize("Device", "source"));
this.addDict(model, "enabled", EnabledEnum.getEnumMap());
super.init(model, context);
}
/**
* 设备激活
*/
@PostMapping(value = "active")
public Rest<Void> deviceActive(@RequestBody DeviceEntity deviceEntity) {
log.info("设备激活:{}", deviceEntity.getDeviceCode());
String busiDesc = this.getModuleDesc() + "设备激活";
Rest<Void> rest = Rest.ok(busiDesc + " 【成功】");
try {
this.service.active(deviceEntity.getDeviceCode(), getContext());
recordSysLog(request, busiDesc + " 【成功】");
} catch (Exception e) {
log.error("设备激活消息", e);
rest = Rest.fail(super.convertException(e));
}
return rest;
}
/**
* 设备启用停用
*/
@PostMapping(value = "enable")
public String deviceEnable(@RequestBody DeviceEntity deviceEntity) {
JSONObject jsonObject = new JSONObject();
Map<String, Object> model = new HashMap<>();
String busiDesc = this.getModuleDesc() + "设备";
try {
this.service.deviceEnabled(deviceEntity.getId(), deviceEntity.getEnabled(), getContext());
recordSysLog(request, busiDesc + EnabledEnum.getByValue(deviceEntity.getEnabled()).getDesc() + " 【成功】");
jsonObject.put(KEY_RESULT_DATA, model);
jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
} catch (Exception e) {
log.error("设备启用停用消息", e);
jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
jsonObject.put(KEY_RESULT_MSG, super.convertException(e));
}
return jsonObject.toJSONString();
}
@Override
protected int saveAfter(DeviceEntity entity, Map<String, Object> model, Context context) throws AppException {
if (ObjectUtils.isEmpty(entity.getUpdateTime())) {
String token = getToken();
DeviceReq deviceReq = new DeviceReq();
deviceReq.setReceiveMethod(DeviceMethodEnum.ADD.getValue());
deviceReq.setDeviceName(entity.getDeviceName());
deviceReq.setDeviceCode(entity.getDeviceCode());
deviceReq.setProductCode(entity.getProductCode());
deviceReq.setIp(entity.getIp());
deviceReq.setPort(entity.getPort());
deviceReq.setSiteId(1L);
deviceReq.setSiteCode("511500000000-0001");
deviceReq.setSiteName("宜宾市民中心");
deviceReq.setLeadingOfficial(entity.getLeadingOfficial());
deviceReq.setLeadingOfficialTelephone(entity.getLeadingOfficialTelephone());
deviceReq.setSource(1);
deviceReq.setDeviceStatus(entity.getDeviceStatus());
Rest<String> rest = deviceFeign.deviceCall(deviceReq, token);
log.info("添加结果:{}", JSON.toJSONString(rest));
} else {
String token = getToken();
DeviceReq deviceReq = new DeviceReq();
deviceReq.setReceiveMethod(DeviceMethodEnum.UPDATE.getValue());
deviceReq.setDeviceName(entity.getDeviceName());
deviceReq.setDeviceCode(entity.getDeviceCode());
deviceReq.setProductCode(entity.getProductCode());
deviceReq.setIp(entity.getIp());
deviceReq.setPort(entity.getPort());
deviceReq.setSiteId(1L);
deviceReq.setSiteCode("511500000000-0001");
deviceReq.setSiteName("宜宾市民中心");
deviceReq.setLeadingOfficial(entity.getLeadingOfficial());
deviceReq.setLeadingOfficialTelephone(entity.getLeadingOfficialTelephone());
deviceReq.setSource(1);
deviceReq.setDeviceStatus(entity.getDeviceStatus());
Rest<String> rest = deviceFeign.deviceCall(deviceReq, token);
log.info("更新结果:{}", JSON.toJSONString(rest));
}
return super.saveAfter(entity, model, context);
}
@Override
protected void deleteBefore(Long[] ids, Context context) throws AppException {
super.deleteBefore(ids, context);
String token = getToken();
DeviceQuery deviceQuery = new DeviceQuery();
deviceQuery.setIdList(Arrays.asList(ids));
List<DeviceEntity> deviceEntities = this.service.find(deviceQuery, context);
for (DeviceEntity entity : deviceEntities) {
DeviceReq deviceReq = new DeviceReq();
deviceReq.setReceiveMethod(DeviceMethodEnum.DEL.getValue());
deviceReq.setDeviceCode(entity.getDeviceCode());
Rest<String> rest = deviceFeign.deviceCall(deviceReq, token);
log.info("删除结果:{}", JSON.toJSONString(rest));
}
}
private String getToken() {
LoginForm loginForm = new LoginForm();
loginForm.setLoginName(loginName);
loginForm.setPassword(password);
Rest<String> rest = deviceFeign.getToken(loginForm);
String token = rest.getData();
return token;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment