fs-danaus
2022-05-25 e9229c1fcca9f0ce7a3a90200eb1de1012e66ce2
完善保存后拉取最新数据接口,增加列权限的输出
4个文件已修改
248 ■■■■ 已修改文件
src/com/yc/action/grid/GTGrid.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/app/v2/controller/RefreashDataCallable.java 208 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/app/v2/entity/RefreshDataEntity.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/open/mutual/controller/MutualController.java 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/action/grid/GTGrid.java
@@ -572,7 +572,8 @@
                sb.append(s.getSql());
            }
            String sql = sb.toString();
            if ((this.formID == 9801 || this.formID == 9842 || this.formID == 9802 || this.formID == 9843 || this.formID == 9816) && !"".equalsIgnoreCase(this.page_formid)) {//每次修改都更新版本号
            if ((this.formID == 9801 || this.formID == 9842 || this.formID == 9802
                    || this.formID == 9843 || this.formID == 9816||this.formID == 9685) && !"".equalsIgnoreCase(this.page_formid)) {//每次修改都更新版本号
                sql = info.getSql() + "\n update gform set version=isnull(version,0)+1  where formid=" + this.page_formid + ";";
            }
            dbid = request.getSession().getAttribute(SessionKey.DATA_BASE_ID) + "";
@@ -636,12 +637,22 @@
                    //gridService.getSimpleJdbcTemplate().execute(" Set ARITHABORT ON  ");
                    Map map = gridService.doSave(" Set ARITHABORT ON  \n "+sql);
                    if (map != null) {
                        String docCode = GridUtils.prossRowSetDataType_String(map, "docCode");
                        info.setDoccode(docCode);
                        info.setRowid(GridUtils.prossRowSetDataType_String(map, "rowid"));
                        info.setDetailRowid(GridUtils.prossRowSetDataType_String(map, "detailRowid"));
                        info.setOnlinePay(GridUtils.prossRowSetDataType_Int(map, "onlinePay"));
                        info.setOnlineRefund(GridUtils.prossRowSetDataType_Int(map, "onlineRefund"));
                        if(map.containsKey("docCode")) {
                            String docCode = GridUtils.prossRowSetDataType_String(map, "docCode");
                            info.setDoccode(docCode);
                        }
                        if(map.containsKey("rowid")) {
                            info.setRowid(GridUtils.prossRowSetDataType_String(map, "rowid"));
                        }
                        if(map.containsKey("detailRowid")) {
                            info.setDetailRowid(GridUtils.prossRowSetDataType_String(map, "detailRowid"));
                        }
                        if(map.containsKey("onlinePay")) {
                            info.setOnlinePay(GridUtils.prossRowSetDataType_Int(map, "onlinePay"));
                        }
                        if(map.containsKey("onlineRefund")) {
                            info.setOnlineRefund(GridUtils.prossRowSetDataType_Int(map, "onlineRefund"));
                        }
                    }
                } else {
                    //gridService.getSimpleJdbcTemplate().execute(" Set ARITHABORT ON  ");
@@ -2820,7 +2831,7 @@
                key.append("(");
                value.append("values(");
                if (this.formID == 9802 || this.formID == 9801 ||
                        this.formID == 9843 || this.formID == 9844 || this.formID == 9816) {
                        this.formID == 9843 || this.formID == 9844 || this.formID == 9816||this.formID==9685) {
                    if ("".equalsIgnoreCase(page_formid)) page_formid = (String) map.get("formid");
                }
                if (this.formID == 9842) {
@@ -3082,7 +3093,7 @@
                if (vss != null && vss.size() > 0) {
                    vs = vss.get(i);
                    if (this.formID == 9802 || this.formID == 9801 ||
                            this.formID == 9843 || this.formID == 9816) {
                            this.formID == 9843 || this.formID == 9816||this.formID==9685) {
                        if ("".equalsIgnoreCase(page_formid)) page_formid = vs.get("formid");
                    }
                    if (this.formID == 9842) {
src/com/yc/app/v2/controller/RefreashDataCallable.java
@@ -3,6 +3,7 @@
import com.yc.action.grid.GridUtils;
import com.yc.app.util.ResponseMessage;
import com.yc.app.v2.entity.RefreshDataEntity;
import com.yc.app.v2.service.BaseFormService;
import com.yc.exception.ApplicationException;
import com.yc.exception.CallBackMessage;
import com.yc.factory.FactoryBean;
@@ -11,90 +12,193 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.dao.EmptyResultDataAccessException;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
import java.util.concurrent.Callable;
public class RefreashDataCallable implements Callable<Object> {
    RefreshDataEntity entity;
    String dbid;
    public RefreashDataCallable(RefreshDataEntity entity, String dbid) {
        this.entity=entity;
        this.dbid=dbid;
        this.entity = entity;
        this.dbid = dbid;
    }
    @Override
    public Object call() throws Exception {
         CallBackMessage callBackMessage=new CallBackMessage();
        CallBackMessage callBackMessage = new CallBackMessage();
        try {
            SpObserver.setDBtoInstance("_" + dbid);
            final Map<String, Object> formData = this.getFormData(entity);
            callBackMessage.setInfo(formData);
            callBackMessage.sendSuccessMessage(ResponseMessage.SUCCESS);
            return callBackMessage.toJSONObject();
        } catch (EmptyResultDataAccessException ex){
        } catch (EmptyResultDataAccessException ex) {
            callBackMessage.sendErrorMessage("查找不到此单据数据");
            return callBackMessage.toJSONObject();
        }catch (Exception e) {
        } catch (Exception e) {
            e.printStackTrace();
            callBackMessage.sendErrorMessage(e.getCause()!=null?e.getCause().getMessage() :e.getMessage());
            callBackMessage.sendErrorMessage(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
            return callBackMessage.toJSONObject();
        } finally {
            SpObserver.setDBtoInstance();
        }
    }
    private  Map<String, Object> getFormData(RefreshDataEntity entity){
        if(entity.getFormType()==18&&StringUtils.isBlank(entity.getPostParmBy18())){
    private Map<String, Object> getFormData(RefreshDataEntity entity) {
        if (entity.getFormType() == 18 && StringUtils.isBlank(entity.getPostParmBy18())) {
            throw new ApplicationException("18类型取数时postParmBy18参数不能为空");
        }
            String where="";
            for(Map.Entry<String, Object> entry:entity.getWhere().entrySet()){
                if(StringUtils.isBlank(where))
                    where+=entry.getKey()+"="+entry.getValue();
                else
                    where+=" and "+entry.getKey()+"="+entry.getValue();
        String where = "";
        for (Map.Entry<String, Object> entry : entity.getWhere().entrySet()) {
            if (StringUtils.isBlank(where)) {
                where += entry.getKey() + "=" + entry.getValue();
            } else {
                where += " and " + entry.getKey() + "=" + entry.getValue();
            }
            String tableNameBy18="";
        GridServiceIfc gridServiceIfc= (GridServiceIfc) FactoryBean.getBean("gridServiceImpl");
        if(StringUtils.isNotBlank(entity.getPostParmBy18())){
        }
        String tableNameBy18 = "";
        GridServiceIfc gridServiceIfc = (GridServiceIfc) FactoryBean.getBean("gridServiceImpl");
        BaseFormService baseFormService = (BaseFormService) FactoryBean.getBean("baseFormServiceImpl");
        if (StringUtils.isNotBlank(entity.getPostParmBy18())) {
//myentercode='' and nowcccode='LY001' and mybuyercode='' and nowccname='溧阳红星德立店' and mycompanyid='' and myvndname='' and mydoctype='' and beginday='2022-04-01' and mydocstatus='' and mydoccode='' and endday='2022-04-30' and myvndcode='' and nowusername='张伟' and mycccode='' and myhdmemo='' and nowusercode='z9000011'
            try {
                SpObserver.setDBtoInstance("_" + dbid);
                final String tableName = gridServiceIfc.getJdbcTemplate().queryForObject("set nocount on \n declare @tableName varchar(500) \n select @tableName=dttable from gform where  formid=? \n select @tableName", String.class, entity.getFormid());
                String[] table =tableName.split("\\|");
                if(table.length<2){
                String[] table = tableName.split("\\|");
                if (table.length < 2) {
                    throw new ApplicationException("18类型表名称后面需要定义有参数列表,请在9802配置");
                }
                final String functionParm = gridServiceIfc.getFunctionParm(table[1], entity.getPostParmBy18(), entity.getEnv());
                if(functionParm.length()>0){
                    tableNameBy18=table[0]+"("+functionParm+")";
                }else{
                    tableNameBy18=table[0]+"()";
                if (functionParm.length() > 0) {
                    tableNameBy18 = table[0] + "(" + functionParm + ")";
                } else {
                    tableNameBy18 = table[0] + "()";
                }
            } catch (Exception e) {
                throw e;
            }finally {
                SpObserver.setDBtoInstance();
            }
        }
        //---------生成字段列表,需要附加权限
         String filedList = createFiledList(entity);
        //---替换参数
        //1---如果是单据需要查一次表头数据,因为有可能替换参数从表头取数
        if(entity.getMainPrimaryKey()!=null&&entity.getMainPrimaryKey().size()>0){
            String maiWwhere = "";
            for (Map.Entry<String, Object> entry : entity.getMainPrimaryKey().entrySet()) {
                if (StringUtils.isBlank(maiWwhere)) {
                    maiWwhere += entry.getKey() + "=" + entry.getValue();
                } else {
                    maiWwhere += " and " + entry.getKey() + "=" + entry.getValue();
                }
            }
        String sql="set nocount on\n" +
                "  declare @sql nvarchar(max),@formid int=?,@headflag int=?,@formType int=?,@where varchar(4000)=?,@hdtable varchar(2500),@dttable varchar(2500),@sqlList varchar(max),@tableName varchar(2500) \n";
                if(entity.getFormType()!=18) {
                   sql+= "   select @hdtable=hdtable,@dttable=dttable from gform where  formid=@formid\n" +
                            "   set @tableName=@hdtable\n" +
                            "   if @headflag=1 \n" +
                            "   begin\n" +
                            "    if @formType=5 or @formType=8 or @formType=496 or @formType=498\n" +
                            "    begin\n" +
                            "    set @tableName=@dttable\n" +
                            "    end\n" +
                            "   end\n" ;
                }else {
                          sql+=  "  begin \n" +
                            "    if @formType=18 \n" +
                            "    begin\n" +
                            "    set @headflag=0 \n" +
                            "    set @tableName=" + GridUtils.prossSqlParm(tableNameBy18) +
                            "    \nend\n" +
                            "  end \n" ;
            RefreshDataEntity refreshDataEntity =new RefreshDataEntity();
            refreshDataEntity.setFormid(entity.getFormid());
            refreshDataEntity.setFormType(entity.getFormType());
            refreshDataEntity.setHeadFlag(0);//指定取表头
            final Map<String, Object> mainTableData = getMainTableData(null, refreshDataEntity, maiWwhere, null);
             mainTableData.forEach((key,value)->{
                 entity.getEnv().put(key,value+"");
             });
        }
        filedList = baseFormService.prossExpressionFormSessionValues(filedList, entity.getEnv());
        //-----取指定的数据
        return getMainTableData(tableNameBy18,entity, where,filedList);
    }
private  Map<String, Object> getMainTableData(String tableNameBy18,RefreshDataEntity entity,String where,String filedList){
    try {
        SpObserver.setDBtoInstance("_" + dbid);
    String sql = "set nocount on\n" +
            "  declare @sql nvarchar(max),@formid int="+entity.getFormid()+",@headflag int="+entity.getHeadFlag()+",@formType int="+entity.getFormType()+",@where varchar(4000)="+GridUtils.prossSqlParm(where)+",@filedList varchar(max)="+GridUtils.prossSqlParm(filedList)+",@hdtable varchar(2500),@dttable varchar(2500),@sqlList varchar(max),@tableName varchar(2500) \n";
    if (entity.getFormType() != 18) {
        sql += "   select @hdtable=hdtable,@dttable=dttable from gform where  formid=@formid\n" +
                "   set @tableName=@hdtable\n" +
                "   if @headflag=1 \n" +
                "   begin\n" +
                "    if @formType=5 or @formType=8 or @formType=496 or @formType=498\n" +
                "    begin\n" +
                "    set @tableName=@dttable\n" +
                "    end\n" +
                "   end\n";//增加
    } else {
        sql += "  begin \n" +
                "    if @formType=18 \n" +
                "    begin\n" +
                "    set @headflag=0 \n" +
                "    set @tableName=" + GridUtils.prossSqlParm(tableNameBy18) +
                "    \nend\n" +
                "  end \n";
    }
    if(filedList==null) {
        //排除数据库不存在的字段
        String controltype=" not in(33,34,38,41)";
        if(entity.getHeadFlag()==0){
            controltype=" and controltype "+controltype;
        }else {
            controltype=" and gridcontroltype "+controltype;
        }
        sql +="   select @sqlList=stuff((SELECT ',' + CONVERT(VARCHAR,  isnull(fieldid,''))+''  from gField where formid=@formid and headflag=@headflag and isLoad=1 "+controltype+" FOR XML PATH ('')),1,1,'')\n"+
          "     select @sql =' select top 1 '+ LOWER(@sqlList)+' from '+ @tableName+' where '+ @where\n";
    }else {
        sql += "   select @sql =' select top 1 '+ LOWER(@filedList)+' from '+ @tableName+' where '+ @where\n";
    }
                   sql+= "   EXEC sp_executesql @sql";
    GridServiceIfc gridServiceIfc = (GridServiceIfc) FactoryBean.getBean("gridServiceImpl");
        return gridServiceIfc.getSimpleJdbcTemplate().queryForMap(sql);
    } catch (Exception ex) {
        throw ex;
    } finally {
        SpObserver.setDBtoInstance();
    }
}
    private String createFiledList(RefreshDataEntity entity) {
        //---从9802取得字段filedId,和对应的Showfieldvalueexpression,Stylecss,Tipsexpression
        StringJoiner joiner = new StringJoiner(",");
        try {
            SpObserver.setDBtoInstance("_" + dbid);
            GridServiceIfc gridServiceIfc = (GridServiceIfc) FactoryBean.getBean("gridServiceImpl");
            final List<Map<String, Object>> list = gridServiceIfc.getJdbcTemplate().queryForList("set nocount on\n select fieldid,Showfieldvalueexpression,Stylecss,Tipsexpression,controltype,gridcontroltype from gField where formid=? and headflag=? and isnull(isLoad,0)=1",entity.getFormid(),entity.getHeadFlag());
            if (list != null) {
                for (Map<String, Object> map : list) {
                    int controltype = 0;
                    if (entity.getHeadFlag() == 0) {
                        controltype = GridUtils.prossRowSetDataType_Int(map, "controltype");
                    } else {
                        controltype = GridUtils.prossRowSetDataType_Int(map, "gridcontroltype");
                    }
                    if (controltype == 33 || controltype == 34 || controltype == 38 || controltype == 41) {
                        continue;
                    }
                    String Showfieldvalueexpression = GridUtils.prossRowSetDataType_String(map, "Showfieldvalueexpression");
                    String csstype = GridUtils.prossRowSetDataType_String(map, "Stylecss");
                    String tipsexpression = GridUtils.prossRowSetDataType_String(map, "Tipsexpression");
                    String fieldId = GridUtils.prossRowSetDataType_String(map, "fieldid");
                    joiner.add("[" + fieldId + "]");
                    if (StringUtils.isNotBlank(Showfieldvalueexpression)) {
                        //----0,1,2的权限值
                        joiner.add(" case when (" + Showfieldvalueexpression + ") =1 then 1   when (" + Showfieldvalueexpression + ") =2 then 2 else 0 end as [" + fieldId + "_expr]");
                    }
                    if (StringUtils.isNotBlank(csstype)) {
                        joiner.add(" (" + prossExclamationMark(csstype) + " ) as [" + fieldId + "_cssexpr]");
                    }
                    if (StringUtils.isNotBlank(tipsexpression)) {
                        joiner.add(" (" + prossExclamationMark(tipsexpression) + " ) as [" + fieldId + "_tipsexpr]");
                    }
                }
               sql+= "   select @sqlList=stuff((SELECT ',' + CONVERT(VARCHAR,  isnull(fieldid,''))+''  from gField where formid=@formid and headflag=@headflag and isLoad=1 FOR XML PATH ('')),1,1,'')\n" +
                "   select @sql =' select top 1 '+ LOWER(@sqlList)+' from '+ @tableName+' where '+ @where\n" +
                "   EXEC sp_executesql @sql";
        return gridServiceIfc.getSimpleJdbcTemplate().queryForMap(sql, entity.getFormid(),entity.getHeadFlag(),entity.getFormType(),where);
            }
            return joiner.toString();
        } catch (Exception ex) {
            throw ex;
        } finally {
            SpObserver.setDBtoInstance();
        }
    }
    private String prossExclamationMark(String str) {
        return StringUtils.contains(str, "!") ? str.replaceFirst("!", "") : ("'" + str + "'");
    }
}
src/com/yc/app/v2/entity/RefreshDataEntity.java
@@ -11,6 +11,7 @@
    Integer headFlag;
    Integer formType;
    HashMap<String, Object> where;
    HashMap<String, Object> mainPrimaryKey;//用于单据的表头关联字段
    String postParmBy18;//18类型的查询条件sql
    Map<String, String> env;
}
src/com/yc/open/mutual/controller/MutualController.java
@@ -1829,11 +1829,11 @@
        DataSourceEntity dataSourceMap = MultiDataSource.getDataSourceMap(dbId);
        String url = this.getSystemUrlByDataSource(dataSourceMap);
        //------TODO 测试用,正式时 需要去掉
        if (url.startsWith("https:")) {
            url = url.replace("https:", "http:") + ":9010";
        } else {
            url = url.replace(":9001", ":9010");
        }
//        if (url.startsWith("https:")) {
//            url = url.replace("https:", "http:") + ":9010";
//        } else {
//            url = url.replace(":9001", ":9010");
//        }
//        //------------
        //log.info("内部推送url:" + url);
        //url="http://localhost:9001";