|
|
@ -8,6 +8,8 @@ import com.qs.serve.common.model.dto.R; |
|
|
|
import com.qs.serve.common.model.enums.BizType; |
|
|
|
import com.qs.serve.common.model.enums.SystemModule; |
|
|
|
import com.qs.serve.common.util.*; |
|
|
|
import com.qs.serve.modules.bms.entity.BmsSupplier; |
|
|
|
import com.qs.serve.modules.bms.mapper.BmsSupplierMapper; |
|
|
|
import com.qs.serve.modules.exl.common.ExlConst; |
|
|
|
import com.qs.serve.modules.exl.common.QsSqlSessionUtil; |
|
|
|
import com.qs.serve.modules.exl.common.TableCreateSqlUtil; |
|
|
@ -37,6 +39,8 @@ import java.time.LocalDateTime; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import static com.qs.serve.modules.exl.common.TableCreateSqlUtil.DEFAULT_STRING; |
|
|
|
|
|
|
|
/** |
|
|
|
* 动态Excel表 数据查询 |
|
|
|
* @author YenHex |
|
|
@ -56,6 +60,7 @@ public class ExlTableDataController { |
|
|
|
private SysUserMapper sysUserMapper; |
|
|
|
private SysPostUserService postUserService; |
|
|
|
private HisUserSupplierMapper hisUserSupplierMapper; |
|
|
|
private BmsSupplierMapper bmsSupplierMapper; |
|
|
|
|
|
|
|
/** |
|
|
|
* 翻页查询 |
|
|
@ -108,6 +113,10 @@ public class ExlTableDataController { |
|
|
|
List<ExlConditionDto> like_conditions = new ArrayList<>(); |
|
|
|
List<ExlConditionDto> in_conditions = new ArrayList<>(); |
|
|
|
|
|
|
|
//map赋值业务参数的key
|
|
|
|
map.putIfAbsent(ExlConst.TYPE_USER_CODE, ""); |
|
|
|
map.putIfAbsent(ExlConst.TYPE_CUSTOMER_CODE, ""); |
|
|
|
|
|
|
|
if(!map.isEmpty()){ |
|
|
|
for (String columnName : map.keySet()) { |
|
|
|
String searchValue = map.get(columnName); |
|
|
@ -119,52 +128,69 @@ public class ExlTableDataController { |
|
|
|
currColumnConf = columnConf; |
|
|
|
break; |
|
|
|
} |
|
|
|
//拓展业务查询条件
|
|
|
|
String extColumnName = null; |
|
|
|
if(columnConf.getColumnType().equals(ExlConst.TYPE_USER_CODE)){ |
|
|
|
extColumnName = columnConf.getColumnName()+"_ext_usr_name"; |
|
|
|
}else if (columnConf.getColumnType().equals(ExlConst.TYPE_CUSTOMER_CODE)){ |
|
|
|
extColumnName = columnConf.getColumnName()+"_ext_cus_name"; |
|
|
|
} |
|
|
|
if(extColumnName!=null&&extColumnName.equals(orgColumn)){ |
|
|
|
ExlColumnConf conf = new ExlColumnConf(); |
|
|
|
conf.setColumnName(extColumnName); |
|
|
|
conf.setColumnType(DEFAULT_STRING); |
|
|
|
conf.setScope(0); |
|
|
|
currColumnConf = conf; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if(currColumnConf==null){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
String colType = currColumnConf.getColumnType(); |
|
|
|
if(!adminFlag){ |
|
|
|
// 权限范围:0->本人;1->下属;2->全部(本人级下属)
|
|
|
|
// 权限范围:0->无;1->本人;2->下属;3->全部(本人级下属)
|
|
|
|
Integer scope = currColumnConf.getScope(); |
|
|
|
Set<String> values = new HashSet<>(); |
|
|
|
// 业务类型
|
|
|
|
String userId = AuthContextUtils.getSysUserId(); |
|
|
|
SysUser sysUser = sysUserMapper.selectById(userId); |
|
|
|
if (colType.equals(ExlConst.TYPE_USER_CODE)){ |
|
|
|
values.add("0"); |
|
|
|
if(scope==0){ |
|
|
|
values.add(sysUser.getCode()); |
|
|
|
}else if (scope>0){ |
|
|
|
List<String> childIds = postUserService.listByChildIds(AuthContextUtils.getSysUserId()); |
|
|
|
if(childIds.size()>0){ |
|
|
|
List<SysUser> sysUsers = sysUserMapper.selectBatchIds(childIds); |
|
|
|
List<String> codes = sysUsers.stream().map(a->a.getCode()).collect(Collectors.toList()); |
|
|
|
values.addAll(codes); |
|
|
|
} |
|
|
|
if (scope==2){ |
|
|
|
if(scope>0){ |
|
|
|
if (colType.equals(ExlConst.TYPE_USER_CODE)){ |
|
|
|
values.add("0"); |
|
|
|
if(scope==1){ |
|
|
|
values.add(sysUser.getCode()); |
|
|
|
}else { |
|
|
|
List<String> childIds = postUserService.listByChildIds(AuthContextUtils.getSysUserId()); |
|
|
|
if(childIds.size()>0){ |
|
|
|
List<SysUser> sysUsers = sysUserMapper.selectBatchIds(childIds); |
|
|
|
List<String> codes = sysUsers.stream().map(a->a.getCode()).collect(Collectors.toList()); |
|
|
|
values.addAll(codes); |
|
|
|
} |
|
|
|
if (scope==3){ |
|
|
|
values.add(sysUser.getCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
ExlConditionDto conditionDto = new ExlConditionDto(orgColumn,values); |
|
|
|
in_conditions.add(conditionDto); |
|
|
|
}else if (colType.equals(ExlConst.TYPE_CUSTOMER_CODE)){ |
|
|
|
values.add("0"); |
|
|
|
List<String> userIds = new ArrayList<>(); |
|
|
|
userIds.add(userId); |
|
|
|
if(scope>1){ |
|
|
|
List<String> childIds = postUserService.listByChildIds(AuthContextUtils.getSysUserId()); |
|
|
|
userIds.addAll(childIds); |
|
|
|
} |
|
|
|
LambdaQueryWrapper<HisUserSupplier> husLqw = new LambdaQueryWrapper<>(); |
|
|
|
husLqw.in(HisUserSupplier::getUserId,userIds); |
|
|
|
husLqw.select(HisUserSupplier::getSupplierCode); |
|
|
|
List<HisUserSupplier> hisUserSuppliers = hisUserSupplierMapper.selectList(husLqw); |
|
|
|
List<String> supplierCodes = hisUserSuppliers.stream() |
|
|
|
.map(HisUserSupplier::getSupplierCode).distinct().collect(Collectors.toList()); |
|
|
|
values.addAll(supplierCodes); |
|
|
|
ExlConditionDto conditionDto = new ExlConditionDto(orgColumn,values); |
|
|
|
in_conditions.add(conditionDto); |
|
|
|
} |
|
|
|
ExlConditionDto conditionDto = new ExlConditionDto(orgColumn,values); |
|
|
|
in_conditions.add(conditionDto); |
|
|
|
}else if (colType.equals(ExlConst.TYPE_CUSTOMER_CODE)){ |
|
|
|
values.add("0"); |
|
|
|
List<String> userIds = new ArrayList<>(); |
|
|
|
userIds.add(userId); |
|
|
|
if(scope>0){ |
|
|
|
List<String> childIds = postUserService.listByChildIds(AuthContextUtils.getSysUserId()); |
|
|
|
userIds.addAll(childIds); |
|
|
|
} |
|
|
|
LambdaQueryWrapper<HisUserSupplier> husLqw = new LambdaQueryWrapper<>(); |
|
|
|
husLqw.in(HisUserSupplier::getUserId,userIds); |
|
|
|
husLqw.select(HisUserSupplier::getSupplierCode); |
|
|
|
List<HisUserSupplier> hisUserSuppliers = hisUserSupplierMapper.selectList(husLqw); |
|
|
|
List<String> supplierCodes = hisUserSuppliers.stream() |
|
|
|
.map(HisUserSupplier::getSupplierCode).distinct().collect(Collectors.toList()); |
|
|
|
values.addAll(supplierCodes); |
|
|
|
ExlConditionDto conditionDto = new ExlConditionDto(orgColumn,values); |
|
|
|
in_conditions.add(conditionDto); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -259,7 +285,15 @@ public class ExlTableDataController { |
|
|
|
//insert into table (cloumns) values (vals),(vals)
|
|
|
|
StringBuilder insertSql = new StringBuilder("insert into "+targetTableName +"( `union_row_id`,"); |
|
|
|
for (int i = 0; i < columnList.size(); i++) { |
|
|
|
insertSql.append(" `"+columnList.get(i).getColumnName()+"` "); |
|
|
|
ExlColumnConf columnConf = columnList.get(i); |
|
|
|
insertSql.append(" `"+columnConf.getColumnName()+"` "); |
|
|
|
if(columnConf.getColumnType().equals(ExlConst.TYPE_USER_CODE)){ |
|
|
|
insertSql.append(","); |
|
|
|
insertSql.append(" `"+columnConf.getColumnName()+"_ext_usr_name` "); |
|
|
|
}else if(columnConf.getColumnType().equals(ExlConst.TYPE_CUSTOMER_CODE)){ |
|
|
|
insertSql.append(","); |
|
|
|
insertSql.append(" `"+columnConf.getColumnName()+"_ext_cus_name` "); |
|
|
|
} |
|
|
|
if(i+1<columnList.size()){ |
|
|
|
insertSql.append(","); |
|
|
|
} |
|
|
@ -278,6 +312,27 @@ public class ExlTableDataController { |
|
|
|
ExlColumnConf columnConf = columnList.get(i); |
|
|
|
String string = jsonObject.getString(columnConf.getColumnName()); |
|
|
|
insertSql.append("'"+string+"'"); |
|
|
|
if(columnConf.getColumnType().equals(ExlConst.TYPE_USER_CODE)){ |
|
|
|
insertSql.append(","); |
|
|
|
LambdaQueryWrapper<SysUser> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.eq(SysUser::getCode,string); |
|
|
|
lqw.select(SysUser::getCode,SysUser::getName); |
|
|
|
List<SysUser> sysUsers = sysUserMapper.selectList(lqw); |
|
|
|
if (sysUsers.size()>0){ |
|
|
|
String name = sysUsers.get(0).getName(); |
|
|
|
insertSql.append("'"+name+"'"); |
|
|
|
} |
|
|
|
}else if(columnConf.getColumnType().equals(ExlConst.TYPE_CUSTOMER_CODE)){ |
|
|
|
insertSql.append(","); |
|
|
|
LambdaQueryWrapper<BmsSupplier> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.eq(BmsSupplier::getCode,string); |
|
|
|
lqw.select(BmsSupplier::getCode,BmsSupplier::getName); |
|
|
|
List<BmsSupplier> supplierList = bmsSupplierMapper.selectList(lqw); |
|
|
|
if (supplierList.size()>0){ |
|
|
|
String name = supplierList.get(0).getName(); |
|
|
|
insertSql.append("'"+name+"'"); |
|
|
|
} |
|
|
|
} |
|
|
|
if(i+1<columnList.size()){ |
|
|
|
insertSql.append(", "); |
|
|
|
} |
|
|
|