|
@@ -37,7 +37,6 @@ import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.lang.reflect.Method;
|
|
|
-import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
@@ -80,67 +79,68 @@ public class FieldUtils {
|
|
|
|
|
|
/**
|
|
|
* 组装最终的sql条件和排序
|
|
|
+ *
|
|
|
* @param bean
|
|
|
* @return
|
|
|
*/
|
|
|
- public static ZfireParamBean supplyParam(ZfireParamBean bean){
|
|
|
- return supplyParam(bean,null);
|
|
|
+ public static ZfireParamBean supplyParam(ZfireParamBean bean) {
|
|
|
+ return supplyParam(bean, null);
|
|
|
}
|
|
|
|
|
|
- public static ZfireParamBean supplyParam(ZfireParamBean bean,Class cls){
|
|
|
+ public static ZfireParamBean supplyParam(ZfireParamBean bean, Class cls) {
|
|
|
//限制最多查询10w条
|
|
|
- if(bean.getPageSize() != null && (bean.getPageSize().equals(-1) || bean.getPageSize().intValue() > 100000)){
|
|
|
+ if (bean.getPageSize() != null && (bean.getPageSize().equals(-1) || bean.getPageSize().intValue() > 100000)) {
|
|
|
bean.setPageSize(100000);
|
|
|
}
|
|
|
//todo 框架自带防注入
|
|
|
bean.setQuery(supplyParam(bean.getParams()));
|
|
|
- if(StringUtils.isNotBlank(bean.getCompanyWechatId())){
|
|
|
- bean.setQuery(bean.getQuery() + " and a.company_wechat_id = '"+bean.getCompanyWechatId()+"'" );
|
|
|
+ if (StringUtils.isNotBlank(bean.getCompanyWechatId())) {
|
|
|
+ bean.setQuery(bean.getQuery() + " and a.company_wechat_id = '" + bean.getCompanyWechatId() + "'");
|
|
|
}
|
|
|
- if(bean.getClazzType() != null){
|
|
|
+ if (bean.getClazzType() != null) {
|
|
|
bean.setSelected(buildSelectColumn(bean.getClazzType()));
|
|
|
- }else if(cls != null) {
|
|
|
+ } else if (cls != null) {
|
|
|
bean.setSelected(buildSelectColumn(cls));
|
|
|
}
|
|
|
- if(StringUtils.isNotBlank(bean.getOrderBy()) && !bean.getOrderBy().contains("order by")) {
|
|
|
+ if (StringUtils.isNotBlank(bean.getOrderBy()) && !bean.getOrderBy().contains("order by")) {
|
|
|
bean.setOrderBy("order by " + bean.getOrderBy());
|
|
|
}
|
|
|
return bean;
|
|
|
}
|
|
|
- public static ZfireParamBean supplyParam(ZfireParamBean bean,Class cls,AdminUserCom adminUser){
|
|
|
+
|
|
|
+ public static ZfireParamBean supplyParam(ZfireParamBean bean, Class cls, AdminUserCom adminUser) {
|
|
|
if (Objects.nonNull(adminUser.getAdminCompanyWechat())) {
|
|
|
bean.setCompanyWechatId(adminUser.getAdminCompanyWechat().getCompanyWechatId());
|
|
|
}
|
|
|
bean.setAdminWebsitIds(adminUser.getAdminWebsitIds());
|
|
|
//限制最多查询10w条
|
|
|
- if(bean.getPageSize() != null && (bean.getPageSize().equals(-1) || bean.getPageSize().intValue() > 100000)){
|
|
|
+ if (bean.getPageSize() != null && (bean.getPageSize().equals(-1) || bean.getPageSize() > 100000)) {
|
|
|
bean.setPageSize(100000);
|
|
|
}
|
|
|
//todo 框架自带防注入
|
|
|
bean.setQuery(supplyParam(bean.getParams()));
|
|
|
- if(StringUtils.isNotBlank(bean.getCompanyWechatId())){
|
|
|
- bean.setQuery(bean.getQuery() + " and a.company_wechat_id = '"+bean.getCompanyWechatId()+"'" );
|
|
|
+ if (StringUtils.isNotBlank(bean.getCompanyWechatId())) {
|
|
|
+ bean.setQuery(bean.getQuery() + " and a.company_wechat_id = '" + bean.getCompanyWechatId() + "'");
|
|
|
}
|
|
|
- if(bean.getClazzType() != null){
|
|
|
+ if (bean.getClazzType() != null) {
|
|
|
bean.setSelected(buildSelectColumn(bean.getClazzType()));
|
|
|
- }else if(cls != null) {
|
|
|
+ } else if (cls != null) {
|
|
|
bean.setSelected(buildSelectColumn(cls));
|
|
|
}
|
|
|
- if(StringUtils.isNotBlank(bean.getOrderBy()) && !bean.getOrderBy().contains("order by")) {
|
|
|
+ if (StringUtils.isNotBlank(bean.getOrderBy()) && !bean.getOrderBy().contains("order by")) {
|
|
|
bean.setOrderBy("order by " + bean.getOrderBy());
|
|
|
}
|
|
|
return bean;
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- public static ZfireParamBean materialParam(ZfireParamBean bean, Class cls, AdminUserCom adminUser){
|
|
|
- return supplyParam(bean,cls,adminUser);
|
|
|
+ public static ZfireParamBean materialParam(ZfireParamBean bean, Class cls, AdminUserCom adminUser) {
|
|
|
+ return supplyParam(bean, cls, adminUser);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 组装最终的sql查询字段
|
|
|
+ *
|
|
|
* @param clazz
|
|
|
* @return
|
|
|
*/
|
|
@@ -171,7 +171,7 @@ public class FieldUtils {
|
|
|
// .map(ZfireField::colName)
|
|
|
// .filter(StringUtils::isNotBlank)
|
|
|
// .orElseGet(() -> parseLineColName(field.getName(), fieldTbName));
|
|
|
- String sqlName = parseLineColName(field.getName(),fieldTbName);
|
|
|
+ String sqlName = parseLineColName(field.getName(), fieldTbName);
|
|
|
sqlNameList.add(sqlName);
|
|
|
}
|
|
|
if (CollectionUtils.isEmpty(sqlNameList)) {
|
|
@@ -191,43 +191,43 @@ public class FieldUtils {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
* 根据前端传的集合生成查询条件
|
|
|
* [{
|
|
|
- * "param":"条件名称",
|
|
|
- * "compare":"比较符(><=like)"
|
|
|
- * "value":"内容"
|
|
|
+ * "param":"条件名称",
|
|
|
+ * "compare":"比较符(><=like)"
|
|
|
+ * "value":"内容"
|
|
|
* }]
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
- public static String supplyParam(List<QueryParamBean> params){
|
|
|
+ public static String supplyParam(List<QueryParamBean> params) {
|
|
|
StringBuffer sb = new StringBuffer(" where 1=1 ");
|
|
|
- if(params == null || params.size() == 0){
|
|
|
+ if (params == null || params.size() == 0) {
|
|
|
return sb.toString();
|
|
|
}
|
|
|
|
|
|
- for(QueryParamBean paramBean : params){
|
|
|
- if(paramBean.getValue() == null)
|
|
|
+ for (QueryParamBean paramBean : params) {
|
|
|
+ if (paramBean.getValue() == null)
|
|
|
continue;
|
|
|
- if(paramBean.getValue() instanceof ArrayList){
|
|
|
+ if (paramBean.getValue() instanceof ArrayList) {
|
|
|
List<String> values = (List<String>) paramBean.getValue();
|
|
|
- if(values != null && values.size() > 0) {
|
|
|
+ if (values != null && values.size() > 0) {
|
|
|
String join = "";
|
|
|
- for(String s : values){
|
|
|
+ for (String s : values) {
|
|
|
s = replaceValue(s);
|
|
|
- join += "'"+s+"',";
|
|
|
+ join += "'" + s + "',";
|
|
|
}
|
|
|
- join = join.substring(0,join.length() - 1);
|
|
|
+ join = join.substring(0, join.length() - 1);
|
|
|
sb.append("and ").append(paramBean.getParam()).append(" in(").append(join).append(") ");
|
|
|
}
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
String value = "";
|
|
|
- if(paramBean.getValue() instanceof Boolean){
|
|
|
+ if (paramBean.getValue() instanceof Boolean) {
|
|
|
value = paramBean.getValue().toString();
|
|
|
} else {
|
|
|
value = paramBean.getValue().toString();
|
|
|
}
|
|
|
- if(StringUtils.isBlank(value))
|
|
|
+ if (StringUtils.isBlank(value))
|
|
|
continue;
|
|
|
|
|
|
value = replaceValue(value);
|
|
@@ -246,9 +246,9 @@ public class FieldUtils {
|
|
|
return sb.toString();
|
|
|
}
|
|
|
|
|
|
- public static String replaceValue(String value){
|
|
|
- return value.replaceAll("'","").replaceAll("\"","")
|
|
|
- .replaceAll(" or ","").replaceAll(" union ","");
|
|
|
+ public static String replaceValue(String value) {
|
|
|
+ return value.replaceAll("'", "").replaceAll("\"", "")
|
|
|
+ .replaceAll(" or ", "").replaceAll(" union ", "");
|
|
|
}
|
|
|
|
|
|
|
|
@@ -266,22 +266,22 @@ public class FieldUtils {
|
|
|
|
|
|
List<List<Object>> rows = new ArrayList<>();
|
|
|
List<String> excelTitles = new ArrayList<>();
|
|
|
- if(CollectionUtils.isEmpty(datas)){
|
|
|
+ if (CollectionUtils.isEmpty(datas)) {
|
|
|
// throw new RemoteServiceException("暂无内容导出");
|
|
|
excelTitles.add("暂无内容导出");
|
|
|
} else {
|
|
|
// Map<String, String> jMap = new LinkedHashMap<>();
|
|
|
List<String> jList = new ArrayList<>();
|
|
|
- if(CollectionUtils.isNotEmpty(titles)) {
|
|
|
+ if (CollectionUtils.isNotEmpty(titles)) {
|
|
|
// for (AdminField title : titles) {
|
|
|
// jMap.put(title.getJName(), title.getLabel());
|
|
|
// }
|
|
|
jList = titles.stream().map(AdminField::getJName).collect(Collectors.toList());
|
|
|
}
|
|
|
- if(jList.isEmpty()){
|
|
|
+ if (jList.isEmpty()) {
|
|
|
Object bean = datas.get(0);
|
|
|
Field[] fields = bean.getClass().getDeclaredFields();
|
|
|
- for(Field field : fields) {
|
|
|
+ for (Field field : fields) {
|
|
|
jList.add(field.getName());
|
|
|
}
|
|
|
}
|
|
@@ -293,7 +293,7 @@ public class FieldUtils {
|
|
|
List<Field> fieldList = Arrays.asList(fields);
|
|
|
Map<String, Field> fieldMap = fieldList.stream().collect(Collectors.toMap(Field::getName, v -> v));
|
|
|
|
|
|
- for(String f:jList){
|
|
|
+ for (String f : jList) {
|
|
|
Field field = fieldMap.get(f);
|
|
|
field.setAccessible(true);
|
|
|
String jName = field.getName();
|
|
@@ -302,19 +302,19 @@ public class FieldUtils {
|
|
|
}
|
|
|
String label = "";
|
|
|
ApiModelProperty annotation = field.getAnnotation(ApiModelProperty.class);
|
|
|
- if(annotation == null) {
|
|
|
+ if (annotation == null) {
|
|
|
continue;
|
|
|
}
|
|
|
label = annotation.value();
|
|
|
|
|
|
ZfireField zfireFieldAnnotation = field.getAnnotation(ZfireField.class);
|
|
|
- if(zfireFieldAnnotation != null && zfireFieldAnnotation.hide()) {
|
|
|
+ if (zfireFieldAnnotation != null && zfireFieldAnnotation.hide()) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
//属性类型
|
|
|
String typeName = field.getType().getName();
|
|
|
- if(typeName.equals("java.util.List") || typeName.equals("java.util.Map")) {
|
|
|
+ if (typeName.equals("java.util.List") || typeName.equals("java.util.Map")) {
|
|
|
continue;
|
|
|
}
|
|
|
Object value = field.get(bean);
|
|
@@ -344,7 +344,7 @@ public class FieldUtils {
|
|
|
}
|
|
|
|
|
|
if (value != null) {
|
|
|
- if ("java.util.Date".equals(typeName)) {
|
|
|
+ if ("java.util.Date" .equals(typeName)) {
|
|
|
//todo 格式化时间
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
row.add(sdf.format(value));
|
|
@@ -368,16 +368,16 @@ public class FieldUtils {
|
|
|
excelData.setTitles(excelTitles);
|
|
|
//目前是异步导出,名字由前端根据菜单名定义
|
|
|
//ExcelUtils.exportExcel(request,response,"test.xlsx",excelData);
|
|
|
- export(excelData,"test.xlsx");
|
|
|
+ export(excelData, "test.xlsx");
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static void export(ExcelData excelData,String fileName) throws IOException {
|
|
|
+ public static void export(ExcelData excelData, String fileName) throws IOException {
|
|
|
OutputStream outputStream = null;
|
|
|
try {
|
|
|
//标题
|
|
|
List<List<String>> titles = new ArrayList<>();
|
|
|
- for(String title : excelData.getTitles()){
|
|
|
+ for (String title : excelData.getTitles()) {
|
|
|
titles.add(Arrays.asList(title));
|
|
|
}
|
|
|
|
|
@@ -401,7 +401,7 @@ public class FieldUtils {
|
|
|
WriteCellStyle cellStyle = writeCellStyle();
|
|
|
|
|
|
//必须放到循环外,否则会刷新流
|
|
|
- ExcelWriter excelWriter = EasyExcel.write(outputStream).registerWriteHandler(new CellWriteHandler(){
|
|
|
+ ExcelWriter excelWriter = EasyExcel.write(outputStream).registerWriteHandler(new CellWriteHandler() {
|
|
|
public void afterCellDispose(CellWriteHandlerContext context) {
|
|
|
CellWriteHandler.super.afterCellDispose(context);
|
|
|
if (BooleanUtils.isNotTrue(context.getHead())) {
|
|
@@ -437,7 +437,7 @@ public class FieldUtils {
|
|
|
e.printStackTrace();
|
|
|
} catch (BeansException e) {
|
|
|
e.printStackTrace();
|
|
|
- }finally {
|
|
|
+ } finally {
|
|
|
if (outputStream != null) {
|
|
|
outputStream.close();
|
|
|
}
|
|
@@ -447,13 +447,14 @@ public class FieldUtils {
|
|
|
|
|
|
/**
|
|
|
* excel样式
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
- public static WriteCellStyle writeCellStyle(){
|
|
|
+ public static WriteCellStyle writeCellStyle() {
|
|
|
//样式
|
|
|
WriteFont font = new WriteFont();
|
|
|
font.setFontName("simsun");
|
|
|
- font.setFontHeightInPoints((short)10);
|
|
|
+ font.setFontHeightInPoints((short) 10);
|
|
|
font.setColor(IndexedColors.BLACK.index);
|
|
|
WriteCellStyle cellStyle = new WriteCellStyle();
|
|
|
cellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
|