需求文档.md 7.8 KB

页面一开始

  • 向后端发送网络请求

    • 后端接口对应代码为:

      @Validated
      @RequiredArgsConstructor
      @RestController
      @RequestMapping("/total/patient")
      public class HistoryPatientController {
          
      private final TotalPatientService totalPatientService;
          
      @GetMapping("/list")
      public TableDataInfo<TotalPatientVo> listPage(TotalPatientBo bo, PageQuery pageQuery) {
          return totalPatientService.listPage(bo, pageQuery);
      }
          
      }
      
    • TotalPatientBo:

      @Data
      public class TotalPatientBo {
          
      private Integer type;
          
      private Integer sex;
          
      private String medicalId;
          
      private Date updateTimeEarliest;
          
      private Date updateTimeLatest;
          
      }
      
    • PageQuery:

      @Data
      public class PageQuery implements Serializable {
          
      @Serial
      private static final long serialVersionUID = 1L;
          
      /**
       * 分页大小
       */
      private Integer pageSize;
          
      /**
       * 当前页数
       */
      private Integer pageNum;
          
      /**
       * 排序列
       */
      private String orderByColumn;
          
      /**
       * 排序的方向desc或者asc
       */
      private String isAsc;
          
      /**
       * 当前记录起始索引 默认值
       */
      public static final int DEFAULT_PAGE_NUM = 1;
          
      /**
       * 每页显示记录数 默认值 默认查全部
       */
      public static final int DEFAULT_PAGE_SIZE = Integer.MAX_VALUE;
          
      /**
       * 构建分页对象
       */
      public <T> Page<T> build() {
          Integer pageNum = ObjectUtil.defaultIfNull(getPageNum(), DEFAULT_PAGE_NUM);
          Integer pageSize = ObjectUtil.defaultIfNull(getPageSize(), DEFAULT_PAGE_SIZE);
          if (pageNum <= 0) {
              pageNum = DEFAULT_PAGE_NUM;
          }
          Page<T> page = new Page<>(pageNum, pageSize);
          List<OrderItem> orderItems = buildOrderItem();
          if (CollUtil.isNotEmpty(orderItems)) {
              page.addOrder(orderItems);
          }
          return page;
      }
          
      /**
       * 构建排序
       *
       * 支持的用法如下:
       * {isAsc:"asc",orderByColumn:"id"} order by id asc
       * {isAsc:"asc",orderByColumn:"id,createTime"} order by id asc,create_time asc
       * {isAsc:"desc",orderByColumn:"id,createTime"} order by id desc,create_time desc
       * {isAsc:"asc,desc",orderByColumn:"id,createTime"} order by id asc,create_time desc
       */
      private List<OrderItem> buildOrderItem() {
          if (StringUtils.isBlank(orderByColumn) || StringUtils.isBlank(isAsc)) {
              return null;
          }
          String orderBy = SqlUtil.escapeOrderBySql(orderByColumn);
          orderBy = StringUtils.toUnderScoreCase(orderBy);
          
          // 兼容前端排序类型
          isAsc = StringUtils.replaceEach(isAsc, new String[]{"ascending", "descending"}, new String[]{"asc", "desc"});
          
          String[] orderByArr = orderBy.split(StringUtils.SEPARATOR);
          String[] isAscArr = isAsc.split(StringUtils.SEPARATOR);
          if (isAscArr.length != 1 && isAscArr.length != orderByArr.length) {
              throw new ServiceException("排序参数有误");
          }
          
          List<OrderItem> list = new ArrayList<>();
          // 每个字段各自排序
          for (int i = 0; i < orderByArr.length; i++) {
              String orderByStr = orderByArr[i];
              String isAscStr = isAscArr.length == 1 ? isAscArr[0] : isAscArr[i];
              if ("asc".equals(isAscStr)) {
                  list.add(OrderItem.asc(orderByStr));
              } else if ("desc".equals(isAscStr)) {
                  list.add(OrderItem.desc(orderByStr));
              } else {
                  throw new ServiceException("排序参数有误");
              }
          }
          return list;
      }
          
      @JsonIgnore
      public Integer getFirstNum() {
          return (pageNum - 1) * pageSize;
      }
          
      public PageQuery(Integer pageSize, Integer pageNum) {
          this.pageSize = pageSize;
          this.pageNum = pageNum;
      }
          
      }
      
    • TableDataInfo:

      @Data
      @NoArgsConstructor
      public class TableDataInfo<T> implements Serializable {
          
      @Serial
      private static final long serialVersionUID = 1L;
          
      /**
       * 总记录数
       */
      private long total;
          
      /**
       * 列表数据
       */
      private List<T> rows;
          
      /**
       * 消息状态码
       */
      private int code;
          
      /**
       * 消息内容
       */
      private String msg;
          
      /**
       * 分页
       *
       * @param list  列表数据
       * @param total 总记录数
       */
      public TableDataInfo(List<T> list, long total) {
          this.rows = list;
          this.total = total;
          this.code = HttpStatus.HTTP_OK;
          this.msg = "查询成功";
      }
          
      /**
       * 根据分页对象构建表格分页数据对象
       */
      public static <T> TableDataInfo<T> build(IPage<T> page) {
          TableDataInfo<T> rspData = new TableDataInfo<>();
          rspData.setCode(HttpStatus.HTTP_OK);
          rspData.setMsg("查询成功");
          rspData.setRows(page.getRecords());
          rspData.setTotal(page.getTotal());
          return rspData;
      }
          
      /**
       * 根据数据列表构建表格分页数据对象
       */
      public static <T> TableDataInfo<T> build(List<T> list) {
          TableDataInfo<T> rspData = new TableDataInfo<>();
          rspData.setCode(HttpStatus.HTTP_OK);
          rspData.setMsg("查询成功");
          rspData.setRows(list);
          rspData.setTotal(list.size());
          return rspData;
      }
          
      /**
       * 构建表格分页数据对象
       */
      public static <T> TableDataInfo<T> build() {
          TableDataInfo<T> rspData = new TableDataInfo<>();
          rspData.setCode(HttpStatus.HTTP_OK);
          rspData.setMsg("查询成功");
          return rspData;
      }
          
      /**
       * 根据原始数据列表和分页参数,构建表格分页数据对象(用于假分页)
       *
       * @param list 原始数据列表(全部数据)
       * @param page 分页参数对象(包含当前页码、每页大小等)
       * @return 构造好的分页结果 TableDataInfo<T>
       */
      public static <T> TableDataInfo<T> build(List<T> list, IPage<T> page) {
          if (CollUtil.isEmpty(list)) {
              return TableDataInfo.build();
          }
          List<T> pageList = CollUtil.page((int) page.getCurrent() - 1, (int) page.getSize(), list);
          return new TableDataInfo<>(pageList, list.size());
      }
          
      }
      
    • TotalPatientVo:

      @Data
      public class TotalPatientVo {
          
      private Long id;
          
      private Date updateTime;
          
      private String name;
          
      private String type;
          
      private String sex;
          
      private String age;
          
      private String idCard;
          
      private String medicalId;
          
      private Date appointmentTime;
          
      private String phoneNumber;
          
      private String principleAction;
          
      private String presentIllnessHistory;
          
      private String previousHistory;
          
      private String diagnose;
          
      }
      
  • 将后端返回的数据放入列表当中,为空的话则默认"--"