jinlin
2024-02-23 1772fc5e211f9e9e0ab4cdc6c29b436aac178c2a
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
package com.zt.modules.workflowconfig.service;
 
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.zt.common.db.query.QueryFilter;
import com.zt.common.service.BaseService;
import com.zt.common.utils.JsonUtils2;
import com.zt.core.context.UserContext;
import com.zt.modules.workflow.model.WfRunTask;
import com.zt.modules.workflow.service.WorkflowService;
import com.zt.modules.workflowconfig.dao.WfDefDao;
import com.zt.modules.workflowconfig.model.WfDef;
import com.zt.modules.workflowconfig.model.WfDefStep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.awt.*;
import java.awt.font.FontRenderContext;
import java.awt.geom.AffineTransform;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
 
@Service
public class WfDefService extends BaseService<WfDefDao, WfDef> {
    @Autowired
    private WfDefDao wfDefDao;
 
    @Autowired
    WorkflowService workflowService;
 
    public int listWfDef(Long id) {
        return wfDefDao.listWfdef(id);
    }
 
    public int listWfDefcode(String code) {
        return wfDefDao.listWfdefcode(code);
    }
 
    enum StatusEnum {zy, jxz, lq, yq, zcwc, cqwc}
 
    String[] fillColorArr = {"#e5e5e5", "#e5e5e5", "#e5e5e5", "#e5e5e5", "#e5e5e5", "#e5e5e5"};
    String[] fontColorArr = {"#e5e5e5", "#e5e5e5", "#e5e5e5", "#e5e5e5", "#e5e5e5", "#e5e5e5"};
 
    public List<WfDef> wfDefList(QueryFilter queryFilter) {
        List<WfDef> wfDef = wfDefDao.wfDefList(queryFilter.getQueryParams());
        return wfDef;
    }
 
    public List<WfDef> getFlowList() {
        return wfDefDao.getFlowList();
    }
 
    public List<WfDefStep> getFlowStepList(String flowId) {
        return wfDefDao.getFlowStepList(flowId);
    }
 
    public WfDef getFlowStatusJson(String flowCode, Long bizId) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("projectId", 10000);
        params.put("diagramId", 10000);
        List<WfDef> list_style = baseDao.getStyleList(params);
        if (list_style.size() > 0) {
            String modelStr = list_style.get(0).getDiagram();
            JSONObject modelJson = new JSONObject(modelStr);
            JSONArray modelJsonArray = modelJson.getJSONArray("cells");
            for (int i = 0; i < modelJsonArray.size(); i++
            ) {
                JSONObject jsonObject = modelJsonArray.getJSONObject(i);
                if (jsonObject.get("shape").equals("custom-circle")) {
                    if ("专业".equals(JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/text".split("/")))) {
                        fillColorArr[StatusEnum.zy.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/body/fill".split("/")).toString();
                        fontColorArr[StatusEnum.zy.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/fill".split("/")).toString();
                    }
                    if ("进行中".equals(JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/text".split("/")))) {
                        fillColorArr[StatusEnum.jxz.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/body/fill".split("/")).toString();
                        fontColorArr[StatusEnum.jxz.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/fill".split("/")).toString();
                    }
                    if ("临期".equals(JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/text".split("/")))) {
                        fillColorArr[StatusEnum.lq.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/body/fill".split("/")).toString();
                        fontColorArr[StatusEnum.lq.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/fill".split("/")).toString();
                    }
                    if ("逾期".equals(JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/text".split("/")))) {
                        fillColorArr[StatusEnum.yq.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/body/fill".split("/")).toString();
                        fontColorArr[StatusEnum.yq.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/fill".split("/")).toString();
                    }
                    if ("完成".equals(JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/text".split("/")))) {
                        fillColorArr[StatusEnum.zcwc.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/body/fill".split("/")).toString();
                        fontColorArr[StatusEnum.zcwc.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/fill".split("/")).toString();
                    }
                    if ("超期完成".equals(JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/text".split("/")))) {
                        fillColorArr[StatusEnum.cqwc.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/body/fill".split("/")).toString();
                        fontColorArr[StatusEnum.cqwc.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/fill".split("/")).toString();
                    }
                }
            }
        }
        if ("yearPlan".equals(flowCode) || "yearPlan2".equals(flowCode))
            params.put("flowCode", "yearPlan");
        else params.put("flowCode", flowCode);
 
        List<WfDef> wfDefList = wfDefDao.wfDefList2(params);
        WfDef wfDef = new WfDef();
        if (wfDefList.size() > 0) {
            wfDef = wfDefList.get(0);
            Map<String, WfRunTask> statusMap = new Hashtable<>();
            String dialgramJsonStr = wfDef.getDiagram();
            {
                if ("yearPlan".equals(flowCode)) {
                    WfRunTask item_zl = new WfRunTask();
                    WfRunTask item_cz = new WfRunTask();
                    int count = baseDao.getRoleCount(UserContext.getUser().getId(), "zlbm");
                    if (count > 1) {
                        item_zl.setStatus(1);
                        item_cz.setStatus(0);
                    } else {
                        item_zl.setStatus(20);
                        item_cz.setStatus(1);
                    }
                    statusMap.put("yearPlan_zl", item_zl);
                    statusMap.put("yearPlan_cz", item_cz);
                } else if ("yearPlan2".equals(flowCode)) {
                    WfRunTask item_zl = new WfRunTask();
                    WfRunTask item_cz = new WfRunTask();
                    int status = baseDao.getPlanStatus(bizId);
                    if (status == 10) {
                        item_zl.setStatus(20);
                        item_cz.setStatus(20);
                    } else if (status == 5) {
                        item_zl.setStatus(20);
                        item_cz.setStatus(1);
                    } else {
                        item_zl.setStatus(1);
                        item_cz.setStatus(0);
                    }
 
                    statusMap.put("yearPlan_zl", item_zl);
                    statusMap.put("yearPlan_cz", item_cz);
                }else {
                    if ("xqzbFlow".equals(flowCode) || "zkxlFlow".equals(flowCode)
                            || "syshFlow".equals(flowCode) || "xjysFlow".equals(flowCode)
                            || "gcbxFlow".equals(flowCode)
                    ) {
                        statusMap = workflowService.getPhaseFlowStatus(flowCode,bizId);
                    }
                    else if ("3".equals(wfDef.getType())) {
                        statusMap = workflowService.getSingleFlowStatus(flowCode, bizId);
                    } else {
                        statusMap = workflowService.getFlowStatus("", bizId);
                    }
                }
 
                int showStatus = 1;
                JSONObject dialgramJson = new JSONObject(dialgramJsonStr);
                JSONArray dialgramJsonArray = dialgramJson.getJSONArray("cells");
 
                for (int i = 0; i < dialgramJsonArray.size(); i++
                ) {
                    JSONObject jsonObject = dialgramJsonArray.getJSONObject(i);
                    String shape = jsonObject.get("shape").toString();
                    StatusEnum status = StatusEnum.zy;//StatusEnum.wqd;
                    if (shape.equals("text-block") || shape.equals("custom-polygon")) {
                        Object text = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/text".split("/"));
                        Object stepMark = JsonUtils2.getJsonValueByPath(jsonObject, "data/stepMarker".split("/"));
                        String receiveName = null;
                        if (text != null && "开始".equals(text)) {
                            status = StatusEnum.zcwc;
                        } else if (stepMark != null && !"".equals(stepMark)) {
                            if (statusMap.get(stepMark) != null) {
                                receiveName = statusMap.get(stepMark).getReceiveName();
                                showStatus = statusMap.get(stepMark).getStatus();
                                if (showStatus == 1)
                                    status = StatusEnum.lq;
                                else if (showStatus == 20)
                                    status = StatusEnum.zcwc;
                            }
                        } else {
                            status = null;
                        }
                        if (status != null) {
                            JsonUtils2.setJsonValueByPath(jsonObject, "attrs/body/fill".split("/"), fillColorArr[status.ordinal()]);
                            JsonUtils2.setJsonValueByPath(jsonObject, "attrs/text/fill".split("/"), fontColorArr[status.ordinal()]);
                            if (receiveName != null) {
                                JsonUtils2.setJsonValueByPath(jsonObject, "data/receiveName".split("/"), receiveName);
                                AffineTransform affinetransform = new AffineTransform();
                                FontRenderContext frc = new FontRenderContext(affinetransform, true, true);
                                Font font = new Font("Helvetica Neue", Font.PLAIN, 14);
                                JsonUtils2.setJsonValueByPath(jsonObject, "data/tipsWidth".split("/"),  (int) font.getStringBounds(receiveName, frc).getWidth());
                            }
                        }
                    }
                }
                wfDef.setDiagram(dialgramJson.toString());
            }
        }
        return wfDef;
    }
}