package com.kingdee.eas.custom.expandassess.service; import com.kingdee.bos.BOSException; import com.kingdee.bos.Context; import com.kingdee.bos.metadata.entity.*; import com.kingdee.bos.metadata.query.util.CompareType; import com.kingdee.eas.basedata.person.PersonInfo; import com.kingdee.eas.common.EASBizException; import com.kingdee.eas.custom.expandassess.*; import com.kingdee.eas.custom.expandassess.app.AssessRatingEnum; import com.kingdee.eas.custom.expandassess.app.ExpandStatusEunm; import com.kingdee.eas.custom.expandassess.app.PeriodStatusEnum; import com.kingdee.eas.custom.performancenew.app.scoreEnum; import com.kingdee.eas.framework.CoreBaseInfo; import com.kingdee.eas.util.app.ContextUtil; import com.kingdee.shr.base.syssetting.app.io.fileImport.BaseColumnInfo; import com.kingdee.shr.base.syssetting.app.io.fileImport.BaseImportService; import com.kingdee.shr.base.syssetting.app.io.fileImport.BaseRowInfo; import com.kingdee.shr.base.syssetting.app.io.fileImport.ImportException; import com.kingdee.shr.ml.util.SHRServerResource; import com.kingdee.util.StringUtils; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.math.BigDecimal; import java.util.HashMap; import java.util.Iterator; import java.util.Map; /** * @author qingwu * @date 2024/5/27 * @apiNote */ public class ExpandAssessFZRImportService extends BaseImportService { private static final SelectorItemCollection SIC = new SelectorItemCollection(); private static final SelectorItemCollection UPDATESIC = new SelectorItemCollection(); static { SIC.add("adminorg.name"); SIC.add("assessor.name"); SIC.add("principal.name"); SIC.add("remark"); SIC.add("checkrate"); SIC.add("assessrate"); SIC.add("oneLift"); SIC.add("shareliftres"); SIC.add("shareliftzy"); SIC.add("shareliftlc"); SIC.add("unitelift"); UPDATESIC.add("checkrate"); UPDATESIC.add("remark"); UPDATESIC.add("oneLift"); UPDATESIC.add("shareliftres"); UPDATESIC.add("shareliftzy"); UPDATESIC.add("shareliftlc"); UPDATESIC.add("unitelift"); UPDATESIC.add("contracts"); } @Override protected void verifyRow(BaseRowInfo row) throws ImportException { super.verifyRow(row); String assessor = row.getValueOfString("assessor"); String adminOrg = row.getValueOfString("adminOrg"); PersonInfo principal = (PersonInfo) row.getValueOfObject("principal"); String parentId = getCustomParam("parentId"); Context ctx = getContext(); String currentPersonId = ContextUtil.getCurrentUserInfo(ctx).getPerson().getId().toString(); if (!currentPersonId.equals(principal.getId().toString())) { throw new ImportException("负责人不是当前登录人,导入失败!!"); } if (!StringUtils.isEmpty(assessor) && !StringUtils.isEmpty(adminOrg)) { try { IExpandAssessEntry iExpandAssessEntry = ExpandAssessEntryFactory.getLocalInstance(getContext()); FilterInfo filterInfo = new FilterInfo(); filterInfo.getFilterItems().add(new FilterItemInfo("assessor.name", assessor)); filterInfo.getFilterItems().add(new FilterItemInfo("adminOrg.name", adminOrg)); filterInfo.getFilterItems().add(new FilterItemInfo("parent.id", parentId)); SelectorItemCollection sic = new SelectorItemCollection(); sic.add("parent.periodStatus"); sic.add("asseStatus"); EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, sic, null); ExpandAssessEntryInfo entryInfo = iExpandAssessEntry.getExpandAssessEntryCollection(entityViewInfo).get(0); ExpandAssessInfo parent = entryInfo.getParent(); if (parent.getPeriodStatus() == PeriodStatusEnum.LOCK) { throw new ImportException("周期已锁定不可导入"); } if (entryInfo.getAsseStatus() == ExpandStatusEunm.PRINCIPALSUBMIT) { throw new ImportException("负责人已提交不可导入"); } } catch (BOSException e) { throw new ImportException(e); } } } @Override protected void submitData(CoreBaseInfo coreBaseInfo) throws ImportException { try { IExpandAssessEntry iExpandAssessEntry = ExpandAssessEntryFactory.getLocalInstance(getContext()); iExpandAssessEntry.updatePartial(coreBaseInfo, UPDATESIC); } catch (EASBizException var4) { ImportException importException = new ImportException(var4.getMessage(getContext().getLocale()), (Throwable) var4); throw importException; } catch (BOSException var5) { ImportException importException = new ImportException(SHRServerResource.getString("com.kingdee.shr.base.syssetting.CommonserviceResource", "save_fails_bos", getContext()), (Throwable) var5); throw importException; } catch (Exception var6) { ImportException importException = new ImportException(SHRServerResource.getString("com.kingdee.shr.base.syssetting.CommonserviceResource", "save_submit_fails", getContext()), var6); throw importException; } } /** * 模板生成完成后执行内容 * * @param columnInfoMap * @param wb * @param sheet */ @Override public void completeGenerateExcel(Map columnInfoMap, XSSFWorkbook wb, XSSFSheet sheet) { Context ctx = getContext(); String parentId = getCustomParam("parentId"); if (StringUtils.isEmpty(parentId)) { throw new RuntimeException("拓展人员考核周期ID不可为空!!"); } int beginRow = 4; try { //当前登录员工id String currentPersonId = ContextUtil.getCurrentUserInfo(ctx).getPerson().getId().toString(); //过滤当前周期状态为已启用排序评分人等于登录人的数据 FilterInfo filterInfo = new FilterInfo(); FilterItemCollection filterItems = filterInfo.getFilterItems(); filterItems.add(new FilterItemInfo("parent.id", parentId)); filterItems.add(new FilterItemInfo("asseStatus", "3")); filterItems.add(new FilterItemInfo("principal.id", currentPersonId)); //SorterItemCollection sorterItemCollection = new SorterItemCollection(); //sorterItemCollection.add(new SorterItemInfo("rankings")); EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, SIC, null); IExpandAssessEntry iExpandAssessEntry = ExpandAssessEntryFactory.getLocalInstance(getContext()); //绩效考核分录实体 ExpandAssessEntryCollection entryCollection = iExpandAssessEntry.getExpandAssessEntryCollection(entityViewInfo); Map columnIndexMap = getColumnIndexFn(columnInfoMap); int fillColumnCount = columnInfoMap.size(); for (int i = 0; i < entryCollection.size(); i++) { XSSFRow xSSFRow = sheet.createRow(i + beginRow); ExpandAssessEntryInfo expandAssessEntryInfo = entryCollection.get(i); for (int j = 0; j < fillColumnCount; j++) { String value = null; Cell createCell = xSSFRow.createCell(j); String columnName = columnIndexMap.get(Integer.valueOf(j)); Object obj = expandAssessEntryInfo.get(columnName); if (obj != null) { if (obj instanceof CoreBaseInfo) { CoreBaseInfo coreBaseInfo = (CoreBaseInfo) expandAssessEntryInfo.get(columnName); //value = coreBaseInfo.get("number") + "##" + coreBaseInfo.get("name"); value = (String) coreBaseInfo.get("name"); } else if (obj instanceof BigDecimal) { BigDecimal bigDecimal = (BigDecimal) obj; value = bigDecimal.setScale(2).toPlainString(); } else { if ("checkRate".equals(columnName) || "assessRate".equals(columnName)) { value = AssessRatingEnum.getEnum((String) obj).getAlias(); } else { value = obj.toString(); } } } createCell.setCellValue(value); } } } catch (BOSException e) { e.printStackTrace(); throw new RuntimeException(e); } } protected Map getColumnIndexFn(Map columnInfoMap) { Map columnIndexMap = new HashMap<>(); Iterator keys = columnInfoMap.keySet().iterator(); int var4 = 0; while (keys.hasNext()) { String key = keys.next(); columnIndexMap.put(Integer.valueOf(var4++), key); } return columnIndexMap; } @Override protected String getPKSelectString(BaseRowInfo row) { String pkSelectString = super.getPKSelectString(row); String parentId = getCustomParam("parentId"); if (StringUtils.isEmpty(parentId)) { throw new RuntimeException("拓展人员考核周期ID不可为空!!"); } return pkSelectString + " and parent.id ='" + parentId + "' "; } }