소스 검색

票加加开票

huangct 8 년 전
부모
커밋
aa597eec21

+ 142 - 0
src/main/java/com/uas/platform/b2b/controller/PiaoPlusNoticeController.java

@@ -0,0 +1,142 @@
+package com.uas.platform.b2b.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import com.uas.platform.b2b.model.PurchaseApBillOut;
+import com.uas.platform.b2b.service.PurchaseApBillOutService;
+import com.uas.platform.b2b.service.PurchaseApCheckService;
+import org.apache.commons.io.IOUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+
+/**
+ * 票加加开票数据回传接口
+ *
+ * @author huangct
+ * @time 创建时间:2018年03月07日
+ */
+
+@SuppressWarnings("deprecation")
+@Controller
+@RequestMapping("/public/apBillOut")
+public class PiaoPlusNoticeController {
+
+	@Autowired
+	PurchaseApCheckService purchaseApCheckService;
+
+	@Autowired
+	private PurchaseApBillOutService purchaseApBillOutService;
+
+	/**
+	 * 电子发票开票成功通知
+	 * @param data
+	 * @return
+	 */
+	@RequestMapping(value = "/electricBillSuccessNotice", method = RequestMethod.POST)
+	@ResponseBody
+	public ModelMap electricBillSuccessNotice(@RequestParam("data") String data){
+		JSONObject noticeData = JSONObject.parseObject(data);
+		String taxpayerId = noticeData.getString("taxpayerId");
+		String billRequestNum = noticeData.getString("billRequestNum");
+		String orderNo = noticeData.getString("orderNo");
+		String reIssue = noticeData.getString("reIssue");//是否允许重开 0允许,1不允许
+		String code = noticeData.getString("code");
+		String resMsg = noticeData.getString("resMsg");
+
+
+		return null;
+	}
+
+	/**
+	 * 电子开票失败通知
+	 * @param data
+	 * @return
+	 */
+	@RequestMapping(value = "/electricBillFailNotice", method = RequestMethod.POST)
+	@ResponseBody
+	public ModelMap electricBillFailNotice(@RequestParam("data") String data){
+		JSONObject noticeData = JSONObject.parseObject(data);
+		String taxpayerId = noticeData.getString("taxpayerId");
+		String billRequestNum = noticeData.getString("billRequestNum");
+		String orderNo = noticeData.getString("orderNo");
+		String reIssue = noticeData.getString("reIssue");//是否允许重开 0允许,1不允许
+
+		//电子发票只有这俩个
+		String code = noticeData.getString("code");
+		String resMsg = noticeData.getString("resMsg");
+
+		return null;
+	}
+
+	/**
+	 * 纸质发票开票成功通知
+	 * @param request
+	 * @return
+	 */
+	@RequestMapping(value = "/paperBillSuccessNotice", method = RequestMethod.POST)
+	@ResponseBody
+	public JSONObject billSuccessNotice(HttpServletRequest request) throws IOException {
+		String data = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());
+		JSONObject jsonObject = new JSONObject();
+		JSONObject noticeData = JSONObject.parseObject(data);
+		String taxpayerId = noticeData.getString("taxpayerId");
+		String fpdm = noticeData.getString("fpdm");//发票代码
+		String fphm = noticeData.getString("fphm");//发票号码
+		String billRequestNum = noticeData.getString("billRequestNum");//请求流水号
+		String orderNo = noticeData.getString("orderNo");
+		String reIssue = noticeData.getString("reIssue");//是否允许重开 0允许,1不允许
+		String code = noticeData.getString("code");//0000 成功
+		String resMsg = noticeData.getString("resMsg");
+
+		PurchaseApBillOut apBillOut = purchaseApBillOutService.findByCode(orderNo);
+
+		apBillOut.setNsrsbh(taxpayerId);
+		apBillOut.setInfoTypeCode(fpdm);
+		apBillOut.setInfoNumber(fphm);
+		apBillOut.setRequestCode(billRequestNum);
+		apBillOut.setReissue(reIssue);
+		apBillOut.setRetmsg(resMsg);
+
+		//修改开票单状态
+		apBillOut.setCheckStatus("已开票");
+
+		purchaseApBillOutService.save(apBillOut);
+
+		jsonObject.put("code", "0000");
+		jsonObject.put("resMsg", "开票成功!");
+
+		return jsonObject;
+	}
+
+	/**
+	 * 纸质开票失败通知
+	 * @param data
+	 * @return
+	 */
+	@RequestMapping(value = "/paperBillFailNotice", method = RequestMethod.POST)
+	@ResponseBody
+	public ModelMap billFailNotice(@RequestParam("data") String data){
+		JSONObject noticeData = JSONObject.parseObject(data);
+		String taxpayerId = noticeData.getString("taxpayerId");
+		String billRequestNum = noticeData.getString("billRequestNum");
+		String totalMoney = noticeData.getString("totalMoney");//税金合计
+		String fplx = noticeData.getString("fplx");//发票类型  1表示蓝票,2表示红票
+		String fpdm = noticeData.getString("fpdm");//发票代码  开票结果为成功时必填
+		String fphm = noticeData.getString("fphm");//发票号码  开票结果为成功时必填
+		String yfpdm = noticeData.getString("yfpdm");//原发票代码  开票类型为红票时必填
+		String yfphm = noticeData.getString("yfphm");//原发票号码  开票类型为红票时必填
+		String sysOrderNo = noticeData.getString("sysOrderNo");//BPM申请单编号  当前开票请求由BPM发起时回填,否则该字段为空。
+
+		String code = noticeData.getString("code");
+		String resMsg = noticeData.getString("resMsg");
+
+		return null;
+	}
+}

+ 4 - 1
src/main/java/com/uas/platform/b2b/controller/SaleApBillOutController.java

@@ -86,6 +86,9 @@ public class SaleApBillOutController {
 	@Autowired
 	private SOAPConsoleService sOAPConsoleService;
 
+	@Autowired
+	private PiaoPlusService piaoPlusService;
+
 	private final static UsageBufferedLogger logger = BufferedLoggerManager.getLogger(UsageBufferedLogger.class);
 
 	/**
@@ -94,7 +97,7 @@ public class SaleApBillOutController {
 	 * @param id
 	 * @return
 	 */
-	//hct 此方法只是更新了打印次数  目前处于弃用状态
+	// 此方法只是更新了打印次数  目前处于弃用状态
 	@RequestMapping(value = "/printCount/{id}", method = RequestMethod.POST)
 	@ResponseBody
 	public ResponseEntity<String> printCount(@PathVariable("id") Long id) {

+ 1 - 1
src/main/java/com/uas/platform/b2b/dao/PurchaseApBillOutDao.java

@@ -3,7 +3,6 @@ package com.uas.platform.b2b.dao;
 import com.uas.platform.b2b.model.PurchaseApBillOut;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
-import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.jpa.repository.query.Procedure;
 import org.springframework.stereotype.Repository;
 
@@ -15,4 +14,5 @@ public interface PurchaseApBillOutDao extends JpaSpecificationExecutor<PurchaseA
     @Procedure(procedureName = "TAXCODE_INSERT")
     public void  saveData(String a,String b,String c,String d,String e,String f,String g,String h,String i,String j,String k,String l,String m,String n,String o,String p,String q,String s);
 
+    public List<PurchaseApBillOut> findByEnUuAndCode(long enUU, String bi_code);
 }

+ 53 - 0
src/main/java/com/uas/platform/b2b/erp/controller/BillOutController.java

@@ -0,0 +1,53 @@
+package com.uas.platform.b2b.erp.controller;
+
+import com.uas.platform.b2b.erp.model.BillOut;
+import com.uas.platform.b2b.erp.service.impl.BillOutService;
+import com.uas.platform.b2b.erp.support.ErpBufferedLogger;
+import com.uas.platform.b2b.service.PurchaseApBillOutService;
+import com.uas.platform.core.logging.BufferedLoggerManager;
+import com.uas.platform.core.util.serializer.FlexJsonUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.List;
+
+/**
+ * 应收开票数据接口
+ *
+ * @author huangct
+ * 
+ */
+@Controller
+@RequestMapping("/erp/purchase/BillOut")
+public class BillOutController {
+
+	@Autowired
+	private PurchaseApBillOutService purchaseApBillOutService;
+	
+	@Autowired
+	private BillOutService billOutService;
+
+	private final static ErpBufferedLogger logger = BufferedLoggerManager.getLogger(ErpBufferedLogger.class);
+
+	/**
+	 * 将ERP的应收开票写到平台
+	 * 
+	 * @param data
+	 * @return
+	 * @throws UnsupportedEncodingException
+	 */
+	@RequestMapping(method = RequestMethod.POST)
+	@ResponseBody
+	public void saveApBills(@RequestParam("data") String data) throws UnsupportedEncodingException {
+		String jsonStr = URLDecoder.decode(data, "UTF-8");
+		List<BillOut> billOuts = FlexJsonUtils.fromJsonArray(jsonStr, BillOut.class);
+		purchaseApBillOutService.saveByItem(billOutService.convertBillOuts(billOuts));
+		logger.log("应收开票单", "上传应收开票单", billOuts.size());
+	}
+}

+ 489 - 0
src/main/java/com/uas/platform/b2b/erp/model/BillOut.java

@@ -0,0 +1,489 @@
+package com.uas.platform.b2b.erp.model;
+
+import com.uas.platform.b2b.model.Product;
+import com.uas.platform.b2b.model.PurchaseApBillOut;
+import com.uas.platform.b2b.model.PurchaseApBillOutInfo;
+import com.uas.platform.b2b.model.PurchaseApBillOutItem;
+import com.uas.platform.b2b.support.SystemSession;
+import org.springframework.util.CollectionUtils;
+
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * ERP应收开票主表数据
+ * @author huangct
+ * @date 2018年2月08日10:14:24
+ *
+ */
+public class BillOut {
+    private String bi_id;
+    private String bi_code;
+    private Date bi_date;
+    private String bi_custcode;
+    private String bi_custname;
+    private String bi_sellercode;
+    private String bi_seller;
+    private Double bi_amount;
+    private String bi_recorder;
+    private Date bi_indate;
+    private String bi_status;
+    private String bi_remark;
+    private String bi_cop;
+    private String bi_currency;
+    private Double bi_rate;
+    private String bi_vouchercode;
+    private String bi_costvouchercode;
+    private String bi_departmentcode;
+    private String bi_department;
+    private String bi_refno;
+    private String bi_salekind;
+    private Double bi_taxdiffer;
+    private Double bi_taxamount;
+    private String bi_salemethod;
+    private String bi_discountamount;
+    private String bi_discount;
+    private String bi_catecode;
+    private String bi_catename;
+    private String bi_setkind;
+    private String bi_sendkind;
+    private String bi_tradecode;
+    private String bi_tradename;
+    private String bi_pricekind;
+    private String bi_pidepartmentcode;
+    private String bi_pidepartmentname;
+    private String bi_statuscode;
+    private Date bi_auditdate;
+    private String bi_auditer;
+    private String bi_paymentscode;
+    private String bi_paymentsmethod;
+    private Double bi_payamount;
+    private Date bi_postdate;
+    private String bi_postman;
+    private String bi_thispayamount;
+    private Date bi_paydate;
+    private List<BillOutDetail> details;
+    private Long bi_custuu;
+
+    public String getBi_id() {
+        return bi_id;
+    }
+
+    public void setBi_id(String bi_id) {
+        this.bi_id = bi_id;
+    }
+
+    public String getBi_code() {
+        return bi_code;
+    }
+
+    public void setBi_code(String bi_code) {
+        this.bi_code = bi_code;
+    }
+
+    public Date getBi_date() {
+        return bi_date;
+    }
+
+    public void setBi_date(Date bi_date) {
+        this.bi_date = bi_date;
+    }
+
+    public String getBi_custcode() {
+        return bi_custcode;
+    }
+
+    public void setBi_custcode(String bi_custcode) {
+        this.bi_custcode = bi_custcode;
+    }
+
+    public String getBi_custname() {
+        return bi_custname;
+    }
+
+    public void setBi_custname(String bi_custname) {
+        this.bi_custname = bi_custname;
+    }
+
+    public String getBi_sellercode() {
+        return bi_sellercode;
+    }
+
+    public void setBi_sellercode(String bi_sellercode) {
+        this.bi_sellercode = bi_sellercode;
+    }
+
+    public String getBi_seller() {
+        return bi_seller;
+    }
+
+    public void setBi_seller(String bi_seller) {
+        this.bi_seller = bi_seller;
+    }
+
+    public Double getBi_amount() {
+        return bi_amount;
+    }
+
+    public void setBi_amount(Double bi_amount) {
+        this.bi_amount = bi_amount;
+    }
+
+    public String getBi_recorder() {
+        return bi_recorder;
+    }
+
+    public void setBi_recorder(String bi_recorder) {
+        this.bi_recorder = bi_recorder;
+    }
+
+    public Date getBi_indate() {
+        return bi_indate;
+    }
+
+    public void setBi_indate(Date bi_indate) {
+        this.bi_indate = bi_indate;
+    }
+
+    public String getBi_status() {
+        return bi_status;
+    }
+
+    public void setBi_status(String bi_status) {
+        this.bi_status = bi_status;
+    }
+
+    public String getBi_remark() {
+        return bi_remark;
+    }
+
+    public void setBi_remark(String bi_remark) {
+        this.bi_remark = bi_remark;
+    }
+
+    public String getBi_cop() {
+        return bi_cop;
+    }
+
+    public void setBi_cop(String bi_cop) {
+        this.bi_cop = bi_cop;
+    }
+
+    public String getBi_currency() {
+        return bi_currency;
+    }
+
+    public void setBi_currency(String bi_currency) {
+        this.bi_currency = bi_currency;
+    }
+
+    public Double getBi_rate() {
+        return bi_rate;
+    }
+
+    public void setBi_rate(Double bi_rate) {
+        this.bi_rate = bi_rate;
+    }
+
+    public String getBi_vouchercode() {
+        return bi_vouchercode;
+    }
+
+    public void setBi_vouchercode(String bi_vouchercode) {
+        this.bi_vouchercode = bi_vouchercode;
+    }
+
+    public String getBi_costvouchercode() {
+        return bi_costvouchercode;
+    }
+
+    public void setBi_costvouchercode(String bi_costvouchercode) {
+        this.bi_costvouchercode = bi_costvouchercode;
+    }
+
+    public String getBi_departmentcode() {
+        return bi_departmentcode;
+    }
+
+    public void setBi_departmentcode(String bi_departmentcode) {
+        this.bi_departmentcode = bi_departmentcode;
+    }
+
+    public String getBi_department() {
+        return bi_department;
+    }
+
+    public void setBi_department(String bi_department) {
+        this.bi_department = bi_department;
+    }
+
+    public String getBi_refno() {
+        return bi_refno;
+    }
+
+    public void setBi_refno(String bi_refno) {
+        this.bi_refno = bi_refno;
+    }
+
+    public String getBi_salekind() {
+        return bi_salekind;
+    }
+
+    public void setBi_salekind(String bi_salekind) {
+        this.bi_salekind = bi_salekind;
+    }
+
+    public Double getBi_taxdiffer() {
+        return bi_taxdiffer;
+    }
+
+    public void setBi_taxdiffer(Double bi_taxdiffer) {
+        this.bi_taxdiffer = bi_taxdiffer;
+    }
+
+    public Double getBi_taxamount() {
+        return bi_taxamount;
+    }
+
+    public void setBi_taxamount(Double bi_taxamount) {
+        this.bi_taxamount = bi_taxamount;
+    }
+
+    public String getBi_salemethod() {
+        return bi_salemethod;
+    }
+
+    public void setBi_salemethod(String bi_salemethod) {
+        this.bi_salemethod = bi_salemethod;
+    }
+
+    public String getBi_discountamount() {
+        return bi_discountamount;
+    }
+
+    public void setBi_discountamount(String bi_discountamount) {
+        this.bi_discountamount = bi_discountamount;
+    }
+
+    public String getBi_discount() {
+        return bi_discount;
+    }
+
+    public void setBi_discount(String bi_discount) {
+        this.bi_discount = bi_discount;
+    }
+
+    public String getBi_catecode() {
+        return bi_catecode;
+    }
+
+    public void setBi_catecode(String bi_catecode) {
+        this.bi_catecode = bi_catecode;
+    }
+
+    public String getBi_catename() {
+        return bi_catename;
+    }
+
+    public void setBi_catename(String bi_catename) {
+        this.bi_catename = bi_catename;
+    }
+
+    public String getBi_setkind() {
+        return bi_setkind;
+    }
+
+    public void setBi_setkind(String bi_setkind) {
+        this.bi_setkind = bi_setkind;
+    }
+
+    public String getBi_sendkind() {
+        return bi_sendkind;
+    }
+
+    public void setBi_sendkind(String bi_sendkind) {
+        this.bi_sendkind = bi_sendkind;
+    }
+
+    public String getBi_tradecode() {
+        return bi_tradecode;
+    }
+
+    public void setBi_tradecode(String bi_tradecode) {
+        this.bi_tradecode = bi_tradecode;
+    }
+
+    public String getBi_tradename() {
+        return bi_tradename;
+    }
+
+    public void setBi_tradename(String bi_tradename) {
+        this.bi_tradename = bi_tradename;
+    }
+
+    public String getBi_pricekind() {
+        return bi_pricekind;
+    }
+
+    public void setBi_pricekind(String bi_pricekind) {
+        this.bi_pricekind = bi_pricekind;
+    }
+
+    public String getBi_pidepartmentcode() {
+        return bi_pidepartmentcode;
+    }
+
+    public void setBi_pidepartmentcode(String bi_pidepartmentcode) {
+        this.bi_pidepartmentcode = bi_pidepartmentcode;
+    }
+
+    public String getBi_pidepartmentname() {
+        return bi_pidepartmentname;
+    }
+
+    public void setBi_pidepartmentname(String bi_pidepartmentname) {
+        this.bi_pidepartmentname = bi_pidepartmentname;
+    }
+
+    public String getBi_statuscode() {
+        return bi_statuscode;
+    }
+
+    public void setBi_statuscode(String bi_statuscode) {
+        this.bi_statuscode = bi_statuscode;
+    }
+
+    public Date getBi_auditdate() {
+        return bi_auditdate;
+    }
+
+    public void setBi_auditdate(Date bi_auditdate) {
+        this.bi_auditdate = bi_auditdate;
+    }
+
+    public String getBi_auditer() {
+        return bi_auditer;
+    }
+
+    public void setBi_auditer(String bi_auditer) {
+        this.bi_auditer = bi_auditer;
+    }
+
+    public String getBi_paymentscode() {
+        return bi_paymentscode;
+    }
+
+    public void setBi_paymentscode(String bi_paymentscode) {
+        this.bi_paymentscode = bi_paymentscode;
+    }
+
+    public String getBi_paymentsmethod() {
+        return bi_paymentsmethod;
+    }
+
+    public void setBi_paymentsmethod(String bi_paymentsmethod) {
+        this.bi_paymentsmethod = bi_paymentsmethod;
+    }
+
+    public Double getBi_payamount() {
+        return bi_payamount;
+    }
+
+    public void setBi_payamount(Double bi_payamount) {
+        this.bi_payamount = bi_payamount;
+    }
+
+    public Date getBi_postdate() {
+        return bi_postdate;
+    }
+
+    public void setBi_postdate(Date bi_postdate) {
+        this.bi_postdate = bi_postdate;
+    }
+
+    public String getBi_postman() {
+        return bi_postman;
+    }
+
+    public void setBi_postman(String bi_postman) {
+        this.bi_postman = bi_postman;
+    }
+
+    public String getBi_thispayamount() {
+        return bi_thispayamount;
+    }
+
+    public void setBi_thispayamount(String bi_thispayamount) {
+        this.bi_thispayamount = bi_thispayamount;
+    }
+
+    public Date getBi_paydate() {
+        return bi_paydate;
+    }
+
+    public void setBi_paydate(Date bi_paydate) {
+        this.bi_paydate = bi_paydate;
+    }
+
+    public List<BillOutDetail> getDetails() {
+        return details;
+    }
+
+    public void setDetails(List<BillOutDetail> details) {
+        this.details = details;
+    }
+
+    public Long getBi_custuu() {
+        return bi_custuu;
+    }
+
+    public void setBi_custuu(Long bi_custuu) {
+        this.bi_custuu = bi_custuu;
+    }
+
+    public PurchaseApBillOut convert(PurchaseApBillOutInfo customerApBillOutInfo, PurchaseApBillOutInfo apBillOutInfo, List<Product> products) {
+        PurchaseApBillOut purchaseApBillOut = new PurchaseApBillOut();
+        purchaseApBillOut.setTaxSum(this.bi_taxamount);
+        purchaseApBillOut.setDiffer(this.bi_taxdiffer);
+        purchaseApBillOut.setRecordDate(this.bi_indate);
+        purchaseApBillOut.setRecorder(this.bi_recorder);
+        purchaseApBillOut.setCheckStatus("未开票");//未开票 已开票 已作废
+        purchaseApBillOut.setRemark(this.bi_remark);
+        purchaseApBillOut.setAuditDate(this.bi_auditdate);
+        //purchaseApBillOut.setResDate(null);//作废日期
+        //purchaseApBillOut.setResMan(null);//作废人
+        //purchaseApBillOut.setStatus(null);//状态 short
+        purchaseApBillOut.setAmount(this.bi_amount);
+        purchaseApBillOut.setPayAmount(this.bi_payamount);
+        purchaseApBillOut.setCurrency(this.bi_currency);
+        purchaseApBillOut.setRate(this.bi_rate);
+        //客户企业开票信息
+        purchaseApBillOut.setCustUu(this.bi_custuu);
+        if (customerApBillOutInfo != null) {
+            purchaseApBillOut.setCustomerApBillOutInfo(customerApBillOutInfo);
+        }
+        purchaseApBillOut.setCustName(this.bi_custname);
+        //当前企业开票信息
+        purchaseApBillOut.setEnUu(SystemSession.getUser().getEnterprise().getUu());
+        if (apBillOutInfo != null) {
+            purchaseApBillOut.setApBillOutInfo(apBillOutInfo);
+        }
+        purchaseApBillOut.setCode(this.bi_code);
+        //purchaseApBillOut.setPrint(null);//打印次数
+
+        if (!CollectionUtils.isEmpty(this.details)) {
+            Set<PurchaseApBillOutItem> purchaseApBillOutItems = new HashSet<PurchaseApBillOutItem>();
+            for (BillOutDetail billOutDetail : this.details) {
+                for (Product product : products) {
+                    if (SystemSession.getUser().getEnterprise().getUu().equals(product.getEnUU()) && billOutDetail.getArd_prodcode().equals(product.getCode())) {
+                        purchaseApBillOutItems.add(billOutDetail.convert(product));
+                    }
+                }
+            }
+            purchaseApBillOut.setItems(purchaseApBillOutItems);
+        }
+        return purchaseApBillOut;
+    }
+}

+ 353 - 0
src/main/java/com/uas/platform/b2b/erp/model/BillOutDetail.java

@@ -0,0 +1,353 @@
+package com.uas.platform.b2b.erp.model;
+
+import com.uas.platform.b2b.model.Product;
+import com.uas.platform.b2b.model.PurchaseApBillOutItem;
+
+/**
+ * ERP应收开票从表数据
+ * @author huangct
+ * @date 2018年2月08日10:24:24
+ *
+ */
+public class BillOutDetail {
+    private String ard_id;
+    private String ard_biid;
+    private Short ard_detno;
+    private String ard_code;
+    private String ard_ordercode;
+    private Double ard_orderamount;
+    private String ard_aramount;
+    private String ard_havepay;
+    private Double ard_nowbalance;
+    private String ard_remark;
+    private String ard_description;
+    private String ard_emcode;
+    private String ard_catecode;
+    private String ard_diffamount;
+    private Long ard_orderdetno;
+    private String ard_prodcode;
+    private Double ard_nowqty;
+    private Double ard_qty;
+    private Double ard_price;
+    private Double ard_costprice;
+    private Double ard_taxrate;
+    private Double ard_nowprice;
+    private String ard_taxamount;
+    private String ard_discount;
+    private String ard_discountamount;
+    private String ard_status;
+    private String ard_statuscode;
+    private String ard_billprice;
+    private String ard_arprice;
+    private String ard_discountnetamount;
+    private String ard_discounttaxamount;
+    private Long ard_orderid;
+    private String ard_poststatus;
+    private String ard_adid;
+    private String ard_tempamount;
+
+    public String getArd_id() {
+        return ard_id;
+    }
+
+    public void setArd_id(String ard_id) {
+        this.ard_id = ard_id;
+    }
+
+    public String getArd_biid() {
+        return ard_biid;
+    }
+
+    public void setArd_biid(String ard_biid) {
+        this.ard_biid = ard_biid;
+    }
+
+    public Short getArd_detno() {
+        return ard_detno;
+    }
+
+    public void setArd_detno(Short ard_detno) {
+        this.ard_detno = ard_detno;
+    }
+
+    public String getArd_code() {
+        return ard_code;
+    }
+
+    public void setArd_code(String ard_code) {
+        this.ard_code = ard_code;
+    }
+
+    public String getArd_ordercode() {
+        return ard_ordercode;
+    }
+
+    public void setArd_ordercode(String ard_ordercode) {
+        this.ard_ordercode = ard_ordercode;
+    }
+
+    public Double getArd_orderamount() {
+        return ard_orderamount;
+    }
+
+    public void setArd_orderamount(Double ard_orderamount) {
+        this.ard_orderamount = ard_orderamount;
+    }
+
+    public String getArd_aramount() {
+        return ard_aramount;
+    }
+
+    public void setArd_aramount(String ard_aramount) {
+        this.ard_aramount = ard_aramount;
+    }
+
+    public String getArd_havepay() {
+        return ard_havepay;
+    }
+
+    public void setArd_havepay(String ard_havepay) {
+        this.ard_havepay = ard_havepay;
+    }
+
+    public Double getArd_nowbalance() {
+        return ard_nowbalance;
+    }
+
+    public void setArd_nowbalance(Double ard_nowbalance) {
+        this.ard_nowbalance = ard_nowbalance;
+    }
+
+    public String getArd_remark() {
+        return ard_remark;
+    }
+
+    public void setArd_remark(String ard_remark) {
+        this.ard_remark = ard_remark;
+    }
+
+    public String getArd_description() {
+        return ard_description;
+    }
+
+    public void setArd_description(String ard_description) {
+        this.ard_description = ard_description;
+    }
+
+    public String getArd_emcode() {
+        return ard_emcode;
+    }
+
+    public void setArd_emcode(String ard_emcode) {
+        this.ard_emcode = ard_emcode;
+    }
+
+    public String getArd_catecode() {
+        return ard_catecode;
+    }
+
+    public void setArd_catecode(String ard_catecode) {
+        this.ard_catecode = ard_catecode;
+    }
+
+    public String getArd_diffamount() {
+        return ard_diffamount;
+    }
+
+    public void setArd_diffamount(String ard_diffamount) {
+        this.ard_diffamount = ard_diffamount;
+    }
+
+    public Long getArd_orderdetno() {
+        return ard_orderdetno;
+    }
+
+    public void setArd_orderdetno(Long ard_orderdetno) {
+        this.ard_orderdetno = ard_orderdetno;
+    }
+
+    public String getArd_prodcode() {
+        return ard_prodcode;
+    }
+
+    public void setArd_prodcode(String ard_prodcode) {
+        this.ard_prodcode = ard_prodcode;
+    }
+
+    public Double getArd_nowqty() {
+        return ard_nowqty;
+    }
+
+    public void setArd_nowqty(Double ard_nowqty) {
+        this.ard_nowqty = ard_nowqty;
+    }
+
+    public Double getArd_qty() {
+        return ard_qty;
+    }
+
+    public void setArd_qty(Double ard_qty) {
+        this.ard_qty = ard_qty;
+    }
+
+    public Double getArd_price() {
+        return ard_price;
+    }
+
+    public void setArd_price(Double ard_price) {
+        this.ard_price = ard_price;
+    }
+
+    public Double getArd_costprice() {
+        return ard_costprice;
+    }
+
+    public void setArd_costprice(Double ard_costprice) {
+        this.ard_costprice = ard_costprice;
+    }
+
+    public Double getArd_taxrate() {
+        return ard_taxrate;
+    }
+
+    public void setArd_taxrate(Double ard_taxrate) {
+        this.ard_taxrate = ard_taxrate;
+    }
+
+    public Double getArd_nowprice() {
+        return ard_nowprice;
+    }
+
+    public void setArd_nowprice(Double ard_nowprice) {
+        this.ard_nowprice = ard_nowprice;
+    }
+
+    public String getArd_taxamount() {
+        return ard_taxamount;
+    }
+
+    public void setArd_taxamount(String ard_taxamount) {
+        this.ard_taxamount = ard_taxamount;
+    }
+
+    public String getArd_discount() {
+        return ard_discount;
+    }
+
+    public void setArd_discount(String ard_discount) {
+        this.ard_discount = ard_discount;
+    }
+
+    public String getArd_discountamount() {
+        return ard_discountamount;
+    }
+
+    public void setArd_discountamount(String ard_discountamount) {
+        this.ard_discountamount = ard_discountamount;
+    }
+
+    public String getArd_status() {
+        return ard_status;
+    }
+
+    public void setArd_status(String ard_status) {
+        this.ard_status = ard_status;
+    }
+
+    public String getArd_statuscode() {
+        return ard_statuscode;
+    }
+
+    public void setArd_statuscode(String ard_statuscode) {
+        this.ard_statuscode = ard_statuscode;
+    }
+
+    public String getArd_billprice() {
+        return ard_billprice;
+    }
+
+    public void setArd_billprice(String ard_billprice) {
+        this.ard_billprice = ard_billprice;
+    }
+
+    public String getArd_arprice() {
+        return ard_arprice;
+    }
+
+    public void setArd_arprice(String ard_arprice) {
+        this.ard_arprice = ard_arprice;
+    }
+
+    public String getArd_discountnetamount() {
+        return ard_discountnetamount;
+    }
+
+    public void setArd_discountnetamount(String ard_discountnetamount) {
+        this.ard_discountnetamount = ard_discountnetamount;
+    }
+
+    public String getArd_discounttaxamount() {
+        return ard_discounttaxamount;
+    }
+
+    public void setArd_discounttaxamount(String ard_discounttaxamount) {
+        this.ard_discounttaxamount = ard_discounttaxamount;
+    }
+
+    public Long getArd_orderid() {
+        return ard_orderid;
+    }
+
+    public void setArd_orderid(Long ard_orderid) {
+        this.ard_orderid = ard_orderid;
+    }
+
+    public String getArd_poststatus() {
+        return ard_poststatus;
+    }
+
+    public void setArd_poststatus(String ard_poststatus) {
+        this.ard_poststatus = ard_poststatus;
+    }
+
+    public String getArd_adid() {
+        return ard_adid;
+    }
+
+    public void setArd_adid(String ard_adid) {
+        this.ard_adid = ard_adid;
+    }
+
+    public String getArd_tempamount() {
+        return ard_tempamount;
+    }
+
+    public void setArd_tempamount(String ard_tempamount) {
+        this.ard_tempamount = ard_tempamount;
+    }
+
+    public PurchaseApBillOutItem convert(Product product) {
+        PurchaseApBillOutItem purchaseApBillOutItem = new PurchaseApBillOutItem();
+        purchaseApBillOutItem.setNumber(this.ard_detno);
+        //purchaseApBillOutItem.setStatus(null);//状态?
+        //purchaseApBillOutItem.setStatusCode(null);//状态码?
+        purchaseApBillOutItem.setNowPrice(this.ard_nowprice);//开票单价
+        //ard_nowbalance  开票金额
+        //ard_orderamount  发票金额
+        purchaseApBillOutItem.setCostPrice(this.ard_costprice);
+        purchaseApBillOutItem.setPrice(this.ard_price);//发票单价
+        purchaseApBillOutItem.setTaxrate(this.ard_taxrate);
+        purchaseApBillOutItem.setQty(this.ard_qty);
+        purchaseApBillOutItem.setNowQty(this.ard_nowqty);
+        purchaseApBillOutItem.setProduct(product);
+        purchaseApBillOutItem.setPrid(product.getId());
+        purchaseApBillOutItem.setProdCode(this.ard_prodcode);
+        purchaseApBillOutItem.setOrderCode(this.ard_ordercode);//发票单号  客户订单单号  ??
+        purchaseApBillOutItem.setOrderDetno(this.ard_orderdetno);
+        purchaseApBillOutItem.setCode(this.ard_code);
+        purchaseApBillOutItem.setOrderId(this.ard_orderid);//发票id  ??
+        //purchaseApBillOutItem.setOldQty(); //已开票数量 ??
+
+        return purchaseApBillOutItem;
+    }
+}

+ 17 - 0
src/main/java/com/uas/platform/b2b/erp/service/impl/BillOutService.java

@@ -0,0 +1,17 @@
+package com.uas.platform.b2b.erp.service.impl;
+
+import com.uas.platform.b2b.erp.model.BillOut;
+import com.uas.platform.b2b.model.PurchaseApBillOutItem;
+
+import java.util.List;
+
+public interface BillOutService {
+
+	/**
+	 * 将ERP系统的应收开票单,转为平台的应收开票单
+	 * 
+	 * @param billOuts
+	 * @return
+	 */
+	List<PurchaseApBillOutItem> convertBillOuts(List<BillOut> billOuts);
+}

+ 81 - 0
src/main/java/com/uas/platform/b2b/erp/service/impl/BillOutServiceImpl.java

@@ -0,0 +1,81 @@
+package com.uas.platform.b2b.erp.service.impl;
+
+import com.uas.platform.b2b.dao.ProductDao;
+import com.uas.platform.b2b.dao.PurchaseApBillOutDao;
+import com.uas.platform.b2b.dao.PurchaseApBillOutInfoDao;
+import com.uas.platform.b2b.erp.model.BillOut;
+import com.uas.platform.b2b.erp.model.BillOutDetail;
+import com.uas.platform.b2b.model.Product;
+import com.uas.platform.b2b.model.PurchaseApBillOut;
+import com.uas.platform.b2b.model.PurchaseApBillOutInfo;
+import com.uas.platform.b2b.model.PurchaseApBillOutItem;
+import com.uas.platform.b2b.support.SystemSession;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+@Service
+public class BillOutServiceImpl implements BillOutService {
+
+	@Autowired
+	private PurchaseApBillOutDao purchaseApBillOutDao;
+
+	@Autowired
+	private ProductDao productDao;
+
+	@Autowired
+	private PurchaseApBillOutInfoDao purchaseApBillOutInfoDao;
+
+
+	@Override
+	public List<PurchaseApBillOutItem> convertBillOuts(List<BillOut> billOuts) {
+		List<PurchaseApBillOutItem> apBillItems = new ArrayList<PurchaseApBillOutItem>();
+		long enUU = SystemSession.getUser().getEnterprise().getUu();
+		for (BillOut billOut : billOuts) {
+			List<PurchaseApBillOut> billOuts2 = purchaseApBillOutDao.findByEnUuAndCode(enUU, billOut.getBi_code());
+			//Enterprise vendor = enterpriseDao.findEnterpriseByUu(billOut.getAb_vendoruu());
+			if (billOuts2.size() == 0) {
+				Long custuu = billOut.getBi_custuu();
+				PurchaseApBillOutInfo customerApBillOutInfo = null;
+				PurchaseApBillOutInfo apBillOutInfo = purchaseApBillOutInfoDao.findByUu(enUU);
+				if (custuu != null) {
+					customerApBillOutInfo = purchaseApBillOutInfoDao.findByUu(custuu);
+				}
+
+				//获取物料
+				List<BillOutDetail> billOutDetails = billOut.getDetails();
+				List<Product> billOutProducts = new ArrayList<>();
+				if (!CollectionUtils.isEmpty(billOutDetails)) {
+					for (BillOutDetail billOutDetail : billOutDetails) {
+						List<Product> products = productDao.findByEnUUAndCode(enUU, billOutDetail.getArd_prodcode());
+						if (!CollectionUtils.isEmpty(products)) {
+							billOutProducts.add(products.get(0));
+						}
+					}
+				}
+
+
+				PurchaseApBillOut purchaseApBillOut = billOut.convert(customerApBillOutInfo, apBillOutInfo, billOutProducts);
+				Iterator<PurchaseApBillOutItem> items = purchaseApBillOut.getItems().iterator();
+				while (items.hasNext()) {
+					PurchaseApBillOutItem purchaseApBillOutItem = items.next();
+					List<Product> products = productDao.findByEnUUAndCode(enUU, purchaseApBillOutItem.getProduct().getCode());
+					if (products.size() > 0) {
+						purchaseApBillOutItem.setProduct(products.get(0));
+						purchaseApBillOutItem.setPrid(products.get(0).getId());
+						purchaseApBillOutItem.setApBillOut(purchaseApBillOut);
+						//TODO purchaseApBillOutItem.setErpDate(new Date());
+						apBillItems.add(purchaseApBillOutItem);
+					} else {
+						items.remove();
+					}
+				}
+			}
+		}
+		return apBillItems;
+	}
+}

+ 32 - 0
src/main/java/com/uas/platform/b2b/model/PurchaseApBillOut.java

@@ -250,6 +250,22 @@ public class PurchaseApBillOut implements Serializable {
 	@Column(name = "pabo_kpdh")
 	private String kpdh;
 
+	//票加加字段
+
+	/**
+	 * 请求流水号
+	 * @return
+	 */
+	@Column(name = "request_code")
+	private String requestCode;
+
+	/**
+	 * 是否允许重开  0允许,1不允许
+	 * @return
+	 */
+	@Column(name = "reissue")
+	private String reissue;
+
 	public Long getId() {
 		return id;
 	}
@@ -537,4 +553,20 @@ public class PurchaseApBillOut implements Serializable {
 	public void setKpdh(String kpdh) {
 		this.kpdh = kpdh;
 	}
+
+	public String getRequestCode() {
+		return requestCode;
+	}
+
+	public void setRequestCode(String requestCode) {
+		this.requestCode = requestCode;
+	}
+
+	public String getReissue() {
+		return reissue;
+	}
+
+	public void setReissue(String reissue) {
+		this.reissue = reissue;
+	}
 }

+ 2 - 2
src/main/java/com/uas/platform/b2b/model/PurchaseApBillOutItem.java

@@ -50,7 +50,7 @@ public class PurchaseApBillOutItem implements Serializable {
 	private Integer statusCode;
 
 	/**
-	 * 开票单价  //已用作明细开票金额
+	 * 开票单价
 	 */
 	@Column(name = "pai_nowprice")
 	private Double nowPrice;
@@ -62,7 +62,7 @@ public class PurchaseApBillOutItem implements Serializable {
 	private Double costPrice;
 
 	/**
-	 * 发票单价  //已用作产品单价
+	 * 发票单价
 	 */
 	@Column(name = "pai_price")
 	private Double price;

+ 73 - 0
src/main/java/com/uas/platform/b2b/service/PiaoPlusService.java

@@ -0,0 +1,73 @@
+package com.uas.platform.b2b.service;
+
+import com.uas.platform.b2b.model.PurchaseApBillOut;
+import org.springframework.ui.ModelMap;
+
+/**
+ * Created by 黄诚天 on 2018/02/25.
+ *
+ * 票加加服务接口
+ */
+public interface PiaoPlusService {
+
+    /**
+     * 发票开具
+     *
+     * @param apBillOut
+     * @return
+     */
+    public ModelMap invoiceIssued(PurchaseApBillOut apBillOut);
+
+    /**
+     * 发票作废  冲红
+     *
+     * @param apBillOut
+     * @return
+     */
+    public ModelMap InvoiceCancel(PurchaseApBillOut apBillOut);
+
+    /**
+     * 查询发票信息
+     *
+     * @param apBillOut
+     * @return
+     */
+    public ModelMap queryInvoiceMessage(PurchaseApBillOut apBillOut);
+
+    /**
+     * 开票统计
+     *
+     * @param queryDate 指定的统计月份。格式YYYYMM
+     * @return
+     */
+    public ModelMap querybillingcount(String queryDate);
+
+    /**
+     * 余票查询 查询金税盘剩余发票
+     * @return
+     */
+    public ModelMap queryBillLeftCount();
+
+    /**
+     * 发票打印  专票和普通,可以通过该接口打印纸质发票。目前仅支持百望税盘
+     * @param apBillOut
+     * @return
+     */
+    public ModelMap printInvoice (PurchaseApBillOut apBillOut);
+
+    /**
+     * 快递单信息获取接口
+     * 外部系统,在开票成功后,可通过订单编号和税号,来获取某个订单的快递单号
+     * @param apBillOut
+     * @return
+     */
+    public ModelMap queryDelivery(PurchaseApBillOut apBillOut);
+
+    /**
+     * 上传接口
+     * 用于在票加加产品纸质发票功能中,导入申请单时规范导入文件的格式与内容
+     * @param apBillOut
+     * @return
+     */
+    public ModelMap uploadInvoice(PurchaseApBillOut apBillOut);
+}

+ 15 - 0
src/main/java/com/uas/platform/b2b/service/PurchaseApBillOutService.java

@@ -148,4 +148,19 @@ public interface PurchaseApBillOutService {
 	 * @return
 	 */
 	public ModelMap invoiceCancel(PurchaseApBillOut apBillOut);
+
+	/**
+	 * 保存开票明细
+	 **/
+	public void saveByItem(List<PurchaseApBillOutItem> apBillOutItems);
+
+	/**
+	 * 保存票加加返回的开票信息
+	 */
+	public void save(PurchaseApBillOut purchaseApBillOut);
+
+	/**
+	 * 根据单号获取开票信息
+	 **/
+	public PurchaseApBillOut findByCode(String orderNo);
 }

+ 958 - 0
src/main/java/com/uas/platform/b2b/service/impl/PiaoPlusServiceImpl.java

@@ -0,0 +1,958 @@
+package com.uas.platform.b2b.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.uas.platform.b2b.dao.PurchaseApBillOutDao;
+import com.uas.platform.b2b.dao.PurchaseApBillOutInfoDao;
+import com.uas.platform.b2b.model.Product;
+import com.uas.platform.b2b.model.PurchaseApBillOut;
+import com.uas.platform.b2b.model.PurchaseApBillOutInfo;
+import com.uas.platform.b2b.model.PurchaseApBillOutItem;
+import com.uas.platform.b2b.service.PiaoPlusService;
+import com.uas.platform.b2b.support.SystemSession;
+import com.uas.platform.core.util.HttpUtil;
+import com.uas.ps.core.util.StringUtils;
+import com.uas.sso.common.encrypt.MD5;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.ui.ModelMap;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.text.DecimalFormat;
+import java.util.*;
+
+@Service
+public class PiaoPlusServiceImpl implements PiaoPlusService{
+    @Autowired
+    PurchaseApBillOutDao purchaseApBillOutDao;
+
+    @Autowired
+    PurchaseApBillOutInfoDao purchaseApBillOutInfoDao;
+
+    DecimalFormat df = new DecimalFormat("#.00");
+    private boolean isBaiWang = true;
+
+    @Override
+    public ModelMap invoiceIssued(PurchaseApBillOut apBillOut) {
+        ModelMap result = new ModelMap();
+        StringBuilder errorMsg = new StringBuilder();
+
+        String url = "http://192.168.253.75:8282/icloud/invoice/issue.json";
+        String invoiceKind = "004";//004:专票,007:普票, 026:电子票.百望税盘必填
+        String eqptType = "1";//设备类型 0税控服务,1税控盘.百望税盘必填
+        String collectorPhone = "18770087064";
+        String drawer = SystemSession.getUser().getUserName();
+        String taxDiskCode = "";
+        String taxDiskPwd = "";
+        String taxSignPwd = "";
+
+        Set<PurchaseApBillOutItem> apBillOutItems = apBillOut.getItems();
+        //获取购方开票信息
+        PurchaseApBillOutInfo customerApBillOutInfo = apBillOut.getCustomerApBillOutInfo();
+        if (customerApBillOutInfo == null) {
+            result.put("error", errorMsg.append("获取不到购方开票信息,请先完善!"));
+            return result;
+        }
+        //获取销方开票信息
+        PurchaseApBillOutInfo apBillOutInfo = apBillOut.getApBillOutInfo();
+        if (apBillOutInfo == null) {
+            result.put("error", errorMsg.append("获取不到销方开票信息,请先完善!"));
+            return result;
+        }
+
+        //签名部分
+        List<String> paras = new ArrayList<>();
+        paras.add("buyerName=" + apBillOut.getCustName());
+        paras.add("collectorPhone=" + collectorPhone);//TODO 收票人手机
+        paras.add("drawer=" + drawer);//开票人
+        paras.add("orderNo=" + apBillOut.getCode());
+        //专票时以下参数参与签名
+        if ("004".equals(invoiceKind)) {
+            paras.add("buyerTaxpayerId=" + customerApBillOutInfo.getTaxNr());
+            paras.add("buyerAddr=" + customerApBillOutInfo.getAddress());
+            paras.add("buyerMobile=" + customerApBillOutInfo.getTel());
+            paras.add("buyerAccountNo=" + customerApBillOutInfo.getBankAccountNr());
+        }
+        paras.add("taxpayerId=" + apBillOutInfo.getTaxNr());
+        //百望税盘时以下参数参与 //TODO 判断
+        if (isBaiWang && "1".equals(eqptType)) {
+            paras.add("issueAddressCode=" + apBillOut.getKpdh());//TODO 开票点代码
+            paras.add("eqptType=" + eqptType);
+            paras.add("invoiceKind=" + invoiceKind);//TODO 发票种类编码
+            //百望税盘且设备类型eqptType为1参与
+            paras.add("taxDiskCode=" + taxDiskCode);//T税控盘编号
+            paras.add("taxDiskPwd=" + taxDiskPwd);//税控盘口令
+            paras.add("taxSignPwd=" + taxSignPwd);//税务数字证书密码
+        }
+        String[] paraArr = new String[paras.size()];
+        String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
+        String sign = sign("icloud/invoice/issue.json", "POST", timestamp, paras.toArray(paraArr));
+
+        Map<String,Object> paraMap = new HashMap<>();
+        if (StringUtils.isEmpty(apBillOutInfo.getTaxNr())) {
+            result.put("error", errorMsg.append("获取不到纳税人识别号!"));
+        }
+        if (StringUtils.isEmpty(apBillOut.getCustName())) {
+            result.put("error", errorMsg.append("获取不到购买方名称!"));
+        }
+        if (StringUtils.isEmpty(collectorPhone)) {
+            result.put("error", errorMsg.append("获取不到收票人手机!"));
+        }
+        if (StringUtils.isEmpty(drawer)) {
+            result.put("error", errorMsg.append("获取不到开票人名称!"));
+        }
+        if (StringUtils.isEmpty(apBillOut.getCode())) {
+            result.put("error", errorMsg.append("获取不到订单号!"));
+        }
+        paraMap.put("taxpayerId", apBillOutInfo.getTaxNr());//纳税人识别号
+        paraMap.put("buyerName", apBillOut.getCustName());//购买方名称
+        paraMap.put("collectorPhone", collectorPhone);//TODO 收票人手机
+        paraMap.put("drawer", SystemSession.getUser().getUserName());//开票人
+        paraMap.put("orderNo", apBillOut.getCode());//订单号
+        //以下为可为空字段
+        paraMap.put("saleAccountNo", customerApBillOutInfo.getBankAccountNr());//销售方银行账号
+        paraMap.put("buyerTaxpayerId", customerApBillOutInfo.getTaxNr());//购买方识别号
+        paraMap.put("buyerAddr", customerApBillOutInfo.getAddress());//购买方地址
+        paraMap.put("buyerMobile", customerApBillOutInfo.getTel());//购买方电话
+        paraMap.put("buyerAccountNo", customerApBillOutInfo.getBankAccountNr());//购买方银行及账号  开户行及账号
+        paraMap.put("storeCode", "");//店铺编码
+        paraMap.put("buyerEmail", "");//购买方邮箱
+        paraMap.put("payee", customerApBillOutInfo.getPayee());//收款人
+        paraMap.put("checker", customerApBillOutInfo.getChecker());//复核人
+        paraMap.put("priceTaxAmount", apBillOut.getTaxSum());//价税合计金额   小数点后2位,以元为单位精确到分
+        if (isBaiWang && StringUtils.isEmpty(apBillOut.getKpdh())) {
+            result.put("error", errorMsg.append("获取不到百望税盘时的开票点代码!"));
+        }
+        if (isBaiWang && StringUtils.isEmpty(eqptType)) {
+            result.put("error", errorMsg.append("获取不到百望税盘时的设备的类型!"));
+        }
+        if (isBaiWang && StringUtils.isEmpty(invoiceKind)) {
+            result.put("error", errorMsg.append("获取不到百望税盘时的开票的类型!"));
+        }
+        if (isBaiWang && "1".equals(eqptType) && StringUtils.isEmpty(taxDiskCode)) {
+            result.put("error", errorMsg.append("获取不到百望税盘时的税控盘编号!"));
+        }
+        if (isBaiWang && "1".equals(eqptType) && StringUtils.isEmpty(taxDiskPwd)) {
+            result.put("error", errorMsg.append("获取不到百望税盘时的税控盘口令!"));
+        }
+        if (isBaiWang && "1".equals(eqptType) && StringUtils.isEmpty(taxSignPwd)) {
+            result.put("error", errorMsg.append("获取不到百望税盘时的税务数字证书密码!"));
+        }
+        if (result.size() > 0) {
+            return result;
+        }
+        paraMap.put("issueAddressCode", apBillOut.getKpdh());//开票点代码  百望税盘必填
+        paraMap.put("eqptType", eqptType);//设备类型 0税控服务,1税控盘.百望税盘必填
+        paraMap.put("invoiceKind", invoiceKind);//004:专票,007:普票,026:电子票.百望税盘必填
+        paraMap.put("taxDiskCode", taxDiskCode);//税控盘编号  百望税盘且设备类型为1必填
+        paraMap.put("taxDiskPwd", taxDiskPwd);//税控盘口令  百望税盘且设备类型为1必填
+        paraMap.put("taxSignPwd", taxSignPwd);//税务数字证书密码  百望税盘且设备类型为1必填
+        paraMap.put("remark", apBillOut.getRemark());
+
+        JSONArray wares = new JSONArray();
+        for (PurchaseApBillOutItem apBillOutItem : apBillOutItems) {
+            // wares  商品行项目信息(发票明细)
+            JSONObject ware = new JSONObject(16, true);
+            Product product = apBillOutItem.getProduct();
+            if (product == null) {
+                result.put("error", errorMsg.append("获取不到商品信息!"));
+                return result;
+            }
+            if (StringUtils.isEmpty(product.getTitle())) {
+                result.put("error", errorMsg.append("获取不到商品名称!"));
+            }
+            if (StringUtils.isEmpty(apBillOutItem.getNowQty())) {
+                result.put("error", errorMsg.append("获取不到商品开票数量!"));
+            }
+            if (StringUtils.isEmpty(apBillOutItem.getNowPrice())) {
+                result.put("error", errorMsg.append("获取不到商品开票单价!"));
+            }
+            if (StringUtils.isEmpty(product.getGoodstaxno())) {
+                result.put("error", errorMsg.append("获取不到商品编码!"));
+            }
+            if (StringUtils.isEmpty(apBillOutItem.getTaxrate())) {
+                result.put("error", errorMsg.append("获取不到商品税率!"));
+            }
+            ware.put("wareName", product.getTitle());//商品名称
+            ware.put("count", apBillOutItem.getNowQty());//数量 整数
+            ware.put("unitPrice", apBillOutItem.getNowPrice());//单价 小数点后2位,以元为单位精确到分,含税价
+            ware.put("wareNo", product.getGoodstaxno());//商品编码  应与税局最新发行的商品和服务税收分类与编码相一致
+            ware.put("taxRate", apBillOutItem.getTaxrate());
+            //否
+            ware.put("unit", product.getUnit());//单位
+            ware.put("standard", product.getSpec());//规格型号
+            ware.put("discountAmount", "");//优惠后总额
+
+            wares.add(ware);
+        }
+
+        paraMap.put("wareListInfo", wares.toString());
+
+        //调用票加加开票接口
+        try {
+            HttpUtil.Response response = HttpUtil.sendPostRequest(url, paraMap);
+            JSONObject resultJo = JSON.parseObject(response.getResponseText());
+            String code = resultJo.getString("code");//结果码 0000代表成功,其它为失败
+            String resMsg = resultJo.getString("resMsg");
+            String requestCode = resultJo.getString("requestCode");//请求流水号
+            if ("0000".equals(code)) {
+                apBillOut.setRetmsg(resMsg);
+                apBillOut.setRequestCode(requestCode);
+                //修改开票单状态
+                apBillOut.setCheckStatus("已开票");
+
+                try {
+                    purchaseApBillOutDao.save(apBillOut);
+                } catch (Exception e) {
+                    result.put("dbError","开具发票成功,但过程中数据库更新开票单失败,需要人工紧急处理,作废此开票单据");
+                }
+
+                result.put("apBillOut",apBillOut);
+            } else {
+                result.put("resultJo",resultJo);
+                //map.put("error","发票开具失败");
+                result.put("error",errorMsg.append(resMsg));
+            }
+        } catch (NullPointerException e) {
+            result.put("error",errorMsg.append("从票加加开票接口获取数据失败"));
+            e.printStackTrace();
+        } catch (Exception e) {
+            result.put("error",errorMsg.append("链接票加加开票接口失败"));
+            e.printStackTrace();
+        }
+
+        return result;
+    }
+
+    @Override
+    public ModelMap InvoiceCancel(PurchaseApBillOut apBillOut) {
+        ModelMap result = new ModelMap();
+        StringBuilder errorMsg = new StringBuilder();
+
+        String url = "http://192.168.253.75:8282/icloud/invoice/revoke.json";
+        String invoiceKind = "004";//004:专票,007:普票, 026:电子票.百望税盘必填
+        String eqptType = "1";//设备类型 0税控服务,1税控盘.百望税盘必填
+        String taxDiskCode = "";
+        String taxDiskPwd = "";
+        String taxSignPwd = "";
+
+        Set<PurchaseApBillOutItem> apBillOutItems = apBillOut.getItems();
+        //获取购方开票信息
+        PurchaseApBillOutInfo customerApBillOutInfo = apBillOut.getCustomerApBillOutInfo();
+        if (customerApBillOutInfo == null) {
+            result.put("error", errorMsg.append("获取不到购方开票信息,请先完善!"));
+            return result;
+        }
+        //获取销方开票信息
+        PurchaseApBillOutInfo apBillOutInfo = apBillOut.getApBillOutInfo();
+        if (apBillOutInfo == null) {
+            result.put("error", errorMsg.append("获取不到销方开票信息,请先完善!"));
+            return result;
+        }
+
+        //签名部分
+        List<String> paras = new ArrayList<>();
+        paras.add("orderNo=" + apBillOut.getCode());
+        paras.add("replacedInvoiceCode=" + apBillOut.getInfoTypeCode());
+        paras.add("replacedInvoiceNo=" + apBillOut.getInfoNumber());
+        paras.add("revokeReson=" + "");//冲红原因
+        paras.add("taxpayerId=" + apBillOutInfo.getTaxNr());
+        //百望税盘参与 //TODO 判断
+        if (isBaiWang) {
+            paras.add("eqptType=" + eqptType);
+            paras.add("issueAddressCode=" + apBillOut.getKpdh());//TODO 开票点代码
+            paras.add("invoiceKind=" + invoiceKind);//TODO 发票种类编码
+        }
+
+        if (isBaiWang && "1".equals(eqptType)) {
+            paras.add("taxDiskCode=" + taxDiskCode);// 税控盘编号
+            paras.add("taxDiskPwd=" + taxDiskPwd);// 税控盘口令
+            paras.add("taxSignPwd=" + taxSignPwd);// 税务数字证书密码
+        }
+
+        int kplx = -1;//TODO 开票类型
+        if (isBaiWang && kplx < 0 && "004".equals(invoiceKind)) {
+            paras.add("redInfoCode=" + "");//TODO 红字信息表编号
+        }
+
+        if (isBaiWang && "004".equals(invoiceKind)) {
+            paras.add("noticeOrderCode=" + "");//TODO 通知单编号
+        }
+
+        String[] paraArr = new String[paras.size()];
+        String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
+        String sign = sign("icloud/invoice/revoke.json", "POST", timestamp, paras.toArray(paraArr));
+
+        Map<String,Object> paraMap = new HashMap<>();
+        String revokeReson = "";
+        if (StringUtils.isEmpty(apBillOutInfo.getTaxNr())) {
+            result.put("error", errorMsg.append("获取不到纳税人识别号!"));
+        }
+        if (StringUtils.isEmpty(apBillOut.getInfoTypeCode())) {
+            result.put("error", errorMsg.append("获取不到原发票代码!"));
+        }
+        if (StringUtils.isEmpty(apBillOut.getInfoNumber())) {
+            result.put("error", errorMsg.append("获取不到原发票号码!"));
+        }
+        if (StringUtils.isEmpty(revokeReson)) {
+            result.put("error", errorMsg.append("获取不到冲红原因!"));
+        }
+        if (StringUtils.isEmpty(apBillOut.getCode())) {
+            result.put("error", errorMsg.append("获取不到订单号!"));
+        }
+        paraMap.put("taxpayerId", apBillOutInfo.getTaxNr());//纳税人识别号
+        paraMap.put("replacedInvoiceCode", apBillOut.getInfoTypeCode());//原发票代码
+        paraMap.put("replacedInvoiceNo", apBillOut.getInfoNumber());//原发票号码
+        paraMap.put("revokeReson", revokeReson);//冲红原因
+        paraMap.put("orderNo", apBillOut.getCode());//订单号
+        //以下为可为空字段
+        String issueAddressCode = apBillOut.getKpdh();
+        String redInfoCode = "";
+        String noticeOrderCode = "";
+        if (isBaiWang && StringUtils.isEmpty(issueAddressCode)) {
+            result.put("error", errorMsg.append("获取不到百望税盘时的开票点代码!"));
+        }
+        if (isBaiWang && StringUtils.isEmpty(eqptType)) {
+            result.put("error", errorMsg.append("获取不到百望税盘时的设备的类型!"));
+        }
+        if (isBaiWang && StringUtils.isEmpty(invoiceKind)) {
+            result.put("error", errorMsg.append("获取不到百望税盘时的开票的类型!"));
+        }
+        if (isBaiWang && "1".equals(eqptType) && StringUtils.isEmpty(taxDiskCode)) {
+            result.put("error", errorMsg.append("获取不到百望税盘时的税控盘编号!"));
+        }
+        if (isBaiWang && "1".equals(eqptType) && StringUtils.isEmpty(taxDiskPwd)) {
+            result.put("error", errorMsg.append("获取不到百望税盘时的税控盘口令!"));
+        }
+        if (isBaiWang && "1".equals(eqptType) && StringUtils.isEmpty(taxSignPwd)) {
+            result.put("error", errorMsg.append("获取不到百望税盘时的税务数字证书密码!"));
+        }
+        if (isBaiWang && "004".equals(invoiceKind) && StringUtils.isEmpty(redInfoCode)) {
+            result.put("error", errorMsg.append("获取不到百望税盘时专票冲红的红字信息表编号!"));
+        }
+        if (isBaiWang && "004".equals(invoiceKind) && StringUtils.isEmpty(noticeOrderCode)) {
+            result.put("error", errorMsg.append("获取不到百望税盘时专票冲红的通知单编号!"));
+        }
+        if (result.size() > 0) {
+            return result;
+        }
+        paraMap.put("issueAddressCode", issueAddressCode);//开票点代码  百望税盘必填
+        paraMap.put("eqptType", eqptType);//设备类型 0税控服务,1税控盘.百望税盘必填
+        paraMap.put("invoiceKind", invoiceKind);//004:专票,007:普票,026:电子票.百望税盘必填
+        paraMap.put("taxDiskCode", taxDiskCode);//税控盘编号  百望税盘且设备类型为1必填
+        paraMap.put("taxDiskPwd", taxDiskPwd);//税控盘口令  百望税盘且设备类型为1必填
+        paraMap.put("taxSignPwd", taxSignPwd);//税务数字证书密码  百望税盘且设备类型为1必填
+        paraMap.put("redInfoCode", redInfoCode);//红字信息表编号  百望税盘, 专票红冲时,必填。
+        paraMap.put("noticeOrderCode", noticeOrderCode);//通知单编号  百望税盘,专票红冲时,必填。
+
+
+        //调用票加加冲红接口
+        try {
+            HttpUtil.Response response = HttpUtil.sendPostRequest(url, paraMap);
+            JSONObject resultJo = JSON.parseObject(response.getResponseText());
+            String code = resultJo.getString("code");//结果码 0000代表成功,其它为失败
+            String resMsg = resultJo.getString("resMsg");
+            String requestCode = resultJo.getString("requestCode");//请求流水号
+            if ("0000".equals(code)) {
+                apBillOut.setRetmsg(resMsg);
+                apBillOut.setRequestCode(requestCode);
+                //修改开票单状态
+                apBillOut.setCheckStatus("已作废");
+
+                try {
+                    purchaseApBillOutDao.save(apBillOut);
+                } catch (Exception e) {
+                    result.put("dbError","冲红发票成功,但过程中数据库更新开票单失败,需要人工紧急处理,作废此开票单据");
+                }
+
+                result.put("apBillOut",apBillOut);
+            } else {
+                result.put("resultJo",resultJo);
+                result.put("error",errorMsg.append(resMsg));
+            }
+        } catch (NullPointerException e) {
+            result.put("error",errorMsg.append("从票加加开票接口获取数据失败"));
+            e.printStackTrace();
+        } catch (Exception e) {
+            result.put("error",errorMsg.append("链接票加加开票接口失败"));
+            e.printStackTrace();
+        }
+
+        return result;
+    }
+
+    @Override
+    public ModelMap queryInvoiceMessage(PurchaseApBillOut apBillOut) {
+        Map<String,Object> paraMap = new HashMap<>();
+        String url = "http://192.168.253.75:8282/icloud/invoice/query.json";
+        String invoiceKind = "004";//004:专票,007:普票, 026:电子票.百望税盘必填
+        String eqptType = "1";//设备类型 0税控服务,1税控盘.百望税盘必填
+
+        Set<PurchaseApBillOutItem> apBillOutItems = apBillOut.getItems();
+        //获取购方开票信息
+        PurchaseApBillOutInfo customerApBillOutInfo = apBillOut.getCustomerApBillOutInfo();
+        //获取销方开票信息
+        PurchaseApBillOutInfo apBillOutInfo = apBillOut.getApBillOutInfo();
+
+        //签名部分  发票代码+发票号码、订单号三选一.传入什么参数就用什么参数签名,为空不参与签名
+        List<String> paras = new ArrayList<>();
+        String invoiceCode = apBillOut.getInfoTypeCode();
+        String invoiceNum = apBillOut.getInfoNumber();
+        String orderNo = apBillOut.getCode();
+        String requestCode = "";//请求流水号
+        if (StringUtils.isEmpty(requestCode) && (StringUtils.isEmpty(invoiceCode) && StringUtils.isEmpty(invoiceNum)) && StringUtils.isEmpty(orderNo)) {
+            //TODO 为空不参与签名
+        } else if (!StringUtils.isEmpty(requestCode)){
+            paras.add("requestCode=" + requestCode);
+            paraMap.put("requestCode", requestCode);
+        } else if (!(StringUtils.isEmpty(invoiceNum) && StringUtils.isEmpty(invoiceCode))) {
+            paras.add("invoiceCode=" + invoiceCode);
+            paras.add("invoiceNum=" + invoiceNum);
+            paraMap.put("invoiceCode", invoiceCode);
+            paraMap.put("invoiceNum", invoiceNum);
+        } else if (!StringUtils.isEmpty(orderNo)) {
+            paras.add("orderNo=" + orderNo);
+            paraMap.put("orderNo", orderNo);
+        }
+
+        paras.add("taxpayerId=" + apBillOutInfo.getTaxNr());
+        String[] paraArr = new String[paras.size()];
+        String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
+        String sign = sign("icloud/invoice/query.json", "POST", timestamp, paras.toArray(paraArr));
+
+        paraMap.put("taxpayerId", apBillOutInfo.getTaxNr());//纳税人识别号
+        paraMap.put("needItem", false);//是否需要商品详情
+
+        //调用票加加查询开票接口
+        try {
+            HttpUtil.Response response = HttpUtil.sendPostRequest(url, paraMap);
+            JSONObject responseJo = JSON.parseObject(response.getResponseText());
+            String code = responseJo.getString("code");//0000代表开具成功,1111代表未开具,2222代表开具中,其它代表开具失败
+            String resMsg = responseJo.getString("resMsg");
+            //TODO 查询结果处理
+
+        } catch (NullPointerException e) {
+            System.out.print("error从票加加开票接口获取数据失败");
+            e.printStackTrace();
+        } catch (Exception e) {
+            System.out.print("error链接票加加开票接口失败");
+            e.printStackTrace();
+        }
+
+        return null;
+    }
+
+    @Override
+    public ModelMap querybillingcount(String queryDate) {
+        Map<String,Object> paraMap = new HashMap<>();
+        String url = "http://192.168.253.75:8282/icloud/invoice/querybillingcount.json";
+        PurchaseApBillOutInfo apBillOutInfo = purchaseApBillOutInfoDao.findByUu(SystemSession.getUser().getEnterprise().getUu());
+        String taxpayerId = apBillOutInfo.getTaxNr();
+
+        //签名部分
+        List<String> paras = new ArrayList<>();
+        paras.add("taxpayerId=" + taxpayerId);
+        paras.add("queryDate=" + queryDate);
+        String[] paraArr = new String[paras.size()];
+        String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
+        String sign = sign("icloud/invoice/querybillingcount.json", "POST", timestamp, paras.toArray(paraArr));
+
+        paraMap.put("taxpayerId", taxpayerId);
+        paraMap.put("queryDate", queryDate);
+
+        //调用票加加统计开票接口
+        try {
+            HttpUtil.Response response = HttpUtil.sendPostRequest(url, paraMap);
+            JSONObject responseJo = JSON.parseObject(response.getResponseText());
+            String code = responseJo.getString("code");//0000代表成功其它代表失败
+            String resMsg = responseJo.getString("resMsg");
+            String totalCount = responseJo.getString("totalCount");//提交开票量
+            String totalSuccCount = responseJo.getString("totalSuccCount");//成功开票量
+            String totalMoney = responseJo.getString("totalMoney");//开票总金额
+
+        } catch (NullPointerException e) {
+            System.out.print("error从票加加开票接口获取数据失败");
+            e.printStackTrace();
+        } catch (Exception e) {
+            System.out.print("error链接票加加开票接口失败");
+            e.printStackTrace();
+        }
+
+        return null;
+    }
+
+    @Override
+    public ModelMap queryBillLeftCount() {
+        Map<String,Object> paraMap = new HashMap<>();
+        String url = "http://192.168.253.75:8282/icloud/invoice/queryBillLeftCount.json";
+        String eqptType = "1";
+        PurchaseApBillOutInfo apBillOutInfo = purchaseApBillOutInfoDao.findByUu(SystemSession.getUser().getEnterprise().getUu());
+        String taxpayerId = apBillOutInfo.getTaxNr();
+
+        List<String> paras = new ArrayList<>();
+        paras.add("taxpayerId=" + taxpayerId);
+        paraMap.put("taxpayerId", taxpayerId);
+
+        if (isBaiWang) {
+            paras.add("eqptType=" + eqptType);
+            paras.add("machineCode=" + "");
+            paras.add("invoiceKind=" + "");
+            paraMap.put("eqptType", eqptType);//设备类型 0税控服务,1税控盘.百望税盘必填
+            paraMap.put("machineCode", "");//机器编号 百望税盘必填。 设备类型0为:核心板编号、1为:税盘编号
+            paraMap.put("invoiceKind", "");//004:专票,007:普票,026:电子票.百望税盘必填
+        }
+
+        if (isBaiWang && "0".equals(eqptType)) {
+            paras.add("teminalFlag=" + "");
+            paraMap.put("teminalFlag", "");//百望税盘且设备类型为0必填,开票点代码
+        }
+
+        if (isBaiWang && "1".equals(eqptType)) {
+            paras.add("taxDiskCode=" + "");
+            paras.add("taxDiskPwd=" + "");
+            paras.add("taxSignPwd=" + "");
+            paraMap.put("taxDiskCode", "");//税控盘编号  百望税盘且设备类型为1必填
+            paraMap.put("taxDiskPwd", "");//税控盘口令  百望税盘且设备类型为1必填
+            paraMap.put("taxSignPwd", "");//税务数字证书密码  百望税盘且设备类型为1必填
+        }
+
+        String[] paraArr = new String[paras.size()];
+        String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
+        String sign = sign("icloud/invoice/querybillingcount.json", "POST", timestamp, paras.toArray(paraArr));
+
+        //调用票加加统计开票接口
+        try {
+            HttpUtil.Response response = HttpUtil.sendPostRequest(url, paraMap);
+            JSONObject responseJo = JSON.parseObject(response.getResponseText());
+            String code = responseJo.getString("code");//0000代表成功其它代表失败
+            String resMsg = responseJo.getString("resMsg");
+            String leftInvoiceNum = responseJo.getString("leftInvoiceNum");//剩余发票量
+
+        } catch (NullPointerException e) {
+            System.out.print("error从票加加开票接口获取数据失败");
+            e.printStackTrace();
+        } catch (Exception e) {
+            System.out.print("error链接票加加开票接口失败");
+            e.printStackTrace();
+        }
+
+        return null;
+    }
+
+    @Override
+    public ModelMap printInvoice(PurchaseApBillOut apBillOut) {
+        ModelMap result = new ModelMap();
+        StringBuilder errorMsg = new StringBuilder();
+
+        Map<String,Object> paraMap = new HashMap<>();
+        String url = "http://192.168.253.75:8282/icloud/invoice/printInvoice.json";
+        String invoiceKind = "004";//004:专票,007:普票, 026:电子票.百望税盘必填
+        String eqptType = "1";//设备类型 0税控服务,1税控盘.百望税盘必填
+        String taxDiskCode = "";
+        String taxDiskPwd = "";
+        String taxSignPwd = "";
+        String invoiceNum = "";//(税控盘必填)单张打印
+        String printKind = "";//(税控盘必填)0:发票打印,1:清单打印  (批量打印不支持清单打印)
+        String printType = "";//(税控盘必填)1:单张打印
+
+        Set<PurchaseApBillOutItem> apBillOutItems = apBillOut.getItems();
+        //获取购方开票信息
+        //PurchaseApBillOutInfo customerApBillOutInfo = apBillOut.getCustomerApBillOutInfo();
+        //获取销方开票信息
+        PurchaseApBillOutInfo apBillOutInfo = apBillOut.getApBillOutInfo();
+        if (apBillOutInfo == null) {
+            result.put("error", errorMsg.append("获取不到销方开票信息,请先完善!"));
+            return result;
+        }
+
+        //签名部分
+        List<String> paras = new ArrayList<>();
+        String issueAddressCode = apBillOut.getKpdh();
+        if (StringUtils.isEmpty(apBillOutInfo.getTaxNr())) {
+            result.put("error", errorMsg.append("获取不到纳税人识别号!"));
+        }
+        if (StringUtils.isEmpty(eqptType)) {
+            result.put("error", errorMsg.append("获取不到设备类型!"));
+        }
+        if (StringUtils.isEmpty(issueAddressCode)) {
+            result.put("error", errorMsg.append("获取不到开票点代码!"));
+        }
+        if (StringUtils.isEmpty(invoiceKind)) {
+            result.put("error", errorMsg.append("获取不到开票类型!"));
+        }
+        if (StringUtils.isEmpty(apBillOut.getInfoTypeCode())) {
+            result.put("error", errorMsg.append("获取不到发票代码!"));
+        }
+        paras.add("taxpayerId=" + apBillOutInfo.getTaxNr());
+        paras.add("eqptType="+ eqptType);
+        paras.add("issueAddressCode=" + issueAddressCode);//开票点代码
+        paras.add("invoiceKind=" + invoiceKind);//004:专票,007:普票
+        paras.add("invoiceCode=" + apBillOut.getInfoTypeCode());//发票代码
+
+        paraMap.put("taxpayerId", apBillOutInfo.getTaxNr());
+        paraMap.put("eqptType", eqptType);
+        paraMap.put("issueAddressCode", apBillOut.getKpdh());
+        paraMap.put("invoiceKind", invoiceKind);
+        paraMap.put("invoiceCode", apBillOut.getInfoTypeCode());
+
+        if ("1".equals(eqptType)) {
+            if (StringUtils.isEmpty(invoiceNum)) {
+                result.put("error", errorMsg.append("获取不到税控盘单张打印时发票号码!"));
+            }
+            if (StringUtils.isEmpty(printKind)) {
+                result.put("error", errorMsg.append("获取不到税控盘的打印类型设置!"));
+            }
+            if (StringUtils.isEmpty(printType)) {
+                result.put("error", errorMsg.append("获取不到税控盘打印方式!"));
+            }
+
+            paras.add("invoiceNum=" + invoiceNum);
+            paras.add("printKind=" + printKind);
+            paras.add("printType=" + printType);
+
+            paraMap.put("invoiceNum", invoiceNum);
+            paraMap.put("printKind", printKind);
+            paraMap.put("printType", printType);
+        }
+
+        if (isBaiWang && "1".equals(eqptType)) {
+            if (StringUtils.isEmpty(taxDiskCode)) {
+                result.put("error", errorMsg.append("获取不到百望税盘时的税控盘编号!"));
+            }
+            if (StringUtils.isEmpty(taxDiskPwd)) {
+                result.put("error", errorMsg.append("获取不到百望税盘时的税控盘口令!"));
+            }
+            if (StringUtils.isEmpty(taxSignPwd)) {
+                result.put("error", errorMsg.append("获取不到百望税盘时的税务数字证书密码!"));
+            }
+
+            paras.add("taxDiskCode=" + taxDiskCode);
+            paras.add("taxDiskPwd=" + taxDiskPwd);
+            paras.add("taxSignPwd=" + taxSignPwd);
+
+            paraMap.put("taxDiskCode", taxDiskCode);
+            paraMap.put("taxDiskPwd", taxDiskPwd);
+            paraMap.put("taxSignPwd", taxSignPwd);
+
+        }
+
+        String[] paraArr = new String[paras.size()];
+        String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
+        String sign = sign("icloud/invoice/printInvoice.json", "POST", timestamp, paras.toArray(paraArr));
+
+        //调用票加加发票打印接口
+        try {
+            HttpUtil.Response response = HttpUtil.sendPostRequest(url, paraMap);
+            JSONObject resultJo = JSON.parseObject(response.getResponseText());
+            String code = resultJo.getString("code");//0000代表成功其它代表失败
+            String resMsg = resultJo.getString("resMsg");
+            if ("0000".equals(code)) {
+                result.put("retmsg",resultJo.getString("retmsg"));
+                //添加打印次数
+                apBillOut.setPrint((short) ((apBillOut.getPrint() == null ? 0 : apBillOut.getPrint()) + 1));
+                try {
+                    purchaseApBillOutDao.save(apBillOut);
+                } catch (Exception e) {
+                    result.put("dbError","发票打印成功,但过程中数据库更新开票单打印次数失败,需要人工处理干预");
+                }
+            } else {
+                result.put("resultJo",resultJo);
+                result.put("error",errorMsg.append(resMsg));
+            }
+        } catch (NullPointerException e) {
+            result.put("error",errorMsg.append("从票加加开票接口获取数据失败"));
+            e.printStackTrace();
+        } catch (Exception e) {
+            result.put("error",errorMsg.append("链接票加加开票接口失败"));
+            e.printStackTrace();
+        }
+
+
+        return result;
+    }
+
+    @Override
+    public ModelMap queryDelivery(PurchaseApBillOut apBillOut) {
+        Map<String,Object> paraMap = new HashMap<>();
+        String url = "http://192.168.253.75:8282/imanager/manager/fetchDeliveryTrackingNumbers.ysy";
+        //获取销方开票信息
+        PurchaseApBillOutInfo apBillOutInfo = apBillOut.getApBillOutInfo();
+        String sysOrderNo = apBillOut.getCode();
+        String taxpayerId = apBillOutInfo.getTaxNr();
+        paraMap.put("sysOrderNo", sysOrderNo);
+        paraMap.put("taxpayerId", taxpayerId);
+
+        //调用票加加快递单信息获取接口
+        try {
+            HttpUtil.Response response = HttpUtil.sendPostRequest(url, paraMap);
+            JSONObject responseJo = JSON.parseObject(response.getResponseText());
+            String code = responseJo.getString("code");//0000代表成功其它代表失败
+            String resMsg = responseJo.getString("resMsg");
+            String data = responseJo.getString("data");
+            String remark = responseJo.getString("remark");
+            String businessName = responseJo.getString("businessName");
+            String number = responseJo.getString("number");
+        } catch (NullPointerException e) {
+            System.out.print("error从票加加开票接口获取数据失败");
+            e.printStackTrace();
+        } catch (Exception e) {
+            System.out.print("error链接票加加开票接口失败");
+            e.printStackTrace();
+        }
+
+        return null;
+    }
+
+    @Override
+    public ModelMap uploadInvoice(PurchaseApBillOut apBillOut) {
+        ModelMap result = new ModelMap();
+        StringBuilder errorMsg = new StringBuilder();
+
+        //Map<String,Object> paraMap = new HashMap<>();
+        JSONObject paraMap = new JSONObject(16,true);
+        String url = "http://test.fapiaoxx.com/imanager/manager/getInvoiceInfoFromBPM.ysy";
+        //String eqptType = "1";//设备类型 0税控服务,1税控盘.百望税盘必填
+        String mediumType = "2";//1: 电子发票; 2: 纸质发票
+        String category = "4";//发票分类  1: 增值税专用发票; 4: 增值税普通发票(纸质);10: 增值税普通发票(电子)
+        boolean isZhuanpiao = true;
+
+        Set<PurchaseApBillOutItem> apBillOutItems = apBillOut.getItems();
+        //获取购方开票信息
+        PurchaseApBillOutInfo customerApBillOutInfo = apBillOut.getCustomerApBillOutInfo();
+        if (customerApBillOutInfo == null) {
+            result.put("error", errorMsg.append("获取不到购方开票信息,请先完善!"));
+            return result;
+        }
+        //获取销方开票信息
+        PurchaseApBillOutInfo apBillOutInfo = apBillOut.getApBillOutInfo();
+        if (apBillOutInfo == null) {
+            result.put("error", errorMsg.append("获取不到销方开票信息,请先完善!"));
+            return result;
+        }
+
+        //签名部分
+        List<String> paras = new ArrayList<>();
+        paras.add("sysOrderNo=" + apBillOut.getCode());
+        paras.add("taxpayerId=" + apBillOutInfo.getTaxNr());
+        String timestamp = String.valueOf(System.currentTimeMillis());
+        paras.add("timestamp=" + timestamp);
+        String[] paraArr = new String[paras.size()];
+        String sign = sign("test.fapiaoxx.com/imanager/manager/getInvoiceInfoFromBPM.ysy", "POST", timestamp, paras.toArray(paraArr));
+
+        if (StringUtils.isEmpty(apBillOut.getCode())) {
+            result.put("error", errorMsg.append("获取不到申请单编号!"));
+        }
+        if (StringUtils.isEmpty(mediumType)) {
+            result.put("error", errorMsg.append("获取不到发票媒介类型!"));
+        }
+        if (StringUtils.isEmpty(category)) {
+            result.put("error", errorMsg.append("获取不到发票分类!"));
+        }
+        if (StringUtils.isEmpty(apBillOutInfo.getTaxNr())) {
+            result.put("error", errorMsg.append("获取不到纳税人识别号!"));
+        }
+        if (StringUtils.isEmpty(customerApBillOutInfo.getEnName())) {
+            result.put("error", errorMsg.append("获取不到购买方名称!"));
+        }
+        paraMap.put("sysOrderNo", apBillOut.getCode());//申请单编号
+        paraMap.put("mediumType", mediumType);//发票媒介类型
+        paraMap.put("category", category);//发票分类
+        paraMap.put("taxpayerId", apBillOutInfo.getTaxNr());
+        paraMap.put("buyerName", customerApBillOutInfo.getEnName());
+        //以下为可为空字段
+        String buyerTaxpayerId = customerApBillOutInfo.getTaxNr();
+        String buyerAddr = apBillOutInfo.getAddress();
+        String buyerMobile = apBillOutInfo.getTel();
+        String buyerAccountNo = apBillOutInfo.getBankAccountNr();
+        if (isZhuanpiao) {
+            if (StringUtils.isEmpty(buyerTaxpayerId)) {
+                result.put("error", errorMsg.append("上传专票申请单时获取不到购买方识别号!"));
+            }
+            if (StringUtils.isEmpty(buyerAddr)) {
+                result.put("error", errorMsg.append("上传专票申请单时获取不到购买方地址!"));
+            }
+            if (StringUtils.isEmpty(buyerMobile)) {
+                result.put("error", errorMsg.append("上传专票申请单时获取不到购方电话!"));
+            }
+            if (StringUtils.isEmpty(buyerAccountNo)) {
+                result.put("error", errorMsg.append("上传专票申请单时获取不到购买方银行及账号!"));
+            }
+        } else {
+            if (StringUtils.isEmpty(buyerTaxpayerId)) {
+                buyerTaxpayerId = "";
+            }
+            if (StringUtils.isEmpty(buyerAddr)) {
+                buyerAddr = "";
+            }
+            if (StringUtils.isEmpty(buyerMobile)) {
+                buyerMobile = "";
+            }
+            if (StringUtils.isEmpty(buyerAccountNo)) {
+                buyerAccountNo = "";
+            }
+        }
+        paraMap.put("buyerTaxpayerId", buyerTaxpayerId);
+        paraMap.put("buyerAddr", buyerAddr);
+        paraMap.put("buyerMobile", buyerMobile);
+        paraMap.put("buyerAccountNo", buyerAccountNo);
+
+        if (StringUtils.isEmpty(apBillOutInfo.getChecker())) {
+            paraMap.put("checker", "");
+        } else {
+            paraMap.put("checker", apBillOutInfo.getChecker());
+        }
+
+        paraMap.put("drawer", "");
+
+        if (StringUtils.isEmpty(apBillOutInfo.getPayee())) {
+            paraMap.put("payee", "");
+        } else {
+            paraMap.put("payee", apBillOutInfo.getPayee());
+        }
+
+        if (StringUtils.isEmpty(apBillOut.getRemark())) {
+            paraMap.put("remark", "");
+        } else {
+            paraMap.put("remark", apBillOut.getRemark());
+        }
+
+        paraMap.put("urlAddress", "");//开票成功回调地址  用于回调开票成功信息
+        paraMap.put("settlementNum", "");//结算单号
+        paraMap.put("contractNum", "");//合同编号
+        paraMap.put("businessInfo", "");//业务信息
+
+        //明细
+        List<JSONObject> wares = new ArrayList<>();
+        for (PurchaseApBillOutItem apBillOutItem : apBillOutItems) {
+            // wares  商品行项目信息(发票明细)
+            Product product = apBillOutItem.getProduct();
+            product.setGoodstaxno((Math.random() + 50) + "");//TODO
+            if (product == null) {
+                result.put("error", errorMsg.append("获取不到商品信息!"));
+                return result;
+            }
+            if (StringUtils.isEmpty(product.getTitle())) {
+                result.put("error", errorMsg.append("获取不到商品名称!"));
+            }
+            if (StringUtils.isEmpty(product.getGoodstaxno())) {
+                result.put("error", errorMsg.append("获取不到商品编码!"));
+            }
+            if (StringUtils.isEmpty(apBillOutItem.getNowQty())) {
+                result.put("error", errorMsg.append("获取不到商品开票数量!"));
+            }
+            if (StringUtils.isEmpty(apBillOutItem.getNowPrice())) {
+                result.put("error", errorMsg.append("获取不到商品开票单价!"));
+            }
+            if (StringUtils.isEmpty(apBillOutItem.getTaxrate())) {
+                result.put("error", errorMsg.append("获取不到商品税率!"));
+            }
+
+            JSONObject ware = new JSONObject(16, true);
+            ware.put("wareName", product.getTitle());//商品名称
+            ware.put("wareNo", "1090232070000000000");//TODO product.getGoodstaxno() 商品编码  应与税局最新发行的商品和服务税收分类与编码相一致
+            if (StringUtils.isEmpty(product.getSpec())) {
+                ware.put("standard", "");//规格型号
+            } else {
+                ware.put("standard", product.getSpec());//规格型号
+            }
+            if (StringUtils.isEmpty(product.getUnit())) {
+                ware.put("unit", "");//单位
+            } else {
+                ware.put("unit", product.getUnit());//单位
+            }
+            ware.put("count", apBillOutItem.getNowQty());//数量 整数
+            ware.put("unitPrice", apBillOutItem.getNowPrice());//单价 小数点后2位,以元为单位精确到分,含税价
+            ware.put("amount", 1.00);//价税合计金额
+            ware.put("taxRate", apBillOutItem.getTaxrate()/100.00);//0表示免税,两位小数,0.17
+            wares.add(ware);
+        }
+
+        paraMap.put("invitem", wares);
+
+        if (result.size() > 0) {
+            return result;
+        }
+
+        //调用票加加上传接口
+        try {
+            String a = paraMap.toString();
+            url = url + "?timestamp=" + timestamp + "&sign=" + sign;
+            //HttpUtil.Response response = HttpUtil.sendPostRequest(url, paraMap);
+            String resultStr =  HttpUtil.sendPost(url, paraMap.toString());
+            JSONObject resultJo = JSON.parseObject(resultStr);
+            String code = resultJo.getString("code");//0000代表成功其它代表失败
+            String resMsg = resultJo.getString("resMsg");;
+
+            if ("0000".equals(code)) {
+                result.put("success", "发票上传成功,开票中!");
+                apBillOut.setRetmsg(resMsg);
+                //apBillOut.setCheckStatus("开票中");
+                try {
+                    purchaseApBillOutDao.save(apBillOut);
+                } catch (Exception e) {
+                    result.put("dbError","上传发票成功,但过程中数据库更新开票单失败,需要人工紧急处理,重新上传此开票单据");
+                }
+            }
+
+            result.put("resultJo",resultStr);
+        } catch (NullPointerException e) {
+            result.put("error",errorMsg.append("从票加加开票接口获取数据失败"));
+            e.printStackTrace();
+        } catch (Exception e) {
+            result.put("error",errorMsg.append("链接票加加开票接口失败"));
+            e.printStackTrace();
+        }
+
+        return null;
+    }
+
+    /**
+     * 生成签名
+     * @return
+     */
+    private String sign(String api, String httpMethod, String timestamp, String prars[]) {
+        StringBuilder content = new StringBuilder();
+        content.append(httpMethod);
+        //获取请求的url
+        content.append(api);
+        //参数按字典排序
+        content.append(sort(prars));
+        //content.append("timestamp=" + timestamp);
+        //String taxpayerKey = "626454404969499358070752";//优软
+        String taxpayerKey = "487843442563106693107397";//丰唐
+        content.append(taxpayerKey);
+
+        String sign = null;
+        try {
+            sign = MD5.toMD5(URLEncoder.encode(content.toString(),"UTF-8"));
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+        return sign;
+    }
+
+    /**
+     * 按字典排序 升序
+     * @param a
+     */
+    public StringBuilder sort(String a[]) {
+        for (int i = 0; i < a.length - 1; i++) {
+            for (int j = i + 1; j < a.length; j++) {
+                if (a[j].compareTo(a[i]) < 0) {
+                    String temp = a[i];
+                    a[i] = a[j];
+                    a[j] = temp;
+                }
+            }
+        }
+
+        StringBuilder paras = new StringBuilder();
+        for (int i = 0; i < a.length; i++) {
+            paras.append(a[i]);
+        }
+
+        return paras;
+    }
+}

+ 29 - 1
src/main/java/com/uas/platform/b2b/service/impl/PurchaseApBillOutServiceImpl.java

@@ -3,6 +3,7 @@ package com.uas.platform.b2b.service.impl;
 import com.uas.platform.b2b.dao.*;
 import com.uas.platform.b2b.model.*;
 import com.uas.platform.b2b.search.SearchService;
+import com.uas.platform.b2b.service.PiaoPlusService;
 import com.uas.platform.b2b.service.PurchaseApBillOutService;
 import com.uas.platform.b2b.service.SOAPConsoleService;
 import com.uas.platform.b2b.support.SystemSession;
@@ -63,6 +64,9 @@ public class PurchaseApBillOutServiceImpl implements PurchaseApBillOutService {
 	@Autowired
 	private SOAPConsoleService soapConsoleService;
 
+	@Autowired
+	private PiaoPlusService piaoPlusService;
+
 	/*@Override
 	public List<PurchaseApCheck> findNotUploadAPcheck() {
 		return purchaseApCheckDao.findByCustUuAndStatusAndCheckStatus(SystemSession.getUser().getEnterprise().getUu(),
@@ -215,7 +219,9 @@ public class PurchaseApBillOutServiceImpl implements PurchaseApBillOutService {
 		PurchaseApBillOut apBillOut = purchaseApBillOutDao.findOne(id);
 		if (apBillOut != null) {
 			//调用航天接口开具发票
-			map =soapConsoleService.invoiceIssued(apBillOut);
+			//map =soapConsoleService.invoiceIssued(apBillOut);
+			//调用票加加上传接口
+			map = piaoPlusService.uploadInvoice(apBillOut);
 		} else {
 			map.put("error", "不存在此开票单");
 		}
@@ -478,4 +484,26 @@ public class PurchaseApBillOutServiceImpl implements PurchaseApBillOutService {
 		}
 		return map;
 	}
+
+	@Override
+	public void saveByItem(List<PurchaseApBillOutItem> apBillOutItems) {
+		List<PurchaseApBillOutItem> purchaseApBillOutItems = purchaseApBillOutItemDao.save(apBillOutItems);
+	}
+
+	@Override
+	public PurchaseApBillOut findByCode(String orderNo) {
+		long enUU = SystemSession.getUser().getEnterprise().getUu();
+		List<PurchaseApBillOut> list = purchaseApBillOutDao.findByEnUuAndCode(enUU, orderNo);
+		if (list.size() > 0) {
+			return list.get(0);
+		}
+		return null;
+	}
+
+	@Override
+	public void save(PurchaseApBillOut apBillOut) {
+		purchaseApBillOutDao.save(apBillOut);
+	}
+
+
 }

+ 4 - 1
src/main/webapp/resources/tpl/index/fa/apBillOut.html

@@ -219,7 +219,7 @@
 					<div class="">
 						<span>单据编号:</span>
 						<span class="text-num"><a ui-sref="fa.apBillOut_detail({id:billOut.id})" title="点击查看详情">{{::billOut.code}}</a></span>
-						<span class="pull-right text-num" title="录单时间">{{::billOut.recordDate | date:'MM月dd日 HH:mm'}} <i class="fa fa-clock-o"></i></span>
+						<span class="pull-right text-num" title="录单时间">{{::billOut.recordDate | date:'yyyy年MM月dd日 HH:mm'}} <i class="fa fa-clock-o"></i></span>
 					</div>
 					<div class="main">
 						<strong><i class="fa fa-star" ng-class="{'text-default':billOut.status==201}"></i> {{::billOut.custName}}</strong>
@@ -256,6 +256,9 @@
 					<div ng-if="billOut.checkStatus == '已开票'" class="text-center text-muted f14">
 						<br> <i class="fa fa-check-square-o"></i> 已开票
 					</div>
+					<div ng-if="billOut.checkStatus == '开票中'" class="text-center text-muted f14">
+						<br> <i class="fa fa-check-square-o"></i> 开票中
+					</div>
 					<div ng-if="billOut.checkStatus == '部分开票'" class="text-center text-muted f14">
 						<br> <i class="fa fa-check-square-o"></i> 部分开票
 					</div>

+ 12 - 6
src/main/webapp/resources/tpl/index/fa/apBillOut_detail.html

@@ -68,7 +68,7 @@
 			</div>
 			<div class="col-xs-3">
 				<span class="title">录单日期</span>
-				<div class="content" ng-bind="::data.recordDate | date:'MM月dd日 HH:mm'"></div>
+				<div class="content" ng-bind="::data.recordDate | date:'yyyy年MM月dd日 HH:mm'"></div>
 			</div>
 			<div class="col-xs-3">
 				<span class="title">录单人</span>
@@ -133,10 +133,13 @@
 						<th width="100">客户单据编号</th>
 						<th width="80">单据类型</th>
 						<th>序号</th>
-						<th>单价</th>
 						<th>税率</th>
-						<th>对账数量</th>
-						<th>对账金额</th>
+						<th>开票单价</th>
+						<th>开票数量</th>
+						<th>开票金额</th>
+						<th>发票单价</th>
+						<th>发票数量</th>
+						<th>发票金额</th>
 						<th width="40">采购单号</th>
 						<th>采购序号</th>
 						<th>应付供应商名称</th>
@@ -150,10 +153,13 @@
 						<td ng-bind="item.inoutno"></td>
 						<td ng-bind="item.orderClass"></td>
 						<td ng-bind="item.inoutnodetno"></td>
-						<td ng-bind="item.price"></td>
 						<td ng-bind="item.taxrate"></td>
-						<td ng-bind="item.nowQty"></td>
 						<td ng-bind="item.nowPrice | number:2"></td>
+						<td ng-bind="item.nowQty | number:2"></td>
+						<td >{{::item.nowPrice * item.nowQty | number:2}}</td>
+						<td ng-bind="item.price | number:2"></td>
+						<td ng-bind="item.qty | number:2"></td>
+						<td >{{::item.price * item.qty | number:2}}</td>
 						<td ng-bind="item.orderCode"></td>
 						<td ng-bind="item.orderDetno"></td>
 						<td ng-bind="data.apBillOutInfo.enName"></td>