src/main/java/com/boying/controller/BarrierController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
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/ParkService.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/BarrierController.java
@@ -8,11 +8,13 @@ import com.boying.service.BarrierService; import com.boying.service.OutParkService; import com.boying.service.ParkService; import com.boying.util.RedisJsonUtil; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.io.IOException; import java.time.LocalDateTime; import java.time.ZoneOffset; import java.util.List; @@ -25,6 +27,7 @@ private final BarrierService barrierService; private final OutParkService outParkService; private final ParkService parkService; private final RedisJsonUtil redisJsonUtil; @PostMapping("findPage") public Object findPage(Page page, String parkId) { @@ -48,12 +51,19 @@ public Object save(Barrier barrier) { barrier.setUpdateTime(LocalDateTime.now()); barrierService.saveOrUpdate(barrier); try { redisJsonUtil.set("barrier-"+barrier.getCode(),barrier); } catch (IOException e) { e.printStackTrace(); } return R.ok("保存成功"); } @PostMapping("delete") public Object delete(Integer id) { Barrier byId = barrierService.getById(id); barrierService.removeById(id); redisJsonUtil.del("barrier-"+byId.getCode()); return R.ok("删除成功"); } @@ -77,6 +87,11 @@ b.setType2(1); b.setUpdateTime(LocalDateTime.now()); barrierService.saveOrUpdate(b); try { redisJsonUtil.set("barrier-"+b.getCode(),b); } catch (IOException e) { e.printStackTrace(); } return R.ok("请求成功"); } @@ -104,6 +119,11 @@ b.setType2(1); b.setUpdateTime(LocalDateTime.now()); barrierService.saveOrUpdate(b); try { redisJsonUtil.set("barrier-"+b.getCode(),b); } catch (IOException e) { e.printStackTrace(); } return R.ok("请求成功"); }else { System.out.println("手动开出口闸"); @@ -119,12 +139,22 @@ b.setType2(1); b.setUpdateTime(LocalDateTime.now()); barrierService.saveOrUpdate(b); try { redisJsonUtil.set("barrier-"+b.getCode(),b); } catch (IOException e) { e.printStackTrace(); } return R.ok("请求成功"); }else { //计费 b.setType2(1); b.setUpdateTime(LocalDateTime.now()); barrierService.saveOrUpdate(b); try { redisJsonUtil.set("barrier-"+b.getCode(),b); } catch (IOException e) { e.printStackTrace(); } return R.ok("请求成功"); } } src/main/java/com/boying/controller/ParkController.java
@@ -9,6 +9,7 @@ import com.boying.entity.User; import com.boying.service.ParkService; import com.boying.service.UserService; import com.boying.util.RedisJsonUtil; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; @@ -17,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -32,6 +34,7 @@ private StringRedisTemplate redisTemplate; private final ParkService parkService; private final UserService userService; private final RedisJsonUtil redisJsonUtil; @PostMapping("/findPage") public Object findPage(Page page) { @@ -58,12 +61,18 @@ redisTemplate.opsForValue().set("car_park_" + park.getId(),"0",30, TimeUnit.DAYS); redisTemplate.opsForValue().set("park_up_" + park.getId(),"true",30, TimeUnit.DAYS); } try { redisJsonUtil.set("park-"+park.getId(), park); } catch (IOException e) { e.printStackTrace(); } return R.ok("保存成功"); } @PostMapping("/delete") public Object delete(Long id) { parkService.removeById(id); redisJsonUtil.del("park-"+id); return R.ok("删除成功"); } src/main/java/com/boying/controller/car/PlateServlet3.java
@@ -12,6 +12,7 @@ import com.boying.service.*; import com.boying.util.DateUtilOther; import com.boying.util.FileUtil; import com.boying.util.RedisJsonUtil; import com.boying.util.StringUtil; import com.google.gson.JsonObject; import com.google.gson.JsonParser; @@ -61,6 +62,7 @@ private final FileInfoService fileInfoService; private final TicketBlackService ticketBlackService; private final OutParkLogService outParkLogService; private final RedisJsonUtil redisJsonUtil; private final String LEDURL = "http://192.168.31.212:9988/LedShow/IGetResultDataAllLine"; /** @@ -140,7 +142,7 @@ @PostMapping("/status") public void heart(String serialno,HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { Barrier barrier = barrierService.findByCode(serialno); Park park = parkService.getById(barrier.getParkId()); Park park = parkService.getOneById(barrier.getParkId()); String redis = redisTemplate.opsForValue().get("park_up_" + park.getId()); String redisnum = redisTemplate.opsForValue().get("car_park_" + park.getId()); if(barrier!=null){ @@ -171,37 +173,49 @@ barrier.setStatus(0); barrier.setUpdateTime(LocalDateTime.now()); barrierService.saveOrUpdate(barrier); try { redisJsonUtil.set("barrier-"+barrier.getCode(),barrier); } catch (IOException e) { e.printStackTrace(); } easyOpen(request,response); }else { //不需开闸 barrier.setStatus(0); barrier.setUpdateTime(LocalDateTime.now()); barrierService.saveOrUpdate(barrier); OutPark outPark = outParkService.count4(barrier.getId()); if(outPark!=null){ if(barrier.getType() == 0){ int i = Integer.parseInt(redisnum); i--; if(i<0){ String s= "2."+outPark.getCarNo()+"缴费完成,场内停车数为"+i+"\n"; writeTxt2(s); redisTemplate.opsForValue().set("car_park_" + park.getId(),"0",30, TimeUnit.DAYS); redisTemplate.opsForValue().set("park_up_" + park.getId(),"true",30, TimeUnit.DAYS); }else { String s= "2."+outPark.getCarNo()+"缴费完成,场内停车数为"+i+"\n"; writeTxt2(s); redisTemplate.opsForValue().set("car_park_" + park.getId(),Integer.toString(i),30, TimeUnit.DAYS); redisTemplate.opsForValue().set("park_up_" + park.getId(),"true",30, TimeUnit.DAYS); try { redisJsonUtil.set("barrier-"+barrier.getCode(),barrier); } catch (IOException e) { e.printStackTrace(); } if(barrier.getType() == 0){ OutPark outPark = outParkService.count4(barrier.getId()); if(outPark!=null){ if(barrier.getType() == 0){ int i = Integer.parseInt(redisnum); i--; if(i<0){ String s= "2."+outPark.getCarNo()+"缴费完成,场内停车数为"+i+"\n"; writeTxt2(s); redisTemplate.opsForValue().set("car_park_" + park.getId(),"0",30, TimeUnit.DAYS); redisTemplate.opsForValue().set("park_up_" + park.getId(),"true",30, TimeUnit.DAYS); }else { String s= "2."+outPark.getCarNo()+"缴费完成,场内停车数为"+i+"\n"; writeTxt2(s); redisTemplate.opsForValue().set("car_park_" + park.getId(),Integer.toString(i),30, TimeUnit.DAYS); redisTemplate.opsForValue().set("park_up_" + park.getId(),"true",30, TimeUnit.DAYS); } } outPark.setStatus2(1); outParkService.saveOrUpdate(outPark); easyOpen(request,response); OutParkLog byOutPark = outParkLogService.getByOutPark(outPark.getCarNo(), outPark.getId()); byOutPark.setOpenTime(LocalDateTime.now()); outParkLogService.saveOrUpdate(byOutPark); enterParkService.deleteByCarNo(outPark.getCarNo(), barrier.getParkId()); redisJsonUtil.del("outPark-"+outPark.getBarrierId()); } outPark.setStatus2(1); outParkService.saveOrUpdate(outPark); easyOpen(request,response); easyOpen(request,response); OutParkLog byOutPark = outParkLogService.getByOutPark(outPark.getCarNo(), outPark.getId()); byOutPark.setOpenTime(LocalDateTime.now()); outParkLogService.saveOrUpdate(byOutPark); enterParkService.deleteByCarNo(outPark.getCarNo(), barrier.getParkId()); } if(barrier.getType() == 1){ boolean in = barrierService.getDateDifIn(barrier.getId()); src/main/java/com/boying/controller/phone/YCPayController.java
@@ -14,9 +14,11 @@ 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.*; @@ -36,6 +38,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; /** * @author kdq @@ -60,6 +63,8 @@ private final EnterParkService enterParkService; private final WXService wxService; private final OutParkLogService outParkLogService; private final RedisJsonUtil redisJsonUtil; /** * 查询订单接口 @@ -680,6 +685,12 @@ if(status.equals("03")){ outPark.setStatus(1); outParkService.saveOrUpdate(outPark); //缓存在redis里 try { redisJsonUtil.set("outPark-"+outPark.getBarrierId(), outPark); } catch (IOException e) { e.printStackTrace(); } } } } src/main/java/com/boying/service/ParkService.java
@@ -12,4 +12,6 @@ */ public interface ParkService extends IService<Park> { int count1(); Park getOneById(Integer parkId); } src/main/java/com/boying/service/impl/BarrierServiceImpl.java
@@ -14,10 +14,12 @@ import com.boying.mapper.ParkMapper; import com.boying.service.BarrierService; import com.boying.service.EnterParkService; import com.boying.util.RedisJsonUtil; import lombok.AllArgsConstructor; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import java.io.IOException; import java.time.ZoneId; import java.util.Date; import java.util.List; @@ -37,17 +39,29 @@ private OutParkMapper outParkMapper; private StringRedisTemplate redisTemplate; private ParkMapper parkMapper; private RedisJsonUtil redisJsonUtil; @Override public Barrier findByCode(String code) { 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 { Barrier barrier = null; try { barrier = redisJsonUtil.get("barrier-"+code,Barrier.class); if(barrier != null){ return barrier; }else { 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(); return null; } return null; } @Override src/main/java/com/boying/service/impl/OutParkServiceImpl.java
@@ -4,14 +4,17 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.boying.entity.OutPark; import com.boying.entity.Park; import com.boying.entity.Statistic; import com.boying.mapper.OutParkMapper; import com.boying.mapper.StatisticMapper; import com.boying.service.OutParkService; import com.boying.service.StatisticService; import com.boying.util.RedisJsonUtil; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; import java.io.IOException; import java.util.Date; import java.util.List; import java.util.Map; @@ -27,6 +30,7 @@ @AllArgsConstructor public class OutParkServiceImpl extends ServiceImpl<OutParkMapper, OutPark> implements OutParkService { private final OutParkMapper outParkMapper; private final RedisJsonUtil redisJsonUtil; @Override public int count1() { @@ -109,18 +113,30 @@ @Override public OutPark count4(Integer bId) { 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; OutPark outPark = null; try { outPark = redisJsonUtil.get("outPark-"+bId, OutPark.class); if(outPark != null){ 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){ 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
@@ -2,15 +2,19 @@ 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.Park; import com.boying.entity.Ticket; import com.boying.mapper.ParkMapper; import com.boying.mapper.TicketMapper; import com.boying.service.ParkService; import com.boying.service.TicketService; import com.boying.util.RedisJsonUtil; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; import java.io.IOException; import java.util.List; import java.util.Map; /** @@ -24,6 +28,7 @@ @AllArgsConstructor public class ParkServiceImpl extends ServiceImpl<ParkMapper, Park> implements ParkService { private final ParkMapper parkMapper; private final RedisJsonUtil redisJsonUtil; @Override public int count1() { QueryWrapper<Park> wrapper = new QueryWrapper<>(); @@ -36,4 +41,22 @@ return sum.intValue(); } } @Override public Park getOneById(Integer parkId) { Park park = null; try { park = redisJsonUtil.get("park-"+parkId, Park.class); if(park != null){ return park; }else { park = getById(parkId); redisJsonUtil.set("park-"+parkId, park); return park; } } catch (IOException e) { e.printStackTrace(); } return null; } } src/main/java/com/boying/util/RedisJsonUtil.java
New file @@ -0,0 +1,37 @@ package com.boying.util; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.ibatis.jdbc.Null; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.io.IOException; /** * @author kdq * @version 1.0.0 * @ClassName RedisJsonUtil.java * @Description TODO * @createTime 2024年03月18日 15:20:00 */ @Component public class RedisJsonUtil { @Resource private StringRedisTemplate stringRedisTemplate; private final ObjectMapper objectMapper = new ObjectMapper(); public <T> void set(String key, T value) throws IOException { String jsonValue = objectMapper.writeValueAsString(value); stringRedisTemplate.opsForValue().set(key, jsonValue); } public <T> T get(String key, Class<T> type) throws IOException { String jsonValue = stringRedisTemplate.opsForValue().get(key); return jsonValue == null ? null : objectMapper.readValue(jsonValue, type); } public void del(String key) { stringRedisTemplate.delete(key); } }