Search in sources :

Example 61 with ExtraProduct

use of com.itrus.portal.db.ExtraProduct in project portal by ixinportal.

the class SZYQBillTask method submitBill.

// 1.提交订单
public void submitBill() {
    synchronized (SZYQBillTaskLock) {
        // start------------处理双机互斥----------
        if (null == taskFlag) {
            taskFlag = systemConfigService.isTimedTaskHost();
        }
        if (taskFlag.equals(false)) {
            return;
        }
        // end------------处理双机互斥----------
        // 1.查找是神州易桥接口的产品.然后遍历这些产品,根据产品查找订单,
        List<ExtraProduct> products = new ArrayList<>();
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = null;
        try {
            products = extraProductService.getExtraProductBySIN(ComNames.SERVICE_INTERFACE_NAME_SZYQQYDB);
            if (null == products || products.isEmpty()) {
                return;
            }
            Integer count = 0;
            for (ExtraProduct product : products) {
                Map<String, Object> paramMap = new HashMap<String, Object>();
                paramMap.put("productId", product.getId());
                paramMap.put("billStatu", ComNames.EXTRA_BILL_STATUS_3);
                // 2.查找是该产品的订单,并且订单状态是已支付,待服务商审核的订单.然后遍历订单信息
                List<Map<String, Object>> Extrabills = sqlSession.selectList("com.itrus.portal.db.ExtraBillMapper.selectByCondition_SZYQ", paramMap);
                if (null == Extrabills || Extrabills.isEmpty()) {
                    continue;
                }
                // 平台编号
                String system_code = product.getServiceId();
                // key
                if (product.getServiceSecret() != null) {
                    product.setServiceSecret(AESencrp.decrypt(product.getServiceSecret(), dbEncKey));
                }
                String key = product.getServiceSecret();
                // 数据库中的:http://www.cs.12366.com+"/city-api/order/createOrder"
                String url = product.getServiceAddress() + "/city-api/order/createOrder";
                // 3.封装参数,发送数据到第三方平台.根据返回值是否成功,如果成功就修改订单状态和审核时间,事物提交.
                for (Map<String, Object> bill : Extrabills) {
                    // 加密串md5(key+时间戳+参数)
                    String sign = new String();
                    // 时间戳
                    long ts = System.currentTimeMillis();
                    String param = "";
                    /**
                     * { " phone ":"186000000", //客户手机号
                     * " productName ":"1122" ,// 商品名称 "num":"1", //购买商品的数量
                     * " preferentialAmount ":" 1520.00 "
                     * ,//商品优惠价格(优惠的金额,差价) " finalAmount ":" 1520.00 "
                     * ,//商品最终价格(商品优惠后的价格,销售价) " orderPayType ":" 0 "
                     * //订单支付状态(1已支付,0待支付) }
                     */
                    param = "{\"phone\":\"" + bill.get("m_phone").toString() + "\"," + "\"productName\":\"" + bill.get("epname").toString() + "\"," + "\"num\":\"" + bill.get("product_num").toString() + "\"," + "\"preferentialAmount\":\"" + 0 + "\"," + "\"finalAmount\":\"" + bill.get("bill_sum").toString() + "\"," + "\"orderPayType\":\"" + 1 + "\"" + "}";
                    LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
                    String signAndtime = ts + param;
                    sign = sign(signAndtime, key, "utf-8");
                    map.add("sign", sign);
                    map.add("ts", ts);
                    map.add("system_code", system_code);
                    map.add("param", param);
                    // TODO 发送到第三方平台
                    /**
                     * { " orderCreateStatus ":"1", //订单生成状态(1成功,0失败)
                     * " ordersNo ":"112233", //订单编号 }
                     * {"data":"orderCreateStatus :1,orderCd:S20170717104850174,orderId:21714","returnCode":"200","returnMsg":"200"}
                     */
                    String result = restTemplate.postForObject(url, map, String.class);
                    Map<String, Object> resultMap = convertJsonStrToMap(result);
                    Map<String, Object> dataMap = (Map<String, Object>) resultMap.get("data");
                    if (dataMap.get("orderCreateStatus").equals("1")) {
                        String ordersNo = (String) dataMap.get("orderId");
                        ExtraBill bill2 = extraBillService.selectByPrimaryKey((Long) bill.get("id"));
                        bill2.setBillsNo(ordersNo);
                        bill2.setBillStatus(ComNames.EXTRA_BILL_STATUS_4);
                        status = transactionManager.getTransaction(def);
                        extraBillService.updateByPrimaryKeySelective(bill2);
                        transactionManager.commit(status);
                        count++;
                    } else {
                        LogUtil.syslog(sqlSession, "推送增值订单失败_神州易桥", "订单号:" + bill.get("bill_id") + "推送失败,错误信息:" + resultMap.get("returnMsg"));
                        continue;
                    }
                }
                LogUtil.syslog(sqlSession, "推送增值订单_神州易桥", "推送成功,推送" + Extrabills.size() + "条,成功" + count + "条。");
            }
        } catch (Exception e) {
            LogUtil.syslog(sqlSession, "推送增值订单失败_神州易桥", "错误:" + e.toString());
            e.printStackTrace();
        } finally {
            if (status != null && !status.isCompleted()) {
                transactionManager.rollback(status);
            }
        }
    }
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) HashMap(java.util.HashMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ExtraBill(com.itrus.portal.db.ExtraBill) ArrayList(java.util.ArrayList) TransactionStatus(org.springframework.transaction.TransactionStatus) SignatureException(java.security.SignatureException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExtraProduct(com.itrus.portal.db.ExtraProduct) HashMap(java.util.HashMap) Map(java.util.Map) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Example 62 with ExtraProduct

use of com.itrus.portal.db.ExtraProduct in project portal by ixinportal.

the class SZYQBillTask method queryBills.

// 2.批量查询订单状态
public void queryBills() {
    synchronized (SZYQBillTaskLock) {
        // start------------处理双机互斥----------
        if (null == taskFlag) {
            taskFlag = systemConfigService.isTimedTaskHost();
        }
        if (taskFlag.equals(false)) {
            return;
        }
        // end------------处理双机互斥----------
        // 1.查找是神州易桥接口的产品.然后遍历这些产品,根据产品查找订单,
        List<ExtraProduct> products = new ArrayList<>();
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = null;
        try {
            products = extraProductService.getExtraProductBySIN(ComNames.SERVICE_INTERFACE_NAME_SZYQQYDB);
            if (null == products || products.isEmpty()) {
                return;
            }
            Integer count = 0;
            for (ExtraProduct product : products) {
                Map<String, Object> paramMap = new HashMap<String, Object>();
                paramMap.put("productId", product.getId());
                paramMap.put("isquery", 1);
                paramMap.put("limit", 20);
                // 2.查找是该产品的订单,并且订单状态是:服务商审核中4,撤销订单中8
                List<Map<String, Object>> Extrabills = sqlSession.selectList("com.itrus.portal.db.ExtraBillMapper.selectByCondition_SZYQ", paramMap);
                if (null == Extrabills || Extrabills.isEmpty()) {
                    continue;
                }
                // 平台编号
                String system_code = product.getServiceId();
                // key
                if (product.getServiceSecret() != null) {
                    product.setServiceSecret(AESencrp.decrypt(product.getServiceSecret(), dbEncKey));
                }
                String key = product.getServiceSecret();
                // url
                String url = product.getServiceAddress() + "/city-api/order/queryOrderStatus";
                // 3.封装参数,发送数据到第三方平台.根据返回值是否成功,如果成功就修改订单状态和审核时间,事物提交.
                for (Map<String, Object> bill : Extrabills) {
                    // 加密串md5(key+时间戳+参数)
                    String sign = new String();
                    // 时间戳
                    long ts = System.currentTimeMillis();
                    String param = "";
                    /**
                     *		param = "{\"orderId\":\""
                     *				+21715+"\","
                     *				+"\"tworderId\":\""
                     *				+"TWCXEB5666456456"+ "\","
                     *				+"\"phone\":\""
                     *				+ "18878996651" + "\""
                     *				+  "}";
                     */
                    param = "{\"orderId\":\"" + bill.get("bills_no").toString() + "\"," + "\"tworderId\":\"" + bill.get("bill_id").toString() + "\"," + "\"phone\":\"" + bill.get("m_phone").toString() + "\"" + "}";
                    LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
                    String signAndtime = ts + param;
                    sign = sign(signAndtime, key, "utf-8");
                    map.add("sign", sign);
                    map.add("ts", ts);
                    map.add("system_code", system_code);
                    map.add("param", param);
                    // TODO 发送到第三方平台
                    /**
                     * { " orderCreateStatus ":"1", //订单生成状态(1成功,0失败)
                     * " ordersNo ":"112233", //订单编号 }
                     */
                    // {"returnCode":200,"returnMsg":"执行成功","data":{"ordersState":2,"ordersNo":"S20170717105409304","tworderId":"TWCXEB5666456456","cancelReason":"","orderId":21715}}
                    String result = restTemplate.postForObject(url, map, String.class);
                    Map<String, Object> resultMap = convertJsonStrToMap(result);
                    Map<String, Object> dataMap = (Map<String, Object>) resultMap.get("data");
                    // TODO 发送到第三方平台
                    /**
                     *								{
                     *									"ordersNo":"订单编号"
                     *								"tworderId ": "天威订单id",
                     *									"ordersState":4,  //订单状态  1服务处理中2.撤销订单失败3、撤销成功 4、处理完成
                     *								    "cancelReason":"撤销原因"
                     *								}
                     *								String result = "{\"ordersNo\":\"" + "订单编号"  + "\","
                     *								+ "\"tworderId\":\"" + "天威订单id" + "\","
                     *								+ "\"ordersState\":\"" + 4 + "\","
                     *								+ "\"cancelReason\":\"" + "撤销原因" + "\""
                     *								+ "}";
                     */
                    ExtraBill bill2 = extraBillService.selectByPrimaryKey((Long) bill.get("id"));
                    Long ordersState = Long.parseLong(dataMap.get("ordersState").toString());
                    if (null == ordersState) {
                        LogUtil.syslog(sqlSession, "批量查询订单失败_神州易桥", "订单号:" + bill.get("bill_id") + "推送失败,错误信息:返回的订单状态为null, 返回的信息:" + resultMap.get("returnMsg"));
                        continue;
                    }
                    // 原本是服务商审核中,可能的状态是已完成或者服务商审核中
                    if (bill2.getBillStatus().equals(ComNames.EXTRA_BILL_STATUS_4)) {
                        if (ordersState.equals(ORDER_STATUS_4)) {
                            if (null != bill2.geteInvoice()) {
                                // 订单需要开票.判断是否开票了.
                                Boolean isinvoiced = bill2.getIsInvoiced();
                                if (null == isinvoiced || isinvoiced.equals(false)) {
                                    bill2.setBillStatus(ComNames.EXTRA_BILL_STATUS_6);
                                } else {
                                    bill2.setBillStatus(ComNames.EXTRA_BILL_STATUS_7);
                                    bill2.setFinishTime(new Date());
                                }
                            } else {
                                // 订单不需要开票,直接完成
                                bill2.setBillStatus(ComNames.EXTRA_BILL_STATUS_7);
                                bill2.setFinishTime(new Date());
                            }
                        } else if (ordersState.equals(ORDER_STATUS_1)) {
                        }
                    } else if (bill2.getBillStatus().equals(ComNames.EXTRA_BILL_STATUS_8)) {
                        // 原本是撤销订单中,可能返回的状态是撤销成功,或者撤销失败
                        if (ordersState.equals(ORDER_STATUS_2)) {
                            // 撤销订单失败
                            bill2.setBillStatus(ComNames.EXTRA_BILL_STATUS_10);
                        } else if (ordersState.equals(ORDER_STATUS_3)) {
                            // 撤销订单成功
                            bill2.setBillStatus(ComNames.EXTRA_BILL_STATUS_9);
                        }
                    }
                    count++;
                    status = transactionManager.getTransaction(def);
                    extraBillService.updateByPrimaryKeySelective(bill2);
                    transactionManager.commit(status);
                }
                LogUtil.syslog(sqlSession, "批量查询订单_神州易桥", "查询成功,查询" + Extrabills.size() + "条,成功" + count + "条。");
            }
        } catch (Exception e) {
            LogUtil.syslog(sqlSession, "批量查询订单_神州易桥", "错误:" + e.toString());
            e.printStackTrace();
        } finally {
            if (status != null && !status.isCompleted()) {
                transactionManager.rollback(status);
            }
        }
    }
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) HashMap(java.util.HashMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ExtraBill(com.itrus.portal.db.ExtraBill) ArrayList(java.util.ArrayList) TransactionStatus(org.springframework.transaction.TransactionStatus) Date(java.util.Date) SignatureException(java.security.SignatureException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExtraProduct(com.itrus.portal.db.ExtraProduct) HashMap(java.util.HashMap) Map(java.util.Map) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Aggregations

ExtraProduct (com.itrus.portal.db.ExtraProduct)62 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)44 HashMap (java.util.HashMap)28 ExtraBill (com.itrus.portal.db.ExtraBill)25 Enterprise (com.itrus.portal.db.Enterprise)24 UserInfo (com.itrus.portal.db.UserInfo)24 IOException (java.io.IOException)20 Project (com.itrus.portal.db.Project)17 ArrayList (java.util.ArrayList)16 ExtraProductSpec (com.itrus.portal.db.ExtraProductSpec)14 HttpSession (javax.servlet.http.HttpSession)14 File (java.io.File)13 BusinessLicense (com.itrus.portal.db.BusinessLicense)12 OpenBankInfo (com.itrus.portal.db.OpenBankInfo)12 TaxRegisterCert (com.itrus.portal.db.TaxRegisterCert)12 UserInfoServiceException (com.itrus.portal.exception.UserInfoServiceException)12 IdentityCard (com.itrus.portal.db.IdentityCard)11 ServiceProvider (com.itrus.portal.db.ServiceProvider)11 OrgCode (com.itrus.portal.db.OrgCode)10 UserinfoEnterprise (com.itrus.portal.db.UserinfoEnterprise)10