|
@@ -13,6 +13,8 @@ import kd.bos.orm.query.QCP;
|
|
|
import kd.bos.orm.query.QFilter;
|
|
import kd.bos.orm.query.QFilter;
|
|
|
import kd.bos.print.core.data.DataRowSet;
|
|
import kd.bos.print.core.data.DataRowSet;
|
|
|
import kd.bos.print.core.data.datasource.CustomDataSource;
|
|
import kd.bos.print.core.data.datasource.CustomDataSource;
|
|
|
|
|
+import kd.bos.print.core.data.datasource.MainDataSource;
|
|
|
|
|
+import kd.bos.print.core.data.datasource.PrtDataSource;
|
|
|
import kd.bos.print.core.data.field.CollectionField;
|
|
import kd.bos.print.core.data.field.CollectionField;
|
|
|
import kd.bos.print.core.data.field.Field;
|
|
import kd.bos.print.core.data.field.Field;
|
|
|
import kd.bos.print.core.data.field.IntegerField;
|
|
import kd.bos.print.core.data.field.IntegerField;
|
|
@@ -46,6 +48,9 @@ import java.util.Map;
|
|
|
*/
|
|
*/
|
|
|
public class EmployeePrintPlugin extends AbstractPrintPlugin implements Plugin {
|
|
public class EmployeePrintPlugin extends AbstractPrintPlugin implements Plugin {
|
|
|
|
|
|
|
|
|
|
+ //记录主数据源
|
|
|
|
|
+ private MainDataSource mainDataSource;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void loadCustomData(CustomDataLoadEvent evt) {
|
|
public void loadCustomData(CustomDataLoadEvent evt) {
|
|
|
Date printYear = HRAppCache.get("nckd_pm").get("printYear", Date.class);
|
|
Date printYear = HRAppCache.get("nckd_pm").get("printYear", Date.class);
|
|
@@ -104,109 +109,113 @@ public class EmployeePrintPlugin extends AbstractPrintPlugin implements Plugin {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void afterLoadData(AfterLoadDataEvent evt) {
|
|
public void afterLoadData(AfterLoadDataEvent evt) {
|
|
|
- String dsName = evt.getDataSource().getDsName();
|
|
|
|
|
- if(!dsName.contains("custom")) {
|
|
|
|
|
- Date printYear = HRAppCache.get("nckd_pm").get("printYear", Date.class);
|
|
|
|
|
- Map<Integer, Long> selectPrintPersonIdMap = HRAppCache.get("nckd_pm").get("employeePrintIdMap", Map.class);
|
|
|
|
|
- if(selectPrintPersonIdMap == null){
|
|
|
|
|
- throw new ValidationException("请选择要打印的日期!");
|
|
|
|
|
- }
|
|
|
|
|
- List<String> seqs = ConvertUtil.toList(selectPrintPersonIdMap.keySet(), ArrayList::new);
|
|
|
|
|
- LocalDate now = LocalDate.now();
|
|
|
|
|
- // 获取5年前的年份
|
|
|
|
|
- int fiveYearsAgo = LocalDate.now().minusYears(5).getYear();
|
|
|
|
|
- Date beginDate = DateUtil.toDate(LocalDate.of(fiveYearsAgo, 1, 1));
|
|
|
|
|
-
|
|
|
|
|
- int currentYear = LocalDate.now().getYear() - 1; // 不包含今年
|
|
|
|
|
- Date endDate = DateUtil.toDate(LocalDate.of(currentYear, 1, 1));
|
|
|
|
|
-
|
|
|
|
|
- Map<String, String> positionMap = new HashMap<>();
|
|
|
|
|
- Map<String, Integer> perfRankMgmtMap = new HashMap<>();
|
|
|
|
|
- try (AlgoContext context = Algo.newContext()) {
|
|
|
|
|
- Collection<Long> personIds = selectPrintPersonIdMap.values();
|
|
|
|
|
- DataSet positionDateSet = getPositions(fiveYearsAgo, currentYear, personIds);
|
|
|
|
|
- if (positionDateSet != null) {
|
|
|
|
|
- while (positionDateSet.hasNext()) {
|
|
|
|
|
- Row next = positionDateSet.next();
|
|
|
|
|
- Long personId = next.getLong(String.join(".", FormConstant.EMPLOYEE_KEY, FormConstant.ID_KEY));
|
|
|
|
|
- int tempIndex = 1;
|
|
|
|
|
- for (int year = fiveYearsAgo; year <= currentYear; year++) {
|
|
|
|
|
- String positionName = next.getString("position_" + tempIndex);
|
|
|
|
|
- positionMap.put(personId + "nckd_position_" + tempIndex, positionName);
|
|
|
|
|
- tempIndex++;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ PrtDataSource dataSource = evt.getDataSource();
|
|
|
|
|
+ if(!(dataSource instanceof MainDataSource)){
|
|
|
|
|
+ return;//非主数据源,立即返回
|
|
|
|
|
+ }
|
|
|
|
|
+ //记录主数据源,用于自定义数据源查询时,获取需要的信息
|
|
|
|
|
+ mainDataSource = (MainDataSource) dataSource;
|
|
|
|
|
+ Date printYear = HRAppCache.get("nckd_pm").get("printYear", Date.class);
|
|
|
|
|
+ Map<Integer, Long> selectPrintPersonIdMap = HRAppCache.get("nckd_pm").get("employeePrintIdMap", Map.class);
|
|
|
|
|
+ if(selectPrintPersonIdMap == null){
|
|
|
|
|
+ throw new ValidationException("请选择要打印的日期!");
|
|
|
|
|
+ }
|
|
|
|
|
+ List<String> seqs = ConvertUtil.toList(selectPrintPersonIdMap.keySet(), ArrayList::new);
|
|
|
|
|
+ LocalDate now = LocalDate.now();
|
|
|
|
|
+ // 获取5年前的年份
|
|
|
|
|
+ int fiveYearsAgo = LocalDate.now().minusYears(5).getYear();
|
|
|
|
|
+ Date beginDate = DateUtil.toDate(LocalDate.of(fiveYearsAgo, 1, 1));
|
|
|
|
|
+
|
|
|
|
|
+ int currentYear = LocalDate.now().getYear() - 1; // 不包含今年
|
|
|
|
|
+ Date endDate = DateUtil.toDate(LocalDate.of(currentYear, 1, 1));
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, String> positionMap = new HashMap<>();
|
|
|
|
|
+ Map<String, Integer> perfRankMgmtMap = new HashMap<>();
|
|
|
|
|
+ try (AlgoContext context = Algo.newContext()) {
|
|
|
|
|
+ Collection<Long> personIds = selectPrintPersonIdMap.values();
|
|
|
|
|
+ DataSet positionDateSet = getPositions(fiveYearsAgo, currentYear, personIds);
|
|
|
|
|
+ if (positionDateSet != null) {
|
|
|
|
|
+ while (positionDateSet.hasNext()) {
|
|
|
|
|
+ Row next = positionDateSet.next();
|
|
|
|
|
+ Long personId = next.getLong(String.join(".", FormConstant.EMPLOYEE_KEY, FormConstant.ID_KEY));
|
|
|
|
|
+ int tempIndex = 1;
|
|
|
|
|
+ for (int year = fiveYearsAgo; year <= currentYear; year++) {
|
|
|
|
|
+ String positionName = next.getString("position_" + tempIndex);
|
|
|
|
|
+ positionMap.put(personId + "nckd_position_" + tempIndex, positionName);
|
|
|
|
|
+ tempIndex++;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- DataSet perfRankMgmtDataSet = getPerfRankMgmt(personIds, fiveYearsAgo, currentYear);
|
|
|
|
|
- if (perfRankMgmtDataSet != null) {
|
|
|
|
|
- while (perfRankMgmtDataSet.hasNext()) {
|
|
|
|
|
- Row next = perfRankMgmtDataSet.next();
|
|
|
|
|
- Long personId = next.getLong(String.join(".", FormConstant.NCKD_PERSON, FormConstant.ID_KEY));
|
|
|
|
|
- int tempIndex = 1;
|
|
|
|
|
- for (int year = fiveYearsAgo; year <= currentYear; year++) {
|
|
|
|
|
- Integer topran = next.getInteger("perfrank_topran_" + tempIndex);
|
|
|
|
|
- Integer topranks = next.getInteger("perfrank_topranks_" + tempIndex);
|
|
|
|
|
- perfRankMgmtMap.put(personId + "nckd_perfrank_topran_" + tempIndex, topran);
|
|
|
|
|
- perfRankMgmtMap.put(personId + "nckd_perfrank_topranks_" + tempIndex, topranks);
|
|
|
|
|
- tempIndex++;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ DataSet perfRankMgmtDataSet = getPerfRankMgmt(personIds, fiveYearsAgo, currentYear);
|
|
|
|
|
+ if (perfRankMgmtDataSet != null) {
|
|
|
|
|
+ while (perfRankMgmtDataSet.hasNext()) {
|
|
|
|
|
+ Row next = perfRankMgmtDataSet.next();
|
|
|
|
|
+ Long personId = next.getLong(String.join(".", FormConstant.NCKD_PERSON, FormConstant.ID_KEY));
|
|
|
|
|
+ int tempIndex = 1;
|
|
|
|
|
+ for (int year = fiveYearsAgo; year <= currentYear; year++) {
|
|
|
|
|
+ Integer topran = next.getInteger("perfrank_topran_" + tempIndex);
|
|
|
|
|
+ Integer topranks = next.getInteger("perfrank_topranks_" + tempIndex);
|
|
|
|
|
+ perfRankMgmtMap.put(personId + "nckd_perfrank_topran_" + tempIndex, topran);
|
|
|
|
|
+ perfRankMgmtMap.put(personId + "nckd_perfrank_topranks_" + tempIndex, topranks);
|
|
|
|
|
+ tempIndex++;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
- // 获取当前打印的数据集并准备过滤后的集合
|
|
|
|
|
- // 2. 获取当前打印的数据集
|
|
|
|
|
- List<DataRowSet> dataRowSets = evt.getDataRowSets();
|
|
|
|
|
- List<DataRowSet> filteredDataRowSets = new ArrayList<>();
|
|
|
|
|
-
|
|
|
|
|
- for (DataRowSet dataRowSet : dataRowSets) {
|
|
|
|
|
- if (dataRowSet.containerKey("reportEntry")) {
|
|
|
|
|
- CollectionField entryField = (CollectionField) dataRowSet.getField("reportEntry");
|
|
|
|
|
- List<DataRowSet> entryRows = entryField.getValue();
|
|
|
|
|
- List<DataRowSet> filteredEntryRows = new ArrayList<>();
|
|
|
|
|
- for (DataRowSet entryRow : entryRows) {
|
|
|
|
|
- String seq = ConvertUtil.toStr(entryRow.getField(FormConstant.SEQ_KEY).getValue());
|
|
|
|
|
- Long personId = selectPrintPersonIdMap.get(seq + "");
|
|
|
|
|
- // 判断该分录行是否在用户勾选的列表中
|
|
|
|
|
- if (seqs.contains(seq)) {
|
|
|
|
|
- for (String fieldKey : entryRow.getFieldKeys()) {
|
|
|
|
|
- if (fieldKey.startsWith("nckd_position_")) {
|
|
|
|
|
- String positionName = positionMap.get(personId + fieldKey);
|
|
|
|
|
- Field field = entryRow.getField(fieldKey);
|
|
|
|
|
- field.setValue(positionName != null ? positionName : "");
|
|
|
|
|
- entryRow.put(fieldKey, field);
|
|
|
|
|
- }
|
|
|
|
|
- if (fieldKey.startsWith("nckd_perfrank_topran_")) {
|
|
|
|
|
- Integer perfRankMgmt = perfRankMgmtMap.get(personId + fieldKey);
|
|
|
|
|
- Field field = entryRow.getField(fieldKey);
|
|
|
|
|
- field.setValue(perfRankMgmt != null ? perfRankMgmt : 0);
|
|
|
|
|
- entryRow.put(fieldKey, field);
|
|
|
|
|
- }
|
|
|
|
|
- if (fieldKey.startsWith("nckd_perfrank_topranks_")) {
|
|
|
|
|
- Integer perfRankMgmt = perfRankMgmtMap.get(personId + fieldKey);
|
|
|
|
|
- Field field = entryRow.getField(fieldKey);
|
|
|
|
|
- field.setValue(perfRankMgmt != null ? perfRankMgmt : 0);
|
|
|
|
|
- entryRow.put(fieldKey, field);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 获取当前打印的数据集并准备过滤后的集合
|
|
|
|
|
+ // 2. 获取当前打印的数据集
|
|
|
|
|
+ List<DataRowSet> dataRowSets = evt.getDataRowSets();
|
|
|
|
|
+ List<DataRowSet> filteredDataRowSets = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ for (DataRowSet dataRowSet : dataRowSets) {
|
|
|
|
|
+ if (dataRowSet.containerKey("reportEntry")) {
|
|
|
|
|
+ CollectionField entryField = (CollectionField) dataRowSet.getField("reportEntry");
|
|
|
|
|
+ List<DataRowSet> entryRows = entryField.getValue();
|
|
|
|
|
+ List<DataRowSet> filteredEntryRows = new ArrayList<>();
|
|
|
|
|
+ for (DataRowSet entryRow : entryRows) {
|
|
|
|
|
+ String seq = ConvertUtil.toStr(entryRow.getField(FormConstant.SEQ_KEY).getValue());
|
|
|
|
|
+ Long personId = selectPrintPersonIdMap.get(seq + "");
|
|
|
|
|
+ // 判断该分录行是否在用户勾选的列表中
|
|
|
|
|
+ if (seqs.contains(seq)) {
|
|
|
|
|
+ for (String fieldKey : entryRow.getFieldKeys()) {
|
|
|
|
|
+ if (fieldKey.startsWith("nckd_position_")) {
|
|
|
|
|
+ String positionName = positionMap.get(personId + fieldKey);
|
|
|
|
|
+ Field field = entryRow.getField(fieldKey);
|
|
|
|
|
+ field.setValue(positionName != null ? positionName : "");
|
|
|
|
|
+ entryRow.put(fieldKey, field);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (fieldKey.startsWith("nckd_perfrank_topran_")) {
|
|
|
|
|
+ Integer perfRankMgmt = perfRankMgmtMap.get(personId + fieldKey);
|
|
|
|
|
+ Field field = entryRow.getField(fieldKey);
|
|
|
|
|
+ field.setValue(perfRankMgmt != null ? perfRankMgmt : 0);
|
|
|
|
|
+ entryRow.put(fieldKey, field);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (fieldKey.startsWith("nckd_perfrank_topranks_")) {
|
|
|
|
|
+ Integer perfRankMgmt = perfRankMgmtMap.get(personId + fieldKey);
|
|
|
|
|
+ Field field = entryRow.getField(fieldKey);
|
|
|
|
|
+ field.setValue(perfRankMgmt != null ? perfRankMgmt : 0);
|
|
|
|
|
+ entryRow.put(fieldKey, field);
|
|
|
}
|
|
}
|
|
|
- filteredEntryRows.add(entryRow);
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- // 用过滤后的分录数据替换原数据
|
|
|
|
|
- if (!filteredEntryRows.isEmpty()) {
|
|
|
|
|
- DataRowSet newDataRowSet = dataRowSet.deepCopy(); // 深拷贝,避免影响原数据
|
|
|
|
|
- newDataRowSet.put("reportEntry", new CollectionField(filteredEntryRows));
|
|
|
|
|
- filteredDataRowSets.add(newDataRowSet);
|
|
|
|
|
|
|
+ filteredEntryRows.add(entryRow);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ // 用过滤后的分录数据替换原数据
|
|
|
|
|
+ if (!filteredEntryRows.isEmpty()) {
|
|
|
|
|
+ DataRowSet newDataRowSet = dataRowSet.deepCopy(); // 深拷贝,避免影响原数据
|
|
|
|
|
+ newDataRowSet.put("reportEntry", new CollectionField(filteredEntryRows));
|
|
|
|
|
+ filteredDataRowSets.add(newDataRowSet);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // 将过滤后的数据集设置回事件,实现只打印勾选行
|
|
|
|
|
- evt.setDataRowSets(filteredDataRowSets);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 将过滤后的数据集设置回事件,实现只打印勾选行
|
|
|
|
|
+ evt.setDataRowSets(filteredDataRowSets);
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|