IDataQuery query = session.createDataQuery();
query.setTarget(session.getObjectDef("time_record"));
query.addFilter("hs_is_deleted", SATConstants.SQL_OP_EQUAL, Boolean.FALSE); //Boolean.FALSE
Long week_start_date_Long = new Long(week_start_date);
Long week_end_date_Long = new Long(week_end_date);
String l_date = week_start_date_Long.toString() + "," + week_end_date_Long.toString();
query.addFilter("occurred_date", SATConstants.SQL_OP_BETWEEN, l_date);
IUnaryFunction uf = session.createUnaryFunction(SATConstants.AGGRE_SUM, "hours_spent1"); //对hours_spent域做sum,将sum值存放在hours_spent1中
uf.setFieldDef(session.getObjectDef("time_record").getFieldDef("hours_spent"));
query.addField(uf);
query.addField("record_type");
query.addFilter("project", SATConstants.SQL_OP_EQUAL, projectOid);
IGroupBy gb = query.createGroupBy();
gb.setGroupByField(session.getObjectDef("time_record").getFieldDef("record_type"));
query.addGroupBy(gb);
IDataCollection dc = query.query(session);
double total=0;
while (dc.next()) {
IBusObject bo = dc.getObject();
double hours_spent=bo.getDoubleField("hours_spent1"); //通过hours_spent1获取sum值
total+=hours_spent;
String record_type="";
int weight=0;
IOption option=bo.getSingleSelection("record_type");
if(option!=null){
weight=option.getWeight();
record_type = option.getText(lo_string);
}
Map m = new HashMap(4);
m.put("record_type",record_type);
m.put("weight",""+weight);
m.put("hour_spent", ""+hours_spent);
l.add(m);
}
dc.close();