weaver-hrm-salary/src/com/engine/salary/component/SalaryWeaTable.java

117 lines
4.8 KiB
Java
Raw Normal View History

2022-03-07 19:27:32 +08:00
package com.engine.salary.component;
import com.cloudstore.eccom.constant.WeaBoolAttr;
2022-03-10 17:57:46 +08:00
import com.cloudstore.eccom.pc.table.*;
2022-03-07 19:27:32 +08:00
import com.engine.salary.annotation.SalaryTable;
import com.engine.salary.annotation.SalaryTableColumn;
import com.engine.salary.annotation.SalaryTableOperate;
import org.apache.commons.lang3.StringUtils;
import weaver.general.PageIdConst;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class SalaryWeaTable<T> extends WeaTable {
public SalaryWeaTable(User user, Class clazz) {
boolean isAnno = clazz.isAnnotationPresent(SalaryTable.class);
if (isAnno) {
SalaryTable table = (SalaryTable) clazz.getAnnotation(SalaryTable.class);
String pageId = table.pageId();
super.setPageID(pageId);
String pageUid = pageId + "_" + user.getUID();
super.setPageUID(pageUid);
String pageSize = PageIdConst.getPageSize(pageId, user.getUID());
super.setPagesize(pageSize);
String backfields = table.fields();
super.setBackfields(backfields);
String sql = table.fromSql();
super.setSqlform(sql);
String where = table.where();
2022-03-10 17:57:46 +08:00
if (StringUtils.isNotBlank(where)) {
super.setSqlwhere(where);
}
2022-03-07 19:27:32 +08:00
String orderby = table.orderby();
2022-03-10 17:57:46 +08:00
if (StringUtils.isNotBlank(orderby)) {
super.setSqlorderby(orderby);
}
String groupby = table.groupby();
if (StringUtils.isNotBlank(groupby)) {
super.setSqlgroupby(groupby);
}
2022-03-07 19:27:32 +08:00
boolean distinct = table.distinct();
super.setSqlisdistinct(String.valueOf(distinct));
String primarykey = table.primarykey();
2022-03-10 17:57:46 +08:00
if (StringUtils.isNotBlank(primarykey)) {
super.setSqlprimarykey(primarykey);
}
2022-03-07 19:27:32 +08:00
SalaryTableOperate[] operates = table.operates();
if (operates != null && operates.length > 0) {
List<WeaTableOperate> operateList = new ArrayList<>();
Arrays.stream(operates).forEach(o -> {
String text = o.text();
int labelId = o.labelId();
String htmlLabelName = SystemEnv.getHtmlLabelName(labelId, user.getLanguage());
if (StringUtils.isNotBlank(htmlLabelName)) {
text = htmlLabelName;
}
WeaTableOperate weaTableOperate = new WeaTableOperate(text, o.href(), o.index());
operateList.add(weaTableOperate);
});
WeaTableOperates weaTableOperates = new WeaTableOperates();
weaTableOperates.setOperate(operateList);
super.setOperates(weaTableOperates);
}
2022-03-11 15:47:08 +08:00
WeaTableType weaTableTypeEnum = table.tableType();
2022-03-07 19:27:32 +08:00
//设置check是否可用
2022-03-11 15:47:08 +08:00
if (weaTableTypeEnum == WeaTableType.CHECKBOX) {
super.setTableType(weaTableTypeEnum);
// WeaTableCheckboxpopedom checkboxpopedom = new WeaTableCheckboxpopedom();
// checkboxpopedom.setShowmethod("true");
// super.setCheckboxpopedom(checkboxpopedom);
2022-03-10 17:57:46 +08:00
}
2022-03-07 19:27:32 +08:00
}
Field[] fields = clazz.getDeclaredFields();
for (Field f : fields) {
boolean isanno = f.isAnnotationPresent(SalaryTableColumn.class);
if (isanno) {
SalaryTableColumn columnAnn = f.getAnnotation(SalaryTableColumn.class);
String text = columnAnn.text();
int labelId = columnAnn.labelId();
String htmlLabelName = SystemEnv.getHtmlLabelName(labelId, user.getLanguage());
if (StringUtils.isNotBlank(htmlLabelName)) {
text = htmlLabelName;
}
String width = columnAnn.width();
String column = columnAnn.column();
String orderkey = columnAnn.orderkey();
boolean display = columnAnn.display();
WeaTableColumn weaTableColumn = new WeaTableColumn(width, text, column, orderkey);
2022-03-08 15:40:26 +08:00
String transmethod = columnAnn.transmethod();
2022-03-10 17:57:46 +08:00
if (StringUtils.isNotBlank(transmethod)) {
2022-03-08 15:40:26 +08:00
weaTableColumn.setTransmethod(transmethod);
}
String otherPara = columnAnn.otherPara();
if(StringUtils.isNotBlank(otherPara)) {
weaTableColumn.setOtherpara(otherPara);
}
2022-03-07 19:27:32 +08:00
if (!display) {
weaTableColumn.setDisplay(WeaBoolAttr.FALSE);
}
super.getColumns().add(weaTableColumn);
}
}
}
}