diff --git a/sscivm/src/private/nccloud/itf/sscivm/ivsale/impl/IVApplicationQueryServiceImpl.java b/sscivm/src/private/nccloud/itf/sscivm/ivsale/impl/IVApplicationQueryServiceImpl.java new file mode 100644 index 0000000..16e87b3 --- /dev/null +++ b/sscivm/src/private/nccloud/itf/sscivm/ivsale/impl/IVApplicationQueryServiceImpl.java @@ -0,0 +1,361 @@ +package nccloud.itf.sscivm.ivsale.impl; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import nc.bs.dao.BaseDAO; +import nc.bs.framework.common.InvocationInfoProxy; +import nc.bs.sscivm.ivsale.bp.IVApplicationQueryBP; +import nc.bs.sscivm.util.IVMSagaValidationUtils; +import nc.jdbc.framework.page.LimitSQLBuilder; +import nc.jdbc.framework.page.SQLBuilderFactory; +import nc.jdbc.framework.processor.BaseProcessor; +import nc.jdbc.framework.processor.BeanListProcessor; +import nc.jdbc.framework.processor.ColumnListProcessor; +import nc.jdbc.framework.processor.ColumnProcessor; +import nc.pubitf.setting.defaultdata.OrgSettingAccessor; +import nc.ui.querytemplate.querytree.IQueryScheme; +import nc.vo.bd.material.measdoc.MeasdocVO; +import nc.vo.pf.pub.util.SQLUtil; +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.IVApplicationRelationVO; +import nc.vo.sscivm.ivsale.IVApplogVO; +import nccloud.itf.sscivm.ivsale.service.IVApplicationQueryService; + +public class IVApplicationQueryServiceImpl implements IVApplicationQueryService { + private static final String TS = "ts"; + private static final String PKS = "pks"; + private BaseDAO baseDAO = new BaseDAO(); + private static Map> PUBLISHAPPMAP = new HashMap(); + + public IVApplicationQueryServiceImpl() { + } + + private BaseDAO getBaseDAO() { + return this.baseDAO; + } + + public IVApplicationAggVO queryByPK(String pk) throws BusinessException { + return (new IVApplicationQueryBP()).getAggIVApplicationVOByPK(pk); + } + + public IVApplicationAggVO queryByPK(String pk, boolean checkSaga) throws BusinessException { + if (checkSaga) { + IVMSagaValidationUtils.checkSagaStatus(pk, IVApplicationHeadVO.getDefaultTableName(), "pk_ivapplication"); + } + + return (new IVApplicationQueryBP()).getAggIVApplicationVOByPK(pk); + } + + public IVApplicationAggVO[] queryAggVOsByPks(String[] pks) throws BusinessException { + return (new IVApplicationQueryBP()).queryAggIVApplicationVOByCondition(SQLUtil.buildSqlForIn("pk_ivapplication", pks)); + } + + public IVApplicationAggVO[] queryAggVOsByPks(String[] pks, boolean checkSaga) throws BusinessException { + if (checkSaga) { + IVMSagaValidationUtils.checkSagaStatus(pks, IVApplicationHeadVO.getDefaultTableName(), "pk_ivapplication"); + } + + return (new IVApplicationQueryBP()).queryAggIVApplicationVOByCondition(SQLUtil.buildSqlForIn("pk_ivapplication", pks)); + } + + public IVApplicationAggVO[] queryAggVOsByCondition(String condition) throws BusinessException { + return (new IVApplicationQueryBP()).queryAggIVApplicationVOByCondition(condition); + } + + public Map> queryApplicationPksBySchema(IQueryScheme queryscheme, String appcode, Boolean sgbzflag) 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 transtypecode = '" + tradetype + "')"; + } + + if (sgbzflag != null) { + if (sgbzflag) { + queryCondition = queryCondition + " and sgbz ='Y' "; + } else { + queryCondition = queryCondition + " and (sgbz='N' or isnull(sgbz,'~')='~') "; + } + } + + String sql = this.buildQuerySql(queryCondition); + 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; + } + } + + // 当传入第四个参数的时候 进行额外的筛选 + @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 "); + String var10000 = sql.toString(); + 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(); + } + + public List queryApplicationsBySchema(IQueryScheme queryscheme, String pageSize, String appcode, Boolean sgbzflag) 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; + if (null != queryCondition && !queryCondition.isEmpty()) { + LimitSQLBuilder limitSQLBuilder = SQLBuilderFactory.getInstance().createLimitSQLBuilder(this.getBaseDAO().getDBType()); + sql.append(limitSQLBuilder.build(this.buildQuerySql(queryCondition), 1, Integer.valueOf(pageSize))); + applicationHeadVOList = (List) this.getBaseDAO().executeQuery(sql.toString(), new BeanListProcessor(IVApplicationHeadVO.class)); + } + + if (applicationHeadVOList != null && applicationHeadVOList.size() > Integer.parseInt(pageSize)) { + 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(); + querySql.append(var10001 + ", " + IVApplicationHeadVO.getDefaultTableName()); + var10001 = IVApplicationHeadVO.getDefaultTableName(); + querySql.append(" where " + var10001 + ".dr =0 and (" + IVApplicationHeadVO.getDefaultTableName() + ".pk_ivapplication=" + IVApplogVO.getDefaultTableName() + ".lyid or " + IVApplicationHeadVO.getDefaultTableName() + ".pk_ivapplication in ( select ron.pk_ivapplication from " + IVApplicationRelationVO.getDefaultTableName() + " ron where ron.fpqqlsh = " + IVApplogVO.getDefaultTableName() + ".lyid)) and " + IVApplogVO.getDefaultTableName() + ".fphm ='" + fphm + "' and " + IVApplogVO.getDefaultTableName() + ".dr=0 "); + if (fpdm != null) { + var10001 = IVApplogVO.getDefaultTableName(); + querySql.append(" and " + var10001 + ".fpdm ='" + fpdm + "' "); + } + + List ivApplicationHeadVOList = (List) this.getBaseDAO().executeQuery(querySql.toString(), new BeanListProcessor(IVApplicationHeadVO.class)); + return ivApplicationHeadVOList != null && ivApplicationHeadVOList.size() != 0 ? (IVApplicationHeadVO[]) ivApplicationHeadVOList.toArray(new IVApplicationHeadVO[ivApplicationHeadVOList.size()]) : null; + } + + public List queryHeadVOsByPks(String[] pks) throws BusinessException { + List applicationHeadVOList = this.queryHeadVOsByPks(pks, (Boolean) null); + return applicationHeadVOList; + } + + public List queryHeadVOsByPks(String[] pks, Boolean sgbzflag) throws BusinessException { + String sqlcondition = ""; + if (sgbzflag != null) { + if (sgbzflag) { + sqlcondition = " sgbz ='Y' and "; + } else { + sqlcondition = " (sgbz='N' or isnull(sgbz,'~')='~') and "; + } + } + + List applicationHeadVOList = (List) this.getBaseDAO().retrieveByClause(IVApplicationHeadVO.class, "dr = 0 and " + sqlcondition + SQLUtil.buildSqlForIn("pk_ivapplication", pks), "preparedate desc, billno desc"); + return applicationHeadVOList; + } + + public MeasdocVO[] queryMeasdocByPk(String pk) throws BusinessException { + String condition = " ( pk_measdoc ='" + pk + "')"; + BaseDAO dao = new BaseDAO(); + Collection coll = dao.retrieveByClause(MeasdocVO.class, condition); + return coll == null ? null : (MeasdocVO[]) coll.toArray(new MeasdocVO[0]); + } + + public UFDouble queryTaxRateByMaterialPK(String pk) throws BusinessException { + StringBuilder sql = new StringBuilder(); + sql.append("select taxrate from bd_taxrate where pk_taxcode in "); + sql.append("("); + sql.append("select pk_taxcode from bd_taxcode where mattaxes in "); + sql.append("("); + sql.append("select pk_mattaxes from bd_material where pk_material = '"); + sql.append(pk); + sql.append("'))"); + String condition = sql.toString(); + List result = (List) this.getBaseDAO().executeQuery(condition, new ColumnListProcessor()); + return result != null && result.size() > 0 ? new UFDouble(result.get(0).toString()) : null; + } + + private String getTradetypeByApp(String appcode) throws BusinessException { + String tradetype = null; + String pk_group = InvocationInfoProxy.getInstance().getGroupId(); + Map map = (Map) PUBLISHAPPMAP.get(pk_group); + if (map != null && map.size() > 0) { + tradetype = (String) map.get(appcode); + } + + if (tradetype == null) { + StringBuilder condition = new StringBuilder(); + condition.append("select pk_billtypecode from pub_publishapp where publishappid ="); + condition.append("("); + condition.append("select pk_appregister from sm_appregister where code = '" + appcode + "'"); + condition.append(")"); + tradetype = (String) this.getBaseDAO().executeQuery(condition.toString(), new ColumnProcessor()); + } + + if (tradetype == null && appcode != null && appcode.length() > 3) { + appcode = appcode.substring(0, appcode.length() - 3); + tradetype = this.getTradetypeByApp(appcode); + } + + if (map == null) { + map = new HashMap(); + } + + if (tradetype == null || tradetype.length() == 0) { + tradetype = "SSCIVA-kpsq"; + } + + map.put(appcode, tradetype); + PUBLISHAPPMAP.put(pk_group, map); + return tradetype; + } +} diff --git a/sscivm/src/private/nccloud/itf/sscivm/ivsale/service/IVApplicationQueryService.java b/sscivm/src/private/nccloud/itf/sscivm/ivsale/service/IVApplicationQueryService.java new file mode 100644 index 0000000..8cf8014 --- /dev/null +++ b/sscivm/src/private/nccloud/itf/sscivm/ivsale/service/IVApplicationQueryService.java @@ -0,0 +1,41 @@ +package nccloud.itf.sscivm.ivsale.service; + +import java.util.List; +import java.util.Map; + +import nc.ui.querytemplate.querytree.IQueryScheme; +import nc.vo.bd.material.measdoc.MeasdocVO; +import nc.vo.pub.BusinessException; +import nc.vo.pub.lang.UFDouble; +import nc.vo.sscivm.ivsale.IVApplicationAggVO; +import nc.vo.sscivm.ivsale.IVApplicationHeadVO; + +public interface IVApplicationQueryService { + IVApplicationAggVO queryByPK(String var1) throws BusinessException; + + IVApplicationAggVO queryByPK(String var1, boolean var2) throws BusinessException; + + IVApplicationAggVO[] queryAggVOsByPks(String[] var1) throws BusinessException; + + IVApplicationAggVO[] queryAggVOsByPks(String[] var1, boolean var2) throws BusinessException; + + List queryHeadVOsByPks(String[] var1, Boolean var2) throws BusinessException; + + List queryHeadVOsByPks(String[] var1) throws BusinessException; + + IVApplicationAggVO[] queryAggVOsByCondition(String var1) throws BusinessException; + + 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; + + String getDefaultOrgUnit() throws Exception; + + MeasdocVO[] queryMeasdocByPk(String var1) throws BusinessException; + + UFDouble queryTaxRateByMaterialPK(String var1) throws BusinessException; + + IVApplicationHeadVO[] queryHeadVOsByFpdmFphm(String var1, String var2) 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 new file mode 100644 index 0000000..fa54227 --- /dev/null +++ b/sscivm/src/private/nccloud/web/sscivm/ivsale/application/action/ApplicationQryAction.java @@ -0,0 +1,113 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package nccloud.web.sscivm.ivsale.application.action; + +import java.util.*; +import java.util.stream.Collectors; + +import com.google.gson.internal.LinkedTreeMap; +import nc.bs.sscivm.ivsale.util.IVSaleUtil; +import nc.bs.sscivm.logger.SSCIVMLogger; +import nc.ui.querytemplate.querytree.IQueryScheme; +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 nccloud.dto.baseapp.querytree.dataformat.QueryTreeFormatVO; +import nccloud.framework.core.json.IJson; +import nccloud.framework.service.ServiceLocator; +import nccloud.framework.web.action.itf.ICommonAction; +import nccloud.framework.web.container.IRequest; +import nccloud.framework.web.container.RequestSysJsonVO; +import nccloud.framework.web.container.SessionContext; +import nccloud.framework.web.convert.translate.Translator; +import nccloud.framework.web.json.JsonFactory; +import nccloud.framework.web.ui.pattern.grid.Grid; +import nccloud.framework.web.ui.pattern.grid.GridOperator; +import nccloud.itf.sscivm.ivsale.service.IVApplicationQueryService; +import nccloud.pubitf.platform.query.INCCloudQueryService; +import nccloud.web.sscivm.ivsale.application.util.DataChangeLogic; + +public class ApplicationQryAction implements ICommonAction { + private static final String TS = "ts"; + private static final String PKS = "pks"; + + public ApplicationQryAction() { + } + + public Object doAction(IRequest request) { + IJson json = JsonFactory.create(); + Map result = new HashMap(); + + try { + QueryTreeFormatVO info = (QueryTreeFormatVO) json.fromJson(request.read(), QueryTreeFormatVO.class); + IVApplicationQueryService queryService = (IVApplicationQueryService) ServiceLocator.find(IVApplicationQueryService.class); + String infoString = request.read(); + Map map = (Map) json.fromJson(infoString, Map.class); + String pagecode = (String) map.get("pagecode"); + String areaid = (String) map.get("areaid"); + RequestSysJsonVO sysparam = request.readSysParam(); + String appcode = sysparam.getAppcode(); + Map pageInfo = (Map) map.get("pageInfo"); + GridOperator operator = new GridOperator(pagecode); + Grid invApplication = null; + Translator translator = new Translator(); + boolean sgbzflag = false; + String pk_group = SessionContext.getInstance().getClientInfo().getPk_group(); + if (IVSaleUtil.isSgsq(appcode, pk_group)) { + sgbzflag = true; + } + List allApplicationAggVOList = null; + 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); + + String pageSize = (String) pageInfo.get("pageSize"); + allApplicationAggVOList = queryService.queryApplicationsBySchema(scheme, pageSize, appcode, sgbzflag); + 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("ts", pkAndTsList.get("ts")); + } + } else { + Map reqMap = (Map) json.fromJson(request.read(), Map.class); + ArrayList pkList = (ArrayList) reqMap.get("pks"); + allApplicationAggVOList = queryService.queryHeadVOsByPks((String[]) pkList.toArray(new String[pkList.size()]), sgbzflag); + 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); + } + } + } catch (Exception e) { + SSCIVMLogger.error(e.getMessage(), e); + ExceptionUtils.wrappException(e); + } + + return result; + } +}