NC65 活期存款计息提供的查询接口:
package nc.impl.fac.ia;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import nc.bs.fac.ia.InterestAccrualPubBS;
import nc.bs.fac.proxy.AiacOuterServiceProxy;
import nc.bs.framework.common.NCLocator;
import nc.impl.fac.ia.ace.AceDemandintcalQueryImpl;
import nc.itf.bd.bankacc.subinfo.IBankAccSubInfoQueryService;
import nc.itf.fac.demandintlist.IDemandIntListQuery;
import nc.itf.fi.rateconfig.IRateconfigQueryService;
import nc.md.persist.framework.IMDPersistenceQueryService;
import nc.md.persist.framework.MDPersistenceService;
import nc.ui.querytemplate.querytree.IQueryScheme;
import nc.vo.bd.bankaccount.BankAccSubVO;
import nc.vo.fac.ia.AggDemandIntCalVO;
import nc.vo.fac.ia.DemandIntCalVO;
import nc.vo.fac.interestobj.AccInterestObjVO;
import nc.vo.fac.interestobj.AggAccInterestObjVO;
import nc.vo.fac.interestobj.IntAccountInfoVO;
import nc.vo.fac.interestobj.InterestObjVerVO;
import nc.vo.fac.ml.MLFac;
import nc.vo.fac.pub.IFACConst;
import nc.vo.fi.rateconfig.AggRateCodeVO;
import nc.vo.fi.rateconfig.RateCodeVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.pub.lang.UFDate;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.vo.tmpub.ia.setdate.ICDSetupVO;
import nc.vo.tmpub.util.ArrayUtil;
import nc.vo.tmpub.util.SqlUtil;
/**
* 活期存款计息提供的查询接口。
* 查得的计息对象转换为活期计息的VO。
*
* @author liuyga
*
*/
public class DemandintcalQueryImpl extends AceDemandintcalQueryImpl {
/**
* 活期存款计息查询
*/
public AggDemandIntCalVO[] queryByQueryScheme(IQueryScheme queryScheme, String oldfield, String newfield)
throws BusinessException {
AggDemandIntCalVO[] bills = null;
try {
String whereSql = this.preQuery(queryScheme);
whereSql += " and "
+ queryScheme.getWhereSQLOnly().replace(oldfield, newfield);// replace是为了替换两个表中字段差异,计息方式在两个表中字段不同的特殊处理
whereSql = whereSql.replace("intobjcode", "objcode");// replace是为了替换两个表中字段差异,计息对象编码在两个表中字段不同的特殊处理
Collection<?> objvos = getMDQueryService().queryBillOfVOByCond(
AccInterestObjVO.class, whereSql, true, false);
if (objvos != null && objvos.size() != 0) {
bills = convertToDemandIntcalVO(objvos.toArray(new AggAccInterestObjVO[0]));
} else {
bills = null;
}
} catch (Exception e) {
ExceptionUtils.marsh(e);
}
return bills;
}
public boolean checkBankUser(String key) throws BusinessException{
boolean b = false;
String where = "pk_accintobj = "+"'"+ key+"'";
Collection<?> objvos = getMDQueryService().queryBillOfVOByCond(
IntAccountInfoVO.class,where , true, false);
if (objvos.size() > 0) {
int count = 0;
for (Object obj : objvos) {
IntAccountInfoVO vo = (IntAccountInfoVO) obj;
if (vo.getUseflag().booleanValue()
|| vo.getDistroyaccdate() != null) {
count++;
}
}
b = count == objvos.size() ? true : false;
}
return b;
}
/**
* 将计息对象转换为活期计息界面展现的VO
*
* @param intObjs
* @return
* @throws BusinessException
*/
private AggDemandIntCalVO[] convertToDemandIntcalVO(
AggAccInterestObjVO[] intObjs) throws BusinessException {
// 取组织、计息对象PK,用来批量查询最近结息日
Map<String, List<String>> orgIntObjMap = new HashMap<String, List<String>>();
// 结息日PK,用来批量查询结息日设置
Set<String> ICDSetupSet = new HashSet<String>();
// 银行账户PK,用来批量查询银行账户信息
Set<String> bankAcc = new HashSet<String>();
// 利率PK,用来批量查询利率配置信息
Set<String> iRateSet = new HashSet<String>();
for (AggAccInterestObjVO agg : intObjs) {
AccInterestObjVO objvo = agg.getParentVO();
IntAccountInfoVO[] accinfovos = agg.getIntAccountInfoVO(); //计息对象账户信息
InterestObjVerVO[] allVersions = agg.getInterestObjVerVO(); //计息对象版本信息
objvo.setRatecode(allVersions[allVersions.length - 1].getPk_ratecode()); //最后一个版本
InterestObjVerVO maxver = allVersions[0];
for(InterestObjVerVO ver : allVersions ){
if(Integer.valueOf(maxver.getVersion())<Integer.valueOf(ver.getVersion())){
maxver = ver;
}
}
objvo.setPk_settledate(maxver.getSettledate());
String pk_org = objvo.getPk_org();
if (IFACConst.COMBINATION.equals(objvo.getIntmode())) {// 合并计息
addKeyValueToMap(orgIntObjMap, pk_org, objvo.getPk_accintobj());
} else if (IFACConst.ONEBYONE.equals(objvo.getIntmode())) {// 分别计息
if (accinfovos != null && accinfovos.length > 0) {
for (IntAccountInfoVO accvo : accinfovos) {
addKeyValueToMap(orgIntObjMap, pk_org, accvo.getPk_intaccinfo()); //类似分组
String bankAccid = accvo.getPk_accid(); //账户编码=ref 银行账户子户
if (!bankAcc.contains(bankAccid)) {
bankAcc.add(bankAccid);
}
}
}
}
// 结息日设置的PK
String settleDatePk = objvo.getPk_settledate();
if (!ICDSetupSet.contains(settleDatePk)) {
ICDSetupSet.add(settleDatePk);
}
// 利率PK
String ratecode = objvo.getRatecode();
if (!iRateSet.contains(ratecode)) {
iRateSet.add(ratecode);
}
}
// 批量查询利率设置 存储为: 利率PK->利率编码、利率名称
Map<String, RateCodeVO> iRateCodeMap = new HashMap<String, RateCodeVO>();
String[] ratePks = iRateSet.toArray(new String[0]);
Collection<AggRateCodeVO> rateCodeVOs = getIRateCodeService().queryRateconfigByPKS(ratePks, null);
for (AggRateCodeVO aggvo : rateCodeVOs) {
RateCodeVO vo = (RateCodeVO) aggvo.getParent();
iRateCodeMap.put((String) vo.getAttributeValue(RateCodeVO.PK_RATECODE), vo);
}
// 批量查询结息日设置 存储为: 结息日PK->结息日设置VO
Map<String, ICDSetupVO> ICDSetupMap = new InterestAccrualPubBS().getICDSetupVO(ICDSetupSet.toArray(new String[0]));
// 批量查询银行账户 存储为 :银行账户PK->银行账户名称Map
Map<String, BankAccSubVO> bankAccMap = null;
if (bankAcc.size() > 0) {
bankAccMap = new HashMap<String, BankAccSubVO>();
BankAccSubVO[] bankAccSubList = getIBankAccSubInfoQueryService().querySubInfosByPKs(bankAcc.toArray(new String[0]));
for (BankAccSubVO vo : bankAccSubList) {
bankAccMap.put(vo.getPk_bankaccsub(), vo);
}
}
// 批量查询最近结息日,存储为: 计息对象PK->最大结息日
Map<String, UFDate> intObjpkMaxIntDateMap = new HashMap<String, UFDate>();
for (String pk_org : orgIntObjMap.keySet()) {
String[] pks = orgIntObjMap.get(pk_org).toArray(new String[0]);
if (intObjpkMaxIntDateMap.size() == 0) {
intObjpkMaxIntDateMap = getDemandIntListQuery().getMaxIntDateMap(pks, pk_org, IFACConst.INT_TYPE_JX);
} else {
intObjpkMaxIntDateMap.putAll(getDemandIntListQuery().getMaxIntDateMap(pks, pk_org, IFACConst.INT_TYPE_JX));
}
}
// 构造活期计息界面展现的VO
ArrayList<AggDemandIntCalVO> aggcalvos = new ArrayList<AggDemandIntCalVO>();
for (AggAccInterestObjVO agg : intObjs) {
AccInterestObjVO objvo = agg.getParentVO();
IntAccountInfoVO[] accinfovos = agg.getIntAccountInfoVO();
if (IFACConst.COMBINATION.equals(objvo.getIntmode())) {// 合并计息
AggDemandIntCalVO aggcalvo = new AggDemandIntCalVO();
DemandIntCalVO vo = new DemandIntCalVO();
vo.setPrimaryKey(objvo.getPrimaryKey()); // 计息对象主表主键
setCommonAttrForDemandIntCalVO(vo, objvo, iRateCodeMap); // 共通项目设定
vo.setIntobjcode(objvo.getObjcode());
vo.setIntobjname(objvo.getIntobjname());
UFDate lastSettleDate = intObjpkMaxIntDateMap.get(objvo.getPk_accintobj()); // 取最近结息日
ICDSetupVO setupVO = ICDSetupMap.get(objvo.getPk_settledate());
if (setupVO == null) {
throw new BusinessException(MLFac.getStr00228()/*"查询不到计息对象的结息日设置,结息日PK:"*/+"[" + objvo.getPk_settledate() + "]");
}
UFDate nextSettleDate = getNextCalDate(objvo.getPk_org(), objvo.getBegdate().asBegin(), lastSettleDate, setupVO);
vo.setLastsettledate(lastSettleDate);// 从利息清单取最近结息日
vo.setNextsettledate(nextSettleDate);// 根据最近结息日推算出来
UFBoolean useflag = objvo.getUseflag();
// 表头未停用,需要判断表体,只要表体有一条未停用,认为是未停用的
if (UFBoolean.FALSE.equals(useflag)) {
//useflag = UFBoolean.TRUE;
for (IntAccountInfoVO accinfo : accinfovos) {
if (UFBoolean.FALSE.equals(accinfo.getUseflag())) {
useflag = UFBoolean.FALSE;
break;
}
}
}
// 停用标识
vo.setUseflag(useflag);
// 取最近的销户日期,只要有任意账户未销户,则认为计息对象未销户
UFDate destroyDate = null;
for (IntAccountInfoVO accinfo : accinfovos) {
UFDate tmpDate = accinfo.getDistroyaccdate();
if (tmpDate == null) {
//destroyDate = null;
break;
} else {
if (destroyDate == null) {
destroyDate = tmpDate;
} else if (tmpDate.afterDate(destroyDate)) {
destroyDate = tmpDate;
}
}
}
vo.setDistroyaccdate(destroyDate);
aggcalvo.setParentVO(vo);
aggcalvos.add(aggcalvo);
} else if (IFACConst.ONEBYONE.equals(objvo.getIntmode())) {// 分别计息
if (accinfovos != null && accinfovos.length > 0) {
for (IntAccountInfoVO accvo : accinfovos) {
AggDemandIntCalVO aggcalvo = new AggDemandIntCalVO();
DemandIntCalVO vo = new DemandIntCalVO();
vo.setPk_intaccinfo(accvo.getPk_intaccinfo());
vo.setPrimaryKey(accvo.getPk_intaccinfo()); // 计息对象子表主键
setCommonAttrForDemandIntCalVO(vo, objvo, iRateCodeMap); // 共通项目设定
if (bankAccMap.get(accvo.getPk_accid()) == null) {
throw new BusinessException(MLFac.getStr00229()/*"查询不到计息对象设置的内部账户,账户PK:["*/+"[" + accvo.getPk_accid() + "]");
}
vo.setIntobjcode(objvo.getObjcode() + "-"
+ (bankAccMap.get(accvo.getPk_accid()).getAccnum()));
vo.setIntobjname(objvo.getIntobjname() + "-"
+ (bankAccMap.get(accvo.getPk_accid()).getAccname()));
UFDate lastSettleDate = intObjpkMaxIntDateMap.get(accvo.getPk_intaccinfo()); // 取最近结息日
ICDSetupVO setupVO = ICDSetupMap.get(objvo.getPk_settledate());
UFDate nextSettleDate = getNextCalDate(objvo.getPk_org(), objvo.getBegdate().asBegin(), lastSettleDate, setupVO);
vo.setLastsettledate(lastSettleDate);// 从利息清单取最近结息日
vo.setNextsettledate(nextSettleDate);// 根据最近结息日推算出来
// 停用标识
vo.setUseflag(accvo.getUseflag());
// 销户日期
vo.setDistroyaccdate(accvo.getDistroyaccdate());
aggcalvo.setParentVO(vo);
aggcalvos.add(aggcalvo);
}
}
}
}
return aggcalvos.toArray(new AggDemandIntCalVO[0]);
}
/**
* 设置活期计息VO的通用属性值(针对分别计息和合并计息)
*
* @param vo
* @param objvo
* @param iRateCodeMap
* @throws BusinessException
*/
private void setCommonAttrForDemandIntCalVO(DemandIntCalVO vo, AccInterestObjVO objvo, Map<String, RateCodeVO> iRateCodeMap) throws BusinessException {
vo.setPk_org(objvo.getPk_org());
vo.setPk_org_v(objvo.getPk_org_v());
vo.setPk_group(objvo.getPk_group());
vo.setPk_gaincenter(objvo.getPk_gaincenter());
vo.setPk_capitalcenter(objvo.getPk_capitalcenter());
vo.setPk_currtype(objvo.getPk_currtype());
vo.setPk_intobj(objvo.getPk_accintobj());
vo.setPk_settledate(objvo.getPk_settledate());
vo.setSettlemode(objvo.getIntmode());
RateCodeVO iRateCodeVO = iRateCodeMap.get(objvo.getRatecode());
if (iRateCodeVO == null) {
throw new BusinessException(MLFac.getStr00230()/*"查询不到计息对象设置的利率信息,利率PK:["*/+"[" + objvo.getRatecode() + "]");
}
vo.setRatecode((String) iRateCodeVO.getPk_ratecode());
vo.setRatename((String) iRateCodeVO.getRatename());
vo.setYrate(iRateCodeVO.getYrate());//FIXME:没法判断
}
private void addKeyValueToMap(Map<String, List<String>> orgIntObjMap, String pk_org, String pk_intObj) {
if (!orgIntObjMap.containsKey(pk_org)) {
List<String> pk_intObjs = new ArrayList<String>();
pk_intObjs.add(pk_intObj);
orgIntObjMap.put(pk_org, pk_intObjs);
} else {
orgIntObjMap.get(pk_org).add(pk_intObj);
}
}
@Override
public AggDemandIntCalVO[] queryBillsByPks(String[] pks)
throws BusinessException {
// TODO Auto-generated method stub
return null;
}
@Override
public String[] queryByPageQueryScheme(IQueryScheme queryScheme)
throws BusinessException {
// TODO Auto-generated method stub
return null;
}
/**
* 获取活期利息清单查询服务
*
* @return
*/
private IDemandIntListQuery getDemandIntListQuery() {
return NCLocator.getInstance().lookup(IDemandIntListQuery.class);
}
/**
* 获取利率编码查询服务
*
* @return
*/
private IRateconfigQueryService getIRateCodeService() {
return NCLocator.getInstance().lookup(IRateconfigQueryService.class);
}
/**
* 根据当前结息日,推算下一结息日
*
* @param pk_org
* @param begDate
* @param lastCalDate
* @param settleDate
* @return
* @throws BusinessException
*/
private UFDate getNextCalDate(String pk_org, UFDate begDate, UFDate lastCalDate, ICDSetupVO settleDate) throws BusinessException {
// 资金日历ID
UFDate calBegDate = lastCalDate != null ? lastCalDate.getDateAfter(1) : begDate;
String pk_settledate = settleDate.getPk_id();
UFDate calEndDate = AiacOuterServiceProxy.getSettleDateQueryService().getNextSettleDate(pk_settledate, pk_org, calBegDate);
return calEndDate;
}
private IBankAccSubInfoQueryService getIBankAccSubInfoQueryService() {
return NCLocator.getInstance().lookup(IBankAccSubInfoQueryService.class);
}
/*
* 返回可用的计息对象
* 过滤掉停用,销户的计息对象。
*
* 提供给预警自动计息使用的。
* @see nc.itf.ifac.ia.IDemandintcalQuery#queryByOrgs(java.lang.String[])
*/
@SuppressWarnings("unchecked")
@Override
public AggDemandIntCalVO[] queryByOrgs(String[] pk_orgs) throws BusinessException {
AggDemandIntCalVO[] result = new AggDemandIntCalVO[0];
if (ArrayUtil.isNull(pk_orgs)) {
return result;
}
String whereCondStr =
SqlUtil.buildSqlForIn(AccInterestObjVO.PK_ORG, pk_orgs);
Collection<AggAccInterestObjVO> bills = MDPersistenceService.lookupPersistenceQueryService().queryBillOfVOByCond(AggAccInterestObjVO.class, whereCondStr, true, false);
if (bills != null && bills.size() != 0) {
ArrayList<AggAccInterestObjVO> realinterestvoArr = new ArrayList<AggAccInterestObjVO>();
for (AggAccInterestObjVO interestvo : bills) {
if (IFACConst.ONEBYONE.equals(interestvo.getParentVO().getIntmode())) {
if (UFBoolean.FALSE.equals(interestvo.getParentVO().getUseflag())) {
IntAccountInfoVO itemvo = (IntAccountInfoVO)(interestvo.getChildrenVO())[0];
if (itemvo.getDistroyaccdate() == null) {
realinterestvoArr.add(interestvo);
}
}
} else {
if (UFBoolean.FALSE.equals(interestvo.getParentVO().getUseflag())) {
realinterestvoArr.add(interestvo);
}
}
}
AggAccInterestObjVO[] intObjs = realinterestvoArr.toArray(new AggAccInterestObjVO[0]);
result = convertToDemandIntcalVO(intObjs);
}
return result;
}
/**
* 返回元数据查询服务对象
*/
private IMDPersistenceQueryService getMDQueryService() {
return MDPersistenceService.lookupPersistenceQueryService();
}
}
父类:
package nc.impl.fac.ia.ace;
import nc.bs.framework.common.NCLocator;
import nc.impl.pubapp.pattern.database.IDExQueryBuilder;
import nc.pubitf.rbac.IFunctionPermissionPubService;
import nc.ui.querytemplate.querytree.FromWhereSQL;
import nc.ui.querytemplate.querytree.IQueryScheme;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.AppContext;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.vo.pubapp.pattern.pub.SqlBuilder;
import nc.vo.pubapp.query2.sql.process.QueryConstants;
import nc.vo.pubapp.query2.sql.process.QuerySchemeUtils;
public abstract class AceDemandintcalQueryImpl implements
nc.itf.fac.ia.IDemandintcalQuery {
/**
* 由子类实现,查询之前对queryScheme进行加工,加入自己的逻辑
*
* @param queryScheme
*/
protected String preQuery(IQueryScheme queryScheme) {
// 查询之前对queryScheme进行加工,加入自己的逻辑
String funcode =(String) queryScheme.get(QueryConstants.KEY_FUNC_NODE);
if (funcode == null) {
return null;
}
String cuserid = AppContext.getInstance().getPkUser();
String pkGroup = AppContext.getInstance().getPkGroup();
try {
String[] orgs =
NCLocator.getInstance().lookup(IFunctionPermissionPubService.class)
.getUserPermissionPkOrgs(cuserid, funcode, pkGroup);
String columnName =QuerySchemeUtils
.getOrgColumnName(queryScheme);
String sql = null;
// 如果用户未分配任何组织时应该查不到任何单据
queryScheme.getTableListFromWhereSQL();
sql = queryScheme.getWhereSQLOnly();
if (orgs == null || orgs.length == 0) {
SqlBuilder builder = new SqlBuilder();
builder.append("fac_accinterestobj" + "." + columnName, "null");
sql = builder.toString();
}
else {
// 在组织很多的时候一定要采用临时表
IDExQueryBuilder builder = new IDExQueryBuilder("TEMP_PUBAPPO_");
sql = builder.buildSQL("fac_accinterestobj" + "." + columnName, orgs);
}
return sql;
}
catch (BusinessException e) {
ExceptionUtils.wrappException(e);
}
return null;
}
public String getMainTableAlias(IQueryScheme queryScheme) {
FromWhereSQL fromWhereSql = queryScheme.getTableJoinFromWhereSQL();
String mainTableAlias =fromWhereSql.getTableAliasByAttrpath(FromWhereSQL.DEFAULT_ATTRPATH);
return mainTableAlias;
}
}