Explorar o código

[bug-1604]【七院】platform 模块流程结束消费报错

szjbdgzl hai 1 ano
pai
achega
85bcccfc9c

+ 74 - 71
ibps-provider-root/modules/provider-platform/src/main/java/com/lc/ibps/mq/consumer/rabbit/RabbitSnapshotMessageQueueConsumer.java

@@ -6,7 +6,6 @@ import com.lc.ibps.base.framework.table.ICommonDao;
 import com.lc.ibps.base.web.context.ContextUtil;
 import com.lc.ibps.cloud.entity.APIResult;
 import com.lc.ibps.cloud.file.provider.UploadProvider;
-import com.lc.ibps.cloud.mq.consumer.api.consumer.IQueueConsumer;
 import com.lc.ibps.cloud.mq.core.constants.QueueConstants;
 import com.lc.ibps.cloud.mq.core.model.Message;
 import com.lc.ibps.common.file.persistence.entity.AttachmentPo;
@@ -22,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 
 import javax.annotation.Resource;
-import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -58,77 +56,82 @@ public class RabbitSnapshotMessageQueueConsumer   {
     protected String runqianBasePath;
 
     @RabbitHandler
-    public void popup(Message<String> message) throws Exception {
+    public void popup(Message<String> message) {
         String instId = message.getVariables().get("instId").toString();
-        String userId = message.getVariables().get("userId").toString();
-        Thread.sleep(10000);
-
-        /*
-        Step 1: fetch below sql by instId. if record returned, goto step 2,otherwise goto step 3.
-
-        select ti_jiao_kuai_zhao from t_lcidglbdbb
-        where tablekey_ = 'tsclb'  and gui_dang_lei_xing = 'process'
-        and  liu_cheng_xuan_ze = (select PROC_DEF_KEY_ from ibps_bpm_inst_his where id_ = '1166693885385113602' limit 1)
-
-        Step 2: check ti_jiao_kuai_zhao, if the value is yes, goto step 2.1, otherwise goto step 2.2
-        Step 2.1: call runQianUpload method to get generate pdf file.
-            //https://www.szjyxt.com/ibps/platform/v3/file/upload/runQianUpload?url=https:%2F%2Fwww.szjyxt.com%2Fdemo%2FreportServlet%3Faction%3D6%
-            26file%3D%25E9%2587%2591%25E9%2580%259A%25E5%258C%25BB%25E5%25AD%25A6%25E5%25AE%259E%25E9%25AA%258C%25E5%25AE%25A4%25E7%25AE%25A1%25E7%2590
-            %2586%25E7%25B3%25BB%25E7%25BB%259F%252F%25E6%258A%2595%25E8%25AF%2589%252F%25E6%258A%2595%25E8%25AF%2589%25E5%25A4%2584%25E7%2590%2586%25E8
-            %25A1%25A8.rpx%26print%3D1%26srcType%3Dfile%26paramString%3Did_%253D1166693885385113600%26org_%3D1136828146851512320&name=%E6%8A%95%E8%AF%89
-            %E5%A4%84%E7%90%86%E8%A1%A8202310251105&type=pdf
-            //uploadFile.runQianUpload()
-            and then update table t_tsclb with field: "shi_fou_guo_shen"="已完成"  "kuai_zhao_": "1166694051567632384"
-        Step 2.2: update table t_tsclb with field: "shi_fou_guo_shen"="已完成"
-
-        Step 3: waiting 10s and try it again.
-
-         */
-
-        Map<String, Object> hisMap = commonDao.queryOne("SELECT PROC_DEF_KEY_,BIZ_KEY_,PROC_DEF_NAME_ FROM ibps_bpm_inst_his WHERE id_ = '" + instId + "' ");
-
-        if (BeanUtils.isNotEmpty(hisMap)){
-            String procDefKey = hisMap.get("PROC_DEF_KEY_").toString();
-            String bizKey = hisMap.get("BIZ_KEY_").toString();
-            String procDefName = hisMap.get("PROC_DEF_NAME_").toString();
-            Map<String, Object> kzMap = commonDao.queryOne(" SELECT ti_jiao_kuai_zhao,bao_biao_lu_jing_,tablekey_ FROM t_lcidglbdbb " +
-                "where liu_cheng_xuan_ze = '"+procDefKey+"' AND gui_dang_lei_xing = 'process' limit 1");
-
-            if (BeanUtils.isNotEmpty(kzMap) && kzMap.containsKey("ti_jiao_kuai_zhao") &&
-                    BeanUtils.isNotEmpty(kzMap.get("ti_jiao_kuai_zhao")) && "是".equals(kzMap.get("ti_jiao_kuai_zhao")) ) {
-                LOGGER.warn("processing snapshot with instId= " + instId);
-                PartyEmployeePo employeePo = partyEmployeeRepository.get(userId);
-                String position = employeePo.getPositions().split(StringPool.COMMA)[0];
-                PartyEntityPo entityPo = partyEntityRepository.get(position);
-                String org = entityPo.getPath().split(StringPool.BACK_SLASH+StringPool.DOT)[0];
-                String reportPath = "金通医学实验室管理系统/" + kzMap.get("bao_biao_lu_jing_");
-                reportPath = URLEncoder.encode(reportPath, "UTF-8");
-                String baseUrl = runqianServer + runqianBasePath + "/reportServlet?action=6&file=";
-                DefaultPartyUserPo user = new DefaultPartyUserPo();
-                user.setUserId(userId);
-                user.setFullname(employeePo.getName());
-                user.setAccount(employeePo.getAccount());
-                ContextUtil.setCurrentUser(user);
-
-                // 文件批量新增修订记录表  需要根据子表(t_wjxzxdjlb)生成各自的快照  流程绑定的是主表(t_wjxdzb)
-                // 生成的快照文件名 取文件修订子表  xiu_ding_wen_jian 字段值 ,若该字段值为空则取 wen_jian_ming_che 字段
-                if ("Process_1ek5omy_2".equals(procDefKey)){
-                    String fileSql = "select id_,parent_id_,xiu_ding_wen_jian,wen_jian_ming_che from t_wjxzxdjlb where parent_id_ = '"+bizKey+"'";
-                    List<Map<String,Object>> list = (List<Map<String, Object>>) commonDao.query(fileSql);
-                    if (BeanUtils.isNotEmpty(list)){
-                        for (Map<String,Object> map : list){
-                            procDefName = (String) (BeanUtils.isNotEmpty(map.get("xiu_ding_wen_jian"))?map.get("xiu_ding_wen_jian"):map.get("wen_jian_ming_che"));
-                            bizKey = (String) map.get("id_");
-                            updateKuaiZhao(procDefKey,procDefName,bizKey,baseUrl,reportPath,org);
-                        }
-                    }
-                }else {
-                    updateKuaiZhao(procDefKey,procDefName,bizKey,baseUrl,reportPath,org);
+        try{
+            String userId = message.getVariables().get("userId").toString();
+            Thread.sleep(10000);
+
+            Map<String, Object> hisMap = commonDao.queryOne("SELECT PROC_DEF_KEY_,BIZ_KEY_,PROC_DEF_NAME_ FROM ibps_bpm_inst_his WHERE id_ = '" + instId + "' ");
+            if (BeanUtils.isNotEmpty(hisMap)){
+                String procDefKey = hisMap.get("PROC_DEF_KEY_").toString();
+                String bizKey = hisMap.get("BIZ_KEY_").toString();
+                String procDefName = hisMap.get("PROC_DEF_NAME_").toString();
+                Map<String, Object> kzMap = commonDao.queryOne(" SELECT ti_jiao_kuai_zhao,bao_biao_lu_jing_,tablekey_ FROM t_lcidglbdbb " +
+                        "where liu_cheng_xuan_ze = '"+procDefKey+"' AND gui_dang_lei_xing = 'process' limit 1");
+
+                if (BeanUtils.isNotEmpty(kzMap) && kzMap.containsKey("ti_jiao_kuai_zhao") &&
+                        BeanUtils.isNotEmpty(kzMap.get("ti_jiao_kuai_zhao")) && "是".equals(kzMap.get("ti_jiao_kuai_zhao")) ) {
+                    LOGGER.warn("processing snapshot with instId= " + instId);
+                    PartyEmployeePo employeePo = partyEmployeeRepository.get(userId);
+                    String position = employeePo.getPositions().split(StringPool.COMMA)[0];
+                    PartyEntityPo entityPo = partyEntityRepository.get(position);
+                    String org = entityPo.getPath().split(StringPool.BACK_SLASH+StringPool.DOT)[0];
+                    String reportPath = "金通医学实验室管理系统/" + kzMap.get("bao_biao_lu_jing_");
+                    reportPath = URLEncoder.encode(reportPath, "UTF-8");
+                    String baseUrl = runqianServer + runqianBasePath + "/reportServlet?action=6&file=";
+                    DefaultPartyUserPo user = new DefaultPartyUserPo();
+                    user.setUserId(userId);
+                    user.setFullname(employeePo.getName());
+                    user.setAccount(employeePo.getAccount());
+                    ContextUtil.setCurrentUser(user);
+
+                    this.produceFile(procDefKey,procDefName,bizKey,baseUrl,reportPath,org);
+
+                }
+            } else{
+                LOGGER.warn("can't find any record. it will be tried it again. instId=" +instId);
+            }
+        }catch (Exception e){
+            String sql = " insert into t_bckzsjb (id_, create_by_, create_time_,biz_key_, proc_def_key_, proc_def_name_," +
+                    " bao_biao_lu_jing_,user_id_,user_name_,account_,end_time_,bo_code_,position_id_,org_id_,msg_,shi_fou_guo_shen_) " +
+                    " select " +
+                    "    h.id_,h.create_by_,now(),h.biz_key_,h.proc_def_key_,h.proc_def_name_,d.bao_biao_lu_jing_,e.id_ user_id_,e.name_,u.account_,h.end_time_, " +
+                    "    concat('t_',f.bo_code_) as bo_code_,e1.position_id,substring_index(p.path_,'.', 1) as org_id_ ,'"+e.getMessage()+"' as msg_,'生成快照异常数据' as shi_fou_guo_shen_" +
+                    " from " +
+                    "    ibps_bpm_inst_his h " +
+                    "    inner join t_lcidglbdbb d on h.proc_def_key_ = d.liu_cheng_xuan_ze " +
+                    "    left join ibps_bpm_def f on f.def_key_ = h.proc_def_key_ " +
+                    "    left join ibps_party_employee e on e.id_ = h.create_by_ " +
+                    "    left join ibps_party_user u on e.id_ = u.id_ " +
+                    "    left join (select id_, substring_index(positions_, ',', 1) as position_id from ibps_party_employee) e1 on e.id_ = e1.id_ " +
+                    "    left join ibps_party_entity p on e1.position_id = p.id_ " +
+                    " where " +
+                    "    d.bao_biao_lu_jing_ is not null " +
+                    "    and d.bao_biao_lu_jing_ <> '' " +
+                    "    and h.id_ ='"+instId+"'";
+            commonDao.execute(sql);
+            LOGGER.error("MQ消费生成快照异常. instId=" +instId);
+            e.printStackTrace();
+        }
+    }
+
+    // 文件修订流程特殊处理
+    private void produceFile(String procDefKey,String procDefName,String bizKey,String baseUrl,String reportPath,String org){
+        // 文件批量新增修订记录表  需要根据子表(t_wjxzxdjlb)生成各自的快照  流程绑定的是主表(t_wjxdzb)
+        // 生成的快照文件名 取文件修订子表  xiu_ding_wen_jian 字段值 ,若该字段值为空则取 wen_jian_ming_che 字段
+        if ("Process_1ek5omy_2".equals(procDefKey)){
+            String fileSql = "select id_,parent_id_,xiu_ding_wen_jian,wen_jian_ming_che from t_wjxzxdjlb where parent_id_ = '"+bizKey+"'";
+            List<Map<String,Object>> list = (List<Map<String, Object>>) commonDao.query(fileSql);
+            if (BeanUtils.isNotEmpty(list)){
+                for (Map<String,Object> map : list){
+                    procDefName = (String) (BeanUtils.isNotEmpty(map.get("xiu_ding_wen_jian"))?map.get("xiu_ding_wen_jian"):map.get("wen_jian_ming_che"));
+                    bizKey = (String) map.get("id_");
+                    this.updateKuaiZhao(procDefKey,procDefName,bizKey,baseUrl,reportPath,org);
                 }
             }
-        } else{
-            LOGGER.warn("can't find any record. it will be tried it again. instId=" +instId);
-            throw new Exception("can't find any record. it will be tried it again.");
+        }else {
+            this.updateKuaiZhao(procDefKey,procDefName,bizKey,baseUrl,reportPath,org);
         }
     }
 
@@ -149,7 +152,7 @@ public class RabbitSnapshotMessageQueueConsumer   {
                     sql = "update t_" + defMap.get("BO_CODE_") + " set kuai_zhao_ = '" + result.getData().getId() + "'  where id_ = '"+bizKey+"'";
                 }
                 commonDao.execute(sql);
-                LOGGER.warn("Generated Snapshot ID=" + result.getData().getId());
+                LOGGER.warn("Generated Snapshot Success FileID=" + result.getData().getId());
             }
         }
     }