提交代码

dev-discount
胡锐 2 years ago
parent 2d00072777
commit ace890c376
  1. 2
      hai-bweb/src/main/java/com/bweb/controller/HighOrderController.java
  2. 2
      hai-cweb/src/main/java/com/cweb/controller/HighTestController.java
  3. 2
      hai-cweb/src/main/java/com/cweb/controller/pay/OrderController.java
  4. 13
      hai-cweb/src/main/java/com/cweb/controller/pay/UnionPayController.java
  5. 21
      hai-cweb/src/test/common/test.java
  6. 49
      hai-service/src/main/java/com/hai/config/MqttProviderConfig.java
  7. 19
      hai-service/src/main/java/com/hai/config/ZkcPrinterTemplate.java
  8. 2
      hai-service/src/main/java/com/hai/service/HighOrderService.java
  9. 52
      hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java
  10. 41
      hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java

@ -90,7 +90,7 @@ public class HighOrderController {
// 1. 热敏打印机 2. 云打印机
if (printType == 2) {
highOrderService.printGasOrder(order.getHighChildOrderList().get(0).getGoodsId(), order.getOrderNo());
highOrderService.printGasOrder(order.getHighChildOrderList().get(0).getGoodsId(), order);
}
return ResponseMsgUtil.success("操作成功");

File diff suppressed because one or more lines are too long

@ -223,7 +223,7 @@ public class OrderController {
} else {
weChatPayReqInfo.setSub_mch_id(wxMerNumber.getCodeValue());
}
profitSharing = "Y";
profitSharing = "N";
// 查询油站
HighMerchantStoreModel store = merchantStoreService.getMerchantStoreById(order.getHighChildOrderList().get(0).getGoodsId());

@ -305,10 +305,6 @@ public class UnionPayController {
this.redisTemplate.boundListOps(MsgTopic.MerStoreAccount.getName()).leftPush(pushParam);
}
new Thread(() -> {
highOrderService.printGasOrder(store.getId(), order.getOrderNo());
}).start();
} else if (store.getSourceType().equals(2)) {
// 推送团油订单
Map<String,Object> paramMap = new HashMap<>();
@ -374,11 +370,18 @@ public class UnionPayController {
}
highOrderService.updateOrder(order);
}
if (order.getHighChildOrderList().get(0).getGoodsType().equals(3)) {
new Thread(() -> {
highOrderService.printGasOrder(order.getHighChildOrderList().get(0).getGoodsId(), order);
}).start();
}
}
}
}
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
JSONObject result = new JSONObject();
result.put("resultcode", "00");

@ -7,6 +7,8 @@ import com.hai.common.QRCodeGenerator;
import com.hai.common.utils.DateUtil;
import com.hai.common.utils.HttpsUtils;
import com.hai.common.utils.IDGenerator;
import com.hai.config.MqttProviderConfig;
import com.hai.config.ZkcPrinterTemplate;
import com.hai.entity.*;
import com.hai.service.*;
import org.junit.Test;
@ -35,27 +37,14 @@ import java.util.*;
public class test {
@Resource
private HighUserService highUserService;
private HighOrderService highOrderService;
@Resource
private HighDiscountUserRelService highDiscountUserRelService;
@Resource
private HighDiscountAgentCodeService highDiscountAgentCodeService;
private MqttProviderConfig mqttProviderConfig;
@Test
public void test(){
/* List<HighDiscountAgentCode> codeList = highDiscountAgentCodeService.getDiscountCodeByDiscountAgentId(55L);
List<HighUser> userList = highUserService.getUserList();
public void test() throws Exception{
int num = 0;
for (HighUser user : userList) {
// 领取优惠券
highDiscountUserRelService.receiveDiscount(user.getId(), codeList.get(num).getId());
num++;
}*/
}

@ -1,28 +1,22 @@
package com.hai.config;
import io.netty.handler.codec.mqtt.MqttConnAckVariableHeader;
import io.netty.handler.codec.mqtt.MqttConnectVariableHeader;
import io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader;
import io.netty.handler.codec.mqtt.MqttPublishVariableHeader;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.PostConstruct;
import org.eclipse.paho.client.mqttv3.*;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import java.util.Random;
@Configuration
@Slf4j
public class MqttProviderConfig {
// @Value("${spring.mqtt.username}")
@Value("${spring.mqtt.username}")
private String username;
// @Value("${spring.mqtt.password}")
@Value("${spring.mqtt.password}")
private String password;
// @Value("${spring.mqtt.url}")
@Value("${spring.mqtt.url}")
private String hostUrl;
/* @Value("${spring.mqtt.client.id}")
@ -60,7 +54,7 @@ public class MqttProviderConfig {
MqttConnectOptions options = new MqttConnectOptions();
//是否清空session,设置false表示服务器会保留客户端的连接记录(订阅主题,qos),客户端重连之后能获取到服务器在客户端断开连接期间推送的消息
//设置为true表示每次连接服务器都是以新的身份
options.setCleanSession(false);
options.setCleanSession(true);
//设置连接用户名
options.setUserName(username);
//设置连接密码
@ -69,8 +63,6 @@ public class MqttProviderConfig {
options.setConnectionTimeout(100);
//设置心跳时间 单位为秒,表示服务器每隔 1.5*20秒的时间向客户端发送心跳判断客户端是否在线
options.setKeepAliveInterval(20);
options.setAutomaticReconnect(false);
// 设置遗嘱消息的话题,若客户端和服务器之间的连接意外断开,服务器将发布客户端的遗嘱信息
// options.setWill("willTopic",(clientId + "与服务器断开连接").getBytes(),0,false);
//设置回调
@ -93,13 +85,44 @@ public class MqttProviderConfig {
mqttMessage.setQos(qos);
mqttMessage.setRetained(retained);
mqttMessage.setPayload(message.getBytes());
client.subscribe(topic, qos);
// 主题的目的地,用于发布/订阅信息
MqttTopic mqttTopic = client.getTopic(topic);
//提供一种机制来跟踪消息的传递进度
//用于在以非阻塞方式(在后台运行)执行发布是跟踪消息的传递进度
MqttDeliveryToken token;
//将指定消息发布到主题,但不等待消息传递完成,返回的token可用于跟踪消息的传递状态
//一旦此方法干净地返回,消息就已被客户端接受发布,当连接可用,将在后台完成消息传递
token = mqttTopic.publish(mqttMessage);
token.waitForCompletion();
} catch (MqttException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
public void publish(int qos,boolean retained,String topic,byte[] message) {
if (client == null) {
init();
}
if (!client.isConnected()) {
init();
}
try {
MqttMessage mqttMessage = new MqttMessage();
mqttMessage.setQos(qos);
mqttMessage.setRetained(retained);
mqttMessage.setPayload(message);
// 主题的目的地,用于发布/订阅信息
MqttTopic mqttTopic = client.getTopic(topic);
//提供一种机制来跟踪消息的传递进度
//用于在以非阻塞方式(在后台运行)执行发布是跟踪消息的传递进度
MqttDeliveryToken token;
//将指定消息发布到主题,但不等待消息传递完成,返回的token可用于跟踪消息的传递状态
//一旦此方法干净地返回,消息就已被客户端接受发布,当连接可用,将在后台完成消息传递。
//一旦此方法干净地返回,消息就已被客户端接受发布,当连接可用,将在后台完成消息传递
token = mqttTopic.publish(mqttMessage);
token.waitForCompletion();

@ -23,7 +23,7 @@ public class ZkcPrinterTemplate {
* @param orderPrice 加油金额
* @return
*/
public static String oilCashierStubTemp(String gasName,
public static byte[] oilCashierStubTemp(String gasName,
String orderNo,
String payTime,
String source,
@ -31,7 +31,6 @@ public class ZkcPrinterTemplate {
String oilNo,
String oilLiters,
String orderPrice) throws Exception {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
// 居中
stream.write(0x1B);
@ -55,7 +54,10 @@ public class ZkcPrinterTemplate {
stream.write("--------------------------------".getBytes("UTF-8"));
stream.write(0x0A);
stream.write(("时间:" + payTime).getBytes("UTF-8"));
stream.write(("打印时间:" + DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss")).getBytes("UTF-8"));
stream.write(0x0A);
stream.write(("支付时间:" + payTime).getBytes("UTF-8"));
stream.write(0x0A);
stream.write("来源:嗨森逛".getBytes("UTF-8"));
@ -96,7 +98,7 @@ public class ZkcPrinterTemplate {
stream.write(0x0A);
stream.write(0x0A);
stream.write(0x0A);
return bytes2Hex(getPrinterBytes(stream.toByteArray(), 1, "UTF-8"));
return getPrinterBytes(stream.toByteArray(), 1, "UTF-8");
}
/**
@ -111,7 +113,7 @@ public class ZkcPrinterTemplate {
* @param orderPrice 加油金额
* @return
*/
public static String oilClientStubTemp(String gasName,
public static byte[] oilClientStubTemp(String gasName,
String orderNo,
String payTime,
String source,
@ -143,7 +145,10 @@ public class ZkcPrinterTemplate {
stream.write("--------------------------------".getBytes("UTF-8"));
stream.write(0x0A);
stream.write(("时间:" + payTime).getBytes("UTF-8"));
stream.write(("打印时间:" + DateUtil.date2String(new Date(), "yyyy-MM-dd HH:mm:ss")).getBytes("UTF-8"));
stream.write(0x0A);
stream.write(("支付时间:" + payTime).getBytes("UTF-8"));
stream.write(0x0A);
stream.write("来源:嗨森逛".getBytes("UTF-8"));
@ -184,7 +189,7 @@ public class ZkcPrinterTemplate {
stream.write(0x0A);
stream.write(0x0A);
stream.write(0x0A);
return bytes2Hex(getPrinterBytes(stream.toByteArray(), 1, "UTF-8"));
return getPrinterBytes(stream.toByteArray(), 1, "UTF-8");
}
public static String hexStringToString(String s) {

@ -432,5 +432,5 @@ public interface HighOrderService {
* 打印加油订单
* @param gasId
*/
void printGasOrder(Long gasId, String orderNo);
void printGasOrder(Long gasId, HighOrder order);
}

@ -385,9 +385,6 @@ public class HighOrderServiceImpl implements HighOrderService {
// 扣预存款
this.redisTemplate.boundListOps(MsgTopic.MerStoreAccount.getName()).leftPush(pushParam);
}
new Thread(() -> {
printGasOrder(store.getId(), highOrder.getOrderNo());
}).start();
} else if (store.getSourceType().equals(2)) {
// 推送团油订单
Map<String,Object> paramMap = new HashMap<>();
@ -456,6 +453,8 @@ public class HighOrderServiceImpl implements HighOrderService {
new Thread(() -> {
if (highOrder.getHighChildOrderList().get(0).getGoodsType().equals(3)) {
printGasOrder(highOrder.getHighChildOrderList().get(0).getGoodsId(), highOrder);
Map<String, Object> pushMsg = new HashMap<>();
pushMsg.put("userId", highOrder.getHighChildOrderList().get(0).getGoodsId());
@ -653,9 +652,6 @@ public class HighOrderServiceImpl implements HighOrderService {
// 扣预存款
this.redisTemplate.boundListOps(MsgTopic.MerStoreAccount.getName()).leftPush(pushParam);
}
new Thread(() -> {
printGasOrder(store.getId(), order.getOrderNo());
}).start();
} else if (store.getSourceType().equals(2)) {
// 推送团油订单
@ -700,6 +696,9 @@ public class HighOrderServiceImpl implements HighOrderService {
new Thread(() -> {
if (order.getHighChildOrderList().get(0).getGoodsType().equals(3)) {
printGasOrder(order.getHighChildOrderList().get(0).getGoodsId(), order);
Map<String, Object> pushMsg = new HashMap<>();
pushMsg.put("userId", order.getHighChildOrderList().get(0).getGoodsId());
@ -959,11 +958,6 @@ public class HighOrderServiceImpl implements HighOrderService {
// 扣预存款
this.redisTemplate.boundListOps(MsgTopic.MerStoreAccount.getName()).leftPush(pushParam);
}
new Thread(() -> {
printGasOrder(store.getId(), order.getOrderNo());
}).start();
} else if (store.getSourceType().equals(2)) {
// 推送团油订单
Map<String,Object> paramMap = new HashMap<>();
@ -1032,6 +1026,8 @@ public class HighOrderServiceImpl implements HighOrderService {
new Thread(() -> {
if (order.getHighChildOrderList().get(0).getGoodsType().equals(3)) {
printGasOrder(order.getHighChildOrderList().get(0).getGoodsId(), order);
Map<String, Object> pushMsg = new HashMap<>();
pushMsg.put("userId", order.getHighChildOrderList().get(0).getGoodsId());
@ -1662,9 +1658,7 @@ public class HighOrderServiceImpl implements HighOrderService {
}
@Override
public void printGasOrder(Long gasId, String orderNo) {
// 查询订单
HighOrder order = getOrderByOrderNo(orderNo);
public void printGasOrder(Long gasId, HighOrder order) {
if (order == null) {
return;
}
@ -1714,7 +1708,8 @@ public class HighOrderServiceImpl implements HighOrderService {
if (device.getType().equals(DeviceTypeEnum.type2.getType())) {
new Thread(() -> {
try {
String oilCashierStubTempText = ZkcPrinterTemplate.oilCashierStubTemp(
mqttProviderConfig.publish(2, false, device.getDeviceImei(),
ZkcPrinterTemplate.oilCashierStubTemp(
childOrder.getGoodsName(),
order.getOrderNo(),
DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"),
@ -1723,21 +1718,21 @@ public class HighOrderServiceImpl implements HighOrderService {
childOrder.getGasOilNo(),
childOrder.getGasOilLiters().toString(),
order.getTotalPrice().toString()
);
mqttProviderConfig.publish(2, false, device.getDeviceImei(), ZkcPrinterTemplate.hexStringToString(oilCashierStubTempText));
));
Thread.sleep(6000);
String oilClientStubTempText = ZkcPrinterTemplate.oilClientStubTemp(
childOrder.getGoodsName(),
order.getOrderNo(),
DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"),
"嗨森逛",
childOrder.getGasGunNo(),
childOrder.getGasOilNo(),
childOrder.getGasOilLiters().toString(),
order.getTotalPrice().toString()
);
mqttProviderConfig.publish(2, false, device.getDeviceImei(), ZkcPrinterTemplate.hexStringToString(oilClientStubTempText));
mqttProviderConfig.publish(2, false, device.getDeviceImei(),
ZkcPrinterTemplate.oilClientStubTemp(
childOrder.getGoodsName(),
order.getOrderNo(),
DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"),
"嗨森逛",
childOrder.getGasGunNo(),
childOrder.getGasOilNo(),
childOrder.getGasOilLiters().toString(),
order.getTotalPrice().toString()
));
} catch (Exception e) {
e.getMessage();
@ -1747,7 +1742,6 @@ public class HighOrderServiceImpl implements HighOrderService {
}
}
}
}
public String priceName(Integer num) {

@ -299,10 +299,6 @@ public class GoodsOrderServiceImpl implements PayService {
// 扣预存款
this.redisTemplate.boundListOps(MsgTopic.MerStoreAccount.getName()).leftPush(pushParam);
}
new Thread(() -> {
highOrderService.printGasOrder(store.getId(), order.getOrderNo());
}).start();
} else if (store.getSourceType().equals(2)) {
// 推送团油订单
Map<String,Object> paramMap = new HashMap<>();
@ -416,22 +412,29 @@ public class GoodsOrderServiceImpl implements PayService {
if (order.getHighChildOrderList().get(0).getGoodsType().equals(3)) {
// 加油站
HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreById(order.getHighChildOrderList().get(0).getGoodsId());
if (store != null) {
if (store.getSourceType() != null && store.getSourceType().equals(1)) {
new Thread(() -> {
Map<String, Object> pushMsg = new HashMap<>();
pushMsg.put("userId", order.getHighChildOrderList().get(0).getGoodsId());
Map<String, Object> msgContent = new HashMap<>();
msgContent.put("order", highOrderService.getGasOrderDetail(order.getOrderNo()));
msgContent.put("voice", baiduVoiceService.text2audio(order.getHighChildOrderList().get(0).getGoodsName() + ",收款:" + order.getTotalPrice() + "元"));
pushMsg.put("message", JSONObject.toJSONString(msgContent));
HttpsUtils.doPost("http://127.0.0.1:9901/msg/websocket/websocket", pushMsg, new HashMap<>());
}).start();
new Thread(() -> {
try {
// 加油站
HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreById(order.getHighChildOrderList().get(0).getGoodsId());
if (store != null) {
if (store.getSourceType() != null && store.getSourceType().equals(1)) {
new Thread(() -> {
Map<String, Object> pushMsg = new HashMap<>();
pushMsg.put("userId", order.getHighChildOrderList().get(0).getGoodsId());
Map<String, Object> msgContent = new HashMap<>();
msgContent.put("order", highOrderService.getGasOrderDetail(order.getOrderNo()));
msgContent.put("voice", baiduVoiceService.text2audio(order.getHighChildOrderList().get(0).getGoodsName() + ",收款:" + order.getTotalPrice() + "元"));
pushMsg.put("message", JSONObject.toJSONString(msgContent));
HttpsUtils.doPost("http://127.0.0.1:9901/msg/websocket/websocket", pushMsg, new HashMap<>());
}).start();
}
}
highOrderService.printGasOrder(order.getHighChildOrderList().get(0).getGoodsId(), order);
} catch (Exception e){
}
}
}).start();
if (order.getProfitSharingStatus() == true) {
new Thread(() -> {

Loading…
Cancel
Save