Excel注解新增属性comboReadDict
This commit is contained in:
parent
161cd2b1ea
commit
bc7a607033
@ -88,6 +88,11 @@ public @interface Excel
|
||||
*/
|
||||
public String[] combo() default {};
|
||||
|
||||
/**
|
||||
* 是否从字典读数据到combo,默认不读取,如读取需要设置dictType注解.
|
||||
*/
|
||||
public boolean comboReadDict() default false;
|
||||
|
||||
/**
|
||||
* 是否需要纵向合并单元格,应对需求:含有list集合单元格)
|
||||
*/
|
||||
|
@ -91,9 +91,10 @@ public class DictUtils
|
||||
{
|
||||
StringBuilder propertyString = new StringBuilder();
|
||||
List<SysDictData> datas = getDictCache(dictType);
|
||||
|
||||
if (StringUtils.isNotNull(datas))
|
||||
if (StringUtils.isNull(datas))
|
||||
{
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
if (StringUtils.containsAny(separator, dictValue))
|
||||
{
|
||||
for (SysDictData dict : datas)
|
||||
@ -118,7 +119,6 @@ public class DictUtils
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return StringUtils.stripEnd(propertyString.toString(), separator);
|
||||
}
|
||||
|
||||
@ -134,8 +134,11 @@ public class DictUtils
|
||||
{
|
||||
StringBuilder propertyString = new StringBuilder();
|
||||
List<SysDictData> datas = getDictCache(dictType);
|
||||
|
||||
if (StringUtils.containsAny(separator, dictLabel) && StringUtils.isNotEmpty(datas))
|
||||
if (StringUtils.isNull(datas))
|
||||
{
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
if (StringUtils.containsAny(separator, dictLabel))
|
||||
{
|
||||
for (SysDictData dict : datas)
|
||||
{
|
||||
@ -162,6 +165,48 @@ public class DictUtils
|
||||
return StringUtils.stripEnd(propertyString.toString(), separator);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典类型获取字典所有值
|
||||
*
|
||||
* @param dictType 字典类型
|
||||
* @return 字典值
|
||||
*/
|
||||
public static String getDictValues(String dictType)
|
||||
{
|
||||
StringBuilder propertyString = new StringBuilder();
|
||||
List<SysDictData> datas = getDictCache(dictType);
|
||||
if (StringUtils.isNull(datas))
|
||||
{
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
for (SysDictData dict : datas)
|
||||
{
|
||||
propertyString.append(dict.getDictValue()).append(SEPARATOR);
|
||||
}
|
||||
return StringUtils.stripEnd(propertyString.toString(), SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典类型获取字典所有标签
|
||||
*
|
||||
* @param dictType 字典类型
|
||||
* @return 字典值
|
||||
*/
|
||||
public static String getDictLabels(String dictType)
|
||||
{
|
||||
StringBuilder propertyString = new StringBuilder();
|
||||
List<SysDictData> datas = getDictCache(dictType);
|
||||
if (StringUtils.isNull(datas))
|
||||
{
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
for (SysDictData dict : datas)
|
||||
{
|
||||
propertyString.append(dict.getDictLabel()).append(SEPARATOR);
|
||||
}
|
||||
return StringUtils.stripEnd(propertyString.toString(), SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定字典缓存
|
||||
*
|
||||
|
@ -1042,17 +1042,28 @@ public class ExcelUtil<T>
|
||||
// 设置列宽
|
||||
sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(attr.prompt()) || attr.combo().length > 0)
|
||||
if (StringUtils.isNotEmpty(attr.prompt()) || attr.combo().length > 0 || attr.comboReadDict())
|
||||
{
|
||||
if (attr.combo().length > 15 || StringUtils.join(attr.combo()).length() > 255)
|
||||
String[] comboArray = attr.combo();
|
||||
if (attr.comboReadDict())
|
||||
{
|
||||
if (!sysDictMap.containsKey("combo_" + attr.dictType()))
|
||||
{
|
||||
String labels = DictUtils.getDictLabels(attr.dictType());
|
||||
sysDictMap.put("combo_" + attr.dictType(), labels);
|
||||
}
|
||||
String val = sysDictMap.get("combo_" + attr.dictType());
|
||||
comboArray = StringUtils.split(val, DictUtils.SEPARATOR);
|
||||
}
|
||||
if (comboArray.length > 15 || StringUtils.join(comboArray).length() > 255)
|
||||
{
|
||||
// 如果下拉数大于15或字符串长度大于255,则使用一个新sheet存储,避免生成的模板下拉值获取不到
|
||||
setXSSFValidationWithHidden(sheet, attr.combo(), attr.prompt(), 1, 100, column, column);
|
||||
setXSSFValidationWithHidden(sheet, comboArray, attr.prompt(), 1, 100, column, column);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 提示信息或只能选择不能输入的列内容.
|
||||
setPromptOrValidation(sheet, attr.combo(), attr.prompt(), 1, 100, column, column);
|
||||
setPromptOrValidation(sheet, comboArray, attr.prompt(), 1, 100, column, column);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user