Commit 35f9dfc4710347241726a94423a62345cbf4dba4

Authored by 王通
1 parent f6bd8e54

1.终点站级可加入前置电子围栏

src/main/java/com/bsth/controller/GeoPremiseController.java 0 → 100644
  1 +package com.bsth.controller;
  2 +
  3 +import com.bsth.common.ResponseCode;
  4 +import com.bsth.entity.GeoPremise;
  5 +import com.bsth.service.GeoPremiseService;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.web.bind.annotation.RequestMapping;
  8 +import org.springframework.web.bind.annotation.RequestMethod;
  9 +import org.springframework.web.bind.annotation.RestController;
  10 +
  11 +import java.util.HashMap;
  12 +import java.util.Map;
  13 +
  14 +/**
  15 + * @author Hill
  16 + */
  17 +@RestController
  18 +@RequestMapping("/api/geopremise")
  19 +public class GeoPremiseController extends BaseController<GeoPremise, Integer> {
  20 +
  21 + @Autowired
  22 + private GeoPremiseService geoPremiseService;
  23 +
  24 + @Override
  25 + @RequestMapping(method = RequestMethod.POST)
  26 + public Map<String, Object> save(GeoPremise geoPremise) {
  27 + Map<String, Object> result = new HashMap<>();
  28 + try {
  29 + result.putAll(geoPremiseService.save(geoPremise));
  30 + result.put("status", ResponseCode.SUCCESS);
  31 + } catch (Exception e) {
  32 + result.put("status", ResponseCode.ERROR);
  33 + }
  34 +
  35 + return result;
  36 + }
  37 +}
... ...
src/main/java/com/bsth/entity/GeoPremise.java 0 → 100644
  1 +package com.bsth.entity;
  2 +
  3 +import javax.persistence.Entity;
  4 +import javax.persistence.Id;
  5 +import javax.persistence.Table;
  6 +
  7 +/**
  8 + * @author Hill
  9 + */
  10 +@Entity
  11 +@Table(name = "bsth_f_geo_premise")
  12 +public class GeoPremise {
  13 +
  14 + @Id
  15 + private Integer id;
  16 +
  17 + private String name;
  18 +
  19 + /**
  20 + * 线路代码
  21 + */
  22 + private String lineCode;
  23 +
  24 + /**
  25 + * 上下行
  26 + * 0上行 1下行
  27 + */
  28 + private int upDown;
  29 +
  30 + /**
  31 + * 站点编码
  32 + */
  33 + private String stationCode;
  34 +
  35 + /**
  36 + * 坐标
  37 + */
  38 + private String coords;
  39 +
  40 + public Integer getId() {
  41 + return id;
  42 + }
  43 +
  44 + public void setId(Integer id) {
  45 + this.id = id;
  46 + }
  47 +
  48 + public String getName() {
  49 + return name;
  50 + }
  51 +
  52 + public void setName(String name) {
  53 + this.name = name;
  54 + }
  55 +
  56 + public String getLineCode() {
  57 + return lineCode;
  58 + }
  59 +
  60 + public void setLineCode(String lineCode) {
  61 + this.lineCode = lineCode;
  62 + }
  63 +
  64 + public int getUpDown() {
  65 + return upDown;
  66 + }
  67 +
  68 + public void setUpDown(int upDown) {
  69 + this.upDown = upDown;
  70 + }
  71 +
  72 + public String getStationCode() {
  73 + return stationCode;
  74 + }
  75 +
  76 + public void setStationCode(String stationCode) {
  77 + this.stationCode = stationCode;
  78 + }
  79 +
  80 + public String getCoords() {
  81 + return coords;
  82 + }
  83 +
  84 + public void setCoords(String coords) {
  85 + this.coords = coords;
  86 + }
  87 +}
... ...
src/main/java/com/bsth/repository/GeoPremiseRepository.java 0 → 100644
  1 +package com.bsth.repository;
  2 +
  3 +import com.bsth.entity.GeoPremise;
  4 +import org.springframework.stereotype.Repository;
  5 +
  6 +/**
  7 + * @author Hill
  8 + */
  9 +@Repository
  10 +public interface GeoPremiseRepository extends BaseRepository<GeoPremise, Integer> {
  11 +
  12 +}
... ...
src/main/java/com/bsth/service/GeoPremiseService.java 0 → 100644
  1 +package com.bsth.service;
  2 +
  3 +import com.bsth.entity.GeoPremise;
  4 +
  5 +/**
  6 + * @author Hill
  7 + */
  8 +public interface GeoPremiseService extends BaseService<GeoPremise, Integer> {
  9 +
  10 +}
... ...
src/main/java/com/bsth/service/impl/GeoPremiseServiceImpl.java 0 → 100644
  1 +package com.bsth.service.impl;
  2 +
  3 +import com.bsth.entity.GeoPremise;
  4 +import com.bsth.entity.LsStationRoute;
  5 +import com.bsth.repository.GeoPremiseRepository;
  6 +import com.bsth.repository.LsStationRouteRepository;
  7 +import com.bsth.service.GeoPremiseService;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.stereotype.Service;
  10 +
  11 +import java.util.HashMap;
  12 +import java.util.Map;
  13 +import java.util.Optional;
  14 +
  15 +/**
  16 + * @author Hill
  17 + */
  18 +@Service
  19 +public class GeoPremiseServiceImpl extends BaseServiceImpl<GeoPremise, Integer> implements GeoPremiseService {
  20 +
  21 + @Autowired
  22 + private GeoPremiseRepository geoPremiseRepository;
  23 +
  24 + @Autowired
  25 + private LsStationRouteRepository lsStationRouteRepository;
  26 +
  27 + @Override
  28 + public GeoPremise findById(Integer id) {
  29 + Optional<GeoPremise> optional = geoPremiseRepository.findById(id);
  30 + return optional.isPresent() ? optional.get() : new GeoPremise();
  31 + }
  32 +
  33 + @Override
  34 + public Map<String, Object> save(GeoPremise geoPremise) {
  35 + Map<String, Object> result = new HashMap<>();
  36 + LsStationRoute stationRoute = lsStationRouteRepository.findById(geoPremise.getId()).get();
  37 + geoPremise.setLineCode(stationRoute.getLineCode());
  38 + geoPremise.setUpDown(stationRoute.getDirections());
  39 + geoPremise.setStationCode(stationRoute.getStationCode());
  40 + geoPremise.setName(String.format("%s-%s", stationRoute.getStationName(), stationRoute.getDirections() == 0 ? "上行" : "下行"));
  41 + geoPremiseRepository.save(geoPremise);
  42 +
  43 + return result;
  44 + }
  45 +}
... ...