|
@@ -1,602 +1,609 @@
|
|
|
-package nc.bs.bd.baseservice.md;
|
|
|
-
|
|
|
-import java.lang.reflect.Array;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-import nc.bs.baseapp.sendZP.OrgSendZP;
|
|
|
-import nc.bs.baseapp.sendZP.SupplierShendZP;
|
|
|
-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.IPersistenceUtil;
|
|
|
-import nc.bs.bd.baseservice.persistence.MDPersistenceUtil;
|
|
|
-import nc.bs.bd.service.ValueObjWithErrLog;
|
|
|
-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.bd.supplier.SupplierVO;
|
|
|
-import nc.vo.org.FinanceOrgVO;
|
|
|
-import nc.vo.pub.BusinessException;
|
|
|
-import nc.vo.pub.CircularlyAccessibleValueObject;
|
|
|
-import nc.vo.pub.SuperVO;
|
|
|
-import nc.vo.util.AuditInfoUtil;
|
|
|
-import nc.vo.util.BDPKLockUtil;
|
|
|
-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;
|
|
|
-
|
|
|
-public class SingleBaseService<T extends SuperVO> {
|
|
|
- private String MDId;
|
|
|
- private String[] subAttributeNames;
|
|
|
- private IBDBusiLogUtil busiLogUtil;
|
|
|
- private IPersistenceUtil<T> persistenceUtil;
|
|
|
- private BDUniqueFieldTrimUtil uniqueFieldTrimUtil;
|
|
|
-
|
|
|
- public SingleBaseService(String MDId) {
|
|
|
- this(MDId, (String[]) null);
|
|
|
- }
|
|
|
-
|
|
|
- public SingleBaseService(String MDId, String[] subAttributeNames) {
|
|
|
- this.busiLogUtil = null;
|
|
|
- this.persistenceUtil = null;
|
|
|
- this.MDId = MDId;
|
|
|
- this.subAttributeNames = subAttributeNames;
|
|
|
- }
|
|
|
-
|
|
|
- public String getMDId() {
|
|
|
- return this.MDId;
|
|
|
- }
|
|
|
-
|
|
|
- public String[] getSubAttributeNames() {
|
|
|
- return this.subAttributeNames == null ? null : (String[]) this.subAttributeNames.clone();
|
|
|
- }
|
|
|
-
|
|
|
- protected IPersistenceUtil<T> getPersistenceUtil() {
|
|
|
- if (this.persistenceUtil == null) {
|
|
|
- this.persistenceUtil = new MDPersistenceUtil(this.getMDId(), this.getSubAttributeNames());
|
|
|
- }
|
|
|
-
|
|
|
- return this.persistenceUtil;
|
|
|
- }
|
|
|
-
|
|
|
- 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);
|
|
|
- BDVersionValidationUtil.validateSuperVO(new SuperVO[]{vo});
|
|
|
- this.deleteValidateVO(vo);
|
|
|
- this.fireBeforeDeleteEvent(vo);
|
|
|
- this.notifyVersionChangeWhenDataDeleted(vo);
|
|
|
- this.dbDeleteVO(vo);
|
|
|
- this.fireAfterDeleteEvent(vo);
|
|
|
- this.writeDeletedBusiLog(vo);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected void deletelockOperate(T vo) throws BusinessException {
|
|
|
- BDPKLockUtil.lockSuperVO(new SuperVO[]{vo});
|
|
|
- }
|
|
|
-
|
|
|
- protected void deleteValidateVO(T vo) throws BusinessException {
|
|
|
- IValidationService validationService = ValidationFrameworkUtil
|
|
|
- .createValidationService(this.getDeleteValidator());
|
|
|
- validationService.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 notifyVersionChangeWhenDataDeleted(T vo) throws BusinessException {
|
|
|
- this.getPersistenceUtil().notifyVersionChangeWhenDataDeleted(this.convertToVOArray(vo));
|
|
|
- }
|
|
|
-
|
|
|
- protected void dbDeleteVO(T vo) throws BusinessException {
|
|
|
- this.getPersistenceUtil().deleteVO(this.convertToVOArray(vo));
|
|
|
- }
|
|
|
-
|
|
|
- protected void fireAfterDeleteEvent(T vo) throws BusinessException {
|
|
|
- BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
- eventUtil.dispatchDeleteAfterEvent(new Object[]{vo});
|
|
|
- //供应商传ZP Yaoy 2022-08-03
|
|
|
- //公共方法,vo获取失败吃掉异常
|
|
|
- SupplierVO[] supplierVOarr = new SupplierVO[1];
|
|
|
- try {
|
|
|
- supplierVOarr[0] = (SupplierVO) vo;
|
|
|
- } catch (Exception e) {}
|
|
|
- if(supplierVOarr[0] != null) {
|
|
|
- SupplierShendZP.process(supplierVOarr, "delete");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- 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 vo;
|
|
|
- } else {
|
|
|
- this.getUniqueFieldTrimUtil().trimUniqueFields(new SuperVO[]{vo});
|
|
|
- this.insertlockOperate(vo);
|
|
|
- this.insertValidateVO(vo);
|
|
|
- this.setInsertAuditInfo(vo);
|
|
|
- this.fireBeforeInsertEvent(vo);
|
|
|
- String pk = this.dbInsertVO(vo);
|
|
|
- vo = this.retrieveVO(pk);
|
|
|
- this.notifyVersionChangeWhenDataInserted(vo);
|
|
|
- this.fireAfterInsertEvent(vo);
|
|
|
- this.writeInsertBusiLog(vo);
|
|
|
- return vo;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected void insertlockOperate(T vo) throws BusinessException {
|
|
|
- BizlockDataUtil.lockDataByBizlock(new CircularlyAccessibleValueObject[]{vo});
|
|
|
- }
|
|
|
-
|
|
|
- protected void insertValidateVO(T vo) throws BusinessException {
|
|
|
- IValidationService validateService = ValidationFrameworkUtil.createValidationService(this.getInsertValidator());
|
|
|
- validateService.validate(vo);
|
|
|
- }
|
|
|
-
|
|
|
- protected Validator[] getInsertValidator() {
|
|
|
- Validator[] validators = new Validator[]{new BDUniqueRuleValidate()};
|
|
|
- return validators;
|
|
|
- }
|
|
|
-
|
|
|
- protected void setInsertAuditInfo(T vo) {
|
|
|
- AuditInfoUtil.addData(vo);
|
|
|
- }
|
|
|
-
|
|
|
- protected void fireBeforeInsertEvent(T vo) throws BusinessException {
|
|
|
- BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
- eventUtil.dispatchInsertBeforeEvent(new Object[]{vo});
|
|
|
- //供应商传ZP Yaoy 2022-08-03
|
|
|
- //公共方法,vo获取失败吃掉异常
|
|
|
- SupplierVO[] supplierVOarr = new SupplierVO[1];
|
|
|
- FinanceOrgVO financeOrgVO = new FinanceOrgVO();
|
|
|
- try {
|
|
|
- supplierVOarr[0] = (SupplierVO) vo;
|
|
|
- } catch (Exception e) {}
|
|
|
- try {
|
|
|
- financeOrgVO = (FinanceOrgVO) vo;
|
|
|
- } catch (Exception e) {}
|
|
|
- if(supplierVOarr[0] != null) {
|
|
|
- SupplierShendZP.process(supplierVOarr, "add");
|
|
|
- }
|
|
|
- if(financeOrgVO.getCode() != null) {
|
|
|
- OrgSendZP.process(financeOrgVO, "add");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected String dbInsertVO(T vo) throws BusinessException {
|
|
|
- String[] pks = this.getPersistenceUtil().insertVO(this.convertToVOArray(vo));
|
|
|
- return pks != null && pks.length > 0 ? pks[0] : null;
|
|
|
- }
|
|
|
-
|
|
|
- protected void notifyVersionChangeWhenDataInserted(T vo) throws BusinessException {
|
|
|
- this.getPersistenceUtil().notifyVersionChangeWhenDataInserted(this.convertToVOArray(vo));
|
|
|
- }
|
|
|
-
|
|
|
- protected void fireAfterInsertEvent(T vo) throws BusinessException {
|
|
|
- BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
- eventUtil.dispatchInsertAfterEvent(new Object[]{vo});
|
|
|
- }
|
|
|
-
|
|
|
- protected void writeInsertBusiLog(T vo) throws BusinessException {
|
|
|
- this.getBusiLogUtil().writeBusiLog("add", (String) null, new SuperVO[]{vo});
|
|
|
- }
|
|
|
-
|
|
|
- public T updateVO(T vo) throws BusinessException {
|
|
|
- if (vo == null) {
|
|
|
- return vo;
|
|
|
- } else {
|
|
|
- this.getUniqueFieldTrimUtil().trimUniqueFields(new SuperVO[]{vo});
|
|
|
- this.updatelockOperate(vo);
|
|
|
- BDVersionValidationUtil.validateSuperVO(new SuperVO[]{vo});
|
|
|
- T oldVO = this.retrieveVO(vo.getPrimaryKey());
|
|
|
- this.updateValidateVO(oldVO, vo);
|
|
|
- this.setUpdateAuditInfo(vo);
|
|
|
- this.fireBeforeUpdateEvent(oldVO, vo);
|
|
|
- this.dbUpdateVO(vo);
|
|
|
- this.notifyVersionChangeWhenDataUpdated(vo);
|
|
|
- vo = this.retrieveVO(vo.getPrimaryKey());
|
|
|
- this.fireAfterUpdateEvent(oldVO, vo);
|
|
|
- this.writeUpdatedBusiLog(oldVO, vo);
|
|
|
- return vo;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected void updatelockOperate(T vo) throws BusinessException {
|
|
|
- BDPKLockUtil.lockSuperVO(new SuperVO[]{vo});
|
|
|
- BizlockDataUtil.lockDataByBizlock(new CircularlyAccessibleValueObject[]{vo});
|
|
|
- }
|
|
|
-
|
|
|
- protected void updateValidateVO(T oldVO, T vo) throws BusinessException {
|
|
|
- IValidationService validateService = ValidationFrameworkUtil
|
|
|
- .createValidationService(this.getUpdateValidator(oldVO));
|
|
|
- validateService.validate(vo);
|
|
|
- }
|
|
|
-
|
|
|
- protected Validator[] getUpdateValidator(T oldVO) {
|
|
|
- Validator[] validators = new Validator[]{new BDUniqueRuleValidate()};
|
|
|
- return validators;
|
|
|
- }
|
|
|
-
|
|
|
- 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 dbUpdateVO(T vo) throws BusinessException {
|
|
|
- this.getPersistenceUtil().updateVO(this.convertToVOArray(vo));
|
|
|
- }
|
|
|
-
|
|
|
- protected void notifyVersionChangeWhenDataUpdated(T vo) throws BusinessException {
|
|
|
- this.getPersistenceUtil().notifyVersionChangeWhenDataUpdated(this.convertToVOArray(vo));
|
|
|
- }
|
|
|
-
|
|
|
- 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获取失败吃掉异常
|
|
|
- SupplierVO[] supplierVOarr = new SupplierVO[1];
|
|
|
- FinanceOrgVO financeOrgVO = new FinanceOrgVO();
|
|
|
- try {
|
|
|
- supplierVOarr[0] = (SupplierVO) vo;
|
|
|
- } catch (Exception e) {}
|
|
|
- try {
|
|
|
- financeOrgVO = (FinanceOrgVO) vo;
|
|
|
- } catch (Exception e) {}
|
|
|
- if(supplierVOarr[0] != null) {
|
|
|
- SupplierShendZP.process(supplierVOarr, "update");
|
|
|
- }
|
|
|
- if(financeOrgVO.getCode() != null) {
|
|
|
- OrgSendZP.process(financeOrgVO, "update");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected void writeUpdatedBusiLog(T oldVO, T vo) throws BusinessException {
|
|
|
- this.getBusiLogUtil().writeModefyBusiLog("edit", vo, oldVO);
|
|
|
- }
|
|
|
-
|
|
|
- public ValueObjWithErrLog disableVO(T... vos) throws BusinessException {
|
|
|
- ValueObjWithErrLog returnValue = null;
|
|
|
- if (vos != null && vos.length != 0) {
|
|
|
- this.disableLockOperate(vos);
|
|
|
- BDVersionValidationUtil.validateSuperVO(vos);
|
|
|
- returnValue = this.filterCanDisableVO(vos);
|
|
|
- T[] disabledVOs = (T[]) returnValue.getVos();
|
|
|
- if (!ArrayUtils.isEmpty(disabledVOs)) {
|
|
|
- this.setDisableFlag(disabledVOs);
|
|
|
- this.setDisableAuditInfo(disabledVOs);
|
|
|
- this.fireBeforeDisableEvent(disabledVOs);
|
|
|
- this.dbDisableVO(disabledVOs);
|
|
|
- this.notifyVersionChangeWhenDataUpdated(disabledVOs[0]);
|
|
|
- disabledVOs = this.retrieveVO(VOArrayUtil.getPrimaryKeyArray(disabledVOs));
|
|
|
- this.fireAfterDisableEvent(disabledVOs);
|
|
|
- this.writeDisableBusiLog(disabledVOs);
|
|
|
- returnValue.setVos(disabledVOs);
|
|
|
- }
|
|
|
-
|
|
|
- return returnValue;
|
|
|
- } else {
|
|
|
- return null;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected ValueObjWithErrLog filterCanDisableVO(T... vos) {
|
|
|
- T[] filteredVOs = this.filterVOByExcludeEnableState(3, vos);
|
|
|
- ValueObjWithErrLog returnWithErrLog = new ValueObjWithErrLog();
|
|
|
- returnWithErrLog.setVos(filteredVOs);
|
|
|
- if (!ArrayUtils.isEmpty(filteredVOs)) {
|
|
|
- ;
|
|
|
- }
|
|
|
-
|
|
|
- return returnWithErrLog;
|
|
|
- }
|
|
|
-
|
|
|
- public T disableSingleVO(T vo) throws BusinessException {
|
|
|
- if (vo == null) {
|
|
|
- return null;
|
|
|
- } else {
|
|
|
- this.disableLockOperate(this.convertToVOArray(vo));
|
|
|
- BDVersionValidationUtil.validateSuperVO(new SuperVO[]{vo});
|
|
|
- if (this.isDataDisabled(vo)) {
|
|
|
- return vo;
|
|
|
- } else {
|
|
|
- this.disableValidateVO(vo);
|
|
|
- this.setDisableFlag(this.convertToVOArray(vo));
|
|
|
- this.setDisableAuditInfo(this.convertToVOArray(vo));
|
|
|
- this.fireBeforeDisableEvent(this.convertToVOArray(vo));
|
|
|
- this.dbDisableVO(this.convertToVOArray(vo));
|
|
|
- this.notifyVersionChangeWhenDataUpdated(vo);
|
|
|
- vo = this.retrieveVO(vo.getPrimaryKey());
|
|
|
- this.fireAfterDisableEvent(this.convertToVOArray(vo));
|
|
|
- this.writeDisableBusiLog(this.convertToVOArray(vo));
|
|
|
- return vo;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected void disableLockOperate(T... vos) throws BusinessException {
|
|
|
- BDPKLockUtil.lockSuperVO(vos);
|
|
|
- }
|
|
|
-
|
|
|
- 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() {
|
|
|
- return new Validator[0];
|
|
|
- }
|
|
|
-
|
|
|
- protected void setDisableFlag(T... vos) {
|
|
|
- SuperVO[] var2 = vos;
|
|
|
- int var3 = vos.length;
|
|
|
-
|
|
|
- for (int var4 = 0; var4 < var3; ++var4) {
|
|
|
- T t = (T) var2[var4];
|
|
|
- t.setAttributeValue("enablestate", 3);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- protected void setDisableAuditInfo(T... vos) {
|
|
|
- AuditInfoUtil.updateData(vos);
|
|
|
- }
|
|
|
-
|
|
|
- protected void fireBeforeDisableEvent(T... vos) throws BusinessException {
|
|
|
- BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
- eventUtil.dispatchEnableToDisableBeforeEvent((Object[]) vos);
|
|
|
- }
|
|
|
-
|
|
|
- protected void dbDisableVO(T... vos) throws BusinessException {
|
|
|
- String[] updateFields = new String[]{"enablestate", "modifier", "modifiedtime"};
|
|
|
- this.getPersistenceUtil().updateVOWithAttrs(updateFields, vos);
|
|
|
- }
|
|
|
-
|
|
|
- protected void fireAfterDisableEvent(T... vos) throws BusinessException {
|
|
|
- BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
- eventUtil.dispatchEnableToDisableAfterEvent((Object[]) vos);
|
|
|
- }
|
|
|
-
|
|
|
- protected void writeDisableBusiLog(T... vos) throws BusinessException {
|
|
|
- this.getBusiLogUtil().writeBusiLog("disable", (String) null, vos);
|
|
|
- }
|
|
|
-
|
|
|
- public ValueObjWithErrLog enableVO(T... vos) throws BusinessException {
|
|
|
- ValueObjWithErrLog returnValue = null;
|
|
|
- if (vos != null && vos.length != 0) {
|
|
|
- this.enablelockOperate(vos);
|
|
|
- BDVersionValidationUtil.validateSuperVO(vos);
|
|
|
- returnValue = this.filterCanEnableVO(vos);
|
|
|
- T[] enabledVOs = (T[]) returnValue.getVos();
|
|
|
- if (!ArrayUtils.isEmpty(enabledVOs)) {
|
|
|
- this.setEnableFlag(enabledVOs);
|
|
|
- this.setEnableAuditInfo(enabledVOs);
|
|
|
- T[] oldVOs = this.retrieveVOByFields(new String[]{"enablestate"},
|
|
|
- VOArrayUtil.getPrimaryKeyArray(enabledVOs));
|
|
|
- this.fireBeforeEnableEvent(oldVOs, enabledVOs);
|
|
|
- this.dbEnableVO(enabledVOs);
|
|
|
- this.notifyVersionChangeWhenDataUpdated(enabledVOs[0]);
|
|
|
- enabledVOs = this.retrieveVO(VOArrayUtil.getPrimaryKeyArray(enabledVOs));
|
|
|
- this.fireAfterEnableEvent(oldVOs, enabledVOs);
|
|
|
- this.writeEnableBusiLog(enabledVOs);
|
|
|
- returnValue.setVos(enabledVOs);
|
|
|
- }
|
|
|
-
|
|
|
- return returnValue;
|
|
|
- } else {
|
|
|
- return null;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected ValueObjWithErrLog filterCanEnableVO(T... vos) {
|
|
|
- T[] filteredVOs = this.filterVOByExcludeEnableState(2, vos);
|
|
|
- ValueObjWithErrLog returnWithErrLog = new ValueObjWithErrLog();
|
|
|
- returnWithErrLog.setVos(filteredVOs);
|
|
|
- if (!ArrayUtils.isEmpty(filteredVOs)) {
|
|
|
- ;
|
|
|
- }
|
|
|
-
|
|
|
- return returnWithErrLog;
|
|
|
- }
|
|
|
-
|
|
|
- public T enableSingleVO(T vo) throws BusinessException {
|
|
|
- if (vo == null) {
|
|
|
- return null;
|
|
|
- } else {
|
|
|
- this.enablelockOperate(this.convertToVOArray(vo));
|
|
|
- BDVersionValidationUtil.validateSuperVO(new SuperVO[]{vo});
|
|
|
- if (this.isDataEnabled(vo)) {
|
|
|
- return vo;
|
|
|
- } else {
|
|
|
- this.enableValidateVO(vo);
|
|
|
- this.setEnableFlag(this.convertToVOArray(vo));
|
|
|
- this.setEnableAuditInfo(this.convertToVOArray(vo));
|
|
|
- T[] oldVO = this.retrieveVOByFields(new String[]{"enablestate"}, new String[]{vo.getPrimaryKey()});
|
|
|
- this.fireBeforeEnableEvent(oldVO, this.convertToVOArray(vo));
|
|
|
- this.dbEnableVO(this.convertToVOArray(vo));
|
|
|
- this.notifyVersionChangeWhenDataUpdated(vo);
|
|
|
- vo = this.retrieveVO(vo.getPrimaryKey());
|
|
|
- this.fireAfterEnableEvent(oldVO, this.convertToVOArray(vo));
|
|
|
- this.writeEnableBusiLog(this.convertToVOArray(vo));
|
|
|
- return vo;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- protected void enablelockOperate(T... vos) throws BusinessException {
|
|
|
- BDPKLockUtil.lockSuperVO(vos);
|
|
|
- }
|
|
|
-
|
|
|
- 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() {
|
|
|
- return new Validator[0];
|
|
|
- }
|
|
|
-
|
|
|
- protected void setEnableFlag(T... vos) {
|
|
|
- SuperVO[] var2 = vos;
|
|
|
- int var3 = vos.length;
|
|
|
-
|
|
|
- for (int var4 = 0; var4 < var3; ++var4) {
|
|
|
- T t = (T) var2[var4];
|
|
|
- t.setAttributeValue("enablestate", 2);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- protected void setEnableAuditInfo(T... vos) {
|
|
|
- AuditInfoUtil.updateData(vos);
|
|
|
- }
|
|
|
-
|
|
|
- protected void fireBeforeEnableEvent(T[] oldVOs, T... vos) throws BusinessException {
|
|
|
- List<T> init2EnableList = new ArrayList();
|
|
|
- List<T> disable2EnableList = new ArrayList();
|
|
|
- this.assortEnableStateOrigin(oldVOs, vos, init2EnableList, disable2EnableList);
|
|
|
- BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
- T[] init2Enables = null;
|
|
|
- T[] disable2Enables = null;
|
|
|
- if (init2EnableList.size() > 0) {
|
|
|
- init2Enables = (T[]) init2EnableList.toArray((SuperVO[]) ((SuperVO[]) Array
|
|
|
- .newInstance(((SuperVO) init2EnableList.get(0)).getClass(), init2EnableList.size())));
|
|
|
- eventUtil.dispatchInitToEnableBeforeEvent((Object[]) init2Enables);
|
|
|
- }
|
|
|
-
|
|
|
- if (disable2EnableList.size() > 0) {
|
|
|
- disable2Enables = (T[]) disable2EnableList.toArray((SuperVO[]) ((SuperVO[]) Array
|
|
|
- .newInstance(((SuperVO) disable2EnableList.get(0)).getClass(), disable2EnableList.size())));
|
|
|
- eventUtil.dispatchDisableToEnableBeforeEvent((Object[]) disable2Enables);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- protected void dbEnableVO(T... vos) throws BusinessException {
|
|
|
- String[] updateFields = new String[]{"enablestate", "modifier", "modifiedtime"};
|
|
|
- this.getPersistenceUtil().updateVOWithAttrs(updateFields, vos);
|
|
|
- }
|
|
|
-
|
|
|
- protected void fireAfterEnableEvent(T[] oldVOs, T... vos) throws BusinessException {
|
|
|
- List<T> init2EnableList = new ArrayList();
|
|
|
- List<T> disable2EnableList = new ArrayList();
|
|
|
- this.assortEnableStateOrigin(oldVOs, vos, init2EnableList, disable2EnableList);
|
|
|
- BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
- T[] init2Enables = null;
|
|
|
- T[] disable2Enables = null;
|
|
|
- if (init2EnableList.size() > 0) {
|
|
|
- init2Enables = (T[]) init2EnableList.toArray((SuperVO[]) ((SuperVO[]) Array
|
|
|
- .newInstance(((SuperVO) init2EnableList.get(0)).getClass(), init2EnableList.size())));
|
|
|
- eventUtil.dispatchInitToEnableAfterEvent((Object[]) init2Enables);
|
|
|
- }
|
|
|
-
|
|
|
- if (disable2EnableList.size() > 0) {
|
|
|
- disable2Enables = (T[]) disable2EnableList.toArray((SuperVO[]) ((SuperVO[]) Array
|
|
|
- .newInstance(((SuperVO) disable2EnableList.get(0)).getClass(), disable2EnableList.size())));
|
|
|
- eventUtil.dispatchDisableToEnableAfterEvent((Object[]) disable2Enables);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- protected void assortEnableStateOrigin(T[] oldVOs, T[] vos, List<T> init2EnableList, List<T> disable2EnableList) {
|
|
|
- for (int i = 0; i < vos.length; ++i) {
|
|
|
- Integer oldEnableState = (Integer) oldVOs[i].getAttributeValue("enablestate");
|
|
|
- if (oldEnableState == 3) {
|
|
|
- disable2EnableList.add(vos[i]);
|
|
|
- } else if (oldEnableState == 1) {
|
|
|
- init2EnableList.add(vos[i]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- protected void writeEnableBusiLog(T... vos) throws BusinessException {
|
|
|
- this.getBusiLogUtil().writeBusiLog("enable", (String) null, vos);
|
|
|
- }
|
|
|
-
|
|
|
- private T[] filterVOByExcludeEnableState(int excludeEnableState, T[] vo) {
|
|
|
- List<T> list = new ArrayList();
|
|
|
- SuperVO[] var4 = vo;
|
|
|
- int var5 = vo.length;
|
|
|
-
|
|
|
- for (int var6 = 0; var6 < var5; ++var6) {
|
|
|
- T t = (T) var4[var6];
|
|
|
- Integer enableState = (Integer) t.getAttributeValue("enablestate");
|
|
|
- if (excludeEnableState != enableState) {
|
|
|
- list.add(t);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return (T[]) list.toArray((SuperVO[]) ((SuperVO[]) Array.newInstance(vo[0].getClass(), list.size())));
|
|
|
- }
|
|
|
-
|
|
|
- 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[] pks) throws BusinessException {
|
|
|
- return this.getPersistenceUtil().retrieveVOByFields(pks, fields);
|
|
|
- }
|
|
|
-
|
|
|
- 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.List;
|
|
|
+
|
|
|
+import nc.bs.baseapp.sendZP.OrgSendZP;
|
|
|
+import nc.bs.baseapp.sendZP.SupplierShendZP;
|
|
|
+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.IPersistenceUtil;
|
|
|
+import nc.bs.bd.baseservice.persistence.MDPersistenceUtil;
|
|
|
+import nc.bs.bd.service.ValueObjWithErrLog;
|
|
|
+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.bd.supplier.SupplierVO;
|
|
|
+import nc.vo.org.FinanceOrgVO;
|
|
|
+import nc.vo.pub.BusinessException;
|
|
|
+import nc.vo.pub.CircularlyAccessibleValueObject;
|
|
|
+import nc.vo.pub.SuperVO;
|
|
|
+import nc.vo.util.AuditInfoUtil;
|
|
|
+import nc.vo.util.BDPKLockUtil;
|
|
|
+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;
|
|
|
+
|
|
|
+public class SingleBaseService<T extends SuperVO> {
|
|
|
+ private String MDId;
|
|
|
+ private String[] subAttributeNames;
|
|
|
+ private IBDBusiLogUtil busiLogUtil;
|
|
|
+ private IPersistenceUtil<T> persistenceUtil;
|
|
|
+ private BDUniqueFieldTrimUtil uniqueFieldTrimUtil;
|
|
|
+
|
|
|
+ public SingleBaseService(String MDId) {
|
|
|
+ this(MDId, (String[]) null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public SingleBaseService(String MDId, String[] subAttributeNames) {
|
|
|
+ this.busiLogUtil = null;
|
|
|
+ this.persistenceUtil = null;
|
|
|
+ this.MDId = MDId;
|
|
|
+ this.subAttributeNames = subAttributeNames;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getMDId() {
|
|
|
+ return this.MDId;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String[] getSubAttributeNames() {
|
|
|
+ return this.subAttributeNames == null ? null : (String[]) this.subAttributeNames.clone();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected IPersistenceUtil<T> getPersistenceUtil() {
|
|
|
+ if (this.persistenceUtil == null) {
|
|
|
+ this.persistenceUtil = new MDPersistenceUtil(this.getMDId(), this.getSubAttributeNames());
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.persistenceUtil;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
+ BDVersionValidationUtil.validateSuperVO(new SuperVO[]{vo});
|
|
|
+ this.deleteValidateVO(vo);
|
|
|
+ this.fireBeforeDeleteEvent(vo);
|
|
|
+ this.notifyVersionChangeWhenDataDeleted(vo);
|
|
|
+ this.dbDeleteVO(vo);
|
|
|
+ this.fireAfterDeleteEvent(vo);
|
|
|
+ this.writeDeletedBusiLog(vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void deletelockOperate(T vo) throws BusinessException {
|
|
|
+ BDPKLockUtil.lockSuperVO(new SuperVO[]{vo});
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void deleteValidateVO(T vo) throws BusinessException {
|
|
|
+ IValidationService validationService = ValidationFrameworkUtil
|
|
|
+ .createValidationService(this.getDeleteValidator());
|
|
|
+ validationService.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 notifyVersionChangeWhenDataDeleted(T vo) throws BusinessException {
|
|
|
+ this.getPersistenceUtil().notifyVersionChangeWhenDataDeleted(this.convertToVOArray(vo));
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void dbDeleteVO(T vo) throws BusinessException {
|
|
|
+ this.getPersistenceUtil().deleteVO(this.convertToVOArray(vo));
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void fireAfterDeleteEvent(T vo) throws BusinessException {
|
|
|
+ BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
+ eventUtil.dispatchDeleteAfterEvent(new Object[]{vo});
|
|
|
+ //供应商传ZP Yaoy 2022-08-03
|
|
|
+ //公共方法,vo获取失败吃掉异常
|
|
|
+ SupplierVO[] supplierVOarr = new SupplierVO[1];
|
|
|
+ try {
|
|
|
+ supplierVOarr[0] = (SupplierVO) vo;
|
|
|
+ } catch (Exception e) {}
|
|
|
+ if(supplierVOarr[0] != null) {
|
|
|
+ SupplierShendZP.process(supplierVOarr, "delete");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 vo;
|
|
|
+ } else {
|
|
|
+ this.getUniqueFieldTrimUtil().trimUniqueFields(new SuperVO[]{vo});
|
|
|
+ this.insertlockOperate(vo);
|
|
|
+ this.insertValidateVO(vo);
|
|
|
+ this.setInsertAuditInfo(vo);
|
|
|
+ this.fireBeforeInsertEvent(vo);
|
|
|
+ String pk = this.dbInsertVO(vo);
|
|
|
+ vo = this.retrieveVO(pk);
|
|
|
+ this.notifyVersionChangeWhenDataInserted(vo);
|
|
|
+ this.fireAfterInsertEvent(vo);
|
|
|
+ this.writeInsertBusiLog(vo);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void insertlockOperate(T vo) throws BusinessException {
|
|
|
+ BizlockDataUtil.lockDataByBizlock(new CircularlyAccessibleValueObject[]{vo});
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void insertValidateVO(T vo) throws BusinessException {
|
|
|
+ IValidationService validateService = ValidationFrameworkUtil.createValidationService(this.getInsertValidator());
|
|
|
+ validateService.validate(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected Validator[] getInsertValidator() {
|
|
|
+ Validator[] validators = new Validator[]{new BDUniqueRuleValidate()};
|
|
|
+ return validators;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void setInsertAuditInfo(T vo) {
|
|
|
+ AuditInfoUtil.addData(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void fireBeforeInsertEvent(T vo) throws BusinessException {
|
|
|
+ BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
+ eventUtil.dispatchInsertBeforeEvent(new Object[]{vo});
|
|
|
+ //供应商传ZP Yaoy 2022-08-03
|
|
|
+ //公共方法,vo获取失败吃掉异常
|
|
|
+ SupplierVO[] supplierVOarr = new SupplierVO[1];
|
|
|
+ FinanceOrgVO financeOrgVO = new FinanceOrgVO();
|
|
|
+ try {
|
|
|
+ supplierVOarr[0] = (SupplierVO) vo;
|
|
|
+ } catch (Exception e) {}
|
|
|
+ try {
|
|
|
+ financeOrgVO = (FinanceOrgVO) vo;
|
|
|
+ } catch (Exception e) {}
|
|
|
+ if(supplierVOarr[0] != null) {
|
|
|
+ SupplierShendZP.process(supplierVOarr, "add");
|
|
|
+ }
|
|
|
+ if(financeOrgVO.getCode() != null) {
|
|
|
+ OrgSendZP.process(financeOrgVO, "add");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected String dbInsertVO(T vo) throws BusinessException {
|
|
|
+ String[] pks = this.getPersistenceUtil().insertVO(this.convertToVOArray(vo));
|
|
|
+ return pks != null && pks.length > 0 ? pks[0] : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void notifyVersionChangeWhenDataInserted(T vo) throws BusinessException {
|
|
|
+ this.getPersistenceUtil().notifyVersionChangeWhenDataInserted(this.convertToVOArray(vo));
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void fireAfterInsertEvent(T vo) throws BusinessException {
|
|
|
+ BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
+ eventUtil.dispatchInsertAfterEvent(new Object[]{vo});
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void writeInsertBusiLog(T vo) throws BusinessException {
|
|
|
+ this.getBusiLogUtil().writeBusiLog("add", (String) null, new SuperVO[]{vo});
|
|
|
+ }
|
|
|
+
|
|
|
+ public T updateVO(T vo) throws BusinessException {
|
|
|
+ if (vo == null) {
|
|
|
+ return vo;
|
|
|
+ } else {
|
|
|
+ this.getUniqueFieldTrimUtil().trimUniqueFields(new SuperVO[]{vo});
|
|
|
+ this.updatelockOperate(vo);
|
|
|
+ BDVersionValidationUtil.validateSuperVO(new SuperVO[]{vo});
|
|
|
+ T oldVO = this.retrieveVO(vo.getPrimaryKey());
|
|
|
+ this.updateValidateVO(oldVO, vo);
|
|
|
+ this.setUpdateAuditInfo(vo);
|
|
|
+ this.fireBeforeUpdateEvent(oldVO, vo);
|
|
|
+ this.dbUpdateVO(vo);
|
|
|
+ this.notifyVersionChangeWhenDataUpdated(vo);
|
|
|
+ vo = this.retrieveVO(vo.getPrimaryKey());
|
|
|
+ this.fireAfterUpdateEvent(oldVO, vo);
|
|
|
+ this.writeUpdatedBusiLog(oldVO, vo);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void updatelockOperate(T vo) throws BusinessException {
|
|
|
+ BDPKLockUtil.lockSuperVO(new SuperVO[]{vo});
|
|
|
+ BizlockDataUtil.lockDataByBizlock(new CircularlyAccessibleValueObject[]{vo});
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void updateValidateVO(T oldVO, T vo) throws BusinessException {
|
|
|
+ IValidationService validateService = ValidationFrameworkUtil
|
|
|
+ .createValidationService(this.getUpdateValidator(oldVO));
|
|
|
+ validateService.validate(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected Validator[] getUpdateValidator(T oldVO) {
|
|
|
+ Validator[] validators = new Validator[]{new BDUniqueRuleValidate()};
|
|
|
+ return validators;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 dbUpdateVO(T vo) throws BusinessException {
|
|
|
+ this.getPersistenceUtil().updateVO(this.convertToVOArray(vo));
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void notifyVersionChangeWhenDataUpdated(T vo) throws BusinessException {
|
|
|
+ this.getPersistenceUtil().notifyVersionChangeWhenDataUpdated(this.convertToVOArray(vo));
|
|
|
+ }
|
|
|
+
|
|
|
+ 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获取失败吃掉异常
|
|
|
+ SupplierVO[] supplierVOarr = new SupplierVO[1];
|
|
|
+ FinanceOrgVO financeOrgVO = new FinanceOrgVO();
|
|
|
+ try {
|
|
|
+ supplierVOarr[0] = (SupplierVO) vo;
|
|
|
+ } catch (Exception e) {}
|
|
|
+ try {
|
|
|
+ financeOrgVO = (FinanceOrgVO) vo;
|
|
|
+ } catch (Exception e) {}
|
|
|
+ if(supplierVOarr[0] != null) {
|
|
|
+ SupplierShendZP.process(supplierVOarr, "update");
|
|
|
+ }
|
|
|
+ if(financeOrgVO.getCode() != null) {
|
|
|
+ if(financeOrgVO.getMnecode()== null) {
|
|
|
+ OrgSendZP.process(financeOrgVO, "update");
|
|
|
+ }else {
|
|
|
+ if(!"不传租凭系统".equals(financeOrgVO.getMnecode())) {
|
|
|
+ OrgSendZP.process(financeOrgVO, "update");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void writeUpdatedBusiLog(T oldVO, T vo) throws BusinessException {
|
|
|
+ this.getBusiLogUtil().writeModefyBusiLog("edit", vo, oldVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ public ValueObjWithErrLog disableVO(T... vos) throws BusinessException {
|
|
|
+ ValueObjWithErrLog returnValue = null;
|
|
|
+ if (vos != null && vos.length != 0) {
|
|
|
+ this.disableLockOperate(vos);
|
|
|
+ BDVersionValidationUtil.validateSuperVO(vos);
|
|
|
+ returnValue = this.filterCanDisableVO(vos);
|
|
|
+ T[] disabledVOs = (T[]) returnValue.getVos();
|
|
|
+ if (!ArrayUtils.isEmpty(disabledVOs)) {
|
|
|
+ this.setDisableFlag(disabledVOs);
|
|
|
+ this.setDisableAuditInfo(disabledVOs);
|
|
|
+ this.fireBeforeDisableEvent(disabledVOs);
|
|
|
+ this.dbDisableVO(disabledVOs);
|
|
|
+ this.notifyVersionChangeWhenDataUpdated(disabledVOs[0]);
|
|
|
+ disabledVOs = this.retrieveVO(VOArrayUtil.getPrimaryKeyArray(disabledVOs));
|
|
|
+ this.fireAfterDisableEvent(disabledVOs);
|
|
|
+ this.writeDisableBusiLog(disabledVOs);
|
|
|
+ returnValue.setVos(disabledVOs);
|
|
|
+ }
|
|
|
+
|
|
|
+ return returnValue;
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected ValueObjWithErrLog filterCanDisableVO(T... vos) {
|
|
|
+ T[] filteredVOs = this.filterVOByExcludeEnableState(3, vos);
|
|
|
+ ValueObjWithErrLog returnWithErrLog = new ValueObjWithErrLog();
|
|
|
+ returnWithErrLog.setVos(filteredVOs);
|
|
|
+ if (!ArrayUtils.isEmpty(filteredVOs)) {
|
|
|
+ ;
|
|
|
+ }
|
|
|
+
|
|
|
+ return returnWithErrLog;
|
|
|
+ }
|
|
|
+
|
|
|
+ public T disableSingleVO(T vo) throws BusinessException {
|
|
|
+ if (vo == null) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ this.disableLockOperate(this.convertToVOArray(vo));
|
|
|
+ BDVersionValidationUtil.validateSuperVO(new SuperVO[]{vo});
|
|
|
+ if (this.isDataDisabled(vo)) {
|
|
|
+ return vo;
|
|
|
+ } else {
|
|
|
+ this.disableValidateVO(vo);
|
|
|
+ this.setDisableFlag(this.convertToVOArray(vo));
|
|
|
+ this.setDisableAuditInfo(this.convertToVOArray(vo));
|
|
|
+ this.fireBeforeDisableEvent(this.convertToVOArray(vo));
|
|
|
+ this.dbDisableVO(this.convertToVOArray(vo));
|
|
|
+ this.notifyVersionChangeWhenDataUpdated(vo);
|
|
|
+ vo = this.retrieveVO(vo.getPrimaryKey());
|
|
|
+ this.fireAfterDisableEvent(this.convertToVOArray(vo));
|
|
|
+ this.writeDisableBusiLog(this.convertToVOArray(vo));
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void disableLockOperate(T... vos) throws BusinessException {
|
|
|
+ BDPKLockUtil.lockSuperVO(vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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() {
|
|
|
+ return new Validator[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void setDisableFlag(T... vos) {
|
|
|
+ SuperVO[] var2 = vos;
|
|
|
+ int var3 = vos.length;
|
|
|
+
|
|
|
+ for (int var4 = 0; var4 < var3; ++var4) {
|
|
|
+ T t = (T) var2[var4];
|
|
|
+ t.setAttributeValue("enablestate", 3);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void setDisableAuditInfo(T... vos) {
|
|
|
+ AuditInfoUtil.updateData(vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void fireBeforeDisableEvent(T... vos) throws BusinessException {
|
|
|
+ BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
+ eventUtil.dispatchEnableToDisableBeforeEvent((Object[]) vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void dbDisableVO(T... vos) throws BusinessException {
|
|
|
+ String[] updateFields = new String[]{"enablestate", "modifier", "modifiedtime"};
|
|
|
+ this.getPersistenceUtil().updateVOWithAttrs(updateFields, vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void fireAfterDisableEvent(T... vos) throws BusinessException {
|
|
|
+ BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
+ eventUtil.dispatchEnableToDisableAfterEvent((Object[]) vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void writeDisableBusiLog(T... vos) throws BusinessException {
|
|
|
+ this.getBusiLogUtil().writeBusiLog("disable", (String) null, vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ public ValueObjWithErrLog enableVO(T... vos) throws BusinessException {
|
|
|
+ ValueObjWithErrLog returnValue = null;
|
|
|
+ if (vos != null && vos.length != 0) {
|
|
|
+ this.enablelockOperate(vos);
|
|
|
+ BDVersionValidationUtil.validateSuperVO(vos);
|
|
|
+ returnValue = this.filterCanEnableVO(vos);
|
|
|
+ T[] enabledVOs = (T[]) returnValue.getVos();
|
|
|
+ if (!ArrayUtils.isEmpty(enabledVOs)) {
|
|
|
+ this.setEnableFlag(enabledVOs);
|
|
|
+ this.setEnableAuditInfo(enabledVOs);
|
|
|
+ T[] oldVOs = this.retrieveVOByFields(new String[]{"enablestate"},
|
|
|
+ VOArrayUtil.getPrimaryKeyArray(enabledVOs));
|
|
|
+ this.fireBeforeEnableEvent(oldVOs, enabledVOs);
|
|
|
+ this.dbEnableVO(enabledVOs);
|
|
|
+ this.notifyVersionChangeWhenDataUpdated(enabledVOs[0]);
|
|
|
+ enabledVOs = this.retrieveVO(VOArrayUtil.getPrimaryKeyArray(enabledVOs));
|
|
|
+ this.fireAfterEnableEvent(oldVOs, enabledVOs);
|
|
|
+ this.writeEnableBusiLog(enabledVOs);
|
|
|
+ returnValue.setVos(enabledVOs);
|
|
|
+ }
|
|
|
+
|
|
|
+ return returnValue;
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected ValueObjWithErrLog filterCanEnableVO(T... vos) {
|
|
|
+ T[] filteredVOs = this.filterVOByExcludeEnableState(2, vos);
|
|
|
+ ValueObjWithErrLog returnWithErrLog = new ValueObjWithErrLog();
|
|
|
+ returnWithErrLog.setVos(filteredVOs);
|
|
|
+ if (!ArrayUtils.isEmpty(filteredVOs)) {
|
|
|
+ ;
|
|
|
+ }
|
|
|
+
|
|
|
+ return returnWithErrLog;
|
|
|
+ }
|
|
|
+
|
|
|
+ public T enableSingleVO(T vo) throws BusinessException {
|
|
|
+ if (vo == null) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ this.enablelockOperate(this.convertToVOArray(vo));
|
|
|
+ BDVersionValidationUtil.validateSuperVO(new SuperVO[]{vo});
|
|
|
+ if (this.isDataEnabled(vo)) {
|
|
|
+ return vo;
|
|
|
+ } else {
|
|
|
+ this.enableValidateVO(vo);
|
|
|
+ this.setEnableFlag(this.convertToVOArray(vo));
|
|
|
+ this.setEnableAuditInfo(this.convertToVOArray(vo));
|
|
|
+ T[] oldVO = this.retrieveVOByFields(new String[]{"enablestate"}, new String[]{vo.getPrimaryKey()});
|
|
|
+ this.fireBeforeEnableEvent(oldVO, this.convertToVOArray(vo));
|
|
|
+ this.dbEnableVO(this.convertToVOArray(vo));
|
|
|
+ this.notifyVersionChangeWhenDataUpdated(vo);
|
|
|
+ vo = this.retrieveVO(vo.getPrimaryKey());
|
|
|
+ this.fireAfterEnableEvent(oldVO, this.convertToVOArray(vo));
|
|
|
+ this.writeEnableBusiLog(this.convertToVOArray(vo));
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void enablelockOperate(T... vos) throws BusinessException {
|
|
|
+ BDPKLockUtil.lockSuperVO(vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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() {
|
|
|
+ return new Validator[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void setEnableFlag(T... vos) {
|
|
|
+ SuperVO[] var2 = vos;
|
|
|
+ int var3 = vos.length;
|
|
|
+
|
|
|
+ for (int var4 = 0; var4 < var3; ++var4) {
|
|
|
+ T t = (T) var2[var4];
|
|
|
+ t.setAttributeValue("enablestate", 2);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void setEnableAuditInfo(T... vos) {
|
|
|
+ AuditInfoUtil.updateData(vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void fireBeforeEnableEvent(T[] oldVOs, T... vos) throws BusinessException {
|
|
|
+ List<T> init2EnableList = new ArrayList();
|
|
|
+ List<T> disable2EnableList = new ArrayList();
|
|
|
+ this.assortEnableStateOrigin(oldVOs, vos, init2EnableList, disable2EnableList);
|
|
|
+ BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
+ T[] init2Enables = null;
|
|
|
+ T[] disable2Enables = null;
|
|
|
+ if (init2EnableList.size() > 0) {
|
|
|
+ init2Enables = (T[]) init2EnableList.toArray((SuperVO[]) ((SuperVO[]) Array
|
|
|
+ .newInstance(((SuperVO) init2EnableList.get(0)).getClass(), init2EnableList.size())));
|
|
|
+ eventUtil.dispatchInitToEnableBeforeEvent((Object[]) init2Enables);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (disable2EnableList.size() > 0) {
|
|
|
+ disable2Enables = (T[]) disable2EnableList.toArray((SuperVO[]) ((SuperVO[]) Array
|
|
|
+ .newInstance(((SuperVO) disable2EnableList.get(0)).getClass(), disable2EnableList.size())));
|
|
|
+ eventUtil.dispatchDisableToEnableBeforeEvent((Object[]) disable2Enables);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void dbEnableVO(T... vos) throws BusinessException {
|
|
|
+ String[] updateFields = new String[]{"enablestate", "modifier", "modifiedtime"};
|
|
|
+ this.getPersistenceUtil().updateVOWithAttrs(updateFields, vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void fireAfterEnableEvent(T[] oldVOs, T... vos) throws BusinessException {
|
|
|
+ List<T> init2EnableList = new ArrayList();
|
|
|
+ List<T> disable2EnableList = new ArrayList();
|
|
|
+ this.assortEnableStateOrigin(oldVOs, vos, init2EnableList, disable2EnableList);
|
|
|
+ BDCommonEventUtil eventUtil = new BDCommonEventUtil(this.getMDId());
|
|
|
+ T[] init2Enables = null;
|
|
|
+ T[] disable2Enables = null;
|
|
|
+ if (init2EnableList.size() > 0) {
|
|
|
+ init2Enables = (T[]) init2EnableList.toArray((SuperVO[]) ((SuperVO[]) Array
|
|
|
+ .newInstance(((SuperVO) init2EnableList.get(0)).getClass(), init2EnableList.size())));
|
|
|
+ eventUtil.dispatchInitToEnableAfterEvent((Object[]) init2Enables);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (disable2EnableList.size() > 0) {
|
|
|
+ disable2Enables = (T[]) disable2EnableList.toArray((SuperVO[]) ((SuperVO[]) Array
|
|
|
+ .newInstance(((SuperVO) disable2EnableList.get(0)).getClass(), disable2EnableList.size())));
|
|
|
+ eventUtil.dispatchDisableToEnableAfterEvent((Object[]) disable2Enables);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void assortEnableStateOrigin(T[] oldVOs, T[] vos, List<T> init2EnableList, List<T> disable2EnableList) {
|
|
|
+ for (int i = 0; i < vos.length; ++i) {
|
|
|
+ Integer oldEnableState = (Integer) oldVOs[i].getAttributeValue("enablestate");
|
|
|
+ if (oldEnableState == 3) {
|
|
|
+ disable2EnableList.add(vos[i]);
|
|
|
+ } else if (oldEnableState == 1) {
|
|
|
+ init2EnableList.add(vos[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void writeEnableBusiLog(T... vos) throws BusinessException {
|
|
|
+ this.getBusiLogUtil().writeBusiLog("enable", (String) null, vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ private T[] filterVOByExcludeEnableState(int excludeEnableState, T[] vo) {
|
|
|
+ List<T> list = new ArrayList();
|
|
|
+ SuperVO[] var4 = vo;
|
|
|
+ int var5 = vo.length;
|
|
|
+
|
|
|
+ for (int var6 = 0; var6 < var5; ++var6) {
|
|
|
+ T t = (T) var4[var6];
|
|
|
+ Integer enableState = (Integer) t.getAttributeValue("enablestate");
|
|
|
+ if (excludeEnableState != enableState) {
|
|
|
+ list.add(t);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return (T[]) list.toArray((SuperVO[]) ((SuperVO[]) Array.newInstance(vo[0].getClass(), list.size())));
|
|
|
+ }
|
|
|
+
|
|
|
+ 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[] pks) throws BusinessException {
|
|
|
+ return this.getPersistenceUtil().retrieveVOByFields(pks, fields);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
}
|