代码规范修改

This commit is contained in:
haozq 2024-02-28 09:51:41 +08:00
parent 0df66f733c
commit 6d41c1ddef
7 changed files with 105 additions and 74 deletions

View File

@ -311,14 +311,14 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
} }
curreCharIsUpperCase = Character.isUpperCase(c); curreCharIsUpperCase = Character.isUpperCase(c);
boolean isB=((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase);
if (i < (str.length() - 1)) { if (i < (str.length() - 1)) {
nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1)); nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1));
} }
if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) { if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) {
sb.append(SEPARATOR); sb.append(SEPARATOR);
} else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase) { } else if (isB) {
sb.append(SEPARATOR); sb.append(SEPARATOR);
} }
sb.append(Character.toLowerCase(c)); sb.append(Character.toLowerCase(c));

View File

@ -312,50 +312,8 @@ public class ExcelUtil<T>
Excel attr = (Excel) entry.getValue()[1]; Excel attr = (Excel) entry.getValue()[1];
// 取得类型,并根据对象类型设置值. // 取得类型,并根据对象类型设置值.
Class<?> fieldType = field.getType(); Class<?> fieldType = field.getType();
if (String.class == fieldType) { val=fileTypeSetData(fieldType,field,val);
String s = Convert.toStr(val); fileTypeIsNotNull(fieldType,field,attr,val,entity);
if (StringUtils.endsWith(s, ".0")) {
val = StringUtils.substringBefore(s, ".0");
} else {
String dateFormat = field.getAnnotation(Excel.class).dateFormat();
if (StringUtils.isNotEmpty(dateFormat)) {
val = parseDateToStr(dateFormat, val);
} else {
val = Convert.toStr(val);
}
}
}
else if ((Integer.TYPE == fieldType || Integer.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val))) {
val = Convert.toInt(val);
} else if ((Long.TYPE == fieldType || Long.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val))) {
val = Convert.toLong(val);
} else if (Double.TYPE == fieldType || Double.class == fieldType) {
val = Convert.toDouble(val);
} else if (Float.TYPE == fieldType || Float.class == fieldType) {
val = Convert.toFloat(val);
} else if (BigDecimal.class == fieldType) {
val = Convert.toBigDecimal(val);
} else if (Date.class == fieldType) {
if (val instanceof String) {
val = DateTimeHelper.parseDates(val);
} else if (val instanceof Double) {
val = DateUtil.getJavaDate((Double) val);
}
} else if (Boolean.TYPE == fieldType || Boolean.class == fieldType) {
val = Convert.toBool(val, false);
}if (StringUtils.isNotNull(fieldType)) {
String propertyName = field.getName();
if (StringUtils.isNotEmpty(attr.targetAttr())) {
propertyName = field.getName() + "." + attr.targetAttr();
} else if (StringUtils.isNotEmpty(attr.readConverterExp())) {
val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator());
}
else if (!attr.handler().equals(ExcelHandlerAdapter.class))
{
val = dataFormatHandlerAdapter(val, attr);
}
ReflectUtils.invokeSetter(entity, propertyName, val);
}
} }
list.add(entity); list.add(entity);
} }
@ -363,6 +321,64 @@ public class ExcelUtil<T>
return list; return list;
} }
public static String endIndex=".0";
public Object fileTypeSetData(Class<?> fieldType,Field field, Object val){
boolean isNum=StringUtils.isNumeric(Convert.toStr(val));
boolean isLong=(Long.TYPE == fieldType || Long.class == fieldType);
boolean isInt=(Integer.TYPE == fieldType || Integer.class == fieldType);
if (String.class == fieldType) {
String s = Convert.toStr(val);
if (StringUtils.endsWith(s, endIndex)) {
val = StringUtils.substringBefore(s, endIndex);
} else {
String dateFormat = field.getAnnotation(Excel.class).dateFormat();
if (StringUtils.isNotEmpty(dateFormat)) {
val = parseDateToStr(dateFormat, val);
} else {
val = Convert.toStr(val);
}
}
} else if (isInt && isNum) {
val = Convert.toInt(val);
} else if (isLong && isNum) {
val = Convert.toLong(val);
} else if (Double.TYPE == fieldType || Double.class == fieldType) {
val = Convert.toDouble(val);
} else if (Float.TYPE == fieldType || Float.class == fieldType) {
val = Convert.toFloat(val);
} else if (BigDecimal.class == fieldType) {
val = Convert.toBigDecimal(val);
} else if (Date.class == fieldType) {
if (val instanceof String) {
val = DateTimeHelper.parseDates(val);
} else if (val instanceof Double) {
val = DateUtil.getJavaDate((Double) val);
}
} else if (Boolean.TYPE == fieldType || Boolean.class == fieldType) {
val = Convert.toBool(val, false);
}
return val;
}
public void fileTypeIsNotNull( Class<?> type,Field field, Excel attr, Object val, T entity) {
if(StringUtils.isNotNull(type)){
String propertyName = field.getName();
if (StringUtils.isNotEmpty(attr.targetAttr())) {
propertyName = field.getName() + "." + attr.targetAttr();
} else if (StringUtils.isNotEmpty(attr.readConverterExp())) {
val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator());
}
else if (!attr.handler().equals(ExcelHandlerAdapter.class))
{
val = dataFormatHandlerAdapter(val, attr);
}
ReflectUtils.invokeSetter(entity, propertyName, val);
}
}
/** /**
* 对list数据源将其里面的数据导入到excel表单 * 对list数据源将其里面的数据导入到excel表单
* *
@ -1175,10 +1191,12 @@ public class ExcelUtil<T>
if (field.isAnnotationPresent(Excel.class)) if (field.isAnnotationPresent(Excel.class))
{ {
Excel attr = field.getAnnotation(Excel.class); Excel attr = field.getAnnotation(Excel.class);
if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) if (attr != null) {
{ boolean typeTrue=(attr.type() == Type.ALL || attr.type() == type);
field.setAccessible(true); if(typeTrue){
fields.add(new Object[] { field, attr }); field.setAccessible(true);
fields.add(new Object[] { field, attr });
}
} }
if (Collection.class.isAssignableFrom(field.getType())) if (Collection.class.isAssignableFrom(field.getType()))
{ {
@ -1188,19 +1206,19 @@ public class ExcelUtil<T>
this.subFields = FieldUtils.getFieldsListWithAnnotation(subClass, Excel.class); this.subFields = FieldUtils.getFieldsListWithAnnotation(subClass, Excel.class);
} }
} }
// 多注解 // 多注解
if (field.isAnnotationPresent(Excels.class)) if (field.isAnnotationPresent(Excels.class)) {
{
Excels attrs = field.getAnnotation(Excels.class); Excels attrs = field.getAnnotation(Excels.class);
Excel[] excels = attrs.value(); Excel[] excels = attrs.value();
for (Excel attr : excels) for (Excel attr : excels) {
{ if (attr != null) {
if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) boolean typeTrue=(attr.type() == Type.ALL || attr.type() == type);
{ if(typeTrue){
field.setAccessible(true); field.setAccessible(true);
fields.add(new Object[] { field, attr }); fields.add(new Object[] { field, attr });
}
} }
} }
} }
} }

View File

@ -306,12 +306,14 @@ public class ReflectUtils
/** /**
* 改变private/protected的方法为public尽量不调用实际改动的语句避免JDK的SecurityManager抱怨 * 改变private/protected的方法为public尽量不调用实际改动的语句避免JDK的SecurityManager抱怨
*/ */
public static void makeAccessible(Method method) public static void makeAccessible(Method method) {
{ boolean isPublic=!Modifier.isPublic(method.getModifiers());
if ((!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers())) boolean isPublic2=!Modifier.isPublic(method.getDeclaringClass().getModifiers());
&& !method.isAccessible()) if (isPublic || isPublic2) {
{ if(!method.isAccessible()){
method.setAccessible(true); method.setAccessible(true);
}
} }
} }
@ -320,10 +322,14 @@ public class ReflectUtils
*/ */
public static void makeAccessible(Field field) public static void makeAccessible(Field field)
{ {
if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers()) boolean isPublic=!Modifier.isPublic(field.getModifiers());
|| Modifier.isFinal(field.getModifiers())) && !field.isAccessible()) boolean isPublic2=!Modifier.isPublic(field.getDeclaringClass().getModifiers());
{ boolean isPublic3=Modifier.isFinal(field.getModifiers());
field.setAccessible(true); if (isPublic || isPublic2 || isPublic3){
if(!field.isAccessible()){
field.setAccessible(true);
}
} }
} }

View File

@ -33,9 +33,10 @@ public class InnerAuthAspect implements Ordered
String userid = ServletUtils.getRequest().getHeader(SecurityConstants.DETAILS_USER_ID); String userid = ServletUtils.getRequest().getHeader(SecurityConstants.DETAILS_USER_ID);
String username = ServletUtils.getRequest().getHeader(SecurityConstants.DETAILS_USERNAME); String username = ServletUtils.getRequest().getHeader(SecurityConstants.DETAILS_USERNAME);
// 用户信息验证 // 用户信息验证
if (innerAuth.isUser() && (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username))) if (innerAuth.isUser()) {
{ if(StringUtils.isEmpty(userid) || StringUtils.isEmpty(username)){
throw new InnerAuthException("没有设置用户信息,不允许访问 "); throw new InnerAuthException("没有设置用户信息,不允许访问 ");
}
} }
return point.proceed(); return point.proceed();
} }

View File

@ -40,5 +40,11 @@ public interface ISelectService {
*/ */
AjaxResult getMenuTree(MenuDto dto); AjaxResult getMenuTree(MenuDto dto);
/**
* 查询字典集合
* code 上级节点编码 null市查询全部
* @param code
* @return
*/
AjaxResult getDictList(Integer code); AjaxResult getDictList(Integer code);
} }

View File

@ -197,7 +197,7 @@ public class DictServiceImpl implements DictService {
*/ */
private List<DictVo> fromTree(DictVo dictVo, List<DictVo> list) { private List<DictVo> fromTree(DictVo dictVo, List<DictVo> list) {
return list.stream() return list.stream()
.filter(ele -> dictVo.getDictCode()==ele.getPidCode()) .filter(ele -> dictVo.getDictCode().toString().equals(ele.getPidCode().toString()))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
} }

View File

@ -59,7 +59,7 @@ public class OrgServiceImpl implements OrgService{
static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) { static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
Map<Object, Boolean> seen = new ConcurrentHashMap<>(); Map<Object, Boolean> seen = new ConcurrentHashMap<>(30);
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null; return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
} }
/** /**