From 9c49930966edbe0f24e62e38f58c2d3e453976b3 Mon Sep 17 00:00:00 2001 From: jiazx0107@163.com <jiazx0107@163.com> Date: 星期三, 23 八月 2023 15:51:39 +0800 Subject: [PATCH] 更新MODBUS-TCP协议 4 --- igds-core/src/main/java/com/ld/igds/view/service/DeviceService.java | 470 +++++++++++++++++++++++++++++----------------------------- 1 files changed, 233 insertions(+), 237 deletions(-) diff --git a/igds-core/src/main/java/com/ld/igds/view/service/DeviceService.java b/igds-core/src/main/java/com/ld/igds/view/service/DeviceService.java index 9635b30..8bb0320 100644 --- a/igds-core/src/main/java/com/ld/igds/view/service/DeviceService.java +++ b/igds-core/src/main/java/com/ld/igds/view/service/DeviceService.java @@ -1,279 +1,275 @@ package com.ld.igds.view.service; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.commons.lang.StringUtils; -import org.hibernate.Session; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - import com.bstek.bdf2.core.orm.hibernate.HibernateDao; import com.bstek.dorado.data.provider.Page; import com.ld.igds.common.CoreDeviceService; import com.ld.igds.models.Device; import com.ld.igds.util.ContextUtil; +import org.apache.commons.lang.StringUtils; +import org.hibernate.Session; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** - * * @author Andy - * */ @Component public class DeviceService extends HibernateDao { - - - @Autowired - private CoreDeviceService coreDeviceService; - /** - * 鍔犺浇鎵�鏈夎澶囨暟鎹� - * <p> - * Title: loadDevice - * </p> - * <p> - * Description: - * </p> - * - */ - public List<Device> loadDevice(Map<String, Object> parameter) { - if (parameter == null || parameter.size() <= 0) - return null; - Map<String, Object> p = new HashMap<String, Object>(); - String hql = " from " + Device.class.getName() - + " where companyId = :companyId "; - - String companyId = (String) parameter.get("companyId"); - if(null == companyId){ - companyId = ContextUtil.getCompanyId(); - } - p.put("companyId", companyId); + @Resource + private CoreDeviceService coreDeviceService; - String depotId = (String) parameter.get("depotId"); - if (StringUtils.isNotEmpty(depotId)) { - hql += " and depotId =:depotId"; - p.put("depotId", depotId); - } + /** + * 鍔犺浇鎵�鏈夎澶囨暟鎹� + * <p> + * Title: loadDevice + * </p> + * <p> + * Description: + * </p> + */ + public List<Device> loadDevice(Map<String, Object> parameter) { + if (parameter == null || parameter.size() <= 0) + return null; - String type = (String) parameter.get("type"); - if (StringUtils.isNotEmpty(type)) { - hql += " and type =:type"; - p.put("type", type); - } + Map<String, Object> p = new HashMap<String, Object>(); + String hql = " from " + Device.class.getName() + + " where companyId = :companyId "; - String serId = (String) parameter.get("serId"); - if (StringUtils.isNotEmpty(serId)) { - hql += " and serId =:serId"; - p.put("serId", serId); - } + String companyId = (String) parameter.get("companyId"); + if (null == companyId) { + companyId = ContextUtil.getCompanyId(); + } + p.put("companyId", companyId); - hql += " order by type,id"; - return this.query(hql, p); - } + String depotId = (String) parameter.get("depotId"); + if (StringUtils.isNotEmpty(depotId)) { + hql += " and depotId =:depotId"; + p.put("depotId", depotId); + } - public void loadDeviceByContion(Page<Device> page, - Map<String, Object> parameter) throws Exception { - Map<String, Object> p = new HashMap<String, Object>(); - String hql = " from " + Device.class.getName() - + " where companyId = :companyId "; - p.put("companyId", ContextUtil.getCompanyId()); - - if(null == parameter)parameter = new HashMap<String, Object>(); + String type = (String) parameter.get("type"); + if (StringUtils.isNotEmpty(type)) { + hql += " and type =:type"; + p.put("type", type); + } - String depotId = (String) parameter.get("depotId"); - if (StringUtils.isNotEmpty(depotId)) { - hql += " and depotId =:depotId"; - p.put("depotId", depotId); - } + String serId = (String) parameter.get("serId"); + if (StringUtils.isNotEmpty(serId)) { + hql += " and serId =:serId"; + p.put("serId", serId); + } - String type = (String) parameter.get("type"); - if (StringUtils.isNotEmpty(type)) { - hql += " and type =:type"; - p.put("type", type); - } + hql += " order by type,id"; + return this.query(hql, p); + } - String serId = (String) parameter.get("serId"); - if (StringUtils.isNotEmpty(serId)) { - hql += " and serId =:serId"; - p.put("serId", serId); - } + public void loadDeviceByContion(Page<Device> page, + Map<String, Object> parameter) throws Exception { + Map<String, Object> p = new HashMap<String, Object>(); + String hql = " from " + Device.class.getName() + + " where companyId = :companyId "; + p.put("companyId", ContextUtil.getCompanyId()); - String countSql = "select count(*) " + hql; - hql += " order by serId,id asc"; - this.pagingQuery(page, hql, countSql, p); - } + if (null == parameter) parameter = new HashMap<String, Object>(); - /** - * 淇敼璁惧淇℃伅 - * <p> - * Title: upDepotDevice - * </p> - * <p> - * Description: - * </p> - * - * @param depotDevice - */ + String depotId = (String) parameter.get("depotId"); + if (StringUtils.isNotEmpty(depotId)) { + hql += " and depotId =:depotId"; + p.put("depotId", depotId); + } - public void upDepotDevice(Device depotDevice) { - Session session = null; - try { - session = this.getSessionFactory().openSession(); - session.update(depotDevice); - } catch (Exception e) { - e.printStackTrace(); - } finally { - session.flush(); - session.close(); - } + String type = (String) parameter.get("type"); + if (StringUtils.isNotEmpty(type)) { + hql += " and type =:type"; + p.put("type", type); + } - } + String serId = (String) parameter.get("serId"); + if (StringUtils.isNotEmpty(serId)) { + hql += " and serId =:serId"; + p.put("serId", serId); + } - /** - * 鍒犻櫎璁惧 - * <p> - * Title: delDepotDevice - * </p> - * <p> - * Description: - * </p> - */ - public void delDepotDevice(Device depotDevice) { - Session session = null; - try { - session = this.getSessionFactory().openSession(); - session.delete(depotDevice); - } catch (Exception e) { - e.printStackTrace(); - } finally { - session.flush(); - session.close(); - } - } + String countSql = "select count(*) " + hql; + hql += " order by serId,id asc"; + this.pagingQuery(page, hql, countSql, p); + } - public void delDepotDevice(String id) { - Session session = null; - try { - session = this.getSessionFactory().openSession(); - String hql = " delete from " + Device.class.getName() - + " where id=:id"; - session.createQuery(hql).setString("id", id).executeUpdate(); - } catch (Exception e) { - e.printStackTrace(); - } finally { - session.flush(); - session.close(); - } - } + /** + * 淇敼璁惧淇℃伅 + * <p> + * Title: upDepotDevice + * </p> + * <p> + * Description: + * </p> + * + * @param depotDevice + */ - public String saveOrUpdate(Device device, String id) { - if (null != id) { - this.delDepotDevice(id); - return null; - } - Session session = null; - try { - session = this.getSessionFactory().openSession(); - if (null != device.getId()) { - session.update(device); - } else { - device.setCompanyId(ContextUtil.getCompanyId()); - device.setId(ContextUtil.buildDeviceId(device.getCompanyId(), - device.getDepotId(), device.getPassCode())); - session.save(device); - } - } catch (Exception e) { - e.printStackTrace(); - } finally { - session.flush(); - session.close(); - } - return null; - } + public void upDepotDevice(Device depotDevice) { + Session session = null; + try { + session = this.getSessionFactory().openSession(); + session.update(depotDevice); + } catch (Exception e) { + e.printStackTrace(); + } finally { + session.flush(); + session.close(); + } - public void addDepotDevice(Device depotDevice) { - Session session = null; - try { - session = this.getSessionFactory().openSession(); - depotDevice.setCompanyId(ContextUtil.getCompanyId()); - depotDevice.setId(ContextUtil.buildDeviceId( - depotDevice.getCompanyId(), depotDevice.getDepotId(), - depotDevice.getPassCode())); - session.save(depotDevice); - } catch (Exception e) { - e.printStackTrace(); - } finally { - session.flush(); - session.close(); - } - } + } - public void refreshCache(String companyId) { - coreDeviceService.refreshCache(companyId); - } + /** + * 鍒犻櫎璁惧 + * <p> + * Title: delDepotDevice + * </p> + * <p> + * Description: + * </p> + */ + public void delDepotDevice(Device depotDevice) { + Session session = null; + try { + session = this.getSessionFactory().openSession(); + session.delete(depotDevice); + } catch (Exception e) { + e.printStackTrace(); + } finally { + session.flush(); + session.close(); + } + } - public Device getDeviceById(String id){ - Map<String, Object> p = new HashMap<String, Object>(); - String hql = " from " + Device.class.getName() - + " where companyId = :companyId and id=:id"; + public void delDepotDevice(String id) { + Session session = null; + try { + session = this.getSessionFactory().openSession(); + String hql = " delete from " + Device.class.getName() + + " where id=:id"; + session.createQuery(hql).setString("id", id).executeUpdate(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + session.flush(); + session.close(); + } + } - String companyId = ContextUtil.getCompanyId(); - p.put("companyId", companyId); - p.put("id", id); - List<Device> list = this.query(hql,p); - if(list != null && list.size() > 0){ - return list.get(0); - } - return null; - } + public String saveOrUpdate(Device device, String id) { + if (null != id) { + this.delDepotDevice(id); + return null; + } + Session session = null; + try { + session = this.getSessionFactory().openSession(); + if (null != device.getId()) { + session.update(device); + } else { + device.setCompanyId(ContextUtil.getCompanyId()); + device.setId(ContextUtil.buildDeviceId(device.getCompanyId(), + device.getDepotId(), device.getPassCode())); + session.save(device); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + session.flush(); + session.close(); + } + return null; + } - public List<Device> loadDeviceByType(Map<String, Object> parameter) { - if (parameter == null || parameter.size() <= 0) - return null; + public void addDepotDevice(Device depotDevice) { + Session session = null; + try { + session = this.getSessionFactory().openSession(); + depotDevice.setCompanyId(ContextUtil.getCompanyId()); + depotDevice.setId(ContextUtil.buildDeviceId( + depotDevice.getCompanyId(), depotDevice.getDepotId(), + depotDevice.getPassCode())); + session.save(depotDevice); + } catch (Exception e) { + e.printStackTrace(); + } finally { + session.flush(); + session.close(); + } + } - Map<String, Object> p = new HashMap<String, Object>(); - String hql = " from " + Device.class.getName() - + " where companyId = :companyId "; + public void refreshCache(String companyId) { + coreDeviceService.refreshCache(companyId); + } - String companyId = (String) parameter.get("companyId"); - if(null == companyId){ - companyId = ContextUtil.getCompanyId(); - } - p.put("companyId", companyId); + public Device getDeviceById(String id) { + Map<String, Object> p = new HashMap<String, Object>(); + String hql = " from " + Device.class.getName() + + " where companyId = :companyId and id=:id"; - String depotId = (String) parameter.get("depotId"); - if (StringUtils.isNotEmpty(depotId)) { - hql += " and depotId =:depotId"; - p.put("depotId", depotId); - } + String companyId = ContextUtil.getCompanyId(); + p.put("companyId", companyId); + p.put("id", id); + List<Device> list = this.query(hql, p); + if (list != null && list.size() > 0) { + return list.get(0); + } + return null; + } - String type = (String) parameter.get("type"); - if (StringUtils.isNotEmpty(type)) { - hql += " and type =:type"; - p.put("type", type); - } + public List<Device> loadDeviceByType(Map<String, Object> parameter) { + if (parameter == null || parameter.size() <= 0) + return null; - String serId = (String) parameter.get("serId"); - if (StringUtils.isNotEmpty(serId)) { - hql += " and serId =:serId"; - p.put("serId", serId); - } - String tag = (String) parameter.get("tag"); - // tag = 1 鏌ヨ椋庢満绫诲瀷鐨勮澶囷紝tag = 2 鏌ヨ鐓ф槑璁惧锛屽惁鍒欐槸鍏朵綑鐨勫叾瀹冭澶� - if (StringUtils.isNotEmpty(tag) && "1".equals(tag)) { - hql += " and type in (:types)"; - p.put("types", new String[] {"02","03","04","0C","0D"}); - }else if (StringUtils.isNotEmpty(tag) && "2".equals(tag)) { - hql += " and type =:type"; - p.put("type", "06"); - }else{ - hql += " and type not in (:types)"; - p.put("types", new String[] {"02","03","04","0C","0D"}); - } - hql += " order by type,id"; - return this.query(hql, p); - } + Map<String, Object> p = new HashMap<String, Object>(); + String hql = " from " + Device.class.getName() + + " where companyId = :companyId "; + + String companyId = (String) parameter.get("companyId"); + if (null == companyId) { + companyId = ContextUtil.getCompanyId(); + } + p.put("companyId", companyId); + + String depotId = (String) parameter.get("depotId"); + if (StringUtils.isNotEmpty(depotId)) { + hql += " and depotId =:depotId"; + p.put("depotId", depotId); + } + + String type = (String) parameter.get("type"); + if (StringUtils.isNotEmpty(type)) { + hql += " and type =:type"; + p.put("type", type); + } + + String serId = (String) parameter.get("serId"); + if (StringUtils.isNotEmpty(serId)) { + hql += " and serId =:serId"; + p.put("serId", serId); + } + String tag = (String) parameter.get("tag"); + // tag = 1 鏌ヨ椋庢満绫诲瀷鐨勮澶囷紝tag = 2 鏌ヨ鐓ф槑璁惧锛屽惁鍒欐槸鍏朵綑鐨勫叾瀹冭澶� + if (StringUtils.isNotEmpty(tag) && "1".equals(tag)) { + hql += " and type in (:types)"; + p.put("types", new String[]{"02", "03", "04", "0C", "0D"}); + } else if (StringUtils.isNotEmpty(tag) && "2".equals(tag)) { + hql += " and type =:type"; + p.put("type", "06"); + } else { + hql += " and type not in (:types)"; + p.put("types", new String[]{"02", "03", "04", "0C", "0D"}); + } + hql += " order by type,id"; + return this.query(hql, p); + } } -- Gitblit v1.9.3