src/main/java/com/boying/controller/BarrierController.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/controller/BarrierController.java
@@ -1,5 +1,6 @@ package com.boying.controller; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.boying.common.R; @@ -10,6 +11,7 @@ import com.boying.service.ParkService; import com.boying.util.RedisJsonUtil; import lombok.RequiredArgsConstructor; 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; @@ -27,7 +29,8 @@ private final BarrierService barrierService; private final OutParkService outParkService; private final ParkService parkService; private final RedisJsonUtil redisJsonUtil; private StringRedisTemplate redisTemplate; @PostMapping("findPage") public Object findPage(Page page, String parkId) { @@ -39,7 +42,7 @@ for(Barrier barrier:records){ long l = System.currentTimeMillis() - barrier.getUpdateTime().toInstant(ZoneOffset.of("+8")).toEpochMilli(); System.out.println(l); if(l>10000){ if(l>20000){ barrier.setStatus(1); } } @@ -52,8 +55,9 @@ barrier.setUpdateTime(LocalDateTime.now()); barrierService.saveOrUpdate(barrier); try { redisJsonUtil.set("barrier-"+barrier.getCode(),barrier); } catch (IOException e) { String jsonValue = JSON.toJSONString(barrier); redisTemplate.opsForValue().set("barrier-"+barrier.getCode(), jsonValue); } catch (Exception e) { e.printStackTrace(); } return R.ok("保存成功"); @@ -63,7 +67,7 @@ public Object delete(Integer id) { Barrier byId = barrierService.getById(id); barrierService.removeById(id); redisJsonUtil.del("barrier-"+byId.getCode()); redisTemplate.delete("barrier-"+byId.getCode()); return R.ok("删除成功"); } @@ -88,8 +92,9 @@ b.setUpdateTime(LocalDateTime.now()); barrierService.saveOrUpdate(b); try { redisJsonUtil.set("barrier-"+b.getCode(),b); } catch (IOException e) { String jsonValue = JSON.toJSONString(b); redisTemplate.opsForValue().set("barrier-"+b.getCode(), jsonValue); } catch (Exception e) { e.printStackTrace(); } return R.ok("请求成功"); @@ -120,8 +125,9 @@ b.setUpdateTime(LocalDateTime.now()); barrierService.saveOrUpdate(b); try { redisJsonUtil.set("barrier-"+b.getCode(),b); } catch (IOException e) { String jsonValue = JSON.toJSONString(b); redisTemplate.opsForValue().set("barrier-"+b.getCode(), jsonValue); } catch (Exception e) { e.printStackTrace(); } return R.ok("请求成功"); @@ -140,8 +146,9 @@ b.setUpdateTime(LocalDateTime.now()); barrierService.saveOrUpdate(b); try { redisJsonUtil.set("barrier-"+b.getCode(),b); } catch (IOException e) { String jsonValue = JSON.toJSONString(b); redisTemplate.opsForValue().set("barrier-"+b.getCode(), jsonValue); } catch (Exception e) { e.printStackTrace(); } return R.ok("请求成功"); @@ -151,8 +158,9 @@ b.setUpdateTime(LocalDateTime.now()); barrierService.saveOrUpdate(b); try { redisJsonUtil.set("barrier-"+b.getCode(),b); } catch (IOException e) { String jsonValue = JSON.toJSONString(b); redisTemplate.opsForValue().set("barrier-"+b.getCode(), jsonValue); } catch (Exception e) { e.printStackTrace(); } return R.ok("请求成功"); src/main/java/com/boying/controller/phone/YCPayController.java
@@ -682,8 +682,8 @@ outPark.setStatus(1); outParkService.saveOrUpdate(outPark); //缓存在redis里 // String jsonValue = JSON.toJSONString(outPark); // redisTemplate.opsForValue().set("outPark-"+outPark.getBarrierId(), jsonValue); String jsonValue = JSON.toJSONString(outPark); redisTemplate.opsForValue().set("outPark-"+outPark.getBarrierId(), jsonValue); } } } src/main/java/com/boying/service/impl/BarrierServiceImpl.java
@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.boying.entity.Barrier; import com.boying.entity.EnterPark; @@ -45,38 +46,38 @@ @Override public Barrier findByCode(String code) { // 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; 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); }else { } } } 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){ // return list.get(0); // }else { // return null; // } } @Override @@ -93,13 +94,22 @@ } @Override public boolean getDateDifIn(Integer barrierId) { public boolean getDateDifIn(Integer parkId) { EnterPark enterPark=null; String s1 = redisTemplate.opsForValue().get("enterPark_dif_" + parkId); if(StringUtils.isBlank(s1)){ QueryWrapper<EnterPark> wrapper = new QueryWrapper<>(); wrapper.lambda() .eq(EnterPark::getBarrierId,barrierId) .eq(EnterPark::getParkId,parkId) .orderByDesc(EnterPark::getId) .last(" limit 1"); EnterPark enterPark = enterParkMapper.selectOne(wrapper); enterPark = enterParkMapper.selectOne(wrapper); String jsonValue = JSON.toJSONString(enterPark); redisTemplate.opsForValue().set("enterPark_dif_"+ parkId, jsonValue); }else { enterPark = JSON.parseObject(s1, EnterPark.class); } if(enterPark != null){ long dif = DateUtil.between(Date.from( enterPark.getCreateTime().atZone( ZoneId.systemDefault()).toInstant()), new Date(), DateUnit.SECOND, false); if(dif >= 5 && dif <= 7){ @@ -123,12 +133,20 @@ @Override public boolean getDateDifOut(Integer barrierId) { OutPark outPark=null; String s1 = redisTemplate.opsForValue().get("outPark_dif_" + barrierId); if(StringUtils.isBlank(s1)){ QueryWrapper<OutPark> wrapper = new QueryWrapper<>(); wrapper.lambda() .eq(OutPark::getBarrierId,barrierId) .orderByDesc(OutPark::getId) .last(" limit 1"); OutPark outPark = outParkMapper.selectOne(wrapper); outPark = outParkMapper.selectOne(wrapper); String jsonValue = JSON.toJSONString(outPark); redisTemplate.opsForValue().set("outPark_dif_"+ barrierId, jsonValue); }else { outPark = JSON.parseObject(s1, OutPark.class); } if(outPark != null){ long dif = DateUtil.between(Date.from( outPark.getCreateTime().atZone( ZoneId.systemDefault()).toInstant()), new Date(), DateUnit.SECOND, false); if(dif >= 20 && dif <= 23){ src/main/java/com/boying/service/impl/OutParkServiceImpl.java
@@ -118,13 +118,20 @@ @Override public OutPark count4(Integer bId) { // OutPark outPark = null; // try { // String s = redisTemplate.opsForValue().get("outPark-"+bId); // if(!StringUtil.isNullOrEmpty(s)){ // outPark = JSON.parseObject(s, OutPark.class); // 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 { return null; } } catch (Exception e) { e.printStackTrace(); } return null; // // QueryWrapper<OutPark> wrapper = new QueryWrapper<>(); // wrapper.lambda() // .eq(OutPark::getBarrierId,bId) @@ -133,30 +140,10 @@ // .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) .eq(OutPark::getStatus,1) .eq(OutPark::getStatus2,0) .orderByDesc(OutPark::getCreateTime); List<OutPark> outParks = outParkMapper.selectList(wrapper); if(outParks.size()>0){ return outParks.get(0); }else{ return null; } } @Override