|
楼主 |
发表于 2018-9-6 14:13:24
|
显示全部楼层
自定义排序已解决。
1.在每个实体类对应的Service层的 setDataGrid()方法中,
在commonService.getDataGridReturn(cq, true);执行前加入如下判断:
//查询条件组装器
org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, employeeDeclare, parameterMap);
if(dataGrid.getSort()==null||"".equals(dataGrid.getSort())) {
//获取优先排序的状态码
Integer lv = jeecgRepo.getDeclareInitStatusNumber(user);
//自定义排序Sql语句
String customFormula = " case this_.declare_status when "+lv+" then 1 when "+(lv-1)+" then 2 when "+(lv-2)+" then 3 ELSE 4 END,this_.declare_status desc";
//新增公共方法 getDataGridReturn
commonRepo.getDataGridReturn(cq,true,"declareStatus",customFormula);
}else {
commonService.getDataGridReturn(cq, true);
}
2.commonRepo.getDataGridReturn()方法中将原先的代码中的排序去掉,替换成
criteria.addOrder(CustomOrder.getOrder(propertyName, customFormula));
而CustomOrder继承Order类
public class CustomOrder extends Order{
// private String propertyName;
private String customFormula;
protected CustomOrder(String propertyName,String customFormula) {
super(propertyName, true);
// this.propertyName=propertyName;
this.customFormula=customFormula;
// TODO Auto-generated constructor stub
}
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)throws HibernateException {
// String[] columns = criteriaQuery.getColumnsUsingProjection(criteria,propertyName);
//customFormula自定义你的字段
//for example
// return " case "+columns[0]+" when 12 then 1 "
// + "when 11 then 2 "
// + "when 10 then 3 "
// + "else 4 end ,"+columns[0]+" desc";
return customFormula;
}
public static CustomOrder getOrder(String propertyName,String customFormula) {
return new CustomOrder(propertyName, customFormula);
}
}
3.在相应申报List.jsp 页面 的dataGrid标签中删掉 sortName="declareStatus" sortOrder="desc" 属性。 |
|