| 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; | 
|     } | 
| } |