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 用于额外参数的查询 - 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获取额外查询条件中的HPRQ和FPHM (开票日期和发票号码) - 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 - - // 如果是额外查询 走额外的查询 如果不是 走正常的查询 - 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 {