背景: v6医药行业 消耗汇总 参照 销售出库单 弹出的查询对话框里的 产品批号 条件原本是参照格式,根据vfree6 自有辅助属性6 linked 得到的 。
客户不满意该处,需要找物料才能进行查询,要求只需要输入一个模糊的 批号的值, 就可以查询该批号的出库单。
修改后代码如下:liljb编辑。
package nc.ui.ic.m50.action;
import java.util.ArrayList;
import java.util.List;
import nc.bs.framework.common.NCLocator;
import nc.itf.ic.vmirule.IVmiRuleService;
import nc.itf.uap.IUAPQueryBS;
import nc.pubitf.rbac.IFunctionPermissionPubService;
import nc.ui.ic.m50.model.VmiSumModelService;
import nc.ui.ic.m50.query.VmiSumQueryCondProcessor;
import nc.ui.ic.m50.view.ICVmiSumDialog;
import nc.ui.pubapp.uif2app.query2.QueryConditionDLGDelegator;
import nc.ui.pubapp.uif2app.query2.action.DefaultQueryAction;
import nc.ui.pubapp.uif2app.query2.model.ModelDataManager;
import nc.ui.querytemplate.querytree.FromWhereSQL;
import nc.ui.querytemplate.querytree.FromWhereSQLImpl;
import nc.ui.querytemplate.querytree.IQueryScheme;
import nc.ui.scmpub.action.SCMActionInitializer;
import nc.vo.ic.m50.entity.VmiSumGenerateParam;
import nc.vo.ic.m50.entity.VmiSumQueryParam;
import nc.vo.ic.pub.define.ICPubMetaNameConst;
import nc.vo.ic.pub.util.CollectionUtils;
import nc.vo.ic.pub.util.ValueCheckUtil;
import nc.vo.ic.vmirule.entity.VmiRuleHeadVO;
import nc.vo.ic.vmirule.entity.VmiRuleVO;
import nc.vo.org.OrgVO;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.AppContext;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.vo.pubapp.pattern.pub.PubAppTool;
import nc.vo.pubapp.pattern.pub.SqlBuilder;
import nc.vo.pubapp.query2.sql.process.QuerySchemeProcessor;
import nc.vo.scmpub.res.SCMActionCode;
/**
* 消耗汇总查询Action;此动作查询出库单进行消耗汇总
*/
public class VmiSumOutBillAction extends DefaultQueryAction {
private static final long serialVersionUID = 2010090423320001L;
/**
* 显示生成消耗汇总单查询结果的对话框,即显示出库单VO和销售发票VO的对话框
*/
private ICVmiSumDialog icVmiSumDialog;
private VmiSumQueryCondProcessor vmiSumQueryCondProcessor = null;
public VmiSumOutBillAction() {
SCMActionInitializer.initializeAction(this, SCMActionCode.IC_VMISUMOUTBILL);
}
public ICVmiSumDialog getIcVmiSumDialog() {
if (this.icVmiSumDialog == null) {
this.icVmiSumDialog =
new ICVmiSumDialog(this.getModel().getContext().getEntranceUI());
this.icVmiSumDialog.initQueryDialog(this, this.icVmiSumDialog);
}
return this.icVmiSumDialog;
}
public VmiSumGenerateParam getVmiSumGenerateParam() {
return this.getCondProcessor().getVmiSumGenerateParam();
}
public VmiSumQueryParam getVmiSumQueryParam() {
return this.getCondProcessor().getVmiSumQueryParam();
}
public void setIcVmiSumDialog(ICVmiSumDialog dialog) {
this.icVmiSumDialog = dialog;
}
private void constructParams(QueryConditionDLGDelegator delegator) {
// 获取Sql串时,不需要生成真正的Sql串,而是生成一个查询条件对象vmiSumQueryParam
FromWhereSQL querySQL =
delegator.getQueryConditionDLG().getTableJoinFromWhereSQL();
String fromPart = querySQL.getFrom();
String wherePart = querySQL.getWhere();
if (!PubAppTool.isNull(fromPart)) {
fromPart = fromPart.replace(" ic_flow", " flow");
}
if (!PubAppTool.isNull(wherePart)) {
wherePart = wherePart.replace("ic_flow.", "flow.");
}
this.getCondProcessor()
.fillVmiSumQueryParam(delegator, fromPart, wherePart);
this.getCondProcessor().fillVmiSumGenerateParam(delegator);
}
private VmiSumQueryCondProcessor getCondProcessor() {
if (this.vmiSumQueryCondProcessor == null) {
this.vmiSumQueryCondProcessor = new VmiSumQueryCondProcessor();
}
return this.vmiSumQueryCondProcessor;
}
private String[] getFuncPermissionOrg(OrgVO[] orgVOs) {
if (orgVOs == null) {
return null;
}
String[] pk_orgs = new String[orgVOs.length];
for (int i = 0; i < pk_orgs.length; i++) {
pk_orgs[i] = orgVOs[i].getPk_org();
}
return pk_orgs;
}
/**
* 权限校验
*
* @param cvmiruleid
*/
private void validatePower(String cvmiruleid) {
VmiRuleVO[] ruleVO = null;
try {
SqlBuilder sqlpart = new SqlBuilder();
sqlpart.append(
VmiRuleHeadVO.TABLE_NAME + "." + VmiRuleHeadVO.CVMIRULEHID,
cvmiruleid);
ruleVO =
NCLocator.getInstance().lookup(IVmiRuleService.class)
.query(sqlpart.toString());
}
catch (BusinessException e) {
ExceptionUtils.wrappException(e);
return;
}
final String funcode = "40082802";
String cuserid = AppContext.getInstance().getPkUser();
String pkGroup = AppContext.getInstance().getPkGroup();
List<String> orgList = new ArrayList<String>();
try {
OrgVO[] orgVOs =
NCLocator.getInstance().lookup(IFunctionPermissionPubService.class)
.getUserPermissionOrg(cuserid, funcode, pkGroup);
String[] orgs = this.getFuncPermissionOrg(orgVOs);
CollectionUtils.addArrayToList(orgList, orgs);
}
catch (BusinessException e) {
ExceptionUtils.wrappException(e);
}
if (ValueCheckUtil.isNullORZeroLength(ruleVO)) {
ExceptionUtils
.wrappBusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
.getStrByID("4008015_0", "04008015-0011")/*@res "请检查消耗汇总规则是否已经被删除"*/);
return;
}
for (VmiRuleVO rule : ruleVO) {
if (!orgList.contains(rule.getParentVO().getAttributeValue(
VmiRuleHeadVO.PK_ORG))) {
ExceptionUtils
.wrappBusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
.getStrByID("4008015_0", "04008015-0012")/*@res "当前用户没有汇总规则定义中财务组织的数据权限"*/);
return;
}
}
}
@Override
protected void executeQuery(IQueryScheme queryScheme) {
QueryConditionDLGDelegator delegator = this.getQryDLGDelegator();
this.constructParams(delegator);
// 注:通过参数传过来的sqlWhere没有用,生成消耗汇总单不需要这个参数
// 因为
// 1. 查询参数已经包装成vmiSumQueryParam,需要传到后台进行复杂的sql逻辑处理
// 2. 生成消耗汇总单的参数已经包装成vmiSumGenerateParam,需要传到后台进行消耗汇总
VmiSumQueryParam vmiSumQueryParam = this.getVmiSumQueryParam();
// String sqlold=queryScheme.getTableJoinFromWhereSQL();
String old=queryScheme.getTableJoinFromWhereSQL().getWhere().toString(); //liljb add
String new1="";//liljb add
FromWhereSQLImpl newFrom= (FromWhereSQLImpl) queryScheme.getTableJoinFromWhereSQL();//liljb add
//增加下面的if 判断 如果有vfree7 的sql 进行替换处理 liljb
if(old.contains("AND ic_flow.vfree7 = '")){
old.length();
int indexofnext = old.indexOf("AND ic_flow.vfree7 = '");
String old2=old.substring(indexofnext+22, old.length());
int indexofnext2=old2.indexOf("'");
int len=indexofnext+22+indexofnext2;
String old3=old.substring(indexofnext, len+1);
new1= old.substring(indexofnext+22, indexofnext+22+indexofnext2);
System.out.println(new1);
String sqlmid="AND ic_flow.vfree6 IN ( SELECT mlot.pk_lotno FROM med_lotno_148 mlot where mlot.vlotno like '%"+new1+"%' AND nvl(mlot.dr,0)=0 ) ";
String old4= old.replace(old3, sqlmid);
newFrom.setWhere(old4);
}
//return FromWhereSQL 接口
queryScheme.getTableJoinFromWhereSQL();
// vmiSumQueryParam.setFromWhereSQL(queryScheme.getTableJoinFromWhereSQL()); OLD liljb 消耗汇总出库单查询替换vfree6为7
vmiSumQueryParam.setFromWhereSQL(newFrom);//liljb 替换上行代码
QuerySchemeProcessor proc = new QuerySchemeProcessor(queryScheme);
String[] dbilldate =
proc.getQueryCondition(ICPubMetaNameConst.DBILLDATE).getValues();
vmiSumQueryParam.setDbilldate(dbilldate);
this.validatePower(vmiSumQueryParam.getCvmirulehid());
ModelDataManager dataManager = (ModelDataManager) super.getDataManager();
VmiSumModelService service =
(VmiSumModelService) dataManager.getQryService();
try {
this.getIcVmiSumDialog().setViewData(
service.generateVmiSumQuery(vmiSumQueryParam));
this.getIcVmiSumDialog().setVmiSumGenerateParam(
this.getVmiSumGenerateParam());
this.getIcVmiSumDialog().showModal();
}
catch (Exception e) {
ExceptionUtils.wrappException(e);
}
}
/**
* 生成消耗汇总单汇总条件提示信息
*/
@Override
protected void showQueryInfo() {
//
}
}