fix(common): 统一异常处理并迁移打印功能到hiprint

- 替换所有System.out.println和printStackTrace为slf4j日志记录
- 在BeanUtils、AuditFieldUtil、DateUtils、ServletUtils等工具类中添加Logger实例
- 在Flowable相关控制器和服务中统一错误日志记录格式
- 在代码生成器中添加日志记录功能
- 将前端打印组件从Lodop迁移到hiprint打印方案
- 更新体温单打印功能使用hiprint预览打印
- 移除调试用的console.log语句
- 修复打印模板中线条元素类型定义
This commit is contained in:
2026-03-06 22:16:44 +08:00
parent 8ef334ba1b
commit b65841c0cc
58 changed files with 678 additions and 888 deletions

View File

@@ -2,6 +2,8 @@ package com.core.common.utils;
import com.core.common.core.domain.model.LoginUser;
import com.core.common.utils.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.lang.reflect.Field;
@@ -13,6 +15,8 @@ import java.util.Date;
*/
@Component
public class AuditFieldUtil {
private static final Logger log = LoggerFactory.getLogger(AuditFieldUtil.class);
/**
* 为实体设置创建相关的审计字段
@@ -65,8 +69,7 @@ public class AuditFieldUtil {
}
} catch (Exception e) {
System.err.println("设置创建审计字段时发生异常: " + e.getMessage());
e.printStackTrace();
log.error("设置创建审计字段时发生异常", e);
}
}
@@ -110,8 +113,7 @@ public class AuditFieldUtil {
}
} catch (Exception e) {
System.err.println("设置更新审计字段时发生异常: " + e.getMessage());
e.printStackTrace();
log.error("设置更新审计字段时发生异常", e);
}
}

View File

@@ -1,6 +1,8 @@
package com.core.common.utils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.management.ManagementFactory;
import java.text.ParseException;
@@ -13,10 +15,13 @@ import java.util.Date;
/**
* 时间工具类
*
*
* @author system
*/
public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
private static final Logger log = LoggerFactory.getLogger(DateUtils.class);
public static String YYYY = "yyyy";
public static String YYYY_MM = "yyyy-MM";
@@ -227,7 +232,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
return endTime;
}
} catch (DateTimeParseException e) {
e.printStackTrace();
log.warn("日期解析失败: {}", strDate, e);
}
return null;
}
@@ -250,7 +255,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
// 检查日期是否是未来的时间
return dateToCheck.isAfter(currentDate);
} catch (Exception e) {
e.printStackTrace();
log.warn("日期解析失败: {}", dateString, e);
// 解析失败或其他异常,返回 false 或根据需要处理异常
return false;
}

View File

@@ -2,6 +2,8 @@ package com.core.common.utils;
import com.core.common.constant.Constants;
import com.core.common.core.text.Convert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
@@ -20,10 +22,13 @@ import java.util.Map;
/**
* 客户端工具类
*
*
* @author system
*/
public class ServletUtils {
private static final Logger log = LoggerFactory.getLogger(ServletUtils.class);
/**
* 获取String参数
*/
@@ -130,7 +135,7 @@ public class ServletUtils {
response.setCharacterEncoding("utf-8");
response.getWriter().print(string);
} catch (IOException e) {
e.printStackTrace();
log.error("渲染响应字符串失败", e);
}
}

View File

@@ -1,5 +1,8 @@
package com.core.common.utils.bean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
@@ -12,6 +15,9 @@ import java.util.regex.Pattern;
* @author system
*/
public class BeanUtils extends org.springframework.beans.BeanUtils {
private static final Logger log = LoggerFactory.getLogger(BeanUtils.class);
/**
* Bean方法名中属性名开始的下标
*/
@@ -37,7 +43,7 @@ public class BeanUtils extends org.springframework.beans.BeanUtils {
try {
copyProperties(src, dest);
} catch (Exception e) {
e.printStackTrace();
log.error("Bean属性复制失败", e);
}
}

View File

@@ -115,7 +115,7 @@ public class FlowDefinitionController extends BaseController {
ImageIO.write(image, "png", os);
}
} catch (Exception e) {
e.printStackTrace();
log.error("读取流程图片失败, deployId: {}", deployId, e);
} finally {
try {
if (os != null) {
@@ -123,7 +123,7 @@ public class FlowDefinitionController extends BaseController {
os.close();
}
} catch (IOException e) {
e.printStackTrace();
log.error("关闭输出流失败", e);
}
}

View File

@@ -211,7 +211,7 @@ public class FlowTaskController extends BaseController {
ImageIO.write(image, "png", os);
}
} catch (Exception e) {
e.printStackTrace();
log.error("读取流程图片失败", e);
} finally {
try {
if (os != null) {
@@ -219,7 +219,7 @@ public class FlowTaskController extends BaseController {
os.close();
}
} catch (IOException e) {
e.printStackTrace();
log.error("关闭输出流失败", e);
}
}
}

View File

@@ -722,7 +722,7 @@ public class FlowableUtils {
// 反射设置属性值
field.set(propertyDto, attribute.getValue());
} catch (IllegalAccessException e) {
e.printStackTrace();
log.warn("反射设置属性值失败", e);
// 如果反射设置失败则忽略该属性
}
});
@@ -730,7 +730,7 @@ public class FlowableUtils {
return propertyDto;
}).collect(Collectors.toList());
} catch (Exception e) {
e.printStackTrace();
log.error("解析流程属性失败", e);
return Collections.emptyList(); // 如果发生异常则返回空列表
}
}

View File

@@ -209,7 +209,7 @@ public class FlowDefinitionServiceImpl extends FlowServiceFactory implements IFl
}
return AjaxResult.success("流程启动成功");
} catch (Exception e) {
e.printStackTrace();
log.error("流程启动错误", e);
return AjaxResult.error("流程启动错误");
}
}

View File

@@ -113,7 +113,7 @@ public class FlowInstanceServiceImpl extends FlowServiceFactory implements IFlow
runtimeService.startProcessInstanceById(procDefId, variables);
return AjaxResult.success("流程启动成功");
} catch (Exception e) {
e.printStackTrace();
log.error("流程启动错误, procDefId: {}", procDefId, e);
return AjaxResult.error("流程启动错误");
}
}

View File

@@ -19,6 +19,8 @@ import com.core.generator.service.IGenTableColumnService;
import com.core.generator.service.IGenTableService;
import org.apache.commons.io.IOUtils;
import org.apache.poi.ss.usermodel.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
@@ -43,6 +45,8 @@ import java.util.Map;
@RestController
@RequestMapping("/tool/gen")
public class GenController extends BaseController {
private static final Logger log = LoggerFactory.getLogger(GenController.class);
@Autowired
private IGenTableService genTableService;
@@ -436,7 +440,7 @@ public class GenController extends BaseController {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath))) {
writer.write(str);
} catch (IOException e) {
e.printStackTrace();
log.error("写入文件失败: {}", filePath, e);
} finally {
is.close();
}

View File

@@ -6,6 +6,8 @@ import com.core.system.domain.SysUserConfig;
import com.core.common.utils.StringUtils;
import com.core.system.mapper.SysUserConfigMapper;
import com.core.system.service.ISysUserConfigService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -13,13 +15,15 @@ import java.util.List;
/**
* 用户配置Service业务层处理
*
* @author
*
* @author
* @date 2026-01-30
*/
@Service
public class SysUserConfigServiceImpl extends ServiceImpl<SysUserConfigMapper, SysUserConfig> implements ISysUserConfigService
{
private static final Logger log = LoggerFactory.getLogger(SysUserConfigServiceImpl.class);
@Autowired
private SysUserConfigMapper sysUserConfigMapper;
@@ -170,8 +174,7 @@ public class SysUserConfigServiceImpl extends ServiceImpl<SysUserConfigMapper, S
}
} catch (Exception e) {
// 记录错误日志以便调试
System.err.println("保存用户配置时发生错误: " + e.getMessage());
e.printStackTrace();
log.error("保存用户配置时发生错误, userId: {}, configKey: {}", userId, configKey, e);
throw e; // 重新抛出异常让上层处理
}
}

View File

@@ -120,7 +120,7 @@ public class CheckMethodAppServiceImpl implements ICheckMethodAppService {
// 导出到Excel
ExcelFillerUtil.makeExcelFile(response, list, headers, excelName, null);
} catch (IOException | IllegalAccessException e) {
e.printStackTrace();
log.error("导出Excel失败", e);
return R.fail("导出Excel失败" + e.getMessage());
}

View File

@@ -101,7 +101,7 @@ public class CheckPartAppServiceImpl implements ICheckPartAppService {
// 导出到Excel
ExcelFillerUtil.makeExcelFile(response, list, headers, excelName, null);
} catch (IOException | IllegalAccessException e) {
e.printStackTrace();
log.error("导出Excel失败", e);
return R.fail("导出Excel失败" + e.getMessage());
}
return R.ok(null, "导出Excel成功");

View File

@@ -42,6 +42,8 @@ import com.openhis.workflow.domain.DeviceDispense;
import com.openhis.workflow.domain.InventoryItem;
import com.openhis.workflow.service.IDeviceDispenseService;
import com.openhis.workflow.service.IInventoryItemService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -59,6 +61,8 @@ import java.util.stream.Collectors;
@Service
public class CommonServiceImpl implements ICommonService {
private static final Logger log = LoggerFactory.getLogger(CommonServiceImpl.class);
@Resource
private AssignSeqUtil assignSeqUtil;
@@ -410,7 +414,7 @@ public class CommonServiceImpl implements ICommonService {
try {
BeanUtils.copyProperties(contract, metadata);
} catch (Exception e) {
e.printStackTrace();
log.warn("Bean复制失败", e);
}
return metadata;
}).collect(Collectors.toList()));

View File

@@ -121,4 +121,13 @@ public interface IDiagTreatMAppService {
* @return 校验结果
*/
R<?> validateActivityEdit(Long activityId);
/**
* 批量设置划价标记
*
* @param ids 诊疗目录ID列表
* @param pricingFlag 划价标记1:允许, 0:不允许)
* @return 结果
*/
R<?> updatePricingFlag(List<Long> ids, Integer pricingFlag);
}

View File

@@ -626,6 +626,39 @@ public class DiagTreatMAppServiceImpl implements IDiagTreatMAppService {
return R.ok();
}
/**
* 批量设置划价标记
*
* @param ids 诊疗目录ID列表
* @param pricingFlag 划价标记1:允许, 0:不允许)
* @return 结果
*/
@Override
public R<?> updatePricingFlag(List<Long> ids, Integer pricingFlag) {
if (ids == null || ids.isEmpty()) {
return R.fail(null, "请选择要设置的诊疗项目");
}
List<ActivityDefinition> activityDefinitionList = new CopyOnWriteArrayList<>();
// 取得更新值
for (Long id : ids) {
ActivityDefinition activityDefinition = new ActivityDefinition();
activityDefinition.setId(id);
activityDefinition.setPricingFlag(pricingFlag);
activityDefinitionList.add(activityDefinition);
}
// 插入操作记录
operationRecordService.addIdsOperationRecord(DbOpType.UPDATE.getCode(),
CommonConstants.TableName.WOR_ACTIVITY_DEFINITION, ids);
// 更新诊疗信息
return activityDefinitionService.updateBatchById(activityDefinitionList)
? R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002, new Object[]{"划价标记"}))
: R.fail(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00007, null));
}
/**
* 导入信息校验
*

View File

@@ -176,4 +176,16 @@ public class DiagnosisTreatmentController {
public R<?> getClinicItems(@RequestParam(required = false) Long orgId) {
return diagTreatMAppService.getClinicItems(orgId);
}
/**
* 批量设置划价标记
*
* @param ids 诊疗目录ID列表
* @param pricingFlag 划价标记1:允许, 0:不允许)
* @return 结果
*/
@PutMapping("/pricing-flag")
public R<?> updatePricingFlag(@RequestBody List<Long> ids, @RequestParam Integer pricingFlag) {
return diagTreatMAppService.updatePricingFlag(ids, pricingFlag);
}
}

View File

@@ -25,6 +25,8 @@ import com.openhis.workflow.service.IActivityDefinitionService;
import com.openhis.workflow.service.IDeviceDispenseService;
import com.openhis.workflow.service.IDeviceRequestService;
import com.openhis.workflow.service.IServiceRequestService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@@ -40,6 +42,8 @@ import java.util.stream.Collectors;
@Component
public class AdviceUtils {
private static final Logger log = LoggerFactory.getLogger(AdviceUtils.class);
@Resource
AssignSeqUtil assignSeqUtil;
@@ -396,7 +400,7 @@ public class AdviceUtils {
iChargeItemService.updateById(mainChargeItem);
}
} catch (JsonProcessingException e) {
e.printStackTrace();
log.error("JSON处理失败", e);
}
}

View File

@@ -560,13 +560,13 @@ public class ThreePartPayServiceImpl implements ThreePartPayService {
System.out.println("回复信息:" + JSON.toJSONString(response));
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
e.printStackTrace();
log.error("Http请求异常, url: {}", url, e);
throw new ServiceException("Http请求异常请稍后再试。");
} finally {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
log.error("关闭响应失败", e);
}
}
return resultString;
@@ -596,13 +596,13 @@ public class ThreePartPayServiceImpl implements ThreePartPayService {
response = httpClient.execute(httpPost);
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
e.printStackTrace();
log.error("Http请求异常, url: {}", url, e);
throw new ServiceException("Http请求异常请稍后再试。");
} finally {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
log.error("关闭响应失败", e);
}
}
return resultString;

View File

@@ -7,6 +7,8 @@ import com.openhis.common.annotation.Dict;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -20,6 +22,8 @@ import java.util.List;
@Component
public class DictAspect {
private static final Logger log = LoggerFactory.getLogger(DictAspect.class);
@Autowired
private JdbcTemplate jdbcTemplate; // 使用 JdbcTemplate 执行 SQL
@@ -99,15 +103,15 @@ public class DictAspect {
// 查询字典值
String dictLabel = queryDictLabel(dictTable, dictCode, dictText, deleteFlag, fieldValue.toString());
if (dictLabel != null) {
// 动态生成 _dictText 字段名
String textFieldName = field.getName() + "_dictText";
try {
// 动态生成 _dictText 字段名
String textFieldName = field.getName() + "_dictText";
Field textField = dto.getClass().getDeclaredField(textFieldName);
textField.setAccessible(true);
textField.set(dto, dictLabel); // 设置 _dictText 字段的值
} catch (NoSuchFieldException e) {
// 如果 _dictText 字段不存在,忽略错误
e.printStackTrace();
log.debug("字段 {} 不存在,跳过字典翻译", textFieldName);
}
}
} else {

View File

@@ -5,6 +5,8 @@ import com.core.common.utils.DateUtils;
import com.core.common.utils.SecurityUtils;
import com.core.framework.config.TenantContext;
import com.openhis.common.constant.CommonConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Field;
@@ -21,6 +23,8 @@ import java.util.Map;
*/
public class HisQueryUtils {
private static final Logger log = LoggerFactory.getLogger(HisQueryUtils.class);
/**
* 条件查询构造器
*
@@ -72,7 +76,7 @@ public class HisQueryUtils {
queryWrapper.ge(dbFieldName, startDate); // 大于等于 STime
queryWrapper.le(dbFieldName, endDate); // 小于等于 ETime
} catch (ParseException e) {
e.printStackTrace();
log.warn("日期解析失败: startValue={}, endValue={}", startValue, endValue, e);
}
}
}
@@ -100,7 +104,7 @@ public class HisQueryUtils {
queryWrapper.eq(fieldName, value);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
log.warn("反射获取字段值失败: field={}", field.getName(), e);
}
}
currentClass = currentClass.getSuperclass();

View File

@@ -1,5 +1,7 @@
package com.openhis.common.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.*;
import org.springframework.stereotype.Component;
@@ -16,6 +18,8 @@ import java.util.concurrent.TimeUnit;
@Component
public class RedisUtil {
private static final Logger log = LoggerFactory.getLogger(RedisUtil.class);
@Autowired
private RedisTemplate<Object, Object> redisTemplate;
@Autowired
@@ -35,7 +39,7 @@ public class RedisUtil {
}
return true;
} catch (Exception e) {
e.printStackTrace();
log.error("Redis expire操作失败, key: {}", key, e);
return false;
}
}
@@ -60,7 +64,7 @@ public class RedisUtil {
try {
return redisTemplate.hasKey(key);
} catch (Exception e) {
e.printStackTrace();
log.error("Redis expire操作失败, key: {}", key, e);
return false;
}
}
@@ -104,7 +108,7 @@ public class RedisUtil {
redisTemplate.opsForValue().set(key, value);
return true;
} catch (Exception e) {
e.printStackTrace();
log.error("Redis expire操作失败, key: {}", key, e);
return false;
}
@@ -127,7 +131,7 @@ public class RedisUtil {
}
return true;
} catch (Exception e) {
e.printStackTrace();
log.error("Redis expire操作失败, key: {}", key, e);
return false;
}
}
@@ -194,7 +198,7 @@ public class RedisUtil {
redisTemplate.opsForHash().putAll(key, map);
return true;
} catch (Exception e) {
e.printStackTrace();
log.error("Redis expire操作失败, key: {}", key, e);
return false;
}
}
@@ -215,7 +219,7 @@ public class RedisUtil {
}
return true;
} catch (Exception e) {
e.printStackTrace();
log.error("Redis expire操作失败, key: {}", key, e);
return false;
}
}
@@ -233,7 +237,7 @@ public class RedisUtil {
redisTemplate.opsForHash().put(key, item, value);
return true;
} catch (Exception e) {
e.printStackTrace();
log.error("Redis expire操作失败, key: {}", key, e);
return false;
}
}
@@ -255,7 +259,7 @@ public class RedisUtil {
}
return true;
} catch (Exception e) {
e.printStackTrace();
log.error("Redis expire操作失败, key: {}", key, e);
return false;
}
}
@@ -316,7 +320,7 @@ public class RedisUtil {
try {
return redisTemplate.opsForSet().members(key);
} catch (Exception e) {
e.printStackTrace();
log.error("Redis操作失败, key: {}", key, e);
return null;
}
}
@@ -332,7 +336,7 @@ public class RedisUtil {
try {
return redisTemplate.opsForSet().isMember(key, value);
} catch (Exception e) {
e.printStackTrace();
log.error("Redis expire操作失败, key: {}", key, e);
return false;
}
}
@@ -348,7 +352,7 @@ public class RedisUtil {
try {
return redisTemplate.opsForSet().add(key, values);
} catch (Exception e) {
e.printStackTrace();
log.error("Redis操作失败, key: {}", key, e);
return 0;
}
}
@@ -369,7 +373,7 @@ public class RedisUtil {
}
return count;
} catch (Exception e) {
e.printStackTrace();
log.error("Redis操作失败, key: {}", key, e);
return 0;
}
}
@@ -384,7 +388,7 @@ public class RedisUtil {
try {
return redisTemplate.opsForSet().size(key);
} catch (Exception e) {
e.printStackTrace();
log.error("Redis操作失败, key: {}", key, e);
return 0;
}
}
@@ -401,7 +405,7 @@ public class RedisUtil {
Long count = redisTemplate.opsForSet().remove(key, values);
return count;
} catch (Exception e) {
e.printStackTrace();
log.error("Redis操作失败, key: {}", key, e);
return 0;
}
}
@@ -419,7 +423,7 @@ public class RedisUtil {
try {
return redisTemplate.opsForList().range(key, start, end);
} catch (Exception e) {
e.printStackTrace();
log.error("Redis操作失败, key: {}", key, e);
return null;
}
}
@@ -434,7 +438,7 @@ public class RedisUtil {
try {
return redisTemplate.opsForList().size(key);
} catch (Exception e) {
e.printStackTrace();
log.error("Redis操作失败, key: {}", key, e);
return 0;
}
}
@@ -450,7 +454,7 @@ public class RedisUtil {
try {
return redisTemplate.opsForList().index(key, index);
} catch (Exception e) {
e.printStackTrace();
log.error("Redis操作失败, key: {}", key, e);
return null;
}
}
@@ -468,7 +472,7 @@ public class RedisUtil {
redisTemplate.opsForList().rightPush(key, value);
return true;
} catch (Exception e) {
e.printStackTrace();
log.error("Redis expire操作失败, key: {}", key, e);
return false;
}
}
@@ -489,7 +493,7 @@ public class RedisUtil {
}
return true;
} catch (Exception e) {
e.printStackTrace();
log.error("Redis expire操作失败, key: {}", key, e);
return false;
}
}
@@ -507,7 +511,7 @@ public class RedisUtil {
redisTemplate.opsForList().rightPushAll(key, value);
return true;
} catch (Exception e) {
e.printStackTrace();
log.error("Redis expire操作失败, key: {}", key, e);
return false;
}
}
@@ -528,7 +532,7 @@ public class RedisUtil {
}
return true;
} catch (Exception e) {
e.printStackTrace();
log.error("Redis expire操作失败, key: {}", key, e);
return false;
}
}
@@ -546,7 +550,7 @@ public class RedisUtil {
redisTemplate.opsForList().set(key, index, value);
return true;
} catch (Exception e) {
e.printStackTrace();
log.error("Redis expire操作失败, key: {}", key, e);
return false;
}
}
@@ -564,7 +568,7 @@ public class RedisUtil {
Long remove = redisTemplate.opsForList().remove(key, count, value);
return remove;
} catch (Exception e) {
e.printStackTrace();
log.error("Redis操作失败, key: {}", key, e);
return 0;
}
}
@@ -590,7 +594,7 @@ public class RedisUtil {
return binaryKeys;
});
} catch (Throwable e) {
e.printStackTrace();
log.error("Redis scan操作失败, keyPrefix: {}", keyPrefix, e);
}
return null;
@@ -605,7 +609,7 @@ public class RedisUtil {
Set<String> keys = keys(keyPrefix);
redisTemplate.delete(keys);
} catch (Throwable e) {
e.printStackTrace();
log.error("Redis删除操作失败, keyPrefix: {}", keyPrefix, e);
}
}