Browse Source

修改sql查询方式

longhu 6 ngày trước cách đây
mục cha
commit
487c2e5f35

+ 0 - 1
src/main/java/com/hr/InterfacePlatformApplication.java

@@ -19,7 +19,6 @@ public class InterfacePlatformApplication
 {
     public static void main(String[] args)
     {
-
         SpringApplication.run(InterfacePlatformApplication.class, args);
         log.info("(♥◠‿◠)ノ゙  测试环境启动成功   ლ(´ڡ`ლ)゙  \n" );
     }

+ 3 - 2
src/main/java/com/hr/controller/IpInterfaceController.java

@@ -1,5 +1,6 @@
 package com.hr.controller;
 
+import com.github.pagehelper.PageInfo;
 import com.hr.param.AccountInterfaceParam;
 import com.hr.param.InterfaceConfigParam;
 import com.hr.param.IpInterfaceParam;
@@ -43,8 +44,8 @@ public class IpInterfaceController {
     @Operation(summary = "分页查询")
     @GetMapping("/list")
     public BasePageResult<IpInterfaceVO> paginQuery(IpInterfaceParam ipInterfaceParam){
-        Page<IpInterfaceVO> ipAccountPOS = ipInterfaceService.paginQuery(ipInterfaceParam, ipInterfaceParam.getPageNum(), ipInterfaceParam.getPageSize());
-        return BasePageResult.success(ipAccountPOS.getContent(), ipAccountPOS.getTotalElements(), ipInterfaceParam.getPageNum(), ipInterfaceParam.getPageSize());
+        PageInfo<IpInterfaceVO> ipAccountPOS = ipInterfaceService.paginQuery(ipInterfaceParam, ipInterfaceParam.getPageNum(), ipInterfaceParam.getPageSize());
+        return BasePageResult.success(ipAccountPOS.getList(), ipAccountPOS.getTotal(), ipInterfaceParam.getPageNum(), ipInterfaceParam.getPageSize());
     }
     
     /** 

+ 4 - 0
src/main/java/com/hr/param/IpInterfaceParam.java

@@ -10,7 +10,9 @@ import org.hibernate.query.Page;
 
 import java.io.Serializable;
 import java.time.LocalDateTime;
+import java.util.Arrays;
 import java.util.Date;
+import java.util.List;
 
 /**
  * 接口表;IpInterface数据表的PO对象
@@ -48,4 +50,6 @@ public class IpInterfaceParam extends PageParam {
     @Schema(description = "更新人姓名")
     private String updateUserName;
 
+    private List<String> statusList = Arrays.asList("normal", "disable");
+
 }

+ 6 - 0
src/main/java/com/hr/repository/jpa/IpInterfaceRepository.java

@@ -1,6 +1,10 @@
 package com.hr.repository.jpa;
 
+import com.hr.param.IpInterfaceParam;
 import com.hr.repository.domain.IpInterfacePO;
+import com.hr.vo.IpInterfaceVO;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.data.domain.Page;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 
@@ -17,4 +21,6 @@ public interface IpInterfaceRepository extends JpaRepository<IpInterfacePO,Long>
 
     IpInterfacePO findByInterfaceName(String interfaceName);
     IpInterfacePO findByInterfaceNo(String interfaceNo);
+
+    List<IpInterfaceVO> queryPage(IpInterfaceParam interfaceParam);
 }

+ 2 - 1
src/main/java/com/hr/service/IpInterfaceService.java

@@ -1,5 +1,6 @@
 package com.hr.service;
 
+import com.github.pagehelper.PageInfo;
 import com.hr.param.InterfaceConfigParam;
 import com.hr.param.IpInterfaceParam;
 import com.hr.param.SwitchStatusParam;
@@ -33,7 +34,7 @@ public interface IpInterfaceService{
      * @param size  每页大小
      * @return
      */
-    Page<IpInterfaceVO> paginQuery(IpInterfaceParam interfaceParam, Integer current, Integer size);
+    PageInfo<IpInterfaceVO> paginQuery(IpInterfaceParam interfaceParam, Integer current, Integer size);
     /** 
      * 新增数据
      *

+ 11 - 19
src/main/java/com/hr/service/impl/IpInterfaceServiceImpl.java

@@ -1,5 +1,7 @@
 package com.hr.service.impl;
 
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
 import com.hr.param.InterfaceConfigParam;
@@ -12,6 +14,7 @@ import com.hr.util.SnowflakeIdWorker;
 import com.hr.vo.IpAccountVO;
 import com.hr.vo.IpInterfaceVO;
 import com.hr.vo.NameValueVO;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.*;
@@ -20,6 +23,7 @@ import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Optional;
 import java.util.concurrent.TimeUnit;
@@ -60,25 +64,13 @@ public class IpInterfaceServiceImpl implements IpInterfaceService {
     }
 
      @Override
-     public Page<IpInterfaceVO> paginQuery(IpInterfaceParam interfaceParam, Integer current, Integer size) {
-         IpInterfacePO ipInterfacePO = new IpInterfacePO();
-         BeanUtils.copyProperties(interfaceParam, ipInterfacePO);
-         ExampleMatcher matcher = ExampleMatcher.matchingAll()
-                 .withIgnoreNullValues()                              // 忽略 null 字段
-                 .withIgnoreCase();
-         Pageable pageAble = PageRequest.of(current - 1 , size);
-         Example<IpInterfacePO> example = Example.of(ipInterfacePO, matcher);
-         Page<IpInterfacePO> page = ipInterfaceRepository.findAll(example, pageAble);
-         List<IpInterfaceVO> resultList = new ArrayList<>();
-
-         page.getContent().forEach(item -> {
-             IpInterfaceVO vo = new IpInterfaceVO();
-             BeanUtils.copyProperties(item, vo);
-             resultList.add(vo);
-         });
-         Page<IpInterfaceVO> resultPage = new PageImpl(resultList);
-         BeanUtils.copyProperties(page, resultPage);
-         return resultPage;
+     public PageInfo<IpInterfaceVO> paginQuery(IpInterfaceParam interfaceParam, Integer current, Integer size) {
+         PageHelper.startPage(interfaceParam.getPageNum(), interfaceParam.getPageSize());
+         if (StringUtils.isNotEmpty(interfaceParam.getStatus())) {
+             interfaceParam.setStatusList(Arrays.asList(interfaceParam.getStatus()));
+         }
+         List<IpInterfaceVO> dbList = ipInterfaceRepository.queryPage(interfaceParam);
+         return PageInfo.of(dbList);
      }
 
      /**

+ 27 - 0
src/main/resources/mapper/IpInterfaceMapper.xml

@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+		PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+		"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.hr.repository.jpa.IpInterfaceRepository">
+
+
+<!--    <select id="queryByBusinessNo" resultType="com.hr.repository.domain.IpOrderPO">-->
+<!--        select * from ip_order where 1=1 and  business_no = :businessNo-->
+<!--    </select>-->
+    <select id="queryCallbackHistory" resultType="com.hr.vo.CallbackHistoryVO">
+        select ord.id,
+               ord.callback_url callbackUrl,
+               log.request_param requsetParam,
+               log.response_result responseParam,
+               ord.status callbackStatus,
+               ord.add_time addTime,
+               ord.update_time updateTime
+        from ip_order ord
+        left join ip_log log on ord.id = log.oid
+        where 1 = 1 and ord.ref_id = :id
+    </select>
+    <select id="queryPage" resultType="com.hr.vo.IpInterfaceVO">
+        select * from ip_interface where 1=1 and interface_name like '%'||:interfaceName||'%'
+        and status in (:statusList)
+    </select>
+</mapper>