| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.boying.common.R; |
| | | import com.boying.common.SystemConfigProperties; |
| | | import com.boying.entity.*; |
| | | import com.boying.service.*; |
| | |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.http.HttpServlet; |
| | |
| | | * Servlet implementation class PlateServlet |
| | | */ |
| | | @Controller |
| | | @RequestMapping("/car") |
| | | @RequestMapping("/ffzf/car") |
| | | @RequiredArgsConstructor |
| | | public class PlateServlet3 extends HttpServlet { |
| | | private static final long serialVersionUID = 1L; |
| | |
| | | while((str = reader.readLine()) != null){ |
| | | lineStr += str; |
| | | } |
| | | System.out.println("获取到的道闸推送数据为:"+lineStr); |
| | | // System.out.println("获取到的道闸推送数据为:"+lineStr); |
| | | |
| | | JSONObject jsonObject1 = JSON.parseObject(lineStr); |
| | | JSONObject alarmInfoPlate = jsonObject1.getJSONObject("AlarmInfoPlate"); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 手机号入场 |
| | | * @param |
| | | * @return |
| | | */ |
| | | @PostMapping("/inParkByPhone" ) |
| | | @ResponseBody |
| | | public Object inParkByPhone( EnterPark enterPark){ |
| | | Barrier barrier = barrierService.getById(enterPark.getBarrierId()); |
| | | if(barrier!=null){ |
| | | String num = redisTemplate.opsForValue().get("car_park_" + barrier.getParkId()); |
| | | if(StringUtils.isBlank(num)){ |
| | | num = "0"; |
| | | redisTemplate.opsForValue().set("car_park_" + barrier.getParkId(),num,30, TimeUnit.DAYS); |
| | | redisTemplate.opsForValue().set("park_up_" + barrier.getParkId(),"true",30, TimeUnit.DAYS); |
| | | } |
| | | Park byId = parkService.getById(barrier.getParkId()); |
| | | if(Integer.parseInt(num) >= byId.getNum() ){ |
| | | return R.failed(null,"禁止通行,车位已满"); |
| | | }else { |
| | | enterPark.setCreateTime(LocalDateTime.now()); |
| | | QueryWrapper<Ticket> wrapper = new QueryWrapper<>(); |
| | | wrapper.lambda() |
| | | .eq(Ticket::getCarNo,enterPark.getCarNo()) |
| | | .eq(Ticket::getPayStatus,1); |
| | | List<Ticket> tickets = ticketService.list(wrapper); |
| | | if(tickets.size()>0){ |
| | | enterPark.setStatus(1);//发现有违章 |
| | | } |
| | | enterParkService.deleteByCarNo(enterPark.getCarNo(),enterPark.getParkId()); |
| | | enterParkService.save(enterPark); |
| | | return R.ok(); |
| | | } |
| | | } |
| | | return R.failed(null,"数据异常"); |
| | | } |
| | | |
| | | /** |
| | | * 手机号出场 |
| | | * @param |
| | | * @return |
| | | */ |
| | | @PostMapping("/outParkByPhone" ) |
| | | @ResponseBody |
| | | public Object outParkByPhone(String code2,String carNo){ |
| | | Barrier byCode2 = barrierService.findByCode2(code2); |
| | | QueryWrapper<EnterPark> wrapper =new QueryWrapper<>(); |
| | | wrapper.lambda() |
| | | .eq(EnterPark::getParkId,byCode2.getParkId()) |
| | | .eq(EnterPark::getCarNo,carNo); |
| | | EnterPark one = enterParkService.getOne(wrapper); |
| | | if(one != null){ |
| | | double money = 0.0; |
| | | String toDayHrMinSec = null; |
| | | OutPark outPark = new OutPark(); |
| | | outPark.setCarNo(carNo); |
| | | outPark.setParkId(one.getParkId()); |
| | | outPark.setBarrierId(byCode2.getId()); |
| | | outPark.setCreateTime(LocalDateTime.now()); |
| | | outPark.setCode(System.currentTimeMillis()+""); |
| | | System.out.println("入场记录:"+one); |
| | | outPark.setEnterTime(one.getCreateTime()); |
| | | outPark.setParkName(byCode2.getName()); |
| | | if(outPark.getTime() > 0){ |
| | | outPark.setTimeStr(DateUtilOther.millisToDayHrMinSec(new Double(outPark.getTime()).longValue())); |
| | | }else { |
| | | outPark.setTimeStr("不足一分钟"); |
| | | } |
| | | try { |
| | | long l = outPark.getCreateTime().toInstant(ZoneOffset.of("+8")).toEpochMilli() - one.getCreateTime().toInstant(ZoneOffset.of("+8")).toEpochMilli(); |
| | | outPark.setTime(l/(1000*60)); |
| | | toDayHrMinSec = DateUtilOther.millisToDayHrMinSec(l/(1000*60)); |
| | | money = costRuleService.getMoney(one.getParkId(), outPark.getEnterTime(), outPark.getCreateTime(), 1); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | outPark.setPrice(money); |
| | | outPark.setStatus3(findTicket(carNo)); |
| | | outParkService.saveOrUpdate(outPark); |
| | | byCode2.setCarNo(carNo); |
| | | //led展示 |
| | | if(toDayHrMinSec == null){ |
| | | return R.failed("异常记录"); |
| | | } |
| | | if(outPark.getPrice()==0&&outPark.getStatus3()==0){ |
| | | System.out.println(outPark.getCarNo()+"该车不需要缴费"); |
| | | String s= "1."+byCode2.getCarNo()+"该车不需要缴费\n"; |
| | | writeTxt2(s); |
| | | byCode2.setType2(1); |
| | | barrierService.updateById(byCode2); |
| | | return R.ok(outPark); |
| | | }else { |
| | | //需要缴费或者有违章 |
| | | System.out.println(outPark.getCarNo()+"该车需要缴费"+outPark.getPrice()); |
| | | String s= "1."+byCode2.getCarNo()+"该车需要缴费\n"; |
| | | writeTxt2(s); |
| | | barrierService.updateById(byCode2); |
| | | return R.ok(outPark); |
| | | } |
| | | |
| | | }else { |
| | | return R.failed("未查询到入场记录"); |
| | | } |
| | | } |
| | | |
| | | |
| | | private void writeTxt( String txt) |
| | | { |