public void remove(Long TIPId) throws InstanceNotFoundException, InvalidRouteException {
   List<Route> routes = routeDao.getRoutesByTIP(TIPId);
   tipDao.remove(TIPId);
   for (Route route : routes) {
     if (routeDao.getTIPsInOrder(route.getId()).size() < 2) {
       routeDao.remove(route.getId());
     } else {
       routeService.updateRouteFromTIPs(route);
     }
   }
 }
Example #2
0
  /**
   * 测试注解
   *
   * @throws Exception
   */
  @Test
  public void testHint() throws Exception {
    SchemaConfig schema = schemaMap.get("TESTDB");
    // 使用注解(新注解,/*后面没有空格),路由到1个节点
    String sql =
        "/*!mycat: sql = select * from employee where sharding_id = 10010 */select * from employee";
    CacheService cacheService = new CacheService();
    RouteService routerService = new RouteService(cacheService);
    RouteResultset rrs =
        routerService.route(new SystemConfig(), schema, ServerParse.SELECT, sql, "UTF-8", null);
    Assert.assertTrue(rrs.getNodes().length == 1);

    // 使用注解(新注解,/*后面有空格),路由到1个节点
    sql =
        "/*#mycat: sql = select * from employee where sharding_id = 10000 */select * from employee";
    rrs = routerService.route(new SystemConfig(), schema, ServerParse.SELECT, sql, "UTF-8", null);
    Assert.assertTrue(rrs.getNodes().length == 1);

    // 不用注解,路由到2个节点
    sql = "select * from employee";
    rrs = routerService.route(new SystemConfig(), schema, ServerParse.SELECT, sql, "UTF-8", null);
    Assert.assertTrue(rrs.getNodes().length == 2);
  }
  @RequestMapping(
      value = "/{invoiceId}/control-letters/{id}/rows/create",
      method = RequestMethod.GET)
  public String showControlLetterRowCreateForm(
      @PathVariable("invoiceId") int invoiceId, @PathVariable("id") int id, Model model) {
    ControlLetterRow controlLetterRow = new ControlLetterRow();
    // TODO: Validate id that coming from form
    controlLetterRow.setControlLetterId(id);

    List<Employee> employees = employeeService.findAll(Employee.EmployeePosition.CONDUCTOR.getId());
    List<Route> routes = routeService.findAll();

    model.addAttribute("controlLetterRow", controlLetterRow);
    model.addAttribute("routes", routes);
    model.addAttribute("employees", employees);
    model.addAttribute("invoiceId", invoiceId);

    return "controlLetterRow/edit";
  }
  @RequestMapping(value = "/{invoiceId}/control-letters/{controlLetterId}/rows/{id}")
  public String showControlLetterRow(
      @PathVariable("invoiceId") int invoiceId,
      @PathVariable("controlLetterId") int controlLetterId,
      @PathVariable("id") int id,
      Model model) {

    ControlLetterRow controlLetterRow = controlLetterRowService.find(id);
    if (controlLetterRow == null) throw new ResourceNotFoundException();
    controlLetterRow.setControlLetterId(controlLetterId);

    List<Employee> employees = employeeService.findAll(Employee.EmployeePosition.CONDUCTOR.getId());
    List<Route> routes = routeService.findAll();

    model.addAttribute("routes", routes);
    model.addAttribute("employees", employees);
    model.addAttribute("controlLetterRow", controlLetterRow);
    model.addAttribute("invoiceId", invoiceId);

    return "controlLetterRow/edit";
  }
  @RequestMapping(value = "/{invoiceId}/control-letters/{id}/rows", method = RequestMethod.POST)
  public String createOrUpdateControlLetterRow(
      @PathVariable("id") int controlLetterid,
      @PathVariable("invoiceId") int invoiceId,
      @ModelAttribute("controlLetterRow") @Validated ControlLetterRow controlLetterRow,
      BindingResult bindingResult,
      Model model,
      RedirectAttributes redirectAttributes) {

    if (!bindingResult.hasErrors())
      controlLetterRowValidator.validate(controlLetterRow, bindingResult);

    if (bindingResult.hasErrors()) {
      List<Employee> employees =
          employeeService.findAll(Employee.EmployeePosition.CONDUCTOR.getId());
      List<Route> routes = routeService.findAll();
      model.addAttribute("routes", routes);
      model.addAttribute("employees", employees);
      model.addAttribute("invoiceId", invoiceId);
      model.addAttribute("employees", employees);

      return "controlLetterRow/edit";
    }

    // TODO: Trigger
    // Якщо рядок новий, то кондуктор ще не повертав квитки, отже вважаємо, що він повернув все, що
    // отримав
    if (controlLetterRow.isNew())
      controlLetterRow.setTicketsReturned(controlLetterRow.getTicketsGiven());

    return handleSaving(
        controlLetterRow,
        controlLetterRowService,
        redirectAttributes,
        "tickets-invoices/" + invoiceId + "/control-letters/" + controlLetterid + "/rows");
  }