后端修改小票配置打印和小票动态打印

This commit is contained in:
齐天大圣 2024-10-23 16:27:04 +08:00
parent 198c25ea5b
commit 1db289de63
19 changed files with 788 additions and 103 deletions

View File

@ -10,12 +10,20 @@ import com.fuint.business.printer.service.PrinterService;
import com.fuint.business.printer.template.*;
import com.fuint.business.printer.unit.Methods;
import com.fuint.business.printer.vo.OrderPayment;
import com.fuint.business.setting.entity.ReceiptPrinting;
import com.fuint.business.setting.service.ReceiptPrintingService;
import com.fuint.business.userManager.entity.LJUserGrade;
import com.fuint.business.userManager.entity.UserBalance;
import com.fuint.business.userManager.mapper.LJUserGradeMapper;
import com.fuint.business.userManager.mapper.UserBalanceMapper;
import com.fuint.common.dto.AccountInfo;
import com.fuint.common.util.Constants;
import com.fuint.common.util.RedisUtil;
import com.fuint.common.util.TokenUtil;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.ResponseObject;
import com.fuint.repository.mapper.MtUserMapper;
import com.fuint.repository.model.MtUser;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
//import com.yly.print_sdk_librar.RequestMethod;
@ -53,7 +61,17 @@ public class printerController extends BaseController {
@Resource
PrinterService printerService;
@Resource
private ReceiptPrintingService receiptPrintingService;
@Resource
private MtUserMapper mtUserMapper;
@Resource
private UserBalanceMapper userBalanceMapper;
@Resource
private LJUserGradeMapper ljUserGradeMapper;
@GetMapping("callback")
public Map<String, String> callback(Map<String , String> map){
log.info("------print/callback-------");
@ -256,13 +274,23 @@ public class printerController extends BaseController {
// PrintOilOrderReport.setHandover(handover);
// Integer random6 = (int) ((Math.random() * 9 + 1) * 100000);
// String url=m.print("4004872261", PrintOilOrderReport.printOilOrder(), "Z"+System.currentTimeMillis()+random6.toString());
printerService.oilOrderReport(oilOrder,TokenUtil.getNowAccountInfo().getStoreId());
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
ReceiptPrinting receiptPrinting = receiptPrintingService.queryReceiptPrintingOne(nowAccountInfo.getStoreId());
MtUser mtUser=mtUserMapper.selectByPhone("13964068390");
UserBalance userBalance=userBalanceMapper.getUserBalanceByUserId(mtUser.getId().toString());
LJUserGrade ljUserGrade= ljUserGradeMapper.getUserGradeByUserId(userBalance.getGradeId().toString());
printerService.oilOrderReport(oilOrder,TokenUtil.getNowAccountInfo().getStoreId(),receiptPrinting,mtUser,userBalance,ljUserGrade);
}
@PostMapping("rePrintOilOrderReport")
public void reOilOrderReport(@RequestBody Map<String, Object> oilOrder) {
printerService.reOilOrderReport(oilOrder,TokenUtil.getNowAccountInfo().getStoreId());
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
ReceiptPrinting receiptPrinting = receiptPrintingService.queryReceiptPrintingOne(nowAccountInfo.getStoreId());
MtUser mtUser=mtUserMapper.selectByPhone("13964068390");
UserBalance userBalance=userBalanceMapper.getUserBalanceByUserId(mtUser.getId().toString());
LJUserGrade ljUserGrade= ljUserGradeMapper.getUserGradeByUserId(userBalance.getGradeId().toString());
printerService.reOilOrderReport(oilOrder,TokenUtil.getNowAccountInfo().getStoreId(),receiptPrinting,mtUser,userBalance,ljUserGrade);
}
/**
* 余额充值订单
@ -278,7 +306,12 @@ public class printerController extends BaseController {
// PrintCardValueReport.setHandover(cardValue);
// Integer random6 = (int) ((Math.random() * 9 + 1) * 100000);
// String url=m.print("4004872261", PrintCardValueReport.printOilOrder(), "Z"+System.currentTimeMillis()+random6.toString());
printerService.printCardValueReport(cardValue, TokenUtil.getNowAccountInfo().getStoreId());
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
ReceiptPrinting receiptPrinting = receiptPrintingService.queryReceiptPrintingOne(nowAccountInfo.getStoreId());
MtUser mtUser=mtUserMapper.selectByPhone("13964068390");
UserBalance userBalance=userBalanceMapper.getUserBalanceByUserId(mtUser.getId().toString());
LJUserGrade ljUserGrade= ljUserGradeMapper.getUserGradeByUserId(userBalance.getGradeId().toString());
printerService.printCardValueReport(cardValue, TokenUtil.getNowAccountInfo().getStoreId(),receiptPrinting,mtUser,userBalance,ljUserGrade);
}
/**

View File

@ -86,6 +86,6 @@ public interface PrintDeviceInfoMapper extends BaseMapper<PrintDeviceInfo> {
int getIsAcquiesceByStoreId(Integer storeId);
List<PrintDeviceInfo> getInfoListByStoreId(Integer storeId);
}

View File

@ -254,10 +254,14 @@ machine_code = values(machine_code)msign = values(msign)device_name = values(dev
<update id="updateIsAcquiesce">
update print_device_info set acquiesce = false where store_id = #{storeId}
</update>
<select id="getIsAcquiesceByStoreId" resultType="java.lang.Integer">
</select>
<select id="getInfoListByStoreId" resultType="com.fuint.business.printer.entity.PrintDeviceInfo">
select
id,machine_code,msign,device_name,user_id,app_key,app_secret,app_public_key,platform_public_key,access_token,payment,create_time,update_time,create_by,update_by,store_id ,acquiesce from print_device_info
where store_id = #{storeId} limit 1
</select>
</mapper>

View File

@ -1,5 +1,9 @@
package com.fuint.business.printer.service;
import com.fuint.business.setting.entity.ReceiptPrinting;
import com.fuint.business.userManager.entity.LJUserGrade;
import com.fuint.business.userManager.entity.UserBalance;
import com.fuint.repository.model.MtUser;
import org.springframework.web.bind.annotation.RequestParam;
import java.math.BigDecimal;
@ -22,12 +26,12 @@ public interface PrinterService {
String printIndex(BigDecimal payAmount,Integer storeId);
void getHandover(Map<String, Object> handover,Integer storeId);
void oilOrderReport(Map<String, Object> handover,Integer storeId);
void reOilOrderReport(Map<String, Object> oilOrder, Integer storeId);
void oilOrderReport(Map<String, Object> handover, Integer storeId, ReceiptPrinting receiptPrinting, MtUser mtUser, UserBalance userBalance, LJUserGrade ljUserGrade);
void reOilOrderReport(Map<String, Object> oilOrder, Integer storeId, ReceiptPrinting receiptPrinting, MtUser mtUser, UserBalance userBalance, LJUserGrade ljUserGrade);
void printTagReport(Map<String, Object> integral,Integer storeId);
void printCardValueReport(Map<String, Object> printCardValue,Integer storeId);
void printCardValueReport(Map<String, Object> printCardValue,Integer storeId, ReceiptPrinting receiptPrinting, MtUser mtUser, UserBalance userBalance, LJUserGrade ljUserGrade);
void printFuelDieselReport(Map<String, Object> printCardValue,Integer storeId);

View File

@ -4,6 +4,8 @@ import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.internal.util.codec.Base64;
import com.fuint.business.order.mapper.AllOrderInfoMapper;
import com.fuint.business.order.vo.AllOrderInfoVo;
import com.fuint.business.printer.entity.PrintDeviceInfo;
import com.fuint.business.printer.mapper.PrintDeviceInfoMapper;
import com.fuint.business.printer.service.PrintDeviceInfoService;
@ -11,7 +13,11 @@ import com.fuint.business.printer.service.PrinterService;
import com.fuint.business.printer.template.*;
import com.fuint.business.printer.unit.Methods;
import com.fuint.business.printer.vo.OrderPayment;
import com.fuint.business.setting.entity.ReceiptPrinting;
import com.fuint.business.userManager.entity.LJUserGrade;
import com.fuint.business.userManager.entity.UserBalance;
import com.fuint.common.util.RedisUtil;
import com.fuint.repository.model.MtUser;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yly.print_sdk_library.RequestMethod;
@ -53,6 +59,8 @@ public class PrinterServiceImpl implements PrinterService {
PrintDeviceInfoService printDeviceInfoService;
@Resource
PrintDeviceInfoMapper printDeviceInfoMapper;
@Resource
private AllOrderInfoMapper allOrderInfoMapper;
@Override
public Map<String, String> PostPush(String ciphertext, String nonce, String tag, String additional_data, String iv, String signature) {
@ -227,9 +235,9 @@ public class PrinterServiceImpl implements PrinterService {
}
}
public void oilOrderReport(Map<String, Object> oilOrder,Integer storeId) {
public void oilOrderReport(Map<String, Object> oilOrder, Integer storeId,ReceiptPrinting receiptPrinting, MtUser mtUser, UserBalance userBalance, LJUserGrade ljUserGrade) {
PrintDeviceInfo infoByStoreId = printDeviceInfoMapper.getInfoByStoreId(storeId);
AllOrderInfoVo allOrderInfoVo=allOrderInfoMapper.getOneByOrderNo("234520241023114642fc06e4");
Methods m=Methods.getInstance();
Object accessToken = RedisUtil.get("scancodemodel+" + storeId);
if (ObjectUtil.isNotEmpty(accessToken)) {
@ -244,7 +252,7 @@ public class PrinterServiceImpl implements PrinterService {
m.init(infoByStoreId.getAppKey(), infoByStoreId.getAppSecret());
PrintOilOrderReport.setHandover(oilOrder);
Integer random6 = (int) ((Math.random() * 9 + 1) * 100000);
String url=m.print(infoByStoreId.getMachineCode(), PrintOilOrderReport.printOilOrder(), "Z"+System.currentTimeMillis()+random6.toString());
String url=m.print(infoByStoreId.getMachineCode(), PrintOilOrderReport.printOilOrder(receiptPrinting,mtUser,userBalance,ljUserGrade,allOrderInfoVo), "Z"+System.currentTimeMillis()+random6.toString());
if (ObjectUtil.isNotEmpty(url)) {
// 使用 Fastjson JSON 字符串解析为 JSONObject
JSONObject jsonObject = JSON.parseObject(url);
@ -252,14 +260,14 @@ public class PrinterServiceImpl implements PrinterService {
String error = jsonObject.getString("error");
if ("18".equals(error)) {
getToken(storeId);
reOilOrderReport(oilOrder,storeId);
oilOrderReport(oilOrder,storeId,receiptPrinting,mtUser,userBalance,ljUserGrade);
}
}
}
public void reOilOrderReport(Map<String, Object> oilOrder,Integer storeId) {
public void reOilOrderReport(Map<String, Object> oilOrder,Integer storeId,ReceiptPrinting receiptPrinting, MtUser mtUser, UserBalance userBalance, LJUserGrade ljUserGrade) {
PrintDeviceInfo infoByStoreId = printDeviceInfoMapper.getInfoByStoreId(storeId);
AllOrderInfoVo allOrderInfoVo=allOrderInfoMapper.getOneByOrderNo("234520241023114642fc06e4");
Methods m=Methods.getInstance();
Object accessToken = RedisUtil.get("scancodemodel+" + storeId);
if (ObjectUtil.isNotEmpty(accessToken)) {
@ -275,7 +283,7 @@ public class PrinterServiceImpl implements PrinterService {
m.init(infoByStoreId.getAppKey(), infoByStoreId.getAppSecret());
RePrintOilOrderReport.setHandover(oilOrder);
Integer random6 = (int) ((Math.random() * 9 + 1) * 100000);
String url=m.print(infoByStoreId.getMachineCode(), RePrintOilOrderReport.rePrintOilOrder(), "Z"+System.currentTimeMillis()+random6.toString());
String url=m.print(infoByStoreId.getMachineCode(), RePrintOilOrderReport.rePrintOilOrder(receiptPrinting,mtUser,userBalance,ljUserGrade,allOrderInfoVo), "Z"+System.currentTimeMillis()+random6.toString());
if (ObjectUtil.isNotEmpty(url)) {
// 使用 Fastjson JSON 字符串解析为 JSONObject
JSONObject jsonObject = JSON.parseObject(url);
@ -283,16 +291,16 @@ public class PrinterServiceImpl implements PrinterService {
String error = jsonObject.getString("error");
if ("18".equals(error)) {
getToken(storeId);
reOilOrderReport(oilOrder,storeId);
reOilOrderReport(oilOrder,storeId,receiptPrinting,mtUser,userBalance,ljUserGrade);
}
}
}
public void printCardValueReport(Map<String, Object> cardValue,Integer storeId) {
public void printCardValueReport(Map<String, Object> cardValue,Integer storeId,ReceiptPrinting receiptPrinting, MtUser mtUser, UserBalance userBalance, LJUserGrade ljUserGrade) {
PrintDeviceInfo infoByStoreId = printDeviceInfoMapper.getInfoByStoreId(storeId);
AllOrderInfoVo allOrderInfoVo=allOrderInfoMapper.getOneByOrderNo("234520241023114642fc06e4");
log.info("handover:{}",cardValue.toString());
Methods m=Methods.getInstance();
Object accessToken = RedisUtil.get("scancodemodel+" + storeId);
@ -309,7 +317,7 @@ public class PrinterServiceImpl implements PrinterService {
m.init(infoByStoreId.getAppKey(), infoByStoreId.getAppSecret());
PrintCardValueReport.setHandover(cardValue);
Integer random6 = (int) ((Math.random() * 9 + 1) * 100000);
String url=m.print(infoByStoreId.getMachineCode(), PrintCardValueReport.printOilOrder(), "Z"+System.currentTimeMillis()+random6.toString());
String url=m.print(infoByStoreId.getMachineCode(), PrintCardValueReport.printOilOrder(receiptPrinting,mtUser,userBalance,ljUserGrade,allOrderInfoVo), "Z"+System.currentTimeMillis()+random6.toString());
if (ObjectUtil.isNotEmpty(url)) {
// 使用 Fastjson JSON 字符串解析为 JSONObject
JSONObject jsonObject = JSON.parseObject(url);
@ -317,7 +325,7 @@ public class PrinterServiceImpl implements PrinterService {
String error = jsonObject.getString("error");
if ("18".equals(error)) {
getToken(storeId);
reOilOrderReport(cardValue,storeId);
printCardValueReport(cardValue,storeId,receiptPrinting,mtUser,userBalance,ljUserGrade);
}
}
@ -349,7 +357,7 @@ public class PrinterServiceImpl implements PrinterService {
String error = jsonObject.getString("error");
if ("18".equals(error)) {
getToken(storeId);
reOilOrderReport(fuelDiesel,storeId);
printFuelDieselReport(fuelDiesel,storeId);
}
}
@ -382,7 +390,7 @@ public class PrinterServiceImpl implements PrinterService {
String error = jsonObject.getString("error");
if ("18".equals(error)) {
getToken(storeId);
reOilOrderReport(integral,storeId);
printIntegralReport(integral,storeId);
}
}
@ -424,7 +432,7 @@ public class PrinterServiceImpl implements PrinterService {
String error = jsonObject.getString("error");
if ("18".equals(error)) {
getToken(storeId);
reOilOrderReport(integral,storeId);
printTagReport(integral,storeId);
}
}

View File

@ -1,19 +1,26 @@
package com.fuint.business.printer.template;
import cn.hutool.core.util.ObjectUtil;
import com.fuint.business.order.vo.AllOrderInfoVo;
import com.fuint.business.setting.entity.ReceiptPrinting;
import com.fuint.business.userManager.entity.LJUserGrade;
import com.fuint.business.userManager.entity.UserBalance;
import com.fuint.common.dto.AccountInfo;
import com.fuint.common.util.TokenUtil;
import com.fuint.repository.model.MtUser;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class PrintCardValueReport {
public static Map<String, Object> handover = new HashMap<>();
public static String printOilOrder() {
StringBuilder sb = new StringBuilder();
public static String printOilOrder(ReceiptPrinting receiptPrinting, MtUser mtUser, UserBalance userBalance, LJUserGrade ljUserGrade,
AllOrderInfoVo allOrderInfoVo) {
/* StringBuilder sb = new StringBuilder();
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedDateTime = now.format(formatter);
@ -55,7 +62,130 @@ public class PrintCardValueReport {
sb.append("<center>谢谢惠顾,欢迎下次光临!</center>");
return sb.toString();
return sb.toString();*/
StringBuilder sb=new StringBuilder();
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedDateTime = now.format(formatter);
System.out.println("当前时间:" + formattedDateTime);
// AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
if(allOrderInfoVo.getPayChannel().equals("applet") && allOrderInfoVo.getContent().equals("油品订单")){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("zzzzz","一键加油"));
}else {
if(allOrderInfoVo.getContent().equals("收银台订单")){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("zzzzz","收银台消费"));
}
if(allOrderInfoVo.getContent().equals("储值卡充值")){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("zzzzz","会员充值"));
}
}
System.out.println( receiptPrinting.getPrintTemplateTop());
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("xxxxx","32131566313655"));
if(mtUser.getUserNo()!=null){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("kkkkk",mtUser.getUserNo()));
}else {
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("卡号:kkkkk\r\n",""));
}
if(mtUser.getCarNo()!=null){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("ccccc",mtUser.getCarNo()));
}else {
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("车牌号:ccccc\r\n",""));
}
if(ljUserGrade.getName()!=null){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("ddddd",ljUserGrade.getName()));
}else {
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("等级:ddddd\r\n",""));
}
if(mtUser.getMobile()!=null){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("sssss",mtUser.getMobile()));
}else {
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("手机号:sssss\r\n",""));
}
if(userBalance.getCardBalance().toString()!=null){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("yyyyy",userBalance.getCardBalance().toString()));
}else {
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("余额:yyyyy\r\n",""));
}
if(userBalance.getPoints().toString()!=null){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("jjjjj",userBalance.getPoints().toString()));
}else {
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("积分:jjjjj\r\n",""));
}
if (ObjectUtil.isNotEmpty(handover.get("oilOrder"))) {
sb.append("<table><tr><td>油品</td><td>金额</td></tr>");
List<Map<String,String>> o = (List<Map<String,String>>)handover.get("oilOrder");
for (Map<String, String> stringStringMap : o) {
sb.append("<tr><td>"+stringStringMap.get("oilName")+"</td>");
sb.append("<td>¥"+ stringStringMap.get("amount")+"</td></tr>");
}
sb.append("</table>");
sb.append("--------------------------------\r\n");
}
if (ObjectUtil.isNotEmpty(handover.get("goodsOrder"))) {
sb.append("<table><tr><td>商品</td><td>数量</td><td>单价</td></tr>");
List<Map<String,String>> o = (List<Map<String,String>>)handover.get("goodsOrder");
for (Map<String, String> stringStringMap : o) {
sb.append("<tr><td>"+stringStringMap.get("oilName")+"</td>");
sb.append("<td>"+stringStringMap.get("unit")+"</td>");
sb.append("<td>"+ stringStringMap.get("amount")+"</td></tr>");
}
sb.append("</table>");
sb.append("--------------------------------\r\n");
}
sb.append("支付方式:"+handover.get("payType")+"\r\n");
if ("credit".equals(handover.get("payType"))) {
sb.append("挂账单位:"+handover.get("unitName")+"\r\n");
sb.append("挂账金额:¥"+handover.get("creditAmount")+"\r\n");
sb.append("--------------------------------\r\n");
}
// if (ObjectUtil.isNotEmpty(handover.get("discount"))) {
// sb.append("订单总额:¥"+handover.get("discount")+"\r\n");
// sb.append("------------------------------------\r\n");
//
// }
if (ObjectUtil.isNotEmpty(handover.get("discount"))) {
sb.append("优惠合计:¥"+handover.get("discount")+"\r\n");
sb.append("--------------------------------\r\n");
}
if (ObjectUtil.isNotEmpty(handover.get("amount"))) {
sb.append("总金额:¥"+handover.get("amount")+"\r\n");
sb.append("--------------------------------\r\n");
}
if (ObjectUtil.isNotEmpty(handover.get("consumeAmount"))) {
sb.append("储值卡付款:¥"+handover.get("consumeAmount")+"\r\n");
sb.append("--------------------------------\r\n");
}
if (ObjectUtil.isNotEmpty(handover.get("consumeRefuelMoney"))) {
sb.append("囤油卡付款:¥"+handover.get("consumeRefuelMoney")+"\r\n");
sb.append("--------------------------------\r\n");
}
if (ObjectUtil.isNotEmpty(handover.get("actualPay"))) {
sb.append("实付款:¥"+handover.get("actualPay")+"\r\n");
sb.append("--------------------------------\r\n");
}
if (ObjectUtil.isNotEmpty(handover.get("seekZero"))) {
sb.append("找零:¥"+handover.get("seekZero")+"\r\n");
sb.append("--------------------------------\r\n");
}
receiptPrinting.setPrintTemplateDown(receiptPrinting.getPrintTemplateDown().
replace("ttttt",formattedDateTime));
return receiptPrinting.getPrintTemplateTop()+sb.toString()+receiptPrinting.getPrintTemplateDown();
}
public static Map<String, Object> getHandover() {
return handover;

View File

@ -1,8 +1,13 @@
package com.fuint.business.printer.template;
import cn.hutool.core.util.ObjectUtil;
import com.fuint.business.order.vo.AllOrderInfoVo;
import com.fuint.business.setting.entity.ReceiptPrinting;
import com.fuint.business.userManager.entity.LJUserGrade;
import com.fuint.business.userManager.entity.UserBalance;
import com.fuint.common.dto.AccountInfo;
import com.fuint.common.util.TokenUtil;
import com.fuint.repository.model.MtUser;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@ -10,25 +15,138 @@ import java.util.*;
public class PrintOilOrderReport {
public static Map<String, Object> handover = new HashMap<>();
public static String printOilOrder(){
public static String printOilOrder(ReceiptPrinting receiptPrinting, MtUser mtUser, UserBalance userBalance, LJUserGrade ljUserGrade,
AllOrderInfoVo allOrderInfoVo){
// StringBuilder sb=new StringBuilder();
//
//
// LocalDateTime now = LocalDateTime.now();
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// String formattedDateTime = now.format(formatter);
// System.out.println("当前时间:" + formattedDateTime);
// AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
// sb.append("<center>订单统计\r\n</center>");
// sb.append("打印时间:"+formattedDateTime +"\r\n");
// sb.append("店铺名称:"+nowAccountInfo.getStoreName() +"\r\n");
// sb.append("--------------------------------\r\n");
// if (ObjectUtil.isNotEmpty(handover.get("oilOrder"))) {
// sb.append("<table><tr><td>油品</td><td>金额</td></tr>");
// List<Map<String,String>> o = (List<Map<String,String>>)handover.get("oilOrder");
// for (Map<String, String> stringStringMap : o) {
// sb.append("<tr><td>"+stringStringMap.get("oilName")+"</td>");
// sb.append("<td>¥"+ stringStringMap.get("amount")+"</td></tr>");
// }
// sb.append("</table>");
// sb.append("--------------------------------\r\n");
// }
// if (ObjectUtil.isNotEmpty(handover.get("goodsOrder"))) {
// sb.append("<table><tr><td>商品</td><td>数量</td><td>单价</td></tr>");
// List<Map<String,String>> o = (List<Map<String,String>>)handover.get("goodsOrder");
// for (Map<String, String> stringStringMap : o) {
// sb.append("<tr><td>"+stringStringMap.get("oilName")+"</td>");
// sb.append("<td>"+stringStringMap.get("unit")+"</td>");
//
// sb.append("<td>"+ stringStringMap.get("amount")+"</td></tr>");
// }
// sb.append("</table>");
// sb.append("--------------------------------\r\n");
// }
// sb.append("支付方式:"+handover.get("payType")+"\r\n");
// if ("credit".equals(handover.get("payType"))) {
// sb.append("挂账单位:"+handover.get("unitName")+"\r\n");
// sb.append("挂账金额:¥"+handover.get("creditAmount")+"\r\n");
// sb.append("--------------------------------\r\n");
// }
//// if (ObjectUtil.isNotEmpty(handover.get("discount"))) {
//// sb.append("订单总额:¥"+handover.get("discount")+"\r\n");
//// sb.append("------------------------------------\r\n");
//// }
// if (ObjectUtil.isNotEmpty(handover.get("discount"))) {
// sb.append("优惠合计:¥"+handover.get("discount")+"\r\n");
// sb.append("--------------------------------\r\n");
//
// }
// if (ObjectUtil.isNotEmpty(handover.get("amount"))) {
// sb.append("总金额:¥"+handover.get("amount")+"\r\n");
// sb.append("--------------------------------\r\n");
//
// }
// if (ObjectUtil.isNotEmpty(handover.get("consumeAmount"))) {
// sb.append("储值卡付款:¥"+handover.get("consumeAmount")+"\r\n");
// sb.append("--------------------------------\r\n");
//
// }
// if (ObjectUtil.isNotEmpty(handover.get("consumeRefuelMoney"))) {
// sb.append("囤油卡付款:¥"+handover.get("consumeRefuelMoney")+"\r\n");
// sb.append("--------------------------------\r\n");
//
// }
// if (ObjectUtil.isNotEmpty(handover.get("actualPay"))) {
// sb.append("实付款:¥"+handover.get("actualPay")+"\r\n");
// sb.append("--------------------------------\r\n");
//
// }
// if (ObjectUtil.isNotEmpty(handover.get("seekZero"))) {
// sb.append("找零:¥"+handover.get("seekZero")+"\r\n");
// sb.append("--------------------------------\r\n");
//
// }
//
// sb.append("<center>谢谢惠顾,欢迎下次光临!</center>");
//
// return sb.toString();
StringBuilder sb=new StringBuilder();
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedDateTime = now.format(formatter);
System.out.println("当前时间:" + formattedDateTime);
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
sb.append("<center>订单统计\r\n</center>");
sb.append("打印时间:"+formattedDateTime +"\r\n");
sb.append("店铺名称:"+nowAccountInfo.getStoreName() +"\r\n");
sb.append("--------------------------------\r\n");
// AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
if(allOrderInfoVo.getPayChannel().equals("applet") && allOrderInfoVo.getContent().equals("油品订单")){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("zzzzz","一键加油"));
}else {
if(allOrderInfoVo.getContent().equals("收银台订单")){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("zzzzz","收银台消费"));
}
if(allOrderInfoVo.getContent().equals("储值卡充值")){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("zzzzz","会员充值"));
}
}
System.out.println( receiptPrinting.getPrintTemplateTop());
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("xxxxx","32131566313655"));
if(mtUser.getUserNo()!=null){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("kkkkk",mtUser.getUserNo()));
}else {
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("卡号:kkkkk\r\n",""));
}
if(mtUser.getCarNo()!=null){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("ccccc",mtUser.getCarNo()));
}else {
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("车牌号:ccccc\r\n",""));
}
if(ljUserGrade.getName()!=null){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("ddddd",ljUserGrade.getName()));
}else {
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("等级:ddddd\r\n",""));
}
if(mtUser.getMobile()!=null){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("sssss",mtUser.getMobile()));
}else {
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("手机号:sssss\r\n",""));
}
if(userBalance.getCardBalance().toString()!=null){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("yyyyy",userBalance.getCardBalance().toString()));
}else {
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("余额:yyyyy\r\n",""));
}
if(userBalance.getPoints().toString()!=null){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("jjjjj",userBalance.getPoints().toString()));
}else {
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("积分:jjjjj\r\n",""));
}
if (ObjectUtil.isNotEmpty(handover.get("oilOrder"))) {
sb.append("<table><tr><td>油品</td><td>金额</td></tr>");
List<Map<String,String>> o = (List<Map<String,String>>)handover.get("oilOrder");
for (Map<String, String> stringStringMap : o) {
@ -87,7 +205,7 @@ public class PrintOilOrderReport {
}
if (ObjectUtil.isNotEmpty(handover.get("actualPay"))) {
sb.append("实付款:¥"+handover.get("actualPay")+"\r\n");
sb.append("实付款:¥"+handover.get("actualPay")+"\r\n");
sb.append("--------------------------------\r\n");
}
@ -96,10 +214,9 @@ public class PrintOilOrderReport {
sb.append("--------------------------------\r\n");
}
sb.append("<center>谢谢惠顾,欢迎下次光临!</center>");
return sb.toString();
receiptPrinting.setPrintTemplateDown(receiptPrinting.getPrintTemplateDown().
replace("ttttt",formattedDateTime));
return receiptPrinting.getPrintTemplateTop()+sb.toString()+receiptPrinting.getPrintTemplateDown();
}
public static Map<String, Object> getHandover() {

View File

@ -1,8 +1,13 @@
package com.fuint.business.printer.template;
import cn.hutool.core.util.ObjectUtil;
import com.fuint.business.order.vo.AllOrderInfoVo;
import com.fuint.business.setting.entity.ReceiptPrinting;
import com.fuint.business.userManager.entity.LJUserGrade;
import com.fuint.business.userManager.entity.UserBalance;
import com.fuint.common.dto.AccountInfo;
import com.fuint.common.util.TokenUtil;
import com.fuint.repository.model.MtUser;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@ -13,32 +18,153 @@ import java.util.Map;
public class RePrintOilOrderReport {
public static Map<String, Object> handover = new HashMap<>();
public static String rePrintOilOrder(){
public static String rePrintOilOrder(ReceiptPrinting receiptPrinting, MtUser mtUser, UserBalance userBalance, LJUserGrade ljUserGrade,
AllOrderInfoVo allOrderInfoVo){
// StringBuilder sb=new StringBuilder();
//
// LocalDateTime now = LocalDateTime.now();
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// String formattedDateTime = now.format(formatter);
// System.out.println("当前时间:" + formattedDateTime);
// AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
//
//
// sb.append("<center>订单统计\r\n</center>");
//
// sb.append("打印时间:"+formattedDateTime +"\r\n");
// sb.append("店铺名称:"+nowAccountInfo.getStoreName() +"\r\n");
// sb.append("----------------------------\r\n");
//
// if (ObjectUtil.isNotEmpty(handover.get("oilOrder"))) {
// sb.append("<table><tr><td>油品</td><td>加油升数</td><td>金额</td></tr>");
// List<Map<String,String>> o = (List<Map<String,String>>)handover.get("oilOrder");
// for (Map<String, String> stringStringMap : o) {
// sb.append("<tr><td>"+stringStringMap.get("oilName")+"</td>");
// sb.append("<td>"+stringStringMap.get("oilNum")+"</td>");
// sb.append("<td>"+ stringStringMap.get("amount")+"</td></tr>");
// }
// sb.append("</table>");
// sb.append("----------------------------\r\n");
//
// }
// if (ObjectUtil.isNotEmpty(handover.get("goodsOrder"))) {
// sb.append("<table><tr><td>商品</td><td>数量</td><td>单价</td></tr>");
// List<Map<String,String>> o = (List<Map<String,String>>)handover.get("goodsOrder");
// for (Map<String, String> stringStringMap : o) {
// sb.append("<tr><td>"+stringStringMap.get("oilName")+"</td>");
// sb.append("<td>"+stringStringMap.get("unit")+"</td>");
// sb.append("<td>"+ stringStringMap.get("amount")+"</td></tr>");
// }
// sb.append("</table>");
// sb.append("----------------------------\r\n");
//
// }
//
// sb.append("支付方式:"+handover.get("payType")+"\r\n");
//
//
// if (ObjectUtil.isNotEmpty(handover.get("amount"))) {
// sb.append("合计:¥"+handover.get("amount")+"\r\n");
// sb.append("----------------------------\r\n");
//
// }
// if (ObjectUtil.isNotEmpty(handover.get("payAmount"))) {
// sb.append("实付款:¥"+handover.get("payAmount")+"\r\n");
// sb.append("----------------------------\r\n");
//
// }
// if (ObjectUtil.isNotEmpty(handover.get("discount"))) {
// sb.append("优惠:¥"+handover.get("discount")+"\r\n");
// sb.append("----------------------------\r\n");
//
// }
// if (ObjectUtil.isNotEmpty(handover.get("seekZero"))) {
// sb.append("找零:¥"+handover.get("seekZero")+"\r\n");
// sb.append("----------------------------\r\n");
//
// }
//
// if (ObjectUtil.isNotEmpty(handover.get("type")) && "2".equals(handover.get("type"))) {
// if (ObjectUtil.isNotEmpty(handover.get("balanceAmount"))) {
// sb.append("储值卡:¥"+handover.get("balanceAmount")+"\r\n");
// sb.append("----------------------------\r\n");
//
// }
// if (ObjectUtil.isNotEmpty(handover.get("oilCardAmount"))) {
// sb.append("屯油卡:"+handover.get("oilCardAmount")+"L\r\n");
// sb.append("----------------------------\r\n");
//
// }
// if (ObjectUtil.isNotEmpty(handover.get("calculateRefundsV"))) {
// sb.append("退款:¥"+handover.get("calculateRefundsV")+"\r\n");
// sb.append("----------------------------\r\n");
//
// }
// }
// sb.append("<center>谢谢惠顾,欢迎下次光临!</center>");
//
// return sb.toString();
StringBuilder sb=new StringBuilder();
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedDateTime = now.format(formatter);
System.out.println("当前时间:" + formattedDateTime);
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
// AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
if(allOrderInfoVo.getPayChannel().equals("applet") && allOrderInfoVo.getContent().equals("油品订单")){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("zzzzz","一键加油"));
}else {
if(allOrderInfoVo.getContent().equals("收银台订单")){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("zzzzz","收银台消费"));
}
if(allOrderInfoVo.getContent().equals("储值卡充值")){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("zzzzz","会员充值"));
}
}
sb.append("<center>订单统计\r\n</center>");
sb.append("打印时间:"+formattedDateTime +"\r\n");
sb.append("店铺名称:"+nowAccountInfo.getStoreName() +"\r\n");
sb.append("----------------------------\r\n");
System.out.println( receiptPrinting.getPrintTemplateTop());
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("xxxxx","32131566313655"));
if(mtUser.getUserNo()!=null){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("kkkkk",mtUser.getUserNo()));
}else {
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("卡号:kkkkk\r\n",""));
}
if(mtUser.getCarNo()!=null){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("ccccc",mtUser.getCarNo()));
}else {
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("车牌号:ccccc\r\n",""));
}
if(ljUserGrade.getName()!=null){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("ddddd",ljUserGrade.getName()));
}else {
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("等级:ddddd\r\n",""));
}
if(mtUser.getMobile()!=null){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("sssss",mtUser.getMobile()));
}else {
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("手机号:sssss\r\n",""));
}
if(userBalance.getCardBalance().toString()!=null){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("yyyyy",userBalance.getCardBalance().toString()));
}else {
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("余额:yyyyy\r\n",""));
}
if(userBalance.getPoints().toString()!=null){
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("jjjjj",userBalance.getPoints().toString()));
}else {
receiptPrinting.setPrintTemplateTop(receiptPrinting.getPrintTemplateTop().replace("积分:jjjjj\r\n",""));
}
if (ObjectUtil.isNotEmpty(handover.get("oilOrder"))) {
sb.append("<table><tr><td>油品</td><td>加油升数</td><td>金额</td></tr>");
sb.append("<table><tr><td>油品</td><td>金额</td></tr>");
List<Map<String,String>> o = (List<Map<String,String>>)handover.get("oilOrder");
for (Map<String, String> stringStringMap : o) {
sb.append("<tr><td>"+stringStringMap.get("oilName")+"</td>");
sb.append("<td>"+stringStringMap.get("oilNum")+"</td>");
sb.append("<td>"+ stringStringMap.get("amount")+"</td></tr>");
sb.append("<td>¥"+ stringStringMap.get("amount")+"</td></tr>");
}
sb.append("</table>");
sb.append("----------------------------\r\n");
sb.append("--------------------------------\r\n");
}
if (ObjectUtil.isNotEmpty(handover.get("goodsOrder"))) {
@ -47,57 +173,60 @@ public class RePrintOilOrderReport {
for (Map<String, String> stringStringMap : o) {
sb.append("<tr><td>"+stringStringMap.get("oilName")+"</td>");
sb.append("<td>"+stringStringMap.get("unit")+"</td>");
sb.append("<td>"+ stringStringMap.get("amount")+"</td></tr>");
}
sb.append("</table>");
sb.append("----------------------------\r\n");
sb.append("--------------------------------\r\n");
}
sb.append("支付方式:"+handover.get("payType")+"\r\n");
if (ObjectUtil.isNotEmpty(handover.get("amount"))) {
sb.append("合计:¥"+handover.get("amount")+"\r\n");
sb.append("----------------------------\r\n");
if ("credit".equals(handover.get("payType"))) {
sb.append("挂账单位:"+handover.get("unitName")+"\r\n");
sb.append("挂账金额:¥"+handover.get("creditAmount")+"\r\n");
sb.append("--------------------------------\r\n");
}
if (ObjectUtil.isNotEmpty(handover.get("payAmount"))) {
sb.append("实付款:¥"+handover.get("payAmount")+"\r\n");
sb.append("----------------------------\r\n");
}
// if (ObjectUtil.isNotEmpty(handover.get("discount"))) {
// sb.append("订单总额:¥"+handover.get("discount")+"\r\n");
// sb.append("------------------------------------\r\n");
//
// }
if (ObjectUtil.isNotEmpty(handover.get("discount"))) {
sb.append("优惠:¥"+handover.get("discount")+"\r\n");
sb.append("----------------------------\r\n");
sb.append("优惠合计:¥"+handover.get("discount")+"\r\n");
sb.append("--------------------------------\r\n");
}
if (ObjectUtil.isNotEmpty(handover.get("amount"))) {
sb.append("总金额:¥"+handover.get("amount")+"\r\n");
sb.append("--------------------------------\r\n");
}
if (ObjectUtil.isNotEmpty(handover.get("consumeAmount"))) {
sb.append("储值卡付款:¥"+handover.get("consumeAmount")+"\r\n");
sb.append("--------------------------------\r\n");
}
if (ObjectUtil.isNotEmpty(handover.get("consumeRefuelMoney"))) {
sb.append("囤油卡付款:¥"+handover.get("consumeRefuelMoney")+"\r\n");
sb.append("--------------------------------\r\n");
}
if (ObjectUtil.isNotEmpty(handover.get("actualPay"))) {
sb.append("实付款:¥"+handover.get("actualPay")+"\r\n");
sb.append("--------------------------------\r\n");
}
if (ObjectUtil.isNotEmpty(handover.get("seekZero"))) {
sb.append("找零:¥"+handover.get("seekZero")+"\r\n");
sb.append("----------------------------\r\n");
sb.append("--------------------------------\r\n");
}
if (ObjectUtil.isNotEmpty(handover.get("type")) && "2".equals(handover.get("type"))) {
if (ObjectUtil.isNotEmpty(handover.get("balanceAmount"))) {
sb.append("储值卡:¥"+handover.get("balanceAmount")+"\r\n");
sb.append("----------------------------\r\n");
}
if (ObjectUtil.isNotEmpty(handover.get("oilCardAmount"))) {
sb.append("屯油卡:"+handover.get("oilCardAmount")+"L\r\n");
sb.append("----------------------------\r\n");
}
if (ObjectUtil.isNotEmpty(handover.get("calculateRefundsV"))) {
sb.append("退款:¥"+handover.get("calculateRefundsV")+"\r\n");
sb.append("----------------------------\r\n");
}
}
sb.append("<center>谢谢惠顾,欢迎下次光临!</center>");
return sb.toString();
receiptPrinting.setPrintTemplateDown(receiptPrinting.getPrintTemplateDown().
replace("ttttt",formattedDateTime));
return receiptPrinting.getPrintTemplateTop()+sb.toString()+receiptPrinting.getPrintTemplateDown();
}
public static Map<String, Object> getHandover() {

View File

@ -157,5 +157,18 @@ public class ReceiptPrinting extends BaseEntity implements Serializable {
*/
@TableField(exist = false)
private String storeName;
/**
* 打印模版顶部
*/
private String printTemplateTop;
/**
* 打印模版底部
*/
private String printTemplateDown;
/**
* 二维码的内容
*/
private String codeContent;
}

View File

@ -19,5 +19,9 @@ public interface ReceiptPrintingMapper extends BaseMapper<ReceiptPrinting> {
// 更具 stordid查询当前油站小票打印配置
List<ReceiptPrinting> queryReceiptPrintingList(@Param("receiptPrinting") ReceiptPrinting receiptPrinting);
void addReceiptPrinting(@Param("receiptPrinting") ReceiptPrinting receiptPrinting);
ReceiptPrinting queryReceiptPrintingOne(@Param("storeId") Integer storeId);
}

View File

@ -11,5 +11,42 @@
store_id = #{receiptPrinting.storeId} and deleted = 0
order by id desc
</select>
<insert id="addReceiptPrinting" >
INSERT into receipt_printing (logo_set, headfoot_set, shop_name, title, receipt_type, foot, top_set,
order_number, member_card, plate_number, membership_level, phone_number,
member_points, bottom_set, operate_time,
contact_way, console_operator, address, remarks, code_set, code_image,
loge_image,store_id,create_name,create_time,create_by,update_time,update_by,print_template_top,print_template_down)
VALUES (#{receiptPrinting.logoSet}, #{receiptPrinting.headfootSet}, #{receiptPrinting.shopName}, #{receiptPrinting.title},
#{receiptPrinting.receiptType}, #{receiptPrinting.foot}, #{receiptPrinting.topSet},
#{receiptPrinting.orderNumber}, #{receiptPrinting.memberCard}, #{receiptPrinting.plateNumber},
#{receiptPrinting.membershipLevel}, #{receiptPrinting.phoneNumber}, #{receiptPrinting.memberPoints},
#{receiptPrinting.bottomSet}, #{receiptPrinting.operateTime},
#{receiptPrinting.contactWay}, #{receiptPrinting.consoleOperator}, #{receiptPrinting.address},
#{receiptPrinting.remarks}, #{receiptPrinting.codeSet}, #{receiptPrinting.codeImage}, #{receiptPrinting.logeImage}
, #{receiptPrinting.storeId}, #{receiptPrinting.createName}, #{receiptPrinting.createTime}, #{receiptPrinting.createBy}
, #{receiptPrinting.updateTime}, #{receiptPrinting.updateBy}, #{receiptPrinting.printTemplateTop}, #{receiptPrinting.printTemplateDown})
ON DUPLICATE KEY UPDATE
logo_set = #{receiptPrinting.logoSet}, headfoot_set = #{receiptPrinting.headfootSet}, shop_name = #{receiptPrinting.shopName},
title = #{receiptPrinting.title}, receipt_type = #{receiptPrinting.receiptType}, foot = #{receiptPrinting.foot},
top_set = #{receiptPrinting.topSet}, order_number = #{receiptPrinting.orderNumber}, member_card = #{receiptPrinting.memberCard},
plate_number = #{receiptPrinting.plateNumber},
member_points = #{receiptPrinting.membershipLevel}, bottom_set = #{receiptPrinting.bottomSet},
operate_time = #{receiptPrinting.operateTime},
contact_way = #{receiptPrinting.contactWay}, console_operator = #{receiptPrinting.consoleOperator},
address = #{receiptPrinting.address}, remarks = #{receiptPrinting.remarks}, code_set = #{receiptPrinting.codeSet},
code_image = #{receiptPrinting.codeImage},loge_image = #{receiptPrinting.logeImage},update_time = #{receiptPrinting.updateTime},
update_by = #{receiptPrinting.updateBy},print_template_top= #{receiptPrinting.printTemplateTop},print_template_down= #{receiptPrinting.printTemplateDown}
</insert>
<select id="queryReceiptPrintingOne" resultType="com.fuint.business.setting.entity.ReceiptPrinting">
SELECT
*
FROM
receipt_printing
WHERE
store_id = #{storeId}
</select>
</mapper>

View File

@ -19,5 +19,5 @@ public interface ReceiptPrintingService extends IService<ReceiptPrinting> {
ReceiptPrinting queryReceiptPrintingList(ReceiptPrinting receiptPrinting);
ReceiptPrinting queryReceiptPrintingOne(Integer storeId);
}

View File

@ -1,19 +1,31 @@
package com.fuint.business.setting.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuint.business.printer.entity.PrintDeviceInfo;
import com.fuint.business.printer.mapper.PrintDeviceInfoMapper;
import com.fuint.business.printer.unit.Methods;
import com.fuint.business.setting.entity.ReceiptPrinting;
import com.fuint.business.setting.mapper.ReceiptPrintingMapper;
import com.fuint.business.setting.service.ReceiptPrintingService;
import com.fuint.business.store.entity.MtStore;
import com.fuint.business.store.mapper.MtStoreMapper;
import com.fuint.business.storeInformation.entity.LJStore;
import com.fuint.business.storeInformation.service.ILJStoreService;
import com.fuint.common.dto.AccountInfo;
import com.fuint.common.util.RedisUtil;
import com.fuint.common.util.TokenUtil;
import com.yly.print_sdk_library.RequestMethod;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@ -24,28 +36,33 @@ import java.util.stream.Collectors;
* @date : 2024-08-30 10:00
**/
@Service
@Slf4j
public class ReceiptPrintingServiceImpl extends ServiceImpl<ReceiptPrintingMapper, ReceiptPrinting> implements ReceiptPrintingService {
@Resource
private ReceiptPrintingMapper receiptPrintingMapper;
@Autowired
private ILJStoreService storeService;
@Autowired
private PrintDeviceInfoMapper printDeviceInfoMapper;
@Autowired
private MtStoreMapper mtStoreMapper;
@Override
@Transactional
public int addReceiptPrinting(ReceiptPrinting receiptPrinting) {
// id不为空 查询 删除
if (receiptPrinting.getId() != null) {
ReceiptPrinting receiptPrinting1 = new ReceiptPrinting();
receiptPrinting1.setId(receiptPrinting.getId());
receiptPrinting1.setDeleted(1);
receiptPrintingMapper.updateById(receiptPrinting1);
}
// if (receiptPrinting.getId() != null) {
// ReceiptPrinting receiptPrinting1 = new ReceiptPrinting();
// receiptPrinting1.setId(receiptPrinting.getId());
// receiptPrinting1.setDeleted(1);
// receiptPrintingMapper.updateById(receiptPrinting1);
// }
// 为空进行新增
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
receiptPrinting.setStoreId(nowAccountInfo.getStoreId());
MtStore mtStore = mtStoreMapper.selectById(nowAccountInfo.getStoreId());
if (receiptPrinting.getHeadfootSets() != null && receiptPrinting.getHeadfootSets().size() > 0 ) {
receiptPrinting.setHeadfootSet(chke(receiptPrinting.getHeadfootSets()));
@ -59,10 +76,119 @@ public class ReceiptPrintingServiceImpl extends ServiceImpl<ReceiptPrintingMappe
receiptPrinting.setBottomSet(chke(receiptPrinting.getBottomSets()));
}
int insert = receiptPrintingMapper.insert(receiptPrinting);
return insert;
//拼接模版
StringBuilder sb=new StringBuilder();
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedDateTime = now.format(formatter);
System.out.println("当前时间:" + formattedDateTime);
if(receiptPrinting.getLogoSet().equals("0")){
sb.append("----------------------------\r\n");
String mm=setIice(receiptPrinting.getCodeImage(),nowAccountInfo.getStoreId());
if ("18".equals(mm)) {
getToken(nowAccountInfo.getStoreId());
setIice(receiptPrinting.getCodeImage(),nowAccountInfo.getStoreId());
}
// List<PrintDeviceInfo> infoByStoreId = printDeviceInfoMapper.getInfoListByStoreId(nowAccountInfo.getStoreId());
// for(int i=0;i<infoByStoreId.size();i++){
// Methods m=Methods.getInstance();
// Object accessToken = RedisUtil.get("scancodemodel+" + nowAccountInfo.getStoreId());
// if (ObjectUtil.isNotEmpty(accessToken)) {
// m.init(accessToken.toString());
// } else {
// String token = getToken(nowAccountInfo.getStoreId());
// if ("error".equals(token)) {
// throw new RuntimeException("获取参数失败,无法打印");
// }else {
// m.init(token);
// }
// }
// m.init(infoByStoreId.get(i).getAppKey(), infoByStoreId.get(i).getAppSecret());
// String url=m.setIcon(infoByStoreId.get(i).getMachineCode(), receiptPrinting.getLogeImage());
// if (ObjectUtil.isNotEmpty(url)) {
// // 使用 Fastjson JSON 字符串解析为 JSONObject
// JSONObject jsonObject = JSON.parseObject(url);
// String error = jsonObject.getString("error");
// System.out.println(error);
// if ("18".equals(error)) {
// getToken(nowAccountInfo.getStoreId());
// }
// }
// }
}else {
sb.append("<ML>logo_state:0</ML>");
}
if(receiptPrinting.getHeadfootSet().contains("0")){
sb.append("<FB><center>"+nowAccountInfo.getStoreName() +"</center></FB>");
}
if(receiptPrinting.getHeadfootSet().contains("1")){
sb.append("<center>"+receiptPrinting.getTitle() +"</center>");
}
if(receiptPrinting.getHeadfootSet().contains("2")){
sb.append("<center>"+"zzzzz</center>");
}
sb.append("打印时间:"+formattedDateTime +"\r\n");
if(receiptPrinting.getTopSet().contains("0")){
sb.append("订单号:xxxxx\r\n");
}
if(receiptPrinting.getTopSet().contains("1")){
sb.append("卡号:kkkkk\r\n");
}
if(receiptPrinting.getTopSet().contains("2")){
sb.append("车牌号:ccccc\r\n");
}
if(receiptPrinting.getTopSet().contains("3")){
sb.append("等级:ddddd\r\n");
}
if(receiptPrinting.getTopSet().contains("4")){
sb.append("手机号:sssss\r\n");
}
if(receiptPrinting.getTopSet().contains("5")){
sb.append("余额:yyyyy\r\n");
}
if(receiptPrinting.getTopSet().contains("6")){
sb.append("积分:jjjjj\r\n");
}
sb.append("----------------------------\r\n");
receiptPrinting.setPrintTemplateTop(sb.toString());
StringBuilder sb1=new StringBuilder();
if(receiptPrinting.getBottomSet().contains("0")){
sb1.append("操作时间:ttttt\r\n");
}
if(receiptPrinting.getBottomSet().contains("1")){
if(mtStore.getPhone().toString()!=null){
sb1.append("联系方式:"+mtStore.getPhone()+"\r\n");
}
}
if(receiptPrinting.getBottomSet().contains("2")){
if(nowAccountInfo.getAccountName().toString()!=null){
sb1.append("操作员:"+nowAccountInfo.getAccountName()+"\r\n");
}
}
if(receiptPrinting.getBottomSet().contains("3")){
if(mtStore.getAddress().toString()!=null){
sb1.append("地址:"+mtStore.getAddress()+"\r\n");
}
}
if(receiptPrinting.getBottomSet().contains("4")){
if(receiptPrinting.getRemarks().toString()!=null){
sb1.append("备注:"+receiptPrinting.getRemarks()+"\r\n");
}
}
sb1.append("----------------------------\r\n");
if(receiptPrinting.getHeadfootSet().contains("3")){
sb1.append("<center>"+receiptPrinting.getFoot()+"</center>\r\n");
}
if(receiptPrinting.getCodeSet().equals("1")){
// sb1.append("<QR>"+receiptPrinting.getCodeContent()+"</QR>\r\n");
sb1.append("<QR>www.baidu.com</QR>\r\n");
}
sb1.append("----------------------------\r\n");
sb1.append("<center>谢谢惠顾,欢迎下次光临!</center>\r\n");
receiptPrinting.setPrintTemplateDown(sb1.toString());
receiptPrintingMapper.addReceiptPrinting(receiptPrinting);
//int insert = receiptPrintingMapper.insert(receiptPrinting);
return 1;
}
@ -109,4 +235,68 @@ public class ReceiptPrintingServiceImpl extends ServiceImpl<ReceiptPrintingMappe
.map(Integer::parseInt)
.collect(Collectors.toList());
}
public String setIice(String address,Integer storeId) {
List<PrintDeviceInfo> infoByStoreId = printDeviceInfoMapper.getInfoListByStoreId(storeId);
for(int i=0;i<infoByStoreId.size();i++){
Methods m=Methods.getInstance();
Object accessToken = RedisUtil.get("scancodemodel+" + storeId);
if (ObjectUtil.isNotEmpty(accessToken)) {
m.init(accessToken.toString());
} else {
String token = getToken(storeId);
if ("error".equals(token)) {
throw new RuntimeException("获取参数失败,无法打印");
}else {
m.init(token);
}
}
m.init(infoByStoreId.get(i).getAppKey(), infoByStoreId.get(i).getAppSecret());
System.out.println("http://192.168.31.54:81/dev-api/static/uploadImages/20241021/1be3cfc573d043d6b6eb42eac97e05a5.jpg");
String url=m.setIcon(infoByStoreId.get(i).getMachineCode(), "https://www.baidu.com/img/flexible/logo/pc/result.png");
if (ObjectUtil.isNotEmpty(url)) {
// 使用 Fastjson JSON 字符串解析为 JSONObject
JSONObject jsonObject = JSON.parseObject(url);
String error = jsonObject.getString("error");
if ("18".equals(error)) {
return "18";
}
}
}
return "success";
}
public String getToken(Integer storeId) {
PrintDeviceInfo infoByStoreId = printDeviceInfoMapper.getInfoByStoreId(storeId);
if (ObjectUtil.isEmpty(infoByStoreId)){
return "error";
}
log.info("--yilianyunAccessTokeninit--");
RequestMethod.getInstance().init(infoByStoreId.getAppKey(),infoByStoreId.getAppSecret());
log.info("--yilianyunAccessTokeninit2--");
try {
// String resJson = RequestMethod.getInstance().scanCodeModel_msign("4004872261", "628023865417");
String resJson = RequestMethod.getInstance().scanCodeModel_msign(infoByStoreId.getMachineCode(), infoByStoreId.getMsign());
log.info("--yilianyunAccessToken--{}",resJson);
JSONObject jsonObject = JSONObject.parseObject(resJson);
String errorDescription = jsonObject.getString("error_description"); // success
log.info("--errorDescriptionToken--{}",errorDescription);
if ("success".equals(errorDescription)) {
JSONObject body = jsonObject.getJSONObject("body");
String accessToken = body.getString("access_token");
RedisUtil.set("scancodemodel+"+storeId,accessToken,60*60*24);
return accessToken;
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return "error";
}
@Override
public ReceiptPrinting queryReceiptPrintingOne(Integer storeId) {
return receiptPrintingMapper.queryReceiptPrintingOne(storeId);
}
}

View File

@ -23,4 +23,6 @@ public interface LJUserGradeMapper extends BaseMapper<LJUserGrade> {
String selectByUserId(@Param("storeId") Integer storeId, @Param("userId") Integer userId);
LJUserGrade selectAllByGradeId(String gradeId);
LJUserGrade getUserGradeByUserId(String gradeId);
}

View File

@ -24,4 +24,5 @@ public interface UserBalanceMapper extends BaseMapper<UserBalance> {
Map<String,Object> selectHoverBalance();
Map<String,Object> addNumberSum();
UserBalance getUserBalanceByUserId(String userId);
}

View File

@ -20,4 +20,7 @@
<select id="selectAllByGradeId" resultType="com.fuint.business.userManager.entity.LJUserGrade">
select * from mt_user_grade where id = #{gradeId}
</select>
<select id="getUserGradeByUserId" resultType="com.fuint.business.userManager.entity.LJUserGrade">
select * from mt_user_grade where id = #{gradeId}
</select>
</mapper>

View File

@ -79,5 +79,11 @@
count(*) sumnum
from mt_user_balance mub
</select>
</mapper>
<select id="getUserBalanceByUserId" resultType="com.fuint.business.userManager.entity.UserBalance">
select
*
from mt_user_balance mub
where mt_user_id=#{userId}
order by create_time desc limit 1
</select>
</mapper>

View File

@ -41,4 +41,6 @@ public interface MtUserMapper extends BaseMapper<MtUser> {
Long getStoreUserCountByTime(@Param("storeId") Integer storeId, @Param("beginTime") Date beginTime, @Param("endTime") Date endTime);
List<MemberTopBean> getMemberConsumeTopList(@Param("merchantId") Integer merchantId, @Param("storeId") Integer storeId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
MtUser selectByPhone(@Param("phone") String phone);
}

View File

@ -90,5 +90,7 @@
select * from mt_user t where t.Id = #{id}
limit 1
</select>
<select id="selectByPhone" resultType="com.fuint.repository.model.MtUser">
select * from mt_user t where t.mobile = #{phone}
</select>
</mapper>