|
@@ -1,5 +1,6 @@
|
|
|
package com.ym.mec.collectfee.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.thoughtworks.xstream.XStream;
|
|
|
import com.ym.mec.collectfee.common.dao.BaseDAO;
|
|
|
import com.ym.mec.collectfee.common.service.impl.BaseServiceImpl;
|
|
@@ -8,125 +9,171 @@ import com.ym.mec.collectfee.entity.*;
|
|
|
import com.ym.mec.collectfee.service.CourseGroupInfoService;
|
|
|
import com.ym.mec.collectfee.service.OrderService;
|
|
|
import com.ym.mec.collectfee.service.SchoolService;
|
|
|
+import com.ym.mec.collectfee.service.YqPayService;
|
|
|
import com.ym.mec.collectfee.utils.HttpUtil;
|
|
|
import com.ym.mec.collectfee.utils.XStreamUtil;
|
|
|
+import com.ym.mec.collectfee.utils.yqpay.YqPayUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.StringWriter;
|
|
|
import java.io.Writer;
|
|
|
-import java.util.Base64;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
public class OrderServiceImpl extends BaseServiceImpl<Integer, Order> implements OrderService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private OrderDao orderDao;
|
|
|
- @Autowired
|
|
|
- private SchoolService schoolService;
|
|
|
- @Autowired
|
|
|
- private CourseGroupInfoService courseGroupInfoService;
|
|
|
-
|
|
|
- //公共密钥
|
|
|
- @Value("${common.properties.mec-publicKey}")
|
|
|
- private String publicKey;
|
|
|
-
|
|
|
- @Value("${common.properties.mec-url}")
|
|
|
- private String url;
|
|
|
-
|
|
|
- @Override
|
|
|
- public BaseDAO<Integer, Order> getDAO() {
|
|
|
- return orderDao;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<Order> getOrderByUserId(Integer userId) {
|
|
|
- return orderDao.getOrderByUserId(userId);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String pushOrder(String batchNum){
|
|
|
- try {
|
|
|
- RequestParamBean requestParamBean = new RequestParamBean();
|
|
|
- List<Order> orderList = orderDao.getOrderByBatch(batchNum);
|
|
|
- if(orderList == null || orderList.size() < 1){
|
|
|
- return null;
|
|
|
- }
|
|
|
- XStream xs = new XStream();
|
|
|
- xs.autodetectAnnotations(true);
|
|
|
- Writer writer = new StringWriter();
|
|
|
- Orders orders = new Orders(orderList);
|
|
|
- xs.toXML(orders,writer);
|
|
|
- String body = writer.toString();
|
|
|
- body = body.substring(body.indexOf("<body>")+6,body.indexOf("</body>"));
|
|
|
-
|
|
|
- body = Base64.getEncoder().encodeToString(body.getBytes());
|
|
|
- requestParamBean.setBody(body);
|
|
|
- requestParamBean.setHead(XStreamUtil.getOrdersHead(body,121512,publicKey,null,null));
|
|
|
-
|
|
|
- xs.autodetectAnnotations(true);
|
|
|
- writer = new StringWriter();
|
|
|
- writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
|
|
|
- xs.toXML(requestParamBean,writer);
|
|
|
- return writer.toString();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public int countOrder(String poName, String voicePort) {
|
|
|
- return orderDao.countOrder(poName,voicePort);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public Order getOrderByOrderNo(String orderNo) {
|
|
|
- return orderDao.getOrderByOrderNo(orderNo);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Object getSchoolDetail(Integer schoolId,Integer clazzId) {
|
|
|
- try {
|
|
|
- RequestParamBean requestParamBean = new RequestParamBean();
|
|
|
- String body = "<classId>" + clazzId + "</classId><schoolId>" + schoolId + "</schoolId>";
|
|
|
- body = Base64.getEncoder().encodeToString(body.getBytes());
|
|
|
- requestParamBean.setBody(body);
|
|
|
- requestParamBean.setHead(XStreamUtil.getOrdersHead(body,124005,publicKey,null,null));
|
|
|
- XStream xs = new XStream();
|
|
|
- xs.autodetectAnnotations(true);
|
|
|
- Writer writer = new StringWriter();
|
|
|
- writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
|
|
|
- xs.toXML(requestParamBean,writer);
|
|
|
- String parseBody = parseBody(HttpUtil.postXmlData(writer.toString(), url));
|
|
|
- ResponseCourseEntity xmlToObject = XStreamUtil.xmlToObject("body", ResponseCourseEntity.class, parseBody);
|
|
|
- courseGroupInfoService.upSetCourseGroup(xmlToObject);
|
|
|
- return schoolService.upsetSchool(xmlToObject);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- public String parseBody(String body){
|
|
|
- body = body.substring(body.indexOf("<body>")+6,body.indexOf("</body>"));
|
|
|
- return "<body><courses>" + new String(Base64.getDecoder().decode(body)) + "</courses></body>";
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int getPayOrderNums() {
|
|
|
- return orderDao.getPayOrderNums();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<Order> findPayingOrders(){
|
|
|
- return orderDao.findPayingOrders();
|
|
|
- }
|
|
|
+ @Value("${yq-pay.notify-url}")
|
|
|
+ private String notifyUrl;
|
|
|
+
|
|
|
+ @Value("${yq-pay.return-host}")
|
|
|
+ private String returnHost;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderDao orderDao;
|
|
|
+ @Autowired
|
|
|
+ private SchoolService schoolService;
|
|
|
+ @Autowired
|
|
|
+ private CourseGroupInfoService courseGroupInfoService;
|
|
|
+
|
|
|
+ //公共密钥
|
|
|
+ @Value("${common.properties.mec-publicKey}")
|
|
|
+ private String publicKey;
|
|
|
+
|
|
|
+ @Value("${common.properties.mec-url}")
|
|
|
+ private String url;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BaseDAO<Integer, Order> getDAO() {
|
|
|
+ return orderDao;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Order> getOrderByUserId(Integer userId) {
|
|
|
+ return orderDao.getOrderByUserId(userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String pushOrder(String batchNum) {
|
|
|
+ try {
|
|
|
+ RequestParamBean requestParamBean = new RequestParamBean();
|
|
|
+ List<Order> orderList = orderDao.getOrderByBatch(batchNum);
|
|
|
+ if (orderList == null || orderList.size() < 1) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ XStream xs = new XStream();
|
|
|
+ xs.autodetectAnnotations(true);
|
|
|
+ Writer writer = new StringWriter();
|
|
|
+ Orders orders = new Orders(orderList);
|
|
|
+ xs.toXML(orders, writer);
|
|
|
+ String body = writer.toString();
|
|
|
+ body = body.substring(body.indexOf("<body>") + 6, body.indexOf("</body>"));
|
|
|
+
|
|
|
+ body = Base64.getEncoder().encodeToString(body.getBytes());
|
|
|
+ requestParamBean.setBody(body);
|
|
|
+ requestParamBean.setHead(XStreamUtil.getOrdersHead(body, 121512, publicKey, null, null));
|
|
|
+
|
|
|
+ xs.autodetectAnnotations(true);
|
|
|
+ writer = new StringWriter();
|
|
|
+ writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
|
|
|
+ xs.toXML(requestParamBean, writer);
|
|
|
+ return writer.toString();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int countOrder(String poName, String voicePort) {
|
|
|
+ return orderDao.countOrder(poName, voicePort);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Order getOrderByOrderNo(String orderNo) {
|
|
|
+ return orderDao.getOrderByOrderNo(orderNo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object getSchoolDetail(Integer schoolId, Integer clazzId) {
|
|
|
+ try {
|
|
|
+ RequestParamBean requestParamBean = new RequestParamBean();
|
|
|
+ String body = "<classId>" + clazzId + "</classId><schoolId>" + schoolId + "</schoolId>";
|
|
|
+ body = Base64.getEncoder().encodeToString(body.getBytes());
|
|
|
+ requestParamBean.setBody(body);
|
|
|
+ requestParamBean.setHead(XStreamUtil.getOrdersHead(body, 124005, publicKey, null, null));
|
|
|
+ XStream xs = new XStream();
|
|
|
+ xs.autodetectAnnotations(true);
|
|
|
+ Writer writer = new StringWriter();
|
|
|
+ writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
|
|
|
+ xs.toXML(requestParamBean, writer);
|
|
|
+ String parseBody = parseBody(HttpUtil.postXmlData(writer.toString(), url));
|
|
|
+ ResponseCourseEntity xmlToObject = XStreamUtil.xmlToObject("body", ResponseCourseEntity.class, parseBody);
|
|
|
+ courseGroupInfoService.upSetCourseGroup(xmlToObject);
|
|
|
+ return schoolService.upsetSchool(xmlToObject);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String parseBody(String body) {
|
|
|
+ body = body.substring(body.indexOf("<body>") + 6, body.indexOf("</body>"));
|
|
|
+ return "<body><courses>" + new String(Base64.getDecoder().decode(body)) + "</courses></body>";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getPayOrderNums() {
|
|
|
+ return orderDao.getPayOrderNums();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Order> findPayingOrders() {
|
|
|
+ return orderDao.findPayingOrders();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map getPayMap(Account routingAccount, Order order, School school) throws Exception {
|
|
|
+
|
|
|
+ String notifyUrl = this.notifyUrl; //异步通知地址
|
|
|
+ String returnUrl = this.returnHost + "/#/login?schoolId=" + school.getSchoolId() + "&classId=" + order.getClassId() + "&cityId=" + school.getCityId();//支付后返回页面
|
|
|
+ String payUrl = "https://qyfapi.95epay.com/api/api/hPay/toPayHtml";//支付跳转页
|
|
|
+ String payChannels = "{\"weChatPay\":true,\"weChatPayMobile\":false,\"aliPay\":true,\"fastpayXy\":true,\"aliPayMobile\":false,\"balancePay\":false}";//支付方式配置
|
|
|
+
|
|
|
+ List<Map> tempRoutingList = new ArrayList();
|
|
|
+ if (routingAccount.getBranchId().equals(0)) {
|
|
|
+ Map<String, Object> routingList = new HashMap<>();
|
|
|
+ routingList.put("routingMerNo", routingAccount.getSellerNo());//分佣账户
|
|
|
+ routingList.put("routingFee", order.getAmount()); //分佣金额
|
|
|
+ tempRoutingList.add(routingList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /*订单信息*/
|
|
|
+ String orderBody = "大雅乐盟培训课程";
|
|
|
+ /*订单标题*/
|
|
|
+ String orderSubject = "培训订单";
|
|
|
+
|
|
|
+ Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
|
|
|
+ resultMap.put("sellerNo", "0021677"); //收款商户号
|
|
|
+ resultMap.put("payChannels", payChannels); //支付方式
|
|
|
+ resultMap.put("orderBody", orderBody); //订单信息
|
|
|
+ resultMap.put("payAmount", order.getAmount()); //支付金额
|
|
|
+ resultMap.put("apiPayType", "1"); //*API支付类型1-即时支付,2-担保支付,3-预授权支付*/
|
|
|
+ resultMap.put("tradeType", "0"); //*交易类型1—充值,0—收款*
|
|
|
+ resultMap.put("merMerOrderNo", order.getOrderNo()); //商户订单号
|
|
|
+ resultMap.put("orderSubject", orderSubject); //订单标题
|
|
|
+ resultMap.put("returnUrl", returnUrl); //前台页面地址
|
|
|
+ if (routingAccount.getBranchId().equals(0)) {
|
|
|
+ resultMap.put("tempRoutingList", JSON.toJSONString(tempRoutingList));//分账设置
|
|
|
+ }
|
|
|
+ Map rqMap = new YqPayUtil(notifyUrl, resultMap).getRequestMap();
|
|
|
+ rqMap.put("host", payUrl);
|
|
|
+ return rqMap;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|