销售订单信用余额联查
package nc.ui.so.m30.billui.action.link;
import java.awt.event.ActionEvent;
import nc.desktop.ui.WorkbenchEnvironment;
import nc.itf.scmpub.reference.uap.group.SysInitGroupQuery;
import nc.pubitf.credit.billcreditquery.IBillCreditQueryMessage;
import nc.ui.ml.NCLangRes;
import nc.ui.pubapp.pub.locator.NCUILocator;
import nc.ui.pubapp.uif2app.AppUiState;
import nc.ui.pubapp.uif2app.model.BillManageModel;
import nc.ui.scmpub.action.SCMActionInitializer;
import nc.ui.so.m30.billui.view.SaleOrderBillForm;
import nc.ui.so.pub.keyvalue.CardKeyValue;
import nc.ui.uif2.NCAction;
import nc.vo.credit.billcreditquery.para.BillQueryPara;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.vo.pubapp.res.NCModule;
import nc.vo.scmpub.res.SCMActionCode;
import nc.vo.so.m30.entity.SaleOrderBVO;
import nc.vo.so.m30.entity.SaleOrderHVO;
import nc.vo.so.m30.entity.SaleOrderVO;
import nc.vo.so.pub.keyvalue.IKeyValue;
import nc.vo.trade.checkrule.VOChecker;
/**
* 销售订单信用余额联查
*
*/
public class SaleOrderCreditQueryAction extends NCAction {
private static final long serialVersionUID = 1L;
private SaleOrderBillForm editor;
private BillManageModel model;
public SaleOrderCreditQueryAction() {
super();
SCMActionInitializer.initializeAction(this, SCMActionCode.SO_CREDITQUERY);
}
@Override
public void doAction(ActionEvent e) throws Exception {
if (!SysInitGroupQuery.isCREDITEnabled()) {
ExceptionUtils.wrappBusinessException(NCLangRes.getInstance().getStrByID("4006011_0", "04006011-0450")/* 请启用信用管理模块 */);
}
Object obj = this.getModel().getSelectedData();
AppUiState uistate = this.getModel().getAppUiState();
if (uistate == AppUiState.EDIT || uistate == AppUiState.ADD || uistate == AppUiState.COPY_ADD) {
obj = this.getEditor().getValue();
}
IKeyValue keyValue = new CardKeyValue(this.getEditor().getBillCardPanel());
int len = keyValue.getBodyCount();
SaleOrderVO vo = null;
SaleOrderHVO head = null;
SaleOrderBVO[] bodys = new SaleOrderBVO[len];
if (VOChecker.isEmpty(obj)) {
head = new SaleOrderHVO();
head.setCchanneltypeid(keyValue.getHeadStringValue(SaleOrderHVO.CCHANNELTYPEID));
head.setCcustomerid(keyValue.getHeadStringValue(SaleOrderHVO.CCUSTOMERID));
head.setCemployeeid(keyValue.getHeadStringValue(SaleOrderHVO.CEMPLOYEEID));
head.setCdeptid(keyValue.getHeadStringValue(SaleOrderHVO.CDEPTID));
head.setPk_org(keyValue.getHeadStringValue(SaleOrderHVO.PK_ORG));
head.setCtrantypeid(keyValue.getHeadStringValue(SaleOrderHVO.CTRANTYPEID));
if (len > 0) {
for (int i = 0; i < len; i++) {
bodys[i] = new SaleOrderBVO();
bodys[i].setCsettleorgid(keyValue.getBodyStringValue(i, SaleOrderBVO.CSETTLEORGID));
bodys[i].setCmaterialid(keyValue.getBodyStringValue(i, SaleOrderBVO.CMATERIALID));
bodys[i].setCprodlineid(keyValue.getBodyStringValue(i, SaleOrderBVO.CPRODLINEID));
}
}
} else {
vo = (SaleOrderVO) obj;
head = vo.getParentVO();
bodys = vo.getChildrenVO();
}
int i = 0;
BillQueryPara[] bqpS = new BillQueryPara[1];
if (bodys.length == 0) {
bqpS[i] = new BillQueryPara();
// 渠道类型
bqpS[i].setCchanneltypeid(head.getCchanneltypeid());
// 客户
bqpS[i].setCcustomerid(head.getCcustomerid());
// 销售业务员
bqpS[i].setCemployeeid(head.getCemployeeid());
// 销售部门
bqpS[i].setCsaledeptid(head.getCdeptid());
// 销售组织
bqpS[i].setCsaleorgid(head.getPk_org());
// 订单类型
bqpS[i].setVtrantypecode(head.getCtrantypeid());
} else {
// 数据封装为BillQueryPara[]
bqpS = new BillQueryPara[bodys.length];
for (SaleOrderBVO body : bodys) {
bqpS[i] = new BillQueryPara();
// 财务组织
bqpS[i].setCfinanceorgid(body.getCsettleorgid());
// 物料
bqpS[i].setCinvtoryid(body.getCmaterialid());
// 产品线
bqpS[i].setCprodlineid(body.getCprodlineid());
// 渠道类型
bqpS[i].setCchanneltypeid(head.getCchanneltypeid());
// 客户
bqpS[i].setCcustomerid(head.getCcustomerid());
// 销售业务员
bqpS[i].setCemployeeid(head.getCemployeeid());
// 销售部门
bqpS[i].setCsaledeptid(head.getCdeptid());
// 销售组织
bqpS[i].setCsaleorgid(head.getPk_org());
// 订单类型
bqpS[i].setVtrantypecode(head.getCtrantypeid());
i++;
}
}
try {
// 调用接口
IBillCreditQueryMessage service = NCUILocator.getInstance().lookup(IBillCreditQueryMessage.class, NCModule.CREDIT);
// 参数为:Container,billType,BillQueryPara[]
service.showMessage(WorkbenchEnvironment.getInstance().getWorkbench().getParent(), "30", bqpS);
} catch (Exception e1) {
ExceptionUtils.wrappException(e1);
}
}
public SaleOrderBillForm getEditor() {
return this.editor;
}
public BillManageModel getModel() {
return this.model;
}
public void setEditor(SaleOrderBillForm editor) {
this.editor = editor;
}
public void setModel(BillManageModel model) {
this.model = model;
model.addAppEventListener(this);
}
@Override
protected boolean isActionEnable() {
AppUiState uistate = this.getModel().getAppUiState();
boolean broenable = uistate == AppUiState.NOT_EDIT && this.model.getSelectedData() != null;
return broenable || uistate == AppUiState.EDIT || uistate == AppUiState.ADD || uistate == AppUiState.COPY_ADD || uistate == AppUiState.TRANSFERBILL_ADD;
}
}
联查客户信用
package nc.ui.ic.m4h.action;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import nc.desktop.ui.WorkbenchEnvironment;
import nc.itf.scmpub.reference.uap.bd.material.MaterialPubService;
import nc.pubitf.credit.billcreditquery.IBillCreditQueryMessage;
import nc.ui.ic.org.query.OrgInfoUIQuery;
import nc.ui.ic.pub.model.ICBizEditorModel;
import nc.ui.ic.pub.model.ICBizModel;
import nc.ui.pubapp.pub.locator.NCUILocator;
import nc.ui.scmpub.action.SCMActionInitializer;
import nc.ui.uif2.NCAction;
import nc.vo.bd.material.MaterialVO;
import nc.vo.credit.billcreditquery.para.BillQueryPara;
import nc.vo.ic.m4h.entity.BorrowOutBodyVO;
import nc.vo.ic.m4h.entity.BorrowOutVO;
import nc.vo.pubapp.res.NCModule;
import nc.vo.scmpub.res.SCMActionCode;
import nc.vo.scmpub.res.billtype.ICBillType;
/**
*
* 本类主要完成以下功能:联查客户信用
*
*/
@SuppressWarnings("serial")
public class LinkQueryCustomerCredit extends NCAction {
private ICBizModel model = null;
private ICBizEditorModel editorModel = null;
public LinkQueryCustomerCredit() {
SCMActionInitializer.initializeAction(this, SCMActionCode.IC_LINKQUERYCUSTOMERCREDIT);
}
@Override
public void doAction(ActionEvent e) throws Exception {
BorrowOutVO bill = (BorrowOutVO) this.getModel().getSelectedData();
String pk_org = bill.getHead().getPk_org();
String cfinanceid = OrgInfoUIQuery.getInstance().getOrgInfoQuery().getFinanceOrgIDByCalBodyID(pk_org);
List<String> cmaterialvids = new ArrayList<String>();
for (BorrowOutBodyVO bvo : bill.getBodys()) {
if (!cmaterialvids.contains(bvo.getCmaterialvid()))
cmaterialvids.add(bvo.getCmaterialvid());
}
Map<String, MaterialVO> map = MaterialPubService.queryMaterialBaseInfo(cmaterialvids.toArray(new String[0]), new String[] { "pk_prodline" });
BillQueryPara[] paras = new BillQueryPara[bill.getBodys().length];
for (int i = 0; i < bill.getBodys().length; i++) {
//封装查询条件
paras[i] = new BillQueryPara();
//客户
paras[i].setCcustomerid(bill.getHead().getCcustomerid());
//销售业务员
paras[i].setCemployeeid(bill.getHead().getCbizid());
//财务组织
paras[i].setCfinanceorgid(cfinanceid);
//销售部门
paras[i].setCsaledeptid(bill.getHead().getCdptid());
//物料
paras[i].setCinvtoryid(bill.getBody(i).getCmaterialvid());
//物料
MaterialVO mvo = map.get(bill.getBody(i).getCmaterialvid());
//产品线
paras[i].setCprodlineid(mvo == null ? null : mvo.getPk_prodline());
}
IBillCreditQueryMessage service = NCUILocator.getInstance().lookup(IBillCreditQueryMessage.class, NCModule.CREDIT);
service.showMessage(WorkbenchEnvironment.getInstance().getWorkbench().getParent(), ICBillType.BorrowOut.getCode(), paras);
}
public ICBizModel getModel() {
return this.model;
}
public void setModel(ICBizModel model) {
this.model = model;
model.addAppEventListener(this);
}
public ICBizEditorModel getEditorModel() {
return this.editorModel;
}
public void setEditorModel(ICBizEditorModel editorModel) {
this.editorModel = editorModel;
}
@Override
protected boolean isActionEnable() {
if (this.model.getSelectedData() == null) {
return false;
}
return super.isActionEnable();
}
}
信用查询接口
package nc.pubitf.credit.billcreditquery;
import nc.vo.credit.billcreditquery.entity.BillCreditQueryVO;
import nc.vo.credit.billcreditquery.para.BillQueryPara;
import nc.vo.pub.BusinessException;
/**
* 信用查询接口
*
*/
public interface IBillCreditQuery {
/**
* 单据信用联查公共接口
*
* @author liyu
* @param billType
*
*/
BillCreditQueryVO[] queryCreditForBill(BillQueryPara[] vos, String billType) throws BusinessException;
}
单据信用查询 公共方法
package nc.pubimpl.credit.billcreditquery;
import nc.bs.credit.creditquery.CreditQuery;
import nc.pubitf.credit.billcreditquery.IBillCreditQuery;
import nc.vo.credit.billcreditquery.entity.BillCreditQueryVO;
import nc.vo.credit.billcreditquery.para.BillQueryPara;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
/**
* 单据信用查询 公共方法
*
*/
public class BillCreditQueryImpl implements IBillCreditQuery {
@Override
public BillCreditQueryVO[] queryCreditForBill(BillQueryPara[] vos, String billType) throws BusinessException {
CreditQuery query = new CreditQuery();
try {
return query.queryCredit(vos, null, billType);
}
catch (Exception e) {
ExceptionUtils.marsh(e);
}
return null;
}
}
信用查询工具类——CreditQueryUtil
package nc.pubimpl.credit.billcreditquery;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import nc.vo.bd.cust.creditctl.CustCreditCtlVO;
import nc.vo.credit.creditamount.entity.CreditAmountVO;
import nc.vo.credit.limittype.entity.LimitTypeHVO;
import nc.vo.credit.limittype.entity.LimitTypeVO;
import nc.vo.pub.lang.UFDouble;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.vo.pubapp.pattern.pub.MapList;
import nc.vo.pubapp.pattern.pub.MapSet;
import nc.itf.scmpub.reference.uap.bd.customer.CustomerPubService;
import nc.itf.scmpub.reference.uap.org.GroupQryService;
import nc.impl.pubapp.env.BSContext;
public class CreditQueryUtil {
/**
* 根据额度类型和信用额度记录增加虚拟额度
*
* @param ltVOS 额度类型
* @param corg_custs 信用控制域-客户集合
* @param avos 信用额度
*/
public CreditAmountVO[] constructAmount(LimitTypeVO[] ltVOS, Map<String, Set<String>> corg_custs, CreditAmountVO[] avos) {
// 虚拟的信用额度为0的记录列表
List<CreditAmountVO> list = new ArrayList<CreditAmountVO>();
// 得到需要虚拟信用额度的额度类型
Map<LimitTypeVO, List<String>> m_cust = this.getNeedToDummy(ltVOS, avos, null);
// 取集团本位币
String pk_group = BSContext.getInstance().getGroupID();
String ccurrencyid = GroupQryService.queryGroupCurrency(pk_group);
// 按额度类型虚拟
for (Entry<LimitTypeVO, List<String>> entry : m_cust.entrySet()) {
LimitTypeHVO head = entry.getKey().getHead();
String[] custs = null;
List<String> l_custs = entry.getValue();
if (l_custs != null && l_custs.size() > 0) {
custs = l_custs.toArray(new String[0]);
} else {
custs = corg_custs.get(head.getPk_org()).toArray(new String[0]);
}
// 取额度类型所属的信用控制域下的客户做循环
for (String cust : custs) {
// 如果客户为空,则不需要虚拟数据
if (cust == null) {
continue;
}
CreditAmountVO amountVO = new CreditAmountVO();
amountVO.setPk_org(head.getPk_org());
amountVO.setClimittypeid(head.getClimittypeid());
amountVO.setCcustomerid(cust);
amountVO.setCcurrencyid(ccurrencyid);
amountVO.setNlimitmny(UFDouble.ZERO_DBL);
amountVO.setPk_group(pk_group);
list.add(amountVO);
}
}
if (avos != null) {
for (CreditAmountVO avo : avos) {
list.add(avo);
}
}
return list.toArray(new CreditAmountVO[0]);
}
/**
* 得到客户分配的信用控制域
*
* @param corgs 信用控制域
* @param customers 客户
* @return 信用控制域-客户集合
*/
public Map<String, Set<String>> getCreditCtlAndCustomers(String[] corgs, String[] customers) {
// 信用控制域-客户
MapSet<String, String> ret = new MapSet<String, String>();
// 信用控制域为空 或者 客户为空
if (null == corgs || corgs.length == 0 || null == customers || customers.length == 0) {
return null;
}
try {
for (String org : corgs) {
CustCreditCtlVO[] custCreditCtlVO = CustomerPubService.getCustCreditCtlVO(customers, org, new String[] { CustCreditCtlVO.PK_CUSTOMER });
for (CustCreditCtlVO cvo : custCreditCtlVO) {
if (null != cvo && cvo.getPk_customer() != null) {
ret.put(org, cvo.getPk_customer());
}
}
}
} catch (Exception e) {
ExceptionUtils.wrappException(e);
}
return ret.toMap();
}
/**
* 获得信用占用时点
*
* @param ltVOS 额度类型
* @return 额度类型主键-占用时点
*/
public Map<String, Integer> getFvoccupiedflag(LimitTypeVO[] vos) {
Map<String, Integer> ret = new HashMap<String, Integer>();
for (LimitTypeVO vo : vos) {
ret.put(vo.getPrimaryKey(), vo.getHead().getFvoccupiedflag());
}
return ret;
}
/**
* 得到符合虚拟条件的额度类型
*
* @param vos 额度类型
* @param avos 信用额度
* @param customers
* @return
*/
public Map<LimitTypeVO, List<String>> getNeedToDummy(LimitTypeVO[] vos, CreditAmountVO[] avos, String[] customers) {
// 1.得到符合虚拟条件的额度类型
Map<String, LimitTypeVO> m_ltvo = new HashMap<String, LimitTypeVO>();
for (LimitTypeVO vo : vos) {
LimitTypeHVO head = vo.getHead();
if (head.getBcontrolflag().booleanValue()) {
m_ltvo.put(vo.getPrimaryKey(), vo);
}
}
// 2.客户集合
Set<String> custs = new HashSet<String>();
// 额度类型和客户的关系
MapList<String, String> lt_cust = new MapList<String, String>();
if (null != avos) {
for (CreditAmountVO avo : avos) {
custs.add(avo.getCcustomerid());
lt_cust.put(avo.getClimittypeid(), avo.getCcustomerid());
}
}
if (null != customers) {
for (String customer : customers) {
custs.add(customer);
}
}
// 3.
Map<LimitTypeVO, List<String>> ltvo_cust = new HashMap<LimitTypeVO, List<String>>();
for (Entry<String, LimitTypeVO> en : m_ltvo.entrySet()) {
String climitTypeid = en.getKey();
List<String> l_custs = lt_cust.get(climitTypeid);
List<String> need_cust = new ArrayList<String>();
if (null == l_custs || l_custs.size() == 0) {
need_cust.addAll(custs);
} else {
for (String cust : custs) {
if (!l_custs.contains(cust)) {
need_cust.add(cust);
}
}
}
ltvo_cust.put(en.getValue(), need_cust);
}
return ltvo_cust;
}
}
信用查询——CreditQuery
package nc.bs.credit.creditquery;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import nc.vo.credit.billcreditquery.entity.BillCreditQueryVO;
import nc.vo.credit.billcreditquery.para.BillQueryPara;
import nc.vo.credit.creditamount.entity.CreditAmountVO;
import nc.vo.credit.engrossmaintain.entity.AccountMnyVO;
import nc.vo.credit.limittype.entity.LimitTypeVO;
import nc.vo.credit.util.TimeUtils;
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.itf.scmpub.reference.uap.org.GroupQryService;
import nc.bs.credit.creditquery.util.BillCreditQueryUtil;
import nc.bs.credit.pub.CreditCommonUtil;
import nc.bs.ml.NCLangResOnserver;
import nc.impl.pubapp.env.BSContext;
import nc.pubimpl.credit.engrossmaintain.QueryAccountMnyImpl;
/**
* 信用查询
*
*/
public class CreditQuery {
// 是否匹配到额度类型
private boolean matchLimitType;
// 是否匹配信用额度
private boolean matchCreditAmount;
// 是否匹配信用控制域
private boolean matchCreditOrg;
// 信用查询结果
private List<BillCreditQueryVO> result = new ArrayList<BillCreditQueryVO>();
// 信用查询结果(服装行业)
private Map<BillQueryPara, BillCreditQueryVO> resultFZHY = new HashMap<BillQueryPara, BillCreditQueryVO>();
// 信用参数匹配(服装行业)
private Map<BillQueryPara, List<BillQueryPara>> keyValueMap = new HashMap<BillQueryPara, List<BillQueryPara>>();
/**
* 查询信用信息
*
* @param billType
*
* @param billType 单据类型
* @param vos 查询数据
* @param date2
* @return 信用信息数组
* @throws Exception
*/
public BillCreditQueryVO[] queryCredit(BillQueryPara[] paras, UFDate queryDate, String billType) throws BusinessException {
// 信用查询工具类
BillCreditQueryUtil bcqUtil = new BillCreditQueryUtil();
bcqUtil.checkNull(paras);
this.matchLimitType = false;
this.matchCreditAmount = false;
this.matchCreditOrg = false;
List<BillQueryPara> plist = bcqUtil.filterCustomer(paras);
String[] forgs = bcqUtil.filterForg(paras);
// 财务组织 - 信用控制域[]
Map<String, List<String>> forg_cOrgs = CreditCommonUtil.getCreditOrg(forgs);
if (null == forg_cOrgs || forg_cOrgs.size() == 0) {
ExceptionUtils.wrappBusinessException(NCLangResOnserver.getInstance().getStrByID("4032001_0", "04032001-0060")/* 财务组织未分配到信用控制域。 */);
}
// 过滤掉同维度的记录(财务组织+产品线+订单类型+渠道类型+销售组织+销售部门+销售业务员+客户)
plist = bcqUtil.filterDim(plist);
// 得到信用控制域 - 查询vo
Map<String, List<BillQueryPara>> corg_plist = bcqUtil.groupByCreditOrg(forg_cOrgs, plist);
// 得到服务器日期
UFDate date = TimeUtils.getsrvBaseDate();
if (queryDate != null) {
date = queryDate;
}
// 循环信用控制域,得到信用信息
for (Entry<String, List<BillQueryPara>> entry : corg_plist.entrySet()) {
this.oneCorgCyc(entry, date, billType);
}
if (!this.isMatchLimitType()) {
ExceptionUtils.wrappBusinessException(NCLangResOnserver.getInstance().getStrByID("4032001_0", "04032001-0062")/* 没有匹配到额度类型,不能显示信用数据。 */);
}
if (!this.isMatchCreditAmount()) {
ExceptionUtils.wrappBusinessException(NCLangResOnserver.getInstance().getStrByID("4032001_0", "04032001-0063")/* 该客户没有设置信用额度,不能显示信用数据。 */);
}
return this.result.toArray(new BillCreditQueryVO[0]);
}
/**
* 为服装行业单独提供的信用查询服务 查询信用信息 因为服装行业要求返回值与BillQueryPara一一对应 返回值为
* HashMap<BillQueryPara, BillCreditQueryVO>
*
* @param billType
*
* @param billType 单据类型
* @param vos 查询数据
* @param date2
* @return HashMap<BillQueryPara, BillCreditQueryVO>
* @throws Exception
*/
public Map<BillQueryPara, BillCreditQueryVO> queryCreditForFZHY(BillQueryPara[] paras, UFDate queryDate, String billType) throws BusinessException {
// 信用查询工具类
BillCreditQueryUtil bcqUtil = new BillCreditQueryUtil();
bcqUtil.checkNull(paras);
this.matchLimitType = false;
this.matchCreditAmount = false;
this.matchCreditOrg = false;
List<BillQueryPara> plist = bcqUtil.filterCustomer(paras);
String[] forgs = bcqUtil.filterForg(paras);
// 财务组织 - 信用控制域[]
Map<String, List<String>> forg_cOrgs = CreditCommonUtil.getCreditOrg(forgs);
// 匹配不到信用控制域直接返回参数为key的空map
if (null == forg_cOrgs || forg_cOrgs.size() == 0) {
for (BillQueryPara para : paras) {
BillCreditQueryVO vo = new BillCreditQueryVO();
this.setNullToBillCreditQueryVOByParaForFZHY(para, vo);
this.resultFZHY.put(para, vo);
}
return this.resultFZHY;
}
// 过滤掉同维度的记录(财务组织+产品线+订单类型+渠道类型+销售组织+销售部门+销售业务员+客户)
plist = bcqUtil.filterDim(plist);
// 得到信用控制域 - 查询vo
Map<String, List<BillQueryPara>> corg_plist = bcqUtil.groupByCreditOrg(forg_cOrgs, plist);
// 得到服务器日期
UFDate date = TimeUtils.getsrvBaseDate();
if (queryDate != null) {
date = queryDate;
}
// 循环信用控制域,得到信用信息
for (Entry<String, List<BillQueryPara>> entry : corg_plist.entrySet()) {
this.oneCorgCycForFZHY(entry, date, billType);
}
// 将前面过滤掉的重复Para打散重新加回Map中
for (Entry<BillQueryPara, List<BillQueryPara>> entry : this.keyValueMap.entrySet()) {
BillQueryPara lastKey = entry.getKey();
if (this.resultFZHY.containsKey(lastKey)) {
List<BillQueryPara> lastParas = entry.getValue();
BillCreditQueryVO resultVO = this.resultFZHY.get(lastKey);
for (BillQueryPara para : lastParas) {
this.resultFZHY.put(para, resultVO);
}
}
}
// 将前面未匹配到信用控制域和额度类型的Para也加回Map中
for (BillQueryPara originPara : paras) {
if (!this.resultFZHY.containsKey(originPara)) {
// 虚拟空VO
BillCreditQueryVO vo = new BillCreditQueryVO();
this.setNullToBillCreditQueryVOByParaForFZHY(originPara, vo);
this.resultFZHY.put(originPara, vo);
}
}
return this.resultFZHY;
}
/**
* 为电子销售单独提供的信用查询服务
*
* 由于电子销售接口要求当结算财务组织为空时表示 匹配所有的结算财务组织,因此单独提供一个方法
*
* @param paras
* @param queryDate
* @return
* @throws BusinessException
*/
public BillCreditQueryVO[] queryCreditForEC(BillQueryPara[] paras) throws BusinessException {
// 信用查询工具类
BillCreditQueryUtil bcqUtil = new BillCreditQueryUtil();
bcqUtil.checkNullForEC(paras);
this.matchLimitType = false;
this.matchCreditAmount = false;
this.matchCreditOrg = false;
List<BillQueryPara> plist = bcqUtil.filterCustomer(paras);
String[] forgs = bcqUtil.filterForgForEC(paras);
// 财务组织 - 信用控制域[]
Map<String, List<String>> forg_cOrgs = CreditCommonUtil.getCreditOrg(forgs);
if (null == forg_cOrgs || forg_cOrgs.size() == 0) {
ExceptionUtils.wrappBusinessException(NCLangResOnserver.getInstance().getStrByID("4032001_0", "04032001-0060")/* 财务组织未分配到信用控制域。 */);
}
// 过滤掉同维度的记录(财务组织+产品线+订单类型+渠道类型+销售组织+销售部门+销售业务员+客户)
plist = bcqUtil.filterDim(plist);
// 得到信用控制域 - 查询vo
Map<String, List<BillQueryPara>> corg_plist = bcqUtil.groupByCreditOrgForEC(forg_cOrgs, plist);
// 得到服务器日期
UFDate date = TimeUtils.getsrvBaseDate();
// 循环信用控制域,得到信用信息
for (Entry<String, List<BillQueryPara>> entry : corg_plist.entrySet()) {
this.oneCorgCycForEC(entry, date);
}
if (!this.isMatchCreditOrg()) {
ExceptionUtils.wrappBusinessException(NCLangResOnserver.getInstance().getStrByID("4032001_0", "04032001-0190")/* 该客户没有分配信用控制域,不能显示信用数据。 */);
}
if (!this.isMatchLimitType()) {
ExceptionUtils.wrappBusinessException(NCLangResOnserver.getInstance().getStrByID("4032001_0", "04032001-0062")/* 没有匹配到额度类型,不能显示信用数据。 */);
}
if (!this.isMatchCreditAmount()) {
ExceptionUtils.wrappBusinessException(NCLangResOnserver.getInstance().getStrByID("4032001_0", "04032001-0063")/* 该客户没有设置信用额度,不能显示信用数据。 */);
}
return this.result.toArray(new BillCreditQueryVO[0]);
}
/**
* 信用控制域单次循环
*
* @param entry
* @param date
* @param billType
* @throws Exception
*/
private void oneCorgCyc(Entry<String, List<BillQueryPara>> corg_lst, UFDate date, String billType) throws BusinessException {
BillCreditQueryUtil bcqUtil = new BillCreditQueryUtil();
if (!bcqUtil.getRootCustomerByCtrlType(corg_lst)) {
return;
}
this.setMatchCreditOrg(true);
Map<String, List<LimitTypeVO>> ltMap = bcqUtil.getLimitType(corg_lst, billType);
Map<LimitTypeVO, List<BillQueryPara>> lt_paras = bcqUtil.groupParaByLimitType(ltMap, corg_lst.getValue(), billType);
// 所有查询信息均未匹配到额度类型时,抛错
for (Entry<LimitTypeVO, List<BillQueryPara>> lt_para : lt_paras.entrySet()) {
this.setMatchLimitType(true);
// 2013-07-16 dongli2 参数过滤,额度类型相同的情况下,只考虑部门,组织,业务员,客户
List<BillQueryPara> paraList = this.filterPara(corg_lst, lt_para);
String pk_limitType = lt_para.getKey().getPrimaryKey();
// 2013-10-21 dongli2 此处key = 组织+额度类型+部门+业务员+客户
Map<String, List<CreditAmountVO>> creditAmountMap = bcqUtil.getCreditAmount(paraList, corg_lst.getKey(), pk_limitType, date);
for (BillQueryPara para : paraList) {
// 2013-10-21 dongli2 此处lt_para是额度类型下的所有参数
// corg_lst的key是财务组织
this.oneParaCyc(para, creditAmountMap, corg_lst, lt_para);
}
}
}
/**
* 为服装行业单独提供的信用查询服务 信用控制域单次循环
*
* @param entry
* @param date
* @param billType
* @throws Exception
*/
private void oneCorgCycForFZHY(Entry<String, List<BillQueryPara>> corg_lst, UFDate date, String billType) throws BusinessException {
BillCreditQueryUtil bcqUtil = new BillCreditQueryUtil();
if (!bcqUtil.getRootCustomerByCtrlType(corg_lst)) {
return;
}
this.setMatchCreditOrg(true);
Map<String, List<LimitTypeVO>> ltMap = bcqUtil.getLimitType(corg_lst, billType);
Map<LimitTypeVO, List<BillQueryPara>> lt_paras = bcqUtil.groupParaByLimitType(ltMap, corg_lst.getValue(), billType);
// 所有查询信息均未匹配到额度类型时,后续做Map补齐处理
for (Entry<LimitTypeVO, List<BillQueryPara>> lt_para : lt_paras.entrySet()) {
// 2013-07-16 dongli2 参数过滤,额度类型相同的情况下,只考虑部门,组织,业务员,客户
List<BillQueryPara> paraList = this.filterPara(corg_lst, lt_para);
String pk_limitType = lt_para.getKey().getPrimaryKey();
// 2013-10-21 dongli2 此处key = 组织+额度类型+部门+业务员+客户
Map<String, List<CreditAmountVO>> creditAmountMap = bcqUtil.getCreditAmount(paraList, corg_lst.getKey(), pk_limitType, date);
for (BillQueryPara para : paraList) {
// 2013-10-21 dongli2 此处lt_para是额度类型下的所有参数
// corg_lst的key是财务组织,para是额度类型下查询参数BillQueryPara的遍历
this.oneParaCycForFZHY(para, creditAmountMap, corg_lst, lt_para);
}
}
}
/**
* 过滤参数,只考虑部门,组织,业务员,客户
*
* @param corg_lst
* @param lt_para
* @return paraList
*/
private List<BillQueryPara> filterPara(Entry<String, List<BillQueryPara>> corg_lst, Entry<LimitTypeVO, List<BillQueryPara>> lt_para) {
List<BillQueryPara> paraList = new ArrayList<BillQueryPara>();
Map<String, BillQueryPara> mapValue = new HashMap<String, BillQueryPara>();
for (BillQueryPara para : lt_para.getValue()) {
String pk_org = corg_lst.getKey();
String pk_lt = lt_para.getKey().getPrimaryKey();// 额度类型key
// 额度类型相同的情况下,只考虑部门,组织,业务员,客户
String key = pk_org + pk_lt + para.getCsaledeptid() + para.getCemployeeid() + para.getCcustomerid();
if (mapValue.containsKey(key)) {
BillQueryPara lastPara = mapValue.get(key);
if (this.keyValueMap.containsKey(lastPara)) {
List<BillQueryPara> mapParas = this.keyValueMap.get(lastPara);
mapParas.add(para);
this.keyValueMap.put(lastPara, mapParas);
} else {
// 添加重复List进keyValueMap
List<BillQueryPara> mapParas = new ArrayList<BillQueryPara>();
// mapParas.add(para);
this.keyValueMap.put(lastPara, mapParas);
}
continue;
}
mapValue.put(key, para);
}
for (Entry<String, BillQueryPara> entry : mapValue.entrySet()) {
paraList.add(entry.getValue());
}
return paraList;
}
private void oneCorgCycForEC(Entry<String, List<BillQueryPara>> corg_lst, UFDate date) throws BusinessException {
BillCreditQueryUtil bcqUtil = new BillCreditQueryUtil();
if (!bcqUtil.getRootCustomerByCtrlType(corg_lst)) {
return;
}
this.setMatchCreditOrg(true);
Map<String, List<LimitTypeVO>> ltMap = bcqUtil.getLimitTypeForEC(corg_lst);
Map<LimitTypeVO, List<BillQueryPara>> lt_paras = bcqUtil.groupParaByLimitTypeForEC(ltMap, corg_lst.getValue());
// 所有查询信息均未匹配到额度类型时,抛错
for (Entry<LimitTypeVO, List<BillQueryPara>> lt_para : lt_paras.entrySet()) {
this.setMatchLimitType(true);
List<BillQueryPara> paraList = lt_para.getValue();
String pk_limitType = lt_para.getKey().getPrimaryKey();
Map<String, List<CreditAmountVO>> creditAmountMap = bcqUtil.getCreditAmountForEC(paraList, corg_lst.getKey(), pk_limitType, date);
this.oneParaCyc(paraList.get(0), creditAmountMap, corg_lst, lt_para);
}
}
private void oneParaCyc(BillQueryPara para, Map<String, List<CreditAmountVO>> creditAmountMap, Entry<String, List<BillQueryPara>> corg_paras, Entry<LimitTypeVO, List<BillQueryPara>> lt_para)
throws BusinessException {
BillCreditQueryUtil bcqUtil = new BillCreditQueryUtil();
String pk_org = corg_paras.getKey();
String pk_lt = lt_para.getKey().getPrimaryKey();
// 信用占用时点
Integer fvoccupiedflag = lt_para.getKey().getHead().getFvoccupiedflag();
// 不设定信用额度按照额度为0控制信用
UFBoolean bControlFlag = lt_para.getKey().getHead().getBcontrolflag();
List<CreditAmountVO> creditAmount = creditAmountMap.get(pk_org + pk_lt + para.getCsaledeptid() + para.getCemployeeid() + para.getCcustomerid());
// 未匹配到信用额度且按额度为0控制信用
if ((null == creditAmount || creditAmount.size() == 0) && bControlFlag.booleanValue()) {
// 虚拟一条信用额度为0的记录
CreditAmountVO caVO = bcqUtil.dummyCreditAmount(pk_org, pk_lt, para);
List<CreditAmountVO> caLst = new ArrayList<CreditAmountVO>();
caLst.add(caVO);
this.setMatchCreditAmount(true);
this.getResult(caLst, fvoccupiedflag, lt_para.getKey());
} else if (null != creditAmount && creditAmount.size() != 0) {
this.setMatchCreditAmount(true);
// 得到信用查询信息
this.getResult(creditAmount, fvoccupiedflag, lt_para.getKey());
}
}
/**
* 为服装行业单独提供的信用查询服务
*
* @param para
* @param creditAmountMap
* @param corg_paras
* @param lt_para
* @throws BusinessException
*/
private void oneParaCycForFZHY(BillQueryPara para, Map<String, List<CreditAmountVO>> creditAmountMap, Entry<String, List<BillQueryPara>> corg_paras, Entry<LimitTypeVO, List<BillQueryPara>> lt_para)
throws BusinessException {
BillCreditQueryUtil bcqUtil = new BillCreditQueryUtil();
String pk_org = corg_paras.getKey();
String pk_lt = lt_para.getKey().getPrimaryKey();
// 信用占用时点
Integer fvoccupiedflag = lt_para.getKey().getHead().getFvoccupiedflag();
// 不设定信用额度按照额度为0控制信用
UFBoolean bControlFlag = lt_para.getKey().getHead().getBcontrolflag();
List<CreditAmountVO> creditAmount = creditAmountMap.get(pk_org + pk_lt + para.getCsaledeptid() + para.getCemployeeid() + para.getCcustomerid());
// 未匹配到信用额度且按额度为0控制信用
if ((null == creditAmount || creditAmount.size() == 0) && bControlFlag.booleanValue()) {
// 虚拟一条信用额度为0的记录
CreditAmountVO caVO = bcqUtil.dummyCreditAmount(pk_org, pk_lt, para);
List<CreditAmountVO> caLst = new ArrayList<CreditAmountVO>();
caLst.add(caVO);
this.setMatchCreditAmount(true);
this.getResultForFZHY(caLst, fvoccupiedflag, lt_para.getKey(), para);
} else if (null != creditAmount && creditAmount.size() != 0) {
this.setMatchCreditAmount(true);
// 得到信用查询信息
this.getResultForFZHY(creditAmount, fvoccupiedflag, lt_para.getKey(), para);
}
// 未匹配到信用额度且不按额度为0控制信用,虚拟一条全部为null的VO返回Map
if ((null == creditAmount || creditAmount.size() == 0) && !bControlFlag.booleanValue()) {
this.setMatchCreditAmount(true);
BillCreditQueryVO vo = new BillCreditQueryVO();
this.setNullToBillCreditQueryVOForFZHY(para, vo, pk_org, pk_lt, fvoccupiedflag);
this.resultFZHY.put(para, vo);
}
}
/**
* 给没有对应查询结果的para生成一个空值vo(服装行业)
*
* @param para
* @param vo
* @param pk_org
* @param pk_lt
* @param fvoccupiedflag
*/
private void setNullToBillCreditQueryVOForFZHY(BillQueryPara para, BillCreditQueryVO vo, String pk_org, String pk_lt, Integer fvoccupiedflag) {
// 信用控制域
vo.setPk_org(pk_org);
// 额度类型
vo.setClimittypeid(pk_lt);
// 销售组织
vo.setCsaleorgid(pk_org);
// 销售部门
vo.setCdeptid(para.getCsaledeptid());
// 销售业务员
vo.setCemployeeid(para.getCemployeeid());
// 客户
vo.setCcustomerid(para.getCcustomerid());
// 币种
// 取集团本位币
String pk_group = BSContext.getInstance().getGroupID();
String ccurrencyid = GroupQryService.queryGroupCurrency(pk_group);
vo.setCorigcurrencyid(ccurrencyid);
// 信用额度
vo.setNlimitmny(null);
// 信用余额
vo.setNbalancemny(null);
// 信用占用开始时点
vo.setFvoccupiedflag(fvoccupiedflag);
// 集团
vo.setPk_group(pk_group);
// 产品线
String[] prodlineids = new String[1];
prodlineids[0] = para.getCprodlineid();
vo.setCprodlineids(prodlineids);
// 订单类型
String[] trantypeids = new String[1];
trantypeids[0] = para.getVtrantypecode();
vo.setCtrantypeids(trantypeids);
// 渠道类型
String[] channeltypeids = new String[1];
channeltypeids[0] = para.getCchanneltypeid();
vo.setCchanneltypeids(channeltypeids);
}
/**
* 给没有对应信用控制域的para生成一个空值vo(服装行业)
*
* @param para
* @param vo
* @param pk_org
* @param pk_lt
* @param fvoccupiedflag
*/
private void setNullToBillCreditQueryVOByParaForFZHY(BillQueryPara para, BillCreditQueryVO vo) {
// 信用控制域
vo.setPk_org(null);
// 额度类型
vo.setClimittypeid(null);
// 销售组织
vo.setCsaleorgid(para.getCsaleorgid());
// 销售部门
vo.setCdeptid(para.getCsaledeptid());
// 销售业务员
vo.setCemployeeid(para.getCemployeeid());
// 客户
vo.setCcustomerid(para.getCcustomerid());
// 币种
// 取集团本位币
String pk_group = BSContext.getInstance().getGroupID();
String ccurrencyid = GroupQryService.queryGroupCurrency(pk_group);
vo.setCorigcurrencyid(ccurrencyid);
// 信用额度
vo.setNlimitmny(null);
// 信用余额
vo.setNbalancemny(null);
// 信用占用开始时点
vo.setFvoccupiedflag(null);
// 集团
vo.setPk_group(pk_group);
// 产品线
String[] prodlineids = new String[1];
prodlineids[0] = para.getCprodlineid();
vo.setCprodlineids(prodlineids);
// 订单类型
String[] trantypeids = new String[1];
trantypeids[0] = para.getVtrantypecode();
vo.setCtrantypeids(trantypeids);
// 渠道类型
String[] channeltypeids = new String[1];
channeltypeids[0] = para.getCchanneltypeid();
vo.setCchanneltypeids(channeltypeids);
}
/**
* 得到信用检查信息
*
* @param fvoccupiedflag
* @param limitTypeVO
* @param caVO
*
* @return
* @throws BusinessException
*/
private void getResult(List<CreditAmountVO> creditAmount, Integer fvoccupiedflag, LimitTypeVO limitTypeVO) throws BusinessException {
String pk_exratescheme = CreditCommonUtil.getExratescheme(creditAmount.get(0).getPk_org());
for (CreditAmountVO amountVO : creditAmount) {
this.oneCreditAmountCyc(amountVO, fvoccupiedflag, limitTypeVO, pk_exratescheme);
}
}
/**
* 得到信用检查信息(服装行业专用) BillQueryPara也传
*
* @param fvoccupiedflag
* @param limitTypeVO
* @param caVO
*
* @return
* @throws BusinessException
*/
private void getResultForFZHY(List<CreditAmountVO> creditAmount, Integer fvoccupiedflag, LimitTypeVO lt, BillQueryPara para) throws BusinessException {
String pk_exratescheme = CreditCommonUtil.getExratescheme(creditAmount.get(0).getPk_org());
for (CreditAmountVO amountVO : creditAmount) {
this.oneCreditAmountCycForFZHY(amountVO, fvoccupiedflag, lt, pk_exratescheme, para);
}
}
/**
* 信用信息单次循环
*
* @param amountVO
* @param fvoccupiedflag
* @param limitTypeVO
* @param pk_exratescheme
* @throws BusinessException
*/
private void oneCreditAmountCyc(CreditAmountVO amountVO, Integer fvoccupiedflag, LimitTypeVO limitTypeVO, String pk_exratescheme) throws BusinessException {
BillCreditQueryUtil bcqUtil = new BillCreditQueryUtil();
BillCreditQueryVO vo = new BillCreditQueryVO();
// 查询当前应收余额
QueryAccountMnyImpl service = new QueryAccountMnyImpl();
AccountMnyVO[] accountMny = service.queryAccountMny(amountVO);
// 计算5个应收,赋值到BillCreditQueryVO内
bcqUtil.getReceivable(accountMny, vo, amountVO, pk_exratescheme);
bcqUtil.setBillCreditQueryVO(amountVO, fvoccupiedflag, vo, limitTypeVO);
this.result.add(vo);
}
/**
* 信用信息单次循环(服装行业专用)
*
* @param amountVO
* @param fvoccupiedflag
* @param limitTypeVO
* @param pk_exratescheme
* @throws BusinessException
*/
private void oneCreditAmountCycForFZHY(CreditAmountVO amountVO, Integer fvoccupiedflag, LimitTypeVO limitTypeVO, String pk_exratescheme, BillQueryPara para) throws BusinessException {
BillCreditQueryUtil bcqUtil = new BillCreditQueryUtil();
BillCreditQueryVO vo = new BillCreditQueryVO();
// 查询当前应收余额
QueryAccountMnyImpl service = new QueryAccountMnyImpl();
AccountMnyVO[] accountMny = service.queryAccountMny(amountVO);
// 计算5个应收,赋值到BillCreditQueryVO内
bcqUtil.getReceivable(accountMny, vo, amountVO, pk_exratescheme);
bcqUtil.setBillCreditQueryVO(amountVO, fvoccupiedflag, vo, limitTypeVO);
this.resultFZHY.put(para, vo);
}
private void setMatchLimitType(boolean matchLimitType) {
this.matchLimitType = matchLimitType;
}
private boolean isMatchLimitType() {
return this.matchLimitType;
}
private void setMatchCreditAmount(boolean matchCreditAmount) {
this.matchCreditAmount = matchCreditAmount;
}
private boolean isMatchCreditAmount() {
return this.matchCreditAmount;
}
private void setMatchCreditOrg(boolean matchCreditOrg) {
this.matchCreditOrg = matchCreditOrg;
}
private boolean isMatchCreditOrg() {
return this.matchCreditOrg;
}
}
信用检查工具类——CreditCheckUtils
package nc.bs.credit.creditcheck;
import java.util.List;
import nc.bs.credit.pub.CreditCommonUtil;
import nc.pubitf.uapbd.CurrencyRateUtil;
import nc.vo.credit.creditamount.entity.CreditAmountVO;
import nc.vo.credit.engrossmaintain.entity.AccountMnyVO;
import nc.vo.credit.pub.ExamItemVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDouble;
import nc.vo.pubapp.calculator.AmountCalculator;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.vo.pubapp.pattern.pub.MathTool;
import nc.vo.scmpub.util.TimeUtils;
public class CreditCheckUtils {
/**
* 累加应收余额的各应收占用,并且进行币种转换,转化为额度类型的币种
*
* @param queryDatas
* @param amountVO
* @param pk_exratescheme2
* @param bSubFlag
* @return
*/
public AccountMnyVO addAccountMny(AccountMnyVO[] queryDatas, CreditAmountVO amountVO, String pk_exratescheme2) {
AccountMnyVO retAccountMnyVO = this.getNewAccountMnyVO(amountVO);
try {
if (null == queryDatas) {
return retAccountMnyVO;
}
// 根据信用控制域,获得汇率方案
String pk_exratescheme = pk_exratescheme2;
if (null == pk_exratescheme2) {
CreditCommonUtil.getExratescheme(amountVO.getPk_org());
}
String date = TimeUtils.getsrvBaseDate().toLocalString();
for (AccountMnyVO amVO : queryDatas) {
// 订单应收
UFDouble nMny = amVO.getNmny();
// 未确认应收
UFDouble nEstArMny = amVO.getNestarmny();
// 确认应收
UFDouble nArMny = amVO.getNarmny();
// 冲减应收
UFDouble nSubMny = amVO.getNsubmny();
// 收款未核销金额
UFDouble nNoverifyMny = amVO.getNnoverifymny();
// 转换为信用额度的币种
if (!amVO.getCorigcurrencyid().equals(amountVO.getCcurrencyid())) {
nMny = this.calAmountByDateRate(nMny, amVO.getCorigcurrencyid(), amountVO.getCcurrencyid(), date, pk_exratescheme);
nEstArMny = this.calAmountByDateRate(nEstArMny, amVO.getCorigcurrencyid(), amountVO.getCcurrencyid(), date, pk_exratescheme);
nArMny = this.calAmountByDateRate(nArMny, amVO.getCorigcurrencyid(), amountVO.getCcurrencyid(), date, pk_exratescheme);
nSubMny = this.calAmountByDateRate(nSubMny, amVO.getCorigcurrencyid(), amountVO.getCcurrencyid(), date, pk_exratescheme);
nNoverifyMny = this.calAmountByDateRate(nNoverifyMny, amVO.getCorigcurrencyid(), amountVO.getCcurrencyid(), date, pk_exratescheme);
}
retAccountMnyVO.setNmny(MathTool.add(nMny, retAccountMnyVO.getNmny()));
retAccountMnyVO.setNestarmny(MathTool.add(nEstArMny, retAccountMnyVO.getNestarmny()));
retAccountMnyVO.setNarmny(MathTool.add(nArMny, retAccountMnyVO.getNarmny()));
retAccountMnyVO.setNsubmny(MathTool.add(nSubMny, retAccountMnyVO.getNsubmny()));
retAccountMnyVO.setNnoverifymny(MathTool.add(nNoverifyMny, retAccountMnyVO.getNnoverifymny()));
}
} catch (Exception e) {
ExceptionUtils.wrappException(e);
}
return retAccountMnyVO;
}
/**
* 累加维度vo中记录的订单应收占用,并且进行币种转换,转化为额度类型的币种
*
* 动作检查函数使用的是维度vo,特提供此方法供检查函数使用
*
* @param list
* @param amountVO
* @param bSubFlag
* @return
*/
public AccountMnyVO addAccountMny(List<ExamItemVO> list, CreditAmountVO amountVO, String pk_exratescheme2) {
AccountMnyVO retAccountMnyVO = this.getNewAccountMnyVO(amountVO);
if (null == list) {
return retAccountMnyVO;
}
// 根据信用控制域,获得汇率方案
String pk_exratescheme = pk_exratescheme2;
if (null == pk_exratescheme2) {
CreditCommonUtil.getExratescheme(amountVO.getPk_org());
}
String date = TimeUtils.getsrvBaseDate().toLocalString();
for (ExamItemVO amVO : list) {
// 订单应收
UFDouble nMny = amVO.getNmny();
// 转换为信用额度的币种
if (!amVO.getCorigcurrencyid().equals(amountVO.getCcurrencyid())) {
nMny = AmountCalculator.calAmountByDateRate(nMny, amVO.getCorigcurrencyid(), amountVO.getCcurrencyid(), date, pk_exratescheme, null);
}
retAccountMnyVO.setNmny(MathTool.add(nMny, retAccountMnyVO.getNmny()));
}
return retAccountMnyVO;
}
/**
* 计算出占用值(按币种分组) = 订单应收 + 未确认应收 + 确认应收 – 冲减应收 – 收款未核销金额
*
* @return
*/
public UFDouble calculateEngrossMny(AccountMnyVO accountMnyVO) {
UFDouble sumMny = UFDouble.ZERO_DBL;
sumMny = MathTool.add(sumMny, accountMnyVO.getNmny());
sumMny = MathTool.add(sumMny, accountMnyVO.getNestarmny());
sumMny = MathTool.add(sumMny, accountMnyVO.getNarmny());
sumMny = MathTool.sub(sumMny, accountMnyVO.getNsubmny());
sumMny = MathTool.sub(sumMny, accountMnyVO.getNnoverifymny());
return sumMny;
}
/**
* 计算出占用值(不考虑币种) = 订单应收 + 未确认应收 + 确认应收 – 冲减应收 – 收款未核销金额
*
* @return
*/
public UFDouble calculateEngrossMnySameCurr(AccountMnyVO[] accountMnyVOs) {
UFDouble sumMny = UFDouble.ZERO_DBL;
if (null != accountMnyVOs && 0 != accountMnyVOs.length) {
for (AccountMnyVO vo : accountMnyVOs) {
sumMny = MathTool.add(sumMny, vo.getNmny());
sumMny = MathTool.add(sumMny, vo.getNestarmny());
sumMny = MathTool.add(sumMny, vo.getNarmny());
sumMny = MathTool.sub(sumMny, vo.getNsubmny());
sumMny = MathTool.sub(sumMny, vo.getNnoverifymny());
}
}
return sumMny;
}
private UFDouble calAmountByDateRate(UFDouble amount, String pk_src_currtype, String pk_dest_currtype, String date, String pk_exratescheme) throws BusinessException {
UFDouble rate = null;
CurrencyRateUtil rateUtil = CurrencyRateUtil.getInstanceByExrateScheme(pk_exratescheme);
rate = rateUtil.getRate(pk_src_currtype, pk_dest_currtype, new UFDate(date));
if (null == rate) {
String msg = nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4032001_0", "04032001-0058")/* @res "请先设置单据币种与信用额度币种间的汇率。" */;
ExceptionUtils.wrappBusinessException(msg);
}
return rateUtil.getAmountByOpp(pk_src_currtype, pk_dest_currtype, amount, rate, new UFDate(date));
}
private AccountMnyVO getNewAccountMnyVO(CreditAmountVO amountVO) {
AccountMnyVO accountMnyVO = new AccountMnyVO();
accountMnyVO.setPk_group(amountVO.getPk_group());
accountMnyVO.setPk_org(amountVO.getPk_org());
accountMnyVO.setClimittypeid(amountVO.getClimittypeid());
accountMnyVO.setCsaleorgid(amountVO.getCsaleorgid());
accountMnyVO.setCdeptid(amountVO.getCsaledeptid());
accountMnyVO.setCcustomerid(amountVO.getCcustomerid());
accountMnyVO.setCemployeeid(amountVO.getCemployeeid());
accountMnyVO.setCorigcurrencyid(amountVO.getCcurrencyid());
return accountMnyVO;
}
}
单据信用查询工具类——BillCreditQueryUtil
package nc.bs.credit.creditquery.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import nc.vo.credit.billcreditquery.entity.BillCreditQueryVO;
import nc.vo.credit.billcreditquery.para.BillQueryPara;
import nc.vo.credit.creditamount.entity.CreditAmountVO;
import nc.vo.credit.engrossmaintain.entity.AccountMnyVO;
import nc.vo.credit.limittype.entity.LimitTypeBtypeVO;
import nc.vo.credit.limittype.entity.LimitTypeCtypeVO;
import nc.vo.credit.limittype.entity.LimitTypePrcVO;
import nc.vo.credit.limittype.entity.LimitTypeVO;
import nc.vo.credit.limittype.pub.MatchLimitTypePara;
import nc.vo.org.FinanceOrgVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.SuperVO;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDouble;
import nc.vo.pubapp.pattern.data.ValueUtils;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.vo.pubapp.pattern.pub.MapList;
import nc.vo.pubapp.pattern.pub.MathTool;
import nc.vo.pubapp.pattern.pub.PubAppTool;
import nc.vo.scmpub.res.billtype.ECBillType;
import nc.vo.scmpub.res.billtype.ICBillType;
import nc.vo.scmpub.res.billtype.SOBillType;
import nc.itf.scmpub.reference.uap.bd.customer.CustomerPubService;
import nc.itf.scmpub.reference.uap.org.GroupQryService;
import nc.pubitf.credit.creditamount.MatchCreditMnyPara;
import nc.pubitf.org.IFinanceOrgPubService;
import nc.bs.credit.creditcheck.CreditCheckUtils;
import nc.bs.credit.pub.CreditCommonUtil;
import nc.bs.framework.common.NCLocator;
import nc.bs.ml.NCLangResOnserver;
import nc.impl.credit.limittype.LimitTypeQueryImpl;
import nc.impl.pubapp.env.BSContext;
import nc.pubimpl.credit.creditamount.MatchCreditMnyImpl;
/**
* 单据信用查询工具类
*
*/
public class BillCreditQueryUtil {
/**
* 虚拟一条信用额度为0的记录
*
* @param pk_org
* @param pk_lt
* @param para
* @return
*/
public CreditAmountVO dummyCreditAmount(String pk_org, String pk_lt, BillQueryPara para) {
CreditAmountVO vo = new CreditAmountVO();
vo.setPk_org(pk_org);
vo.setClimittypeid(pk_lt);
vo.setCcustomerid(para.getCcustomerid());
vo.setBcdownsaleflag(UFBoolean.FALSE);
// 取集团本位币
String pk_group = BSContext.getInstance().getGroupID();
String ccurrencyid = GroupQryService.queryGroupCurrency(pk_group);
vo.setCcurrencyid(ccurrencyid);
vo.setNlimitmny(UFDouble.ZERO_DBL);
vo.setPk_group(pk_group);
return vo;
}
/**
* 过滤掉客户为空的记录,如果客户全为空,则报错
*
* @param vos
* @return
*/
public List<BillQueryPara> filterCustomer(BillQueryPara[] vos) {
List<BillQueryPara> list = new ArrayList<BillQueryPara>();
for (BillQueryPara vo : vos) {
if (vo.getCcustomerid() != null) {
list.add(vo);
}
}
if (list.size() == 0) {
ExceptionUtils.wrappBusinessException(NCLangResOnserver.getInstance().getStrByID("4032001_0", "04032001-0184")/* 客户不能为空。 */);
}
return list;
}
/**
* 按财务组织+产品线+订单类型+渠道类型+销售组织+销售部门+销售业务员+客户过滤重复
*
* @param plist
* @return
*/
public List<BillQueryPara> filterDim(List<BillQueryPara> plist) {
Map<String, BillQueryPara> dim = new HashMap<String, BillQueryPara>();
for (BillQueryPara para : plist) {
String key = para.getCfinanceorgid() + para.getCprodlineid() + para.getVtrantypecode() + para.getCchanneltypeid() + para.getCsaleorgid() + para.getCsaledeptid() + para.getCemployeeid()
+ para.getCcustomerid();
dim.put(key, para);
}
List<BillQueryPara> ret = new ArrayList<BillQueryPara>();
ret.addAll(dim.values());
return ret;
}
/**
* 从信用检查参数中过滤空、重复的财务组织
*
* @param paras 信用查询参数
* @return 信用查询参数
*/
public String[] filterForg(BillQueryPara[] paras) {
Set<String> fSet = new HashSet<String>();
for (BillQueryPara para : paras) {
if (null != para.getCfinanceorgid()) {
fSet.add(para.getCfinanceorgid());
}
}
if (0 == fSet.size()) {
ExceptionUtils.wrappBusinessException(NCLangResOnserver.getInstance().getStrByID("4032001_0", "04032001-0059")/* 财务组织为空。 */);
}
return fSet.toArray(new String[0]);
}
/**
* 从信用检查参数中过滤重复的财务组织,如果有财务组织为空,则查询所有的财务组织
*
* @param paras 信用查询参数
* @return 信用查询参数
* @throws BusinessException
*/
public String[] filterForgForEC(BillQueryPara[] paras) throws BusinessException {
Set<String> fSet = new HashSet<String>();
for (BillQueryPara para : paras) {
if (null != para.getCfinanceorgid()) {
fSet.add(para.getCfinanceorgid());
} else {
String pk_group = BSContext.getInstance().getGroupID();
IFinanceOrgPubService service = NCLocator.getInstance().lookup(IFinanceOrgPubService.class);
FinanceOrgVO[] vos = service.queryAllFinanceOrgVOSByGroupID(pk_group);
if (null != vos && vos.length > 0) {
Set<String> set_allOrgs = new HashSet<String>();
for (FinanceOrgVO orgVO : vos) {
set_allOrgs.add(orgVO.getPk_financeorg());
}
return set_allOrgs.toArray(new String[0]);
}
}
}
return fSet.toArray(new String[0]);
}
/**
* 得到 产品线+订单类型+渠道类型 - 额度类型
*
* @param billType
*
* @param entry
* @param billType
* @return
* @throws Exception
*/
public Map<String, List<LimitTypeVO>> getLimitType(Entry<String, List<BillQueryPara>> corg_lst, String billType) throws BusinessException {
String creditOrg = corg_lst.getKey();
List<BillQueryPara> lpara = corg_lst.getValue();
MatchLimitTypePara[] paras = new MatchLimitTypePara[lpara.size()];
int i = 0;
for (BillQueryPara bqp : lpara) {
if (ICBillType.BorrowOut.getCode().equals(billType)) {
paras[i++] = new MatchLimitTypePara(bqp.getCprodlineid(), bqp.getVtrantypecode() == null ? "all" : bqp.getVtrantypecode(), bqp.getCchanneltypeid() == null ? "all" : bqp.getCchanneltypeid());
} else if (SOBillType.PreOrder.getCode().equals(billType) || SOBillType.SaleQuotation.getCode().equals(billType) || ECBillType.ECPreOrder.getCode().equals(billType)) {
paras[i++] = new MatchLimitTypePara(bqp.getCprodlineid(), bqp.getVtrantypecode() == null ? "all" : bqp.getVtrantypecode(), bqp.getCchanneltypeid());
} else if (SOBillType.Order.getCode().equals(billType) || SOBillType.Invoice.getCode().equals(billType) || SOBillType.Delivery.getCode().equals(billType) || null == billType) {
paras[i++] = new MatchLimitTypePara(bqp.getCprodlineid(), bqp.getVtrantypecode(), bqp.getCchanneltypeid());
}
}
Map<String, List<LimitTypeVO>> ltMap = this.getMatchLimitType(creditOrg, paras, billType);
return ltMap;
}
private Map<String, List<LimitTypeVO>> getMatchLimitType(String creditorg, MatchLimitTypePara[] paras, String billType) throws BusinessException {
Map<String, List<LimitTypeVO>> maplist = new HashMap<String, List<LimitTypeVO>>();
try {
LimitTypeQueryImpl queryImpl = new LimitTypeQueryImpl();
LimitTypeVO[] bills = queryImpl.queryVOByCOrg(new String[] { creditorg });
if (bills.length == 0) {
return maplist;
}
for (MatchLimitTypePara para : paras) {
List<LimitTypeVO> list = this.match(bills, para);
String key = null;
if (ICBillType.BorrowOut.getCode().equals(billType)) {
key = para.getCprodlineid() + (para.getVtrantypecode() == null ? "all" : para.getVtrantypecode()) + (para.getCchanneltypeid() == null ? "all" : para.getCchanneltypeid());
} else if (SOBillType.PreOrder.getCode().equals(billType) || SOBillType.SaleQuotation.getCode().equals(billType) || ECBillType.ECPreOrder.getCode().equals(billType)) {
key = para.getCprodlineid() + (para.getVtrantypecode() == null ? "all" : para.getVtrantypecode()) + para.getCchanneltypeid();
} else if (SOBillType.Order.getCode().equals(billType) || SOBillType.Invoice.getCode().equals(billType) || SOBillType.Delivery.getCode().equals(billType) || null == billType) {
key = para.getCprodlineid() + para.getVtrantypecode() + para.getCchanneltypeid();
}
if (list != null && list.size() > 0) {
maplist.put(key, list);
}
}
} catch (Exception e) {
ExceptionUtils.marsh(e);
}
return maplist;
}
public Map<String, List<LimitTypeVO>> getLimitTypeForEC(Entry<String, List<BillQueryPara>> corg_lst) throws BusinessException {
String creditOrg = corg_lst.getKey();
List<BillQueryPara> lpara = corg_lst.getValue();
MatchLimitTypePara[] paras = new MatchLimitTypePara[lpara.size()];
int i = 0;
for (BillQueryPara bqp : lpara) {
paras[i++] = new MatchLimitTypePara(bqp.getCprodlineid() == null ? "all" : bqp.getCprodlineid(), bqp.getVtrantypecode() == null ? "all" : bqp.getVtrantypecode(),
bqp.getCchanneltypeid() == null ? "all" : bqp.getCchanneltypeid());
}
Map<String, List<LimitTypeVO>> ltMap = this.getMatchLimitTypeForEC(creditOrg, paras);
return ltMap;
}
private Map<String, List<LimitTypeVO>> getMatchLimitTypeForEC(String creditorg, MatchLimitTypePara[] paras) throws BusinessException {
Map<String, List<LimitTypeVO>> maplist = new HashMap<String, List<LimitTypeVO>>();
try {
LimitTypeQueryImpl queryImpl = new LimitTypeQueryImpl();
LimitTypeVO[] bills = queryImpl.queryVOByCOrg(new String[] { creditorg });
if (bills.length == 0) {
return maplist;
}
for (MatchLimitTypePara para : paras) {
List<LimitTypeVO> list = this.match(bills, para);
String key = null;
key = (para.getCprodlineid() == null ? "all" : para.getCprodlineid()) + (para.getVtrantypecode() == null ? "all" : para.getVtrantypecode())
+ (para.getCchanneltypeid() == null ? "all" : para.getVtrantypecode());
if (list != null && list.size() > 0) {
maplist.put(key, list);
}
}
} catch (Exception e) {
ExceptionUtils.marsh(e);
}
return maplist;
}
private List<LimitTypeVO> match(LimitTypeVO[] bills, MatchLimitTypePara para) {
List<LimitTypeVO> list = new ArrayList<LimitTypeVO>();
for (LimitTypeVO bill : bills) {
boolean bcontainflag = this.checkContainItem(bill.getLimitTypePrcItem(), para.getCprodlineid(), LimitTypePrcVO.CPRODLINEID);
if (!bcontainflag) {
continue;
}
bcontainflag = this.checkContainItem(bill.getLimitTypeBtypeItem(), para.getVtrantypecode(), LimitTypeBtypeVO.VTRANTYPECODE);
if (!bcontainflag) {
continue;
}
bcontainflag = this.checkContainItem(bill.getLimitTypeCtypeItem(), para.getCchanneltypeid(), LimitTypeCtypeVO.CCHANNELTYPEID);
if (bcontainflag) {
list.add(bill);
}
}
return list;
}
private boolean checkContainItem(SuperVO[] vos, String id, String column) {
boolean flag = false;
// 为客户联查提供的,当该字段为all时,则任务不按其过滤匹配所有
if (!PubAppTool.isNull(id) && PubAppTool.isEqual(id, "all")) {
return true;
}
if (null == vos || vos.length == 0) {
return true;
}
for (SuperVO vo : vos) {
String value = ValueUtils.getString(vo.getAttributeValue(column));
if (PubAppTool.isEqual(value, id)) {
flag = true;
break;
}
}
return flag;
}
/**
* 得到“基于上级信用控制的客户”
*
* @param corg_lst
* @return
* @throws BusinessException
*/
public boolean getRootCustomerByCtrlType(Entry<String, List<BillQueryPara>> corg_lst) throws BusinessException {
try {
List<BillQueryPara> l_bqp = corg_lst.getValue();
String pk_org = corg_lst.getKey();
// 客户在表头,所以所有客户都一样
// String[] custPkS = new String[] {
// l_bqp.get(0).getCcustomerid()
// };
// 为接口和列表界面的查询做修改
String[] custPkS = new String[l_bqp.size()];
for (int i = 0; i < l_bqp.size(); i++) {
custPkS[i] = l_bqp.get(i).getCcustomerid();
}
Map<String, String> custMap = CustomerPubService.queryRootCustomerByCreditType(custPkS, pk_org);
if (null == custMap || custMap.size() == 0) {
return false;
}
// 如果客户不基于上级信用控制,则custMap中放他本身,否则信用额度中的客户更新为上级客户。
for (BillQueryPara bqp : l_bqp) {
String custId = bqp.getCcustomerid();
if (custId != null && null != custMap.get(custId)) {
bqp.setCcustomerid(custMap.get(custId));
}
}
} catch (Exception e) {
ExceptionUtils.wrappException(e);
}
return true;
}
/**
* 得到信用控制域对应的待查询vo
*
* @param controlOrgs
* @param paras
* @return
*/
public Map<String, List<BillQueryPara>> groupByCreditOrg(Map<String, List<String>> financeOrgs_controlOrgs, List<BillQueryPara> paras) {
// 信用控制域 - 待查询vo
MapList<String, BillQueryPara> controlOrgs_paras = new MapList<String, BillQueryPara>();
Iterator<BillQueryPara> parasIte = paras.iterator();
while (parasIte.hasNext()) {
BillQueryPara para = parasIte.next();
// 取出待检查vo对应的信用控制域
List<String> controlOrgs = financeOrgs_controlOrgs.get(para.getCfinanceorgid());
if (null != controlOrgs) {
Iterator<String> controlOrgsIte = controlOrgs.iterator();
while (controlOrgsIte.hasNext()) {
controlOrgs_paras.put(controlOrgsIte.next(), para);
}
}
}
return controlOrgs_paras.toMap();
}
public Map<String, List<BillQueryPara>> groupByCreditOrgForEC(Map<String, List<String>> forg_cOrgs, List<BillQueryPara> plist) {
// 匹配到的所有信用控制域
Set<String> set_creditOrg = new HashSet<String>();
Collection<List<String>> c = forg_cOrgs.values();
for (Iterator<List<String>> iterator = c.iterator(); iterator.hasNext();) {
List<String> list = iterator.next();
for (Iterator<String> iterator2 = list.iterator(); iterator2.hasNext();) {
set_creditOrg.add(iterator2.next());
}
}
// 信用控制域 - 待查询vo
MapList<String, BillQueryPara> controlOrgs_paras = new MapList<String, BillQueryPara>();
Iterator<BillQueryPara> parasIte = plist.iterator();
while (parasIte.hasNext()) {
BillQueryPara para = parasIte.next();
String fOrg = para.getCfinanceorgid();
if (null == fOrg) {
for (String creditOrg : set_creditOrg) {
controlOrgs_paras.put(creditOrg, para);
}
} else {
// 取出待检查vo对应的信用控制域
List<String> controlOrgs = forg_cOrgs.get(fOrg);
if (null != controlOrgs) {
Iterator<String> controlOrgsIte = controlOrgs.iterator();
while (controlOrgsIte.hasNext()) {
controlOrgs_paras.put(controlOrgsIte.next(), para);
}
}
}
}
return controlOrgs_paras.toMap();
}
/**
* 将查询数据按额度类型分组
*
* @param ltMap 产品线+订单类型+渠道类型 - 额度类型[]
* @param billType 单据类型
* @param paras 查询数据[]
* @param billType
* @return 额度类型-BillQueryPara[]
*/
public Map<LimitTypeVO, List<BillQueryPara>> groupParaByLimitType(Map<String, List<LimitTypeVO>> ltMap, List<BillQueryPara> paras, String billType) {
MapList<String, BillQueryPara> para = new MapList<String, BillQueryPara>();
Map<String, LimitTypeVO> ltPK_lt = new HashMap<String, LimitTypeVO>();
Map<LimitTypeVO, List<BillQueryPara>> ltVO_Bqp = new HashMap<LimitTypeVO, List<BillQueryPara>>();
this.getLimitTypeVO(para, ltPK_lt, paras, ltMap, billType);
// 得到limitTypeVO - BillQueryPara
for (Entry<String, List<BillQueryPara>> entry : para.toMap().entrySet()) {
LimitTypeVO vo = ltPK_lt.get(entry.getKey());
ltVO_Bqp.put(vo, entry.getValue());
}
return ltVO_Bqp;
}
/**
* 根据单据类型获得额度类型
*
* @param ltMap
* @param para
* @param billType
* @param ltMap
* @param billType
* @return
*/
private void getLimitTypeVO(MapList<String, BillQueryPara> ltPK_Bqps, Map<String, LimitTypeVO> ltPK_lt, List<BillQueryPara> paras, Map<String, List<LimitTypeVO>> ltMap, String billType) {
List<LimitTypeVO> ltLst = null;
for (BillQueryPara para : paras) {
String key = null;
if (ICBillType.BorrowOut.getCode().equals(billType)) {
key = para.getCprodlineid() + (para.getVtrantypecode() == null ? "all" : para.getVtrantypecode()) + (para.getCchanneltypeid() == null ? "all" : para.getCchanneltypeid());
} else if (SOBillType.PreOrder.getCode().equals(billType) || SOBillType.SaleQuotation.getCode().equals(billType) || ECBillType.ECPreOrder.getCode().equals(billType)) {
key = para.getCprodlineid() + (para.getVtrantypecode() == null ? "all" : para.getVtrantypecode()) + para.getCchanneltypeid();
} else if (SOBillType.Order.getCode().equals(billType) || SOBillType.Invoice.getCode().equals(billType) || SOBillType.Delivery.getCode().equals(billType) || null == billType) {
key = para.getCprodlineid() + para.getVtrantypecode() + para.getCchanneltypeid();
}
if (null != key) {
ltLst = ltMap.get(key);
if (ltLst != null && ltLst.size() > 0) {
for (LimitTypeVO ltVO : ltLst) {
ltPK_Bqps.put(ltVO.getPrimaryKey(), para);
ltPK_lt.put(ltVO.getPrimaryKey(), ltVO);
}
}
}
}
}
public Map<LimitTypeVO, List<BillQueryPara>> groupParaByLimitTypeForEC(Map<String, List<LimitTypeVO>> ltMap, List<BillQueryPara> paras) {
MapList<String, BillQueryPara> para = new MapList<String, BillQueryPara>();
Map<String, LimitTypeVO> ltPK_lt = new HashMap<String, LimitTypeVO>();
Map<LimitTypeVO, List<BillQueryPara>> ltVO_Bqp = new HashMap<LimitTypeVO, List<BillQueryPara>>();
this.getLimitTypeVOForEC(para, ltPK_lt, paras, ltMap);
// 得到limitTypeVO - BillQueryPara
for (Entry<String, List<BillQueryPara>> entry : para.toMap().entrySet()) {
LimitTypeVO vo = ltPK_lt.get(entry.getKey());
ltVO_Bqp.put(vo, entry.getValue());
}
return ltVO_Bqp;
}
private void getLimitTypeVOForEC(MapList<String, BillQueryPara> ltPK_Bqps, Map<String, LimitTypeVO> ltPK_lt, List<BillQueryPara> paras, Map<String, List<LimitTypeVO>> ltMap) {
List<LimitTypeVO> ltLst = null;
for (BillQueryPara para : paras) {
String key = (para.getCprodlineid() == null ? "all" : para.getCprodlineid()) + (para.getVtrantypecode() == null ? "all" : para.getVtrantypecode())
+ (para.getCchanneltypeid() == null ? "all" : para.getCchanneltypeid());
ltLst = ltMap.get(key);
if (ltLst != null && ltLst.size() > 0) {
for (LimitTypeVO ltVO : ltLst) {
ltPK_Bqps.put(ltVO.getPrimaryKey(), para);
ltPK_lt.put(ltVO.getPrimaryKey(), ltVO);
}
}
}
}
public void setBillCreditQueryVO(CreditAmountVO amountVO, Integer fvoccupiedflag, BillCreditQueryVO vo, LimitTypeVO ltVO) {
// 信用控制域
vo.setPk_org(amountVO.getPk_org());
// 额度类型
vo.setClimittypeid(amountVO.getClimittypeid());
// 销售组织
vo.setCsaleorgid(amountVO.getCsaleorgid());
// 销售部门
vo.setCdeptid(amountVO.getCsaledeptid());
// 销售业务员
vo.setCemployeeid(amountVO.getCemployeeid());
// 客户
vo.setCcustomerid(amountVO.getCcustomerid());
// 币种
vo.setCorigcurrencyid(amountVO.getCcurrencyid());
// 信用额度
vo.setNlimitmny(amountVO.getNlimitmny());
// 信用余额
vo.setNbalancemny(MathTool.sub(amountVO.getNlimitmny(), vo.getNengrossmny()));
// 信用占用开始时点
vo.setFvoccupiedflag(fvoccupiedflag);
// 集团
vo.setPk_group(amountVO.getPk_group());
// 产品线
vo.setCprodlineids(CreditCommonUtil.getSuperVOPks(ltVO.getLimitTypePrcItem(), LimitTypePrcVO.CPRODLINEID));
// 订单类型
vo.setCtrantypeids(CreditCommonUtil.getSuperVOPks(ltVO.getLimitTypeBtypeItem(), LimitTypeBtypeVO.VTRANTYPECODE));
// 渠道类型
vo.setCchanneltypeids(CreditCommonUtil.getSuperVOPks(ltVO.getLimitTypeCtypeItem(), LimitTypeCtypeVO.CCHANNELTYPEID));
}
/**
* 获得信用额度
*
* @param paraList 信用查询参数
* @param corg 信用控制域
* @param pk_limitType 额度类型
* @param date 匹配信用额度的时间
* @return 信用额度
*/
public Map<String, List<CreditAmountVO>> getCreditAmount(List<BillQueryPara> paraList, String corg, String pk_limitType, UFDate date) {
try {
List<MatchCreditMnyPara> mcmList = new ArrayList<MatchCreditMnyPara>();
for (BillQueryPara para : paraList) {
MatchCreditMnyPara mcmPara = new MatchCreditMnyPara(corg, pk_limitType, para.getCsaleorgid(), para.getCsaledeptid(), para.getCemployeeid(), para.getCcustomerid());
mcmList.add(mcmPara);
}
MatchCreditMnyImpl mcm = new MatchCreditMnyImpl();
return mcm.batchmatchCreditMny(mcmList.toArray(new MatchCreditMnyPara[0]), date);
} catch (BusinessException e) {
ExceptionUtils.wrappException(e);
}
return new HashMap<String, List<CreditAmountVO>>();
}
public Map<String, List<CreditAmountVO>> getCreditAmountForEC(List<BillQueryPara> paraList, String corg, String pk_limitType, UFDate date) {
try {
List<MatchCreditMnyPara> mcmList = new ArrayList<MatchCreditMnyPara>();
for (BillQueryPara para : paraList) {
MatchCreditMnyPara mcmPara = new MatchCreditMnyPara(corg, pk_limitType, para.getCsaleorgid(), para.getCsaledeptid(), para.getCemployeeid(), para.getCcustomerid());
mcmList.add(mcmPara);
}
MatchCreditMnyImpl mcm = new MatchCreditMnyImpl();
return mcm.batchmatchCreditMnyForEC(mcmList.toArray(new MatchCreditMnyPara[0]), date);
} catch (BusinessException e) {
ExceptionUtils.wrappException(e);
}
return new HashMap<String, List<CreditAmountVO>>();
}
/**
* 检查参数vo、财务组织、订单客户是否为空
*
* @param vos
*/
@SuppressWarnings("null")
public void checkNull(BillQueryPara[] paras) {
if (null == paras || 0 == paras.length) {
ExceptionUtils.wrappBusinessException(NCLangResOnserver.getInstance().getStrByID("4032001_0", "04032001-0061")/* 查询vo不能为空,请检查 */);
}
for (BillQueryPara para : paras) {
if (null == para.getCcustomerid()) {
ExceptionUtils.wrappBusinessException(NCLangResOnserver.getInstance().getStrByID("4032001_0", "04032001-0184")/* 客户不能为空。 */);
}
if (null == para.getCfinanceorgid()) {
ExceptionUtils.wrappBusinessException(NCLangResOnserver.getInstance().getStrByID("4032001_0", "04032001-0059")/* 财务组织为空。 */);
}
}
}
/**
* 检查参数vo、订单客户是否为空
*
* @param vos
*/
@SuppressWarnings("null")
public void checkNullForEC(BillQueryPara[] paras) {
if (null == paras || 0 == paras.length) {
ExceptionUtils.wrappBusinessException(NCLangResOnserver.getInstance().getStrByID("4032001_0", "04032001-0061")/* 查询vo不能为空,请检查 */);
}
for (BillQueryPara para : paras) {
if (null == para.getCcustomerid()) {
ExceptionUtils.wrappBusinessException(NCLangResOnserver.getInstance().getStrByID("4032001_0", "04032001-0184")/* 客户不能为空。 */);
}
}
}
/**
* 计算5个应收,赋值到BillCreditQueryVO内
*
* @param queryDatas
* @param bcqVO
* @param pk_exratescheme
* @param bSubFlag
* @param string
*/
public void getReceivable(AccountMnyVO[] queryDatas, BillCreditQueryVO bcqVO, CreditAmountVO amountVO, String pk_exratescheme) {
CreditCheckUtils ccUtils = new CreditCheckUtils();
AccountMnyVO amVO = ccUtils.addAccountMny(queryDatas, amountVO, pk_exratescheme);
bcqVO.setNmny(amVO.getNmny());
bcqVO.setNestarmny(amVO.getNestarmny());
bcqVO.setNarmny(amVO.getNarmny());
bcqVO.setNnoverifymny(amVO.getNnoverifymny());
bcqVO.setNsubmny(amVO.getNsubmny());
bcqVO.setNengrossmny(this.nvl(amVO.getNmny()).add(this.nvl(amVO.getNestarmny())).add(this.nvl(amVO.getNarmny())).sub(this.nvl(amVO.getNnoverifymny())).sub(this.nvl(amVO.getNsubmny())));
}
private UFDouble nvl(UFDouble d) {
return d == null ? UFDouble.ZERO_DBL : d;
}
}