系统需要授权才能使用

master
yiming 3 years ago
parent 1acb78e77f
commit f94adbc2b9

1
.gitignore vendored

@ -32,3 +32,4 @@ target
/modules/modules.iml /modules/modules.iml
/modules/filter/filter.iml /modules/filter/filter.iml
/modules/common/common.iml /modules/common/common.iml
lp.key

@ -2,11 +2,4 @@ package com.leaper.filter;
public interface FilterConstance { public interface FilterConstance {
String HEADER = "token";
String JWT_KEY = "zhehekeji";
String SESSION_PREFIX = "session:";
Long SESSION_EXPIRE = 10800l;
} }

@ -0,0 +1,69 @@
package com.leaper.filter.aspect;
import com.leaper.common.util.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.Scanner;
@Slf4j
public class LPLicense {
private static LocalDateTime lastUpdate = null;
private static String lic_str = null;
private static String lic_path = "./lp.lic";
private static String key_path = "./lp.key";
public static void createLicKeyIfNotExist(){
File file = new File(key_path);
if(!file.exists()){
try {
Process process = Runtime.getRuntime().exec(
new String[] { "wmic", "cpu", "get", "ProcessorId" });
process.getOutputStream().close();
Scanner sc = new Scanner(process.getInputStream());
String property = sc.next();
String cpu = sc.next();
FileUtil.save(cpu,key_path);
} catch (IOException e) {
e.printStackTrace();
log.error("createLicKeyIfNotExist error:{}",e);
}
}
}
public static String getLic(){
//每小时读取一次lic文件
if(lastUpdate == null || LocalDateTime.now().toLocalTime().getHour() != lastUpdate.toLocalTime().getHour()){
lastUpdate = LocalDateTime.now();
lic_str = FileUtil.getText(lic_path);
}
return lic_str;
}
public static boolean checkLic(String pathStr){
//todo 检测
return true;
}
public static boolean checkLic(){
String licStr = getLic();
if(StringUtils.isEmpty(licStr)){
return false;
}
return checkLic(licStr);
}
public static void main(String[] args) {
createLicKeyIfNotExist();
}
}

@ -0,0 +1,25 @@
package com.leaper.filter.aspect;
import com.leaper.filter.pojo.LicenseHandler;
import com.zhehekeji.core.util.Assert;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
@Aspect
@Component
@Slf4j
public class LicenseAspect {
/**
* leaper..*.controller
* leaper controller
*
* @param
*/
@Before("execution(public * com.leaper..*.controller.*.*(..))")
public void handler(){
Assert.isTrue(LPLicense.checkLic(),"未获取授权请将C:\\hzleaper_auto_install\\logistics_package\\lp.key发送给授权人员");
}
}

@ -1,70 +0,0 @@
package com.leaper.filter.aspect;
import com.alibaba.fastjson.JSONObject;
import com.leaper.common.util.HttpUtil;
import com.leaper.filter.FilterConstance;
import com.zhehekeji.core.pojo.HttpStatus;
import com.zhehekeji.core.pojo.Result;
import com.zhehekeji.core.util.Assert;
import com.leaper.filter.pojo.CurrentUser;
import com.leaper.filter.pojo.SessionHandler;
import com.leaper.filter.util.CurrentUserUtil;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
/**
* @Description Session
* @Author wangyiming1031@aliyun.com
* @Date 2019/10/28 19:26
**/
@Aspect
@Component
@Slf4j
public class SessionAspect {
@Value("${zhehe.filter.enable}")
private Boolean enable;
@Value("${userUrl}")
private String userUrl;
/**
* leaper..*.controller
* leaper controller
*
* @param sessionHandler
*/
@Before("execution(public * com.leaper..*.controller.*.*(..))&&@annotation(sessionHandler)")
public void handler(SessionHandler sessionHandler){
if(!enable){
return;
}
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String token = request.getHeader(FilterConstance.HEADER);
CurrentUser currentUser = null;
try {
String res = HttpUtil.token(userUrl+"/api/account/checkToken",token);
Result currentUserResult = JSONObject.parseObject(res,Result.class);
if(currentUserResult != null && currentUserResult.getCode() == 200){
currentUser = JSONObject.parseObject(JSONObject.toJSONString(currentUserResult.getData()),CurrentUser.class);
}
} catch (IOException e) {
e.printStackTrace();
}
if (sessionHandler.login()) {
Assert.isTrue(currentUser != null, HttpStatus.UNAUTHORIZED.getCode(), HttpStatus.UNAUTHORIZED.getReasonPhrase());
}
if (sessionHandler.auth()) {
//todo 权限检验
}
CurrentUserUtil.setCurrentUser(currentUser);
}
}

@ -5,18 +5,10 @@ import java.lang.annotation.*;
@Target(ElementType.METHOD) @Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Documented @Documented
public @interface SessionHandler { public @interface LicenseHandler {
String value() default ""; String value() default "";
UserType userType() default UserType.USER;
/**
*
* @return true: false:
*/
boolean login() default true;
/** /**
* *
* @return true: false: * @return true: false:

@ -1,30 +0,0 @@
package com.leaper.filter.util;
import com.leaper.filter.pojo.CurrentUser;
/**
* @Description 线
* @Author wangyiming1031@aliyun.com
* @Date 2019/10/28 19:22
**/
public class CurrentUserUtil {
private static ThreadLocal<CurrentUser> currentUser = new ThreadLocal<>();
/**
*
*
* @return
*/
public static CurrentUser getCurrentUser() {
return currentUser.get();
}
public static void setCurrentUser(CurrentUser user) {
currentUser.set(user);
}
public static void delCurrentUser() {
currentUser.remove();
}
}

@ -1,85 +0,0 @@
package com.leaper.filter.util;
import com.alibaba.fastjson.JSONObject;
import com.leaper.filter.FilterConstance;
import com.leaper.filter.pojo.CurrentUser;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
/**
* @Description JWTUtil
* @Author wangyiming1031@aliyun.com
* @Date 2019/10/28 19:11
**/
public class JwtUtil {
/**
* JWT
*
* @return
*/
private static String createJWT(CurrentUser currentUser) {
String userJson = JSONObject.toJSONString(currentUser);
JwtBuilder builder = Jwts.builder()
.setSubject(userJson)
.setIssuedAt(new Date())
.signWith(SignatureAlgorithm.HS256, FilterConstance.JWT_KEY);
return builder.compact();
}
/**
* JWT
* jwt
* @param jwtStr
* @return
*/
public static Claims parseJWT(String jwtStr) {
return Jwts.parser()
.setSigningKey(FilterConstance.JWT_KEY)
.parseClaimsJws(jwtStr)
.getBody();
}
/**
*
*
* @param request
* @return
*/
public static CurrentUser getUser(HttpServletRequest request) {
String token = getToken(request);
Claims claims;
try {
claims = parseJWT(token);
} catch (Exception e) {
return null;
}
String json = claims.getSubject();
CurrentUser userInfo = JSONObject.parseObject(json, CurrentUser.class);
return userInfo;
}
private static String getToken(HttpServletRequest request) {
return request.getHeader(FilterConstance.HEADER);
}
/**
* jwt,jwt
* header
* @param response
* @param currentUser
* @return
*/
public static String createTokenAndHeader(HttpServletResponse response,CurrentUser currentUser){
String jwt = createJWT(currentUser);
response.setHeader(FilterConstance.HEADER,jwt);
return jwt;
}
}

@ -26,6 +26,11 @@
<artifactId>common</artifactId> <artifactId>common</artifactId>
<version>${common.version}</version> <version>${common.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.leaper</groupId>
<artifactId>filter</artifactId>
<version>${common.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>

@ -43,16 +43,17 @@
<artifactId>common</artifactId> <artifactId>common</artifactId>
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.50.Final</version>
</dependency>
<dependency> <dependency>
<groupId>com.leaper</groupId> <groupId>com.leaper</groupId>
<artifactId>filter</artifactId> <artifactId>filter</artifactId>
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.50.Final</version>
</dependency>
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>

@ -4,7 +4,7 @@ import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication(scanBasePackages = {"com.leaper"}) @SpringBootApplication(scanBasePackages = {"com.leaper","com.zhehekeji.core"})
@MapperScan("com.leaper.**.mapper.**") @MapperScan("com.leaper.**.mapper.**")
public class Application { public class Application {
public static void main(String[] args) { public static void main(String[] args) {

@ -1,5 +1,6 @@
package com.leaper.web.controller; package com.leaper.web.controller;
import com.leaper.filter.pojo.LicenseHandler;
import com.leaper.web.lib.CameraConnMap; import com.leaper.web.lib.CameraConnMap;
import com.leaper.web.lib.CameraControlLoginModule; import com.leaper.web.lib.CameraControlLoginModule;
import com.leaper.web.lib.CameraControlModule; import com.leaper.web.lib.CameraControlModule;
@ -53,6 +54,7 @@ public class CameraControlController {
@PostMapping("/up/{id}") @PostMapping("/up/{id}")
@ApiOperation(value = "球机控制向上") @ApiOperation(value = "球机控制向上")
@LicenseHandler
public Result up(@PathVariable Integer id) { public Result up(@PathVariable Integer id) {
log.debug("球机控制向上"); log.debug("球机控制向上");
checkLogin(id); checkLogin(id);
@ -62,6 +64,7 @@ public class CameraControlController {
@PostMapping("/up/stop/{id}") @PostMapping("/up/stop/{id}")
@ApiOperation(value = "球机控制向上 停止") @ApiOperation(value = "球机控制向上 停止")
@LicenseHandler
public Result upStop(@PathVariable Integer id) { public Result upStop(@PathVariable Integer id) {
log.debug("球机控制向上 停止"); log.debug("球机控制向上 停止");
checkLogin(id); checkLogin(id);
@ -71,6 +74,7 @@ public class CameraControlController {
@PostMapping("/down/{id}") @PostMapping("/down/{id}")
@ApiOperation(value = "球机控制向下") @ApiOperation(value = "球机控制向下")
@LicenseHandler
public Result down(@PathVariable Integer id) { public Result down(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlDownStart(id,0,0,1); cameraControlModule.ptzControlDownStart(id,0,0,1);
@ -80,6 +84,7 @@ public class CameraControlController {
@PostMapping("/down/stop/{id}") @PostMapping("/down/stop/{id}")
@ApiOperation(value = "球机控制向下-停止") @ApiOperation(value = "球机控制向下-停止")
@LicenseHandler
public Result downStop(@PathVariable Integer id) { public Result downStop(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlDownEnd(id,0); cameraControlModule.ptzControlDownEnd(id,0);
@ -89,6 +94,7 @@ public class CameraControlController {
@PostMapping("/left/{id}") @PostMapping("/left/{id}")
@ApiOperation(value = "球机控制向左") @ApiOperation(value = "球机控制向左")
@LicenseHandler
public Result left(@PathVariable Integer id) { public Result left(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlLeftStart(id,0,0,1); cameraControlModule.ptzControlLeftStart(id,0,0,1);
@ -98,6 +104,7 @@ public class CameraControlController {
@PostMapping("/left/stop/{id}") @PostMapping("/left/stop/{id}")
@ApiOperation(value = "球机控制左-停止") @ApiOperation(value = "球机控制左-停止")
@LicenseHandler
public Result leftStop(@PathVariable Integer id) { public Result leftStop(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlLeftEnd(id,0); cameraControlModule.ptzControlLeftEnd(id,0);
@ -108,6 +115,7 @@ public class CameraControlController {
@PostMapping("/leftUp/{id}") @PostMapping("/leftUp/{id}")
@ApiOperation(value = "球机控制向左上") @ApiOperation(value = "球机控制向左上")
@LicenseHandler
public Result leftUp(@PathVariable Integer id) { public Result leftUp(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlLeftUpStart(id,0,1,1); cameraControlModule.ptzControlLeftUpStart(id,0,1,1);
@ -117,6 +125,7 @@ public class CameraControlController {
@PostMapping("/leftUp/stop/{id}") @PostMapping("/leftUp/stop/{id}")
@ApiOperation(value = "球机控制左上-停止") @ApiOperation(value = "球机控制左上-停止")
@LicenseHandler
public Result leftUpStop(@PathVariable Integer id) { public Result leftUpStop(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlLeftUpEnd(id,0); cameraControlModule.ptzControlLeftUpEnd(id,0);
@ -126,6 +135,7 @@ public class CameraControlController {
@PostMapping("/leftDown/{id}") @PostMapping("/leftDown/{id}")
@ApiOperation(value = "球机控制向左下") @ApiOperation(value = "球机控制向左下")
@LicenseHandler
public Result leftDown(@PathVariable Integer id) { public Result leftDown(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlLeftDownStart(id,0,1,1); cameraControlModule.ptzControlLeftDownStart(id,0,1,1);
@ -135,6 +145,7 @@ public class CameraControlController {
@PostMapping("/leftDown/stop/{id}") @PostMapping("/leftDown/stop/{id}")
@ApiOperation(value = "球机控制左下-停止") @ApiOperation(value = "球机控制左下-停止")
@LicenseHandler
public Result leftDownStop(@PathVariable Integer id) { public Result leftDownStop(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlLeftDownEnd(id,0); cameraControlModule.ptzControlLeftDownEnd(id,0);
@ -145,6 +156,7 @@ public class CameraControlController {
@PostMapping("/right/{id}") @PostMapping("/right/{id}")
@ApiOperation(value = "球机控制向右") @ApiOperation(value = "球机控制向右")
@LicenseHandler
public Result right(@PathVariable Integer id) { public Result right(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlRightStart(id,0,0,1); cameraControlModule.ptzControlRightStart(id,0,0,1);
@ -154,6 +166,7 @@ public class CameraControlController {
@PostMapping("/right/stop/{id}") @PostMapping("/right/stop/{id}")
@ApiOperation(value = "球机控制右-停止") @ApiOperation(value = "球机控制右-停止")
@LicenseHandler
public Result rightStop(@PathVariable Integer id) { public Result rightStop(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlRightEnd(id,0); cameraControlModule.ptzControlRightEnd(id,0);
@ -164,6 +177,7 @@ public class CameraControlController {
@PostMapping("/rightUp/{id}") @PostMapping("/rightUp/{id}")
@ApiOperation(value = "球机控制向右上") @ApiOperation(value = "球机控制向右上")
@LicenseHandler
public Result rightUp(@PathVariable Integer id) { public Result rightUp(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlRightUpStart(id,0,1,1); cameraControlModule.ptzControlRightUpStart(id,0,1,1);
@ -173,6 +187,7 @@ public class CameraControlController {
@PostMapping("/rightUp/stop/{id}") @PostMapping("/rightUp/stop/{id}")
@ApiOperation(value = "球机控制右上-停止") @ApiOperation(value = "球机控制右上-停止")
@LicenseHandler
public Result rightUpStop(@PathVariable Integer id) { public Result rightUpStop(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlRightUpEnd(id,0); cameraControlModule.ptzControlRightUpEnd(id,0);
@ -182,6 +197,7 @@ public class CameraControlController {
@PostMapping("/rightDown/{id}") @PostMapping("/rightDown/{id}")
@ApiOperation(value = "球机控制向右下") @ApiOperation(value = "球机控制向右下")
@LicenseHandler
public Result rightDown(@PathVariable Integer id) { public Result rightDown(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlRightDownStart(id,0,1,1); cameraControlModule.ptzControlRightDownStart(id,0,1,1);
@ -191,6 +207,7 @@ public class CameraControlController {
@PostMapping("/rightDown/stop/{id}") @PostMapping("/rightDown/stop/{id}")
@ApiOperation(value = "球机控制右下-停止") @ApiOperation(value = "球机控制右下-停止")
@LicenseHandler
public Result rightDownStop(@PathVariable Integer id) { public Result rightDownStop(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlRightDownEnd(id,0); cameraControlModule.ptzControlRightDownEnd(id,0);
@ -200,6 +217,7 @@ public class CameraControlController {
@PostMapping("/zoomAdd/start/{id}") @PostMapping("/zoomAdd/start/{id}")
@ApiOperation(value = "球机控制 变倍+") @ApiOperation(value = "球机控制 变倍+")
@LicenseHandler
public Result ZoomAddStart(@PathVariable Integer id) { public Result ZoomAddStart(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlZoomAddStart(id,0,1); cameraControlModule.ptzControlZoomAddStart(id,0,1);
@ -208,6 +226,7 @@ public class CameraControlController {
@PostMapping("/zoomAdd/stop/{id}") @PostMapping("/zoomAdd/stop/{id}")
@ApiOperation(value = "球机控制 变倍+ 停止") @ApiOperation(value = "球机控制 变倍+ 停止")
@LicenseHandler
public Result ZoomAddEnd(@PathVariable Integer id) { public Result ZoomAddEnd(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlZoomAddEnd(id,0); cameraControlModule.ptzControlZoomAddEnd(id,0);
@ -216,6 +235,7 @@ public class CameraControlController {
@PostMapping("/zoomDec/start/{id}") @PostMapping("/zoomDec/start/{id}")
@ApiOperation(value = "球机控制 变倍-") @ApiOperation(value = "球机控制 变倍-")
@LicenseHandler
public Result ZoomDecStart(@PathVariable Integer id) { public Result ZoomDecStart(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlZoomDecStart(id,0,1); cameraControlModule.ptzControlZoomDecStart(id,0,1);
@ -224,6 +244,7 @@ public class CameraControlController {
@PostMapping("/zoomDec/stop/{id}") @PostMapping("/zoomDec/stop/{id}")
@ApiOperation(value = "球机控制 变倍- 停止") @ApiOperation(value = "球机控制 变倍- 停止")
@LicenseHandler
public Result ZoomDecEnd(@PathVariable Integer id) { public Result ZoomDecEnd(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlZoomDecEnd(id,0); cameraControlModule.ptzControlZoomDecEnd(id,0);
@ -232,6 +253,7 @@ public class CameraControlController {
@PostMapping("/focusAdd/start/{id}") @PostMapping("/focusAdd/start/{id}")
@ApiOperation(value = "球机控制 变焦 +") @ApiOperation(value = "球机控制 变焦 +")
@LicenseHandler
public Result FocusAddStart(@PathVariable Integer id) { public Result FocusAddStart(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlFocusAddStart(id,0,1); cameraControlModule.ptzControlFocusAddStart(id,0,1);
@ -240,6 +262,7 @@ public class CameraControlController {
@PostMapping("/focusAdd/stop/{id}") @PostMapping("/focusAdd/stop/{id}")
@ApiOperation(value = "球机控制 变焦+ 停止") @ApiOperation(value = "球机控制 变焦+ 停止")
@LicenseHandler
public Result focusAddEnd(@PathVariable Integer id) { public Result focusAddEnd(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlFocusAddEnd(id,0); cameraControlModule.ptzControlFocusAddEnd(id,0);
@ -248,6 +271,7 @@ public class CameraControlController {
@PostMapping("/focusDec/start/{id}") @PostMapping("/focusDec/start/{id}")
@ApiOperation(value = "球机控制 变焦 -") @ApiOperation(value = "球机控制 变焦 -")
@LicenseHandler
public Result FocusDecStart(@PathVariable Integer id) { public Result FocusDecStart(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlFocusDecStart(id,0,1); cameraControlModule.ptzControlFocusDecStart(id,0,1);
@ -256,6 +280,7 @@ public class CameraControlController {
@PostMapping("/focusDec/stop/{id}") @PostMapping("/focusDec/stop/{id}")
@ApiOperation(value = "球机控制 变焦- 停止") @ApiOperation(value = "球机控制 变焦- 停止")
@LicenseHandler
public Result focusDecEnd(@PathVariable Integer id) { public Result focusDecEnd(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlFocusDecEnd(id,0); cameraControlModule.ptzControlFocusDecEnd(id,0);
@ -264,6 +289,7 @@ public class CameraControlController {
@PostMapping("/irisAdd/start/{id}") @PostMapping("/irisAdd/start/{id}")
@ApiOperation(value = "球机控制 光圈 +") @ApiOperation(value = "球机控制 光圈 +")
@LicenseHandler
public Result irisAddStart(@PathVariable Integer id) { public Result irisAddStart(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlIrisAddStart(id,0,1); cameraControlModule.ptzControlIrisAddStart(id,0,1);
@ -272,6 +298,7 @@ public class CameraControlController {
@PostMapping("/irisAdd/stop/{id}") @PostMapping("/irisAdd/stop/{id}")
@ApiOperation(value = "球机控制 光圈+ 停止") @ApiOperation(value = "球机控制 光圈+ 停止")
@LicenseHandler
public Result irisAddEnd(@PathVariable Integer id) { public Result irisAddEnd(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlIrisAddEnd(id,0); cameraControlModule.ptzControlIrisAddEnd(id,0);
@ -280,6 +307,7 @@ public class CameraControlController {
@PostMapping("/irisDec/start/{id}") @PostMapping("/irisDec/start/{id}")
@ApiOperation(value = "球机控制 光圈 -") @ApiOperation(value = "球机控制 光圈 -")
@LicenseHandler
public Result irisDecStart(@PathVariable Integer id) { public Result irisDecStart(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlIrisDecStart(id,0,1); cameraControlModule.ptzControlIrisDecStart(id,0,1);
@ -288,6 +316,7 @@ public class CameraControlController {
@PostMapping("/irisDec/stop/{id}") @PostMapping("/irisDec/stop/{id}")
@ApiOperation(value = "球机控制 光圈- 停止") @ApiOperation(value = "球机控制 光圈- 停止")
@LicenseHandler
public Result irisDecEnd(@PathVariable Integer id) { public Result irisDecEnd(@PathVariable Integer id) {
checkLogin(id); checkLogin(id);
cameraControlModule.ptzControlIrisDecEnd(id,0); cameraControlModule.ptzControlIrisDecEnd(id,0);

@ -2,6 +2,7 @@ package com.leaper.web.controller;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.leaper.filter.pojo.LicenseHandler;
import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.IntByReference;
import com.leaper.common.util.ValidatorUtil; import com.leaper.common.util.ValidatorUtil;
import com.zhehekeji.core.pojo.Result; import com.zhehekeji.core.pojo.Result;
@ -41,18 +42,21 @@ public class CameraController {
@PostMapping("/page") @PostMapping("/page")
@ApiOperation(value = "球机列表分页 ") @ApiOperation(value = "球机列表分页 ")
@LicenseHandler
public Result<PageInfo<Camera>> list(@RequestBody StreetSearch streetSearch) { public Result<PageInfo<Camera>> list(@RequestBody StreetSearch streetSearch) {
return new Result<>(cameraService.cameras(streetSearch)); return new Result<>(cameraService.cameras(streetSearch));
} }
@GetMapping("/{id}") @GetMapping("/{id}")
@ApiOperation(value = "球机") @ApiOperation(value = "球机")
@LicenseHandler
public Result<Camera> detail(@PathVariable Integer id) { public Result<Camera> detail(@PathVariable Integer id) {
return new Result<>(cameraService.detail(id)); return new Result<>(cameraService.detail(id));
} }
@PostMapping("") @PostMapping("")
@ApiOperation(value = "球机新增 ") @ApiOperation(value = "球机新增 ")
@LicenseHandler
public Result<Integer> add(@RequestBody Camera camera) { public Result<Integer> add(@RequestBody Camera camera) {
return new Result<>(cameraService.add(camera)); return new Result<>(cameraService.add(camera));
} }

@ -0,0 +1,69 @@
package com.leaper.web.service;
import com.leaper.common.util.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.Scanner;
@Slf4j
public class LPLicense {
private static LocalDateTime lastUpdate = null;
private static String lic_str = null;
private static String lic_path = "./lp.lic";
private static String key_path = "./lp.key";
public static void createLicKeyIfNotExist(){
File file = new File(key_path);
if(!file.exists()){
try {
Process process = Runtime.getRuntime().exec(
new String[] { "wmic", "cpu", "get", "ProcessorId" });
process.getOutputStream().close();
Scanner sc = new Scanner(process.getInputStream());
String property = sc.next();
String cpu = sc.next();
FileUtil.save(cpu,key_path);
} catch (IOException e) {
e.printStackTrace();
log.error("createLicKeyIfNotExist error:{}",e);
}
}
}
public static String getLic(){
//每小时读取一次lic文件
if(lastUpdate == null || LocalDateTime.now().toLocalTime().getHour() != lastUpdate.toLocalTime().getHour()){
lastUpdate = LocalDateTime.now();
lic_str = FileUtil.getText(lic_path);
}
return lic_str;
}
public static boolean checkLic(String pathStr){
//todo 检测
return true;
}
public static boolean checkLic(){
String licStr = getLic();
if(StringUtils.isEmpty(licStr)){
return false;
}
return checkLic(licStr);
}
public static void main(String[] args) {
createLicKeyIfNotExist();
}
}

@ -153,22 +153,22 @@ public class KsecDecoder extends DelimiterBasedFrameDecoder {
} else if (Cmd.D.name().equals(ksecInfo.getType())) { } else if (Cmd.D.name().equals(ksecInfo.getType())) {
//柳州去掉告警 //柳州去掉告警
// String code = dataInfo.getCmdName(); String code = dataInfo.getCmdName();
// if(code.equals(Cmd.D1.name())){ if(code.equals(Cmd.D1.name())){
// log.info("plcId:{},warn start",plcCmdInfo.getPlcId()); log.info("plcId:{},warn start",plcCmdInfo.getPlcId());
// //根据告警code转动camera //根据告警code转动camera
// String warnCode = dataInfo.getWarnCode(); String warnCode = dataInfo.getWarnCode();
// if(!StringUtils.isEmpty(warnCode)){ if(!StringUtils.isEmpty(warnCode)){
// String warnCode0 = Cmd.D1.name()+"-"+warnCode.split(",")[0]; String warnCode0 = Cmd.D1.name()+"-"+warnCode.split(",")[0];
// plcService.warnAction(plcCmdInfo,warnCode0); plcService.warnAction(plcCmdInfo,warnCode0);
// } }
// plcService.warnStart(plcCmdInfo.getPlcId(),dataInfo.getWarnCode()); plcService.warnStart(plcCmdInfo.getPlcId(),dataInfo.getWarnCode());
// }else if(code.equals(Cmd.D2.name())){ }else if(code.equals(Cmd.D2.name())){
// log.info("plcId:{},warn stop",plcCmdInfo.getPlcId()); log.info("plcId:{},warn stop",plcCmdInfo.getPlcId());
// plcService.warnStop(plcCmdInfo.getPlcId()); plcService.warnStop(plcCmdInfo.getPlcId());
// }else { }else {
// log.info("other D code :{}",code); log.info("other D code :{}",code);
// } }
} else if (Cmd.E.name().equals(ksecInfo.getType())) { } else if (Cmd.E.name().equals(ksecInfo.getType())) {
//盘点 //盘点

Loading…
Cancel
Save