代码如下:把下边这个类放在审批脚本中(审批前)
public class AfterApproveRule implements IRule {
@Override
public void process(Object[] vos) {
if (vos != null && vos.length > 0) {
for (int i = 0; i < vos.length; i++) {
AggSupplierMaintainHVO aggvo = (AggSupplierMaintainHVO) vos[i];
SupplierMaintainHVO hvo = aggvo.getParentVO();
int staus = hvo.getApprovestatus();
if (staus != 1) {
return;
}
SupplierVO svo = new SupplierVO();
String code = hvo.getCode();// 供应商pk
svo.setName(hvo.getName());// 供应商名称
svo.setEcotypesincevfive(hvo.getType());// 经济类型
svo.setLegalbody(hvo.getFddbr());// 法定代表人
svo.setRegisterfund(hvo.getZczb());// 注册资本
svo.setPk_currtype(hvo.getPk_currtype());// 注册资金币种
svo.setEstablishdate(hvo.getFounddate());// 成立日期
svo.setBuslicensenum(hvo.getXydm());// 社会统一信用代码
svo.setDef1(hvo.getFrsfzh());// 法人身份证号
svo.setDef2(hvo.getDate_end() == null ? "" : hvo.getDate_end().toString());// 截止日期
svo.setCorpaddress(hvo.getCorpaddress());// 公司地址、注册地址
svo.setRegisteradd(hvo.getRegaddress());
svo.setPk_country(hvo.getPk_country());// 国家地区
if (hvo.getRetail().booleanValue()) {
svo.setSupprop(hvo.getGyslx() == null ? 0 : hvo.getGyslx());// 供应商类型
}
else {
svo.setSupprop(hvo.getGyslx());// 供应商类型
}
svo.setDef14(hvo.getFzjg());// 发证机关
svo.setMemo(hvo.getJyfw());// 经营范围
svo.setDef16(hvo.getJyzt());// 经营状态
svo.setPk_financeorg(hvo.getPk_nbdw());// 内部单位pk
svo.setTel1(hvo.getCorptel());// 公司电话
svo.setFax1(hvo.getCorpfax());// 公司传真
svo.setPk_suptaxes(hvo.getTax());// 税类
svo.setEmail(hvo.getEmail());// 电子邮箱
svo.setIsfreecust(hvo.getRetail());// 散户
svo.setDef18(hvo.getProjecttype().toString());// 工程类
svo.setDef19(hvo.getFgclzt());// 非工程类状态
// 如果维护类型为更正,则不改变版本。维护类型为变更时,则改变版本
boolean isUpdateVersion = true;
if ("1".equals(hvo.getMaintaintype())) {
isUpdateVersion = false;
}
ISupplierBaseInfoService sup = NCLocator.getInstance().lookup(ISupplierBaseInfoService.class);
try {
sup.maintenanceSupplyVoForH1H106(code, svo, isUpdateVersion);
}
catch (BusinessException e) {
ExceptionUtils.wrappException(e);
}
}
}
}
}
此方法:如下 sup.maintenanceSupplyVoForH1H106(code, svo, isUpdateVersion);
public void maintenanceSupplyVoForH1H106(String srcSupplierVOPk, SupplierVO supplierVO, boolean isUpdateVersion)
throws BusinessException {
// 1.查询原始数据
Collection<SupplierVO> oldCollection =
MDPersistenceService.lookupPersistenceQueryService().queryBillOfVOByPKs(SupplierVO.class, new String[] {
srcSupplierVOPk
}, false);
SupplierVO[] SupplierVOs = oldCollection.toArray(new SupplierVO[0]);
if (SupplierVOs != null && SupplierVOs.length > 0) {
SupplierVO srcVO = SupplierVOs[0];
// 复制一条数据
SupplierVO oldVo = (SupplierVO) new DeepCloneTool().deepClone(srcVO); // 老版本数据
this.handleOldVoInfo(oldVo, isUpdateVersion, supplierVO);
if (isUpdateVersion) {
SupplierVO newVo = (SupplierVO) new DeepCloneTool().deepClone(srcVO); // 新版本数据
// 生成新版本VO数据
this.handleNewVoInfo(supplierVO, newVo);
//ADD BY JM 设置旧vo中的启用状态为停用
oldVo.setEnablestate(3);
String nwpk = newVo.getPk_supplier();
oldVo.setDef17(nwpk);
//以下代码是同时更新所有旧的原始记录中的指向供应商字段
//获取来源单据pk
String oldpk = oldVo.getDef4();
String code = oldVo.getCode();
try {
IUAPQueryBS querybs = NCLocator.getInstance().lookup(IUAPQueryBS.class);
String codesql0 = "select substr(code,0,6) code from bd_supplier where code like '"+code+"'";
List<Map<?, ?>> list = (ArrayList) querybs.executeQuery(codesql0, new MapListProcessor());
if(list != null){
for(Map<?,?> map:list){
String cod = map.get("code").toString();
String codesql = "select * from bd_supplier where code like '"+cod+"%'";
List list1 = (List) querybs.executeQuery(codesql, new MapListProcessor());
if (!list1.isEmpty()) {
for (int ii = 0; ii<list1.size(); ii++ ) {
Map maplis = (Map) list1.get(ii);
String temp = (String) maplis.get("def17");
String pk_supplier = (String) maplis.get("pk_supplier");
if(temp != null){
String sql1 = "update bd_supplier set def17 = '"+nwpk+"' where pk_supplier = '"+pk_supplier+"'";
BaseDAO dao=new BaseDAO();
dao.executeUpdate(sql1);
}
}
}
}
}
} catch (BusinessException e) {
e.printStackTrace();
}
插入到表中的方法如下 this.handleNewVoInfo(supplierVO, newVo)
/**
* 复制供应商信息
*
* @param infoVo 维护传过来的数据
* @param newVo 复制上一版本供应商的数据
* @throws BusinessException
*/
private void handleNewVoInfo(SupplierVO infoVo, SupplierVO newVo) throws BusinessException {
// 处理非业务字段
newVo.setDef3(String.valueOf(Integer.parseInt(newVo.getDef3()) + 1)); // 设置版本号+1
newVo.setCode(newVo.getCode() + "_" + newVo.getDef3());
newVo.setDef4(newVo.getPk_supplier()); // 记录原始主键
newVo.setDef5("Y"); // 标识是最新数据
newVo.setCreator(infoVo.getCreator());
newVo.setCreationtime(infoVo.getCreationtime());
// 处理传过来的业务字段
this.copyVo(newVo, infoVo);
// 执行新增新数据
newVo.setPk_supplier(null);
newVo.setStatus(VOStatus.NEW);
this.dbInsertVO(newVo);
// VOInsert<SupplierVO> insert = new VOInsert<SupplierVO>();
// insert.insert(new SupplierVO[] {
// newVo
// });
}
完整步骤