- 1
- 2
insrtQuery.append(",?,?,?,?,?,?,?,?,?,?,?,?,?,?")
.append(",?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");//
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
Всего: 4
−55
insrtQuery.append(",?,?,?,?,?,?,?,?,?,?,?,?,?,?")
.append(",?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");//
SQL building еб вашу мать!!!!!!!
+69
private static <T extends Contract> Class getClazz(T contract) {
return contract instanceof ContractLease ? ContractLease.class :
contract instanceof ContractPlantsSale ? ContractPlantsSale.class :
contract instanceof ContractForestWorks ? ContractForestWorks.class :
contract instanceof ContractPermanent ? ContractPermanent.class :
contract instanceof ContractForestDeclaration ? ContractForestDeclaration.class :
contract instanceof ContractReport ? ContractReport.class : null;
Обожаю такие штуки, такая красивая лесенка...
+142
if (filter != null)
for (FilterItem item : filter.getItems()) {
if (StringUtils.isBlank(item.getProperty()) || StringUtils.isBlank(item.getValue())) {
log.warn("Skipping wrong filter: {}", PrintHelper.objectToString(item));
continue;
}
String property = item.getProperty().trim();
String value = item.getValue().trim();
if (property.equals(USER_ACCESS_LEVEL)) {
this.accessLevelType = Integer.valueOf(value);
paramsMap.put("user_access_level_type.id", ":" + USER_ACCESS_LEVEL);
valuesMap.put(USER_ACCESS_LEVEL, this.accessLevelType);
} if (property.equals(USER_TYPE)) {
this.userType = Integer.valueOf(value);
paramsMap.put("user_type.id", ":" + USER_TYPE);
valuesMap.put(USER_TYPE, this.userType);
} if (property.equals(FEDERAL_DISTRICT_ID)) {
this.federalDistrictId = Integer.valueOf(value);
paramsMap.put("user_org_detail.federal_district_fkey", ":" + FEDERAL_DISTRICT_ID);
valuesMap.put(FEDERAL_DISTRICT_ID, this.federalDistrictId);
} if (property.equals(CONSTITUENT_ENTITY_ID)) {
this.constituentEntityId = Integer.valueOf(value);
paramsMap.put("user_org_detail.constituent_entity_fkey", ":" + CONSTITUENT_ENTITY_ID);
valuesMap.put(CONSTITUENT_ENTITY_ID, this.constituentEntityId);
} if (property.equals(FORESTRY_ID)) {
this.forestryId = value;
paramsMap.put("user_org_detail.forestry_fkey", ":" + FORESTRY_ID);
valuesMap.put(FORESTRY_ID, this.forestryId);
} if (property.equals(USER_ROLE_ID)) {
this.userRoleId = value;
paramsMap.put("user_role.role_fkey", ":" + USER_ROLE_ID);
valuesMap.put(USER_ROLE_ID, this.userRoleId);
} if (property.equals(USER_LOGIN)) {
this.userLogin = value;
paramsMap.put("usr.login", ":" + USER_LOGIN);
valuesMap.put(USER_LOGIN, "%" + this.userLogin + "%");
} if (property.equals(USER_NAME)) {
this.userName = value;
String[] query = this.userName.split(" ");
String[] fnamePlaceholders = {};
String[] lnamePlaceholders = {};
String[] mnamePlaceholders = {};
for (int i = 0; i < query.length; i++) {
String fname = ":first_name_" + i;
fnamePlaceholders = ArrayUtils.add(fnamePlaceholders, fname);
String lname = ":last_name_" + i;
lnamePlaceholders = ArrayUtils.add(lnamePlaceholders, lname);
String mname = ":middle_name_" + i;
mnamePlaceholders = ArrayUtils.add(mnamePlaceholders, mname);
valuesMap.put("first_name_" + i, "%" + query[i] + "%");
valuesMap.put("last_name_" + i, "%" + query[i] + "%");
valuesMap.put("middle_name_" + i, "%" + query[i] + "%");
}
userParams.put("usr.first_name", fnamePlaceholders);
userParams.put("usr.last_name", lnamePlaceholders);
userParams.put("usr.middle_name", mnamePlaceholders);
} if (property.equals(USER_STATUS)) {
this.userStatus = value;
paramsMap.put("usr.status", ":" + USER_STATUS);
valuesMap.put(USER_STATUS, this.userStatus);
} if (property.equals(PARTY_NAME)) {
this.partyName = value;
String[] query = value.split(" ");
String[] fnamePlaceholders = {};
String[] lnamePlaceholders = {};
String[] mnamePlaceholders = {};
for (int i = 0; i < query.length; i++) {
String fname = ":person_first_name_" + i;
fnamePlaceholders = ArrayUtils.add(fnamePlaceholders, fname);
String lname = ":person_last_name_" + i;
lnamePlaceholders = ArrayUtils.add(lnamePlaceholders, lname);
String mname = ":person_mid_name_" + i;
mnamePlaceholders = ArrayUtils.add(mnamePlaceholders, mname);
valuesMap.put("person_first_name_" + i, "%" + query[i] + "%");
valuesMap.put("person_last_name_" + i, "%" + query[i] + "%");
valuesMap.put("person_mid_name_" + i, "%" + query[i] + "%");
}
partyParams.put("party.person_first_name", fnamePlaceholders);
partyParams.put("party.person_last_name", lnamePlaceholders);
partyParams.put("party.person_mid_name", mnamePlaceholders);
partyParams.put("party.party_name", new String[]{":party_name"});
valuesMap.put("party_name", "%" + this.partyName + "%");
} if (property.equals(PARTY_INN)) {
this.partyInn = value;
paramsMap.put("party.inn", ":" + PARTY_INN);
valuesMap.put(PARTY_INN, this.partyInn);
} if (property.equals(USER_IS_MASTER)) {
this.userIsMaster = Boolean.valueOf(value);
paramsMap.put("user_org_detail.organization_master", ":" + USER_IS_MASTER);
конструктор для named jdbc
... если долго смотреть на строки, можно увидеть жирафа...
+71
@Override
List search(Long ownerId, Long projectId, String docnumber, String ctr1, String ctr2, Long dateFrom, Long dateTo, String contract,
Double amountFrom, Double amountTo, Double vatAmountFrom, Double vatAmountTo, Double withVatAmountFrom,
Double withVatAmountTo, Boolean defect, DocumentDefect d, Long vatId, Integer limit, String sortField, String order, String docType) {
// доступные проекты
List projects = projectDAO.findAll(ownerId)
if(!projects){
logger.warn("Ошибка отображения списка документов: нет доступных проектов: ownerId:$ownerId")
return []
}
Criteria criteria = currentSession.createCriteria(DocumentView)
.createAlias("document", "d")//
.createAlias("d.project", "p")//
.add(Restrictions.in("p.id", projects.id))//
// if(projectId)
// criteria.add(Restrictions.eq("d.project.id", projectId))
if (docnumber)
criteria.add(Restrictions.ilike("docNumber", docnumber, MatchMode.ANYWHERE))
if (ctr1)
criteria.add(Restrictions.ilike("supplierName", ctr1, MatchMode.ANYWHERE))
if (ctr2)
criteria.add(Restrictions.ilike("customerName", ctr2, MatchMode.ANYWHERE))
if (dateFrom) {
Calendar date1 = Calendar.instance
date1.setTime(new Date(dateFrom))
criteria.add(Restrictions.ge("docDate", date1))
}
if (dateTo) {
Calendar date1 = Calendar.instance
date1.setTime(new Date(dateTo))
date1.add(Calendar.DAY_OF_MONTH, 1)
criteria.add(Restrictions.lt("docDate", date1))
}
if (contract)
criteria.add(Restrictions.ilike("contract", contract, MatchMode.ANYWHERE))
if (amountFrom)
criteria.add(Restrictions.ge("amount", amountFrom))
if (amountTo)
criteria.add(Restrictions.le("amount", amountTo))
if (vatAmountFrom)
criteria.add(Restrictions.ge("vatAmount", vatAmountFrom))
if (vatAmountTo)
criteria.add(Restrictions.le("vatAmount", vatAmountTo))
if (withVatAmountFrom)
criteria.add(Restrictions.ge("totalAmount", withVatAmountFrom))
if (withVatAmountTo)
criteria.add(Restrictions.le("totalAmount", withVatAmountTo))
if (defect) {
criteria.add(Restrictions.isNotNull("defect"))
if (d)
criteria.add(Restrictions.eq("defect", d))
}
// if (vatId)
// criteria.add(Restrictions.eq("d.", withVatAmountTo))
if (docType) {
def dt = DocumentType.values().find { it.link == docType || it.code == docType }
if (dt)
criteria.add(Restrictions.like("docLink", dt.code, MatchMode.START))
else
logger.error("Неправильное значение параметра фильтрации по виду документа [d_t:$docType]. Допустимые значения ${DocumentType.values().code}")
}
// получаем общее кол-во записей без ограничений по странице
def rowCount = criteria.setProjection(Projections.rowCount()).uniqueResult() as Integer
List result = criteria.setProjection(null)//
.setResultTransformer(Criteria.ROOT_ENTITY)//
.addOrder(Order."$order"(sortField))//
.setMaxResults(limit)//
.list()
[rowCount, result]
}
поиск ?!