fs-danaus
2024-03-16 a2ecbf17d6ba1c7b135fe10bb4cdfefa05b75add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
package com.yc.app.v2.service.impl;
 
import com.yc.action.grid.GridUtils;
import com.yc.app.v2.entity.FormVOEntity;
import com.yc.app.v2.entity.GFieldEntity;
import com.yc.app.v2.entity.GformEntity;
import com.yc.app.v2.entity.MetaDataEntity;
import com.yc.app.v2.service.DanJunFormService;
import com.yc.app.v2.utils.Page;
import com.yc.exception.ApplicationException;
import com.yc.factory.FactoryBean;
import com.yc.service.panel.SqlDBHelperIfc;
import com.yc.service.sqlformat.entity.SqlFormatEntity;
import com.yc.service.sqlformat.utils.SqlFormatUtils;
import com.yc.utils.SessionKey;
import org.apache.commons.lang3.StringUtils;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Service;
 
import java.util.Base64;
import java.util.List;
import java.util.Map;
 
import static java.util.stream.Collectors.toList;
 
/**
 * 单据窗体类型基类
 */
@Service
public class DanJunFormServiceImpl extends BaseFormServiceImpl implements DanJunFormService {
 
    @Override
    public MetaDataEntity getMetaData(FormVOEntity formVOEntity, Map<String, String> env) {
        MetaDataEntity metaData = super.getMetaData(formVOEntity, env);
        if (metaData != null) {
            //单据状态值
            metaData.getInfo().put("9815", this.getSimpleJdbcTemplate().queryForList("set nocount on select dictvalue,interValue from _sysdict where dictid=(select DocStatusName from gform where formid=?)", formVOEntity.getFormId()));
 
            //OA按钮设置
            List<Map<String, Object>> list = this.getSimpleJdbcTemplate().queryForList("set nocount on select " + table3 + " from gfieldApprovedButton a left join t111634 b on a.ButtonName=b.ButtonName where a.formid=? order by a.[docitem] asc", formVOEntity.getFormId());
 
           // metaData.getInfo().put("9881", procc9881SQLFormat(list));
            metaData.getInfo().put("9881", list);
 
        }
        if (StringUtils.isBlank(formVOEntity.getDocCode())) {
            //没单号,表示新单
            formVOEntity.setNew(true);
        }
        return metaData;
    }
 
    /**
     * 处理动态sql
     *
     * @param list
     * @return
     */
    protected List<Map<String, Object>> procc9881SQLFormat(List<Map<String, Object>> list) {
 
        list.stream().map(x -> {
 
            final Map<String, SqlFormatEntity> sqlFormat = SqlFormatUtils.createSQLFormat(x, 9881);
            x.putAll(sqlFormat);
            return x;
        }).collect(toList());
        return list;
    }
 
    @Override
    public void prossDanJuPerssion(Page page, MetaDataEntity metaDataEntity, Map<String, String> env,FormVOEntity formVOEntity) {
        if(metaDataEntity.getGformEntity().isGetHeadTabe()) {
            //---处理9881,OA按钮的显示或隐藏
            List<Map> list = (List<Map>) metaDataEntity.getInfo().get("9881");
            StringBuilder sb = new StringBuilder();
            list.stream().forEach(x -> {
                sb.append(GridUtils.prossRowSetDataType_String(x, "buttonID")).append(";pb#")
                        .append(GridUtils.prossRowSetDataType_String(x, "showItemExpression")).append(";pb#")
                        .append(env.get(SessionKey.USERCODE)).append(";pb#")
                        .append(GridUtils.prossRowSetDataType_String(x, "editStatus")).append(";pb#")
                        .append(metaDataEntity.getGformEntity().getHdtable()).append(";pb#")
                        .append(StringUtils.isBlank(env.get("doccode")) ? "null" : env.get("doccode")).append(";fen#");
            });
            SqlDBHelperIfc sqlDBHelperIfc = (SqlDBHelperIfc) FactoryBean.getBean("SqlDBHelper");
            //替换会话值(取会话),页面值(取表数据)
            try {
                if (sb.length() > 0) {
                    Map buttonInfoMap = sqlDBHelperIfc.getBoolSql(prossExpressionFormSessionValues(sb.toString(), env));//取出按钮的设置信息
                    page.setOABtnInfo(buttonInfoMap);
                }
            } catch (Exception e) {
                e.printStackTrace();
                throw new ApplicationException(e.getMessage());
            }
            if (
                    StringUtils.isBlank(page.getOrigWhere())
                            //列表或有数据返回表明不需要执行下面的权限处理
                            ||
                            (page.getData() != null && ((List) page.getData()).size() > 0)
            ) {
                return;
            }
            String doccode=null;
            try {
                //getPageNum>1表示分页取数,5,8的主表只有一条记录,分页后是没有数据,而不是没权限查看
                if(page.getPageNum()==1) {
                    String where=page.getOrigWhere();
                    try{
                    //解码出错表示不是base64编码
                    where=new String(Base64.getDecoder().decode(page.getOrigWhere()),"utf-8");
                }catch (Exception e){}
                     doccode=where.toLowerCase().replaceAll("(?i)doccode='", "").replace("'", "").toUpperCase();
                    String enterName = gridService.getSimpleJdbcTemplate().queryForObject("select entername from " + page.getTableName() + " where " +where, String.class);
 
                    if (enterName != null) {
                        //没权限查看
                        throw new ApplicationException("您没有权限查看【" + doccode + "】单据内容,请联系制单人【" + enterName + "】", -1003);
                    } else {
                        //单据已删除
                        throw new ApplicationException("单据【" + doccode + "】已删除", -1003);
                    }
                }
            }catch (EmptyResultDataAccessException ex){
                throw new ApplicationException("查找不到此单据【"+doccode+"】", -1003);
            }catch (Exception e) {
                    throw new ApplicationException(e.getMessage(), -1003);
 
            }
 
        }
 
    }
 
    @Override
    protected String getDataformid(GformEntity gformEntity) {
        return "";
    }
 
    @Override
    public String getCancelBtnAndRevokeBtn(GformEntity gformEntity, FormVOEntity formVOEntity) {
        StringBuilder sb = new StringBuilder();
        if(gformEntity.isGetHeadTabe()) {
            if (StringUtils.isNotBlank(gformEntity.getCancelbtnprocname())) {
                //---取消确认按钮
                sb.append(" ,case when (1=1 ");
                if (StringUtils.isNotBlank(gformEntity.getCancelbtneditstatus())) {
                    sb.append("and docstatus in(select list from getinstr('" + gformEntity.getCancelbtneditstatus() + "') as b)");
                }
                if (StringUtils.isNotBlank(gformEntity.getCancelbtnexpression())) {
                    sb.append("and (" + gformEntity.getCancelbtnexpression() + ") \n");
                }
                sb.append(") then 1 else 0 end as [CancelBtn_Visible] \n");
            } else {
                //没设置则按钮不显示
                sb.append(",0 as [CancelBtn_Visible]");
            }
            //-----撤回按钮
            if (StringUtils.isNotBlank(gformEntity.getRevokebtnprocname())) {
                sb.append(",case when (1=1 ");
                if (StringUtils.isNotBlank(gformEntity.getRevokebtneditstatus())) {
                    sb.append("and docstatus in(select list from getinstr('" + gformEntity.getRevokebtneditstatus() + "') as b)\n");
                }
                if (StringUtils.isNotBlank(gformEntity.getRevokebtnexpression())) {
                    sb.append("and (" + gformEntity.getRevokebtnexpression() + ")\n");
                }
                sb.append(") then 1 else 0 end as [RevokeBtn_Visible]");
            } else {
                //没设置则按钮不显示
                sb.append(",0 as [RevokeBtn_Visible]");
            }
            //---------------在线交流,流程跟踪 by danaus 2024-03-15 09:36
            Integer isShowOnlineMsg = gformEntity.getIsshowonlinemsg();//是否显示,1显示,0不显示
            String showOnlineMsgExpression = gformEntity.getShowOnlineMsgExpression();//表达式
            Integer isShowProcessTracking = gformEntity.getIsshowprocesstracking();
            String showProcessTrackingExpression = gformEntity.getShowProcessTrackingExpression();
            //--在线交流sql表达式
            if (isShowOnlineMsg != null && isShowOnlineMsg == 1) {
                if (org.apache.commons.lang3.StringUtils.isNotBlank(showOnlineMsgExpression)) {
                    sb.append(",(case when " + showOnlineMsgExpression + " then 1 else 0 end) as [isShowOnlineMsgBtn_Visible]");
                } else {
                    //没有设置表达式,默认显示
                    sb.append(",1 as [isShowOnlineMsgBtn_Visible]");
                }
            } else {
                sb.append(",0 as [isShowOnlineMsgBtn_Visible]");
            }
            //--流程跟踪sql表达式
            if (isShowProcessTracking != null && isShowProcessTracking == 1) {
                if (org.apache.commons.lang3.StringUtils.isNotBlank(showProcessTrackingExpression)) {
                    sb.append(",(case when " + showProcessTrackingExpression + " then 1 else 0 end) as [isShowProcessTrackingBtn_Visible]");
                } else {
                    sb.append(",1 as [isShowProcessTrackingBtn_Visible]");
                }
            } else {
                sb.append(",0 as [isShowProcessTrackingBtn_Visible]");
            }
            //-----------
        }
        return sb.toString();
    }
 
    @Override
    public void perDanJuOpenProc(FormVOEntity formVOEntity, Map<String, String> env) {
        try {
            //---TODO 打开单据执行已读状态处理
            String execProc = gridService.getSimpleJdbcTemplate().queryForObject("set nocount on \n update a set a.isread=1,ReadDateTime=getdate()  from t219001 a where a.usercode=? and a.formid=? and a.formtype=? and a.doccode=? \n declare @execproc varchar(200)  \n select @execproc=isnull(execproc,'') from _sysOpenDoc where formid=? and formtype=? \n select @execproc", String.class, env.get(SessionKey.USERCODE), formVOEntity.getFormId(), formVOEntity.getFormType(), formVOEntity.getDocCode(), formVOEntity.getFormId(), formVOEntity.getFormType());
            if (StringUtils.isNotBlank(execProc)) {
                gridService.getSimpleJdbcTemplate().execute(" exec " + replaceStringFormSessionValues(execProc, env));
            }
        } catch (Exception e) {
            throw new ApplicationException((e.getCause() != null ? e.getCause().getMessage() : e.getMessage()) + "-请检查" + formVOEntity.getFormId() + "在【9884】所定义的存储过程是否已在数据库中维护好");
        }
    }
 
 
    @Override
    public Page getData(FormVOEntity formVOEntity, Map<String, String> env, MetaDataEntity metaDataEntity) {
        Page page= super.getData(formVOEntity, env, metaDataEntity);
        //---增加取消确认,撤回按钮的输出
        if(metaDataEntity!=null){
            //--加载主表数据才执行
           if( metaDataEntity.getGformEntity().isGetHeadTabe()&&page.getData()!=null){
              List<Map> list= (List<Map>) page.getData();
              if(list.size()>0){
                  //---替换参数输出 p170402Post '@usercode';'@username';doccode;formid;docstatus;'取消确认';'';''
                String cancelProName=this.getRecordValues(list.get(0),metaDataEntity.getGformEntity().getCancelbtnprocname(),env);
                String revokeProName=this.getRecordValues(list.get(0),metaDataEntity.getGformEntity().getRevokebtnprocname(),env);
                  ((Map)list.get(0)).put("CancelBtnProName",cancelProName);
                  ((Map)list.get(0)).put("RevokeBtnProName",revokeProName);
              }
           }
        }
        return page;
    }
 
    @Override
    public Integer getGridControlType(GFieldEntity gFieldEntity, GformEntity gformEntity) {
        //默认取面板类型
        return gFieldEntity.getControltype()==null?1:gFieldEntity.getControltype();
    }
}