4ssss

package com.kingdee.eas.auto4s.prt.yd.vm.vi.app;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.eas.basedata.org.OrgUnitInfo;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.framework.report.util.RptParams;
import com.kingdee.eas.framework.report.util.RptRowSet;
import com.kingdee.eas.util.app.DbUtil;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.log4j.Logger;

public class RepairWOSAReportFacadeControllerBean extends AbstractRepairWOSAReportFacadeControllerBean
{
private static Logger logger = Logger.getLogger("com.kingdee.eas.auto4s.prt.yd.vm.vi.app.RepairWOSAReportFacadeControllerBean");

public RptParams createTempTable(Context ctx, RptParams params)
throws BOSException, EASBizException
{
dropTempTable(params.getString("tempTable"), ctx);

String tempTable = "tempTable";
tempTable = createTempTableAndInsertData(ctx, tempTable, params);

RptParams result = new RptParams();
result.setString("tempTable", tempTable);
return result;
}

public String createTempTableAndInsertData(Context ctx, String tempTable, RptParams params)
throws BOSException
{
String createSql = createTempTable(ctx, tempTable, params);
tempTable = createTempTable(ctx, createSql);

String insertSql = insertTempTable(ctx, tempTable, params);
DbUtil.execute(ctx, insertSql);

return tempTable;
}

public String createTempTable(Context ctx, String tempTable, RptParams params)
{
StringBuffer sql = new StringBuffer();

sql.append(" Create Table " + tempTable + "( \n");
sql.append(" saName NVARCHAR(255) ,actualCount NUMERIC(28,10) , mechanieCount NUMERIC(28,10), \n");
sql.append(" paintCount NUMERIC(28,10) ,revenues NUMERIC(28,10) , timeAmount NUMERIC(28,10), \n");
sql.append(" timeCost NUMERIC(28,10) ,timeRate NVARCHAR(255) , timeMargin NUMERIC(28,10), \n");
sql.append(" timeMarginRate NVARCHAR(255) ,sparepartAmount NUMERIC(28,10) , sparepartCost NUMERIC(28,10), \n");
sql.append(" sparepartRate NVARCHAR(255) ,sparepartMargin NUMERIC(28,10) , sparepartMarginRate NVARCHAR(255), \n");
sql.append(" singleMargin NUMERIC(28,10) ,singleMarginRate NVARCHAR(255) \n");
sql.append(" );");
return sql.toString();
}

public String insertTempTable(Context ctx, String tempTable, RptParams params)
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date beginDate = (Date)params.getObject("beginDate");
Date endDate = (Date)params.getObject("endDate");

OrgUnitInfo orgUnit = (OrgUnitInfo)params.getObject("orgUnit");
String begin = sdf.format(beginDate);
String end = sdf.format(endDate);

StringBuffer filterSql = new StringBuffer();
filterSql.append(" RepairWO.FComeTime >= {ts '" + begin + "'} and \n");
filterSql.append(" RepairWO.FComeTime <= {ts '" + end + " 23:59:59'} and \n");
filterSql.append(" RepairWO.FOrgUnitID = '" + orgUnit.getId() + "' \n");

StringBuffer sumSql = new StringBuffer();
sumSql.append(" select person.fid personID , \n");
sumSql.append(" (case when revenuesSql.totalAmount is null then 0 else revenuesSql.totalAmount end) + \n");
sumSql.append(" (case when RepairClaimSql.totalAmount is null then 0 else RepairClaimSql.totalAmount end) + \n");
sumSql.append(" (case when otherSql.totalAmount is null then 0 else otherSql.totalAmount end) totalAmount, \n");

sumSql.append(" (case when revenuesSql.timeAmount is null then 0 else revenuesSql.timeAmount end) + \n");
sumSql.append(" (case when RepairClaimSql.timeAmount is null then 0 else RepairClaimSql.timeAmount end) + \n");
sumSql.append(" (case when otherSql.timeAmount is null then 0 else otherSql.timeAmount end) timeAmount , \n");

sumSql.append(" (case when revenuesSql.spamount is null then 0 else revenuesSql.spamount end) + \n");
sumSql.append(" (case when RepairClaimSql.spamount is null then 0 else RepairClaimSql.spamount end) + \n");
sumSql.append(" (case when otherSql.spamount is null then 0 else otherSql.spamount end) spamount \n");

sumSql.append(" from T_ATS_RepairWO RepairWO \n");

sumSql.append(" left outer join T_BD_Person person \n");
sumSql.append(" on RepairWO.FSAID = person.fid \n");

sumSql.append(" left outer join ( \n");
sumSql.append(" select sum(Repairwarranty.FTotalAmount) totalAmount, sum(Repairwarranty.FWorkTimeAmount) timeAmount , \n");
sumSql.append(" sum(Repairwarranty.FSPAmount) spamount , RepairWO.FSAID said \n");
sumSql.append(" from T_ATS_RepairWO RepairWO \n");
sumSql.append(" inner join T_ATS_Repairwarranty Repairwarranty \n");
sumSql.append(" on Repairwarranty.FRepairWOID = repairWO.fid \n");
sumSql.append(" inner join T_ATS_RepairType RepairType \n");
sumSql.append(" on RepairWO.FRepairTypeID = RepairType.fid \n");
sumSql.append(" where RepairType.fnumber = '001' or RepairType.fnumber = '002' and \n");
sumSql.append(filterSql);
sumSql.append(" group by RepairWO.FSAID \n");
sumSql.append(" ) revenuesSql on revenuesSql.said = person.fid \n");

sumSql.append(" left outer join ( \n");
sumSql.append(" select sum(RepairClaim.FTotalAmount) totalAmount, sum(RepairClaim.FWorkTimeAmount) timeAmount , \n");
sumSql.append(" sum(RepairClaim.FSPAmount) spamount , RepairWO.FSAID said \n");
sumSql.append(" from T_ATS_RepairWO RepairWO \n");
sumSql.append(" inner join T_ATS_RepairClaim RepairClaim \n");
sumSql.append(" on RepairClaim.FRepairWOID = repairWO.fid \n");
sumSql.append(" inner join T_ATS_RepairType RepairType \n");
sumSql.append(" on RepairWO.FRepairTypeID = RepairType.fid \n");
sumSql.append(" where RepairType.fnumber = '006' and \n");
sumSql.append(filterSql);
sumSql.append(" group by RepairWO.FSAID \n");
sumSql.append(" ) RepairClaimSql on RepairClaimSql.said = person.fid \n");

sumSql.append(" left outer join ( \n");
sumSql.append(" select sum(RepairWO.FRepairTotalAmount) totalAmount,sum(itemEntry.FARAmount) timeAmount, \n");
sumSql.append(" sum(partEntry.FARAmount) spamount , RepairWO.FSAID said \n");
sumSql.append(" from T_ATS_RepairWO RepairWO \n");
sumSql.append(" left join T_ATS_RWORepairItemEntry itemEntry \n");
sumSql.append(" on itemEntry.FParentID = RepairWO.fid \n");
sumSql.append(" left join T_ATS_RWOSparepartEntry partEntry \n");
sumSql.append(" on partEntry.FParentID = RepairWO.fid \n");
sumSql.append(" inner join T_ATS_RepairType RepairType \n");
sumSql.append(" on RepairWO.FRepairTypeID = RepairType.fid \n");
sumSql.append(" where RepairType.fnumber != '006' and RepairType.fnumber != '001' and RepairType.fnumber != '002' and \n");
sumSql.append(filterSql);
sumSql.append(" group by RepairWO.FSAID \n");
sumSql.append(" ) otherSql on otherSql.said = person.fid \n");

sumSql.append("where ").append(filterSql);
sumSql.append(" group by person.fid , \n");
sumSql.append(" revenuesSql.totalAmount , RepairClaimSql.totalAmount,otherSql.totalAmount , \n");
sumSql.append(" revenuesSql.timeAmount , RepairClaimSql.timeAmount,otherSql.timeAmount, \n");
sumSql.append(" revenuesSql.spamount , RepairClaimSql.spamount,otherSql.spamount \n");

StringBuffer sql = new StringBuffer();
sql.append(" insert into " + tempTable + " \n");

sql.append(" select \n");
sql.append(" person.fname_l2 personName, actualSql.actualCount actualCount, \n");
sql.append(" mechanieSql.mechanieCount mechanieCount, paintSql.paintCount paintCount, \n");
sql.append(" sumSql.totalAmount totalAmount, sumSql.timeAmount timeAmount, sum(itemEntry.FWorkTimeCost) timeCost ,\n");
sql.append(" round((case when sumSql.totalAmount is null then 0 when sumSql.totalAmount = 0 then 0 else sumSql.timeAmount/sumSql.totalAmount end)*100 , 2)||'%' timeRate ,\n");
sql.append(" sumSql.timeAmount - sum(itemEntry.FWorkTimeCost) timeMargin , \n");
sql.append(" round((case when sumSql.timeAmount is null then 0 when sumSql.timeAmount = 0 then 0 else (sumSql.timeAmount - sum(itemEntry.FWorkTimeCost))/sumSql.timeAmount end)*100 , 2)||'%' timeMarginRate , \n");
sql.append(" sumSql.spamount spamount , sum(saleIssue.fTotalActualCost) sparepartCost , \n");
sql.append(" round((case when sumSql.totalAmount is null then 0 when sumSql.totalAmount = 0 then 0 else sumSql.spamount /sumSql.totalAmount end)*100 , 2)||'%' sparepartRate , \n");
sql.append(" sumSql.spamount - sum(saleIssue.fTotalActualCost) sparepartMargin , \n");
sql.append(" round((case when sumSql.spamount is null then 0 when sumSql.spamount = 0 then 0 else (sumSql.spamount - sum(saleIssue.fTotalActualCost))/sumSql.spamount end)*100 , 2)||'%' sparepartMarginRate , \n");
sql.append(" sumSql.timeAmount - sum(itemEntry.FWorkTimeCost) + sumSql.spamount - sum(saleIssue.fTotalActualCost) singleMargin , \n");
sql.append(" round((case when sumSql.totalAmount is null then 0 when sumSql.totalAmount = 0 then 0 else \n");
sql.append(" (sumSql.timeAmount - sum(itemEntry.FWorkTimeCost) + sumSql.spamount - sum(saleIssue.fTotalActualCost))/sumSql.totalAmount end)*100 , 2)||'%' timeRate \n");

sql.append(" from T_ATS_RepairWO RepairWO \n");

sql.append(" left outer join T_BD_Person person \n");
sql.append(" on RepairWO.FSAID = person.fid \n");

sql.append(" left join T_ATS_RWORepairItemEntry itemEntry \n");
sql.append(" on itemEntry.FParentID = RepairWO.fid \n");

sql.append(" left outer join ( \n");

sql.append(" select count(*) actualCount, actual.said said from ( \n");
sql.append(" select count(*) actualCount , RepairWO.FSAID said \n");
sql.append(" from T_ATS_RepairWO RepairWO where ").append(filterSql).append("\n");
sql.append(" group by TO_CHAR(RepairWO.FComeTime,'yyyy-MM-DD') , RepairWO.FVehicleID , RepairWO.FSAID) actual \n");
sql.append(" group by actual.said \n");
sql.append(" ) actualSql on actualSql.said = person.fid \n");

sql.append(" left outer join ( \n");
sql.append(" select count(*) mechanieCount, mechanie.said said from ( \n");
sql.append(" select count(*) mechanieCount , RepairWO.FSAID said \n");
sql.append(" from T_ATS_RepairWO RepairWO \n");
sql.append(" left join T_ATS_RepairType RepairType \n");
sql.append(" on RepairWO.FRepairTypeID = RepairType.fid \n");
sql.append(" where RepairType.fnumber != '006' and RepairType.fnumber != '011' and\n");
sql.append(filterSql).append("\n");
sql.append(" group by TO_CHAR(RepairWO.FComeTime,'yyyy-MM-DD') , RepairWO.FVehicleID , RepairWO.FSAID ) mechanie \n");
sql.append(" group by mechanie.said \n");
sql.append(" ) mechanieSql on mechanieSql.said = person.fid \n");

sql.append(" left outer join ( \n");
sql.append(" select count(*) paintCount, paint.said said from ( \n");
sql.append(" select count(*) paintCount , RepairWO.FSAID said \n");
sql.append(" from T_ATS_RepairWO RepairWO \n");
sql.append(" left join T_ATS_RepairType RepairType \n");
sql.append(" on RepairWO.FRepairTypeID = RepairType.fid \n");
sql.append(" where RepairType.fnumber = '006' or RepairType.fnumber = '011' \n");
sql.append(" group by TO_CHAR(RepairWO.FComeTime,'yyyy-MM-DD') , RepairWO.FVehicleID , RepairWO.FSAID ) paint \n");
sql.append(" group by paint.said \n");
sql.append(" ) paintSql on paintSql.said = person.fid \n");

sql.append(" left outer join ( ").append(sumSql).append(") sumSql \n");
sql.append(" on sumSql.personID = person.fid \n");

sql.append(" left outer join T_IM_SaleIssueBill saleIssue \n");
sql.append(" on saleIssue.fsourcebillid = RepairWO.fid \n");

sql.append("where ").append(filterSql);
sql.append(" group by person.fname_l2 , actualSql.actualCount,mechanieSql.mechanieCount,paintSql.paintCount ,\n");
sql.append(" sumSql.totalAmount , sumSql.timeAmount , sumSql.spamount \n");
System.out.println("SQL打印:" + sql.toString());
return sql.toString();
}

protected RptParams _query(Context ctx, RptParams params, int from, int len)
throws BOSException, EASBizException
{
RptRowSet rs = executeQuery("select * from " + params.getString("tempTable"), null, from, len, ctx);
RptParams pp = new RptParams();
pp.setObject("rowset", rs);
return pp;
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值