Commit 7b9d46bfad17af186c1edd3445949cace8944d4d
1 parent
15fe5ca3
时刻表明细(图形版本)制作批量插入代码写入
Showing
4 changed files
with
119 additions
and
4 deletions
src/main/java/com/bsth/controller/schedule/core/TTInfoDetailController.java
| @@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
| 8 | import org.springframework.web.bind.annotation.PathVariable; | 8 | import org.springframework.web.bind.annotation.PathVariable; |
| 9 | import org.springframework.web.bind.annotation.RequestMapping; | 9 | import org.springframework.web.bind.annotation.RequestMapping; |
| 10 | import org.springframework.web.bind.annotation.RequestMethod; | 10 | import org.springframework.web.bind.annotation.RequestMethod; |
| 11 | +import org.springframework.web.bind.annotation.RequestParam; | ||
| 11 | import org.springframework.web.bind.annotation.RestController; | 12 | import org.springframework.web.bind.annotation.RestController; |
| 12 | 13 | ||
| 13 | import java.util.HashMap; | 14 | import java.util.HashMap; |
| @@ -87,5 +88,16 @@ public class TTInfoDetailController extends BController<TTInfoDetail, Long> { | @@ -87,5 +88,16 @@ public class TTInfoDetailController extends BController<TTInfoDetail, Long> { | ||
| 87 | } | 88 | } |
| 88 | return rtn; | 89 | return rtn; |
| 89 | } | 90 | } |
| 90 | - | 91 | + |
| 92 | + /** | ||
| 93 | + * 时刻表明细批量插入 | ||
| 94 | + * | ||
| 95 | + * @param entities | ||
| 96 | + * | ||
| 97 | + * @return | ||
| 98 | + */ | ||
| 99 | + @RequestMapping(value = "/skbDetailMxSave" ,method = RequestMethod.POST) | ||
| 100 | + public Map<String, Object> skbDetailMxSave(@RequestParam Map<String, Object> entities){ | ||
| 101 | + return ttInfoDetailService.skbDetailMxSave(entities); | ||
| 102 | + } | ||
| 91 | } | 103 | } |
src/main/java/com/bsth/repository/schedule/GuideboardInfoRepository.java
| @@ -3,6 +3,7 @@ package com.bsth.repository.schedule; | @@ -3,6 +3,7 @@ package com.bsth.repository.schedule; | ||
| 3 | import java.util.List; | 3 | import java.util.List; |
| 4 | import java.util.Map; | 4 | import java.util.Map; |
| 5 | 5 | ||
| 6 | +import com.bsth.entity.Line; | ||
| 6 | import com.bsth.entity.schedule.EmployeeConfigInfo; | 7 | import com.bsth.entity.schedule.EmployeeConfigInfo; |
| 7 | import com.bsth.entity.schedule.GuideboardInfo; | 8 | import com.bsth.entity.schedule.GuideboardInfo; |
| 8 | import com.bsth.repository.BaseRepository; | 9 | import com.bsth.repository.BaseRepository; |
| @@ -37,4 +38,8 @@ public interface GuideboardInfoRepository extends BaseRepository<GuideboardInfo, | @@ -37,4 +38,8 @@ public interface GuideboardInfoRepository extends BaseRepository<GuideboardInfo, | ||
| 37 | "where td.ttinfo.id=?1 " + | 38 | "where td.ttinfo.id=?1 " + |
| 38 | "group by td.ttinfo.id, td.lp.id, td.lp.lpName") | 39 | "group by td.ttinfo.id, td.lp.id, td.lp.lpName") |
| 39 | List<Map<String, Object>> findLpName(Long ttid); | 40 | List<Map<String, Object>> findLpName(Long ttid); |
| 41 | + | ||
| 42 | + @Query(value = "SELECT g FROM GuideboardInfo g where g.xl =?1 and g.lpName = ?2 and g.lpNo = ?3 and lpType =?4 and isCancel = 0") | ||
| 43 | + List<GuideboardInfo> validateLp(Line xl,String lpName , int lpNo,String lpType); | ||
| 44 | + | ||
| 40 | } | 45 | } |
src/main/java/com/bsth/service/schedule/TTInfoDetailService.java
| @@ -6,6 +6,7 @@ import org.apache.commons.lang3.StringUtils; | @@ -6,6 +6,7 @@ import org.apache.commons.lang3.StringUtils; | ||
| 6 | 6 | ||
| 7 | import java.util.ArrayList; | 7 | import java.util.ArrayList; |
| 8 | import java.util.List; | 8 | import java.util.List; |
| 9 | +import java.util.Map; | ||
| 9 | 10 | ||
| 10 | /** | 11 | /** |
| 11 | * Created by xu on 16/7/2. | 12 | * Created by xu on 16/7/2. |
| @@ -200,5 +201,5 @@ public interface TTInfoDetailService extends BService<TTInfoDetail, Long> { | @@ -200,5 +201,5 @@ public interface TTInfoDetailService extends BService<TTInfoDetail, Long> { | ||
| 200 | // TODO:这个方法可以用通用方法解决,以后改 | 201 | // TODO:这个方法可以用通用方法解决,以后改 |
| 201 | List<TTInfoDetail> findBcdetails(Integer xlId, Long ttinfoId, Long lpId); | 202 | List<TTInfoDetail> findBcdetails(Integer xlId, Long ttinfoId, Long lpId); |
| 202 | 203 | ||
| 203 | - | 204 | + Map<String, Object> skbDetailMxSave(Map<String, Object> map); |
| 204 | } | 205 | } |
src/main/java/com/bsth/service/schedule/impl/TTInfoDetailServiceImpl.java
| 1 | package com.bsth.service.schedule.impl; | 1 | package com.bsth.service.schedule.impl; |
| 2 | 2 | ||
| 3 | +import com.alibaba.fastjson.JSONArray; | ||
| 4 | +import com.alibaba.fastjson.JSONObject; | ||
| 5 | +import com.bsth.common.ResponseCode; | ||
| 3 | import com.bsth.entity.CarPark; | 6 | import com.bsth.entity.CarPark; |
| 7 | +import com.bsth.entity.Line; | ||
| 4 | import com.bsth.entity.LineInformation; | 8 | import com.bsth.entity.LineInformation; |
| 5 | import com.bsth.entity.StationRoute; | 9 | import com.bsth.entity.StationRoute; |
| 6 | import com.bsth.entity.schedule.GuideboardInfo; | 10 | import com.bsth.entity.schedule.GuideboardInfo; |
| 7 | import com.bsth.entity.schedule.TTInfoDetail; | 11 | import com.bsth.entity.schedule.TTInfoDetail; |
| 12 | +import com.bsth.repository.CarParkRepository; | ||
| 13 | +import com.bsth.repository.LineRepository; | ||
| 14 | +import com.bsth.repository.StationRepository; | ||
| 15 | +import com.bsth.repository.schedule.GuideboardInfoRepository; | ||
| 8 | import com.bsth.repository.schedule.TTInfoDetailRepository; | 16 | import com.bsth.repository.schedule.TTInfoDetailRepository; |
| 17 | +import com.bsth.repository.schedule.TTInfoRepository; | ||
| 9 | import com.bsth.service.CarParkService; | 18 | import com.bsth.service.CarParkService; |
| 10 | import com.bsth.service.LineInformationService; | 19 | import com.bsth.service.LineInformationService; |
| 11 | import com.bsth.service.StationRouteService; | 20 | import com.bsth.service.StationRouteService; |
| @@ -58,7 +67,16 @@ public class TTInfoDetailServiceImpl extends BServiceImpl<TTInfoDetail, Long> im | @@ -58,7 +67,16 @@ public class TTInfoDetailServiceImpl extends BServiceImpl<TTInfoDetail, Long> im | ||
| 58 | private TTInfoDetailRepository ttInfoDetailRepository; | 67 | private TTInfoDetailRepository ttInfoDetailRepository; |
| 59 | @Autowired | 68 | @Autowired |
| 60 | private DataToolsProperties dataToolsProperties; | 69 | private DataToolsProperties dataToolsProperties; |
| 61 | - | 70 | + @Autowired |
| 71 | + private LineRepository lineRepository; | ||
| 72 | + @Autowired | ||
| 73 | + private TTInfoRepository infoRepository; | ||
| 74 | + @Autowired | ||
| 75 | + private StationRepository staRepository; | ||
| 76 | + @Autowired | ||
| 77 | + private CarParkRepository carParkRepository; | ||
| 78 | + @Autowired | ||
| 79 | + private GuideboardInfoRepository guideboardInfoRepository; | ||
| 62 | @Autowired | 80 | @Autowired |
| 63 | @Qualifier(value = "dataToolsServiceImpl") | 81 | @Qualifier(value = "dataToolsServiceImpl") |
| 64 | private DataToolsService dataToolsService; | 82 | private DataToolsService dataToolsService; |
| @@ -512,5 +530,84 @@ public class TTInfoDetailServiceImpl extends BServiceImpl<TTInfoDetail, Long> im | @@ -512,5 +530,84 @@ public class TTInfoDetailServiceImpl extends BServiceImpl<TTInfoDetail, Long> im | ||
| 512 | public List<TTInfoDetail> findBcdetails(Integer xlId, Long ttinfoId, Long lpId) { | 530 | public List<TTInfoDetail> findBcdetails(Integer xlId, Long ttinfoId, Long lpId) { |
| 513 | return ttInfoDetailRepository.findBcdetails(xlId, ttinfoId, lpId); | 531 | return ttInfoDetailRepository.findBcdetails(xlId, ttinfoId, lpId); |
| 514 | } | 532 | } |
| 515 | - | 533 | + |
| 534 | + @Override | ||
| 535 | + public Map<String, Object> skbDetailMxSave(Map<String, Object> map) { | ||
| 536 | + Map<String, Object> rs_m = new HashMap<String,Object>(); | ||
| 537 | + try { | ||
| 538 | + String d = map.get("d") == null ? null : map.get("d").toString(); | ||
| 539 | + if(d!=null) | ||
| 540 | + ttInfoDetailRepository.save(jsonArrayToListEntity(d)); | ||
| 541 | + } catch (Exception e) { | ||
| 542 | + e.printStackTrace(); | ||
| 543 | + rs_m.put("status", ResponseCode.ERROR); | ||
| 544 | + } | ||
| 545 | + rs_m.put("status", ResponseCode.SUCCESS); | ||
| 546 | + return rs_m; | ||
| 547 | + } | ||
| 548 | + | ||
| 549 | + public List<TTInfoDetail> jsonArrayToListEntity(String jsonStr) throws Exception { | ||
| 550 | + List<TTInfoDetail> listTd = new ArrayList<TTInfoDetail>(); | ||
| 551 | + JSONArray jsonArray = JSONArray.parseArray(jsonStr); | ||
| 552 | + for(int i =0; i<jsonArray.size();i++) { | ||
| 553 | + JSONObject jsonObj = jsonArray.getJSONObject(i); | ||
| 554 | + if(jsonObj.getString("bcType").equals("bd") || jsonObj.getString("bcType").equals("lc") || jsonObj.getString("bcType").equals("cf")) | ||
| 555 | + continue; | ||
| 556 | + listTd.add(objToEntity(jsonObj)); | ||
| 557 | + } | ||
| 558 | + return listTd; | ||
| 559 | + } | ||
| 560 | + | ||
| 561 | + public TTInfoDetail objToEntity(JSONObject obj) throws Exception { | ||
| 562 | + TTInfoDetail td = new TTInfoDetail(); | ||
| 563 | + Line xl = lineRepository.findOne(Integer.parseInt(obj.getString("xl"))); | ||
| 564 | + td.setXl(xl); | ||
| 565 | + td.setTtinfo(obj.getString("ttinfo") == null ? null : infoRepository.findOne(Long.parseLong(obj.getString("ttinfo")))); | ||
| 566 | + td.setLp(getLp(xl,obj.getString("lp"),Integer.parseInt(obj.getString("lp")),obj.getString("lpType"))); | ||
| 567 | + td.setFcno(Integer.parseInt(obj.getString("fcno"))); | ||
| 568 | + td.setXlDir(dirToCod(obj.get("xlDir").toString())); | ||
| 569 | + td.setQdz( obj.getString("qdz") ==null? null : staRepository.findOne(Integer.parseInt(obj.getString("qdz")))); | ||
| 570 | + td.setZdz(obj.getString("zdz") ==null ? null :staRepository.findOne(Integer.parseInt(obj.getString("zdz")))); | ||
| 571 | + td.setTcc(carParkRepository.findOne(Integer.parseInt(obj.getString("tcc")))); | ||
| 572 | + td.setFcsj(obj.getString("fcsj")); | ||
| 573 | + td.setBcs(Integer.parseInt(obj.getString("bcs"))); | ||
| 574 | + td.setJhlc(Double.parseDouble(obj.getString("jhlc"))); | ||
| 575 | + td.setBcsj(Integer.parseInt(obj.getString("bcsj"))); | ||
| 576 | + td.setBcType(obj.getString("bcType")); | ||
| 577 | + td.setIsFB(false); | ||
| 578 | + td.setIsSwitchXl(false); | ||
| 579 | + td.setSwitchXl(null); | ||
| 580 | + td.setSwitchXlDesc(null); | ||
| 581 | + td.setRemark(null); | ||
| 582 | + td.setCreateBy(null); | ||
| 583 | + td.setUpdateBy(null); | ||
| 584 | + return td; | ||
| 585 | + } | ||
| 586 | + | ||
| 587 | + public GuideboardInfo getLp(Line xl,String name, int code, String lpType) throws Exception { | ||
| 588 | + GuideboardInfo entity = new GuideboardInfo(); | ||
| 589 | + List<GuideboardInfo> lgi = guideboardInfoRepository.validateLp(xl, name, code,lpType); | ||
| 590 | + if(lgi.size()>0) { | ||
| 591 | + entity = lgi.get(0); | ||
| 592 | + }else{ | ||
| 593 | + entity.setXl(xl); | ||
| 594 | + entity.setLpNo(code); | ||
| 595 | + entity.setLpName(name); | ||
| 596 | + entity.setLpType(lpType); | ||
| 597 | + entity.setIsCancel(false); | ||
| 598 | + entity.setCreateBy(null); | ||
| 599 | + entity.setUpdateBy(null); | ||
| 600 | + guideboardInfoRepository.save(entity); | ||
| 601 | + } | ||
| 602 | + return entity; | ||
| 603 | + } | ||
| 604 | + | ||
| 605 | + public String dirToCod(String str) throws Exception { | ||
| 606 | + String c = ""; | ||
| 607 | + if(str.equals("relationshipGraph-up")) | ||
| 608 | + c = "0"; | ||
| 609 | + else if(str.equals("relationshipGraph-down")) | ||
| 610 | + c = "1"; | ||
| 611 | + return c; | ||
| 612 | + } | ||
| 516 | } | 613 | } |