多页签excel导入

 先新建公共的导入窗口及窗口中的内容

ClientUI:

package nc.ui.jygyl.zkgylIn;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import nc.bs.framework.common.NCLocator;
import nc.itf.jygyl.export.IQgdExportMaintain;
import nc.itf.uap.IUAPQueryBS;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.ui.pub.beans.MessageDialog;
import nc.ui.pub.beans.UIPanel;
import nc.ui.pub.beans.UIRefPane;
import nc.ui.pub.bill.BillCardPanel;
import nc.vo.jygyl.export.tool.BljhImportUtils;
import nc.vo.jygyl.export.tool.ClckImportUtils;
import nc.vo.jygyl.export.tool.GeneraloutImportUtils;
import nc.vo.jygyl.export.tool.InvCountBillExportUtils;
import nc.vo.jygyl.export.tool.PoOrderImportUtils;
import nc.vo.jygyl.export.tool.SCOrderImportUtils;
import nc.vo.jygyl.export.tool.SapplyBillImportUtils;
import nc.vo.jygyl.export.tool.StoreReqImportUtils;
import nc.vo.jygyl.export.tool.WtjgrkImportUtils;
import nc.vo.jygyl.export.tool.ZkdImportUtils;
import nc.vo.jygyl.export.tool.m23.ArriveImportUtils;
import nc.vo.jygyl.export.tool.m45.PurchaseInImportUtils;
import nc.vo.jygyl.tool.NullValueUtils;
import nc.vo.pubapp.AppContext;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;


/**
 * 业务单据导入
 * @author lyh
 * @date 2023-05-31
 */
public class ClientUI extends UIPanel{

	private static final long serialVersionUID = -7973821104724069917L;
	private UIPanel uipanel;
	private BillCardPanel billCardPanel;
	private JTextField filePath;
	private IUAPQueryBS basedao;

	public ClientUI() {
		// TODO 自动生成的构造函数存根
		setLayout(new BorderLayout());
		add(getExportOutPanel(), java.awt.BorderLayout.CENTER);
		add(getUIPanel(), java.awt.BorderLayout.NORTH);
		UIRefPane refPane = (UIRefPane) getBillCardPanel().getHeadItem("jylx").getComponent();
		refPane.getRefModel().setWherePart(" pk_billtypecode in ('55A3-0001','55A3-0002','55A3-0003','61-common','422X-01','4455-Cxx-2','4455-Cxx-3','4I-02','4I-03','4I-Cxx-1','4I-Cxx-2','4I-Cxx-3','4I-Cxx-4','4I-Cxx-5','4I-Cxx-99','20-Cxx-1','20-Cxx-2','20-Cxx-3','23-Cxx-1','23-Cxx-2','23-Cxx-3','23-Cxx-4','45-Cxx-1','45-Cxx-2','45-Cxx-3','4R-01','4K-01','21-Cxx-1','21-Cxx-2','21-Cxx-3','21','4D-01','4D-02','4D-03','47-01','47-Cxx-01')");
		refPane.setMultiSelectedEnabled(false);
	}

	private BillCardPanel getBillCardPanel(){
		if (billCardPanel == null) {
			billCardPanel = new BillCardPanel();
			billCardPanel.loadTemplet("zkgyldr", null, AppContext.getInstance().getPkUser(), null);
			billCardPanel.setEnabled(true);
		} 
		return billCardPanel;
	}

	private nc.ui.pub.beans.UIPanel getUIPanel() {
		if (uipanel == null) {
			uipanel = new UIPanel();
			uipanel.setLayout(new BorderLayout());
			uipanel.setBorder(BorderFactory.createTitledBorder("查询条件"));
			uipanel.add(getBillCardPanel(), java.awt.BorderLayout.CENTER);
		}
		return uipanel;
	}

	/**
	 * 导入模板
	 * @return
	 */
	private JPanel getExportOutPanel(){
		JPanel jPanel = new JPanel();
		jPanel.setLayout(null);
		jPanel.setSize(600,300);
		jPanel.setBorder(BorderFactory.createTitledBorder("导入"));
		JLabel filePathLabel = new JLabel("文件路径:");
		filePathLabel.setBounds(10, 15, 100, 20);
		filePath = new JTextField();
		filePath.setBounds(80, 15, 350, 20);
		filePath.setEditable(false);
		//选择
		getSelectFileButton().setBounds(440, 15, 120, 20);
		getImportTxtButton().setBounds(570, 15, 80, 20);

		JTextArea content = new JTextArea(50,10);
		content.setText("");
		content.setFont(new Font("宋体",1,10));
		JScrollPane js = new JScrollPane(content);
		js.setBounds(10, 60, 770, 100);

		jPanel.add(filePathLabel);
		jPanel.add(filePath);
		jPanel.add(getSelectFileButton());	
		jPanel.add(getImportTxtButton());
		jPanel.add(js);
		jPanel.setVisible(true);
		return jPanel;
	}

	private JButton selectFileBtn = null;

	/**
	 * 选择文件按钮
	 * @return
	 */
	private JButton getSelectFileButton(){
		if(selectFileBtn == null){
			selectFileBtn = new JButton("选择路径");
			selectFileBtn.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent arg0) {
					fileSelect();
				}
			});
		}
		return selectFileBtn;
	}

	/**
	 * 选择文件
	 *
	 */
	private void fileSelect(){
		FileDialog fileDlg = new FileDialog();
		if (fileDlg.show()) {
			// 得到导入的EXCEL文件路径
			String filepath = fileDlg.getFilePath();
			filePath.setText(filepath);
		}
	}

	/**
	 * 导入按钮
	 */
	private JButton importTxtBtn = null;
	private JButton getImportTxtButton(){
		if(importTxtBtn == null){
			importTxtBtn = new JButton("导入");
			importTxtBtn.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent arg0) {
					try {
						if(filePath.getText() == null || filePath.getText().equals("")){
							ExceptionUtils.wrappBusinessException("请选择入出文件路径!");
						}
						doImport(filePath.getText().toString());
					} catch (Exception e) {
						MessageDialog.showHintDlg(null, "", "导入失败"+e.getMessage());
						return;
					}
					MessageDialog.showHintDlg(null, "", "导入成功,请查询");
				}
			});
		}
		return importTxtBtn;
	}

	/**
	 * 导入处理
	 * @throws FileNotFoundException 
	 */
	public void doImport(String filepath) throws Exception{
		//校验非空
		getBillCardPanel().dataNotNullValidate();

		if(filePath.getText() == null || filePath.getText().equals("")){
			ExceptionUtils.wrappBusinessException("请选择导入文件路径!");
		}
		//交易类型
		String jylx = NullValueUtils.getNullStringValue(getBillCardPanel().getHeadItem("jylx").getValueObject());
		String sql = " select pk_billtypecode from bd_billtype where pk_billtypeid = '"+ jylx +"' and isnull(dr,0) = 0 ";
		String pk_billtypecode = NullValueUtils.getNullStringValue(getqueryService().executeQuery(sql,new ColumnProcessor()));
		//55A3-0001生产备料计划 || 55A3-0002全程委外备料计划 || 55A3-0003工序委外备料计划
		if(pk_billtypecode.equals("55A3-0001") || pk_billtypecode.equals("55A3-0002") || pk_billtypecode.equals("55A3-0003")){
			BljhImportUtils.getInstance().bljhImportUtils(filePath);
		}else if("61-common".equals(pk_billtypecode)){
			SCOrderImportUtils.getInstance().importData(filepath);
		}else if(pk_billtypecode.equals("422X-01")){
			InputStream input = new FileInputStream(filepath);
			StoreReqImportUtils.getInstance().importData(input);
		}else if(pk_billtypecode.equals("4455-Cxx-2") || pk_billtypecode.equals("4455-Cxx-3")){ // 出库申请单 :项目物料出库申请单、项目直采出库申请单
			SapplyBillImportUtils.getInstance().sapplyBillImport(filepath, pk_billtypecode);
		}else if(pk_billtypecode.equals("4I-02") || pk_billtypecode.equals("4I-03") || pk_billtypecode.equals("4I-Cxx-1") || pk_billtypecode.equals("4I-Cxx-2") || pk_billtypecode.equals("4I-Cxx-3") || pk_billtypecode.equals("4I-Cxx-4") || pk_billtypecode.equals("4I-Cxx-5") || pk_billtypecode.equals("4I-Cxx-99")){ // 其它出库单 :转库出库、盘亏出库、生产物料出库、项目直采出库、项目物料出库、零售物料出库、产成品出库、仓库拆分成本出库
			GeneraloutImportUtils.getInstance().generaloutImport(filepath, pk_billtypecode);
		}else if(pk_billtypecode.equals("20-Cxx-1") || pk_billtypecode.equals("20-Cxx-3")){
			InputStream input = new FileInputStream(filepath);
			NCLocator.getInstance().lookup(IQgdExportMaintain.class).importqgd(input);
		}else if(pk_billtypecode.equals("23-Cxx-1") || pk_billtypecode.equals("23-Cxx-2") || pk_billtypecode.equals("23-Cxx-3") || pk_billtypecode.equals("23-Cxx-4")){
			ArriveImportUtils.getInstance().arriveImport(filepath);
		}else if(pk_billtypecode.equals("45-Cxx-1") || pk_billtypecode.equals("45-Cxx-2") || pk_billtypecode.equals("45-Cxx-3") || pk_billtypecode.equals("23-Cxx-4")){
			PurchaseInImportUtils.getInstance().arriveImport(filepath);
		}else if(pk_billtypecode.equals("4R-01")){//盘点
			InvCountBillExportUtils.getInstance().importData(filePath);
          //NCLocator.getInstance().lookup(IQgdExportMaintain.class).importData(filePath);在实现类里不能直接这样用,因为filePath是JTextField类型
		}else if(pk_billtypecode.equals("4K-01") || pk_billtypecode.equals("4K-02")){//4K-01转库,4K-02备料计划转库
			ZkdImportUtils.getInstance().zkdImportUtils(filePath);
		}else if (pk_billtypecode.equals("21-Cxx-1") || pk_billtypecode.equals("21-Cxx-2") || pk_billtypecode.equals("21-Cxx-3") || pk_billtypecode.equals("21")) {//采购订单
			PoOrderImportUtils.getInstance().poOrderImportUtils(filePath);			
		}else if(pk_billtypecode.equals("4D-02")){
			ClckImportUtils.getInstance().clckImportUtils(filePath,pk_billtypecode);
		}else if(pk_billtypecode.equals("47-Cxx-01") || pk_billtypecode.equals("47-01")){
			WtjgrkImportUtils.getInstance().wtjgrkImportUtils(filePath, pk_billtypecode);
		}
	}
	private IUAPQueryBS queryservice;
	private IUAPQueryBS getqueryService() {
		if(queryservice == null) {
			queryservice = NCLocator.getInstance().lookup(IUAPQueryBS.class);
		}
		return queryservice;
	}

}

FileDialog:

package nc.ui.jygyl.zkgylIn;

import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;


public class FileDialog {

JFileChooser jFileChooser = new JFileChooser(); 
	
	public FileDialog() {
		super();
	}
	
	public boolean show(){
		jFileChooser.removeChoosableFileFilter(jFileChooser.getAcceptAllFileFilter());
		jFileChooser.setFileFilter(new FileFilter() {
			public boolean accept(File f) {
				if(f.getName().endsWith(".xlsx")||f.isDirectory()){
			          return true;
			        }
			        return false;
			}
			public String getDescription() {
				// TODO 自动生成方法存根
				return "所有文件(*.xlsx)";
			}
		});
		return JFileChooser.APPROVE_OPTION == jFileChooser.showOpenDialog(null);
	}
	
	public String getFilePath(){
		return jFileChooser.getSelectedFile().getPath();
	}
}

最后新建导入接口及其实现类,别忘记添加upm

 

IInvCountBillMaintain:

package nc.itf.jygyl.export;

import java.util.List;

import nc.vo.ic.m4r.entity.InvCountBillVO;
import nc.vo.pub.BusinessException;

/**
 * 盘点单接口类
 * @author wf
 * @date:2023-06-01
 */
public interface IInvCountBillMaintain {
	/**
	 * 执行动作脚本
	 */
	public void executeData(List<InvCountBillVO> voslist) throws BusinessException ;

}

InvCountBillImpl:

package nc.impl.jygyl.export;

import java.util.ArrayList;
import java.util.List;

import nc.bs.dao.BaseDAO;
import nc.bs.framework.common.NCLocator;
import nc.impl.pubapp.pattern.data.bill.BillQuery;
import nc.impl.pubapp.pattern.database.DataAccessUtils;
import nc.itf.jygyl.export.IInvCountBillMaintain;
import nc.itf.uap.pf.IplatFormEntry;
import nc.jdbc.framework.processor.ColumnListProcessor;
import nc.vo.ic.m4r.entity.InvCountBillVO;
import nc.vo.ic.pub.sql.SqlUtil;
import nc.vo.pub.AggregatedValueObject;
import nc.vo.pub.BusinessException;
import nc.vo.pub.JavaType;
import nc.vo.pubapp.pattern.pub.SqlBuilder;



public class InvCountBillImpl implements IInvCountBillMaintain{
	/**
	 * 执行动作脚本
	 */
	@Override
	public void executeData(List<InvCountBillVO> voslist) throws BusinessException {

		List<List<Object>> updateList = new ArrayList<List<Object>>();

		for (int i = 0; i < voslist.size(); i++) {
			InvCountBillVO aggvos = voslist.get(i); 
			//完成后将信息修改为导入信息上的时间
			List<Object> updateValue = new ArrayList<Object>(); 
			// 审批人
			updateValue.add(aggvos.getParentVO().getApprover());
			//审批时间
			updateValue.add(aggvos.getParentVO().getTaudittime());
			// 创建人
			updateValue.add(aggvos.getParentVO().getCreator());
			// 创建时间
			updateValue.add(aggvos.getParentVO().getCreationtime());
			//制单人
			updateValue.add(aggvos.getParentVO().getBillmaker());
			//制单时间
			updateValue.add(aggvos.getParentVO().getDmakedate());
			//最后修改人
			updateValue.add(aggvos.getParentVO().getModifier());
			//最后修改时间
			updateValue.add(aggvos.getParentVO().getModifiedtime());
			//原单据主键
			updateValue.add(aggvos.getParentVO().getVdef10());
			updateList.add(updateValue);
			//执行保存
			InvCountBillVO saveaggvo = (InvCountBillVO) doActionResult(aggvos, "WRITE", "4R");
			//执行审批
			doAction(saveaggvo, "APPROVE", "4R");
		}

		//执行更新
		String sql = SqlUtil.getUpdateSql("ic_invcount_h",
				new String[] { "creator", "creationtime", "modifier", "modifiedtime", "billmaker", "dmakedate", "approver", "taudittime" },
				new String[] {

				"?",
				"?",
				"?",
				"?",
				"?",
				"?",
				"?",
				"?"

		}, new String[] { "vdef10" }, null, null);
		new DataAccessUtils().update(sql,
				new JavaType[] { JavaType.String, JavaType.UFDateTime, JavaType.String, JavaType.UFDateTime, JavaType.String, JavaType.UFDate, JavaType.String, JavaType.UFDate, JavaType.String }, updateList);


	}


	/**
	 * 执行动作脚本
	 * 
	 * @param vo
	 * @param actionCode
	 * @param billtype
	 * @throws BusinessException
	 */
	protected void doAction(AggregatedValueObject aggvo, String actionCode,
			String billtype) throws BusinessException {
		IplatFormEntry platform = NCLocator.getInstance().lookup(
				IplatFormEntry.class);
		platform.processAction(actionCode, billtype, null, aggvo, null, null);

	}

	/**
	 * 执行动作脚本
	 * 
	 * @param vo
	 * @param actionCode
	 * @param billtype
	 * @throws BusinessException
	 */
	protected AggregatedValueObject doActionResult(AggregatedValueObject aggvo,
			String actionCode, String billtype) throws BusinessException {
		IplatFormEntry platform = NCLocator.getInstance().lookup(
				IplatFormEntry.class);
		AggregatedValueObject[] resultvos = (AggregatedValueObject[]) platform
				.processAction(actionCode, billtype, null, aggvo, null, null);
		return resultvos[0];

	}
	private BaseDAO basedao;

	private BaseDAO getBaseDao(){
		if(basedao == null){
			basedao = new BaseDAO();
		}
		return basedao;
	}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值