Merge branch 'master' of https://e.coding.net/g-cphe0354/shouyinjixitong/wx-cashier-service
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.chaozhanggui.system.cashierservice.util;
|
||||
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.NameValuePair;
|
||||
@@ -15,6 +17,7 @@ import org.apache.http.util.EntityUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class FeieyunPrintUtil {
|
||||
@@ -114,6 +117,223 @@ public class FeieyunPrintUtil {
|
||||
|
||||
}
|
||||
|
||||
public static String getPrintData(String sn,String pickupNumber,String date,String productName,Integer number,String remark) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("<CB>"+pickupNumber+"</CB><BR><BR>");
|
||||
builder.append("<L>时间: "+date+" </L><BR><BR><BR>");
|
||||
|
||||
if(productName.length()>4||remark.length()>4){
|
||||
builder.append("<B><BOLD>"+productName+" "+number+"</BOLD></B><BR><BR>");
|
||||
builder.append("<B><BOLD>"+remark+" </BOLD></B><BR>");
|
||||
}else {
|
||||
builder.append("<B><BOLD>"+productName+" "+number+"</BOLD></B><BR><BR>");
|
||||
builder.append("<B><BOLD>"+remark+" </BOLD></B><BR>");
|
||||
}
|
||||
builder.append("<CUT>");
|
||||
|
||||
String content=builder.toString();
|
||||
|
||||
System.out.println("content:".concat(content));
|
||||
|
||||
//通过POST请求,发送打印信息到服务器
|
||||
RequestConfig requestConfig = RequestConfig.custom()
|
||||
.setSocketTimeout(30000)//读取超时
|
||||
.setConnectTimeout(30000)//连接超时
|
||||
.build();
|
||||
|
||||
CloseableHttpClient httpClient = HttpClients.custom()
|
||||
.setDefaultRequestConfig(requestConfig)
|
||||
.build();
|
||||
|
||||
HttpPost post = new HttpPost(URL);
|
||||
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
|
||||
nvps.add(new BasicNameValuePair("user",USER));
|
||||
String STIME = String.valueOf(System.currentTimeMillis()/1000);
|
||||
nvps.add(new BasicNameValuePair("stime",STIME));
|
||||
nvps.add(new BasicNameValuePair("sig",signature(USER,UKEY,STIME)));
|
||||
nvps.add(new BasicNameValuePair("apiname","Open_printMsg"));//固定值,不需要修改
|
||||
nvps.add(new BasicNameValuePair("sn",sn));
|
||||
nvps.add(new BasicNameValuePair("content",content));
|
||||
nvps.add(new BasicNameValuePair("times","1"));//打印联数
|
||||
|
||||
CloseableHttpResponse response = null;
|
||||
String result = null;
|
||||
try
|
||||
{
|
||||
post.setEntity(new UrlEncodedFormEntity(nvps,"utf-8"));
|
||||
response = httpClient.execute(post);
|
||||
int statecode = response.getStatusLine().getStatusCode();
|
||||
if(statecode == 200){
|
||||
HttpEntity httpentity = response.getEntity();
|
||||
if (httpentity != null){
|
||||
//服务器返回的JSON字符串,建议要当做日志记录起来
|
||||
result = EntityUtils.toString(httpentity);
|
||||
System.out.println("result:".concat(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
try {
|
||||
if(response!=null){
|
||||
response.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
post.abort();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
httpClient.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static String getCashPrintData(OrderDetailPO detailPO, String sn, String type, String orderType){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("<CB>"+detailPO.getMerchantName()+"</CB><BR><BR>");
|
||||
sb.append("<C><BOLD>"+type+"【"+detailPO.getMasterId()+"】</BOLD></C><BR><BR>");
|
||||
sb.append("订单号: "+detailPO.getOrderNo()+" <BR>");
|
||||
sb.append("交易时间: "+detailPO.getTradeDate()+" <BR>");
|
||||
sb.append("收银员: "+detailPO.getOperator()+" <BR><BR><BR>");
|
||||
sb.append("------------------------<BR>");
|
||||
char paddingCharacter = ' ';
|
||||
sb.append("<S>"+String.format("%-15s","品名").replace(' ', paddingCharacter)+String.format("%-4s","数量").replace(' ', paddingCharacter)+String.format("%4s","小计").replace(' ', paddingCharacter)+"</S><BR>");
|
||||
for (OrderDetailPO.Detail detail : detailPO.getDetailList()) {
|
||||
if(detail.getProductName().length()>4){
|
||||
|
||||
int count=getProducrName(detail.getProductName());
|
||||
if(count<=0){
|
||||
int length=15-(detail.getProductName().length()-4);
|
||||
sb.append(""+String.format("%-"+length+"s",detail.getProductName()).replace(' ', paddingCharacter)+String.format("%-4s",detail.getNumber()).replace(' ', paddingCharacter)+String.format("%8s",detail.getAmount()).replace(' ', paddingCharacter)+"<BR>");
|
||||
}else {
|
||||
int length=15+count-(detail.getProductName().length()-4);
|
||||
sb.append(""+String.format("%-"+length+"s",detail.getProductName()).replace(' ', paddingCharacter)+String.format("%-4s",detail.getNumber()).replace(' ', paddingCharacter)+String.format("%8s",detail.getAmount()).replace(' ', paddingCharacter)+"<BR>");
|
||||
}
|
||||
|
||||
}else {
|
||||
sb.append(""+String.format("%-15s",detail.getProductName()).replace(' ', paddingCharacter)+String.format("%-4s",detail.getNumber()).replace(' ', paddingCharacter)+String.format("%8s",detail.getAmount()).replace(' ', paddingCharacter)+"<BR>");
|
||||
}
|
||||
|
||||
if(detail.getSpec()!=null&& ObjectUtil.isNotEmpty(detail.getSpec())){
|
||||
sb.append("规格:"+detail.getSpec()+"<BR>");
|
||||
}
|
||||
|
||||
sb.append("<BR>");
|
||||
|
||||
}
|
||||
sb.append("------------------------<BR>");
|
||||
String t="¥"+detailPO.getReceiptsAmount();
|
||||
t=String.format("%11s",t).replace(' ', paddingCharacter);
|
||||
if(orderType.equals("return")){
|
||||
sb.append("<B>应退"+t+"</B><BR>");
|
||||
}else {
|
||||
sb.append("<B>应收"+t+"</B><BR>");
|
||||
}
|
||||
if(ObjectUtil.isNotEmpty(detailPO.getPayType())&&ObjectUtil.isNotNull(detailPO.getPayType())&&detailPO.getPayType().equals("deposit")){
|
||||
sb.append("储值¥"+detailPO.getReceiptsAmount()+" <BR>");
|
||||
sb.append("------------------------<BR>");
|
||||
sb.append("积分:"+detailPO.getIntegral()+"<BR>");
|
||||
}
|
||||
|
||||
sb.append("余额:"+detailPO.getBalance()+"<BR>");
|
||||
sb.append("------------------------<BR>");
|
||||
|
||||
if(ObjectUtil.isNotEmpty(detailPO.getRemark())&&ObjectUtil.isNotNull(detailPO.getRemark())){
|
||||
sb.append("<L>备注:"+detailPO.getRemark()+"</L><BR>");
|
||||
}
|
||||
|
||||
|
||||
|
||||
sb.append("打印时间:"+DateUtils.getTime(new Date())+"<BR>");
|
||||
|
||||
sb.append("<CUT>");
|
||||
|
||||
String content=sb.toString();
|
||||
|
||||
//通过POST请求,发送打印信息到服务器
|
||||
RequestConfig requestConfig = RequestConfig.custom()
|
||||
.setSocketTimeout(30000)//读取超时
|
||||
.setConnectTimeout(30000)//连接超时
|
||||
.build();
|
||||
|
||||
CloseableHttpClient httpClient = HttpClients.custom()
|
||||
.setDefaultRequestConfig(requestConfig)
|
||||
.build();
|
||||
|
||||
HttpPost post = new HttpPost(URL);
|
||||
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
|
||||
nvps.add(new BasicNameValuePair("user",USER));
|
||||
String STIME = String.valueOf(System.currentTimeMillis()/1000);
|
||||
nvps.add(new BasicNameValuePair("stime",STIME));
|
||||
nvps.add(new BasicNameValuePair("sig",signature(USER,UKEY,STIME)));
|
||||
nvps.add(new BasicNameValuePair("apiname","Open_printMsg"));//固定值,不需要修改
|
||||
nvps.add(new BasicNameValuePair("sn",sn));
|
||||
nvps.add(new BasicNameValuePair("content",content));
|
||||
nvps.add(new BasicNameValuePair("times","1"));//打印联数
|
||||
|
||||
CloseableHttpResponse response = null;
|
||||
String result = null;
|
||||
try
|
||||
{
|
||||
post.setEntity(new UrlEncodedFormEntity(nvps,"utf-8"));
|
||||
response = httpClient.execute(post);
|
||||
int statecode = response.getStatusLine().getStatusCode();
|
||||
if(statecode == 200){
|
||||
HttpEntity httpentity = response.getEntity();
|
||||
if (httpentity != null){
|
||||
//服务器返回的JSON字符串,建议要当做日志记录起来
|
||||
result = EntityUtils.toString(httpentity);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
try {
|
||||
if(response!=null){
|
||||
response.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
post.abort();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
httpClient.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static int getProducrName(String str){
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.chaozhanggui.system.cashierservice.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.lang.Math.*;
|
||||
import static java.lang.Math.sin;
|
||||
|
||||
public class LocationUtils {
|
||||
|
||||
public static String district(String keywords) {
|
||||
Map<String, String> param=new HashMap<>();
|
||||
//超掌柜生活-用户端
|
||||
param.put("key","7a7f2e4790ea222660a027352ee3af39");
|
||||
param.put("keywords",keywords);
|
||||
param.put("subdistrict","1");
|
||||
param.put("extensions","base");
|
||||
String s = HttpClientUtil.doGet("https://restapi.amap.com/v3/config/district", param);
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将角度转化为弧度
|
||||
*/
|
||||
public static double radians(double d) {
|
||||
return d * Math.PI / 180.0;
|
||||
}
|
||||
/**
|
||||
* 根据两点经纬度坐标计算直线距离
|
||||
* <p>
|
||||
* S = 2arcsin√sin²(a/2)+cos(lat1)*cos(lat2)*sin²(b/2) ̄*6378.137
|
||||
* <p>
|
||||
* 1. lng1 lat1 表示A点经纬度,lng2 lat2 表示B点经纬度;<br>
|
||||
* 2. a=lat1 – lat2 为两点纬度之差 b=lng1 -lng2 为两点经度之差;<br>
|
||||
* 3. 6378.137为地球赤道半径,单位为千米;
|
||||
*
|
||||
* @param lng1 点1经度
|
||||
* @param lat1 点1纬度
|
||||
* @param lng2 点2经度
|
||||
* @param lat2 点2纬度
|
||||
* @return 距离,单位千米(KM)
|
||||
* @see <a href="https://zh.wikipedia.org/wiki/%E5%8D%8A%E6%AD%A3%E7%9F%A2%E5%85%AC%E5%BC%8F">半正矢(Haversine)公式</a>
|
||||
*/
|
||||
public static double getDistanceFrom2LngLat(double lng1, double lat1, double lng2, double lat2) {
|
||||
//将角度转化为弧度
|
||||
double radLng1 = radians(lng1);
|
||||
double radLat1 = radians(lat1);
|
||||
double radLng2 = radians(lng2);
|
||||
double radLat2 = radians(lat2);
|
||||
|
||||
double a = radLat1 - radLat2;
|
||||
double b = radLng1 - radLng2;
|
||||
|
||||
return 2 * asin(sqrt(sin(a / 2) * sin(a / 2) + cos(radLat1) * cos(radLat2) * sin(b / 2) * sin(b / 2))) * 6378.137;
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// // 示例经纬度坐标
|
||||
// double lat1 = 108.954398;
|
||||
// double lon1 = 34.308687;
|
||||
//
|
||||
// double lat2 = 108.953555;
|
||||
// double lon2 = 34.276169;
|
||||
//
|
||||
// // 计算距离
|
||||
// double distance = getDistanceFrom2LngLat(lat1, lon1, lat2, lon2);
|
||||
// System.out.println("Distance between the two points is: " + distance + " km");
|
||||
// }
|
||||
}
|
||||
@@ -217,9 +217,9 @@ public class PrinterUtils {
|
||||
detailList.add(detail);
|
||||
detailList.add(detail3);
|
||||
detailList.add(detail4);
|
||||
OrderDetailPO detailPO=new OrderDetailPO("牛叉闪闪","普通打印","#365","DD20240306134718468","2024-03-06 15:00:00","【POS-1】001","79000.80","5049758.96","deposit","0",detailList);
|
||||
// OrderDetailPO detailPO=new OrderDetailPO("牛叉闪闪","普通打印","#365","DD20240306134718468","2024-03-06 15:00:00","【POS-1】001","79000.80","5049758.96","deposit","0",detailList);
|
||||
|
||||
|
||||
printTickets(1,1,"ZF544PG03W00001",getCashPrintData(detailPO,"结算单"));
|
||||
// printTickets(1,1,"ZF544PG03W00001",getCashPrintData(detailPO,"结算单"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,10 +295,10 @@ public class RedisUtils {
|
||||
* @param timeUnit 类型
|
||||
* @return true成功 false 失败
|
||||
*/
|
||||
public boolean set(String key, Object value, long time, TimeUnit timeUnit) {
|
||||
public boolean set(String key, String value, long time, TimeUnit timeUnit) {
|
||||
try {
|
||||
if (time > 0) {
|
||||
redisTemplate.opsForValue().set(key, value, time, timeUnit);
|
||||
stringRedisTemplate.opsForValue().set(key, value, time, timeUnit);
|
||||
} else {
|
||||
set(key, value);
|
||||
}
|
||||
|
||||
@@ -51,4 +51,14 @@ public class StringUtil {
|
||||
return JSON.parseArray(listString);
|
||||
|
||||
}
|
||||
|
||||
public static String random(int length) {
|
||||
Random random = new Random();
|
||||
String result = "";
|
||||
for (int i = 0; i < length; i++) {
|
||||
result += random.nextInt(10);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.chaozhanggui.system.cashierservice.util;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyun.dysmsapi20170525.Client;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.chaozhanggui.system.cashierservice.sign.CodeEnum.SUCCESS;
|
||||
|
||||
/**
|
||||
* 获取验证码相关工具
|
||||
* @author 12847
|
||||
*/
|
||||
@Component
|
||||
public class ValidateCodeUtil {
|
||||
/**
|
||||
* 阿里云key
|
||||
*/
|
||||
@Value("${aliyun.keyid}")
|
||||
private String ACCESSKEYID;
|
||||
/**
|
||||
* 阿里云secret
|
||||
*/
|
||||
@Value("${aliyun.keysecret}")
|
||||
private String ACCESSKEYSECRET;
|
||||
/**
|
||||
* 十小时
|
||||
*/
|
||||
protected static final long MILLIS_MINUTE = 10 *60 * 60 *1000;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
|
||||
/**
|
||||
* 获取验证码(阿里云)
|
||||
*/
|
||||
public Result requestValidateCodeAli(String phone, String checkCode) {
|
||||
Client client = null;
|
||||
try {
|
||||
client = createClient();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 1.发送短信
|
||||
com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest()
|
||||
.setSignName("银收客")
|
||||
.setTemplateCode("SMS_244665149")
|
||||
.setTemplateParam("{\"code\":" +"'"+checkCode +"'"+"}")
|
||||
.setPhoneNumbers(phone);
|
||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||
try {
|
||||
assert client != null;
|
||||
return Result.success(SUCCESS,client.sendSmsWithOptions(sendSmsRequest, runtime));
|
||||
} catch (Exception e) {
|
||||
return Result.fail(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 发送短信(阿里云)
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public Client createClient() throws Exception {
|
||||
Config config = new Config();
|
||||
config.accessKeyId = ACCESSKEYID;
|
||||
config.accessKeySecret = ACCESSKEYSECRET;
|
||||
return new com.aliyun.dysmsapi20170525.Client(config);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user