版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sir_jun/article/details/39322021
package nc.imp.hn.wl.wl.yundan;
import java.util.ArrayList;
import java.util.HashMap;
import nc.bs.dao.BaseDAO;
import nc.bs.framework.common.NCLocator;
import nc.bs.hn.wl.pub.SuperDMO;
import nc.bs.pub.pf.PfUtilBO;
import nc.bs.pub.taskcenter.BgWorkingContext;
import nc.bs.pub.taskcenter.IBackgroundWorkPlugin;
import nc.itf.uap.busibean.ISysInitQry;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.vo.bd.b08.CustBasVO;
import nc.vo.hn.hn303007.WAYBILLVO;
import nc.vo.hn.hn303010.AggSlArrivivalVO;
import nc.vo.hn.hn303010.SlArrivivalVO;
import nc.vo.hn.hnh506.ChannelVO;
import nc.vo.hn.wl.wl.yunhao.YunDanHaoVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDouble;
import nc.vo.pub.para.SysInitVO;
/**
* 运单同步
*
* <p>
* 创建人: liljb
* 创建日期: 2014-9-16
* @version 1.0
* @since NC5.7
*/
@SuppressWarnings({ "deprecation", "unchecked" })
public class YunDanSys implements IBackgroundWorkPlugin {
private StringBuilder rwrz = new StringBuilder();// 任务日志
private SuperDMO wldao;
private BaseDAO dao;
public String executeTask(BgWorkingContext bgwc) throws BusinessException {
ChannelVO[] channelDVO = (ChannelVO[]) getDao().retrieveByClause(ChannelVO.class, "ileveltype='2' and iproducttype ='3'").toArray(new ChannelVO[0]);
if (channelDVO == null || channelDVO.length == 0) {
return "没有对应的渠道 YunDanSys 34line";
}
ChannelVO channelSDVO = channelDVO[0];
if (channelSDVO.getPk_correscorp() == null) {
return "##" + channelSDVO.getVlevelcode() + "##的 pk_correscorp 为空";
}
ISysInitQry sysinitQry = NCLocator.getInstance().lookup(ISysInitQry.class);
SysInitVO sysvo = sysinitQry.queryByParaCode(channelSDVO.getPk_correscorp(), "XHFXWL001");
if (sysvo == null || sysvo.getValue().equals("N")) {
return "XHFXWL001 为空";
}
// 每次处理的条数
int forinti = 1;
// 读取到货登记运号信息表 (物流方写入)
String sql = "select * from T_WL_YH where RECEFLAG='0' and sendflag='0'";
sql += " and ROWNUM<= " + forinti + "";
// sql += " and yh='008561'";
ArrayList<YunDanHaoVO> ydhvolist = (ArrayList<YunDanHaoVO>) getWLDao().executeQuery(sql, new BeanListProcessor(YunDanHaoVO.class));
rwrz.append("读取到货登记运号信息表:" + sql + "####");
if (ydhvolist.size() > 0) {
UFDate currenttime = new UFDate();
StringBuffer strbufferDH = new StringBuffer();
StringBuffer strbufferXT = new StringBuffer();
StringBuffer strbf = new StringBuffer();
//到货 DH 和销退 XT 分开
for (YunDanHaoVO temp : ydhvolist) {
if (temp.getDJLX().equals("DH")) {
strbufferDH.append("'" + temp.getFLOWID_TLDJHZ() + "',");
}
if (temp.getDJLX().equals("XT")) {
strbufferXT.append("'" + temp.getFLOWID_TLDJHZ() + "',");
}
strbf.append("'" + temp.getSL_GYS_CODE() + "',");
}
String custsql = "select * from bd_cubasdoc where pk_cubasdoc in(" + strbf.toString().substring(0, strbf.length() - 1) + ")";
ArrayList<CustBasVO> custbasvo = (ArrayList<CustBasVO>) getDao().executeQuery(custsql, new BeanListProcessor(CustBasVO.class));
if (!(custbasvo.size() > 0)) {
return rwrz + "sql:" + custsql + "返回结果为空";
}
// 客户PK ,名字
HashMap<String, String> custmap = new HashMap<String, String>();
for (CustBasVO temp : custbasvo) {
custmap.put(temp.getPk_cubasdoc(), temp.getCustname());
}
ArrayList<WAYBILLVO> xtlist = new ArrayList<WAYBILLVO>();
for (YunDanHaoVO temp : ydhvolist) {
// 构造运单管理表
WAYBILLVO wayvo = new WAYBILLVO();
wayvo.setSl_gys_code(temp.getSL_GYS_CODE());
wayvo.setPk_corp(channelSDVO.getPk_corp());
wayvo.setVbillcode(temp.getYH());// 运单号
if (temp.getDJLX().equals("DH")) {
wayvo.setSendtype(1);//到货
} else if (temp.getDJLX().equals("XT")) {
wayvo.setSendtype(2);// 销退
}
wayvo.setSendname(custmap.get(temp.getSL_GYS_CODE()));// 发货方名称
wayvo.setVbaono(temp.getBJSL());// 包数
// TODO 件数的取值需要确认
wayvo.setVjianno(new UFDouble(0));// 件数
wayvo.setVperson(temp.getSL_YWBM_CODE());// 货主
wayvo.setDbilldate(currenttime);// 运单日期
wayvo.setTlrq(temp.getTLRQ1());// 运单登记日期
wayvo.setWl_yh_pk(temp.getFLOWID_TLDJHZ().toString());// 物流运单主键
wayvo.setYdlx(temp.getDJLX());
getDao().insertVO(wayvo);
rwrz.append("构造运单管理表运号:" + temp.getYH());
// 销退到货单,自动匹配上然后审批发送物流
if (wayvo.getYdlx().equals("XT")) {
xtlist.add(wayvo);
}
}
if (strbufferDH.length() != 0) {
// 读取完后回写已经读取过的物流运单信息表中的接收标志RECEFLAG字段,设置为‘1’
String wlsql = "update T_WL_YH set RECEFLAG='1' where FLOWID_TLDJHZ in(" + strbufferDH.toString().substring(0, strbufferDH.length() - 1) + ")";
getWLDao().executeUpdate(wlsql);
rwrz.append("####回写T_wl_yh 标记 dh :" + wlsql);
}
// 销退到货单新需求:自动匹配上然后审批发送物流
if (xtlist.size() != 0) {
for (WAYBILLVO vo : xtlist) {
String vbillno = vo.getVbillcode();// 运单号
String sl_gys_code = vo.getSl_gys_code();// 供应商基本pk(在这里是客户)
String sql1 = "select * from hn_slarrivival t where t.vbillstatus='8' and nvl(t.dr,0)=0 and t.pk_supplier in(select pk_channel from bd_channel a where a.pk_corrbasdoc='" + sl_gys_code + "' and nvl(a.dr,0)=0) and pk_waybill ='" + vbillno + "'";
ArrayList<SlArrivivalVO> slvolist = (ArrayList<SlArrivivalVO>) getDao().executeQuery(sql1, new BeanListProcessor(SlArrivivalVO.class));
rwrz.append("####找销退到货单并审核" + sql1);
ReCalcuTHLX cal = new ReCalcuTHLX();
RecalcuThlxByydh call = new RecalcuThlxByydh();
if (slvolist.size() != 0) {
// 再次计算退货流向
for (SlArrivivalVO slArrivivalVO : slvolist) {
// cal.calcuxtthlx(slArrivivalVO);
try {
call.calcthlx(slArrivivalVO.getPk_waybill(), sl_gys_code);
} catch (Exception e) {
throw new BusinessException(e.getMessage());
}
}
for (SlArrivivalVO vo1 : slvolist) {
AggSlArrivivalVO agg1 = new AggSlArrivivalVO();
vo1.setVapproveid(vo1.getVoperatorid());
vo1.setTlrq(vo.getTlrq().getDate());// 运单登记日期
getDao().updateVO(vo1);
agg1.setParentVO(vo1);
try {
getPfutilbo().processAction("APPROVE", "TN1B", new UFDate().toString(), null, agg1, null);
String wlsqlXT = "update T_WL_YH set RECEFLAG='1' where FLOWID_TLDJHZ in('" + vo.getWl_yh_pk() + "')";
getWLDao().executeUpdate(wlsqlXT);
} catch (Exception e) {
e.printStackTrace();
throw new BusinessException(e);
}
}
}
// 找不到销退到货单,更新RECEFLAG=5
else {
String wlsqlXT = "update T_WL_YH set RECEFLAG='5' where FLOWID_TLDJHZ in('" + vo.getWl_yh_pk() + "')";
getWLDao().executeUpdate(wlsqlXT);
rwrz.append("####找不到销退到货单" + wlsqlXT);
}
}
}
// System.out.println("运单号同步成功" + ydhvolist.size() + "条");
}
// TODO 需要找人确认这个 2 是什么意思 李林君2014年9月16日 19:29:25
String sql1 = "select * from T_WL_YH where SENDERRFLAG='2'";
ArrayList<YunDanHaoVO> ydhvolist1 = (ArrayList<YunDanHaoVO>) getWLDao().executeQuery(sql1, new BeanListProcessor(YunDanHaoVO.class));
if (ydhvolist1.size() > 0) {
for (YunDanHaoVO delvo : ydhvolist1) {
String sqldel = "delete from hn_waybill where vbillcode='" + delvo.getYH() + "' and wl_yh_pk='" + delvo.getFLOWID_TLDJHZ() + "'";
getDao().executeUpdate(sqldel);
rwrz.append("####end" + sqldel);
}
}
return rwrz.toString();
}
private SuperDMO getWLDao() {
if (wldao == null) {
wldao = new SuperDMO();
}
return wldao;
}
private BaseDAO getDao() {
if (dao == null) {
dao = new BaseDAO();
}
return dao;
}
private PfUtilBO pfutilbo;
private PfUtilBO getPfutilbo() {
if (pfutilbo == null) {
pfutilbo = new PfUtilBO();
}
return pfutilbo;
}
}