|
@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.github.yulichang.query.MPJQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.sckj.common.TapholeAdminThreadLocal;
|
|
|
+import com.sckj.common.core.AjaxResult;
|
|
|
import com.sckj.common.validate.commons.PageValidate;
|
|
|
import com.sckj.device.service.ITCameraService;
|
|
|
import com.sckj.device.validate.TCameraCreateValidate;
|
|
@@ -21,9 +23,12 @@ import com.sckj.common.util.UrlUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.Assert;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
* 摄像头实现类
|
|
@@ -97,9 +102,13 @@ public class TCameraServiceImpl implements ITCameraService {
|
|
|
* @param createValidate 参数
|
|
|
*/
|
|
|
@Override
|
|
|
- public void add(TCameraCreateValidate createValidate) {
|
|
|
+ public int add(TCameraCreateValidate createValidate) {
|
|
|
TCamera model = new TCamera();
|
|
|
+ if (!checkPortAndIp(createValidate.getPort(), createValidate.getIp())){
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
model.setCreateTime(new Date(System.currentTimeMillis()));
|
|
|
+ model.setCreateBy(String.valueOf(TapholeAdminThreadLocal.getAdminUsername()));
|
|
|
model.setUpdateTime(new Date(System.currentTimeMillis()));
|
|
|
model.setNo(createValidate.getNo());
|
|
|
model.setName(createValidate.getName());
|
|
@@ -107,12 +116,10 @@ public class TCameraServiceImpl implements ITCameraService {
|
|
|
model.setLocation(createValidate.getLocation());
|
|
|
model.setIp(createValidate.getIp());
|
|
|
model.setPort(createValidate.getPort());
|
|
|
- model.setAccount(createValidate.getAccount());
|
|
|
- model.setPassword(createValidate.getPassword());
|
|
|
model.setStatus(createValidate.getStatus());
|
|
|
model.setVcrId(createValidate.getVcrId());
|
|
|
model.setType(createValidate.getType());
|
|
|
- tCameraMapper.insert(model);
|
|
|
+ return tCameraMapper.insert(model);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -122,7 +129,7 @@ public class TCameraServiceImpl implements ITCameraService {
|
|
|
* @param updateValidate 参数
|
|
|
*/
|
|
|
@Override
|
|
|
- public void edit(TCameraUpdateValidate updateValidate) {
|
|
|
+ public int edit(TCameraUpdateValidate updateValidate) {
|
|
|
TCamera model = tCameraMapper.selectOne(
|
|
|
new QueryWrapper<TCamera>()
|
|
|
.eq("id", updateValidate.getId())
|
|
@@ -130,18 +137,34 @@ public class TCameraServiceImpl implements ITCameraService {
|
|
|
|
|
|
Assert.notNull(model, "数据不存在!");
|
|
|
|
|
|
+ if (!checkPortAndIp(updateValidate.getPort(), updateValidate.getIp())){
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
model.setUpdateTime(new Date(System.currentTimeMillis()));
|
|
|
+ model.setUpdateBy(String.valueOf(TapholeAdminThreadLocal.getAdminUsername()));
|
|
|
model.setNo(updateValidate.getNo());
|
|
|
model.setName(updateValidate.getName());
|
|
|
model.setModel(updateValidate.getModel());
|
|
|
model.setLocation(updateValidate.getLocation());
|
|
|
model.setIp(updateValidate.getIp());
|
|
|
model.setPort(updateValidate.getPort());
|
|
|
- model.setAccount(updateValidate.getAccount());
|
|
|
- model.setPassword(updateValidate.getPassword());
|
|
|
model.setStatus(updateValidate.getStatus());
|
|
|
model.setVcrId(updateValidate.getVcrId());
|
|
|
- tCameraMapper.updateById(model);
|
|
|
+ return tCameraMapper.updateById(model);
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean checkPortAndIp(String port, String ip){
|
|
|
+ if (Integer.parseInt(port) > 65535){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String IP_PATTERN = "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$";
|
|
|
+ Pattern pattern = Pattern.compile(IP_PATTERN);
|
|
|
+ Matcher matcher = pattern.matcher(ip);
|
|
|
+ if (!matcher.matches()){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -162,4 +185,23 @@ public class TCameraServiceImpl implements ITCameraService {
|
|
|
tCameraMapper.delete(new QueryWrapper<TCamera>().eq("id", id));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 摄像头批量删除
|
|
|
+ *
|
|
|
+ * @author zhanghao
|
|
|
+ * @param ids 主键数组
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AjaxResult<Object> del_ex(List<Long> ids) {
|
|
|
+ List<TCamera> models = tCameraMapper.selectList(
|
|
|
+ new QueryWrapper<TCamera>()
|
|
|
+ .in("id", ids));
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(models)){
|
|
|
+ return AjaxResult.failed("数据不存在");
|
|
|
+ }
|
|
|
+ tCameraMapper.delete(new QueryWrapper<TCamera>().in("id", ids));
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
}
|