Потребовался вывод в ЛК учётных периодов с наработкой.
Сделал через web.action. Но как я понял, текущий тренд - делать это через web service?
Помогите переделать это:
Код:
package ru.iks.inet.dyn.xslt;
import org.apache.log4j.Logger;
import org.w3c.dom.Element;
import java.sql.*;
import java.util.*;
import java.math.BigDecimal;
import bitel.billing.common.TimeUtils;
import bitel.billing.server.contract.action.base.ActionBase;
import bitel.billing.server.contract.bean.ContractMemo;
import bitel.billing.server.contract.bean.ContractMemoManager;
import ru.bitel.bgbilling.common.BGException;
import ru.bitel.common.Utils;
import ru.bitel.common.XMLUtils;
import ru.bitel.bgbilling.server.util.Setup;
public class myAP extends ActionBase
{
private static final Logger logger = Logger.getLogger( myAP.class );
int NPAY_MID = 3;
int INET_MID = 1;
int SCRIPT_USERID = 0;
public void myAP()
{
}
public void doAction()
throws BGException
{
setData();
}
protected void setDataForXslt()
{
Connection con;
con = setup.getDBConnectionFromPool();
String query = "select a.id, a.pid, a.dateFrom, a.dateTo, max(r.amount) " +
" from inet_tariff_traffic_range_1 as r left join " +
"( " +
" select o.id, p.id as pid, p.dateFrom, p.dateTo, o.time_from, o.time_to " +
" from inet_accounting_period_1 p left join contract_tariff_option o on p.contractId=o.cid and p.dateFrom=o.time_from " +
" where o.option_id=18 and o.time_from <= curdate() and p.dateTo>=20130401 and o.cid="+ cid +
" order by o.time_from desc " +
" limit 2 " +
") as a on r.rangeKey = (a.id | 0x500000000000000) and r.contractId=" + cid +
" where a.id is not null " +
"group by a.id, a.pid " +
"order by a.time_from";
try {
ResultSet rs = con.prepareStatement( query ).executeQuery();
while(rs.next()){
int oId = rs.getInt(1);
int pId = rs.getInt(2);
Date dateFrom = rs.getDate(3);
Date dateTo = rs.getDate(4);
long traffic = rs.getLong(5);
Element element = createElement(rootNode, "myAccountingPeriodTraffic");
element.setAttribute("contractId", Integer.toString(cid));
element.setAttribute("dateFrom", TimeUtils.format(dateFrom, "yyyy-MM-dd"));
element.setAttribute("dateTo", TimeUtils.format(dateTo, "yyyy-MM-dd"));
element.setAttribute("traffic", String.format("%1.2fMb", (traffic*1.0/1024/1024)));
element.setAttribute("id", Integer.toString(pId));
}
}
catch(Exception e) {
setWebErrorMessage(e.getMessage());
}
}
}
в код web service. И как потом его использовать в xslt?