NC65二开单据单据追溯功能开发
一.单据元数据字段增加字段
来源单据主键
来源单据类型
二.设置单据按钮&&修改单据类型
单据增加按钮
<bean id="linkQueryAction" class="nc.ui.so.socontract.ace.action.common.UserDefLinkQueryAction">
<property name="model"><ref bean="bmModel"/></property>
<property name="billType" value="HD01"/>
<property name="exceptionHandler"><ref bean="exceptionHandler" /></property>
</bean>
package nc.ui.so.socontract.ace.action.common;
import nc.ui.pubapp.uif2app.actions.LinkQueryAction;
import nc.ui.scmpub.action.SCMActionInitializer;
public class UserDefLinkQueryAction extends LinkQueryAction {
public UserDefLinkQueryAction() {
// TODO Auto-generated constructor stub
setOpenMode(1);
SCMActionInitializer.initializeAction(this, "BillLinkQuery");
}
}
设置来源单据数据查询类
三.实现类代码:
package nc.vo.so.socontract.linkquery;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import nc.bs.logging.Logger;
import nc.bs.pf.pub.PfDataCache;
import nc.bs.trade.billsource.DefaultDataFinder;
import nc.jdbc.framework.JdbcSession;
import nc.jdbc.framework.PersistenceManager;
import nc.jdbc.framework.SQLParameter;
import nc.jdbc.framework.exception.DbException;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.jdbc.framework.processor.ResultSetProcessor;
import nc.uif.pub.exception.UifRuntimeException;
import nc.vo.pu.pub.util.ArrayUtil;
import nc.vo.pubapp.pattern.pub.SqlBuilder;
import nc.vo.trade.billsource.LightBillVO;
/**
* 军品销售合同单据联查类
* @author Think
*
*/
public class ContractSrcFinder extends DefaultDataFinder {
@Override
public LightBillVO[] getForwardBills(String srcBillType,
String curBillType, String... srcBillID) {
// TODO Auto-generated method stub
if(!"30".equals(srcBillType)){
return super.getForwardBills(srcBillType, curBillType, srcBillID);
}else{
SqlBuilder sql = new SqlBuilder();
// sql.append("SELECT distinct pk_head id,'"+curBillType+"' code FROM so_socontract_b ");
// sql.append(" where dr = 0 ");
// // and csrcid = '"+srcBillID+"' and csrctype='"+srcBillType+"'"
// sql.append(" and csrcid ",srcBillID);
// //sql.append(" and csrctype ",srcBillType);
String pk= PfDataCache.getBillTypeInfo(curBillType).getPk_billtypeid();
sql.append("SELECT distinct t1.pk_head id,t1.vbillcode code,t1.pk_billtypecode type,'"+pk+"' transtypepk,t2.csrcid sourceID FROM SO_SOCONTRACT_H t1 ");
sql.append("LEFT JOIN SO_SOCONTRACT_B t2 on t1.PK_HEAD = t2.PK_HEAD");
sql.append(" WHERE t1.dr = 0 And t2.dr =0 ");
sql.append(" and t2.csrcid ",srcBillID);
PersistenceManager sessionManager = null;
try {
sessionManager = PersistenceManager.getInstance();
JdbcSession session = sessionManager.getJdbcSession();
ArrayList result =
(ArrayList) session.executeQuery(sql.toString(),
new BeanListProcessor(LightBillVO.class));
if (result.size() == 0) {
return null;
}
else {
return (LightBillVO[]) result.toArray(new LightBillVO[result.size()]);
}
}
catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new UifRuntimeException("getForwardBills error");
}
finally {
sessionManager.release();
}
}
}
public LightBillVO[] getSoContractSourceBills(String curBillType, String curBillID){
SqlBuilder sqlbuilder = new SqlBuilder();
sqlbuilder.append("select * from so_saleorder where csaleorderid in ( ");
sqlbuilder.append(" select csrcid from so_socontract_b where dr = 0 and pk_head = ? ");
sqlbuilder.append(" ) and dr = 0 ");
PersistenceManager sessionManager = null;
try {
sessionManager = PersistenceManager.getInstance();
JdbcSession session = sessionManager.getJdbcSession();
SQLParameter para = new SQLParameter();
para.addParam(curBillID);
ResultSetProcessor p = new ResultSetProcessor(){
@Override
public Object handleResultSet(ResultSet rs)
throws SQLException {
// TODO Auto-generated method stub
ArrayList al = new ArrayList();
while(rs.next()){
String id = rs.getString("csaleorderid");
String code = rs.getString("vbillcode");
if (id != null && id.trim().length() > 0) {
LightBillVO svo = new LightBillVO();
svo.setType("30");
svo.setID(id);
svo.setCode(code);
al.add(svo);
}
}
return al;
}
};
ArrayList<LightBillVO> result =
(ArrayList<LightBillVO>) session.executeQuery(sqlbuilder.toString(),
para, p);
if (result.size() == 0) {
return null;
}
// 增补上游单据号
for (LightBillVO vo : result) {
List<String> info = this.getBillCodeAndCorp(vo.getType(), vo.getID());
if (info != null) {
vo.setCode(info.get(0));
vo.setCorp(info.get(1));
}
}
return result.toArray(new nc.vo.trade.billsource.LightBillVO[result
.size()]);
}catch (DbException e) {
Logger.error(e.getMessage(), e);
throw new UifRuntimeException(e.getMessage());
}
finally {
sessionManager.release();
}
}
@Override
public LightBillVO[] getSourceBills(String curBillType, String curBillID) {
// TODO Auto-generated method stub
//return super.getSourceBills(curBillType, curBillID);
LightBillVO[] source = super.getSourceBills(curBillType, curBillID);
LightBillVO[] sosource = this.getSoContractSourceBills(curBillType, curBillID);
return ArrayUtil.combinArrays(source,sosource);
}
}
四.效果