From 00bb962d3cbf996faa1dd934cab8bc8c7f7fe8a6 Mon Sep 17 00:00:00 2001
From: kongdeqiang <123456>
Date: 星期一, 19 九月 2022 18:43:55 +0800
Subject: [PATCH] 增加日志和redis
---
src/main/java/com/boying/controller/car/PlateServlet2.java | 51 ++++++++++++++--
src/main/java/com/boying/controller/OutParkController.java | 33 ++++++++++
pom.xml | 4 +
src/main/java/com/boying/controller/phone/FFPayController.java | 62 ++++++++++++++++++++
4 files changed, 139 insertions(+), 11 deletions(-)
diff --git a/pom.xml b/pom.xml
index e01f017..83d2120 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,6 +25,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-redis</artifactId>
+ </dependency>
<dependency>
<groupId>mysql</groupId>
diff --git a/src/main/java/com/boying/controller/OutParkController.java b/src/main/java/com/boying/controller/OutParkController.java
index 6d9e5c3..b14b7b9 100644
--- a/src/main/java/com/boying/controller/OutParkController.java
+++ b/src/main/java/com/boying/controller/OutParkController.java
@@ -12,6 +12,7 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
+import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -26,6 +27,7 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
+import java.util.concurrent.TimeUnit;
import static com.boying.common.util.DateUtil.getMinute;
@@ -46,6 +48,10 @@
@Autowired
private CostRuleService costRuleService;
+ @Autowired
+ private ParkService parkService;
+ @Autowired
+ private StringRedisTemplate redisTemplate;
@PostMapping("findPage")
public Object findPage(int page,int pageSize) {
@@ -188,7 +194,20 @@
Barrier barrier1 = findBarrier(code2);
barrierId = barrier1.getId();
parkId = barrier1.getParkId();
-
+ Park park = (Park)parkService.findById(parkId);
+ int num = 0;
+ String s = redisTemplate.opsForValue().get("car_park_" + parkId);
+ if(park != null){
+ num = park.getNum();
+ if(s !=null){
+ if(Integer.parseInt(s) > num){
+ return "null";
+ }
+ }else {
+ s= "0";
+ redisTemplate.opsForValue().set("car_park_" + parkId,s,30, TimeUnit.DAYS);
+ }
+ }
enterParkService.deleteByCarNo(carNo,parkId);
EnterPark enterPark = new EnterPark();
enterPark.setCreateTime(new Date());
@@ -212,6 +231,9 @@
// enterPark.setStatus(1);//鍙戠幇鏈夎繚绔�
// }
enterParkService.save(enterPark);
+ int i = Integer.parseInt(s);
+ i++;
+ redisTemplate.opsForValue().set("car_park_" + parkId,Integer.toString(i),30, TimeUnit.DAYS);
Barrier barrier = (Barrier) barrierService.findById(barrierId);
barrier.setType2(1);
@@ -233,6 +255,7 @@
outPark.setCode(System.currentTimeMillis()+"");
EnterPark enterPark = enterParkService.findByCarNo(carNo).get(0);
+
if(enterPark==null){
s += "鏈彂鐜板叆鍦鸿溅杈嗭細"+carNo+"\n";
writeTxt(s);
@@ -241,6 +264,7 @@
s += "鍙戠幇鍏ュ満杞﹁締: "+enterPark.getCarNo()+",閬撻椄id涓猴細"+enterPark.getBarrierId()+",鍋滆溅鍦篿d锛�"+enterPark.getParkId()+",杩濈珷鏍囪瘑锛�"+enterPark.getStatus()+"\n";
outPark.setEnterTime(enterPark.getCreateTime());
}
+ String redis = redisTemplate.opsForValue().get("car_park_" + parkId);
long l = outPark.getCreateTime().getTime() - enterPark.getCreateTime().getTime();
s+= "鍦哄唴鏃堕暱涓猴細"+l+"姣,鍚堣涓�: "+l/(1000*60)+"绉抃n";
outPark.setTime(l/(1000*60));
@@ -255,6 +279,13 @@
//outPark.setStatus3(findTicket(carNo));
outParkService.save(outPark);
+ int i = Integer.parseInt(redis);
+ i--;
+ if(i<0){
+ redisTemplate.opsForValue().set("car_park_" + parkId,"0",30, TimeUnit.DAYS);
+ }else {
+ redisTemplate.opsForValue().set("car_park_" + parkId,Integer.toString(i),30, TimeUnit.DAYS);
+ }
Barrier barrier = (Barrier) barrierService.findById(barrierId);
barrier.setCarNo(carNo);
diff --git a/src/main/java/com/boying/controller/car/PlateServlet2.java b/src/main/java/com/boying/controller/car/PlateServlet2.java
index 8fd430c..aa197ed 100755
--- a/src/main/java/com/boying/controller/car/PlateServlet2.java
+++ b/src/main/java/com/boying/controller/car/PlateServlet2.java
@@ -5,10 +5,7 @@
import com.boying.common.SystemConfigProperties;
import com.boying.common.util.DateUtil;
import com.boying.common.util.StringUtil;
-import com.boying.entity.Barrier;
-import com.boying.entity.EnterPark;
-import com.boying.entity.OutPark;
-import com.boying.entity.Ticket;
+import com.boying.entity.*;
import com.boying.service.*;
import com.google.gson.JsonIOException;
import com.google.gson.JsonObject;
@@ -16,6 +13,7 @@
import com.google.gson.JsonSyntaxException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
+import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -33,6 +31,7 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
+import java.util.concurrent.TimeUnit;
import static com.boying.common.util.DateUtil.getMinute;
@@ -45,6 +44,10 @@
private static final long serialVersionUID = 1L;
@Autowired
private SystemConfigProperties systemConfigProperties;
+ @Autowired
+ private StringRedisTemplate redisTemplate;
+ @Autowired
+ private ParkService parkService;
/**
* 鍥炲寮�闂�
@@ -112,6 +115,7 @@
@PostMapping("/PlateServlet")
protected void info(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String s= "";
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream(),"UTF-8"));
String str = "";
String lineStr = "";
@@ -162,7 +166,8 @@
}
System.out.println("缂栧彿锛�"+serialno+"璁惧璇嗗埆鍒颁簡锛�"+license);
- s+="杞︾墝鍙蜂负锛�"+license+",serialno涓猴細"+code+"\n";
+ String format = sdf.format(new Date());
+ s+= format+",杞︾墝鍙蜂负锛�"+license+",serialno涓猴細"+code+"銆� ";
Barrier barrier = barrierService.findByCode(code);
if(barrier==null){
@@ -170,11 +175,11 @@
}else{
if(barrier.getType()==0){
outPark(license, barrier.getId(), barrier.getParkId());
- s+=license+"淇濆瓨鍑哄満璁板綍\n";
+ s+=license+"-淇濆瓨鍑哄満璁板綍\n";
}else{
open(request, response);//鎶潌
enterPark(license,barrier.getId(),barrier.getParkId());
- s+=license+"淇濆瓨鍏ュ満璁板綍\n";
+ s+=license+"-淇濆瓨鍏ュ満璁板綍\n";
}
}
writeTxt(s);
@@ -182,14 +187,20 @@
}
catch (JsonIOException e) {
+ System.out.println("鏃犲叆鍦鸿褰�");
+ s+=" ,鏌ヨ鍦哄唴璁板綍寮傚父";
e.printStackTrace();
writeTxt(s);
}
catch (JsonSyntaxException e) {
+ System.out.println("鏃犲叆鍦鸿褰�");
+ s+=" ,鏌ヨ鍦哄唴璁板綍寮傚父";
e.printStackTrace();
writeTxt(s);
}
catch (Exception e) {
+ System.out.println("鏃犲叆鍦鸿褰�");
+ s+=" ,鏌ヨ鍦哄唴璁板綍寮傚父";
writeTxt(s);
}
}
@@ -225,7 +236,20 @@
private CostRuleService costRuleService;
public void enterPark(String carNo,Long barrierId,Long parkId) {
-
+ Park park = (Park)parkService.findById(parkId);
+ int num = 0;
+ String s = redisTemplate.opsForValue().get("car_park_" + parkId);
+ if(park != null){
+ num = park.getNum();
+ if(s !=null){
+ if(Integer.parseInt(s) > num){
+ return;
+ }
+ }else {
+ s= "0";
+ redisTemplate.opsForValue().set("car_park_" + parkId,s,30, TimeUnit.DAYS);
+ }
+ }
enterParkService.deleteByCarNo(carNo,parkId);
EnterPark enterPark = new EnterPark();
enterPark.setCreateTime(new Date());
@@ -249,6 +273,9 @@
enterPark.setStatus(1);//鍙戠幇鏈夎繚绔�
}
enterParkService.save(enterPark);
+ int i = Integer.parseInt(s);
+ i++;
+ redisTemplate.opsForValue().set("car_park_" + parkId,Integer.toString(i),30, TimeUnit.DAYS);
Barrier barrier = (Barrier) barrierService.findById(barrierId);
barrier.setType2(1);
@@ -269,6 +296,7 @@
}else{
outPark.setEnterTime(enterPark.getCreateTime());
}
+ String redis = redisTemplate.opsForValue().get("car_park_" + parkId);
long l = outPark.getCreateTime().getTime() - enterPark.getCreateTime().getTime();
outPark.setTime(l/(1000*60));
double money = 0;
@@ -281,6 +309,13 @@
outPark.setStatus3(findTicket(carNo));
outParkService.save(outPark);
+ int i = Integer.parseInt(redis);
+ i--;
+ if(i<0){
+ redisTemplate.opsForValue().set("car_park_" + parkId,"0",30, TimeUnit.DAYS);
+ }else {
+ redisTemplate.opsForValue().set("car_park_" + parkId,Integer.toString(i),30, TimeUnit.DAYS);
+ }
Barrier barrier = (Barrier) barrierService.findById(barrierId);
barrier.setCarNo(carNo);
diff --git a/src/main/java/com/boying/controller/phone/FFPayController.java b/src/main/java/com/boying/controller/phone/FFPayController.java
index 4ba73e3..b0034e7 100644
--- a/src/main/java/com/boying/controller/phone/FFPayController.java
+++ b/src/main/java/com/boying/controller/phone/FFPayController.java
@@ -20,8 +20,11 @@
import javax.persistence.criteria.Root;
import javax.servlet.http.HttpServletRequest;
+import java.io.BufferedWriter;
+import java.io.FileWriter;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -190,16 +193,21 @@
@PostMapping("result")
public String result(HttpServletRequest request,String payKey,String payerTypeCode,String payerNum,String payCode,Double amt,String status,String errorInfo,String sign,String signType) throws Exception{
System.out.println(payCode+"-------"+status);
+ String s = "payCode===="+payCode+",\n";
try {
+ s += "寮�濮嬭蛋鍥炶皟鎺ュ彛------>";
+ writeTxt(s);
updateOrderRecord(payCode,status);
}catch (Exception e){
-
+ s += "鏇存柊璁㈠崟璁板綍鍑哄紓甯�------>";
+ writeTxt(s);
}
return "success";
}
//鏇存柊璁㈠崟璁板綍
public void updateOrderRecord(String payCode,String status){
+ String s = "鏇存柊璁㈠崟璁板綍锛歱ayCode===="+payCode+",status==="+status+",\n";
Specification<OrderRecord> specification = new Specification<OrderRecord>() {
@Override
public Predicate toPredicate(Root<OrderRecord> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
@@ -211,8 +219,10 @@
}
};
List<OrderRecord> all = orderRecordService.findAll(specification);
+ s += "鏌ヨ鍒拌鍗曡褰曚负锛�"+all.size()+"鏉★紝\n";
if(all.size()==1){
OrderRecord orderRecord = all.get(0);
+ s += "鏌ヨ鍒拌鍗曚负锛�"+orderRecord.getId()+"锛孿n";
if(status.equals("01")){
orderRecord.setStatus(0);
}
@@ -226,9 +236,12 @@
if(orderRecord.getType()==0){
updateTicket(orderRecord.getQueryId(),status);
}else{
+ s += "淇敼鍑哄満琛細"+orderRecord.getQueryId()+"锛宻tatus==="+status+",\n";
+ writeTxt(s);
updateOutPark(orderRecord.getQueryId(),status);
}
}
+ writeTxt(s);
}
//鏇存柊缃氬崟鐨勭姸鎬�
@@ -306,13 +319,22 @@
// }
public void updateOutPark(Long outParkId,String status){
+ String s = "寮�濮嬩慨鏀瑰嚭鍦鸿〃-----銆�,\n";
+ s+= "outparkId==="+outParkId+",status==="+status+",\n";
+ writeTxt(s);
OutPark outPark = (OutPark) outParkService.findById(outParkId);
if(outPark!=null){
+ s += "鎵惧埌鍑哄満鏁版嵁锛�"+outPark.getId()+",\n";
+ writeTxt(s);
if(status.equals("03")){
+ s += "鍑哄満鏁版嵁淇敼----銆�";
+ writeTxt(s);
outPark.setStatus(1);
outParkService.save(outPark);
}
}
+ s += "鏈壘鍒板嚭鍦烘暟鎹�-----銆�";
+ writeTxt(s);
}
//鍒犻櫎杩涘仠杞﹀満鐨勬暟鎹�
@@ -336,9 +358,13 @@
//鐢熸垚鐢靛瓙缂存鐮�
@PostMapping("park")
public Object park(Long id){
+ String logs = "寮�濮嬬即璐规祦绋�------銆�";
+ logs += "鍑哄満id涓猴細"+id+",\n";
OutPark outPark = (OutPark) outParkService.findById(id);
if(outPark.getPrice()==0){
updateOutPark(outPark.getId(),"03");
+ logs += "鏀粯閲戦涓�0,\n";
+ writeTxt(logs);
return error("鏈鍋滆溅鏃犻渶鏀粯璐圭敤");
}
@@ -356,13 +382,17 @@
List<WhiteList> all = whiteListService.findAll(specification);
for(WhiteList w : all){
if(w.getType()==0){
+ logs+=outPark.getCarNo()+"鍦ㄧ櫧鍚嶅崟,\n";
updateOutPark(outPark.getId(),"03");
+ writeTxt(logs);
return error("鏈鍋滆溅鏃犻渶鏀粯璐圭敤!");
}else{
if(w.getParkId()!=null){
if(w.getEndTime()!=null){
if(w.getParkId()==outPark.getParkId()&&new Date().getTime()<w.getEndTime().getTime()){
+ logs+=outPark.getCarNo()+"鍦ㄧ壒娈婅鍒欑櫧鍚嶅崟,\n";
updateOutPark(outPark.getId(),"03");
+ writeTxt(logs);
return error("鏈鍋滆溅鏃犻渶鏀粯璐圭敤!");
}
}
@@ -396,6 +426,8 @@
sbf.append("&signType=MD5");
String s1 = httpsRequest(ip+"/pay/inpay","POST",sbf.toString());
if(s1.equals("error")){
+ logs += "鐢熸垚鎵ф硶鐢靛瓙缂存鐮佸け璐ワ紝璇疯仈绯荤鐞嗗憳,\n";
+ writeTxt(logs);
return error("鐢熸垚鎵ф硶鐢靛瓙缂存鐮佸け璐ワ紝璇疯仈绯荤鐞嗗憳");
}
JSONObject jsonObject = JSON.parseObject(s1);
@@ -404,15 +436,20 @@
if(eInfo.equals("姝よ鍗曞凡杩囨湡")){
outPark.setCode(System.currentTimeMillis()+"");
outParkService.save(outPark);
+ logs += "姝よ鍗曞凡杩囨湡,\n";
+ writeTxt(logs);
return park(id);
}else{
+ logs += "姝よ鍗曟湁寮傚父閿欒,\n";
+ writeTxt(logs);
return error(eInfo);
}
}else{
String payCode = jsonObject.get("payCode").toString();
+ logs += "payCode: "+payCode+",\n";
outPark.setPayCode(payCode);
outParkService.save(outPark);
-
+ writeTxt(logs);
addOrderRecord(outPark);
return success("鐢熸垚鍋滆溅鐢靛瓙缂存鐮�","https://hbfs.govpay.ccb.com/online/fssm?fee=130000000001&PyfScnCgycd=01&pyfTpcd=3&BNo="+payCode);
}
@@ -446,4 +483,25 @@
orderRecordService.save(orderRecord);
}
+
+ private void writeTxt( String txt)
+ {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+ try
+ {
+ FileWriter f = new FileWriter(systemConfigProperties.getLogPath()+"鏀粯鏃ュ織"+sdf.format(new Date())+".txt",true);
+ BufferedWriter bw=new BufferedWriter(f);
+ bw.write(txt);
+ bw.newLine();
+ bw.close();
+ }
+ catch(Exception e)
+ {
+ System.out.println("鎵撳嵃閿欒");
+ }
+ }
+
+
+
+
}
--
Gitblit v1.9.1