Commit 15ab7751 by huluobin

费用系统的批量搜索

parent 09950487
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
<org.apache.poi>3.9</org.apache.poi> <org.apache.poi>3.9</org.apache.poi>
<commons.fileupload>1.3.1</commons.fileupload> <commons.fileupload>1.3.1</commons.fileupload>
<commons.io>2.4</commons.io> <commons.io>2.4</commons.io>
<commons-lang3.verson>3.10</commons-lang3.verson>
</properties> </properties>
<dependencies> <dependencies>
...@@ -172,6 +173,20 @@ ...@@ -172,6 +173,20 @@
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
<version>${commons.io}</version> <version>${commons.io}</version>
</dependency> </dependency>
<!--apache lang 工具包-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.verson}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>
<!-- POI end--> <!-- POI end-->
<dependency> <dependency>
......
...@@ -3,7 +3,6 @@ package com.blt.other.other_cost.controller; ...@@ -3,7 +3,6 @@ package com.blt.other.other_cost.controller;
import com.blt.other.other_commons.utils.AxiosUtil; import com.blt.other.other_commons.utils.AxiosUtil;
import com.blt.other.other_commons.utils.MyMapperUtil; import com.blt.other.other_commons.utils.MyMapperUtil;
import com.blt.other.other_cost.service.CostListSearchService; import com.blt.other.other_cost.service.CostListSearchService;
import com.blt.other.other_cost.service.CostService;
import com.blt.other.other_cost.vo.CostListSearchKeysVo; import com.blt.other.other_cost.vo.CostListSearchKeysVo;
import com.blt.other.other_database.model.CostDomain; import com.blt.other.other_database.model.CostDomain;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -12,13 +11,11 @@ import org.springframework.web.bind.annotation.PostMapping; ...@@ -12,13 +11,11 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.persistence.criteria.CriteriaBuilder;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
@RestController @RestController
...@@ -29,14 +26,15 @@ public class CostListSearchController { ...@@ -29,14 +26,15 @@ public class CostListSearchController {
private CostListSearchService costListSearchService; private CostListSearchService costListSearchService;
@PostMapping("/search/key") @PostMapping("/search/key")
public Map<String,Object> getByKey(HttpServletResponse response, HttpServletRequest request){ public Map<String,Object> getByKey(HttpServletResponse response,
HttpServletRequest request){
AxiosUtil.setCors(response,request); AxiosUtil.setCors(response,request);
String key = request.getParameter("key"); String key = request.getParameter("key");
String pageNumStr = request.getParameter("pageNum"); String pageNumStr = request.getParameter("pageNum");
String pageSizeStr = request.getParameter("pageSize"); String pageSizeStr = request.getParameter("pageSize");
Map<String, Object> map = costListSearchService.seachByKey(key,Integer.parseInt(pageNumStr),Integer.parseInt(pageSizeStr)); Map<String, Object> map = costListSearchService.searchByKey(key,Integer.parseInt(pageNumStr),Integer.parseInt(pageSizeStr));
map.put("success",true); map.put("success",true);
return map; return map;
} }
......
...@@ -15,10 +15,10 @@ public interface CostListSearchDao { ...@@ -15,10 +15,10 @@ public interface CostListSearchDao {
/** /**
* 通过关键字模糊查询 * 通过关键字模糊查询
* @param key * @param keys
* @return * @return
*/ */
List<CostDomain> selectByKey(@Param("key") String key); List<CostDomain> selectByKey(@Param("keys") List<String> keys);
List<CostDomain> selectByKeys(CostListSearchKeysVo searchKeysVo); List<CostDomain> selectByKeys(CostListSearchKeysVo searchKeysVo);
......
...@@ -14,7 +14,7 @@ public interface CostListSearchService { ...@@ -14,7 +14,7 @@ public interface CostListSearchService {
* @param key * @param key
* @return * @return
*/ */
Map<String,Object> seachByKey(String key,int pageNum,int pageSize); Map<String,Object> searchByKey(String key, int pageNum, int pageSize);
List<CostDto> domainListToDto(List<CostDomain> domains); List<CostDto> domainListToDto(List<CostDomain> domains);
......
...@@ -10,15 +10,15 @@ import com.blt.other.other_database.mapper.StatusMapper; ...@@ -10,15 +10,15 @@ import com.blt.other.other_database.mapper.StatusMapper;
import com.blt.other.other_database.model.CostDomain; import com.blt.other.other_database.model.CostDomain;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import org.apache.commons.collections.ListUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap; import java.util.stream.Collectors;
import java.util.List;
import java.util.Map;
@Service @Service
public class CostListSearchServiceImpl implements CostListSearchService { public class CostListSearchServiceImpl implements CostListSearchService {
...@@ -31,10 +31,10 @@ public class CostListSearchServiceImpl implements CostListSearchService { ...@@ -31,10 +31,10 @@ public class CostListSearchServiceImpl implements CostListSearchService {
private CostService costService; private CostService costService;
@Override @Override
public Map<String, Object> seachByKey(String key,int pageNum,int pageSize) { public Map<String, Object> searchByKey(String key, int pageNum, int pageSize) {
Map<String,Object> result = new HashMap<>(); Map<String,Object> result = new HashMap<>();
PageHelper.startPage(pageNum,pageSize); PageHelper.startPage(pageNum,pageSize);
List<CostDomain> costDomains = costListSearchDao.selectByKey(key); List<CostDomain> costDomains = costListSearchDao.selectByKey(Lists.newArrayList(key.split(",")).stream().filter(Objects::nonNull).collect(Collectors.toList()));
List<CostDto> dtos = domainListToDto(costDomains); List<CostDto> dtos = domainListToDto(costDomains);
PageInfo<CostDomain> pageInfo = new PageInfo<>(costDomains); PageInfo<CostDomain> pageInfo = new PageInfo<>(costDomains);
result.put("costs",dtos); result.put("costs",dtos);
......
...@@ -7,18 +7,32 @@ ...@@ -7,18 +7,32 @@
* *
FROM FROM
cost cost
WHERE WHERE false
cost_plan_no = #{key} <foreach collection="keys" item="key" index="index">
OR <if test="key != null and key != '' ">
cost_no LIKE CONCAT('%',#{key},'%') or cost_plan_no = #{key}
OR </if>
create_username LIKE CONCAT('%',#{key},'%') </foreach>
OR <foreach collection="keys" item="key" index="index">
type_name LIKE CONCAT('%',#{key},'%') <if test="key != null and key != '' ">
OR or cost_no LIKE CONCAT('%',#{key},'%')
kind_name LIKE CONCAT('%',#{key},'%') </if>
OR </foreach>
company_name LIKE CONCAT('%',#{key},'%') <foreach collection="keys" item="key" index="index">
<if test="key != null and key != '' ">
or type_name LIKE CONCAT('%',#{key},'%')
</if>
</foreach>
<foreach collection="keys" item="key" index="index">
<if test="key != null and key != '' ">
or kind_name LIKE CONCAT('%',#{key},'%')
</if>
</foreach>
<foreach collection="keys" item="key" index="index">
<if test="key != null and key != '' ">
or company_name LIKE CONCAT('%',#{key},'%')
</if>
</foreach>
</select> </select>
<select id="selectByKeys" resultType="com.blt.other.other_database.model.CostDomain"> <select id="selectByKeys" resultType="com.blt.other.other_database.model.CostDomain">
......
package com.blt.other.other_cost.service;
import com.alibaba.fastjson.JSON;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.annotation.Resource;
import java.util.Map;
/**
* <p>
*
* </p>
*
* @author robbendev
* @since 2020/8/20 4:33 下午
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class CostListSearchServiceTest {
@Resource
CostListSearchService costListSearchService;
@Test
public void searchByKey() {
Map<String, Object> result = costListSearchService.searchByKey("F024926,F024927,F024928", 1, 100);
System.out.println(JSON.toJSONString(result));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment