diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java index a728365e6..c62156025 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java @@ -102,6 +102,18 @@ public class LambdaQueryWrapperX extends LambdaQueryWrapper { // ========== 重写父类方法,方便链式调用 ========== + @Override + public LambdaQueryWrapperX isNull(boolean condition, SFunction column) { + super.isNull(condition, column); + return this; + } + + @Override + public LambdaQueryWrapperX isNotNull(boolean condition, SFunction column) { + super.isNotNull(condition, column); + return this; + } + @Override public LambdaQueryWrapperX eq(boolean condition, SFunction column, Object val) { super.eq(condition, column, val); diff --git a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/reporttemplate/ReporttemplateController.java b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/reporttemplate/ReporttemplateController.java index c24f33bb8..30f8c1d9d 100644 --- a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/reporttemplate/ReporttemplateController.java +++ b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/reporttemplate/ReporttemplateController.java @@ -71,16 +71,30 @@ public class ReporttemplateController { @GetMapping("/getlist") @Operation(summary = "获得诊断模板list") @PreAuthorize("@ss.hasPermission('system:reporttemplate:query')") - public CommonResult> getReporttemplateList() { - List reporttemplates = reporttemplateService.getReporttemplatelist(); + public CommonResult> getReporttemplateList(@Valid ReporttemplatePageReqVO pageReqVO) { + List reporttemplates = Collections.emptyList(); + PageResult pageResult = null; + try { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + pageResult = reporttemplateService.getReporttemplatePage(pageReqVO); + } catch (Exception ex) { + pageResult = null; + } + if (pageResult != null) + reporttemplates = pageResult.getList(); return success(reporttemplates); } @GetMapping("/page") @Operation(summary = "获得诊断模板分页") @PreAuthorize("@ss.hasPermission('system:reporttemplate:query')") - public CommonResult> getReporttemplatePage(@Valid ReporttemplatePageReqVO pageReqVO) { - PageResult pageResult = reporttemplateService.getReporttemplatePage(pageReqVO); + public CommonResult> getReporttemplatePage(@Valid ReporttemplatePageReqVO pageReqVO) { + PageResult pageResult = null; + try { + pageResult = reporttemplateService.getReporttemplatePage(pageReqVO); + } catch (Exception ex) { + pageResult = new PageResult<>(Collections.emptyList(), Long.valueOf(0)); + } return success(pageResult); } diff --git a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/reporttemplate/vo/ReporttemplatePageReqVO.java b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/reporttemplate/vo/ReporttemplatePageReqVO.java index 0a2406c55..a44d725d7 100644 --- a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/reporttemplate/vo/ReporttemplatePageReqVO.java +++ b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/reporttemplate/vo/ReporttemplatePageReqVO.java @@ -19,7 +19,7 @@ public class ReporttemplatePageReqVO extends PageParam { @Schema(description = "模板名称", example = "李四") private String templateName; - @Schema(description = "模板权限:all,private,public", example = "2") + @Schema(description = "模板权限:全部(0),公有(1),私有(2)", example = "0") private String templateLimitsType; @Schema(description = "机构ID", example = "2935") diff --git a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/reporttemplate/vo/ReporttemplateSaveReqVO.java b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/reporttemplate/vo/ReporttemplateSaveReqVO.java index 00233319b..b4c935ce1 100644 --- a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/reporttemplate/vo/ReporttemplateSaveReqVO.java +++ b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/reporttemplate/vo/ReporttemplateSaveReqVO.java @@ -14,6 +14,9 @@ public class ReporttemplateSaveReqVO { @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "17893") private String id; + @Schema(description = "数据类型:0诊断模板、1节点") + private String dataType; + @Schema(description = "下拉框:体检模板,住院模板,门诊模板", example = "2") private String templateType; diff --git a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/dal/reporttemplate/ReporttemplateDO.java b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/dal/reporttemplate/ReporttemplateDO.java index adbb325dc..519d245d6 100644 --- a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/dal/reporttemplate/ReporttemplateDO.java +++ b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/dal/reporttemplate/ReporttemplateDO.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.ultrasoniccom.dal.reporttemplate; import lombok.*; import com.baomidou.mybatisplus.annotation.*; + import java.util.*; import java.time.*; @@ -22,7 +23,7 @@ public class ReporttemplateDO { /** * 主键 */ - @TableId(value="ID",type = IdType.INPUT) + @TableId(value = "ID", type = IdType.INPUT) private String id; /** * 父类ID @@ -34,6 +35,11 @@ public class ReporttemplateDO { */ @TableField("orgId") private String orgId; + /** + * 数据类型:0诊断模板、1节点 + */ + @TableField("dataType") + private String dataType; /** * 下拉框:体检模板,住院模板,门诊模板 */ @@ -69,6 +75,11 @@ public class ReporttemplateDO { */ @TableField("diagResults") private String diagResults; + /** + * 模板使用的时间 + */ + @TableField("updateTime") + private LocalDateTime updateTime; /** * 创建人 */ diff --git a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/dal/reporttemplate/ReporttemplateMapper.java b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/dal/reporttemplate/ReporttemplateMapper.java index 2d9dc3501..5aababb5e 100644 --- a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/dal/reporttemplate/ReporttemplateMapper.java +++ b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/dal/reporttemplate/ReporttemplateMapper.java @@ -3,8 +3,11 @@ package cn.iocoder.yudao.module.ultrasoniccom.dal.reporttemplate; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.ultrasoniccom.controller.admin.reporttemplate.vo.*; import com.baomidou.mybatisplus.annotation.InterceptorIgnore; +import com.baomidou.mybatisplus.core.conditions.Wrapper; import org.apache.ibatis.annotations.Mapper; + import java.util.*; /** @@ -16,4 +19,31 @@ import java.util.*; @Mapper public interface ReporttemplateMapper extends BaseMapperX { + //查询 + default List selectList(String pid, String orgId) { + return selectList(new LambdaQueryWrapperX() + .neIfPresent(ReporttemplateDO::getIsdelete, '1') + .eq(ReporttemplateDO::getPid, pid) + .eqIfPresent(ReporttemplateDO::getOrgId, orgId) + .orderByAsc(ReporttemplateDO::getTemplateName)); + } + + default List selectNodes(ReporttemplatePageReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .neIfPresent(ReporttemplateDO::getIsdelete, '1') + .eq(ReporttemplateDO::getOrgId, reqVO.getOrgId()) + .likeIfPresent(ReporttemplateDO::getTemplateName, reqVO.getTemplateName()) + .isNull(reqVO.getTemplateLimitsType() != null && reqVO.getTemplateLimitsType().trim().equals("1"), + ReporttemplateDO::getPrivateDoctorId) + .isNotNull(reqVO.getTemplateLimitsType() != null && reqVO.getTemplateLimitsType().trim().equals("2"), + ReporttemplateDO::getPrivateDoctorId) + .orderByAsc(ReporttemplateDO::getTemplateName)); + } + + default List selectNodes(String orgId) { + return selectList(new LambdaQueryWrapperX() + .neIfPresent(ReporttemplateDO::getIsdelete, '1') + .eq(ReporttemplateDO::getOrgId, orgId) + .orderByAsc(ReporttemplateDO::getTemplateName)); + } } \ No newline at end of file diff --git a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/service/reporttemplate/ReporttemplateService.java b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/service/reporttemplate/ReporttemplateService.java index af08d5c7a..fd36491b9 100644 --- a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/service/reporttemplate/ReporttemplateService.java +++ b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/service/reporttemplate/ReporttemplateService.java @@ -25,11 +25,8 @@ public interface ReporttemplateService { //查询方法 ReporttemplateDO getReporttemplate(String id); - List getReporttemplatelist(String orgId); + PageResult getReporttemplatePage(ReporttemplatePageReqVO pageReqVO); - PageResult getReporttemplatePage(ReporttemplatePageReqVO pageReqVO); - - //临时方法 - List getReporttemplatelist(); + List getReporttemplatelist(); } \ No newline at end of file diff --git a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/service/reporttemplate/ReporttemplateServiceImpl.java b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/service/reporttemplate/ReporttemplateServiceImpl.java index d7336aa46..4e453ed62 100644 --- a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/service/reporttemplate/ReporttemplateServiceImpl.java +++ b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/service/reporttemplate/ReporttemplateServiceImpl.java @@ -10,12 +10,15 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; import org.springframework.validation.annotation.Validated; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.annotation.Resource; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -43,7 +46,7 @@ public class ReporttemplateServiceImpl implements ReporttemplateService { //当前登陆用户 AdminUserDO user = userService.getUser(getLoginUserId()); //当前时间 - LocalDateTime dateTime= LocalDateTime.parse( + LocalDateTime dateTime = LocalDateTime.parse( LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") ); @@ -65,9 +68,17 @@ public class ReporttemplateServiceImpl implements ReporttemplateService { public void updateReporttemplate(ReporttemplateSaveReqVO updateReqVO) { //校验存在 validateExists(updateReqVO.getId()); + ReporttemplateDO tempDO = getReporttemplate(updateReqVO.getId()); + //VO转DO ReporttemplateDO reporttemplateDO = BeanUtils.toBean(updateReqVO, ReporttemplateDO.class); + if (tempDO != null && reporttemplateDO != null) { + reporttemplateDO.setCreateDate(tempDO.getCreateDate()); + reporttemplateDO.setCreatePerson(tempDO.getCreatePerson()); + reporttemplateDO.setIsdelete(tempDO.getIsdelete()); + } + reporttemplateMapper.updateById(reporttemplateDO); } @@ -78,14 +89,13 @@ public class ReporttemplateServiceImpl implements ReporttemplateService { //当前登陆用户 AdminUserDO user = userService.getUser(getLoginUserId()); //当前时间 - LocalDateTime dateTime= LocalDateTime.parse( + LocalDateTime dateTime = LocalDateTime.parse( LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") ); //创建DO - ReporttemplateDO reporttemplateDO=new ReporttemplateDO(); + ReporttemplateDO reporttemplateDO = getReporttemplate(id); - reporttemplateDO.setId(id); reporttemplateDO.setDeleteDate(dateTime); reporttemplateDO.setDeletePerson(user.getUsername()); reporttemplateDO.setIsdelete("1"); @@ -99,27 +109,160 @@ public class ReporttemplateServiceImpl implements ReporttemplateService { } @Override - public List getReporttemplatelist(String orgId) { - return null; + public PageResult getReporttemplatePage(ReporttemplatePageReqVO pageReqVO) { + List _viewPage = Collections.emptyList(); + List _view = null; + + //当前登陆用户 + AdminUserDO user = userService.getUser(getLoginUserId()); + pageReqVO.setOrgId(user.getOrgId()); + //全部数据(缓存) + List _tempAll = reporttemplateMapper.selectNodes(user.getOrgId()); + List _tempVAll = null; + //直接符合的叶和根 + List _temp = reporttemplateMapper.selectNodes(pageReqVO); + List _tempV = null; + //经推导符合的根 + List _tempOther = null; + List _tempVOther = null; + + if (_temp != null && _temp.size() > 0) { + //计算_tempOther + ReporttemplateDO _tempDO = null; + ReporttemplateDO _tempDO2 = null; + boolean doNext = true; + _tempOther = new ArrayList<>(); + for (ReporttemplateDO item : _temp) { + _tempDO = item; + doNext = true; + while (doNext) { + _tempDO2 = null; + final String pid = _tempDO.getPid(); + _tempDO = _tempAll.stream().filter(it -> it.getId() != null && pid != null && !pid.trim().equals("0") && it.getId().equals(pid)) + .findFirst().orElse(null); + if (_tempDO == null || _tempDO.getId() == null || _tempDO.getPid() == null) + doNext = false; + else { + final String id = _tempDO.getId(); + _tempDO2 = _temp.stream().filter(it -> it.getId() != null && it.getId().equals(id)) + .findFirst().orElse(null); + if (_tempDO2 != null) + doNext = false; + else if (_tempOther.contains(_tempDO)) + doNext = false; + else { + _tempOther.add(_tempDO); + if (_tempDO.getPid().trim().equals("0")) + doNext = false; + } + } + } + } + //计算_tempV + if (!(pageReqVO.getTemplateLimitsType() != null && (pageReqVO.getTemplateLimitsType().trim().equals("1") || pageReqVO.getTemplateLimitsType().trim().equals("2"))) && + !StringUtils.hasText(pageReqVO.getTemplateName())) { + //判断查询条件优化渲染速度 + _tempV = treeViewBuild(null, "0", user.getOrgId()); + _tempVOther = new ArrayList<>(); + } else { + _tempV = BeanUtils.toBean(_temp, ReporttemplateTreeView.class); + for (ReporttemplateTreeView item : _tempV) { + if (item != null && item.getDataType() != null && item.getDataType().trim().equals("1")) + treeViewBuild(item, item.getId(), item.getOrgId()); + } + _tempVOther = BeanUtils.toBean(_tempOther, ReporttemplateTreeView.class); + } + _tempVAll = Stream.concat(_tempV.stream(), _tempVOther.stream()) + .distinct().collect(Collectors.toList()); + //计算_view + _view = _tempVAll.stream().filter(it -> it.getId() != null && it.getPid() != null && it.getPid().trim().equals("0")) + .sorted(Comparator.comparing(ReporttemplateTreeView::getTemplateName)).collect(Collectors.toList()); + if (_view != null && _view.size() > 0) { + for (ReporttemplateTreeView item : _view) { + if (item != null && item.getDataType() != null && item.getDataType().trim().equals("1")) + treeViewBuild(item, item.getId(), _tempVAll); + } + } else + _view = null; + } + //结果 + if (_view != null && _view.size() > 0) { + if (!PageParam.PAGE_SIZE_NONE.equals(pageReqVO.getPageSize())) { + int index_start = (pageReqVO.getPageNo() - 1) * pageReqVO.getPageSize(); + int index_end = pageReqVO.getPageNo() * pageReqVO.getPageSize() - 1; + if (_view.size() - 1 >= index_start) { + if (_view.size() - 1 < index_end) + index_end = _view.size() - 1; + _viewPage = _view.subList(index_start, index_end + 1); + } + } else { + _viewPage = _view; + } + } + return new PageResult<>(_viewPage, Long.valueOf(_view == null ? 0 : _view.size())); } @Override - public PageResult getReporttemplatePage(ReporttemplatePageReqVO pageReqVO) { - return reporttemplateMapper.selectPage(pageReqVO, new LambdaQueryWrapperX() - .likeIfPresent(ReporttemplateDO::getTemplateName, pageReqVO.getTemplateName()) - .eq(ReporttemplateDO::getIsdelete, '0')); + public List getReporttemplatelist() { + List _out = null; + + //当前登陆用户 + AdminUserDO user = userService.getUser(getLoginUserId()); + + _out = treeViewBuild(null, "0", user.getOrgId()); + + if (!(_out != null && _out.size() > 0)) + _out = Collections.emptyList(); + return _out; } //其它方法 private void validateExists(String id) { if (reporttemplateMapper.selectById(id) == null) { - throw exception(new ErrorCode(1,"ID为空")); + throw exception(new ErrorCode(1, "ID为空")); } } - //临时方法 - @Override - public List getReporttemplatelist() { - return reporttemplateMapper.selectList(); + private List treeViewBuild(ReporttemplateTreeView view, String pid, List source) { + List _out = null; + + if (view != null && view.children != null) + return view.children; + + if (source != null && source.size() > 0) + _out = source.stream().filter(it -> it.getId() != null && it.getPid() != null && it.getPid().trim().equals(pid)) + .sorted(Comparator.comparing(ReporttemplateTreeView::getTemplateName)).collect(Collectors.toList()); + if (_out != null && _out.size() > 0) { + if (view != null) + view.children = _out; + for (ReporttemplateTreeView item : _out) { + if (item != null && item.getDataType() != null && item.getDataType().trim().equals("1") && item.children == null) + treeViewBuild(item, item.getId(), source); + } + } + + if (!(_out != null && _out.size() > 0)) + _out = null; + return _out; + } + + private List treeViewBuild(ReporttemplateTreeView view, String pid, String orgId) { + List _out = null; + List _temp = null; + + _temp = reporttemplateMapper.selectList(pid, orgId); + if (_temp != null && _temp.size() > 0) { + _out = BeanUtils.toBean(_temp, ReporttemplateTreeView.class); + if (view != null) + view.children = _out; + for (ReporttemplateTreeView item : _out) { + if (item != null && item.getDataType() != null && item.getDataType().trim().equals("1")) + treeViewBuild(item, item.getId(), item.getOrgId()); + } + } + + if (!(_out != null && _out.size() > 0)) + _out = null; + return _out; } } \ No newline at end of file diff --git a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/service/reporttemplate/ReporttemplateTreeView.java b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/service/reporttemplate/ReporttemplateTreeView.java new file mode 100644 index 000000000..8e08bd629 --- /dev/null +++ b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/service/reporttemplate/ReporttemplateTreeView.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.module.ultrasoniccom.service.reporttemplate; + +import lombok.*; +import java.time.*; +import java.util.*; + +@Data +public class ReporttemplateTreeView { + + public List children; + + private String id; + private String pid; + private String orgId; + private String dataType; + private String templateName; + private String examDescription; + private String diagResults; + private String privateDoctorId; + + private String templateType; + private String examPartCode; + private String examPart; + private LocalDateTime updateTime; + + private LocalDateTime createDate; + private String createPerson; + private String isdelete; + private LocalDateTime deleteDate; + private String deletePerson; + +}