|
@@ -0,0 +1,442 @@
|
|
|
+package nccloud.web.hrbm.bmfile.excel;
|
|
|
+
|
|
|
+import nc.bs.dao.BaseDAO;
|
|
|
+import nc.bs.logging.Logger;
|
|
|
+import nc.hr.utils.MultiLangHelper;
|
|
|
+import nc.hr.utils.ResHelper;
|
|
|
+import nc.itf.bm.bmfile.IBmfileManageService;
|
|
|
+import nc.itf.bm.bmfile.IBmfileQueryService;
|
|
|
+import nc.itf.bm.bmfile.IHRBmfileConstant;
|
|
|
+import nc.itf.hr.bm.IBmClassQueryService;
|
|
|
+import nc.itf.hr.bm.IBmItemQueryService;
|
|
|
+import nc.itf.om.IOMCommonQueryService;
|
|
|
+import nc.itf.uap.IUAPQueryBS;
|
|
|
+import nc.jdbc.framework.processor.BeanListProcessor;
|
|
|
+import nc.vo.bm.bmclass.AssignclsVO;
|
|
|
+import nc.vo.bm.bmclass.BmClassConstant;
|
|
|
+import nc.vo.bm.bmclass.BmClassItemVO;
|
|
|
+import nc.vo.bm.bmclass.BmClassVO;
|
|
|
+import nc.vo.bm.data.BmDataVO;
|
|
|
+import nc.vo.bm.item.BmFromEnumVO;
|
|
|
+import nc.vo.bm.item.BmItemVO;
|
|
|
+import nc.vo.bm.period.BmPeriodVO;
|
|
|
+import nc.vo.bm.pub.BmLoginContext;
|
|
|
+import nc.vo.hi.psndoc.PsnJobVO;
|
|
|
+import nc.vo.hr.itemsource.TypeEnumVO;
|
|
|
+import nc.vo.org.OrgVO;
|
|
|
+import nc.vo.platform.appsystemplate.FormPropertyVO;
|
|
|
+import nc.vo.pub.BusinessException;
|
|
|
+import nc.vo.pub.SuperVO;
|
|
|
+import nc.vo.pub.VOStatus;
|
|
|
+import nc.vo.pub.lang.UFBoolean;
|
|
|
+import nc.vo.pub.lang.UFLiteralDate;
|
|
|
+import nc.vo.uif2.LoginContext;
|
|
|
+import nccloud.base.exception.ExceptionUtils;
|
|
|
+import nccloud.commons.collections.CollectionUtils;
|
|
|
+import nccloud.commons.collections.MapUtils;
|
|
|
+import nccloud.commons.lang.ArrayUtils;
|
|
|
+import nccloud.framework.service.ServiceLocator;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+
|
|
|
+public class BmfileImportDataProcess {
|
|
|
+ //险种pk集合 test
|
|
|
+ private Set<String> classPkSet = null;
|
|
|
+ //员工号集合
|
|
|
+ private List<String> clerkCodeList = null;
|
|
|
+ //判断是否应该有项目,没有则移除vo中的值
|
|
|
+ private Map<String, List<String>> classItemKeyMap = null;
|
|
|
+ //通过classid查询集团分配险种主键
|
|
|
+ private Map<String, String> map4Assigncls = null;
|
|
|
+
|
|
|
+ public Map<Integer, StringBuilder> validateAndSave(LoginContext context, SuperVO[] vos, Set<String> importField) {
|
|
|
+ BmLoginContext bmContext = (BmLoginContext) context;
|
|
|
+ Map<Integer, StringBuilder> result = new HashMap<>();
|
|
|
+ if (ArrayUtils.isEmpty(vos)) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ //险种pk集合
|
|
|
+ classPkSet = new HashSet<>();
|
|
|
+ //员工号集合
|
|
|
+ clerkCodeList = new ArrayList<>();
|
|
|
+ //通过classid查询集团分配险种主键
|
|
|
+ classItemKeyMap = new HashMap<>();
|
|
|
+ BmDataVO[] dataVOS = new BmDataVO[vos.length];
|
|
|
+ for (int i = 0; i < vos.length; i++) {
|
|
|
+ dataVOS[i] = (BmDataVO) vos[i];
|
|
|
+ setBmClassAndClerkInfo((BmDataVO) vos[i], classPkSet, clerkCodeList);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ //通过classid查询集团分配险种主键
|
|
|
+ map4Assigncls = getAssignclsInfo(dataVOS);
|
|
|
+ //员工号和pk_psnjob的映射关系
|
|
|
+ Map<String, PsnJobVO> jobMap = getPsnjobMap(context);
|
|
|
+ //险种和对应的险种项目
|
|
|
+ classItemKeyMap = getBmClassWithItems(bmContext, result);
|
|
|
+ BmClassVO[] bmClassVOs = ServiceLocator.find(IBmClassQueryService.class).getBusinessBmClass(new String[]{bmContext.getPk_org()});
|
|
|
+ Set<String> bmClassSet = new HashSet<String>();
|
|
|
+ for (BmClassVO bmClassVO : bmClassVOs) {
|
|
|
+ if (!bmClassVO.getCyear().equals(bmContext.getCyear()) || !bmClassVO.getCperiod().equals(bmContext.getCperiod())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ bmClassSet.add(bmClassVO.getPk_bm_class());
|
|
|
+ }
|
|
|
+ boolean isNotExistsJob=false;
|
|
|
+ //判断是否应该有项目,没有则移除vo中的值
|
|
|
+ for (int i = 0; i < dataVOS.length; i++) {
|
|
|
+ BmDataVO vo = dataVOS[i];
|
|
|
+ if(MapUtils.isEmpty(jobMap)){
|
|
|
+ for (int j = 0; j < dataVOS.length; j++) {
|
|
|
+ addErrMsg(j, ResHelper.getString("60150bmfile", "160150bmfile0023") + vo.getAttributeValue("pk_psnjob.clerkcode"), result);/**@res 没找找到有效任职!员工号:**/
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ PsnJobVO jobVO = jobMap.get(vo.getAttributeValue("pk_psnjob.clerkcode"));
|
|
|
+ if (jobVO == null) {
|
|
|
+ addErrMsg(i, ResHelper.getString("60150bmfile", "160150bmfile0023") + vo.getAttributeValue("pk_psnjob.clerkcode"), result);/**@res 没找找到有效任职!员工号:**/
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (!bmClassSet.contains(vo.getPk_bm_class())) {
|
|
|
+ OrgVO orgVO = ServiceLocator.find(IOMCommonQueryService.class).queryByPK(OrgVO.class, bmContext.getPk_org());
|
|
|
+ String orgName = (orgVO == null) ? "" : orgVO.getName();
|
|
|
+ addErrMsg(i, "在当前组织(" + orgName + ")期间(" + bmContext.getCyear() + bmContext.getCperiod() + "),未找到该险种", result);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 补充档案数据
|
|
|
+ ensureBmData(vo, jobVO, bmContext, importField);
|
|
|
+ }
|
|
|
+ if (result.isEmpty()) {
|
|
|
+ // 批量更新财务组织,财务部门,成本中心,成本部门
|
|
|
+ BmDataVO[] bmDataVOs = ServiceLocator.find(IBmfileQueryService.class).getPkFinanceOrg(dataVOS);
|
|
|
+ // 保存数据
|
|
|
+ saveBmDatas(bmDataVOs, (BmLoginContext) context, result);
|
|
|
+ }
|
|
|
+ } catch (BusinessException e) {
|
|
|
+ Logger.error("报错===========================================" + e.getMessage(), e);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param context
|
|
|
+ * @param itemList
|
|
|
+ * @throws BusinessException
|
|
|
+ */
|
|
|
+ public void extendFieldProcess(LoginContext context, List<FormPropertyVO> itemList) throws BusinessException {
|
|
|
+ BmLoginContext bmLoginContext = null;
|
|
|
+ if (context instanceof BmLoginContext) {
|
|
|
+ bmLoginContext = (BmLoginContext) context;
|
|
|
+ }
|
|
|
+ if (bmLoginContext == null) {
|
|
|
+ Logger.error("参数出错,请检查期间参数是否正确!");
|
|
|
+ ExceptionUtils.wrapBusinessException("参数出错,请检查期间参数是否正确!");
|
|
|
+ }
|
|
|
+ String condition = " category_id = '" + BmClassConstant.DOC_CATEGORY_ID + "'";
|
|
|
+ BmItemVO[] bmItemVOS = ServiceLocator.find(IBmItemQueryService.class).queryByCondition(context, condition);
|
|
|
+ for (BmItemVO itemVO : bmItemVOS) {
|
|
|
+ FormPropertyVO vo = getDefaultItem(itemVO);
|
|
|
+ itemList.add(vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addErrMsg(int index, String msg, Map<Integer, StringBuilder> result) {
|
|
|
+ StringBuilder stringBuilder = result.get(index);
|
|
|
+ if (stringBuilder == null) {
|
|
|
+ stringBuilder = new StringBuilder();
|
|
|
+ result.put(index, stringBuilder);
|
|
|
+ }
|
|
|
+ stringBuilder.append(msg + "\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param itemVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private FormPropertyVO getDefaultItem(BmItemVO itemVO) {
|
|
|
+ FormPropertyVO item = new FormPropertyVO();
|
|
|
+ UFBoolean disable = UFBoolean.TRUE;
|
|
|
+ boolean flag = itemVO.getIfromflag().intValue() == BmFromEnumVO.USER_INPUT.toIntValue();
|
|
|
+ if (flag) {
|
|
|
+ disable = UFBoolean.FALSE;
|
|
|
+ }
|
|
|
+ item.setRequired(UFBoolean.FALSE);
|
|
|
+ item.setDisabled(disable);
|
|
|
+ item.setLabel(MultiLangHelper.getName(itemVO));
|
|
|
+ item.setVisible(UFBoolean.TRUE);
|
|
|
+ item.setCode(itemVO.getItemkey());
|
|
|
+ item.setMaxlength(itemVO.getIfldwidth());
|
|
|
+ int type = itemVO.getIitemtype().intValue();
|
|
|
+ if (type == TypeEnumVO.FLOATTYPE.toIntValue()) {
|
|
|
+ item.setItemtype("number");
|
|
|
+ item.setDatatype(31);
|
|
|
+ item.setDataval(itemVO.getIflddecimal() + ",-100000000000000000000,100000000000000000000");
|
|
|
+ } else if (type == TypeEnumVO.DATETYPE.toIntValue()) {
|
|
|
+ item.setItemtype("datePickerNoTimeZone");
|
|
|
+ item.setDatatype(39);
|
|
|
+ } else if (type == TypeEnumVO.CHARTYPE.toIntValue()) {
|
|
|
+ item.setItemtype("input");
|
|
|
+ item.setDatatype(1);
|
|
|
+ }
|
|
|
+ return item;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 员工号和pk_psnjob的映射关系
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map<String, PsnJobVO> getPsnjobMap(LoginContext context) {
|
|
|
+ Map<String, PsnJobVO> jobMap = null;
|
|
|
+ BaseDAO dao = new BaseDAO();
|
|
|
+ List<PsnJobVO> jobVOList = null;
|
|
|
+ Set<String> pkSet = new HashSet();
|
|
|
+ String[] pks = clerkCodeList.toArray(new String[0]);
|
|
|
+ if (ArrayUtils.isNotEmpty(pks)) {
|
|
|
+ for (String pk : pks) {
|
|
|
+ pkSet.add(pk);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ //查询所有任职
|
|
|
+ //String sql = "select pk_psnjob,clerkcode,pk_psndoc,pk_org,pk_dept,pk_org_v,pk_dept_v from hi_psnjob where endflag = 'N' and lastflag = 'Y' and clerkcode in (" + new InSQLCreator().getInSQL(clerkCodeList.toArray(new String[0])) + ")";
|
|
|
+ StringBuffer sqlBuffer = new StringBuffer();
|
|
|
+ sqlBuffer.append("select hi_psnjob.pk_psnjob, "); // 1
|
|
|
+ sqlBuffer.append(" hi_psnjob.pk_psnorg, "); // 2
|
|
|
+ sqlBuffer.append(" hi_psnjob.assgid, "); // 3
|
|
|
+ sqlBuffer.append(" hi_psnjob.pk_psndoc, "); // 4
|
|
|
+ sqlBuffer.append(" hi_psnjob.clerkcode, "); // 5
|
|
|
+ sqlBuffer.append(" hi_psnjob.jobglbdef6, "); // dzz 20231025 社保档案导入设置 财务组织部门 责任组织部门
|
|
|
+ sqlBuffer.append(" hi_psnjob.jobglbdef5, "); // dzz 20231025 社保档案导入设置 财务组织部门 责任组织部门
|
|
|
+ sqlBuffer.append(" org_orgs.pk_org, ");
|
|
|
+ sqlBuffer.append(" org_orgs.pk_vid as pk_org_v, ");
|
|
|
+ sqlBuffer.append(" org_dept.pk_dept, ");
|
|
|
+ sqlBuffer.append(" org_dept.pk_vid as pk_dept_v ");
|
|
|
+ sqlBuffer.append(" from hi_psnjob ");
|
|
|
+ sqlBuffer.append(" inner join bd_psndoc on bd_psndoc.pk_psndoc = hi_psnjob.pk_psndoc ");
|
|
|
+ sqlBuffer.append(" inner join hi_psnorg on hi_psnorg.pk_psnorg = hi_psnjob.pk_psnorg ");
|
|
|
+ sqlBuffer.append(" left outer join org_dept on org_dept.pk_dept = hi_psnjob.pk_dept ");
|
|
|
+ sqlBuffer.append(" left outer join org_orgs on org_orgs.pk_org = hi_psnjob.pk_org ");
|
|
|
+ sqlBuffer.append(" left outer join org_hrorg on org_hrorg.pk_hrorg = hi_psnjob.pk_hrorg ");
|
|
|
+ sqlBuffer.append(" where 1=1 and org_hrorg.enablestate=2 ");
|
|
|
+ if (context instanceof BmLoginContext) {
|
|
|
+ BmLoginContext bmContext = (BmLoginContext) context;
|
|
|
+ String year = bmContext.getCyear();
|
|
|
+ String period = bmContext.getCperiod();
|
|
|
+ String periodSql = "select distinct p.cenddate,p.cstartdate,p.year,p.period from bm_period p where p.year ='" + year + "' and p.period='" + period + "'";
|
|
|
+ List<BmPeriodVO> periodList = (List<BmPeriodVO>) ServiceLocator.find(IUAPQueryBS.class)
|
|
|
+ .executeQuery(periodSql, new BeanListProcessor(BmPeriodVO.class));
|
|
|
+ if (CollectionUtils.isNotEmpty(periodList)) {
|
|
|
+ UFLiteralDate beginDate = periodList.get(0).getCstartdate();
|
|
|
+ UFLiteralDate endDate = periodList.get(0).getCenddate();
|
|
|
+ String pkOrg = bmContext.getPk_org();
|
|
|
+ sqlBuffer.append(" and (hi_psnorg.psntype = 0 and hi_psnorg.indocflag = 'Y' and ");
|
|
|
+ sqlBuffer.append(" hi_psnjob.ismainjob = 'Y' and hi_psnjob.begindate <= '" + endDate + "' and");
|
|
|
+ sqlBuffer.append(" (hi_psnjob.enddate >= '" + beginDate + "' or hi_psnjob.enddate is null) and");
|
|
|
+ sqlBuffer.append(" hi_psnjob.begindate =");
|
|
|
+ sqlBuffer.append(" (select max(psnjob.begindate)");
|
|
|
+ sqlBuffer.append(" from hi_psnjob psnjob");
|
|
|
+ sqlBuffer.append(" where hi_psnjob.pk_psndoc = psnjob.pk_psndoc");
|
|
|
+ sqlBuffer.append(" and hi_psnjob.pk_psnorg = psnjob.pk_psnorg");
|
|
|
+ sqlBuffer.append(" and hi_psnjob.pk_hrorg = psnjob.pk_hrorg");
|
|
|
+ sqlBuffer.append(" and psnjob.begindate <= '" + endDate + "'");
|
|
|
+ sqlBuffer.append(" and (psnjob.enddate >= '" + beginDate + "' or psnjob.enddate is null)");
|
|
|
+ sqlBuffer.append(" and psnjob.ismainjob = 'Y') and");
|
|
|
+ sqlBuffer.append(" (hi_psnjob.pk_dept = '" + pkOrg + "' or");
|
|
|
+ sqlBuffer.append(" hi_psnjob.pk_hrorg = '" + pkOrg + "'))");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ jobVOList = (List<PsnJobVO>) ServiceLocator.find(IBmfileQueryService.class).executeQuery(sqlBuffer.toString(), "hi_psnjob.clerkcode", pkSet.toArray(new String[0]), new BeanListProcessor(PsnJobVO.class));
|
|
|
+ if (CollectionUtils.isEmpty(jobVOList)) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ jobMap = new HashMap<>();
|
|
|
+ }
|
|
|
+ } catch (BusinessException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(jobVOList)) {
|
|
|
+ for (PsnJobVO jobVO : jobVOList) {
|
|
|
+ jobMap.put(jobVO.getClerkcode(), jobVO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return jobMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 补充档案数据
|
|
|
+ *
|
|
|
+ * @param vo
|
|
|
+ * @param jobVO
|
|
|
+ * @param bmContext
|
|
|
+ * @param importField
|
|
|
+ */
|
|
|
+ private void ensureBmData(BmDataVO vo, PsnJobVO jobVO, BmLoginContext bmContext, Set<String> importField) {
|
|
|
+ vo.setPk_org(bmContext.getPk_org());
|
|
|
+ vo.setPk_group(bmContext.getPk_group());
|
|
|
+ vo.setPk_psnjob(jobVO.getPk_psnjob());//根据员工号设置pk_psnjob
|
|
|
+ vo.setPk_psndoc(jobVO.getPk_psndoc());//根据员工号设置pk_psndoc
|
|
|
+ vo.setWorkorg(jobVO.getPk_org()); //补充任职组织
|
|
|
+ vo.setWorkdept(jobVO.getPk_dept()); //补充任职部门
|
|
|
+ vo.setWorkorgvid(jobVO.getPk_org_v()); //补充任职组织
|
|
|
+ vo.setWorkdeptvid(jobVO.getPk_dept_v()); //补充任职部门
|
|
|
+ vo.setPk_psnorg(jobVO.getPk_psnorg());
|
|
|
+ vo.setAssgid(jobVO.getAssgid());
|
|
|
+ vo.setCperiod(bmContext.getCperiod());
|
|
|
+ vo.setCyear(bmContext.getCyear());
|
|
|
+ vo.setCaculateflag(UFBoolean.FALSE);
|
|
|
+ vo.setCheckflag(UFBoolean.FALSE);
|
|
|
+ //dzz 20231025 社保档案导入设置 财务组织部门 责任组织部门
|
|
|
+ vo.setGlbdef1((String) jobVO.getAttributeValue("jobglbdef6")); //财务组织
|
|
|
+ vo.setGlbdef2((String) jobVO.getAttributeValue("jobglbdef5")); // 财务部门
|
|
|
+ vo.setGlbdef3(jobVO.getPk_org()); // 责任组织
|
|
|
+ vo.setGlbdef4( jobVO.getPk_dept()); // 责任部门
|
|
|
+ if (vo.getAccountstate() == null) {
|
|
|
+ vo.setAccountstate(IHRBmfileConstant.ACCOUNTSTATE_NORMAL);
|
|
|
+ }
|
|
|
+
|
|
|
+ vo.setAccounttype(IHRBmfileConstant.ACCOUNTTYPE_NEW);
|
|
|
+ vo.setPk_sourcecls(map4Assigncls.get(vo.getPk_bm_class()));
|
|
|
+ for (String key : importField) {
|
|
|
+ //判断导入列是档案项目且不在险种项目中的,一律置空
|
|
|
+ if (!key.startsWith("c_") && !key.startsWith("d_") && !key.startsWith("f_")) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //险种没有项目或者险种项目不包括该项目
|
|
|
+ if (classItemKeyMap.get(vo.getPk_bm_class()) == null || !classItemKeyMap.get(vo.getPk_bm_class()).contains(key)) {
|
|
|
+ vo.setAttributeValue(key, null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param vo
|
|
|
+ * @param classPkList
|
|
|
+ * @param clerkCodeList
|
|
|
+ */
|
|
|
+ private void setBmClassAndClerkInfo(BmDataVO vo, Set<String> classPkSet, List<String> clerkCodeList) {
|
|
|
+ String pk_bm_class = vo.getPk_bm_class();
|
|
|
+ classPkSet.add(pk_bm_class);
|
|
|
+ clerkCodeList.add(vo.getAttributeValue("pk_psnjob.clerkcode").toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 险种和对应的险种项目
|
|
|
+ *
|
|
|
+ * @param bmContext
|
|
|
+ * @return
|
|
|
+ * @throws BusinessException
|
|
|
+ */
|
|
|
+ private Map<String, List<String>> getBmClassWithItems(BmLoginContext bmContext, Map<Integer, StringBuilder> result) throws BusinessException {
|
|
|
+ Map<String, List<String>> classItemKeyMap = new HashMap<>();
|
|
|
+ BmClassItemVO[] classItemVOS = ServiceLocator.find(IBmClassQueryService.class).queryFileClassItem(bmContext.getCyear(), bmContext.getCperiod(), classPkSet.toArray(new String[classPkSet.size()]));
|
|
|
+ if (classItemVOS == null) {
|
|
|
+ //Logger.error("查询险种项目出错");
|
|
|
+ //result.put(-3, new StringBuilder(ResHelper.getString("60150bmfile", "160150bmfile0022")));//放在第一行
|
|
|
+ return classItemKeyMap;
|
|
|
+ }
|
|
|
+ for (BmClassItemVO classItemVO : classItemVOS) {
|
|
|
+ String pk_bm_class = classItemVO.getPk_bm_class();
|
|
|
+ List<String> itemKeyList = classItemKeyMap.get(pk_bm_class);
|
|
|
+ if (itemKeyList == null) {
|
|
|
+ itemKeyList = new ArrayList<>();
|
|
|
+ classItemKeyMap.put(pk_bm_class, itemKeyList);
|
|
|
+ }
|
|
|
+ itemKeyList.add(classItemVO.getItemkey());
|
|
|
+ }
|
|
|
+ return classItemKeyMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过classid查询集团分配险种主键
|
|
|
+ *
|
|
|
+ * @param dataVOS
|
|
|
+ * @return
|
|
|
+ * @throws BusinessException
|
|
|
+ */
|
|
|
+ private Map<String, String> getAssignclsInfo(BmDataVO[] dataVOS) throws BusinessException {
|
|
|
+ //通过classid查询集团分配险种主键
|
|
|
+ AssignclsVO[] assignclsVOs = ServiceLocator.find(IBmfileQueryService.class).queryAssignclsVOsByClassVOs(dataVOS);
|
|
|
+ if (ArrayUtils.isEmpty(assignclsVOs)) {
|
|
|
+ return new HashMap<String, String>();
|
|
|
+ }
|
|
|
+ Map<String, String> map4Assigncls = new HashMap<String, String>();
|
|
|
+ for (int i = 0; i < assignclsVOs.length; i++) {
|
|
|
+ map4Assigncls.put(assignclsVOs[i].getClassid(), assignclsVOs[i].getPk_assigncls());
|
|
|
+ }
|
|
|
+ return map4Assigncls;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存数据
|
|
|
+ *
|
|
|
+ * @param bmDataVOs
|
|
|
+ * @param context
|
|
|
+ * @throws BusinessException
|
|
|
+ */
|
|
|
+ private void saveBmDatas(BmDataVO[] bmDataVOs, BmLoginContext context, Map<Integer, StringBuilder> result) throws BusinessException {
|
|
|
+ //数据保存
|
|
|
+ List<BmDataVO> insertBmDataList = new ArrayList<BmDataVO>();
|
|
|
+ List<BmDataVO> updateBmDataList = new ArrayList<BmDataVO>();
|
|
|
+ //将excel表格里的数据,根据组织、期间、人员、险种进行分类,如果根据这些条件能查到档案信息,则进行更新操作,否则进行插入操作
|
|
|
+ groupData(bmDataVOs, insertBmDataList, updateBmDataList, result);
|
|
|
+ if (CollectionUtils.isNotEmpty(insertBmDataList)) {
|
|
|
+ ServiceLocator.find(IBmfileManageService.class).insertBmDataVOs(insertBmDataList.toArray(new BmDataVO[0]), context);
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(updateBmDataList)) {
|
|
|
+ ServiceLocator.find(IBmfileManageService.class).updateBmDataVOs(updateBmDataList.toArray(new BmDataVO[0]));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将excel表格里的数据,根据组织、期间、人员、险种进行分类,
|
|
|
+ * 如果根据这些条件能查到档案信息,则进行更新操作,否则进行插入操作
|
|
|
+ *
|
|
|
+ * @param oldBmData
|
|
|
+ * @param insertBmDataList
|
|
|
+ * @param updateBmDataList
|
|
|
+ * @throws BusinessException
|
|
|
+ */
|
|
|
+ private void groupData(BmDataVO[] oldBmData, List<BmDataVO> insertBmDataList, List<BmDataVO> updateBmDataList, Map<Integer, StringBuilder> result) throws BusinessException {
|
|
|
+ if (ArrayUtils.isEmpty(oldBmData)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String pkOrg = oldBmData[0].getPk_org();
|
|
|
+ String pkGroup = oldBmData[0].getPk_group();
|
|
|
+ String cyear = oldBmData[0].getCyear();
|
|
|
+ String cperiod = oldBmData[0].getCperiod();
|
|
|
+ IBmfileQueryService service = ServiceLocator.find(IBmfileQueryService.class);
|
|
|
+ BmDataVO[] dbBmDatas;
|
|
|
+ boolean isExitBmClassItem = false;
|
|
|
+ for (BmDataVO bmData : oldBmData) {
|
|
|
+ dbBmDatas = service.queryBmDataVOS(pkGroup, pkOrg, bmData.getPk_psndoc(), cyear, cperiod, null, null);
|
|
|
+ isExitBmClassItem = false;
|
|
|
+ // 该人员在该期间没有险种数据,从excel读取的数据,直接插入到数据库
|
|
|
+ if (ArrayUtils.isEmpty(dbBmDatas)) {
|
|
|
+ bmData.setStatus(VOStatus.NEW);
|
|
|
+ insertBmDataList.add(bmData);
|
|
|
+ } else {
|
|
|
+ for (BmDataVO dbBmData : dbBmDatas) {
|
|
|
+ // 该人员在该期间已存在该险种数据,从excel读取的数据后,直接赋值到原数据
|
|
|
+ if (bmData.getPk_bm_class().equals(dbBmData.getPk_bm_class())) {
|
|
|
+ bmData.setPk_bm_data(dbBmData.getPk_bm_data());
|
|
|
+ bmData.setStatus(VOStatus.UPDATED);
|
|
|
+ updateBmDataList.add(bmData);
|
|
|
+ isExitBmClassItem = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 该人员在该期间有险种数据,但是没有excel上读取的险种数据,这时执行插入操作
|
|
|
+ if (!isExitBmClassItem) {
|
|
|
+ bmData.setStatus(VOStatus.NEW);
|
|
|
+ insertBmDataList.add(bmData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|