Browse Source

日志数据丢失,万盛计量,任务审批查看报表按钮

DengLinLang 23 hours ago
parent
commit
4d926ef99b

+ 6 - 1
blade-service-api/blade-business-api/src/main/java/org/springblade/business/vo/SaveContractLogVO.java

@@ -34,8 +34,12 @@ public class SaveContractLogVO {
     private List<JSONObject> correlationIds;
     @ApiModelProperty("源数据的日志id")
     private  String oldDataId;
+    //这里只是为了解决事务导致的表锁 把这个参数传到保存日志关联工序信息的地方去删除
+    @ApiModelProperty("对应实体表的数据id = businessIds")
+    private  String businessIds;
 
-    public SaveContractLogVO(String businessId, String projectId, String contractId, Long wbsNodeId, Long tableId, Integer wbsNodeType, String recordTime, List<JSONObject> correlationIds, String oldDataId) {
+
+    public SaveContractLogVO(String businessId, String projectId, String contractId, Long wbsNodeId, Long tableId, Integer wbsNodeType, String recordTime, List<JSONObject> correlationIds, String oldDataId,String businessIds) {
         this.dataId = businessId;
         this.projectId = Long.parseLong(projectId);
         this.contractId = Long.parseLong(contractId);
@@ -45,6 +49,7 @@ public class SaveContractLogVO {
         this.recordTime = recordTime;
         this.correlationIds = correlationIds;
         this.oldDataId = oldDataId;
+        this.businessIds = businessIds;
     }
 
     public SaveContractLogVO() {

+ 33 - 2
blade-service/blade-business/src/main/java/org/springblade/business/feignClient/ContractLogClientImpl.java

@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
 import org.springblade.business.entity.ContractLog;
 import org.springblade.business.entity.ContractLogWbs;
 import org.springblade.business.feign.ContractLogClient;
@@ -18,12 +20,14 @@ import org.springblade.core.tool.utils.Func;
 import org.springblade.manager.entity.WbsTreePrivate;
 import org.springblade.manager.feign.WbsTreePrivateClient;
 import org.springframework.beans.BeanUtils;
+import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
+@Slf4j
 @RestController
 @AllArgsConstructor
 @NonDS
@@ -34,6 +38,7 @@ public class ContractLogClientImpl implements ContractLogClient {
     private final IContractLogWbsService contractLogWbsService;
 
     private final WbsTreePrivateClient wbsTreePrivateClient;
+    private final JdbcTemplate jdbcTemplate;
 
     @Override
     public List<JSONObject> queryContractLogWbsByBusinessId(String businessId) {
@@ -136,6 +141,14 @@ public class ContractLogClientImpl implements ContractLogClient {
 
     @Override
     public String saveContractLog(SaveContractLogVO saveContractLogVO) {
+        String businessIds = saveContractLogVO.getBusinessIds();
+        //删除旧数据
+        if (StringUtils.isNotEmpty(businessIds)) {
+            //删除关联工序信息
+            String delSql = " delete from u_contract_log_wbs where business_id in(" + businessIds + ")";
+            this.jdbcTemplate.execute(delSql);
+        }
+
         ContractLog contractLog = new ContractLog();
         //复制数据
         BeanUtils.copyProperties(saveContractLogVO, contractLog);
@@ -159,8 +172,26 @@ public class ContractLogClientImpl implements ContractLogClient {
             this.contractLogWbsService.saveBatch(logWbsList);
         }
 
-        this.contractLogService.save(contractLog);
-
+        try {
+            this.contractLogService.save(contractLog);
+        } catch (Exception e) {
+            return "新增异常";
+        }
+        try {
+            StringBuilder saveSql = new StringBuilder("INSERT INTO u_contract_log(id,project_id,contract_id,wbs_node_id,wbs_node_type" +
+                    ",record_time,data_id,create_user,create_user_name,update_user,status,file_name,pdf_url,table_id,old_data_id) VALUES ");
+            saveSql.append("(" + contractLog.getId() + "," + contractLog.getProjectId() + "," + contractLog.getContractId() + "," +
+                    contractLog.getWbsNodeId() + "," + contractLog.getWbsNodeType() + ",'" + contractLog.getRecordTime() + "','" +
+                    contractLog.getDataId()+ "'," + contractLog.getCreateUser() + ",'" +contractLog.getCreateUserName()+ "'," +
+                    contractLog.getUpdateUser()+ "," + contractLog.getStatus() + ",'" + contractLog.getFileName() + "','" + contractLog.getPdfUrl() + "'," +
+                    contractLog.getTableId() + ",'" + contractLog.getOldDataId() + "')");
+            StringBuilder logSql = new StringBuilder("INSERT INTO blade_log_sql (contract_log_id,user_id,create_time,sql_info) VALUES " );
+            String replaceSql = saveSql.toString().replace("\"", "'");
+            logSql.append("("+contractLog.getId()+","+contractLog.getCreateUser()+",SYSDATE(),\"" + replaceSql + "\")");
+            jdbcTemplate.execute(logSql.toString());
+        } catch (Exception e) {
+            return contractLog.getId().toString();
+        }
         return contractLog.getId().toString();
     }
 

+ 4 - 2
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ExcelTabController.java

@@ -3062,7 +3062,8 @@ public class ExcelTabController extends BladeController {
                                 objLog.getWbsNodeType(),
                                 currentTime,
                                 logWbsList,
-                                theLogId
+                                theLogId,
+                                null
                         ));
                         logIds.add(id);
                     }else {
@@ -3085,7 +3086,8 @@ public class ExcelTabController extends BladeController {
                                     contractLog.getWbsNodeType(),
                                     currentTime,
                                     logWbsList,
-                                    theLogId
+                                    theLogId,
+                                    null
                             );
                             this.contractLogClient.saveLogWbsList(saveContractLogVO);
                         }

+ 46 - 27
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ExcelTabServiceImpl.java

@@ -75,6 +75,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.TransactionDefinition;
 import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.support.DefaultTransactionDefinition;
 
 import java.io.*;
@@ -639,6 +640,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
      * 保存日志
      */
     @Override
+    @Transactional
     public String saveOrUpdateTheLog(List<TableInfo> tableInfoList) {
         //查询绑定的节点
         WbsTreePrivate tableNode = this.wbsTreePrivateService.getOne(Wrappers.<WbsTreePrivate>lambdaQuery().eq(WbsTreePrivate::getPKeyId, tableInfoList.get(0).getPkeyId()));
@@ -678,8 +680,8 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
 
         //删除旧数据
         if (StringUtils.isNotEmpty(businessIds)) {
-            //删除实体表数据、关联工序信息
-            String delSql = "delete from " + tableNode.getInitTableName() + " where id in(" + businessIds + "); delete from u_contract_log_wbs where business_id in(" + businessIds + ")";
+            //删除实体表数据、
+            String delSql = "delete from " + tableNode.getInitTableName() + " where id in(" + businessIds + ")";
             this.jdbcTemplate.execute(delSql);
         }
         if (StringUtils.isNotEmpty(ids)) {
@@ -687,17 +689,21 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
             String delSql = "delete from u_contract_log where id in(" + ids + ")";
             this.jdbcTemplate.execute(delSql);
             //添加操作日志
-            String delSqlNew = delSql.replace("\"", "'");
-            StringBuffer sb = new StringBuffer();
-            sb.append("insert into blade_log_sql (p_key_id,contract_log_id,user_id,create_time,sql_info) VALUES");
-            sb.append("(" + tableNode.getPKeyId());
-            sb.append("," + ids);
-            sb.append(","+ AuthUtil.getUserId());
-            sb.append(",SYSDATE()");
-            sb.append(",\"");
-            sb.append(delSqlNew);
-            sb.append("\")");
-            jdbcTemplate.execute(sb.toString());
+            try {
+                String delSqlNew = delSql.replace("\"", "'");
+                StringBuffer sb = new StringBuffer();
+                sb.append("insert into blade_log_sql (p_key_id,contract_log_id,user_id,create_time,sql_info) VALUES");
+                sb.append("(" + tableNode.getPKeyId());
+                sb.append(",\"" + ids+"\"");
+                sb.append(","+ AuthUtil.getUserId());
+                sb.append(",SYSDATE()");
+                sb.append(",\"");
+                sb.append(delSqlNew);
+                sb.append("\")");
+                jdbcTemplate.execute(sb.toString());
+            } catch (DataAccessException e) {
+                log.error("添加操作日志异常:ExcelTabServiceImpl-saveOrUpdateTheLog() 搜索代码:jdbcTemplate.execute(sb.toString());");
+            }
         }
 
         List<String> dataIds = new LinkedList<>();
@@ -734,6 +740,9 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                 String errorMessage = e.getMessage();
                 if (StringUtils.isNotEmpty(errorMessage)) {
                     String errorKey = null;
+                    if(errorMessage.contains("bad SQL grammar")){
+                        throw new ServiceException("存在不规则特殊字符,新增失败");
+                    }
                     if (errorMessage.contains("long for column ") && errorMessage.contains(" at ")) {
                         errorKey = errorMessage.split("long for column ")[1].split(" at ")[0];
                     }
@@ -747,6 +756,8 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                                 errorKeyName = tabElement.getEName();
                             }
                         }
+                    }else {
+                        throw new RuntimeException("新增数据异常");
                     }
                 }
                 e.printStackTrace();
@@ -778,22 +789,30 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                 parentNode.getMajorDataType(),
                 recordTime,
                 logWbsList,
-                oldDataId
+                oldDataId,
+                businessIds
         ));
+        if("新增异常".equals(dataId)){
+            throw new ServiceException("日志文件新增异常");
+        }
         if (StringUtils.isNotEmpty(dataId)) {
-            for (String insterTataSql : insterTataSqls) {
-                //添加操作日志
-                String sqlNew = insterTataSql.toString().replace("\"", "'");
-                StringBuffer sb = new StringBuffer();
-                sb.append("insert into blade_log_sql (p_key_id,contract_log_id,user_id,create_time,sql_info) VALUES ");
-                sb.append("("+tableNode.getPKeyId());
-                sb.append(","+dataId);
-                sb.append(","+AuthUtil.getUserId());
-                sb.append(",SYSDATE()");
-                sb.append(",\"");
-                sb.append(sqlNew);
-                sb.append("\")");
-                jdbcTemplate.execute(sb.toString());
+            try {
+                for (String insterTataSql : insterTataSqls) {
+                    //添加操作日志
+                    String sqlNew = insterTataSql.toString().replace("\"", "'");
+                    StringBuffer sb = new StringBuffer();
+                    sb.append("insert into blade_log_sql (p_key_id,contract_log_id,user_id,create_time,sql_info) VALUES ");
+                    sb.append("("+tableNode.getPKeyId());
+                    sb.append(","+dataId);
+                    sb.append(","+AuthUtil.getUserId());
+                    sb.append(",SYSDATE()");
+                    sb.append(",\"");
+                    sb.append(sqlNew);
+                    sb.append("\")");
+                    jdbcTemplate.execute(sb.toString());
+                }
+            } catch (DataAccessException e) {
+                log.error("添加操作日志异常 ExcelTabServiceImpl-saveOrUpdateTheLog()方法 搜索代码:for (String insterTataSql : insterTataSqls) { ");
             }
             dataIds.add(dataId);
         }

+ 4 - 4
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/FormulaServiceImpl.java

@@ -2346,18 +2346,18 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
             d6.setCellValue(AmountToChineseConverter.upperCase2(currentPay.doubleValue()));
             //-----------------------------------------------------------承包单位申报款--------------------------------------------------------------------
             Cell e10 = getCellByAddress(sheet, "E10");
-            e10.setCellValue(AllcurrentMeterTotal.toString());
+            e10.setCellValue(AllcurrentMeterTotal.toString()+"元");
             //-----------------------------------------------------------经审核承包单位应得款--------------------------------------------------------------------
             Cell e11 = getCellByAddress(sheet, "E11");
-            e11.setCellValue(AllcurrentMeterTotal.toString());
+            e11.setCellValue(AllcurrentMeterTotal.toString()+"元");
             //------------------------------------------------------------本期应扣款------------------------------------------------------------
             //本期扣取保留金=本期计量 - 本期支付
             BigDecimal deductionMoney = AllcurrentMeterTotal.subtract(currentPay);
             Cell e12 = getCellByAddress(sheet, "E12");
-            e12.setCellValue(deductionMoney.toString());
+            e12.setCellValue(deductionMoney.toString()+"元");
             //------------------------------------------------------------本期应付款------------------------------------------------------------
             Cell e13 = getCellByAddress(sheet, "E13");
-            e13.setCellValue(currentPay.toString());
+            e13.setCellValue(currentPay.toString()+"元");
 
             //***************************************************************所有日期*************************************************************************
             //底部日期

+ 1 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/SignPfxFilePreServiceImpl.java

@@ -75,7 +75,6 @@ public class SignPfxFilePreServiceImpl implements ISignPfxFilePreService {
     @Override
     public R prePicture(SignPfxFilePreVo vo) throws Exception {
 //        SignPfxFilePre spr = signPfxFilePreMapper.selectByPrimaryKey(vo.getId());
-        InputStream inputStreamByUrl1 = FileUtils.getInputStreamByUrl(vo.getFileStr());
         MultipartFile file1 = vo.getFile();
         //宽度
         Double wide = vo.getWide();
@@ -83,6 +82,7 @@ public class SignPfxFilePreServiceImpl implements ISignPfxFilePreService {
         Double high = vo.getHigh();
         if(ObjectUtil.isEmpty(wide) && ObjectUtil.isEmpty(high)){
             if(ObjectUtil.isEmpty(file1)){
+                InputStream inputStreamByUrl1 = FileUtils.getInputStreamByUrl(vo.getFileStr());
                 Map imageSize = FileUtils.getImageSize(inputStreamByUrl1);
                 Integer width = (Integer) imageSize.get("width");
                 Integer height = (Integer) imageSize.get("height");

+ 4 - 4
blade-service/blade-manager/src/main/java/org/springblade/manager/utils/AmountToChineseConverter.java

@@ -6,7 +6,7 @@ public class AmountToChineseConverter {
 
     public static String upperCase2(double money){
         String[] upNum = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
-        String[] danwei = {"","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟"};
+        String[] danwei = {"","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟"};
         //取消科学记数法
         NumberFormat numFormat = NumberFormat.getInstance();
         numFormat.setMaximumFractionDigits(2);//设置小数位个数
@@ -30,7 +30,7 @@ public class AmountToChineseConverter {
         //大于12位就直接返回。
         int moneyLen = strMoney.length();
         if(money==0){
-            return "零整";
+            return "零整";
         }
         if(moneyLen>12){
             return "金额:"+money+"元,超出大写转换范围。最大金额:999999999999.99元";
@@ -78,8 +78,8 @@ public class AmountToChineseConverter {
                 String substring = result.substring(0,result.length() - 1);
                 result = substring;
             }
-            result = result.concat("");
-            result = result.replaceAll("圆圆","圆");
+            result = result.concat("");
+            result = result.replaceAll("元元","元");
             result = result.replaceAll("万万","万");
 
         }

+ 3 - 3
blade-service/blade-meter/src/main/java/org/springblade/meter/controller/TaskController.java

@@ -3612,7 +3612,7 @@ public class TaskController extends BladeController {
         if (task == null){
             return R.fail("未找到任务相关信息");
         }
-        if (task.getStatus() == 2){
+        if (task.getStatus() == 2 || task.getStatus() == 1){
             String pdfUrl;
             //审批完成
             String sql;
@@ -3626,10 +3626,10 @@ public class TaskController extends BladeController {
                 return R.fail("电签报表生成中,请稍后再试");
             }
             return R.data(pdfUrl);
-        }else if (task.getStatus() == 1){
+        }/*else if (task.getStatus() == 1){
             //审批中
             return calculate(reportId, type, taskType);
-        }else {
+        }*/else {
             //已废除
             return R.fail("已废除无法查看报表");
         }