代码规范修改

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);
boolean isB=((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase);
if (i < (str.length() - 1)) {
nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1));
}
if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) {
sb.append(SEPARATOR);
} else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase) {
} else if (isB) {
sb.append(SEPARATOR);
}
sb.append(Character.toLowerCase(c));

View File

@ -312,10 +312,27 @@ public class ExcelUtil<T>
Excel attr = (Excel) entry.getValue()[1];
// 取得类型,并根据对象类型设置值.
Class<?> fieldType = field.getType();
val=fileTypeSetData(fieldType,field,val);
fileTypeIsNotNull(fieldType,field,attr,val,entity);
}
list.add(entity);
}
}
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, ".0")) {
val = StringUtils.substringBefore(s, ".0");
if (StringUtils.endsWith(s, endIndex)) {
val = StringUtils.substringBefore(s, endIndex);
} else {
String dateFormat = field.getAnnotation(Excel.class).dateFormat();
if (StringUtils.isNotEmpty(dateFormat)) {
@ -324,10 +341,9 @@ public class ExcelUtil<T>
val = Convert.toStr(val);
}
}
}
else if ((Integer.TYPE == fieldType || Integer.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val))) {
} else if (isInt && isNum) {
val = Convert.toInt(val);
} else if ((Long.TYPE == fieldType || Long.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val))) {
} else if (isLong && isNum) {
val = Convert.toLong(val);
} else if (Double.TYPE == fieldType || Double.class == fieldType) {
val = Convert.toDouble(val);
@ -343,7 +359,12 @@ public class ExcelUtil<T>
}
} else if (Boolean.TYPE == fieldType || Boolean.class == fieldType) {
val = Convert.toBool(val, false);
}if (StringUtils.isNotNull(fieldType)) {
}
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();
@ -357,11 +378,6 @@ public class ExcelUtil<T>
ReflectUtils.invokeSetter(entity, propertyName, val);
}
}
list.add(entity);
}
}
return list;
}
/**
* 对list数据源将其里面的数据导入到excel表单
@ -1175,11 +1191,13 @@ public class ExcelUtil<T>
if (field.isAnnotationPresent(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);
if(typeTrue){
field.setAccessible(true);
fields.add(new Object[] { field, attr });
}
}
if (Collection.class.isAssignableFrom(field.getType()))
{
subMethod = getSubMethod(field.getName(), clazz);
@ -1188,20 +1206,20 @@ public class ExcelUtil<T>
this.subFields = FieldUtils.getFieldsListWithAnnotation(subClass, Excel.class);
}
}
// 多注解
if (field.isAnnotationPresent(Excels.class))
{
if (field.isAnnotationPresent(Excels.class)) {
Excels attrs = field.getAnnotation(Excels.class);
Excel[] excels = attrs.value();
for (Excel attr : excels)
{
if (attr != null && (attr.type() == Type.ALL || attr.type() == type))
{
for (Excel attr : excels) {
if (attr != null) {
boolean typeTrue=(attr.type() == Type.ALL || attr.type() == type);
if(typeTrue){
field.setAccessible(true);
fields.add(new Object[] { field, attr });
}
}
}
}
}
}

View File

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

View File

@ -33,10 +33,11 @@ public class InnerAuthAspect implements Ordered
String userid = ServletUtils.getRequest().getHeader(SecurityConstants.DETAILS_USER_ID);
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("没有设置用户信息,不允许访问 ");
}
}
return point.proceed();
}

View File

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

View File

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

View File

@ -59,7 +59,7 @@ public class OrgServiceImpl implements OrgService{
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;
}
/**