Commit 15ab7751 by huluobin

费用系统的批量搜索

parent 09950487
......@@ -36,6 +36,7 @@
<org.apache.poi>3.9</org.apache.poi>
<commons.fileupload>1.3.1</commons.fileupload>
<commons.io>2.4</commons.io>
<commons-lang3.verson>3.10</commons-lang3.verson>
</properties>
<dependencies>
......@@ -172,6 +173,20 @@
<artifactId>commons-io</artifactId>
<version>${commons.io}</version>
</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-->
<dependency>
......
......@@ -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.MyMapperUtil;
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_database.model.CostDomain;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -12,13 +11,11 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.persistence.criteria.CriteriaBuilder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.Set;
@RestController
......@@ -29,14 +26,15 @@ public class CostListSearchController {
private CostListSearchService costListSearchService;
@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);
String key = request.getParameter("key");
String pageNumStr = request.getParameter("pageNum");
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);
return map;
}
......
......@@ -15,10 +15,10 @@ public interface CostListSearchDao {
/**
* 通过关键字模糊查询
* @param key
* @param keys
* @return
*/
List<CostDomain> selectByKey(@Param("key") String key);
List<CostDomain> selectByKey(@Param("keys") List<String> keys);
List<CostDomain> selectByKeys(CostListSearchKeysVo searchKeysVo);
......
......@@ -14,7 +14,7 @@ public interface CostListSearchService {
* @param key
* @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);
......
......@@ -10,15 +10,15 @@ import com.blt.other.other_database.mapper.StatusMapper;
import com.blt.other.other_database.model.CostDomain;
import com.github.pagehelper.PageHelper;
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.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class CostListSearchServiceImpl implements CostListSearchService {
......@@ -31,10 +31,10 @@ public class CostListSearchServiceImpl implements CostListSearchService {
private CostService costService;
@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<>();
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);
PageInfo<CostDomain> pageInfo = new PageInfo<>(costDomains);
result.put("costs",dtos);
......
......@@ -7,18 +7,32 @@
*
FROM
cost
WHERE
cost_plan_no = #{key}
OR
cost_no LIKE CONCAT('%',#{key},'%')
OR
create_username LIKE CONCAT('%',#{key},'%')
OR
type_name LIKE CONCAT('%',#{key},'%')
OR
kind_name LIKE CONCAT('%',#{key},'%')
OR
company_name LIKE CONCAT('%',#{key},'%')
WHERE false
<foreach collection="keys" item="key" index="index">
<if test="key != null and key != '' ">
or cost_plan_no = #{key}
</if>
</foreach>
<foreach collection="keys" item="key" index="index">
<if test="key != null and key != '' ">
or cost_no LIKE CONCAT('%',#{key},'%')
</if>
</foreach>
<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 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