package com.topsun.posclient.sales.core.dao; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamWriter; import com.topsun.posclient.common.AppConstants; import com.topsun.posclient.common.LoggerUtil; import com.topsun.posclient.common.POSException; import com.topsun.posclient.common.ProjectUtil; import com.topsun.posclient.common.dao.BaseDao; import com.topsun.posclient.datamodel.Item; import com.topsun.posclient.datamodel.OldGold; import com.topsun.posclient.datamodel.Promotion; import com.topsun.posclient.datamodel.RetailFP; import com.topsun.posclient.datamodel.RetailM; import com.topsun.posclient.datamodel.RetailMP; import com.topsun.posclient.datamodel.RetailP; import com.topsun.posclient.datamodel.UnSalePart; import com.topsun.posclient.datamodel.dto.ItemDTO; import com.topsun.posclient.datamodel.dto.PromotionDTO; import com.topsun.posclient.datamodel.dto.RetailDTO; import com.topsun.posclient.sales.core.SalesCoreActivator; import com.topsun.posclient.webservice.POSServerCaller; import com.topsun.posclient.webservice.dto.ArrayOfretail_FPE; import com.topsun.posclient.webservice.dto.ArrayOfretail_M; import com.topsun.posclient.webservice.dto.ArrayOfretail_MP; import com.topsun.posclient.webservice.dto.ArrayOfretail_OldGold; import com.topsun.posclient.webservice.dto.ArrayOfretail_P; import com.topsun.posclient.webservice.dto.ArrayOfretail_UnSalePart; import com.topsun.posclient.webservice.dto.ProcessResult; import com.topsun.posclient.webservice.dto.Retail_FPE; import com.topsun.posclient.webservice.dto.Retail_M; import com.topsun.posclient.webservice.dto.Retail_MP; import com.topsun.posclient.webservice.dto.Retail_OldGold; import com.topsun.posclient.webservice.dto.Retail_P; import com.topsun.posclient.webservice.dto.Retail_UnSalePart; import com.topsun.posclient.webservice.dto.SavePartSales; import com.topsun.posclient.webservice.dto.SavePartSalesReq; import com.topsun.posclient.webservice.dto.SavePartSalesResponse; /** * @author Dong * */ public class PartSaleDao extends BaseDao { /** * 保存零售数据 * @param retailDto * @param isBack * @throws Exception * @throws POSException */ public void saveRetail(RetailDTO retailDto, String docNum) throws POSException { if(POSServerCaller.isConnected()){ try{ ProcessResult result = this.savePartSales(retailDto); if(result.getFlag().equals(POSServerCaller.SUCCESS)){ this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_PartSales", AppConstants.DATA_PARTSALES_HIS_PATH); this.updateDocNum(docNum); return; }else if(result.getFlag().equals(POSServerCaller.DOUBLEDOCNUM_ERROR)){ throw new POSException(result.getFlag(), "联机失败【"+result.getMsg()+"】"); }else{ throw new POSException(result.getFlag(), "联机失败【"+result.getMsg()+"】,零售数据已成功保存在本地"); } }catch(POSException e){ try { this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_PartSales", AppConstants.DATA_PARTSALES_PATH_BACK); this.updateDocNum(docNum); } catch (Exception e1) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "零售数据本地保存出错", e1); throw new POSException("零售数据本地保存出错"); } throw new POSException(e.getErrorCode(), e.getErrorMessage()); } catch (Exception e) { e.printStackTrace(); LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "零售数据本地保存出错", e); try { this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_PartSales", AppConstants.DATA_PARTSALES_PATH_BACK); this.updateDocNum(docNum); } catch (Exception e1) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "零售数据本地保存出错", e1); throw new POSException("零售数据本地保存出错"); } throw new POSException("联机失败,零售数据已成功保存在本地"); } }else{ try { this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_PartSales", AppConstants.DATA_PARTSALES_PATH); this.updateDocNum(docNum); } catch (Exception e) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "零售数据本地保存出错", e); throw new POSException("零售数据本地保存出错"); } throw new POSException("联机失败,零售数据已成功保存在本地"); } } /** * 保存零售退换货 * @param retailDto * @throws Exception */ public void saveRetailReturned(RetailDTO retailDto, String docNum) throws POSException { if(POSServerCaller.isConnected()){ try{ ProcessResult result = this.savePartSales(retailDto); if(result.getFlag().equals(POSServerCaller.SUCCESS)){ this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_returned", AppConstants.DATA_RETURNED_HIS_PATH); this.updateRDocNum(docNum); return; }else if(result.getFlag().equals(POSServerCaller.DOUBLEDOCNUM_ERROR)){ throw new POSException(result.getFlag(), "联机失败【"+result.getMsg()+"】"); }else{ throw new POSException("联机失败【"+result.getMsg()+"】,退换货数据已成功保存在本地"); } }catch(POSException e){ try { this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_returned", AppConstants.DATA_RETURNED_PATH_BACK); this.updateRDocNum(docNum); } catch (Exception e1) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "退换货数据本地保存出错", e1); throw new POSException("退换货数据本地保存出错"); } throw new POSException(e.getErrorCode(), e.getErrorMessage()); } catch (Exception e) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "退换货数据本地保存出错", e); try { this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_returned", AppConstants.DATA_RETURNED_PATH_BACK); this.updateRDocNum(docNum); } catch (Exception e1) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "退换货数据本地保存出错", e1); throw new POSException("退换货数据本地保存出错"); } throw new POSException("联机失败,退换货数据已成功保存在本地"); } }else{ try { this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_returned", AppConstants.DATA_RETURNED_PATH); this.updateRDocNum(docNum); } catch (Exception e) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "退换货数据本地保存出错", e); throw new POSException("退换货数据本地保存出错"); } throw new POSException("联机失败,退换货数据已成功保存在本地"); } } /** * 投资金条回购数据 * @param retailDto * @throws Exception */ public void saveRetailGoldBuyBack(RetailDTO retailDto, String docNum) throws POSException { if(POSServerCaller.isConnected()){ try{ ProcessResult result = this.savePartSales(retailDto); if(result.getFlag().equals(POSServerCaller.SUCCESS)){ this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_GoldBack", AppConstants.DATA_GOLDBACK_HIS_PATH); this.updateGDocNum(docNum); return; }else if(result.getFlag().equals(POSServerCaller.DOUBLEDOCNUM_ERROR)){ throw new POSException(result.getFlag(), "联机失败【"+result.getMsg()+"】"); }else{ throw new POSException("联机失败【"+result.getMsg()+"】,投资金条回购数据已成功保存在本地"); } }catch(POSException e){ try { this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_GoldBack", AppConstants.DATA_GOLDBACK_PATH_BACK); this.updateGDocNum(docNum); } catch (Exception e1) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "投资金条回购数据本地保存出错", e1); throw new POSException("投资金条回购数据本地保存出错"); } throw new POSException(e.getErrorCode(), e.getErrorMessage()); } catch (Exception e) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "投资金条回购数据本地保存出错", e); try { this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_GoldBack", AppConstants.DATA_GOLDBACK_PATH_BACK); this.updateGDocNum(docNum); } catch (Exception e1) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "投资金条回购数据本地保存出错", e1); throw new POSException("投资金条回购数据本地保存出错"); } throw new POSException("联机失败,投资金条回购数据已成功保存在本地"); } }else{ try { this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_GoldBack", AppConstants.DATA_GOLDBACK_PATH); this.updateGDocNum(docNum); } catch (Exception e) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "投资金条回购数据本地保存出错", e); throw new POSException("投资金条回购数据本地保存出错"); } throw new POSException("联机失败,投资金条回购数据已成功保存在本地"); } } /** * 保存投资金条预订数据 * @param retailDto * @throws Exception */ public void saveRetailGoldBooking(RetailDTO retailDto, String docNum) throws POSException { if(POSServerCaller.isConnected()){ try{ ProcessResult result = this.savePartSales(retailDto); if(result.getFlag().equals(POSServerCaller.SUCCESS)){ this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_GoldBooking", AppConstants.DATA_GOLDBOOKING_HIS_PATH); // this.updateBDocNum(docNum); return; }else if(result.getFlag().equals(POSServerCaller.DOUBLEDOCNUM_ERROR)){ throw new POSException(result.getFlag(), "联机失败【"+result.getMsg()+"】"); }else{ throw new POSException("联机失败【"+result.getMsg()+"】,投资金条预订数据已成功保存在本地"); } }catch(POSException e){ try { this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_GoldBooking", AppConstants.DATA_GOLDBOOKING_PATH_BACK); // this.updateBDocNum(docNum); } catch (Exception e1) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "投资金条预订数据本地保存出错", e1); throw new POSException("投资金条预订数据本地保存出错"); } throw new POSException(e.getErrorCode(), e.getErrorMessage()); } catch (Exception e) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "投资金条预订数据本地保存出错", e); try { this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_GoldBooking", AppConstants.DATA_GOLDBOOKING_PATH_BACK); // this.updateBDocNum(docNum); } catch (Exception e1) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "投资金条预订数据本地保存出错", e1); throw new POSException("投资金条预订数据本地保存出错"); } throw new POSException("联机失败,投资金条预订数据已成功保存在本地"); } }else{ try { this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_GoldBooking", AppConstants.DATA_GOLDBOOKING_PATH); // this.updateBDocNum(docNum); } catch (Exception e) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "投资金条回购数据本地保存出错", e); throw new POSException("投资金条预订数据本地保存出错"); } throw new POSException("联机失败,投资金条预订数据已成功保存在本地"); } } /** * 保存投资金条现货数据 * @param retailDto * @throws Exception */ public void saveRetailGoldNow(RetailDTO retailDto, String docNum) throws POSException { if(POSServerCaller.isConnected()){ try{ ProcessResult result = this.savePartSales(retailDto); if(result.getFlag().equals(POSServerCaller.SUCCESS)){ this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_GoldSales", AppConstants.DATA_GOLDSALES_HIS_PATH); this.updateBDocNum(docNum); return; }else if(result.getFlag().equals(POSServerCaller.DOUBLEDOCNUM_ERROR)){ throw new POSException(result.getFlag(), "联机失败【"+result.getMsg()+"】"); }else{ throw new POSException("联机失败【"+result.getMsg()+"】,投资金条现货数据已成功保存在本地"); } }catch(POSException e){ try { this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_GoldSales", AppConstants.DATA_GOLDSALES_PATH_BACK); this.updateBDocNum(docNum); } catch (Exception e1) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "投资金条现货数据本地保存出错", e1); throw new POSException("投资金条现货数据本地保存出错"); } throw new POSException(e.getErrorCode(), e.getErrorMessage()); } catch (Exception e) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "投资金条现货数据本地保存出错", e); try { this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_GoldSales", AppConstants.DATA_GOLDSALES_PATH_BACK); this.updateBDocNum(docNum); } catch (Exception e1) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "投资金条现货数据本地保存出错", e1); throw new POSException("投资金条现货数据本地保存出错"); } throw new POSException("联机失败,投资金条现货数据已成功保存在本地"); } }else{ try { this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_GoldSales", AppConstants.DATA_GOLDSALES_PATH); this.updateBDocNum(docNum); } catch (Exception e) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "投资金条现货数据本地保存出错", e); throw new POSException("投资金条现货数据本地保存出错"); } throw new POSException("联机失败,投资金条现货数据已成功保存在本地"); } } /** * 保存投资金条到期 * @param retailDto * @throws Exception */ public void saveRetailGoldTimeOut(RetailDTO retailDto, String docNum) throws POSException { if(POSServerCaller.isConnected()){ try{ ProcessResult result = this.savePartSales(retailDto); if(result.getFlag().equals(POSServerCaller.SUCCESS)){ this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_GoldTimeOut", AppConstants.DATA_GOLDTIMEOUT_HIS_PATH); this.updateBDocNum(docNum); return; }else if(result.getFlag().equals(POSServerCaller.DOUBLEDOCNUM_ERROR)){ throw new POSException(result.getFlag(), "联机失败【"+result.getMsg()+"】"); }else{ throw new POSException("联机失败【"+result.getMsg()+"】,投资金条预订数据已成功保存在本地"); } }catch(POSException e){ try { this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_GoldTimeOut", AppConstants.DATA_GOLDTIMEOUT_PATH_BACK); this.updateBDocNum(docNum); } catch (Exception e1) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "投资金条到期数据本地保存出错", e1); throw new POSException("投资金条到期数据本地保存出错"); } throw new POSException(e.getErrorCode(), e.getErrorMessage()); } catch (Exception e) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "投资金条到期数据本地保存出错", e); try { this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_GoldTimeOut", AppConstants.DATA_GOLDTIMEOUT_PATH_BACK); this.updateBDocNum(docNum); } catch (Exception e1) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "投资金条到期数据本地保存出错", e1); throw new POSException("投资金条到期数据本地保存出错"); } throw new POSException("联机失败,投资金条到期数据已成功保存在本地"); } }else{ try { this.getLocalProcessor().createXmlFileFromObject(retailDto, "data_GoldTimeOut", AppConstants.DATA_GOLDTIMEOUT_PATH); this.updateBDocNum(docNum); } catch (Exception e) { LoggerUtil.logError(SalesCoreActivator.PLUGIN_ID, "投资金条到期数据本地保存出错", e); throw new POSException("投资金条到期数据本地保存出错"); } throw new POSException("联机失败,投资金条到期数据已成功保存在本地"); } } /** * 获取有效时间促销方案 * @return * @throws POSException */ public PromotionDTO getValidTimePromotion() throws Exception{ String fullPath = ProjectUtil.getRuntimeClassPath()+AppConstants.DATA_PROMOTE_FILENAME; File file = new File(fullPath); String localData = this.getLocalProcessor().getDataFileContent(file); PromotionDTO promotionDTO = (PromotionDTO)this.getLocalProcessor().getObjectFromXml(localData, PromotionDTO.class); if(null == promotionDTO || null == promotionDTO.getPromotionList() || promotionDTO.getPromotionList().size() == 0){ return promotionDTO; } List<Promotion> prmis = new ArrayList<Promotion>(); List<Promotion> promotions = promotionDTO.getPromotionList(); for(Promotion prmi : promotions){ //时间判断,当前时间是否在促销时间范围内 if(validatePrmi(prmi)){ prmis.add(prmi); } } promotionDTO.setPromotionList(prmis); return promotionDTO; } /** * 保存零售数据 * @param retailDTO * @return * @throws Exception * @throws */ private ProcessResult savePartSales(RetailDTO retailDTO) throws Exception{ List<com.topsun.posclient.datamodel.Retail> retailList = retailDTO.getRetailList(); com.topsun.posclient.webservice.dto.Retail[] retails = new com.topsun.posclient.webservice.dto.Retail[retailList.size()]; for(int i=0; i<retailList.size(); i++){ com.topsun.posclient.webservice.dto.Retail retail = new com.topsun.posclient.webservice.dto.Retail(); com.topsun.posclient.datamodel.Retail rm = retailList.get(i); retail.setAccountData(ProjectUtil.getCalendar(rm.getAccountData())); retail.setDocNum(rm.getDocNum()); retail.setSalesType(rm.getSalesType()); retail.setTotalSales(rm.getTotalSales()); retail.setDiscountAccount(rm.getDiscountAccount()); retail.setDiscountAmount(rm.getDiscountAmount()); retail.setDiscountAmount_M(rm.getDiscountAmount_M()); retail.setDiscountRate(rm.getDiscountRate()); retail.setDiscountToZero(rm.getDiscountToZero()); retail.setDiscount(rm.getDiscount()); retail.setInvoceAmount(rm.getInvoceAmount()); retail.setIsMember(rm.getIsMember()); retail.setMemberDiscount(rm.getMemberDiscount()); retail.setShopID(rm.getShopID()); retail.setCardNo(rm.getCardNo()); retail.setCashierID(rm.getCashierID()); retail.setEnablePoint(rm.getEnablePoint()); retail.setUsePoint(rm.getUsePoint()); retail.setSalesDate(ProjectUtil.getCalendar(rm.getSalesDate())); retail.setReceivable(rm.getReceivable()); retail.setTotals(rm.getTotals()); retail.setIsReturn(rm.getIsReturn()); retail.setIsReplace(rm.getIsReplace()); retail.setMemo("Memo"); retail.setSourceNum(rm.getSourceNum()); retail.setOldDocNum(rm.getOldDocNum()); this.setRetailDetail(rm, retail); retails[i] = retail; } com.topsun.posclient.webservice.dto.ArrayOfRetail arrayOfRetail = new com.topsun.posclient.webservice.dto.ArrayOfRetail(); arrayOfRetail.setRetail(retails); SavePartSalesReq req = new SavePartSalesReq(); req.setUserCredential(POSServerCaller.getDefaultUserCredential()); req.setRetails(arrayOfRetail); SavePartSales savePartSales48 = new SavePartSales(); savePartSales48.setSavePartSalesReq(req); // XMLOutputFactory xof = XMLOutputFactory.newInstance(); // OutputStream os = new FileOutputStream(new File("D:/req.xml")); // XMLStreamWriter xmlWriter = xof.createXMLStreamWriter(os); // savePartSales48.serialize(new javax.xml.namespace.QName( // "http://www.topsunit.com/rms", // "savePartSalesReq", // "ns1"), xmlWriter); SavePartSalesResponse response = POSServerCaller.getWebService().savePartSales(savePartSales48); ProcessResult result = response.getSavePartSalesResult().getResult(); return result; } public void setRetailDetail(com.topsun.posclient.datamodel.Retail retail, com.topsun.posclient.webservice.dto.Retail wsRetail){ ArrayOfretail_M retail_Ms = new ArrayOfretail_M(); List<RetailM> rms = retail.getRetailMList(); Retail_M[] rmArry = new Retail_M[rms.size()]; for(int x=0; x<rms.size(); x++){ RetailM retailM = rms.get(x); Retail_M rmm = new Retail_M(); rmm.setAccountType(retailM.getAccountType()); rmm.setEmployeeID(retailM.getEmployeeID()); rmm.setFactAmount(retailM.getFactAmount()); rmm.setInvoceCode(retailM.getInvoiceCode()); rmm.setInvoiceAmount(retailM.getInvoiceAmount()); rmm.setIsReplace(retailM.getIsReplace()); rmm.setItemCode(retailM.getItemCode()); rmm.setItemID(retailM.getItemId()); rmm.setItemType(retailM.getItemType()); rmm.setMATNR(retailM.getMATNR()); rmm.setOldAmount(retailM.getOldAmount()); rmm.setPalAmount(retailM.getPalAmount()); rmm.setPalWeight(retailM.getPalWeight()); rmm.setPayAmount(retailM.getPayAmount()); rmm.setPointAmount(retailM.getPointAmount()); rmm.setPrice_G(retailM.getPrice_G()); rmm.setProcessFee(retailM.getProcessFee()); rmm.setProcessFee_S(retailM.getProcessFee_S()); rmm.setPromotionID(retailM.getPromotionID()); rmm.setPromotionName(retailM.getPromotionName()); rmm.setReplaceAmount(retailM.getReplaceAmount()); rmm.setSalesAmount(retailM.getSalesAmount()); rmm.setSalesWeight(retailM.getSalesWeight()); rmm.setSourceCode(retailM.getSourceCode()); rmm.setUnSalesWeight(retailM.getUnSalesWeight()); rmm.setWeight(retailM.getWeight()); rmm.setMatkl(retailM.getMatkl()); rmm.setLineNum(0); rmm.setMatkl(retailM.getMatkl()); rmm.setSettlementPrice_G(retailM.getSettlementPrice_G()); rmm.setSettlementPrice(retailM.getSettlementPrice()); rmArry[x] = rmm; } retail_Ms.setRetail_M(rmArry); ArrayOfretail_P retail_Ps = new ArrayOfretail_P(); List<RetailP> rps = retail.getRetailPList(); //设置零售结算方式明细 if(null != rps && rps.size() > 0){ Retail_P[] rpArry = new Retail_P[rps.size()]; for(int y=0; y<rps.size(); y++){ RetailP retailP = rps.get(y); Retail_P rmp = new Retail_P(); rmp.setPayModeID(retailP.getPayModeID()); rmp.setPoundage(retailP.getPoundage()); rmp.setPoundageRate(retailP.getPoundageRate()); rmp.setSum(retailP.getSum()); rmp.setBankcardno(retailP.getCardNo()); rpArry[y] = rmp; } retail_Ps.setRetail_P(rpArry); } ArrayOfretail_MP retail_MPs = new ArrayOfretail_MP(); List<RetailMP> rmps = retail.getRetailMPList(); //设置零售明细 if(null != rmps && rmps.size() > 0){ Retail_MP[] rmpArry = new Retail_MP[rmps.size()]; for(int z=0; z<rmps.size(); z++){ RetailMP retailMP = rmps.get(z); if(null != retailMP){ Retail_MP rmmp = new Retail_MP(); rmmp.setIsPrint(retailMP.getIsPrint()); rmmp.setItemCode(retailMP.getItemCode()); rmmp.setItemID(retailMP.getItemID()); rmmp.setPayModeID(retailMP.getPayModeID()); rmmp.setPoundage(retailMP.getPoundage()); rmmp.setPoundageRate(retailMP.getPoundageRate()); rmmp.setSum(retailMP.getSum()); rmmp.setBankcardno(retailMP.getCardNo()); rmpArry[z] = rmmp; } } retail_MPs.setRetail_MP(rmpArry); } //设置旧金数据明细 ArrayOfretail_OldGold retail_OldGolds = new ArrayOfretail_OldGold(); List<OldGold> oGolds = retail.getOldGoldList(); if(null != oGolds && oGolds.size() >0){ Retail_OldGold[] oldGoldArry = new Retail_OldGold[oGolds.size()]; for(int m=0; m<oGolds.size(); m++){ OldGold oldGold = oGolds.get(m); Retail_OldGold retail_OldGold = new Retail_OldGold(); retail_OldGold.setIdfCode(oldGold.getIdfCode()); oldGoldArry[m] = retail_OldGold; } retail_OldGolds.setRetail_OldGold(oldGoldArry); } //设置断料数据 ArrayOfretail_UnSalePart aoup = new ArrayOfretail_UnSalePart(); List<UnSalePart> unSalePartList = retail.getUnSalePartList(); if(null != unSalePartList && unSalePartList.size() >0){ Retail_UnSalePart[] unSalePartArray = new Retail_UnSalePart[unSalePartList.size()]; for(int n=0; n<unSalePartList.size(); n++){ UnSalePart up = unSalePartList.get(n); Retail_UnSalePart retail_UnSalePart = new Retail_UnSalePart(); retail_UnSalePart.setIdfCode(up.getIdfCode()); retail_UnSalePart.setItemCode(up.getItemCode()); retail_UnSalePart.setPalAccount(up.getPalAccount()); retail_UnSalePart.setPalAmount(up.getPalAmount()); retail_UnSalePart.setPalWeight(up.getPalWeight()); retail_UnSalePart.setPrice_A(up.getPrice_A()); retail_UnSalePart.setPrice_G(up.getPrice_G()); retail_UnSalePart.setSourceCode(up.getSourceCode()); retail_UnSalePart.setWeight(up.getWeight()); retail_UnSalePart.setWeight_F(up.getWeight_F()); unSalePartArray[n] = retail_UnSalePart; } aoup.setRetail_UnSalePart(unSalePartArray); } //设置发票数据 ArrayOfretail_FPE aofpe = new ArrayOfretail_FPE(); List<RetailFP> retailFPs = retail.getRetailFPList(); if(null != retailFPs && retailFPs.size() >0){ Retail_FPE[] retail_FPEArray = new Retail_FPE[retailFPs.size()]; for(int n=0; n<retailFPs.size(); n++){ RetailFP up = retailFPs.get(n); Retail_FPE retail_FPE = new Retail_FPE(); retail_FPE.setFPDM(up.getFPDM()); retail_FPE.setFPH(up.getFPH()); retail_FPE.setFPMSID((null != up.getFPMSID() && !"".equals(up.getFPMSID()))?Integer.valueOf(up.getFPMSID()):0); retail_FPE.setInvoiceAmount(ProjectUtil.formatString(up.getInvoiceAmount())); retail_FPE.setItemCode(up.getItemCode()); retail_FPE.setItemID(Integer.valueOf(up.getItemID())); retail_FPE.setKPRID(up.getKPRID()); retail_FPE.setOldFPH(up.getOldFPH()); retail_FPE.setPOS(up.getPOS()); retail_FPE.setShopID(Integer.valueOf((null == up.getShopID()?"0":up.getShopID()))); retail_FPE.setType(up.getType()); retail_FPE.setUsedDate(ProjectUtil.getCalendar(ProjectUtil.getDate(up.getUsedDate()))); retail_FPEArray[n] = retail_FPE; } aofpe.setRetail_FP(retail_FPEArray); } wsRetail.setRetail_MPs(retail_MPs); wsRetail.setRetail_Ms(retail_Ms); wsRetail.setRetail_OldGolds(retail_OldGolds); wsRetail.setRetail_Ps(retail_Ps); wsRetail.setRetail_UnSaleParts(aoup); wsRetail.setRetail_FPs(aofpe); } /** * 校验促销方式有效时间 * @param promotion 促销方案 * @return */ private boolean validatePrmi(Promotion promotion){ if(ProjectUtil.compareCurrentDate(promotion.getStartDate(), promotion.getEndDate())){ if(validateWeek(promotion)){ int sHour = Integer.valueOf(promotion.getStartTime().split(":")[0]); int eHour = Integer.valueOf(promotion.getEndTime().split(":")[0]); return ProjectUtil.compareCurrentHour(sHour, eHour); }else{ return false; } }else{ return false; } } /** * 删除本地单品数据 * @param retailMs 零售明细集合 * @throws Exception */ public void deleteItems(List<Item> items) throws Exception { for(Item item : items){ //旧金和服务费不需要删除本地单品数据 if(item.getItemType().equals(AppConstants.ITEM_TYPE_SERVICEFEE)){ continue; } if(item.getItemType().equals(AppConstants.ITEM_TYPE_OLDGOLD)){ continue; } //删除本地零售数据 File indexFile = getIndexItemDataFile(item.getId()); if(null == indexFile){ return; } ItemDTO indexDTO = (ItemDTO)this.getLocalProcessor().getObjectFromXml(this.getLocalProcessor().getDataFileContent(indexFile), ItemDTO.class); List<Item> indexItemList = indexDTO.getItemList(); for(Item indexItem : indexItemList){ if(indexItem.getId() == item.getId()){ indexItemList.remove(indexItem); } } indexDTO.setItemList(indexItemList); this.getLocalProcessor().deleteDataFile(indexFile.getAbsolutePath()); this.getLocalProcessor().createXmlFileFromObject(indexDTO, indexFile.getAbsolutePath()); } } /** * 获取单品数据索引文件 * @param itemId * @return */ private File getIndexItemDataFile(int itemId){ //单据数据文件夹 File folder = new File(ProjectUtil.getRuntimeClassPath()+AppConstants.DATA_ITEM_PATH); File[] dataFiles = folder.listFiles(); for(File file : dataFiles){ String fileName = file.getName(); int index = Integer.valueOf(fileName.substring(fileName.indexOf("#"), fileName.indexOf(".xml"))); if(index > itemId && index < (itemId+10000)){ return file; }else{ return null; } } return null; } /** * 周校验 * @param promotion * @return */ private boolean validateWeek(Promotion promotion){ Calendar calendar = Calendar.getInstance(); Date currDate = new Date(); calendar.setTime(currDate); int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); switch(dayOfWeek-1){ case 0: return promotion.getSun() == 1?true:false; case 1: return promotion.getMon() == 1?true:false; case 2: return promotion.getTur() == 1?true:false; case 3: return promotion.getWen() == 1?true:false; case 4: return promotion.getThu() == 1?true:false; case 5: return promotion.getFri() == 1?true:false; case 6: return promotion.getSat() == 1?true:false; default: return false; } } }