package com.tenwa.apzl.comm; import java.util.ArrayList; import java.util.List; import jbo.app.tenwa.customer.DISTRIBUTOR_ACCOUNT; import jbo.com.tenwa.lease.comm.LB_CONTRACT_INFO; import jbo.sys.OVERDUE_DUNNING_INFO; import com.amarsoft.are.jbo.BizObject; import com.amarsoft.are.jbo.BizObjectManager; import com.amarsoft.are.jbo.JBOException; import com.amarsoft.are.jbo.JBOFactory; import com.amarsoft.are.jbo.JBOTransaction; public class PartdeptDistribute { private String userid; private String contract_number; private String ids; private String distributorNo; private String accountId; private String isMain; public String getIsMain() { return isMain; } public void setIsMain(String isMain) { this.isMain = isMain; } public String getAccountId() { return accountId; } public void setAccountId(String accountId) { this.accountId = accountId; } public String getDistributorNo() { return distributorNo; } public void setDistributorNo(String distributorNo) { this.distributorNo = distributorNo; } public String getUserid() { return userid; } public void setUserid(String userid) { this.userid = userid; } public String getContract_number() { return contract_number; } public void setContract_number(String contract_number) { this.contract_number = contract_number; } public String getIds() { return ids; } public void setIds(String ids) { this.ids = ids; } /* * 选择催款员 */ public String selectPartdept(JBOTransaction tx){ String userid = this.getUserid(); String contractNumber = this.getContract_number(); try { BizObject contractInfo = JBOFactory.createBizObjectQuery(LB_CONTRACT_INFO.CLASS_NAME, "contract_no=:contract_number").setParameter("contract_number", contractNumber).getSingleResult(false); String contractId = contractInfo.getAttribute("id").toString(); BizObjectManager overdueManager = JBOFactory.getBizObjectManager(OVERDUE_DUNNING_INFO.CLASS_NAME, tx); BizObject overdue = overdueManager.createQuery("contract_id=:contract_id").setParameter("contract_id", contractId).getSingleResult(false); if(overdue == null){ BizObject overdue2 = overdueManager.newObject(); overdue2.setAttributeValue("contract_id", contractId); overdue2.setAttributeValue("part_dept", userid); overdueManager.saveObject(overdue2); }else{ overdueManager.createQuery("update O set part_dept=:part_dept where contract_id=:contract_id") .setParameter("contract_id", contractId).setParameter("part_dept", userid).executeUpdate(); } } catch (JBOException e) { e.printStackTrace(); } return ""; } /** * 批量修改催款员 */ public String selectPartdepts(JBOTransaction tx){ String userid = this.getUserid(); String[] arrIds = ids.split("@"); BizObjectManager overdueManager; try { overdueManager = JBOFactory.getBizObjectManager(OVERDUE_DUNNING_INFO.CLASS_NAME, tx); for (int i = 0; i < arrIds.length; i++) { String contractId = arrIds[i]; BizObject overdue = overdueManager.createQuery("contract_id=:contract_id").setParameter("contract_id", contractId).getSingleResult(false); if(overdue == null){ BizObject overdue2 = overdueManager.newObject(); overdue2.setAttributeValue("contract_id", contractId); overdue2.setAttributeValue("part_dept", userid); overdueManager.saveObject(overdue2); }else{ overdueManager.createQuery("update O set part_dept=:part_dept where contract_id=:contract_id") .setParameter("contract_id", contractId).setParameter("part_dept", userid).executeUpdate(); } } } catch (JBOException e) { e.printStackTrace(); } return ""; } /** * 判断经销商账户主账户,只能存在一个主账户 */ public String isMainAccount(JBOTransaction tx){ String msg = ""; try { if("Y".equals(isMain)){ List list = new ArrayList(); String main = ""; @SuppressWarnings("unchecked") List resultList = JBOFactory.createBizObjectQuery(DISTRIBUTOR_ACCOUNT.CLASS_NAME, "distributor_id=:distributor_id") .setParameter("distributor_id", this.distributorNo).getResultList(false); for (BizObject bo : resultList) { main=bo.getAttribute("is_main")==null?"":bo.getAttribute("is_main").toString(); String accid = bo.getAttribute("ID").toString(); //如果此账户是主账户则不参与判断 if(!(accid.equals(accountId) && main.equals("Y"))){ list.add(main); } } if(list.contains("Y")==true){ msg = "一个经销商只能有一个主账户"; } } return msg; } catch (JBOException e) { e.printStackTrace(); } return msg; } }