/* */ package com.midea.common.dao; /* */ /* */ import com.midea.common.dao.filter.QueryResInterceptor; /* */ import com.midea.common.dao.filter.ResEnumInter; /* */ import com.midea.common.utils.BeanUtils; /* */ import com.midea.common.utils.GenericsUtils; /* */ import com.midea.common.vo.PageInfo; /* */ import com.midea.common.vo.QueryRule; /* */ import java.io.Serializable; /* */ import java.util.ArrayList; /* */ import java.util.Iterator; /* */ import java.util.List; /* */ import java.util.Map; /* */ import java.util.Set; /* */ import org.hibernate.Criteria; /* */ import org.hibernate.Session; /* */ import org.hibernate.criterion.CriteriaSpecification; /* */ import org.hibernate.criterion.Order; /* */ import org.hibernate.criterion.Projection; /* */ import org.hibernate.criterion.Projections; /* */ import org.hibernate.internal.CriteriaImpl; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public class BaseDaoHibernate/* */ extends EntityDaoHibernate /* */ implements BaseDao /* */ { /* */ protected Class entityClass; /* */ /* */ public BaseDaoHibernate() /* */ { /* 41 */ entityClass = GenericsUtils.getSuperClassGenricType(super.getClass()); /* */ } /* */ /* */ public BaseDaoHibernate(Class persistentClass) { /* 45 */ entityClass = persistentClass; /* */ } /* */ /* */ /* */ public T get(PK paramPK) /* */ { /* 51 */ return (Serializable)super.getSession().get(entityClass, paramPK); /* */ } /* */ /* */ public List getAll() { /* 55 */ return find(QueryRule.getInstance()); /* */ } /* */ /* */ public boolean exists(PK paramPK) { /* 59 */ Object entity = getSession().get(entityClass, paramPK); /* 60 */ return entity != null; /* */ } /* */ /* */ public void save(T object) { /* 64 */ getSession().saveOrUpdate(object); /* */ } /* */ /* */ public void update(T object) { /* 68 */ getSession().update(object); /* */ } /* */ /* */ public void deleteByPK(PK paramPK) { /* 72 */ delete(get(paramPK)); /* */ } /* */ /* */ public void delete(T object) { /* 76 */ getSession().delete(object); /* */ } /* */ /* */ public void merge(T object) { /* 80 */ getSession().merge(object); /* */ } /* */ /* */ public List find(QueryRule queryRule) /* */ { /* 85 */ Criteria criteria = getSession().createCriteria(entityClass); /* 86 */ QueryRuleUtils.createCriteriaWithQueryRule(criteria, queryRule); /* */ /* 88 */ List orders = QueryRuleUtils.getOrderFromQueryRule(queryRule); /* 89 */ for (Order o : orders) { /* 90 */ criteria.addOrder(o); /* */ } /* 92 */ return criteria.setFirstResult(0).list(); /* */ } /* */ /* */ public PageInfo find(QueryRule queryRule, int pageNo, int pageSize) { /* 96 */ ResEnumInter resEnumInter = (ResEnumInter)QueryResInterceptor.keyLocal.get(); /* 97 */ pageNo = pageNo <= 0 ? 1 : pageNo; /* 98 */ pageSize = pageSize <= 0 ? 10 : pageSize; /* */ /* 100 */ PageInfo pageInfo = new PageInfo(pageNo, pageSize); /* 101 */ Criteria criteria = getSession().createCriteria(entityClass); /* 102 */ QueryRuleUtils.createCriteriaWithQueryRule(criteria, queryRule); /* 103 */ CriteriaImpl impl = (CriteriaImpl)criteria; /* */ /* 105 */ Projection projection = impl.getProjection(); /* */ try { /* 107 */ List orderEntries = (List)BeanUtils.forceGetProperty(impl, "orderEntries"); /* 108 */ BeanUtils.forceSetProperty(impl, "orderEntries", new ArrayList()); /* */ } catch (Exception e) { /* 110 */ throw new InternalError(" Runtime Exception impossibility throw "); /* */ } /* 112 */ List orderEntries = new ArrayList(); /* 113 */ int totalCount = 0; /* 114 */ criteria.setProjection(Projections.rowCount()); /* 115 */ if (criteria.uniqueResult().getClass().getName().equals("java.lang.Long")) { /* 116 */ totalCount = Integer.parseInt(criteria.uniqueResult().toString()); /* */ } else { /* 118 */ totalCount = Integer.parseInt((String)criteria.uniqueResult()); /* */ } /* 120 */ if (totalCount < 1) { /* 121 */ return pageInfo; /* */ } /* */ /* 124 */ pageInfo.setTotalCount(totalCount); /* 125 */ if (pageNo > pageInfo.getTotalPageCount()) { /* 126 */ pageNo = pageInfo.getTotalPageCount(); /* 127 */ pageInfo.setPageNo(pageNo); /* */ } /* */ /* 130 */ criteria.setProjection(projection); /* 131 */ if (projection == null) /* 132 */ criteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY); /* */ try { /* 134 */ BeanUtils.forceSetProperty(impl, "orderEntries", orderEntries); /* */ } catch (Exception e) { /* 136 */ throw new InternalError(" Runtime Exception impossibility throw "); /* */ } /* */ /* 139 */ List orders = QueryRuleUtils.getOrderFromQueryRule(queryRule); /* 140 */ for (Order o : orders) { /* 141 */ criteria.addOrder(o); /* */ } /* */ /* 144 */ if (resEnumInter != null) { /* 145 */ QueryResInterceptor.keyLocal.set(resEnumInter); /* */ } /* 147 */ int startIndex = PageInfo.getStartIndex(pageNo, pageSize); /* 148 */ List data = criteria.setFirstResult(startIndex).setMaxResults(pageSize).list(); /* 149 */ pageInfo.setData(data); /* 150 */ return pageInfo; /* */ } /* */ /* */ public List findList(QueryRule queryRule, int start, int count) { /* 154 */ start = start < 0 ? 0 : start; /* 155 */ count = count < 0 ? 0 : count; /* */ /* 157 */ Criteria criteria = getSession().createCriteria(entityClass); /* 158 */ QueryRuleUtils.createCriteriaWithQueryRule(criteria, queryRule); /* */ /* 160 */ List orders = QueryRuleUtils.getOrderFromQueryRule(queryRule); /* 161 */ for (Order o : orders) { /* 162 */ criteria.addOrder(o); /* */ } /* 164 */ return criteria.setFirstResult(start).setMaxResults(count).list(); /* */ } /* */ /* */ public T findUnique(String propertyName, Object value) { /* 168 */ QueryRule queryRule = QueryRule.getInstance(); /* 169 */ queryRule.addEqual(propertyName, value); /* 170 */ return findUnique(queryRule); /* */ } /* */ /* */ public T findUnique(Map properties) { /* 174 */ QueryRule queryRule = QueryRule.getInstance(); /* 175 */ for (Iterator iterator = properties.keySet().iterator(); iterator.hasNext();) { /* 176 */ String key = (String)iterator.next(); /* 177 */ queryRule.addEqual(key, properties.get(key)); /* */ } /* 179 */ return findUnique(queryRule); /* */ } /* */ /* */ public T findUnique(QueryRule queryRule) { /* 183 */ List list = find(queryRule); /* 184 */ if (list.isEmpty()) { /* 185 */ return null; /* */ } /* 187 */ if (list.size() == 1) /* */ { /* 189 */ return (Serializable)list.get(0); /* */ } /* 191 */ throw new IllegalStateException("findUnique return " + list.size() + " record(s)."); /* */ } /* */ } /* Location: E:\mavenRepo\repo\com\midea\common\1.3.3\common-1.3.3.jar * Qualified Name: com.midea.common.dao.BaseDaoHibernate * Java Class Version: 7 (51.0) * JD-Core Version: 0.7.1 */
/** * Description:设备改名Dao * Created on 2015年10月16日 * * Copyright(C) 2015, by Midea company. * Original Author: mengdelong * Contributor(s): * * Changes * ------- * Log: * */ package com.proserver.dao; import java.util.ArrayList; import java.util.List; import org.springframework.stereotype.Component; import com.midea.common.dao.BaseDaoHibernate; import com.midea.common.vo.QueryRule; import com.proserver.model.DataBase.DeviceInfoModel; @Component("deviceInfoDao") public class DeviceInfoDao extends BaseDaoHibernate{ // /** // * @Description: 添加DeviceRename对象 // * @param deviceInfoModel // * @return boolean // * @author mengdelong // * @date 2015年10月16日 // */ // public boolean addDeviceInfo(DeviceInfoModel deviceInfoModel) { // try { // this.getSession().save(deviceInfoModel); // return true; // } catch (Exception e) { // e.printStackTrace(); // return false; // } // } /** * @Description: 根据virtualId获取DeviceInfoModel对象 * @param virtualId * @author mengdelong * @date 2015年10月19日 */ public DeviceInfoModel getByVirtualId(String virtualId) { QueryRule queryRule = QueryRule.getInstance(); queryRule.addEqual("virtualId", virtualId); DeviceInfoModel deviceInfoModel = this.findUnique(queryRule); return deviceInfoModel; } // /** // * @Description: 根据virtualId修改设备名称 // * @param deviceName // * @param virtualId // * @author mengdelong // * @date 2015年10月21日 // */ // public void updateDeviceNameByVirtualId(String deviceName, String virtualId) { // String hql = "update DeviceInfoModel set deviceName = ? where virtualId = ?"; // this.executeHql(hql, new Object[] { deviceName, virtualId }); // } // // /** // * @Description: 根据virtualId修改设备名称和更新修改时间 // * @param deviceName // * @param modifyTime // * @param virtualId // * @author chencq // * @date 2015年10月22日 // */ // public void updateDeviceNameByVirtualId(String deviceName, long modifyTime, String virtualId) { // String hql = "update DeviceInfoModel set deviceName = ? ,modifyTime = ? where virtualId = ?"; // this.executeHql(hql, new Object[] { deviceName, modifyTime, virtualId }); // } /** * @param referPhysicalId * @return * @Description: 根据referPhysicalId获取DeviceInfoModel对象 * @author chencq * @date 2016年4月13日 */ public List getByReferPhysicalId(String referPhysicalId) { QueryRule queryRule = QueryRule.getInstance(); queryRule.addEqual("referPhysicalId", referPhysicalId); return this.find(queryRule); } /** * @Description: 获取DeviceInfoModel对象 * @return * @author HuangYongXing * @date 2016年3月31日 */ public List getDeviceInfoModelListAll() { List list = new ArrayList<>(); list = this.getAll(); return list; } /** * @Description: 根据virtualId更新DeviceInfoModel对象 * @param deviceInfoModel * @author chencq * @date 2015年10月22日 */ public void updateDeviceNameByVirtualId(DeviceInfoModel deviceInfoModel) { this.update(deviceInfoModel); } /** * @Description: 根据virtualId删除DeviceInfoModel对象 * @param virtualId * @author mengdelong * @date 2015年10月21日 */ public void deleteByVirtualId(String virtualId) { if (null != getByVirtualId(virtualId)) { this.deleteByPK(virtualId); } } }
/* */ package com.midea.common.vo; /* */ /* */ import java.io.Serializable; /* */ import java.util.ArrayList; /* */ import java.util.Collection; /* */ import java.util.List; /* */ import org.hibernate.criterion.Criterion; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public final class QueryRule /* */ implements Serializable /* */ { /* */ private static final long serialVersionUID = 1L; /* */ public static final int LIKE = 1; /* */ public static final int IN = 2; /* */ public static final int BETWEEN = 3; /* */ public static final int EQ = 4; /* */ public static final int NOTEQ = 5; /* */ public static final int GT = 6; /* */ public static final int GE = 7; /* */ public static final int LT = 8; /* */ public static final int LE = 9; /* */ public static final int SQL = 10; /* */ public static final int ISNULL = 11; /* */ public static final int ISNOTNULL = 12; /* */ public static final int ISEMPTY = 13; /* */ public static final int ISNOTEMPTY = 14; /* */ public static final int OR = 15; /* */ public static final int MAX_RESULTS = 101; /* */ public static final int FIRST_RESULTS = 102; /* */ public static final int ASC_ORDER = 103; /* */ public static final int DESC_ORDER = 104; /* 45 */ private final ListruleList = new ArrayList(); /* */ /* 47 */ private final List queryRuleList = new ArrayList(); /* */ private String propertyName; /* */ /* */ private QueryRule() {} /* */ /* */ private QueryRule(String propertyName) /* */ { /* 54 */ this.propertyName = propertyName; /* */ } /* */ /* */ public static QueryRule getInstance() { /* 58 */ return new QueryRule(); /* */ } /* */ /* */ public QueryRule addAscOrder(String propertyName) { /* 62 */ ruleList.add(new Rule(103, propertyName)); /* 63 */ return this; /* */ } /* */ /* */ public QueryRule addDescOrder(String propertyName) { /* 67 */ ruleList.add(new Rule(104, propertyName)); /* 68 */ return this; /* */ } /* */ /* */ public QueryRule addIsNull(String propertyName) { /* 72 */ ruleList.add(new Rule(11, propertyName)); /* 73 */ return this; /* */ } /* */ /* */ public QueryRule addIsNotNull(String propertyName) { /* 77 */ ruleList.add(new Rule(12, propertyName)); /* 78 */ return this; /* */ } /* */ /* */ public QueryRule addIsEmpty(String propertyName) { /* 82 */ ruleList.add(new Rule(13, propertyName)); /* 83 */ return this; /* */ } /* */ /* */ public QueryRule addIsNotEmpty(String propertyName) { /* 87 */ ruleList.add(new Rule(14, propertyName)); /* 88 */ return this; /* */ } /* */ /* */ public QueryRule addLike(String propertyName, Object value) { /* 92 */ ruleList.add(new Rule(1, propertyName, new Object[] { value })); /* 93 */ return this; /* */ } /* */ /* */ public QueryRule addEqual(String propertyName, Object value) { /* 97 */ ruleList.add(new Rule(4, propertyName, new Object[] { value })); /* 98 */ return this; /* */ } /* */ /* */ public QueryRule addBetween(String propertyName, Object[] values) { /* 102 */ ruleList.add(new Rule(3, propertyName, values)); /* 103 */ return this; /* */ } /* */ /* */ public QueryRule addOr(Criterion criterion1, Criterion criterion2) { /* 107 */ ruleList.add(new Rule(15, "", new Object[] { criterion1, criterion2 })); /* 108 */ return this; /* */ } /* */ /* */ public QueryRule addOrs(Criterion criterion1, Criterion criterion2, Criterion criterion3) { /* 112 */ ruleList.add(new Rule(15, "", new Object[] { criterion1, criterion2, criterion3 })); /* 113 */ return this; /* */ } /* */ /* */ public QueryRule addIn(String propertyName, Collection extends Object> values) { /* 117 */ if ((values == null) || (values.size() == 0)) { /* 118 */ ruleList.add(new Rule(2, propertyName, new Object[0])); /* */ } else { /* 120 */ ruleList.add(new Rule(2, propertyName, new Object[] { values })); /* */ } /* */ /* 123 */ return this; /* */ } /* */ /* */ public QueryRule addIn(String propertyName, Object[] values) { /* 127 */ if ((values == null) || (values.length == 0)) { /* 128 */ values = new Object[0]; /* */ } /* */ /* 131 */ ruleList.add(new Rule(2, propertyName, values)); /* 132 */ return this; /* */ } /* */ /* */ public QueryRule addNotEqual(String propertyName, Object value) { /* 136 */ ruleList.add(new Rule(5, propertyName, new Object[] { value })); /* 137 */ return this; /* */ } /* */ /* */ public QueryRule addGreaterThan(String propertyName, Object value) { /* 141 */ ruleList.add(new Rule(6, propertyName, new Object[] { value })); /* 142 */ return this; /* */ } /* */ /* */ public QueryRule addGreaterEqual(String propertyName, Object value) { /* 146 */ ruleList.add(new Rule(7, propertyName, new Object[] { value })); /* 147 */ return this; /* */ } /* */ /* */ public QueryRule addLessThan(String propertyName, Object value) { /* 151 */ ruleList.add(new Rule(8, propertyName, new Object[] { value })); /* 152 */ return this; /* */ } /* */ /* */ public QueryRule addLessEqual(String propertyName, Object value) { /* 156 */ ruleList.add(new Rule(9, propertyName, new Object[] { value })); /* 157 */ return this; /* */ } /* */ /* */ public QueryRule addSql(String sql) { /* 161 */ ruleList.add(new Rule(10, sql)); /* 162 */ return this; /* */ } /* */ /* */ public QueryRule addSubQueryRule(String propertyName) { /* 166 */ QueryRule queryRule = new QueryRule(propertyName); /* 167 */ queryRuleList.add(queryRule); /* 168 */ return queryRule; /* */ } /* */ /* */ public List getRuleList() { /* 172 */ return ruleList; /* */ } /* */ /* */ public List getQueryRuleList() { /* 176 */ return queryRuleList; /* */ } /* */ /* */ public String getPropertyName() { /* 180 */ return propertyName; /* */ } /* */ /* */ public class Rule implements Serializable { /* */ private static final long serialVersionUID = 1L; /* */ private final int type; /* */ private final String propertyName; /* */ private Object[] values; /* */ /* */ public Rule(int paramInt, String paramString) { /* 190 */ propertyName = paramString; /* 191 */ type = paramInt; /* */ } /* */ /* */ public Rule(int paramInt, String paramString, Object[] paramArrayOfObject) { /* 195 */ propertyName = paramString; /* 196 */ values = paramArrayOfObject; /* 197 */ type = paramInt; /* */ } /* */ /* */ public Object[] getValues() { /* 201 */ return values; /* */ } /* */ /* */ public int getType() { /* 205 */ return type; /* */ } /* */ /* */ public String getPropertyName() { /* 209 */ return propertyName; /* */ } /* */ } /* */ } /* Location: E:\mavenRepo\repo\com\midea\common\1.3.3\common-1.3.3.jar * Qualified Name: com.midea.common.vo.QueryRule * Java Class Version: 7 (51.0) * JD-Core Version: 0.7.1 */
public class Rule implements Serializable {
/* */ private static final long serialVersionUID = 1L;
/* */ private final int type;
/* */ private final String propertyName;
/* */ private Object[] values;
/* */
/* */ public Rule(int paramInt, String paramString) {
/* 190 */ propertyName = paramString;
/* 191 */ type = paramInt;
/* */ }
/* */
/* */ public Rule(int paramInt, String paramString, Object[] paramArrayOfObject) {
/* 195 */ propertyName = paramString;
/* 196 */ values = paramArrayOfObject;
/* 197 */ type = paramInt;
/* */ }
/* */
/* */ public Object[] getValues() {
/* 201 */ return values;
/* */ }
/* */
/* */ public int getType() {
/* 205 */ return type;
/* */ }
/* */
/* */ public String getPropertyName() {
/* 209 */ return propertyName;
/* */ }
/* */ }
/* */ }
//移动端向body输出执行错误信息
function showErrorMsgToBody(msg){
var temp = $("#commonErrorMsgInfo")[0];
if(!temp){
$("body").append('');
}
$("#commonErrorMsgInfo").val(msg); //方法2
}