allwiki首页  
天下维客 你可以修改的网络知识库
首页最近更改优秀条目专题展示电脑科技词典软件学习网络知识电脑安全明星时尚天下百科
 

Test

天下维客,你可以修改的网络知识库

Jump to: navigation, search

package com.toptv.dms.components.businessmanage.common.action;

import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap;

import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping;

import com.toptv.dms.common.ChangeFee; import com.toptv.dms.components.account.sysaccount.model.SysAccountModel; import com.toptv.dms.components.businessmanage.cardmanage.dao.UserCardDAO; import com.toptv.dms.components.businessmanage.cardmanage.model.UserCardModel; import com.toptv.dms.components.businessmanage.common.dao.OperationBean; import com.toptv.dms.components.businessmanage.common.model.CardRelationModel; import com.toptv.dms.components.businessmanage.common.model.FeeListModel; import com.toptv.dms.components.businessmanage.common.model.FeeModel; import com.toptv.dms.components.businessmanage.customermanage.dao.

   CustomerQryDAO;

import com.toptv.dms.components.businessmanage.customermanage.model.

   CustomerModel;

import com.toptv.dms.components.login.LoginUserInfoModel; import com.toptv.dms.print.model.DGPrintModel; import com.toptv.utils.SystemDate; import com.toptv.util.Format; import com.toptv.dms.components.businessmanage.stbmanage.dao.StbDAO; import com.toptv.dms.components.businessmanage.stbmanage.model.StbModel; import com.toptv.dms.components.common.transact.model.TransactModel; import com.toptv.dms.common.GetSn; import com.toptv.dms.components.common.util.CommonUtil; import com.toptv.dms.components.common.transact.util.TransactUtil; import com.toptv.dms.components.dtvossinterface.client.*; import com.toptv.dms.components.dtvossinterface.model.request.*; import com.toptv.dms.components.dtvossinterface.model.response.*; import com.toptv.util.db.DBTool; import com.toptv.dms.components.businessmanage.productmanage.model.

   UserProductModel;

import javax.transaction.UserTransaction; import com.toptv.dms.components.businessmanage.common.dao.OperationCardDAO; import com.toptv.dms.components.common.transact.dao.TransactDAO; import com.toptv.utils.ConnectionManager; import java.sql.Connection; import com.toptv.dms.components.businessmanage.common.model.GroupAddModel; /**

* 保存数据,将暂存的数据全部存入数据库中;
*
* @author wuheping
*/

public class BuySaveAction

   extends Action {
 public ActionForward execute(ActionMapping actionMapping,
                              ActionForm actionForm,
                              HttpServletRequest request,
                              HttpServletResponse httpServletResponse) {
   String forwardTarget = "success";
   DGPrintModel modPrint = null;
   TransactDAO transactDAO = new TransactDAO(); //业务受理记录
    GroupAddModel groupaddmodel=new GroupAddModel();
   String usercode = request.getParameter("usercode");
   DBTool db = null;
   UserTransaction tx = null;
   ConnectionManager cm = new ConnectionManager();
   Connection con = null; //连接(用来得到序列号)
   try {
     HttpSession session = request.getSession();
     tx = (UserTransaction) com.toptv.util.BaseClient.getUserTransact();
     tx.begin();


     LoginUserInfoModel modUserinfo = (LoginUserInfoModel) session.
         getAttribute("USERINFO");
     String strOperatorCode = modUserinfo.getOperatorCode();
     String strOperatorName = modUserinfo.getOperatorName();
     String custflag = Format.getStrFromRequest(request, "custflag");
     OperationBean operationBean = new OperationBean(session);
     CustomerModel modCustomer = operationBean.getCustomerModel();
     //开始设定费用支付类型
     ArrayList alCardno = new ArrayList();
     ArrayList alStbno = new ArrayList();
     boolean bExistFlag = false;
     ArrayList alCard = operationBean.getCardList();
     System.out.println("alCard大小为:"+alCard.size());
     String feepaytype = request.getParameter("feepaytype");
     String servId = ""; //第一个卡的 serv_id
     String cardno="";//第一个卡的 cardno
     for (int i = 0; i < alCard.size(); i++) {
       CardRelationModel modCardRelation = (CardRelationModel) alCard.get(i);
       if (i==0) {
         servId = modCardRelation.getUserCardModel().getServ_id();
         cardno = modCardRelation.getUserCardModel().getCardno();
       }
       HashMap hmFee = modCardRelation.getFee();
       FeeModel modFeePack = (FeeModel) hmFee.get("packFee");
       if (modFeePack != null) {
         modFeePack.setPaytype(feepaytype);
       }
       FeeModel modFeeCard = (FeeModel) hmFee.get("cardFee"); //卡费用
       if (modFeeCard != null) {
         modFeeCard.setPaytype(feepaytype);
       }
       FeeModel modFeeStb = (FeeModel) hmFee.get("stbFee"); //机顶盒费用
       if (modFeeStb != null) {
         modFeeStb.setPaytype(feepaytype);
       }
     }
     operationBean.setAlCard(alCard); //保存更改后的数据
     String strPayMoney = Format.getStrFromRequest(request, "payMoney"); //预交款金额
     if (strPayMoney == null || strPayMoney.trim().equals("")) {
       strPayMoney = "0";
     }
     java.math.BigDecimal dbPayMoney = Format.getBigDecimal(strPayMoney);
     //预交款保存
     if (dbPayMoney.doubleValue() > 0) { //预付款
       CardRelationModel modCardRelationTmp = (CardRelationModel) alCard.get(0);
       servId = modCardRelationTmp.getUserCardModel().getServ_id();
       TransactModel modTransact = modCardRelationTmp.getTransactModel();
       GetSn getSn = new GetSn();
       FeeModel modFee = new FeeModel();
       String strFeeno = CommonUtil.PREFIX_FEE_NO +
           getSn.getSequence("SEQ_FEE", 12, "0");
       modFee.setCustNo(usercode); //客户编号
       modFee.setFeeNo(strFeeno); //主键
       modFee.setFlag("1");
       modFee.setOperatorcode(strOperatorCode); //操作员
       modFee.setPaytype(feepaytype); //费用支付类型
       modFee.setRegioncode(Format.getStr(modCustomer.getRegioncode())); //区域
       modFee.setRemark("购买产品预付费");
       modFee.setServId(Format.getStr(servId)); //服务标识id
       modFee.setStorecode(Format.getStr(modCustomer.getStorecode())); //营业点
       modFee.setRebatefee(new BigDecimal("0")); //优惠金额
       modFee.setFactfee(dbPayMoney); //实际金额
       modFee.setTotalfee(dbPayMoney); //总额
       String strFeeListno = CommonUtil.PREFIX_FEE_NO +
           getSn.getSequence("SEQ_FEELIST", 14, "0");
       FeeListModel modFeeList = new FeeListModel();
       modFeeList.setAmount(new java.math.BigDecimal("1"));
       modFeeList.setCustNo(usercode);
       modFeeList.setDiscount(new java.math.BigDecimal("0"));
       modFeeList.setFeelistNo(strFeeListno); //主键
       modFeeList.setBussType(TransactUtil.BUSS_TYPE_PP); //预付款
       modFeeList.setFeename("预付款");
       modFeeList.setFeecode("9002");
       modFeeList.setFeeNo(strFeeno);
       modFeeList.setMoney(dbPayMoney);
       modFeeList.setPrice(dbPayMoney);
       modFeeList.setPriceunit("1");
       modFeeList.setTranNo(Format.getStr(modTransact.getTran_no()));
       modFeeList.setRemark("购产品时预付费");
       modFeeList.setServId(Format.getStr(servId));
       FeeListModel[] modFeeListArray = new FeeListModel[1];
       modFeeListArray[0] = modFeeList;
       modFee.setModFeeList(modFeeListArray);
       modCardRelationTmp.removeFeeOfPrePay();
       modCardRelationTmp.addFeeOfPrePay(modFee);
       operationBean.setCard(servId, modCardRelationTmp);
     }
     String strErrorMsg = "";
     String strPrintContent = ""; //打印的内容
     String strUsercode = request.getParameter("usercode");
     String firstServid = "";
     int cardCount = 0;
     UserCardDAO usercardDao = new UserCardDAO();
     System.out.println("alcard大小为:"+alCard.size());
     if (alCard != null && alCard.size() > 0) {
       cardCount = alCard.size();
       for (int i = 0; i < cardCount; i++) {
         CardRelationModel modCardRelation = (CardRelationModel) alCard
             .get(i);
         UserCardModel modUsercard = modCardRelation
             .getUserCardModel();
         if (modUsercard != null) {
           if (i == 0) {
             firstServid = modUsercard.getServ_id();
           }
           String cardnoTmp = modUsercard.getCardno();
           System.out.println("智能卡号:"+cardnoTmp);
           if (cardnoTmp != null) {
             alCardno.add(cardnoTmp);
             java.util.HashMap hmCard = usercardDao
                 .getCardByCardNo(cardnoTmp);
             if (hmCard != null && !hmCard.isEmpty()) {
               strErrorMsg = "智能卡:" + cardnoTmp + "已存在;\n"
                   + strErrorMsg;
               bExistFlag = true;
               break;
             }
           }
         }
         //判断机顶盒是否已存在  zjp 2005-06-17
         StbModel modStb = modCardRelation.getModStb();
         if (modStb != null &&
             !Format.getStr(modStb.getStbno()).trim().equals("")) {
           alStbno.add(modStb.getStbno());
           StbDAO sDao = new StbDAO();
           HashMap stbHs = sDao.getStb(modStb.getStbno());
           if (!Format.getStrFromHashMap(stbHs, "STATUS",
                                         "").trim().equals("2")) {
             strErrorMsg = "机顶盒:" + modStb.getStbno() + "无效;\n";
           }
         }
         //判断机顶盒是否已存在  zjp 2005-06-17
       }
     }
 System.out.println("cardCount值为:"+cardCount);
     if (cardCount == 2) {
       String cardno0 = (String) alCardno.get(0);
       String cardno1 = (String) alCardno.get(1);
       if (cardno0 != null && cardno0.equals(cardno1)) {
         strErrorMsg = "智能卡:" + cardno0 + "重复;\n" + strErrorMsg;
         bExistFlag = true;
       }
     }
     else if (cardCount >= 3) {
       for (int i = 0; i < cardCount; i++) {
         for (int j = i + 1; j < cardCount; j++) {
           String cardno_i = (String) alCardno.get(i);
           String cardno_j = (String) alCardno.get(j);
           if (cardno_i != null && cardno_i.equals(cardno_j)) {
             strErrorMsg = "智能卡:" + cardno_i + "重复;\n"
                 + strErrorMsg;
             bExistFlag = true;
             break;
           }
         }
         if (bExistFlag == true) {
           break;
         }
       }
     }
     //判断机顶盒是否重复 zjp 2005-06-17
     if (alStbno.size() == 2) {
       String stbno0 = (String) alStbno.get(0);
       String stbno01 = (String) alStbno.get(1);
       if (stbno0 != null && stbno0.equals(stbno01)) {
         strErrorMsg = "机顶盒:" + stbno0 + "重复;\n" + strErrorMsg;
         bExistFlag = true;
       }
     }
     else if (alStbno.size() >= 3) {
       for (int i = 0; i < alStbno.size(); i++) {
         for (int j = i + 1; j < alStbno.size(); j++) {
           String stbno_i = (String) alStbno.get(i);
           String stbno_j = (String) alStbno.get(j);
           if (stbno_i != null && stbno_i.equals(stbno_j)) {
             strErrorMsg = "机顶盒:" + stbno_i + "重复;\n"
                 + strErrorMsg;
             bExistFlag = true;
             break;
           }
         }
         if (bExistFlag == true) {
           break;
         }
       }
     }
     //判断机顶盒是否重复 zjp 2005-06-17
     if (bExistFlag == false) {
       String msg = "该用户开户成功!";
       boolean bFlag = operationBean.getBuyFlag();
       if (bFlag == true) { //购买卡保存
         operationBean.saveCardInfo();
         msg = "该用户购买智能卡成功!";
       }
       else { //开户保存
         CustomerModel modCustomerTmp = CustomerQryDAO
             .getCustomerByCustNo(strUsercode);
         if (modCustomerTmp != null && modCustomerTmp.getCust_no() != null) {
           request.setAttribute("errorMessage", "该客户编码已存在,不能保存!");
           forwardTarget = "failure";
         }
         else {
           operationBean.saveWholeInfo();
         }
       }
       //获取打印的内容和相关费用
       //发票格式: 费项名称 # 数量 # 单价 # 金额
       int n = 0;
       int iCardFeeCount = 0;
       ArrayList alFeeDetail = new ArrayList();
       BigDecimal bdValue = new BigDecimal("0");
       BigDecimal bdReceiptMoney = new BigDecimal("0");
       String strReceiptConent = "";
       if (alCard != null && alCard.size() > 0) {
         for (int i = 0; i < alCard.size(); i++) {
           CardRelationModel modCardRelation = (CardRelationModel) alCard.get(i);
           HashMap hmFee = modCardRelation.getFee();
           if (hmFee != null && !hmFee.isEmpty()) {
             FeeModel modFeeCard = (FeeModel) hmFee.get("cardFee"); //智能卡费用
             if (modFeeCard != null) {
               FeeListModel[] modsFeeList = modFeeCard.getModFeeList();
               if (modsFeeList != null
                   && modsFeeList.length > 0) {
                 for (int j = 0; j < modsFeeList.length; j++) {
                   alFeeDetail.add(modsFeeList[j]);
                   if (modsFeeList[j].getMoney()
                       .compareTo(new BigDecimal("0")) > 0) {
                     BigDecimal bdMoney = modsFeeList[j] .getMoney();
                     strPrintContent = strPrintContent
                         + "智能卡费用#1#"
                         + bdMoney.toString() + "#"
                         + bdMoney.toString() + "&&";
                     bdValue = bdValue.add(modsFeeList[j].getMoney());
                   }
                 }
               }
             }
             //机顶盒费用  zjp 2005-06-17
             FeeModel modFeeStb = (FeeModel) hmFee.get("stbFee"); //套餐费用
             if (modFeeStb != null) {
               FeeListModel[] modsStbFeeList = modFeeStb.getModFeeList();
               if (modsStbFeeList != null && modsStbFeeList.length > 0) {
                 for (int j = 0; j < modsStbFeeList.length; j++) {
                   BigDecimal bdMoney = modsStbFeeList[j].getMoney();
                   if (bdMoney.compareTo(new BigDecimal("0")) > 0) {
                     strPrintContent = strPrintContent +
                         modsStbFeeList[j].getFeename() + "#1#"
                         + bdMoney.toString() + "#"
                         + bdMoney.toString() + "&&";
                     bdValue = bdValue.add(bdMoney);
                   }
                 }
               }
             }
             //机顶盒费用  zjp 2005-06-17
             //预付款 2005-06-23  zjp
             FeeModel modFeePrePay = (FeeModel) hmFee.get("prePayFee"); //套餐费用
             if (modFeePrePay != null) {
               FeeListModel[] modsPrePayFeeList = modFeePrePay.getModFeeList();
               if (modsPrePayFeeList != null && modsPrePayFeeList.length > 0) {
                 for (int j = 0; j < modsPrePayFeeList.length; j++) {
                   BigDecimal bdMoney = modsPrePayFeeList[j].getMoney();
                   if (bdMoney.compareTo(new BigDecimal("0")) > 0) {
                     strPrintContent = strPrintContent +
                         modsPrePayFeeList[j].getFeename() + "#1#"
                         + bdMoney.toString() + "#"
                         + bdMoney.toString() + "&&";
                     bdValue = bdValue.add(bdMoney);
                     //帐务调整 处理预交费 zjp 2005-09-15
                     strReceiptConent = strReceiptConent
                         + "预存款#" + bdMoney + "&&";
                     bdReceiptMoney = bdReceiptMoney.add(bdMoney);
                   }
                 }
               }
             }
             //预付款 2005-06-23  zjp
             //套餐费用
             FeeModel modFeePack = (FeeModel) hmFee
                 .get("packFee"); //套餐费用
             if (modFeePack != null) {
               FeeListModel[] modsPackFeeList = modFeePack
                   .getModFeeList();
               if (modsPackFeeList != null&& modsPackFeeList.length > 0) {
                 for (int j = 0; j < modsPackFeeList.length; j++) {
                   BigDecimal bdMoney = modsPackFeeList[j].getMoney();
                   if (bdMoney.compareTo(new BigDecimal("0")) > 0) {
                     strPrintContent = strPrintContent
                         + modsPackFeeList[j].getFeename()+ "#1#"
                         + bdMoney.toString() + "#"
                         + bdMoney.toString() + "&&";
                     bdValue = bdValue.add(bdMoney);
                   }
                 }
               }
             }
           }
         }
       }
       //add by cjxian 05/05/17 for budgetplan
       String budgeSeq = (String) request.getParameter("budgeSeq");
       String firstPayMoney = bdValue.toString();
       if (budgeSeq != null && !budgeSeq.equals("") && bdValue != null
           && bdValue.doubleValue() > 0) {
         firstPayMoney = com.toptv.dms.components.account.budgetplan.dao.
             BudgetPlanDAO
             .writeACBudgetPlan(budgeSeq, bdValue.toString(),strUsercode, firstServid);
       }
       //发票打印设置
       if (bdValue != null && bdValue.doubleValue() > 0) {
         request.setAttribute("invoiceFlag", "1"); //打印收据
         request.setAttribute("content", strPrintContent); //打印内容
         if (firstPayMoney != "0") {
           request.setAttribute("money", firstPayMoney); //打印金额
         }else {
           request.setAttribute("money", bdValue.toString()); //打印金额
         }
       }
       request.setAttribute("receiptFlag", "1"); //打印收据
       modPrint = new DGPrintModel();
       modPrint.setCustomerName(modCustomer.getCust_name());
       modPrint.setCustomerNo(modCustomer.getCust_no());
       modPrint.setCert_no(modCustomer.getCert_no());
       modPrint.setCardno(cardno);
       modPrint.setCert_type(com.toptv.dms.components.carrymanage.basesetup.
                             basedata.dao.BaseDataDAO.getParaNameByCode("022",
                                        modCustomer.getCert_type()));
       //根据卡号取机顶盒信息
       ArrayList alBox = operationBean.getBoxList();
       StbModel modStb = new StbModel();
       if (alBox!=null && alBox.size() >=1){
          modStb = (StbModel)alBox.get(0);
       }
       String typeName = Format.getPKFieldName("t_mkstbtype","TYPENAME","TYPECODE",modStb.getStbtype());
       modPrint.setStb_brand(typeName);
       modPrint.setStb_no(modStb.getStbno());
       modPrint.setStb_type(modStb.getStbtype());
       String strApplyno = com.toptv.dms.components.carrymanage.basesetup.
           basedata.dao.BaseDataDAO.getProtocolId();
       modPrint.setApplyno(strApplyno);
       modPrint.setMoney(bdValue.toString());
       modPrint.setCaptitalMoney(ChangeFee.moneyUpper(bdValue
           .toString()));
       modPrint.setOperationCode(strOperatorName);
       SystemDate sysDate = new SystemDate();
       modPrint.setPrintDate(sysDate.getSysdate().toString());
       modPrint.setContent(strPrintContent);
       //modPrint.setFee_no("");
       com.toptv.dms.components.carrymanage.basesetup.
           basedata.dao.BaseDataDAO.setTransactApplyno(strApplyno, strUsercode);
       session.setAttribute("modReceiptPrint", modPrint);
       request.setAttribute("modApplyPrint", modPrint);
       session.setAttribute("modPrint", modPrint);
       session.setAttribute("modCustomer", modCustomer);
       if ( servId!=null ) {
          session.setAttribute("modProtocol",operationBean.getCard(servId));
       }else {
         session.removeAttribute("modProtocol");
       }
       session.removeAttribute("modPackList");
       session.removeAttribute("modProductList");
       session.removeAttribute("modLowstProtocol");//删除保底优惠协议


       //礼品卡保存
       String tradeCardPwd = request.getParameter("tradeCardPwd");
       if (tradeCardPwd != null && tradeCardPwd.trim().length() >= 1) {
          OperationCardDAO operationCardDao = new OperationCardDAO();
          operationCardDao.consumeTradecard(tradeCardPwd, bdValue.doubleValue(),
                                     strOperatorCode, usercode,firstServid);
       }
         if(!strerror.equals("")){
           request.setAttribute("errorMessage", strerror);
           forwardTarget = "failure";
           tx.rollback(); //事务会滚
     return (actionMapping.findForward(forwardTarget));
         }
       operationBean.reset();
       groupaddmodel.menuListAll=null;
       if (alCardno.size() > 0) {
         session.setAttribute("SESSION_CARDNO", cardno);
         session.setAttribute("SESSION_SERVID", servId);
       }
       session.setAttribute("SESSION_CUSTFLAG", custflag);
       session.setAttribute("SESSION_USERCODE", strUsercode);
       session.setAttribute("SESSION_STATUS", "1");
       //设置成功提示页
       session.removeAttribute("customerInfo2");
       request.setAttribute("msg", msg);
       tx.commit(); //事务提交
     } else {
       request.setAttribute("errorMessage", strErrorMsg);
       forwardTarget = "failure";
       tx.rollback();  //事务会滚
     }
   }catch (Exception ex) {
     ex.printStackTrace();
     try{
       tx.rollback();
     }catch(Exception e){
       System.out.println("事务回滚异常!"+e.getMessage());
     }
     request.setAttribute("errorMessage", ex.getMessage());
     forwardTarget = "failure";
   }finally {
     if (db != null) {
       db.closeDB();
     }
   }
   return (actionMapping.findForward(forwardTarget));
 }

}

Personal tools
工具
金银币拍卖 金币拍卖预展  金银币网店 熊猫金银币 生肖金银币