package com.ld.igds.sec.service;
|
|
import com.bstek.bdf2.core.orm.hibernate.HibernateDao;
|
import com.bstek.dorado.data.provider.Page;
|
import com.ld.igds.models.*;
|
import com.ld.igds.util.ContextUtil;
|
import com.ld.igds.util.DateUtil;
|
|
import org.apache.commons.lang3.StringUtils;
|
import org.hibernate.Session;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
@Component
|
public class SecurityService extends HibernateDao {
|
|
@Resource
|
private CoreSecCameraService coreSecCameraService;
|
|
public List<SecCamera> listCamera(Map<String, Object> param) {
|
String hql = " from " + SecCamera.class.getName()
|
+ " where companyId=:companyId and deptId=:deptId";
|
|
Map<String, Object> args = new HashMap<String, Object>();
|
args.put("companyId", ContextUtil.getCompanyId());
|
args.put("deptId", ContextUtil.subDeptId(null));
|
|
if (null != param) {
|
String str = (String) param.get("name");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and name like:name";
|
args.put("name", "%" + str + "%");
|
}
|
|
str = (String) param.get("brand");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and brand =:brand";
|
args.put("brand", str);
|
}
|
|
str = (String) param.get("type");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and type =:type";
|
args.put("type", str);
|
}
|
}
|
|
hql += " order by name";
|
|
return this.query(hql, args);
|
}
|
|
public void saveCamera(SecCamera data) {
|
if (null == data.getCompanyId()) {
|
data.setCompanyId(ContextUtil.getCompanyId());
|
}
|
data.setUpdateTime(new Date());
|
if (data.getChanNum() == 0) {
|
data.setChanNum(1);
|
}
|
Session session = this.getSessionFactory().openSession();
|
try {
|
if (null == data.getId()) {
|
data.setId(ContextUtil.getUUID());
|
session.save(data);
|
} else {
|
session.update(data);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
}
|
|
public String delCamera(SecCamera data) {
|
Session session = this.getSessionFactory().openSession();
|
try {
|
if (null != data.getId()) {
|
session.delete(data);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
return null;
|
}
|
|
public void pageCustomer(Page<SecCustomer> page, Map<String, Object> param)
|
throws Exception {
|
String hql = " from " + SecCustomer.class.getName()
|
+ " where companyId=:companyId";
|
|
Map<String, Object> args = new HashMap<String, Object>();
|
args.put("companyId", ContextUtil.getCompanyId());
|
|
if (null != param) {
|
String str = (String) param.get("customer");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and customer like:customer";
|
args.put("customer", "%" + str + "%");
|
}
|
|
str = (String) param.get("idCard");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and idCard =:idCard";
|
args.put("idCard", str);
|
}
|
|
Date date = (Date) param.get("start");
|
if (null != date) {
|
hql += " and start >=:start";
|
args.put("start", DateUtil.getCurZero(date));
|
}
|
|
date = (Date) param.get("end");
|
if (null != date) {
|
hql += " and start >=:end";
|
args.put("end", DateUtil.getNextZero(date));
|
}
|
|
}
|
|
String count = "select count(*) " + hql;
|
|
hql += " order by start desc";
|
|
this.pagingQuery(page, hql, count, args);
|
}
|
|
public void saveCustomer(SecCustomer data) {
|
data.setUpdateUser(ContextUtil.getLoginUserCName());
|
if (null == data.getCompanyId()) {
|
data.setCompanyId(ContextUtil.getCompanyId());
|
}
|
Session session = this.getSessionFactory().openSession();
|
try {
|
if (null == data.getId()) {
|
data.setId(ContextUtil.getUUID());
|
session.save(data);
|
} else {
|
session.update(data);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
}
|
|
public String delCustomer(SecCustomer data) {
|
Session session = this.getSessionFactory().openSession();
|
try {
|
if (null != data.getId()) {
|
session.delete(data);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
return null;
|
}
|
|
public void pagePatrol(Page<SecPatrolRecord> page, Map<String, Object> param)
|
throws Exception {
|
String hql = " from " + SecPatrolRecord.class.getName()
|
+ " where companyId=:companyId and deptId=:deptId";
|
|
Map<String, Object> args = new HashMap<String, Object>();
|
args.put("companyId", ContextUtil.getCompanyId());
|
args.put("deptId", ContextUtil.subDeptId(null));
|
|
if (null != param) {
|
String str = (String) param.get("userName");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and userName like:userName";
|
args.put("userName", "%" + str + "%");
|
}
|
|
Date date = (Date) param.get("start");
|
if (null != date) {
|
hql += " and createTime >=:start";
|
args.put("start", DateUtil.getCurZero(date));
|
}
|
|
date = (Date) param.get("end");
|
if (null != date) {
|
hql += " and createTime <=:end";
|
args.put("end", DateUtil.getNextZero(date));
|
}
|
}
|
|
String count = "select count(*) " + hql;
|
|
hql += " order by createTime desc";
|
|
this.pagingQuery(page, hql, count, args);
|
}
|
|
public void savePatrol(SecPatrolRecord data) {
|
if (null == data.getCompanyId()) {
|
data.setCompanyId(ContextUtil.getCompanyId());
|
}
|
Session session = this.getSessionFactory().openSession();
|
try {
|
if (null == data.getId()) {
|
data.setId(ContextUtil.getUUID());
|
session.save(data);
|
} else {
|
session.update(data);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
}
|
|
public String delPatrol(SecPatrolRecord data) {
|
Session session = this.getSessionFactory().openSession();
|
try {
|
if (null != data.getId()) {
|
session.delete(data);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
return null;
|
}
|
|
public List<SecVideoMac> listVodeo(Map<String, Object> param) {
|
String hql = " from " + SecVideoMac.class.getName()
|
+ " where companyId=:companyId";
|
Map<String, Object> args = new HashMap<String, Object>();
|
args.put("companyId", ContextUtil.getCompanyId());
|
|
hql += " order by name";
|
|
return this.query(hql, args);
|
}
|
|
public void saveVideo(SecVideoMac data) {
|
data.setUpdateTime(new Date());
|
data.setUpdateUser(ContextUtil.getLoginUserCName());
|
if (null == data.getCompanyId()) {
|
data.setCompanyId(ContextUtil.getCompanyId());
|
}
|
Session session = this.getSessionFactory().openSession();
|
try {
|
if (null == data.getId()) {
|
data.setId(ContextUtil.getUUID());
|
session.save(data);
|
} else {
|
session.update(data);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
}
|
|
public String delVideo(SecVideoMac data) {
|
Session session = this.getSessionFactory().openSession();
|
try {
|
if (null != data.getId()) {
|
session.delete(data);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
return null;
|
}
|
|
public void refreshCache(String companyId) {
|
coreSecCameraService.refreshCache(companyId);
|
}
|
|
public List<SecFire> listFire(Map<String, Object> param) {
|
String hql = " from " + SecFire.class.getName()
|
+ " where companyId=:companyId";
|
|
Map<String, Object> args = new HashMap<String, Object>();
|
args.put("companyId", ContextUtil.getCompanyId());
|
|
if (null != param) {
|
String str = (String) param.get("name");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and name like:name";
|
args.put("name", "%" + str + "%");
|
}
|
}
|
|
hql += " order by name";
|
|
return this.query(hql, args);
|
}
|
|
public void saveFire(SecFire data) {
|
data.setUpdateTime(new Date());
|
data.setUpdateUser(ContextUtil.getLoginUserCName());
|
|
if (null == data.getCompanyId()) {
|
data.setCompanyId(ContextUtil.getCompanyId());
|
}
|
Session session = this.getSessionFactory().openSession();
|
try {
|
if (null == data.getId()) {
|
data.setId(ContextUtil.getUUID());
|
session.save(data);
|
} else {
|
session.update(data);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
}
|
|
public String delFire(SecFire data) {
|
Session session = this.getSessionFactory().openSession();
|
try {
|
if (null != data.getId()) {
|
session.delete(data);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
return null;
|
}
|
|
|
// --------------电子巡更设备配置-------------//
|
|
public List<SecPatrolDevice> listPatrolDevice(Map<String, Object> param) {
|
String hql = " from " + SecPatrolDevice.class.getName()
|
+ " where companyId=:companyId";
|
|
Map<String, Object> args = new HashMap<String, Object>();
|
args.put("companyId", ContextUtil.getCompanyId());
|
|
if (null != param) {
|
String str = (String) param.get("name");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and name like:name";
|
args.put("name", "%" + str + "%");
|
}
|
|
str = (String) param.get("deptId");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and deptId =:deptId";
|
args.put("brand", str);
|
}
|
|
str = (String) param.get("userName");
|
if (StringUtils.isNotEmpty(str)) {
|
hql += " and userName like:userName";
|
args.put("userName", str);
|
}
|
}
|
|
hql += " order by name";
|
|
return this.query(hql, args);
|
}
|
|
public void savePatrolDevice(SecPatrolDevice data) {
|
if (null == data.getCompanyId()) {
|
data.setCompanyId(ContextUtil.getCompanyId());
|
}
|
|
Session session = this.getSessionFactory().openSession();
|
try {
|
if (null == data.getId()) {
|
data.setId(ContextUtil.getUUID());
|
data.setUpdateUser(ContextUtil.getLoginUserName());
|
session.save(data);
|
} else {
|
session.update(data);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
}
|
|
public String delPatrolDevice(SecPatrolDevice data) {
|
Session session = this.getSessionFactory().openSession();
|
try {
|
if (null != data.getId()) {
|
session.delete(data);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
session.flush();
|
session.close();
|
}
|
return null;
|
}
|
|
}
|