BService.java
public Bsave(Bb, HttpServletRequest request) {
b.setRecordInfo(super.GenRecordInfo(b.getRecordInfo(), request));
b= bDao.save(b);
try {
zService.saveByZfcg(b, request);
} catch (Exception e) {
e.printStackTrace();
}
return b;
}
ZService.java
public Z dtl(int refnum, String applyTo) {
String hql = "FROM Z WHERE refnum =? and applyTo =?";
List<Object> args = new ArrayList<Object>();
args.add(refnum);
args.add(applyTo);
return zDao.dtl(hql, args);
}
// 保存数据
public void saveByZfcg(B b, HttpServletRequest request) {
Z z = new Z();
Z z1 = dtl(b.getId(), "B ");// 查看
if (z1 != null) { //判断表中是否有采购的id,和"B ",
z1 .setProject_Code(b.getBid_Code()); //有就更新这条记录
z1 .setProject_Code(b.getBid_Code()); //
z1 .setProject_Name(b.getBid_Name());
z1 .setProject_Type("采购");
z1 .setProject_Publish_Time(b.getRecordInfo().getCreatedAt());
z1 .setPublish_Time(b.getRecordInfo().getCreatedAt());
z1 .setTrade_Time(b.getKbsj());
z1 .setApplyTo("B ");
z1 .setRefnum(b.getId());
save(z1 , request);
} else {
z.setProject_Code(b.getBid_Code());// 存入对应的字段(没有就保存一条)
z.setProject_Name(b.getBid_Name());
z.setProject_Type("采购");
z.setProject_Publish_Time(b.getRecordInfo().getCreatedAt());
z.setPublish_Time(b.getRecordInfo().getCreatedAt());
z.setTrade_Time(b.getKbsj());
z.setApplyTo("B ");
z.setRefnum(b.getId());
save(z, request);
}
}