Browse Source

添加角色相关的接口,用户信息添加角色信息

pull/151/head
648540858 3 years ago
parent
commit
9e8cab609d
  1. 16
      sql/mysql.sql
  2. 94
      src/main/java/com/genersoft/iot/vmp/conf/SipConfig.java
  3. 2
      src/main/java/com/genersoft/iot/vmp/conf/security/AnonymousAuthenticationEntryPoint.java
  4. 5
      src/main/java/com/genersoft/iot/vmp/conf/security/dto/LoginUser.java
  5. 12
      src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java
  6. 6
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java
  7. 46
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java
  8. 12
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
  9. 2
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java
  10. 6
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/RegisterRequestProcessor.java
  11. 18
      src/main/java/com/genersoft/iot/vmp/service/IRoleService.java
  12. 14
      src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
  13. 41
      src/main/java/com/genersoft/iot/vmp/service/impl/RoleServerImpl.java
  14. 35
      src/main/java/com/genersoft/iot/vmp/storager/dao/RoleMapper.java
  15. 28
      src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java
  16. 50
      src/main/java/com/genersoft/iot/vmp/storager/dao/dto/Role.java
  17. 18
      src/main/java/com/genersoft/iot/vmp/storager/dao/dto/User.java
  18. 8
      src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java
  19. 13
      src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java
  20. 47
      src/main/java/com/genersoft/iot/vmp/vmanager/server/ServerController.java
  21. 101
      src/main/java/com/genersoft/iot/vmp/vmanager/user/RoleController.java
  22. 48
      src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java
  23. 16
      src/main/java/com/genersoft/iot/vmp/web/ApiController.java
  24. 8
      src/main/resources/all-application.yml
  25. 6
      src/main/resources/application-dev.yml
  26. 1
      src/main/resources/banner.txt
  27. BIN
      src/main/resources/wvp.sqlite
  28. 58
      src/test/java/com/genersoft/iot/vmp/service/impl/RoleServiceImplTest.java
  29. 17
      src/test/java/com/genersoft/iot/vmp/service/impl/UserServiceImplTest.java

16
sql/mysql.sql

@ -227,12 +227,22 @@ create table user
username varchar(255) not null, username varchar(255) not null,
password varchar(255) not null, password varchar(255) not null,
roleId int not null, roleId int not null,
create_time varchar(50) not null, createTime varchar(50) not null,
update_time varchar(50) not null updateTime varchar(50) not null
); );
create unique index user_username_uindex create unique index user_username_uindex
on user (username); on user (username);
insert into user (username, password, roleId, create_time, update_time) values ('admin', '21232f297a57a5a743894a0e4a801fc3', '0', '2021-04-13 14:14:57', '2021-04-13 14:14:57'); insert into user (username, password, roleId, createTime, updateTime) values ('admin', '21232f297a57a5a743894a0e4a801fc3', '1', '2021-04-13 14:14:57', '2021-04-13 14:14:57');
create table role (
id int auto_increment
primary key,
name TEXT NOT NULL,
authority TEXT NOT NULL,
createTime varchar(50) not null,
updateTime varchar(50) not null
);
insert into role (id, name, authority, createTime, updateTime) values ('1', 'admin', '0', '2021-04-13 14:14:57', '2021-04-13 14:14:57');

94
src/main/java/com/genersoft/iot/vmp/conf/SipConfig.java

@ -2,71 +2,101 @@ package com.genersoft.iot.vmp.conf;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
@Configuration("sipConfig") @Component
@ConfigurationProperties(prefix = "sip", ignoreInvalidFields = true)
public class SipConfig { public class SipConfig {
@Value("${sip.ip}") private String ip;
private String sipIp;
/** /**
* 默认使用sip.ip * 默认使用 0.0.0.0
*/ */
@Value("${sip.monitor-ip:0.0.0.0}") private String monitorIp = "0.0.0.0";
private String monitorIp;
@Value("${sip.port}") private Integer port;
private Integer sipPort;
@Value("${sip.domain}") private String domain;
private String sipDomain;
@Value("${sip.id}") private String id;
private String sipId;
@Value("${sip.password}") private String password;
private String sipPassword;
@Value("${sip.ptz.speed:50}") Integer ptzSpeed = 50;
Integer speed;
@Value("${sip.keepalive-timeout:180}") Integer keepaliveTimeOut = 180;
Integer keepaliveTimeOut;
@Value("${sip.register-time-interval:60}") Integer registerTimeInterval = 60;
Integer registerTimeInterval;
public void setIp(String ip) {
this.ip = ip;
}
public void setMonitorIp(String monitorIp) {
this.monitorIp = monitorIp;
}
public void setPort(Integer port) {
this.port = port;
}
public void setDomain(String domain) {
this.domain = domain;
}
public void setId(String id) {
this.id = id;
}
public void setPassword(String password) {
this.password = password;
}
public void setPtzSpeed(Integer ptzSpeed) {
this.ptzSpeed = ptzSpeed;
}
public void setKeepaliveTimeOut(Integer keepaliveTimeOut) {
this.keepaliveTimeOut = keepaliveTimeOut;
}
public void setRegisterTimeInterval(Integer registerTimeInterval) {
this.registerTimeInterval = registerTimeInterval;
}
public String getMonitorIp() { public String getMonitorIp() {
return monitorIp; return monitorIp;
} }
public String getSipIp() { public String getIp() {
return sipIp; return ip;
} }
public Integer getSipPort() { public Integer getPort() {
return sipPort; return port;
} }
public String getSipDomain() { public String getDomain() {
return sipDomain; return domain;
} }
public String getSipId() { public String getId() {
return sipId; return id;
} }
public String getSipPassword() { public String getPassword() {
return sipPassword; return password;
} }
public Integer getSpeed() { public Integer getPtzSpeed() {
return speed; return ptzSpeed;
} }
public Integer getKeepaliveTimeOut() { public Integer getKeepaliveTimeOut() {

2
src/main/java/com/genersoft/iot/vmp/conf/security/AnonymousAuthenticationEntryPoint.java

@ -28,8 +28,8 @@ public class AnonymousAuthenticationEntryPoint implements AuthenticationEntryPoi
response.setHeader("Access-Control-Allow-Headers", "token, Accept, Origin, X-Requested-With, Content-Type, Last-Modified"); response.setHeader("Access-Control-Allow-Headers", "token, Accept, Origin, X-Requested-With, Content-Type, Last-Modified");
response.setHeader("Content-type", "application/json;charset=UTF-8"); response.setHeader("Content-type", "application/json;charset=UTF-8");
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("msg", e.getMessage());
jsonObject.put("code", "-1"); jsonObject.put("code", "-1");
jsonObject.put("msg", "请登录后重新请求");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
try { try {
response.getWriter().print(jsonObject.toJSONString()); response.getWriter().print(jsonObject.toJSONString());

5
src/main/java/com/genersoft/iot/vmp/conf/security/dto/LoginUser.java

@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.conf.security.dto; package com.genersoft.iot.vmp.conf.security.dto;
import com.genersoft.iot.vmp.storager.dao.dto.Role;
import com.genersoft.iot.vmp.storager.dao.dto.User; import com.genersoft.iot.vmp.storager.dao.dto.User;
import org.springframework.security.core.CredentialsContainer; import org.springframework.security.core.CredentialsContainer;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
@ -93,8 +94,8 @@ public class LoginUser implements UserDetails, CredentialsContainer {
return user.getId(); return user.getId();
} }
public int getRoleId() { public Role getRole() {
return user.getRoleId(); return user.getRole();
} }

12
src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java

@ -93,15 +93,15 @@ public class SipLayer implements SipListener {
ListeningPoint tcpListeningPoint = null; ListeningPoint tcpListeningPoint = null;
SipProviderImpl tcpSipProvider = null; SipProviderImpl tcpSipProvider = null;
try { try {
tcpListeningPoint = sipStack.createListeningPoint(sipConfig.getMonitorIp(), sipConfig.getSipPort(), "TCP"); tcpListeningPoint = sipStack.createListeningPoint(sipConfig.getMonitorIp(), sipConfig.getPort(), "TCP");
tcpSipProvider = (SipProviderImpl)sipStack.createSipProvider(tcpListeningPoint); tcpSipProvider = (SipProviderImpl)sipStack.createSipProvider(tcpListeningPoint);
tcpSipProvider.addSipListener(this); tcpSipProvider.addSipListener(this);
logger.info("Sip Server TCP 启动成功 port {" + sipConfig.getMonitorIp() + ":" + sipConfig.getSipPort() + "}"); logger.info("Sip Server TCP 启动成功 port {" + sipConfig.getMonitorIp() + ":" + sipConfig.getPort() + "}");
} catch (TransportNotSupportedException e) { } catch (TransportNotSupportedException e) {
e.printStackTrace(); e.printStackTrace();
} catch (InvalidArgumentException e) { } catch (InvalidArgumentException e) {
logger.error("无法使用 [ {}:{} ]作为SIP[ TCP ]服务,可排查: 1. sip.monitor-ip 是否为本机网卡IP; 2. sip.port 是否已被占用" logger.error("无法使用 [ {}:{} ]作为SIP[ TCP ]服务,可排查: 1. sip.monitor-ip 是否为本机网卡IP; 2. sip.port 是否已被占用"
, sipConfig.getMonitorIp(), sipConfig.getSipPort()); , sipConfig.getMonitorIp(), sipConfig.getPort());
} catch (TooManyListenersException e) { } catch (TooManyListenersException e) {
e.printStackTrace(); e.printStackTrace();
} catch (ObjectInUseException e) { } catch (ObjectInUseException e) {
@ -116,7 +116,7 @@ public class SipLayer implements SipListener {
ListeningPoint udpListeningPoint = null; ListeningPoint udpListeningPoint = null;
SipProviderImpl udpSipProvider = null; SipProviderImpl udpSipProvider = null;
try { try {
udpListeningPoint = sipStack.createListeningPoint(sipConfig.getMonitorIp(), sipConfig.getSipPort(), "UDP"); udpListeningPoint = sipStack.createListeningPoint(sipConfig.getMonitorIp(), sipConfig.getPort(), "UDP");
udpSipProvider = (SipProviderImpl)sipStack.createSipProvider(udpListeningPoint); udpSipProvider = (SipProviderImpl)sipStack.createSipProvider(udpListeningPoint);
udpSipProvider.addSipListener(this); udpSipProvider.addSipListener(this);
// udpSipProvider.setAutomaticDialogSupportEnabled(false); // udpSipProvider.setAutomaticDialogSupportEnabled(false);
@ -124,13 +124,13 @@ public class SipLayer implements SipListener {
e.printStackTrace(); e.printStackTrace();
} catch (InvalidArgumentException e) { } catch (InvalidArgumentException e) {
logger.error("无法使用 [ {}:{} ]作为SIP[ UDP ]服务,可排查: 1. sip.monitor-ip 是否为本机网卡IP; 2. sip.port 是否已被占用" logger.error("无法使用 [ {}:{} ]作为SIP[ UDP ]服务,可排查: 1. sip.monitor-ip 是否为本机网卡IP; 2. sip.port 是否已被占用"
, sipConfig.getMonitorIp(), sipConfig.getSipPort()); , sipConfig.getMonitorIp(), sipConfig.getPort());
} catch (TooManyListenersException e) { } catch (TooManyListenersException e) {
e.printStackTrace(); e.printStackTrace();
} catch (ObjectInUseException e) { } catch (ObjectInUseException e) {
e.printStackTrace(); e.printStackTrace();
} }
logger.info("Sip Server UDP 启动成功 port [" + sipConfig.getMonitorIp() + ":" + sipConfig.getSipPort() + "]"); logger.info("Sip Server UDP 启动成功 port [" + sipConfig.getMonitorIp() + ":" + sipConfig.getPort() + "]");
return udpSipProvider; return udpSipProvider;
} }

6
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderPlarformProvider.java

@ -39,13 +39,13 @@ public class SIPRequestHeaderPlarformProvider {
SipURI requestURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP() + ":" + parentPlatform.getServerPort()); SipURI requestURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getServerGBId(), parentPlatform.getServerIP() + ":" + parentPlatform.getServerPort());
// via // via
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>(); ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getSipIp(), sipConfig.getSipPort(), ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getIp(), sipConfig.getPort(),
parentPlatform.getTransport(), viaTag); parentPlatform.getTransport(), viaTag);
viaHeader.setRPort(); viaHeader.setRPort();
viaHeaders.add(viaHeader); viaHeaders.add(viaHeader);
// from // from
SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getDeviceGBId(), SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(parentPlatform.getDeviceGBId(),
sipConfig.getSipIp() + ":" + sipConfig.getSipPort()); sipConfig.getIp() + ":" + sipConfig.getPort());
Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag);
// to // to
@ -75,7 +75,7 @@ public class SIPRequestHeaderPlarformProvider {
public Request createRegisterRequest(@NotNull ParentPlatform platform, long CSeq, String fromTag, String viaTag, CallIdHeader callIdHeader) throws ParseException, InvalidArgumentException, PeerUnavailableException { public Request createRegisterRequest(@NotNull ParentPlatform platform, long CSeq, String fromTag, String viaTag, CallIdHeader callIdHeader) throws ParseException, InvalidArgumentException, PeerUnavailableException {
Request request = null; Request request = null;
String sipAddress = sipConfig.getSipIp() + ":" + sipConfig.getSipPort(); String sipAddress = sipConfig.getIp() + ":" + sipConfig.getPort();
//请求行 //请求行
SipURI requestLine = sipFactory.createAddressFactory().createSipURI(platform.getServerGBId(), SipURI requestLine = sipFactory.createAddressFactory().createSipURI(platform.getServerGBId(),
platform.getServerIP() + ":" + platform.getServerPort()); platform.getServerIP() + ":" + platform.getServerPort());

46
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java

@ -37,16 +37,16 @@ public class SIPRequestHeaderProvider {
SipURI requestURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress()); SipURI requestURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress());
// via // via
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>(); ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getSipIp(), sipConfig.getSipPort(), device.getTransport(), viaTag); ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getIp(), sipConfig.getPort(), device.getTransport(), viaTag);
viaHeader.setRPort(); viaHeader.setRPort();
viaHeaders.add(viaHeader); viaHeaders.add(viaHeader);
// from // from
SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(), SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(),
sipConfig.getSipIp() + ":" + sipConfig.getSipPort()); sipConfig.getIp() + ":" + sipConfig.getPort());
Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag);
// to // to
SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), sipConfig.getSipDomain()); SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), sipConfig.getDomain());
Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, toTag); ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, toTag);
@ -68,16 +68,16 @@ public class SIPRequestHeaderProvider {
SipURI requestLine = sipFactory.createAddressFactory().createSipURI(channelId, device.getHostAddress()); SipURI requestLine = sipFactory.createAddressFactory().createSipURI(channelId, device.getHostAddress());
//via //via
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>(); ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getSipIp(), sipConfig.getSipPort(), device.getTransport(), viaTag); ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getIp(), sipConfig.getPort(), device.getTransport(), viaTag);
viaHeader.setRPort(); viaHeader.setRPort();
viaHeaders.add(viaHeader); viaHeaders.add(viaHeader);
//from //from
SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(),sipConfig.getSipDomain()); SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(),sipConfig.getDomain());
Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记,否则无法创建会话,无法回应ack FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记,否则无法创建会话,无法回应ack
//to //to
SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId,sipConfig.getSipDomain()); SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId,sipConfig.getDomain());
Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress,null); ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress,null);
@ -88,11 +88,11 @@ public class SIPRequestHeaderProvider {
CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(1L, Request.INVITE); CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(1L, Request.INVITE);
request = sipFactory.createMessageFactory().createRequest(requestLine, Request.INVITE, callIdHeader, cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards); request = sipFactory.createMessageFactory().createRequest(requestLine, Request.INVITE, callIdHeader, cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards);
Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(), sipConfig.getSipIp()+":"+sipConfig.getSipPort())); Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort()));
// Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(), device.getHost().getIp()+":"+device.getHost().getPort())); // Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), device.getHost().getIp()+":"+device.getHost().getPort()));
request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
// Subject // Subject
SubjectHeader subjectHeader = sipFactory.createHeaderFactory().createSubjectHeader(String.format("%s:%s,%s:%s", channelId, ssrc, sipConfig.getSipId(), 0)); SubjectHeader subjectHeader = sipFactory.createHeaderFactory().createSubjectHeader(String.format("%s:%s,%s:%s", channelId, ssrc, sipConfig.getId(), 0));
request.addHeader(subjectHeader); request.addHeader(subjectHeader);
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "SDP"); ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "SDP");
request.setContent(content, contentTypeHeader); request.setContent(content, contentTypeHeader);
@ -109,11 +109,11 @@ public class SIPRequestHeaderProvider {
viaHeader.setRPort(); viaHeader.setRPort();
viaHeaders.add(viaHeader); viaHeaders.add(viaHeader);
//from //from
SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(),sipConfig.getSipDomain()); SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(),sipConfig.getDomain());
Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记,否则无法创建会话,无法回应ack FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记,否则无法创建会话,无法回应ack
//to //to
SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId,sipConfig.getSipDomain()); SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId,sipConfig.getDomain());
Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress,null); ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress,null);
@ -124,8 +124,8 @@ public class SIPRequestHeaderProvider {
CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(1L, Request.INVITE); CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(1L, Request.INVITE);
request = sipFactory.createMessageFactory().createRequest(requestLine, Request.INVITE, callIdHeader, cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards); request = sipFactory.createMessageFactory().createRequest(requestLine, Request.INVITE, callIdHeader, cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards);
Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(), sipConfig.getSipIp()+":"+sipConfig.getSipPort())); Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort()));
// Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(), device.getHost().getIp()+":"+device.getHost().getPort())); // Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), device.getHost().getIp()+":"+device.getHost().getPort()));
request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "SDP"); ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "SDP");
@ -139,14 +139,14 @@ public class SIPRequestHeaderProvider {
SipURI requestLine = sipFactory.createAddressFactory().createSipURI(channelId, device.getHostAddress()); SipURI requestLine = sipFactory.createAddressFactory().createSipURI(channelId, device.getHostAddress());
// via // via
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>(); ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getSipIp(), sipConfig.getSipPort(), device.getTransport(), viaTag); ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getIp(), sipConfig.getPort(), device.getTransport(), viaTag);
viaHeaders.add(viaHeader); viaHeaders.add(viaHeader);
//from //from
SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(),sipConfig.getSipDomain()); SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(),sipConfig.getDomain());
Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记,否则无法创建会话,无法回应ack FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记,否则无法创建会话,无法回应ack
//to //to
SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId,sipConfig.getSipDomain()); SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(channelId,sipConfig.getDomain());
Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress,toTag); ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress,toTag);
@ -158,7 +158,7 @@ public class SIPRequestHeaderProvider {
CallIdHeader callIdHeader = sipFactory.createHeaderFactory().createCallIdHeader(callId); CallIdHeader callIdHeader = sipFactory.createHeaderFactory().createCallIdHeader(callId);
request = sipFactory.createMessageFactory().createRequest(requestLine, Request.BYE, callIdHeader, cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards); request = sipFactory.createMessageFactory().createRequest(requestLine, Request.BYE, callIdHeader, cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards);
Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(), sipConfig.getSipIp()+":"+sipConfig.getSipPort())); Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort()));
return request; return request;
} }
@ -169,17 +169,17 @@ public class SIPRequestHeaderProvider {
SipURI requestURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress()); SipURI requestURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress());
// via // via
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>(); ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getSipIp(), sipConfig.getSipPort(), ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getIp(), sipConfig.getPort(),
device.getTransport(), viaTag); device.getTransport(), viaTag);
viaHeader.setRPort(); viaHeader.setRPort();
viaHeaders.add(viaHeader); viaHeaders.add(viaHeader);
// from // from
SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(), SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getId(),
sipConfig.getSipIp() + ":" + sipConfig.getSipPort()); sipConfig.getIp() + ":" + sipConfig.getPort());
Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI); Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag); FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag);
// to // to
SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), sipConfig.getSipDomain()); SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), sipConfig.getDomain());
Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI); Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, toTag); ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, toTag);
@ -192,7 +192,7 @@ public class SIPRequestHeaderProvider {
toHeader, viaHeaders, maxForwards); toHeader, viaHeaders, maxForwards);
Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(), sipConfig.getSipIp()+":"+sipConfig.getSipPort())); Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getId(), sipConfig.getIp()+":"+sipConfig.getPort()));
request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
// Expires // Expires

12
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java

@ -105,7 +105,7 @@ public class SIPCommander implements ISIPCommander {
*/ */
@Override @Override
public boolean ptzdirectCmd(Device device, String channelId, int leftRight, int upDown) { public boolean ptzdirectCmd(Device device, String channelId, int leftRight, int upDown) {
return ptzCmd(device, channelId, leftRight, upDown, 0, sipConfig.getSpeed(), 0); return ptzCmd(device, channelId, leftRight, upDown, 0, sipConfig.getPtzSpeed(), 0);
} }
/** /**
@ -131,7 +131,7 @@ public class SIPCommander implements ISIPCommander {
*/ */
@Override @Override
public boolean ptzZoomCmd(Device device, String channelId, int inOut) { public boolean ptzZoomCmd(Device device, String channelId, int inOut) {
return ptzCmd(device, channelId, 0, 0, inOut, 0, sipConfig.getSpeed()); return ptzCmd(device, channelId, 0, 0, inOut, 0, sipConfig.getPtzSpeed());
} }
/** /**
@ -468,7 +468,7 @@ public class SIPCommander implements ISIPCommander {
StringBuffer content = new StringBuffer(200); StringBuffer content = new StringBuffer(200);
content.append("v=0\r\n"); content.append("v=0\r\n");
content.append("o="+sipConfig.getSipId()+" 0 0 IN IP4 "+sipConfig.getSipIp()+"\r\n"); content.append("o="+sipConfig.getId()+" 0 0 IN IP4 "+sipConfig.getIp()+"\r\n");
content.append("s=Playback\r\n"); content.append("s=Playback\r\n");
content.append("u="+channelId+":0\r\n"); content.append("u="+channelId+":0\r\n");
content.append("c=IN IP4 "+mediaServerItem.getSdpIp()+"\r\n"); content.append("c=IN IP4 "+mediaServerItem.getSdpIp()+"\r\n");
@ -575,7 +575,7 @@ public class SIPCommander implements ISIPCommander {
StringBuffer content = new StringBuffer(200); StringBuffer content = new StringBuffer(200);
content.append("v=0\r\n"); content.append("v=0\r\n");
content.append("o="+sipConfig.getSipId()+" 0 0 IN IP4 "+sipConfig.getSipIp()+"\r\n"); content.append("o="+sipConfig.getId()+" 0 0 IN IP4 "+sipConfig.getIp()+"\r\n");
content.append("s=Download\r\n"); content.append("s=Download\r\n");
content.append("u="+channelId+":0\r\n"); content.append("u="+channelId+":0\r\n");
content.append("c=IN IP4 "+mediaServerItem.getSdpIp()+"\r\n"); content.append("c=IN IP4 "+mediaServerItem.getSdpIp()+"\r\n");
@ -749,7 +749,7 @@ public class SIPCommander implements ISIPCommander {
broadcastXml.append("<Notify>\r\n"); broadcastXml.append("<Notify>\r\n");
broadcastXml.append("<CmdType>Broadcast</CmdType>\r\n"); broadcastXml.append("<CmdType>Broadcast</CmdType>\r\n");
broadcastXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n"); broadcastXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
broadcastXml.append("<SourceID>" + sipConfig.getSipId() + "</SourceID>\r\n"); broadcastXml.append("<SourceID>" + sipConfig.getId() + "</SourceID>\r\n");
broadcastXml.append("<TargetID>" + device.getDeviceId() + "</TargetID>\r\n"); broadcastXml.append("<TargetID>" + device.getDeviceId() + "</TargetID>\r\n");
broadcastXml.append("</Notify>\r\n"); broadcastXml.append("</Notify>\r\n");
@ -774,7 +774,7 @@ public class SIPCommander implements ISIPCommander {
broadcastXml.append("<Notify>\r\n"); broadcastXml.append("<Notify>\r\n");
broadcastXml.append("<CmdType>Broadcast</CmdType>\r\n"); broadcastXml.append("<CmdType>Broadcast</CmdType>\r\n");
broadcastXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n"); broadcastXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
broadcastXml.append("<SourceID>" + sipConfig.getSipId() + "</SourceID>\r\n"); broadcastXml.append("<SourceID>" + sipConfig.getId() + "</SourceID>\r\n");
broadcastXml.append("<TargetID>" + device.getDeviceId() + "</TargetID>\r\n"); broadcastXml.append("<TargetID>" + device.getDeviceId() + "</TargetID>\r\n");
broadcastXml.append("</Notify>\r\n"); broadcastXml.append("</Notify>\r\n");

2
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java

@ -550,7 +550,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
deviceChannel.setStatus(gbStream.isStatus()?1:0); deviceChannel.setStatus(gbStream.isStatus()?1:0);
// deviceChannel.setParentId(parentPlatform.getDeviceGBId()); // deviceChannel.setParentId(parentPlatform.getDeviceGBId());
deviceChannel.setRegisterWay(1); deviceChannel.setRegisterWay(1);
deviceChannel.setCivilCode(cmder.getSipConfig().getSipDomain()); deviceChannel.setCivilCode(cmder.getSipConfig().getDomain());
deviceChannel.setModel("live"); deviceChannel.setModel("live");
deviceChannel.setOwner("wvp-pro"); deviceChannel.setOwner("wvp-pro");
// deviceChannel.setAddress("test"); // deviceChannel.setAddress("test");

6
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/RegisterRequestProcessor.java

@ -79,9 +79,9 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor {
// 校验密码是否正确 // 校验密码是否正确
if (authorhead != null) { if (authorhead != null) {
passwordCorrect = new DigestServerAuthenticationHelper().doAuthenticatePlainTextPassword(request, passwordCorrect = new DigestServerAuthenticationHelper().doAuthenticatePlainTextPassword(request,
sipConfig.getSipPassword()); sipConfig.getPassword());
} }
if (StringUtils.isEmpty(sipConfig.getSipPassword())){ if (StringUtils.isEmpty(sipConfig.getPassword())){
passwordCorrect = true; passwordCorrect = true;
} }
@ -94,7 +94,7 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor {
logger.info("[{}] 密码错误 回复401", requestAddress); logger.info("[{}] 密码错误 回复401", requestAddress);
} }
response = getMessageFactory().createResponse(Response.UNAUTHORIZED, request); response = getMessageFactory().createResponse(Response.UNAUTHORIZED, request);
new DigestServerAuthenticationHelper().generateChallenge(getHeaderFactory(), response, sipConfig.getSipDomain()); new DigestServerAuthenticationHelper().generateChallenge(getHeaderFactory(), response, sipConfig.getDomain());
}else { }else {
if (!passwordCorrect){ if (!passwordCorrect){
// 注册失败 // 注册失败

18
src/main/java/com/genersoft/iot/vmp/service/IRoleService.java

@ -0,0 +1,18 @@
package com.genersoft.iot.vmp.service;
import com.genersoft.iot.vmp.storager.dao.dto.Role;
import java.util.List;
public interface IRoleService {
Role getRoleById(int id);
int add(Role role);
int delete(int id);
List<Role> getAll();
int update(Role role);
}

14
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java

@ -83,7 +83,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
for (MediaServerItem mediaServerItem : mediaServerItemList) { for (MediaServerItem mediaServerItem : mediaServerItemList) {
// 更新 // 更新
if (mediaServerItem.getSsrcConfig() == null) { if (mediaServerItem.getSsrcConfig() == null) {
SsrcConfig ssrcConfig = new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getSipDomain()); SsrcConfig ssrcConfig = new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getDomain());
mediaServerItem.setSsrcConfig(ssrcConfig); mediaServerItem.setSsrcConfig(ssrcConfig);
redisUtil.set(VideoManagerConstants.MEDIA_SERVER_PREFIX + mediaServerItem.getId(), mediaServerItem); redisUtil.set(VideoManagerConstants.MEDIA_SERVER_PREFIX + mediaServerItem.getId(), mediaServerItem);
} }
@ -145,7 +145,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
*/ */
@Override @Override
public void clearRTPServer(MediaServerItem mediaServerItem) { public void clearRTPServer(MediaServerItem mediaServerItem) {
mediaServerItem.setSsrcConfig(new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getSipDomain())); mediaServerItem.setSsrcConfig(new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getDomain()));
redisUtil.zAdd(VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX, mediaServerItem.getId(), 0); redisUtil.zAdd(VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX, mediaServerItem.getId(), 0);
} }
@ -162,7 +162,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
new SsrcConfig( new SsrcConfig(
mediaServerItemInDataBase.getId(), mediaServerItemInDataBase.getId(),
null, null,
sipConfig.getSipDomain() sipConfig.getDomain()
) )
); );
} }
@ -264,12 +264,12 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
if (serverItemInRedis != null) { if (serverItemInRedis != null) {
serverItemFromConfig.setSsrcConfig(serverItemInRedis.getSsrcConfig()); serverItemFromConfig.setSsrcConfig(serverItemInRedis.getSsrcConfig());
}else { }else {
serverItemFromConfig.setSsrcConfig(new SsrcConfig(serverItemFromConfig.getId(), null, sipConfig.getSipDomain())); serverItemFromConfig.setSsrcConfig(new SsrcConfig(serverItemFromConfig.getId(), null, sipConfig.getDomain()));
} }
redisUtil.set(key, serverItemFromConfig); redisUtil.set(key, serverItemFromConfig);
}else { }else {
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItemFromConfig.getId(); String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItemFromConfig.getId();
serverItemFromConfig.setSsrcConfig(new SsrcConfig(serverItemFromConfig.getId(), null, sipConfig.getSipDomain())); serverItemFromConfig.setSsrcConfig(new SsrcConfig(serverItemFromConfig.getId(), null, sipConfig.getDomain()));
redisUtil.set(key, serverItemFromConfig); redisUtil.set(key, serverItemFromConfig);
mediaServerMapper.add(serverItemFromConfig); mediaServerMapper.add(serverItemFromConfig);
} }
@ -279,11 +279,11 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
String now = this.format.format(System.currentTimeMillis()); String now = this.format.format(System.currentTimeMillis());
if (serverItem == null){ if (serverItem == null){
// 一个新的zlm接入wvp // 一个新的zlm接入wvp
serverItem = new MediaServerItem(zlmServerConfig, sipConfig.getSipIp()); serverItem = new MediaServerItem(zlmServerConfig, sipConfig.getIp());
serverItem.setCreateTime(now); serverItem.setCreateTime(now);
serverItem.setUpdateTime(now); serverItem.setUpdateTime(now);
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItem.getId(); String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + serverItem.getId();
serverItem.setSsrcConfig(new SsrcConfig(serverItem.getId(), null, sipConfig.getSipDomain())); serverItem.setSsrcConfig(new SsrcConfig(serverItem.getId(), null, sipConfig.getDomain()));
redisUtil.set(key, serverItem); redisUtil.set(key, serverItem);
// 存入数据库 // 存入数据库
mediaServerMapper.add(serverItem); mediaServerMapper.add(serverItem);

41
src/main/java/com/genersoft/iot/vmp/service/impl/RoleServerImpl.java

@ -0,0 +1,41 @@
package com.genersoft.iot.vmp.service.impl;
import com.genersoft.iot.vmp.service.IRoleService;
import com.genersoft.iot.vmp.storager.dao.RoleMapper;
import com.genersoft.iot.vmp.storager.dao.dto.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class RoleServerImpl implements IRoleService {
@Autowired
private RoleMapper roleMapper;
@Override
public Role getRoleById(int id) {
return roleMapper.selectById(id);
}
@Override
public int add(Role role) {
return roleMapper.add(role);
}
@Override
public int delete(int id) {
return roleMapper.delete(id);
}
@Override
public List<Role> getAll() {
return roleMapper.selectAll();
}
@Override
public int update(Role role) {
return roleMapper.update(role);
}
}

35
src/main/java/com/genersoft/iot/vmp/storager/dao/RoleMapper.java

@ -0,0 +1,35 @@
package com.genersoft.iot.vmp.storager.dao;
import com.genersoft.iot.vmp.storager.dao.dto.Role;
import com.genersoft.iot.vmp.storager.dao.dto.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import java.util.List;
@Mapper
@Repository
public interface RoleMapper {
@Insert("INSERT INTO role (name, authority, createTime, updateTime) VALUES" +
"('${name}', '${authority}', '${createTime}', '${updateTime}')")
int add(Role role);
@Update(value = {" <script>" +
"UPDATE role " +
"SET updateTime='${updateTime}' " +
"<if test=\"name != null\">, name='${name}'</if>" +
"<if test=\"authority != null\">, authority='${authority}'</if>" +
"WHERE id != 1 and id=#{id}" +
" </script>"})
int update(Role role);
@Delete("DELETE FROM role WHERE id != 1 and id=#{id}")
int delete(int id);
@Select("select * FROM role WHERE id=#{id}")
Role selectById(int id);
@Select("select * FROM role")
List<Role> selectAll();
}

28
src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java

@ -10,32 +10,42 @@ import java.util.List;
@Repository @Repository
public interface UserMapper { public interface UserMapper {
@Insert("INSERT INTO user (username, password, roleId, create_time, update_time) VALUES" + @Insert("INSERT INTO user (username, password, roleId, createTime, updateTime) VALUES" +
"('${username}', '${password}', '${roleId}', '${createTime}', '${updateTime}')") "('${username}', '${password}', '${role.id}', '${createTime}', '${updateTime}')")
int add(User user); int add(User user);
@Update(value = {" <script>" + @Update(value = {" <script>" +
"UPDATE user " + "UPDATE user " +
"SET update_time='${updateTime}' " + "SET updateTime='${updateTime}' " +
"<if test=\"roleId != null\">, roleId='${roleId}'</if>" + "<if test=\"role != null\">, roleId='${role.id}'</if>" +
"<if test=\"password != null\">, password='${password}'</if>" + "<if test=\"password != null\">, password='${password}'</if>" +
"<if test=\"username != null\">, username='${username}'</if>" + "<if test=\"username != null\">, username='${username}'</if>" +
"WHERE id=#{id}" + "WHERE id=#{id}" +
" </script>"}) " </script>"})
int update(User user); int update(User user);
@Delete("DELETE FROM user WHERE id=#{id}") @Delete("DELETE FROM user WHERE id != 1 and id=#{id}")
int delete(int id); int delete(int id);
@Select("select * FROM user WHERE username=#{username} AND password=#{password}") @Select("select user.*, role.id roleID, role.name roleName, role.authority roleAuthority , role.createTime roleCreateTime , role.updateTime roleUpdateTime FROM user, role WHERE user.roleId=role.id and user.username=#{username} AND user.password=#{password}")
@Results(id = "roleMap", value = {
@Result(column = "roleID", property = "role.id"),
@Result(column = "roleName", property = "role.name"),
@Result(column = "roleAuthority", property = "role.authority"),
@Result(column = "roleCreateTime", property = "role.createTime"),
@Result(column = "roleUpdateTime", property = "role.updateTime")
})
User select(String username, String password); User select(String username, String password);
@Select("select * FROM user WHERE id=#{id}") @Select("select user.*, role.id roleID, role.name roleName, role.authority roleAuthority, role.createTime roleCreateTime , role.updateTime roleUpdateTime FROM user, role WHERE user.roleId=role.id and user.id=#{id}")
@ResultMap(value="roleMap")
User selectById(int id); User selectById(int id);
@Select("select * FROM user WHERE username=#{username}") @Select("select user.*, role.id roleID, role.name roleName, role.authority roleAuthority, role.createTime roleCreateTime , role.updateTime roleUpdateTime FROM user, role WHERE user.roleId=role.id and username=#{username}")
@ResultMap(value="roleMap")
User getUserByUsername(String username); User getUserByUsername(String username);
@Select("select * FROM user") @Select("select user.*, role.id roleID, role.name roleName, role.authority roleAuthority, role.createTime roleCreateTime , role.updateTime roleUpdateTime FROM user, role WHERE user.roleId=role.id")
@ResultMap(value="roleMap")
List<User> selectAll(); List<User> selectAll();
} }

50
src/main/java/com/genersoft/iot/vmp/storager/dao/dto/Role.java

@ -0,0 +1,50 @@
package com.genersoft.iot.vmp.storager.dao.dto;
public class Role {
private int id;
private String name;
private String authority;
private String createTime;
private String updateTime;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthority() {
return authority;
}
public void setAuthority(String authority) {
this.authority = authority;
}
public String getCreateTime() {
return createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
public String getUpdateTime() {
return updateTime;
}
public void setUpdateTime(String updateTime) {
this.updateTime = updateTime;
}
}

18
src/main/java/com/genersoft/iot/vmp/storager/dao/dto/User.java

@ -7,7 +7,7 @@ public class User {
private String password; private String password;
private String createTime; private String createTime;
private String updateTime; private String updateTime;
private int roleId; private Role role;
public int getId() { public int getId() {
return id; return id;
@ -41,14 +41,6 @@ public class User {
this.createTime = createTime; this.createTime = createTime;
} }
public int getRoleId() {
return roleId;
}
public void setRoleId(int roleId) {
this.roleId = roleId;
}
public String getUpdateTime() { public String getUpdateTime() {
return updateTime; return updateTime;
} }
@ -56,4 +48,12 @@ public class User {
public void setUpdateTime(String updateTime) { public void setUpdateTime(String updateTime) {
this.updateTime = updateTime; this.updateTime = updateTime;
} }
public Role getRole() {
return role;
}
public void setRole(Role role) {
this.role = role;
}
} }

8
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java

@ -52,10 +52,10 @@ public class PlatformController {
@GetMapping("/server_config") @GetMapping("/server_config")
public ResponseEntity<JSONObject> serverConfig() { public ResponseEntity<JSONObject> serverConfig() {
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
result.put("deviceIp", sipConfig.getSipIp()); result.put("deviceIp", sipConfig.getIp());
result.put("devicePort", sipConfig.getSipPort()); result.put("devicePort", sipConfig.getPort());
result.put("username", sipConfig.getSipId()); result.put("username", sipConfig.getId());
result.put("password", sipConfig.getSipPassword()); result.put("password", sipConfig.getPassword());
return new ResponseEntity<>(result, HttpStatus.OK); return new ResponseEntity<>(result, HttpStatus.OK);
} }

13
src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java

@ -1,5 +1,7 @@
package com.genersoft.iot.vmp.vmanager.log; package com.genersoft.iot.vmp.vmanager.log;
import com.genersoft.iot.vmp.conf.UserSetup;
import com.genersoft.iot.vmp.media.zlm.ZLMRunner;
import com.genersoft.iot.vmp.service.ILogService; import com.genersoft.iot.vmp.service.ILogService;
import com.genersoft.iot.vmp.storager.dao.dto.LogDto; import com.genersoft.iot.vmp.storager.dao.dto.LogDto;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
@ -8,6 +10,8 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -23,9 +27,14 @@ import java.text.SimpleDateFormat;
@RequestMapping("/api/log") @RequestMapping("/api/log")
public class LogController { public class LogController {
private final static Logger logger = LoggerFactory.getLogger(LogController.class);
@Autowired @Autowired
private ILogService logService; private ILogService logService;
@Autowired
private UserSetup userSetup;
private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/** /**
@ -60,7 +69,9 @@ public class LogController {
if (StringUtils.isEmpty(query)) query = null; if (StringUtils.isEmpty(query)) query = null;
if (StringUtils.isEmpty(startTime)) startTime = null; if (StringUtils.isEmpty(startTime)) startTime = null;
if (StringUtils.isEmpty(endTime)) endTime = null; if (StringUtils.isEmpty(endTime)) endTime = null;
if (!userSetup.getLogInDatebase()) {
logger.warn("自动记录日志功能已关闭,查询结果可能不完整。");
}
try { try {
if (startTime != null) format.parse(startTime); if (startTime != null) format.parse(startTime);

47
src/main/java/com/genersoft/iot/vmp/vmanager/server/ServerController.java

@ -1,7 +1,11 @@
package com.genersoft.iot.vmp.vmanager.server; package com.genersoft.iot.vmp.vmanager.server;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.VManageBootstrap; import com.genersoft.iot.vmp.VManageBootstrap;
import com.genersoft.iot.vmp.common.VersionPo; import com.genersoft.iot.vmp.common.VersionPo;
import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.conf.UserSetup;
import com.genersoft.iot.vmp.conf.VersionInfo; import com.genersoft.iot.vmp.conf.VersionInfo;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import com.genersoft.iot.vmp.service.IMediaServerService; import com.genersoft.iot.vmp.service.IMediaServerService;
@ -9,9 +13,13 @@ import com.genersoft.iot.vmp.utils.SpringBeanFactory;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import gov.nist.javax.sip.SipStackImpl; import gov.nist.javax.sip.SipStackImpl;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.sip.ListeningPoint; import javax.sip.ListeningPoint;
@ -36,6 +44,15 @@ public class ServerController {
@Autowired @Autowired
VersionInfo versionInfo; VersionInfo versionInfo;
@Autowired
SipConfig sipConfig;
@Autowired
UserSetup userSetup;
@Value("${server.port}")
private int serverPort;
@ApiOperation("流媒体服务列表") @ApiOperation("流媒体服务列表")
@GetMapping(value = "/media_server/list") @GetMapping(value = "/media_server/list")
@ -113,4 +130,34 @@ public class ServerController {
result.setData(versionInfo.getVersion()); result.setData(versionInfo.getVersion());
return result; return result;
} }
@ApiOperation("配置信息")
@GetMapping(value = "/config")
@ApiImplicitParams({
@ApiImplicitParam(name="type", value = "配置类型(sip, base)", dataTypeClass = String.class),
})
@ResponseBody
public WVPResult<JSONObject> getVersion(String type){
WVPResult<JSONObject> result = new WVPResult<>();
result.setCode(0);
result.setMsg("success");
JSONObject jsonObject = new JSONObject();
jsonObject.put("server.port", serverPort);
if (StringUtils.isEmpty(type)) {
jsonObject.put("sip", JSON.toJSON(sipConfig));
jsonObject.put("base", JSON.toJSON(userSetup));
}else {
switch (type){
case "sip":
jsonObject.put("sip", sipConfig);
break;
case "base":
jsonObject.put("base", userSetup);
break;
}
}
result.setData(jsonObject);
return result;
}
} }

101
src/main/java/com/genersoft/iot/vmp/vmanager/user/RoleController.java

@ -0,0 +1,101 @@
package com.genersoft.iot.vmp.vmanager.user;
import com.genersoft.iot.vmp.conf.security.SecurityUtils;
import com.genersoft.iot.vmp.service.IRoleService;
import com.genersoft.iot.vmp.service.IUserService;
import com.genersoft.iot.vmp.storager.dao.dto.Role;
import com.genersoft.iot.vmp.storager.dao.dto.User;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.text.SimpleDateFormat;
import java.util.List;
@Api(tags = "角色管理")
@CrossOrigin
@RestController
@RequestMapping("/api/role")
public class RoleController {
@Autowired
private IRoleService roleService;
private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@ApiOperation("添加角色")
@ApiImplicitParams({
@ApiImplicitParam(name = "name", required = true, value = "角色名", dataTypeClass = String.class),
@ApiImplicitParam(name = "authority", required = true, value = "权限(自行定义内容,目前未使用)", dataTypeClass = String.class),
})
@PostMapping("/add")
public ResponseEntity<WVPResult<Integer>> add(@RequestParam String name,
@RequestParam(required = false) String authority){
WVPResult<Integer> result = new WVPResult<>();
// 获取当前登录用户id
int currenRoleId = SecurityUtils.getUserInfo().getRole().getId();
if (currenRoleId != 1) {
// 只用角色id为1才可以删除和添加用户
result.setCode(-1);
result.setMsg("用户无权限");
return new ResponseEntity<>(result, HttpStatus.FORBIDDEN);
}
Role role = new Role();
role.setName(name);
role.setAuthority(authority);
role.setCreateTime(format.format(System.currentTimeMillis()));
role.setUpdateTime(format.format(System.currentTimeMillis()));
int addResult = roleService.add(role);
result.setCode(addResult > 0 ? 0 : -1);
result.setMsg(addResult > 0 ? "success" : "fail");
result.setData(addResult);
return new ResponseEntity<>(result, HttpStatus.OK);
}
@ApiOperation("删除角色")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", required = true, value = "用户Id", dataTypeClass = Integer.class),
})
@DeleteMapping("/delete")
public ResponseEntity<WVPResult<String>> delete(@RequestParam Integer id){
// 获取当前登录用户id
int currenRoleId = SecurityUtils.getUserInfo().getRole().getId();
WVPResult<String> result = new WVPResult<>();
if (currenRoleId != 1) {
// 只用角色id为0才可以删除和添加用户
result.setCode(-1);
result.setMsg("用户无权限");
return new ResponseEntity<>(result, HttpStatus.FORBIDDEN);
}
int deleteResult = roleService.delete(id);
result.setCode(deleteResult>0? 0 : -1);
result.setMsg(deleteResult>0? "success" : "fail");
return new ResponseEntity<>(result, HttpStatus.OK);
}
@ApiOperation("查询角色")
@ApiImplicitParams({})
@GetMapping("/all")
public ResponseEntity<WVPResult<List<Role>>> all(){
// 获取当前登录用户id
List<Role> allRoles = roleService.getAll();
WVPResult<List<Role>> result = new WVPResult<>();
result.setCode(0);
result.setMsg("success");
result.setData(allRoles);
return new ResponseEntity<>(result, HttpStatus.OK);
}
}

48
src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java

@ -2,7 +2,9 @@ package com.genersoft.iot.vmp.vmanager.user;
import com.genersoft.iot.vmp.conf.security.SecurityUtils; import com.genersoft.iot.vmp.conf.security.SecurityUtils;
import com.genersoft.iot.vmp.conf.security.dto.LoginUser; import com.genersoft.iot.vmp.conf.security.dto.LoginUser;
import com.genersoft.iot.vmp.service.IRoleService;
import com.genersoft.iot.vmp.service.IUserService; import com.genersoft.iot.vmp.service.IUserService;
import com.genersoft.iot.vmp.storager.dao.dto.Role;
import com.genersoft.iot.vmp.storager.dao.dto.User; import com.genersoft.iot.vmp.storager.dao.dto.User;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -14,6 +16,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.util.DigestUtils; import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.security.sasl.AuthenticationException; import javax.security.sasl.AuthenticationException;
@ -32,6 +35,9 @@ public class UserController {
@Autowired @Autowired
private IUserService userService; private IUserService userService;
@Autowired
private IRoleService roleService;
private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@ApiOperation("登录") @ApiOperation("登录")
@ -97,21 +103,38 @@ public class UserController {
@PostMapping("/add") @PostMapping("/add")
public ResponseEntity<WVPResult<Integer>> add(@RequestParam String username, public ResponseEntity<WVPResult<Integer>> add(@RequestParam String username,
@RequestParam String password, @RequestParam String password,
@RequestParam int roleId){ @RequestParam Integer roleId){
WVPResult<Integer> result = new WVPResult<>();
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password) || roleId == null) {
result.setCode(-1);
result.setMsg("参数不可为空");
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
}
// 获取当前登录用户id // 获取当前登录用户id
int currenRoleId = SecurityUtils.getUserInfo().getRoleId(); int currenRoleId = SecurityUtils.getUserInfo().getRole().getId();
if (currenRoleId != 0) { if (currenRoleId != 1) {
// 只用角色id为0才可以删除和添加用户 // 只用角色id为1才可以删除和添加用户
return new ResponseEntity<>(null, HttpStatus.FORBIDDEN); result.setCode(-1);
result.setMsg("用户无权限");
return new ResponseEntity<>(result, HttpStatus.FORBIDDEN);
} }
User user = new User(); User user = new User();
user.setUsername(username); user.setUsername(username);
user.setPassword(DigestUtils.md5DigestAsHex(password.getBytes())); user.setPassword(DigestUtils.md5DigestAsHex(password.getBytes()));
user.setRoleId(roleId);
Role role = roleService.getRoleById(roleId);
if (role == null) {
result.setCode(-1);
result.setMsg("roleId is not found");
// 角色不存在
return new ResponseEntity<>(result, HttpStatus.OK);
}
user.setRole(role);
user.setCreateTime(format.format(System.currentTimeMillis())); user.setCreateTime(format.format(System.currentTimeMillis()));
user.setUpdateTime(format.format(System.currentTimeMillis())); user.setUpdateTime(format.format(System.currentTimeMillis()));
int addResult = userService.addUser(user); int addResult = userService.addUser(user);
WVPResult<Integer> result = new WVPResult<>();
result.setCode(addResult > 0 ? 0 : -1); result.setCode(addResult > 0 ? 0 : -1);
result.setMsg(addResult > 0 ? "success" : "fail"); result.setMsg(addResult > 0 ? "success" : "fail");
result.setData(addResult); result.setData(addResult);
@ -125,13 +148,16 @@ public class UserController {
@DeleteMapping("/delete") @DeleteMapping("/delete")
public ResponseEntity<WVPResult<String>> delete(@RequestParam Integer id){ public ResponseEntity<WVPResult<String>> delete(@RequestParam Integer id){
// 获取当前登录用户id // 获取当前登录用户id
int currenRoleId = SecurityUtils.getUserInfo().getRoleId(); int currenRoleId = SecurityUtils.getUserInfo().getRole().getId();
if (currenRoleId != 0) { WVPResult<String> result = new WVPResult<>();
if (currenRoleId != 1) {
// 只用角色id为0才可以删除和添加用户 // 只用角色id为0才可以删除和添加用户
return new ResponseEntity<>(null, HttpStatus.FORBIDDEN); result.setCode(-1);
result.setMsg("用户无权限");
return new ResponseEntity<>(result, HttpStatus.FORBIDDEN);
} }
int deleteResult = userService.deleteUser(id); int deleteResult = userService.deleteUser(id);
WVPResult<String> result = new WVPResult<>();
result.setCode(deleteResult>0? 0 : -1); result.setCode(deleteResult>0? 0 : -1);
result.setMsg(deleteResult>0? "success" : "fail"); result.setMsg(deleteResult>0? "success" : "fail");
return new ResponseEntity<>(result, HttpStatus.OK); return new ResponseEntity<>(result, HttpStatus.OK);

16
src/main/java/com/genersoft/iot/vmp/web/ApiController.java

@ -38,10 +38,10 @@ public class ApiController {
result.put("ServerTime","2020-09-02 17:11"); result.put("ServerTime","2020-09-02 17:11");
result.put("StartUpTime","2020-09-02 17:11"); result.put("StartUpTime","2020-09-02 17:11");
result.put("Server",""); result.put("Server","");
result.put("SIPSerial", sipConfig.getSipId()); result.put("SIPSerial", sipConfig.getId());
result.put("SIPRealm", sipConfig.getSipDomain()); result.put("SIPRealm", sipConfig.getDomain());
result.put("SIPHost", sipConfig.getSipIp()); result.put("SIPHost", sipConfig.getIp());
result.put("SIPPort", sipConfig.getSipPort()); result.put("SIPPort", sipConfig.getPort());
result.put("ChannelCount","1000"); result.put("ChannelCount","1000");
result.put("VersionType",""); result.put("VersionType","");
result.put("LogoMiniText",""); result.put("LogoMiniText","");
@ -65,10 +65,10 @@ public class ApiController {
// result.put("ServerTime","2020-09-02 17:11"); // result.put("ServerTime","2020-09-02 17:11");
// result.put("StartUpTime","2020-09-02 17:11"); // result.put("StartUpTime","2020-09-02 17:11");
// result.put("Server",""); // result.put("Server","");
// result.put("SIPSerial", sipConfig.getSipId()); // result.put("SIPSerial", sipConfig.getId());
// result.put("SIPRealm", sipConfig.getSipDomain()); // result.put("SIPRealm", sipConfig.getDomain());
// result.put("SIPHost", sipConfig.getSipIp()); // result.put("SIPHost", sipConfig.getIp());
// result.put("SIPPort", sipConfig.getSipPort()); // result.put("SIPPort", sipConfig.getPort());
// result.put("ChannelCount","1000"); // result.put("ChannelCount","1000");
// result.put("VersionType",""); // result.put("VersionType","");
// result.put("LogoMiniText",""); // result.put("LogoMiniText","");

8
src/main/resources/all-application.yml

@ -76,6 +76,8 @@ sip:
keepalive-timeout: 180 keepalive-timeout: 180
# [可选] 国标级联注册失败,再次发起注册的时间间隔。 默认60秒 # [可选] 国标级联注册失败,再次发起注册的时间间隔。 默认60秒
register-time-interval: 60 register-time-interval: 60
# [可选] 云台控制速度
ptz-speed: 50
# TODO [可选] 收到心跳后自动上线, 重启服务后会将所有设备置为离线,默认false,等待注册后上线。设置为true则收到心跳设置为上线。 # TODO [可选] 收到心跳后自动上线, 重启服务后会将所有设备置为离线,默认false,等待注册后上线。设置为true则收到心跳设置为上线。
# keepalliveToOnline: false # keepalliveToOnline: false
@ -156,3 +158,9 @@ user-settings:
# 在线文档: swagger-ui(生产环境建议关闭) # 在线文档: swagger-ui(生产环境建议关闭)
swagger-ui: swagger-ui:
enabled: true enabled: true
# 版本信息, 不需修改
version:
version: "@project.version@"
description: "@project.description@"
artifact-id: "@project.artifactId@"

6
src/main/resources/application-dev.yml

@ -86,3 +86,9 @@ user-settings:
# 在线文档: swagger-ui(生产环境建议关闭) # 在线文档: swagger-ui(生产环境建议关闭)
swagger-ui: swagger-ui:
enabled: true enabled: true
# 版本信息, 不需修改
version:
version: "@project.version@"
description: "@project.description@"
artifact-id: "@project.artifactId@"

1
src/main/resources/banner.txt

@ -6,3 +6,4 @@
\ \____________\ \__/ / \ \__\ \ \__\ \ \__\\ _\\ \_______\ \ \____________\ \__/ / \ \__\ \ \__\ \ \__\\ _\\ \_______\
\|____________|\|__|/ \|__| \|__| \|__|\|__|\|_______| \|____________|\|__|/ \|__| \|__| \|__|\|__|\|_______|
版本:${version.version}

BIN
src/main/resources/wvp.sqlite

Binary file not shown.

58
src/test/java/com/genersoft/iot/vmp/service/impl/RoleServiceImplTest.java

@ -0,0 +1,58 @@
package com.genersoft.iot.vmp.service.impl;
import com.genersoft.iot.vmp.service.IRoleService;
import com.genersoft.iot.vmp.service.IUserService;
import com.genersoft.iot.vmp.storager.dao.dto.Role;
import com.genersoft.iot.vmp.storager.dao.dto.User;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.List;
@SpringBootTest
@RunWith(SpringRunner.class)
class RoleServiceImplTest {
@Resource
private IRoleService roleService;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@org.junit.jupiter.api.Test
void getAllUser() {
List<Role> all = roleService.getAll();
Role roleById = roleService.getRoleById(1);
System.out.println();
}
@org.junit.jupiter.api.Test
void add() {
for (int i = 0; i < 10; i++) {
Role role = new Role();
role.setName("test+" + i);
role.setAuthority("adadadda");
role.setCreateTime(format.format(System.currentTimeMillis()));
role.setUpdateTime(format.format(System.currentTimeMillis()));
roleService.add(role);
}
}
@org.junit.jupiter.api.Test
void delete() {
roleService.delete(20);
}
@org.junit.jupiter.api.Test
void update() {
Role role = new Role();
role.setId(21);
role.setName("TTTTTT");
role.setAuthority("adadadda");
roleService.update(role);
}
}

17
src/test/java/com/genersoft/iot/vmp/service/impl/UserServiceImplTest.java

@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.service.impl;
import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm; import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
import com.genersoft.iot.vmp.service.IDeviceAlarmService; import com.genersoft.iot.vmp.service.IDeviceAlarmService;
import com.genersoft.iot.vmp.service.IUserService; import com.genersoft.iot.vmp.service.IUserService;
import com.genersoft.iot.vmp.storager.dao.dto.Role;
import com.genersoft.iot.vmp.storager.dao.dto.User; import com.genersoft.iot.vmp.storager.dao.dto.User;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
@ -11,6 +12,7 @@ import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List;
@SpringBootTest @SpringBootTest
@ -24,7 +26,11 @@ class UserServiceImplTest {
@org.junit.jupiter.api.Test @org.junit.jupiter.api.Test
void getAllUser() { void getAllUser() {
List<User> allUsers = userService.getAllUsers();
System.out.println(userService.getAllUsers().size()); System.out.println(userService.getAllUsers().size());
User admin = userService.getUser("admin", "21232f297a57a5a743894a0e4a801fc3");
User admin1 = userService.getUserByUsername("admin");
System.out.println(12);
} }
@ -34,7 +40,10 @@ class UserServiceImplTest {
User user = new User(); User user = new User();
user.setUsername("admin_" + i); user.setUsername("admin_" + i);
user.setPassword("admin_password_" + i); user.setPassword("admin_password_" + i);
user.setRoleId((int)(Math.random()*4 + 1));
Role role = new Role();
role.setId(1);
user.setRole(role);
user.setCreateTime(format.format(System.currentTimeMillis())); user.setCreateTime(format.format(System.currentTimeMillis()));
user.setUpdateTime(format.format(System.currentTimeMillis())); user.setUpdateTime(format.format(System.currentTimeMillis()));
userService.addUser(user); userService.addUser(user);
@ -49,10 +58,12 @@ class UserServiceImplTest {
@org.junit.jupiter.api.Test @org.junit.jupiter.api.Test
void update() { void update() {
User user = new User(); User user = new User();
user.setId(1003); user.setId(11);
user.setUsername("update" ); user.setUsername("update" );
user.setPassword("update"); user.setPassword("update");
user.setRoleId((int)(Math.random()*4 + 1)); Role role = new Role();
role.setId(2);
user.setRole(role);
user.setUpdateTime(format.format(System.currentTimeMillis())); user.setUpdateTime(format.format(System.currentTimeMillis()));
userService.updateUsers(user); userService.updateUsers(user);
} }

Loading…
Cancel
Save