src/main/java/com/boying/common/ScheduledTaskConfig.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/boying/controller/BarrierController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/boying/controller/ParkController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/boying/controller/UserController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/boying/controller/phone/NoticeController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/boying/entity/Park.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/boying/entity/User.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/boying/scheduled/Scheduled1.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/boying/service/OutParkService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/boying/common/ScheduledTaskConfig.java
New file @@ -0,0 +1,25 @@ package com.boying.common; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.SchedulingConfigurer; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.scheduling.config.ScheduledTaskRegistrar; /** * @author kdq * @version 1.0.0 * @ClassName ScheduledTaskConfig.java * @Description TODO * @createTime 2022年09月21日 16:08:00 */ @Configuration public class ScheduledTaskConfig implements SchedulingConfigurer { @Override public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) { ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); taskScheduler.setPoolSize(3); taskScheduler.initialize(); scheduledTaskRegistrar.setTaskScheduler(taskScheduler); } } src/main/java/com/boying/controller/BarrierController.java
@@ -7,12 +7,10 @@ import com.boying.common.util.DateUtil; import com.boying.common.util.HttpUtil; import com.boying.common.util.StringUtil; import com.boying.entity.Barrier; import com.boying.entity.EnterPark; import com.boying.entity.Park; import com.boying.entity.User; import com.boying.entity.*; import com.boying.service.BarrierService; import com.boying.service.EnterParkService; import com.boying.service.OutParkService; import com.boying.service.ParkService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; @@ -40,6 +38,8 @@ private BarrierService barrierService; @Autowired private SystemConfigProperties systemConfigProperties; @Autowired private OutParkService outParkService; @PostMapping("findPage") public Object findPage(int page,int pageSize,String parkId) { @@ -125,4 +125,35 @@ barrierService.save(b); return success("请求成功"); } @PostMapping("openBarrier") public Object openBarrier(Long barrierId,Integer type) { Barrier b= (Barrier) barrierService.findById(barrierId); if (b==null) { return error("未找到该道闸"); }else { if(b.getType() == 1){ //入口闸,直接开启 b.setType2(1); barrierService.save(b); return success("请求成功"); }else { //出口闸,判断状态 if(type == null || type == 0){ //取消计费 OutPark outPark = outParkService.findByCarNoAndBarrierId(b.getCarNo(), b.getId()); outPark.setPrice(0d); outParkService.save(outPark); b.setType2(1); barrierService.save(b); return success("请求成功"); }else { //计费 b.setType2(1); barrierService.save(b); return success("请求成功"); } } } } } src/main/java/com/boying/controller/ParkController.java
@@ -1,25 +1,43 @@ package com.boying.controller; import com.boying.common.BaseController; import com.boying.common.util.StringUtil; import com.boying.entity.Park; import com.boying.entity.User; import com.boying.service.ParkService; import com.boying.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; 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; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @RestController @RequestMapping("park") public class ParkController extends BaseController { @Autowired private StringRedisTemplate redisTemplate; @Autowired private ParkService parkService; @Autowired private UserService userService; @PostMapping("findPage") public Object findPage(int page,int pageSize) { @@ -42,7 +60,47 @@ @PostMapping("findAll") public Object findAll() { List all = parkService.findAll(); return success("删除成功",all); List<Park> all = parkService.findAll(); for (Park park : all) { String s = redisTemplate.opsForValue().get("car_park_" + park.getId()); if(StringUtil.isNullOrEmpty(s)){ park.setCarNum(0); }else { park.setCarNum(Integer.parseInt(s)); } } return success("查询成功",all); } @PostMapping("getCarNum") public Object getCarNum(Long parkId) { Park byId = (Park) parkService.findById(parkId); String s = redisTemplate.opsForValue().get("car_park_" + parkId); if(StringUtil.isNullOrEmpty(s)){ byId.setCarNum(0); }else { byId.setCarNum(Integer.parseInt(s)); } return success("查询成功",byId); } @PostMapping("getByUserId") public Object getByUserId(Long userId) { User byId = (User)userService.findById(userId); List<Park> list = new ArrayList<>(); if(byId == null){ return error("未查询到用户"); }else { String parkIds = byId.getParkIds(); if(StringUtil.isNullOrEmpty(parkIds)){ return error("该用户未管理停车场"); } List<Long> ids= Arrays.stream(parkIds.split(",")).map(s->Long.parseLong(s.trim())).collect(Collectors.toList()); for (Long id : ids) { list.add((Park) parkService.findById(id)); } return success("查询成功",list); } } } src/main/java/com/boying/controller/UserController.java
@@ -135,4 +135,6 @@ } return error("旧密码不正确"); } } src/main/java/com/boying/controller/phone/NoticeController.java
@@ -64,7 +64,7 @@ }; List<EnterPark> all = enterParkService.findAll(specification2); for(EnterPark enterPark:all){ Park park = (Park) parkService.findById(enterPark.getId()); Park park = (Park) parkService.findById(enterPark.getParkId()); enterPark.setParkName(park.getName()); } return success("",all); @@ -88,6 +88,12 @@ } }; Page<EnterPark> all = enterParkService.findPage(pageable,specification2); for (EnterPark enterPark : all.getContent()) { Park byId = (Park)parkService.findById(enterPark.getParkId()); if(byId != null){ enterPark.setParkName(byId.getName()); } } return success("",all); } } src/main/java/com/boying/entity/Park.java
@@ -4,6 +4,7 @@ import javax.persistence.Entity; import javax.persistence.Table; import javax.persistence.Transient; @Table(name = "park") @Entity @@ -15,6 +16,8 @@ private String content;//描述 private String lng;//经度 private String lat;//纬度 @Transient private int carNum;//当前车数 public String getName() { @@ -64,4 +67,8 @@ public void setLat(String lat) { this.lat = lat; } public int getCarNum(){return carNum;} public void setCarNum(int carNum){this.carNum = carNum;} } src/main/java/com/boying/entity/User.java
@@ -18,6 +18,7 @@ private String lng; private String lat; private Long parkId; private String parkIds; public String getName() { return name; @@ -90,4 +91,12 @@ public void setParkId(Long parkId) { this.parkId = parkId; } public String getParkIds() { return parkIds; } public void setParkIds(String parkIds) { this.parkIds = parkIds; } } src/main/java/com/boying/scheduled/Scheduled1.java
@@ -8,6 +8,7 @@ import org.springframework.stereotype.Component; import java.io.IOException; import java.util.Date; import java.util.List; //大屏页面统计 @@ -27,21 +28,23 @@ @Autowired private TicketBlackService ticketBlackService; @Scheduled(cron = "0 0 * * * ?") @Scheduled(cron = "0 0/40 * * * ?") public void execute() throws IOException { System.out.println("开始定时任务-------》"); List<TicketBlack> list = ticketBlackService.updateType(); for(TicketBlack t:list){ t.setBlackType(1); ticketBlackService.save(t); if(list.size() > 0){ for(TicketBlack t:list){ t.setBlackType(1); ticketBlackService.save(t); } } List<Statistic> all = statisticService.findAll(); Statistic statistic = all.get(0); if(statistic==null){ return; } statistic.setCreateTime(new Date()); statistic.setData1(outParkService.count1()); statistic.setData2(outParkService.count2()); statistic.setData3(outParkService.sumByPrice()); @@ -72,5 +75,6 @@ statistic.setData19(ticketBlackService.count1()); statistic.setData20(ticketBlackService.count2()); statisticService.save(statistic); System.out.println("结束定时任务-------》"); } } src/main/java/com/boying/service/OutParkService.java
@@ -17,6 +17,7 @@ import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; import java.util.ArrayList; import java.util.Date; import java.util.List; @Service @@ -93,4 +94,9 @@ public OutPark findByCarNoAndBarrierId(String carNo, Long id) { return outParkDao.findByCarNoAndBarrierId(carNo,id); } public static void main(String[] args) { Date startTime = DateUtil.getEndTime(); System.out.println(startTime); } }