From 938d677f004a20095ce32be1dfa523d10f27e558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=8E?= <125556714+Topfunplus@users.noreply.github.com> Date: Fri, 6 Jun 2025 12:32:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8F=91=E7=A5=A8=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重构了 ApplicationQryAction 和 IVApplicationQueryService 接口 - 新增 queryByInvoiceNumberAndAggPK 方法用于查询开票记录 -优化了分页查询逻辑,支持特殊查询条件下的手动分页- 调整了 SQL构建方式,提高了查询效率 --- .../impl/IVApplicationQueryServiceImpl.java | 167 +++++++----------- .../service/IVApplicationQueryService.java | 7 +- .../action/ApplicationQryAction.java | 62 +++++-- 3 files changed, 111 insertions(+), 125 deletions(-) diff --git a/sscivm/src/private/nccloud/itf/sscivm/ivsale/impl/IVApplicationQueryServiceImpl.java b/sscivm/src/private/nccloud/itf/sscivm/ivsale/impl/IVApplicationQueryServiceImpl.java index 16e87b3..16b21fa 100644 --- a/sscivm/src/private/nccloud/itf/sscivm/ivsale/impl/IVApplicationQueryServiceImpl.java +++ b/sscivm/src/private/nccloud/itf/sscivm/ivsale/impl/IVApplicationQueryServiceImpl.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.Map; import nc.bs.dao.BaseDAO; +import nc.bs.dao.DAOException; import nc.bs.framework.common.InvocationInfoProxy; import nc.bs.sscivm.ivsale.bp.IVApplicationQueryBP; import nc.bs.sscivm.util.IVMSagaValidationUtils; @@ -117,53 +118,6 @@ public class IVApplicationQueryServiceImpl implements IVApplicationQueryService } } - // ĸʱ жɸѡ - @Override - public Map> queryApplicationPksBySchema(IQueryScheme queryscheme, String appcode, Boolean sgbzflag, List> extraParams) throws BusinessException { - if (queryscheme == null) { - return null; - } else { - String queryCondition = queryscheme.getWhereSQLOnly(); - Map> pkAndTsList = null; - if (!queryCondition.isEmpty()) { - String tradetype = this.getTradetypeByApp(appcode); - if ("SSCIVA-kpsq".equals(tradetype)) { - queryCondition = "(" + queryCondition + ")"; - } else { - queryCondition = "(" + queryCondition + " and sn.transtypecode = '" + tradetype + "')"; - } - - if (sgbzflag != null) { - if (sgbzflag) { - queryCondition = queryCondition + " and sn.sgbz ='Y' "; - } else { - queryCondition = queryCondition + " and (sn.sgbz='N' or isnull(sn.sgbz,'~')='~') "; - } - } - String sql = this.buildQuerySql(queryCondition, extraParams); - pkAndTsList = (Map) this.getBaseDAO().executeQuery(sql, new BaseProcessor() { - private static final long serialVersionUID = 1L; - Map> result = new HashMap(); - List pkList = new ArrayList(); - List tsList = new ArrayList(); - - public Object processResultSet(ResultSet paramResultSet) throws SQLException { - while (paramResultSet.next()) { - this.pkList.add((String) paramResultSet.getObject("pk_ivapplication")); - this.tsList.add((String) paramResultSet.getObject("ts")); - } - - this.result.put("pks", this.pkList); - this.result.put("ts", this.tsList); - return this.result; - } - }); - } - - return pkAndTsList; - } - } - private String buildQuerySql(String queryCondition) { StringBuilder sql = new StringBuilder("SELECT * "); sql.append("from " + IVApplicationHeadVO.getDefaultTableName() + " where "); @@ -171,64 +125,6 @@ public class IVApplicationQueryServiceImpl implements IVApplicationQueryService return var10000 + queryCondition + " and dr = 0 order by preparedate desc, billno desc"; } - // ˲ otherExtraQueryParams ڶIJѯ - private String buildQuerySql(String queryCondition, List> otherExtraQueryParams) { - String var10000 = "SELECT * " + "from " + IVApplicationHeadVO.getDefaultTableName() + - " sn " + - " left join " + IVApplogVO.getDefaultTableName() + - " sg " + - " on " + " sn." + IVApplicationHeadVO.PK_IVAPPLICATION + - " = " + " sg." + IVApplogVO.PK_IVAPPLOG + - " where 1=1 "; - StringBuilder extraSql = new StringBuilder(); - if (otherExtraQueryParams != null && !otherExtraQueryParams.isEmpty()) { - for (Map map : otherExtraQueryParams) { - if (map != null && !map.isEmpty()) { - Map value = (Map) map.get("value"); - String column = (String) map.get("field"); - String firstValue = value.get("firstvalue"); - String secondValue = value.get("secondvalue"); - String alias = " sn."; - String oprtype = (String) map.get("oprtype"); - if (column.equals("KPRQ")) { - alias = " sg."; - } - if (column.equals("pk_org") && oprtype.equals("=")) { - String[] pks = firstValue.split(","); - extraSql.append(" and (").append(alias).append("pk_org").append(" in ("); - for (int i = 0; i < pks.length; ++i) { - extraSql.append("'").append(pks[i]).append("'"); - if (i != pks.length - 1) { - extraSql.append(","); - } - } - extraSql.append(")"); - extraSql.append(")"); - continue; - } - switch (oprtype) { - case "between": { - extraSql.append(" and (").append(alias).append(column).append(" >= '").append(firstValue).append("' and ").append(alias).append(column).append(" <= '").append(secondValue).append("' )"); - break; - } - case "like": { - extraSql.append(" and (").append(alias).append(column).append(" like '%").append(firstValue).append("' )"); - break; - } - case "=": { - extraSql.append(" and (").append(alias).append(column).append(" = '").append(firstValue).append("' )"); - break; - } - default: { - break; - } - } - } - } - } - return var10000 + extraSql + " and sn.dr = 0 order by sn.preparedate desc, sn.billno desc"; - } - public String getDefaultOrgUnit() throws Exception { return OrgSettingAccessor.getDefaultOrgUnit(); } @@ -269,6 +165,48 @@ public class IVApplicationQueryServiceImpl implements IVApplicationQueryService } } + public List queryApplicationsBySchema(IQueryScheme queryscheme, String pageSize, String appcode, Boolean sgbzflag, Boolean pageControl) throws BusinessException { + if (queryscheme == null) { + return null; + } else { + StringBuilder sql = new StringBuilder(); + String queryCondition = queryscheme.getWhereSQLOnly(); + String tradetype = this.getTradetypeByApp(appcode); + if ("SSCIVA-kpsq".equals(tradetype)) { + queryCondition = "(" + queryCondition + ")"; + } else { + queryCondition = "(" + queryCondition + " and transtypecode = '" + tradetype + "')"; + } + + if (sgbzflag != null) { + if (sgbzflag) { + queryCondition = queryCondition + " and sgbz ='Y' "; + } else { + queryCondition = queryCondition + " and (sgbz='N' or isnull(sgbz,'~')='~') "; + } + } + + List applicationHeadVOList = null; + // pageControl Ϊfalse ô߷ҳ߼ + if (null != queryCondition && !queryCondition.isEmpty()) { + if (pageControl) { + LimitSQLBuilder limitSQLBuilder = SQLBuilderFactory.getInstance().createLimitSQLBuilder(this.getBaseDAO().getDBType()); + sql.append(limitSQLBuilder.build(this.buildQuerySql(queryCondition), 1, Integer.valueOf(pageSize))); + } + applicationHeadVOList = (List) this.getBaseDAO().executeQuery(this.buildQuerySql(queryCondition).toString(), new BeanListProcessor(IVApplicationHeadVO.class)); + } + + if (applicationHeadVOList != null && applicationHeadVOList.size() > Integer.parseInt(pageSize)) { + if (!pageControl) { + return applicationHeadVOList; + } + applicationHeadVOList = applicationHeadVOList.subList(0, Integer.parseInt(pageSize)); + } + + return applicationHeadVOList; + } + } + public IVApplicationHeadVO[] queryHeadVOsByFpdmFphm(String fpdm, String fphm) throws BusinessException { StringBuilder querySql = new StringBuilder("select DISTINCT " + IVApplicationHeadVO.getDefaultTableName() + ".* from "); String var10001 = IVApplogVO.getDefaultTableName(); @@ -284,6 +222,25 @@ public class IVApplicationQueryServiceImpl implements IVApplicationQueryService return ivApplicationHeadVOList != null && ivApplicationHeadVOList.size() != 0 ? (IVApplicationHeadVO[]) ivApplicationHeadVOList.toArray(new IVApplicationHeadVO[ivApplicationHeadVOList.size()]) : null; } + // ɸѡĿƱ뵥ѯƱ¼ + public List queryByInvoiceNumberAndAggPK(String[] pks, String[] invoiceDate, String[] invoiceNums) throws BusinessException { + StringBuilder sql = new StringBuilder("select lyid from " + IVApplogVO.getDefaultTableName() + " where 1=1"); + String invoiceDateStr, pkStr, invoiceNumStr; + if (pks != null && pks.length > 0) { + pkStr = SQLUtil.buildSqlForIn("lyid", pks); + sql.append(" and ").append(pkStr); + } + if (invoiceDate != null && invoiceDate.length > 0) { + invoiceDateStr = " KPRQ >= '" + invoiceDate[0] + "'" + " and KPRQ <=" + "'" + invoiceDate[1] + "'"; + sql.append(" and ").append(invoiceDateStr); + } + if (invoiceNums != null && invoiceNums.length > 0) { + invoiceNumStr = SQLUtil.buildSqlForIn("FPHM", invoiceNums); + sql.append(" and ").append(invoiceNumStr); + } + return (List) this.getBaseDAO().executeQuery(sql.toString(), new BeanListProcessor(IVApplogVO.class)); + } + public List queryHeadVOsByPks(String[] pks) throws BusinessException { List applicationHeadVOList = this.queryHeadVOsByPks(pks, (Boolean) null); return applicationHeadVOList; diff --git a/sscivm/src/private/nccloud/itf/sscivm/ivsale/service/IVApplicationQueryService.java b/sscivm/src/private/nccloud/itf/sscivm/ivsale/service/IVApplicationQueryService.java index 8cf8014..f6a27ae 100644 --- a/sscivm/src/private/nccloud/itf/sscivm/ivsale/service/IVApplicationQueryService.java +++ b/sscivm/src/private/nccloud/itf/sscivm/ivsale/service/IVApplicationQueryService.java @@ -9,6 +9,7 @@ import nc.vo.pub.BusinessException; import nc.vo.pub.lang.UFDouble; import nc.vo.sscivm.ivsale.IVApplicationAggVO; import nc.vo.sscivm.ivsale.IVApplicationHeadVO; +import nc.vo.sscivm.ivsale.IVApplogVO; public interface IVApplicationQueryService { IVApplicationAggVO queryByPK(String var1) throws BusinessException; @@ -27,10 +28,10 @@ public interface IVApplicationQueryService { Map> queryApplicationPksBySchema(IQueryScheme var1, String var2, Boolean var3) throws BusinessException; - Map> queryApplicationPksBySchema(IQueryScheme var1, String var2, Boolean var3, List> var4) throws BusinessException; - List queryApplicationsBySchema(IQueryScheme var1, String var2, String var3, Boolean var4) throws BusinessException; + List queryApplicationsBySchema(IQueryScheme var1, String var2, String var3, Boolean var4, Boolean var5) throws BusinessException; + String getDefaultOrgUnit() throws Exception; MeasdocVO[] queryMeasdocByPk(String var1) throws BusinessException; @@ -38,4 +39,6 @@ public interface IVApplicationQueryService { UFDouble queryTaxRateByMaterialPK(String var1) throws BusinessException; IVApplicationHeadVO[] queryHeadVOsByFpdmFphm(String var1, String var2) throws BusinessException; + + List queryByInvoiceNumberAndAggPK(String[] pks, String[] invoiceDate, String[] invoiceNums) throws BusinessException; } diff --git a/sscivm/src/private/nccloud/web/sscivm/ivsale/application/action/ApplicationQryAction.java b/sscivm/src/private/nccloud/web/sscivm/ivsale/application/action/ApplicationQryAction.java index fa54227..167da64 100644 --- a/sscivm/src/private/nccloud/web/sscivm/ivsale/application/action/ApplicationQryAction.java +++ b/sscivm/src/private/nccloud/web/sscivm/ivsale/application/action/ApplicationQryAction.java @@ -16,6 +16,7 @@ import nc.vo.pubapp.pattern.exception.ExceptionUtils; import nc.vo.pubapp.query2.sql.process.QueryCondition; import nc.vo.pubapp.query2.sql.process.QuerySchemeProcessor; import nc.vo.sscivm.ivsale.IVApplicationHeadVO; +import nc.vo.sscivm.ivsale.IVApplogVO; import nccloud.dto.baseapp.querytree.dataformat.QueryTreeFormatVO; import nccloud.framework.core.json.IJson; import nccloud.framework.service.ServiceLocator; @@ -64,31 +65,56 @@ public class ApplicationQryAction implements ICommonAction { if (info.getQuerycondition() != null) { INCCloudQueryService ncCloudQueryService = (INCCloudQueryService) ServiceLocator.find(INCCloudQueryService.class); IQueryScheme scheme = ncCloudQueryService.convertCondition(info); - - //TODOȡѯеHPRQFPHM (ƱںͷƱ) - Map queryMap = (Map) map.get("querycondition"); - List> customQueryContion = (List>) queryMap.get("conditions"); - List> filteredCondition = customQueryContion.stream() - .filter((queryItem) -> queryItem.get("field").equals("FPHM") || queryItem.get("field").equals("KPRQ")) - .collect(Collectors.toList()); - boolean isExtraQuery = filteredCondition != null && filteredCondition.size() > 0; - QuerySchemeProcessor processor = new QuerySchemeProcessor(scheme); - // TODO - - // Ƕѯ ߶IJѯ IJѯ - Map> pkAndTsList = - isExtraQuery ? queryService.queryApplicationPksBySchema(scheme, appcode, sgbzflag, customQueryContion) - : queryService.queryApplicationPksBySchema(scheme, appcode, sgbzflag); - + Map> pkAndTsList = queryService.queryApplicationPksBySchema(scheme, appcode, sgbzflag); String pageSize = (String) pageInfo.get("pageSize"); - allApplicationAggVOList = queryService.queryApplicationsBySchema(scheme, pageSize, appcode, sgbzflag); + // õallApplicationVOListеPK,ԼѯеFPHM ٲѯһݿ + boolean isSpcialQuery = false; + QuerySchemeProcessor processor = new QuerySchemeProcessor(scheme); + QueryCondition kprq = processor.getQueryCondition("KPRQ"); + QueryCondition fphm = processor.getQueryCondition("FPHM"); + if (kprq == null && fphm == null) { + allApplicationAggVOList = queryService.queryApplicationsBySchema(scheme, pageSize, appcode, sgbzflag); + } else { + allApplicationAggVOList = queryService.queryApplicationsBySchema(scheme, pageSize, appcode, sgbzflag, false); + isSpcialQuery = true; + } + // ѯݿ kprq fphm һΪ ôͲҳ ֶҳѯ + String[] invoiceDate = {}; + String[] invoiceNums = {}; + String[] filteredPks = {}; + if (isSpcialQuery) { + if (kprq != null) { + invoiceDate = kprq.getValues(); + } + if (fphm != null) { + invoiceNums = fphm.getValues(); + } + if (allApplicationAggVOList.size() != 0) { + List ivApplicationHeadVOS = allApplicationAggVOList.stream() + .map(IVApplicationHeadVO::getPk_ivapplication) + .collect(Collectors.toList()); + filteredPks = ivApplicationHeadVOS.toArray(new String[0]); + } + // д˷Ʊ ִд߼ + if (invoiceDate != null && invoiceDate.length > 0) { + List ivApplogVOS = queryService.queryByInvoiceNumberAndAggPK(filteredPks, invoiceDate, invoiceNums); + // allApplicationAggVOList ivApplogVOSÿһlyidǷ + allApplicationAggVOList = allApplicationAggVOList.stream() + .filter(aggVO -> ivApplogVOS.stream() + .anyMatch(logVO -> logVO.getLyid().equals(aggVO.getPk_ivapplication()))) + .collect(Collectors.toList()); + } + filteredPks = allApplicationAggVOList.stream() + .map(IVApplicationHeadVO::getPk_ivapplication) + .collect(Collectors.toList()).toArray(new String[0]); + } if (allApplicationAggVOList != null && allApplicationAggVOList.size() > 0) { invApplication = operator.toGrid(allApplicationAggVOList.toArray(new IVApplicationHeadVO[allApplicationAggVOList.size()])); invApplication.setPageid(pagecode); DataChangeLogic.setViewScala(invApplication); translator.translate(invApplication); result.put(areaid, invApplication); - result.put("pks", pkAndTsList.get("pks")); + result.put("pks", filteredPks.length > 0 ? filteredPks : pkAndTsList.get("pks")); result.put("ts", pkAndTsList.get("ts")); } } else {