src/main/java/com/boying/controller/ParkController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/boying/controller/car/PlateServlet3.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/boying/controller/phone/YCPayController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/boying/service/impl/BarrierServiceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/boying/service/impl/OutParkServiceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/boying/service/impl/ParkServiceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/boying/util/RedisJsonUtil.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/boying/controller/ParkController.java
@@ -112,10 +112,15 @@ for (Long id : ids) { Park byId1 = parkService.getById(id); String num = redisTemplate.opsForValue().get("car_park_" + byId1.getId()); try { if(StringUtils.isNotBlank(num)){ num = "0"; } byId1.setCarNum(Integer.parseInt(num)); }catch (Exception e){ byId1.setCarNum(0); e.printStackTrace(); } list.add(byId1); } return R.ok(list); src/main/java/com/boying/controller/car/PlateServlet3.java
@@ -62,7 +62,7 @@ private final FileInfoService fileInfoService; private final TicketBlackService ticketBlackService; private final OutParkLogService outParkLogService; private final RedisJsonUtil redisJsonUtil; // private final RedisJsonUtil redisJsonUtil; private final String LEDURL = "http://192.168.31.212:9988/LedShow/IGetResultDataAllLine"; /** @@ -142,7 +142,8 @@ @PostMapping("/status") public void heart(String serialno,HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { Barrier barrier = barrierService.findByCode(serialno); Park park = parkService.getOneById(barrier.getParkId()); // Park park = parkService.getOneById(barrier.getParkId()); Park park = parkService.getById(barrier.getParkId()); String redis = redisTemplate.opsForValue().get("park_up_" + park.getId()); String redisnum = redisTemplate.opsForValue().get("car_park_" + park.getId()); if(barrier!=null){ @@ -173,22 +174,18 @@ barrier.setStatus(0); barrier.setUpdateTime(LocalDateTime.now()); barrierService.saveOrUpdate(barrier); try { redisJsonUtil.set("barrier-"+barrier.getCode(),barrier); } catch (IOException e) { e.printStackTrace(); } // String jsonValue = JSON.toJSONString(barrier); // redisTemplate.opsForValue().set("barrier-"+barrier.getCode(), jsonValue); easyOpen(request,response); }else { //不需开闸 barrier.setStatus(0); barrier.setUpdateTime(LocalDateTime.now()); barrierService.saveOrUpdate(barrier); try { redisJsonUtil.set("barrier-"+barrier.getCode(),barrier); } catch (IOException e) { e.printStackTrace(); } // String jsonValue = JSON.toJSONString(barrier); // redisTemplate.opsForValue().set("barrier-"+barrier.getCode(), jsonValue); if(barrier.getType() == 0){ OutPark outPark = outParkService.count4(barrier.getId()); if(outPark!=null){ @@ -214,7 +211,7 @@ byOutPark.setOpenTime(LocalDateTime.now()); outParkLogService.saveOrUpdate(byOutPark); enterParkService.deleteByCarNo(outPark.getCarNo(), barrier.getParkId()); redisJsonUtil.del("outPark-"+outPark.getBarrierId()); // redisTemplate.delete("outPark-"+outPark.getBarrierId()); } } if(barrier.getType() == 1){ src/main/java/com/boying/controller/phone/YCPayController.java
@@ -2,7 +2,6 @@ import cn.hutool.http.Header; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -13,17 +12,14 @@ import com.boying.entity.*; import com.boying.service.*; import com.boying.util.DateUtilOther; import com.boying.util.HTTPEntityUtil; import com.boying.util.RedisJsonUtil; import com.google.gson.Gson; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; @@ -38,7 +34,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; /** * @author kdq @@ -63,7 +59,7 @@ private final EnterParkService enterParkService; private final WXService wxService; private final OutParkLogService outParkLogService; private final RedisJsonUtil redisJsonUtil; private StringRedisTemplate redisTemplate; /** @@ -686,11 +682,8 @@ outPark.setStatus(1); outParkService.saveOrUpdate(outPark); //缓存在redis里 try { redisJsonUtil.set("outPark-"+outPark.getBarrierId(), outPark); } catch (IOException e) { e.printStackTrace(); } // String jsonValue = JSON.toJSONString(outPark); // redisTemplate.opsForValue().set("outPark-"+outPark.getBarrierId(), jsonValue); } } } src/main/java/com/boying/service/impl/BarrierServiceImpl.java
@@ -2,6 +2,7 @@ import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.boying.entity.Barrier; @@ -15,6 +16,7 @@ import com.boying.service.BarrierService; import com.boying.service.EnterParkService; import com.boying.util.RedisJsonUtil; import com.boying.util.StringUtil; import lombok.AllArgsConstructor; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; @@ -39,29 +41,42 @@ private OutParkMapper outParkMapper; private StringRedisTemplate redisTemplate; private ParkMapper parkMapper; private RedisJsonUtil redisJsonUtil; @Override public Barrier findByCode(String code) { Barrier barrier = null; try { barrier = redisJsonUtil.get("barrier-"+code,Barrier.class); if(barrier != null){ return barrier; }else { // Barrier barrier = null; // try { // String s = redisTemplate.opsForValue().get("barrier-"+code); // if(!StringUtil.isNullOrEmpty(s)){ // barrier = JSON.parseObject(s, Barrier.class); // return barrier; // }else { // QueryWrapper<Barrier> wrapper = new QueryWrapper<>(); // wrapper.lambda() // .eq(Barrier::getCode,code); // List<Barrier> list = list(wrapper); // if(list.size()>0){ // String jsonValue = JSON.toJSONString(list.get(0)); // redisTemplate.opsForValue().set("barrier-"+code, jsonValue); // return list.get(0); // } // } // } catch (Exception e) { // e.printStackTrace(); // return null; // } // return null; QueryWrapper<Barrier> wrapper = new QueryWrapper<>(); wrapper.lambda() .eq(Barrier::getCode,code); List<Barrier> list = list(wrapper); if(list.size()>0){ redisJsonUtil.set("barrier-"+code,list.get(0)); return list.get(0); } } } catch (IOException e) { e.printStackTrace(); }else { return null; } return null; } @Override src/main/java/com/boying/service/impl/OutParkServiceImpl.java
@@ -1,8 +1,10 @@ package com.boying.service.impl; import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.boying.entity.Barrier; import com.boying.entity.OutPark; import com.boying.entity.Park; import com.boying.entity.Statistic; @@ -11,7 +13,9 @@ import com.boying.service.OutParkService; import com.boying.service.StatisticService; import com.boying.util.RedisJsonUtil; import com.boying.util.StringUtil; import lombok.AllArgsConstructor; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import java.io.IOException; @@ -30,7 +34,8 @@ @AllArgsConstructor public class OutParkServiceImpl extends ServiceImpl<OutParkMapper, OutPark> implements OutParkService { private final OutParkMapper outParkMapper; private final RedisJsonUtil redisJsonUtil; private StringRedisTemplate redisTemplate; @Override public int count1() { @@ -113,12 +118,33 @@ @Override public OutPark count4(Integer bId) { OutPark outPark = null; try { outPark = redisJsonUtil.get("outPark-"+bId, OutPark.class); if(outPark != null){ return outPark; }else { // OutPark outPark = null; // try { // String s = redisTemplate.opsForValue().get("outPark-"+bId); // if(!StringUtil.isNullOrEmpty(s)){ // outPark = JSON.parseObject(s, OutPark.class); // return outPark; // }else { // QueryWrapper<OutPark> wrapper = new QueryWrapper<>(); // wrapper.lambda() // .eq(OutPark::getBarrierId,bId) // .eq(OutPark::getStatus,1) // .eq(OutPark::getStatus2,0) // .orderByDesc(OutPark::getCreateTime); // List<OutPark> outParks = outParkMapper.selectList(wrapper); // if(outParks.size()>0){ // String jsonValue = JSON.toJSONString(outParks.get(0)); // redisTemplate.opsForValue().set("outPark-"+bId, jsonValue); // return outParks.get(0); // }else{ // return null; // } // } // } catch (Exception e) { // e.printStackTrace(); // } // return null; QueryWrapper<OutPark> wrapper = new QueryWrapper<>(); wrapper.lambda() .eq(OutPark::getBarrierId,bId) @@ -127,16 +153,10 @@ .orderByDesc(OutPark::getCreateTime); List<OutPark> outParks = outParkMapper.selectList(wrapper); if(outParks.size()>0){ redisJsonUtil.set("outPark-"+bId, outParks.get(0)); return outParks.get(0); }else{ return null; } } } catch (IOException e) { e.printStackTrace(); } return null; } @Override src/main/java/com/boying/service/impl/ParkServiceImpl.java
@@ -1,5 +1,6 @@ package com.boying.service.impl; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.boying.entity.Barrier; @@ -10,7 +11,9 @@ import com.boying.service.ParkService; import com.boying.service.TicketService; import com.boying.util.RedisJsonUtil; import com.boying.util.StringUtil; import lombok.AllArgsConstructor; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import java.io.IOException; @@ -28,7 +31,7 @@ @AllArgsConstructor public class ParkServiceImpl extends ServiceImpl<ParkMapper, Park> implements ParkService { private final ParkMapper parkMapper; private final RedisJsonUtil redisJsonUtil; private StringRedisTemplate redisTemplate; @Override public int count1() { QueryWrapper<Park> wrapper = new QueryWrapper<>(); @@ -46,15 +49,17 @@ public Park getOneById(Integer parkId) { Park park = null; try { park = redisJsonUtil.get("park-"+parkId, Park.class); if(park != null){ String s = redisTemplate.opsForValue().get("park-"+parkId); if(!StringUtil.isNullOrEmpty(s)){ park = JSON.parseObject(s, Park.class); return park; }else { park = getById(parkId); redisJsonUtil.set("park-"+parkId, park); String jsonValue = JSON.toJSONString(park); redisTemplate.opsForValue().set("park-"+parkId, jsonValue); return park; } } catch (IOException e) { } catch (Exception e) { e.printStackTrace(); } return null; src/main/java/com/boying/util/RedisJsonUtil.java
@@ -1,7 +1,9 @@ package com.boying.util; import com.alibaba.fastjson.JSON; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.ibatis.jdbc.Null; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; @@ -17,21 +19,20 @@ */ @Component public class RedisJsonUtil { @Resource private StringRedisTemplate stringRedisTemplate; private final ObjectMapper objectMapper = new ObjectMapper(); private static StringRedisTemplate stringRedisTemplate; public <T> void set(String key, T value) throws IOException { String jsonValue = objectMapper.writeValueAsString(value); public static <T> void set(String key, T value) throws IOException { String jsonValue = JSON.toJSONString(value); stringRedisTemplate.opsForValue().set(key, jsonValue); } public <T> T get(String key, Class<T> type) throws IOException { public static <T> T get(String key, Class<T> type) throws IOException { String jsonValue = stringRedisTemplate.opsForValue().get(key); return jsonValue == null ? null : objectMapper.readValue(jsonValue, type); return jsonValue == null ? null : JSON.parseObject(jsonValue, type); } public void del(String key) { public static void del(String key) { stringRedisTemplate.delete(key); } }