本文主要是介绍从中间表取数更新TW销售合同登记数据(含表体),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
package nc.bs.backgroundtasks;import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;import nc.bs.dao.BaseDAO;
import nc.bs.framework.common.NCLocator;
import nc.bs.pub.pa.PreAlertObject;
import nc.bs.pub.taskcenter.BgWorkingContext;
import nc.bs.pub.taskcenter.IBackgroundWorkPlugin;
import nc.impl.pubapp.pattern.data.bill.BillQuery;
import nc.itf.jych.IXshtdjMaintain;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.jdbc.framework.processor.ColumnListProcessor;
import nc.vo.jych.oavo.OaXshtBVO;
import nc.vo.jych.oavo.OaXshtVO;
import nc.vo.jych.util.SqlBuilder;
import nc.vo.jych.xshtdj.AggXshtdjVO;
import nc.vo.jych.xshtdj.XshtdjBVO;
import nc.vo.jych.xshtdj.XshtdjVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.SuperVOUtil;
import nc.vo.pub.VOStatus;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.wgbfb.tool.NullValueUtils;
/*** @desc : 从中间表取数更新TW销售合同登记数据* @author hanh* @date : 2023-10-09*/public class OAXshtdjPlugin implements IBackgroundWorkPlugin{@Overridepublic PreAlertObject executeTask(BgWorkingContext arg0) throws BusinessException {//抽取中间表数据generateZjXsht();return null;}//抽取中间表数据@SuppressWarnings("unchecked")private void generateZjXsht() throws BusinessException {//查询中间表中未执行的主表数据String sql = " select * from jych_zj_xsht where nvl(dr,0) = 0 and nvl(iszx,'N') != 'Y' ";//volist存放中间表中未执行的主表数据List<OaXshtVO> volist = (List<OaXshtVO>) getDao().executeQuery(sql.toString(), new BeanListProcessor(OaXshtVO.class));if(volist == null || volist.size() < 1){return;}//idlist存放id+sjlyList<String> idlist = new ArrayList<String>(); //zjpklist存放中间表主表主键List<String> zjpklist = new ArrayList<String>();for (OaXshtVO vo : volist) {//给idlist和zjpklist赋值String id = vo.getId()+vo.getSjly();idlist.add(id);zjpklist.add(vo.getPk_xsht());}//根据中间表id+sjly,查询nc系统中已存在的主表主键SqlBuilder pksql = new SqlBuilder(); pksql.append(" select pk_xshtdj from jych_xshtdj where nvl(dr,0) = 0 and ");pksql.appendNotIn(" def1||sjly ", idlist.toArray(new String[0]));List<String> pklist = (List<String>) getDao().executeQuery(pksql.toString(), new ColumnListProcessor());//Map<key : id+sjly , value : AggVO> 将已存在的AggVO放入vomapMap<String, AggXshtdjVO> vomap = new HashMap<String, AggXshtdjVO>();if(pklist != null && pklist.size() > 0){//根据已存在的主表主键获取已存在的AggVOBillQuery<AggXshtdjVO> billQuery = new BillQuery<AggXshtdjVO>(AggXshtdjVO.class);AggXshtdjVO[] aggvos = billQuery.query(pklist.toArray(new String[0]));for (AggXshtdjVO aggvo : aggvos) {//将aggvo对应的id和aggvo捆绑String wxtbs = aggvo.getParentVO().getDef1();String sjly = aggvo.getParentVO().getSjly();String id = wxtbs + sjly;vomap.put(id, aggvo);}}SqlBuilder sqlnameb = new SqlBuilder(); //查询中间表中主表所对应的子表数据sqlnameb.append(" select * from jych_zj_xsht_b where nvl(dr,0) = 0 and ");sqlnameb.append(" mainid||sjly ", idlist.toArray(new String[0]));//bvolist存放已存在主表对应的子表数据List<OaXshtBVO> bvolist = (List<OaXshtBVO>) getDao().executeQuery(sqlnameb.toString(), new BeanListProcessor(OaXshtBVO.class));//Map<key : mainid+sjly , value : AggVO> 已存在主表对应的子表数据放入bvomapMap<String, List<OaXshtBVO>> bvomap = new HashMap<String, List<OaXshtBVO>>();if(bvolist != null && bvolist.size() > 0){for (OaXshtBVO bvo : bvolist) {//将bvo对应的mainid和bvo捆绑String mainid = bvo.getMainid()+bvo.getSjly();if(bvomap.containsKey(mainid)){//如果bvomap存在该mainid,直接将该bvo和该mainid捆绑List<OaXshtBVO> list = bvomap.get(mainid);list.add(bvo);bvomap.put(mainid, list);} else {//如果bvomap不存在该mainid,则新建一个list,然后再将该bvo和该mainid捆绑List<OaXshtBVO> list = new ArrayList<OaXshtBVO>();list.add(bvo);bvomap.put(mainid, list);}}}//翻译OaXshtVOupdateHeadVO(volist.toArray(new OaXshtVO[0])); //insertlist存放执行插入的aggvoList<AggXshtdjVO> insertlist = new ArrayList<AggXshtdjVO>();//updatelist存放执行更新后的aggvoList<AggXshtdjVO> updatelist = new ArrayList<AggXshtdjVO>();//orgupdatelist存放执行更新前的aggvo List<AggXshtdjVO> orgupdatelist = new ArrayList<AggXshtdjVO>(); for (OaXshtVO vo : volist) {//封装insertlist、updatelist、orgupdatelistif(vomap != null && vomap.size() > 0 && vomap.containsKey(vo.getId()+vo.getSjly())){ //修改AggXshtdjVO aggvo = vomap.get(vo.getId()+vo.getSjly());AggXshtdjVO clone = (AggXshtdjVO) aggvo.clone();XshtdjVO headvo = clone.getParentVO();headvo.setStatus(VOStatus.UPDATED);setHeadvo(headvo, vo);updatelist.add(clone);orgupdatelist.add(aggvo);} else { //新增AggXshtdjVO aggvo = new AggXshtdjVO();XshtdjVO headvo = new XshtdjVO();headvo.setStatus(VOStatus.NEW);headvo.setPk_billtype("XSHT");headvo.setTranstypecode("XSHT");headvo.setPk_org(vo.getPk_org());headvo.setPk_org_v(vo.getPk_org_v());headvo.setPk_group(vo.getPk_group());headvo.setPk_transtype(vo.getPk_transtype());headvo.setDbilldate(new UFDate());headvo.setVbillstatus(-1);setHeadvo(headvo, vo);if(bvomap != null && bvomap.size() > 0 && bvomap.containsKey(vo.getId()+vo.getSjly())){XshtdjBVO[] bvos = setbodyvo(bvomap.get(vo.getId()+vo.getSjly()));aggvo.setChildrenVO(bvos);}aggvo.setParentVO(headvo);insertlist.add(aggvo);}}if(insertlist != null && insertlist.size() > 0){//调新增接口AggXshtdjVO[] insertvos = getService().insert(insertlist.toArray(new AggXshtdjVO[0]), insertlist.toArray(new AggXshtdjVO[0]));List<AggXshtdjVO> insertvolist = new ArrayList<AggXshtdjVO>();for (AggXshtdjVO insertvo : insertvos) {AggXshtdjVO clone = (AggXshtdjVO) insertvo.clone();XshtdjVO vo = clone.getParentVO();vo.setVbillstatus(1);vo.setApprovedate(new UFDateTime());vo.setApprover(vo.getCreator());insertvolist.add(clone);}getService().approve(insertvolist.toArray(new AggXshtdjVO[0]), insertvos);}if(updatelist != null && updatelist.size() > 0){//调更新接口getService().update(updatelist.toArray(new AggXshtdjVO[0]), orgupdatelist.toArray(new AggXshtdjVO[0]));}SqlBuilder updatesql = new SqlBuilder(); //更新中间表中已执行数据的是否执行标识updatesql.append(" update jych_zj_xsht set iszx = 'Y' where ");updatesql.append(" pk_xsht ", zjpklist.toArray(new String[0]));getDao().executeUpdate(updatesql.toString());}private void updateHeadVO(OaXshtVO[] headvos) {SuperVOUtil.execFormulaWithVOs(headvos, new String[] {// 组织"pk_org->getcolvalue2(org_orgs,pk_org,code,\"05\",islastversion,\"Y\")",// 组织版本"pk_org_v->getcolvalue(org_orgs,pk_vid,pk_org,pk_org)",// 集团"pk_group->getcolvalue(org_group,pk_group,code,\"01\")",//申请人"lastname->getColValue2(bd_psndoc,pk_psndoc,name,lastname,dr,0)",//申请部门"departmentname->getColValue2(org_dept,pk_dept,name,departmentname,dr,0)",//甲方"jfdwbm->getcolvalue2(bd_customer,pk_customer,name,jfdwbm,dr,0)",//乙方"partyb->getcolvalue2(bd_supplier,pk_supplier,name,\"北京城建智控科技股份有限公司\",dr,0)",//币种"bz->getcolvalue2(bd_currtype,pk_currtype,name,bz,dr,0)",//营销项目"xmbh->getColValue2(zkch_marketpro,pk_marketpro,marketprocode,xmbh,dr,0)",});}public void setHeadvo(XshtdjVO headvo, OaXshtVO vo){headvo.setDef1(vo.getId());//项目编号headvo.setPk_marketpro(vo.getXmbh());//合同编码headvo.setHtcode(vo.getHtbh());//合同名称headvo.setHtname(vo.getHtmc());//合同类型headvo.setHttype(vo.getHtlx());//投标类型headvo.setTbtype(vo.getTblx());//甲方headvo.setPartya(vo.getJfdwbm());headvo.setPartyb(vo.getPartyb());//合同金额(含税)headvo.setNmny(vo.getHtjkhs());//合同金额(不含税)headvo.setNtmny(vo.getHtjkbhs());//税率(%)headvo.setTaxrate(NullValueUtils.getNullStringValue(vo.getSl()));//税额headvo.setPaid(vo.getSe());//累计开票金额// headvo.setLjkpmny(rs.getString(1));//累计回款金额// headvo.setLjhkmny(rs.getString(1));//累计结算金额// headvo.setLjnjsmny(rs.getString(1));//申请日期headvo.setSqdate(vo.getSqrq());//签约日期headvo.setQydate(vo.getQyrq());//归档日期headvo.setGddate(vo.getSjyyrq());//所属机构headvo.setSsjg(vo.getSzjg());//申请人headvo.setSqr(vo.getLastname());//申请部门headvo.setSqdept(vo.getDepartmentname());//是否关联交易方headvo.setIsgljyf(vo.getSfgljyf());//是否包含自研产品headvo.setIszycp(vo.getSfbhzycp());//合同开工日期headvo.setHtkgdate(vo.getHtkgrq());//合同竣工日期headvo.setHtjgdate(vo.getHtjgrq());//合同工期headvo.setHtgq(vo.getHtgq());//履约地点headvo.setLyadress(vo.getLydd());//币种headvo.setBz(vo.getBz());//汇率headvo.setHl(vo.getHl());//合同份数headvo.setHtfs(vo.getHtfs());//是否为公司标椎合同模板headvo.setIsgsbzmb(vo.getSfwgsbzhtmb());//合同章headvo.setHtz(vo.getHtz());//公章headvo.setGz(vo.getGz());//法人章headvo.setFrz(vo.getFrz());//总经理手签章headvo.setZjlsqz(vo.getZjlsqz());//福州分公司公章headvo.setFzfgsgz(vo.getFzfgsgz());//总经理印章headvo.setZjlyz(vo.getZjlyz());//备注说明headvo.setMemo(vo.getBzsm());headvo.setSjly(vo.getSjly());}public XshtdjBVO[] setbodyvo(List<OaXshtBVO> bvolist){XshtdjBVO[] bvos = new XshtdjBVO[bvolist.size()];for (int i = 0; i < bvos.length; i++) {OaXshtBVO bvo = bvolist.get(i);bvos[i] = new XshtdjBVO();bvos[i].setRowno(i+1+"0");//税率bvos[i].setTaxrate(bvo.getSl());//含税金额bvos[i].setNmny(bvo.getHsje());//不含税金额bvos[i].setNtmny(bvo.getBhsje());//合计税额bvos[i].setPaid(bvo.getSey());//合同事项bvos[i].setHtsx(bvo.getHtsx());bvos[i].setStatus(VOStatus.NEW);}return bvos;}private IXshtdjMaintain service;private IXshtdjMaintain getService() {if (service == null) {service = NCLocator.getInstance().lookup(IXshtdjMaintain.class);}return service;}private BaseDAO dao;private BaseDAO getDao(){if(dao == null){dao = new BaseDAO();}return dao;}}
这篇关于从中间表取数更新TW销售合同登记数据(含表体)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!