Commit a2558d9df711f644c8b485430852df7b1df5ba0f
Merge branch 'minhang' of git@192.168.168.201:panzhaov5/bsth_control.git into minhang
Showing
12 changed files
with
479 additions
and
19 deletions
Too many changes to show.
To preserve performance only 12 of 22 files are displayed.
pom.xml
| @@ -299,6 +299,11 @@ | @@ -299,6 +299,11 @@ | ||
| 299 | <version>3.3.0</version> | 299 | <version>3.3.0</version> |
| 300 | </dependency> | 300 | </dependency> |
| 301 | 301 | ||
| 302 | + <dependency> | ||
| 303 | + <groupId>com.github.stuxuhai</groupId> | ||
| 304 | + <artifactId>jpinyin</artifactId> | ||
| 305 | + <version>1.1.8</version> | ||
| 306 | + </dependency> | ||
| 302 | </dependencies> | 307 | </dependencies> |
| 303 | 308 | ||
| 304 | <dependencyManagement> | 309 | <dependencyManagement> |
src/main/java/com/bsth/controller/PersonnelController.java
| 1 | package com.bsth.controller; | 1 | package com.bsth.controller; |
| 2 | 2 | ||
| 3 | +import com.bsth.common.Constants; | ||
| 4 | +import com.bsth.data.pinyin.PersionPinYin; | ||
| 5 | +import com.bsth.data.pinyin.PersionPinYinBuffer; | ||
| 3 | import com.bsth.entity.Personnel; | 6 | import com.bsth.entity.Personnel; |
| 7 | +import com.bsth.entity.sys.CompanyAuthority; | ||
| 4 | import com.bsth.service.PersonnelService; | 8 | import com.bsth.service.PersonnelService; |
| 5 | import org.springframework.beans.factory.annotation.Autowired; | 9 | import org.springframework.beans.factory.annotation.Autowired; |
| 6 | import org.springframework.web.bind.annotation.RequestMapping; | 10 | import org.springframework.web.bind.annotation.RequestMapping; |
| @@ -8,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestMethod; | @@ -8,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestMethod; | ||
| 8 | import org.springframework.web.bind.annotation.RequestParam; | 12 | import org.springframework.web.bind.annotation.RequestParam; |
| 9 | import org.springframework.web.bind.annotation.RestController; | 13 | import org.springframework.web.bind.annotation.RestController; |
| 10 | 14 | ||
| 15 | +import javax.servlet.http.HttpServletRequest; | ||
| 11 | import java.util.List; | 16 | import java.util.List; |
| 12 | import java.util.Map; | 17 | import java.util.Map; |
| 13 | 18 | ||
| @@ -21,8 +26,22 @@ public class PersonnelController extends BaseController<Personnel, Integer> { | @@ -21,8 +26,22 @@ public class PersonnelController extends BaseController<Personnel, Integer> { | ||
| 21 | @Autowired | 26 | @Autowired |
| 22 | private PersonnelService service; | 27 | private PersonnelService service; |
| 23 | 28 | ||
| 29 | + @Autowired | ||
| 30 | + PersionPinYinBuffer persionPinYinBuffer; | ||
| 31 | + | ||
| 24 | @RequestMapping(value = "/sreachPersonnel", method = RequestMethod.GET) | 32 | @RequestMapping(value = "/sreachPersonnel", method = RequestMethod.GET) |
| 25 | public List<Map<String, String>> sreachPersonnel(@RequestParam String jobCode) { | 33 | public List<Map<String, String>> sreachPersonnel(@RequestParam String jobCode) { |
| 26 | return service.sreachPersonnel(jobCode); | 34 | return service.sreachPersonnel(jobCode); |
| 27 | } | 35 | } |
| 36 | + | ||
| 37 | + @RequestMapping(value = "/all_py", method = RequestMethod.GET) | ||
| 38 | + public List<PersionPinYin> findAll_PY(){ | ||
| 39 | + return persionPinYinBuffer.getAll(); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + @RequestMapping(value = "/list_py", method = RequestMethod.GET) | ||
| 43 | + public List<PersionPinYin> findByCurrUser_PY(HttpServletRequest request){ | ||
| 44 | + List<CompanyAuthority> auths = (List<CompanyAuthority>) request.getSession().getAttribute(Constants.COMPANY_AUTHORITYS); | ||
| 45 | + return persionPinYinBuffer.getAll(auths); | ||
| 46 | + } | ||
| 28 | } | 47 | } |
src/main/java/com/bsth/controller/realcontrol/BasicDataController.java
| 1 | package com.bsth.controller.realcontrol; | 1 | package com.bsth.controller.realcontrol; |
| 2 | 2 | ||
| 3 | -import com.alibaba.fastjson.JSON; | ||
| 4 | import com.alibaba.fastjson.serializer.PropertyFilter; | 3 | import com.alibaba.fastjson.serializer.PropertyFilter; |
| 5 | import com.bsth.common.ResponseCode; | 4 | import com.bsth.common.ResponseCode; |
| 6 | import com.bsth.data.BasicData; | 5 | import com.bsth.data.BasicData; |
| @@ -60,16 +59,16 @@ public class BasicDataController { | @@ -60,16 +59,16 @@ public class BasicDataController { | ||
| 60 | return rs; | 59 | return rs; |
| 61 | } | 60 | } |
| 62 | 61 | ||
| 63 | - @RequestMapping("/personnel") | 62 | + /*@RequestMapping("/personnel") |
| 64 | public Map<String, Object> findPersonnelInfo(){ | 63 | public Map<String, Object> findPersonnelInfo(){ |
| 65 | Map<String, Object> rs = new HashMap<>(); | 64 | Map<String, Object> rs = new HashMap<>(); |
| 66 | PersonnelFieldFilter filter=new PersonnelFieldFilter(); | 65 | PersonnelFieldFilter filter=new PersonnelFieldFilter(); |
| 67 | //驾驶员 | 66 | //驾驶员 |
| 68 | rs.put("jsy", JSON.parse(JSON.toJSONString(BasicData.jsyMap.values(), filter))); | 67 | rs.put("jsy", JSON.parse(JSON.toJSONString(BasicData.jsyMap.values(), filter))); |
| 69 | //售票员 | 68 | //售票员 |
| 70 | - rs.put("spy", JSON.parse(JSON.toJSONString(BasicData.spyMap.values(), filter))); | 69 | + rs.put("spy", JSON.parse(JSON.toJSONString(BasicData.spyMap.values(), filter)));*//* |
| 71 | return rs; | 70 | return rs; |
| 72 | - } | 71 | + }*/ |
| 73 | 72 | ||
| 74 | @RequestMapping("/all_personnel") | 73 | @RequestMapping("/all_personnel") |
| 75 | public Map<String, String> all_personnel(){ | 74 | public Map<String, String> all_personnel(){ |
| @@ -179,15 +178,12 @@ public class BasicDataController { | @@ -179,15 +178,12 @@ public class BasicDataController { | ||
| 179 | map.put("lineCode", line.getLineCode()); | 178 | map.put("lineCode", line.getLineCode()); |
| 180 | rs.add(map); | 179 | rs.add(map); |
| 181 | } | 180 | } |
| 182 | - //listMultimap.put(line.getName(), nbbm); | ||
| 183 | } | 181 | } |
| 184 | - //return listMultimap.asMap(); | ||
| 185 | - | ||
| 186 | return rs; | 182 | return rs; |
| 187 | } | 183 | } |
| 188 | 184 | ||
| 189 | /** | 185 | /** |
| 190 | - * 获取站点和停车场对照表 | 186 | + * 获取站点和停车场历时公里对照表 |
| 191 | * @param idx | 187 | * @param idx |
| 192 | * @return | 188 | * @return |
| 193 | */ | 189 | */ |
src/main/java/com/bsth/data/BasicData.java
| @@ -2,6 +2,7 @@ package com.bsth.data; | @@ -2,6 +2,7 @@ package com.bsth.data; | ||
| 2 | 2 | ||
| 3 | import com.bsth.Application; | 3 | import com.bsth.Application; |
| 4 | import com.bsth.data.gpsdata.arrival.GeoCacheData; | 4 | import com.bsth.data.gpsdata.arrival.GeoCacheData; |
| 5 | +import com.bsth.data.pinyin.PersionPinYinBuffer; | ||
| 5 | import com.bsth.entity.*; | 6 | import com.bsth.entity.*; |
| 6 | import com.bsth.entity.schedule.CarConfigInfo; | 7 | import com.bsth.entity.schedule.CarConfigInfo; |
| 7 | import com.bsth.repository.*; | 8 | import com.bsth.repository.*; |
| @@ -64,10 +65,10 @@ public class BasicData implements CommandLineRunner { | @@ -64,10 +65,10 @@ public class BasicData implements CommandLineRunner { | ||
| 64 | //线路Code和shangHaiLinecode 对照 | 65 | //线路Code和shangHaiLinecode 对照 |
| 65 | public static Map<String, String> lineCode2ShangHaiCodeMap; | 66 | public static Map<String, String> lineCode2ShangHaiCodeMap; |
| 66 | 67 | ||
| 67 | - //驾驶员工号 和 personnel 对象映射 | 68 | + /*//驾驶员工号 和 personnel 对象映射 |
| 68 | public static Map<String, Personnel> jsyMap; | 69 | public static Map<String, Personnel> jsyMap; |
| 69 | //售票员工号 和 personnel 对象映射 | 70 | //售票员工号 和 personnel 对象映射 |
| 70 | - public static Map<String, Personnel> spyMap; | 71 | + public static Map<String, Personnel> spyMap;*/ |
| 71 | //所以员工和personnerl 对象映射 | 72 | //所以员工和personnerl 对象映射 |
| 72 | public static Map<String, Personnel> perMap; | 73 | public static Map<String, Personnel> perMap; |
| 73 | //全量员工 工号和姓名对照 | 74 | //全量员工 工号和姓名对照 |
| @@ -137,6 +138,9 @@ public class BasicData implements CommandLineRunner { | @@ -137,6 +138,9 @@ public class BasicData implements CommandLineRunner { | ||
| 137 | @Autowired | 138 | @Autowired |
| 138 | Station2ParkBuffer station2ParkBuffer; | 139 | Station2ParkBuffer station2ParkBuffer; |
| 139 | 140 | ||
| 141 | + @Autowired | ||
| 142 | + PersionPinYinBuffer persionPinYinBuffer; | ||
| 143 | + | ||
| 140 | 144 | ||
| 141 | @Override | 145 | @Override |
| 142 | public void run() { | 146 | public void run() { |
| @@ -165,6 +169,8 @@ public class BasicData implements CommandLineRunner { | @@ -165,6 +169,8 @@ public class BasicData implements CommandLineRunner { | ||
| 165 | geoCacheData.loadData(); | 169 | geoCacheData.loadData(); |
| 166 | station2ParkBuffer.saveAll(); | 170 | station2ParkBuffer.saveAll(); |
| 167 | logger.info("加载基础数据成功!,"); | 171 | logger.info("加载基础数据成功!,"); |
| 172 | + //人员拼音转换 | ||
| 173 | + persionPinYinBuffer.refresh(); | ||
| 168 | } catch (Exception e) { | 174 | } catch (Exception e) { |
| 169 | logger.error("加载基础数据时出现异常,", e); | 175 | logger.error("加载基础数据时出现异常,", e); |
| 170 | } | 176 | } |
| @@ -321,7 +327,7 @@ public class BasicData implements CommandLineRunner { | @@ -321,7 +327,7 @@ public class BasicData implements CommandLineRunner { | ||
| 321 | public void loadPersonnelInfo() { | 327 | public void loadPersonnelInfo() { |
| 322 | Iterator<Personnel> iterator = personnelRepository.findAll().iterator(); | 328 | Iterator<Personnel> iterator = personnelRepository.findAll().iterator(); |
| 323 | 329 | ||
| 324 | - Map<String, Personnel> jsyTempMap = new HashMap<>(), spyTempMap = new HashMap<>(),perTempMap=new HashMap<>(); | 330 | + Map<String, Personnel> /*jsyTempMap = new HashMap<>(), spyTempMap = new HashMap<>(),*/perTempMap=new HashMap<>(); |
| 325 | Map<String, String> allPersonMap = new HashMap<>(); | 331 | Map<String, String> allPersonMap = new HashMap<>(); |
| 326 | 332 | ||
| 327 | Personnel p; | 333 | Personnel p; |
| @@ -333,20 +339,20 @@ public class BasicData implements CommandLineRunner { | @@ -333,20 +339,20 @@ public class BasicData implements CommandLineRunner { | ||
| 333 | if (StringUtils.isEmpty(jobCode)) | 339 | if (StringUtils.isEmpty(jobCode)) |
| 334 | continue; | 340 | continue; |
| 335 | 341 | ||
| 336 | - if (p.getPosts() != null) { | 342 | + /*if (p.getPosts() != null) { |
| 337 | if (p.getPosts().equals("1")) | 343 | if (p.getPosts().equals("1")) |
| 338 | jsyTempMap.put(jobCode, p); | 344 | jsyTempMap.put(jobCode, p); |
| 339 | else if (p.getPosts().equals("2")) | 345 | else if (p.getPosts().equals("2")) |
| 340 | spyTempMap.put(jobCode, p); | 346 | spyTempMap.put(jobCode, p); |
| 341 | - } | 347 | + }*/ |
| 342 | 348 | ||
| 343 | perTempMap.put(jobCode, p); | 349 | perTempMap.put(jobCode, p); |
| 344 | 350 | ||
| 345 | allPersonMap.put(jobCode, p.getPersonnelName()); | 351 | allPersonMap.put(jobCode, p.getPersonnelName()); |
| 346 | } | 352 | } |
| 347 | 353 | ||
| 348 | - jsyMap = jsyTempMap; | ||
| 349 | - spyMap = spyTempMap; | 354 | + //jsyMap = jsyTempMap; |
| 355 | + //spyMap = spyTempMap; | ||
| 350 | allPerson = allPersonMap; | 356 | allPerson = allPersonMap; |
| 351 | perMap = perTempMap; | 357 | perMap = perTempMap; |
| 352 | } | 358 | } |
src/main/java/com/bsth/data/pinyin/PersionPinYin.java
0 → 100644
| 1 | +package com.bsth.data.pinyin; | ||
| 2 | + | ||
| 3 | +import com.fasterxml.jackson.annotation.JsonIgnore; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 人员拼音映射 | ||
| 7 | + * Created by panzhao on 2017/7/19. | ||
| 8 | + */ | ||
| 9 | +public class PersionPinYin { | ||
| 10 | + | ||
| 11 | + /** | ||
| 12 | + * Id | ||
| 13 | + */ | ||
| 14 | + private Integer id; | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * 工号 | ||
| 18 | + */ | ||
| 19 | + private String workId; | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 姓名 | ||
| 23 | + */ | ||
| 24 | + private String name; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 全拼 | ||
| 28 | + */ | ||
| 29 | + private String fullChars; | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * 简便 | ||
| 33 | + */ | ||
| 34 | + private String camelChars; | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * 所属公司编码 | ||
| 38 | + */ | ||
| 39 | + @JsonIgnore | ||
| 40 | + private String companyId; | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * 所属分公司编码 | ||
| 44 | + */ | ||
| 45 | + @JsonIgnore | ||
| 46 | + private String fgsCompanyId; | ||
| 47 | + | ||
| 48 | + public String getWorkId() { | ||
| 49 | + return workId; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public void setWorkId(String workId) { | ||
| 53 | + this.workId = workId; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public String getName() { | ||
| 57 | + return name; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + public void setName(String name) { | ||
| 61 | + this.name = name; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + public String getFullChars() { | ||
| 65 | + return fullChars; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + public void setFullChars(String fullChars) { | ||
| 69 | + this.fullChars = fullChars; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + public String getCamelChars() { | ||
| 73 | + return camelChars; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public void setCamelChars(String camelChars) { | ||
| 77 | + this.camelChars = camelChars; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + public String getCompanyId() { | ||
| 81 | + return companyId; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + public void setCompanyId(String companyId) { | ||
| 85 | + this.companyId = companyId; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + public String getFgsCompanyId() { | ||
| 89 | + return fgsCompanyId; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + public void setFgsCompanyId(String fgsCompanyId) { | ||
| 93 | + this.fgsCompanyId = fgsCompanyId; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + public Integer getId() { | ||
| 97 | + return id; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + public void setId(Integer id) { | ||
| 101 | + this.id = id; | ||
| 102 | + } | ||
| 103 | +} |
src/main/java/com/bsth/data/pinyin/PersionPinYinBuffer.java
0 → 100644
| 1 | +package com.bsth.data.pinyin; | ||
| 2 | + | ||
| 3 | +import com.bsth.data.BasicData; | ||
| 4 | +import com.bsth.entity.Personnel; | ||
| 5 | +import com.bsth.entity.sys.CompanyAuthority; | ||
| 6 | +import com.github.stuxuhai.jpinyin.PinyinException; | ||
| 7 | +import com.github.stuxuhai.jpinyin.PinyinFormat; | ||
| 8 | +import com.github.stuxuhai.jpinyin.PinyinHelper; | ||
| 9 | +import com.google.common.collect.ArrayListMultimap; | ||
| 10 | +import org.slf4j.Logger; | ||
| 11 | +import org.slf4j.LoggerFactory; | ||
| 12 | +import org.springframework.stereotype.Component; | ||
| 13 | + | ||
| 14 | +import java.util.ArrayList; | ||
| 15 | +import java.util.Collection; | ||
| 16 | +import java.util.List; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * 人员拼音数据映射缓存 | ||
| 20 | + * Created by panzhao on 2017/7/19. | ||
| 21 | + */ | ||
| 22 | +@Component | ||
| 23 | +public class PersionPinYinBuffer { | ||
| 24 | + | ||
| 25 | + static ArrayListMultimap<String, PersionPinYin> listMultimap = ArrayListMultimap.create(); | ||
| 26 | + static List<PersionPinYin> all = new ArrayList<>(); | ||
| 27 | + | ||
| 28 | + Logger log = LoggerFactory.getLogger(this.getClass()); | ||
| 29 | + | ||
| 30 | + | ||
| 31 | + public void refresh(){ | ||
| 32 | + ArrayListMultimap<String, PersionPinYin> listMultimapCopy = ArrayListMultimap.create(); | ||
| 33 | + List<PersionPinYin> allCopy = new ArrayList<>(); | ||
| 34 | + PersionPinYin ppy; | ||
| 35 | + | ||
| 36 | + Collection<Personnel> list = BasicData.perMap.values(); | ||
| 37 | + for(Personnel p : list){ | ||
| 38 | + ppy = new PersionPinYin(); | ||
| 39 | + ppy.setId(p.getId()); | ||
| 40 | + ppy.setCompanyId(p.getCompanyCode()); | ||
| 41 | + ppy.setFgsCompanyId(p.getBrancheCompanyCode()); | ||
| 42 | + ppy.setName(p.getPersonnelName()); | ||
| 43 | + ppy.setWorkId(p.getJobCode()); | ||
| 44 | + try { | ||
| 45 | + ppy.setFullChars(PinyinHelper.convertToPinyinString(ppy.getName(), "" , PinyinFormat.WITHOUT_TONE)); | ||
| 46 | + ppy.setCamelChars(PinyinHelper.getShortPinyin(ppy.getName())); | ||
| 47 | + }catch (PinyinException pye){ | ||
| 48 | + log.error("拼音转换出现异常," + ppy.getName(), pye); | ||
| 49 | + continue; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + listMultimapCopy.put(ppy.getCompanyId() + "_" + ppy.getFgsCompanyId(), ppy); | ||
| 53 | + allCopy.add(ppy); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + if(allCopy.size() > 0){ | ||
| 57 | + all = allCopy; | ||
| 58 | + listMultimap = listMultimapCopy; | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + public List<PersionPinYin> getAll(){ | ||
| 63 | + return all; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + public List<PersionPinYin> getAll(List<CompanyAuthority> auths){ | ||
| 67 | + List<PersionPinYin> rs = new ArrayList<>(); | ||
| 68 | + for(CompanyAuthority ca : auths){ | ||
| 69 | + rs.addAll(listMultimap.get(ca.getCompanyCode() + "_" + ca.getSubCompanyCode())); | ||
| 70 | + } | ||
| 71 | + return rs; | ||
| 72 | + } | ||
| 73 | +} |
src/main/java/com/bsth/data/schedule/DayOfSchedule.java
| @@ -7,6 +7,7 @@ import com.bsth.common.ResponseCode; | @@ -7,6 +7,7 @@ import com.bsth.common.ResponseCode; | ||
| 7 | import com.bsth.data.LineConfigData; | 7 | import com.bsth.data.LineConfigData; |
| 8 | import com.bsth.data.gpsdata.GpsRealData; | 8 | import com.bsth.data.gpsdata.GpsRealData; |
| 9 | import com.bsth.data.gpsdata.recovery.GpsDataRecovery; | 9 | import com.bsth.data.gpsdata.recovery.GpsDataRecovery; |
| 10 | +import com.bsth.data.schedule.f_a_l.FirstAndLastHandler; | ||
| 10 | import com.bsth.entity.realcontrol.LineConfig; | 11 | import com.bsth.entity.realcontrol.LineConfig; |
| 11 | import com.bsth.entity.realcontrol.ScheduleRealInfo; | 12 | import com.bsth.entity.realcontrol.ScheduleRealInfo; |
| 12 | import com.bsth.entity.schedule.SchedulePlanInfo; | 13 | import com.bsth.entity.schedule.SchedulePlanInfo; |
| @@ -176,6 +177,8 @@ public class DayOfSchedule { | @@ -176,6 +177,8 @@ public class DayOfSchedule { | ||
| 176 | //添加到缓存 | 177 | //添加到缓存 |
| 177 | putAll(list); | 178 | putAll(list); |
| 178 | 179 | ||
| 180 | + //标记首末班 | ||
| 181 | + FirstAndLastHandler.marks(list); | ||
| 179 | 182 | ||
| 180 | Set<String> lps = searchAllLP(list); | 183 | Set<String> lps = searchAllLP(list); |
| 181 | for (String lp : lps) { | 184 | for (String lp : lps) { |
src/main/java/com/bsth/data/schedule/f_a_l/FirstAndLastHandler.java
0 → 100644
| 1 | +package com.bsth.data.schedule.f_a_l; | ||
| 2 | + | ||
| 3 | +import com.bsth.data.BasicData; | ||
| 4 | +import com.bsth.data.schedule.DayOfSchedule; | ||
| 5 | +import com.bsth.data.schedule.ScheduleComparator; | ||
| 6 | +import com.bsth.data.schedule.f_a_l.entity.ToGateway; | ||
| 7 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | ||
| 8 | +import com.bsth.util.db.DBUtils_MS; | ||
| 9 | +import org.slf4j.Logger; | ||
| 10 | +import org.slf4j.LoggerFactory; | ||
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 12 | +import org.springframework.jdbc.core.BatchPreparedStatementSetter; | ||
| 13 | +import org.springframework.jdbc.core.JdbcTemplate; | ||
| 14 | +import org.springframework.jdbc.datasource.DataSourceTransactionManager; | ||
| 15 | +import org.springframework.stereotype.Component; | ||
| 16 | +import org.springframework.transaction.TransactionDefinition; | ||
| 17 | +import org.springframework.transaction.TransactionStatus; | ||
| 18 | +import org.springframework.transaction.support.DefaultTransactionDefinition; | ||
| 19 | + | ||
| 20 | +import java.sql.PreparedStatement; | ||
| 21 | +import java.sql.SQLException; | ||
| 22 | +import java.util.ArrayList; | ||
| 23 | +import java.util.Collections; | ||
| 24 | +import java.util.List; | ||
| 25 | +import java.util.concurrent.ConcurrentHashMap; | ||
| 26 | + | ||
| 27 | +/** | ||
| 28 | + * 首末班处理程序 | ||
| 29 | + * Created by panzhao on 2017/7/19. | ||
| 30 | + */ | ||
| 31 | +@Component | ||
| 32 | +public class FirstAndLastHandler { | ||
| 33 | + | ||
| 34 | + static ConcurrentHashMap<String, ToGateway> maps = new ConcurrentHashMap<>(); | ||
| 35 | + | ||
| 36 | + static Logger log = LoggerFactory.getLogger(FirstAndLastHandler.class); | ||
| 37 | + | ||
| 38 | + static boolean flag; | ||
| 39 | + | ||
| 40 | + @Autowired | ||
| 41 | + DayOfSchedule dayOfSchedule; | ||
| 42 | + | ||
| 43 | + public void marks(String lineCode){ | ||
| 44 | + marks(dayOfSchedule.findByLineCode(lineCode)); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * 标记首末班 | ||
| 49 | + * @param list | ||
| 50 | + */ | ||
| 51 | + public static void marks(List<ScheduleRealInfo> list){ | ||
| 52 | + try{ | ||
| 53 | + Collections.sort(list, new ScheduleComparator.FCSJ()); | ||
| 54 | + //按上下行分组 | ||
| 55 | + List<ScheduleRealInfo> ups = new ArrayList<>(), | ||
| 56 | + downs = new ArrayList<>(); | ||
| 57 | + | ||
| 58 | + for(ScheduleRealInfo sch : list){ | ||
| 59 | + if(sch.getXlDir().equals("0")) | ||
| 60 | + ups.add(sch); | ||
| 61 | + else | ||
| 62 | + downs.add(sch); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + markOneWay(ups); | ||
| 66 | + markOneWay(downs); | ||
| 67 | + }catch (Exception e){ | ||
| 68 | + log.error("", e); | ||
| 69 | + } | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * 标记单程,上行或下行 | ||
| 74 | + * @param list | ||
| 75 | + */ | ||
| 76 | + private static void markOneWay(List<ScheduleRealInfo> list){ | ||
| 77 | + ScheduleRealInfo first = null, last = null; | ||
| 78 | + | ||
| 79 | + for(ScheduleRealInfo sch: list){ | ||
| 80 | + if(sch._isInout() || sch.getBcType().equals("region") | ||
| 81 | + || sch.getBcType().equals("venting")) | ||
| 82 | + continue; | ||
| 83 | + | ||
| 84 | + if(first == null) | ||
| 85 | + first = sch; | ||
| 86 | + | ||
| 87 | + last = sch; | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + put(first, last); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + private static void put(ScheduleRealInfo first, ScheduleRealInfo last){ | ||
| 94 | + if(first == null || last == null) | ||
| 95 | + return; | ||
| 96 | + | ||
| 97 | + ToGateway tg = new ToGateway(); | ||
| 98 | + tg.setLineCode(first.getXlBm()); | ||
| 99 | + tg.setUpDown(Integer.parseInt(first.getXlDir())); | ||
| 100 | + tg.setsDeviceId(BasicData.deviceId2NbbmMap.inverse().get(first.getClZbh())); | ||
| 101 | + tg.setSt(first.getDfsjT()); | ||
| 102 | + | ||
| 103 | + tg.setRq(first.getScheduleDateStr()); | ||
| 104 | + | ||
| 105 | + tg.seteDeviceId(BasicData.deviceId2NbbmMap.inverse().get(last.getClZbh())); | ||
| 106 | + tg.setEt(last.getDfsjT()); | ||
| 107 | + | ||
| 108 | + maps.put(tg.getLineCode() + "_" + tg.getUpDown(), tg); | ||
| 109 | + flag = true; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + public static void saveAll(){ | ||
| 113 | + if(!flag) | ||
| 114 | + return; | ||
| 115 | + | ||
| 116 | + final List<ToGateway> pstList = new ArrayList<>(maps.values()); | ||
| 117 | + if(pstList == null || pstList.size() == 0) | ||
| 118 | + return; | ||
| 119 | + | ||
| 120 | + flag = false; | ||
| 121 | + JdbcTemplate jdbcTemp = new JdbcTemplate(DBUtils_MS.getDataSource()); | ||
| 122 | + //编程式事务 | ||
| 123 | + DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemp.getDataSource()); | ||
| 124 | + DefaultTransactionDefinition def = new DefaultTransactionDefinition(); | ||
| 125 | + def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); | ||
| 126 | + TransactionStatus status = tran.getTransaction(def); | ||
| 127 | + | ||
| 128 | + try{ | ||
| 129 | + //删除 | ||
| 130 | + jdbcTemp.update("delete from bsth_t_first_last"); | ||
| 131 | + //重新写入 | ||
| 132 | + jdbcTemp.batchUpdate("insert into bsth_t_first_last(line_code, s_device_id, st, e_device_id, et, up_down, rq) VALUES(?, ?, ?, ?, ?, ?, ?)", new BatchPreparedStatementSetter() { | ||
| 133 | + @Override | ||
| 134 | + public void setValues(PreparedStatement ps, int i) throws SQLException { | ||
| 135 | + ToGateway tg = pstList.get(i); | ||
| 136 | + ps.setString(1, tg.getLineCode()); | ||
| 137 | + ps.setString(2, tg.getsDeviceId()); | ||
| 138 | + ps.setLong(3, tg.getSt()); | ||
| 139 | + ps.setString(4, tg.geteDeviceId()); | ||
| 140 | + ps.setLong(5, tg.getEt()); | ||
| 141 | + ps.setInt(6, tg.getUpDown()); | ||
| 142 | + ps.setString(7, tg.getRq()); | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + @Override | ||
| 146 | + public int getBatchSize() { | ||
| 147 | + return pstList.size(); | ||
| 148 | + } | ||
| 149 | + }); | ||
| 150 | + | ||
| 151 | + log.info("首末班数据入库," + pstList.size()); | ||
| 152 | + tran.commit(status); | ||
| 153 | + }catch (Exception e){ | ||
| 154 | + log.error("", e); | ||
| 155 | + tran.rollback(status); | ||
| 156 | + } | ||
| 157 | + } | ||
| 158 | +} |
src/main/java/com/bsth/data/schedule/f_a_l/entity/ToGateway.java
0 → 100644
| 1 | +package com.bsth.data.schedule.f_a_l.entity; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 发送给网关的首末班数据格式 | ||
| 5 | + * Created by panzhao on 2017/7/19. | ||
| 6 | + */ | ||
| 7 | +public class ToGateway { | ||
| 8 | + | ||
| 9 | + /** 线路 */ | ||
| 10 | + private String lineCode; | ||
| 11 | + | ||
| 12 | + /** 上下行 */ | ||
| 13 | + private int upDown; | ||
| 14 | + | ||
| 15 | + /** 首班设备号 */ | ||
| 16 | + private String sDeviceId; | ||
| 17 | + | ||
| 18 | + /** 首班时间 */ | ||
| 19 | + private Long st; | ||
| 20 | + | ||
| 21 | + /** 末班设备号 */ | ||
| 22 | + private String eDeviceId; | ||
| 23 | + | ||
| 24 | + /** 末班时间 */ | ||
| 25 | + private Long et; | ||
| 26 | + | ||
| 27 | + /** 班次日期 */ | ||
| 28 | + private String rq; | ||
| 29 | + | ||
| 30 | + | ||
| 31 | + public String getLineCode() { | ||
| 32 | + return lineCode; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public void setLineCode(String lineCode) { | ||
| 36 | + this.lineCode = lineCode; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public Long getSt() { | ||
| 40 | + return st; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public void setSt(Long st) { | ||
| 44 | + this.st = st; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public Long getEt() { | ||
| 48 | + return et; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public void setEt(Long et) { | ||
| 52 | + this.et = et; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public String getRq() { | ||
| 56 | + return rq; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public void setRq(String rq) { | ||
| 60 | + this.rq = rq; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public int getUpDown() { | ||
| 64 | + return upDown; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public void setUpDown(int upDown) { | ||
| 68 | + this.upDown = upDown; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public String getsDeviceId() { | ||
| 72 | + return sDeviceId; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public void setsDeviceId(String sDeviceId) { | ||
| 76 | + this.sDeviceId = sDeviceId; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public String geteDeviceId() { | ||
| 80 | + return eDeviceId; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + public void seteDeviceId(String eDeviceId) { | ||
| 84 | + this.eDeviceId = eDeviceId; | ||
| 85 | + } | ||
| 86 | +} |
src/main/java/com/bsth/data/schedule/thread/ScheduleRefreshThread.java
| @@ -5,6 +5,7 @@ import com.bsth.data.LineConfigData; | @@ -5,6 +5,7 @@ import com.bsth.data.LineConfigData; | ||
| 5 | import com.bsth.data.directive.DayOfDirectives; | 5 | import com.bsth.data.directive.DayOfDirectives; |
| 6 | import com.bsth.data.pilot80.PilotReport; | 6 | import com.bsth.data.pilot80.PilotReport; |
| 7 | import com.bsth.data.schedule.DayOfSchedule; | 7 | import com.bsth.data.schedule.DayOfSchedule; |
| 8 | +import com.bsth.data.schedule.f_a_l.FirstAndLastHandler; | ||
| 8 | import com.bsth.entity.realcontrol.LineConfig; | 9 | import com.bsth.entity.realcontrol.LineConfig; |
| 9 | import org.slf4j.Logger; | 10 | import org.slf4j.Logger; |
| 10 | import org.slf4j.LoggerFactory; | 11 | import org.slf4j.LoggerFactory; |
| @@ -69,7 +70,9 @@ public class ScheduleRefreshThread extends Thread{ | @@ -69,7 +70,9 @@ public class ScheduleRefreshThread extends Thread{ | ||
| 69 | logger.info(lineCode + "翻班完成, " + currSchDate + " -班次数量:" + dayOfSchedule.findByLineCode(lineCode).size()); | 70 | logger.info(lineCode + "翻班完成, " + currSchDate + " -班次数量:" + dayOfSchedule.findByLineCode(lineCode).size()); |
| 70 | } | 71 | } |
| 71 | } | 72 | } |
| 72 | - | 73 | + |
| 74 | + //首末班入库(给网关用的数据) | ||
| 75 | + FirstAndLastHandler.saveAll(); | ||
| 73 | } catch (Exception e) { | 76 | } catch (Exception e) { |
| 74 | logger.error("", e); | 77 | logger.error("", e); |
| 75 | } | 78 | } |
src/main/java/com/bsth/service/schedule/impl/CarDeviceServiceImpl.java
| @@ -7,6 +7,8 @@ import com.bsth.service.schedule.CarDeviceService; | @@ -7,6 +7,8 @@ import com.bsth.service.schedule.CarDeviceService; | ||
| 7 | import com.bsth.service.schedule.exception.ScheduleException; | 7 | import com.bsth.service.schedule.exception.ScheduleException; |
| 8 | import org.springframework.beans.factory.annotation.Autowired; | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 9 | import org.springframework.stereotype.Service; | 9 | import org.springframework.stereotype.Service; |
| 10 | +import org.springframework.transaction.annotation.Isolation; | ||
| 11 | +import org.springframework.transaction.annotation.Propagation; | ||
| 10 | import org.springframework.transaction.annotation.Transactional; | 12 | import org.springframework.transaction.annotation.Transactional; |
| 11 | import org.springframework.util.CollectionUtils; | 13 | import org.springframework.util.CollectionUtils; |
| 12 | 14 | ||
| @@ -21,7 +23,7 @@ public class CarDeviceServiceImpl extends BServiceImpl<CarDevice, Long> implemen | @@ -21,7 +23,7 @@ public class CarDeviceServiceImpl extends BServiceImpl<CarDevice, Long> implemen | ||
| 21 | @Autowired | 23 | @Autowired |
| 22 | private CarsService carsService; | 24 | private CarsService carsService; |
| 23 | 25 | ||
| 24 | - @Transactional | 26 | + @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED) |
| 25 | @Override | 27 | @Override |
| 26 | public CarDevice save(CarDevice carDevice) { | 28 | public CarDevice save(CarDevice carDevice) { |
| 27 | // 查找对应的车辆基础信息,更新设备编号数据 | 29 | // 查找对应的车辆基础信息,更新设备编号数据 |
src/main/java/com/bsth/service/schedule/impl/TTInfoDetailServiceImpl.java
| @@ -144,6 +144,11 @@ public class TTInfoDetailServiceImpl extends BServiceImpl<TTInfoDetail, Long> im | @@ -144,6 +144,11 @@ public class TTInfoDetailServiceImpl extends BServiceImpl<TTInfoDetail, Long> im | ||
| 144 | return ttInfoDetailForEdit.getEditInfo(xlid, ttid, maxfcno); | 144 | return ttInfoDetailForEdit.getEditInfo(xlid, ttid, maxfcno); |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | + public static void main(String[] args) { | ||
| 148 | + String test = "中1中111"; | ||
| 149 | + System.out.println(test.replaceAll("(\\d+)$", "")); | ||
| 150 | + } | ||
| 151 | + | ||
| 147 | @Override | 152 | @Override |
| 148 | public void validateExcelSheet(String filename, String sheetname, Integer lineid, String linename) throws ScheduleException { | 153 | public void validateExcelSheet(String filename, String sheetname, Integer lineid, String linename) throws ScheduleException { |
| 149 | try { | 154 | try { |
| @@ -162,8 +167,9 @@ public class TTInfoDetailServiceImpl extends BServiceImpl<TTInfoDetail, Long> im | @@ -162,8 +167,9 @@ public class TTInfoDetailServiceImpl extends BServiceImpl<TTInfoDetail, Long> im | ||
| 162 | if (StringUtils.isEmpty(cell_con)) { | 167 | if (StringUtils.isEmpty(cell_con)) { |
| 163 | throw new Exception(String.format("第1行,第%d列数据不能为空", i + 1)); | 168 | throw new Exception(String.format("第1行,第%d列数据不能为空", i + 1)); |
| 164 | } else { | 169 | } else { |
| 165 | - // 正则表达式去除数字 | ||
| 166 | - cell_con = cell_con.replaceAll("[\\d+]", ""); | 170 | + // 正则表达式去除右侧数字 |
| 171 | +// cell_con = cell_con.replaceAll("[\\d+]", ""); | ||
| 172 | + cell_con = cell_con.replaceAll("(\\d+)$", ""); | ||
| 167 | 173 | ||
| 168 | if (i == 0) { // 第一列必须是路牌2个字 | 174 | if (i == 0) { // 第一列必须是路牌2个字 |
| 169 | if (!"路牌".equals(cell_con.trim())) { | 175 | if (!"路牌".equals(cell_con.trim())) { |