Commit a09430e2 by 彭祥礼

多表多条件分页查询优化

parent f1def573
package com.winsun.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
......@@ -16,7 +15,6 @@ import com.winsun.utils.ProduceIdUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
......@@ -92,7 +90,6 @@ public class RongHeController {
Product product = productMapper.selectById(bandproductId);
UniversityInfo universityInfo = universityInfoMapper.selectById(product.getUniversityId());
Map<String, Object> objMap = new HashMap<>();
objMap.put("product", product);
objMap.put("universityInfo", universityInfo);
......
package com.winsun.bean;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import com.baomidou.mybatisplus.enums.IdType;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@TableName("hhr_user")
@Data
......@@ -63,11 +59,13 @@ public class HhrUser implements Serializable{
/**
* 上级id
*/
@TableField("parent_id")
private String parentId;
/**
* 所有上级id
*/
@TableField("parent_ids")
private String parentIds;
/**
......
......@@ -76,38 +76,47 @@ public class SaleCensusController extends BaseController{
List<Map<String,Object>> dataList = new LinkedList<>();
List<String> userIds = new ArrayList<>();
if(StringUtils.isNotBlank(leader)){
Wrapper<SysUser> sysUserWrapper = new EntityWrapper<>();
sysUserWrapper.like( "name", leader.trim(), SqlLike.DEFAULT);
List<SysUser> sysUserList = sysUserMapper.selectList(sysUserWrapper);
if(sysUserList.size()==0){
List<String> parentId = new ArrayList<>();
if(StringUtils.isNotBlank(position)) {
Wrapper<HhrUser> hhrUserWrapper = new EntityWrapper<>();
hhrUserWrapper.eq("position", position.trim());
List<HhrUser> hhrUserList = hhrUserMapper.selectList(hhrUserWrapper);
if (hhrUserList.size() == 0) {
page.setTotal(0);
return ResponseData.success(page, "没有数据!");
}
for (SysUser sysUser : sysUserList) {
userIds.add(sysUser.getId());
for (HhrUser hhrUser : hhrUserList) {
userIds.add(hhrUser.getId());
if (StringUtils.isNotBlank(hhrUser.getParentId())) {
parentId.add(hhrUser.getParentId());
}
}
}
List<String> userIdst = new ArrayList<>();
if(StringUtils.isNotBlank(position)){
Wrapper<HhrUser> hhrUserWrapper = new EntityWrapper<>();
if(userIds.size()>0){
hhrUserWrapper.in("id",userIds);
if(StringUtils.isNotBlank(leader)){
Wrapper<SysUser> sysUserWrapper = new EntityWrapper<>();
if (parentId.size() > 0) {
sysUserWrapper.in("id", parentId);
}
sysUserWrapper.eq( "name", leader.trim());
List<SysUser> sysUserList = sysUserMapper.selectList(sysUserWrapper);
if(sysUserList.size()==0){
log.info("没有数据");
}
hhrUserWrapper.eq( "position", position.trim());
Wrapper<HhrUser> hhrUserWrapper = new EntityWrapper<>();
hhrUserWrapper.eq("parent_id",sysUserList.get(0).getId());
List<HhrUser> hhrUserList = hhrUserMapper.selectList(hhrUserWrapper);
if(hhrUserList.size()==0){
page.setTotal(0);
return ResponseData.success(page, "没有数据!");
log.info("没有数据");
}
userIds.removeAll(userIds);
for (HhrUser hhrUser : hhrUserList) {
userIdst.add(hhrUser.getId());
userIds.add(hhrUser.getId());
}
}
Wrapper<SalesOrder> wrapper0 = new EntityWrapper();
wrapper0.setSqlSelect("user_id userId,COUNT(*) recentlyNum");
if(userIdst.size()>0){
wrapper0.in("user_id",userIdst);
if(userIds.size()>0){
wrapper0.in("user_id",userIds);
}
wrapper0.like(StringUtils.isNotBlank(name), "name", name.trim(), SqlLike.DEFAULT);
wrapper0.eq(StringUtils.isNotBlank(account), "account", account.trim());
......@@ -117,13 +126,9 @@ public class SaleCensusController extends BaseController{
wrapper0.eq( "del_flag", 0);
wrapper0.groupBy("user_id");
if(StringUtils.isNotBlank(activateTime)){
String[] months = activateTime.split("\\,");
if(!activateTime.equals(",") && StringUtils.isNotEmpty(activateTime)){
String m1 = months[0].substring(0,7);
String month1 = m1.substring(0,4) + m1.substring(5);
String m2 = months[1].substring(0,7);
String month2 = m2.substring(0,4) + m2.substring(5);
wrapper0.between("activate_time",month1,month2);
String[] dates = activateTime.split("\\,");
if(!activateTime.equals(",")){
wrapper0.between("activate_time",dates[0],dates[1]);
}
}
dataList = salesOrderMapper.selectMaps(wrapper0);
......@@ -136,14 +141,6 @@ public class SaleCensusController extends BaseController{
Integer endpageSize = (pageNo-1) == dataList.size()/pageSize?(pageNo-1)*pageSize+dataList.size()%pageSize:pageNo*pageSize;
dataList = dataList.subList((pageNo-1)*pageSize, endpageSize);
}
List<String> ids = new ArrayList<>();
for (Map<String, Object> objectMap : dataList) {
ids.add(objectMap.get("userId").toString());
}
Wrapper<HhrUser> hhrUserWrapper1 = new EntityWrapper<>();
hhrUserWrapper1.in("id",ids);
List<HhrUser> hhrUsers = hhrUserMapper.selectList(hhrUserWrapper1);
for (Map<String, Object> objectMap : dataList) {
String userId = objectMap.get("userId").toString();
Wrapper<SalesOrder> salesOrderWrapper = new EntityWrapper();
......@@ -156,7 +153,8 @@ public class SaleCensusController extends BaseController{
objectMap.put("account",salesOrder.getAccount());
objectMap.put("salesSubst",salesOrder.getSalesSubst());
objectMap.put("salesSchool",salesOrder.getSalesSchool());
for (HhrUser hhrUser : hhrUsers) {
HhrUser hhrUser = hhrUserMapper.selectById(salesOrder.getUserId());
if(hhrUser != null){
if(hhrUser.getId().equals(userId)){
objectMap.put("position",hhrUser.getPosition());
if(StringUtils.isNotBlank(hhrUser.getParentId())){
......@@ -165,7 +163,6 @@ public class SaleCensusController extends BaseController{
objectMap.put("leader",sysUser.getName());
}
}
break;
}
}
}
......@@ -196,36 +193,47 @@ public class SaleCensusController extends BaseController{
List<Map<String,Object>> dataList = new LinkedList<>();
List<String> userIds = new ArrayList<>();
List<String> parentId = new ArrayList<>();
if(StringUtils.isNotBlank(position)) {
Wrapper<HhrUser> hhrUserWrapper = new EntityWrapper<>();
hhrUserWrapper.eq("position", position.trim());
List<HhrUser> hhrUserList = hhrUserMapper.selectList(hhrUserWrapper);
if (hhrUserList.size() == 0) {
log.info("没有数据");
}
for (HhrUser hhrUser : hhrUserList) {
userIds.add(hhrUser.getId());
if (StringUtils.isNotBlank(hhrUser.getParentId())) {
parentId.add(hhrUser.getParentId());
}
}
}
if(StringUtils.isNotBlank(leader)){
Wrapper<SysUser> sysUserWrapper = new EntityWrapper<>();
sysUserWrapper.like( "name", leader.trim(), SqlLike.DEFAULT);
if (parentId.size() > 0) {
sysUserWrapper.in("id", parentId);
}
sysUserWrapper.eq( "name", leader.trim());
List<SysUser> sysUserList = sysUserMapper.selectList(sysUserWrapper);
if(sysUserList.size()==0){
log.info("没有数据");
}
for (SysUser sysUser : sysUserList) {
userIds.add(sysUser.getId());
}
}
List<String> userIdst = new ArrayList<>();
if(StringUtils.isNotBlank(position)){
Wrapper<HhrUser> hhrUserWrapper = new EntityWrapper<>();
if(userIds.size()>0){
hhrUserWrapper.in("id",userIds);
}
hhrUserWrapper.eq( "position", position.trim());
hhrUserWrapper.eq("parent_id",sysUserList.get(0).getId());
List<HhrUser> hhrUserList = hhrUserMapper.selectList(hhrUserWrapper);
if(hhrUserList.size()==0){
log.info("没有数据");
}
userIds.removeAll(userIds);
for (HhrUser hhrUser : hhrUserList) {
userIdst.add(hhrUser.getId());
userIds.add(hhrUser.getId());
}
}
Wrapper<SalesOrder> wrapper0 = new EntityWrapper();
wrapper0.setSqlSelect("user_id userId,COUNT(*) recentlyNum");
if(userIdst.size()>0){
wrapper0.in("user_id",userIdst);
if(userIds.size()>0){
wrapper0.in("user_id",userIds);
userIds.removeAll(userIds);
}
wrapper0.like(StringUtils.isNotBlank(name), "name", name.trim(), SqlLike.DEFAULT);
wrapper0.eq(StringUtils.isNotBlank(account), "account", account.trim());
......@@ -235,25 +243,20 @@ public class SaleCensusController extends BaseController{
wrapper0.eq( "del_flag", 0);
wrapper0.groupBy("user_id");
if(StringUtils.isNotBlank(activateTime)){
String[] months = activateTime.split("\\,");
if(!activateTime.equals(",") && StringUtils.isNotEmpty(activateTime)){
String m1 = months[0].substring(0,7);
String month1 = m1.substring(0,4) + m1.substring(5);
String m2 = months[1].substring(0,7);
String month2 = m2.substring(0,4) + m2.substring(5);
wrapper0.between("activate_time",month1,month2);
String[] dates = activateTime.split("\\,");
if(!activateTime.equals(",")){
wrapper0.between("activate_time",dates[0],dates[1]);
}
}
dataList = salesOrderMapper.selectMaps(wrapper0);
if(dataList.size()==0){
log.info("没有数据");
}
List<String> ids = new ArrayList<>();
for (Map<String, Object> objectMap : dataList) {
ids.add(objectMap.get("userId").toString());
userIds.add(objectMap.get("userId").toString());
}
Wrapper<HhrUser> hhrUserWrapper1 = new EntityWrapper<>();
hhrUserWrapper1.in("id",ids);
hhrUserWrapper1.in("id",userIds);
List<HhrUser> hhrUsers = hhrUserMapper.selectList(hhrUserWrapper1);
for (Map<String, Object> objectMap : dataList) {
......
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