|
@@ -1,648 +1,656 @@
|
|
|
-package nc.bs.bd.baseservice.md;
|
|
|
-
|
|
|
-import java.lang.reflect.Array;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.Iterator;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
-
|
|
|
-import nc.bs.baseapp.sendZP.DeptSendZP;
|
|
|
-import nc.bs.baseapp.sendZP.OrgSendZP;
|
|
|
-import nc.bs.bd.baseservice.BDUniqueFieldTrimUtil;
|
|
|
-import nc.bs.bd.baseservice.busilog.BDBusiLogUtil;
|
|
|
-import nc.bs.bd.baseservice.busilog.IBDBusiLogUtil;
|
|
|
-import nc.bs.bd.baseservice.persistence.ITreePersistenceUtil;
|
|
|
-import nc.bs.bd.baseservice.persistence.MDTreePersistenceUtil;
|
|
|
-import nc.bs.bd.baseservice.persistence.TreeRootInnerCodeLockUtil;
|
|
|
-import nc.bs.bd.baseservice.validator.BDTreeEnableValidator;
|
|
|
-import nc.bs.businessevent.bd.BDCommonEventUtil;
|
|
|
-import nc.bs.uif2.validation.IValidationService;
|
|
|
-import nc.bs.uif2.validation.ValidationFrameworkUtil;
|
|
|
-import nc.bs.uif2.validation.Validator;
|
|
|
-import nc.vo.org.DeptVO;
|
|
|
-import nc.vo.org.FinanceOrgVO;
|
|
|
-import nc.vo.org.OrgVO;
|
|
|
-import nc.vo.pub.BusinessException;
|
|
|
-import nc.vo.pub.CircularlyAccessibleValueObject;
|
|
|
-import nc.vo.pub.SuperVO;
|
|
|
-import nc.vo.pub.lang.UFBoolean;
|
|
|
-import nc.vo.util.AuditInfoUtil;
|
|
|
-import nc.vo.util.BDReferenceChecker;
|
|
|
-import nc.vo.util.BDUniqueRuleValidate;
|
|
|
-import nc.vo.util.BDVersionValidationUtil;
|
|
|
-import nc.vo.util.bizlock.BizlockDataUtil;
|
|
|
-import nccloud.commons.lang.ArrayUtils;
|
|
|
-import nccloud.commons.lang.StringUtils;
|
|
|
-
|
|
|
-public class TreeBaseService<T extends SuperVO> {
|
|
|
- private String MDId;
|
|
|
- private String[] subAttributeNames;
|
|
|
- private IBDBusiLogUtil busiLogUtil;
|
|
|
- private ITreePersistenceUtil<T> persistenceUtil;
|
|
|
- private TreeRootInnerCodeLockUtil<T> rootLockUtil;
|
|
|
- private BDUniqueFieldTrimUtil uniqueFieldTrimUtil;
|
|
|
-
|
|
|
- public TreeBaseService(String mdID, String[] subAttributeNames) {
|
|
|
- this(mdID, subAttributeNames, (ITreePersistenceUtil) null);
|
|
|
- }
|
|
|
-
|
|
|
- public TreeBaseService(String mdID, String[] subAttributeNames, ITreePersistenceUtil<T> persistenceUtil) {
|
|
|
- this.busiLogUtil = null;
|
|
|
- this.rootLockUtil = null;
|
|
|
- this.MDId = mdID;
|
|
|
- this.persistenceUtil = persistenceUtil;
|
|
|
- this.subAttributeNames = subAttributeNames;
|
|
|
- }
|
|
|
-
|
|
|
- public String getMDId() {
|
|
|
- return this.MDId;
|
|
|
- }
|
|
|
-
|
|
|
- public String[] getSubAttributeNames() {
|
|
|
- return this.subAttributeNames == null ? null : (String[]) this.subAttributeNames.clone();
|
|
|
- }
|
|
|
-
|
|
|
- protected ITreePersistenceUtil<T> getPersistenceUtil() {
|
|
|
- if (this.persistenceUtil == null) {
|
|
|
- this.persistenceUtil = new MDTreePersistenceUtil(this.getMDId(), this.getSubAttributeNames());
|
|
|
- }
|
|
|
-
|
|
|
- return this.persistenceUtil;
|
|
|
- }
|
|
|
-
|
|
|
- protected TreeRootInnerCodeLockUtil<T> getRootLockUtil() {
|
|
|
- if (this.rootLockUtil == null) {
|
|
|
- this.rootLockUtil = new TreeRootInnerCodeLockUtil(this.getPersistenceUtil());
|
|
|
- }
|
|
|
-
|
|
|
- return this.rootLockUtil;
|
|
|
- }
|
|
|
-
|
|
|
- protected void setBusiLogUtil(IBDBusiLogUtil busiLogUtil) {
|
|
|
- this.busiLogUtil = busiLogUtil;
|
|
|
- }
|
|
|
-
|
|
|
- protected IBDBusiLogUtil getBusiLogUtil() {
|
|
|
- if (this.busiLogUtil == null) {
|
|
|
- this.busiLogUtil = new BDBusiLogUtil(this.getMDId());
|
|
|
- }
|
|
|
-
|
|
|
- return this.busiLogUtil;
|
|
|
- }
|
|
|
-
|
|
|
- public void deleteVO(T vo) throws BusinessException {
|
|
|
- if (vo != null) {
|
|
|
- this.deleteLockOperate(vo);
|
|
|
- this.deleteVersionValidate(vo);
|
|
|
- this.deleteValidateVO(vo);
|
|
|
- this.fireBeforeDeleteEvent(vo);
|
|
|
- this.notifyVersionChangeWhenDataDeleted(vo);
|
|
|
- this.fireAfterDeleteEvent(vo);
|
|
|
- this.dbDeleteVO(vo);
|
|
|
- this.writeDeletedBusiLog(vo);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected void deleteLockOperate(T vo) throws BusinessException {
|
|
|
- this.getRootLockUtil().lockBranchRoot(vo);
|
|
|
- }
|
|
|
-
|
|
|
- protected void deleteVersionValidate(T vo) throws BusinessException {
|
|
|
- BDVersionValidationUtil.validateSuperVO(new SuperVO[]{vo});
|
|
|
- }
|
|
|
-
|
|
|
- protected void deleteValidateVO(T vo) throws BusinessException {
|
|
|
- IValidationService validateService = ValidationFrameworkUtil.createValidationService(this.getDeleteValidator());
|
|
|
- validateService.validate(vo);
|
|
|
- }
|
|
|
-
|
|
|
- protected Validator[] getDeleteValidator() {
|
|
|
- Validator[] validators = new Validator[]{BDReferenceChecker.getInstance()};
|
|
|
- return validators;
|
|
|
- }
|
|
|
-
|
|
|
- protected void fireBeforeDeleteEvent(T vo) throws BusinessException {
|
|
|
- BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
- eventUtil.dispatchDeleteBeforeEvent(new Object[]{vo});
|
|
|
- }
|
|
|
-
|
|
|
- protected void fireAfterDeleteEvent(T vo) throws BusinessException {
|
|
|
- BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
- eventUtil.dispatchDeleteAfterEvent(new Object[]{vo});
|
|
|
- //部门传HS Yaoy 2022-08-03
|
|
|
- //公共方法,vo获取失败吃掉异常
|
|
|
- DeptVO[] deptVOarr = new DeptVO[1];
|
|
|
-
|
|
|
- try {
|
|
|
- deptVOarr[0] = (DeptVO) vo;
|
|
|
- } catch (Exception e) {}
|
|
|
-
|
|
|
- if(deptVOarr[0] != null) {
|
|
|
- DeptSendZP.process(deptVOarr, "delete");
|
|
|
- }
|
|
|
-
|
|
|
- if(deptVOarr[0] == null) {
|
|
|
- //组织传租聘系统 YY 2022-08-22
|
|
|
- FinanceOrgVO financeOrgVO = new FinanceOrgVO();
|
|
|
- try {
|
|
|
- OrgVO orgVO = (OrgVO) vo;
|
|
|
- //是否业务单元数据,不是不走接口
|
|
|
- if(orgVO.getIsbusinessunit().booleanValue()) {
|
|
|
- financeOrgVO.setCode(orgVO.getCode());
|
|
|
- financeOrgVO.setName(orgVO.getName());
|
|
|
- }
|
|
|
- } catch (Exception e) {}
|
|
|
- if(financeOrgVO.getCode() != null && financeOrgVO.getCode().length() != 0) {
|
|
|
- OrgSendZP.process(financeOrgVO, "delete");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected void dbDeleteVO(T vo) throws BusinessException {
|
|
|
- this.getPersistenceUtil().deleteVO(this.convertToVOArray(vo));
|
|
|
- }
|
|
|
-
|
|
|
- protected void notifyVersionChangeWhenDataDeleted(T vo) throws BusinessException {
|
|
|
- this.getPersistenceUtil().notifyVersionChangeWhenDataDeleted((T[]) new SuperVO[]{vo});
|
|
|
- }
|
|
|
-
|
|
|
- protected void writeDeletedBusiLog(T vo) throws BusinessException {
|
|
|
- this.getBusiLogUtil().writeBusiLog("delete", (String) null, new SuperVO[]{vo});
|
|
|
- }
|
|
|
-
|
|
|
- public T insertVO(T vo) throws BusinessException {
|
|
|
- if (vo == null) {
|
|
|
- return null;
|
|
|
- } else {
|
|
|
- this.getUniqueFieldTrimUtil().trimUniqueFields(new SuperVO[]{vo});
|
|
|
- this.insertLockOperate(this.convertToVOArray(vo));
|
|
|
- this.insertValidateVO(vo);
|
|
|
- this.setInsertAuditInfo(this.convertToVOArray(vo));
|
|
|
- this.fireBeforeInsertEvent(this.convertToVOArray(vo));
|
|
|
- String pk = this.dbInsertVO(vo);
|
|
|
- vo = this.retrieveVO(pk);
|
|
|
- this.notifyVersionChangeWhenDataInserted(this.convertToVOArray(vo));
|
|
|
- this.fireAfterInsertEvent(this.convertToVOArray(vo));
|
|
|
- this.writeInsertBusiLog(this.convertToVOArray(vo));
|
|
|
- return vo;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void insertVOs(T[] vos) throws BusinessException {
|
|
|
- if (vos != null && vos.length != 0) {
|
|
|
- this.getUniqueFieldTrimUtil().trimUniqueFields(vos);
|
|
|
- this.insertLockOperate(vos);
|
|
|
- this.insertValidateVO(vos);
|
|
|
- this.setInsertAuditInfo(vos);
|
|
|
- this.fireBeforeInsertEvent(vos);
|
|
|
- String[] pks = this.dbInsertVOs(vos);
|
|
|
- vos = this.retrieveVO(pks);
|
|
|
- this.notifyVersionChangeWhenDataInserted(vos);
|
|
|
- this.fireAfterInsertEvent(vos);
|
|
|
- this.writeInsertBusiLog(vos);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected void insertLockOperate(T... vos) throws BusinessException {
|
|
|
- List<T> needToLockRoot = this.getParentNotExistsVOs(vos);
|
|
|
- Iterator var3 = needToLockRoot.iterator();
|
|
|
-
|
|
|
- while (var3.hasNext()) {
|
|
|
- T vo = (T) var3.next();
|
|
|
- this.getRootLockUtil().lockBranchRoot(vo);
|
|
|
- }
|
|
|
-
|
|
|
- BizlockDataUtil.lockDataByBizlock(vos);
|
|
|
- }
|
|
|
-
|
|
|
- private List<T> getParentNotExistsVOs(T... vos) throws BusinessException {
|
|
|
- Set<String> pkSet = new HashSet();
|
|
|
-
|
|
|
- for (int i = 0; i < vos.length; ++i) {
|
|
|
- pkSet.add(vos[i].getPrimaryKey());
|
|
|
- }
|
|
|
-
|
|
|
- List<T> parentNotInPkSetVOs = new ArrayList();
|
|
|
- String parentField = this.getPersistenceUtil().getParentPkFieldName();
|
|
|
-
|
|
|
- for (int i = 0; i < vos.length; ++i) {
|
|
|
- if (!pkSet.contains(vos[i].getAttributeValue(parentField))) {
|
|
|
- parentNotInPkSetVOs.add(vos[i]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return parentNotInPkSetVOs;
|
|
|
- }
|
|
|
-
|
|
|
- protected void insertValidateVO(T vo) throws BusinessException {
|
|
|
- IValidationService validationService = ValidationFrameworkUtil
|
|
|
- .createValidationService(this.getInsertValidator());
|
|
|
- validationService.validate(vo);
|
|
|
- }
|
|
|
-
|
|
|
- protected void insertValidateVO(T[] vos) throws BusinessException {
|
|
|
- IValidationService validationService = ValidationFrameworkUtil
|
|
|
- .createValidationService(this.getInsertValidator());
|
|
|
- validationService.validate(vos);
|
|
|
- }
|
|
|
-
|
|
|
- protected Validator[] getInsertValidator() {
|
|
|
- Validator[] validators = new Validator[]{new BDUniqueRuleValidate()};
|
|
|
- return validators;
|
|
|
- }
|
|
|
-
|
|
|
- protected void setInsertAuditInfo(T... vos) throws BusinessException {
|
|
|
- AuditInfoUtil.addData(vos);
|
|
|
- }
|
|
|
-
|
|
|
- protected void fireBeforeInsertEvent(T... vos) throws BusinessException {
|
|
|
- BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
- eventUtil.dispatchInsertBeforeEvent((Object[]) vos);
|
|
|
- }
|
|
|
-
|
|
|
- protected void fireAfterInsertEvent(T... vos) throws BusinessException {
|
|
|
- BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
- eventUtil.dispatchInsertAfterEvent((Object[]) vos);
|
|
|
-
|
|
|
- //部门传ZP Yaoy 2022-08-03
|
|
|
- //公共方法,vo获取失败吃掉异常
|
|
|
- DeptVO[] deptVOarr = new DeptVO[vos.length];
|
|
|
- try {
|
|
|
- deptVOarr = (DeptVO[]) vos;
|
|
|
- } catch (Exception e) {}
|
|
|
- if(deptVOarr[0] != null) {
|
|
|
- DeptSendZP.process(deptVOarr, "add");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected String dbInsertVO(T vo) throws BusinessException {
|
|
|
- String[] pks = this.getPersistenceUtil().insertVOWithInnerCode(this.convertToVOArray(vo));
|
|
|
- return pks != null && pks.length > 0 ? pks[0] : null;
|
|
|
- }
|
|
|
-
|
|
|
- protected String[] dbInsertVOs(T... vos) throws BusinessException {
|
|
|
- return this.getPersistenceUtil().insertVOWithInnerCode(vos);
|
|
|
- }
|
|
|
-
|
|
|
- protected void notifyVersionChangeWhenDataInserted(T... vos) throws BusinessException {
|
|
|
- this.getPersistenceUtil().notifyVersionChangeWhenDataInserted(vos);
|
|
|
- }
|
|
|
-
|
|
|
- protected void writeInsertBusiLog(T... vos) throws BusinessException {
|
|
|
- this.getBusiLogUtil().writeBusiLog("add", (String) null, vos);
|
|
|
- }
|
|
|
-
|
|
|
- public T updateVO(T vo) throws BusinessException {
|
|
|
- if (vo == null) {
|
|
|
- return null;
|
|
|
- } else {
|
|
|
- this.getUniqueFieldTrimUtil().trimUniqueFields(new SuperVO[]{vo});
|
|
|
- this.updateLockOperate(vo);
|
|
|
- this.updateVersionValidate(vo);
|
|
|
- T oldVO = this.retrieveVO(vo.getPrimaryKey());
|
|
|
- this.updateValidateVO(oldVO, vo);
|
|
|
- this.setUpdateAuditInfo(this.convertToVOArray(vo));
|
|
|
- this.fireBeforeUpdateEvent(oldVO, vo);
|
|
|
- this.dbUpdateVO(oldVO, vo);
|
|
|
- vo = this.retrieveVO(vo.getPrimaryKey());
|
|
|
- this.notifyVersionChangeWhenDataUpdated(this.convertToVOArray(vo));
|
|
|
- this.fireAfterUpdateEvent(oldVO, vo);
|
|
|
- this.writeUpdatedBusiLog(this.convertToVOArray(oldVO), this.convertToVOArray(vo));
|
|
|
- return vo;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public T updateVOWithSub(T vo, ITreeUpdateWithChildren<T> updatWithChildren) throws BusinessException {
|
|
|
- if (vo == null) {
|
|
|
- return null;
|
|
|
- } else {
|
|
|
- this.getUniqueFieldTrimUtil().trimUniqueFields(new SuperVO[]{vo});
|
|
|
- this.updateLockOperate(vo);
|
|
|
- this.updateVersionValidate(vo);
|
|
|
- T[] oldVOs = this.retrieveSubVOsWithSelf(vo);
|
|
|
- T oldVO = this.getVOByPk(oldVOs, vo.getPrimaryKey());
|
|
|
- this.updateValidateVO(oldVO, vo);
|
|
|
- T[] updateVOs = this.createToUpdateVOsByOldSubVOs(vo, oldVOs, updatWithChildren);
|
|
|
- this.setUpdateAuditInfo(updateVOs);
|
|
|
- this.fireBeforeUpdateEvent(oldVOs, updateVOs);
|
|
|
- this.dbUpdateVOWithSub(oldVO, updateVOs, updatWithChildren);
|
|
|
- updateVOs = this.retrieveVO(VOArrayUtil.getPrimaryKeyArray(updateVOs));
|
|
|
- this.notifyVersionChangeWhenDataUpdated(updateVOs);
|
|
|
- this.fireAfterUpdateEvent(oldVOs, updateVOs);
|
|
|
- this.writeUpdatedBusiLog(oldVOs, updateVOs);
|
|
|
- return this.getVOByPk(updateVOs, vo.getPrimaryKey());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected void updateLockOperate(T vo) throws BusinessException {
|
|
|
- this.getRootLockUtil().lockBranchRootWhenParentChanged(vo);
|
|
|
- BizlockDataUtil.lockDataByBizlock(new CircularlyAccessibleValueObject[]{vo});
|
|
|
- }
|
|
|
-
|
|
|
- protected void updateVersionValidate(T vo) throws BusinessException {
|
|
|
- BDVersionValidationUtil.validateSuperVO(new SuperVO[]{vo});
|
|
|
- }
|
|
|
-
|
|
|
- protected void updateValidateVO(T oldVO, T vo) throws BusinessException {
|
|
|
- IValidationService validationService = ValidationFrameworkUtil
|
|
|
- .createValidationService(this.getUpdateValidator(oldVO));
|
|
|
- validationService.validate(vo);
|
|
|
- }
|
|
|
-
|
|
|
- protected Validator[] getUpdateValidator(T oldVO) {
|
|
|
- Validator[] validators = new Validator[]{new BDUniqueRuleValidate()};
|
|
|
- return validators;
|
|
|
- }
|
|
|
-
|
|
|
- private T[] createToUpdateVOsByOldSubVOs(T newVO, T[] oldVOs, ITreeUpdateWithChildren<T> updatWithChildren)
|
|
|
- throws BusinessException {
|
|
|
- T oldVO = this.getVOByPk(oldVOs, newVO.getPrimaryKey());
|
|
|
- T[] newVOs = (T[]) ((SuperVO[]) Array.newInstance(newVO.getClass(), oldVOs.length));
|
|
|
-
|
|
|
- for (int i = 0; i < oldVOs.length; ++i) {
|
|
|
- if (StringUtils.equals(oldVOs[i].getPrimaryKey(), newVO.getPrimaryKey())) {
|
|
|
- newVOs[i] = newVO;
|
|
|
- } else {
|
|
|
- newVOs[i] = updatWithChildren.getUpdateChildrenVO(oldVO, newVO, (T) oldVOs[i].clone());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return newVOs;
|
|
|
- }
|
|
|
-
|
|
|
- protected void setUpdateAuditInfo(T... vo) {
|
|
|
- AuditInfoUtil.updateData(vo);
|
|
|
- }
|
|
|
-
|
|
|
- protected void fireBeforeUpdateEvent(T oldVO, T vo) throws BusinessException {
|
|
|
- BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
- eventUtil.setOldObjs(new Object[]{oldVO});
|
|
|
- eventUtil.dispatchUpdateBeforeEvent(new Object[]{vo});
|
|
|
- }
|
|
|
-
|
|
|
- protected void fireBeforeUpdateEvent(T[] oldVOs, T[] vos) throws BusinessException {
|
|
|
- BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
- eventUtil.setOldObjs(oldVOs);
|
|
|
- eventUtil.dispatchUpdateBeforeEvent((Object[]) vos);
|
|
|
- }
|
|
|
-
|
|
|
- protected void fireAfterUpdateEvent(T oldVO, T vo) throws BusinessException {
|
|
|
- BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
- eventUtil.setOldObjs(new Object[]{oldVO});
|
|
|
- eventUtil.dispatchUpdateAfterEvent(new Object[]{vo});
|
|
|
-
|
|
|
-
|
|
|
- //部门传ZP Yaoy 2022-08-03
|
|
|
- //公共方法,vo获取失败吃掉异常
|
|
|
- DeptVO[] deptVOarr = new DeptVO[1];
|
|
|
- try {
|
|
|
- deptVOarr[0] = (DeptVO) vo;
|
|
|
- } catch (Exception e) {}
|
|
|
- if(deptVOarr[0] != null) {
|
|
|
- DeptSendZP.process(deptVOarr, "update");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected void fireAfterUpdateEvent(T[] oldVOs, T[] vos) throws BusinessException {
|
|
|
- BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
- eventUtil.setOldObjs(oldVOs);
|
|
|
- eventUtil.dispatchUpdateAfterEvent((Object[]) vos);
|
|
|
- }
|
|
|
-
|
|
|
- protected void dbUpdateVO(T oldVO, T vo) throws BusinessException {
|
|
|
- this.getPersistenceUtil().updateVOWithInnerCode(vo, oldVO);
|
|
|
- }
|
|
|
-
|
|
|
- protected void dbUpdateVOWithSub(T oldVO, T[] updateVOs, ITreeUpdateWithChildren<T> updatWithChildren)
|
|
|
- throws BusinessException {
|
|
|
- this.getPersistenceUtil().updateVOWithInnerCode(this.getVOByPk(updateVOs, oldVO.getPrimaryKey()), oldVO);
|
|
|
- T[] vos = this.filterVOsByPk(updateVOs, oldVO.getPrimaryKey());
|
|
|
- this.getPersistenceUtil().updateVOWithAttrs(updatWithChildren.getChildrenUpdateFields(), vos);
|
|
|
- }
|
|
|
-
|
|
|
- private T getVOByPk(T[] vos, String pk) {
|
|
|
- for (int i = 0; i < vos.length; ++i) {
|
|
|
- if (StringUtils.equals(vos[i].getPrimaryKey(), pk)) {
|
|
|
- return vos[i];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- private T[] filterVOsByPk(T[] updateVOs, String pk) throws BusinessException {
|
|
|
- List<T> list = new ArrayList();
|
|
|
-
|
|
|
- for (int i = 0; i < updateVOs.length; ++i) {
|
|
|
- if (!StringUtils.equals(updateVOs[i].getPrimaryKey(), pk)) {
|
|
|
- list.add(updateVOs[i]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- T[] vos = VOArrayUtil.convertToVOArray(this.getPersistenceUtil().getEntityClass(), list.toArray());
|
|
|
- return vos;
|
|
|
- }
|
|
|
-
|
|
|
- protected void notifyVersionChangeWhenDataUpdated(T... vos) throws BusinessException {
|
|
|
- this.getPersistenceUtil().notifyVersionChangeWhenDataInserted(vos);
|
|
|
- }
|
|
|
-
|
|
|
- protected void writeUpdatedBusiLog(T[] oldVOs, T[] vos) throws BusinessException {
|
|
|
- this.getBusiLogUtil().writeModefyBusiLog("edit", vos, oldVOs);
|
|
|
- }
|
|
|
-
|
|
|
- public T enableVO(T vo) throws BusinessException {
|
|
|
- if (vo == null) {
|
|
|
- return null;
|
|
|
- } else {
|
|
|
- this.enableLockOperate(vo);
|
|
|
- this.enableVersionValidate(vo);
|
|
|
- if (this.isDataEnabled(vo)) {
|
|
|
- return vo;
|
|
|
- } else {
|
|
|
- this.enableValidateVO(vo);
|
|
|
- this.setEnableAuditInfo(vo);
|
|
|
- this.setEnableFlag(vo);
|
|
|
- T oldVO = this.retrieveVOByFields(new String[]{"enablestate"}, vo.getPrimaryKey());
|
|
|
- this.fireBeforeEnableEvent(oldVO, vo);
|
|
|
- this.dbEnableVO(vo);
|
|
|
- vo = this.retrieveVO(vo.getPrimaryKey());
|
|
|
- this.notifyVersionChangeWhenDataUpdated(this.convertToVOArray(vo));
|
|
|
- this.fireAfterEnableEvent(oldVO, vo);
|
|
|
- this.writeEnableBusiLog(vo);
|
|
|
- return vo;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected void enableLockOperate(T vo) throws BusinessException {
|
|
|
- this.getRootLockUtil().lockBranchRoot(vo);
|
|
|
- }
|
|
|
-
|
|
|
- protected void enableVersionValidate(T vo) throws BusinessException {
|
|
|
- BDVersionValidationUtil.validateSuperVO(new SuperVO[]{vo});
|
|
|
- }
|
|
|
-
|
|
|
- protected boolean isDataEnabled(T vo) {
|
|
|
- Integer enable_state = (Integer) vo.getAttributeValue("enablestate");
|
|
|
- return 2 == enable_state;
|
|
|
- }
|
|
|
-
|
|
|
- protected void enableValidateVO(T vo) throws BusinessException {
|
|
|
- IValidationService validateService = ValidationFrameworkUtil.createValidationService(this.getEnableValidator());
|
|
|
- validateService.validate(vo);
|
|
|
- }
|
|
|
-
|
|
|
- protected Validator[] getEnableValidator() throws BusinessException {
|
|
|
- return new Validator[]{new BDTreeEnableValidator()};
|
|
|
- }
|
|
|
-
|
|
|
- protected void setEnableAuditInfo(T vo) {
|
|
|
- AuditInfoUtil.updateData(vo);
|
|
|
- }
|
|
|
-
|
|
|
- protected void setEnableFlag(T vo) {
|
|
|
- vo.setAttributeValue("enablestate", 2);
|
|
|
- }
|
|
|
-
|
|
|
- protected void fireBeforeEnableEvent(T oldVO, T vo) throws BusinessException {
|
|
|
- BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
- if (3 == (Integer) oldVO.getAttributeValue("enablestate")) {
|
|
|
- eventUtil.dispatchDisableToEnableBeforeEvent(new Object[]{vo});
|
|
|
- } else {
|
|
|
- eventUtil.dispatchInitToEnableBeforeEvent(new Object[]{vo});
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- protected void fireAfterEnableEvent(T oldVO, T vo) throws BusinessException {
|
|
|
- BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
- if (3 == (Integer) oldVO.getAttributeValue("enablestate")) {
|
|
|
- eventUtil.dispatchDisableToEnableAfterEvent(new Object[]{vo});
|
|
|
- } else {
|
|
|
- eventUtil.dispatchInitToEnableAfterEvent(new Object[]{vo});
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- protected void dbEnableVO(T vo) throws BusinessException {
|
|
|
- String[] updateFields = new String[]{"enablestate", "modifier", "modifiedtime"};
|
|
|
- this.getPersistenceUtil().updateVOWithAttrs(updateFields, this.convertToVOArray(vo));
|
|
|
- }
|
|
|
-
|
|
|
- protected void writeEnableBusiLog(T vo) throws BusinessException {
|
|
|
- this.getBusiLogUtil().writeBusiLog("enable", (String) null, new SuperVO[]{vo});
|
|
|
- }
|
|
|
-
|
|
|
- public T disableVO(T vo) throws BusinessException {
|
|
|
- if (vo == null) {
|
|
|
- return null;
|
|
|
- } else {
|
|
|
- this.disableLockOperate(vo);
|
|
|
- this.disableVersionValidate(vo);
|
|
|
- if (this.isDataDisabled(vo)) {
|
|
|
- return vo;
|
|
|
- } else {
|
|
|
- this.disableValidateVO(vo);
|
|
|
- T[] needDisableVOs = this.retrieveSubVOsWithSelf(vo);
|
|
|
- this.setDisableAuditInfo(needDisableVOs);
|
|
|
- this.setDisableFlag(needDisableVOs);
|
|
|
- this.fireBeforeDisableEvent(needDisableVOs);
|
|
|
- this.dbDisable(needDisableVOs);
|
|
|
- needDisableVOs = this.retrieveVO(VOArrayUtil.getPrimaryKeyArray(needDisableVOs));
|
|
|
- this.notifyVersionChangeWhenDataUpdated(needDisableVOs);
|
|
|
- this.fireAfterDisableEvent(needDisableVOs);
|
|
|
- this.writeDisableBusiLog(needDisableVOs);
|
|
|
- return needDisableVOs[0];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected void disableLockOperate(T vo) throws BusinessException {
|
|
|
- this.getRootLockUtil().lockBranchRoot(vo);
|
|
|
- }
|
|
|
-
|
|
|
- protected void disableVersionValidate(T vo) throws BusinessException {
|
|
|
- BDVersionValidationUtil.validateSuperVO(new SuperVO[]{vo});
|
|
|
- }
|
|
|
-
|
|
|
- protected boolean isDataDisabled(T vo) {
|
|
|
- Integer enable_state = (Integer) vo.getAttributeValue("enablestate");
|
|
|
- return 3 == enable_state;
|
|
|
- }
|
|
|
-
|
|
|
- protected void disableValidateVO(T vo) throws BusinessException {
|
|
|
- IValidationService validateService = ValidationFrameworkUtil
|
|
|
- .createValidationService(this.getDisableValidator());
|
|
|
- validateService.validate(vo);
|
|
|
- }
|
|
|
-
|
|
|
- protected Validator[] getDisableValidator() throws BusinessException {
|
|
|
- return new Validator[0];
|
|
|
- }
|
|
|
-
|
|
|
- protected void setDisableAuditInfo(T[] vos) {
|
|
|
- AuditInfoUtil.updateData(vos);
|
|
|
- }
|
|
|
-
|
|
|
- protected void setDisableFlag(T[] vos) {
|
|
|
- SuperVO[] var2 = vos;
|
|
|
- int var3 = vos.length;
|
|
|
-
|
|
|
- for (int var4 = 0; var4 < var3; ++var4) {
|
|
|
- T vo = (T) var2[var4];
|
|
|
- vo.setAttributeValue("enablestate", 3);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- protected void fireBeforeDisableEvent(T[] vos) throws BusinessException {
|
|
|
- BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
- eventUtil.dispatchEnableToDisableBeforeEvent((Object[]) vos);
|
|
|
- }
|
|
|
-
|
|
|
- protected void fireAfterDisableEvent(T[] vos) throws BusinessException {
|
|
|
- BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
- eventUtil.dispatchEnableToDisableAfterEvent((Object[]) vos);
|
|
|
- }
|
|
|
-
|
|
|
- protected void dbDisable(T[] vos) throws BusinessException {
|
|
|
- String[] updateFields = new String[]{"enablestate", "modifier", "modifiedtime"};
|
|
|
- this.getPersistenceUtil().updateVOWithAttrs(updateFields, vos);
|
|
|
- }
|
|
|
-
|
|
|
- protected void writeDisableBusiLog(T... vos) throws BusinessException {
|
|
|
- this.getBusiLogUtil().writeBusiLog("disable", (String) null, vos);
|
|
|
- }
|
|
|
-
|
|
|
- protected T retrieveVO(String pk) throws BusinessException {
|
|
|
- T[] vos = this.retrieveVO(new String[]{pk});
|
|
|
- return ArrayUtils.isEmpty(vos) ? null : vos[0];
|
|
|
- }
|
|
|
-
|
|
|
- protected T[] retrieveVO(String[] pks) throws BusinessException {
|
|
|
- return this.getPersistenceUtil().retrieveVO(pks);
|
|
|
- }
|
|
|
-
|
|
|
- protected T retrieveVOByFields(String[] fields, String pk) throws BusinessException {
|
|
|
- T[] vos = this.getPersistenceUtil().retrieveVOByFields(new String[]{pk}, fields);
|
|
|
- return ArrayUtils.isEmpty(vos) ? null : vos[0];
|
|
|
- }
|
|
|
-
|
|
|
- protected T[] retrieveSubVOsWithSelf(T vo) throws BusinessException {
|
|
|
- return this.getPersistenceUtil().retrieveSubVOsWithSelf(vo.getPrimaryKey());
|
|
|
- }
|
|
|
-
|
|
|
- protected T[] convertToVOArray(T obj) throws BusinessException {
|
|
|
- return VOArrayUtil.convertToVOArray(this.getPersistenceUtil().getEntityClass(), new Object[]{obj});
|
|
|
- }
|
|
|
-
|
|
|
- protected BDUniqueFieldTrimUtil getUniqueFieldTrimUtil() {
|
|
|
- if (this.uniqueFieldTrimUtil == null) {
|
|
|
- this.uniqueFieldTrimUtil = new BDUniqueFieldTrimUtil(this.getMDId());
|
|
|
- }
|
|
|
-
|
|
|
- return this.uniqueFieldTrimUtil;
|
|
|
- }
|
|
|
+package nc.bs.bd.baseservice.md;
|
|
|
+
|
|
|
+import java.lang.reflect.Array;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+import nc.bs.baseapp.sendZP.DeptSendZP;
|
|
|
+import nc.bs.baseapp.sendZP.OrgSendZP;
|
|
|
+import nc.bs.bd.baseservice.BDUniqueFieldTrimUtil;
|
|
|
+import nc.bs.bd.baseservice.busilog.BDBusiLogUtil;
|
|
|
+import nc.bs.bd.baseservice.busilog.IBDBusiLogUtil;
|
|
|
+import nc.bs.bd.baseservice.persistence.ITreePersistenceUtil;
|
|
|
+import nc.bs.bd.baseservice.persistence.MDTreePersistenceUtil;
|
|
|
+import nc.bs.bd.baseservice.persistence.TreeRootInnerCodeLockUtil;
|
|
|
+import nc.bs.bd.baseservice.validator.BDTreeEnableValidator;
|
|
|
+import nc.bs.businessevent.bd.BDCommonEventUtil;
|
|
|
+import nc.bs.uif2.validation.IValidationService;
|
|
|
+import nc.bs.uif2.validation.ValidationFrameworkUtil;
|
|
|
+import nc.bs.uif2.validation.Validator;
|
|
|
+import nc.vo.org.DeptVO;
|
|
|
+import nc.vo.org.FinanceOrgVO;
|
|
|
+import nc.vo.org.OrgVO;
|
|
|
+import nc.vo.pub.BusinessException;
|
|
|
+import nc.vo.pub.CircularlyAccessibleValueObject;
|
|
|
+import nc.vo.pub.SuperVO;
|
|
|
+import nc.vo.pub.lang.UFBoolean;
|
|
|
+import nc.vo.util.AuditInfoUtil;
|
|
|
+import nc.vo.util.BDReferenceChecker;
|
|
|
+import nc.vo.util.BDUniqueRuleValidate;
|
|
|
+import nc.vo.util.BDVersionValidationUtil;
|
|
|
+import nc.vo.util.bizlock.BizlockDataUtil;
|
|
|
+import nccloud.commons.lang.ArrayUtils;
|
|
|
+import nccloud.commons.lang.StringUtils;
|
|
|
+
|
|
|
+public class TreeBaseService<T extends SuperVO> {
|
|
|
+ private String MDId;
|
|
|
+ private String[] subAttributeNames;
|
|
|
+ private IBDBusiLogUtil busiLogUtil;
|
|
|
+ private ITreePersistenceUtil<T> persistenceUtil;
|
|
|
+ private TreeRootInnerCodeLockUtil<T> rootLockUtil;
|
|
|
+ private BDUniqueFieldTrimUtil uniqueFieldTrimUtil;
|
|
|
+
|
|
|
+ public TreeBaseService(String mdID, String[] subAttributeNames) {
|
|
|
+ this(mdID, subAttributeNames, (ITreePersistenceUtil) null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public TreeBaseService(String mdID, String[] subAttributeNames, ITreePersistenceUtil<T> persistenceUtil) {
|
|
|
+ this.busiLogUtil = null;
|
|
|
+ this.rootLockUtil = null;
|
|
|
+ this.MDId = mdID;
|
|
|
+ this.persistenceUtil = persistenceUtil;
|
|
|
+ this.subAttributeNames = subAttributeNames;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getMDId() {
|
|
|
+ return this.MDId;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String[] getSubAttributeNames() {
|
|
|
+ return this.subAttributeNames == null ? null : (String[]) this.subAttributeNames.clone();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected ITreePersistenceUtil<T> getPersistenceUtil() {
|
|
|
+ if (this.persistenceUtil == null) {
|
|
|
+ this.persistenceUtil = new MDTreePersistenceUtil(this.getMDId(), this.getSubAttributeNames());
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.persistenceUtil;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected TreeRootInnerCodeLockUtil<T> getRootLockUtil() {
|
|
|
+ if (this.rootLockUtil == null) {
|
|
|
+ this.rootLockUtil = new TreeRootInnerCodeLockUtil(this.getPersistenceUtil());
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.rootLockUtil;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void setBusiLogUtil(IBDBusiLogUtil busiLogUtil) {
|
|
|
+ this.busiLogUtil = busiLogUtil;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected IBDBusiLogUtil getBusiLogUtil() {
|
|
|
+ if (this.busiLogUtil == null) {
|
|
|
+ this.busiLogUtil = new BDBusiLogUtil(this.getMDId());
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.busiLogUtil;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void deleteVO(T vo) throws BusinessException {
|
|
|
+ if (vo != null) {
|
|
|
+ this.deleteLockOperate(vo);
|
|
|
+ this.deleteVersionValidate(vo);
|
|
|
+ this.deleteValidateVO(vo);
|
|
|
+ this.fireBeforeDeleteEvent(vo);
|
|
|
+ this.notifyVersionChangeWhenDataDeleted(vo);
|
|
|
+ this.fireAfterDeleteEvent(vo);
|
|
|
+ this.dbDeleteVO(vo);
|
|
|
+ this.writeDeletedBusiLog(vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void deleteLockOperate(T vo) throws BusinessException {
|
|
|
+ this.getRootLockUtil().lockBranchRoot(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void deleteVersionValidate(T vo) throws BusinessException {
|
|
|
+ BDVersionValidationUtil.validateSuperVO(new SuperVO[]{vo});
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void deleteValidateVO(T vo) throws BusinessException {
|
|
|
+ IValidationService validateService = ValidationFrameworkUtil.createValidationService(this.getDeleteValidator());
|
|
|
+ validateService.validate(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected Validator[] getDeleteValidator() {
|
|
|
+ Validator[] validators = new Validator[]{BDReferenceChecker.getInstance()};
|
|
|
+ return validators;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void fireBeforeDeleteEvent(T vo) throws BusinessException {
|
|
|
+ BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
+ eventUtil.dispatchDeleteBeforeEvent(new Object[]{vo});
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void fireAfterDeleteEvent(T vo) throws BusinessException {
|
|
|
+ BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
+ eventUtil.dispatchDeleteAfterEvent(new Object[]{vo});
|
|
|
+ //部门传HS Yaoy 2022-08-03
|
|
|
+ //公共方法,vo获取失败吃掉异常
|
|
|
+ DeptVO[] deptVOarr = new DeptVO[1];
|
|
|
+
|
|
|
+ try {
|
|
|
+ deptVOarr[0] = (DeptVO) vo;
|
|
|
+ } catch (Exception e) {}
|
|
|
+
|
|
|
+ if(deptVOarr[0] != null) {
|
|
|
+ DeptSendZP.process(deptVOarr, "delete");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(deptVOarr[0] == null) {
|
|
|
+ //组织传租聘系统 YY 2022-08-22
|
|
|
+ FinanceOrgVO financeOrgVO = new FinanceOrgVO();
|
|
|
+ try {
|
|
|
+ OrgVO orgVO = (OrgVO) vo;
|
|
|
+ //是否业务单元数据,不是不走接口
|
|
|
+ if(orgVO.getIsbusinessunit().booleanValue()) {
|
|
|
+ financeOrgVO.setCode(orgVO.getCode());
|
|
|
+ financeOrgVO.setName(orgVO.getName());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {}
|
|
|
+ if(financeOrgVO.getCode() != null && financeOrgVO.getCode().length() != 0) {
|
|
|
+ OrgSendZP.process(financeOrgVO, "delete");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void dbDeleteVO(T vo) throws BusinessException {
|
|
|
+ this.getPersistenceUtil().deleteVO(this.convertToVOArray(vo));
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void notifyVersionChangeWhenDataDeleted(T vo) throws BusinessException {
|
|
|
+ this.getPersistenceUtil().notifyVersionChangeWhenDataDeleted((T[]) new SuperVO[]{vo});
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void writeDeletedBusiLog(T vo) throws BusinessException {
|
|
|
+ this.getBusiLogUtil().writeBusiLog("delete", (String) null, new SuperVO[]{vo});
|
|
|
+ }
|
|
|
+
|
|
|
+ public T insertVO(T vo) throws BusinessException {
|
|
|
+ if (vo == null) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ this.getUniqueFieldTrimUtil().trimUniqueFields(new SuperVO[]{vo});
|
|
|
+ this.insertLockOperate(this.convertToVOArray(vo));
|
|
|
+ this.insertValidateVO(vo);
|
|
|
+ this.setInsertAuditInfo(this.convertToVOArray(vo));
|
|
|
+ this.fireBeforeInsertEvent(this.convertToVOArray(vo));
|
|
|
+ String pk = this.dbInsertVO(vo);
|
|
|
+ vo = this.retrieveVO(pk);
|
|
|
+ this.notifyVersionChangeWhenDataInserted(this.convertToVOArray(vo));
|
|
|
+ this.fireAfterInsertEvent(this.convertToVOArray(vo));
|
|
|
+ this.writeInsertBusiLog(this.convertToVOArray(vo));
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void insertVOs(T[] vos) throws BusinessException {
|
|
|
+ if (vos != null && vos.length != 0) {
|
|
|
+ this.getUniqueFieldTrimUtil().trimUniqueFields(vos);
|
|
|
+ this.insertLockOperate(vos);
|
|
|
+ this.insertValidateVO(vos);
|
|
|
+ this.setInsertAuditInfo(vos);
|
|
|
+ this.fireBeforeInsertEvent(vos);
|
|
|
+ String[] pks = this.dbInsertVOs(vos);
|
|
|
+ vos = this.retrieveVO(pks);
|
|
|
+ this.notifyVersionChangeWhenDataInserted(vos);
|
|
|
+ this.fireAfterInsertEvent(vos);
|
|
|
+ this.writeInsertBusiLog(vos);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void insertLockOperate(T... vos) throws BusinessException {
|
|
|
+ List<T> needToLockRoot = this.getParentNotExistsVOs(vos);
|
|
|
+ Iterator var3 = needToLockRoot.iterator();
|
|
|
+
|
|
|
+ while (var3.hasNext()) {
|
|
|
+ T vo = (T) var3.next();
|
|
|
+ this.getRootLockUtil().lockBranchRoot(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ BizlockDataUtil.lockDataByBizlock(vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<T> getParentNotExistsVOs(T... vos) throws BusinessException {
|
|
|
+ Set<String> pkSet = new HashSet();
|
|
|
+
|
|
|
+ for (int i = 0; i < vos.length; ++i) {
|
|
|
+ pkSet.add(vos[i].getPrimaryKey());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<T> parentNotInPkSetVOs = new ArrayList();
|
|
|
+ String parentField = this.getPersistenceUtil().getParentPkFieldName();
|
|
|
+
|
|
|
+ for (int i = 0; i < vos.length; ++i) {
|
|
|
+ if (!pkSet.contains(vos[i].getAttributeValue(parentField))) {
|
|
|
+ parentNotInPkSetVOs.add(vos[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return parentNotInPkSetVOs;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void insertValidateVO(T vo) throws BusinessException {
|
|
|
+ IValidationService validationService = ValidationFrameworkUtil
|
|
|
+ .createValidationService(this.getInsertValidator());
|
|
|
+ validationService.validate(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void insertValidateVO(T[] vos) throws BusinessException {
|
|
|
+ IValidationService validationService = ValidationFrameworkUtil
|
|
|
+ .createValidationService(this.getInsertValidator());
|
|
|
+ validationService.validate(vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected Validator[] getInsertValidator() {
|
|
|
+ Validator[] validators = new Validator[]{new BDUniqueRuleValidate()};
|
|
|
+ return validators;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void setInsertAuditInfo(T... vos) throws BusinessException {
|
|
|
+ AuditInfoUtil.addData(vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void fireBeforeInsertEvent(T... vos) throws BusinessException {
|
|
|
+ BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
+ eventUtil.dispatchInsertBeforeEvent((Object[]) vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void fireAfterInsertEvent(T... vos) throws BusinessException {
|
|
|
+ BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
+ eventUtil.dispatchInsertAfterEvent((Object[]) vos);
|
|
|
+
|
|
|
+ //部门传ZP Yaoy 2022-08-03
|
|
|
+ //公共方法,vo获取失败吃掉异常
|
|
|
+ DeptVO[] deptVOarr = new DeptVO[vos.length];
|
|
|
+ try {
|
|
|
+ deptVOarr = (DeptVO[]) vos;
|
|
|
+ } catch (Exception e) {}
|
|
|
+ if(deptVOarr[0] != null) {
|
|
|
+ DeptSendZP.process(deptVOarr, "add");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected String dbInsertVO(T vo) throws BusinessException {
|
|
|
+ String[] pks = this.getPersistenceUtil().insertVOWithInnerCode(this.convertToVOArray(vo));
|
|
|
+ return pks != null && pks.length > 0 ? pks[0] : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected String[] dbInsertVOs(T... vos) throws BusinessException {
|
|
|
+ return this.getPersistenceUtil().insertVOWithInnerCode(vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void notifyVersionChangeWhenDataInserted(T... vos) throws BusinessException {
|
|
|
+ this.getPersistenceUtil().notifyVersionChangeWhenDataInserted(vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void writeInsertBusiLog(T... vos) throws BusinessException {
|
|
|
+ this.getBusiLogUtil().writeBusiLog("add", (String) null, vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ public T updateVO(T vo) throws BusinessException {
|
|
|
+ if (vo == null) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ this.getUniqueFieldTrimUtil().trimUniqueFields(new SuperVO[]{vo});
|
|
|
+ this.updateLockOperate(vo);
|
|
|
+ this.updateVersionValidate(vo);
|
|
|
+ T oldVO = this.retrieveVO(vo.getPrimaryKey());
|
|
|
+ this.updateValidateVO(oldVO, vo);
|
|
|
+ this.setUpdateAuditInfo(this.convertToVOArray(vo));
|
|
|
+ this.fireBeforeUpdateEvent(oldVO, vo);
|
|
|
+ this.dbUpdateVO(oldVO, vo);
|
|
|
+ vo = this.retrieveVO(vo.getPrimaryKey());
|
|
|
+ this.notifyVersionChangeWhenDataUpdated(this.convertToVOArray(vo));
|
|
|
+ this.fireAfterUpdateEvent(oldVO, vo);
|
|
|
+ this.writeUpdatedBusiLog(this.convertToVOArray(oldVO), this.convertToVOArray(vo));
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public T updateVOWithSub(T vo, ITreeUpdateWithChildren<T> updatWithChildren) throws BusinessException {
|
|
|
+ if (vo == null) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ this.getUniqueFieldTrimUtil().trimUniqueFields(new SuperVO[]{vo});
|
|
|
+ this.updateLockOperate(vo);
|
|
|
+ this.updateVersionValidate(vo);
|
|
|
+ T[] oldVOs = this.retrieveSubVOsWithSelf(vo);
|
|
|
+ T oldVO = this.getVOByPk(oldVOs, vo.getPrimaryKey());
|
|
|
+ this.updateValidateVO(oldVO, vo);
|
|
|
+ T[] updateVOs = this.createToUpdateVOsByOldSubVOs(vo, oldVOs, updatWithChildren);
|
|
|
+ this.setUpdateAuditInfo(updateVOs);
|
|
|
+ this.fireBeforeUpdateEvent(oldVOs, updateVOs);
|
|
|
+ this.dbUpdateVOWithSub(oldVO, updateVOs, updatWithChildren);
|
|
|
+ updateVOs = this.retrieveVO(VOArrayUtil.getPrimaryKeyArray(updateVOs));
|
|
|
+ this.notifyVersionChangeWhenDataUpdated(updateVOs);
|
|
|
+ this.fireAfterUpdateEvent(oldVOs, updateVOs);
|
|
|
+ this.writeUpdatedBusiLog(oldVOs, updateVOs);
|
|
|
+ return this.getVOByPk(updateVOs, vo.getPrimaryKey());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void updateLockOperate(T vo) throws BusinessException {
|
|
|
+ this.getRootLockUtil().lockBranchRootWhenParentChanged(vo);
|
|
|
+ BizlockDataUtil.lockDataByBizlock(new CircularlyAccessibleValueObject[]{vo});
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void updateVersionValidate(T vo) throws BusinessException {
|
|
|
+ BDVersionValidationUtil.validateSuperVO(new SuperVO[]{vo});
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void updateValidateVO(T oldVO, T vo) throws BusinessException {
|
|
|
+ IValidationService validationService = ValidationFrameworkUtil
|
|
|
+ .createValidationService(this.getUpdateValidator(oldVO));
|
|
|
+ validationService.validate(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected Validator[] getUpdateValidator(T oldVO) {
|
|
|
+ Validator[] validators = new Validator[]{new BDUniqueRuleValidate()};
|
|
|
+ return validators;
|
|
|
+ }
|
|
|
+
|
|
|
+ private T[] createToUpdateVOsByOldSubVOs(T newVO, T[] oldVOs, ITreeUpdateWithChildren<T> updatWithChildren)
|
|
|
+ throws BusinessException {
|
|
|
+ T oldVO = this.getVOByPk(oldVOs, newVO.getPrimaryKey());
|
|
|
+ T[] newVOs = (T[]) ((SuperVO[]) Array.newInstance(newVO.getClass(), oldVOs.length));
|
|
|
+
|
|
|
+ for (int i = 0; i < oldVOs.length; ++i) {
|
|
|
+ if (StringUtils.equals(oldVOs[i].getPrimaryKey(), newVO.getPrimaryKey())) {
|
|
|
+ newVOs[i] = newVO;
|
|
|
+ } else {
|
|
|
+ newVOs[i] = updatWithChildren.getUpdateChildrenVO(oldVO, newVO, (T) oldVOs[i].clone());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return newVOs;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void setUpdateAuditInfo(T... vo) {
|
|
|
+ AuditInfoUtil.updateData(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void fireBeforeUpdateEvent(T oldVO, T vo) throws BusinessException {
|
|
|
+ BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
+ eventUtil.setOldObjs(new Object[]{oldVO});
|
|
|
+ eventUtil.dispatchUpdateBeforeEvent(new Object[]{vo});
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void fireBeforeUpdateEvent(T[] oldVOs, T[] vos) throws BusinessException {
|
|
|
+ BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
+ eventUtil.setOldObjs(oldVOs);
|
|
|
+ eventUtil.dispatchUpdateBeforeEvent((Object[]) vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void fireAfterUpdateEvent(T oldVO, T vo) throws BusinessException {
|
|
|
+ BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
+ eventUtil.setOldObjs(new Object[]{oldVO});
|
|
|
+ eventUtil.dispatchUpdateAfterEvent(new Object[]{vo});
|
|
|
+
|
|
|
+
|
|
|
+ //部门传ZP Yaoy 2022-08-03
|
|
|
+ //公共方法,vo获取失败吃掉异常
|
|
|
+ DeptVO[] deptVOarr = new DeptVO[1];
|
|
|
+ try {
|
|
|
+ deptVOarr[0] = (DeptVO) vo;
|
|
|
+ } catch (Exception e) {}
|
|
|
+ if(deptVOarr[0] != null) {
|
|
|
+ //Yaoy 2022-11-25
|
|
|
+ if(deptVOarr[0].getMemo() == null) {
|
|
|
+ DeptSendZP.process(deptVOarr, "update");
|
|
|
+ System.out.println();
|
|
|
+ }else {
|
|
|
+ if(!"不传租凭系统".equals(deptVOarr[0].getMemo())) {
|
|
|
+ DeptSendZP.process(deptVOarr, "update");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void fireAfterUpdateEvent(T[] oldVOs, T[] vos) throws BusinessException {
|
|
|
+ BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
+ eventUtil.setOldObjs(oldVOs);
|
|
|
+ eventUtil.dispatchUpdateAfterEvent((Object[]) vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void dbUpdateVO(T oldVO, T vo) throws BusinessException {
|
|
|
+ this.getPersistenceUtil().updateVOWithInnerCode(vo, oldVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void dbUpdateVOWithSub(T oldVO, T[] updateVOs, ITreeUpdateWithChildren<T> updatWithChildren)
|
|
|
+ throws BusinessException {
|
|
|
+ this.getPersistenceUtil().updateVOWithInnerCode(this.getVOByPk(updateVOs, oldVO.getPrimaryKey()), oldVO);
|
|
|
+ T[] vos = this.filterVOsByPk(updateVOs, oldVO.getPrimaryKey());
|
|
|
+ this.getPersistenceUtil().updateVOWithAttrs(updatWithChildren.getChildrenUpdateFields(), vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ private T getVOByPk(T[] vos, String pk) {
|
|
|
+ for (int i = 0; i < vos.length; ++i) {
|
|
|
+ if (StringUtils.equals(vos[i].getPrimaryKey(), pk)) {
|
|
|
+ return vos[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private T[] filterVOsByPk(T[] updateVOs, String pk) throws BusinessException {
|
|
|
+ List<T> list = new ArrayList();
|
|
|
+
|
|
|
+ for (int i = 0; i < updateVOs.length; ++i) {
|
|
|
+ if (!StringUtils.equals(updateVOs[i].getPrimaryKey(), pk)) {
|
|
|
+ list.add(updateVOs[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ T[] vos = VOArrayUtil.convertToVOArray(this.getPersistenceUtil().getEntityClass(), list.toArray());
|
|
|
+ return vos;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void notifyVersionChangeWhenDataUpdated(T... vos) throws BusinessException {
|
|
|
+ this.getPersistenceUtil().notifyVersionChangeWhenDataInserted(vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void writeUpdatedBusiLog(T[] oldVOs, T[] vos) throws BusinessException {
|
|
|
+ this.getBusiLogUtil().writeModefyBusiLog("edit", vos, oldVOs);
|
|
|
+ }
|
|
|
+
|
|
|
+ public T enableVO(T vo) throws BusinessException {
|
|
|
+ if (vo == null) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ this.enableLockOperate(vo);
|
|
|
+ this.enableVersionValidate(vo);
|
|
|
+ if (this.isDataEnabled(vo)) {
|
|
|
+ return vo;
|
|
|
+ } else {
|
|
|
+ this.enableValidateVO(vo);
|
|
|
+ this.setEnableAuditInfo(vo);
|
|
|
+ this.setEnableFlag(vo);
|
|
|
+ T oldVO = this.retrieveVOByFields(new String[]{"enablestate"}, vo.getPrimaryKey());
|
|
|
+ this.fireBeforeEnableEvent(oldVO, vo);
|
|
|
+ this.dbEnableVO(vo);
|
|
|
+ vo = this.retrieveVO(vo.getPrimaryKey());
|
|
|
+ this.notifyVersionChangeWhenDataUpdated(this.convertToVOArray(vo));
|
|
|
+ this.fireAfterEnableEvent(oldVO, vo);
|
|
|
+ this.writeEnableBusiLog(vo);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void enableLockOperate(T vo) throws BusinessException {
|
|
|
+ this.getRootLockUtil().lockBranchRoot(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void enableVersionValidate(T vo) throws BusinessException {
|
|
|
+ BDVersionValidationUtil.validateSuperVO(new SuperVO[]{vo});
|
|
|
+ }
|
|
|
+
|
|
|
+ protected boolean isDataEnabled(T vo) {
|
|
|
+ Integer enable_state = (Integer) vo.getAttributeValue("enablestate");
|
|
|
+ return 2 == enable_state;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void enableValidateVO(T vo) throws BusinessException {
|
|
|
+ IValidationService validateService = ValidationFrameworkUtil.createValidationService(this.getEnableValidator());
|
|
|
+ validateService.validate(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected Validator[] getEnableValidator() throws BusinessException {
|
|
|
+ return new Validator[]{new BDTreeEnableValidator()};
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void setEnableAuditInfo(T vo) {
|
|
|
+ AuditInfoUtil.updateData(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void setEnableFlag(T vo) {
|
|
|
+ vo.setAttributeValue("enablestate", 2);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void fireBeforeEnableEvent(T oldVO, T vo) throws BusinessException {
|
|
|
+ BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
+ if (3 == (Integer) oldVO.getAttributeValue("enablestate")) {
|
|
|
+ eventUtil.dispatchDisableToEnableBeforeEvent(new Object[]{vo});
|
|
|
+ } else {
|
|
|
+ eventUtil.dispatchInitToEnableBeforeEvent(new Object[]{vo});
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void fireAfterEnableEvent(T oldVO, T vo) throws BusinessException {
|
|
|
+ BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
+ if (3 == (Integer) oldVO.getAttributeValue("enablestate")) {
|
|
|
+ eventUtil.dispatchDisableToEnableAfterEvent(new Object[]{vo});
|
|
|
+ } else {
|
|
|
+ eventUtil.dispatchInitToEnableAfterEvent(new Object[]{vo});
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void dbEnableVO(T vo) throws BusinessException {
|
|
|
+ String[] updateFields = new String[]{"enablestate", "modifier", "modifiedtime"};
|
|
|
+ this.getPersistenceUtil().updateVOWithAttrs(updateFields, this.convertToVOArray(vo));
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void writeEnableBusiLog(T vo) throws BusinessException {
|
|
|
+ this.getBusiLogUtil().writeBusiLog("enable", (String) null, new SuperVO[]{vo});
|
|
|
+ }
|
|
|
+
|
|
|
+ public T disableVO(T vo) throws BusinessException {
|
|
|
+ if (vo == null) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ this.disableLockOperate(vo);
|
|
|
+ this.disableVersionValidate(vo);
|
|
|
+ if (this.isDataDisabled(vo)) {
|
|
|
+ return vo;
|
|
|
+ } else {
|
|
|
+ this.disableValidateVO(vo);
|
|
|
+ T[] needDisableVOs = this.retrieveSubVOsWithSelf(vo);
|
|
|
+ this.setDisableAuditInfo(needDisableVOs);
|
|
|
+ this.setDisableFlag(needDisableVOs);
|
|
|
+ this.fireBeforeDisableEvent(needDisableVOs);
|
|
|
+ this.dbDisable(needDisableVOs);
|
|
|
+ needDisableVOs = this.retrieveVO(VOArrayUtil.getPrimaryKeyArray(needDisableVOs));
|
|
|
+ this.notifyVersionChangeWhenDataUpdated(needDisableVOs);
|
|
|
+ this.fireAfterDisableEvent(needDisableVOs);
|
|
|
+ this.writeDisableBusiLog(needDisableVOs);
|
|
|
+ return needDisableVOs[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void disableLockOperate(T vo) throws BusinessException {
|
|
|
+ this.getRootLockUtil().lockBranchRoot(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void disableVersionValidate(T vo) throws BusinessException {
|
|
|
+ BDVersionValidationUtil.validateSuperVO(new SuperVO[]{vo});
|
|
|
+ }
|
|
|
+
|
|
|
+ protected boolean isDataDisabled(T vo) {
|
|
|
+ Integer enable_state = (Integer) vo.getAttributeValue("enablestate");
|
|
|
+ return 3 == enable_state;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void disableValidateVO(T vo) throws BusinessException {
|
|
|
+ IValidationService validateService = ValidationFrameworkUtil
|
|
|
+ .createValidationService(this.getDisableValidator());
|
|
|
+ validateService.validate(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected Validator[] getDisableValidator() throws BusinessException {
|
|
|
+ return new Validator[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void setDisableAuditInfo(T[] vos) {
|
|
|
+ AuditInfoUtil.updateData(vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void setDisableFlag(T[] vos) {
|
|
|
+ SuperVO[] var2 = vos;
|
|
|
+ int var3 = vos.length;
|
|
|
+
|
|
|
+ for (int var4 = 0; var4 < var3; ++var4) {
|
|
|
+ T vo = (T) var2[var4];
|
|
|
+ vo.setAttributeValue("enablestate", 3);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void fireBeforeDisableEvent(T[] vos) throws BusinessException {
|
|
|
+ BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
+ eventUtil.dispatchEnableToDisableBeforeEvent((Object[]) vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void fireAfterDisableEvent(T[] vos) throws BusinessException {
|
|
|
+ BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
+ eventUtil.dispatchEnableToDisableAfterEvent((Object[]) vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void dbDisable(T[] vos) throws BusinessException {
|
|
|
+ String[] updateFields = new String[]{"enablestate", "modifier", "modifiedtime"};
|
|
|
+ this.getPersistenceUtil().updateVOWithAttrs(updateFields, vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void writeDisableBusiLog(T... vos) throws BusinessException {
|
|
|
+ this.getBusiLogUtil().writeBusiLog("disable", (String) null, vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected T retrieveVO(String pk) throws BusinessException {
|
|
|
+ T[] vos = this.retrieveVO(new String[]{pk});
|
|
|
+ return ArrayUtils.isEmpty(vos) ? null : vos[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ protected T[] retrieveVO(String[] pks) throws BusinessException {
|
|
|
+ return this.getPersistenceUtil().retrieveVO(pks);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected T retrieveVOByFields(String[] fields, String pk) throws BusinessException {
|
|
|
+ T[] vos = this.getPersistenceUtil().retrieveVOByFields(new String[]{pk}, fields);
|
|
|
+ return ArrayUtils.isEmpty(vos) ? null : vos[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ protected T[] retrieveSubVOsWithSelf(T vo) throws BusinessException {
|
|
|
+ return this.getPersistenceUtil().retrieveSubVOsWithSelf(vo.getPrimaryKey());
|
|
|
+ }
|
|
|
+
|
|
|
+ protected T[] convertToVOArray(T obj) throws BusinessException {
|
|
|
+ return VOArrayUtil.convertToVOArray(this.getPersistenceUtil().getEntityClass(), new Object[]{obj});
|
|
|
+ }
|
|
|
+
|
|
|
+ protected BDUniqueFieldTrimUtil getUniqueFieldTrimUtil() {
|
|
|
+ if (this.uniqueFieldTrimUtil == null) {
|
|
|
+ this.uniqueFieldTrimUtil = new BDUniqueFieldTrimUtil(this.getMDId());
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.uniqueFieldTrimUtil;
|
|
|
+ }
|
|
|
}
|